From 3a398488078997ab5a7cb4df6a8f6602fb9b0d27 Mon Sep 17 00:00:00 2001
From: thomas <th.arnold@gmx.net>
Date: Fri, 1 Jun 2012 08:40:59 +0200
Subject: [PATCH] 5239_v1

---
 .../interpolation/DualEdgeTriangulation.cc         |   44 ++++++++++----------
 src/analysis/interpolation/DualEdgeTriangulation.h |    4 +-
 2 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/analysis/interpolation/DualEdgeTriangulation.cc b/src/analysis/interpolation/DualEdgeTriangulation.cc
index 2a5d49c..370424b 100644
--- a/src/analysis/interpolation/DualEdgeTriangulation.cc
+++ b/src/analysis/interpolation/DualEdgeTriangulation.cc
@@ -295,7 +295,7 @@ int DualEdgeTriangulation::addPoint( Point3D* p )
         {
           toswap = index;
           index = mHalfEdge[mHalfEdge[mHalfEdge[index]->getNext()]->getDual()]->getNext();
-          checkSwap( toswap );
+          checkSwap( toswap , 0 );
           if ( toswap == cwedge )
           {
             break;
@@ -329,9 +329,9 @@ int DualEdgeTriangulation::addPoint( Point3D* p )
         mHalfEdge.at( nextnextnumber )->setNext(( int )edge6 );
 
         //check, if there are swaps necessary
-        checkSwap( number );
-        checkSwap( nextnumber );
-        checkSwap( nextnextnumber );
+        checkSwap( number , 0 );
+        checkSwap( nextnumber , 0 );
+        checkSwap( nextnextnumber , 0 );
       }
 
       //the point is exactly on an existing edge (the number of the edge is stored in the variable 'mEdgeWithPoint'---------------
@@ -364,10 +364,10 @@ int DualEdgeTriangulation::addPoint( Point3D* p )
         mHalfEdge[edgef]->setNext( nedge2 );
 
         //swap edges if necessary
-        checkSwap( edgec );
-        checkSwap( edged );
-        checkSwap( edgee );
-        checkSwap( edgef );
+        checkSwap( edgec , 0 );
+        checkSwap( edged , 0 );
+        checkSwap( edgee , 0 );
+        checkSwap( edgef , 0 );
       }
 
       else if ( number == -100 || number == -5 )//this means unknown problems or a numerical error occured in 'baseEdgeOfTriangle'
@@ -680,7 +680,7 @@ bool DualEdgeTriangulation::calcPoint( double x, double y, Point3D* result )
   }
 }
 
-bool DualEdgeTriangulation::checkSwap( unsigned int edge )
+bool DualEdgeTriangulation::checkSwap( unsigned int edge, unsigned int recursivDeep )
 {
   if ( swapPossible( edge ) )
   {
@@ -688,10 +688,9 @@ bool DualEdgeTriangulation::checkSwap( unsigned int edge )
     Point3D* ptb = mPointVector[mHalfEdge[mHalfEdge[edge]->getNext()]->getPoint()];
     Point3D* ptc = mPointVector[mHalfEdge[mHalfEdge[mHalfEdge[edge]->getNext()]->getNext()]->getPoint()];
     Point3D* ptd = mPointVector[mHalfEdge[mHalfEdge[mHalfEdge[edge]->getDual()]->getNext()]->getPoint()];
-
-    if ( MathUtils::inCircle( ptd, pta, ptb, ptc ) )//empty circle criterion violated
+    if ( MathUtils::inCircle( ptd, pta, ptb, ptc ) && recursivDeep < 100 )//empty circle criterion violated
     {
-      doSwap( edge );//swap the edge (recursiv)
+      doSwap( edge , recursivDeep );//swap the edge (recursiv)
       return true;
     }
   }
@@ -716,7 +715,7 @@ void DualEdgeTriangulation::doOnlySwap( unsigned int edge )
   mHalfEdge[edge2]->setPoint( mHalfEdge[edge5]->getPoint() );
 }
 
