MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / precisePredicates

Function precisePredicates

source/MRMesh/MR2DContoursTriangulation.cpp:87–130  ·  view source on GitHub ↗

default predicates: exact integer arithmetic with simulation-of-simplicity (historical behavior)

Source from the content-addressed store, hash-verified

85
86// default predicates: exact integer arithmetic with simulation-of-simplicity (historical behavior)
87static SweepLinePredicates precisePredicates( const Contours2f& contours )
88{
89 Box3f box;
90 int pointsSize = 0;
91 for ( const auto& cont : contours )
92 {
93 for ( const auto& p : cont )
94 box.include( to3dim( p ) );
95 if ( cont.size() > 3 )
96 {
97 assert( cont.front() == cont.back() );
98 pointsSize += int( cont.size() ) - 1;
99 }
100 }
101
102 auto pts = std::make_shared<Vector<Vector2i, VertId>>();
103 pts->reserve( pointsSize );
104 auto toInt = [conv = getToIntConverter( Box3d( box ) )] ( const Vector2f& coord )
105 {
106 return to2dim( conv( to3dim( coord ) ) );
107 };
108 auto toFloat = [conv = getToFloatConverter( Box3d( box ) )] ( const Vector2i& coord )
109 {
110 return to2dim( conv( to3dim( coord ) ) );
111 };
112
113 SweepLinePredicates p;
114 setPts2Predicates( p, pts );
115 // resolve an input vertex by (contourId, pointId); initMeshByContours_ drives the order, so
116 // `contours` only needs to outlive construction (every caller passes its own input by reference)
117 p.addInputPoint = [&contours, pts, toInt] ( VertId v, int contourId, int pointId )
118 {
119 pts->autoResizeSet( v, toInt( contours[contourId][pointId] ) );
120 };
121 p.addIntersectionPoint = [pts] ( VertId v, VertId a, VertId b, VertId c, VertId d )
122 {
123 pts->autoResizeSet( v, findSegmentSegmentIntersectionPrecise( ( *pts )[a], ( *pts )[b], ( *pts )[c], ( *pts )[d] ) );
124 };
125 p.point = [pts, toFloat] ( VertId v )
126 {
127 return to3dim( toFloat( ( *pts )[v] ) );
128 };
129 return p;
130}
131
132// per-contour vertex counts; lets the queue build the initial edge loops independently of coordinate dimension
133static std::vector<int> getContourSizes( const Contours2f& contours )

Callers 3

getOutlineMeshFunction · 0.85
triangulateContoursFunction · 0.85

Calls 10

to3dimFunction · 0.85
getToIntConverterFunction · 0.85
to2dimFunction · 0.85
getToFloatConverterFunction · 0.85
setPts2PredicatesFunction · 0.85
includeMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
autoResizeSetMethod · 0.45

Tested by

no test coverage detected