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; return z; }
102  static bool HasVTAdjacency() { return false; }
103 
104  typename TT::FacePointer &VFp() { static typename TT::FacePointer fp=0; assert(0); return fp; }
105  typename TT::FacePointer cVFp() const { static typename TT::FacePointer fp=0; assert(0); return fp; }
106  int &VFi() { static int z=-1; assert(0); return z;}
107  int cVFi() const { static int z=-1; assert(0); return z;}
108  bool IsNull() const { return true; }
109  static bool HasVFAdjacency() { return false; }
110  bool IsVFInitialized() const {return static_cast<const typename TT::VertexType *>(this)->cVFi()!=-1;}
111  void VFClear() {
112  if(IsVFInitialized()) {
113  static_cast<typename TT::VertexPointer>(this)->VFp()=0;
114  static_cast<typename TT::VertexPointer>(this)->VFi()=-1;
115  }
116  }
117 
118  typename TT::EdgePointer &VEp() { static typename TT::EdgePointer ep=0; assert(0); return ep; }
119  typename TT::EdgePointer cVEp() const { static typename TT::EdgePointer ep=0; assert(0); return ep; }
120  int &VEi() { static int z=-1; return z;}
121  int cVEi() const { static int z=-1; return z;}
122  static bool HasVEAdjacency() { return false; }
123  bool IsVEInitialized() const {return static_cast<const typename TT::VertexType *>(this)->cVEi()!=-1;}
124  void VEClear() {
125  if(IsVEInitialized()) {
126  static_cast<typename TT::VertexPointer>(this)->VEp()=0;
127  static_cast<typename TT::VertexPointer>(this)->VEi()=-1;
128  }
129  }
130  typename TT::HEdgePointer &VHp() { static typename TT::HEdgePointer ep=0; assert(0); return ep; }
131  typename TT::HEdgePointer cVHp() const { static typename TT::HEdgePointer ep=0; assert(0); return ep; }
132  int &VHi() { static int z=0; return z;}
133  int cVHi() const { static int z=0; return z;}
134  static bool HasVHAdjacency() { return false; }
135 
136  typedef float CurScalarType;
137  typedef float ScalarTypeCur;
138  typedef Point3f CurVecType;
139  typedef Point2f CurvatureType;
140  float &Kh() { static float dummy = 0.f; assert(0);return dummy;}
141  float &Kg() { static float dummy = 0.f; assert(0);return dummy;}
142  float cKh() const { static float dummy = 0.f; assert(0); return dummy;}
143  float cKg() const { static float dummy = 0.f; assert(0); return dummy;}
144 
145  typedef CurvatureDirBaseType<float> CurvatureDirType;
146  CurVecType &PD1() {static CurVecType v(0,0,0); assert(0);return v;}
147  CurVecType &PD2() {static CurVecType v(0,0,0); assert(0);return v;}
148  CurVecType cPD1() const {static CurVecType v(0,0,0); assert(0);return v;}
149  CurVecType cPD2() const {static CurVecType v(0,0,0); assert(0);return v;}
150 
151  CurScalarType &K1() { static ScalarType v = 0.0;assert(0);return v;}
152  CurScalarType &K2() { static ScalarType v = 0.0;assert(0);return v;}
153  CurScalarType cK1() const {static ScalarType v = 0.0;assert(0);return v;}
154  CurScalarType cK2() const {static ScalarType v = 0.0;assert(0);return v;}
155 
156  static bool HasCurvature() { return false; }
157  static bool HasCurvatureDir() { return false; }
158  inline bool IsCurvatureEnabled() const { return TT::VertexType::HasCurvature();}
159  inline bool IsCurvatureDirEnabled() const { return TT::VertexType::HasCurvatureDir();}
160 
161  template < class RightValueType>
162  void ImportData(const RightValueType & /*rVert*/ ) {
163 // TT::ImportData( rVert);
164  }
165  static void Name(std::vector<std::string> & name){TT::Name(name);}
166 };
167 
168 /*-------------------------- COORD ----------------------------------------*/
173 template <class A, class T> class Coord: public T {
174 public:
175  typedef A CoordType;
176  typedef typename A::ScalarType ScalarType;
178  inline const CoordType &P() const { return _coord; }
180  inline CoordType &P() { return _coord; }
182  inline CoordType cP() const { return _coord; }
183 
184  template < class RightValueType>
185  void ImportData(const RightValueType & rVert ) { if(rVert.IsCoordEnabled()) P().Import(rVert.cP()); T::ImportData( rVert); }
186  static bool HasCoord() { return true; }
187  static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord"));T::Name(name);}
188 
189 private:
190  CoordType _coord;
191 };
193 template <class T> class Coord3f: public Coord<vcg::Point3f, T> {
194 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3f"));T::Name(name);}
195 };
197 template <class T> class Coord3d: public Coord<vcg::Point3d, T> {
198 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3d"));T::Name(name);}
199 };
200 
201 /*-------------------------- NORMAL ----------------------------------------*/
213 template <class A, class T> class Normal: public T {
214 public:
215  typedef A NormalType;
217  inline const NormalType &N() const { return _norm; }
219  inline NormalType &N() { return _norm; }
221  inline NormalType cN() const { return _norm; }
222  template < class RightValueType>
223  void ImportData(const RightValueType & rVert ){
224  if(rVert.IsNormalEnabled()) N().Import(rVert.cN());
225  T::ImportData( rVert);
226  }
227  static bool HasNormal() { return true; }
228  static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal"));T::Name(name);}
229 
230 private:
231  NormalType _norm;
232 };
233 
234 template <class T> class Normal3s: public Normal<vcg::Point3s, T> {
235 public:static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3s"));T::Name(name);}
236 };
238 template <class T> class Normal3f: public Normal<vcg::Point3f, T> {
239 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3f"));T::Name(name);}
240 };
242 template <class T> class Normal3d: public Normal<vcg::Point3d, T> {
243 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3d"));T::Name(name);}
244 };
245 
246 
247 /*-------------------------- INCREMENTAL MARK ----------------------------------------*/
253 template <class T> class Mark: public T {
254 public:
255  Mark():_imark(0){}
257  inline const int &IMark() const { return _imark;}
259  inline int &IMark() { return _imark;}
261  inline int cIMark() const { return _imark;}
262  static bool HasMark() { return true; }
263  inline void InitIMark() { _imark = 0; }
264  template < class RightValueType>
265  void ImportData(const RightValueType & rVert ) { if(rVert.IsMarkEnabled()) IMark() = rVert.cIMark(); T::ImportData( rVert); }
266  static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);}
267 
268  private:
269  int _imark;
270 };
271 
272 /*-------------------------- TEXCOORD ----------------------------------------*/
286 template <class A, class TT> class TexCoord: public TT {
287 public:
288  typedef A TexCoordType;
289 
291  const TexCoordType &T() const { return _t; }
292  TexCoordType &T() { return _t; }
293  TexCoordType cT() const { return _t; }
294  template < class RightValueType>
295  void ImportData(const RightValueType & rVert ) { if(rVert.IsTexCoordEnabled()) T() = rVert.cT(); TT::ImportData( rVert); }
296  static bool HasTexCoord() { return true; }
297  static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord"));TT::Name(name);}
298 
299 private:
300  TexCoordType _t;
301 };
302 
303 
304 template <class TT> class TexCoord2s: public TexCoord<TexCoord2<short,1>, TT> {
305 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord2s"));TT::Name(name);}
306 };
308 template <class TT> class TexCoord2f: public TexCoord<TexCoord2<float,1>, TT> {
309 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord2f"));TT::Name(name);}
310 };
312 template <class TT> class TexCoord2d: public TexCoord<TexCoord2<double,1>, TT> {
313 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("TexCoord2d"));TT::Name(name);}
314 };
315 
316 /*------------------------- FLAGS -----------------------------------------*/
323 template <class T> class BitFlags: public T {
324 public:
325  BitFlags(){_flags=0;}
326  typedef int FlagType;
327  inline const int &Flags() const {return _flags; }
328  inline int &Flags() {return _flags; }
329  inline int cFlags() const {return _flags; }
330  template < class RightValueType>
331  void ImportData(const RightValueType & rVert ) { if(RightValueType::HasFlags()) Flags() = rVert.cFlags(); T::ImportData( rVert); }
332  static bool HasFlags() { return true; }
333  static void Name(std::vector<std::string> & name){name.push_back(std::string("BitFlags"));T::Name(name);}
334 
335 private:
336  int _flags;
337 };
338 
339 
340 /*-------------------------- Color ----------------------------------*/
346 template <class A, class T> class Color: public T {
347 public:
348  Color():_color(vcg::Color4b::White) {}
349  typedef A ColorType;
350  inline const ColorType &C() const { return _color; }
351  inline ColorType &C() { return _color; }
352  inline ColorType cC() const { return _color; }
353  template < class RightValueType>
354  void ImportData(const RightValueType & rVert ) { if(rVert.IsColorEnabled()) C() = rVert.cC(); T::ImportData( rVert); }
355  static bool HasColor() { return true; }
356  static void Name(std::vector<std::string> & name){name.push_back(std::string("Color"));T::Name(name);}
357 
358 private:
359  ColorType _color;
360 };
361 
362 template <class TT> class Color4b: public Color<vcg::Color4b, TT> {
363  public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Color4b"));TT::Name(name);}
364 };
365 
366 /*-------------------------- Quality ----------------------------------*/
374 template <class A, class TT> class Quality: public TT {
375 public:
376  typedef A QualityType;
377  Quality():_quality(0) {}
378 
379  inline const QualityType &Q() const { return _quality; }
380  inline QualityType &Q() { return _quality; }
381  inline QualityType cQ() const {return _quality; }
382  template < class RightValueType>
383  void ImportData(const RightValueType & rVert ) { if(rVert.IsQualityEnabled()) Q() = rVert.cQ(); TT::ImportData( rVert); }
384  static bool HasQuality() { return true; }
385  static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality"));TT::Name(name);}
386 
387 private:
388  QualityType _quality;
389 };
390 
391 template <class TT> class Qualitys: public Quality<short, TT> {
392 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualitys"));TT::Name(name);}
393 };
394 template <class TT> class Qualityf: public Quality<float, TT> {
395 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityf"));TT::Name(name);}
396 };
397 template <class TT> class Qualityd: public Quality<double, TT> {
398 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityd"));TT::Name(name);}
399 };
400 
401  /*-------------------------- Curvature ----------------------------------*/
402 
406  template <class A, class TT> class Curvature: public TT {
407  public:
408  typedef Point2<A> CurvatureType;
409  typedef typename CurvatureType::ScalarType ScalarTypeCur;
410  const ScalarTypeCur &Kh() const { return _hk[0]; }
411  const ScalarTypeCur &Kg() const { return _hk[1]; }
412  ScalarTypeCur &Kh() { return _hk[0]; }
413  ScalarTypeCur &Kg() { return _hk[1]; }
414  ScalarTypeCur cKh() const { return _hk[0]; }
415  ScalarTypeCur cKg() const { return _hk[1]; }
416 
417  template < class RightValueType>
418  void ImportData(const RightValueType & rVert ) {
419  if(rVert.IsCurvatureEnabled()) {
420  Kh() = rVert.cKh();
421  Kg() = rVert.cKg();
422  }
423  TT::ImportData( rVert);
424  }
425 
426  static bool HasCurvature() { return true; }
427  static void Name(std::vector<std::string> & name){name.push_back(std::string("Curvature"));TT::Name(name);}
428 
429  private:
430  Point2<A> _hk;
431  };
432 
433 
434  template <class T> class Curvaturef: public Curvature< float, T> {
435  public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Curvaturef"));T::Name(name);}
436  };
437  template <class T> class Curvatured: public Curvature<double , T> {
438  public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Curvatured"));T::Name(name);}
439  };
440 
441 /*-------------------------- Curvature Direction ----------------------------------*/
442 
447 template <class A, class TT> class CurvatureDir: public TT {
448 public:
449  typedef A CurvatureDirType;
450  typedef typename CurvatureDirType::VecType CurVecType;
451  typedef typename CurvatureDirType::ScalarType CurScalarType;
452 
453  CurVecType &PD1(){ return _curv.max_dir; }
454  CurVecType &PD2(){ return _curv.min_dir; }
455  const CurVecType &cPD1() const { return _curv.max_dir; }
456  const CurVecType &cPD2() const { return _curv.min_dir; }
457 
458  CurScalarType &K1(){ return _curv.k1; }
459  CurScalarType &K2(){ return _curv.k2; }
460  const CurScalarType &cK1() const { return _curv.k1; }
461  const CurScalarType &cK2() const { return _curv.k2; }
462  template < class RightValueType>
463  void ImportData(const RightValueType & rVert ) {
464  if(rVert.IsCurvatureDirEnabled()) {
465  PD1().Import(rVert.cPD1());
466  PD2().Import(rVert.cPD2());
467  K1() = rVert.cK1(); K2() = rVert.cK2();
468  }
469  TT::ImportData( rVert);
470  }
471 
472  static bool HasCurvatureDir() { return true; }
473  static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDir"));TT::Name(name);}
474 
475 private:
476  CurvatureDirType _curv;
477 };
478 
479 
480 template <class T> class CurvatureDirf: public CurvatureDir<CurvatureDirBaseType<float>, T> {
481 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDirf"));T::Name(name);}
482 };
483 template <class T> class CurvatureDird: public CurvatureDir<CurvatureDirBaseType<double>, T> {
484 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDird"));T::Name(name);}
485 };
486 
487 /*-------------------------- Radius ----------------------------------*/
492  template <class A, class TT> class Radius: public TT {
493  public:
494  typedef A RadiusType;
495  const RadiusType &R() const { return _radius; }
496  RadiusType &R() { return _radius; }
497  RadiusType cR() const {return _radius; }
498  template < class RightValueType>
499  void ImportData(const RightValueType & rVert ) { if(rVert.IsRadiusEnabled()) R() = rVert.cR(); TT::ImportData( rVert); }
500  static bool HasRadius() { return true; }
501  static void Name(std::vector<std::string> & name){name.push_back(std::string("Radius"));TT::Name(name);}
502 
503  private:
504  RadiusType _radius;
505  };
506 
507 template <class TT> class Radiusf: public Radius<float, TT> {
508 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Radiusf"));TT::Name(name);}
509 };
510 
511 
512 /*----------------------------- VEADJ ------------------------------*/
520 template <class T> class VEAdj: public T {
521 public:
522  VEAdj(){_ep=0;_zp=-1;}
523  typename T::EdgePointer &VEp() {return _ep; }
524  typename T::EdgePointer cVEp() const {return _ep; }
525  int &VEi() {return _zp; }
526  int cVEi() const {return _zp; }
527  template < class RightValueType>
528  void ImportData(const RightValueType & rVert ) { T::ImportData( rVert); }
529  static bool HasVEAdjacency() { return true; }
530  static void Name(std::vector<std::string> & name){name.push_back(std::string("VEAdj"));T::Name(name);}
531 
532 private:
533  typename T::EdgePointer _ep ;
534  int _zp ;
535 };
536 
537 /*----------------------------- VFADJ ------------------------------*/
548  template <class T> class VFAdj: public T {
549  public:
550  VFAdj(){_fp=0;_zp=-1;}
551  typename T::FacePointer &VFp() { return _fp; }
552  typename T::FacePointer cVFp() const { return _fp; }
553  int &VFi() { return _zp; }
554  int cVFi() const { return _zp; }
555  bool IsNull() const { return _zp==-1;}
556  template < class RightValueType>
557  void ImportData(const RightValueType & rVert ) { T::ImportData( rVert); }
558  static bool HasVFAdjacency() { return true; }
559  static void Name(std::vector<std::string> & name){name.push_back(std::string("VFAdj"));T::Name(name);}
560 
561  private:
562  typename T::FacePointer _fp ;
563  int _zp ;
564  };
565 
566 /*----------------------------- VHADJ ------------------------------*/
567 
568 template <class T> class VHAdj: public T {
569 public:
570  VHAdj(){_hp=0;_zp=-1;}
571  typename T::HEdgePointer &VHp() {return _hp; }
572  typename T::HEdgePointer cVHp() const {return _hp; }
573  int &VHi() {return _zp; }
574  template < class RightValueType>
575  void ImportData(const RightValueType & rVert ) { T::ImportData( rVert); }
576  static bool HasVHAdjacency() { return true; }
577  static void Name(std::vector<std::string> & name){name.push_back(std::string("VHAdj"));T::Name(name);}
578 
579 private:
580  typename T::HEdgePointer _hp ;
581  int _zp ;
582 };
583 
584 /*----------------------------- VTADJ ------------------------------*/
585 
586 template <class T> class VTAdj: public T {
587 public:
588  VTAdj() { _tp = 0; _zp=-1;}
589  typename T::TetraPointer &VTp() { return _tp; }
590  typename T::TetraPointer cVTp() const { return _tp; }
591  int &VTi() {return _zp; }
592  static bool HasVTAdjacency() { return true; }
593  static void Name( std::vector< std::string > & name ) { name.push_back( std::string("VTAdj") ); T::Name(name); }
594 
595 private:
596  typename T::TetraPointer _tp ;
597  int _zp ;
598 };
599  // End Doxygen VertexComponentGroup
601  } // end namespace vert
602 }// end namespace vcg
603 #endif