File: component.h

package info (click to toggle)
meshlab 2020.09%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 45,132 kB
  • sloc: cpp: 400,238; ansic: 31,952; javascript: 1,578; sh: 387; yacc: 238; lex: 139; python: 86; makefile: 30
file content (373 lines) | stat: -rw-r--r-- 16,501 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/****************************************************************************
* VCGLib                                                            o o     *
* Visual and Computer Graphics Library                            o     o   *
*                                                                _   O  _   *
* Copyright(C) 2004-2016                                           \/)\/    *
* 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_MESH
#error "This file should not be included alone. It is automatically included by complex.h"
#endif
#ifndef __VCG_EDGE_PLUS_COMPONENT
#define __VCG_EDGE_PLUS_COMPONENT

namespace vcg {
namespace edge {

/** \addtogroup EdgeComponentGroup
	@{
  */

/*
Some naming Rules
All the Components that can be added to a vertex should be defined in the namespace edge:

*/
/*------------------------- EMPTY CORE COMPONENTS -----------------------------------------*/

template <class T> class EmptyCore: public T
{
public:
	inline       typename T::VertexType *       &  V( const int j )       { (void)j; assert(0);  static typename T::VertexType *vp=0;         return vp;    }
	inline       typename T::VertexType * const &  V( const int j ) const { (void)j; assert(0);  static typename T::VertexType *vp=0;         return vp;    }
	inline       typename T::VertexType *         cV( const int j ) const { (void)j; assert(0);  static typename T::VertexType *vp=0;         return vp;    }
	inline       typename T::CoordType &           P( const int j )       { (void)j; assert(0);  static typename T::CoordType coord(0, 0, 0); return coord; }
	inline const typename T::CoordType &           P( const int j ) const { (void)j; assert(0);  static typename T::CoordType coord(0, 0, 0); return coord; }
	inline const typename T::CoordType &          cP( const int j ) const { (void)j; assert(0);  static typename T::CoordType coord(0, 0, 0); return coord; }
	static bool HasEVAdjacency()   { return false; }
	static bool HasVertexRef()     { return false; }

	typedef vcg::Color4b ColorType;
	ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; }
	ColorType cC() const { static ColorType dumcolor(vcg::Color4b::White);  assert(0); return dumcolor; }
	static bool HasColor()   { return false; }

	typedef float QualityType;
	QualityType &Q() { static QualityType dummyQuality(0);  assert(0); return dummyQuality; }
	QualityType cQ() const { static QualityType dummyQuality(0);  assert(0); return dummyQuality; }
	static bool HasQuality()   { return false; }

	typedef int  MarkType;
	inline void InitIMark()    {  }
	inline int cIMark() const { assert(0); static int tmp=-1; return tmp;}
	inline int &IMark()       { assert(0); static int tmp=-1; return tmp;}
	static bool HasMark()   { return false; }
	inline bool IsMarkEnabled( )         const { return T::EdgeType::HasMark(); }


	typedef int FlagType;
	int &Flags() { static int dummyflags(0);  assert(0); return dummyflags; }
	int Flags() const { return 0; }
	static bool HasFlags()   { return false; }

	typename T::EdgePointer &VEp(const int &  ) { static typename T::EdgePointer ep=0;  assert(0); return ep; }
	typename T::EdgePointer cVEp(const int & ) const { static typename T::EdgePointer ep=0;  assert(0); return ep; }
	int &VEi(const int &){static int z=0; assert(0); return z;}
	int cVEi(const int &) const {static int z=0; assert(0); return z;}
	static bool HasVEAdjacency()   {   return false; }

	typename T::EdgePointer &EEp(const int &  ) { static typename T::EdgePointer ep=0;  assert(0); return ep; }
	typename T::EdgePointer cEEp(const int & ) const { static typename T::EdgePointer ep=0;  assert(0); return ep; }
	int &EEi(const int &){static int z=0; assert(0); return z;}
	int cEEi(const int &) const {static int z=0; assert(0); return z;}
	static bool HasEEAdjacency()   {   return false; }

	typename T::HEdgePointer &EHp(  ) { static typename T::HEdgePointer hp=0;  assert(0); return hp; }
	typename T::HEdgePointer cEHp(  ) const { static typename T::HEdgePointer hp=0;  assert(0); return hp; }
	static bool HasEHAdjacency()   {   return false; }

	typename T::FacePointer &EFp() { static typename T::FacePointer fp=0;  assert(0); return fp; }
	typename T::FacePointer cEFp() const  { static typename T::FacePointer fp=0;  assert(0); return fp; }
	int &EFi()   {static int z=0; return z;}
	int &cEFi() const {static int z=0; return z;}
	static bool HasEFAdjacency()   {   return false; }

	template <class LeftF>
	void ImportData(const LeftF & leftF) {T::ImportData(leftF);}
	static void Name(std::vector<std::string> & name){T::Name(name);}
};

