trimesh_attribute.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 ****************************************************************************/
00032 #include<vcg/complex/complex.h>
00033 class MyEdge;
00034 class MyFace;
00035 class MyVertex;
00036 struct MyUsedTypes : public vcg::UsedTypes<     vcg::Use<MyVertex>              ::AsVertexType,
00037                                             vcg::Use<MyFace>                    ::AsFaceType>{};
00038 
00039 class MyVertex  : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f,vcg::vertex::Normal3f>{};
00040 class MyFace    : public vcg::Face< MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f> {};
00041 
00042 class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> > {};
00043 
00044 int main()
00045 {
00046   MyMesh m;
00048   // add a per-vertex attribute with type float named "Irradiance"
00049   MyMesh::PerVertexAttributeHandle<float> named_hv = vcg::tri::Allocator<MyMesh>:: GetPerVertexAttribute<float> (m,std::string("Irradiance"));
00051 
00052   // add a per-vertex attribute with type float named "Radiosity"
00053   vcg::tri::Allocator<MyMesh>:: GetPerVertexAttribute<float> (m,std::string("Radiosity"));
00054 
00055   // add a per-vertex attribute with type bool and no name specified
00056   MyMesh::PerVertexAttributeHandle<bool> anon_hv = vcg::tri::Allocator<MyMesh>:: GetPerVertexAttribute<bool> (m);
00057 
00058   // add a per-face attribute with type bool and no name specified
00059   MyMesh::PerFaceAttributeHandle<bool> anon_hf = vcg::tri::Allocator<MyMesh>:: GetPerFaceAttribute<bool> (m);
00060 
00062   MyMesh::VertexIterator vi; int i;
00063   for(i=0, vi   = m.vert.begin(); vi != m.vert.end(); ++vi,++i){
00064    named_hv[vi]  = 1.0f;  // [] operator takes a iterator
00065    named_hv[*vi] = 1.0f;  //                or a MyMesh::VertexType object
00066    named_hv[&*vi]= 1.0f;  //                or a pointer to it
00067    named_hv[i]   = 1.0f;  //                or an integer index
00068   }
00070 
00071   vcg::tri::Allocator<MyMesh>::ClearPerVertexAttribute<float>(m,named_hv);
00072 
00073   // query if an attribute is present or not
00074   bool hasRadiosity = vcg::tri::HasPerVertexAttribute(m,"Radiosity");
00075 
00076   // obtain another handle of a previously attribute
00077    MyMesh::PerVertexAttributeHandle<float> ret_hv = vcg::tri::Allocator<MyMesh>:: FindPerVertexAttribute<float>(m,"Radiosity");
00078 
00080   // you can also have PerMesh attributes
00081   MyMesh::PerMeshAttributeHandle<int> hm = vcg::tri::Allocator<MyMesh>:: GetPerMeshAttribute<int> (m,std::string("ADummyIntegerAttribute"));
00082   // PerMesh attributes are accessed directly using the handle itself
00083   hm() = 10;
00085 
00087   // delete an attribute by name
00088   vcg::tri::Allocator<MyMesh>::DeletePerVertexAttribute(m, "Radiosity");
00089 
00090   // delete an attribute by handle
00091   vcg::tri::Allocator<MyMesh>::DeletePerVertexAttribute(m, anon_hv);
00093 
00094   bool res;
00095   res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,named_hv);         printf("Is Valid: %s\n",res?"Yes":"No");
00096   res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,anon_hf); printf("Is Valid: %s\n",res?"Yes":"No");
00097   res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,hm); printf("Is Valid: %s\n",res?"Yes":"No");
00098   vcg::tri::Allocator<MyMesh>::DeletePerVertexAttribute(m,ret_hv);
00099   vcg::tri::Allocator<MyMesh>::DeletePerFaceAttribute(m,anon_hf);
00100   res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,named_hv);         printf("Is Valid: %s\n",res?"Yes":"No");
00101   res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,anon_hf); printf("Is Valid: %s\n",res?"Yes":"No");
00102   res = vcg::tri::Allocator<MyMesh>::IsValidHandle(m,hm); printf("Is Valid: %s\n",res?"Yes":"No");
00103 }


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