Refactored curve on manifold
This commit is contained in:
parent
42f25c825b
commit
e0b7a64b04
|
|
@ -26,6 +26,7 @@
|
||||||
#include<wrap/io_trimesh/export.h>
|
#include<wrap/io_trimesh/export.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include<vcg/complex/algorithms/cut_tree.h>
|
||||||
#include<vcg/complex/algorithms/curve_on_manifold.h>
|
#include<vcg/complex/algorithms/curve_on_manifold.h>
|
||||||
#include<vcg/complex/algorithms/crease_cut.h>
|
#include<vcg/complex/algorithms/crease_cut.h>
|
||||||
|
|
||||||
|
|
@ -46,45 +47,60 @@ int main(int argc,char ** argv )
|
||||||
{
|
{
|
||||||
MyMesh base, basecopy, poly;
|
MyMesh base, basecopy, poly;
|
||||||
int ret0 = tri::io::Importer<MyMesh>::Open(base,argv[1]);
|
int ret0 = tri::io::Importer<MyMesh>::Open(base,argv[1]);
|
||||||
tri::UpdateBounding<MyMesh>::Box(base);
|
|
||||||
tri::Append<MyMesh,MyMesh>::MeshCopy(basecopy,base);
|
|
||||||
printf( "Mesh %s has %i vert and %i faces\n", argv[1], basecopy.VN(), basecopy.FN() );
|
|
||||||
if(ret0 != 0 )
|
if(ret0 != 0 )
|
||||||
{
|
{
|
||||||
printf("Failed Loading\n");
|
printf("Failed Loading\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tri::UpdateBounding<MyMesh>::Box(base);
|
||||||
|
printf( "Mesh %s has %i vert and %i faces\n", argv[1], base.VN(), base.FN() );
|
||||||
|
srand(time(0));
|
||||||
|
tri::CutTree<MyMesh> ct(base);
|
||||||
|
ct.BuildVisitTree(poly,rand()%base.fn);
|
||||||
|
tri::io::ExporterPLY<MyMesh>::Save(poly,"tree.ply",tri::io::Mask::IOM_EDGEINDEX);
|
||||||
|
|
||||||
tri::CoM<MyMesh> cc(base);
|
tri::CoM<MyMesh> cc(base);
|
||||||
cc.Init();
|
cc.Init();
|
||||||
cc.BuildVisitTree(poly);
|
cc.MarkFauxEdgeWithPolyLine(poly);
|
||||||
tri::UpdateBounding<MyMesh>::Box(poly);
|
tri::Append<MyMesh,MyMesh>::MeshCopy(basecopy,base);
|
||||||
tri::io::ExporterPLY<MyMesh>::Save(poly,"tree.ply",tri::io::Mask::IOM_EDGEINDEX);
|
|
||||||
while(cc.OptimizeTree(poly));
|
|
||||||
tri::io::ExporterPLY<MyMesh>::Save(poly,"tree1.ply",tri::io::Mask::IOM_EDGEINDEX);
|
|
||||||
|
|
||||||
cc.MarkFauxEdgeWithPolyLine(basecopy,poly);
|
|
||||||
tri::UpdateTopology<MyMesh>::FaceFace(basecopy);
|
tri::UpdateTopology<MyMesh>::FaceFace(basecopy);
|
||||||
tri::CutMeshAlongNonFauxEdges<MyMesh>(basecopy);
|
tri::CutMeshAlongNonFauxEdges<MyMesh>(basecopy);
|
||||||
tri::io::ExporterPLY<MyMesh>::Save(basecopy,"basecut.ply");
|
tri::io::ExporterPLY<MyMesh>::Save(basecopy,"base_cut_with_tree.ply");
|
||||||
|
|
||||||
|
|
||||||
cc.par.surfDistThr = base.bbox.Diag()/100.0;
|
cc.par.surfDistThr = base.bbox.Diag()/100.0;
|
||||||
cc.par.maxSimpEdgeLen = base.bbox.Diag()/60.0;
|
cc.par.maxSimpEdgeLen = base.bbox.Diag()/40.0;
|
||||||
cc.SmoothProject(poly,5,0.8, 0.2);
|
cc.par.minRefEdgeLen = base.bbox.Diag()/80.0;
|
||||||
|
cc.SmoothProject(poly,40,0.5, .7);
|
||||||
|
|
||||||
Distribution<float> dist;
|
Distribution<float> dist;
|
||||||
cc.EvaluateHausdorffDistance(poly, dist );
|
cc.EvaluateHausdorffDistance(poly, dist );
|
||||||
tri::io::ExporterPLY<MyMesh>::Save(poly,"poly_adapted.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
|
||||||
cc.par.surfDistThr = base.bbox.Diag()/1000.0;
|
// tri::io::ExporterPLY<MyMesh>::Save(poly,"poly_adapted.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
||||||
cc.par.maxSimpEdgeLen = base.bbox.Diag()/500.0;
|
// cc.par.surfDistThr = base.bbox.Diag()/2000.0;
|
||||||
cc.SmoothProject(poly,5,0.3, 0.7);
|
// cc.par.maxSimpEdgeLen = base.bbox.Diag()/100.0;
|
||||||
|
// cc.par.minRefEdgeLen = base.bbox.Diag()/200.0;
|
||||||
|
// cc.SmoothProject(poly,10,0.3, 0.7);
|
||||||
|
// cc.SmoothProject(poly,1,0.01, 0.99);
|
||||||
tri::io::ExporterPLY<MyMesh>::Save(poly,"poly_adapted2.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
tri::io::ExporterPLY<MyMesh>::Save(poly,"poly_adapted2.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
||||||
cc.par.minRefEdgeLen = base.bbox.Diag()/200.0;
|
std::vector<MyVertex*> newVertVec;
|
||||||
cc.Refine(poly,true);
|
|
||||||
cc.Refine(poly,true);
|
|
||||||
cc.SnapPolyline(poly);
|
cc.SnapPolyline(poly);
|
||||||
tri::io::ExporterPLY<MyMesh>::Save(poly,"poly_adapted2_snap.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
tri::io::ExporterPLY<MyMesh>::Save(poly,"poly_snap.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
||||||
cc.par.maxSimpEdgeLen = base.bbox.Diag()/200.0;
|
cc.RefineCurveByBaseMesh(poly);
|
||||||
cc.SmoothProject(poly,10 ,0.8, 0.2);
|
tri::io::ExporterPLY<MyMesh>::Save(poly,"poly_refined.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
||||||
cc.RefineBaseMesh(poly);
|
|
||||||
tri::io::ExporterPLY<MyMesh>::Save(poly,"poly_adapted2_snapSmooth.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
cc.SplitMeshWithPolyline(poly);
|
||||||
|
cc.RefineCurveByBaseMesh(poly);
|
||||||
|
tri::io::ExporterPLY<MyMesh>::Save(base,"base_refined.ply",tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
||||||
|
cc.SplitMeshWithPolyline(poly);
|
||||||
|
cc.RefineCurveByBaseMesh(poly);
|
||||||
|
cc.SplitMeshWithPolyline(poly);
|
||||||
|
cc.RefineCurveByBaseMesh(poly);
|
||||||
|
tri::io::ExporterPLY<MyMesh>::Save(base,"base_refined2.ply",tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY+tri::io::Mask::IOM_FACEFLAGS);
|
||||||
|
cc.MarkFauxEdgeWithPolyLine(poly);
|
||||||
|
CutMeshAlongNonFauxEdges(base);
|
||||||
|
tri::io::ExporterPLY<MyMesh>::Save(base,"base_refined2_cut.ply",tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,238 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* VCGLib o o *
|
||||||
|
* Visual and Computer Graphics Library o o *
|
||||||
|
* _ O _ *
|
||||||
|
* Copyright(C) 2004-2016 \/)\/ *
|
||||||
|
* Visual Computing Lab /\/| *
|
||||||
|
* ISTI - Italian National Research Council | *
|
||||||
|
* \ *
|
||||||
|
* All rights reserved. *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||||
|
* for more details. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef CUT_TREE_H
|
||||||
|
#define CUT_TREE_H
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
namespace tri {
|
||||||
|
|
||||||
|
template <class MeshType>
|
||||||
|
class CutTree
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename MeshType::ScalarType ScalarType;
|
||||||
|
typedef typename MeshType::CoordType CoordType;
|
||||||
|
typedef typename MeshType::VertexType VertexType;
|
||||||
|
typedef typename MeshType::VertexPointer VertexPointer;
|
||||||
|
typedef typename MeshType::VertexIterator VertexIterator;
|
||||||
|
typedef typename MeshType::EdgeIterator EdgeIterator;
|
||||||
|
typedef typename MeshType::EdgeType EdgeType;
|
||||||
|
typedef typename MeshType::FaceType FaceType;
|
||||||
|
typedef typename MeshType::FacePointer FacePointer;
|
||||||
|
typedef typename MeshType::FaceIterator FaceIterator;
|
||||||
|
typedef Box3 <ScalarType> Box3Type;
|
||||||
|
typedef typename vcg::GridStaticPtr<FaceType, ScalarType> MeshGrid;
|
||||||
|
typedef typename vcg::GridStaticPtr<EdgeType, ScalarType> EdgeGrid;
|
||||||
|
typedef typename face::Pos<FaceType> PosType;
|
||||||
|
typedef typename tri::UpdateTopology<MeshType>::PEdge PEdge;
|
||||||
|
|
||||||
|
MeshType &base;
|
||||||
|
// MeshGrid uniformGrid;
|
||||||
|
|
||||||
|
// Param par;
|
||||||
|
CutTree(MeshType &_m) :base(_m){}
|
||||||
|
|
||||||
|
|
||||||
|
void OptimizeTree(MeshType &t)
|
||||||
|
{
|
||||||
|
tri::Allocator<MeshType>::CompactEveryVector(t);
|
||||||
|
int lastEn=t.en;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
lastEn=t.en;
|
||||||
|
tri::UpdateTopology<MeshType>::VertexEdge(t);
|
||||||
|
tri::UpdateTopology<MeshType>::VertexFace(base);
|
||||||
|
VertexConstDataWrapper<MeshType > vdw(base);
|
||||||
|
KdTree<ScalarType> kdtree(vdw);
|
||||||
|
|
||||||
|
// First simple loop that search for 2->1 moves.
|
||||||
|
for(VertexIterator vi=t.vert.begin();vi!=t.vert.end();++vi)
|
||||||
|
{
|
||||||
|
std::vector<VertexType *> starVec;
|
||||||
|
edge::VVStarVE(&*vi,starVec);
|
||||||
|
if(starVec.size()==2)
|
||||||
|
{
|
||||||
|
PosType pos;
|
||||||
|
if(ExistEdge(kdtree,starVec[0]->P(),starVec[1]->P(),pos))
|
||||||
|
edge::VEEdgeCollapse(t,&*vi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tri::Allocator<MeshType>::CompactEveryVector(t);
|
||||||
|
}
|
||||||
|
while(t.en<lastEn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given two points return true if on the base mesh there exist an edge with that two coords
|
||||||
|
// if return true the pos indicate the found edge.
|
||||||
|
bool ExistEdge(KdTree<ScalarType> &kdtree, CoordType &p0, CoordType &p1, PosType &fpos)
|
||||||
|
{
|
||||||
|
ScalarType locEps = SquaredDistance(p0,p1)/100000.0;
|
||||||
|
|
||||||
|
VertexType *v0=0,*v1=0;
|
||||||
|
unsigned int veInd;
|
||||||
|
ScalarType sqdist;
|
||||||
|
kdtree.doQueryClosest(p0,veInd,sqdist);
|
||||||
|
if(sqdist<locEps)
|
||||||
|
v0 = &base.vert[veInd];
|
||||||
|
kdtree.doQueryClosest(p1,veInd,sqdist);
|
||||||
|
if(sqdist<locEps)
|
||||||
|
v1 = &base.vert[veInd];
|
||||||
|
if(v0 && v1)
|
||||||
|
{
|
||||||
|
face::VFIterator<FaceType> vfi(v0);
|
||||||
|
while(!vfi.End())
|
||||||
|
{
|
||||||
|
if(vfi.V1()==v1)
|
||||||
|
{
|
||||||
|
fpos = PosType(vfi.F(),vfi.I(), v0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(vfi.V2()==v1)
|
||||||
|
{
|
||||||
|
fpos = PosType(vfi.F(),(vfi.I()+1)%3, v1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
++vfi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int findNonVisitedEdgesDuringRetract(VertexType * vp, EdgeType * &ep)
|
||||||
|
{
|
||||||
|
std::vector<EdgeType *> starVec;
|
||||||
|
edge::VEStarVE(&*vp,starVec);
|
||||||
|
int cnt =0;
|
||||||
|
for(size_t i=0;i<starVec.size();++i) {
|
||||||
|
if(!starVec[i]->IsV()) {
|
||||||
|
cnt++;
|
||||||
|
ep = starVec[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Retract(MeshType &t)
|
||||||
|
{
|
||||||
|
printf("Retracting a tree of %i edges and %i vertices\n",t.en,t.vn);
|
||||||
|
tri::UpdateTopology<MeshType>::VertexEdge(t);
|
||||||
|
|
||||||
|
std::stack<VertexType *> vertStack;
|
||||||
|
|
||||||
|
// Put on the stack all the vertex with just a single incident edge.
|
||||||
|
for(VertexIterator vi=t.vert.begin();vi!=t.vert.end();++vi)
|
||||||
|
{
|
||||||
|
std::vector<EdgeType *> starVec;
|
||||||
|
edge::VEStarVE(&*vi,starVec);
|
||||||
|
if(starVec.size()==1)
|
||||||
|
vertStack.push(&*vi);
|
||||||
|
}
|
||||||
|
|
||||||
|
tri::UpdateFlags<MeshType>::EdgeClearV(t);
|
||||||
|
tri::UpdateFlags<MeshType>::VertexClearV(t);
|
||||||
|
|
||||||
|
int unvisitedEdgeNum = t.en;
|
||||||
|
while((!vertStack.empty()) && (unvisitedEdgeNum > 2) )
|
||||||
|
{
|
||||||
|
VertexType *vp = vertStack.top();
|
||||||
|
vertStack.pop();
|
||||||
|
vp->C()=Color4b::Blue;
|
||||||
|
EdgeType *ep=0;
|
||||||
|
int eCnt = findNonVisitedEdgesDuringRetract(vp,ep);
|
||||||
|
if(eCnt==1) // We have only one non visited edge over vp
|
||||||
|
{
|
||||||
|
assert(!ep->IsV());
|
||||||
|
ep->SetV();
|
||||||
|
--unvisitedEdgeNum;
|
||||||
|
VertexType *otherVertP;
|
||||||
|
if(ep->V(0)==vp) otherVertP = ep->V(1);
|
||||||
|
else otherVertP = ep->V(0);
|
||||||
|
vertStack.push(otherVertP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(unvisitedEdgeNum >0);
|
||||||
|
|
||||||
|
for(size_t i =0; i<t.edge.size();++i)
|
||||||
|
if(t.edge[i].IsV()) tri::Allocator<MeshType>::DeleteEdge(t,t.edge[i]);
|
||||||
|
assert(t.en >0);
|
||||||
|
tri::Clean<MeshType>::RemoveUnreferencedVertex(t);
|
||||||
|
tri::Allocator<MeshType>::CompactEveryVector(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// \brief This function build a cut tree.
|
||||||
|
//
|
||||||
|
// First we make a bread first FF face visit.
|
||||||
|
// Each time that we encounter a visited face we cut add to the tree the edge
|
||||||
|
// that brings to the already visited face.
|
||||||
|
// this structure build a dense graph and we retract this graph retracting each
|
||||||
|
// leaf until we remains with just the loops that cuts the object.
|
||||||
|
|
||||||
|
void BuildVisitTree(MeshType &dualMesh, int startingFaceInd=0)
|
||||||
|
{
|
||||||
|
tri::UpdateTopology<MeshType>::FaceFace(base);
|
||||||
|
tri::UpdateFlags<MeshType>::FaceClearV(base);
|
||||||
|
std::vector<face::Pos<FaceType> > visitStack; // the stack contain the pos on the 'starting' face.
|
||||||
|
|
||||||
|
base.face[startingFaceInd].SetV();
|
||||||
|
for(int i=0;i<3;++i)
|
||||||
|
visitStack.push_back(PosType(&(base.face[startingFaceInd]),i,base.face[startingFaceInd].V(i)));
|
||||||
|
|
||||||
|
int cnt=1;
|
||||||
|
|
||||||
|
while(!visitStack.empty())
|
||||||
|
{
|
||||||
|
std::swap(visitStack.back(),visitStack[rand()%visitStack.size()]);
|
||||||
|
PosType c = visitStack.back();
|
||||||
|
visitStack.pop_back();
|
||||||
|
assert(c.F()->IsV());
|
||||||
|
c.F()->C() = Color4b::ColorRamp(0,base.fn,cnt);
|
||||||
|
c.FlipF();
|
||||||
|
if(!c.F()->IsV())
|
||||||
|
{
|
||||||
|
++cnt;
|
||||||
|
c.F()->SetV();
|
||||||
|
c.FlipE();c.FlipV();
|
||||||
|
visitStack.push_back(c);
|
||||||
|
c.FlipE();c.FlipV();
|
||||||
|
visitStack.push_back(c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tri::Allocator<MeshType>::AddEdge(dualMesh,c.V()->P(),c.VFlip()->P());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(cnt==base.fn);
|
||||||
|
|
||||||
|
tri::Clean<MeshType>::RemoveDuplicateVertex(dualMesh);
|
||||||
|
Retract(dualMesh);
|
||||||
|
OptimizeTree(dualMesh);
|
||||||
|
tri::UpdateBounding<MeshType>::Box(dualMesh);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
} // end namespace tri
|
||||||
|
} // end namespace vcg
|
||||||
|
|
||||||
|
#endif // CUT_TREE_H
|
||||||
Loading…
Reference in New Issue