VCG Library
vertex/component.h
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_COMPONENT
27 #define __VCG_VERTEX_PLUS_COMPONENT
28 
29 namespace vcg {
30 namespace vertex {
35 /*------------------------- Base Classes -----------------------------------------*/
36 
37  template <class S>
38  struct CurvatureDirBaseType{
39  typedef Point3<S> VecType;
40  typedef S ScalarType;
41  CurvatureDirBaseType () {}
42  Point3<S>max_dir,min_dir; // max and min curvature direction
43  S k1,k2;// max and min curvature values
44  };
45 
46 /*------------------------- EMPTY CORE COMPONENTS -----------------------------------------*/
47 
48 template <class TT> class EmptyCore: public TT {
49 public:
50  typedef int FlagType;
51  int &Flags() { assert(0); static int dummyflags(0); return dummyflags; }
52  int cFlags() const { return 0; }
53  static bool HasFlags() { return false; }
54 
55  typedef vcg::Point3f CoordType;
56  typedef CoordType::ScalarType ScalarType;
57  CoordType &P() { assert(0); static CoordType coord(0, 0, 0); return coord; }
58  CoordType cP() const { assert(0); static CoordType coord(0, 0, 0); assert(0); return coord; }
59  static bool HasCoord() { return false; }
60  inline bool IsCoordEnabled() const { return TT::VertexType::HasCoord();}
61 
62  typedef vcg::Point3s NormalType;
63  NormalType &N() { assert(0); static NormalType dummy_normal(0, 0, 0); return dummy_normal; }
64  NormalType cN() const { assert(0); static NormalType dummy_normal(0, 0, 0); return dummy_normal; }
65  static bool HasNormal() { return false; }
66  inline bool IsNormalEnabled() const { return TT::VertexType::HasNormal();}
67 
68  typedef float QualityType;
69  QualityType &Q() { assert(0); static QualityType dummyQuality(0); return dummyQuality; }
70  QualityType cQ() const { assert(0); static QualityType dummyQuality(0); return dummyQuality; }
71  static bool HasQuality() { return false; }
72  inline bool IsQualityEnabled() const { return TT::VertexType::HasQuality();}
73 
74  typedef vcg::Color4b ColorType;
75  ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; }
76  ColorType cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; }
77  static bool HasColor() { return false; }
78  inline bool IsColorEnabled() const { return TT::VertexType::HasColor();}
79 
80  typedef int MarkType;
81  void InitIMark() { }
82  int cIMark() const { assert(0); static int tmp=-1; return tmp;}
83  int &IMark() { assert(0); static int tmp=-1; return tmp;}
84  static bool HasMark() { return false; }
85  inline bool IsMarkEnabled() const { return TT::VertexType::HasMark();}
86 
87  typedef ScalarType RadiusType;
88  RadiusType &R() { static ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; }
89  RadiusType cR() const { static const ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; }
90  static bool HasRadius() { return false; }
91  inline bool IsRadiusEnabled() const { return TT::VertexType::HasRadius();}
92 
93  typedef vcg::TexCoord2<float,1> TexCoordType;
94  TexCoordType &T() { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; }
95  TexCoordType cT() const { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; }
96  static bool HasTexCoord() { return false; }
97  inline bool IsTexCoordEnabled() const { return TT::VertexType::HasTexCoord();}
98 
99  typename TT::TetraPointer &VTp() { static typename TT::TetraPointer tp = 0; assert(0); return tp; }
100  typename TT::TetraPointer cVTp() const { static typename TT::TetraPointer tp = 0; assert(0); return tp; }
101  int &VTi() { static int z = 0; assert(0); return z; }
102  int cVTi() const { static int z = 0; assert(0); return z; }
103  static bool HasVTAdjacency() { return false; }
104  bool IsVTInitialized() const {return static_cast<const typename TT::VertexType *>(this)->cVTi()!=-1;}
105  void VTClear() {
106  if(IsVTInitialized()) {
107  static_cast<typename TT::VertexPointer>(this)->VTp()=0;
108  static_cast<typename TT::VertexPointer>(this)->VTi()=-1;
109  }
110  }
111 
112  typename TT::FacePointer &VFp() { static typename TT::FacePointer fp=0; assert(0); return fp; }
113  typename TT::FacePointer cVFp() const { static typename TT::FacePointer fp=0; assert(0); return fp; }
114  int &VFi() { static int z=-1; assert(0); return z;}
115  int cVFi() const { static int z=-1; assert(0); return z;}
116  bool IsNull() const { return true; }
117  static bool HasVFAdjacency() { return false; }
118  bool IsVFInitialized() const {return static_cast<const typename TT::VertexType *>(this)->cVFi()!=-1;}
119  void VFClear() {
120  if(IsVFInitialized()) {
121  static_cast<typename TT::VertexPointer>(this)->VFp()=0;
122  static_cast<typename TT::VertexPointer>(this)->VFi()=-1;
123  }
124  }
125 
126  typename TT::EdgePointer &VEp() { static typename TT::EdgePointer ep=0; assert(0); return ep; }
127  typename TT::EdgePointer cVEp() const { static typename TT::EdgePointer ep=0; assert(0); return ep; }
128  int &VEi() { static int z=-1; return z;}
129  int cVEi() const { static int z=-1; return z;}
130  static bool HasVEAdjacency() { return false; }
131  bool IsVEInitialized() const {return static_cast<const typename TT::VertexType *>(this)->cVEi()!=-1;}
132  void VEClear() {
133  if(IsVEInitialized()) {
134  static_cast<typename TT::VertexPointer>(this)->VEp()=0;
135  static_cast<typename TT::VertexPointer>(this)->VEi()=-1;
136  }
137  }
138  typename TT::HEdgePointer &VHp() { static typename TT::HEdgePointer ep=0; assert(0); return ep; }
139  typename TT::HEdgePointer cVHp() const { static typename TT::HEdgePointer ep=0; assert(0); return ep; }
140  int &VHi() { static int z=0; return z;}
141  int cVHi() const { static int z=0; return z;}
142  static bool HasVHAdjacency() { return false; }
143 
144  typedef float CurScalarType;
145  typedef float ScalarTypeCur;
146  typedef Point3f CurVecType;
147  typedef Point2f CurvatureType;
148  float &Kh() { static float dummy = 0.f; assert(0);return dummy;}
149  float &Kg() { static float dummy = 0.f; assert(0);return dummy;}
150  float cKh() const { static float dummy = 0.f; assert(0); return dummy;}
151  float cKg() const { static float dummy = 0.f; assert(0); return dummy;}
152 
153  typedef CurvatureDirBaseType<float> CurvatureDirType;
154  CurVecType &PD1() {static CurVecType v(0,0,0); assert(0);return v;}
155  CurVecType &PD2() {static CurVecType v(0,0,0); assert(0);return v;}
156  CurVecType cPD1() const {static CurVecType v(0,0,0); assert(0);return v;}
157  CurVecType cPD2() const {static CurVecType v(0,0,0); assert(0);return v;}
158 
159  CurScalarType &K1() { static ScalarType v = 0.0;assert(0);return v;}
160  CurScalarType &K2() { static ScalarType v = 0.0;assert(0);return v;}
161  CurScalarType cK1() const {static ScalarType v = 0.0;assert(0);return v;}
162  CurScalarType cK2() const {static ScalarType v = 0.0;assert(0);return v;}
163 
164  static bool HasCurvature() { return false; }
165  static bool HasCurvatureDir() { return false; }
166  inline bool IsCurvatureEnabled() const { return TT::VertexType::HasCurvature();}
167  inline bool IsCurvatureDirEnabled() const { return TT::VertexType::HasCurvatureDir();}
168 
169  template < class RightValueType>
170  void ImportData(const RightValueType & /*rVert*/ ) {
171 // TT::ImportData( rVert);
172  }
173  static void Name(std::vector<std::string> & name){TT::Name(name);}
174 };
175 
176 /*-------------------------- COORD ----------------------------------------*/
181 template <class A, class T> class Coord: public T {
182 public:
183  typedef A CoordType;
184  typedef typename A::ScalarType ScalarType;
186  inline const CoordType &P() const { return _coord; }
188  inline CoordType &P() { return _coord; }
190  inline CoordType cP() const { return _coord; }
191 
192  template < class RightValueType>
193  void ImportData(const RightValueType & rVert ) { if(rVert.IsCoordEnabled()) P().Import(rVert.cP()); T::ImportData( rVert); }
194  static bool HasCoord() { return true; }
195  static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord"));T::Name(name);}
196 
197 private:
198  CoordType _coord;
199 };
201 template <class T> class Coord3f: public Coord<vcg::Point3f, T> {
202 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3f"));T::Name(name);}
203 };
205 template <class T> class Coord3d: public Coord<vcg::Point3d, T> {
206 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3d"));T::Name(name);}
207 };
208 
209 /*-------------------------- NORMAL ----------------------------------------*/
221 template <class A, class T> class Normal: public T {
222 public:
223  typedef A NormalType;
225  inline const NormalType &N() const { return _norm; }
227  inline NormalType &N() { return _norm; }
229  inline NormalType cN() const { return _norm; }
230  template < class RightValueType>
231  void ImportData(const RightValueType & rVert ){
232  if(rVert.IsNormalEnabled()) N().Import(rVert.cN());
233  T::ImportData( rVert);
234  }
235  static bool HasNormal() { return true; }
236  static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal"));T::Name(name);}
237 
238 private:
239  NormalType _norm;
240 };
241 
242 template <class T> class Normal3s: public Normal<vcg::Point3s, T> {
243 public:static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3s"));T::Name(name);}
244 };
246 template <class T> class Normal3f: public Normal<vcg::Point3f, T> {
247 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3f"));T::Name(name);}
248 };
250 template <class T> class Normal3d: public Normal<vcg::Point3d, T> {
251 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3d"));T::Name(name);}
252 };
253 
254 
255 /*-------------------------- INCREMENTAL MARK ----------------------------------------*/
261 template <class T> class Mark: public T {
262 public:
263  Mark():_imark(0){}
265  inline const int &IMark() const { return _imark;}
267  inline int &IMark() { return _imark;}
269  inline int cIMark() const { return _imark;}
270  static bool HasMark() { return true; }
271  inline void InitIMark() { _imark = 0; }
272  template < class RightValueType>
273  void ImportData(const RightValueType & rVert ) { if(rVert.IsMarkEnabled()) IMark() = rVert.cIMark(); T::ImportData( rVert); }
274  static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);}
275 
276  private:
277  int _imark;
278 };
279 
280 /*-------------------------- TEXCOORD ----------------------------------------*/
294 template <class A, class TT> class TexCoord: public TT {
295 public:
296  typedef A TexCoordType;
297 
299  const TexCoordType &T() const { return _t; }
300  TexCoordType &T() { return _t; }
301  TexCoordType cT() const { return _t; }
302  template < class RightValueType>
303  void ImportData(const RightValueType & rVert ) { if(rVert.IsTexCoordEnabled()) T() = rVert.cT(); TT::ImportData( rVert); }
304  static bool HasTexCoord() { return true; }
305  static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord"));TT::Name(name);}
306 
307 private:
308  TexCoordType _t;
309 };
310 
311 
312 template <class TT> class TexCoord2s: public TexCoord<TexCoord2<short,1>, TT> {
313 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord2s"));TT::Name(name);}
314 };
316 template <class TT> class TexCoord2f: public TexCoord<TexCoord2<float,1>, TT> {
317 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord2f"));TT::Name(name);}
318 };
320 template <class TT> class TexCoord2d: public TexCoord<TexCoord2<double,1>, TT> {
321 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord2d"));TT::Name(name);}
322 };
323 
324 /*------------------------- FLAGS -----------------------------------------*/
331 template <class T> class BitFlags: public T {
332 public:
333  BitFlags(){_flags=0;}
334  typedef int FlagType;
335  inline const int &Flags() const {return _flags; }
336  inline int &Flags() {return _flags; }
337  inline int cFlags() const {return _flags; }
338  template < class RightValueType>
339  void ImportData(const RightValueType & rVert ) { if(RightValueType::HasFlags()) Flags() = rVert.cFlags(); T::ImportData( rVert); }
340  static bool HasFlags() { return true; }
341  static void Name(std::vector<std::string> & name){name.push_back(std::string("BitFlags"));T::Name(name);}
342 
343 private:
344  int _flags;
345 };
346 
347 
348 /*-------------------------- Color ----------------------------------*/
354 template <class A, class T> class Color: public T {
355 public:
356  Color():_color(vcg::Color4b::White) {}
357  typedef A ColorType;
358  inline const ColorType &C() const { return _color; }
359  inline ColorType &C() { return _color; }
360  inline ColorType cC() const { return _color; }
361  template < class RightValueType>
362  void ImportData(const RightValueType & rVert ) { if(rVert.IsColorEnabled()) C() = rVert.cC(); T::ImportData( rVert); }
363  static bool HasColor() { return true; }
364  static void Name(std::vector<std::string> & name){name.push_back(std::string("Color"));T::Name(name);}
365 
366 private:
367  ColorType _color;
368 };
369 
370 template <class TT> class Color4b: public Color<vcg::Color4b, TT> {
371  public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Color4b"));TT::Name(name);}
372 };
373 
374 /*-------------------------- Quality ----------------------------------*/
382 template <class A, class TT> class Quality: public TT {
383 public:
384  typedef A QualityType;
385  Quality():_quality(0) {}
386 
387  inline const QualityType &Q() const { return _quality; }
388  inline QualityType &Q() { return _quality; }
389  inline QualityType cQ() const {return _quality; }
390  template < class RightValueType>
391  void ImportData(const RightValueType & rVert ) { if(rVert.IsQualityEnabled()) Q() = rVert.cQ(); TT::ImportData( rVert); }
392  static bool HasQuality() { return true; }
393  static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality"));TT::Name(name);}
394 
395 private:
396  QualityType _quality;
397 };
398 
399 template <class TT> class Qualitys: public Quality<short, TT> {
400 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualitys"));TT::Name(name);}
401 };
402 template <class TT> class Qualityf: public Quality<float, TT> {
403 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityf"));TT::Name(name);}
404 };
405 template <class TT> class Qualityd: public Quality<double, TT> {
406 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityd"));TT::Name(name);}
407 };
408 
409  /*-------------------------- Curvature ----------------------------------*/
410 
414  template <class A, class TT> class Curvature: public TT {
415  public:
416  typedef Point2<A> CurvatureType;
417  typedef typename CurvatureType::ScalarType ScalarTypeCur;
418  const ScalarTypeCur &Kh() const { return _hk[0]; }
419  const ScalarTypeCur &Kg() const { return _hk[1]; }
420  ScalarTypeCur &Kh() { return _hk[0]; }
421  ScalarTypeCur &Kg() { return _hk[1]; }
422  ScalarTypeCur cKh() const { return _hk[0]; }
423  ScalarTypeCur cKg() const { return _hk[1]; }
424 
425  template < class RightValueType>
426  void ImportData(const RightValueType & rVert ) {
427  if(rVert.IsCurvatureEnabled()) {
428  Kh() = rVert.cKh();
429  Kg() = rVert.cKg();
430  }
431  TT::ImportData( rVert);
432  }
433 
434  static bool HasCurvature() { return true; }
435  static void Name(std::vector<std::string> & name){name.push_back(std::string("Curvature"));TT::Name(name);}
436 
437  private:
438  Point2<A> _hk;
439  };
440 
441 
442  template <class T> class Curvaturef: public Curvature< float, T> {
443  public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Curvaturef"));T::Name(name);}
444  };
445  template <class T> class Curvatured: public Curvature<double , T> {
446  public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Curvatured"));T::Name(name);}
447  };
448 
449 /*-------------------------- Curvature Direction ----------------------------------*/
450 
455 template <class A, class TT> class CurvatureDir: public TT {
456 public:
457  typedef A CurvatureDirType;
458  typedef typename CurvatureDirType::VecType CurVecType;
459  typedef typename CurvatureDirType::ScalarType CurScalarType;
460 
461  CurVecType &PD1(){ return _curv.max_dir; }
462  CurVecType &PD2(){ return _curv.min_dir; }
463  const CurVecType &cPD1() const { return _curv.max_dir; }
464  const CurVecType &cPD2() const { return _curv.min_dir; }
465 
466  CurScalarType &K1(){ return _curv.k1; }
467  CurScalarType &K2(){ return _curv.k2; }
468  const CurScalarType &cK1() const { return _curv.k1; }
469  const CurScalarType &cK2() const { return _curv.k2; }
470  template < class RightValueType>
471  void ImportData(const RightValueType & rVert ) {
472  if(rVert.IsCurvatureDirEnabled()) {
473  PD1().Import(rVert.cPD1());
474  PD2().Import(rVert.cPD2());
475  K1() = rVert.cK1(); K2() = rVert.cK2();
476  }
477  TT::ImportData( rVert);
478  }
479 
480  static bool HasCurvatureDir() { return true; }
481  static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDir"));TT::Name(name);}
482 
483 private:
484  CurvatureDirType _curv;
485 };
486 
487 
488 template <class T> class CurvatureDirf: public CurvatureDir<CurvatureDirBaseType<float>, T> {
489 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDirf"));T::Name(name);}
490 };
491 template <class T> class CurvatureDird: public CurvatureDir<CurvatureDirBaseType<double>, T> {
492 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDird"));T::Name(name);}
493 };
494 
495 /*-------------------------- Radius ----------------------------------*/
500  template <class A, class TT> class Radius: public TT {
501  public:
502  typedef A RadiusType;
503  const RadiusType &R() const { return _radius; }
504  RadiusType &R() { return _radius; }
505  RadiusType cR() const {return _radius; }
506  template < class RightValueType>
507  void ImportData(const RightValueType & rVert ) { if(rVert.IsRadiusEnabled()) R() = rVert.cR(); TT::ImportData( rVert); }
508  static bool HasRadius() { return true; }
509  static void Name(std::vector<std::string> & name){name.push_back(std::string("Radius"));TT::Name(name);}
510 
511  private:
512  RadiusType _radius;
513  };
514 
515 template <class TT> class Radiusf: public Radius<float, TT> {
516 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Radiusf"));TT::Name(name);}
517 };
518 
519 
520 /*----------------------------- VEADJ ------------------------------*/
528 template <class T> class VEAdj: public T {
529 public:
530  VEAdj(){_ep=0;_zp=-1;}
531  typename T::EdgePointer &VEp() {return _ep; }
532  typename T::EdgePointer cVEp() const {return _ep; }
533  int &VEi() {return _zp; }
534  int cVEi() const {return _zp; }
535  template < class RightValueType>
536  void ImportData(const RightValueType & rVert ) { T::ImportData( rVert); }
537  static bool HasVEAdjacency() { return true; }
538  static void Name(std::vector<std::string> & name){name.push_back(std::string("VEAdj"));T::Name(name);}
539 
540 private:
541  typename T::EdgePointer _ep ;
542  int _zp ;
543 };
544 
545 /*----------------------------- VFADJ ------------------------------*/
556  template <class T> class VFAdj: public T {
557  public:
558  VFAdj(){_fp=0;_zp=-1;}
559  typename T::FacePointer &VFp() { return _fp; }
560  typename T::FacePointer cVFp() const { return _fp; }
561  int &VFi() { return _zp; }
562  int cVFi() const { return _zp; }
563  bool IsNull() const { return _zp==-1;}
564  template < class RightValueType>
565  void ImportData(const RightValueType & rVert ) { T::ImportData( rVert); }
566  static bool HasVFAdjacency() { return true; }
567  static void Name(std::vector<std::string> & name){name.push_back(std::string("VFAdj"));T::Name(name);}
568 
569  private:
570  typename T::FacePointer _fp ;
571  int _zp ;
572  };
573 
574 /*----------------------------- VHADJ ------------------------------*/
575 
576 template <class T> class VHAdj: public T {
577 public:
578  VHAdj(){_hp=0;_zp=-1;}
579  typename T::HEdgePointer &VHp() {return _hp; }
580  typename T::HEdgePointer cVHp() const {return _hp; }
581  int &VHi() {return _zp; }
582  template < class RightValueType>
583  void ImportData(const RightValueType & rVert ) { T::ImportData( rVert); }
584  static bool HasVHAdjacency() { return true; }
585  static void Name(std::vector<std::string> & name){name.push_back(std::string("VHAdj"));T::Name(name);}
586 
587 private:
588  typename T::HEdgePointer _hp ;
589  int _zp ;
590 };
591 
592 /*----------------------------- VTADJ ------------------------------*/
593 
594 template <class T> class VTAdj: public T {
595 public:
596  VTAdj() { _tp = 0; _zp=-1;}
597  typename T::TetraPointer &VTp() { return _tp; }
598  typename T::TetraPointer cVTp() const { return _tp; }
599  int &VTi() {return _zp; }
600  int cVTi() const { return _zp; }
601  static bool HasVTAdjacency() { return true; }
602  static void Name( std::vector< std::string > & name ) { name.push_back( std::string("VTAdj") ); T::Name(name); }
603 
604 private:
605  typename T::TetraPointer _tp ;
606  int _zp ;
607 };
608  // End Doxygen VertexComponentGroup
610  } // end namespace vert
611 }// end namespace vcg
612 #endif