VCG Library
edge/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_EDGE_PLUS_COMPONENT
27 #define __VCG_EDGE_PLUS_COMPONENT
28 
29 namespace vcg {
30  namespace edge {
31 
36 /*
37 Some naming Rules
38 All the Components that can be added to a vertex should be defined in the namespace edge:
39 
40 */
41  /*------------------------- EMPTY CORE COMPONENTS -----------------------------------------*/
42 
43 template <class T> class EmptyCore: public T
44  {
45 public:
46  inline typename T::VertexType * & V( const int j ) { (void)j; assert(0); static typename T::VertexType *vp=0; return vp; }
47  inline typename T::VertexType * const & V( const int j ) const { (void)j; assert(0); static typename T::VertexType *vp=0; return vp; }
48  inline typename T::VertexType * cV( const int j ) const { (void)j; assert(0); static typename T::VertexType *vp=0; return vp; }
49  inline typename T::CoordType & P( const int j ) { (void)j; assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
50  inline const typename T::CoordType & P( const int j ) const { (void)j; assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
51  inline const typename T::CoordType & cP( const int j ) const { (void)j; assert(0); static typename T::CoordType coord(0, 0, 0); return coord; }
52  static bool HasEVAdjacency() { return false; }
53  static bool HasVertexRef() { return false; }
54 
55  typedef vcg::Color4b ColorType;
56  ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; }
57  ColorType cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; }
58  static bool HasColor() { return false; }
59 
60  typedef float QualityType;
61  QualityType &Q() { static QualityType dummyQuality(0); assert(0); return dummyQuality; }
62  QualityType cQ() const { static QualityType dummyQuality(0); assert(0); return dummyQuality; }
63  static bool HasQuality() { return false; }
64 
65  typedef int MarkType;
66  inline void InitIMark() { }
67  inline int cIMark() const { assert(0); static int tmp=-1; return tmp;}
68  inline int &IMark() { assert(0); static int tmp=-1; return tmp;}
69  static bool HasMark() { return false; }
70 
71  typedef int FlagType;
72  int &Flags() { static int dummyflags(0); assert(0); return dummyflags; }
73  int Flags() const { return 0; }
74  static bool HasFlags() { return false; }
75 
76  typename T::EdgePointer &VEp(const int & ) { static typename T::EdgePointer ep=0; assert(0); return ep; }
77  typename T::EdgePointer cVEp(const int & ) const { static typename T::EdgePointer ep=0; assert(0); return ep; }
78  int &VEi(const int &){static int z=0; assert(0); return z;}
79  int cVEi(const int &) const {static int z=0; assert(0); return z;}
80  static bool HasVEAdjacency() { return false; }
81 
82  typename T::EdgePointer &EEp(const int & ) { static typename T::EdgePointer ep=0; assert(0); return ep; }
83  typename T::EdgePointer cEEp(const int & ) const { static typename T::EdgePointer ep=0; assert(0); return ep; }
84  int &EEi(const int &){static int z=0; assert(0); return z;}
85  int cEEi(const int &) const {static int z=0; assert(0); return z;}
86  static bool HasEEAdjacency() { return false; }
87 
88  typename T::HEdgePointer &EHp( ) { static typename T::HEdgePointer hp=0; assert(0); return hp; }
89  typename T::HEdgePointer cEHp( ) const { static typename T::HEdgePointer hp=0; assert(0); return hp; }
90  static bool HasEHAdjacency() { return false; }
91 
92  typename T::FacePointer &EFp() { static typename T::FacePointer fp=0; assert(0); return fp; }
93  typename T::FacePointer cEFp() const { static typename T::FacePointer fp=0; assert(0); return fp; }
94  int &EFi() {static int z=0; return z;}
95  int &cEFi() const {static int z=0; return z;}
96  static bool HasEFAdjacency() { return false; }
97 
98  template <class LeftF>
99  void ImportData(const LeftF & leftF) {T::ImportData(leftF);}
100  static void Name(std::vector<std::string> & name){T::Name(name);}
101  };
102 
103  /*-------------------------- VertexRef ----------------------------------------*/
109 template <class T> class VertexRef: public T {
110 public:
111  VertexRef(){
112  v[0]=0;
113  v[1]=0;
114  }
115 
116  typedef typename T::VertexType::CoordType CoordType;
117  typedef typename T::VertexType::ScalarType ScalarType;
118 
119  inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<2); return v[j]; }
120  inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<2); return v[j]; }
121  inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<2); return v[j]; }
122 
123  // Shortcut per accedere ai punti delle facce
124  inline CoordType & P( const int j ) { assert(j>=0 && j<2); return v[j]->P(); }
125  inline const CoordType &cP( const int j ) const { assert(j>=0 && j<2); return v[j]->P(); }
126 
130  inline typename T::VertexType * & V0( const int j ) { return V(j);}
131  inline typename T::VertexType * & V1( const int j ) { return V((j+1)%2);}
132  inline const typename T::VertexType * const & V0( const int j ) const { return V(j);}
133  inline const typename T::VertexType * const & V1( const int j ) const { return V((j+1)%2);}
134  inline const typename T::VertexType * const & cV0( const int j ) const { return cV(j);}
135  inline const typename T::VertexType * const & cV1( const int j ) const { return cV((j+1)%2);}
136 
138  inline CoordType & P0( const int j ) { return V(j)->P();}
139  inline CoordType & P1( const int j ) { return V((j+1)%2)->P();}
140  inline const CoordType & P0( const int j ) const { return V(j)->P();}
141  inline const CoordType & P1( const int j ) const { return V((j+1)%2)->P();}
142  inline const CoordType & cP0( const int j ) const { return cV(j)->P();}
143  inline const CoordType & cP1( const int j ) const { return cV((j+1)%2)->P();}
144 
145  template <class LeftF>
146  void ImportData(const LeftF & leftF){ T::ImportData(leftF);}
147 
148  static bool HasEVAdjacency() { return true; }
149  static bool HasVertexRef() { return true; }
150  static void Name(std::vector<std::string> & name){name.push_back(std::string("VertexRef"));T::Name(name);}
151 
152 
153  private:
154  typename T::VertexType *v[2];
155 };
156 
157 template <class T> class EVAdj : public VertexRef<T>{};
158 
159 
160 /*-------------------------- INCREMENTAL MARK ----------------------------------------*/
161 
166 template <class T> class Mark: public T {
167 public:
168  Mark():_imark(0){}
169  static bool HasMark() { return true; }
170  static bool HasMarkOcc() { return true; }
171  inline void InitIMark() { _imark = 0; }
172  inline int & IMark() { return _imark;}
173  inline const int & IMark() const {return _imark;}
174  template < class LeftV>
175  void ImportData(const LeftV & left ) { IMark() = left.IMark(); T::ImportData( left); }
176  static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);}
177 
178  private:
179  int _imark;
180 };
181 
182 /*------------------------- FLAGS -----------------------------------------*/
187 template <class T> class BitFlags: public T {
188 public:
189  BitFlags(){_flags=0;}
190  typedef int FlagType;
191  int &Flags() {return _flags; }
192  int Flags() const {return _flags; }
193  template < class LeftV>
194  void ImportData(const LeftV & left ) { Flags() = left.Flags(); T::ImportData( left); }
195  static bool HasFlags() { return true; }
196  static void Name(std::vector<std::string> & name){name.push_back(std::string("BitFlags"));T::Name(name);}
197 
198 private:
199  int _flags;
200 };
201 
202 /*-------------------------- Color ----------------------------------*/
208 template <class A, class T> class Color: public T {
209 public:
210  Color():_color(vcg::Color4b::White) {}
211  typedef A ColorType;
212  ColorType &C() { return _color; }
213  const ColorType &C() const { return _color; }
214  const ColorType &cC() const { return _color; }
215  template < class LeftV>
216  void ImportData(const LeftV & left ) { C() = left.cC(); T::ImportData( left); }
217  static bool HasColor() { return true; }
218  static void Name(std::vector<std::string> & name){name.push_back(std::string("Color"));T::Name(name);}
219 
220 private:
221  ColorType _color;
222 };
223 
224 template <class TT> class Color4b: public edge::Color<vcg::Color4b, TT> {
225  public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Color4b"));TT::Name(name);}
226 };
227 
228 /*-------------------------- Quality ----------------------------------*/
235 template <class A, class TT> class Quality: public TT {
236 public:
237  typedef A QualityType;
238  QualityType &Q() { return _quality; }
239  const QualityType & cQ() const {return _quality; }
240  template < class LeftV>
241  void ImportData(const LeftV & left ) { Q() = left.cQ(); TT::ImportData( left); }
242  static bool HasQuality() { return true; }
243  static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality"));TT::Name(name);}
244 
245 private:
246  QualityType _quality;
247 };
248 
249 template <class TT> class Qualitys: public Quality<short, TT> {
250 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualitys"));TT::Name(name);}
251 };
252 template <class TT> class Qualityf: public Quality<float, TT> {
253 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityf"));TT::Name(name);}
254 };
255 template <class TT> class Qualityd: public Quality<double, TT> {
256 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityd"));TT::Name(name);}
257 };
258 
259 /*----------------------------- VEADJ ------------------------------*/
267  template <class T> class VEAdj: public T {
268  public:
269  VEAdj(){_ep[0]=0;_ep[1]=0;_zp[0]=-1;_zp[1]=-1;}
270  typename T::EdgePointer &VEp(const int & i) {return _ep[i]; }
271  typename T::EdgePointer cVEp(const int & i) const {return _ep[i]; }
272  int &VEi(const int & i){ return _zp[i];}
273  int cVEi(const int &i )const {return _zp[i];}
274 
275  template < class LeftV>
276  void ImportData(const LeftV & left ) { T::ImportData( left); }
277  static bool HasVEAdjacency() { return true; }
278  static bool HasVEAdjacencyOcc() { return true; }
279  static void Name(std::vector<std::string> & name){name.push_back(std::string("VEAdj"));T::Name(name);}
280 
281  private:
282  typename T::EdgePointer _ep[2] ;
283  int _zp[2] ;
284  };
285 
286 /*----------------------------- EEADJ ------------------------------*/
300 template <class T> class EEAdj: public T {
301 public:
302  EEAdj(){_ep[0]=0;_ep[1]=0;_zp[0]=-1;_zp[1]=-1;}
303  typename T::EdgePointer &EEp(const int & i) {return _ep[i]; }
304  typename T::EdgePointer cEEp(const int & i) const {return _ep[i]; }
305  int &EEi(const int & i){ return _zp[i];}
306  int cEEi(const int &i )const {return _zp[i];}
307 
308  template < class LeftV>
309  void ImportData(const LeftV & left ) { T::ImportData( left); }
310  static bool HasEEAdjacency() { return true; }
311  static bool HasEEAdjacencyOcc() { return true; }
312  static void Name(std::vector<std::string> & name){name.push_back(std::string("EEAdj"));T::Name(name);}
313 
314 private:
315  typename T::EdgePointer _ep[2] ;
316  int _zp[2] ;
317 };
318 
319 /*----------------------------- EHADJ ------------------------------*/
320 template <class T> class EHAdj: public T {
321 public:
322  EHAdj(){_hp=0;}
323  typename T::HEdgePointer &EHp( ) {return _hp ; }
324  const typename T::HEdgePointer cEHp( ) const {return _hp ; }
325 
326  template < class LeftV>
327  void ImportData(const LeftV & left ) { T::ImportData( left); }
328  static bool HasEHAdjacency() { return true; }
329  static bool HasEHAdjacencyOcc() { return true; }
330  static void Name(std::vector<std::string> & name){name.push_back(std::string("EHAdj"));T::Name(name);}
331 
332 private:
333  typename T::HEdgePointer _hp ;
334 };
335 
336 /*----------------------------- EFADJ ------------------------------*/
344 template <class T> class EFAdj: public T {
345 public:
346  EFAdj(){_fp=0;}
347  typename T::FacePointer &EFp() {return _fp; }
348  typename T::FacePointer cEFp() const {return _fp; }
349  int &EFi() {return _zp; }
350  int cEFi() const {return _zp; }
351  template < class LeftV>
352  void ImportData(const LeftV & left ) { T::ImportData( left); }
353  static bool HasEFAdjacency() { return true; }
354  static bool HasEFAdjacencyOcc() { return true; }
355  static void Name(std::vector<std::string> & name){name.push_back(std::string("EFAdj"));T::Name(name);}
356 
357 private:
358  typename T::FacePointer _fp ;
359  int _zp ;
360 };
361  // End Doxygen EdgeComponentGroup
363  } // end namespace edge
364 }// end namespace vcg
365 #endif