23#ifndef __VCGLIB_CURVE_ON_SURF_H
24#define __VCGLIB_CURVE_ON_SURF_H
26#include<vcg/complex/complex.h>
27#include<vcg/simplex/face/topology.h>
28#include<vcg/complex/algorithms/update/topology.h>
29#include<vcg/complex/algorithms/update/color.h>
30#include<vcg/complex/algorithms/update/normal.h>
31#include<vcg/complex/algorithms/update/quality.h>
32#include<vcg/complex/algorithms/clean.h>
33#include<vcg/complex/algorithms/refine.h>
34#include<vcg/complex/algorithms/create/platonic.h>
35#include<vcg/complex/algorithms/point_sampling.h>
36#include <vcg/space/index/grid_static_ptr.h>
37#include <vcg/space/index/kdtree/kdtree.h>
38#include <vcg/math/histogram.h>
39#include<vcg/space/distance3.h>
40#include <vcg/complex/algorithms/attribute_seam.h>
41#include <wrap/io_trimesh/export_ply.h>
87template <
class MeshType>
91 typedef typename MeshType::ScalarType ScalarType;
92 typedef typename MeshType::CoordType CoordType;
93 typedef typename MeshType::VertexType VertexType;
94 typedef typename MeshType::VertexPointer VertexPointer;
95 typedef typename MeshType::VertexIterator VertexIterator;
96 typedef typename MeshType::EdgeIterator EdgeIterator;
97 typedef typename MeshType::EdgeType EdgeType;
98 typedef typename MeshType::FaceType FaceType;
99 typedef typename MeshType::FacePointer FacePointer;
100 typedef typename MeshType::FaceIterator FaceIterator;
102 typedef Segment3<ScalarType> Segment3Type;
103 typedef typename vcg::GridStaticPtr<FaceType, ScalarType> MeshGrid;
104 typedef typename vcg::GridStaticPtr<EdgeType, ScalarType> EdgeGrid;
105 typedef typename face::Pos<FaceType> PosType;
176 ScalarType closestDist;
189 ScalarType closestDist;
190 CoordType closestP,closestN;
203 ScalarType closestDist;
216 ScalarType closestDist;
241 assert(ip[0]+ip[1]+ip[2] == 1.0);
257 if(ip[i]>0.0 && ip[(i+1)%3]>0.0 && ip[(i+2)%3]==0.0 ) {
274 if(ip[i]==1.0 && ip[(i+1)%3]==0.0 && ip[(i+2)%3]==0.0 ) {
291 if(ip[i]==1.0 && ip[(i+1)%3]==0.0 && ip[(i+2)%3]==0.0 )
return fp->V(i);
326 for(EdgeIterator ei=poly.edge.begin(); ei!=poly.edge.end();++ei)
344 bool ret=face::FindSharedFaces<FaceType>(v0,v1,ff0,ff1,e0,e1);
348 assert(ff0->V(e0)==v0 || ff0->V(e0)==v1);
349 ff0->SetFaceEdgeS(e0);
350 ff1->SetFaceEdgeS(e1);
370 ScalarType
MinDistOnEdge(CoordType samplePnt, EdgeGrid &edgeGrid, MeshType &poly, CoordType &closestPoint)
373 EdgeType *cep = vcg::tri::GetClosestEdgeBase(poly,edgeGrid,samplePnt,
par.
gridBailout,polyDist,closestPoint);
388 static ScalarType
MinDistOnEdge(VertexType *v0,VertexType *v1, EdgeGrid &edgeGrid, MeshType &poly, CoordType &closestPoint)
390 ScalarType minPolyDist = std::numeric_limits<ScalarType>::max();
391 const ScalarType sampleNum = 50;
392 const ScalarType maxDist = poly.bbox.Diag()/10.0;
393 for(ScalarType k = 0;k<sampleNum+1;++k)
396 CoordType closestPPoly;
397 CoordType samplePnt = (v0->P()*k +v1->P()*(sampleNum-k))/sampleNum;
399 EdgeType *cep = vcg::tri::GetClosestEdgeBase(poly,edgeGrid,samplePnt,maxDist,polyDist,closestPPoly);
401 if(polyDist < minPolyDist)
403 minPolyDist = polyDist;
404 closestPoint = samplePnt;
428 static inline void ExtractVertex(
const MeshType & srcMesh,
const FaceType & f,
int whichWedge,
const MeshType & dstMesh, VertexType & v)
434 v.ImportData(*f.cV(whichWedge));
451 static inline bool CompareVertex(
const MeshType & m,
const VertexType & vA,
const VertexType & vB)
455 if(vA.C() ==
Color4b(Color4b::Red) && vB.C() ==
Color4b(Color4b::Blue) )
return false;
456 if(vA.C() ==
Color4b(Color4b::Blue) && vB.C() ==
Color4b(Color4b::Red) )
return false;
473 static CoordType
QLerp(VertexType *v0, VertexType *v1)
476 ScalarType qSum = fabs(v0->Q())+fabs(v1->Q());
477 ScalarType w0 = (qSum - fabs(v0->Q()))/qSum;
478 ScalarType w1 = (qSum - fabs(v1->Q()))/qSum;
479 return v0->P()*w0 + v1->P()*w1;
501 int borderCnt=0,midCnt=0,nonmanifCnt=0;
502 for(VertexIterator vi=poly.vert.begin(); vi!=poly.vert.end();++vi)
508 if(ip[0]>0 && ip[1]>0) { vi->P() = f->P(0)*ip[0]+f->P(1)*ip[1]; edgeSnapCnt++; assert(ip[2]==0); vi->C()=Color4b::White;}
509 if(ip[0]>0 && ip[2]>0) { vi->P() = f->P(0)*ip[0]+f->P(2)*ip[2]; edgeSnapCnt++; assert(ip[1]==0); vi->C()=Color4b::White;}
510 if(ip[1]>0 && ip[2]>0) { vi->P() = f->P(1)*ip[1]+f->P(2)*ip[2]; edgeSnapCnt++; assert(ip[0]==0); vi->C()=Color4b::White;}
512 if(ip[0]==1.0) { vi->P() = f->P(0); vertSnapCnt++; assert(ip[1]==0 && ip[2]==0); vi->C()=Color4b::Black; }
513 if(ip[1]==1.0) { vi->P() = f->P(1); vertSnapCnt++; assert(ip[0]==0 && ip[2]==0); vi->C()=Color4b::Black;}
514 if(ip[2]==1.0) { vi->P() = f->P(2); vertSnapCnt++; assert(ip[0]==0 && ip[1]==0); vi->C()=Color4b::Black;}
518 int deg = edge::VEDegree<EdgeType>(&*vi);
519 if (deg > 2) { nonmanifCnt++; vi->C()=Color4b::Magenta; }
520 if (deg < 2) { borderCnt++; vi->C()=Color4b::Green;}
521 if (deg== 2) { midCnt++; vi->C()=Color4b::Blue;}
524 printf(
"SnapPolyline %i vertices: snapped %i onto vert and %i onto edges %i nonmanif, %i border, %i mid\n",
525 poly.vn, vertSnapCnt, edgeSnapCnt, nonmanifCnt,borderCnt,midCnt); fflush(stdout);
528 if(dupCnt) printf(
"SnapPolyline: Removed %i Duplicated vertices\n",dupCnt);
530 return vertSnapCnt==0 && edgeSnapCnt==0 && dupCnt==0;
533 void SelectBoundaryVertex(MeshType &poly)
538 if(edge::VEDegree<EdgeType>(&v)==1) v.SetS();
542 void SelectUniformlyDistributed(MeshType &poly,
int k)
544 tri::TrivialPointerSampler<MeshType> tps;
545 ScalarType samplingRadius = tri::Stat<MeshType>::ComputeEdgeLengthSum(poly)/ScalarType(k);
546 tri::SurfaceSampling<MeshType, typename tri::TrivialPointerSampler<MeshType> >::EdgeMeshUniform(poly,tps,samplingRadius);
547 for(
int i=0;i<tps.sampleVec.size();++i)
548 tps.sampleVec[i]->SetS();
567 void DecomposeNonManifoldPolyline(MeshType &poly,
bool singSplitFlag =
true)
569 tri::Allocator<MeshType>::CompactEveryVector(poly);
570 std::vector<int> degreeVec(poly.vn, 0);
571 tri::UpdateTopology<MeshType>::VertexEdge(poly);
574 if(singSplitFlag) delta = 1;
577 for(VertexIterator vi=poly.vert.begin(); vi!=poly.vert.end();++vi)
579 std::vector<EdgeType *> starVec;
580 edge::VEStarVE(&*vi,starVec);
581 degreeVec[tri::Index(poly, *vi)] = starVec.size();
583 neededVert += starVec.size()-delta;
585 printf(
"DecomposeNonManifold Adding %i vert to a polyline of %i vert\n",neededVert,poly.vn);
588 for(
size_t i=0;i<degreeVec.size();++i)
592 std::vector<EdgeType *> edgeStarVec;
593 edge::VEStarVE(&(poly.vert[i]),edgeStarVec);
594 assert(edgeStarVec.size() == degreeVec[i]);
595 for(
size_t j=delta;j<edgeStarVec.size();++j)
597 EdgeType *ep = edgeStarVec[j];
599 if(tri::Index(poly,ep->V(0)) == i) ind = 0;
602 ep->V(ind) = &*firstVi;
603 ep->V(ind)->P() = poly.vert[i].P();
604 ep->V(ind)->N() = poly.vert[i].N();
609 assert(firstVi == poly.vert.end());
646 std::vector< std::pair<int,VertexPointer> > toSplitVec;
648 for(VertexIterator vi=poly.vert.begin(); vi!=poly.vert.end();++vi)
653 toSplitVec.push_back(std::make_pair(tri::Index(
base,f),&*vi));
656 printf(
"SplitMeshWithPolyline found %lu non snapped points\n",toSplitVec.size()); fflush(stdout);
662 for(
size_t i =0; i<toSplitVec.size();++i)
664 newVi->P() = toSplitVec[i].second->P();
665 newVi->C()=Color4b::Green;
674 std::map<std::pair<CoordType,CoordType>, VertexPointer> edgeToSplitMap;
677 edgeToSplitMap.clear();
678 for(VertexIterator vi=poly.vert.begin(); vi!=poly.vert.end();++vi)
685 if((ip[i ]>0 && ip[i ]<1.0) &&
686 (ip[(i+1)%3]>0 && ip[(i+1)%3]<1.0) &&
689 CoordType p0=f->P0(i);
690 CoordType p1=f->P1(i);
691 if (p0>p1) std::swap(p0,p1);
692 if(edgeToSplitMap[std::make_pair(p0,p1)])
693 printf(
"Found an already used Edge %lu - %lu vert %lu!!!\n", tri::Index(
base,f->V0(i)),tri::Index(
base,f->V1(i)),tri::Index(poly,&*vi));
694 edgeToSplitMap[std::make_pair(p0,p1)]=&*vi;
698 printf(
"SplitMeshWithPolyline: Created a map of %lu edges to be split\n",edgeToSplitMap.size());
702 tri::RefineE(
base,eSplit,ePred);
704 }
while(edgeToSplitMap.size()>0);
745 printf(
"SimplifyNullEdges: Removed %i Duplicated vertices\n",cnt);
748 void SimplifyMidEdge(MeshType &poly)
751 int midEdgeCollapseCnt=0;
756 for(
int ei =0; ei<poly.en; ++ei)
758 VertexType *v0=poly.edge[ei].V(0);
759 VertexType *v1=poly.edge[ei].V(1);
770 if( ( f0 == f1 && e0i == e1i) ||
771 ( f0 == f1->FFp(e1i) && e0i == f1->FFi(e1i)) ||
772 (f0->FFp(e0i) == f1 && f0->FFi(e0i) == e1i) ||
773 (f0->FFp(e0i) == f1->FFp(e1i) && f0->FFi(e0i) == f1->FFi(e1i)) )
775 CoordType newp = (v0->P()+v1->P())/2.0;
778 midEdgeCollapseCnt++;
782 tri::Allocator<MeshType>::CompactEveryVector(poly);
784 }
while(startVn>poly.vn);
797 int startVn= poly.vn;;
798 int midFaceCollapseCnt=0;
799 int vertexEdgeCollapseCnt=0;
806 for(
int i =0; i<poly.vn;++i)
808 std::vector<VertexPointer> starVecVp;
809 edge::VVStarVE(&(poly.vert[i]),starVecVp);
810 if( (starVecVp.size()==2) )
812 CoordType ipP, ipN, ipI;
820 VertexPointer vertexSnapP = 0;
821 VertexPointer vertexSnapN = 0;
822 VertexPointer vertexSnapI = 0;
825 if(ipP[j]==1.0) vertexSnapP=fpP->V(j);
826 if(ipN[j]==1.0) vertexSnapN=fpN->V(j);
827 if(ipI[j]==1.0) vertexSnapI=fpI->V(j);
830 bool collapseFlag=
false;
832 if((!snapI && snapP && snapN) ||
833 (!snapI && !snapP && fpI==fpP) ||
834 (!snapI && !snapN && fpI==fpN) )
837 midFaceCollapseCnt++;
841 if(snapI && snapP && snapN && vertexSnapI==0 && (vertexSnapP!=0 || vertexSnapN!=0) )
843 for(
int j=0;j<3;++j) {
844 if(ipI[j]!=0 && (fpI->V(j)==vertexSnapP || fpI->V(j)==vertexSnapN)) {
846 vertexEdgeCollapseCnt++;
852 edge::VEEdgeCollapse(poly,&(poly.vert[i]));
855 }
while(curVn>poly.vn);
856 printf(
"SimplifyMidFace %5i -> %5i %i mid %i ve \n",startVn,poly.vn,midFaceCollapseCnt,vertexEdgeCollapseCnt);
859 void Simplify(MeshType &poly)
861 int startEn = poly.en;
862 Distribution<ScalarType> hist;
863 for(
int i =0; i<poly.en;++i)
864 hist.Add(edge::Length(poly.edge[i]));
868 for(
int i =0; i<poly.vn;++i)
870 std::vector<VertexPointer> starVecVp;
871 edge::VVStarVE(&(poly.vert[i]),starVecVp);
872 if ((starVecVp.size()==2) && (!poly.vert[i].IsS()))
874 ScalarType newSegLen = Distance(starVecVp[0]->P(), starVecVp[1]->P());
875 Segment3Type seg(starVecVp[0]->P(),starVecVp[1]->P());
877 CoordType closestPSeg;
878 SegmentPointDistance(seg,poly.vert[i].cP(),closestPSeg,segDist);
880 ScalarType maxSurfDist = MaxSegDist(starVecVp[0], starVecVp[1],fp,fn);
884 edge::VEEdgeCollapse(poly,&(poly.vert[i]));
889 tri::Allocator<MeshType>::CompactEveryVector(poly);
894 void EvaluateHausdorffDistance(MeshType &poly, Distribution<ScalarType> &dist)
897 tri::UpdateTopology<MeshType>::VertexEdge(poly);
899 for(
int i =0; i<poly.edge.size();++i)
901 CoordType farthestP, farthestN;
902 ScalarType maxDist = MaxSegDist(poly.edge[i].V(0),poly.edge[i].V(1), farthestP, farthestN, &dist);
903 poly.edge[i].V(0)->Q()+= maxDist;
904 poly.edge[i].V(1)->Q()+= maxDist;
906 for(
int i=0;i<poly.vn;++i)
908 ScalarType deg = edge::VEDegree<EdgeType>(&poly.vert[i]);
909 poly.vert[i].Q()/=deg;
955 ScalarType sum = ip[0]+ip[1]+ip[2];
958 if(ip[i]!=1.0) ip[i]/=sum;
960 sum = ip[0]+ip[1]+ip[2];
964 if(ip[i]>0.0 && ip[i]<1.0)
965 ip[i]=1.0-(ip[(i+1)%3]+ip[(i+2)%3]);
968 sum = ip[0]+ip[1]+ip[2];
971 if(ip[0]==0 || ip[1]==0 || ip[2]==0)
return true;
995 Segment3Type segPoly(v0->P(),v1->P());
996 const ScalarType sampleNum = 40;
1001 if(f0==f1)
return false;
1003 bool snap0=
false,snap1=
false;
1007 VertexPointer vertexSnap0 = 0;
1008 VertexPointer vertexSnap1 = 0;
1011 for(
int i=0;i<3;++i) {
1012 if(ip0[i]==1.0) vertexSnap0=f0->V(i);
1013 if(ip0[i]==0.0) seg0=Segment3Type(f0->P1(i),f0->P2(i));
1018 for(
int i=0;i<3;++i){
1019 if(ip1[i]==1.0) vertexSnap1=f1->V(i);
1020 if(ip1[i]==0.0) seg1=Segment3Type(f1->P1(i),f1->P2(i));
1024 CoordType bestSplitPt(0,0,0);
1025 ScalarType bestDist = std::numeric_limits<ScalarType>::max();
1026 for(ScalarType k = 1;k<sampleNum;++k)
1028 CoordType samplePnt = segPoly.Lerp(k/sampleNum);
1034 VertexPointer vertexSnapI = 0;
1035 for(
int i=0;i<3;++i)
1036 if(ip[i]==1.0) vertexSnapI=f->V(i);
1037 CoordType closestPt = f->P(0)*ip[0]+f->P(1)*ip[1]+f->P(2)*ip[2];
1038 if(Distance(samplePnt,closestPt) < bestDist )
1040 ScalarType dist0=std::numeric_limits<ScalarType>::max();
1041 ScalarType dist1=std::numeric_limits<ScalarType>::max();
1042 CoordType closestSegPt;
1043 if(snap0) SegmentPointDistance(seg0,closestPt,closestSegPt,dist0);
1044 if(snap1) SegmentPointDistance(seg1,closestPt,closestSegPt,dist1);
1046 ( vertexSnapI!=vertexSnap0 && vertexSnapI!=vertexSnap1) )
1048 bestDist = Distance(samplePnt,closestPt);
1049 bestSplitPt = closestPt;
1056 splitPt = bestSplitPt;
1078 if(f0==f1)
return true;
1085 FacePointer f0p=0;
int e0p=-1;
1086 FacePointer f1p=0;
int e1p=-1;
1087 assert((e0Snap != v0Snap) && (e1Snap != v1Snap));
1090 f0p = f0->FFp(e0); e0p=f0->FFi(e0); assert(f0p->FFp(e0p)==f0);
1093 f1p = f1->FFp(e1); e1p=f1->FFi(e1); assert(f1p->FFp(e1p)==f1);
1096 if(e0Snap && e1Snap) {
1097 if(f0==f1p || f0p==f1p || f0p==f1 || f0==f1)
return true;
1100 if(e0Snap && v1Snap) {
1101 assert(v1>=0 && v1<3 && v0==-1 && e1==-1);
1102 if(f0->V2(e0) ==f1->V(v1))
return true;
1103 if(f0p->V2(e0p)==f1->V(v1))
return true;
1106 if(e1Snap && v0Snap) {
1107 assert(v0>=0 && v0<3 && v1==-1 && e0==-1);
1108 if(f1->V2(e1) ==f0->V(v0))
return true;
1109 if(f1p->V2(e1p)==f0->V(v0))
return true;
1112 if(v1Snap && v0Snap) {
1113 PosType startPos(f0,f0->V(v0));
1114 PosType curPos=startPos;
1117 assert(curPos.V()==f0->V(v0));
1118 if(curPos.VFlip()==f1->V(v1))
return true;
1122 while(curPos!=startPos);
1146 splitPt=(v0->P()+v1->P())/2.0;
1148 CoordType ip0,ip1,ipm;
1153 if(f0==f1)
return false;
1159 splitPt = fm->P(0)*ipm[0]+fm->P(1)*ipm[1]+fm->P(2)*ipm[2];
1161 if(!snap0 && !snap1) {
1174 if(f0->FFp(e0) == f1)
return false;
1177 for(
int i=0;i<3;++i)
1178 if(f1->V(i)==f0->V(v0))
return false;
1184 if(f1->FFp(e1) == f0)
return false;
1187 for(
int i=0;i<3;++i)
1188 if(f0->V(i)==f1->V(v1))
return false;
1196 bool TestSplitSegWithMeshAdaptOld(VertexType *v0, VertexType *v1, CoordType &splitPt)
1198 Segment3Type segPoly(v0->P(),v1->P());
1199 const ScalarType sampleNum = 40;
1203 if(f0==f1)
return false;
1208 if(!snap0 && !snap1) {
1210 splitPt=(v0->P()+v1->P())/2.0;
1222 if(f0->FFp(e0) == f1)
return false;
1225 for(
int i=0;i<3;++i)
1226 if(f1->V(i)==f0->V(v0))
return false;
1229 splitPt=(v0->P()+v1->P())/2.0;
1235 ScalarType MaxSegDist(VertexType *v0, VertexType *v1, CoordType &farthestPointOnSurf, CoordType &farthestN, Distribution<ScalarType> *dist=0)
1237 ScalarType maxSurfDist = 0;
1238 const ScalarType sampleNum = 10;
1239 const ScalarType maxDist =
base.bbox.Diag()/10.0;
1240 for(ScalarType k = 1;k<sampleNum;++k)
1242 ScalarType surfDist;
1243 CoordType closestPSurf;
1244 CoordType samplePnt = (v0->P()*k +v1->P()*(sampleNum-k))/sampleNum;
1245 FaceType *f = vcg::tri::GetClosestFaceBase(
base,
uniformGrid,samplePnt,maxDist, surfDist, closestPSurf);
1247 dist->Add(surfDist);
1249 if(surfDist > maxSurfDist)
1251 maxSurfDist = surfDist;
1252 farthestPointOnSurf = closestPSurf;
1274 int startEdgeSize = poly.en;
1275 for(
int i =0; i<startEdgeSize;++i)
1277 EdgeType &ei = poly.edge[i];
1280 CoordType farthestP, farthestN;
1281 ScalarType maxDist = MaxSegDist(ei.V(0),ei.V(1),farthestP, farthestN);
1284 edge::VEEdgeSplit(poly, &ei, farthestP, farthestN);
1300 std::vector<int> edgeToRefineVec;
1301 for(
int i=0; i<poly.en;++i)
1302 edgeToRefineVec.push_back(i);
1303 int startEn=poly.en;
1305 while (!edgeToRefineVec.empty() && iterCnt<100) {
1307 std::vector<int> edgeToRefineVecNext;
1308 for(
int i=0; i<edgeToRefineVec.size();++i)
1310 EdgeType &e = poly.edge[edgeToRefineVec[i]];
1314 edge::VEEdgeSplit(poly, &e, splitPt);
1315 edgeToRefineVecNext.push_back(edgeToRefineVec[i]);
1316 edgeToRefineVecNext.push_back(poly.en-1);
1320 swap(edgeToRefineVecNext,edgeToRefineVec);
1321 printf(
"RefineCurveByBaseMesh %i en -> %i en\n",startEn,poly.en); fflush(stdout);
1326 SimplifyMidEdge(poly);
1328 printf(
"RefineCurveByBaseMesh %i en -> %i en\n",startEn,poly.en); fflush(stdout);
1347 void SmoothProject(MeshType &poly,
int iterNum, ScalarType smoothWeight, ScalarType projectWeight)
1349 tri::RequireCompactness(poly);
1352 assert(poly.en>0 &&
base.fn>0);
1353 for(
int k=0;k<iterNum;++k)
1355 if(k==iterNum-1) projectWeight=1;
1357 std::vector<CoordType> posVec(poly.vn,CoordType(0,0,0));
1358 std::vector<int> cntVec(poly.vn,0);
1360 for(
int i =0; i<poly.en;++i)
1362 for(
int j=0;j<2;++j)
1364 int vertInd = tri::Index(poly,poly.edge[i].V0(j));
1365 posVec[vertInd] += poly.edge[i].V1(j)->P();
1366 cntVec[vertInd] += 1;
1370 const ScalarType maxDist =
base.bbox.Diag()/10.0;
1371 for(
int i=0; i<poly.vn; ++i)
1372 if(!poly.vert[i].IsS())
1374 CoordType smoothPos = (poly.vert[i].P() + posVec[i])/ScalarType(cntVec[i]+1);
1376 CoordType newP = poly.vert[i].P()*(1.0-smoothWeight) + smoothPos *smoothWeight;
1386 FaceType *f = vcg::tri::GetClosestFaceBase(
base,
uniformGrid,newP,maxDist, minDist, closestP);
1388 poly.vert[i].P() = newP*(1.0-projectWeight) +closestP*projectWeight;
1389 poly.vert[i].N() = f->N();
1411 std::map<std::pair<CoordType,CoordType>, VertexPointer> &edgeToPolyVertMap;
1413 EdgePointPred(std::map<std::pair<CoordType,CoordType>, VertexPointer> &_edgeToPolyVertMap):edgeToPolyVertMap(_edgeToPolyVertMap){};
1414 bool operator()(face::Pos<FaceType> ep)
const
1416 CoordType p0 = ep.V()->P();
1417 CoordType p1 = ep.VFlip()->P();
1418 if (p0>p1) std::swap(p0,p1);
1419 return edgeToPolyVertMap.find(std::make_pair(p0,p1)) != edgeToPolyVertMap.end();
1426 std::map<std::pair<CoordType,CoordType>, VertexPointer> &edgeToPolyVertMap;
1428 EdgePointSplit(std::map<std::pair<CoordType,CoordType>, VertexPointer> &_edgeToPolyVertMap):edgeToPolyVertMap(_edgeToPolyVertMap){};
1429 void operator()(VertexType &nv, face::Pos<FaceType> ep)
1431 CoordType p0 = ep.V()->P();
1432 CoordType p1 = ep.VFlip()->P();
1433 if (p0>p1) std::swap(p0,p1);
1434 VertexPointer vp=edgeToPolyVertMap[std::make_pair(p0,p1)];
1442 cc.lerp(c0,c1,0.5f);
1443 return Color4b::Red;
1445 TexCoord2f WedgeInterp(TexCoord2f &t0, TexCoord2f &t1)
1448 assert(t0.n()== t1.n());
1450 tmp.t()=(t0.t()+t1.t())/2.0;
Class to safely add and delete elements in a mesh.
Definition: allocate.h:97
static VertexIterator AddVertices(MeshType &m, size_t n, PointerUpdater< VertexPointer > &pu)
Add n vertices to the mesh. Function to add n vertices to the mesh. The elements are added always to ...
Definition: allocate.h:189
static FaceIterator AddFaces(MeshType &m, size_t n)
Function to add n faces to the mesh. First wrapper, with no parameters.
Definition: allocate.h:615
static int RemoveDuplicateVertex(MeshType &m, bool RemoveDegenerateFlag=true)
Definition: clean.h:206
Definition: curve_on_manifold.h:1409
Parameter class controlling the behavior of CoM algorithms.
Definition: curve_on_manifold.h:116
ScalarType surfDistThr
Max distance between surface and curve; used in simplify and refine.
Definition: curve_on_manifold.h:119
ScalarType barycentricSnapThr
Threshold for snapping barycentric coords to 0 or 1 (controls vertex/edge snapping)
Definition: curve_on_manifold.h:125
ScalarType gridBailout
The maximum distance bailout used in grid-based spatial queries.
Definition: curve_on_manifold.h:124
ScalarType maxSimpEdgeLen
Maximal admitted edge length (used in simplify: never make edges longer than this)
Definition: curve_on_manifold.h:121
void SetDefault(MeshType &m)
Set all parameters to reasonable defaults based on the mesh bounding box.
Definition: curve_on_manifold.h:131
ScalarType minRefEdgeLen
Minimal admitted edge length (used in refine: never make edges shorter than this)
Definition: curve_on_manifold.h:120
ScalarType maxSnapThr
The maximum distance allowed when snapping a polyline vertex onto a mesh vertex (currently unused)
Definition: curve_on_manifold.h:123
void Dump() const
Print current parameter values to stdout.
Definition: curve_on_manifold.h:143
ScalarType maxSmoothDelta
The maximum movement admitted during smoothing (currently unused)
Definition: curve_on_manifold.h:122
Param(MeshType &m)
Constructor with default parameter initialization based on mesh size.
Definition: curve_on_manifold.h:128
A class for managing curves on a 2-manifold (Curve on Manifold - CoM).
Definition: curve_on_manifold.h:89
ScalarType MinDistOnEdge(CoordType samplePnt, EdgeGrid &edgeGrid, MeshType &poly, CoordType &closestPoint)
Find the minimum distance from a sample point to the polyline.
Definition: curve_on_manifold.h:370
MeshType & base
Reference to the base triangulated surface mesh.
Definition: curve_on_manifold.h:158
void SimplifyNullEdges(MeshType &poly)
Remove duplicate/zero-length edges from a polyline.
Definition: curve_on_manifold.h:741
VertexPointer FindVertexSnap(FacePointer fp, CoordType &ip)
Find the vertex pointer for a vertex-snapped barycentric coordinate.
Definition: curve_on_manifold.h:288
FaceType * GetClosestFace(const CoordType &p)
Get the closest face to a query point.
Definition: curve_on_manifold.h:174
MeshGrid uniformGrid
Spatial acceleration structure for closest point queries.
Definition: curve_on_manifold.h:159
FaceType * GetClosestFaceIP(const CoordType &p, CoordType &ip)
Get the closest face and its barycentric coordinates.
Definition: curve_on_manifold.h:187
void RefineCurveByBaseMesh(MeshType &poly)
RefineCurveByBaseMesh.
Definition: curve_on_manifold.h:1297
Param par
Parameters controlling algorithm behavior.
Definition: curve_on_manifold.h:160
bool TagFaceEdgeSelWithPolyLine(MeshType &poly, bool markFlag=true)
Tag face edges of the base mesh that coincide with polyline edges.
Definition: curve_on_manifold.h:318
void SimplifyMidFace(MeshType &poly)
SimplifyMidFace remove all the vertices that in the mid of a face and between two of the points snapp...
Definition: curve_on_manifold.h:795
CoM(MeshType &_m)
Constructor: initializes the CoM with a base mesh.
Definition: curve_on_manifold.h:163
FaceType * GetClosestFacePoint(const CoordType &p, CoordType &closestP)
Get the closest face and the closest point on it.
Definition: curve_on_manifold.h:214
bool SnapPolyline(MeshType &poly)
SnapPolyline snaps the vertexes of a polyline onto the base mesh.
Definition: curve_on_manifold.h:495
static CoordType QLerp(VertexType *v0, VertexType *v1)
Compute quality-weighted linear interpolation between two vertices.
Definition: curve_on_manifold.h:473
bool IsWellSnapped(const CoordType &ip)
Test if a barycentric coordinate is well snapped.
Definition: curve_on_manifold.h:235
bool SnappedOnSameFace(FacePointer f0, CoordType i0, FacePointer f1, CoordType i1)
SnappedOnSameFace Return true if the two points are snapped to a common face;.
Definition: curve_on_manifold.h:1076
bool TestSplitSegWithMeshAdapt(VertexType *v0, VertexType *v1, CoordType &splitPt)
TestSplitSegWithMesh Given a poly segment decide if it should be split along elements of base mesh.
Definition: curve_on_manifold.h:1144
FaceType * GetClosestFaceIP(const CoordType &p, CoordType &ip, CoordType &in)
Get the closest face, barycentric coordinates, and normal.
Definition: curve_on_manifold.h:201
void RefineCurveByDistance(MeshType &poly)
RefineCurve.
Definition: curve_on_manifold.h:1271
bool BarycentricSnap(CoordType &ip)
Snap barycentric coordinates to 0 or 1 if within threshold.
Definition: curve_on_manifold.h:948
void Init()
Initialize the CoM data structures for processing.
Definition: curve_on_manifold.h:723
void SmoothProject(MeshType &poly, int iterNum, ScalarType smoothWeight, ScalarType projectWeight)
SmoothProject.
Definition: curve_on_manifold.h:1347
bool TestSplitSegWithMesh(VertexType *v0, VertexType *v1, CoordType &splitPt)
TestSplitSegWithMesh Given a poly segment decide if it should be split along elements of base mesh.
Definition: curve_on_manifold.h:993
static bool CompareVertex(const MeshType &m, const VertexType &vA, const VertexType &vB)
Compare two vertices for seam compatibility.
Definition: curve_on_manifold.h:451
static void ExtractVertex(const MeshType &srcMesh, const FaceType &f, int whichWedge, const MeshType &dstMesh, VertexType &v)
Extract vertex attributes for seam processing.
Definition: curve_on_manifold.h:428
bool IsSnappedVertex(CoordType &ip, int &vi)
Check if a barycentric coordinate is snapped to a vertex.
Definition: curve_on_manifold.h:271
static ScalarType MinDistOnEdge(VertexType *v0, VertexType *v1, EdgeGrid &edgeGrid, MeshType &poly, CoordType &closestPoint)
Find the closest point on a mesh edge to the polyline (static version)
Definition: curve_on_manifold.h:388
bool IsSnappedEdge(CoordType &ip, int &ei)
Check if a barycentric coordinate is snapped to an edge.
Definition: curve_on_manifold.h:254
void SplitMeshWithPolyline(MeshType &poly)
Split the base mesh to make it conforming with the polyline.
Definition: curve_on_manifold.h:644
static int PerVertexConstant(MeshType &m, Color4b vs=Color4b::White, bool selected=false)
This function colors all (or the selected) the vertices of a mesh.
Definition: color.h:83
static void PerVertexQualityRamp(MeshType &m, ScalarType minq=0., ScalarType maxq=0., vcg::ColorMap cmap=vcg::ColorMap::RGB)
This function colores all the faces of a mesh with a hue color shade dependent on the quality.
Definition: color.h:222
Management, updating and computation of per-vertex and per-face flags (like border flags).
Definition: flag.h:44
static void PerFaceNormalized(ComputeMeshType &m)
Equivalent to PerFace() and NormalizePerFace()
Definition: normal.h:276
static void VertexConstant(MeshType &m, VertexQualityType q)
Definition: quality.h:67
static size_t VertexClear(MeshType &m)
This function clear the selection flag for all the vertices.
Definition: selection.h:237
Auxiliary data structure for computing face face adjacency information.
Definition: topology.h:149
Generation of per-vertex and per-face topological information.
Definition: topology.h:43
static void VertexFace(MeshType &m)
Update the Vertex-Face topological relation.
Definition: topology.h:467
static void FaceFace(MeshType &m)
Update the Face-Face topological relation by allowing to retrieve for each face what other faces shar...
Definition: topology.h:395
static void TestVertexEdge(MeshType &m)
Test correctness of VEtopology.
Definition: topology.h:584
void ForEachVertex(const MeshType &m, Callable action)
Definition: foreach.h:126
void TriSplit(FaceType *fToSplit, FaceType *newf0, FaceType *newf1, typename FaceType::VertexType *newVert)
Definition: topology.h:842
Definition: curve_on_manifold.h:1424