Fade2D Documentation pages v2.16.7
Delaunay Features
Triangle2.h
Go to the documentation of this file.
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 
19 #pragma once
20 #include "Point2.h"
21 
22 
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 
35 {
40 };
41 
42 
58 class CLASS_DECLSPEC Triangle2
59 {
60 public:
63  {
64  aVertexPointer[0]=NULL;
65  aVertexPointer[1]=NULL;
66  aVertexPointer[2]=NULL;
67  aOppTriangles[0]=NULL;
68  aOppTriangles[1]=NULL;
69  aOppTriangles[2]=NULL;
70 
71  } // Never used!
72 
83  Point2* getCorner(const int idx) const;
84 
91  void getCorners(Point2*& p0,Point2*& p1,Point2*& p2) const;
92 
93 
94 
96 std::pair<Point2,bool> getDual(bool bForceExact=false) const; // DEPRECATED, see getCircumcenter()
97 
122 Point2 getCircumcenter(CircumcenterQuality& ccq,bool bForceExact=false) const;
123 
124 
125 
134 
135 
136 #if GEOM_PSEUDO3D==GEOM_TRUE
144  Vector2 getNormalVector() const;
145 
146 
147 
148 #endif
160 double getInteriorAngle2D(int idx) const;
161 
162 #if GEOM_PSEUDO3D==GEOM_TRUE
170 double getInteriorAngle25D(int idx) const;
171 #endif
172 
182  double getArea2D() const;
183 
184 
185 
186 
187 #if GEOM_PSEUDO3D==GEOM_TRUE
195  double getArea25D() const;
196 #endif
197 
209  Triangle2* getOppositeTriangle(const int idx) const;
210 
211 
224  int getIntraTriangleIndex(const Point2* pCorner) const;
225 
238  int getIntraTriangleIndex(const Triangle2* pNeig) const;
239 
254  int getIntraTriangleIndex(const Point2* p0,const Point2* p1) const;
255 
267  double getSquaredEdgeLength2D(int idx) const;
268 
271  double getSquaredEdgeLength(int idx) const; // Deprecated, use getSquaredEdgeLength2D()
272 
273 #if GEOM_PSEUDO3D==GEOM_TRUE
282  double getSquaredEdgeLength25D(int idx) const;
283 #endif
289  void setOppTriangle(const int idx, Triangle2* pTriangle);
296  void setProperties( Point2* pI, Point2* pJ, Point2* pK);
297 
299  void clearProperties();
300 
302  void setPropertiesAndOppT(Point2* pI, Point2* pJ, Point2* pK,Triangle2* pNeig0,Triangle2* pNeig1,Triangle2* pNeig2);
303 
311  void setVertexPointer(const int idx, Point2* pVtx);
312 
320  bool hasVertex(const Point2* pVtx) const;
321 
329  bool hasVertex(const Point2& q) const;
330 
341  bool hasOnEdge(int idx,const Point2& q) const;
342 
354  bool hasOn(const Point2& q) const;
355 
362  int getMaxIndex() const;
363 
370  int getMinIndex() const;
371 
382  double getMaxSqEdgeLen2D() const;
383 
385  void getCommonOffset(double& x,double& y) const;
386 
395  CLASS_DECLSPEC
396  friend std::ostream &operator<<(std::ostream &stream, const Triangle2& c);
398  friend inline void registerTriangles(Triangle2* fromTriangle,int ith,Triangle2* toTriangle,int jth);
399 
400 protected:
402  double computeArea(double l0,double l1,double l2) const;
404  bool getCC_inexact(double avgOffX,double avgOffY,Point2& cc) const;
406  Point2* aVertexPointer[3];
408  Triangle2* aOppTriangles[3];
409  //bool bState;
410 };
411 
412 namespace{
414 inline bool checkRange(int ith)
415 {
416  return (ith==0 || ith==1 || ith==2); // true if ith={0,1,2}
417 }
418 
419 }
420 inline Triangle2* Triangle2::getOppositeTriangle(const int ith) const
421 {
422  assert(checkRange(ith));
423  return aOppTriangles[ith];
424 }
425 
426 inline void Triangle2::setOppTriangle(const int ith, Triangle2* pNeig)
427 {
428  assert(checkRange(ith));
429  aOppTriangles[ith]=pNeig;
430 }
431 
432 
433 inline int Triangle2::getIntraTriangleIndex(const Point2* p0,const Point2* p1) const
434 {
435  for(int i=0;i<3;++i)
436  {
437  int ici1((i+1)%3);
438  int ici2((i+2)%3);
439  if( (aVertexPointer[ici1]==p0 && aVertexPointer[ici2]==p1) ||
440  (aVertexPointer[ici1]==p1 && aVertexPointer[ici2]==p0) ) return i;
441  }
442 
443  GCOUT<<"BUG: Triangle2::getIntraTriangleIndex failed for"<<std::endl;// COUTOK
444  GCOUT<<*p0<<std::endl;// COUTOK
445  GCOUT<<*p1<<std::endl;// COUTOK
446  GCOUT<<*this<<std::endl;// COUTOK
447  assert(false);
448  return -1;
449 }
450 
451 inline int Triangle2::getIntraTriangleIndex(const Point2* pVtx) const
452 {
453 #ifndef NDEBUG
454  for(int i=0;i<3;++i)
455  {
456  if(aVertexPointer[i]==pVtx)
457  {
458  return i;
459  }
460  }
461  assert(false);
462 #endif
463  return ( (aVertexPointer[1]==pVtx) + 2*(aVertexPointer[2]==pVtx));
464 }
465 
466 
467 inline int Triangle2::getIntraTriangleIndex(const Triangle2* pTriangle) const
468 {
469 #ifndef NDEBUG
470  // Just debug code
471  for(int i=0;i<3;++i)
472  {
473  if(aOppTriangles[i]==pTriangle)
474  {
475  return i;
476  }
477  }
478  assert(false);
479 #endif
480  return ( (aOppTriangles[1]==pTriangle) + 2*(aOppTriangles[2]==pTriangle));
481 }
482 
483 
484 
485 inline Point2* Triangle2::getCorner(const int ith) const
486 {
487  assert(checkRange(ith));
488  return aVertexPointer[ith];
489 }
490 
491 inline void Triangle2::getCorners(Point2*& p0,Point2*& p1,Point2*& p2) const
492 {
493  p0=aVertexPointer[0];
494  p1=aVertexPointer[1];
495  p2=aVertexPointer[2];
496 }
497 
498 inline void Triangle2::setVertexPointer(const int ith, Point2* pp)
499 {
500  aVertexPointer[ith]=pp;
501 }
502 
503 inline void Triangle2::setProperties( Point2* pI, Point2* pJ, Point2* pK)
504 {
505  assert((pI!=NULL && pJ!=NULL && pK!=NULL));
506  aVertexPointer[0]=pI;
507  aVertexPointer[1]=pJ;
508  aVertexPointer[2]=pK;
509  pI->setIncidentTriangle(this);
510  pJ->setIncidentTriangle(this);
511  pK->setIncidentTriangle(this);
512  aOppTriangles[0]=NULL;
513  aOppTriangles[1]=NULL;
514  aOppTriangles[2]=NULL;
515 }
516 
517 inline void Triangle2::clearProperties()
518 {
519  for(int i=0;i<3;++i)
520  {
521  aVertexPointer[i]=NULL;
522  aOppTriangles[i]=NULL;
523  }
524 }
525 
526 inline void Triangle2::setPropertiesAndOppT(
527  Point2* pI, Point2* pJ, Point2* pK,
528  Triangle2* pNeig0,Triangle2* pNeig1,Triangle2* pNeig2
529  )
530 {
531  assert((pI!=NULL && pJ!=NULL && pK!=NULL));
532  aVertexPointer[0]=pI;
533  aVertexPointer[1]=pJ;
534  aVertexPointer[2]=pK;
535  pI->setIncidentTriangle(this);
536  pJ->setIncidentTriangle(this);
537  pK->setIncidentTriangle(this);
538  aOppTriangles[0]=pNeig0;
539  aOppTriangles[1]=pNeig1;
540  aOppTriangles[2]=pNeig2;
541 }
542 
544 inline void registerTriangles(Triangle2* pFromT,int ith,Triangle2* pToT,int jth)
545 {
546  assert(checkRange(ith));
547  assert(checkRange(jth));
548 
549  pFromT->aOppTriangles[ith]=pToT;
550  pToT->aOppTriangles[jth]=pFromT;
551 
552 }
553 
554 
555 
556 
557 } // (namespace)
CircumcenterQuality
Enumeration for the quality of the circumcenter computation.
Definition: Triangle2.h:35
@ CCQ_INEXACT
Double precision computation, the result is accurate enough.
Definition: Triangle2.h:37
@ CCQ_OUT_OF_BOUNDS
Computation with multiple-precision arithmetic, but the result is not representable with double preci...
Definition: Triangle2.h:39
@ CCQ_INIT
Init value.
Definition: Triangle2.h:36
@ CCQ_EXACT
Computation with multiple-precision arithmetic, the result is exact (apart from tiny quantization err...
Definition: Triangle2.h:38
Represents a 2D point.
Definition: Point2.h:61
Represents a triangle in a triangulation.
Definition: Triangle2.h:59
Point2 getCircumcenter(CircumcenterQuality &ccq, bool bForceExact=false) const
Get the circumcenter of the triangle.
double getSquaredEdgeLength2D(int idx) const
Get the squared 2D length of the specified edge.
CLASS_DECLSPEC friend std::ostream & operator<<(std::ostream &stream, const Triangle2 &c)
Output operator for Triangle2.
bool hasVertex(const Point2 *pVtx) const
Check if the specified vertex is a corner of the triangle.
bool hasOn(const Point2 &q) const
Check if the triangle includes the specified point.
double getInteriorAngle2D(int idx) const
Get interior 2D angle.
bool hasVertex(const Point2 &q) const
Check if the specified point coincides with a corner of the triangle.
double getArea2D() const
Get the 2D area of the triangle.
int getMinIndex() const
Get the index of the smallest edge.
Triangle2()
Default constructor.
Definition: Triangle2.h:62
int getMaxIndex() const
Get the index of the largest edge.
bool hasOnEdge(int idx, const Point2 &q) const
Check if an edge includes the specified point.
Point2 getBarycenter() const
Get the barycenter of the triangle.
double getMaxSqEdgeLen2D() const
Get the maximum squared 2D edge length.
Vector.
Definition: Vector2.h:47