-void DualEdgeTriangulation::doSwap( unsigned int edge )
+void DualEdgeTriangulation::doSwap( unsigned int edge, unsigned int recursivDeep )
 {
   unsigned int edge1 = edge;
   unsigned int edge2 = mHalfEdge[edge]->getDual();
@@ -732,10 +731,11 @@ void DualEdgeTriangulation::doSwap( unsigned int edge )
   mHalfEdge[edge6]->setNext( edge3 );
   mHalfEdge[edge1]->setPoint( mHalfEdge[edge3]->getPoint() );//change the points to which edge1 and edge2 point
   mHalfEdge[edge2]->setPoint( mHalfEdge[edge5]->getPoint() );
-  checkSwap( edge3 );
-  checkSwap( edge6 );
-  checkSwap( edge4 );
-  checkSwap( edge5 );
+  recursivDeep++;
+  checkSwap( edge3 , recursivDeep );
+  checkSwap( edge6 , recursivDeep );
+  checkSwap( edge4 , recursivDeep );
+  checkSwap( edge5 , recursivDeep );
 }
 
 #if 0
@@ -1557,7 +1557,7 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
   //optimisation of the new edges
   for ( iter = crossedEdges.begin(); iter != crossedEdges.end(); ++iter )
   {
-    checkSwap(( *( iter ) ) );
+    checkSwap(( *( iter ) ) , 0 );
   }
 
   return leftPolygon.first();
@@ -3245,10 +3245,10 @@ int DualEdgeTriangulation::splitHalfEdge( int edge, float position )
   mHalfEdge[mHalfEdge[edge3]->getNext()]->setNext( edge6 );
 
   //test four times recursively for swaping
-  checkSwap( mHalfEdge[edge5]->getNext() );
-  checkSwap( mHalfEdge[edge2]->getNext() );
-  checkSwap( mHalfEdge[dualedge]->getNext() );
-  checkSwap( mHalfEdge[edge3]->getNext() );
+  checkSwap( mHalfEdge[edge5]->getNext() , 0 );
+  checkSwap( mHalfEdge[edge2]->getNext() , 0 );
+  checkSwap( mHalfEdge[dualedge]->getNext() , 0 );
+  checkSwap( mHalfEdge[edge3]->getNext() , 0 );
 
   mDecorator->addPoint( new Point3D( p->getX(), p->getY(), 0 ) );//dirty hack to enforce update of decorators
 
diff --git a/src/analysis/interpolation/DualEdgeTriangulation.h b/src/analysis/interpolation/DualEdgeTriangulation.h
index b433c3b..bb47764 100644
--- a/src/analysis/interpolation/DualEdgeTriangulation.h
+++ b/src/analysis/interpolation/DualEdgeTriangulation.h
@@ -148,9 +148,9 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
     /**returns the number of a HalfEdge from a triangle in which 'point' is in. If the number -10 is returned, this means, that 'point' is outside the convex hull. If -5 is returned, then numerical problems with the leftOfTest occured (and the value of the possible edge is stored in the variable 'mUnstableEdge'. -20 means, that the inserted point is exactly on an edge (the number is stored in the variable 'mEdgeWithPoint'). -25 means, that the point is already in the triangulation (the number of the point is stored in the member 'mTwiceInsPoint'. If -100 is returned, this means that something else went wrong*/
     int baseEdgeOfTriangle( Point3D* point );
     /**Checks, if 'edge' has to be swapped because of the empty circle criterion. If so, doSwap(...) is called.*/
-    bool checkSwap( unsigned int edge );
+    bool checkSwap( unsigned int edge, unsigned int recursivDeep );
     /**Swaps 'edge' and test recursively for other swaps (delaunay criterion)*/
-    void doSwap( unsigned int edge );
+    void doSwap( unsigned int edge, unsigned int recursivDeep );
     /**Swaps 'edge' and does no recursiv testing*/
     void doOnlySwap( unsigned int edge );
     /**Number of an edge which does not point to the virtual point. It continuously updated for a fast search*/
-- 
1.7.8.msysgit.0

