libsurf
Programmer's Documentation

intersect.h (r6227/r5385)
1 
2 /* Copyright (C) 2015 David Eller <david@larosterna.com>
3  *
4  * Commercial License Usage
5  * Licensees holding valid commercial licenses may use this file in accordance
6  * with the terms contained in their respective non-exclusive license agreement.
7  * For further information contact david@larosterna.com .
8  *
9  * GNU General Public License Usage
10  * Alternatively, this file may be used under the terms of the GNU General
11  * Public License version 3.0 as published by the Free Software Foundation and
12  * appearing in the file gpl.txt included in the packaging of this file.
13  */
14 
15 #ifndef SURF_INTERSECT_H
16 #define SURF_INTERSECT_H
17 
18 #include <set>
19 #include <deque>
20 
21 #include "edgefaceisec.h"
22 
23 class TriMesh;
24 class MeshPatch;
25 class IsecLinePoint;
26 class MeshFields;
27 class BndRect;
28 
29 typedef std::set<EdgeFaceIsec> IsecTags;
30 
31 struct XsrSpot
32 {
33  Vct2 ctr;
34  Real ru, rv, maxsr;
35 
36  bool overlaps(const XsrSpot & a) const {
37  Real du = fabs(ctr[0] - a.ctr[0]);
38  Real dv = fabs(ctr[1] - a.ctr[1]);
39  if (du < ru+a.ru and dv < rv+a.rv)
40  return true;
41  else
42  return false;
43  }
44 
45  void merge(const XsrSpot & a) {
46  Real umin = std::min(ctr[0]-ru, a.ctr[0]-a.ru);
47  Real umax = std::max(ctr[0]+ru, a.ctr[0]+a.ru);
48  Real vmin = std::min(ctr[1]-rv, a.ctr[1]-a.rv);
49  Real vmax = std::max(ctr[1]+rv, a.ctr[1]+a.rv);
50  ctr[0] = 0.5*(umin + umax);
51  ctr[1] = 0.5*(vmin + vmax);
52  ru = 0.5*(umax - umin);
53  rv = 0.5*(vmax - vmin);
54  maxsr = std::max(maxsr, a.maxsr);
55  }
56 };
57 
58 typedef std::vector<XsrSpot> XsrSpotArray;
59 
61 {
62  std::vector<BndRect> bb;
63  XsrSpotArray xsa;
64  int shape;
65 };
66 
79 {
80  public:
81 
83  Intersector(MeshPatch *sred, MeshPatch *sblue);
84 
86  const IsecSet & findIntersections(Real maxgap = 1e-4);
87 
89  uint nlines() const {return isc.size();}
90 
92  const IsecSet & filter(Real maxphi, Real maxlen, Real minlen);
93 
95  const IsecSet & reduce(Real maxphi, Real minlen, Real bntol = 1e-4);
96 
98  void sortLooseLines(Real ptol = 1e-4);
99 
101  bool openLeadingEdge(uint i, uint j, Real ptol = 1e-4) const;
102 
104  bool connectLeadingEdge(const Indices & vi, const Indices & vj);
105 
107  bool closedLoops(Real tol = gmepsilon) const;
108 
110  bool connectedLines(Real tol = gmepsilon) const;
111 
113  bool endsOnBoundaries(Real ptol = 1e-4) const;
114 
116  uint joinSeamLines(Real tol, Real ptol = 1e-4);
117 
119  void addViz(MeshFields & mvz) const;
120 
122  void boxes(std::vector<BndRect> & bra, std::vector<BndRect> & brb) const;
123 
125  void sboxes(Real s, std::vector<BndRect> & bra, std::vector<BndRect> & brb) const;
126 
128  void locateXsrSpots(Real s, XsrSpotArray & xsa, XsrSpotArray & xsb) const;
129 
130  private:
131 
133  const MeshPatch *patch(const TriMesh *psf) const;
134 
136  std::pair<Vct2, Vct2> parameter(const EdgeFaceIsec & is) const;
137 
139  const MeshPatch *patch(const TriEdge & e) const;
140 
142  const MeshPatch *patch(const TriFace & f) const;
143 
145  Real sizeRatio(uint i, uint j) const;
146 
148  Real sizeRatio(uint i, uint j, Vct2 & ctr, Vct2 & r) const;
149 
151  const EdgeFaceIsec *findFirst(const IsecTags & t) const;
152 
154  const EdgeFaceIsec *findNext(const IsecLinePoint & last) const;
155 
157  const EdgeFaceIsec *findNearest(const IsecLinePoint & last,
158  const MeshPatch *psf,
159  uint i, Real & mdist) const;
160 
162  void mergeOverlaps(XsrSpotArray & xsa) const;
163 
165  void joinConnectedLines(Real tol);
166 
167  private:
168 
170  MeshPatch *sa, *sb;
171 
173  IsecSet isc;
174 
176  FaceIsecMap mf;
177 
179  EdgeIsecMap me;
180 };
181 
182 #endif
183 
void mergeOverlaps(XsrSpotArray &xsa) const
merge overlapping xsr spots
Definition: intersect.cpp:784
bool endsOnBoundaries(Real ptol=1e-4) const
check if the intersection lines end on boundaries
Definition: intersect.cpp:459
const IsecSet & filter(Real maxphi, Real maxlen, Real minlen)
after locating, drop uninteresting or duplicate intersection points
Definition: intersect.cpp:478
Generates the triangulation of a single surface.
Definition: meshpatch.h:61
Intersector(MeshPatch *sred, MeshPatch *sblue)
initialize with two discretized surfaces
Definition: intersect.cpp:95
IsecSet isc
all intersection lines
Definition: intersect.h:173
Real sizeRatio(uint i, uint j) const
convert size ratio to ratio sa/sb
Definition: intersect.cpp:820
bool connectedLines(Real tol=gmepsilon) const
check if open intersection lines are connected
Definition: intersect.cpp:417
const MeshPatch * patch(const TriMesh *psf) const
identify the corresponding meshpatch
Definition: intersect.cpp:374
void sortLooseLines(Real ptol=1e-4)
sort loose intersection lines so that they begin on boundary
Definition: intersect.cpp:879
std::pair< Vct2, Vct2 > parameter(const EdgeFaceIsec &is) const
obtain intersection parameter set
Definition: intersect.cpp:389
const IsecSet & findIntersections(Real maxgap=1e-4)
find all intersection lines
Definition: intersect.cpp:107
void locateXsrSpots(Real s, XsrSpotArray &xsa, XsrSpotArray &xsb) const
locate spots with excessive size ratio for all intersections
Definition: intersect.cpp:745
uint nlines() const
number of intersection lines found
Definition: intersect.h:89
Intersection between edge and triangular face.
Definition: edgefaceisec.h:34
Locates intersection lines.
Definition: intersect.h:78
const IsecSet & reduce(Real maxphi, Real minlen, Real bntol=1e-4)
reduce number of intersection points using a local size criterion
Definition: intersect.cpp:559
void boxes(std::vector< BndRect > &bra, std::vector< BndRect > &brb) const
compute bounding rectangles of intersections
Definition: intersect.cpp:682
const EdgeFaceIsec * findNext(const IsecLinePoint &last) const
find next intersection object, return 0 if unsuccesfull
Definition: intersect.cpp:281
void sboxes(Real s, std::vector< BndRect > &bra, std::vector< BndRect > &brb) const
compute bounding rectangles of regions where size ration s is exceeded
Definition: intersect.cpp:707
FaceIsecMap mf
map faces to intersections
Definition: intersect.h:176
bool openLeadingEdge(uint i, uint j, Real ptol=1e-4) const
test if loose end may be caused by unconnected leading edge
Definition: intersect.cpp:905
EdgeIsecMap me
map edges to intersections
Definition: intersect.h:179
uint joinSeamLines(Real tol, Real ptol=1e-4)
join seam lines if possible
Definition: intersect.cpp:1020
const EdgeFaceIsec * findNearest(const IsecLinePoint &last, const MeshPatch *psf, uint i, Real &mdist) const
find closest intersection among the nb edges of i
Definition: intersect.cpp:308
void joinConnectedLines(Real tol)
join connected intersection lines
Definition: intersect.cpp:1057
bool closedLoops(Real tol=gmepsilon) const
check if all intersection lines are closed in 3D
Definition: intersect.cpp:404
const EdgeFaceIsec * findFirst(const IsecTags &t) const
find starting point, returns 0 if unsuccessfull
Definition: intersect.cpp:242
Definition: intersect.h:31
Definition: intersect.h:60
MeshPatch * sa
two discretized surfaces
Definition: intersect.h:170
void addViz(MeshFields &mvz) const
create vizualization of the intersection points and lines
Definition: intersect.cpp:652
bool connectLeadingEdge(const Indices &vi, const Indices &vj)
try to connect across unconnected leading edge
Definition: intersect.cpp:987
Generated on Wed Jan 19 2022 03:03:15 for libsurf by   doxygen 1.8.5