From 0896041baac47e5bab8212e492b9d51ac98157ee Mon Sep 17 00:00:00 2001 From: cignoni Date: Fri, 14 Oct 2005 17:52:07 +0000 Subject: [PATCH] First working version of optional sample --- .../trimesh_optional/trimesh_optional.cpp | 82 +++++++++++++++++++ .../trimesh_optional/trimesh_optional.pro | 13 +++ .../trimesh_topology/trimesh_topology.cpp | 7 +- 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 apps/sample/trimesh_optional/trimesh_optional.cpp create mode 100644 apps/sample/trimesh_optional/trimesh_optional.pro diff --git a/apps/sample/trimesh_optional/trimesh_optional.cpp b/apps/sample/trimesh_optional/trimesh_optional.cpp new file mode 100644 index 00000000..8b22e95a --- /dev/null +++ b/apps/sample/trimesh_optional/trimesh_optional.cpp @@ -0,0 +1,82 @@ +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace vcg; +using namespace std; + + + +class CEdge; // dummy prototype never used +class CFace; +class CFaceOcf; +class CVertex; +class CVertexOcf; + +// Opt stuff + +class CVertex : public VertexSimp2< CVertex, CEdge, CFace, vert::Coord3f, vert::Normal3f >{}; +class CVertexOcf : public VertexSimp2< CVertexOcf, CEdge, CFaceOcf, vert::Coord3f, vert::Normal3f >{}; + +class CFace : public FaceSimp2< CVertex, CEdge, CFace, face::FFAdj, face::VertexRef, face::Flag, face::Normal3f > {}; +class CFaceOcf : public FaceSimp2< CVertexOcf, CEdge, CFaceOcf, face::InfoOcf, face::FFAdjOcf, face::VertexRef, face::Flag, face::Normal3fOcf > {}; + +class CMeshOcf : public vcg::tri::TriMesh< vector, face::vector_ocf > {}; +class CMesh : public vcg::tri::TriMesh< vector, vector > {}; + + +int main(int , char **) +{ + CMesh cm; + CMeshOcf cmo; + tri::Tetrahedron(cm); + tri::Tetrahedron(cmo); + + printf("Generated mesh has %i vertices and %i triangular faces\n",cm.vn,cm.fn); + + /// Calculates both vertex and face normals. + /// The normal of a vertex v is the weigthed average of the normals of the faces incident on v. + /// normals are not normalized + + + + cmo.face.EnableFFAdjacency(); + + vcg::tri::UpdateTopology::FaceFace(cm); + vcg::tri::UpdateTopology::FaceFace(cmo); + + vcg::tri::UpdateFlags::FaceBorderFromFF(cm); + vcg::tri::UpdateFlags::FaceBorderFromFF(cmo); + + vcg::tri::UpdateNormals::PerVertexNormalized(cm); + vcg::tri::UpdateNormals::PerVertexNormalized(cmo); + + printf("Size of CFace %3i\n",sizeof(CFace)); + printf("Size of CFaceOcf %3i\n",sizeof(CFaceOcf)); + + 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(t2-t0<3000) + { + t0=clock(); + Refine(cm,MidPointButterfly(),0); + t1=clock(); + Refine(cmo,MidPointButterfly(),0); + t2=clock(); + printf("Mesh is %i %i in Std:%i Ocf:%i\n",cm.vn,cm.fn,t1-t0,t2-t1); + } + return 0; +} diff --git a/apps/sample/trimesh_optional/trimesh_optional.pro b/apps/sample/trimesh_optional/trimesh_optional.pro new file mode 100644 index 00000000..cd4b2e79 --- /dev/null +++ b/apps/sample/trimesh_optional/trimesh_optional.pro @@ -0,0 +1,13 @@ +###################################################################### +# Automatically generated by qmake (2.00a) ven 24. giu 14:14:20 2005 +###################################################################### +# To solve issue related to slash vs. backslash under cygwin try: +# env MINGW_IN_SHELL=1 qmake -spec win32-g++ + +TARGET = trimesh_optional +LIBPATH += +DEPENDPATH += . +INCLUDEPATH += . ../../.. +CONFIG += console stl +TEMPLATE = app +SOURCES += trimesh_optional.cpp ../../../wrap/ply/plylib.cpp \ No newline at end of file diff --git a/apps/sample/trimesh_topology/trimesh_topology.cpp b/apps/sample/trimesh_topology/trimesh_topology.cpp index 60c2a766..272c4cb5 100644 --- a/apps/sample/trimesh_topology/trimesh_topology.cpp +++ b/apps/sample/trimesh_topology/trimesh_topology.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -34,14 +35,14 @@ int main(int ,char ** ){ // Now for each face the F() members are meaningful - if(m.face[0].IsBorder(0)) printf("Edge 0 of face 0 is a border\n"); + if(face::IsBorder(m.face[0],0)) printf("Edge 0 of face 0 is a border\n"); else printf("Edge 0 of face 0 is NOT a border\n"); // always this path! vcg::face::FFDetach(m.face[0],0); // Detach the face [0] from the mesh vcg::face::FFDetach(m.face[0],1); vcg::face::FFDetach(m.face[0],2); - if(m.face[0].IsBorder(0)) printf("Edge 0 of face 0 is a border\n"); // always this path! + if(face::IsBorder(m.face[0],0)) printf("Edge 0 of face 0 is a border\n"); // always this path! else printf("Edge 0 of face 0 is NOT a border\n"); m.face[0].SetD(); // deleting face [0] (i.e. marked as deleted) @@ -59,7 +60,7 @@ int main(int ,char ** ){ { for(int j=0;j<3;j++) { - if ((*fi).IsBorder(j) && !m.IsMarked(&*fi)) + if ( face::IsBorder(*fi,j) && !m.IsMarked(&*fi)) { m.Mark(&*fi); hei.Set(&*fi,j,fi->V(j));