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

Function fillIntermediateIndicesMap

source/MRMesh/MROffsetContours.cpp:26–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24using SingleOffset = std::function<float( int )>;
25
26void fillIntermediateIndicesMap(
27 const Contours2f& contours,
28 const Contours2f& intermediateRes,
29 const IntermediateIndicesMaps& shiftsMap,
30 OffsetContoursParams::Type type,
31 IntermediateIndicesMaps& outMap )
32{
33 auto findIndex = [&] ( int contId, int newIndex )->int
34 {
35 const auto& sm = shiftsMap[contId].map;
36 const auto& cont = contours[shiftsMap[contId].contourId];
37 const auto& resCont = intermediateRes[contId];
38
39 bool isClosed = cont.front() == cont.back();
40 if ( isClosed )
41 {
42 bool forward = type == OffsetContoursParams::Type::Offset ||
43 ( sm.size() > 1 && sm[1] - sm[0] > 0 );
44 int result = 0;
45 if ( forward )
46 {
47 for ( int i = 0; i < cont.size(); ++i )
48 if ( newIndex < sm[i] )
49 {
50 result = i;
51 break;
52 }
53 }
54 else
55 {
56 newIndex = int( resCont.size() ) - 1 - newIndex;
57 for ( int i = 0; i < cont.size(); ++i )
58 if ( newIndex < sm[int( cont.size() ) - 1 - i] )
59 {
60 result = i;
61 break;
62 }
63 }
64 return result == int( cont.size() ) - 1 ? 0 : result;
65 }
66 // if not closed
67 auto firstPartSize = sm[int( cont.size() ) - 1];
68 bool forward = newIndex < firstPartSize;
69 if ( forward )
70 {
71 for ( int i = 0; i < cont.size(); ++i )
72 if ( newIndex < sm[i] )
73 return i;
74 }
75 else
76 {
77 newIndex = int( resCont.size() ) - 2 - newIndex;
78 for ( int i = 0; i < cont.size(); ++i )
79 if ( newIndex < sm[int( sm.size() ) - 1 - i] )
80 return i;
81 }
82 return 0;
83 };

Callers 1

offsetContoursFunction · 0.85

Calls 3

ParallelForFunction · 0.85
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected