Geom Software - C++ Programming and Geometry Libraries
Fade2D Documentation pages v1.56
Triangle2.h
1 // Copyright (C) Geom Software e.U, Bernhard Kornberger, Graz/Austria
2 //
3 // This file is part of the Fade2D library. The student license is free
4 // of charge and covers personal non-commercial research. Licensees
5 // holding a commercial license may use this file in accordance with
6 // the Commercial License Agreement.
7 //
8 // This software is provided AS IS with NO WARRANTY OF ANY KIND,
9 // INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
10 // FOR A PARTICULAR PURPOSE.
11 //
12 // Please contact the author if any conditions of this licensing are
13 // not clear to you.
14 //
15 // Author: Bernhard Kornberger, bkorn (at) geom.at
16 // http://www.geom.at
17 
18 
19 #pragma once
20 #include "Point2.h"
21 
22 
23 #include "common.h"
24 #if GEOM_PSEUDO3D==GEOM_TRUE
25  namespace GEOM_FADE25D {
26 #elif GEOM_PSEUDO3D==GEOM_FALSE
27  namespace GEOM_FADE2D {
28 #else
29  #error GEOM_PSEUDO3D is not defined
30 #endif
31 
48 class CLASS_DECLSPEC Triangle2
49 {
50 public:
55  {
56  aVertexPointer[0]=NULL;
57  aVertexPointer[1]=NULL;
58  aVertexPointer[2]=NULL;
59  aOppTriangles[0]=NULL;
60  aOppTriangles[1]=NULL;
61  aOppTriangles[2]=NULL;
62 
63  } // Never used!
64 
65 
66 
76  Point2* getCorner(const int ith) const;
77 
78 #if GEOM_PSEUDO3D==GEOM_TRUE
79 
99 std::pair<Point2,bool> getDual() const;
100 #else
101 
118 std::pair<Point2,bool> getDual() const;
119 #endif
120 
125  Point2 getBarycenter() const;
126 
127 
128 #if GEOM_PSEUDO3D==GEOM_TRUE
129 
133  Vector2 getNormalVector() const;
134 #endif
135 
148 double getInteriorAngle2D(int ith) const;
149 
150 #if GEOM_PSEUDO3D==GEOM_TRUE
151 
155 double getInteriorAngle25D(int ith) const;
156 #endif
157 
158 
159 
172  double getArea2D() const;
173 
174 
175 
176 
177 #if GEOM_PSEUDO3D==GEOM_TRUE
178 
185  double getArea25D() const;
186 #endif
187 
188 
202  Triangle2* getOppositeTriangle(const int ith) const;
203 
204 
216  int getIntraTriangleIndex(const Point2* p) const;
229  int getIntraTriangleIndex(const Triangle2* pTriangle) const;
230 
236  int getIntraTriangleIndex(const Point2* p0,const Point2* p1) const;
237 
238 
240  //*
241  //*
242  //* Internal use
243 //*/
244  //bool getState() const;
245 
253  double getSquaredEdgeLength(int ith) const;
254 
255 //** \brief Method for internal use
256  //*
257  //* Internal use
258 //*/
259  //void setState(bool bState_);
269  void setOppTriangle(const int ith, Triangle2* pTriangle);
272  void setProperties( Point2* pI, Point2* pJ, Point2* pK);
273 
276  void setPropertiesAndOppT(Point2* pI, Point2* pJ, Point2* pK,Triangle2* pNeig0,Triangle2* pNeig1,Triangle2* pNeig2);
277 
280  void setVertexPointer(const int ith, Point2* pp);
281 
286  bool hasVertex(Point2* pVtx) const;
287 
292  bool hasOnEdge(int i,const Point2& q) const;
293 
296  int getMaxIndex() const;
297 
298 
299 
300  // DEBUG
301  CLASS_DECLSPEC
302  friend std::ostream &operator<<(std::ostream &stream, const Triangle2& c);
303 
304 protected:
305  double computeArea(double l0,double l1,double l2) const;
306  bool isAccurateCC(int maxIdx,const Point2& cc) const;
307  bool getCC_strategy1(double avgOffX,double avgOffY,Point2& cc) const;
308  void getCC_strategy2(int maxIdx,double avgOffX,double avgOffY,Point2& cc) const;
309  void getCommonOffset(double& x,double& y) const;
310  Point2* aVertexPointer[3];
311  Triangle2* aOppTriangles[3];
312  //bool bState;
313 };
314 
315 namespace{
316 inline bool checkRange(int ith)
317 {
318  return (ith==0 || ith==1 || ith==2); // true if ith={0,1,2}
319 }
320 
321 }
322 inline Triangle2* Triangle2::getOppositeTriangle(const int ith) const
323 {
324  assert(checkRange(ith));
325  return aOppTriangles[ith];
326 }
327 
328 inline void Triangle2::setOppTriangle(const int ith, Triangle2* pNeig)
329 {
330  assert(checkRange(ith));
331  aOppTriangles[ith]=pNeig;
332 }
333 
334 
335 inline int Triangle2::getIntraTriangleIndex(const Point2* p0,const Point2* p1) const
336 {
337  for(int i=0;i<3;++i)
338  {
339  int ici1((i+1)%3);
340  int ici2((i+2)%3);
341 
342  if( aVertexPointer[ici1]==p0 && aVertexPointer[ici2]==p1) return i;
343  if( aVertexPointer[ici1]==p1 && aVertexPointer[ici2]==p0) return i;
344  }
345 
346  std::cout<<"BUG: Triangle2::getIntraTriangleIndex failed for"<<std::endl;// COUTOK
347  std::cout<<*p0<<std::endl;// COUTOK
348  std::cout<<*p1<<std::endl;// COUTOK
349  std::cout<<*this<<std::endl;// COUTOK
350  assert(false);
351  return -1;
352 }
353 
354 inline int Triangle2::getIntraTriangleIndex(const Point2* pp) const
355 {
356  if(aVertexPointer[0]==pp) return 0;
357  if(aVertexPointer[1]==pp) return 1;
358 #ifndef NDEBUG
359  if(aVertexPointer[2]!=pp)
360  {
361  std::cout<<"BUG: Triangle2::getIntraTriangleIndex failed for"<<std::endl;// COUTOK
362  std::cout<<*pp<<std::endl;// COUTOK
363  std::cout<<*this<<std::endl;// COUTOK
364  assert(false);
365  }
366 #endif
367 
368  return 2;
369 }
370 
371 inline int Triangle2::getIntraTriangleIndex(const Triangle2* pTriangle) const
372 {
373  if(getOppositeTriangle(0)==pTriangle) return 0;
374  if(getOppositeTriangle(1)==pTriangle) return 1;
375 
376 #ifndef NDEBUG
377  if(getOppositeTriangle(2)!=pTriangle)
378  {
379  std::cout<<"Triangle2::getIntraTriangleIndex, pTriangle is not a neighbor of the current triangle"<<std::endl;// COUTOK
380  std::cout<<"Current triangle: "<<*this<<std::endl;// COUTOK
381  std::cout<<"pTriangle: "<<*pTriangle<<std::endl;// COUTOK
382 
383 
384  assert(false);
385  }
386 #endif
387  return 2;
388 }
389 
390 inline Point2* Triangle2::getCorner(const int ith) const
391 {
392  assert(checkRange(ith));
393  return aVertexPointer[ith];
394 }
395 
396 inline void Triangle2::setVertexPointer(const int ith, Point2* pp)
397 {
398  aVertexPointer[ith]=pp;
399 }
400 
401 inline void Triangle2::setProperties( Point2* pI, Point2* pJ, Point2* pK)
402 {
403  assert((pI!=NULL && pJ!=NULL && pK!=NULL));
404  aVertexPointer[0]=pI;
405  aVertexPointer[1]=pJ;
406  aVertexPointer[2]=pK;
407  pI->setIncidentTriangle(this);
408  pJ->setIncidentTriangle(this);
409  pK->setIncidentTriangle(this);
410  for(size_t i=0;i<3;++i)
411  {
412  aOppTriangles[i]=NULL;
413  }
414 }
415 
416 
417 inline void Triangle2::setPropertiesAndOppT(
418  Point2* pI, Point2* pJ, Point2* pK,
419  Triangle2* pNeig0,Triangle2* pNeig1,Triangle2* pNeig2
420  )
421 {
422  assert((pI!=NULL && pJ!=NULL && pK!=NULL));
423  aVertexPointer[0]=pI;
424  aVertexPointer[1]=pJ;
425  aVertexPointer[2]=pK;
426  pI->setIncidentTriangle(this);
427  pJ->setIncidentTriangle(this);
428  pK->setIncidentTriangle(this);
429  aOppTriangles[0]=pNeig0;
430  aOppTriangles[1]=pNeig1;
431  aOppTriangles[2]=pNeig2;
432 }
433 
434 
435 
436 
437 
438 
439 } // (namespace)
Point.
Definition: Point2.h:39
Triangle2()
Constructor.
Definition: Triangle2.h:54
Vector.
Definition: Vector2.h:37
void setIncidentTriangle(Triangle2 *pT)
Associate a triangle with the point.
Definition: Point2.h:416
Triangle.
Definition: Triangle2.h:48
Definition: Bbox2.h:25