Fade2D Documentation pages v1.97
Delaunay Features
TriangleAroundVertexIterator.h
Go to the documentation of this file.
1 // (c) 2010 Geom e.U. Bernhard Kornberger, Graz/Austria. All rights reserved.
2 //
3 // This file is part of the Fade2D library. You can use it for your personal
4 // non-commercial research. Licensees holding a commercial license may use this
5 // file in accordance with the Commercial License Agreement provided
6 // with the Software.
7 //
8 // This software is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
9 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10 //
11 // Please contact the author if any conditions of this licensing are not clear
12 // to you.
13 //
14 // Author: Bernhard Kornberger, bkorn (at) geom.at
15 // http://www.geom.at
17 
18 #pragma once
19 #include "common.h"
20 #include "Point2.h"
21 #include "Triangle2.h"
22 //#include "tools.h"
23 
24 #include "common.h"
25 #if GEOM_PSEUDO3D==GEOM_TRUE
26  namespace GEOM_FADE25D {
27 #elif GEOM_PSEUDO3D==GEOM_FALSE
28  namespace GEOM_FADE2D {
29 #else
30  #error GEOM_PSEUDO3D is not defined
31 #endif
32 
34 inline
35 int inc1( int num)
36 {
37  ++num;
38  if(num>2) return 0;
39  return num;
40 }
41 
43 inline
44 int inc2( int num)
45 {
46  --num;
47  if(num<0) return 2;
48  return num;
49 }
64 class CLASS_DECLSPEC TriangleAroundVertexIterator
65 {
66 public:
73  explicit TriangleAroundVertexIterator(const Point2* pPnt_):pPnt(pPnt_),pTr(pPnt_->getIncidentTriangle()),pSavedTr(NULL)
74  {
75  if(pTr==NULL)
76  {
77  //flog("TriangleAroundVertexIterator::TriangleAroundVertexIterator(), created from an invalid point");
78  FadeException fadeEx;
79  throw fadeEx;
80  }
81  assert(pTr!=NULL);
82 
83  }
89  TriangleAroundVertexIterator(Point2* pPnt_, Triangle2* pTr_):pPnt(pPnt_),pTr(pTr_),pSavedTr(NULL)
90  {
91  assert(pTr!=NULL);
92  }
97  TriangleAroundVertexIterator(const TriangleAroundVertexIterator& it) : pPnt(it.pPnt),pTr(it.pTr),pSavedTr(NULL)
98  {
99  assert(pTr!=NULL);
100  }
101 
103  {
104  pPnt=other.pPnt;
105  pTr=other.pTr;
106  pSavedTr=other.pSavedTr;
107  return *this;
108  }
120  {
121 //std::cout<<"tavi++"<<std::endl;
122  if(pTr==NULL)
123  {
124 //std::cout<<"pTr==NULL, calling loop"<<std::endl;
125  loop();
126  return *this;
127  }
128 
129  int ccwIdx=inc1(pTr->getIntraTriangleIndex(pPnt));
130 //std::cout<<"ccwIdx="<<ccwIdx<<"now swapping saved="<<pSavedTr<<", pTr="<<pTr<<std::endl;;
131  std::swap(pSavedTr,pTr);
132  pTr=pSavedTr->getOppositeTriangle(ccwIdx);
133 //std::cout<<"and pTr is now the opposite triangle of pSavedTr="<<*pSavedTr<<", namely "<<pTr<<std::endl;
134 
135  return *this;
136  }
137 
149  {
150  if(pTr==NULL)
151  {
152  loop();
153  return *this;
154  }
155  int cwIdx=inc2(pTr->getIntraTriangleIndex(pPnt));
156  std::swap(pSavedTr,pTr);
157  pTr=pSavedTr->getOppositeTriangle(cwIdx);
158  return *this;
159  }
168  {
169  return (pPnt==rhs.pPnt && pTr==rhs.pTr);
170  }
178  {
179  return (pPnt!=rhs.pPnt || pTr!=rhs.pTr);
180  }
187  {
188  return pTr;
189  }
197  {
198  TriangleAroundVertexIterator tmp(*this);
199  ++tmp;
200  return *tmp;
201  }
209  {
210  TriangleAroundVertexIterator tmp(*this);
211  --tmp;
212  return *tmp;
213  }
214 
215 
216 
217 protected:
218  const Point2* pPnt;
219  Triangle2 *pTr,*pSavedTr;
220 
221  void loop()
222  {
223  assert(pTr==NULL && pSavedTr!=NULL);
224 
225  enum DIRECTION{DIRECTION_NONE,DIRECTION_BACK,DIRECTION_FWD};
226  DIRECTION direction(DIRECTION_NONE);
227 
228  int axisIndex=pSavedTr->getIntraTriangleIndex(pPnt);
229 
230  if(pSavedTr->getOppositeTriangle(inc2(axisIndex))!=NULL)
231  {
232  direction=DIRECTION_BACK;
233  }
234  if(pSavedTr->getOppositeTriangle(inc1(axisIndex))!=NULL)
235  {
236  assert(direction==DIRECTION_NONE);
237  direction=DIRECTION_FWD;
238  }
239  pTr=pSavedTr;
240  if(direction==DIRECTION_FWD) while(*operator++()!=NULL); // fast forward
241  if(direction==DIRECTION_BACK) while(*operator--()!=NULL); // rewind
242  pTr=pSavedTr;
243  }
244 };
245 
246 
247 } // (namespace)
Point.
Definition: Point2.h:43
Triangle.
Definition: Triangle2.h:59
Triangle2 * getOppositeTriangle(const int ith) const
Get the i-th neighbor triangle.
Definition: Triangle2.h:389
int getIntraTriangleIndex(const Point2 *p) const
Get the index of p in the triangle.
Definition: Triangle2.h:428
Iterator for all triangles around a given vertex.
Definition: TriangleAroundVertexIterator.h:65
bool operator!=(const TriangleAroundVertexIterator &rhs)
operator!=()
Definition: TriangleAroundVertexIterator.h:177
bool operator==(const TriangleAroundVertexIterator &rhs)
operator==()
Definition: TriangleAroundVertexIterator.h:167
Triangle2 * previewNextTriangle()
Preview next triangle (CCW direction)
Definition: TriangleAroundVertexIterator.h:196
Triangle2 * operator*()
Returns a pointer to the current triangle (or NULL)
Definition: TriangleAroundVertexIterator.h:186
Triangle2 * previewPrevTriangle()
Preview previous triangle (CW direction)
Definition: TriangleAroundVertexIterator.h:208
TriangleAroundVertexIterator & operator++()
Proceed to the next triangle (the one in counterclockwise order)
Definition: TriangleAroundVertexIterator.h:119
TriangleAroundVertexIterator(const TriangleAroundVertexIterator &it)
Copy constructor.
Definition: TriangleAroundVertexIterator.h:97
TriangleAroundVertexIterator(Point2 *pPnt_, Triangle2 *pTr_)
Constructor.
Definition: TriangleAroundVertexIterator.h:89
TriangleAroundVertexIterator & operator--()
Proceed to the previous triangle (the one in clockwise order)
Definition: TriangleAroundVertexIterator.h:148
TriangleAroundVertexIterator(const Point2 *pPnt_)
Constructor.
Definition: TriangleAroundVertexIterator.h:73