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  inline bool IsMarkEnabled( ) const { return T::EdgeType::HasMark(); }
71 
72 
73  typedef int FlagType;
74  int &Flags() { static int dummyflags(0); assert(0); return dummyflags; }
75  int Flags() const { return 0; }
76  static bool HasFlags() { return false; }
77 
78  typename T::EdgePointer &VEp(const int & ) { static typename T::EdgePointer ep=0; assert(0); return ep; }
79  typename T::EdgePointer cVEp(const int & ) const { static typename T::EdgePointer ep=0; assert(0); return ep; }
80  int &VEi(const int &){static int z=0; assert(0); return z;}
81  int cVEi(const int &) const {static int z=0; assert(0); return z;}
82  static bool HasVEAdjacency() { return false; }
83 
84  typename T::EdgePointer &EEp(const int & ) { static typename T::EdgePointer ep=0; assert(0); return ep; }
85  typename T::EdgePointer cEEp(const int & ) const { static typename T::EdgePointer ep=0; assert(0); return ep; }
86  int &EEi(const int &){static int z=0; assert(0); return z;}
87  int cEEi(const int &) const {static int z=0; assert(0); return z;}
88  static bool HasEEAdjacency() { return false; }
89 
90  typename T::HEdgePointer &EHp( ) { static typename T::HEdgePointer hp=0; assert(0); return hp; }
91  typename T::HEdgePointer cEHp( ) const { static typename T::HEdgePointer hp=0; assert(0); return hp; }
92  static bool HasEHAdjacency() { return false; }
93 
94  typename T::FacePointer &EFp() { static typename T::FacePointer fp=0; assert(0); return fp; }
95  typename T::FacePointer cEFp() const { static typename T::FacePointer fp=0; assert(0); return fp; }
96  int &EFi() {static int z=0; return z;}
97  int &cEFi() const {static int z=0; return z;}
98  static bool HasEFAdjacency() { return false; }
99 
100  template <class LeftF>
101  void ImportData(const LeftF & leftF) {T::ImportData(leftF);}
102  static void Name(std::vector<std::string> & name){T::Name(name);}
103 };
104 
105 /*-------------------------- VertexRef ----------------------------------------*/
111 template <class T> class VertexRef: public T {
112 public:
113  VertexRef(){
114  v[0]=0;
115  v[1]=0;
116  }
117 
118  typedef typename T::VertexType::CoordType CoordType;
119  typedef typename T::VertexType::ScalarType ScalarType;
120 
121  inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<2); return v[j]; }
122  inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<2); return v[j]; }
123  inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<2); return v[j]; }
124 
125  // Shortcut per accedere ai punti delle facce
126  inline CoordType & P( const int j ) { assert(j>=0 && j<2); return v[j]->P(); }
127  inline const CoordType &cP( const int j ) const { assert(j>=0 && j<2); return v[j]->P(); }
128 
132  inline typename T::VertexType * & V0( const int j ) { return V(j);}
133  inline typename T::VertexType * & V1( const int j ) { return V((j+1)%2);}
134  inline const typename T::VertexType * const & V0( const int j ) const { return V(j);}
135  inline const typename T::VertexType * const & V1( const int j ) const { return V((j+1)%2);}
136  inline const typename T::VertexType * const & cV0( const int j ) const { return cV(j);}
137  inline const typename T::VertexType * const & cV1( const int j ) const { return cV((j+1)%2);}
138 
140  inline CoordType & P0( const int j ) { return V(j)->P();}
141  inline CoordType & P1( const int j ) { return V((j+1)%2)->P();}
142  inline const CoordType & P0( const int j ) const { return V(j)->P();}
143  inline const CoordType & P1( const int j ) const { return V((j+1)%2)->P();}
144  inline const CoordType & cP0( const int j ) const { return cV(j)->P();}
145  inline const CoordType & cP1( const int j ) const { return cV((j+1)%2)->P();}
146 
147  template <class LeftF>
148  void ImportData(const LeftF & leftF){ T::ImportData(leftF);}
149 
150  static bool HasEVAdjacency() { return true; }
151  static bool HasVertexRef() { return true; }
152  static void Name(std::vector<std::string> & name){name.push_back(std::string("VertexRef"));T::Name(name);}
153 
154 
155 private:
156  typename T::VertexType *v[2];
157 };
158 
159 template <class T> class EVAdj : public VertexRef<T>{};
160 
161 
162 /*-------------------------- INCREMENTAL MARK ----------------------------------------*/
163 
168 template <class T> class Mark: public T {
169 public:
170  Mark():_imark(0){}
171  static bool HasMark() { return true; }
172  static bool HasMarkOcc() { return true; }
173  inline void InitIMark() { _imark = 0; }
174  inline int & IMark() { return _imark;}
175  inline int cIMark() const { return _imark;}
176 
177  template < class RightValueType>
178  void ImportData(const RightValueType & rightE )
179  {
180  if(rightE.IsMarkEnabled())
181  IMark() = rightE.cIMark();
182  T::ImportData(rightE);
183  }
184  static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);}
185 
186 private:
187  int _imark;
188 };
189 
190 /*------------------------- FLAGS -----------------------------------------*/
195 template <class T> class BitFlags: public T {
196 public:
197  BitFlags(){_flags=0;}
198  typedef int FlagType;
199  int &Flags() {return _flags; }
200  int Flags() const {return _flags; }
201  template < class LeftV>
202  void ImportData(const LeftV & left ) { Flags() = left.Flags(); T::ImportData( left); }
203  static bool HasFlags() { return true; }
204  static void Name(std::vector<std::string> & name){name.push_back(std::string("BitFlags"));T::Name(name);}
205 
206 private:
207  int _flags;
208 };
209 
210 /*-------------------------- Color ----------------------------------*/
216 template <class A, class T> class Color: public T {
217 public:
218  Color():_color(vcg::Color4b::White) {}
219  typedef A ColorType;
220  ColorType &C() { return _color; }
221  const ColorType &C() const { return _color; }
222  const ColorType &cC() const { return _color; }
223  template < class LeftV>
224  void ImportData(const LeftV & left ) { C() = left.cC(); T::ImportData( left); }
225  static bool HasColor() { return true; }
226  static void Name(std::vector<std::string> & name){name.push_back(std::string("Color"));T::Name(name);}
227 
228 private:
229  ColorType _color;
230 };
231 
232 template <class TT> class Color4b: public edge::Color<vcg::Color4b, TT> {
233 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Color4b"));TT::Name(name);}
234 };
235 
236 /*-------------------------- Quality ----------------------------------*/
243 template <class A, class TT> class Quality: public TT {
244 public:
245  typedef A QualityType;
246  QualityType &Q() { return _quality; }
247  const QualityType & cQ() const {return _quality; }
248  template < class LeftV>
249  void ImportData(const LeftV & left ) { Q() = left.cQ(); TT::ImportData( left); }
250  static bool HasQuality() { return true; }
251  static void Name(std::vector<std::string> & name){name.push_back(std::string("Quality"));TT::Name(name);}
252 
253 private:
254  QualityType _quality;
255 };
256 
257 template <class TT> class Qualitys: public Quality<short, TT> {
258 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualitys"));TT::Name(name);}
259 };
260 template <class TT> class Qualityf: public Quality<float, TT> {
261 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityf"));TT::Name(name);}
262 };
263 template <class TT> class Qualityd: public Quality<double, TT> {
264 public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Qualityd"));TT::Name(name);}
265 };
266 
267 /*----------------------------- VEADJ ------------------------------*/
275 template <class T> class VEAdj: public T {
276 public:
277  VEAdj(){_ep[0]=0;_ep[1]=0;_zp[0]=-1;_zp[1]=-1;}
278  typename T::EdgePointer &VEp(const int & i) {return _ep[i]; }
279  typename T::EdgePointer cVEp(const int & i) const {return _ep[i]; }
280  int &VEi(const int & i){ return _zp[i];}
281  int cVEi(const int &i )const {return _zp[i];}
282 
283  template < class LeftV>
284  void ImportData(const LeftV & left ) { T::ImportData( left); }
285  static bool HasVEAdjacency() { return true; }
286  static bool HasVEAdjacencyOcc() { return true; }
287  static void Name(std::vector<std::string> & name){name.push_back(std::string("VEAdj"));T::Name(name);}
288 
289 private:
290  typename T::EdgePointer _ep[2] ;
291  int _zp[2] ;
292 };
293 
294 /*----------------------------- EEADJ ------------------------------*/
308 template <class T> class EEAdj: public T {
309 public:
310  EEAdj(){_ep[0]=0;_ep[1]=0;_zp[0]=-1;_zp[1]=-1;}
311  typename T::EdgePointer &EEp(const int & i) {return _ep[i]; }
312  typename T::EdgePointer cEEp(const int & i) const {return _ep[i]; }
313  int &EEi(const int & i){ return _zp[i];}
314  int cEEi(const int &i )const {return _zp[i];}
315 
316  template < class LeftV>
317  void ImportData(const LeftV & left ) { T::ImportData( left); }
318  static bool HasEEAdjacency() { return true; }
319  static bool HasEEAdjacencyOcc() { return true; }
320  static void Name(std::vector<std::string> & name){name.push_back(std::string("EEAdj"));T::Name(name);}
321 
322 private:
323  typename T::EdgePointer _ep[2] ;
324  int _zp[2] ;
325 };
326 
327 /*----------------------------- EHADJ ------------------------------*/
328 template <class T> class EHAdj: public T {
329 public:
330  EHAdj(){_hp=0;}
331  typename T::HEdgePointer &EHp( ) {return _hp ; }
332  const typename T::HEdgePointer cEHp( ) const {return _hp ; }
333 
334  template < class LeftV>
335  void ImportData(const LeftV & left ) { T::ImportData( left); }
336  static bool HasEHAdjacency() { return true; }
337  static bool HasEHAdjacencyOcc() { return true; }
338  static void Name(std::vector<std::string> & name){name.push_back(std::string("EHAdj"));T::Name(name);}
339 
340 private:
341  typename T::HEdgePointer _hp ;
342 };
343 
344 /*----------------------------- EFADJ ------------------------------*/
352 template <class T> class EFAdj: public T {
353 public:
354  EFAdj(){_fp=0;}
355  typename T::FacePointer &EFp() {return _fp; }
356  typename T::FacePointer cEFp() const {return _fp; }
357  int &EFi() {return _zp; }
358  int cEFi() const {return _zp; }
359  template < class LeftV>
360  void ImportData(const LeftV & left ) { T::ImportData( left); }
361  static bool HasEFAdjacency() { return true; }
362  static bool HasEFAdjacencyOcc() { return true; }
363  static void Name(std::vector<std::string> & name){name.push_back(std::string("EFAdj"));T::Name(name);}
364 
365 private:
366  typename T::FacePointer _fp ;
367  int _zp ;
368 };
369  // End Doxygen EdgeComponentGroup
371 } // end namespace edge
372 }// end namespace vcg
373 #endif