From 604bc3903ff6f24e14f5c9a530fb8256eb90b6d0 Mon Sep 17 00:00:00 2001 From: cignoni Date: Mon, 25 Nov 2013 13:12:09 +0000 Subject: [PATCH] --- .../trimesh_optional/trimesh_optional.cpp | 150 +++++++++--------- 1 file changed, 78 insertions(+), 72 deletions(-) diff --git a/apps/sample/trimesh_optional/trimesh_optional.cpp b/apps/sample/trimesh_optional/trimesh_optional.cpp index b62e9066..2a2353a3 100644 --- a/apps/sample/trimesh_optional/trimesh_optional.cpp +++ b/apps/sample/trimesh_optional/trimesh_optional.cpp @@ -21,6 +21,16 @@ * * ****************************************************************************/ +/*! \file trimesh_optional.cpp +\ingroup code_sample + +\brief the minimal example of using the \ref optional_component "Optional Components". + +This file shows how to dynamically allocate component that you do not need most of the time. + +*/ + + #include #include @@ -29,33 +39,49 @@ #include #include #include -#include #include #include -#include -class CFace; -class CFaceOcf; -class CVertex; -class CVertexOcf; +class MyFace; +class MyVertex; -struct MyUsedTypes: public vcg::UsedTypes::AsVertexType,vcg::Use::AsFaceType>{}; -struct MyUsedTypesOcf: public vcg::UsedTypes::AsVertexType,vcg::Use::AsFaceType>{}; +struct MyUsedTypes: public vcg::UsedTypes< + vcg::Use::AsVertexType, + vcg::Use::AsFaceType>{}; -// Optional stuff has two suffixes: -// OCF Optional Component Fast -// OCC Optional Component Compact +class MyVertex : public vcg::Vertex< MyUsedTypes, + vcg::vertex::Coord3f, vcg::vertex::Qualityf, + vcg::vertex::Color4b, vcg::vertex::BitFlags, + vcg::vertex::Normal3f, vcg::vertex::VFAdj >{}; -class CVertex : public vcg::Vertex< MyUsedTypes, - vcg::vertex::Coord3f, vcg::vertex::BitFlags,vcg::vertex::Normal3f >{}; -class CVertexOcf : public vcg::Vertex< MyUsedTypesOcf, - vcg::vertex::InfoOcf, vcg::vertex::Coord3f, vcg::vertex::QualityfOcf,vcg::vertex::Color4b, - vcg::vertex::BitFlags, vcg::vertex::Normal3f,vcg::vertex::RadiusfOcf, vcg::vertex::CurvatureDirfOcf, vcg::vertex::CurvaturefOcf >{}; -class CFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::BitFlags, vcg::face::Normal3f > {}; -class CFaceOcf : public vcg::Face< MyUsedTypesOcf, vcg::face::InfoOcf, vcg::face::FFAdjOcf, vcg::face::VertexRef, vcg::face::BitFlags, vcg::face::Normal3fOcf > {}; +class MyFace : public vcg::Face< MyUsedTypes, + vcg::face::FFAdj, vcg::face::VFAdj, + vcg::face::Color4b, vcg::face::VertexRef, + vcg::face::BitFlags, vcg::face::Normal3f > {}; +class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector > {}; -class CMesh : public vcg::tri::TriMesh< std::vector, std::vector > {}; -class CMeshOcf : public vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf > {}; + +class MyVertexOcf; +class MyFaceOcf; + +struct MyUsedTypesOcf: public vcg::UsedTypes< + vcg::Use::AsVertexType, + vcg::Use::AsFaceType>{}; + +class MyVertexOcf : public vcg::Vertex< MyUsedTypesOcf, + vcg::vertex::InfoOcf, // <--- Note the use of the 'special' InfoOcf component + vcg::vertex::Coord3f, vcg::vertex::QualityfOcf, + vcg::vertex::Color4b, vcg::vertex::BitFlags, + vcg::vertex::Normal3f, vcg::vertex::VFAdjOcf >{}; + +class MyFaceOcf : public vcg::Face< MyUsedTypesOcf, + vcg::face::InfoOcf, // <--- Note the use of the 'special' InfoOcf component + vcg::face::FFAdjOcf, vcg::face::VFAdjOcf, + vcg::face::Color4bOcf, vcg::face::VertexRef, + vcg::face::BitFlags, vcg::face::Normal3fOcf > {}; + +// the mesh class must make use of the 'vector_ocf' containers instead of the classical std::vector +class MyMeshOcf : public vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf > {}; using namespace vcg; @@ -63,79 +89,59 @@ using namespace std; int main(int , char **) { - CMesh cm; - CMeshOcf cmof; - + MyMesh cm; + MyMeshOcf cmof; + tri::Tetrahedron(cm); tri::Tetrahedron(cmof); - + printf("Generated mesh has %i vertices and %i triangular faces\n",cm.VN(),cm.FN()); - + assert(tri::HasFFAdjacency(cmof) == false); cmof.face.EnableFFAdjacency(); assert(tri::HasFFAdjacency(cmof) == true); - tri::UpdateTopology::FaceFace(cm); - tri::UpdateTopology::FaceFace(cmof); + assert(tri::HasVFAdjacency(cmof) == false); + cmof.vert.EnableVFAdjacency(); + cmof.face.EnableVFAdjacency(); + assert(tri::HasVFAdjacency(cmof) == true); - tri::UpdateFlags::FaceBorderFromFF(cm); - tri::UpdateFlags::FaceBorderFromFF(cmof); + tri::UpdateTopology::FaceFace(cm); + tri::UpdateTopology::FaceFace(cmof); - tri::UpdateNormal::PerVertexPerFace(cm); - cmof.face.EnableNormal(); // if you remove this the next line will throw an exception for a missing 'normal' component - tri::UpdateNormal::PerVertexPerFace(cmof); + tri::UpdateFlags::FaceBorderFromFF(cm); + tri::UpdateFlags::FaceBorderFromFF(cmof); + + tri::UpdateNormal::PerVertexPerFace(cm); + cmof.face.EnableNormal(); // remove this line and you will throw an exception for a missing 'normal' component + tri::UpdateNormal::PerVertexPerFace(cmof); - cmof.vert.EnableCurvature(); - cmof.vert.EnableCurvatureDir(); cmof.vert.EnableQuality(); - tri::UpdateColor::PerVertexConstant(cmof,Color4b::LightGray); + tri::UpdateColor::PerVertexConstant(cmof,Color4b::LightGray); + printf("cmof IsColorEnabled() %s\n",cmof.face.back().IsColorEnabled()?"Yes":"No"); + cmof.face.EnableColor(); + tri::UpdateColor::PerFaceConstant(cmof,Color4b::LightGray); cmof.vert[0].C()=Color4b::Red; + printf("cmof IsColorEnabled() %s\n",cmof.face.back().IsColorEnabled()?"Yes":"No"); + printf("cm IsColorEnabled() %s\n",cm.face.back().IsColorEnabled()?"Yes":"No"); + printf("cm IsColorEnabled() %s\n",cm.face.back().HasColor()?"Yes":"No"); + printf("Normal of face 0 is %f %f %f\n\n",cm.face[0].N()[0],cm.face[0].N()[1],cm.face[0].N()[2]); int t0=0,t1=0,t2=0; - while(float(t1-t0)/CLOCKS_PER_SEC < 0.0025) + while(float(t1-t0)/CLOCKS_PER_SEC < 0.1f) { t0=clock(); -// tri::Refine(cm,tri::MidPointButterfly(cm),0); -// tri::UpdateCurvature::MeanAndGaussian(cmof); -// tri::UpdateQuality::VertexFromGaussianCurvature(cmof); - - tri::RefineOddEven (cm, tri::OddPointLoop(cm), tri::EvenPointLoop(), 0); - tri::Refine(cmof,tri::MidPoint(&cmof),0); + tri::RefineOddEven (cm, tri::OddPointLoop(cm), tri::EvenPointLoop(), 0); t1=clock(); - tri::RefineOddEven (cm, tri::OddPointLoop(cm), tri::EvenPointLoop(), 0); + tri::RefineOddEven (cmof, tri::OddPointLoop(cmof), tri::EvenPointLoop(), 0); t2=clock(); } - printf("Last Iteration: Refined a tetra up to a mesh of %i faces in %5.2f %5.2f sec\n",cm.FN(),float(t1-t0)/CLOCKS_PER_SEC,float(t2-t1)/CLOCKS_PER_SEC); - tri::io::ExporterOFF::Save(cmof,"test.off",tri::io::Mask::IOM_VERTCOLOR); - unsigned int hh = 0; - for(CMeshOcf::VertexIterator vi = cmof.vert.begin(); vi!=cmof.vert.end();++vi,++hh){ - if(hh%3==0) - vcg::tri::Allocator::DeleteVertex(cmof,*vi); - } - - cmof.vert.EnableRadius(); -// return 0; - for(CMeshOcf::VertexIterator vi = cmof.vert.begin(); vi!=cmof.vert.end();++vi) - if(!(*vi).IsD()) - { - vi->Q() = tri::Index(cmof,*vi); - vi->R() = vi->P()[0]; - } - - - tri::Allocator::CompactVertexVector(cmof); - tri::UpdateBounding::Box(cmof); - for(CMeshOcf::VertexIterator vi = cmof.vert.begin(); vi!=cmof.vert.end();++vi) - { - if(!(*vi).IsD()) - { - float q =vi->Q(); - float r =vi->R(); - } - } - + printf("Last Iteration: Refined a tetra up to a mesh of %i faces in:\n" + "Standard Component %5.2f sec\n" + "OCF Component %5.2f sec\n",cm.FN(),float(t1-t0)/CLOCKS_PER_SEC,float(t2-t1)/CLOCKS_PER_SEC); + tri::io::ExporterOFF::Save(cmof,"test.off",tri::io::Mask::IOM_VERTCOLOR); return 0; }