77 const point& pt = pts[i];
79 os <<
"v " << pt.
x() <<
' ' << pt.
y() <<
' ' << pt.
z() <<
endl;
88 Info<<
"Dumping borderPoints as obj file: " << fName <<
endl;
92 forAll(borderPoint, pointi)
94 if (borderPoint[pointi] != -1)
98 os <<
"v " << pt.
x() <<
' ' << pt.
y() <<
' ' << pt.
z() <<
endl;
108 Info<<
"Dumping borderEdges as obj file: " << fName <<
endl;
116 if (borderEdge[edgeI])
120 os <<
"l " <<
e.start()+1 <<
' ' <<
e.end()+1 <<
endl;
133 Info<<
"Dumping connectedFaces as obj file: " << fName <<
endl;
141 os <<
"v " << ctr.
x() <<
' ' << ctr.
y() <<
' ' << ctr.
z() <<
endl;
146 void testSortedEdgeFaces(
const triSurface& surf)
153 const labelList& myFaces = edgeFaces[edgeI];
154 const labelList& sortMyFaces = sortedEdgeFaces[edgeI];
158 if (!sortMyFaces.found(myFaces[i]))
165 if (!myFaces.found(sortMyFaces[i]))
175 label markBorderEdges
182 label nBorderEdges = 0;
188 if (edgeFaces[edgeI].size() == 4)
190 borderEdge[edgeI] =
true;
198 dumpEdges(surf, borderEdge);
207 label markBorderPoints
219 forAll(pointEdges, pointi)
221 const labelList& pEdges = pointEdges[pointi];
223 label nBorderEdges = 0;
227 if (borderEdge[pEdges[i]])
233 if (nBorderEdges == 2 && borderPoint[pointi] == -1)
235 borderPoint[pointi] =
nPoints++;
243 dumpPoints(surf, borderPoint);
246 return nBorderPoints;
252 scalar minEdgeLen(
const triSurface& surf,
const label pointi)
258 scalar minLen = GREAT;
262 label edgeI = pEdges[i];
286 label edgeI = edgeLabels[i];
308 <<
' ' << v1 <<
" in candidates " << edgeLabels
321 const label otherEdgeI,
329 label edgeI = fEdges[i];
348 <<
" connected to point " << pointi
365 const label startFacei,
366 const label startEdgeI,
367 const label startPointi,
373 label facei = startFacei;
374 label edgeI = startEdgeI;
375 label pointi = startPointi;
386 edgeI =
otherEdge(surf, facei, edgeI, pointi);
388 if (borderEdge[edgeI])
390 if (!faceToEdge.insert(facei, edgeI))
410 if (eFaces.size() != 2)
413 <<
"Can only handle edges with 2 or 4 edges for now."
417 if (eFaces[0] == facei)
421 else if (eFaces[1] == facei)
437 pointi = surf.
edges()[edgeI].otherVertex(pointi);
439 if (borderPoint[pointi] == -1)
454 const label firstFacei,
455 const label sharedEdgeI
464 label startIndex =
f.find(
e.start());
467 const bool edgeOrder = (
f[
f.fcIndex(startIndex)] ==
e.end());
475 const label faceIndex = eFaces.find(firstFacei);
480 return eFaces[eFaces.rcIndex(faceIndex)];
485 return eFaces[eFaces.fcIndex(faceIndex)];
508 const label edgeI = iter.val();
510 if (!edgeDone[edgeI])
512 edgeDone[edgeI] =
true;
520 const labelList& eFaces = sortedEdgeFaces[edgeI];
524 label facei = eFaces[i];
526 if (faceToEdge.found(facei))
532 else if (face1I == -1)
541 if (face0I == -1 && face1I == -1)
543 Info<<
"Writing surface to errorSurf.obj" <<
endl;
545 surf.
write(
"errorSurf.obj");
548 <<
"Cannot find two faces using border edge " << edgeI
549 <<
" verts:" << edges[edgeI]
550 <<
" eFaces:" << eFaces <<
endl
551 <<
"face0I:" << face0I
552 <<
" face1I:" << face1I <<
nl
553 <<
"faceToEdge:" << faceToEdge <<
nl
555 <<
"Written surface to errorSurf.obj"
561 const edge&
e = edges[edgeI];
592 scalar magMidVec =
mag(midVec);
594 if (magMidVec > SMALL)
599 borderPointVec[
e.start()] += midVec;
600 borderPointVec[
e.end()] += midVec;
619 const label facei = iter.key();
624 if (pointMap[
f[fp]] != -1)
626 newTris[facei][fp] = pointMap[
f[fp]];
635 bool splitBorderEdges
647 if (borderEdge[edgeI])
651 if (borderPoint[
e.start()] == -1 && borderPoint[
e.end()] == -1)
655 edgesToBeSplit[nSplit++] = edgeI;
659 edgesToBeSplit.
setSize(nSplit);
663 Info<<
"Splitting surface along " << nSplit <<
" borderEdges that don't"
664 <<
" neighbour other borderEdges" <<
nl <<
endl;
666 surf = triSurfaceTools::greenRefine(surf, edgesToBeSplit);
677 int main(
int argc,
char *argv[])
681 "Split multiply connected surface edges by duplicating points"
689 "Add debugging output"
698 Info<<
"Reading surface from " << inSurfName <<
endl;
703 testSortedEdgeFaces(surf);
707 markBorderEdges(
debug, surf, borderEdge);
713 markBorderPoints(
debug, surf, borderEdge, borderPoint);
716 splitBorderEdges(surf, borderEdge, borderPoint);
719 Info<<
"Writing split surface to " << outSurfName <<
nl <<
endl;
720 surf.
write(outSurfName);
721 Info<<
"Finished writing surface to " << outSurfName <<
nl <<
endl;
725 label nOldBorderEdges = -1;
726 label nOldBorderPoints = -1;
735 label nBorderEdges = markBorderEdges(
debug, surf, borderEdge);
737 if (nBorderEdges == 0)
739 Info<<
"Found no border edges. Exiting." <<
nl <<
nl;
747 label nBorderPoints =
756 if (nBorderPoints == 0)
758 Info<<
"Found no border points. Exiting." <<
nl <<
nl;
764 <<
" border edges :" << nBorderEdges <<
nl
765 <<
" border points:" << nBorderPoints <<
nl
770 nBorderPoints == nOldBorderPoints
771 && nBorderEdges == nOldBorderEdges
774 Info<<
"Stopping since number of border edges and point is same"
775 <<
" as in previous iteration" <<
nl <<
endl;
785 label startEdgeI = -1;
786 label startPointi = -1;
790 if (borderEdge[edgeI])
794 if ((borderPoint[
e[0]] != -1) && (borderPoint[
e[1]] == -1))
801 else if ((borderPoint[
e[0]] == -1) && (borderPoint[
e[1]] != -1))
811 if (startEdgeI == -1)
813 Info<<
"Cannot find starting point of splitLine\n" <<
endl;
821 label firstFacei = eFaces[0];
825 label secondFacei = sharedFace(surf, firstFacei, startEdgeI);
827 Info<<
"Starting local walk from:" <<
endl
828 <<
" edge :" << startEdgeI <<
endl
829 <<
" point:" << startPointi <<
endl
830 <<
" face0:" << firstFacei <<
endl
831 <<
" face1:" << secondFacei <<
endl
839 faceToEdge.insert(firstFacei, startEdgeI);
855 faceToEdge.insert(secondFacei, startEdgeI);
871 Info<<
"Finished local walk and visited" <<
nl
872 <<
" border edges :" << faceToEdge.size() <<
nl
873 <<
" border points(but not edges):" <<
faceToPoint.size() <<
nl
878 dumpFaces(
"faceToEdge.obj", surf, faceToEdge);
891 calcPointVecs(surf, faceToEdge,
faceToPoint, borderPointVec);
896 newPoints.setSize(newPoints.size() + nBorderPoints);
898 forAll(borderPoint, pointi)
904 scalar minLen = minEdgeLen(surf, pointi);
908 newPoints[
newPointi] = newPoints[pointi] + 0.1 * minLen *
n;
923 newTris[facei].region() = surf[facei].region();
927 renumberFaces(surf, borderPoint, faceToEdge, newTris);
929 renumberFaces(surf, borderPoint,
faceToPoint, newTris);
939 const point& pt = newPoints[
f[fp]];
941 if (
mag(pt) >= GREAT/2)
943 Info<<
"newTri:" << facei <<
" verts:" <<
f
944 <<
" vert:" <<
f[fp] <<
" point:" << pt <<
endl;
952 if (
debug || (iteration != 0 && (iteration % 20) == 0))
954 Info<<
"Writing surface to " << outSurfName <<
nl <<
endl;
956 surf.
write(outSurfName);
958 Info<<
"Finished writing surface to " << outSurfName <<
nl <<
endl;
962 nOldBorderEdges = nBorderEdges;
963 nOldBorderPoints = nBorderPoints;
969 Info<<
"Writing final surface to " << outSurfName <<
nl <<
endl;
971 surf.
write(outSurfName);