1 /**************************************************************************** 2 * VCGLib o o * 3 * Visual and Computer Graphics Library o o * 4 * _ O _ * 5 * Copyright(C) 2004-2016 \/)\/ * 6 * Visual Computing Lab /\/| * 7 * ISTI - Italian National Research Council | * 8 * \ * 9 * All rights reserved. * 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 * This program is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 20 * for more details. * 21 * * 22 ****************************************************************************/ 23 #ifndef __VCG_MESH 24 #error "This file should not be included alone. It is automatically included by complex.h" 25 #endif 26 #ifndef __VCG_VERTEX_PLUS 27 #define __VCG_VERTEX_PLUS 28 29 namespace vcg { 30 31 32 /* The base class form which we start to add our components. 33 it has the empty definition for all the standard members (coords, color flags) 34 Note: 35 in order to avoid both virtual classes and ambiguous definitions all 36 the subsequent overrides must be done in a sequence of derivation. 37 38 In other words we cannot derive and add in a single derivation step 39 (with multiple ancestor), both the real (non-empty) normal and color but 40 we have to build the type a step a time (deriving from a single ancestor at a time). 41 42 The Real Big Vertex class; 43 44 The class __VertexArityMax__ is the one that is the Last to be derived, 45 and therefore is the only one to know the real members 46 (after the many overrides) so all the functions with common behaviour 47 using the members defined in the various Empty/nonEmpty component classes 48 MUST be defined here. 49 50 I.e. IsD() that uses the overridden Flags() member must be defined here. 51 52 */ 53 54 template <class UserTypes, 55 template <typename> class A, template <typename> class B, 56 template <typename> class C, template <typename> class D, 57 template <typename> class E, template <typename> class F, 58 template <typename> class G, template <typename> class H, 59 template <typename> class I, template <typename> class J, 60 template <typename> class K, template <typename> class L> 61 class VertexArityMax: public Arity12<vertex::EmptyCore<UserTypes>, A, B, C, D, E, F, G, H, I, J, K, L> { 62 63 // ----- Flags stuff ----- 64 public: 65 66 67 68 enum { 69 70 DELETED = 0x0001, // This bit indicate that the vertex is deleted from the mesh 71 NOTREAD = 0x0002, // This bit indicate that the vertex of the mesh is not readable 72 NOTWRITE = 0x0004, // This bit indicate that the vertex is not modifiable 73 MODIFIED = 0x0008, // This bit indicate that the vertex is modified 74 VISITED = 0x0010, // This bit can be used to mark the visited vertex 75 SELECTED = 0x0020, // This bit can be used to select 76 BORDER = 0x0100, // Border Flag 77 USER0 = 0x0200 // First user bit 78 }; 79 IsD()80 bool IsD() const {return (this->cFlags() & DELETED) != 0;} /// checks if the vertex is deleted IsR()81 bool IsR() const {return (this->cFlags() & NOTREAD) == 0;} /// checks if the vertex is readable IsW()82 bool IsW() const {return (this->cFlags() & NOTWRITE)== 0;}/// checks if the vertex is modifiable IsRW()83 bool IsRW() const {return (this->cFlags() & (NOTREAD | NOTWRITE)) == 0;}/// This funcion checks whether the vertex is both readable and modifiable IsS()84 bool IsS() const {return (this->cFlags() & SELECTED) != 0;}/// checks if the vertex is Selected IsB()85 bool IsB() const {return (this->cFlags() & BORDER) != 0;}/// checks if the vertex is a border one IsV()86 bool IsV() const {return (this->cFlags() & VISITED) != 0;}/// checks if the vertex Has been visited 87 88 89 /** Set the flag value 90 @param flagp Valore da inserire nel flag 91 */ SetFlags(int flagp)92 void SetFlags(int flagp) {this->Flags()=flagp;} 93 94 /** Set the flag value 95 @param flagp Valore da inserire nel flag 96 */ ClearFlags()97 void ClearFlags() {this->Flags()=0;} SetD()98 void SetD() {this->Flags() |=DELETED;}/// deletes the vertex from the mesh ClearD()99 void ClearD() {this->Flags() &=(~DELETED);}/// un-delete a vertex SetR()100 void SetR() {this->Flags() &=(~NOTREAD);}/// marks the vertex as readable ClearR()101 void ClearR() {this->Flags() |=NOTREAD;}/// marks the vertex as not readable ClearW()102 void ClearW() {this->Flags() |=NOTWRITE;}/// marks the vertex as writable SetW()103 void SetW() {this->Flags() &=(~NOTWRITE);}/// marks the vertex as not writable SetS()104 void SetS() {this->Flags() |=SELECTED;}/// select the vertex ClearS()105 void ClearS() {this->Flags() &= ~SELECTED;}/// Un-select a vertex SetB()106 void SetB() {this->Flags() |=BORDER;} ClearB()107 void ClearB() {this->Flags() &=~BORDER;} SetV()108 void SetV() {this->Flags() |=VISITED;} ClearV()109 void ClearV() {this->Flags() &=~VISITED;} 110 111 /// Return the first bit that is not still used FirstUnusedBitFlag()112 static int &FirstUnusedBitFlag() 113 { 114 static int b =USER0; 115 return b; 116 } 117 118 /// Allocate a bit among the flags that can be used by user. It updates the FirstUnusedBitFlag. NewBitFlag()119 static inline int NewBitFlag() 120 { 121 int bitForTheUser = FirstUnusedBitFlag(); 122 FirstUnusedBitFlag()=FirstUnusedBitFlag()<<1; 123 return bitForTheUser; 124 } 125 126 /// De-allocate a pre allocated bit. It updates the FirstUnusedBitFlag. 127 // Note you must deallocate bit in the inverse order of the allocation (as in a stack) DeleteBitFlag(int bitval)128 static inline bool DeleteBitFlag(int bitval) 129 { 130 if(FirstUnusedBitFlag()>>1==bitval) { 131 FirstUnusedBitFlag() = FirstUnusedBitFlag()>>1; 132 return true; 133 } 134 assert(0); 135 return false; 136 } 137 138 /// This function checks if the given user bit is true IsUserBit(int userBit)139 bool IsUserBit(int userBit){return (this->Flags() & userBit) != 0;} 140 141 /// This function set the given user bit SetUserBit(int userBit)142 void SetUserBit(int userBit){this->Flags() |=userBit;} 143 144 /// This function clear the given user bit ClearUserBit(int userBit)145 void ClearUserBit(int userBit){this->Flags() &= (~userBit);} 146 147 template<class BoxType> GetBBox(BoxType & bb)148 void GetBBox( BoxType & bb ) const 149 { bb.Set(this->cP()); } 150 151 }; 152 153 154 /* 155 156 These are the three main classes that are used by the library user to define its own vertexes. 157 The user MUST specify the names of all the type involved in a generic complex. 158 so for example when defining a vertex of a trimesh you must know the name of the type of the edge and of the face. 159 Typical usage example: 160 161 A vertex with coords, flags and normal for use in a standard trimesh: 162 163 class VertexNf : public VertexSimp2< VertexNf, EdgeProto, FaceProto, vert::Coord3d, vert::Flag, vert::Normal3f > {}; 164 165 166 A vertex with coords, and normal for use in a tetrahedral mesh AND in a standard trimesh: 167 168 class TetraVertex : public VertexSimp3< TetraVertex, EdgeProto, FaceProto, TetraProto, vert::Coord3d, vert::Normal3f > {}; 169 170 171 A summary of the available vertex attributes (see component.h for more details): 172 173 Coord3f, Coord3d, 174 Normal3s, Normal3f, Normal3d 175 Mark //a int component (incremental mark) 176 BitFlags 177 TexCoord2s, TexCoord2f, TexCoord2d 178 Color4b 179 Qualitys, Qualityf, Qualityd 180 VFAdj //topology (vertex->face adjacency) 181 */ 182 183 template <class UserTypes, 184 template <typename> class A = DefaultDeriver, template <typename> class B = DefaultDeriver, 185 template <typename> class C = DefaultDeriver, template <typename> class D = DefaultDeriver, 186 template <typename> class E = DefaultDeriver, template <typename> class F = DefaultDeriver, 187 template <typename> class G = DefaultDeriver, template <typename> class H = DefaultDeriver, 188 template <typename> class I = DefaultDeriver, template <typename> class J = DefaultDeriver, 189 template <typename> class K = DefaultDeriver, template <typename> class L = DefaultDeriver> 190 class Vertex: public VertexArityMax<UserTypes, A, B, C, D, E, F, G, H, I, J, K, L> { 191 public: typedef AllTypes::AVertexType IAm; typedef UserTypes TypesPool;}; 192 193 }// end namespace 194 #endif 195