/*-------------------------- VertexRef ----------------------------------------*/
/*! \brief The references to the two vertexes of a edge
   *
   * Stored as pointers to the VertexType
   */

template <class T> class VertexRef: public T {
public:
	VertexRef(){
		v[0]=0;
		v[1]=0;
	}

	typedef typename T::VertexType::CoordType CoordType;
	typedef typename T::VertexType::ScalarType ScalarType;

	inline typename T::VertexType *       & V( const int j ) 	     { assert(j>=0 && j<2); return v[j]; }
	inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<2); return v[j]; }
	inline typename T::VertexType *  cV( const int j ) const { assert(j>=0 && j<2);	return v[j]; }

	// Shortcut per accedere ai punti delle facce
	inline       CoordType & P( const int j ) 	    {	assert(j>=0 && j<2);		return v[j]->P();	}
	inline const CoordType &cP( const int j ) const	{	assert(j>=0 && j<2);		return v[j]->P(); }

	/** Return the pointer to the ((j+1)%3)-th vertex of the face.
		@param j Index of the face vertex.
	 */
	inline       typename T::VertexType *       &  V0( const int j )       { return V(j);}
	inline       typename T::VertexType *       &  V1( const int j )       { return V((j+1)%2);}
	inline const typename T::VertexType * const &  V0( const int j ) const { return V(j);}
	inline const typename T::VertexType * const &  V1( const int j ) const { return V((j+1)%2);}
	inline const typename T::VertexType * const & cV0( const int j ) const { return cV(j);}
	inline const typename T::VertexType * const & cV1( const int j ) const { return cV((j+1)%2);}

	/// Shortcut per accedere ai punti delle facce
	inline       CoordType &  P0( const int j )       { return V(j)->P();}
	inline       CoordType &  P1( const int j )       { return V((j+1)%2)->P();}
	inline const CoordType &  P0( const int j ) const { return V(j)->P();}
	inline const CoordType &  P1( const int j ) const { return V((j+1)%2)->P();}
	inline const CoordType & cP0( const int j ) const { return cV(j)->P();}
	inline const CoordType & cP1( const int j ) const { return cV((j+1)%2)->P();}

	template <class LeftF>
	void ImportData(const LeftF & leftF){ T::ImportData(leftF);}

	static bool HasEVAdjacency()   {   return true; }
	static bool HasVertexRef()   { return true; }
	static void Name(std::vector<std::string> & name){name.push_back(std::string("VertexRef"));T::Name(name);}


private:
	typename T::VertexType *v[2];
};

template <class T> class EVAdj : public VertexRef<T>{};


/*-------------------------- INCREMENTAL MARK  ----------------------------------------*/

/*! \brief \em Component: Per edge \b Incremental \b Mark
 *
 * An int that allows to efficently un-mark the whole mesh. \sa UnmarkAll
 */
