Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tesselation.cpp

    rb998c3 re359a8  
    99
    1010#include "helpers.hpp"
    11 #include "info.hpp"
    1211#include "linkedcell.hpp"
    1312#include "log.hpp"
     
    2322/** Constructor of BoundaryPointSet.
    2423 */
    25 BoundaryPointSet::BoundaryPointSet() :
    26     LinesCount(0),
    27     value(0.),
    28     Nr(-1)
    29 {
    30         Info FunctionInfo(__func__);
    31         Log() << Verbose(1) << "Adding noname." << endl;
     24BoundaryPointSet::BoundaryPointSet()
     25{
     26  LinesCount = 0;
     27  Nr = -1;
     28  value = 0.;
    3229};
    3330
     
    3532 * \param *Walker TesselPoint this boundary point represents
    3633 */
    37 BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker) :
    38   LinesCount(0),
    39   node(Walker),
    40   value(0.),
    41   Nr(Walker->nr)
    42 {
    43         Info FunctionInfo(__func__);
    44   Log() << Verbose(1) << "Adding Node " << *Walker << endl;
     34BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker)
     35{
     36  node = Walker;
     37  LinesCount = 0;
     38  Nr = Walker->nr;
     39  value = 0.;
    4540};
    4641
     
    5146BoundaryPointSet::~BoundaryPointSet()
    5247{
    53         Info FunctionInfo(__func__);
    54   //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
     48  //Log() << Verbose(5) << "Erasing point nr. " << Nr << "." << endl;
    5549  if (!lines.empty())
    5650    eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl;
     
    6357void BoundaryPointSet::AddLine(class BoundaryLineSet *line)
    6458{
    65         Info FunctionInfo(__func__);
    66   Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "."
     59  Log() << Verbose(6) << "Adding " << *this << " to line " << *line << "."
    6760      << endl;
    6861  if (line->endpoints[0] == this)
     
    9285/** Constructor of BoundaryLineSet.
    9386 */
    94 BoundaryLineSet::BoundaryLineSet() :
    95     Nr(-1)
    96 {
    97         Info FunctionInfo(__func__);
     87BoundaryLineSet::BoundaryLineSet()
     88{
    9889  for (int i = 0; i < 2; i++)
    9990    endpoints[i] = NULL;
     91  Nr = -1;
    10092};
    10193
     
    10799BoundaryLineSet::BoundaryLineSet(class BoundaryPointSet *Point[2], const int number)
    108100{
    109         Info FunctionInfo(__func__);
    110101  // set number
    111102  Nr = number;
     
    115106  Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
    116107  Point[1]->AddLine(this); //
    117   // set skipped to false
    118   skipped = false;
    119108  // clear triangles list
    120   Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
     109  Log() << Verbose(5) << "New Line with endpoints " << *this << "." << endl;
    121110};
    122111
     
    127116BoundaryLineSet::~BoundaryLineSet()
    128117{
    129         Info FunctionInfo(__func__);
    130118  int Numbers[2];
    131119
     
    146134        for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
    147135          if ((*Runner).second == this) {
    148             //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
     136            //Log() << Verbose(5) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
    149137            endpoints[i]->lines.erase(Runner);
    150138            break;
     
    152140      } else { // there's just a single line left
    153141        if (endpoints[i]->lines.erase(Nr)) {
    154           //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
     142          //Log() << Verbose(5) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
    155143        }
    156144      }
    157145      if (endpoints[i]->lines.empty()) {
    158         //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
     146        //Log() << Verbose(5) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
    159147        if (endpoints[i] != NULL) {
    160148          delete(endpoints[i]);
     
    173161void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
    174162{
    175         Info FunctionInfo(__func__);
    176   Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
     163  Log() << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
    177164  triangles.insert(TrianglePair(triangle->Nr, triangle));
    178165};
     
    184171bool BoundaryLineSet::IsConnectedTo(class BoundaryLineSet *line)
    185172{
    186         Info FunctionInfo(__func__);
    187173  if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
    188174    return true;
     
    199185bool BoundaryLineSet::CheckConvexityCriterion()
    200186{
    201         Info FunctionInfo(__func__);
    202187  Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
    203188  // get the two triangles
    204189  if (triangles.size() != 2) {
    205     eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
     190    eLog() << Verbose(1) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
    206191    return true;
    207192  }
    208193  // check normal vectors
    209194  // have a normal vector on the base line pointing outwards
    210   //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
     195  //Log() << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
    211196  BaseLineCenter.CopyVector(endpoints[0]->node->node);
    212197  BaseLineCenter.AddVector(endpoints[1]->node->node);
     
    214199  BaseLine.CopyVector(endpoints[0]->node->node);
    215200  BaseLine.SubtractVector(endpoints[1]->node->node);
    216   //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
     201  //Log() << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
    217202
    218203  BaseLineNormal.Zero();
     
    222207  class BoundaryPointSet *node = NULL;
    223208  for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    224     //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
     209    //Log() << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    225210    NormalCheck.AddVector(&runner->second->NormalVector);
    226211    NormalCheck.Scale(sign);
     
    229214      BaseLineNormal.CopyVector(&runner->second->NormalVector);   // yes, copy second on top of first
    230215    else {
    231       eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl;
     216      Log() << Verbose(1) << "CRITICAL: Triangle " << *runner->second << " has zero normal vector!" << endl;
     217      exit(255);
    232218    }
    233219    node = runner->second->GetThirdEndpoint(this);
    234220    if (node != NULL) {
    235       //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
     221      //Log() << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    236222      helper[i].CopyVector(node->node->node);
    237223      helper[i].SubtractVector(&BaseLineCenter);
    238224      helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
    239       //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
     225      //Log() << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    240226      i++;
    241227    } else {
    242       eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;
     228      //eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;
    243229      return true;
    244230    }
    245231  }
    246   //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
     232  //Log() << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
    247233  if (NormalCheck.NormSquared() < MYEPSILON) {
    248     Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
     234    Log() << Verbose(3) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
    249235    return true;
    250236  }
     
    252238  double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    253239  if ((angle - M_PI) > -MYEPSILON) {
    254     Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl;
     240    Log() << Verbose(3) << "ACCEPT: Angle is greater than pi: convex." << endl;
    255241    return true;
    256242  } else {
    257     Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl;
     243    Log() << Verbose(3) << "REJECT: Angle is less than pi: concave." << endl;
    258244    return false;
    259245  }
     
    266252bool BoundaryLineSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
    267253{
    268         Info FunctionInfo(__func__);
    269254  for(int i=0;i<2;i++)
    270255    if (point == endpoints[i])
     
    279264class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(class BoundaryPointSet *point)
    280265{
    281         Info FunctionInfo(__func__);
    282266  if (endpoints[0] == point)
    283267    return endpoints[1];
     
    302286/** Constructor for BoundaryTriangleSet.
    303287 */
    304 BoundaryTriangleSet::BoundaryTriangleSet() :
    305   Nr(-1)
    306 {
    307         Info FunctionInfo(__func__);
     288BoundaryTriangleSet::BoundaryTriangleSet()
     289{
    308290  for (int i = 0; i < 3; i++)
    309291    {
     
    311293      lines[i] = NULL;
    312294    }
     295  Nr = -1;
    313296};
    314297
     
    317300 * \param number number of triangle
    318301 */
    319 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number) :
    320   Nr(number)
    321 {
    322         Info FunctionInfo(__func__);
     302BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number)
     303{
    323304  // set number
     305  Nr = number;
    324306  // set lines
    325   for (int i = 0; i < 3; i++) {
    326     lines[i] = line[i];
    327     lines[i]->AddTriangle(this);
    328   }
     307  Log() << Verbose(5) << "New triangle " << Nr << ":" << endl;
     308  for (int i = 0; i < 3; i++)
     309    {
     310      lines[i] = line[i];
     311      lines[i]->AddTriangle(this);
     312    }
    329313  // get ascending order of endpoints
    330   PointMap OrderMap;
     314  map<int, class BoundaryPointSet *> OrderMap;
    331315  for (int i = 0; i < 3; i++)
    332316    // for all three lines
    333     for (int j = 0; j < 2; j++) { // for both endpoints
    334       OrderMap.insert(pair<int, class BoundaryPointSet *> (
    335           line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
    336       // and we don't care whether insertion fails
    337     }
     317    for (int j = 0; j < 2; j++)
     318      { // for both endpoints
     319        OrderMap.insert(pair<int, class BoundaryPointSet *> (
     320            line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
     321        // and we don't care whether insertion fails
     322      }
    338323  // set endpoints
    339324  int Counter = 0;
    340   Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl;
    341   for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
    342     endpoints[Counter] = runner->second;
    343     Log() << Verbose(0) << " " << *endpoints[Counter] << endl;
    344     Counter++;
    345   }
    346   if (Counter < 3) {
    347     eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl;
    348     performCriticalExit();
    349   }
     325  Log() << Verbose(6) << " with end points ";
     326  for (map<int, class BoundaryPointSet *>::iterator runner = OrderMap.begin(); runner
     327      != OrderMap.end(); runner++)
     328    {
     329      endpoints[Counter] = runner->second;
     330      Log() << Verbose(0) << " " << *endpoints[Counter];
     331      Counter++;
     332    }
     333  if (Counter < 3)
     334    {
     335      eLog() << Verbose(0) << "ERROR! We have a triangle with only two distinct endpoints!" << endl;
     336      performCriticalExit();
     337    }
     338  Log() << Verbose(0) << "." << endl;
    350339};
    351340
     
    356345BoundaryTriangleSet::~BoundaryTriangleSet()
    357346{
    358         Info FunctionInfo(__func__);
    359347  for (int i = 0; i < 3; i++) {
    360348    if (lines[i] != NULL) {
    361349      if (lines[i]->triangles.erase(Nr)) {
    362         //Log() << Verbose(0) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
     350        //Log() << Verbose(5) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
    363351      }
    364352      if (lines[i]->triangles.empty()) {
    365           //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
     353          //Log() << Verbose(5) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
    366354          delete (lines[i]);
    367355          lines[i] = NULL;
     
    369357    }
    370358  }
    371   //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
     359  //Log() << Verbose(5) << "Erasing triangle Nr." << Nr << " itself." << endl;
    372360};
    373361
     
    378366void BoundaryTriangleSet::GetNormalVector(Vector &OtherVector)
    379367{
    380         Info FunctionInfo(__func__);
    381368  // get normal vector
    382369  NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     
    385372  if (NormalVector.ScalarProduct(&OtherVector) > 0.)
    386373    NormalVector.Scale(-1.);
    387   Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl;
    388374};
    389375
     
    402388bool BoundaryTriangleSet::GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection)
    403389{
    404         Info FunctionInfo(__func__);
    405390  Vector CrossPoint;
    406391  Vector helper;
    407392
    408393  if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
    409     eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
     394    Log() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
    410395    return false;
    411396  }
     
    423408  } while (CrossPoint.NormSquared() < MYEPSILON);
    424409  if (i==3) {
    425     eLog() << Verbose(0) << "Could not find any cross points, something's utterly wrong here!" << endl;
     410    eLog() << Verbose(1) << "Could not find any cross points, something's utterly wrong here!" << endl;
     411    exit(255);
    426412  }
    427413  CrossPoint.SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     
    442428bool BoundaryTriangleSet::ContainsBoundaryLine(class BoundaryLineSet *line)
    443429{
    444         Info FunctionInfo(__func__);
    445430  for(int i=0;i<3;i++)
    446431    if (line == lines[i])
     
    455440bool BoundaryTriangleSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
    456441{
    457         Info FunctionInfo(__func__);
    458442  for(int i=0;i<3;i++)
    459443    if (point == endpoints[i])
     
    468452bool BoundaryTriangleSet::ContainsBoundaryPoint(class TesselPoint *point)
    469453{
    470         Info FunctionInfo(__func__);
    471454  for(int i=0;i<3;i++)
    472455    if (point == endpoints[i]->node)
     
    481464bool BoundaryTriangleSet::IsPresentTupel(class BoundaryPointSet *Points[3])
    482465{
    483         Info FunctionInfo(__func__);
    484466  return (((endpoints[0] == Points[0])
    485467            || (endpoints[0] == Points[1])
     
    503485bool BoundaryTriangleSet::IsPresentTupel(class BoundaryTriangleSet *T)
    504486{
    505         Info FunctionInfo(__func__);
    506487  return (((endpoints[0] == T->endpoints[0])
    507488            || (endpoints[0] == T->endpoints[1])
     
    525506class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(class BoundaryLineSet *line)
    526507{
    527         Info FunctionInfo(__func__);
    528508  // sanity check
    529509  if (!ContainsBoundaryLine(line))
     
    542522void BoundaryTriangleSet::GetCenter(Vector *center)
    543523{
    544         Info FunctionInfo(__func__);
    545524  center->Zero();
    546525  for(int i=0;i<3;i++)
     
    555534ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
    556535{
    557   ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]";
    558 //  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
    559 //      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
     536  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
     537      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
    560538  return ost;
    561539};
    562540
    563 // ======================================== Polygons on Boundary =================================
    564 
    565 /** Constructor for BoundaryPolygonSet.
    566  */
    567 BoundaryPolygonSet::BoundaryPolygonSet() :
    568   Nr(-1)
    569 {
    570   Info FunctionInfo(__func__);
    571 };
    572 
    573 /** Destructor of BoundaryPolygonSet.
    574  * Just clears endpoints.
    575  * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
    576  */
    577 BoundaryPolygonSet::~BoundaryPolygonSet()
    578 {
    579   Info FunctionInfo(__func__);
    580   endpoints.clear();
    581   Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl;
    582 };
    583 
    584 /** Calculates the normal vector for this triangle.
    585  * Is made unique by comparison with \a OtherVector to point in the other direction.
    586  * \param &OtherVector direction vector to make normal vector unique.
    587  * \return allocated vector in normal direction
    588  */
    589 Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
    590 {
    591   Info FunctionInfo(__func__);
    592   // get normal vector
    593   Vector TemporaryNormal;
    594   Vector *TotalNormal = new Vector;
    595   PointSet::const_iterator Runner[3];
    596   for (int i=0;i<3; i++) {
    597     Runner[i] = endpoints.begin();
    598     for (int j = 0; j<i; j++) { // go as much further
    599       Runner[i]++;
    600       if (Runner[i] == endpoints.end()) {
    601         eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl;
    602         performCriticalExit();
    603       }
    604     }
    605   }
    606   TotalNormal->Zero();
    607   int counter=0;
    608   for (; Runner[2] != endpoints.end(); ) {
    609     TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
    610     for (int i=0;i<3;i++) // increase each of them
    611       Runner[i]++;
    612     TotalNormal->AddVector(&TemporaryNormal);
    613   }
    614   TotalNormal->Scale(1./(double)counter);
    615 
    616   // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    617   if (TotalNormal->ScalarProduct(&OtherVector) > 0.)
    618     TotalNormal->Scale(-1.);
    619   Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl;
    620 
    621   return TotalNormal;
    622 };
    623 
    624 /** Calculates the center point of the triangle.
    625  * Is third of the sum of all endpoints.
    626  * \param *center central point on return.
    627  */
    628 void BoundaryPolygonSet::GetCenter(Vector * const center) const
    629 {
    630   Info FunctionInfo(__func__);
    631   center->Zero();
    632   int counter = 0;
    633   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    634     center->AddVector((*Runner)->node->node);
    635     counter++;
    636   }
    637   center->Scale(1./(double)counter);
    638   Log() << Verbose(1) << "Center is at " << *center << "." << endl;
    639 }
    640 
    641 /** Checks whether the polygons contains all three endpoints of the triangle.
    642  * \param *triangle triangle to test
    643  * \return true - triangle is contained polygon, false - is not
    644  */
    645 bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
    646 {
    647   Info FunctionInfo(__func__);
    648   return ContainsPresentTupel(triangle->endpoints, 3);
    649 };
    650 
    651 /** Checks whether the polygons contains both endpoints of the line.
    652  * \param *line line to test
    653  * \return true - line is of the triangle, false - is not
    654  */
    655 bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
    656 {
    657   Info FunctionInfo(__func__);
    658   return ContainsPresentTupel(line->endpoints, 2);
    659 };
    660 
    661 /** Checks whether point is any of the three endpoints this triangle contains.
    662  * \param *point point to test
    663  * \return true - point is of the triangle, false - is not
    664  */
    665 bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    666 {
    667   Info FunctionInfo(__func__);
    668   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    669     Log() << Verbose(0) << "Checking against " << **Runner << endl;
    670     if (point == (*Runner)) {
    671       Log() << Verbose(0) << " Contained." << endl;
    672       return true;
    673     }
    674   }
    675   Log() << Verbose(0) << " Not contained." << endl;
    676   return false;
    677 };
    678 
    679 /** Checks whether point is any of the three endpoints this triangle contains.
    680  * \param *point TesselPoint to test
    681  * \return true - point is of the triangle, false - is not
    682  */
    683 bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
    684 {
    685   Info FunctionInfo(__func__);
    686   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    687     if (point == (*Runner)->node) {
    688       Log() << Verbose(0) << " Contained." << endl;
    689       return true;
    690     }
    691   Log() << Verbose(0) << " Not contained." << endl;
    692   return false;
    693 };
    694 
    695 /** Checks whether given array of \a *Points coincide with polygons's endpoints.
    696  * \param **Points pointer to an array of BoundaryPointSet
    697  * \param dim dimension of array
    698  * \return true - set of points is contained in polygon, false - is not
    699  */
    700 bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
    701 {
    702   Info FunctionInfo(__func__);
    703   int counter = 0;
    704   Log() << Verbose(1) << "Polygon is " << *this << endl;
    705   for(int i=0;i<dim;i++) {
    706     Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl;
    707     if (ContainsBoundaryPoint(Points[i])) {
    708       counter++;
    709     }
    710   }
    711 
    712   if (counter == dim)
    713     return true;
    714   else
    715     return false;
    716 };
    717 
    718 /** Checks whether given PointList coincide with polygons's endpoints.
    719  * \param &endpoints PointList
    720  * \return true - set of points is contained in polygon, false - is not
    721  */
    722 bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
    723 {
    724   Info FunctionInfo(__func__);
    725   size_t counter = 0;
    726   Log() << Verbose(1) << "Polygon is " << *this << endl;
    727   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    728     Log() << Verbose(1) << " Testing endpoint " << **Runner << endl;
    729     if (ContainsBoundaryPoint(*Runner))
    730       counter++;
    731   }
    732 
    733   if (counter == endpoints.size())
    734     return true;
    735   else
    736     return false;
    737 };
    738 
    739 /** Checks whether given set of \a *Points coincide with polygons's endpoints.
    740  * \param *P pointer to BoundaryPolygonSet
    741  * \return true - is the very triangle, false - is not
    742  */
    743 bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
    744 {
    745   return ContainsPresentTupel((const PointSet)P->endpoints);
    746 };
    747 
    748 /** Gathers all the endpoints' triangles in a unique set.
    749  * \return set of all triangles
    750  */
    751 TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
    752 {
    753   Info FunctionInfo(__func__);
    754   pair <TriangleSet::iterator, bool> Tester;
    755   TriangleSet *triangles = new TriangleSet;
    756 
    757   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    758     for(LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
    759       for(TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
    760         //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
    761         if (ContainsBoundaryTriangle(Sprinter->second)) {
    762           Tester = triangles->insert(Sprinter->second);
    763           if (Tester.second)
    764             Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl;
    765         }
    766       }
    767 
    768   Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl;
    769   return triangles;
    770 };
    771 
    772 /** Fills the endpoints of this polygon from the triangles attached to \a *line.
    773  * \param *line lines with triangles attached
    774  * \return true - polygon contains endpoints, false - line was NULL
    775  */
    776 bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
    777 {
    778   Info FunctionInfo(__func__);
    779   pair <PointSet::iterator, bool> Tester;
    780   if (line == NULL)
    781     return false;
    782   Log() << Verbose(1) << "Filling polygon from line " << *line << endl;
    783   for(TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
    784     for (int i=0;i<3;i++) {
    785       Tester = endpoints.insert((Runner->second)->endpoints[i]);
    786       if (Tester.second)
    787         Log() << Verbose(1) << "  Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl;
    788     }
    789   }
    790 
    791   return true;
    792 };
    793 
    794 /** output operator for BoundaryPolygonSet.
    795  * \param &ost output stream
    796  * \param &a boundary polygon
    797  */
    798 ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
    799 {
    800   ost << "[" << a.Nr << "|";
    801   for(PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
    802    ost << (*Runner)->node->Name;
    803    Runner++;
    804    if (Runner != a.endpoints.end())
    805      ost << ",";
    806   }
    807   ost<< "]";
    808   return ost;
    809 };
    810 
    811541// =========================================================== class TESSELPOINT ===========================================
    812542
     
    815545TesselPoint::TesselPoint()
    816546{
    817   Info FunctionInfo(__func__);
    818547  node = NULL;
    819548  nr = -1;
     
    825554TesselPoint::~TesselPoint()
    826555{
    827   Info FunctionInfo(__func__);
    828556};
    829557
     
    840568ostream & TesselPoint::operator << (ostream &ost)
    841569{
    842         Info FunctionInfo(__func__);
    843   ost << "[" << (nr) << "|" << this << "]";
     570  ost << "[" << (Name) << "|" << this << "]";
    844571  return ost;
    845572};
     
    852579PointCloud::PointCloud()
    853580{
    854         Info FunctionInfo(__func__);
     581
    855582};
    856583
     
    859586PointCloud::~PointCloud()
    860587{
    861         Info FunctionInfo(__func__);
     588
    862589};
    863590
     
    866593/** Constructor of class CandidateForTesselation.
    867594 */
    868 CandidateForTesselation::CandidateForTesselation (BoundaryLineSet* line) :
    869   BaseLine(line),
    870   ShortestAngle(2.*M_PI),
    871   OtherShortestAngle(2.*M_PI)
    872 {
    873         Info FunctionInfo(__func__);
    874 };
    875 
    876 
    877 /** Constructor of class CandidateForTesselation.
    878  */
    879 CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
    880     BaseLine(line),
    881     IsDegenerated(false),
    882     ShortestAngle(2.*M_PI),
    883     OtherShortestAngle(2.*M_PI)
    884 {
    885         Info FunctionInfo(__func__);
     595CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) {
     596  point = candidate;
     597  BaseLine = line;
    886598  OptCenter.CopyVector(&OptCandidateCenter);
    887599  OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
     
    891603 */
    892604CandidateForTesselation::~CandidateForTesselation() {
     605  point = NULL;
    893606  BaseLine = NULL;
    894607};
    895608
    896 /** output operator for CandidateForTesselation.
    897  * \param &ost output stream
    898  * \param &a boundary line
    899  */
    900 ostream & operator <<(ostream &ost, const  CandidateForTesselation &a)
    901 {
    902   ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with ";
    903   if (a.pointlist.empty())
    904     ost << "no candidate.";
    905   else {
    906     ost << "candidate";
    907     if (a.pointlist.size() != 1)
    908       ost << "s ";
    909     else
    910       ost << " ";
    911     for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
    912       ost << *(*Runner) << " ";
    913     ost << " at angle " << (a.ShortestAngle)<< ".";
    914   }
    915 
    916   return ost;
    917 };
    918 
    919 
    920609// =========================================================== class TESSELATION ===========================================
    921610
    922611/** Constructor of class Tesselation.
    923612 */
    924 Tesselation::Tesselation() :
    925   PointsOnBoundaryCount(0),
    926   LinesOnBoundaryCount(0),
    927   TrianglesOnBoundaryCount(0),
    928   LastTriangle(NULL),
    929   TriangleFilesWritten(0),
    930   InternalPointer(PointsOnBoundary.begin())
    931 {
    932         Info FunctionInfo(__func__);
     613Tesselation::Tesselation()
     614{
     615  PointsOnBoundaryCount = 0;
     616  LinesOnBoundaryCount = 0;
     617  TrianglesOnBoundaryCount = 0;
     618  InternalPointer = PointsOnBoundary.begin();
     619  LastTriangle = NULL;
     620  TriangleFilesWritten = 0;
    933621}
    934622;
     
    939627Tesselation::~Tesselation()
    940628{
    941         Info FunctionInfo(__func__);
    942   Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl;
     629  Log() << Verbose(1) << "Free'ing TesselStruct ... " << endl;
    943630  for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
    944631    if (runner->second != NULL) {
     
    948635      eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl;
    949636  }
    950   Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
     637  Log() << Verbose(1) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
    951638}
    952639;
     
    957644Vector * Tesselation::GetCenter(ofstream *out) const
    958645{
    959         Info FunctionInfo(__func__);
    960646  Vector *Center = new Vector(0.,0.,0.);
    961647  int num=0;
     
    973659TesselPoint * Tesselation::GetPoint() const
    974660{
    975         Info FunctionInfo(__func__);
    976661  return (InternalPointer->second->node);
    977662};
     
    982667TesselPoint * Tesselation::GetTerminalPoint() const
    983668{
    984         Info FunctionInfo(__func__);
    985669  PointMap::const_iterator Runner = PointsOnBoundary.end();
    986670  Runner--;
     
    993677void Tesselation::GoToNext() const
    994678{
    995         Info FunctionInfo(__func__);
    996679  if (InternalPointer != PointsOnBoundary.end())
    997680    InternalPointer++;
     
    1003686void Tesselation::GoToPrevious() const
    1004687{
    1005         Info FunctionInfo(__func__);
    1006688  if (InternalPointer != PointsOnBoundary.begin())
    1007689    InternalPointer--;
     
    1013695void Tesselation::GoToFirst() const
    1014696{
    1015         Info FunctionInfo(__func__);
    1016697  InternalPointer = PointsOnBoundary.begin();
    1017698};
     
    1022703void Tesselation::GoToLast() const
    1023704{
    1024         Info FunctionInfo(__func__);
    1025705  InternalPointer = PointsOnBoundary.end();
    1026706  InternalPointer--;
     
    1032712bool Tesselation::IsEmpty() const
    1033713{
    1034         Info FunctionInfo(__func__);
    1035714  return (PointsOnBoundary.empty());
    1036715};
     
    1041720bool Tesselation::IsEnd() const
    1042721{
    1043         Info FunctionInfo(__func__);
    1044722  return (InternalPointer == PointsOnBoundary.end());
    1045723};
     
    1054732Tesselation::GuessStartingTriangle()
    1055733{
    1056         Info FunctionInfo(__func__);
    1057734  // 4b. create a starting triangle
    1058735  // 4b1. create all distances
     
    1101778          baseline->second.first->second->node->node,
    1102779          baseline->second.second->second->node->node);
    1103       Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl;
     780      Log() << Verbose(2) << "Plane vector of candidate triangle is ";
     781      PlaneVector.Output();
     782      Log() << Verbose(0) << endl;
    1104783      // 4. loop over all points
    1105784      double sign = 0.;
     
    1117796          if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    1118797            continue;
    1119           Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl;
     798          Log() << Verbose(3) << "Projection of " << checker->second->node->Name
     799              << " yields distance of " << distance << "." << endl;
    1120800          tmp = distance / fabs(distance);
    1121801          // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
     
    1170850      if (checker == PointsOnBoundary.end())
    1171851        {
    1172           Log() << Verbose(2) << "Looks like we have a candidate!" << endl;
     852          Log() << Verbose(0) << "Looks like we have a candidate!" << endl;
    1173853          break;
    1174854        }
     
    1200880  else
    1201881    {
    1202       eLog() << Verbose(0) << "No starting triangle found." << endl;
     882      Log() << Verbose(1) << "No starting triangle found." << endl;
     883      exit(255);
    1203884    }
    1204885}
     
    1220901void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
    1221902{
    1222         Info FunctionInfo(__func__);
    1223903  bool flag;
    1224904  PointMap::iterator winner;
     
    1239919        // get peak point with respect to this base line's only triangle
    1240920        BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
    1241         Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl;
     921        Log() << Verbose(2) << "Current baseline is between " << *(baseline->second) << "." << endl;
    1242922        for (int i = 0; i < 3; i++)
    1243923          if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
    1244924            peak = BTS->endpoints[i];
    1245         Log() << Verbose(1) << " and has peak " << *peak << "." << endl;
     925        Log() << Verbose(3) << " and has peak " << *peak << "." << endl;
    1246926
    1247927        // prepare some auxiliary vectors
     
    1258938          CenterVector.AddVector(BTS->endpoints[i]->node->node);
    1259939        CenterVector.Scale(1. / 3.);
    1260         Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl;
     940        Log() << Verbose(4) << "CenterVector of base triangle is " << CenterVector << endl;
    1261941
    1262942        // normal vector of triangle
     
    1265945        BTS->GetNormalVector(NormalVector);
    1266946        NormalVector.CopyVector(&BTS->NormalVector);
    1267         Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl;
     947        Log() << Verbose(4) << "NormalVector of base triangle is " << NormalVector << endl;
    1268948
    1269949        // vector in propagation direction (out of triangle)
     
    1272952        TempVector.CopyVector(&CenterVector);
    1273953        TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    1274         //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
     954        //Log() << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    1275955        if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
    1276956          PropagationVector.Scale(-1.);
    1277         Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl;
     957        Log() << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl;
    1278958        winner = PointsOnBoundary.end();
    1279959
     
    1281961        for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
    1282962          if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
    1283             Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl;
     963            Log() << Verbose(3) << "Target point is " << *(target->second) << ":" << endl;
    1284964
    1285965            // first check direction, so that triangles don't intersect
     
    1288968            VirtualNormalVector.ProjectOntoPlane(&NormalVector);
    1289969            TempAngle = VirtualNormalVector.Angle(&PropagationVector);
    1290             Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
     970            Log() << Verbose(4) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
    1291971            if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees)
    1292               Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
     972              Log() << Verbose(4) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
    1293973              continue;
    1294974            } else
    1295               Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
     975              Log() << Verbose(4) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
    1296976
    1297977            // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
     
    1299979            LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
    1300980            if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
    1301               Log() << Verbose(2) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl;
     981              Log() << Verbose(4) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl;
    1302982              continue;
    1303983            }
    1304984            if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
    1305               Log() << Verbose(2) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl;
     985              Log() << Verbose(4) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl;
    1306986              continue;
    1307987            }
     
    13201000            helper.ProjectOntoPlane(&TempVector);
    13211001            if (fabs(helper.NormSquared()) < MYEPSILON) {
    1322               Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl;
     1002              Log() << Verbose(4) << "Chosen set of vectors is linear dependent." << endl;
    13231003              continue;
    13241004            }
     
    13371017            // calculate angle
    13381018            TempAngle = NormalVector.Angle(&VirtualNormalVector);
    1339             Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
     1019            Log() << Verbose(4) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
    13401020            if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
    13411021              SmallestAngle = TempAngle;
    13421022              winner = target;
    1343               Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1023              Log() << Verbose(4) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
    13441024            } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
    13451025              // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
     
    13591039                SmallestAngle = TempAngle;
    13601040                winner = target;
    1361                 Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
     1041                Log() << Verbose(4) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
    13621042              } else
    1363                 Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
     1043                Log() << Verbose(4) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
    13641044            } else
    1365               Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1045              Log() << Verbose(4) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
    13661046          }
    13671047        } // end of loop over all boundary points
     
    13691049        // 5b. The point of the above whose triangle has the greatest angle with the triangle the current line belongs to (it only belongs to one, remember!): New triangle
    13701050        if (winner != PointsOnBoundary.end()) {
    1371           Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
     1051          Log() << Verbose(2) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
    13721052          // create the lins of not yet present
    13731053          BLS[0] = baseline->second;
     
    13991079          TrianglesOnBoundaryCount++;
    14001080        } else {
    1401           eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
     1081          Log() << Verbose(1) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
    14021082        }
    14031083
    14041084        // 5d. If the set of lines is not yet empty, go to 5. and continue
    14051085      } else
    1406         Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
     1086        Log() << Verbose(2) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
    14071087  } while (flag);
    14081088
     
    14191099bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
    14201100{
    1421         Info FunctionInfo(__func__);
    14221101  Vector Intersection, Normal;
    14231102  TesselPoint *Walker = NULL;
     
    14261105  bool AddFlag = false;
    14271106  LinkedCell *BoundaryPoints = NULL;
     1107
     1108  Log() << Verbose(1) << "Begin of InsertStraddlingPoints" << endl;
    14281109
    14291110  cloud->GoToFirst();
     
    14361117    }
    14371118    Walker = cloud->GetPoint();
    1438     Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;
     1119    Log() << Verbose(2) << "Current point is " << *Walker << "." << endl;
    14391120    // get the next triangle
    14401121    triangles = FindClosestTrianglesToPoint(Walker->node, BoundaryPoints);
    14411122    BTS = triangles->front();
    14421123    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
    1443       Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl;
     1124      Log() << Verbose(2) << "No triangles found, probably a tesselation point itself." << endl;
    14441125      cloud->GoToNext();
    14451126      continue;
    14461127    } else {
    14471128    }
    1448     Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl;
     1129    Log() << Verbose(2) << "Closest triangle is " << *BTS << "." << endl;
    14491130    // get the intersection point
    14501131    if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
    1451       Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl;
     1132      Log() << Verbose(2) << "We have an intersection at " << Intersection << "." << endl;
    14521133      // we have the intersection, check whether in- or outside of boundary
    14531134      if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
    14541135        // inside, next!
    1455         Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
     1136        Log() << Verbose(2) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
    14561137      } else {
    14571138        // outside!
    1458         Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
     1139        Log() << Verbose(2) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
    14591140        class BoundaryLineSet *OldLines[3], *NewLines[3];
    14601141        class BoundaryPointSet *OldPoints[3], *NewPoint;
     
    14661147        Normal.CopyVector(&BTS->NormalVector);
    14671148        // add Walker to boundary points
    1468         Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl;
     1149        Log() << Verbose(2) << "Adding " << *Walker << " to BoundaryPoints." << endl;
    14691150        AddFlag = true;
    14701151        if (AddBoundaryPoint(Walker,0))
     
    14731154          continue;
    14741155        // remove triangle
    1475         Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl;
     1156        Log() << Verbose(2) << "Erasing triangle " << *BTS << "." << endl;
    14761157        TrianglesOnBoundary.erase(BTS->Nr);
    14771158        delete(BTS);
     
    14811162          BPS[1] = OldPoints[i];
    14821163          NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1483           Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl;
     1164          Log() << Verbose(3) << "Creating new line " << *NewLines[i] << "." << endl;
    14841165          LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
    14851166          LinesOnBoundaryCount++;
     
    14921173            if (NewLines[j]->IsConnectedTo(BLS[0])) {
    14931174              if (n>2) {
    1494                 eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl;
     1175                Log() << Verbose(1) << BLS[0] << " connects to all of the new lines?!" << endl;
    14951176                return false;
    14961177              } else
     
    15031184          BTS->GetNormalVector(Normal);
    15041185          Normal.Scale(-1.);
    1505           Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl;
     1186          Log() << Verbose(2) << "Created new triangle " << *BTS << "." << endl;
    15061187          TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    15071188          TrianglesOnBoundaryCount++;
     
    15171198  // exit
    15181199  delete(Center);
     1200  Log() << Verbose(1) << "End of InsertStraddlingPoints" << endl;
    15191201  return true;
    15201202};
     
    15271209bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
    15281210{
    1529         Info FunctionInfo(__func__);
    15301211  PointTestPair InsertUnique;
    15311212  BPS[n] = new class BoundaryPointSet(Walker);
     
    15491230void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
    15501231{
    1551         Info FunctionInfo(__func__);
    15521232  PointTestPair InsertUnique;
    15531233  TPS[n] = new class BoundaryPointSet(Candidate);
     
    15571237  } else {
    15581238    delete TPS[n];
    1559     Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
     1239    Log() << Verbose(4) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
    15601240    TPS[n] = (InsertUnique.first)->second;
    15611241  }
     
    15701250void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
    15711251{
    1572         Info FunctionInfo(__func__);
    15731252  PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
    15741253  if (FindPoint != PointsOnBoundary.end())
     
    15881267  bool insertNewLine = true;
    15891268
    1590   LineMap::iterator FindLine = a->lines.find(b->node->nr);
    1591   if (FindLine != a->lines.end()) {
    1592     Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
    1593 
     1269  if (a->lines.find(b->node->nr) != a->lines.end()) {
     1270    LineMap::iterator FindLine = a->lines.find(b->node->nr);
    15941271    pair<LineMap::iterator,LineMap::iterator> FindPair;
    15951272    FindPair = a->lines.equal_range(b->node->nr);
     1273    Log() << Verbose(5) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
    15961274
    15971275    for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     
    15991277      if (FindLine->second->triangles.size() < 2) {
    16001278        insertNewLine = false;
    1601         Log() << Verbose(0) << "Using existing line " << *FindLine->second << endl;
     1279        Log() << Verbose(4) << "Using existing line " << *FindLine->second << endl;
    16021280
    16031281        BPS[0] = FindLine->second->endpoints[0];
    16041282        BPS[1] = FindLine->second->endpoints[1];
    16051283        BLS[n] = FindLine->second;
    1606 
    1607         // remove existing line from OpenLines
    1608         CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
    1609         if (CandidateLine != OpenLines.end()) {
    1610           Log() << Verbose(1) << " Removing line from OpenLines." << endl;
    1611           delete(CandidateLine->second);
    1612           OpenLines.erase(CandidateLine);
    1613         } else {
    1614           eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl;
    1615         }
    16161284
    16171285        break;
     
    16361304void Tesselation::AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
    16371305{
    1638         Info FunctionInfo(__func__);
    1639   Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
     1306  Log() << Verbose(4) << "Adding line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
    16401307  BPS[0] = a;
    16411308  BPS[1] = b;
     
    16451312  // increase counter
    16461313  LinesOnBoundaryCount++;
    1647   // also add to open lines
    1648   CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
    1649   OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
    16501314};
    16511315
     
    16551319void Tesselation::AddTesselationTriangle()
    16561320{
    1657         Info FunctionInfo(__func__);
    16581321  Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
    16591322
     
    16741337void Tesselation::AddTesselationTriangle(const int nr)
    16751338{
    1676         Info FunctionInfo(__func__);
    1677   Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1339  Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
    16781340
    16791341  // add triangle to global map
     
    16931355void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
    16941356{
    1695         Info FunctionInfo(__func__);
    16961357  if (triangle == NULL)
    16971358    return;
    16981359  for (int i = 0; i < 3; i++) {
    16991360    if (triangle->lines[i] != NULL) {
    1700       Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
     1361      Log() << Verbose(5) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
    17011362      triangle->lines[i]->triangles.erase(triangle->Nr);
    17021363      if (triangle->lines[i]->triangles.empty()) {
    1703           Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
     1364          Log() << Verbose(5) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
    17041365          RemoveTesselationLine(triangle->lines[i]);
    17051366      } else {
    1706         Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ";
    1707         OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
     1367        Log() << Verbose(5) << *triangle->lines[i] << " is still attached to another triangle: ";
    17081368        for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
    17091369          Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
    17101370        Log() << Verbose(0) << endl;
    17111371//        for (int j=0;j<2;j++) {
    1712 //          Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
     1372//          Log() << Verbose(5) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
    17131373//          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
    17141374//            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
     
    17221382
    17231383  if (TrianglesOnBoundary.erase(triangle->Nr))
    1724     Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
     1384    Log() << Verbose(5) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
    17251385  delete(triangle);
    17261386};
     
    17321392void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
    17331393{
    1734         Info FunctionInfo(__func__);
    17351394  int Numbers[2];
    17361395
     
    17531412        for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
    17541413          if ((*Runner).second == line) {
    1755             Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     1414            Log() << Verbose(5) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
    17561415            line->endpoints[i]->lines.erase(Runner);
    17571416            break;
     
    17591418      } else { // there's just a single line left
    17601419        if (line->endpoints[i]->lines.erase(line->Nr))
    1761           Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     1420          Log() << Verbose(5) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
    17621421      }
    17631422      if (line->endpoints[i]->lines.empty()) {
    1764         Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
     1423        Log() << Verbose(5) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
    17651424        RemoveTesselationPoint(line->endpoints[i]);
    17661425      } else {
    1767         Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ";
     1426        Log() << Verbose(5) << *line->endpoints[i] << " has still lines it's attached to: ";
    17681427        for(LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
    17691428          Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
     
    17781437
    17791438  if (LinesOnBoundary.erase(line->Nr))
    1780     Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl;
     1439    Log() << Verbose(5) << "Removing line Nr. " << line->Nr << "." << endl;
    17811440  delete(line);
    17821441};
     
    17891448void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
    17901449{
    1791         Info FunctionInfo(__func__);
    17921450  if (point == NULL)
    17931451    return;
    17941452  if (PointsOnBoundary.erase(point->Nr))
    1795     Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl;
     1453    Log() << Verbose(5) << "Removing point Nr. " << point->Nr << "." << endl;
    17961454  delete(point);
    17971455};
     
    18081466int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
    18091467{
    1810         Info FunctionInfo(__func__);
    18111468  int adjacentTriangleCount = 0;
    18121469  class BoundaryPointSet *Points[3];
    18131470
     1471  Log() << Verbose(2) << "Begin of CheckPresenceOfTriangle" << endl;
    18141472  // builds a triangle point set (Points) of the end points
    18151473  for (int i = 0; i < 3; i++) {
     
    18301488          for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
    18311489            TriangleMap *triangles = &FindLine->second->triangles;
    1832             Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
     1490            Log() << Verbose(3) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
    18331491            for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
    18341492              if (FindTriangle->second->IsPresentTupel(Points)) {
     
    18361494              }
    18371495            }
    1838             Log() << Verbose(1) << "end." << endl;
     1496            Log() << Verbose(3) << "end." << endl;
    18391497          }
    18401498          // Only one of the triangle lines must be considered for the triangle count.
    1841           //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     1499          //Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    18421500          //return adjacentTriangleCount;
    18431501        }
     
    18461504  }
    18471505
    1848   Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     1506  Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     1507  Log() << Verbose(2) << "End of CheckPresenceOfTriangle" << endl;
    18491508  return adjacentTriangleCount;
    18501509};
     
    18601519class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
    18611520{
    1862         Info FunctionInfo(__func__);
    18631521  class BoundaryTriangleSet *triangle = NULL;
    18641522  class BoundaryPointSet *Points[3];
     
    18901548          }
    18911549          // Only one of the triangle lines must be considered for the triangle count.
    1892           //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     1550          //Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    18931551          //return adjacentTriangleCount;
    18941552        }
     
    19111569void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
    19121570{
    1913         Info FunctionInfo(__func__);
     1571  Log() << Verbose(1) << "Begin of FindStartingTriangle\n";
    19141572  int i = 0;
     1573  TesselPoint* FirstPoint = NULL;
     1574  TesselPoint* SecondPoint = NULL;
    19151575  TesselPoint* MaxPoint[NDIM];
    1916   TesselPoint* Temporary;
    19171576  double maxCoordinate[NDIM];
    1918   BoundaryLineSet BaseLine;
     1577  Vector Oben;
    19191578  Vector helper;
    19201579  Vector Chord;
    19211580  Vector SearchDirection;
    1922   Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
    1923   Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
    1924   Vector SphereCenter;
    1925   Vector NormalVector;
    1926 
    1927   NormalVector.Zero();
     1581
     1582  Oben.Zero();
    19281583
    19291584  for (i = 0; i < 3; i++) {
     
    19381593      for (LC->n[(i+2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {
    19391594        const LinkedNodes *List = LC->GetCurrentCell();
    1940         //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     1595        //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    19411596        if (List != NULL) {
    19421597          for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
    19431598            if ((*Runner)->node->x[i] > maxCoordinate[i]) {
    1944               Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
     1599              Log() << Verbose(2) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
    19451600              maxCoordinate[i] = (*Runner)->node->x[i];
    19461601              MaxPoint[i] = (*Runner);
     
    19531608  }
    19541609
    1955   Log() << Verbose(1) << "Found maximum coordinates: ";
     1610  Log() << Verbose(2) << "Found maximum coordinates: ";
    19561611  for (int i=0;i<NDIM;i++)
    19571612    Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t";
     
    19591614
    19601615  BTS = NULL;
     1616  CandidateList *OptCandidates = new CandidateList();
    19611617  for (int k=0;k<NDIM;k++) {
    1962     NormalVector.Zero();
    1963     NormalVector.x[k] = 1.;
    1964     BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
    1965     Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
     1618    Oben.Zero();
     1619    Oben.x[k] = 1.;
     1620    FirstPoint = MaxPoint[k];
     1621    Log() << Verbose(1) << "Coordinates of start node at " << *FirstPoint->node << "." << endl;
    19661622
    19671623    double ShortestAngle;
     1624    TesselPoint* OptCandidate = NULL;
    19681625    ShortestAngle = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
    19691626
    1970     FindSecondPointForTesselation(BaseLine.endpoints[0]->node, NormalVector, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
    1971     if (Temporary == NULL)  // have we found a second point?
     1627    FindSecondPointForTesselation(FirstPoint, Oben, OptCandidate, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
     1628    SecondPoint = OptCandidate;
     1629    if (SecondPoint == NULL)  // have we found a second point?
    19721630      continue;
    1973     BaseLine.endpoints[1] = new BoundaryPointSet(Temporary);
    1974 
    1975     // construct center of circle
    1976     CircleCenter.CopyVector(BaseLine.endpoints[0]->node->node);
    1977     CircleCenter.AddVector(BaseLine.endpoints[1]->node->node);
    1978     CircleCenter.Scale(0.5);
    1979 
    1980     // construct normal vector of circle
    1981     CirclePlaneNormal.CopyVector(BaseLine.endpoints[0]->node->node);
    1982     CirclePlaneNormal.SubtractVector(BaseLine.endpoints[1]->node->node);
    1983 
    1984     double radius = CirclePlaneNormal.NormSquared();
     1631
     1632    helper.CopyVector(FirstPoint->node);
     1633    helper.SubtractVector(SecondPoint->node);
     1634    helper.Normalize();
     1635    Oben.ProjectOntoPlane(&helper);
     1636    Oben.Normalize();
     1637    helper.VectorProduct(&Oben);
     1638    ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
     1639
     1640    Chord.CopyVector(FirstPoint->node); // bring into calling function
     1641    Chord.SubtractVector(SecondPoint->node);
     1642    double radius = Chord.ScalarProduct(&Chord);
    19851643    double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
    1986 
    1987     NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
    1988     NormalVector.Normalize();
    1989     ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    1990 
    1991     SphereCenter.CopyVector(&NormalVector);
    1992     SphereCenter.Scale(CircleRadius);
    1993     SphereCenter.AddVector(&CircleCenter);
    1994     // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
     1644    helper.CopyVector(&Oben);
     1645    helper.Scale(CircleRadius);
     1646    // Now, oben and helper are two orthonormalized vectors in the plane defined by Chord (not normalized)
    19951647
    19961648    // look in one direction of baseline for initial candidate
    1997     SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector);  // whether we look "left" first or "right" first is not important ...
     1649    SearchDirection.MakeNormalVector(&Chord, &Oben);  // whether we look "left" first or "right" first is not important ...
    19981650
    19991651    // adding point 1 and point 2 and add the line between them
    2000     Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
    2001     Log() << Verbose(0) << "Found second point is at " << *BaseLine.endpoints[1]->node << ".\n";
    2002 
    2003     //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
    2004     CandidateForTesselation OptCandidates(&BaseLine);
    2005     FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
    2006     Log() << Verbose(0) << "List of third Points is:" << endl;
    2007     for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
    2008         Log() << Verbose(0) << " " << *(*it) << endl;
    2009     }
    2010 
    2011     BTS = NULL;
    2012     AddCandidateTriangle(OptCandidates);
    2013 //    delete(BaseLine.endpoints[0]);
    2014 //    delete(BaseLine.endpoints[1]);
    2015 
     1652    Log() << Verbose(1) << "Coordinates of start node at " << *FirstPoint->node << "." << endl;
     1653    AddTesselationPoint(FirstPoint, 0);
     1654    Log() << Verbose(1) << "Found second point is at " << *SecondPoint->node << ".\n";
     1655    AddTesselationPoint(SecondPoint, 1);
     1656    AddTesselationLine(TPS[0], TPS[1], 0);
     1657
     1658    //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << helper << ".\n";
     1659    FindThirdPointForTesselation(Oben, SearchDirection, helper, BLS[0], NULL, *&OptCandidates, &ShortestAngle, RADIUS, LC);
     1660    Log() << Verbose(1) << "List of third Points is ";
     1661    for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1662        Log() << Verbose(0) << " " << *(*it)->point;
     1663    }
     1664    Log() << Verbose(0) << endl;
     1665
     1666    for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1667      // add third triangle point
     1668      AddTesselationPoint((*it)->point, 2);
     1669      // add the second and third line
     1670      AddTesselationLine(TPS[1], TPS[2], 1);
     1671      AddTesselationLine(TPS[0], TPS[2], 2);
     1672      // ... and triangles to the Maps of the Tesselation class
     1673      BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     1674      AddTesselationTriangle();
     1675      // ... and calculate its normal vector (with correct orientation)
     1676      (*it)->OptCenter.Scale(-1.);
     1677      Log() << Verbose(2) << "Anti-Oben is currently " << (*it)->OptCenter << "." << endl;
     1678      BTS->GetNormalVector((*it)->OptCenter);  // vector to compare with should point inwards
     1679      Log() << Verbose(0) << "==> Found starting triangle consists of " << *FirstPoint << ", " << *SecondPoint << " and "
     1680      << *(*it)->point << " with normal vector " << BTS->NormalVector << ".\n";
     1681
     1682      // if we do not reach the end with the next step of iteration, we need to setup a new first line
     1683      if (it != OptCandidates->end()--) {
     1684        FirstPoint = (*it)->BaseLine->endpoints[0]->node;
     1685        SecondPoint = (*it)->point;
     1686        // adding point 1 and point 2 and the line between them
     1687        AddTesselationPoint(FirstPoint, 0);
     1688        AddTesselationPoint(SecondPoint, 1);
     1689        AddTesselationLine(TPS[0], TPS[1], 0);
     1690      }
     1691      Log() << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl;
     1692    }
    20161693    if (BTS != NULL) // we have created one starting triangle
    20171694      break;
    20181695    else {
    20191696      // remove all candidates from the list and then the list itself
    2020       OptCandidates.pointlist.clear();
    2021     }
    2022   }
     1697      class CandidateForTesselation *remover = NULL;
     1698      for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1699        remover = *it;
     1700        delete(remover);
     1701      }
     1702      OptCandidates->clear();
     1703    }
     1704  }
     1705
     1706  // remove all candidates from the list and then the list itself
     1707  class CandidateForTesselation *remover = NULL;
     1708  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1709    remover = *it;
     1710    delete(remover);
     1711  }
     1712  delete(OptCandidates);
     1713  Log() << Verbose(1) << "End of FindStartingTriangle\n";
    20231714};
    20241715
    20251716/** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
    20261717 * This is supposed to prevent early closing of the tesselation.
    2027  * \param CandidateLine CandidateForTesselation with baseline and shortestangle , i.e. not \a *OptCandidate
     1718 * \param *BaseRay baseline, i.e. not \a *OptCandidate
    20281719 * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
     1720 * \param ShortestAngle path length on this circle band for the current \a *ThirdNode
    20291721 * \param RADIUS radius of sphere
    20301722 * \param *LC LinkedCell structure
    20311723 * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
    20321724 */
    2033 //bool Tesselation::HasOtherBaselineBetterCandidate(CandidateForTesselation &CandidateLine, const TesselPoint * const ThirdNode, double RADIUS, const LinkedCell * const LC) const
    2034 //{
    2035 //      Info FunctionInfo(__func__);
    2036 //  bool result = false;
    2037 //  Vector CircleCenter;
    2038 //  Vector CirclePlaneNormal;
    2039 //  Vector OldSphereCenter;
    2040 //  Vector SearchDirection;
    2041 //  Vector helper;
    2042 //  TesselPoint *OtherOptCandidate = NULL;
    2043 //  double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    2044 //  double radius, CircleRadius;
    2045 //  BoundaryLineSet *Line = NULL;
    2046 //  BoundaryTriangleSet *T = NULL;
    2047 //
    2048 //  // check both other lines
    2049 //  PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
    2050 //  if (FindPoint != PointsOnBoundary.end()) {
    2051 //    for (int i=0;i<2;i++) {
    2052 //      LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
    2053 //      if (FindLine != (FindPoint->second)->lines.end()) {
    2054 //        Line = FindLine->second;
    2055 //        Log() << Verbose(0) << "Found line " << *Line << "." << endl;
    2056 //        if (Line->triangles.size() == 1) {
    2057 //          T = Line->triangles.begin()->second;
    2058 //          // construct center of circle
    2059 //          CircleCenter.CopyVector(Line->endpoints[0]->node->node);
    2060 //          CircleCenter.AddVector(Line->endpoints[1]->node->node);
    2061 //          CircleCenter.Scale(0.5);
    2062 //
    2063 //          // construct normal vector of circle
    2064 //          CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
    2065 //          CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
    2066 //
    2067 //          // calculate squared radius of circle
    2068 //          radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    2069 //          if (radius/4. < RADIUS*RADIUS) {
    2070 //            CircleRadius = RADIUS*RADIUS - radius/4.;
    2071 //            CirclePlaneNormal.Normalize();
    2072 //            //Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    2073 //
    2074 //            // construct old center
    2075 //            GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
    2076 //            helper.CopyVector(&T->NormalVector);  // normal vector ensures that this is correct center of the two possible ones
    2077 //            radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
    2078 //            helper.Scale(sqrt(RADIUS*RADIUS - radius));
    2079 //            OldSphereCenter.AddVector(&helper);
    2080 //            OldSphereCenter.SubtractVector(&CircleCenter);
    2081 //            //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
    2082 //
    2083 //            // construct SearchDirection
    2084 //            SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
    2085 //            helper.CopyVector(Line->endpoints[0]->node->node);
    2086 //            helper.SubtractVector(ThirdNode->node);
    2087 //            if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    2088 //              SearchDirection.Scale(-1.);
    2089 //            SearchDirection.ProjectOntoPlane(&OldSphereCenter);
    2090 //            SearchDirection.Normalize();
    2091 //            Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2092 //            if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    2093 //              // rotated the wrong way!
    2094 //              eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
    2095 //            }
    2096 //
    2097 //            // add third point
    2098 //            FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, OptCandidates, ThirdNode, RADIUS, LC);
    2099 //            for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); ++it) {
    2100 //              if (((*it) == BaseRay->endpoints[0]->node) || ((*it) == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
    2101 //                continue;
    2102 //              Log() << Verbose(0) << " Third point candidate is " << (*it)
    2103 //              << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
    2104 //              Log() << Verbose(0) << " Baseline is " << *BaseRay << endl;
    2105 //
    2106 //              // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
    2107 //              TesselPoint *PointCandidates[3];
    2108 //              PointCandidates[0] = (*it);
    2109 //              PointCandidates[1] = BaseRay->endpoints[0]->node;
    2110 //              PointCandidates[2] = BaseRay->endpoints[1]->node;
    2111 //              bool check=false;
    2112 //              int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
    2113 //              // If there is no triangle, add it regularly.
    2114 //              if (existentTrianglesCount == 0) {
    2115 //                SetTesselationPoint((*it), 0);
    2116 //                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
    2117 //                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
    2118 //
    2119 //                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
    2120 //                  OtherOptCandidate = (*it);
    2121 //                  check = true;
    2122 //                }
    2123 //              } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
    2124 //                SetTesselationPoint((*it), 0);
    2125 //                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
    2126 //                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
    2127 //
    2128 //                // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
    2129 //                // i.e. at least one of the three lines must be present with TriangleCount <= 1
    2130 //                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
    2131 //                  OtherOptCandidate = (*it);
    2132 //                  check = true;
    2133 //                }
    2134 //              }
    2135 //
    2136 //              if (check) {
    2137 //                if (ShortestAngle > OtherShortestAngle) {
    2138 //                  Log() << Verbose(0) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
    2139 //                  result = true;
    2140 //                  break;
    2141 //                }
    2142 //              }
    2143 //            }
    2144 //            delete(OptCandidates);
    2145 //            if (result)
    2146 //              break;
    2147 //          } else {
    2148 //            Log() << Verbose(0) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
    2149 //          }
    2150 //        } else {
    2151 //          eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;
    2152 //        }
    2153 //      } else {
    2154 //        Log() << Verbose(1) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
    2155 //      }
    2156 //    }
    2157 //  } else {
    2158 //    eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;
    2159 //  }
    2160 //
    2161 //  return result;
    2162 //};
     1725bool Tesselation::HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const ThirdNode, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const
     1726{
     1727  bool result = false;
     1728  Vector CircleCenter;
     1729  Vector CirclePlaneNormal;
     1730  Vector OldSphereCenter;
     1731  Vector SearchDirection;
     1732  Vector helper;
     1733  TesselPoint *OtherOptCandidate = NULL;
     1734  double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
     1735  double radius, CircleRadius;
     1736  BoundaryLineSet *Line = NULL;
     1737  BoundaryTriangleSet *T = NULL;
     1738
     1739  Log() << Verbose(1) << "Begin of HasOtherBaselineBetterCandidate" << endl;
     1740
     1741  // check both other lines
     1742  PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
     1743  if (FindPoint != PointsOnBoundary.end()) {
     1744    for (int i=0;i<2;i++) {
     1745      LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
     1746      if (FindLine != (FindPoint->second)->lines.end()) {
     1747        Line = FindLine->second;
     1748        Log() << Verbose(1) << "Found line " << *Line << "." << endl;
     1749        if (Line->triangles.size() == 1) {
     1750          T = Line->triangles.begin()->second;
     1751          // construct center of circle
     1752          CircleCenter.CopyVector(Line->endpoints[0]->node->node);
     1753          CircleCenter.AddVector(Line->endpoints[1]->node->node);
     1754          CircleCenter.Scale(0.5);
     1755
     1756          // construct normal vector of circle
     1757          CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
     1758          CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
     1759
     1760          // calculate squared radius of circle
     1761          radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
     1762          if (radius/4. < RADIUS*RADIUS) {
     1763            CircleRadius = RADIUS*RADIUS - radius/4.;
     1764            CirclePlaneNormal.Normalize();
     1765            //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     1766
     1767            // construct old center
     1768            GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
     1769            helper.CopyVector(&T->NormalVector);  // normal vector ensures that this is correct center of the two possible ones
     1770            radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
     1771            helper.Scale(sqrt(RADIUS*RADIUS - radius));
     1772            OldSphereCenter.AddVector(&helper);
     1773            OldSphereCenter.SubtractVector(&CircleCenter);
     1774            //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
     1775
     1776            // construct SearchDirection
     1777            SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
     1778            helper.CopyVector(Line->endpoints[0]->node->node);
     1779            helper.SubtractVector(ThirdNode->node);
     1780            if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
     1781              SearchDirection.Scale(-1.);
     1782            SearchDirection.ProjectOntoPlane(&OldSphereCenter);
     1783            SearchDirection.Normalize();
     1784            Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     1785            if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     1786              // rotated the wrong way!
     1787              eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     1788            }
     1789
     1790            // add third point
     1791            CandidateList *OptCandidates = new CandidateList();
     1792            FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, Line, ThirdNode, OptCandidates, &OtherShortestAngle, RADIUS, LC);
     1793            for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1794              if (((*it)->point == BaseRay->endpoints[0]->node) || ((*it)->point == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
     1795                continue;
     1796              Log() << Verbose(1) << " Third point candidate is " << *(*it)->point
     1797              << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
     1798              Log() << Verbose(1) << " Baseline is " << *BaseRay << endl;
     1799
     1800              // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
     1801              TesselPoint *PointCandidates[3];
     1802              PointCandidates[0] = (*it)->point;
     1803              PointCandidates[1] = BaseRay->endpoints[0]->node;
     1804              PointCandidates[2] = BaseRay->endpoints[1]->node;
     1805              bool check=false;
     1806              int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
     1807              // If there is no triangle, add it regularly.
     1808              if (existentTrianglesCount == 0) {
     1809                SetTesselationPoint((*it)->point, 0);
     1810                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
     1811                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
     1812
     1813                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
     1814                  OtherOptCandidate = (*it)->point;
     1815                  check = true;
     1816                }
     1817              } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
     1818                SetTesselationPoint((*it)->point, 0);
     1819                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
     1820                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
     1821
     1822                // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
     1823                // i.e. at least one of the three lines must be present with TriangleCount <= 1
     1824                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
     1825                  OtherOptCandidate = (*it)->point;
     1826                  check = true;
     1827                }
     1828              }
     1829
     1830              if (check) {
     1831                if (ShortestAngle > OtherShortestAngle) {
     1832                  Log() << Verbose(1) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
     1833                  result = true;
     1834                  break;
     1835                }
     1836              }
     1837            }
     1838            delete(OptCandidates);
     1839            if (result)
     1840              break;
     1841          } else {
     1842            Log() << Verbose(1) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
     1843          }
     1844        } else {
     1845          eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;
     1846        }
     1847      } else {
     1848        Log() << Verbose(2) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
     1849      }
     1850    }
     1851  } else {
     1852    eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;
     1853  }
     1854
     1855  Log() << Verbose(1) << "End of HasOtherBaselineBetterCandidate" << endl;
     1856
     1857  return result;
     1858};
    21631859
    21641860/** This function finds a triangle to a line, adjacent to an existing one.
    21651861 * @param out output stream for debugging
    2166  * @param CandidateLine current cadndiate baseline to search from
     1862 * @param Line current baseline to search from
    21671863 * @param T current triangle which \a Line is edge of
    21681864 * @param RADIUS radius of the rolling ball
     
    21701866 * @param *LC LinkedCell structure with neighbouring points
    21711867 */
    2172 bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
    2173 {
    2174         Info FunctionInfo(__func__);
     1868bool Tesselation::FindNextSuitableTriangle(BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
     1869{
     1870  Log() << Verbose(0) << "Begin of FindNextSuitableTriangle\n";
    21751871  bool result = true;
     1872  CandidateList *OptCandidates = new CandidateList();
    21761873
    21771874  Vector CircleCenter;
    21781875  Vector CirclePlaneNormal;
    2179   Vector RelativeSphereCenter;
     1876  Vector OldSphereCenter;
    21801877  Vector SearchDirection;
    21811878  Vector helper;
    21821879  TesselPoint *ThirdNode = NULL;
    21831880  LineMap::iterator testline;
     1881  double ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    21841882  double radius, CircleRadius;
    21851883
     1884  Log() << Verbose(1) << "Current baseline is " << Line << " of triangle " << T << "." << endl;
    21861885  for (int i=0;i<3;i++)
    2187     if ((T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[0]->node) && (T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[1]->node)) {
     1886    if ((T.endpoints[i]->node != Line.endpoints[0]->node) && (T.endpoints[i]->node != Line.endpoints[1]->node))
    21881887      ThirdNode = T.endpoints[i]->node;
    2189       break;
    2190     }
    2191   Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdNode " << *ThirdNode << " of triangle " << T << "." << endl;
    21921888
    21931889  // construct center of circle
    2194   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2195   CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     1890  CircleCenter.CopyVector(Line.endpoints[0]->node->node);
     1891  CircleCenter.AddVector(Line.endpoints[1]->node->node);
    21961892  CircleCenter.Scale(0.5);
    21971893
    21981894  // construct normal vector of circle
    2199   CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2200   CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     1895  CirclePlaneNormal.CopyVector(Line.endpoints[0]->node->node);
     1896  CirclePlaneNormal.SubtractVector(Line.endpoints[1]->node->node);
    22011897
    22021898  // calculate squared radius of circle
    22031899  radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    22041900  if (radius/4. < RADIUS*RADIUS) {
    2205     // construct relative sphere center with now known CircleCenter
    2206     RelativeSphereCenter.CopyVector(&T.SphereCenter);
    2207     RelativeSphereCenter.SubtractVector(&CircleCenter);
    2208 
    22091901    CircleRadius = RADIUS*RADIUS - radius/4.;
    22101902    CirclePlaneNormal.Normalize();
    2211     Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    2212 
    2213     Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl;
    2214 
    2215     // construct SearchDirection and an "outward pointer"
    2216     SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
    2217     helper.CopyVector(&CircleCenter);
     1903    //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     1904
     1905    // construct old center
     1906    GetCenterofCircumcircle(&OldSphereCenter, *T.endpoints[0]->node->node, *T.endpoints[1]->node->node, *T.endpoints[2]->node->node);
     1907    helper.CopyVector(&T.NormalVector);  // normal vector ensures that this is correct center of the two possible ones
     1908    radius = Line.endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
     1909    helper.Scale(sqrt(RADIUS*RADIUS - radius));
     1910    OldSphereCenter.AddVector(&helper);
     1911    OldSphereCenter.SubtractVector(&CircleCenter);
     1912    //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
     1913
     1914    // construct SearchDirection
     1915    SearchDirection.MakeNormalVector(&T.NormalVector, &CirclePlaneNormal);
     1916    helper.CopyVector(Line.endpoints[0]->node->node);
    22181917    helper.SubtractVector(ThirdNode->node);
    22191918    if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    22201919      SearchDirection.Scale(-1.);
    2221     Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2222     if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     1920    SearchDirection.ProjectOntoPlane(&OldSphereCenter);
     1921    SearchDirection.Normalize();
     1922    Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     1923    if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    22231924      // rotated the wrong way!
    22241925      eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     
    22261927
    22271928    // add third point
    2228     FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdNode, RADIUS, LC);
     1929    FindThirdPointForTesselation(T.NormalVector, SearchDirection, OldSphereCenter, &Line, ThirdNode, OptCandidates, &ShortestAngle, RADIUS, LC);
    22291930
    22301931  } else {
    2231     Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl;
    2232   }
    2233 
    2234   if (CandidateLine.pointlist.empty()) {
     1932    Log() << Verbose(1) << "Circumcircle for base line " << Line << " and base triangle " << T << " is too big!" << endl;
     1933  }
     1934
     1935  if (OptCandidates->begin() == OptCandidates->end()) {
    22351936    eLog() << Verbose(2) << "Could not find a suitable candidate." << endl;
    22361937    return false;
    22371938  }
    2238   Log() << Verbose(0) << "Third Points are: " << endl;
    2239   for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
    2240     Log() << Verbose(0) << " " << *(*it) << endl;
    2241   }
    2242 
    2243   return true;
    2244 
    2245 //  BoundaryLineSet *BaseRay = CandidateLine.BaseLine;
    2246 //  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    2247 //    Log() << Verbose(0) << "Third point candidate is " << *(*it)->point
    2248 //    << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
    2249 //    Log() << Verbose(0) << "Baseline is " << *BaseRay << endl;
    2250 //
    2251 //    // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
    2252 //    TesselPoint *PointCandidates[3];
    2253 //    PointCandidates[0] = (*it)->point;
    2254 //    PointCandidates[1] = BaseRay->endpoints[0]->node;
    2255 //    PointCandidates[2] = BaseRay->endpoints[1]->node;
    2256 //    int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
    2257 //
    2258 //    BTS = NULL;
    2259 //    // check for present edges and whether we reach better candidates from them
    2260 //    //if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) {
    2261 //    if (0) {
    2262 //      result = false;
    2263 //      break;
    2264 //    } else {
    2265 //      // If there is no triangle, add it regularly.
    2266 //      if (existentTrianglesCount == 0) {
    2267 //        AddTesselationPoint((*it)->point, 0);
    2268 //        AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    2269 //        AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    2270 //
    2271 //        if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
    2272 //          CandidateLine.point = (*it)->point;
    2273 //          CandidateLine.OptCenter.CopyVector(&((*it)->OptCenter));
    2274 //          CandidateLine.OtherOptCenter.CopyVector(&((*it)->OtherOptCenter));
    2275 //          CandidateLine.ShortestAngle = ShortestAngle;
    2276 //        } else {
    2277 ////          eLog() << Verbose(1) << "This triangle consisting of ";
    2278 ////          Log() << Verbose(0) << *(*it)->point << ", ";
    2279 ////          Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    2280 ////          Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    2281 ////          Log() << Verbose(0) << "exists and is not added, as it 0x80000000006fc150(does not seem helpful!" << endl;
    2282 //          result = false;
    2283 //        }
    2284 //      } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
    2285 //          AddTesselationPoint((*it)->point, 0);
    2286 //          AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    2287 //          AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    2288 //
    2289 //          // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
    2290 //          // i.e. at least one of the three lines must be present with TriangleCount <= 1
    2291 //          if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS) || CandidateLine.BaseLine->skipped) {
    2292 //            CandidateLine.point = (*it)->point;
    2293 //            CandidateLine.OptCenter.CopyVector(&(*it)->OptCenter);
    2294 //            CandidateLine.OtherOptCenter.CopyVector(&(*it)->OtherOptCenter);
    2295 //            CandidateLine.ShortestAngle = ShortestAngle+2.*M_PI;
    2296 //
    2297 //          } else {
    2298 ////            eLog() << Verbose(1) << "This triangle consisting of " << *(*it)->point << ", " << *BaseRay->endpoints[0]->node << " and " << *BaseRay->endpoints[1]->node << " " << "exists and is not added, as it does not seem helpful!" << endl;
    2299 //            result = false;
    2300 //          }
    2301 //      } else {
    2302 ////        Log() << Verbose(1) << "This triangle consisting of ";
    2303 ////        Log() << Verbose(0) << *(*it)->point << ", ";
    2304 ////        Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    2305 ////        Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    2306 ////        Log() << Verbose(0) << "is invalid!" << endl;
    2307 //        result = false;
    2308 //      }
    2309 //    }
    2310 //
    2311 //    // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
    2312 //    BaseRay = BLS[0];
    2313 //    if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
    2314 //      eLog() << Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl;
    2315 //      exit(255);
    2316 //    }
    2317 //
    2318 //  }
    2319 //
    2320 //  // remove all candidates from the list and then the list itself
    2321 //  class CandidateForTesselation *remover = NULL;
    2322 //  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    2323 //    remover = *it;
    2324 //    delete(remover);
    2325 //  }
    2326 //  delete(OptCandidates);
     1939  Log() << Verbose(1) << "Third Points are ";
     1940  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1941    Log() << Verbose(1) << " " << *(*it)->point << endl;
     1942  }
     1943
     1944  BoundaryLineSet *BaseRay = &Line;
     1945  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1946    Log() << Verbose(1) << " Third point candidate is " << *(*it)->point
     1947    << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
     1948    Log() << Verbose(1) << " Baseline is " << *BaseRay << endl;
     1949
     1950    // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
     1951    TesselPoint *PointCandidates[3];
     1952    PointCandidates[0] = (*it)->point;
     1953    PointCandidates[1] = BaseRay->endpoints[0]->node;
     1954    PointCandidates[2] = BaseRay->endpoints[1]->node;
     1955    int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
     1956
     1957    BTS = NULL;
     1958    // check for present edges and whether we reach better candidates from them
     1959    if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) {
     1960      result = false;
     1961      break;
     1962    } else {
     1963      // If there is no triangle, add it regularly.
     1964      if (existentTrianglesCount == 0) {
     1965        AddTesselationPoint((*it)->point, 0);
     1966        AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
     1967        AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
     1968
     1969        if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
     1970          AddTesselationLine(TPS[0], TPS[1], 0);
     1971          AddTesselationLine(TPS[0], TPS[2], 1);
     1972          AddTesselationLine(TPS[1], TPS[2], 2);
     1973
     1974          BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     1975          AddTesselationTriangle();
     1976          (*it)->OptCenter.Scale(-1.);
     1977          BTS->GetNormalVector((*it)->OptCenter);
     1978          (*it)->OptCenter.Scale(-1.);
     1979
     1980          Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector
     1981            << " for this triangle ... " << endl;
     1982        //Log() << Verbose(1) << "We have "<< TrianglesOnBoundaryCount << " for line " << *BaseRay << "." << endl;
     1983        } else {
     1984          eLog() << Verbose(2) << "This triangle consisting of ";
     1985          Log() << Verbose(0) << *(*it)->point << ", ";
     1986          Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
     1987          Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
     1988          Log() << Verbose(0) << "exists and is not added, as it does not seem helpful!" << endl;
     1989          result = false;
     1990        }
     1991      } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
     1992          AddTesselationPoint((*it)->point, 0);
     1993          AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
     1994          AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
     1995
     1996          // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
     1997          // i.e. at least one of the three lines must be present with TriangleCount <= 1
     1998          if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
     1999            AddTesselationLine(TPS[0], TPS[1], 0);
     2000            AddTesselationLine(TPS[0], TPS[2], 1);
     2001            AddTesselationLine(TPS[1], TPS[2], 2);
     2002
     2003            BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2004            AddTesselationTriangle();  // add to global map
     2005
     2006            (*it)->OtherOptCenter.Scale(-1.);
     2007            BTS->GetNormalVector((*it)->OtherOptCenter);
     2008            (*it)->OtherOptCenter.Scale(-1.);
     2009
     2010            eLog() << Verbose(2) << "--> WARNING: Special new triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " for this triangle ... " << endl;
     2011            Log() << Verbose(1) << "We have "<< BaseRay->triangles.size() << " for line " << BaseRay << "." << endl;
     2012          } else {
     2013            eLog() << Verbose(2) << "This triangle consisting of " << *(*it)->point << ", " << *BaseRay->endpoints[0]->node << " and " << *BaseRay->endpoints[1]->node << " " << "exists and is not added, as it does not seem helpful!" << endl;
     2014            result = false;
     2015          }
     2016      } else {
     2017        Log() << Verbose(1) << "This triangle consisting of ";
     2018        Log() << Verbose(0) << *(*it)->point << ", ";
     2019        Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
     2020        Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
     2021        Log() << Verbose(0) << "is invalid!" << endl;
     2022        result = false;
     2023      }
     2024    }
     2025
     2026    // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
     2027    BaseRay = BLS[0];
     2028    if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
     2029      eLog() << Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl;
     2030      exit(255);
     2031    }
     2032
     2033  }
     2034
     2035  // remove all candidates from the list and then the list itself
     2036  class CandidateForTesselation *remover = NULL;
     2037  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     2038    remover = *it;
     2039    delete(remover);
     2040  }
     2041  delete(OptCandidates);
     2042  Log() << Verbose(0) << "End of FindNextSuitableTriangle\n";
    23272043  return result;
    2328 };
    2329 
    2330 /** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
    2331  * \param CandidateLine triangle to add
    2332  * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in AddTesselationLine()
    2333  */
    2334 void Tesselation::AddCandidateTriangle(CandidateForTesselation CandidateLine)
    2335 {
    2336         Info FunctionInfo(__func__);
    2337   Vector Center;
    2338   TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
    2339 
    2340   // fill the set of neighbours
    2341   Center.CopyVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2342   Center.SubtractVector(TurningPoint->node);
    2343   set<TesselPoint*> SetOfNeighbours;
    2344   SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
    2345   for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
    2346     SetOfNeighbours.insert(*Runner);
    2347   TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, &Center);
    2348 
    2349   // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
    2350   TesselPointList::iterator Runner = connectedClosestPoints->begin();
    2351   TesselPointList::iterator Sprinter = Runner;
    2352   Sprinter++;
    2353   while(Sprinter != connectedClosestPoints->end()) {
    2354     // add the points
    2355     AddTesselationPoint(TurningPoint, 0);
    2356     AddTesselationPoint((*Runner), 1);
    2357     AddTesselationPoint((*Sprinter), 2);
    2358 
    2359 
    2360     // add the lines
    2361     AddTesselationLine(TPS[0], TPS[1], 0);
    2362     AddTesselationLine(TPS[0], TPS[2], 1);
    2363     AddTesselationLine(TPS[1], TPS[2], 2);
    2364 
    2365     // add the triangles
    2366     BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    2367     AddTesselationTriangle();
    2368     BTS->GetCenter(&Center);
    2369     Center.SubtractVector(&CandidateLine.OptCenter);
    2370     BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
    2371     BTS->GetNormalVector(Center);
    2372 
    2373     Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << "." << endl;
    2374     Runner = Sprinter;
    2375     Sprinter++;
    2376   }
    2377   delete(connectedClosestPoints);
    23782044};
    23792045
     
    23872053class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
    23882054{
    2389         Info FunctionInfo(__func__);
    23902055  class BoundaryPointSet *Spot = NULL;
    23912056  class BoundaryLineSet *OtherBase;
     
    23992064  OtherBase = new class BoundaryLineSet(BPS,-1);
    24002065
    2401   Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl;
    2402   Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl;
     2066  Log() << Verbose(3) << "INFO: Current base line is " << *Base << "." << endl;
     2067  Log() << Verbose(3) << "INFO: Other base line is " << *OtherBase << "." << endl;
    24032068
    24042069  // get the closest point on each line to the other line
     
    24202085  delete(ClosestPoint);
    24212086  if ((distance[0] * distance[1]) > 0)  { // have same sign?
    2422     Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
     2087    Log() << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
    24232088    if (distance[0] < distance[1]) {
    24242089      Spot = Base->endpoints[0];
     
    24282093    return Spot;
    24292094  } else {  // different sign, i.e. we are in between
    2430     Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
     2095    Log() << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
    24312096    return NULL;
    24322097  }
     
    24362101void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
    24372102{
    2438         Info FunctionInfo(__func__);
    24392103  // print all lines
    2440   Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl;
     2104  Log() << Verbose(1) << "Printing all boundary points for debugging:" << endl;
    24412105  for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
    2442     Log() << Verbose(0) << *(PointRunner->second) << endl;
     2106    Log() << Verbose(2) << *(PointRunner->second) << endl;
    24432107};
    24442108
    24452109void Tesselation::PrintAllBoundaryLines(ofstream *out) const
    24462110{
    2447         Info FunctionInfo(__func__);
    24482111  // print all lines
    2449   Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl;
     2112  Log() << Verbose(1) << "Printing all boundary lines for debugging:" << endl;
    24502113  for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
    2451     Log() << Verbose(0) << *(LineRunner->second) << endl;
     2114    Log() << Verbose(2) << *(LineRunner->second) << endl;
    24522115};
    24532116
    24542117void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
    24552118{
    2456         Info FunctionInfo(__func__);
    24572119  // print all triangles
    2458   Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl;
     2120  Log() << Verbose(1) << "Printing all boundary triangles for debugging:" << endl;
    24592121  for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
    2460     Log() << Verbose(0) << *(TriangleRunner->second) << endl;
     2122    Log() << Verbose(2) << *(TriangleRunner->second) << endl;
    24612123};
    24622124
     
    24682130double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
    24692131{
    2470         Info FunctionInfo(__func__);
    24712132  class BoundaryLineSet *OtherBase;
    24722133  Vector *ClosestPoint[2];
     
    24802141  OtherBase = new class BoundaryLineSet(BPS,-1);
    24812142
    2482   Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl;
    2483   Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl;
     2143  Log() << Verbose(3) << "INFO: Current base line is " << *Base << "." << endl;
     2144  Log() << Verbose(3) << "INFO: Other base line is " << *OtherBase << "." << endl;
    24842145
    24852146  // get the closest point on each line to the other line
     
    25012162
    25022163  if (Distance.NormSquared() < MYEPSILON) { // check for intersection
    2503     Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
     2164    Log() << Verbose(3) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
    25042165    return false;
    25052166  } else { // check for sign against BaseLineNormal
     
    25112172    }
    25122173    for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2513       Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
     2174      Log() << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
    25142175      BaseLineNormal.AddVector(&(runner->second->NormalVector));
    25152176    }
     
    25172178
    25182179    if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
    2519       Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;
     2180      Log() << Verbose(2) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;
    25202181      // calculate volume summand as a general tetraeder
    25212182      return volume;
    25222183    } else {  // Base higher than OtherBase -> do nothing
    2523       Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl;
     2184      Log() << Verbose(2) << "REJECT: Base line is higher: Nothing to do." << endl;
    25242185      return 0.;
    25252186    }
     
    25362197class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
    25372198{
    2538         Info FunctionInfo(__func__);
    25392199  class BoundaryLineSet *OldLines[4], *NewLine;
    25402200  class BoundaryPointSet *OldPoints[2];
     
    25432203  int i,m;
    25442204
     2205  Log() << Verbose(1) << "Begin of FlipBaseline" << endl;
     2206
    25452207  // calculate NormalVector for later use
    25462208  BaseLineNormal.Zero();
     
    25502212  }
    25512213  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2552     Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
     2214    Log() << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
    25532215    BaseLineNormal.AddVector(&(runner->second->NormalVector));
    25542216  }
     
    25632225  i=0;
    25642226  m=0;
    2565   Log() << Verbose(0) << "The four old lines are: ";
     2227  Log() << Verbose(3) << "The four old lines are: ";
    25662228  for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    25672229    for (int j=0;j<3;j++) // all of their endpoints and baselines
     
    25712233      }
    25722234  Log() << Verbose(0) << endl;
    2573   Log() << Verbose(0) << "The two old points are: ";
     2235  Log() << Verbose(3) << "The two old points are: ";
    25742236  for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    25752237    for (int j=0;j<3;j++) // all of their endpoints and baselines
     
    25972259
    25982260  // remove triangles and baseline removes itself
    2599   Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
     2261  Log() << Verbose(3) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
    26002262  OldBaseLineNr = Base->Nr;
    26012263  m=0;
    26022264  for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2603     Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
     2265    Log() << Verbose(3) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
    26042266    OldTriangleNrs[m++] = runner->second->Nr;
    26052267    RemoveTesselationTriangle(runner->second);
     
    26112273  NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
    26122274  LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
    2613   Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl;
     2275  Log() << Verbose(3) << "INFO: Created new baseline " << *NewLine << "." << endl;
    26142276
    26152277  // construct new triangles with flipped baseline
     
    26262288    BTS->GetNormalVector(BaseLineNormal);
    26272289    AddTesselationTriangle(OldTriangleNrs[0]);
    2628     Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
     2290    Log() << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
    26292291
    26302292    BLS[0] = (i==2 ? OldLines[3] : OldLines[2]);
     
    26342296    BTS->GetNormalVector(BaseLineNormal);
    26352297    AddTesselationTriangle(OldTriangleNrs[1]);
    2636     Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
     2298    Log() << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
    26372299  } else {
    2638     eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl;
     2300    Log() << Verbose(1) << "The four old lines do not connect, something's utterly wrong here!" << endl;
    26392301    return NULL;
    26402302  }
    26412303
     2304  Log() << Verbose(1) << "End of FlipBaseline" << endl;
    26422305  return NewLine;
    26432306};
     
    26542317void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
    26552318{
    2656         Info FunctionInfo(__func__);
     2319  Log() << Verbose(2) << "Begin of FindSecondPointForTesselation" << endl;
    26572320  Vector AngleCheck;
    26582321  class TesselPoint* Candidate = NULL;
     
    26752338    Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
    26762339  }
    2677   Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :"
     2340  Log() << Verbose(3) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :"
    26782341    << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl;
    26792342
     
    26822345      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    26832346        const LinkedNodes *List = LC->GetCurrentCell();
    2684         //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     2347        //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    26852348        if (List != NULL) {
    26862349          for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     
    27132376                angle = AngleCheck.Angle(&Oben);
    27142377                if (angle < Storage[0]) {
    2715                   //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
    2716                   Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
     2378                  //Log() << Verbose(3) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
     2379                  Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
    27172380                  OptCandidate = Candidate;
    27182381                  Storage[0] = angle;
    2719                   //Log() << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
     2382                  //Log() << Verbose(3) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
    27202383                } else {
    2721                   //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
     2384                  //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
    27222385                }
    27232386              } else {
    2724                 //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
     2387                //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
    27252388              }
    27262389            } else {
    2727               //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
     2390              //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
    27282391            }
    27292392          }
    27302393        } else {
    2731           Log() << Verbose(0) << "Linked cell list is empty." << endl;
     2394          Log() << Verbose(3) << "Linked cell list is empty." << endl;
    27322395        }
    27332396      }
     2397  Log() << Verbose(2) << "End of FindSecondPointForTesselation" << endl;
    27342398};
    27352399
     
    27602424 * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
    27612425 * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
    2762  * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
     2426 * @param BaseLine BoundaryLineSet with the current base line
    27632427 * @param ThirdNode third point to avoid in search
     2428 * @param candidates list of equally good candidates to return
     2429 * @param ShortestAngle the current path length on this circle band for the current OptCandidate
    27642430 * @param RADIUS radius of sphere
    27652431 * @param *LC LinkedCell structure with neighbouring points
    27662432 */
    2767 void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const
    2768 {
    2769         Info FunctionInfo(__func__);
     2433void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, class BoundaryLineSet *BaseLine, const class TesselPoint  * const ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC) const
     2434{
    27702435  Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
    27712436  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
     
    27752440  Vector NewNormalVector;   // normal vector of the Candidate's triangle
    27762441  Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
    2777   Vector RelativeOldSphereCenter;
    2778   Vector NewPlaneCenter;
    27792442  double CircleRadius; // radius of this circle
    27802443  double radius;
    2781   double otherradius;
    27822444  double alpha, Otheralpha; // angles (i.e. parameter for the circle).
    2783   bool IsDegenerated;
    27842445  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
    27852446  TesselPoint *Candidate = NULL;
    2786   TesselPoint *CandidateTriangle[3];
    2787 
    2788   Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
     2447  CandidateForTesselation *optCandidate = NULL;
     2448
     2449  Log() << Verbose(1) << "Begin of FindThirdPointForTesselation" << endl;
     2450
     2451  Log() << Verbose(2) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
    27892452
    27902453  // construct center of circle
    2791   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2792   CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     2454  CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node);
     2455  CircleCenter.AddVector(BaseLine->endpoints[1]->node->node);
    27932456  CircleCenter.Scale(0.5);
    27942457
    27952458  // construct normal vector of circle
    2796   CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2797   CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2798 
    2799   RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
    2800   RelativeOldSphereCenter.SubtractVector(&CircleCenter);
    2801 
    2802   CandidateTriangle[0] = CandidateLine.BaseLine->endpoints[0]->node;
    2803   CandidateTriangle[1] = CandidateLine.BaseLine->endpoints[1]->node;
     2459  CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node);
     2460  CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
    28042461
    28052462  // calculate squared radius TesselPoint *ThirdNode,f circle
    2806   radius = CirclePlaneNormal.NormSquared()/4.;
    2807   if (radius < RADIUS*RADIUS) {
    2808     CircleRadius = RADIUS*RADIUS - radius;
     2463  radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
     2464  if (radius/4. < RADIUS*RADIUS) {
     2465    CircleRadius = RADIUS*RADIUS - radius/4.;
    28092466    CirclePlaneNormal.Normalize();
    2810     Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     2467    //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    28112468
    28122469    // test whether old center is on the band's plane
    2813     if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    2814       eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
    2815       RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
    2816     }
    2817     radius = RelativeOldSphereCenter.NormSquared();
     2470    if (fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
     2471      eLog() << Verbose(1) << "Something's very wrong here: OldSphereCenter is not on the band's plane as desired by " << fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
     2472      OldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
     2473    }
     2474    radius = OldSphereCenter.ScalarProduct(&OldSphereCenter);
    28182475    if (fabs(radius - CircleRadius) < HULLEPSILON) {
    2819       Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl;
     2476      //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
    28202477
    28212478      // check SearchDirection
    2822       Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2823       if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {  // rotated the wrong way!
     2479      //Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2480      if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {  // rotated the wrong way!
    28242481        eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl;
    28252482      }
     
    28292486        for(int i=0;i<NDIM;i++) // store indices of this cell
    28302487        N[i] = LC->n[i];
    2831         //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     2488        //Log() << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    28322489      } else {
    28332490        eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl;
     
    28352492      }
    28362493      // then go through the current and all neighbouring cells and check the contained points for possible candidates
    2837       //Log() << Verbose(1) << "LC Intervals:";
     2494      //Log() << Verbose(2) << "LC Intervals:";
    28382495      for (int i=0;i<NDIM;i++) {
    28392496        Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
     
    28462503          for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    28472504            const LinkedNodes *List = LC->GetCurrentCell();
    2848             //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     2505            //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    28492506            if (List != NULL) {
    28502507              for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     
    28522509
    28532510                // check for three unique points
    2854                 Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl;
    2855                 if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node) ){
    2856 
    2857                   // find center on the plane
    2858                   GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
    2859                   Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl;
    2860 
    2861                   if ((NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node))
    2862                   && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)
     2511                //Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " at " << Candidate->node << "." << endl;
     2512                if ((Candidate != BaseLine->endpoints[0]->node) && (Candidate != BaseLine->endpoints[1]->node) ){
     2513
     2514                  // construct both new centers
     2515                  GetCenterofCircumcircle(&NewSphereCenter, *BaseLine->endpoints[0]->node->node, *BaseLine->endpoints[1]->node->node, *Candidate->node);
     2516                  OtherNewSphereCenter.CopyVector(&NewSphereCenter);
     2517
     2518                  if ((NewNormalVector.MakeNormalVector(BaseLine->endpoints[0]->node->node, BaseLine->endpoints[1]->node->node, Candidate->node))
     2519                  && (fabs(NewNormalVector.ScalarProduct(&NewNormalVector)) > HULLEPSILON)
    28632520                  ) {
    2864                     Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
    2865                     radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
    2866                     Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    2867                     Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2868                     Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl;
     2521                    helper.CopyVector(&NewNormalVector);
     2522                    //Log() << Verbose(2) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
     2523                    radius = BaseLine->endpoints[0]->node->node->DistanceSquared(&NewSphereCenter);
    28692524                    if (radius < RADIUS*RADIUS) {
    2870                       otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
    2871                       if (fabs(radius - otherradius) > HULLEPSILON) {
    2872                         eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl;
    2873                       }
    2874                       // construct both new centers
    2875                       NewSphereCenter.CopyVector(&NewPlaneCenter);
    2876                       OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
    2877                       helper.CopyVector(&NewNormalVector);
    28782525                      helper.Scale(sqrt(RADIUS*RADIUS - radius));
    2879                       Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl;
     2526                      //Log() << Verbose(2) << "INFO: Distance of NewCircleCenter to NewSphereCenter is " << helper.Norm() << " with sphere radius " << RADIUS << "." << endl;
    28802527                      NewSphereCenter.AddVector(&helper);
    2881                       Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
     2528                      NewSphereCenter.SubtractVector(&CircleCenter);
     2529                      //Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
     2530
    28822531                      // OtherNewSphereCenter is created by the same vector just in the other direction
    28832532                      helper.Scale(-1.);
    28842533                      OtherNewSphereCenter.AddVector(&helper);
    2885                       Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
     2534                      OtherNewSphereCenter.SubtractVector(&CircleCenter);
     2535                      //Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
    28862536
    28872537                      alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    28882538                      Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    28892539                      alpha = min(alpha, Otheralpha);
    2890 
    2891                       CandidateTriangle[2] = Candidate;
    2892                       // the idea of the IsDegenerated flag is not to put a penalty on degenerated triangles, but to push them to the
    2893                       // very end of the Tesselation::OpenLines list.
    2894                       IsDegenerated = (CheckPresenceOfTriangle(CandidateTriangle) >= 3);
    2895                       if (!IsDegenerated && CandidateLine.IsDegenerated) {  // if current is not, but old one was, comparison would be unfair
    2896                         // if there is a better candidate, drop the current list and add the new candidate
    2897                         // otherwise ignore the new candidate and keep the list
    2898                         if (CandidateLine.ShortestAngle-2.*M_PI > (alpha - HULLEPSILON)) {
    2899                           if (fabs(alpha - Otheralpha) > MYEPSILON) {
    2900                             CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
    2901                             CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
    2902                           } else {
    2903                             CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
    2904                             CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     2540                      // if there is a better candidate, drop the current list and add the new candidate
     2541                      // otherwise ignore the new candidate and keep the list
     2542                      if (*ShortestAngle > (alpha - HULLEPSILON)) {
     2543                        optCandidate = new CandidateForTesselation(Candidate, BaseLine, OptCandidateCenter, OtherOptCandidateCenter);
     2544                        if (fabs(alpha - Otheralpha) > MYEPSILON) {
     2545                          optCandidate->OptCenter.CopyVector(&NewSphereCenter);
     2546                          optCandidate->OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     2547                        } else {
     2548                          optCandidate->OptCenter.CopyVector(&OtherNewSphereCenter);
     2549                          optCandidate->OtherOptCenter.CopyVector(&NewSphereCenter);
     2550                        }
     2551                        // if there is an equal candidate, add it to the list without clearing the list
     2552                        if ((*ShortestAngle - HULLEPSILON) < alpha) {
     2553                          candidates->push_back(optCandidate);
     2554                          Log() << Verbose(2) << "ACCEPT: We have found an equally good candidate: " << *(optCandidate->point) << " with "
     2555                            << alpha << " and circumsphere's center at " << optCandidate->OptCenter << "." << endl;
     2556                        } else {
     2557                          // remove all candidates from the list and then the list itself
     2558                          class CandidateForTesselation *remover = NULL;
     2559                          for (CandidateList::iterator it = candidates->begin(); it != candidates->end(); ++it) {
     2560                            remover = *it;
     2561                            delete(remover);
    29052562                          }
    2906                           // if there is an equal candidate, add it to the list without clearing the list
    2907                           if ((CandidateLine.ShortestAngle-2.*M_PI - HULLEPSILON) < alpha) {
    2908                             CandidateLine.pointlist.push_back(Candidate);
    2909                             Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
    2910                               << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    2911                           } else {
    2912                             // remove all candidates from the list and then the list itself
    2913                             CandidateLine.pointlist.clear();
    2914                             CandidateLine.pointlist.push_back(Candidate);
    2915                             Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
    2916                               << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    2917                           }
    2918                           CandidateLine.ShortestAngle = alpha;
    2919                           CandidateLine.IsDegenerated = IsDegenerated;
    2920                           if (IsDegenerated)
    2921                             CandidateLine.ShortestAngle += 2.*M_PI;
    2922                           Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
     2563                          candidates->clear();
     2564                          candidates->push_back(optCandidate);
     2565                          Log() << Verbose(2) << "ACCEPT: We have found a better candidate: " << *(optCandidate->point) << " with "
     2566                            << alpha << " and circumsphere's center at " << optCandidate->OptCenter << "." << endl;
     2567                        }
     2568                        *ShortestAngle = alpha;
     2569                        //Log() << Verbose(2) << "INFO: There are " << candidates->size() << " candidates in the list now." << endl;
     2570                      } else {
     2571                        if ((optCandidate != NULL) && (optCandidate->point != NULL)) {
     2572                          //Log() << Verbose(2) << "REJECT: Old candidate " << *(optCandidate->point) << " with " << *ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
    29232573                        } else {
    2924                           if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
    2925                             Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
    2926                           } else {
    2927                             Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
    2928                           }
    2929                         }
    2930                       } else {
    2931                         // if there is a better candidate, drop the current list and add the new candidate
    2932                         // otherwise ignore the new candidate and keep the list
    2933                         if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
    2934                           if (fabs(alpha - Otheralpha) > MYEPSILON) {
    2935                             CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
    2936                             CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
    2937                           } else {
    2938                             CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
    2939                             CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
    2940                           }
    2941                           // if there is an equal candidate, add it to the list without clearing the list
    2942                           if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
    2943                             CandidateLine.pointlist.push_back(Candidate);
    2944                             Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
    2945                               << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    2946                           } else {
    2947                             // remove all candidates from the list and then the list itself
    2948                             CandidateLine.pointlist.clear();
    2949                             CandidateLine.pointlist.push_back(Candidate);
    2950                             Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
    2951                               << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    2952                           }
    2953                           CandidateLine.ShortestAngle = alpha;
    2954                           Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
    2955                         } else {
    2956                           if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
    2957                             Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
    2958                           } else {
    2959                             Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
    2960                           }
     2574                          //Log() << Verbose(2) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
    29612575                        }
    29622576                      }
    29632577
    29642578                    } else {
    2965                       Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
     2579                      //Log() << Verbose(2) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
    29662580                    }
    29672581                  } else {
    2968                     Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
     2582                    //Log() << Verbose(2) << "REJECT: Three points from " << *BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
    29692583                  }
    29702584                } else {
    29712585                  if (ThirdNode != NULL) {
    2972                     Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
     2586                    //Log() << Verbose(2) << "REJECT: Base triangle " << *BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
    29732587                  } else {
    2974                     Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl;
     2588                    //Log() << Verbose(2) << "REJECT: Base triangle " << *BaseLine << " contains Candidate " << *Candidate << "." << endl;
    29752589                  }
    29762590                }
     
    29832597  } else {
    29842598    if (ThirdNode != NULL)
    2985       Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
     2599      Log() << Verbose(2) << "Circumcircle for base line " << *BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
    29862600    else
    2987       Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl;
    2988   }
    2989 
    2990   Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl;
    2991   if (CandidateLine.pointlist.size() > 1) {
    2992     CandidateLine.pointlist.unique();
    2993     CandidateLine.pointlist.sort(); //SortCandidates);
    2994   }
     2601      Log() << Verbose(2) << "Circumcircle for base line " << *BaseLine << " is too big!" << endl;
     2602  }
     2603
     2604  //Log() << Verbose(2) << "INFO: Sorting candidate list ..." << endl;
     2605  if (candidates->size() > 1) {
     2606    candidates->unique();
     2607    candidates->sort(SortCandidates);
     2608  }
     2609
     2610  Log() << Verbose(1) << "End of FindThirdPointForTesselation" << endl;
    29952611};
    29962612
     
    30022618class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
    30032619{
    3004         Info FunctionInfo(__func__);
    30052620  const BoundaryLineSet * lines[2] = { line1, line2 };
    30062621  class BoundaryPointSet *node = NULL;
     
    30162631          { // if insertion fails, we have common endpoint
    30172632            node = OrderTest.first->second;
    3018             Log() << Verbose(1) << "Common endpoint of lines " << *line1
     2633            Log() << Verbose(5) << "Common endpoint of lines " << *line1
    30192634                << " and " << *line2 << " is: " << *node << "." << endl;
    30202635            j = 2;
     
    30332648list<BoundaryTriangleSet*> * Tesselation::FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const
    30342649{
    3035         Info FunctionInfo(__func__);
    30362650  TesselPoint *trianglePoints[3];
    30372651  TesselPoint *SecondPoint = NULL;
     
    30392653
    30402654  if (LinesOnBoundary.empty()) {
    3041     eLog() << Verbose(1) << "Error: There is no tesselation structure to compare the point with, please create one first.";
     2655    Log() << Verbose(0) << "Error: There is no tesselation structure to compare the point with, please create one first.";
    30422656    return NULL;
    30432657  }
     
    30472661  // check whether closest point is "too close" :), then it's inside
    30482662  if (trianglePoints[0] == NULL) {
    3049     Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
     2663    Log() << Verbose(2) << "Is the only point, no one else is closeby." << endl;
    30502664    return NULL;
    30512665  }
    30522666  if (trianglePoints[0]->node->DistanceSquared(x) < MYEPSILON) {
    3053     Log() << Verbose(1) << "Point is right on a tesselation point, no nearest triangle." << endl;
     2667    Log() << Verbose(3) << "Point is right on a tesselation point, no nearest triangle." << endl;
    30542668    PointMap::const_iterator PointRunner = PointsOnBoundary.find(trianglePoints[0]->nr);
    30552669    triangles = new list<BoundaryTriangleSet*>;
     
    30752689    }
    30762690  } else {
    3077     set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(trianglePoints[0]);
    3078     TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(connectedPoints, trianglePoints[0], x);
    3079     delete(connectedPoints);
     2691    list<TesselPoint*> *connectedClosestPoints = GetCircleOfConnectedPoints(trianglePoints[0], x);
    30802692    if (connectedClosestPoints != NULL) {
    30812693      trianglePoints[1] = connectedClosestPoints->front();
     
    30852697          eLog() << Verbose(1) << "IsInnerPoint encounters serious error, point " << i << " not found." << endl;
    30862698        }
    3087         //Log() << Verbose(1) << "List of triangle points:" << endl;
    3088         //Log() << Verbose(2) << *trianglePoints[i] << endl;
     2699        //Log() << Verbose(2) << "List of triangle points:" << endl;
     2700        //Log() << Verbose(3) << *trianglePoints[i] << endl;
    30892701      }
    30902702
    30912703      triangles = FindTriangles(trianglePoints);
    3092       Log() << Verbose(1) << "List of possible triangles:" << endl;
     2704      Log() << Verbose(2) << "List of possible triangles:" << endl;
    30932705      for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    3094         Log() << Verbose(2) << **Runner << endl;
     2706        Log() << Verbose(3) << **Runner << endl;
    30952707
    30962708      delete(connectedClosestPoints);
    30972709    } else {
    30982710      triangles = NULL;
    3099       eLog() << Verbose(2) << "There is no circle of connected points!" << endl;
     2711      Log() << Verbose(1) << "There is no circle of connected points!" << endl;
    31002712    }
    31012713  }
     
    31172729class BoundaryTriangleSet * Tesselation::FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const
    31182730{
    3119         Info FunctionInfo(__func__);
    31202731  class BoundaryTriangleSet *result = NULL;
    31212732  list<BoundaryTriangleSet*> *triangles = FindClosestTrianglesToPoint(x, LC);
     
    31272738  if (triangles->size() == 1) { // there is no degenerate case
    31282739    result = triangles->front();
    3129     Log() << Verbose(1) << "Normal Vector of this triangle is " << result->NormalVector << "." << endl;
     2740    Log() << Verbose(2) << "Normal Vector of this triangle is " << result->NormalVector << "." << endl;
    31302741  } else {
    31312742    result = triangles->front();
    31322743    result->GetCenter(&Center);
    31332744    Center.SubtractVector(x);
    3134     Log() << Verbose(1) << "Normal Vector of this front side is " << result->NormalVector << "." << endl;
     2745    Log() << Verbose(2) << "Normal Vector of this front side is " << result->NormalVector << "." << endl;
    31352746    if (Center.ScalarProduct(&result->NormalVector) < 0) {
    31362747      result = triangles->back();
    3137       Log() << Verbose(1) << "Normal Vector of this back side is " << result->NormalVector << "." << endl;
     2748      Log() << Verbose(2) << "Normal Vector of this back side is " << result->NormalVector << "." << endl;
    31382749      if (Center.ScalarProduct(&result->NormalVector) < 0) {
    31392750        eLog() << Verbose(1) << "Front and back side yield NormalVector in wrong direction!" << endl;
     
    31542765bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
    31552766{
    3156         Info FunctionInfo(__func__);
    31572767  class BoundaryTriangleSet *result = FindClosestTriangleToPoint(&Point, LC);
    31582768  Vector Center;
     
    31642774
    31652775  result->GetCenter(&Center);
    3166   Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
     2776  Log() << Verbose(3) << "INFO: Central point of the triangle is " << Center << "." << endl;
    31672777  Center.SubtractVector(&Point);
    3168   Log() << Verbose(2) << "INFO: Vector from center to point to test is " << Center << "." << endl;
     2778  Log() << Verbose(3) << "INFO: Vector from center to point to test is " << Center << "." << endl;
    31692779  if (Center.ScalarProduct(&result->NormalVector) > -MYEPSILON) {
    31702780    Log() << Verbose(1) << Point << " is an inner point." << endl;
     
    31852795bool Tesselation::IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const
    31862796{
    3187         Info FunctionInfo(__func__);
    31882797  return IsInnerPoint(*(Point->node), LC);
    31892798}
     
    31972806set<TesselPoint*> * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    31982807{
    3199         Info FunctionInfo(__func__);
    32002808  set<TesselPoint*> *connectedPoints = new set<TesselPoint*>;
    32012809  class BoundaryPointSet *ReferencePoint = NULL;
    32022810  TesselPoint* current;
    32032811  bool takePoint = false;
     2812
     2813  Log() << Verbose(3) << "Begin of GetAllConnectedPoints" << endl;
    32042814
    32052815  // find the respective boundary point
     
    32082818    ReferencePoint = PointRunner->second;
    32092819  } else {
    3210     eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
     2820    Log() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
    32112821    ReferencePoint = NULL;
    32122822  }
     
    32322842
    32332843   if (takePoint) {
    3234      Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
     2844     Log() << Verbose(5) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
    32352845     connectedPoints->insert(current);
    32362846   }
     
    32442854  }
    32452855
     2856  Log() << Verbose(3) << "End of GetAllConnectedPoints" << endl;
    32462857  return connectedPoints;
    32472858};
     
    32552866 *
    32562867 * @param *out output stream for debugging
    3257  * @param *SetOfNeighbours all points for which the angle should be calculated
    32582868 * @param *Point of which get all connected points
    32592869 * @param *Reference Reference vector for zero angle or NULL for no preference
    32602870 * @return list of the all points linked to the provided one
    32612871 */
    3262 list<TesselPoint*> * Tesselation::GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    3263 {
    3264         Info FunctionInfo(__func__);
     2872list<TesselPoint*> * Tesselation::GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference) const
     2873{
    32652874  map<double, TesselPoint*> anglesOfPoints;
     2875  set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(Point);
    32662876  list<TesselPoint*> *connectedCircle = new list<TesselPoint*>;
    32672877  Vector center;
     
    32712881  Vector helper;
    32722882
    3273   if (SetOfNeighbours == NULL) {
    3274     eLog() << Verbose(2) << "Could not find any connected points!" << endl;
     2883  if (connectedPoints == NULL) {
     2884    Log() << Verbose(2) << "Could not find any connected points!" << endl;
    32752885    delete(connectedCircle);
    32762886    return NULL;
    32772887  }
     2888  Log() << Verbose(2) << "Begin of GetCircleOfConnectedPoints" << endl;
    32782889
    32792890  // calculate central point
    3280   for (set<TesselPoint*>::const_iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
     2891  for (set<TesselPoint*>::const_iterator TesselRunner = connectedPoints->begin(); TesselRunner != connectedPoints->end(); TesselRunner++)
    32812892    center.AddVector((*TesselRunner)->node);
    32822893  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
    32832894  //  << "; scale factor " << 1.0/connectedPoints.size();
    3284   center.Scale(1.0/SetOfNeighbours->size());
    3285   Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
     2895  center.Scale(1.0/connectedPoints->size());
     2896  Log() << Verbose(4) << "INFO: Calculated center of all circle points is " << center << "." << endl;
    32862897
    32872898  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
     
    32892900  PlaneNormal.SubtractVector(&center);
    32902901  PlaneNormal.Normalize();
    3291   Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
     2902  Log() << Verbose(4) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
    32922903
    32932904  // construct one orthogonal vector
     
    32982909  }
    32992910  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    3300     Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
    3301     AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
     2911    Log() << Verbose(4) << "Using alternatively " << *(*connectedPoints->begin())->node << " as angle 0 referencer." << endl;
     2912    AngleZero.CopyVector((*connectedPoints->begin())->node);
    33022913    AngleZero.SubtractVector(Point->node);
    33032914    AngleZero.ProjectOntoPlane(&PlaneNormal);
     
    33072918    }
    33082919  }
    3309   Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
     2920  Log() << Verbose(4) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
    33102921  if (AngleZero.NormSquared() > MYEPSILON)
    33112922    OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
    33122923  else
    33132924    OrthogonalVector.MakeNormalVector(&PlaneNormal);
    3314   Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
     2925  Log() << Verbose(4) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
    33152926
    33162927  // go through all connected points and calculate angle
    3317   for (set<TesselPoint*>::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
     2928  for (set<TesselPoint*>::iterator listRunner = connectedPoints->begin(); listRunner != connectedPoints->end(); listRunner++) {
    33182929    helper.CopyVector((*listRunner)->node);
    33192930    helper.SubtractVector(Point->node);
    33202931    helper.ProjectOntoPlane(&PlaneNormal);
    33212932    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    3322     Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
     2933    Log() << Verbose(3) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
    33232934    anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
    33242935  }
     
    33272938    connectedCircle->push_back(AngleRunner->second);
    33282939  }
     2940
     2941  delete(connectedPoints);
     2942
     2943  Log() << Verbose(2) << "End of GetCircleOfConnectedPoints" << endl;
    33292944
    33302945  return connectedCircle;
     
    33392954list<list<TesselPoint*> *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    33402955{
    3341         Info FunctionInfo(__func__);
    33422956  map<double, TesselPoint*> anglesOfPoints;
    33432957  list<list<TesselPoint*> *> *ListOfPaths = new list<list<TesselPoint*> *>;
     
    33842998        StartLine = CurrentLine;
    33852999        CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
    3386         Log() << Verbose(1)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
     3000        Log() << Verbose(3)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
    33873001        do {
    33883002          // push current one
    3389           Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     3003          Log() << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
    33903004          connectedPath->push_back(CurrentPoint->node);
    33913005
    33923006          // find next triangle
    33933007          for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
    3394             Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
     3008            Log() << Verbose(3) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
    33953009            if ((Runner->second != triangle)) { // look for first triangle not equal to old one
    33963010              triangle = Runner->second;
     
    33993013                if (!TriangleRunner->second) {
    34003014                  TriangleRunner->second = true;
    3401                   Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl;
     3015                  Log() << Verbose(3) << "INFO: Connecting triangle is " << *triangle << "." << endl;
    34023016                  break;
    34033017                } else {
    3404                   Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
     3018                  Log() << Verbose(3) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
    34053019                  triangle = NULL;
    34063020                }
     
    34173031            if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
    34183032              CurrentLine = triangle->lines[i];
    3419               Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
     3033              Log() << Verbose(3) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
    34203034              break;
    34213035            }
     
    34313045        } while (CurrentLine != StartLine);
    34323046        // last point is missing, as it's on start line
    3433         Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     3047        Log() << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
    34343048        if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
    34353049          connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
     
    34373051        ListOfPaths->push_back(connectedPath);
    34383052      } else {
    3439         Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
     3053        Log() << Verbose(3) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
    34403054      }
    34413055    }
     
    34553069list<list<TesselPoint*> *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    34563070{
    3457         Info FunctionInfo(__func__);
    34583071  list<list<TesselPoint*> *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    34593072  list<list<TesselPoint*> *> *ListofClosedPaths = new list<list<TesselPoint*> *>;
     
    34693082    connectedPath = *ListRunner;
    34703083
    3471     Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl;
     3084    Log() << Verbose(2) << "INFO: Current path is " << connectedPath << "." << endl;
    34723085
    34733086    // go through list, look for reappearance of starting Point and count
     
    34793092      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    34803093        // we have a closed circle from Marker to new Marker
    3481         Log() << Verbose(1) << count+1 << ". closed path consists of: ";
     3094        Log() << Verbose(3) << count+1 << ". closed path consists of: ";
    34823095        newPath = new list<TesselPoint*>;
    34833096        list<TesselPoint*>::iterator CircleSprinter = Marker;
     
    34953108    }
    34963109  }
    3497   Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl;
     3110  Log() << Verbose(3) << "INFO: " << count << " closed additional path(s) have been created." << endl;
    34983111
    34993112  // delete list of paths
     
    35173130set<BoundaryTriangleSet*> *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    35183131{
    3519         Info FunctionInfo(__func__);
    35203132  set<BoundaryTriangleSet*> *connectedTriangles = new set<BoundaryTriangleSet*>;
    35213133
     
    35563168    return 0.;
    35573169  } else
    3558     Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl;
     3170    Log() << Verbose(2) << "Removing point " << *point << " from tesselated boundary ..." << endl;
    35593171
    35603172  // copy old location for the volume
     
    35863198  NormalVector.Zero();
    35873199  for (map<class BoundaryTriangleSet *, int>::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    3588     Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
     3200    Log() << Verbose(3) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
    35893201    NormalVector.SubtractVector(&Runner->first->NormalVector); // has to point inward
    35903202    RemoveTesselationTriangle(Runner->first);
     
    36163228        smallestangle = 0.;
    36173229        for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
    3618           Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
     3230          Log() << Verbose(3) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
    36193231          // construct vectors to next and previous neighbour
    36203232          StartNode = MiddleNode;
     
    36443256        MiddleNode = EndNode;
    36453257        if (MiddleNode == connectedPath->end()) {
    3646           eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl;
    3647           performCriticalExit();
     3258          Log() << Verbose(1) << "CRITICAL: Could not find a smallest angle!" << endl;
     3259          exit(255);
    36483260        }
    36493261        StartNode = MiddleNode;
     
    36543266        if (EndNode == connectedPath->end())
    36553267          EndNode = connectedPath->begin();
    3656         Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl;
    3657         Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
    3658         Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl;
    3659         Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;
     3268        Log() << Verbose(4) << "INFO: StartNode is " << **StartNode << "." << endl;
     3269        Log() << Verbose(4) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
     3270        Log() << Verbose(4) << "INFO: EndNode is " << **EndNode << "." << endl;
     3271        Log() << Verbose(3) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;
    36603272        TriangleCandidates[0] = *StartNode;
    36613273        TriangleCandidates[1] = *MiddleNode;
     
    36633275        triangle = GetPresentTriangle(TriangleCandidates);
    36643276        if (triangle != NULL) {
    3665           eLog() << Verbose(0) << "New triangle already present, skipping!" << endl;
     3277          eLog() << Verbose(2) << "New triangle already present, skipping!" << endl;
    36663278          StartNode++;
    36673279          MiddleNode++;
     
    36753287          continue;
    36763288        }
    3677         Log() << Verbose(3) << "Adding new triangle points."<< endl;
     3289        Log() << Verbose(5) << "Adding new triangle points."<< endl;
    36783290        AddTesselationPoint(*StartNode, 0);
    36793291        AddTesselationPoint(*MiddleNode, 1);
    36803292        AddTesselationPoint(*EndNode, 2);
    3681         Log() << Verbose(3) << "Adding new triangle lines."<< endl;
     3293        Log() << Verbose(5) << "Adding new triangle lines."<< endl;
    36823294        AddTesselationLine(TPS[0], TPS[1], 0);
    36833295        AddTesselationLine(TPS[0], TPS[2], 1);
     
    36943306        // prepare nodes for next triangle
    36953307        StartNode = EndNode;
    3696         Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
     3308        Log() << Verbose(4) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
    36973309        connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
    36983310        if (connectedPath->size() == 2) { // we are done
     
    37013313          break;
    37023314        } else if (connectedPath->size() < 2) { // something's gone wrong!
    3703           eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl;
    3704           performCriticalExit();
     3315          Log() << Verbose(1) << "CRITICAL: There are only two endpoints left!" << endl;
     3316          exit(255);
    37053317        } else {
    37063318          MiddleNode = StartNode;
     
    37303342          if (maxgain != 0) {
    37313343            volume += maxgain;
    3732             Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
     3344            Log() << Verbose(3) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
    37333345            OtherBase = FlipBaseline(*Candidate);
    37343346            NewLines.erase(Candidate);
     
    37413353      delete(connectedPath);
    37423354    }
    3743     Log() << Verbose(0) << count << " triangles were created." << endl;
     3355    Log() << Verbose(1) << count << " triangles were created." << endl;
    37443356  } else {
    37453357    while (!ListOfClosedPaths->empty()) {
     
    37493361      delete(connectedPath);
    37503362    }
    3751     Log() << Verbose(0) << "No need to create any triangles." << endl;
     3363    Log() << Verbose(1) << "No need to create any triangles." << endl;
    37523364  }
    37533365  delete(ListOfClosedPaths);
    37543366
    3755   Log() << Verbose(0) << "Removed volume is " << volume << "." << endl;
     3367  Log() << Verbose(1) << "Removed volume is " << volume << "." << endl;
    37563368
    37573369  return volume;
     
    37703382list<BoundaryTriangleSet*> *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    37713383{
    3772         Info FunctionInfo(__func__);
    37733384  list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;
    37743385  LineMap::const_iterator FindLine;
     
    38113422}
    38123423
    3813 struct BoundaryLineSetCompare {
    3814   bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) {
    3815     int lowerNra = -1;
    3816     int lowerNrb = -1;
    3817 
    3818     if (a->endpoints[0] < a->endpoints[1])
    3819       lowerNra = 0;
    3820     else
    3821       lowerNra = 1;
    3822 
    3823     if (b->endpoints[0] < b->endpoints[1])
    3824       lowerNrb = 0;
    3825     else
    3826       lowerNrb = 1;
    3827 
    3828     if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
    3829       return true;
    3830     else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
    3831       return false;
    3832     else {  // both lower-numbered endpoints are the same ...
    3833      if (a->endpoints[(lowerNra+1)%2] < b->endpoints[(lowerNrb+1)%2])
    3834        return true;
    3835      else if (a->endpoints[(lowerNra+1)%2] > b->endpoints[(lowerNrb+1)%2])
    3836        return false;
    3837     }
    3838     return false;
    3839   };
    3840 };
    3841 
    3842 #define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
    3843 
    38443424/**
    38453425 * Finds all degenerated lines within the tesselation structure.
     
    38503430map<int, int> * Tesselation::FindAllDegeneratedLines()
    38513431{
    3852         Info FunctionInfo(__func__);
    3853         UniqueLines AllLines;
     3432  map<int, class BoundaryLineSet *> AllLines;
    38543433  map<int, int> * DegeneratedLines = new map<int, int>;
    38553434
    38563435  // sanity check
    38573436  if (LinesOnBoundary.empty()) {
    3858     eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.";
     3437    Log() << Verbose(1) << "Warning: FindAllDegeneratedTriangles() was called without any tesselation structure.";
    38593438    return DegeneratedLines;
    38603439  }
    38613440
    38623441  LineMap::iterator LineRunner1;
    3863   pair< UniqueLines::iterator, bool> tester;
     3442  pair<LineMap::iterator, bool> tester;
    38643443  for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
    3865     tester = AllLines.insert( LineRunner1->second );
    3866     if (!tester.second) { // found degenerated line
    3867       DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr) );
    3868       DegeneratedLines->insert ( pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr) );
     3444    tester = AllLines.insert( pair<int,BoundaryLineSet *> (LineRunner1->second->endpoints[0]->Nr, LineRunner1->second) );
     3445    if ((!tester.second) && (tester.first->second->endpoints[1]->Nr == LineRunner1->second->endpoints[1]->Nr)) { // found degenerated line
     3446      DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, tester.first->second->Nr) );
     3447      DegeneratedLines->insert ( pair<int, int> (tester.first->second->Nr, LineRunner1->second->Nr) );
    38693448    }
    38703449  }
     
    38723451  AllLines.clear();
    38733452
    3874   Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
     3453  Log() << Verbose(1) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
    38753454  map<int,int>::iterator it;
    3876   for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
    3877     const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
    3878     const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
    3879     if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
    3880       Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl;
    3881     else
    3882       eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl;
    3883   }
     3455  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++)
     3456      Log() << Verbose(2) << (*it).first << " => " << (*it).second << endl;
    38843457
    38853458  return DegeneratedLines;
     
    38943467map<int, int> * Tesselation::FindAllDegeneratedTriangles()
    38953468{
    3896         Info FunctionInfo(__func__);
    38973469  map<int, int> * DegeneratedLines = FindAllDegeneratedLines();
    38983470  map<int, int> * DegeneratedTriangles = new map<int, int>;
     
    39223494  delete(DegeneratedLines);
    39233495
    3924   Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
     3496  Log() << Verbose(1) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
    39253497  map<int,int>::iterator it;
    39263498  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    3927       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     3499      Log() << Verbose(2) << (*it).first << " => " << (*it).second << endl;
    39283500
    39293501  return DegeneratedTriangles;
     
    39363508void Tesselation::RemoveDegeneratedTriangles()
    39373509{
    3938         Info FunctionInfo(__func__);
    39393510  map<int, int> * DegeneratedTriangles = FindAllDegeneratedTriangles();
    39403511  TriangleMap::iterator finder;
    39413512  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    39423513  int count  = 0;
     3514
     3515  Log() << Verbose(1) << "Begin of RemoveDegeneratedTriangles" << endl;
    39433516
    39443517  for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
     
    39993572      // erase the pair
    40003573      count += (int) DegeneratedTriangles->erase(triangle->Nr);
    4001       Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
     3574      Log() << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
    40023575      RemoveTesselationTriangle(triangle);
    40033576      count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
    4004       Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
     3577      Log() << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
    40053578      RemoveTesselationTriangle(partnerTriangle);
    40063579    } else {
    4007       Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
     3580      Log() << Verbose(1) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
    40083581        << " and its partner " << *partnerTriangle << " because it is essential for at"
    40093582        << " least one of the endpoints to be kept in the tesselation structure." << endl;
     
    40113584  }
    40123585  delete(DegeneratedTriangles);
    4013   if (count > 0)
    4014     LastTriangle = NULL;
    4015 
    4016   Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
     3586
     3587  Log() << Verbose(1) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
     3588  Log() << Verbose(1) << "End of RemoveDegeneratedTriangles" << endl;
    40173589}
    40183590
     
    40273599void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
    40283600{
    4029         Info FunctionInfo(__func__);
     3601  Log() << Verbose(2) << "Begin of AddBoundaryPointByDegeneratedTriangle" << endl;
     3602
    40303603  // find nearest boundary point
    40313604  class TesselPoint *BackupPoint = NULL;
     
    40433616    return;
    40443617  }
    4045   Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
     3618  Log() << Verbose(2) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
    40463619
    40473620  // go through its lines and find the best one to split
     
    40763649
    40773650  // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
    4078   Log() << Verbose(2) << "Adding new triangle points."<< endl;
     3651  Log() << Verbose(5) << "Adding new triangle points."<< endl;
    40793652  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    40803653  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    40813654  AddTesselationPoint(point, 2);
    4082   Log() << Verbose(2) << "Adding new triangle lines."<< endl;
     3655  Log() << Verbose(5) << "Adding new triangle lines."<< endl;
    40833656  AddTesselationLine(TPS[0], TPS[1], 0);
    40843657  AddTesselationLine(TPS[0], TPS[2], 1);
     
    40873660  BTS->GetNormalVector(TempTriangle->NormalVector);
    40883661  BTS->NormalVector.Scale(-1.);
    4089   Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
     3662  Log() << Verbose(3) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
    40903663  AddTesselationTriangle();
    40913664
    40923665  // create other side of this triangle and close both new sides of the first created triangle
    4093   Log() << Verbose(2) << "Adding new triangle points."<< endl;
     3666  Log() << Verbose(5) << "Adding new triangle points."<< endl;
    40943667  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    40953668  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    40963669  AddTesselationPoint(point, 2);
    4097   Log() << Verbose(2) << "Adding new triangle lines."<< endl;
     3670  Log() << Verbose(5) << "Adding new triangle lines."<< endl;
    40983671  AddTesselationLine(TPS[0], TPS[1], 0);
    40993672  AddTesselationLine(TPS[0], TPS[2], 1);
     
    41013674  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    41023675  BTS->GetNormalVector(TempTriangle->NormalVector);
    4103   Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
     3676  Log() << Verbose(3) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
    41043677  AddTesselationTriangle();
    41053678
     
    41083681    if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
    41093682      if (BestLine == BTS->lines[i]){
    4110         eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl;
    4111         performCriticalExit();
     3683        Log() << Verbose(1) << "CRITICAL: BestLine is same as found line, something's wrong here!" << endl;
     3684        exit(255);
    41123685      }
    41133686      BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle) );
     
    41163689    }
    41173690  }
     3691
     3692  // exit
     3693  Log() << Verbose(2) << "End of AddBoundaryPointByDegeneratedTriangle" << endl;
    41183694};
    41193695
     
    41253701void Tesselation::Output(const char *filename, const PointCloud * const cloud)
    41263702{
    4127         Info FunctionInfo(__func__);
    41283703  ofstream *tempstream = NULL;
    41293704  string NameofTempFile;
     
    41383713      NameofTempFile.erase(npos, 1);
    41393714      NameofTempFile.append(TecplotSuffix);
    4140       Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     3715      Log() << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
    41413716      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    41423717      WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
     
    41523727      NameofTempFile.erase(npos, 1);
    41533728      NameofTempFile.append(Raster3DSuffix);
    4154       Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     3729      Log() << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
    41553730      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    41563731      WriteRaster3dFile(tempstream, this, cloud);
     
    41643739    TriangleFilesWritten++;
    41653740};
    4166 
    4167 struct BoundaryPolygonSetCompare {
    4168   bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const {
    4169     if (s1->endpoints.size() < s2->endpoints.size())
    4170       return true;
    4171     else if (s1->endpoints.size() > s2->endpoints.size())
    4172       return false;
    4173     else { // equality of number of endpoints
    4174       PointSet::const_iterator Walker1 = s1->endpoints.begin();
    4175       PointSet::const_iterator Walker2 = s2->endpoints.begin();
    4176       while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
    4177         if ((*Walker1)->Nr < (*Walker2)->Nr)
    4178           return true;
    4179         else if ((*Walker1)->Nr > (*Walker2)->Nr)
    4180           return false;
    4181         Walker1++;
    4182         Walker2++;
    4183       }
    4184       return false;
    4185     }
    4186   }
    4187 };
    4188 
    4189 #define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
    4190 
    4191 /** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
    4192  * \return number of polygons found
    4193  */
    4194 int Tesselation::CorrectAllDegeneratedPolygons()
    4195 {
    4196   Info FunctionInfo(__func__);
    4197 
    4198   /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
    4199   map <int, int> *DegeneratedTriangles = FindAllDegeneratedTriangles();
    4200   set < BoundaryPointSet *> EndpointCandidateList;
    4201   pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
    4202   pair < map < int, Vector *>::iterator, bool > TriangleInsertionTester;
    4203   for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
    4204     Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl;
    4205     map < int, Vector *> TriangleVectors;
    4206     // gather all NormalVectors
    4207     Log() << Verbose(1) << "Gathering triangles ..." << endl;
    4208     for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
    4209       for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    4210         if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
    4211           TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) );
    4212           if (TriangleInsertionTester.second)
    4213             Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;
    4214         } else {
    4215           Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl;
    4216         }
    4217       }
    4218     // check whether there are two that are parallel
    4219     Log() << Verbose(1) << "Finding two parallel triangles ..." << endl;
    4220     for (map < int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
    4221       for (map < int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
    4222         if (VectorWalker != VectorRunner) { // skip equals
    4223           const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second);  // ScalarProduct should result in -1. for degenerated triangles
    4224           Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl;
    4225           if (fabs(SCP + 1.) < ParallelEpsilon) {
    4226             InsertionTester = EndpointCandidateList.insert((Runner->second));
    4227             if (InsertionTester.second)
    4228               Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl;
    4229             // and break out of both loops
    4230             VectorWalker = TriangleVectors.end();
    4231             VectorRunner = TriangleVectors.end();
    4232             break;
    4233           }
    4234         }
    4235   }
    4236 
    4237   /// 3. Find connected endpoint candidates and put them into a polygon
    4238   UniquePolygonSet ListofDegeneratedPolygons;
    4239   BoundaryPointSet *Walker = NULL;
    4240   BoundaryPointSet *OtherWalker = NULL;
    4241   BoundaryPolygonSet *Current = NULL;
    4242   stack <BoundaryPointSet*> ToCheckConnecteds;
    4243   while (!EndpointCandidateList.empty()) {
    4244     Walker = *(EndpointCandidateList.begin());
    4245     if (Current == NULL) {  // create a new polygon with current candidate
    4246       Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl;
    4247       Current = new BoundaryPolygonSet;
    4248       Current->endpoints.insert(Walker);
    4249       EndpointCandidateList.erase(Walker);
    4250       ToCheckConnecteds.push(Walker);
    4251     }
    4252 
    4253     // go through to-check stack
    4254     while (!ToCheckConnecteds.empty()) {
    4255       Walker = ToCheckConnecteds.top(); // fetch ...
    4256       ToCheckConnecteds.pop(); // ... and remove
    4257       for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
    4258         OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
    4259         Log() << Verbose(1) << "Checking " << *OtherWalker << endl;
    4260         set < BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
    4261         if (Finder != EndpointCandidateList.end()) {  // found a connected partner
    4262           Log() << Verbose(1) << " Adding to polygon." << endl;
    4263           Current->endpoints.insert(OtherWalker);
    4264           EndpointCandidateList.erase(Finder);  // remove from candidates
    4265           ToCheckConnecteds.push(OtherWalker);  // but check its partners too
    4266         } else {
    4267           Log() << Verbose(1) << " is not connected to " << *Walker << endl;
    4268         }
    4269       }
    4270     }
    4271 
    4272     Log() << Verbose(0) << "Final polygon is " << *Current << endl;
    4273     ListofDegeneratedPolygons.insert(Current);
    4274     Current = NULL;
    4275   }
    4276 
    4277   const int counter = ListofDegeneratedPolygons.size();
    4278 
    4279   Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl;
    4280   for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
    4281     Log() << Verbose(0) << " " << **PolygonRunner << endl;
    4282 
    4283   /// 4. Go through all these degenerated polygons
    4284   for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
    4285     stack <int> TriangleNrs;
    4286     Vector NormalVector;
    4287     /// 4a. Gather all triangles of this polygon
    4288     TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
    4289 
    4290     if (T->size() == 2) {
    4291       Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl;
    4292       delete(T);
    4293       continue;
    4294     }
    4295 
    4296     TriangleSet::iterator TriangleWalker = T->begin();  // is the inner iterator
    4297     /// 4a. Get NormalVector for one side (this is "front")
    4298     NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
    4299     Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl;
    4300     TriangleWalker++;
    4301     TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
    4302     /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back")
    4303     BoundaryTriangleSet *triangle = NULL;
    4304     while (TriangleSprinter != T->end()) {
    4305       TriangleWalker = TriangleSprinter;
    4306       triangle = *TriangleWalker;
    4307       TriangleSprinter++;
    4308       Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl;
    4309       if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
    4310         Log() << Verbose(1) << " Removing ... " << endl;
    4311         TriangleNrs.push(triangle->Nr);
    4312         T->erase(TriangleWalker);
    4313         RemoveTesselationTriangle(triangle);
    4314       } else
    4315         Log() << Verbose(1) << " Keeping ... " << endl;
    4316     }
    4317     /// 4c. Copy all "front" triangles but with inverse NormalVector
    4318     TriangleWalker = T->begin();
    4319     while (TriangleWalker != T->end()) {  // go through all front triangles
    4320       Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl;
    4321       for (int i = 0; i < 3; i++)
    4322         AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
    4323       AddTesselationLine(TPS[0], TPS[1], 0);
    4324       AddTesselationLine(TPS[0], TPS[2], 1);
    4325       AddTesselationLine(TPS[1], TPS[2], 2);
    4326       if (TriangleNrs.empty())
    4327         eLog() << Verbose(0) << "No more free triangle numbers!" << endl;
    4328       BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
    4329       AddTesselationTriangle(); // ... and add
    4330       TriangleNrs.pop();
    4331       BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
    4332       BTS->NormalVector.Scale(-1.);
    4333       TriangleWalker++;
    4334     }
    4335     if (!TriangleNrs.empty()) {
    4336       eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl;
    4337     }
    4338     delete(T);  // remove the triangleset
    4339   }
    4340 
    4341   map<int, int> * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
    4342   Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
    4343   map<int,int>::iterator it;
    4344   for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
    4345       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
    4346   delete(SimplyDegeneratedTriangles);
    4347 
    4348   /// 5. exit
    4349   UniquePolygonSet::iterator PolygonRunner;
    4350   while (!ListofDegeneratedPolygons.empty()) {
    4351     PolygonRunner = ListofDegeneratedPolygons.begin();
    4352     delete(*PolygonRunner);
    4353     ListofDegeneratedPolygons.erase(PolygonRunner);
    4354   }
    4355 
    4356   return counter;
    4357 };
Note: See TracChangeset for help on using the changeset viewer.