Geom Software - C++ Programming and Geometry Libraries
Fade2D Documentation pages v1.58
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 clearProperties();
277 
280  void setPropertiesAndOppT(Point2* pI, Point2* pJ, Point2* pK,Triangle2* pNeig0,Triangle2* pNeig1,Triangle2* pNeig2);
281 
284  void setVertexPointer(const int ith, Point2* pp);
285 
290  bool hasVertex(Point2* pVtx) const;
291 
296  bool hasOnEdge(int i,const Point2& q) const;
297 
300  int getMaxIndex() const;
301 
304  int getMinIndex() const;
305 
306 
307  // DEBUG
308  CLASS_DECLSPEC
309  friend std::ostream &operator<<(std::ostream &stream, const Triangle2& c);
310 
311 protected:
312  double computeArea(double l0,double l1,double l2) const;
313  bool isAccurateCC(int maxIdx,const Point2& cc) const;
314  bool getCC_strategy1(double avgOffX,double avgOffY,Point2& cc) const;
315  void getCC_strategy2(int maxIdx,double avgOffX,double avgOffY,Point2& cc) const;
316  void getCommonOffset(double& x,double& y) const;
317  Point2* aVertexPointer[3];
318  Triangle2* aOppTriangles[3];
319  //bool bState;
320 };
321 
322 namespace{
323 inline bool checkRange(int ith)
324 {
325  return (ith==0 || ith==1 || ith==2); // true if ith={0,1,2}
326 }
327 
328 }
329 inline Triangle2* Triangle2::getOppositeTriangle(const int ith) const
330 {
331  assert(checkRange(ith));
332  return aOppTriangles[ith];
333 }
334 
335 inline void Triangle2::setOppTriangle(const int ith, Triangle2* pNeig)
336 {
337  assert(checkRange(ith));
338  aOppTriangles[ith]=pNeig;
339 }
340 
341 
342 inline int Triangle2::getIntraTriangleIndex(const Point2* p0,const Point2* p1) const
343 {
344  for(int i=0;i<3;++i)
345  {
346  int ici1((i+1)%3);
347  int ici2((i+2)%3);
348 
349  if( aVertexPointer[ici1]==p0 && aVertexPointer[ici2]==p1) return i;
350  if( aVertexPointer[ici1]==p1 && aVertexPointer[ici2]==p0) return i;
351  }
352 
353  std::cout<<"BUG: Triangle2::getIntraTriangleIndex failed for"<<std::endl;// COUTOK
354  std::cout<<*p0<<std::endl;// COUTOK
355  std::cout<<*p1<<std::endl;// COUTOK
356  std::cout<<*this<<std::endl;// COUTOK
357  assert(false);
358  return -1;
359 }
360 
361 inline int Triangle2::getIntraTriangleIndex(const Point2* pp) const
362 {
363  if(aVertexPointer[0]==pp) return 0;
364  if(aVertexPointer[1]==pp) return 1;
365 #ifndef NDEBUG
366  if(aVertexPointer[2]!=pp)
367  {
368  std::cout<<"BUG: Triangle2::getIntraTriangleIndex failed for"<<std::endl;// COUTOK
369  std::cout<<*pp<<std::endl;// COUTOK
370  std::cout<<*this<<std::endl;// COUTOK
371  assert(false);
372  }
373 #endif
374 
375  return 2;
376 }
377 
378 inline int Triangle2::getIntraTriangleIndex(const Triangle2* pTriangle) const
379 {
380  if(getOppositeTriangle(0)==pTriangle) return 0;
381  if(getOppositeTriangle(1)==pTriangle) return 1;
382 
383 #ifndef NDEBUG
384  if(getOppositeTriangle(2)!=pTriangle)
385  {
386  std::cout<<"Triangle2::getIntraTriangleIndex, pTriangle is not a neighbor of the current triangle"<<std::endl;// COUTOK
387  std::cout<<"Current triangle: "<<*this<<std::endl;// COUTOK
388  std::cout<<"pTriangle: "<<*pTriangle<<std::endl;// COUTOK
389 
390 
391  assert(false);
392  }
393 #endif
394  return 2;
395 }
396 
397 inline Point2* Triangle2::getCorner(const int ith) const
398 {
399  assert(checkRange(ith));
400  return aVertexPointer[ith];
401 }
402 
403 inline void Triangle2::setVertexPointer(const int ith, Point2* pp)
404 {
405  aVertexPointer[ith]=pp;
406 }
407 
408 inline void Triangle2::setProperties( Point2* pI, Point2* pJ, Point2* pK)
409 {
410  assert((pI!=NULL && pJ!=NULL && pK!=NULL));
411  aVertexPointer[0]=pI;
412  aVertexPointer[1]=pJ;
413  aVertexPointer[2]=pK;
414  pI->setIncidentTriangle(this);
415  pJ->setIncidentTriangle(this);
416  pK->setIncidentTriangle(this);
417  for(size_t i=0;i<3;++i)
418  {
419  aOppTriangles[i]=NULL;
420  }
421 }
422 
423 inline void Triangle2::clearProperties()
424 {
425  for(int i=0;i<3;++i)
426  {
427  aVertexPointer[i]=NULL;
428  aOppTriangles[i]=NULL;
429  }
430 }
431 
432 inline void Triangle2::setPropertiesAndOppT(
433  Point2* pI, Point2* pJ, Point2* pK,
434  Triangle2* pNeig0,Triangle2* pNeig1,Triangle2* pNeig2
435  )
436 {
437  assert((pI!=NULL && pJ!=NULL && pK!=NULL));
438  aVertexPointer[0]=pI;
439  aVertexPointer[1]=pJ;
440  aVertexPointer[2]=pK;
441  pI->setIncidentTriangle(this);
442  pJ->setIncidentTriangle(this);
443  pK->setIncidentTriangle(this);
444  aOppTriangles[0]=pNeig0;
445  aOppTriangles[1]=pNeig1;
446  aOppTriangles[2]=pNeig2;
447 }
448 
449 
450 
451 
452 
453 
454 } // (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