template <class T> class Mark: public T {
public:
	Mark():_imark(0){}
	static bool HasMark()      { return true; }
	static bool HasMarkOcc()   { return true; }
	inline void InitIMark()    { _imark = 0; }
	inline int & IMark()       { return _imark;}
	inline int cIMark() const  { return _imark;}

	template < class RightValueType>
	void ImportData(const RightValueType & rightE )
	{
		if(rightE.IsMarkEnabled())
			IMark() = rightE.cIMark();
		T::ImportData(rightE);
	}
	static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);}

private:
	int _imark;
};

/*------------------------- FLAGS -----------------------------------------*/
/*! \brief \em Component: Per edge \b Flags
   *
   * This component stores a 32 bit array of bit flags. These bit flags are used for keeping track of selection, deletion, visiting etc. \sa \ref flags for more details on common uses of flags.
   */
template <class T> class BitFlags:  public T {
public:
	BitFlags(){_flags=0;}
	typedef int FlagType;
	int &Flags() {return _flags; }
	int Flags() const {return _flags; }
	template < class LeftV>
	void ImportData(const LeftV  & left ) { Flags() = left.Flags(); T::ImportData( left); }
	static bool HasFlags()   { return true; }
	static void Name(std::vector<std::string> & name){name.push_back(std::string("BitFlags"));T::Name(name);}

private:
	int  _flags;
};

/*-------------------------- Color  ----------------------------------*/
/*! \brief \em Component: Per edge \b Color
   *
   * Usually most of the library expects a color stored as 4 unsigned chars (so the component you use is a \c vertex::Color4b)
   * but you can also use float for the color components.
   */
template <class A, class T> class Color: public T {
public:
	Color():_color(vcg::Color4b::White) {}
	typedef A ColorType;
	ColorType &C() { return _color; }
	const ColorType &C() const { return _color; }
	const ColorType &cC() const { return _color; }
	template < class LeftV>
	void ImportData(const LeftV  & left ) { C() = left.cC(); T::ImportData( left); }
	static bool HasColor()   { return true; }
	static void Name(std::vector<std::string> & name){name.push_back(std::string("Color"));T::Name(name);}

private:
	ColorType _color;
};

template <class TT> class Color4b: public edge::Color<vcg::Color4b, TT> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Color4b"));TT::Name(name);}
};

/*-------------------------- Quality  ----------------------------------*/
/*! \brief \em Component: Per edge \b quality
   *
   * The Quality Component is a generic place for storing a float. The term 'quality' is a bit misleading and it is due to its original storic meaning. You should intend it as a general purpose container.
   * \sa vcg::tri::UpdateColor for methods transforming quality into colors
   * \sa vcg::tri::UpdateQuality for methods to manage it
   */
template <class A, class TT> class Quality: public TT {
public:
	typedef A QualityType;
	QualityType &Q() { return _quality; }
	const QualityType & cQ() const {return _quality; }
	template < class LeftV>
	void ImportData(const LeftV  & left ) { Q() = left.cQ(); TT::ImportData( left); }
	static bool HasQuality()   { return true; }
	static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality"));TT::Name(name);}

private:
	QualityType _quality;
};

template <class TT> class Qualitys: public Quality<short, TT> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualitys"));TT::Name(name);}
};
template <class TT> class Qualityf: public Quality<float, TT> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityf"));TT::Name(name);}
};
template <class TT> class Qualityd: public Quality<double, TT> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityd"));TT::Name(name);}
};

/*----------------------------- VEADJ ------------------------------*/
/*! \brief \em Component: Per vertex \b Vertex-Edge adjacency relation companion component
  This component implement one element of the list of edges incident on a vertex.
  You must use this component only toghether with the corresponding \ref vcg::vertex::VEAdj component in the vertex type

  \sa vcg::tri::UpdateTopology for functions that compute this relation
  \sa iterators
  */
