From 2577210a54d416a473f4dbf7c8a911aeb328562d Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 4 Oct 2012 11:10:25 +0000 Subject: [PATCH] **** SIGNIFICANT CHANGES ***** - Cleaned up include order: Now you only need to include (no more vertex/base.h etc) - Added official VN() EN() FN() const members for knowing number of vertexes etc... - Added exceptions (at last!) Now instead of: assert(HasPerVertexNormal(m)) you should write: if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException(); --- vcg/complex/allocate.h | 10 +--- vcg/complex/complex.h | 90 ++++++++++------------------ vcg/complex/exception.h | 35 +++++++++++ vcg/complex/used_types.h | 14 ++++- vcg/connectors/hedge.h | 9 +-- vcg/connectors/hedge_component.h | 6 +- vcg/simplex/edge/base.h | 8 +-- vcg/simplex/edge/component.h | 6 +- vcg/simplex/face/base.h | 9 +-- vcg/simplex/face/component.h | 6 +- vcg/simplex/face/component_polygon.h | 5 -- vcg/simplex/vertex/base.h | 54 +---------------- vcg/simplex/vertex/component.h | 7 +-- 13 files changed, 88 insertions(+), 171 deletions(-) create mode 100644 vcg/complex/exception.h diff --git a/vcg/complex/allocate.h b/vcg/complex/allocate.h index d1b53fc0..593d2867 100644 --- a/vcg/complex/allocate.h +++ b/vcg/complex/allocate.h @@ -25,12 +25,8 @@ #define __VCGLIB_TRIALLOCATOR #include -#include #include -#include #include -#include -#include namespace vcg { @@ -66,9 +62,9 @@ namespace vcg { template size_t Index(MeshType &m, const typename MeshType::FaceType * fp) {return fp-&*m.face.begin();} template - size_t Index(MeshType &m, const typename MeshType::EdgeType* e) {return e-&*m.edge.begin();} + size_t Index(MeshType &m, const typename MeshType::EdgeType* e) {return e-&*m.edge.begin();} template - size_t Index(MeshType &m, const typename MeshType::HEdgeType* h) {return h-&*m.hedge.begin();} + size_t Index(MeshType &m, const typename MeshType::HEdgeType* h) {return h-&*m.hedge.begin();} template void ReorderAttribute(ATTR_CONT &c,std::vector & newVertIndex, MeshType & /* m */){ @@ -78,7 +74,7 @@ namespace vcg { } template - void ResizeAttribute(ATTR_CONT &c,const int & sz , MeshType &/*m*/){ + void ResizeAttribute(ATTR_CONT &c,const int & sz , MeshType &/*m*/){ typename std::set::iterator ai; for(ai =c.begin(); ai != c.end(); ++ai) ((typename MeshType::PointerToAttribute)(*ai)).Resize(sz); diff --git a/vcg/complex/complex.h b/vcg/complex/complex.h index b5af867d..0cacfb09 100644 --- a/vcg/complex/complex.h +++ b/vcg/complex/complex.h @@ -2,7 +2,7 @@ * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * -* Copyright(C) 2004 \/)\/ * +* Copyright(C) 2004-2012 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * @@ -21,30 +21,20 @@ * * ****************************************************************************/ -#if defined(_MSC_VER) -#pragma warning( disable : 4804 ) -#endif +#ifndef __VCG_MESH +#define __VCG_MESH + #include #include #include #include -#include -#include -#include +#include +#include #include -#include -#include -#include -#include #include -#include #include - -#ifndef __VCG_MESH -#define __VCG_MESH - namespace vcg { namespace tri { /** \addtogroup trimesh */ @@ -197,22 +187,34 @@ class TriMesh typedef Box3 BoxType; - /// Set of vertices + /// Container of vertices, usually a vector. VertContainer vert; - /// Actual number of vertices + /// Current number of vertices; this member is for internal use only. You should always use the VN() member int vn; - /// Set of faces - FaceContainer face; - /// Actual number of faces - int fn; - /// Set of edges + /// Current number of vertices + inline int VN() const { return vn; } + + /// Container of edges, usually a vector. EdgeContainer edge; - /// Actual number of edges + /// Current number of edges; this member is for internal use only. You should always use the EN() member int en; - /// Set of hedges - HEdgeContainer hedge; - /// Actual number of hedges + /// Current number of edges + inline int EN() const { return en; } + + /// Container of faces, usually a vector. + FaceContainer face; + /// Current number of faces; this member is for internal use only. You should always use the FN() member + int fn; + /// Current number of faces + inline int FN() const { return fn; } + + /// Container of half edges, usually a vector. + HEdgeContainer hedge; + /// Current number of hedges int hn; + /// Current number of hedges; this member is for internal use only. You should always use the HN() member + inline int HN() const { return hn; } + /// Bounding box of the mesh Box3 bbox; @@ -361,7 +363,7 @@ void Clear() { vert.clear(); face.clear(); - edge.clear(); + edge.clear(); // textures.clear(); // normalmaps.clear(); vn = 0; @@ -380,38 +382,6 @@ int & VertexNumber(){ return vn;} /// The incremental mark int imark; -/// Calcolo del volume di una mesh chiusa -ScalarType Volume() -{ - FaceIterator fi; - int j,k; - ScalarType V = 0; - CoordType T,N,B; - - for(fi = face.begin(); fi!=face.end(); ++fi) - { - for(j = 0; j < 3; ++j) - { - /*calcolo tangente, normale e binormale (6 volte)*/ - k = (j+1)%3; - T = (*fi).P(k) - (*fi).P(j); - T.Normalize(); - B = ( (*fi).P( k ) - (*fi).P(j) ) ^ - ( (*fi).P((k+1)%3) - (*fi).P(j) ) ; - B.Normalize(); - N = T ^ B; - - CoordType pj = (*fi).P(j); - CoordType pk = (*fi).P(k); - - - V += (pk* T )*(pk*N)*(pk*B); - V += (pj*(-T))*(pj*N)*(pj*B); - } - } - return V/6.0; -} - private: // TriMesh cannot be copied. Use Append (see vcg/complex/append.h) TriMesh operator =(const TriMesh & /*m*/){assert(0);return TriMesh();} diff --git a/vcg/complex/exception.h b/vcg/complex/exception.h new file mode 100644 index 00000000..e3125f7d --- /dev/null +++ b/vcg/complex/exception.h @@ -0,0 +1,35 @@ +/**************************************************************************** +* 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. * +* * +****************************************************************************/ +#ifndef __VCG_EXCEPTION_H +#define __VCG_EXCEPTION_H + +namespace vcg +{ +class MissingComponentException : public std::exception +{ +public: + MissingComponentException() {} +}; +} + +#endif // EXCEPTION_H diff --git a/vcg/complex/used_types.h b/vcg/complex/used_types.h index d6d5a9d9..fdadac6e 100755 --- a/vcg/complex/used_types.h +++ b/vcg/complex/used_types.h @@ -1,13 +1,23 @@ #ifndef VCG_USED_TYPES_H #define VCG_USED_TYPES_H -#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include +#include #include +#include #include namespace vcg{ diff --git a/vcg/connectors/hedge.h b/vcg/connectors/hedge.h index 06af2230..62f1ca44 100644 --- a/vcg/connectors/hedge.h +++ b/vcg/connectors/hedge.h @@ -20,18 +20,11 @@ * for more details. * * * ****************************************************************************/ +#include #ifndef __VCG_HEDGE_ #define __VCG_HEDGE_ -//#include -//#include -//#include -#include -//#include -#include -#include - namespace vcg { /*------------------------------------------------------------------*/ diff --git a/vcg/connectors/hedge_component.h b/vcg/connectors/hedge_component.h index 3f244a88..d78b7175 100644 --- a/vcg/connectors/hedge_component.h +++ b/vcg/connectors/hedge_component.h @@ -20,14 +20,10 @@ * for more details. * * * ****************************************************************************/ +#include #ifndef __VCG_HEDGE_COMPONENT #define __VCG_HEDGE_COMPONENT -//#include -#include -//#include -//#include -#include namespace vcg { namespace hedge { diff --git a/vcg/simplex/edge/base.h b/vcg/simplex/edge/base.h index c0c2f164..38c984e7 100644 --- a/vcg/simplex/edge/base.h +++ b/vcg/simplex/edge/base.h @@ -20,17 +20,11 @@ * for more details. * * * ****************************************************************************/ +#include #ifndef __VCG_EDGE_PLUS #define __VCG_EDGE_PLUS -//#include -//#include -//#include -#include -//#include -#include -#include namespace vcg { diff --git a/vcg/simplex/edge/component.h b/vcg/simplex/edge/component.h index b4debd98..7f4a708f 100644 --- a/vcg/simplex/edge/component.h +++ b/vcg/simplex/edge/component.h @@ -20,14 +20,10 @@ * for more details. * * * ****************************************************************************/ +#include #ifndef __VCG_EDGE_PLUS_COMPONENT #define __VCG_EDGE_PLUS_COMPONENT -#include -#include -//#include -//#include -#include namespace vcg { namespace edge { diff --git a/vcg/simplex/face/base.h b/vcg/simplex/face/base.h index 640144fa..ed9627f1 100644 --- a/vcg/simplex/face/base.h +++ b/vcg/simplex/face/base.h @@ -20,18 +20,11 @@ * for more details. * * * ****************************************************************************/ +#include #ifndef __VCG_FACE_PLUS #define __VCG_FACE_PLUS -#include -#include -#include -#include -#include -#include -#include - namespace vcg { /*------------------------------------------------------------------*/ diff --git a/vcg/simplex/face/component.h b/vcg/simplex/face/component.h index 5ccd6798..5dd76455 100644 --- a/vcg/simplex/face/component.h +++ b/vcg/simplex/face/component.h @@ -20,14 +20,10 @@ * for more details. * * * ****************************************************************************/ - +#include #ifndef __VCG_FACE_PLUS_COMPONENT #define __VCG_FACE_PLUS_COMPONENT -#include -#include -#include -#include namespace vcg { diff --git a/vcg/simplex/face/component_polygon.h b/vcg/simplex/face/component_polygon.h index af874814..c2255154 100644 --- a/vcg/simplex/face/component_polygon.h +++ b/vcg/simplex/face/component_polygon.h @@ -24,11 +24,6 @@ #ifndef __VCG_POLYGON_COMPONENT #define __VCG_POLYGON_COMPONENT -//#include -//#include -//#include -//#include - namespace vcg { namespace face { /* diff --git a/vcg/simplex/vertex/base.h b/vcg/simplex/vertex/base.h index f4cb465c..9cede68a 100644 --- a/vcg/simplex/vertex/base.h +++ b/vcg/simplex/vertex/base.h @@ -20,62 +20,10 @@ * for more details. * * * ****************************************************************************/ -/**************************************************************************** - History - -$Log: not supported by cvs2svn $ -Revision 1.12 2008/03/17 11:39:14 ganovelli -added curvature and curvatruredir (compiled .net 2005 and gcc) - -Revision 1.11 2008/02/04 21:26:49 ganovelli -added ImportData which imports all local attributes into vertexplus and faceplus. -A local attribute is everything (N(), C(), Q()....) except pointers to other simplices -(i.e. FFAdj, VFAdj, VertexRef) which are set to NULL. -Added some function for const attributes - -Revision 1.10 2007/03/12 15:37:21 tarini -Texture coord name change! "TCoord" and "Texture" are BAD. "TexCoord" is GOOD. - -Revision 1.9 2007/02/12 19:00:56 ganovelli -added Name(std:vector& n) that fills n with the names of the attribute of the vertex type - -Revision 1.8 2006/09/28 17:34:11 cignoni -Added Missing GetBBox function - -Revision 1.7 2006/02/27 17:42:43 ponchio -Added some documentation. - -Revision 1.6 2005/12/05 15:58:10 cignoni -Removed spurious definition of flags in Aritymax that was overriding the correct definition in EmplyBitFlags and BitFlags classes - -Revision 1.5 2005/12/02 00:44:41 cignoni -Reformatted and compacted flags code. - -Revision 1.4 2005/11/16 22:59:35 cignoni -Standardized name of flags. It is plural becouse each simplex has many flag. - -Revision 1.3 2005/11/12 18:36:51 cignoni -Added 'Visited' flag functions - -Revision 1.2 lags2004/04/03 13:33:55 cignoni -Missing include - -Revision 1.1 2004/03/29 08:36:26 cignoni -First working version! - - -****************************************************************************/ +#include #ifndef __VCG_VERTEX_PLUS #define __VCG_VERTEX_PLUS -//#include -#include -#include -#include -#include -//#include -#include - namespace vcg { /*------------------------------------------------------------------*/ diff --git a/vcg/simplex/vertex/component.h b/vcg/simplex/vertex/component.h index 06d5ae46..c122b344 100644 --- a/vcg/simplex/vertex/component.h +++ b/vcg/simplex/vertex/component.h @@ -20,14 +20,9 @@ * for more details. * * * ****************************************************************************/ +#include #ifndef __VCG_VERTEX_PLUS_COMPONENT #define __VCG_VERTEX_PLUS_COMPONENT -#include -#include -#include -#include -#include - namespace vcg { namespace vertex { /*