trimesh_optional.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2012                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 
00034 #include<vcg/complex/complex.h>
00035 
00036 #include<vcg/complex/algorithms/create/platonic.h>
00037 #include<vcg/complex/algorithms/update/topology.h>
00038 #include<vcg/complex/algorithms/update/flag.h>
00039 #include<vcg/complex/algorithms/update/normal.h>
00040 #include<vcg/complex/algorithms/update/bounding.h>
00041 #include<vcg/complex/algorithms/update/curvature.h>
00042 #include <vcg/complex/algorithms/refine_loop.h>
00043 #include <wrap/io_trimesh/export_off.h>
00044 
00045 class MyFace;
00046 class MyVertex;
00047 
00048 struct MyUsedTypes:    public   vcg::UsedTypes<
00049     vcg::Use<MyVertex>::AsVertexType,
00050     vcg::Use<MyFace  >::AsFaceType>{};
00051 
00052 class MyVertex     : public vcg::Vertex<        MyUsedTypes,
00053     vcg::vertex::Coord3f,  vcg::vertex::Qualityf,
00054     vcg::vertex::Color4b,  vcg::vertex::BitFlags,
00055     vcg::vertex::Normal3f, vcg::vertex::VFAdj >{};
00056 
00057 class MyFace       : public vcg::Face< MyUsedTypes,
00058     vcg::face::FFAdj,   vcg::face::VFAdj,
00059     vcg::face::Color4b, vcg::face::VertexRef,
00060     vcg::face::BitFlags,   vcg::face::Normal3f > {};
00061 class MyMesh       : public vcg::tri::TriMesh<     std::vector<MyVertex   >,           std::vector<MyFace   > > {};
00062 
00063 
00064 class MyVertexOcf;
00065 class MyFaceOcf;
00066 
00067 struct MyUsedTypesOcf: public   vcg::UsedTypes<
00068     vcg::Use<MyVertexOcf>::AsVertexType,
00069     vcg::Use<MyFaceOcf>::AsFaceType>{};
00070 
00071 class MyVertexOcf  : public vcg::Vertex< MyUsedTypesOcf,
00072     vcg::vertex::InfoOcf,       //   <--- Note the use of the 'special' InfoOcf component
00073     vcg::vertex::Coord3f,  vcg::vertex::QualityfOcf,
00074     vcg::vertex::Color4b,  vcg::vertex::BitFlags,
00075     vcg::vertex::Normal3f, vcg::vertex::VFAdjOcf >{};
00076 
00077 class MyFaceOcf    : public vcg::Face< MyUsedTypesOcf,
00078     vcg::face::InfoOcf,         //   <--- Note the use of the 'special' InfoOcf component
00079     vcg::face::FFAdjOcf,   vcg::face::VFAdjOcf,
00080     vcg::face::Color4bOcf, vcg::face::VertexRef,
00081     vcg::face::BitFlags,   vcg::face::Normal3fOcf > {};
00082 
00083 // the mesh class must make use of the 'vector_ocf' containers instead of the classical std::vector
00084 class MyMeshOcf : public vcg::tri::TriMesh< vcg::vertex::vector_ocf<MyVertexOcf>, vcg::face::vector_ocf<MyFaceOcf> > {};
00085 
00086 
00087 using namespace vcg;
00088 using namespace std;
00089 
00090 int main(int , char **)
00091 {
00092   MyMesh cm;
00093   MyMeshOcf cmof;
00094 
00095   tri::Tetrahedron(cm);
00096   tri::Tetrahedron(cmof);
00097 
00098   printf("Generated mesh has %i vertices and %i triangular faces\n",cm.VN(),cm.FN());
00099 
00100   assert(tri::HasFFAdjacency(cmof) == false);
00101   cmof.face.EnableFFAdjacency();
00102   assert(tri::HasFFAdjacency(cmof) == true);
00103 
00104   assert(tri::HasVFAdjacency(cmof) == false);
00105   cmof.vert.EnableVFAdjacency();
00106   cmof.face.EnableVFAdjacency();
00107   assert(tri::HasVFAdjacency(cmof) == true);
00108 
00109   tri::UpdateTopology<MyMesh   >::FaceFace(cm);
00110   tri::UpdateTopology<MyMeshOcf>::FaceFace(cmof);
00111 
00112   tri::UpdateFlags<MyMesh   >::FaceBorderFromFF(cm);
00113   tri::UpdateFlags<MyMeshOcf>::FaceBorderFromFF(cmof);
00114 
00115   tri::UpdateNormal<MyMesh   >::PerVertexPerFace(cm);
00116   cmof.face.EnableNormal();  // remove this line and you will throw an exception for a missing 'normal' component
00117   tri::UpdateNormal<MyMeshOcf>::PerVertexPerFace(cmof);
00118 
00119   cmof.vert.EnableQuality();
00120 
00121   tri::UpdateColor<MyMeshOcf>::PerVertexConstant(cmof,Color4b::LightGray);
00122   printf("cmof IsColorEnabled() %s\n",cmof.face.back().IsColorEnabled()?"Yes":"No");
00123   cmof.face.EnableColor();
00124   tri::UpdateColor<MyMeshOcf>::PerFaceConstant(cmof,Color4b::LightGray);
00125   cmof.vert[0].C()=Color4b::Red;
00126 
00127   printf("cmof IsColorEnabled() %s\n",cmof.face.back().IsColorEnabled()?"Yes":"No");
00128   printf("cm IsColorEnabled() %s\n",cm.face.back().IsColorEnabled()?"Yes":"No");
00129   printf("cm IsColorEnabled() %s\n",cm.face.back().HasColor()?"Yes":"No");
00130 
00131   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]);
00132   int t0=0,t1=0,t2=0;
00133   while(float(t1-t0)/CLOCKS_PER_SEC < 0.1f)
00134   {
00135     t0=clock();
00136     tri::RefineOddEven<MyMesh> (cm, tri::OddPointLoop<MyMesh>(cm), tri::EvenPointLoop<MyMesh>(), 0);
00137     t1=clock();
00138     tri::RefineOddEven<MyMeshOcf> (cmof, tri::OddPointLoop<MyMeshOcf>(cmof), tri::EvenPointLoop<MyMeshOcf>(), 0);
00139     t2=clock();
00140   }
00141   printf("Last Iteration: Refined a tetra up to a mesh of %i faces in:\n"
00142          "Standard Component %5.2f sec\n"
00143          "OCF      Component %5.2f sec\n",cm.FN(),float(t1-t0)/CLOCKS_PER_SEC,float(t2-t1)/CLOCKS_PER_SEC);
00144   tri::io::ExporterOFF<MyMeshOcf>::Save(cmof,"test.off",tri::io::Mask::IOM_VERTCOLOR);
00145 
00146   return 0;
00147 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:38:20