template <class T> class VEAdj: public T {
public:
	VEAdj(){_ep[0]=0;_ep[1]=0;_zp[0]=-1;_zp[1]=-1;}
	typename T::EdgePointer &VEp(const int & i) {return _ep[i]; }
	typename T::EdgePointer cVEp(const int & i) const {return _ep[i]; }
	int &VEi(const int & i){ return _zp[i];}
	int cVEi(const int &i )const {return _zp[i];}

	template < class LeftV>
	void ImportData(const LeftV  & left ) {  T::ImportData( left); }
	static bool HasVEAdjacency()   {   return true; }
	static bool HasVEAdjacencyOcc()   {   return true; }
	static void Name(std::vector<std::string> & name){name.push_back(std::string("VEAdj"));T::Name(name);}

private:
	typename T::EdgePointer _ep[2] ;
	int _zp[2] ;
};

/*----------------------------- EEADJ ------------------------------*/
/*! \brief \em Component: \b Edge-Edge adjacency relation
  This component implement store the pointer (and index) of the adjacent edges.
  If the vertex is 1-manifold (as in a classical polyline)
  it holds that:
  \code
   e->EEp(i)->EEp(e->EEi(i)) == e
  \endcode
  otherwise the edges are connected in a unordered chain (quite similar to how Face-Face adjacency relation is stored);

  \sa vcg::tri::UpdateTopology for functions that compute this relation
  \sa iterators
  */

template <class T> class EEAdj: public T {
public:
	EEAdj(){_ep[0]=0;_ep[1]=0;_zp[0]=-1;_zp[1]=-1;}
	typename T::EdgePointer &EEp(const int & i) {return _ep[i]; }
	typename T::EdgePointer cEEp(const int & i) const {return _ep[i]; }
	int &EEi(const int & i){ return _zp[i];}
	int cEEi(const int &i )const {return _zp[i];}

	template < class LeftV>
	void ImportData(const LeftV  & left ) {  T::ImportData( left); }
	static bool HasEEAdjacency()   {   return true; }
	static bool HasEEAdjacencyOcc()   {   return true; }
	static void Name(std::vector<std::string> & name){name.push_back(std::string("EEAdj"));T::Name(name);}

private:
	typename T::EdgePointer _ep[2] ;
	int _zp[2] ;
};

/*----------------------------- EHADJ ------------------------------*/
template <class T> class EHAdj: public T {
public:
	EHAdj(){_hp=0;}
	typename T::HEdgePointer &EHp( ) {return _hp ; }
	const typename T::HEdgePointer cEHp( ) const {return _hp ; }

	template < class LeftV>
	void ImportData(const LeftV  & left ) { T::ImportData( left); }
	static bool HasEHAdjacency()   {   return true; }
	static bool HasEHAdjacencyOcc()   {   return true; }
	static void Name(std::vector<std::string> & name){name.push_back(std::string("EHAdj"));T::Name(name);}

private:
	typename T::HEdgePointer _hp ;
};

/*----------------------------- EFADJ ------------------------------*/
/*! \brief \em Component: \b Edge-Face adjacency relation
  This component implement store the pointer to a face sharing this edge.

  \sa vcg::tri::UpdateTopology for functions that compute this relation
  \sa iterators
  */

template <class T> class EFAdj: public T {
public:
	EFAdj(){_fp=0;}
	typename T::FacePointer &EFp()       {return _fp; }
	typename T::FacePointer cEFp() const {return _fp; }
	int &EFi()        {return _zp; }
	int cEFi() const  {return _zp; }
	template < class LeftV>
	void ImportData(const LeftV  & left ) {  T::ImportData( left); }
	static bool HasEFAdjacency()      {   return true; }
	static bool HasEFAdjacencyOcc()   {   return true; }
	static void Name(std::vector<std::string> & name){name.push_back(std::string("EFAdj"));T::Name(name);}

private:
	typename T::FacePointer _fp ;
	int _zp ;
};

/** @} */   // End Doxygen EdgeComponentGroup
} // end namespace edge
}// end namespace vcg
#endif