Fade2.5D Documentation pages v2.16.7
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 incBy1( int num)
36 {
37  ++num;
38  if(num>2) return 0;
39  return num;
40 }
41 
43 inline
44 int incBy2( int num)
45 {
46  --num;
47  if(num<0) return 2;
48  return num;
49 }
50 
81 class CLASS_DECLSPEC TriangleAroundVertexIterator
82 {
83 public:
92  explicit TriangleAroundVertexIterator(const Point2* pPnt_):pPnt(pPnt_),pTr(pPnt_->getIncidentTriangle()),pSavedTr(NULL)
93  {
94  if(pTr==NULL)
95  {
96  //flog("TriangleAroundVertexIterator::TriangleAroundVertexIterator(), created from an invalid point");
97  FadeException fadeEx;
98  throw fadeEx;
99  }
100  assert(pTr!=NULL);
101 
102  }
108  TriangleAroundVertexIterator(Point2* pPnt_, Triangle2* pTr_):pPnt(pPnt_),pTr(pTr_),pSavedTr(NULL)
109  {
110  assert(pTr!=NULL);
111  }
118  TriangleAroundVertexIterator(const TriangleAroundVertexIterator& it) : pPnt(it.pPnt),pTr(it.pTr),pSavedTr(NULL)
119  {
120  assert(pTr!=NULL);
121  }
130  {
131  pPnt=other.pPnt;
132  pTr=other.pTr;
133  pSavedTr=other.pSavedTr;
134  return *this;
135  }
136 
146  {
147 //GCOUT<<"tavi++"<<std::endl;
148  if(pTr==NULL)
149  {
150 //GCOUT<<"pTr==NULL, calling loop"<<std::endl;
151  loop();
152  return *this;
153  }
154 
155  int ccwIdx=incBy1(pTr->getIntraTriangleIndex(pPnt));
156 //GCOUT<<"ccwIdx="<<ccwIdx<<"now swapping saved="<<pSavedTr<<", pTr="<<pTr<<std::endl;;
157  std::swap(pSavedTr,pTr);
158  pTr=pSavedTr->getOppositeTriangle(ccwIdx);
159 //GCOUT<<"and pTr is now the opposite triangle of pSavedTr="<<*pSavedTr<<", namely "<<pTr<<std::endl;
160 
161  return *this;
162  }
163 
173  {
174  if(pTr==NULL)
175  {
176  loop();
177  return *this;
178  }
179  int cwIdx=incBy2(pTr->getIntraTriangleIndex(pPnt));
180  std::swap(pSavedTr,pTr);
181  pTr=pSavedTr->getOppositeTriangle(cwIdx);
182  return *this;
183  }
191  {
192  return (pPnt==rhs.pPnt && pTr==rhs.pTr);
193  }
201  {
202  return (pPnt!=rhs.pPnt || pTr!=rhs.pTr);
203  }
211  {
212  return pTr;
213  }
224  {
225  TriangleAroundVertexIterator tmp(*this);
226  ++tmp;
227  return *tmp;
228  }
237  {
238  TriangleAroundVertexIterator tmp(*this);
239  --tmp;
240  return *tmp;
241  }
242 
243 
244 
245 protected:
246  const Point2* pPnt;
247  Triangle2 *pTr,*pSavedTr;
249  void loop()
250  {
251  assert(pTr==NULL && pSavedTr!=NULL);
252 
253  enum DIRECTION{DIRECTION_NONE,DIRECTION_BACK,DIRECTION_FWD};
254  DIRECTION direction(DIRECTION_NONE);
255 
256  int axisIndex=pSavedTr->getIntraTriangleIndex(pPnt);
257 
258  if(pSavedTr->getOppositeTriangle(incBy2(axisIndex))!=NULL)
259  {
260  direction=DIRECTION_BACK;
261  }
262  if(pSavedTr->getOppositeTriangle(incBy1(axisIndex))!=NULL)
263  {
264  assert(direction==DIRECTION_NONE);
265  direction=DIRECTION_FWD;
266  }
267  pTr=pSavedTr;
268  if(direction==DIRECTION_FWD) while(*operator++()!=NULL); // fast forward
269  if(direction==DIRECTION_BACK) while(*operator--()!=NULL); // rewind
270  pTr=pSavedTr;
271  }
272 };
273 
274 
275 } // (namespace)
Represents a 2.5D point.
Definition: Point2.h:61
Represents a triangle in a triangulation.
Definition: Triangle2.h:59
Triangle2 * getOppositeTriangle(const int idx) const
Get the neighbor triangle at the specified index.
Definition: Triangle2.h:420
int getIntraTriangleIndex(const Point2 *pCorner) const
Get the index of the specified corner.
Definition: Triangle2.h:451
Iterator for all triangles around a given vertex.
Definition: TriangleAroundVertexIterator.h:82
Triangle2 * previewNextTriangle()
Preview the next triangle (CCW direction).
Definition: TriangleAroundVertexIterator.h:223
TriangleAroundVertexIterator & operator--()
Move the iterator to the previous triangle (clockwise order)
Definition: TriangleAroundVertexIterator.h:172
Triangle2 * previewPrevTriangle()
Preview the previous triangle (CW direction).
Definition: TriangleAroundVertexIterator.h:236
TriangleAroundVertexIterator(Point2 *pPnt_, Triangle2 *pTr_)
Constructor.
Definition: TriangleAroundVertexIterator.h:108
TriangleAroundVertexIterator & operator=(const TriangleAroundVertexIterator &other)
Assignment operator.
Definition: TriangleAroundVertexIterator.h:129
Triangle2 * operator*()
Returns the current triangle (or NULL)
Definition: TriangleAroundVertexIterator.h:210
bool operator!=(const TriangleAroundVertexIterator &rhs)
Compare the current iterator with another iterator.
Definition: TriangleAroundVertexIterator.h:200
bool operator==(const TriangleAroundVertexIterator &rhs)
Compare the current iterator with another iterator.
Definition: TriangleAroundVertexIterator.h:190
TriangleAroundVertexIterator(const Point2 *pPnt_)
Constructor.
Definition: TriangleAroundVertexIterator.h:92
TriangleAroundVertexIterator(const TriangleAroundVertexIterator &it)
Copy constructor.
Definition: TriangleAroundVertexIterator.h:118
TriangleAroundVertexIterator & operator++()
Move the iterator to the next triangle (counterclockwise order)
Definition: TriangleAroundVertexIterator.h:145