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 /****************************************************************************
24   History
25 
26 $Log: not supported by cvs2svn $
27 Revision 1.1  2007/05/09 10:31:53  ganovelli
28 added
29 
30 
31 
32 ****************************************************************************/
33 // #ifndef __VCG_TETRA_MESH
34 // #error "This file should not be included alone. It is automatically included by complex.h"
35 // #endif
36 #ifndef __VCG_TETRA_PLUS
37 #define __VCG_TETRA_PLUS
38 
39 //#include <vcg/space/point3.h>
40 //#include <vcg/space/texcoord2.h>
41 //#include <vcg/space/color4.h>
42 //#include <vcg/simplex/tetrahedron/component.h>
43 
44 namespace vcg {
45 
46 /*------------------------------------------------------------------*/
47 
48 // /* The base class form which we start to add our components.
49 // it has the empty definition for all the standard members (coords, color flags)
50 // Note:
51 // in order to avoid both virtual classes and ambiguous definitions all
52 // the subsequent overrides must be done in a sequence of derivation.
53 
54 // In other words we cannot derive and add in a single derivation step
55 // (with multiple ancestor), both the real (non-empty) normal and color but
56 // we have to build the type a step a time (deriving from a single ancestor at a time).
57 
58 
59 
60 
61 template <class UserTypes>
62                 class TetraTypeHolder: public UserTypes {
63   public:
64 
65     template <class RightT>
ImportData(const RightT &)66     void ImportData(const RightT & ){}
Name(std::vector<std::string> &)67     static void Name(std::vector<std::string> & /* name */){}
68 
69 
70  // prot
VN()71     inline int VN()  const { return 4;}
72 };
73 
74 /* The base class form which we start to add our components.
75 it has the empty definition for all the standard members (coords, color flags)
76 Note:
77 in order to avoid both virtual classes and ambiguous definitions all
78 the subsequent overrides must be done in a sequence of derivation.
79 
80 In other words we cannot derive and add in a single derivation step
81 (with multiple ancestor), both the real (non-empty) normal and color but
82 we have to build the type a step a time (deriving from a single ancestor at a time).
83 
84 
85 */
86 template <class UserTypes>
87 class TetraSimpBase: public
88             tetrahedron::EmptyCore< TetraTypeHolder <UserTypes> > {
89 };
90 
91 template <class UserTypes,
92           template <typename> class A, template <typename> class B,
93           template <typename> class C, template <typename> class D,
94           template <typename> class E, template <typename> class F,
95           template <typename> class G, template <typename> class H,
96           template <typename> class I, template <typename> class J,
97           template <typename> class K, template <typename> class L>
98 class TetraArityMax: public Arity12<TetraSimpBase<UserTypes>, A, B, C, D, E, F, G, H, I, J, K, L> {
99 
100 // ----- Flags stuff -----
101 public:
102 
103    	enum {
104 
105 		DELETED     = 0x00000001,		// Tet is deleted from the mesh
106 		NOTREAD     = 0x00000002,		// Tet of the mesh is not readable
107 		NOTWRITE    = 0x00000004,		// Tet of the mesh is not writable
108         VISITED     = 0x00000010,		// Tet has been visited. Usualy this is a per-algorithm used bit.
109 		SELECTED    = 0x00000020,		// Tet is selected. Algorithms should try to work only on selected face (if explicitly requested)
110 		// Border _flags, it is assumed that BORDERi = BORDER0<<i
111 		BORDER0     = 0x00000040,
112 		BORDER1     = 0x00000080,
113 		BORDER2     = 0x00000100,
114 		BORDER3     = 0x00000200,
115 		BORDER0123  = BORDER0 | BORDER1 | BORDER2 | BORDER3,
116 		// Crease _flags,  it is assumed that FEATUREi = FEATURE0<<i
117 		// First user bit
118 		USER0       = 0x00004000
119 			};
120 
121 
122  	///  checks if the Tet is deleted
IsD()123         bool IsD() const {return (this->cFlags() & DELETED) != 0;}
124 	///  checks if the Tet is readable
IsR()125         bool IsR() const {return (this->cFlags() & NOTREAD) == 0;}
126 	///  checks if the Tet is modifiable
IsW()127         bool IsW() const {return (this->cFlags() & NOTWRITE)== 0;}
128 	/// This funcion checks whether the Tet is both readable and modifiable
IsRW()129         bool IsRW() const {return (this->cFlags() & (NOTREAD | NOTWRITE)) == 0;}
130 	///  checks if the Tet is Modified
IsS()131         bool IsS() const {return (this->cFlags() & SELECTED) != 0;}
132 	///  checks if the Tet is Modified
IsV()133         bool IsV() const {return (this->cFlags() & VISITED) != 0;}
134 
135 	/** Set the flag value
136 		@param flagp Valore da inserire nel flag
137 	*/
SetFlags(int flagp)138 	void SetFlags(int flagp) {this->Flags()=flagp;}
139 
140 	/** Set the flag value
141 		@param flagp Valore da inserire nel flag
142 	*/
ClearFlags()143 	void ClearFlags() {this->Flags()=0;}
144 
145 	///  deletes the Tet from the mesh
SetD()146 	void SetD() {this->Flags() |=DELETED;}
147 	///  un-delete a Tet
ClearD()148 	void ClearD() {this->Flags() &=(~DELETED);}
149 	///  marks the Tet as readable
SetR()150 	void SetR() {this->Flags() &=(~NOTREAD);}
151 	///  marks the Tet as not readable
ClearR()152 	void ClearR() {this->Flags() |=NOTREAD;}
153 	///  marks the Tet as writable
SetW()154 	void SetW() {this->Flags() &=(~NOTWRITE);}
155 	///  marks the Tet as notwritable
ClearW()156 	void ClearW() {this->Flags() |=NOTWRITE;}
157 	///  select the Tet
SetS()158 	void SetS()		{this->Flags() |=SELECTED;}
159 	/// Un-select a Tet
ClearS()160   void ClearS()	{this->Flags() &= ~SELECTED;}
161 	///  select the Tet
SetV()162 	void SetV()		{this->Flags() |=VISITED;}
163 	/// Un-select a Tet
ClearV()164   void ClearV()	{this->Flags() &= ~VISITED;}
165 
166 	/// This function checks if the face is border
IsB(int i)167 	bool IsB(int i) const {return (this->cFlags() & (BORDER0<<i)) != 0;}
IsAnyB()168 	bool IsAnyB() const {return (this->cFlags() & (BORDER0123)) != 0;}
169 	/// This function select the face
SetB(int i)170   void SetB(int i)		{this->Flags() |=(BORDER0<<i);}
171 	/// This funcion execute the inverse operation of SetS()
ClearB(int i)172 	void ClearB(int i)	{this->Flags() &= (~(BORDER0<<i));}
173 
174 	///  Return the first bit that is not still used
FirstUnusedBitFlag()175 	static int &FirstUnusedBitFlag()
176 	{
177 	  static int b =USER0;
178 	  return b;
179 	}
180 
181 	/// Allocate a bit among the flags that can be used by user. It updates the FirstUnusedBitFlag.
NewBitFlag()182 	static inline int NewBitFlag()
183 	{
184 	  int bitForTheUser = FirstUnusedBitFlag();
185 	  FirstUnusedBitFlag()=FirstUnusedBitFlag()<<1;
186 	  return bitForTheUser;
187 	}
188 
189 	/// De-allocate a pre allocated bit. It updates the FirstUnusedBitFlag.
190 	// Note you must deallocate bit in the inverse order of the allocation (as in a stack)
DeleteBitFlag(int bitval)191 	static inline bool DeleteBitFlag(int bitval)
192 	{
193 	  if(FirstUnusedBitFlag()>>1==bitval) {
194 		FirstUnusedBitFlag() = FirstUnusedBitFlag()>>1;
195 		return true;
196 	  }
197 	  assert(0);
198 	  return false;
199 	}
200 
201 	/// This function checks if the given user bit is true
IsUserBit(int userBit)202 	bool IsUserBit(int userBit){return (this->Flags() & userBit) != 0;}
203 
204 	/// This function set the given user bit
SetUserBit(int userBit)205 	void SetUserBit(int userBit){this->Flags() |=userBit;}
206 
207 	/// This function clear the given user bit
ClearUserBit(int userBit)208 	void ClearUserBit(int userBit){this->Flags() &= (~userBit);}
209 
210  template<class BoxType>
GetBBox(BoxType & bb)211   void GetBBox( BoxType & bb ) const
212   {
213 	  bb.Set(this->cP(0));
214 	  bb.Add(this->cP(1));
215 	  bb.Add(this->cP(2));
216 	  bb.Add(this->cP(3));
217   }
218 
219 
220 };
221 
222 // template < typename T=int>
223 // class TetraDefaultDeriver : public T {};
224 
225 /*
226 
227 These are the three main classes that are used by the library user to define its own Facees.
228 The user MUST specify the names of all the type involved in a generic complex.
229 so for example when defining a Face of a trimesh you must know the name of the type of the edge and of the face.
230 Typical usage example:
231 
232 A Face with coords, flags and normal for use in a standard trimesh:
233 
234 class MyFaceNf   : public FaceSimp2< VertProto, EdgeProto, MyFaceNf, face::Flag, face::Normal3f  > {};
235 
236 
237 A Face with coords, and normal for use in a tetrahedral mesh AND in a standard trimesh:
238 
239 class TetraFace   : public FaceSimp3< VertProto, EdgeProto, TetraFace, TetraProto, face::Coord3d, face::Normal3f  > {};
240 
241 
242 A summary of the components that can be added to a face (see components.h for details):
243 
244 VertexRef
245 Mark                                            //Incremental mark (int)
246 VTAdj                                           //Topology vertex face adjacency
247                                                  (pointers to next face in the ring of the vertex
248 TTAdj                                           //topology: face face adj
249                                                   pointers to adjacent faces
250 
251 */
252 
253 template <class UserTypes,
254           template <typename> class A = DefaultDeriver, template <typename> class B = DefaultDeriver,
255           template <typename> class C = DefaultDeriver, template <typename> class D = DefaultDeriver,
256           template <typename> class E = DefaultDeriver, template <typename> class F = DefaultDeriver,
257           template <typename> class G = DefaultDeriver, template <typename> class H = DefaultDeriver,
258           template <typename> class I = DefaultDeriver, template <typename> class J = DefaultDeriver,
259           template <typename> class K = DefaultDeriver, template <typename> class L = DefaultDeriver>
260 class TetraSimp : public TetraArityMax<UserTypes, A, B, C, D, E, F, G, H, I, J, K, L>  {
261 			 public: typedef AllTypes::ATetraType IAm; typedef UserTypes TypesPool;};
262 
263 }// end namespace
264 #endif
265 
266