Fade2.5D Documentation pages v1.86
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 
33 
34 inline
35 int inc1( int num)
36 {
37  ++num;
38  if(num>2) return 0;
39  return num;
40 }
41 
42 inline
43 int inc2( int num)
44 {
45  --num;
46  if(num<0) return 2;
47  return num;
48 }
63 class CLASS_DECLSPEC TriangleAroundVertexIterator
64 {
65 public:
72  explicit TriangleAroundVertexIterator(const Point2* pPnt_):pPnt(pPnt_),pTr(pPnt_->getIncidentTriangle()),pSavedTr(NULL)
73  {
74  if(pTr==NULL)
75  {
76  //flog("TriangleAroundVertexIterator::TriangleAroundVertexIterator(), created from an invalid point");
77  FadeException fadeEx;
78  throw fadeEx;
79  }
80  assert(pTr!=NULL);
81 
82  }
88  TriangleAroundVertexIterator(Point2* pPnt_, Triangle2* pTr_):pPnt(pPnt_),pTr(pTr_),pSavedTr(NULL)
89  {
90  assert(pTr!=NULL);
91  }
96  TriangleAroundVertexIterator(const TriangleAroundVertexIterator& it) : pPnt(it.pPnt),pTr(it.pTr),pSavedTr(NULL)
97  {
98  assert(pTr!=NULL);
99  }
100 
102  {
103  pPnt=other.pPnt;
104  pTr=other.pTr;
105  pSavedTr=other.pSavedTr;
106  return *this;
107  }
119  {
120 //std::cout<<"tavi++"<<std::endl;
121  if(pTr==NULL)
122  {
123 //std::cout<<"pTr==NULL, calling loop"<<std::endl;
124  loop();
125  return *this;
126  }
127 
128  int ccwIdx=inc1(pTr->getIntraTriangleIndex(pPnt));
129 //std::cout<<"ccwIdx="<<ccwIdx<<"now swapping saved="<<pSavedTr<<", pTr="<<pTr<<std::endl;;
130  std::swap(pSavedTr,pTr);
131  pTr=pSavedTr->getOppositeTriangle(ccwIdx);
132 //std::cout<<"and pTr is now the opposite triangle of pSavedTr="<<*pSavedTr<<", namely "<<pTr<<std::endl;
133 
134  return *this;
135  }
136 
148  {
149  if(pTr==NULL)
150  {
151  loop();
152  return *this;
153  }
154  int cwIdx=inc2(pTr->getIntraTriangleIndex(pPnt));
155  std::swap(pSavedTr,pTr);
156  pTr=pSavedTr->getOppositeTriangle(cwIdx);
157  return *this;
158  }
167  {
168  return (pPnt==rhs.pPnt && pTr==rhs.pTr);
169  }
177  {
178  return (pPnt!=rhs.pPnt || pTr!=rhs.pTr);
179  }
186  {
187  return pTr;
188  }
196  {
197  TriangleAroundVertexIterator tmp(*this);
198  ++tmp;
199  return *tmp;
200  }
208  {
209  TriangleAroundVertexIterator tmp(*this);
210  --tmp;
211  return *tmp;
212  }
213 
214 
215 
216 protected:
217  const Point2* pPnt;
218  Triangle2 *pTr,*pSavedTr;
219 
220  void loop()
221  {
222  assert(pTr==NULL && pSavedTr!=NULL);
223 
224  enum DIRECTION{DIRECTION_NONE,DIRECTION_BACK,DIRECTION_FWD};
225  DIRECTION direction(DIRECTION_NONE);
226 
227  int axisIndex=pSavedTr->getIntraTriangleIndex(pPnt);
228 
229  if(pSavedTr->getOppositeTriangle(inc2(axisIndex))!=NULL)
230  {
231  direction=DIRECTION_BACK;
232  }
233  if(pSavedTr->getOppositeTriangle(inc1(axisIndex))!=NULL)
234  {
235  assert(direction==DIRECTION_NONE);
236  direction=DIRECTION_FWD;
237  }
238  pTr=pSavedTr;
239  if(direction==DIRECTION_FWD) while(*operator++()!=NULL); // fast forward
240  if(direction==DIRECTION_BACK) while(*operator--()!=NULL); // rewind
241  pTr=pSavedTr;
242  }
243 };
244 
245 
246 } // (namespace)
GEOM_FADE25D::TriangleAroundVertexIterator::operator*
Triangle2 * operator*()
Returns a pointer to the current triangle (or NULL)
Definition: TriangleAroundVertexIterator.h:185
GEOM_FADE25D::TriangleAroundVertexIterator::operator==
bool operator==(const TriangleAroundVertexIterator &rhs)
operator==()
Definition: TriangleAroundVertexIterator.h:166
GEOM_FADE25D::TriangleAroundVertexIterator::TriangleAroundVertexIterator
TriangleAroundVertexIterator(const TriangleAroundVertexIterator &it)
Copy constructor.
Definition: TriangleAroundVertexIterator.h:96
GEOM_FADE25D::TriangleAroundVertexIterator
Iterator for all triangles around a given vertex.
Definition: TriangleAroundVertexIterator.h:63
GEOM_FADE25D::TriangleAroundVertexIterator::operator!=
bool operator!=(const TriangleAroundVertexIterator &rhs)
operator!=()
Definition: TriangleAroundVertexIterator.h:176
GEOM_FADE25D::TriangleAroundVertexIterator::previewPrevTriangle
Triangle2 * previewPrevTriangle()
Preview previous triangle (CW direction)
Definition: TriangleAroundVertexIterator.h:207
GEOM_FADE25D::TriangleAroundVertexIterator::TriangleAroundVertexIterator
TriangleAroundVertexIterator(Point2 *pPnt_, Triangle2 *pTr_)
Constructor.
Definition: TriangleAroundVertexIterator.h:88
GEOM_FADE25D::Triangle2
Triangle.
Definition: Triangle2.h:48
GEOM_FADE25D::TriangleAroundVertexIterator::operator++
TriangleAroundVertexIterator & operator++()
Proceed to the next triangle (the one in counterclockwise order)
Definition: TriangleAroundVertexIterator.h:118
GEOM_FADE25D::TriangleAroundVertexIterator::operator--
TriangleAroundVertexIterator & operator--()
Proceed to the previous triangle (the one in clockwise order)
Definition: TriangleAroundVertexIterator.h:147
GEOM_FADE25D::Triangle2::getIntraTriangleIndex
int getIntraTriangleIndex(const Point2 *p) const
Get the index of p in the triangle.
Definition: Triangle2.h:393
GEOM_FADE25D::Triangle2::getOppositeTriangle
Triangle2 * getOppositeTriangle(const int ith) const
Get the i-th neighbor triangle.
Definition: Triangle2.h:354
GEOM_FADE25D::Point2
Point.
Definition: Point2.h:40
GEOM_FADE25D::TriangleAroundVertexIterator::previewNextTriangle
Triangle2 * previewNextTriangle()
Preview next triangle (CCW direction)
Definition: TriangleAroundVertexIterator.h:195
GEOM_FADE25D::TriangleAroundVertexIterator::TriangleAroundVertexIterator
TriangleAroundVertexIterator(const Point2 *pPnt_)
Constructor.
Definition: TriangleAroundVertexIterator.h:72