/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2004-2012 \/)\/ * * 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. * * * ****************************************************************************/ #include #include #include #include #include #include using namespace vcg; class MyEdge; class MyFace; class MyVertex; struct MyUsedTypes : public UsedTypes::AsVertexType, Use::AsEdgeType, Use::AsFaceType>{}; class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Qualityf, vertex::Color4b, vertex::VEAdj, vertex::VFAdj,vertex::BitFlags >{}; class MyEdge : public Edge< MyUsedTypes, edge::VertexRef, edge::VEAdj, edge::EEAdj, edge::BitFlags> {}; class MyFace : public Face < MyUsedTypes, face::VertexRef, face::Normal3f, face::VFAdj, face::FFAdj, face::Mark, face::Color4b, face::BitFlags > {}; class MyMesh : public tri::TriMesh< std::vector, std::vector, std::vector >{}; int main(int argc,char ** argv ) { MyMesh base, basecopy, poly; int ret0 = tri::io::Importer::Open(base,argv[1]); if(ret0 != 0 ) { printf("Failed Loading\n"); exit(-1); } tri::UpdateBounding::Box(base); printf( "Mesh %s has %i vert and %i faces\n", argv[1], base.VN(), base.FN() ); srand(time(0)); tri::CutTree ct(base); ct.BuildVisitTree(poly,rand()%base.fn); tri::io::ExporterPLY::Save(poly,"tree.ply",tri::io::Mask::IOM_EDGEINDEX); tri::CoM cc(base); cc.Init(); cc.MarkFauxEdgeWithPolyLine(poly); tri::Append::MeshCopy(basecopy,base); tri::UpdateTopology::FaceFace(basecopy); tri::CutMeshAlongNonFauxEdges(basecopy); tri::io::ExporterPLY::Save(basecopy,"base_cut_with_tree.ply"); cc.par.surfDistThr = base.bbox.Diag()/100.0; cc.par.maxSimpEdgeLen = base.bbox.Diag()/40.0; cc.par.minRefEdgeLen = base.bbox.Diag()/80.0; cc.SmoothProject(poly,40,0.5, .7); Distribution dist; cc.EvaluateHausdorffDistance(poly, dist ); // tri::io::ExporterPLY::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()/2000.0; // 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::Save(poly,"poly_adapted2.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY); std::vector newVertVec; cc.SnapPolyline(poly); tri::io::ExporterPLY::Save(poly,"poly_snap.ply",tri::io::Mask::IOM_EDGEINDEX+tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY); cc.RefineCurveByBaseMesh(poly); tri::io::ExporterPLY::Save(poly,"poly_refined.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::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::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::Save(base,"base_refined2_cut.ply",tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY); return 0; }