Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tesselation.cpp

    r244a84 rb1a6d8  
    77
    88#include <fstream>
     9#include <assert.h>
    910
    1011#include "helpers.hpp"
     
    1415#include "tesselation.hpp"
    1516#include "tesselationhelpers.hpp"
     17#include "triangleintersectionlist.hpp"
    1618#include "vector.hpp"
    1719#include "verbose.hpp"
     
    2426 */
    2527BoundaryPointSet::BoundaryPointSet() :
    26     LinesCount(0),
    27     value(0.),
    28     Nr(-1)
    29 {
    30         Info FunctionInfo(__func__);
    31         Log() << Verbose(1) << "Adding noname." << endl;
    32 };
     28  LinesCount(0), value(0.), Nr(-1)
     29{
     30  Info FunctionInfo(__func__);
     31  DoLog(1) && (Log() << Verbose(1) << "Adding noname." << endl);
     32}
     33;
    3334
    3435/** Constructor of BoundaryPointSet with Tesselpoint.
     
    3637 */
    3738BoundaryPointSet::BoundaryPointSet(TesselPoint * const 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;
    45 };
     39  LinesCount(0), node(Walker), value(0.), Nr(Walker->nr)
     40{
     41  Info FunctionInfo(__func__);
     42  DoLog(1) && (Log() << Verbose(1) << "Adding Node " << *Walker << endl);
     43}
     44;
    4645
    4746/** Destructor of BoundaryPointSet.
     
    5150BoundaryPointSet::~BoundaryPointSet()
    5251{
    53         Info FunctionInfo(__func__);
     52  Info FunctionInfo(__func__);
    5453  //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
    5554  if (!lines.empty())
    56     eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl;
     55    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);
    5756  node = NULL;
    58 };
     57}
     58;
    5959
    6060/** Add a line to the LineMap of this point.
     
    6363void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
    6464{
    65         Info FunctionInfo(__func__);
    66   Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "."
    67       << endl;
    68   if (line->endpoints[0] == this)
    69     {
    70       lines.insert(LinePair(line->endpoints[1]->Nr, line));
    71     }
    72   else
    73     {
    74       lines.insert(LinePair(line->endpoints[0]->Nr, line));
    75     }
     65  Info FunctionInfo(__func__);
     66  DoLog(1) && (Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl);
     67  if (line->endpoints[0] == this) {
     68    lines.insert(LinePair(line->endpoints[1]->Nr, line));
     69  } else {
     70    lines.insert(LinePair(line->endpoints[0]->Nr, line));
     71  }
    7672  LinesCount++;
    77 };
     73}
     74;
    7875
    7976/** output operator for BoundaryPointSet.
     
    9390 */
    9491BoundaryLineSet::BoundaryLineSet() :
    95     Nr(-1)
    96 {
    97         Info FunctionInfo(__func__);
     92  Nr(-1)
     93{
     94  Info FunctionInfo(__func__);
    9895  for (int i = 0; i < 2; i++)
    9996    endpoints[i] = NULL;
    100 };
     97}
     98;
    10199
    102100/** Constructor of BoundaryLineSet with two endpoints.
     
    107105BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
    108106{
    109         Info FunctionInfo(__func__);
     107  Info FunctionInfo(__func__);
    110108  // set number
    111109  Nr = number;
     
    118116  skipped = false;
    119117  // clear triangles list
    120   Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
    121 };
     118  DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
     119}
     120;
    122121
    123122/** Constructor of BoundaryLineSet with two endpoints.
     
    140139  skipped = false;
    141140  // clear triangles list
    142   Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
    143 };
     141  DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
     142}
     143;
    144144
    145145/** Destructor for BoundaryLineSet.
     
    149149BoundaryLineSet::~BoundaryLineSet()
    150150{
    151         Info FunctionInfo(__func__);
     151  Info FunctionInfo(__func__);
    152152  int Numbers[2];
    153153
     
    180180        //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
    181181        if (endpoints[i] != NULL) {
    182           delete(endpoints[i]);
     182          delete (endpoints[i]);
    183183          endpoints[i] = NULL;
    184184        }
     
    187187  }
    188188  if (!triangles.empty())
    189     eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl;
    190 };
     189    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
     190}
     191;
    191192
    192193/** Add triangle to TriangleMap of this boundary line.
     
    195196void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
    196197{
    197         Info FunctionInfo(__func__);
    198   Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
     198  Info FunctionInfo(__func__);
     199  DoLog(0) && (Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl);
    199200  triangles.insert(TrianglePair(triangle->Nr, triangle));
    200 };
     201}
     202;
    201203
    202204/** Checks whether we have a common endpoint with given \a *line.
     
    206208bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
    207209{
    208         Info FunctionInfo(__func__);
     210  Info FunctionInfo(__func__);
    209211  if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
    210212    return true;
    211213  else
    212214    return false;
    213 };
     215}
     216;
    214217
    215218/** Checks whether the adjacent triangles of a baseline are convex or not.
     
    221224bool BoundaryLineSet::CheckConvexityCriterion() const
    222225{
    223         Info FunctionInfo(__func__);
     226  Info FunctionInfo(__func__);
    224227  Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
    225228  // get the two triangles
    226229  if (triangles.size() != 2) {
    227     eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
     230    DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
    228231    return true;
    229232  }
     
    233236  BaseLineCenter.CopyVector(endpoints[0]->node->node);
    234237  BaseLineCenter.AddVector(endpoints[1]->node->node);
    235   BaseLineCenter.Scale(1./2.);
     238  BaseLineCenter.Scale(1. / 2.);
    236239  BaseLine.CopyVector(endpoints[0]->node->node);
    237240  BaseLine.SubtractVector(endpoints[1]->node->node);
     
    241244  NormalCheck.Zero();
    242245  double sign = -1.;
    243   int i=0;
     246  int i = 0;
    244247  class BoundaryPointSet *node = NULL;
    245   for(TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
     248  for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    246249    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    247250    NormalCheck.AddVector(&runner->second->NormalVector);
     
    249252    sign = -sign;
    250253    if (runner->second->NormalVector.NormSquared() > MYEPSILON)
    251       BaseLineNormal.CopyVector(&runner->second->NormalVector);   // yes, copy second on top of first
     254      BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first
    252255    else {
    253       eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl;
     256      DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
    254257    }
    255258    node = runner->second->GetThirdEndpoint(this);
     
    258261      helper[i].CopyVector(node->node->node);
    259262      helper[i].SubtractVector(&BaseLineCenter);
    260       helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
     263      helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles!
    261264      //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    262265      i++;
    263266    } else {
    264       eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;
     267      DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
    265268      return true;
    266269    }
     
    268271  //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
    269272  if (NormalCheck.NormSquared() < MYEPSILON) {
    270     Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
     273    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl);
    271274    return true;
    272275  }
     
    274277  double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    275278  if ((angle - M_PI) > -MYEPSILON) {
    276     Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl;
     279    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
    277280    return true;
    278281  } else {
    279     Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl;
     282    DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
    280283    return false;
    281284  }
     
    288291bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    289292{
    290         Info FunctionInfo(__func__);
    291   for(int i=0;i<2;i++)
     293  Info FunctionInfo(__func__);
     294  for (int i = 0; i < 2; i++)
    292295    if (point == endpoints[i])
    293296      return true;
    294297  return false;
    295 };
     298}
     299;
    296300
    297301/** Returns other endpoint of the line.
     
    301305class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
    302306{
    303         Info FunctionInfo(__func__);
     307  Info FunctionInfo(__func__);
    304308  if (endpoints[0] == point)
    305309    return endpoints[1];
     
    308312  else
    309313    return NULL;
    310 };
     314}
     315;
    311316
    312317/** output operator for BoundaryLineSet.
     
    314319 * \param &a boundary line
    315320 */
    316 ostream & operator <<(ostream &ost, const  BoundaryLineSet &a)
     321ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
    317322{
    318323  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << "," << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "]";
    319324  return ost;
    320 };
     325}
     326;
    321327
    322328// ======================================== Triangles on Boundary =================================
     
    327333  Nr(-1)
    328334{
    329         Info FunctionInfo(__func__);
    330   for (int i = 0; i < 3; i++)
    331     {
    332       endpoints[i] = NULL;
    333       lines[i] = NULL;
    334     }
    335 };
     335  Info FunctionInfo(__func__);
     336  for (int i = 0; i < 3; i++) {
     337    endpoints[i] = NULL;
     338    lines[i] = NULL;
     339  }
     340}
     341;
    336342
    337343/** Constructor for BoundaryTriangleSet with three lines.
     
    342348  Nr(number)
    343349{
    344         Info FunctionInfo(__func__);
     350  Info FunctionInfo(__func__);
    345351  // set number
    346352  // set lines
     
    354360    // for all three lines
    355361    for (int j = 0; j < 2; j++) { // for both endpoints
    356       OrderMap.insert(pair<int, class BoundaryPointSet *> (
    357           line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
     362      OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
    358363      // and we don't care whether insertion fails
    359364    }
    360365  // set endpoints
    361366  int Counter = 0;
    362   Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl;
     367  DoLog(0) && (Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl);
    363368  for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
    364369    endpoints[Counter] = runner->second;
    365     Log() << Verbose(0) << " " << *endpoints[Counter] << endl;
     370    DoLog(0) && (Log() << Verbose(0) << " " << *endpoints[Counter] << endl);
    366371    Counter++;
    367372  }
    368373  if (Counter < 3) {
    369     eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl;
     374    DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl);
    370375    performCriticalExit();
    371376  }
    372 };
     377}
     378;
    373379
    374380/** Destructor of BoundaryTriangleSet.
     
    378384BoundaryTriangleSet::~BoundaryTriangleSet()
    379385{
    380         Info FunctionInfo(__func__);
     386  Info FunctionInfo(__func__);
    381387  for (int i = 0; i < 3; i++) {
    382388    if (lines[i] != NULL) {
     
    385391      }
    386392      if (lines[i]->triangles.empty()) {
    387           //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
    388           delete (lines[i]);
    389           lines[i] = NULL;
     393        //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
     394        delete (lines[i]);
     395        lines[i] = NULL;
    390396      }
    391397    }
    392398  }
    393399  //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
    394 };
     400}
     401;
    395402
    396403/** Calculates the normal vector for this triangle.
     
    400407void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
    401408{
    402         Info FunctionInfo(__func__);
     409  Info FunctionInfo(__func__);
    403410  // get normal vector
    404411  NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     
    407414  if (NormalVector.ScalarProduct(&OtherVector) > 0.)
    408415    NormalVector.Scale(-1.);
    409   Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl;
    410 };
     416  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl);
     417}
     418;
    411419
    412420/** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
     
    429437
    430438  if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
    431     eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
     439    DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
    432440    return false;
    433441  }
    434442
    435   Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl;
    436   Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl;
    437   Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl;
     443  DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl);
     444  DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl);
     445  DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
    438446
    439447  if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) {
    440     Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl;
     448    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
    441449    return true;
    442   }   else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
    443     Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl;
     450  } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
     451    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
    444452    return true;
    445   }   else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
    446     Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl;
     453  } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
     454    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
    447455    return true;
    448456  }
    449457  // Calculate cross point between one baseline and the line from the third endpoint to intersection
    450   int i=0;
     458  int i = 0;
    451459  do {
    452     if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) {
    453       helper.CopyVector(endpoints[(i+1)%3]->node->node);
    454       helper.SubtractVector(endpoints[i%3]->node->node);
    455       CrossPoint.SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector
    456       const double s = CrossPoint.ScalarProduct(&helper)/helper.NormSquared();
    457       Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl;
    458       if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
    459         Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl;
    460         i=4;
     460    if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) {
     461      helper.CopyVector(endpoints[(i + 1) % 3]->node->node);
     462      helper.SubtractVector(endpoints[i % 3]->node->node);
     463      CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
     464      const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared();
     465      DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl);
     466      if ((s < -MYEPSILON) || ((s - 1.) > MYEPSILON)) {
     467        DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
     468        i = 4;
    461469        break;
    462470      }
    463471      i++;
    464     } else 
     472    } else
    465473      break;
    466   } while (i<3);
    467   if (i==3) {
    468     Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl;
     474  } while (i < 3);
     475  if (i == 3) {
     476    DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl);
    469477    return true;
    470478  } else {
    471     Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl;
     479    DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl);
    472480    return false;
    473481  }
    474 };
    475 
    476 /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
    477  * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
     482}
     483;
     484
     485/** Finds the point on the triangle to the point \a *x.
     486 * We call Vector::GetIntersectionWithPlane() with \a * and the center of the triangle to receive an intersection point.
     487 * Then we check the in-plane part (the part projected down onto plane). We check whether it crosses one of the
     488 * boundary lines. If it does, we return this intersection as closest point, otherwise the projected point down.
    478489 * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
    479490 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
     
    490501
    491502  // 1. get intersection with plane
    492   Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl;
     503  DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl);
    493504  GetCenter(&Direction);
    494505  if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
     
    499510  Vector InPlane;
    500511  InPlane.CopyVector(x);
    501   InPlane.SubtractVector(ClosestPoint);  // points from plane intersection to straight-down point
     512  InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point
    502513  InPlane.ProjectOntoPlane(&NormalVector);
    503514  InPlane.AddVector(ClosestPoint);
    504515
    505   Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl;
    506   Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl;
    507   Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl;
     516  DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl);
     517  DoLog(2) && (Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl);
     518  DoLog(2) && (Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl);
    508519
    509520  // Calculate cross point between one baseline and the desired point such that distance is shortest
     
    513524  Vector CrossPoint[3];
    514525  Vector helper;
    515   for (int i=0;i<3;i++) {
     526  for (int i = 0; i < 3; i++) {
    516527    // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
    517     Direction.CopyVector(endpoints[(i+1)%3]->node->node);
    518     Direction.SubtractVector(endpoints[i%3]->node->node);
     528    Direction.CopyVector(endpoints[(i + 1) % 3]->node->node);
     529    Direction.SubtractVector(endpoints[i % 3]->node->node);
    519530    // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
    520     CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node);
     531    CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node);
    521532    CrossDirection[i].CopyVector(&CrossPoint[i]);
    522533    CrossDirection[i].SubtractVector(&InPlane);
    523     CrossPoint[i].SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector
    524     const double s = CrossPoint[i].ScalarProduct(&Direction)/Direction.NormSquared();
    525     Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl;
    526     if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
    527       CrossPoint[i].AddVector(endpoints[i%3]->node->node); // make cross point absolute again
    528       Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i%3]->node->node << " and " << *endpoints[(i+1)%3]->node->node << "." << endl;
     534    CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
     535    const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared();
     536    DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl);
     537    if ((s >= -MYEPSILON) && ((s - 1.) <= MYEPSILON)) {
     538      CrossPoint[i].AddVector(endpoints[i % 3]->node->node); // make cross point absolute again
     539      DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl);
    529540      const double distance = CrossPoint[i].DistanceSquared(x);
    530541      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
     
    536547  }
    537548  InsideFlag = true;
    538   for (int i=0;i<3;i++) {
    539     const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+1)%3]);
    540     const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+2)%3]);;
    541     if ((sign > -MYEPSILON) && (othersign > -MYEPSILON))  // have different sign
     549  for (int i = 0; i < 3; i++) {
     550    const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 1) % 3]);
     551    const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 2) % 3]);
     552    ;
     553    if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
    542554      InsideFlag = false;
    543555  }
     
    545557    ClosestPoint->CopyVector(&InPlane);
    546558    ShortestDistance = InPlane.DistanceSquared(x);
    547   } else {  // also check endnodes
    548     for (int i=0;i<3;i++) {
     559  } else { // also check endnodes
     560    for (int i = 0; i < 3; i++) {
    549561      const double distance = x->DistanceSquared(endpoints[i]->node->node);
    550562      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
     
    554566    }
    555567  }
    556   Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl;
     568  DoLog(1) && (Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl);
    557569  return ShortestDistance;
    558 };
     570}
     571;
    559572
    560573/** Checks whether lines is any of the three boundary lines this triangle contains.
     
    564577bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
    565578{
    566         Info FunctionInfo(__func__);
    567   for(int i=0;i<3;i++)
     579  Info FunctionInfo(__func__);
     580  for (int i = 0; i < 3; i++)
    568581    if (line == lines[i])
    569582      return true;
    570583  return false;
    571 };
     584}
     585;
    572586
    573587/** Checks whether point is any of the three endpoints this triangle contains.
     
    577591bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    578592{
    579         Info FunctionInfo(__func__);
    580   for(int i=0;i<3;i++)
     593  Info FunctionInfo(__func__);
     594  for (int i = 0; i < 3; i++)
    581595    if (point == endpoints[i])
    582596      return true;
    583597  return false;
    584 };
     598}
     599;
    585600
    586601/** Checks whether point is any of the three endpoints this triangle contains.
     
    590605bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
    591606{
    592         Info FunctionInfo(__func__);
    593   for(int i=0;i<3;i++)
     607  Info FunctionInfo(__func__);
     608  for (int i = 0; i < 3; i++)
    594609    if (point == endpoints[i]->node)
    595610      return true;
    596611  return false;
    597 };
     612}
     613;
    598614
    599615/** Checks whether three given \a *Points coincide with triangle's endpoints.
     
    603619bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
    604620{
    605         Info FunctionInfo(__func__);
    606         Log() << Verbose(1) << "INFO: Checking " << Points[0] << ","  << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl;
    607   return (((endpoints[0] == Points[0])
    608             || (endpoints[0] == Points[1])
    609             || (endpoints[0] == Points[2])
    610           ) && (
    611             (endpoints[1] == Points[0])
    612             || (endpoints[1] == Points[1])
    613             || (endpoints[1] == Points[2])
    614           ) && (
    615             (endpoints[2] == Points[0])
    616             || (endpoints[2] == Points[1])
    617             || (endpoints[2] == Points[2])
    618 
    619           ));
    620 };
     621  Info FunctionInfo(__func__);
     622  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl);
     623  return (((endpoints[0] == Points[0]) || (endpoints[0] == Points[1]) || (endpoints[0] == Points[2])) && ((endpoints[1] == Points[0]) || (endpoints[1] == Points[1]) || (endpoints[1] == Points[2])) && ((endpoints[2] == Points[0]) || (endpoints[2] == Points[1]) || (endpoints[2] == Points[2])
     624
     625  ));
     626}
     627;
    621628
    622629/** Checks whether three given \a *Points coincide with triangle's endpoints.
     
    626633bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
    627634{
    628         Info FunctionInfo(__func__);
    629   return (((endpoints[0] == T->endpoints[0])
    630             || (endpoints[0] == T->endpoints[1])
    631             || (endpoints[0] == T->endpoints[2])
    632           ) && (
    633             (endpoints[1] == T->endpoints[0])
    634             || (endpoints[1] == T->endpoints[1])
    635             || (endpoints[1] == T->endpoints[2])
    636           ) && (
    637             (endpoints[2] == T->endpoints[0])
    638             || (endpoints[2] == T->endpoints[1])
    639             || (endpoints[2] == T->endpoints[2])
    640 
    641           ));
    642 };
     635  Info FunctionInfo(__func__);
     636  return (((endpoints[0] == T->endpoints[0]) || (endpoints[0] == T->endpoints[1]) || (endpoints[0] == T->endpoints[2])) && ((endpoints[1] == T->endpoints[0]) || (endpoints[1] == T->endpoints[1]) || (endpoints[1] == T->endpoints[2])) && ((endpoints[2] == T->endpoints[0]) || (endpoints[2] == T->endpoints[1]) || (endpoints[2] == T->endpoints[2])
     637
     638  ));
     639}
     640;
    643641
    644642/** Returns the endpoint which is not contained in the given \a *line.
     
    648646class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
    649647{
    650         Info FunctionInfo(__func__);
     648  Info FunctionInfo(__func__);
    651649  // sanity check
    652650  if (!ContainsBoundaryLine(line))
    653651    return NULL;
    654   for(int i=0;i<3;i++)
     652  for (int i = 0; i < 3; i++)
    655653    if (!line->ContainsBoundaryPoint(endpoints[i]))
    656654      return endpoints[i];
    657655  // actually, that' impossible :)
    658656  return NULL;
    659 };
     657}
     658;
    660659
    661660/** Calculates the center point of the triangle.
     
    665664void BoundaryTriangleSet::GetCenter(Vector * const center) const
    666665{
    667         Info FunctionInfo(__func__);
     666  Info FunctionInfo(__func__);
    668667  center->Zero();
    669   for(int i=0;i<3;i++)
     668  for (int i = 0; i < 3; i++)
    670669    center->AddVector(endpoints[i]->node->node);
    671   center->Scale(1./3.);
    672   Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl;
     670  center->Scale(1. / 3.);
     671  DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl);
    673672}
    674673
     
    680679{
    681680  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]";
    682 //  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
    683 //      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
     681  //  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
     682  //      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
    684683  return ost;
    685 };
     684}
     685;
    686686
    687687// ======================================== Polygons on Boundary =================================
     
    693693{
    694694  Info FunctionInfo(__func__);
    695 };
     695}
     696;
    696697
    697698/** Destructor of BoundaryPolygonSet.
     
    703704  Info FunctionInfo(__func__);
    704705  endpoints.clear();
    705   Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl;
    706 };
     706  DoLog(1) && (Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl);
     707}
     708;
    707709
    708710/** Calculates the normal vector for this triangle.
     
    718720  Vector *TotalNormal = new Vector;
    719721  PointSet::const_iterator Runner[3];
    720   for (int i=0;i<3; i++) {
     722  for (int i = 0; i < 3; i++) {
    721723    Runner[i] = endpoints.begin();
    722     for (int j = 0; j<i; j++) { // go as much further
     724    for (int j = 0; j < i; j++) { // go as much further
    723725      Runner[i]++;
    724726      if (Runner[i] == endpoints.end()) {
    725         eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl;
     727        DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
    726728        performCriticalExit();
    727729      }
     
    729731  }
    730732  TotalNormal->Zero();
    731   int counter=0;
    732   for (; Runner[2] != endpoints.end(); ) {
     733  int counter = 0;
     734  for (; Runner[2] != endpoints.end();) {
    733735    TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
    734     for (int i=0;i<3;i++) // increase each of them
     736    for (int i = 0; i < 3; i++) // increase each of them
    735737      Runner[i]++;
    736738    TotalNormal->AddVector(&TemporaryNormal);
    737739  }
    738   TotalNormal->Scale(1./(double)counter);
     740  TotalNormal->Scale(1. / (double) counter);
    739741
    740742  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    741743  if (TotalNormal->ScalarProduct(&OtherVector) > 0.)
    742744    TotalNormal->Scale(-1.);
    743   Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl;
     745  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
    744746
    745747  return TotalNormal;
    746 };
     748}
     749;
    747750
    748751/** Calculates the center point of the triangle.
     
    755758  center->Zero();
    756759  int counter = 0;
    757   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     760  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    758761    center->AddVector((*Runner)->node->node);
    759762    counter++;
    760763  }
    761   center->Scale(1./(double)counter);
    762   Log() << Verbose(1) << "Center is at " << *center << "." << endl;
     764  center->Scale(1. / (double) counter);
     765  DoLog(1) && (Log() << Verbose(1) << "Center is at " << *center << "." << endl);
    763766}
    764767
     
    771774  Info FunctionInfo(__func__);
    772775  return ContainsPresentTupel(triangle->endpoints, 3);
    773 };
     776}
     777;
    774778
    775779/** Checks whether the polygons contains both endpoints of the line.
     
    781785  Info FunctionInfo(__func__);
    782786  return ContainsPresentTupel(line->endpoints, 2);
    783 };
     787}
     788;
    784789
    785790/** Checks whether point is any of the three endpoints this triangle contains.
     
    790795{
    791796  Info FunctionInfo(__func__);
    792   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    793     Log() << Verbose(0) << "Checking against " << **Runner << endl;
     797  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     798    DoLog(0) && (Log() << Verbose(0) << "Checking against " << **Runner << endl);
    794799    if (point == (*Runner)) {
    795       Log() << Verbose(0) << " Contained." << endl;
     800      DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
    796801      return true;
    797802    }
    798803  }
    799   Log() << Verbose(0) << " Not contained." << endl;
     804  DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
    800805  return false;
    801 };
     806}
     807;
    802808
    803809/** Checks whether point is any of the three endpoints this triangle contains.
     
    808814{
    809815  Info FunctionInfo(__func__);
    810   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     816  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    811817    if (point == (*Runner)->node) {
    812       Log() << Verbose(0) << " Contained." << endl;
     818      DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
    813819      return true;
    814820    }
    815   Log() << Verbose(0) << " Not contained." << endl;
     821  DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
    816822  return false;
    817 };
     823}
     824;
    818825
    819826/** Checks whether given array of \a *Points coincide with polygons's endpoints.
     
    826833  Info FunctionInfo(__func__);
    827834  int counter = 0;
    828   Log() << Verbose(1) << "Polygon is " << *this << endl;
    829   for(int i=0;i<dim;i++) {
    830     Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl;
     835  DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
     836  for (int i = 0; i < dim; i++) {
     837    DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl);
    831838    if (ContainsBoundaryPoint(Points[i])) {
    832839      counter++;
     
    838845  else
    839846    return false;
    840 };
     847}
     848;
    841849
    842850/** Checks whether given PointList coincide with polygons's endpoints.
     
    848856  Info FunctionInfo(__func__);
    849857  size_t counter = 0;
    850   Log() << Verbose(1) << "Polygon is " << *this << endl;
    851   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    852     Log() << Verbose(1) << " Testing endpoint " << **Runner << endl;
     858  DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
     859  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     860    DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << **Runner << endl);
    853861    if (ContainsBoundaryPoint(*Runner))
    854862      counter++;
     
    859867  else
    860868    return false;
    861 };
     869}
     870;
    862871
    863872/** Checks whether given set of \a *Points coincide with polygons's endpoints.
     
    867876bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
    868877{
    869   return ContainsPresentTupel((const PointSet)P->endpoints);
    870 };
     878  return ContainsPresentTupel((const PointSet) P->endpoints);
     879}
     880;
    871881
    872882/** Gathers all the endpoints' triangles in a unique set.
     
    876886{
    877887  Info FunctionInfo(__func__);
    878   pair <TriangleSet::iterator, bool> Tester;
     888  pair<TriangleSet::iterator, bool> Tester;
    879889  TriangleSet *triangles = new TriangleSet;
    880890
    881   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    882     for(LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
    883       for(TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
     891  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     892    for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
     893      for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
    884894        //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
    885895        if (ContainsBoundaryTriangle(Sprinter->second)) {
    886896          Tester = triangles->insert(Sprinter->second);
    887897          if (Tester.second)
    888             Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl;
     898            DoLog(0) && (Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl);
    889899        }
    890900      }
    891901
    892   Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl;
     902  DoLog(1) && (Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl);
    893903  return triangles;
    894 };
     904}
     905;
    895906
    896907/** Fills the endpoints of this polygon from the triangles attached to \a *line.
     
    901912{
    902913  Info FunctionInfo(__func__);
    903   pair <PointSet::iterator, bool> Tester;
     914  pair<PointSet::iterator, bool> Tester;
    904915  if (line == NULL)
    905916    return false;
    906   Log() << Verbose(1) << "Filling polygon from line " << *line << endl;
    907   for(TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
    908     for (int i=0;i<3;i++) {
     917  DoLog(1) && (Log() << Verbose(1) << "Filling polygon from line " << *line << endl);
     918  for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
     919    for (int i = 0; i < 3; i++) {
    909920      Tester = endpoints.insert((Runner->second)->endpoints[i]);
    910921      if (Tester.second)
    911         Log() << Verbose(1) << "  Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl;
     922        DoLog(1) && (Log() << Verbose(1) << "  Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl);
    912923    }
    913924  }
    914925
    915926  return true;
    916 };
     927}
     928;
    917929
    918930/** output operator for BoundaryPolygonSet.
     
    923935{
    924936  ost << "[" << a.Nr << "|";
    925   for(PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
    926    ost << (*Runner)->node->Name;
    927    Runner++;
    928    if (Runner != a.endpoints.end())
    929      ost << ",";
    930   }
    931   ost<< "]";
     937  for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
     938    ost << (*Runner)->node->Name;
     939    Runner++;
     940    if (Runner != a.endpoints.end())
     941      ost << ",";
     942  }
     943  ost << "]";
    932944  return ost;
    933 };
     945}
     946;
    934947
    935948// =========================================================== class TESSELPOINT ===========================================
     
    942955  node = NULL;
    943956  nr = -1;
    944   Name =  NULL;
    945 };
     957  Name = NULL;
     958}
     959;
    946960
    947961/** Destructor for class TesselPoint.
     
    950964{
    951965  //Info FunctionInfo(__func__);
    952 };
     966}
     967;
    953968
    954969/** Prints LCNode to screen.
    955970 */
    956 ostream & operator << (ostream &ost, const TesselPoint &a)
     971ostream & operator <<(ostream &ost, const TesselPoint &a)
    957972{
    958973  ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]";
    959974  return ost;
    960 };
     975}
     976;
    961977
    962978/** Prints LCNode to screen.
    963979 */
    964 ostream & TesselPoint::operator << (ostream &ost)
    965 {
    966         Info FunctionInfo(__func__);
     980ostream & TesselPoint::operator <<(ostream &ost)
     981{
     982  Info FunctionInfo(__func__);
    967983  ost << "[" << (nr) << "|" << this << "]";
    968984  return ost;
    969 };
    970 
     985}
     986;
    971987
    972988// =========================================================== class POINTCLOUD ============================================
     
    976992PointCloud::PointCloud()
    977993{
    978         //Info FunctionInfo(__func__);
    979 };
     994  //Info FunctionInfo(__func__);
     995}
     996;
    980997
    981998/** Destructor for class PointCloud.
     
    9831000PointCloud::~PointCloud()
    9841001{
    985         //Info FunctionInfo(__func__);
    986 };
     1002  //Info FunctionInfo(__func__);
     1003}
     1004;
    9871005
    9881006// ============================ CandidateForTesselation =============================
     
    9901008/** Constructor of class CandidateForTesselation.
    9911009 */
    992 CandidateForTesselation::CandidateForTesselation (BoundaryLineSet* line) :
    993   BaseLine(line),
    994   ShortestAngle(2.*M_PI),
    995   OtherShortestAngle(2.*M_PI)
    996 {
    997         Info FunctionInfo(__func__);
    998 };
    999 
     1010CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
     1011  BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
     1012{
     1013  Info FunctionInfo(__func__);
     1014}
     1015;
    10001016
    10011017/** Constructor of class CandidateForTesselation.
    10021018 */
    1003 CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
    1004     BaseLine(line),
    1005     ShortestAngle(2.*M_PI),
    1006     OtherShortestAngle(2.*M_PI)
    1007 {
    1008         Info FunctionInfo(__func__);
     1019CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
     1020  BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
     1021{
     1022  Info FunctionInfo(__func__);
    10091023  OptCenter.CopyVector(&OptCandidateCenter);
    10101024  OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
    1011 };
     1025}
     1026;
    10121027
    10131028/** Destructor for class CandidateForTesselation.
    10141029 */
    1015 CandidateForTesselation::~CandidateForTesselation() {
    1016   BaseLine = NULL;
    1017 };
     1030CandidateForTesselation::~CandidateForTesselation()
     1031{
     1032}
     1033;
     1034
     1035/** Checks validity of a given sphere of a candidate line.
     1036 * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside.
     1037 * \param RADIUS radius of sphere
     1038 * \param *LC LinkedCell structure with other atoms
     1039 * \return true - sphere is valid, false - sphere contains other points
     1040 */
     1041bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
     1042{
     1043  Info FunctionInfo(__func__);
     1044
     1045  const double radiusSquared = RADIUS * RADIUS;
     1046  list<const Vector *> VectorList;
     1047  VectorList.push_back(&OptCenter);
     1048  //VectorList.push_back(&OtherOptCenter);  // don't check the other (wrong) center
     1049
     1050  if (!pointlist.empty())
     1051    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
     1052  else
     1053    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
     1054  // check baseline for OptCenter and OtherOptCenter being on sphere's surface
     1055  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1056    for (int i = 0; i < 2; i++) {
     1057      const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->node) - radiusSquared);
     1058      if (distance > HULLEPSILON) {
     1059        DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     1060        return false;
     1061      }
     1062    }
     1063  }
     1064
     1065  // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
     1066  for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
     1067    const TesselPoint *Walker = *Runner;
     1068    for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1069      const double distance = fabs((*VRunner)->DistanceSquared(Walker->node) - radiusSquared);
     1070      if (distance > HULLEPSILON) {
     1071        DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     1072        return false;
     1073      } else {
     1074        DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl);
     1075      }
     1076    }
     1077  }
     1078
     1079  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
     1080  bool flag = true;
     1081  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1082    // get all points inside the sphere
     1083    TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
     1084
     1085    DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl);
     1086    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     1087      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&OtherOptCenter) << "." << endl);
     1088
     1089    // remove baseline's endpoints and candidates
     1090    for (int i = 0; i < 2; i++) {
     1091      DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl);
     1092      ListofPoints->remove(BaseLine->endpoints[i]->node);
     1093    }
     1094    for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
     1095      DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl);
     1096      ListofPoints->remove(*Runner);
     1097    }
     1098    if (!ListofPoints->empty()) {
     1099      DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
     1100      flag = false;
     1101      DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
     1102      for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     1103        DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << endl);
     1104    }
     1105    delete (ListofPoints);
     1106
     1107    // check with animate_sphere.tcl VMD script
     1108    if (ThirdPoint != NULL) {
     1109      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl);
     1110    } else {
     1111      DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl);
     1112      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl);
     1113    }
     1114  }
     1115  return flag;
     1116}
     1117;
    10181118
    10191119/** output operator for CandidateForTesselation.
     
    10211121 * \param &a boundary line
    10221122 */
    1023 ostream & operator <<(ostream &ost, const  CandidateForTesselation &a)
     1123ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
    10241124{
    10251125  ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with ";
     
    10341134    for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
    10351135      ost << *(*Runner) << " ";
    1036     ost << " at angle " << (a.ShortestAngle)<< ".";
     1136    ost << " at angle " << (a.ShortestAngle) << ".";
    10371137  }
    10381138
    10391139  return ost;
    1040 };
    1041 
     1140}
     1141;
    10421142
    10431143// =========================================================== class TESSELATION ===========================================
     
    10461146 */
    10471147Tesselation::Tesselation() :
    1048   PointsOnBoundaryCount(0),
    1049   LinesOnBoundaryCount(0),
    1050   TrianglesOnBoundaryCount(0),
    1051   LastTriangle(NULL),
    1052   TriangleFilesWritten(0),
    1053   InternalPointer(PointsOnBoundary.begin())
    1054 {
    1055         Info FunctionInfo(__func__);
     1148  PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin())
     1149{
     1150  Info FunctionInfo(__func__);
    10561151}
    10571152;
     
    10621157Tesselation::~Tesselation()
    10631158{
    1064         Info FunctionInfo(__func__);
    1065   Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl;
     1159  Info FunctionInfo(__func__);
     1160  DoLog(0) && (Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl);
    10661161  for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
    10671162    if (runner->second != NULL) {
     
    10691164      runner->second = NULL;
    10701165    } else
    1071       eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl;
    1072   }
    1073   Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
     1166      DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);
     1167  }
     1168  DoLog(0) && (Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl);
    10741169}
    10751170;
     
    10771172/** PointCloud implementation of GetCenter
    10781173 * Uses PointsOnBoundary and STL stuff.
    1079  */   
     1174 */
    10801175Vector * Tesselation::GetCenter(ofstream *out) const
    10811176{
    1082         Info FunctionInfo(__func__);
    1083   Vector *Center = new Vector(0.,0.,0.);
    1084   int num=0;
     1177  Info FunctionInfo(__func__);
     1178  Vector *Center = new Vector(0., 0., 0.);
     1179  int num = 0;
    10851180  for (GoToFirst(); (!IsEnd()); GoToNext()) {
    10861181    Center->AddVector(GetPoint()->node);
    10871182    num++;
    10881183  }
    1089   Center->Scale(1./num);
     1184  Center->Scale(1. / num);
    10901185  return Center;
    1091 };
     1186}
     1187;
    10921188
    10931189/** PointCloud implementation of GoPoint
    10941190 * Uses PointsOnBoundary and STL stuff.
    1095  */   
     1191 */
    10961192TesselPoint * Tesselation::GetPoint() const
    10971193{
    1098         Info FunctionInfo(__func__);
     1194  Info FunctionInfo(__func__);
    10991195  return (InternalPointer->second->node);
    1100 };
     1196}
     1197;
    11011198
    11021199/** PointCloud implementation of GetTerminalPoint.
    11031200 * Uses PointsOnBoundary and STL stuff.
    1104  */   
     1201 */
    11051202TesselPoint * Tesselation::GetTerminalPoint() const
    11061203{
    1107         Info FunctionInfo(__func__);
     1204  Info FunctionInfo(__func__);
    11081205  PointMap::const_iterator Runner = PointsOnBoundary.end();
    11091206  Runner--;
    11101207  return (Runner->second->node);
    1111 };
     1208}
     1209;
    11121210
    11131211/** PointCloud implementation of GoToNext.
    11141212 * Uses PointsOnBoundary and STL stuff.
    1115  */   
     1213 */
    11161214void Tesselation::GoToNext() const
    11171215{
    1118         Info FunctionInfo(__func__);
     1216  Info FunctionInfo(__func__);
    11191217  if (InternalPointer != PointsOnBoundary.end())
    11201218    InternalPointer++;
    1121 };
     1219}
     1220;
    11221221
    11231222/** PointCloud implementation of GoToPrevious.
    11241223 * Uses PointsOnBoundary and STL stuff.
    1125  */   
     1224 */
    11261225void Tesselation::GoToPrevious() const
    11271226{
    1128         Info FunctionInfo(__func__);
     1227  Info FunctionInfo(__func__);
    11291228  if (InternalPointer != PointsOnBoundary.begin())
    11301229    InternalPointer--;
    1131 };
     1230}
     1231;
    11321232
    11331233/** PointCloud implementation of GoToFirst.
    11341234 * Uses PointsOnBoundary and STL stuff.
    1135  */   
     1235 */
    11361236void Tesselation::GoToFirst() const
    11371237{
    1138         Info FunctionInfo(__func__);
     1238  Info FunctionInfo(__func__);
    11391239  InternalPointer = PointsOnBoundary.begin();
    1140 };
     1240}
     1241;
    11411242
    11421243/** PointCloud implementation of GoToLast.
     
    11451246void Tesselation::GoToLast() const
    11461247{
    1147         Info FunctionInfo(__func__);
     1248  Info FunctionInfo(__func__);
    11481249  InternalPointer = PointsOnBoundary.end();
    11491250  InternalPointer--;
    1150 };
     1251}
     1252;
    11511253
    11521254/** PointCloud implementation of IsEmpty.
    11531255 * Uses PointsOnBoundary and STL stuff.
    1154  */   
     1256 */
    11551257bool Tesselation::IsEmpty() const
    11561258{
    1157         Info FunctionInfo(__func__);
     1259  Info FunctionInfo(__func__);
    11581260  return (PointsOnBoundary.empty());
    1159 };
     1261}
     1262;
    11601263
    11611264/** PointCloud implementation of IsLast.
    11621265 * Uses PointsOnBoundary and STL stuff.
    1163  */   
     1266 */
    11641267bool Tesselation::IsEnd() const
    11651268{
    1166         Info FunctionInfo(__func__);
     1269  Info FunctionInfo(__func__);
    11671270  return (InternalPointer == PointsOnBoundary.end());
    1168 };
    1169 
     1271}
     1272;
    11701273
    11711274/** Gueses first starting triangle of the convex envelope.
     
    11761279void Tesselation::GuessStartingTriangle()
    11771280{
    1178         Info FunctionInfo(__func__);
     1281  Info FunctionInfo(__func__);
    11791282  // 4b. create a starting triangle
    11801283  // 4b1. create all distances
     
    11861289
    11871290  // with A chosen, take each pair B,C and sort
    1188   if (A != PointsOnBoundary.end())
    1189     {
    1190       B = A;
    1191       B++;
    1192       for (; B != PointsOnBoundary.end(); B++)
    1193         {
    1194           C = B;
    1195           C++;
    1196           for (; C != PointsOnBoundary.end(); C++)
    1197             {
    1198               tmp = A->second->node->node->DistanceSquared(B->second->node->node);
    1199               distance = tmp * tmp;
    1200               tmp = A->second->node->node->DistanceSquared(C->second->node->node);
    1201               distance += tmp * tmp;
    1202               tmp = B->second->node->node->DistanceSquared(C->second->node->node);
    1203               distance += tmp * tmp;
    1204               DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
    1205             }
    1206         }
    1207     }
     1291  if (A != PointsOnBoundary.end()) {
     1292    B = A;
     1293    B++;
     1294    for (; B != PointsOnBoundary.end(); B++) {
     1295      C = B;
     1296      C++;
     1297      for (; C != PointsOnBoundary.end(); C++) {
     1298        tmp = A->second->node->node->DistanceSquared(B->second->node->node);
     1299        distance = tmp * tmp;
     1300        tmp = A->second->node->node->DistanceSquared(C->second->node->node);
     1301        distance += tmp * tmp;
     1302        tmp = B->second->node->node->DistanceSquared(C->second->node->node);
     1303        distance += tmp * tmp;
     1304        DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
     1305      }
     1306    }
     1307  }
    12081308  //    // listing distances
    12091309  //    Log() << Verbose(1) << "Listing DistanceMMap:";
     
    12151315  // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
    12161316  DistanceMultiMap::iterator baseline = DistanceMMap.begin();
    1217   for (; baseline != DistanceMMap.end(); baseline++)
    1218     {
    1219       // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
    1220       // 2. next, we have to check whether all points reside on only one side of the triangle
    1221       // 3. construct plane vector
    1222       PlaneVector.MakeNormalVector(A->second->node->node,
    1223           baseline->second.first->second->node->node,
    1224           baseline->second.second->second->node->node);
    1225       Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl;
    1226       // 4. loop over all points
    1227       double sign = 0.;
    1228       PointMap::iterator checker = PointsOnBoundary.begin();
    1229       for (; checker != PointsOnBoundary.end(); checker++)
    1230         {
    1231           // (neglecting A,B,C)
    1232           if ((checker == A) || (checker == baseline->second.first) || (checker
    1233               == baseline->second.second))
    1234             continue;
    1235           // 4a. project onto plane vector
    1236           TrialVector.CopyVector(checker->second->node->node);
    1237           TrialVector.SubtractVector(A->second->node->node);
    1238           distance = TrialVector.ScalarProduct(&PlaneVector);
    1239           if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    1240             continue;
    1241           Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl;
    1242           tmp = distance / fabs(distance);
    1243           // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
    1244           if ((sign != 0) && (tmp != sign))
    1245             {
    1246               // 4c. If so, break 4. loop and continue with next candidate in 1. loop
    1247               Log() << Verbose(2) << "Current candidates: "
    1248                   << A->second->node->Name << ","
    1249                   << baseline->second.first->second->node->Name << ","
    1250                   << baseline->second.second->second->node->Name << " leaves "
    1251                   << checker->second->node->Name << " outside the convex hull."
    1252                   << endl;
    1253               break;
    1254             }
    1255           else
    1256             { // note the sign for later
    1257               Log() << Verbose(2) << "Current candidates: "
    1258                   << A->second->node->Name << ","
    1259                   << baseline->second.first->second->node->Name << ","
    1260                   << baseline->second.second->second->node->Name << " leave "
    1261                   << checker->second->node->Name << " inside the convex hull."
    1262                   << endl;
    1263               sign = tmp;
    1264             }
    1265           // 4d. Check whether the point is inside the triangle (check distance to each node
    1266           tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
    1267           int innerpoint = 0;
    1268           if ((tmp < A->second->node->node->DistanceSquared(
    1269               baseline->second.first->second->node->node)) && (tmp
    1270               < A->second->node->node->DistanceSquared(
    1271                   baseline->second.second->second->node->node)))
    1272             innerpoint++;
    1273           tmp = checker->second->node->node->DistanceSquared(
    1274               baseline->second.first->second->node->node);
    1275           if ((tmp < baseline->second.first->second->node->node->DistanceSquared(
    1276               A->second->node->node)) && (tmp
    1277               < baseline->second.first->second->node->node->DistanceSquared(
    1278                   baseline->second.second->second->node->node)))
    1279             innerpoint++;
    1280           tmp = checker->second->node->node->DistanceSquared(
    1281               baseline->second.second->second->node->node);
    1282           if ((tmp < baseline->second.second->second->node->node->DistanceSquared(
    1283               baseline->second.first->second->node->node)) && (tmp
    1284               < baseline->second.second->second->node->node->DistanceSquared(
    1285                   A->second->node->node)))
    1286             innerpoint++;
    1287           // 4e. If so, break 4. loop and continue with next candidate in 1. loop
    1288           if (innerpoint == 3)
    1289             break;
    1290         }
    1291       // 5. come this far, all on same side? Then break 1. loop and construct triangle
    1292       if (checker == PointsOnBoundary.end())
    1293         {
    1294           Log() << Verbose(2) << "Looks like we have a candidate!" << endl;
    1295           break;
    1296         }
    1297     }
    1298   if (baseline != DistanceMMap.end())
    1299     {
    1300       BPS[0] = baseline->second.first->second;
    1301       BPS[1] = baseline->second.second->second;
    1302       BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1303       BPS[0] = A->second;
    1304       BPS[1] = baseline->second.second->second;
    1305       BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1306       BPS[0] = baseline->second.first->second;
    1307       BPS[1] = A->second;
    1308       BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1309 
    1310       // 4b3. insert created triangle
    1311       BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    1312       TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    1313       TrianglesOnBoundaryCount++;
    1314       for (int i = 0; i < NDIM; i++)
    1315         {
    1316           LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
    1317           LinesOnBoundaryCount++;
    1318         }
    1319 
    1320       Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl;
    1321     }
    1322   else
    1323     {
    1324       eLog() << Verbose(0) << "No starting triangle found." << endl;
    1325     }
     1317  for (; baseline != DistanceMMap.end(); baseline++) {
     1318    // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
     1319    // 2. next, we have to check whether all points reside on only one side of the triangle
     1320    // 3. construct plane vector
     1321    PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node);
     1322    DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl);
     1323    // 4. loop over all points
     1324    double sign = 0.;
     1325    PointMap::iterator checker = PointsOnBoundary.begin();
     1326    for (; checker != PointsOnBoundary.end(); checker++) {
     1327      // (neglecting A,B,C)
     1328      if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
     1329        continue;
     1330      // 4a. project onto plane vector
     1331      TrialVector.CopyVector(checker->second->node->node);
     1332      TrialVector.SubtractVector(A->second->node->node);
     1333      distance = TrialVector.ScalarProduct(&PlaneVector);
     1334      if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
     1335        continue;
     1336      DoLog(2) && (Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl);
     1337      tmp = distance / fabs(distance);
     1338      // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
     1339      if ((sign != 0) && (tmp != sign)) {
     1340        // 4c. If so, break 4. loop and continue with next candidate in 1. loop
     1341        DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leaves " << checker->second->node->Name << " outside the convex hull." << endl);
     1342        break;
     1343      } else { // note the sign for later
     1344        DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leave " << checker->second->node->Name << " inside the convex hull." << endl);
     1345        sign = tmp;
     1346      }
     1347      // 4d. Check whether the point is inside the triangle (check distance to each node
     1348      tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
     1349      int innerpoint = 0;
     1350      if ((tmp < A->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))
     1351        innerpoint++;
     1352      tmp = checker->second->node->node->DistanceSquared(baseline->second.first->second->node->node);
     1353      if ((tmp < baseline->second.first->second->node->node->DistanceSquared(A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))
     1354        innerpoint++;
     1355      tmp = checker->second->node->node->DistanceSquared(baseline->second.second->second->node->node);
     1356      if ((tmp < baseline->second.second->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(A->second->node->node)))
     1357        innerpoint++;
     1358      // 4e. If so, break 4. loop and continue with next candidate in 1. loop
     1359      if (innerpoint == 3)
     1360        break;
     1361    }
     1362    // 5. come this far, all on same side? Then break 1. loop and construct triangle
     1363    if (checker == PointsOnBoundary.end()) {
     1364      DoLog(2) && (Log() << Verbose(2) << "Looks like we have a candidate!" << endl);
     1365      break;
     1366    }
     1367  }
     1368  if (baseline != DistanceMMap.end()) {
     1369    BPS[0] = baseline->second.first->second;
     1370    BPS[1] = baseline->second.second->second;
     1371    BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1372    BPS[0] = A->second;
     1373    BPS[1] = baseline->second.second->second;
     1374    BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1375    BPS[0] = baseline->second.first->second;
     1376    BPS[1] = A->second;
     1377    BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1378
     1379    // 4b3. insert created triangle
     1380    BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     1381    TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
     1382    TrianglesOnBoundaryCount++;
     1383    for (int i = 0; i < NDIM; i++) {
     1384      LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
     1385      LinesOnBoundaryCount++;
     1386    }
     1387
     1388    DoLog(1) && (Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl);
     1389  } else {
     1390    DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl);
     1391  }
    13261392}
    13271393;
     
    13421408void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
    13431409{
    1344         Info FunctionInfo(__func__);
     1410  Info FunctionInfo(__func__);
    13451411  bool flag;
    13461412  PointMap::iterator winner;
     
    13611427        // get peak point with respect to this base line's only triangle
    13621428        BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
    1363         Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl;
     1429        DoLog(0) && (Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl);
    13641430        for (int i = 0; i < 3; i++)
    13651431          if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
    13661432            peak = BTS->endpoints[i];
    1367         Log() << Verbose(1) << " and has peak " << *peak << "." << endl;
     1433        DoLog(1) && (Log() << Verbose(1) << " and has peak " << *peak << "." << endl);
    13681434
    13691435        // prepare some auxiliary vectors
     
    13801446          CenterVector.AddVector(BTS->endpoints[i]->node->node);
    13811447        CenterVector.Scale(1. / 3.);
    1382         Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl;
     1448        DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
    13831449
    13841450        // normal vector of triangle
     
    13871453        BTS->GetNormalVector(NormalVector);
    13881454        NormalVector.CopyVector(&BTS->NormalVector);
    1389         Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl;
     1455        DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl);
    13901456
    13911457        // vector in propagation direction (out of triangle)
     
    13971463        if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
    13981464          PropagationVector.Scale(-1.);
    1399         Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl;
     1465        DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl);
    14001466        winner = PointsOnBoundary.end();
    14011467
     
    14031469        for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
    14041470          if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
    1405             Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl;
     1471            DoLog(1) && (Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl);
    14061472
    14071473            // first check direction, so that triangles don't intersect
     
    14101476            VirtualNormalVector.ProjectOntoPlane(&NormalVector);
    14111477            TempAngle = VirtualNormalVector.Angle(&PropagationVector);
    1412             Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
    1413             if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees)
    1414               Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
     1478            DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl);
     1479            if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
     1480              DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl);
    14151481              continue;
    14161482            } else
    1417               Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
     1483              DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl);
    14181484
    14191485            // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
     
    14211487            LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
    14221488            if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
    1423               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;
     1489              DoLog(2) && (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);
    14241490              continue;
    14251491            }
    14261492            if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
    1427               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;
     1493              DoLog(2) && (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);
    14281494              continue;
    14291495            }
     
    14311497            // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
    14321498            if ((((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (GetCommonEndpoint(LineChecker[0]->second, LineChecker[1]->second) == peak)))) {
    1433               Log() << Verbose(4) << "Current target is peak!" << endl;
     1499              DoLog(4) && (Log() << Verbose(4) << "Current target is peak!" << endl);
    14341500              continue;
    14351501            }
     
    14421508            helper.ProjectOntoPlane(&TempVector);
    14431509            if (fabs(helper.NormSquared()) < MYEPSILON) {
    1444               Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl;
     1510              DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl);
    14451511              continue;
    14461512            }
     
    14521518            TempVector.AddVector(baseline->second->endpoints[1]->node->node);
    14531519            TempVector.AddVector(target->second->node->node);
    1454             TempVector.Scale(1./3.);
     1520            TempVector.Scale(1. / 3.);
    14551521            TempVector.SubtractVector(Center);
    14561522            // make it always point outward
     
    14591525            // calculate angle
    14601526            TempAngle = NormalVector.Angle(&VirtualNormalVector);
    1461             Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
     1527            DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl);
    14621528            if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
    14631529              SmallestAngle = TempAngle;
    14641530              winner = target;
    1465               Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1531              DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
    14661532            } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
    14671533              // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
     
    14811547                SmallestAngle = TempAngle;
    14821548                winner = target;
    1483                 Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
     1549                DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl);
    14841550              } else
    1485                 Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
     1551                DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl);
    14861552            } else
    1487               Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1553              DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
    14881554          }
    14891555        } // end of loop over all boundary points
     
    14911557        // 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
    14921558        if (winner != PointsOnBoundary.end()) {
    1493           Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
     1559          DoLog(0) && (Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl);
    14941560          // create the lins of not yet present
    14951561          BLS[0] = baseline->second;
     
    15211587          TrianglesOnBoundaryCount++;
    15221588        } else {
    1523           eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
     1589          DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);
    15241590        }
    15251591
    15261592        // 5d. If the set of lines is not yet empty, go to 5. and continue
    15271593      } else
    1528         Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
     1594        DoLog(0) && (Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl);
    15291595  } while (flag);
    15301596
    15311597  // exit
    1532   delete(Center);
    1533 };
     1598  delete (Center);
     1599}
     1600;
    15341601
    15351602/** Inserts all points outside of the tesselated surface into it by adding new triangles.
     
    15411608bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
    15421609{
    1543         Info FunctionInfo(__func__);
     1610  Info FunctionInfo(__func__);
    15441611  Vector Intersection, Normal;
    15451612  TesselPoint *Walker = NULL;
     
    15511618  cloud->GoToFirst();
    15521619  BoundaryPoints = new LinkedCell(this, 5.);
    1553   while (!cloud->IsEnd()) {  // we only have to go once through all points, as boundary can become only bigger
     1620  while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
    15541621    if (AddFlag) {
    1555       delete(BoundaryPoints);
     1622      delete (BoundaryPoints);
    15561623      BoundaryPoints = new LinkedCell(this, 5.);
    15571624      AddFlag = false;
    15581625    }
    15591626    Walker = cloud->GetPoint();
    1560     Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;
     1627    DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Walker << "." << endl);
    15611628    // get the next triangle
    15621629    triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
    15631630    BTS = triangles->front();
    15641631    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
    1565       Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl;
     1632      DoLog(0) && (Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl);
    15661633      cloud->GoToNext();
    15671634      continue;
    15681635    } else {
    15691636    }
    1570     Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl;
     1637    DoLog(0) && (Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl);
    15711638    // get the intersection point
    15721639    if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
    1573       Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl;
     1640      DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl);
    15741641      // we have the intersection, check whether in- or outside of boundary
    15751642      if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
    15761643        // inside, next!
    1577         Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
     1644        DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl);
    15781645      } else {
    15791646        // outside!
    1580         Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
     1647        DoLog(0) && (Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl);
    15811648        class BoundaryLineSet *OldLines[3], *NewLines[3];
    15821649        class BoundaryPointSet *OldPoints[3], *NewPoint;
    15831650        // store the three old lines and old points
    1584         for (int i=0;i<3;i++) {
     1651        for (int i = 0; i < 3; i++) {
    15851652          OldLines[i] = BTS->lines[i];
    15861653          OldPoints[i] = BTS->endpoints[i];
     
    15881655        Normal.CopyVector(&BTS->NormalVector);
    15891656        // add Walker to boundary points
    1590         Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl;
     1657        DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl);
    15911658        AddFlag = true;
    1592         if (AddBoundaryPoint(Walker,0))
     1659        if (AddBoundaryPoint(Walker, 0))
    15931660          NewPoint = BPS[0];
    15941661        else
    15951662          continue;
    15961663        // remove triangle
    1597         Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl;
     1664        DoLog(0) && (Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl);
    15981665        TrianglesOnBoundary.erase(BTS->Nr);
    1599         delete(BTS);
     1666        delete (BTS);
    16001667        // create three new boundary lines
    1601         for (int i=0;i<3;i++) {
     1668        for (int i = 0; i < 3; i++) {
    16021669          BPS[0] = NewPoint;
    16031670          BPS[1] = OldPoints[i];
    16041671          NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1605           Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl;
     1672          DoLog(1) && (Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl);
    16061673          LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
    16071674          LinesOnBoundaryCount++;
    16081675        }
    16091676        // create three new triangle with new point
    1610         for (int i=0;i<3;i++) { // find all baselines
     1677        for (int i = 0; i < 3; i++) { // find all baselines
    16111678          BLS[0] = OldLines[i];
    16121679          int n = 1;
    1613           for (int j=0;j<3;j++) {
     1680          for (int j = 0; j < 3; j++) {
    16141681            if (NewLines[j]->IsConnectedTo(BLS[0])) {
    1615               if (n>2) {
    1616                 eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl;
     1682              if (n > 2) {
     1683                DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);
    16171684                return false;
    16181685              } else
     
    16251692          BTS->GetNormalVector(Normal);
    16261693          Normal.Scale(-1.);
    1627           Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl;
     1694          DoLog(0) && (Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl);
    16281695          TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    16291696          TrianglesOnBoundaryCount++;
     
    16311698      }
    16321699    } else { // something is wrong with FindClosestTriangleToPoint!
    1633       eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl;
     1700      DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl);
    16341701      return false;
    16351702    }
     
    16381705
    16391706  // exit
    1640   delete(Center);
     1707  delete (Center);
    16411708  return true;
    1642 };
     1709}
     1710;
    16431711
    16441712/** Adds a point to the tesselation::PointsOnBoundary list.
     
    16491717bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
    16501718{
    1651         Info FunctionInfo(__func__);
     1719  Info FunctionInfo(__func__);
    16521720  PointTestPair InsertUnique;
    16531721  BPS[n] = new class BoundaryPointSet(Walker);
     
    16571725    return true;
    16581726  } else {
    1659     delete(BPS[n]);
     1727    delete (BPS[n]);
    16601728    BPS[n] = InsertUnique.first->second;
    16611729    return false;
     
    16711739void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
    16721740{
    1673         Info FunctionInfo(__func__);
     1741  Info FunctionInfo(__func__);
    16741742  PointTestPair InsertUnique;
    16751743  TPS[n] = new class BoundaryPointSet(Candidate);
     
    16791747  } else {
    16801748    delete TPS[n];
    1681     Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
     1749    DoLog(0) && (Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl);
    16821750    TPS[n] = (InsertUnique.first)->second;
    16831751  }
     
    16921760void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
    16931761{
    1694         Info FunctionInfo(__func__);
     1762  Info FunctionInfo(__func__);
    16951763  PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
    16961764  if (FindPoint != PointsOnBoundary.end())
     
    16981766  else
    16991767    TPS[n] = NULL;
    1700 };
     1768}
     1769;
    17011770
    17021771/** Function tries to add line from current Points in BPS to BoundaryLineSet.
    17031772 * If successful it raises the line count and inserts the new line into the BLS,
    17041773 * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
     1774 * @param *OptCenter desired OptCenter if there are more than one candidate line
     1775 * @param *candidate third point of the triangle to be, for checking between multiple open line candidates
    17051776 * @param *a first endpoint
    17061777 * @param *b second endpoint
    17071778 * @param n index of Tesselation::BLS giving the line with both endpoints
    17081779 */
    1709 void Tesselation::AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) {
     1780void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     1781{
    17101782  bool insertNewLine = true;
    1711 
    17121783  LineMap::iterator FindLine = a->lines.find(b->node->nr);
     1784  BoundaryLineSet *WinningLine = NULL;
    17131785  if (FindLine != a->lines.end()) {
    1714     Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
    1715 
    1716     pair<LineMap::iterator,LineMap::iterator> FindPair;
     1786    DoLog(1) && (Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl);
     1787
     1788    pair<LineMap::iterator, LineMap::iterator> FindPair;
    17171789    FindPair = a->lines.equal_range(b->node->nr);
    17181790
    1719     for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     1791    for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) {
     1792      DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
    17201793      // If there is a line with less than two attached triangles, we don't need a new line.
    1721       if (FindLine->second->triangles.size() < 2) {
    1722         insertNewLine = false;
    1723         Log() << Verbose(0) << "Using existing line " << *FindLine->second << endl;
    1724 
    1725         BPS[0] = FindLine->second->endpoints[0];
    1726         BPS[1] = FindLine->second->endpoints[1];
    1727         BLS[n] = FindLine->second;
    1728 
    1729         // remove existing line from OpenLines
    1730         CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
    1731         if (CandidateLine != OpenLines.end()) {
    1732           Log() << Verbose(1) << " Removing line from OpenLines." << endl;
    1733           delete(CandidateLine->second);
    1734           OpenLines.erase(CandidateLine);
    1735         } else {
    1736           eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl;
     1794      if (FindLine->second->triangles.size() == 1) {
     1795        CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
     1796        if (!Finder->second->pointlist.empty())
     1797          DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
     1798        else
     1799          DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl);
     1800        // get open line
     1801        for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
     1802          if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(&Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
     1803            DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl);
     1804            insertNewLine = false;
     1805            WinningLine = FindLine->second;
     1806            break;
     1807          } else {
     1808            DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *(*CandidateChecker) << "'s center " << Finder->second->OptCenter << " does not match desired on " << *OptCenter << "." << endl);
     1809          }
    17371810        }
    1738 
    1739         break;
    17401811      }
    17411812    }
     
    17431814
    17441815  if (insertNewLine) {
    1745     AlwaysAddTesselationTriangleLine(a, b, n);
     1816    AddNewTesselationTriangleLine(a, b, n);
     1817  } else {
     1818    AddExistingTesselationTriangleLine(WinningLine, n);
    17461819  }
    17471820}
     
    17561829 * @param n index of Tesselation::BLS giving the line with both endpoints
    17571830 */
    1758 void Tesselation::AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
    1759 {
    1760         Info FunctionInfo(__func__);
    1761   Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
     1831void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     1832{
     1833  Info FunctionInfo(__func__);
     1834  DoLog(0) && (Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl);
    17621835  BPS[0] = a;
    17631836  BPS[1] = b;
    1764   BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);  // this also adds the line to the local maps
     1837  BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
    17651838  // add line to global map
    17661839  LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
     
    17691842  // also add to open lines
    17701843  CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
    1771   OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
    1772 };
     1844  OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
     1845}
     1846;
     1847
     1848/** Uses an existing line for a new triangle.
     1849 * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines.
     1850 * \param *FindLine the line to add
     1851 * \param n index of the line to set in Tesselation::BLS
     1852 */
     1853void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n)
     1854{
     1855  Info FunctionInfo(__func__);
     1856  DoLog(0) && (Log() << Verbose(0) << "Using existing line " << *Line << endl);
     1857
     1858  // set endpoints and line
     1859  BPS[0] = Line->endpoints[0];
     1860  BPS[1] = Line->endpoints[1];
     1861  BLS[n] = Line;
     1862  // remove existing line from OpenLines
     1863  CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
     1864  if (CandidateLine != OpenLines.end()) {
     1865    DoLog(1) && (Log() << Verbose(1) << " Removing line from OpenLines." << endl);
     1866    delete (CandidateLine->second);
     1867    OpenLines.erase(CandidateLine);
     1868  } else {
     1869    DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
     1870  }
     1871}
     1872;
    17731873
    17741874/** Function adds triangle to global list.
     
    17771877void Tesselation::AddTesselationTriangle()
    17781878{
    1779         Info FunctionInfo(__func__);
    1780   Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1879  Info FunctionInfo(__func__);
     1880  DoLog(1) && (Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl);
    17811881
    17821882  // add triangle to global map
     
    17881888
    17891889  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
    1790 };
     1890}
     1891;
    17911892
    17921893/** Function adds triangle to global list.
     
    17961897void Tesselation::AddTesselationTriangle(const int nr)
    17971898{
    1798         Info FunctionInfo(__func__);
    1799   Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1899  Info FunctionInfo(__func__);
     1900  DoLog(0) && (Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl);
    18001901
    18011902  // add triangle to global map
     
    18061907
    18071908  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
    1808 };
     1909}
     1910;
    18091911
    18101912/** Removes a triangle from the tesselation.
     
    18151917void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
    18161918{
    1817         Info FunctionInfo(__func__);
     1919  Info FunctionInfo(__func__);
    18181920  if (triangle == NULL)
    18191921    return;
    18201922  for (int i = 0; i < 3; i++) {
    18211923    if (triangle->lines[i] != NULL) {
    1822       Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
     1924      DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl);
    18231925      triangle->lines[i]->triangles.erase(triangle->Nr);
    18241926      if (triangle->lines[i]->triangles.empty()) {
    1825           Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
    1826           RemoveTesselationLine(triangle->lines[i]);
     1927        DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl);
     1928        RemoveTesselationLine(triangle->lines[i]);
    18271929      } else {
    1828         Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ";
    1829         OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
    1830         for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
    1831           Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
    1832         Log() << Verbose(0) << endl;
    1833 //        for (int j=0;j<2;j++) {
    1834 //          Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
    1835 //          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
    1836 //            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
    1837 //          Log() << Verbose(0) << endl;
    1838 //        }
     1930        DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ");
     1931        OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
     1932        for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
     1933          DoLog(0) && (Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t");
     1934        DoLog(0) && (Log() << Verbose(0) << endl);
     1935        //        for (int j=0;j<2;j++) {
     1936        //          Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
     1937        //          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
     1938        //            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
     1939        //          Log() << Verbose(0) << endl;
     1940        //        }
    18391941      }
    1840       triangle->lines[i] = NULL;  // free'd or not: disconnect
     1942      triangle->lines[i] = NULL; // free'd or not: disconnect
    18411943    } else
    1842       eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl;
     1944      DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl);
    18431945  }
    18441946
    18451947  if (TrianglesOnBoundary.erase(triangle->Nr))
    1846     Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
    1847   delete(triangle);
    1848 };
     1948    DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl);
     1949  delete (triangle);
     1950}
     1951;
    18491952
    18501953/** Removes a line from the tesselation.
     
    18541957void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
    18551958{
    1856         Info FunctionInfo(__func__);
     1959  Info FunctionInfo(__func__);
    18571960  int Numbers[2];
    18581961
     
    18751978        for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
    18761979          if ((*Runner).second == line) {
    1877             Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     1980            DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
    18781981            line->endpoints[i]->lines.erase(Runner);
    18791982            break;
     
    18811984      } else { // there's just a single line left
    18821985        if (line->endpoints[i]->lines.erase(line->Nr))
    1883           Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     1986          DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
    18841987      }
    18851988      if (line->endpoints[i]->lines.empty()) {
    1886         Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
     1989        DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl);
    18871990        RemoveTesselationPoint(line->endpoints[i]);
    18881991      } else {
    1889         Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ";
    1890         for(LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
    1891           Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
    1892         Log() << Verbose(0) << endl;
     1992        DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ");
     1993        for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
     1994          DoLog(0) && (Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t");
     1995        DoLog(0) && (Log() << Verbose(0) << endl);
    18931996      }
    1894       line->endpoints[i] = NULL;  // free'd or not: disconnect
     1997      line->endpoints[i] = NULL; // free'd or not: disconnect
    18951998    } else
    1896       eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl;
     1999      DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);
    18972000  }
    18982001  if (!line->triangles.empty())
    1899     eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl;
     2002    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);
    19002003
    19012004  if (LinesOnBoundary.erase(line->Nr))
    1902     Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl;
    1903   delete(line);
    1904 };
     2005    DoLog(0) && (Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl);
     2006  delete (line);
     2007}
     2008;
    19052009
    19062010/** Removes a point from the tesselation.
     
    19112015void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
    19122016{
    1913         Info FunctionInfo(__func__);
     2017  Info FunctionInfo(__func__);
    19142018  if (point == NULL)
    19152019    return;
    19162020  if (PointsOnBoundary.erase(point->Nr))
    1917     Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl;
    1918   delete(point);
    1919 };
     2021    DoLog(0) && (Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl);
     2022  delete (point);
     2023}
     2024;
     2025
     2026/** Checks validity of a given sphere of a candidate line.
     2027 * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
     2028 * We check CandidateForTesselation::OtherOptCenter
     2029 * \param &CandidateLine contains other degenerated candidates which we have to subtract as well
     2030 * \param RADIUS radius of sphere
     2031 * \param *LC LinkedCell structure with other atoms
     2032 * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
     2033 */
     2034bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const
     2035{
     2036  Info FunctionInfo(__func__);
     2037
     2038  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
     2039  bool flag = true;
     2040
     2041  DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter.x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl);
     2042  // get all points inside the sphere
     2043  TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
     2044
     2045  DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
     2046  for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     2047    DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl);
     2048
     2049  // remove triangles's endpoints
     2050  for (int i = 0; i < 2; i++)
     2051    ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node);
     2052
     2053  // remove other candidates
     2054  for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner)
     2055    ListofPoints->remove(*Runner);
     2056
     2057  // check for other points
     2058  if (!ListofPoints->empty()) {
     2059    DoLog(1) && (Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
     2060    flag = false;
     2061    DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
     2062    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     2063      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl);
     2064  }
     2065  delete (ListofPoints);
     2066
     2067  return flag;
     2068}
     2069;
    19202070
    19212071/** Checks whether the triangle consisting of the three points is already present.
     
    19302080int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
    19312081{
    1932         Info FunctionInfo(__func__);
     2082  Info FunctionInfo(__func__);
    19332083  int adjacentTriangleCount = 0;
    19342084  class BoundaryPointSet *Points[3];
     
    19522102          for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
    19532103            TriangleMap *triangles = &FindLine->second->triangles;
    1954             Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
     2104            DoLog(1) && (Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl);
    19552105            for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
    19562106              if (FindTriangle->second->IsPresentTupel(Points)) {
     
    19582108              }
    19592109            }
    1960             Log() << Verbose(1) << "end." << endl;
     2110            DoLog(1) && (Log() << Verbose(1) << "end." << endl);
    19612111          }
    19622112          // Only one of the triangle lines must be considered for the triangle count.
     
    19682118  }
    19692119
    1970   Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     2120  DoLog(0) && (Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl);
    19712121  return adjacentTriangleCount;
    1972 };
     2122}
     2123;
    19732124
    19742125/** Checks whether the triangle consisting of the three points is already present.
     
    19822133class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
    19832134{
    1984         Info FunctionInfo(__func__);
     2135  Info FunctionInfo(__func__);
    19852136  class BoundaryTriangleSet *triangle = NULL;
    19862137  class BoundaryPointSet *Points[3];
     
    20202171
    20212172  return triangle;
    2022 };
    2023 
     2173}
     2174;
    20242175
    20252176/** Finds the starting triangle for FindNonConvexBorder().
     
    20302181 * \param RADIUS radius of virtual rolling sphere
    20312182 * \param *LC LinkedCell structure with neighbouring TesselPoint's
    2032  */
    2033 void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
    2034 {
    2035         Info FunctionInfo(__func__);
     2183 * \return true - a starting triangle has been created, false - no valid triple of points found
     2184 */
     2185bool Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
     2186{
     2187  Info FunctionInfo(__func__);
    20362188  int i = 0;
    20372189  TesselPoint* MaxPoint[NDIM];
    20382190  TesselPoint* Temporary;
    20392191  double maxCoordinate[NDIM];
    2040   BoundaryLineSet BaseLine;
     2192  BoundaryLineSet *BaseLine = NULL;
    20412193  Vector helper;
    20422194  Vector Chord;
    20432195  Vector SearchDirection;
    2044   Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     2196  Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
    20452197  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
    20462198  Vector SphereCenter;
     
    20552207
    20562208  // 1. searching topmost point with respect to each axis
    2057   for (int i=0;i<NDIM;i++) { // each axis
    2058     LC->n[i] = LC->N[i]-1; // current axis is topmost cell
    2059     for (LC->n[(i+1)%NDIM]=0;LC->n[(i+1)%NDIM]<LC->N[(i+1)%NDIM];LC->n[(i+1)%NDIM]++)
    2060       for (LC->n[(i+2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {
    2061         const LinkedNodes *List = LC->GetCurrentCell();
     2209  for (int i = 0; i < NDIM; i++) { // each axis
     2210    LC->n[i] = LC->N[i] - 1; // current axis is topmost cell
     2211    for (LC->n[(i + 1) % NDIM] = 0; LC->n[(i + 1) % NDIM] < LC->N[(i + 1) % NDIM]; LC->n[(i + 1) % NDIM]++)
     2212      for (LC->n[(i + 2) % NDIM] = 0; LC->n[(i + 2) % NDIM] < LC->N[(i + 2) % NDIM]; LC->n[(i + 2) % NDIM]++) {
     2213        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    20622214        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    20632215        if (List != NULL) {
    2064           for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
     2216          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    20652217            if ((*Runner)->node->x[i] > maxCoordinate[i]) {
    2066               Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
     2218              DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl);
    20672219              maxCoordinate[i] = (*Runner)->node->x[i];
    20682220              MaxPoint[i] = (*Runner);
     
    20702222          }
    20712223        } else {
    2072           eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
     2224          DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
    20732225        }
    20742226      }
    20752227  }
    20762228
    2077   Log() << Verbose(1) << "Found maximum coordinates: ";
    2078   for (int i=0;i<NDIM;i++)
    2079     Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t";
    2080   Log() << Verbose(0) << endl;
     2229  DoLog(1) && (Log() << Verbose(1) << "Found maximum coordinates: ");
     2230  for (int i = 0; i < NDIM; i++)
     2231    DoLog(0) && (Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t");
     2232  DoLog(0) && (Log() << Verbose(0) << endl);
    20812233
    20822234  BTS = NULL;
    2083   for (int k=0;k<NDIM;k++) {
     2235  for (int k = 0; k < NDIM; k++) {
    20842236    NormalVector.Zero();
    20852237    NormalVector.x[k] = 1.;
    2086     BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
    2087     Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
     2238    BaseLine = new BoundaryLineSet();
     2239    BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
     2240    DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
    20882241
    20892242    double ShortestAngle;
    20902243    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.
    20912244
    2092     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_...
    2093     if (Temporary == NULL)  // have we found a second point?
     2245    Temporary = NULL;
     2246    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_...
     2247    if (Temporary == NULL) {
     2248      // have we found a second point?
     2249      delete BaseLine;
    20942250      continue;
    2095     BaseLine.endpoints[1] = new BoundaryPointSet(Temporary);
     2251    }
     2252    BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
    20962253
    20972254    // construct center of circle
    2098     CircleCenter.CopyVector(BaseLine.endpoints[0]->node->node);
    2099     CircleCenter.AddVector(BaseLine.endpoints[1]->node->node);
     2255    CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node);
     2256    CircleCenter.AddVector(BaseLine->endpoints[1]->node->node);
    21002257    CircleCenter.Scale(0.5);
    21012258
    21022259    // construct normal vector of circle
    2103     CirclePlaneNormal.CopyVector(BaseLine.endpoints[0]->node->node);
    2104     CirclePlaneNormal.SubtractVector(BaseLine.endpoints[1]->node->node);
     2260    CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node);
     2261    CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
    21052262
    21062263    double radius = CirclePlaneNormal.NormSquared();
    2107     double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
     2264    double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
    21082265
    21092266    NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
    21102267    NormalVector.Normalize();
    2111     ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
     2268    ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
    21122269
    21132270    SphereCenter.CopyVector(&NormalVector);
     
    21172274
    21182275    // look in one direction of baseline for initial candidate
    2119     SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector);  // whether we look "left" first or "right" first is not important ...
     2276    SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ...
    21202277
    21212278    // adding point 1 and point 2 and add the line between them
    2122     Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
    2123     Log() << Verbose(0) << "Found second point is at " << *BaseLine.endpoints[1]->node << ".\n";
     2279    DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
     2280    DoLog(0) && (Log() << Verbose(0) << "Found second point is at " << *BaseLine->endpoints[1]->node << ".\n");
    21242281
    21252282    //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
    2126     CandidateForTesselation OptCandidates(&BaseLine);
     2283    CandidateForTesselation OptCandidates(BaseLine);
    21272284    FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
    2128     Log() << Verbose(0) << "List of third Points is:" << endl;
     2285    DoLog(0) && (Log() << Verbose(0) << "List of third Points is:" << endl);
    21292286    for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
    2130         Log() << Verbose(0) << " " << *(*it) << endl;
    2131     }
    2132 
    2133     BTS = NULL;
    2134     AddCandidateTriangle(OptCandidates);
    2135 //    delete(BaseLine.endpoints[0]);
    2136 //    delete(BaseLine.endpoints[1]);
    2137 
    2138     if (BTS != NULL) // we have created one starting triangle
     2287      DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
     2288    }
     2289    if (!OptCandidates.pointlist.empty()) {
     2290      BTS = NULL;
     2291      AddCandidatePolygon(OptCandidates, RADIUS, LC);
     2292    } else {
     2293      delete BaseLine;
     2294      continue;
     2295    }
     2296
     2297    if (BTS != NULL) { // we have created one starting triangle
     2298      delete BaseLine;
    21392299      break;
    2140     else {
     2300    } else {
    21412301      // remove all candidates from the list and then the list itself
    21422302      OptCandidates.pointlist.clear();
    21432303    }
    2144   }
    2145 };
     2304    delete BaseLine;
     2305  }
     2306
     2307  return (BTS != NULL);
     2308}
     2309;
    21462310
    21472311/** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
     
    22142378//            if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    22152379//              // rotated the wrong way!
    2216 //              eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     2380//              DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
    22172381//            }
    22182382//
     
    22712435//          }
    22722436//        } else {
    2273 //          eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;
     2437//          DoeLog(2) && (eLog()<< Verbose(2) << "Baseline is connected to two triangles already?" << endl);
    22742438//        }
    22752439//      } else {
     
    22782442//    }
    22792443//  } else {
    2280 //    eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;
     2444//    DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl);
    22812445//  }
    22822446//
     
    22922456 * @param *LC LinkedCell structure with neighbouring points
    22932457 */
    2294 bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
    2295 {
    2296         Info FunctionInfo(__func__);
    2297   bool result = true;
    2298 
     2458bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
     2459{
     2460  Info FunctionInfo(__func__);
    22992461  Vector CircleCenter;
    23002462  Vector CirclePlaneNormal;
     
    23022464  Vector SearchDirection;
    23032465  Vector helper;
    2304   TesselPoint *ThirdNode = NULL;
     2466  BoundaryPointSet *ThirdPoint = NULL;
    23052467  LineMap::iterator testline;
    23062468  double radius, CircleRadius;
    23072469
    2308   for (int i=0;i<3;i++)
    2309     if ((T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[0]->node) && (T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[1]->node)) {
    2310       ThirdNode = T.endpoints[i]->node;
     2470  for (int i = 0; i < 3; i++)
     2471    if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
     2472      ThirdPoint = T.endpoints[i];
    23112473      break;
    23122474    }
    2313   Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdNode " << *ThirdNode << " of triangle " << T << "." << endl;
     2475  DoLog(0) && (Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << "." << endl);
     2476
     2477  CandidateLine.T = &T;
    23142478
    23152479  // construct center of circle
     
    23242488  // calculate squared radius of circle
    23252489  radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    2326   if (radius/4. < RADIUS*RADIUS) {
     2490  if (radius / 4. < RADIUS * RADIUS) {
    23272491    // construct relative sphere center with now known CircleCenter
    23282492    RelativeSphereCenter.CopyVector(&T.SphereCenter);
    23292493    RelativeSphereCenter.SubtractVector(&CircleCenter);
    23302494
    2331     CircleRadius = RADIUS*RADIUS - radius/4.;
     2495    CircleRadius = RADIUS * RADIUS - radius / 4.;
    23322496    CirclePlaneNormal.Normalize();
    2333     Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    2334 
    2335     Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl;
     2497    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
     2498
     2499    DoLog(1) && (Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl);
    23362500
    23372501    // construct SearchDirection and an "outward pointer"
    23382502    SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
    23392503    helper.CopyVector(&CircleCenter);
    2340     helper.SubtractVector(ThirdNode->node);
     2504    helper.SubtractVector(ThirdPoint->node->node);
    23412505    if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    23422506      SearchDirection.Scale(-1.);
    2343     Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2507    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
    23442508    if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    23452509      // rotated the wrong way!
    2346       eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     2510      DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
    23472511    }
    23482512
    23492513    // add third point
    2350     FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdNode, RADIUS, LC);
     2514    FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC);
    23512515
    23522516  } else {
    2353     Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl;
     2517    DoLog(0) && (Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl);
    23542518  }
    23552519
    23562520  if (CandidateLine.pointlist.empty()) {
    2357     eLog() << Verbose(2) << "Could not find a suitable candidate." << endl;
     2521    DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl);
    23582522    return false;
    23592523  }
    2360   Log() << Verbose(0) << "Third Points are: " << endl;
     2524  DoLog(0) && (Log() << Verbose(0) << "Third Points are: " << endl);
    23612525  for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
    2362     Log() << Verbose(0) << " " << *(*it) << endl;
     2526    DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
    23632527  }
    23642528
    23652529  return true;
    2366 
    2367 //  BoundaryLineSet *BaseRay = CandidateLine.BaseLine;
    2368 //  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    2369 //    Log() << Verbose(0) << "Third point candidate is " << *(*it)->point
    2370 //    << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
    2371 //    Log() << Verbose(0) << "Baseline is " << *BaseRay << endl;
    2372 //
    2373 //    // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
    2374 //    TesselPoint *PointCandidates[3];
    2375 //    PointCandidates[0] = (*it)->point;
    2376 //    PointCandidates[1] = BaseRay->endpoints[0]->node;
    2377 //    PointCandidates[2] = BaseRay->endpoints[1]->node;
    2378 //    int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
    2379 //
    2380 //    BTS = NULL;
    2381 //    // check for present edges and whether we reach better candidates from them
    2382 //    //if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) {
    2383 //    if (0) {
    2384 //      result = false;
    2385 //      break;
    2386 //    } else {
    2387 //      // If there is no triangle, add it regularly.
    2388 //      if (existentTrianglesCount == 0) {
    2389 //        AddTesselationPoint((*it)->point, 0);
    2390 //        AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    2391 //        AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    2392 //
    2393 //        if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
    2394 //          CandidateLine.point = (*it)->point;
    2395 //          CandidateLine.OptCenter.CopyVector(&((*it)->OptCenter));
    2396 //          CandidateLine.OtherOptCenter.CopyVector(&((*it)->OtherOptCenter));
    2397 //          CandidateLine.ShortestAngle = ShortestAngle;
    2398 //        } else {
    2399 ////          eLog() << Verbose(1) << "This triangle consisting of ";
    2400 ////          Log() << Verbose(0) << *(*it)->point << ", ";
    2401 ////          Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    2402 ////          Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    2403 ////          Log() << Verbose(0) << "exists and is not added, as it 0x80000000006fc150(does not seem helpful!" << endl;
    2404 //          result = false;
    2405 //        }
    2406 //      } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
    2407 //          AddTesselationPoint((*it)->point, 0);
    2408 //          AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    2409 //          AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    2410 //
    2411 //          // 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)
    2412 //          // i.e. at least one of the three lines must be present with TriangleCount <= 1
    2413 //          if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS) || CandidateLine.BaseLine->skipped) {
    2414 //            CandidateLine.point = (*it)->point;
    2415 //            CandidateLine.OptCenter.CopyVector(&(*it)->OptCenter);
    2416 //            CandidateLine.OtherOptCenter.CopyVector(&(*it)->OtherOptCenter);
    2417 //            CandidateLine.ShortestAngle = ShortestAngle+2.*M_PI;
    2418 //
    2419 //          } else {
    2420 ////            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;
    2421 //            result = false;
    2422 //          }
    2423 //      } else {
    2424 ////        Log() << Verbose(1) << "This triangle consisting of ";
    2425 ////        Log() << Verbose(0) << *(*it)->point << ", ";
    2426 ////        Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    2427 ////        Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    2428 ////        Log() << Verbose(0) << "is invalid!" << endl;
    2429 //        result = false;
    2430 //      }
    2431 //    }
    2432 //
    2433 //    // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
    2434 //    BaseRay = BLS[0];
    2435 //    if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
    2436 //      eLog() << Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl;
    2437 //      exit(255);
    2438 //    }
    2439 //
    2440 //  }
    2441 //
    2442 //  // remove all candidates from the list and then the list itself
    2443 //  class CandidateForTesselation *remover = NULL;
    2444 //  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    2445 //    remover = *it;
    2446 //    delete(remover);
    2447 //  }
    2448 //  delete(OptCandidates);
    2449   return result;
    2450 };
     2530}
     2531;
     2532
     2533/** Walks through Tesselation::OpenLines() and finds candidates for newly created ones.
     2534 * \param *&LCList atoms in LinkedCell list
     2535 * \param RADIUS radius of the virtual sphere
     2536 * \return true - for all open lines without candidates so far, a candidate has been found,
     2537 *         false - at least one open line without candidate still
     2538 */
     2539bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList)
     2540{
     2541  bool TesselationFailFlag = true;
     2542  CandidateForTesselation *baseline = NULL;
     2543  BoundaryTriangleSet *T = NULL;
     2544
     2545  for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
     2546    baseline = Runner->second;
     2547    if (baseline->pointlist.empty()) {
     2548      assert((baseline->BaseLine->triangles.size() == 1) && ("Open line without exactly one attached triangle"));
     2549      T = (((baseline->BaseLine->triangles.begin()))->second);
     2550      DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl);
     2551      TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
     2552    }
     2553  }
     2554  return TesselationFailFlag;
     2555}
     2556;
    24512557
    24522558/** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
    24532559 * \param CandidateLine triangle to add
    2454  * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in AddTesselationLine()
    2455  */
    2456 void Tesselation::AddCandidateTriangle(CandidateForTesselation CandidateLine)
    2457 {
    2458         Info FunctionInfo(__func__);
     2560 * \param RADIUS Radius of sphere
     2561 * \param *LC LinkedCell structure
     2562 * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in
     2563 * AddTesselationLine() in AddCandidateTriangle()
     2564 */
     2565void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC)
     2566{
     2567  Info FunctionInfo(__func__);
    24592568  Vector Center;
    24602569  TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
     2570  TesselPointList::iterator Runner;
     2571  TesselPointList::iterator Sprinter;
    24612572
    24622573  // fill the set of neighbours
     
    24672578  TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
    24682579
     2580  DoLog(0) && (Log() << Verbose(0) << "List of Candidates for Turning Point " << *TurningPoint << ":" << endl);
     2581  for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
     2582    DoLog(0) && (Log() << Verbose(0) << " " << **TesselRunner << endl);
     2583
    24692584  // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
    2470   Log() << Verbose(0) << "List of Candidates for Turning Point: " << *TurningPoint << "." << endl;
    2471   for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
    2472     Log() << Verbose(0) << **TesselRunner << endl;
    2473   TesselPointList::iterator Runner = connectedClosestPoints->begin();
    2474   TesselPointList::iterator Sprinter = Runner;
     2585  Runner = connectedClosestPoints->begin();
     2586  Sprinter = Runner;
    24752587  Sprinter++;
    2476   while(Sprinter != connectedClosestPoints->end()) {
    2477     // add the points
     2588  while (Sprinter != connectedClosestPoints->end()) {
     2589    DoLog(0) && (Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl);
     2590
    24782591    AddTesselationPoint(TurningPoint, 0);
    2479     AddTesselationPoint((*Runner), 1);
    2480     AddTesselationPoint((*Sprinter), 2);
    2481 
    2482     // add the lines
    2483     AddTesselationLine(TPS[0], TPS[1], 0);
    2484     AddTesselationLine(TPS[0], TPS[2], 1);
    2485     AddTesselationLine(TPS[1], TPS[2], 2);
    2486 
    2487     // add the triangles
    2488     BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    2489     AddTesselationTriangle();
    2490     BTS->GetCenter(&Center);
    2491     Center.SubtractVector(&CandidateLine.OptCenter);
    2492     BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
    2493     BTS->GetNormalVector(Center);
    2494 
    2495     Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << "." << endl;
     2592    AddTesselationPoint(*Runner, 1);
     2593    AddTesselationPoint(*Sprinter, 2);
     2594
     2595    AddCandidateTriangle(CandidateLine, Opt);
     2596
    24962597    Runner = Sprinter;
    24972598    Sprinter++;
    2498     Log() << Verbose(0) << "Current Runner is " << **Runner << "." << endl;
    2499     if (Sprinter != connectedClosestPoints->end())
    2500       Log() << Verbose(0) << " There are still more triangles to add." << endl;
    2501   }
    2502   delete(connectedClosestPoints);
     2599    if (Sprinter != connectedClosestPoints->end()) {
     2600      // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
     2601      FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); // Assume BTS contains last triangle
     2602      DoLog(0) && (Log() << Verbose(0) << " There are still more triangles to add." << endl);
     2603    }
     2604    // pick candidates for other open lines as well
     2605    FindCandidatesforOpenLines(RADIUS, LC);
     2606
     2607    // check whether we add a degenerate or a normal triangle
     2608    if (CheckDegeneracy(CandidateLine, RADIUS, LC)) {
     2609      // add normal and degenerate triangles
     2610      DoLog(1) && (Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl);
     2611      AddCandidateTriangle(CandidateLine, OtherOpt);
     2612
     2613      if (Sprinter != connectedClosestPoints->end()) {
     2614        // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
     2615        FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter);
     2616      }
     2617      // pick candidates for other open lines as well
     2618      FindCandidatesforOpenLines(RADIUS, LC);
     2619    }
     2620  }
     2621  delete (connectedClosestPoints);
    25032622};
     2623
     2624/** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate.
     2625 * \param *Sprinter next candidate to which internal open lines are set
     2626 * \param *OptCenter OptCenter for this candidate
     2627 */
     2628void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter)
     2629{
     2630  Info FunctionInfo(__func__);
     2631
     2632  pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr);
     2633  for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     2634    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
     2635    // If there is a line with less than two attached triangles, we don't need a new line.
     2636    if (FindLine->second->triangles.size() == 1) {
     2637      CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
     2638      if (!Finder->second->pointlist.empty())
     2639        DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
     2640      else {
     2641        DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl);
     2642        Finder->second->T = BTS;  // is last triangle
     2643        Finder->second->pointlist.push_back(Sprinter);
     2644        Finder->second->ShortestAngle = 0.;
     2645        Finder->second->OptCenter.CopyVector(OptCenter);
     2646      }
     2647    }
     2648  }
     2649};
     2650
     2651/** If a given \a *triangle is degenerated, this adds both sides.
     2652 * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction.
     2653 * Note that endpoints are stored in Tesselation::TPS
     2654 * \param CandidateLine CanddiateForTesselation structure for the desired BoundaryLine
     2655 * \param RADIUS radius of sphere
     2656 * \param *LC pointer to LinkedCell structure
     2657 */
     2658void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
     2659{
     2660  Info FunctionInfo(__func__);
     2661  Vector Center;
     2662  CandidateMap::const_iterator CandidateCheck = OpenLines.end();
     2663  BoundaryTriangleSet *triangle = NULL;
     2664
     2665  /// 1. Create or pick the lines for the first triangle
     2666  DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl);
     2667  for (int i = 0; i < 3; i++) {
     2668    BLS[i] = NULL;
     2669    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2670    AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
     2671  }
     2672
     2673  /// 2. create the first triangle and NormalVector and so on
     2674  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl);
     2675  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2676  AddTesselationTriangle();
     2677
     2678  // create normal vector
     2679  BTS->GetCenter(&Center);
     2680  Center.SubtractVector(&CandidateLine.OptCenter);
     2681  BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
     2682  BTS->GetNormalVector(Center);
     2683  // give some verbose output about the whole procedure
     2684  if (CandidateLine.T != NULL)
     2685    DoLog(0) && (Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
     2686  else
     2687    DoLog(0) && (Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2688  triangle = BTS;
     2689
     2690  /// 3. Gather candidates for each new line
     2691  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl);
     2692  for (int i = 0; i < 3; i++) {
     2693    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2694    CandidateCheck = OpenLines.find(BLS[i]);
     2695    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     2696      if (CandidateCheck->second->T == NULL)
     2697        CandidateCheck->second->T = triangle;
     2698      FindNextSuitableTriangle(*(CandidateCheck->second), *CandidateCheck->second->T, RADIUS, LC);
     2699    }
     2700  }
     2701
     2702  /// 4. Create or pick the lines for the second triangle
     2703  DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl);
     2704  for (int i = 0; i < 3; i++) {
     2705    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2706    AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
     2707  }
     2708
     2709  /// 5. create the second triangle and NormalVector and so on
     2710  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl);
     2711  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2712  AddTesselationTriangle();
     2713
     2714  BTS->SphereCenter.CopyVector(&CandidateLine.OtherOptCenter);
     2715  // create normal vector in other direction
     2716  BTS->GetNormalVector(&triangle->NormalVector);
     2717  BTS->NormalVector.Scale(-1.);
     2718  // give some verbose output about the whole procedure
     2719  if (CandidateLine.T != NULL)
     2720    DoLog(0) && (Log() << Verbose(0) << "--> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
     2721  else
     2722    DoLog(0) && (Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2723
     2724  /// 6. Adding triangle to new lines
     2725  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl);
     2726  for (int i = 0; i < 3; i++) {
     2727    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2728    CandidateCheck = OpenLines.find(BLS[i]);
     2729    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     2730      if (CandidateCheck->second->T == NULL)
     2731        CandidateCheck->second->T = BTS;
     2732    }
     2733  }
     2734}
     2735;
     2736
     2737/** Adds a triangle to the Tesselation structure from three given TesselPoint's.
     2738 * Note that endpoints are in Tesselation::TPS.
     2739 * \param CandidateLine CandidateForTesselation structure contains other information
     2740 * \param type which opt center to add (i.e. which side) and thus which NormalVector to take
     2741 */
     2742void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type)
     2743{
     2744  Info FunctionInfo(__func__);
     2745  Vector Center;
     2746  Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter;
     2747
     2748  // add the lines
     2749  AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0);
     2750  AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1);
     2751  AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2);
     2752
     2753  // add the triangles
     2754  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2755  AddTesselationTriangle();
     2756
     2757  // create normal vector
     2758  BTS->GetCenter(&Center);
     2759  Center.SubtractVector(OptCenter);
     2760  BTS->SphereCenter.CopyVector(OptCenter);
     2761  BTS->GetNormalVector(Center);
     2762
     2763  // give some verbose output about the whole procedure
     2764  if (CandidateLine.T != NULL)
     2765    DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
     2766  else
     2767    DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2768}
     2769;
    25042770
    25052771/** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
     
    25122778class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
    25132779{
    2514         Info FunctionInfo(__func__);
     2780  Info FunctionInfo(__func__);
    25152781  class BoundaryPointSet *Spot = NULL;
    25162782  class BoundaryLineSet *OtherBase;
    25172783  Vector *ClosestPoint;
    25182784
    2519   int m=0;
    2520   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2521     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2785  int m = 0;
     2786  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2787    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    25222788      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
    25232789        BPS[m++] = runner->second->endpoints[j];
    2524   OtherBase = new class BoundaryLineSet(BPS,-1);
    2525 
    2526   Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl;
    2527   Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl;
     2790  OtherBase = new class BoundaryLineSet(BPS, -1);
     2791
     2792  DoLog(1) && (Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl);
     2793  DoLog(1) && (Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl);
    25282794
    25292795  // get the closest point on each line to the other line
     
    25312797
    25322798  // delete the temporary other base line
    2533   delete(OtherBase);
     2799  delete (OtherBase);
    25342800
    25352801  // get the distance vector from Base line to OtherBase line
     
    25382804  BaseLine.CopyVector(Base->endpoints[1]->node->node);
    25392805  BaseLine.SubtractVector(Base->endpoints[0]->node->node);
    2540   for (int i=0;i<2;i++) {
     2806  for (int i = 0; i < 2; i++) {
    25412807    DistanceToIntersection[i].CopyVector(ClosestPoint);
    25422808    DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
    25432809    distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
    25442810  }
    2545   delete(ClosestPoint);
    2546   if ((distance[0] * distance[1]) > 0)  { // have same sign?
    2547     Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
     2811  delete (ClosestPoint);
     2812  if ((distance[0] * distance[1]) > 0) { // have same sign?
     2813    DoLog(1) && (Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl);
    25482814    if (distance[0] < distance[1]) {
    25492815      Spot = Base->endpoints[0];
     
    25522818    }
    25532819    return Spot;
    2554   } else {  // different sign, i.e. we are in between
    2555     Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
     2820  } else { // different sign, i.e. we are in between
     2821    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl);
    25562822    return NULL;
    25572823  }
    25582824
    2559 };
     2825}
     2826;
    25602827
    25612828void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
    25622829{
    2563         Info FunctionInfo(__func__);
     2830  Info FunctionInfo(__func__);
    25642831  // print all lines
    2565   Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl;
    2566   for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
    2567     Log() << Verbose(0) << *(PointRunner->second) << endl;
    2568 };
     2832  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl);
     2833  for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)
     2834    DoLog(0) && (Log() << Verbose(0) << *(PointRunner->second) << endl);
     2835}
     2836;
    25692837
    25702838void Tesselation::PrintAllBoundaryLines(ofstream *out) const
    25712839{
    2572         Info FunctionInfo(__func__);
     2840  Info FunctionInfo(__func__);
    25732841  // print all lines
    2574   Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl;
     2842  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl);
    25752843  for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
    2576     Log() << Verbose(0) << *(LineRunner->second) << endl;
    2577 };
     2844    DoLog(0) && (Log() << Verbose(0) << *(LineRunner->second) << endl);
     2845}
     2846;
    25782847
    25792848void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
    25802849{
    2581         Info FunctionInfo(__func__);
     2850  Info FunctionInfo(__func__);
    25822851  // print all triangles
    2583   Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl;
     2852  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl);
    25842853  for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
    2585     Log() << Verbose(0) << *(TriangleRunner->second) << endl;
    2586 };
     2854    DoLog(0) && (Log() << Verbose(0) << *(TriangleRunner->second) << endl);
     2855}
     2856;
    25872857
    25882858/** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
     
    25932863double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
    25942864{
    2595         Info FunctionInfo(__func__);
     2865  Info FunctionInfo(__func__);
    25962866  class BoundaryLineSet *OtherBase;
    25972867  Vector *ClosestPoint[2];
    25982868  double volume;
    25992869
    2600   int m=0;
    2601   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2602     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2870  int m = 0;
     2871  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2872    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    26032873      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
    26042874        BPS[m++] = runner->second->endpoints[j];
    2605   OtherBase = new class BoundaryLineSet(BPS,-1);
    2606 
    2607   Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl;
    2608   Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl;
     2875  OtherBase = new class BoundaryLineSet(BPS, -1);
     2876
     2877  DoLog(0) && (Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl);
     2878  DoLog(0) && (Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl);
    26092879
    26102880  // get the closest point on each line to the other line
     
    26212891
    26222892  // delete the temporary other base line and the closest points
    2623   delete(ClosestPoint[0]);
    2624   delete(ClosestPoint[1]);
    2625   delete(OtherBase);
     2893  delete (ClosestPoint[0]);
     2894  delete (ClosestPoint[1]);
     2895  delete (OtherBase);
    26262896
    26272897  if (Distance.NormSquared() < MYEPSILON) { // check for intersection
    2628     Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
     2898    DoLog(0) && (Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl);
    26292899    return false;
    26302900  } else { // check for sign against BaseLineNormal
     
    26322902    BaseLineNormal.Zero();
    26332903    if (Base->triangles.size() < 2) {
    2634       eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;
     2904      DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
    26352905      return 0.;
    26362906    }
    26372907    for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2638       Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
     2908      DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
    26392909      BaseLineNormal.AddVector(&(runner->second->NormalVector));
    26402910    }
    2641     BaseLineNormal.Scale(1./2.);
     2911    BaseLineNormal.Scale(1. / 2.);
    26422912
    26432913    if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
    2644       Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;
     2914      DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl);
    26452915      // calculate volume summand as a general tetraeder
    26462916      return volume;
    2647     } else {  // Base higher than OtherBase -> do nothing
    2648       Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl;
     2917    } else { // Base higher than OtherBase -> do nothing
     2918      DoLog(0) && (Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl);
    26492919      return 0.;
    26502920    }
    26512921  }
    2652 };
     2922}
     2923;
    26532924
    26542925/** For a given baseline and its two connected triangles, flips the baseline.
     
    26612932class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
    26622933{
    2663         Info FunctionInfo(__func__);
     2934  Info FunctionInfo(__func__);
    26642935  class BoundaryLineSet *OldLines[4], *NewLine;
    26652936  class BoundaryPointSet *OldPoints[2];
    26662937  Vector BaseLineNormal;
    26672938  int OldTriangleNrs[2], OldBaseLineNr;
    2668   int i,m;
     2939  int i, m;
    26692940
    26702941  // calculate NormalVector for later use
    26712942  BaseLineNormal.Zero();
    26722943  if (Base->triangles.size() < 2) {
    2673     eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;
     2944    DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
    26742945    return NULL;
    26752946  }
    26762947  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2677     Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
     2948    DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
    26782949    BaseLineNormal.AddVector(&(runner->second->NormalVector));
    26792950  }
    2680   BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
     2951  BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
    26812952
    26822953  // get the two triangles
    26832954  // gather four endpoints and four lines
    2684   for (int j=0;j<4;j++)
     2955  for (int j = 0; j < 4; j++)
    26852956    OldLines[j] = NULL;
    2686   for (int j=0;j<2;j++)
     2957  for (int j = 0; j < 2; j++)
    26872958    OldPoints[j] = NULL;
    2688   i=0;
    2689   m=0;
    2690   Log() << Verbose(0) << "The four old lines are: ";
    2691   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2692     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2959  i = 0;
     2960  m = 0;
     2961  DoLog(0) && (Log() << Verbose(0) << "The four old lines are: ");
     2962  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2963    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    26932964      if (runner->second->lines[j] != Base) { // pick not the central baseline
    26942965        OldLines[i++] = runner->second->lines[j];
    2695         Log() << Verbose(0) << *runner->second->lines[j] << "\t";
     2966        DoLog(0) && (Log() << Verbose(0) << *runner->second->lines[j] << "\t");
    26962967      }
    2697   Log() << Verbose(0) << endl;
    2698   Log() << Verbose(0) << "The two old points are: ";
    2699   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2700     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2968  DoLog(0) && (Log() << Verbose(0) << endl);
     2969  DoLog(0) && (Log() << Verbose(0) << "The two old points are: ");
     2970  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2971    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    27012972      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
    27022973        OldPoints[m++] = runner->second->endpoints[j];
    2703         Log() << Verbose(0) << *runner->second->endpoints[j] << "\t";
     2974        DoLog(0) && (Log() << Verbose(0) << *runner->second->endpoints[j] << "\t");
    27042975      }
    2705   Log() << Verbose(0) << endl;
     2976  DoLog(0) && (Log() << Verbose(0) << endl);
    27062977
    27072978  // check whether everything is in place to create new lines and triangles
    2708   if (i<4) {
    2709     eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;
     2979  if (i < 4) {
     2980    DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
    27102981    return NULL;
    27112982  }
    2712   for (int j=0;j<4;j++)
     2983  for (int j = 0; j < 4; j++)
    27132984    if (OldLines[j] == NULL) {
    2714       eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;
     2985      DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
    27152986      return NULL;
    27162987    }
    2717   for (int j=0;j<2;j++)
     2988  for (int j = 0; j < 2; j++)
    27182989    if (OldPoints[j] == NULL) {
    2719       eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl;
     2990      DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl);
    27202991      return NULL;
    27212992    }
    27222993
    27232994  // remove triangles and baseline removes itself
    2724   Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
     2995  DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl);
    27252996  OldBaseLineNr = Base->Nr;
    2726   m=0;
    2727   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2728     Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
     2997  m = 0;
     2998  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
     2999    DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl);
    27293000    OldTriangleNrs[m++] = runner->second->Nr;
    27303001    RemoveTesselationTriangle(runner->second);
     
    27363007  NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
    27373008  LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
    2738   Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl;
     3009  DoLog(0) && (Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl);
    27393010
    27403011  // construct new triangles with flipped baseline
    2741   i=-1;
     3012  i = -1;
    27423013  if (OldLines[0]->IsConnectedTo(OldLines[2]))
    2743     i=2;
     3014    i = 2;
    27443015  if (OldLines[0]->IsConnectedTo(OldLines[3]))
    2745     i=3;
    2746   if (i!=-1) {
     3016    i = 3;
     3017  if (i != -1) {
    27473018    BLS[0] = OldLines[0];
    27483019    BLS[1] = OldLines[i];
     
    27513022    BTS->GetNormalVector(BaseLineNormal);
    27523023    AddTesselationTriangle(OldTriangleNrs[0]);
    2753     Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
    2754 
    2755     BLS[0] = (i==2 ? OldLines[3] : OldLines[2]);
     3024    DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
     3025
     3026    BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]);
    27563027    BLS[1] = OldLines[1];
    27573028    BLS[2] = NewLine;
     
    27593030    BTS->GetNormalVector(BaseLineNormal);
    27603031    AddTesselationTriangle(OldTriangleNrs[1]);
    2761     Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
     3032    DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
    27623033  } else {
    2763     eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl;
     3034    DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);
    27643035    return NULL;
    27653036  }
    27663037
    27673038  return NewLine;
    2768 };
    2769 
     3039}
     3040;
    27703041
    27713042/** Finds the second point of starting triangle.
     
    27793050void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
    27803051{
    2781         Info FunctionInfo(__func__);
     3052  Info FunctionInfo(__func__);
    27823053  Vector AngleCheck;
    27833054  class TesselPoint* Candidate = NULL;
     
    27883059  int Nupper[NDIM];
    27893060
    2790   if (LC->SetIndexToNode(a)) {  // get cell for the starting point
    2791     for(int i=0;i<NDIM;i++) // store indices of this cell
     3061  if (LC->SetIndexToNode(a)) { // get cell for the starting point
     3062    for (int i = 0; i < NDIM; i++) // store indices of this cell
    27923063      N[i] = LC->n[i];
    27933064  } else {
    2794     eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl;
     3065    DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);
    27953066    return;
    27963067  }
    27973068  // then go through the current and all neighbouring cells and check the contained points for possible candidates
    2798   for (int i=0;i<NDIM;i++) {
    2799     Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
    2800     Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
    2801   }
    2802   Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :"
    2803     << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl;
     3069  for (int i = 0; i < NDIM; i++) {
     3070    Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
     3071    Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
     3072  }
     3073  DoLog(0) && (Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :" << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl);
    28043074
    28053075  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    28063076    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    28073077      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    2808         const LinkedNodes *List = LC->GetCurrentCell();
     3078        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    28093079        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    28103080        if (List != NULL) {
    2811           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3081          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    28123082            Candidate = (*Runner);
    28133083            // check if we only have one unique point yet ...
     
    28353105              norm = aCandidate.Norm();
    28363106              // second point shall have smallest angle with respect to Oben vector
    2837               if (norm < RADIUS*2.) {
     3107              if (norm < RADIUS * 2.) {
    28383108                angle = AngleCheck.Angle(&Oben);
    28393109                if (angle < Storage[0]) {
    28403110                  //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
    2841                   Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
     3111                  DoLog(1) && (Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n");
    28423112                  OptCandidate = Candidate;
    28433113                  Storage[0] = angle;
     
    28543124          }
    28553125        } else {
    2856           Log() << Verbose(0) << "Linked cell list is empty." << endl;
     3126          DoLog(0) && (Log() << Verbose(0) << "Linked cell list is empty." << endl);
    28573127        }
    28583128      }
    2859 };
    2860 
     3129}
     3130;
    28613131
    28623132/** This recursive function finds a third point, to form a triangle with two given ones.
     
    28863156 * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
    28873157 * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
    2888  * @param ThirdNode third point to avoid in search
     3158 * @param ThirdPoint third point to avoid in search
    28893159 * @param RADIUS radius of sphere
    28903160 * @param *LC LinkedCell structure with neighbouring points
    28913161 */
    2892 void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const
    2893 {
    2894         Info FunctionInfo(__func__);
    2895   Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     3162void Tesselation::FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdPoint, const double RADIUS, const LinkedCell *LC) const
     3163{
     3164  Info FunctionInfo(__func__);
     3165  Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
    28963166  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
    28973167  Vector SphereCenter;
    2898   Vector NewSphereCenter;   // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
    2899   Vector OtherNewSphereCenter;   // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
    2900   Vector NewNormalVector;   // normal vector of the Candidate's triangle
     3168  Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
     3169  Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
     3170  Vector NewNormalVector; // normal vector of the Candidate's triangle
    29013171  Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
    29023172  Vector RelativeOldSphereCenter;
     
    29093179  TesselPoint *Candidate = NULL;
    29103180
    2911   Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
     3181  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl);
     3182
     3183  // copy old center
     3184  CandidateLine.OldCenter.CopyVector(&OldSphereCenter);
     3185  CandidateLine.ThirdPoint = ThirdPoint;
     3186  CandidateLine.pointlist.clear();
    29123187
    29133188  // construct center of circle
     
    29233198  RelativeOldSphereCenter.SubtractVector(&CircleCenter);
    29243199
    2925   // calculate squared radius TesselPoint *ThirdNode,f circle
    2926   radius = CirclePlaneNormal.NormSquared()/4.;
    2927   if (radius < RADIUS*RADIUS) {
    2928     CircleRadius = RADIUS*RADIUS - radius;
     3200  // calculate squared radius TesselPoint *ThirdPoint,f circle
     3201  radius = CirclePlaneNormal.NormSquared() / 4.;
     3202  if (radius < RADIUS * RADIUS) {
     3203    CircleRadius = RADIUS * RADIUS - radius;
    29293204    CirclePlaneNormal.Normalize();
    2930     Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     3205    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
    29313206
    29323207    // test whether old center is on the band's plane
    29333208    if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    2934       eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
     3209      DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl);
    29353210      RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
    29363211    }
    29373212    radius = RelativeOldSphereCenter.NormSquared();
    29383213    if (fabs(radius - CircleRadius) < HULLEPSILON) {
    2939       Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl;
     3214      DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl);
    29403215
    29413216      // check SearchDirection
    2942       Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2943       if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {  // rotated the wrong way!
    2944         eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl;
     3217      DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
     3218      if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
     3219        DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
    29453220      }
    29463221
    29473222      // get cell for the starting point
    29483223      if (LC->SetIndexToVector(&CircleCenter)) {
    2949         for(int i=0;i<NDIM;i++) // store indices of this cell
    2950         N[i] = LC->n[i];
     3224        for (int i = 0; i < NDIM; i++) // store indices of this cell
     3225          N[i] = LC->n[i];
    29513226        //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    29523227      } else {
    2953         eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl;
     3228        DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);
    29543229        return;
    29553230      }
    29563231      // then go through the current and all neighbouring cells and check the contained points for possible candidates
    29573232      //Log() << Verbose(1) << "LC Intervals:";
    2958       for (int i=0;i<NDIM;i++) {
    2959         Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
    2960         Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
     3233      for (int i = 0; i < NDIM; i++) {
     3234        Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
     3235        Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
    29613236        //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
    29623237      }
     
    29653240        for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    29663241          for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    2967             const LinkedNodes *List = LC->GetCurrentCell();
     3242            const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    29683243            //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    29693244            if (List != NULL) {
    2970               for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3245              for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    29713246                Candidate = (*Runner);
    29723247
    29733248                // check for three unique points
    2974                 Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl;
    2975                 if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node) ){
     3249                DoLog(2) && (Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl);
     3250                if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) {
    29763251
    29773252                  // find center on the plane
    29783253                  GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
    2979                   Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl;
    2980 
    2981                   if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node)
    2982                   && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)
    2983                   ) {
    2984                     Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
     3254                  DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl);
     3255
     3256                  if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) {
     3257                    DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl);
    29853258                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
    2986                     Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    2987                     Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2988                     Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl;
    2989                     if (radius < RADIUS*RADIUS) {
     3259                    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
     3260                    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
     3261                    DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl);
     3262                    if (radius < RADIUS * RADIUS) {
    29903263                      otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
    2991                       if (fabs(radius - otherradius) > HULLEPSILON) {
    2992                         eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl;
    2993                       }
    2994                       // construct both new centers
    2995                       NewSphereCenter.CopyVector(&NewPlaneCenter);
    2996                       OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
    2997                       helper.CopyVector(&NewNormalVector);
    2998                       helper.Scale(sqrt(RADIUS*RADIUS - radius));
    2999                       Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl;
    3000                       NewSphereCenter.AddVector(&helper);
    3001                       Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
    3002                       // OtherNewSphereCenter is created by the same vector just in the other direction
    3003                       helper.Scale(-1.);
    3004                       OtherNewSphereCenter.AddVector(&helper);
    3005                       Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
    3006 
    3007                       alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    3008                       Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    3009                       alpha = min(alpha, Otheralpha);
    3010 
    3011                       // if there is a better candidate, drop the current list and add the new candidate
    3012                       // otherwise ignore the new candidate and keep the list
    3013                       if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
    3014                         if (fabs(alpha - Otheralpha) > MYEPSILON) {
    3015                           CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
    3016                           CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     3264                      if (fabs(radius - otherradius) < HULLEPSILON) {
     3265                        // construct both new centers
     3266                        NewSphereCenter.CopyVector(&NewPlaneCenter);
     3267                        OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
     3268                        helper.CopyVector(&NewNormalVector);
     3269                        helper.Scale(sqrt(RADIUS * RADIUS - radius));
     3270                        DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl);
     3271                        NewSphereCenter.AddVector(&helper);
     3272                        DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl);
     3273                        // OtherNewSphereCenter is created by the same vector just in the other direction
     3274                        helper.Scale(-1.);
     3275                        OtherNewSphereCenter.AddVector(&helper);
     3276                        DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl);
     3277
     3278                        alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
     3279                        Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
     3280                        if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
     3281                          if (OldSphereCenter.DistanceSquared(&NewSphereCenter) < OldSphereCenter.DistanceSquared(&OtherNewSphereCenter))
     3282                            alpha = Otheralpha;
     3283                        } else
     3284                          alpha = min(alpha, Otheralpha);
     3285
     3286                        // if there is a better candidate, drop the current list and add the new candidate
     3287                        // otherwise ignore the new candidate and keep the list
     3288                        if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
     3289                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
     3290                            CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
     3291                            CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     3292                          } else {
     3293                            CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
     3294                            CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     3295                          }
     3296                          // if there is an equal candidate, add it to the list without clearing the list
     3297                          if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
     3298                            CandidateLine.pointlist.push_back(Candidate);
     3299                            DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
     3300                          } else {
     3301                            // remove all candidates from the list and then the list itself
     3302                            CandidateLine.pointlist.clear();
     3303                            CandidateLine.pointlist.push_back(Candidate);
     3304                            DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
     3305                          }
     3306                          CandidateLine.ShortestAngle = alpha;
     3307                          DoLog(0) && (Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl);
    30173308                        } else {
    3018                           CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
    3019                           CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     3309                          if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
     3310                            DoLog(1) && (Log() << Verbose(1) << "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl);
     3311                          } else {
     3312                            DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl);
     3313                          }
    30203314                        }
    3021                         // if there is an equal candidate, add it to the list without clearing the list
    3022                         if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
    3023                           CandidateLine.pointlist.push_back(Candidate);
    3024                           Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
    3025                             << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    3026                         } else {
    3027                           // remove all candidates from the list and then the list itself
    3028                           CandidateLine.pointlist.clear();
    3029                           CandidateLine.pointlist.push_back(Candidate);
    3030                           Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
    3031                             << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    3032                         }
    3033                         CandidateLine.ShortestAngle = alpha;
    3034                         Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
    30353315                      } else {
    3036                         if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
    3037                           Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
    3038                         } else {
    3039                           Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
    3040                         }
     3316                        DoLog(1) && (Log() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
    30413317                      }
    30423318                    } else {
    3043                       Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
     3319                      DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl);
    30443320                    }
    30453321                  } else {
    3046                     Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
     3322                    DoLog(1) && (Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl);
    30473323                  }
    30483324                } else {
    3049                   if (ThirdNode != NULL) {
    3050                     Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
     3325                  if (ThirdPoint != NULL) {
     3326                    DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << "." << endl);
    30513327                  } else {
    3052                     Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl;
     3328                    DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl);
    30533329                  }
    30543330                }
     
    30573333          }
    30583334    } else {
    3059       eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;
     3335      DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
    30603336    }
    30613337  } else {
    3062     if (ThirdNode != NULL)
    3063       Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
     3338    if (ThirdPoint != NULL)
     3339      DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!" << endl);
    30643340    else
    3065       Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl;
    3066   }
    3067 
    3068   Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl;
     3341      DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl);
     3342  }
     3343
     3344  DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl);
    30693345  if (CandidateLine.pointlist.size() > 1) {
    30703346    CandidateLine.pointlist.unique();
    30713347    CandidateLine.pointlist.sort(); //SortCandidates);
    30723348  }
    3073 };
     3349
     3350  if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
     3351    DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
     3352    performCriticalExit();
     3353  }
     3354}
     3355;
    30743356
    30753357/** Finds the endpoint two lines are sharing.
     
    30803362class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
    30813363{
    3082         Info FunctionInfo(__func__);
     3364  Info FunctionInfo(__func__);
    30833365  const BoundaryLineSet * lines[2] = { line1, line2 };
    30843366  class BoundaryPointSet *node = NULL;
     
    30873369  for (int i = 0; i < 2; i++)
    30883370    // for both lines
    3089     for (int j = 0; j < 2; j++)
    3090       { // for both endpoints
    3091         OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (
    3092             lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
    3093         if (!OrderTest.second)
    3094           { // if insertion fails, we have common endpoint
    3095             node = OrderTest.first->second;
    3096             Log() << Verbose(1) << "Common endpoint of lines " << *line1
    3097                 << " and " << *line2 << " is: " << *node << "." << endl;
    3098             j = 2;
    3099             i = 2;
    3100             break;
    3101           }
     3371    for (int j = 0; j < 2; j++) { // for both endpoints
     3372      OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
     3373      if (!OrderTest.second) { // if insertion fails, we have common endpoint
     3374        node = OrderTest.first->second;
     3375        DoLog(1) && (Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl);
     3376        j = 2;
     3377        i = 2;
     3378        break;
    31023379      }
     3380    }
    31033381  return node;
    3104 };
     3382}
     3383;
    31053384
    31063385/** Finds the boundary points that are closest to a given Vector \a *x.
     
    31163395
    31173396  if (LinesOnBoundary.empty()) {
    3118     eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl;
     3397    DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);
    31193398    return NULL;
    31203399  }
     
    31223401  // gather all points close to the desired one
    31233402  LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
    3124   for(int i=0;i<NDIM;i++) // store indices of this cell
     3403  for (int i = 0; i < NDIM; i++) // store indices of this cell
    31253404    N[i] = LC->n[i];
    3126   Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    3127 
     3405  DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
    31283406  DistanceToPointMap * points = new DistanceToPointMap;
    31293407  LC->GetNeighbourBounds(Nlower, Nupper);
     
    31323410    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    31333411      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    3134         const LinkedNodes *List = LC->GetCurrentCell();
     3412        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    31353413        //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    31363414        if (List != NULL) {
    3137           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3415          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    31383416            FindPoint = PointsOnBoundary.find((*Runner)->nr);
    31393417            if (FindPoint != PointsOnBoundary.end()) {
    3140               points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(x), FindPoint->second) );
    3141               Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl;
     3418              points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(x), FindPoint->second));
     3419              DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl);
    31423420            }
    31433421          }
    31443422        } else {
    3145           eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
     3423          DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
    31463424        }
    31473425      }
     
    31493427  // check whether we found some points
    31503428  if (points->empty()) {
    3151     eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
    3152     delete(points);
     3429    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
     3430    delete (points);
    31533431    return NULL;
    31543432  }
    31553433  return points;
    3156 };
     3434}
     3435;
    31573436
    31583437/** Finds the boundary line that is closest to a given Vector \a *x.
     
    31643443{
    31653444  Info FunctionInfo(__func__);
    3166 
    31673445  // get closest points
    3168   DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3446  DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
    31693447  if (points == NULL) {
    3170     eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
     3448    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
    31713449    return NULL;
    31723450  }
    31733451
    31743452  // for each point, check its lines, remember closest
    3175   Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl;
     3453  DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl);
    31763454  BoundaryLineSet *ClosestLine = NULL;
    31773455  double MinDistance = -1.;
     
    32013479        helper.SubtractVector(&Center);
    32023480        const double lengthB = helper.ScalarProduct(&BaseLine);
    3203         if (lengthB*lengthA < 0) { // if have different sign
     3481        if (lengthB * lengthA < 0) { // if have different sign
    32043482          ClosestLine = LineRunner->second;
    32053483          MinDistance = distance;
    3206           Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl;
     3484          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl);
    32073485        } else {
    3208           Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl;
     3486          DoLog(1) && (Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl);
    32093487        }
    32103488      } else {
    3211         Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl;
     3489        DoLog(1) && (Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl);
    32123490      }
    32133491    }
    32143492  }
    3215   delete(points);
     3493  delete (points);
    32163494  // check whether closest line is "too close" :), then it's inside
    32173495  if (ClosestLine == NULL) {
    3218     Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
     3496    DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
    32193497    return NULL;
    32203498  }
    32213499  return ClosestLine;
    3222 };
    3223 
     3500}
     3501;
    32243502
    32253503/** Finds the triangle that is closest to a given Vector \a *x.
     
    32303508TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
    32313509{
    3232         Info FunctionInfo(__func__);
    3233 
    3234         // get closest points
    3235         DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3510  Info FunctionInfo(__func__);
     3511  // get closest points
     3512  DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
    32363513  if (points == NULL) {
    3237     eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
     3514    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
    32383515    return NULL;
    32393516  }
    32403517
    32413518  // for each point, check its lines, remember closest
    3242   Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl;
     3519  DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl);
    32433520  LineSet ClosestLines;
    32443521  double MinDistance = 1e+16;
     
    32623539      const double lengthEndB = BaseLineIntersection.NormSquared();
    32633540
    3264       if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) {  // intersection would be outside, take closer endpoint
     3541      if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
    32653542        const double lengthEnd = Min(lengthEndA, lengthEndB);
    32663543        if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
     
    32683545          ClosestLines.insert(LineRunner->second);
    32693546          MinDistance = lengthEnd;
    3270           Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl;
    3271         } else if  (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
     3547          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl);
     3548        } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
    32723549          ClosestLines.insert(LineRunner->second);
    3273           Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl;
     3550          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl);
    32743551        } else { // line is worse
    3275           Log() << Verbose(1) << "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << "." << endl;
     3552          DoLog(1) && (Log() << Verbose(1) << "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << "." << endl);
    32763553        }
    32773554      } else { // intersection is closer, calculate
     
    32843561        const double distance = BaseLineIntersection.NormSquared();
    32853562        if (Center.NormSquared() > BaseLine.NormSquared()) {
    3286           eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl;
     3563          DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);
    32873564        }
    32883565        if ((ClosestLines.empty()) || (distance < MinDistance)) {
    32893566          ClosestLines.insert(LineRunner->second);
    32903567          MinDistance = distance;
    3291           Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl;
     3568          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl);
    32923569        } else {
    3293           Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl;
     3570          DoLog(2) && (Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl);
    32943571        }
    32953572      }
    32963573    }
    32973574  }
    3298   delete(points);
     3575  delete (points);
    32993576
    33003577  // check whether closest line is "too close" :), then it's inside
    33013578  if (ClosestLines.empty()) {
    3302     Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
     3579    DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
    33033580    return NULL;
    33043581  }
     
    33063583  for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
    33073584    for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
    3308     candidates->push_back(Runner->second);
    3309   }
     3585      candidates->push_back(Runner->second);
     3586    }
    33103587  return candidates;
    3311 };
     3588}
     3589;
    33123590
    33133591/** Finds closest triangle to a point.
     
    33153593 * \param *out output stream for debugging
    33163594 * \param *x Vector to look from
     3595 * \param &distance contains found distance on return
    33173596 * \return list of BoundaryTriangleSet of nearest triangles or NULL.
    33183597 */
    33193598class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
    33203599{
    3321         Info FunctionInfo(__func__);
     3600  Info FunctionInfo(__func__);
    33223601  class BoundaryTriangleSet *result = NULL;
    33233602  TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
     
    33303609
    33313610  // go through all and pick the one with the best alignment to x
    3332   double MinAlignment = 2.*M_PI;
     3611  double MinAlignment = 2. * M_PI;
    33333612  for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
    33343613    (*Runner)->GetCenter(&Center);
     
    33393618      result = *Runner;
    33403619      MinAlignment = Alignment;
    3341       Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl;
     3620      DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl);
    33423621    } else {
    3343       Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl;
    3344     }
    3345   }
    3346   delete(triangles);
     3622      DoLog(1) && (Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl);
     3623    }
     3624  }
     3625  delete (triangles);
    33473626
    33483627  return result;
    3349 };
     3628}
     3629;
    33503630
    33513631/** Checks whether the provided Vector is within the Tesselation structure.
     
    33583638bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
    33593639{
    3360   return (GetDistanceSquaredToSurface(Point, LC) < MYEPSILON);
    3361 }
     3640  Info FunctionInfo(__func__);
     3641  TriangleIntersectionList Intersections(&Point, this, LC);
     3642
     3643  return Intersections.IsInside();
     3644}
     3645;
    33623646
    33633647/** Returns the distance to the surface given by the tesselation.
     
    33893673
    33903674  if (triangle == NULL) {// is boundary point or only point in point cloud?
    3391     Log() << Verbose(1) << "No triangle given!" << endl;
     3675    DoLog(1) && (Log() << Verbose(1) << "No triangle given!" << endl);
    33923676    return -1.;
    33933677  } else {
    3394     Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl;
     3678    DoLog(1) && (Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl);
    33953679  }
    33963680
    33973681  triangle->GetCenter(&Center);
    3398   Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
     3682  DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl);
    33993683  DistanceToCenter.CopyVector(&Center);
    34003684  DistanceToCenter.SubtractVector(&Point);
    3401   Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl;
     3685  DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl);
    34023686
    34033687  // check whether we are on boundary
     
    34083692    Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
    34093693    DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
    3410     Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl;
     3694    DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl);
    34113695    if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
    3412       Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl;
     3696      DoLog(1) && (Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl);
    34133697      return 0.;
    34143698    } else {
    3415       Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl;
     3699      DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl);
    34163700      return false;
    34173701    }
     
    34193703    // calculate smallest distance
    34203704    distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
    3421     Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl;
     3705    DoLog(1) && (Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl);
    34223706
    34233707    // then check direction to boundary
    34243708    if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
    3425       Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl;
     3709      DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl);
    34263710      return -distance;
    34273711    } else {
    3428       Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl;
     3712      DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl);
    34293713      return +distance;
    34303714    }
    34313715  }
    3432 };
    3433 
    3434 /** Calculates distance to a tesselated surface.
     3716}
     3717;
     3718
     3719/** Calculates minimum distance from \a&Point to a tesselated surface.
    34353720 * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
    34363721 * \param &Point point to calculate distance from
     
    34383723 * \return distance squared to closest point on surface
    34393724 */
    3440 double Tesselation::GetDistanceSquaredToSurface(const Vector &Point, const LinkedCell* const LC) const
    3441 {
    3442   BoundaryTriangleSet *triangle = FindClosestTriangleToVector(&Point, LC);
    3443   const double distance = GetDistanceSquaredToTriangle(Point, triangle);
    3444   return Min(distance, LC->RADIUS);
    3445 };
     3725double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const
     3726{
     3727  Info FunctionInfo(__func__);
     3728  TriangleIntersectionList Intersections(&Point, this, LC);
     3729
     3730  return Intersections.GetSmallestDistance();
     3731}
     3732;
     3733
     3734/** Calculates minimum distance from \a&Point to a tesselated surface.
     3735 * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
     3736 * \param &Point point to calculate distance from
     3737 * \param *LC needed for finding closest points fast
     3738 * \return distance squared to closest point on surface
     3739 */
     3740BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const
     3741{
     3742  Info FunctionInfo(__func__);
     3743  TriangleIntersectionList Intersections(&Point, this, LC);
     3744
     3745  return Intersections.GetClosestTriangle();
     3746}
     3747;
    34463748
    34473749/** Gets all points connected to the provided point by triangulation lines.
     
    34533755TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    34543756{
    3455         Info FunctionInfo(__func__);
    3456         TesselPointSet *connectedPoints = new TesselPointSet;
     3757  Info FunctionInfo(__func__);
     3758  TesselPointSet *connectedPoints = new TesselPointSet;
    34573759  class BoundaryPointSet *ReferencePoint = NULL;
    34583760  TesselPoint* current;
    34593761  bool takePoint = false;
    3460 
    34613762  // find the respective boundary point
    34623763  PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
     
    34643765    ReferencePoint = PointRunner->second;
    34653766  } else {
    3466     eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
     3767    DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
    34673768    ReferencePoint = NULL;
    34683769  }
     
    34703771  // little trick so that we look just through lines connect to the BoundaryPoint
    34713772  // OR fall-back to look through all lines if there is no such BoundaryPoint
    3472   const LineMap *Lines;;
     3773  const LineMap *Lines;
     3774  ;
    34733775  if (ReferencePoint != NULL)
    34743776    Lines = &(ReferencePoint->lines);
     
    34773779  LineMap::const_iterator findLines = Lines->begin();
    34783780  while (findLines != Lines->end()) {
    3479    takePoint = false;
    3480 
    3481    if (findLines->second->endpoints[0]->Nr == Point->nr) {
    3482      takePoint = true;
    3483      current = findLines->second->endpoints[1]->node;
    3484    } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
    3485      takePoint = true;
    3486      current = findLines->second->endpoints[0]->node;
    3487    }
    3488 
    3489    if (takePoint) {
    3490      Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
    3491      connectedPoints->insert(current);
    3492    }
    3493 
    3494    findLines++;
     3781    takePoint = false;
     3782
     3783    if (findLines->second->endpoints[0]->Nr == Point->nr) {
     3784      takePoint = true;
     3785      current = findLines->second->endpoints[1]->node;
     3786    } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
     3787      takePoint = true;
     3788      current = findLines->second->endpoints[0]->node;
     3789    }
     3790
     3791    if (takePoint) {
     3792      DoLog(1) && (Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl);
     3793      connectedPoints->insert(current);
     3794    }
     3795
     3796    findLines++;
    34953797  }
    34963798
    34973799  if (connectedPoints->empty()) { // if have not found any points
    3498     eLog() << Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl;
     3800    DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl);
    34993801    return NULL;
    35003802  }
    35013803
    35023804  return connectedPoints;
    3503 };
    3504 
     3805}
     3806;
    35053807
    35063808/** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
     
    35183820TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    35193821{
    3520         Info FunctionInfo(__func__);
     3822  Info FunctionInfo(__func__);
    35213823  map<double, TesselPoint*> anglesOfPoints;
    35223824  TesselPointList *connectedCircle = new TesselPointList;
     
    35253827  Vector OrthogonalVector;
    35263828  Vector helper;
    3527   const TesselPoint * const TrianglePoints[3] = {Point, NULL, NULL};
     3829  const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL };
    35283830  TriangleList *triangles = NULL;
    35293831
    35303832  if (SetOfNeighbours == NULL) {
    3531     eLog() << Verbose(2) << "Could not find any connected points!" << endl;
    3532     delete(connectedCircle);
     3833    DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
     3834    delete (connectedCircle);
    35333835    return NULL;
    35343836  }
     
    35403842      PlaneNormal.AddVector(&(*Runner)->NormalVector);
    35413843  } else {
    3542     eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl;
     3844    DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
    35433845    performCriticalExit();
    35443846  }
    3545   PlaneNormal.Scale(1.0/triangles->size());
    3546   Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl;
     3847  PlaneNormal.Scale(1.0 / triangles->size());
     3848  DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl);
    35473849  PlaneNormal.Normalize();
    35483850
     
    35533855    AngleZero.ProjectOntoPlane(&PlaneNormal);
    35543856  }
    3555   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    3556     Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
     3857  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
     3858    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
    35573859    AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    35583860    AngleZero.SubtractVector(Point->node);
    35593861    AngleZero.ProjectOntoPlane(&PlaneNormal);
    35603862    if (AngleZero.NormSquared() < MYEPSILON) {
    3561       eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
     3863      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
    35623864      performCriticalExit();
    35633865    }
    35643866  }
    3565   Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
     3867  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    35663868  if (AngleZero.NormSquared() > MYEPSILON)
    35673869    OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
    35683870  else
    35693871    OrthogonalVector.MakeNormalVector(&PlaneNormal);
    3570   Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
     3872  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    35713873
    35723874  // go through all connected points and calculate angle
     
    35763878    helper.ProjectOntoPlane(&PlaneNormal);
    35773879    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    3578     Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
    3579     anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
    3580   }
    3581 
    3582   for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
     3880    DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl);
     3881    anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
     3882  }
     3883
     3884  for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
    35833885    connectedCircle->push_back(AngleRunner->second);
    35843886  }
     
    36103912
    36113913  if (SetOfNeighbours == NULL) {
    3612     eLog() << Verbose(2) << "Could not find any connected points!" << endl;
    3613     delete(connectedCircle);
     3914    DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
     3915    delete (connectedCircle);
    36143916    return NULL;
    36153917  }
     
    36223924  }
    36233925
    3624   Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl;
     3926  DoLog(1) && (Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl);
    36253927  // calculate central point
    3626 
    36273928  TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
    36283929  TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
     
    36343935  while (TesselC != SetOfNeighbours->end()) {
    36353936    helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
    3636     Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl;
     3937    DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl);
    36373938    counter++;
    36383939    TesselA++;
     
    36433944  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
    36443945  //  << "; scale factor " << counter;
    3645   PlaneNormal.Scale(1.0/(double)counter);
    3646 //  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
    3647 //
    3648 //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
    3649 //  PlaneNormal.CopyVector(Point->node);
    3650 //  PlaneNormal.SubtractVector(&center);
    3651 //  PlaneNormal.Normalize();
    3652   Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
     3946  PlaneNormal.Scale(1.0 / (double) counter);
     3947  //  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
     3948  //
     3949  //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
     3950  //  PlaneNormal.CopyVector(Point->node);
     3951  //  PlaneNormal.SubtractVector(&center);
     3952  //  PlaneNormal.Normalize();
     3953  DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl);
    36533954
    36543955  // construct one orthogonal vector
     
    36583959    AngleZero.ProjectOntoPlane(&PlaneNormal);
    36593960  }
    3660   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    3661     Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
     3961  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
     3962    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
    36623963    AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    36633964    AngleZero.SubtractVector(Point->node);
    36643965    AngleZero.ProjectOntoPlane(&PlaneNormal);
    36653966    if (AngleZero.NormSquared() < MYEPSILON) {
    3666       eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
     3967      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
    36673968      performCriticalExit();
    36683969    }
    36693970  }
    3670   Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
     3971  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    36713972  if (AngleZero.NormSquared() > MYEPSILON)
    36723973    OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
    36733974  else
    36743975    OrthogonalVector.MakeNormalVector(&PlaneNormal);
    3675   Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
     3976  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    36763977
    36773978  // go through all connected points and calculate angle
    3678   pair <map<double, TesselPoint*>::iterator, bool > InserterTest;
     3979  pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
    36793980  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    36803981    helper.CopyVector((*listRunner)->node);
     
    36833984    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    36843985    if (angle > M_PI) // the correction is of no use here (and not desired)
    3685       angle = 2.*M_PI - angle;
    3686     Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl;
    3687     InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
     3986      angle = 2. * M_PI - angle;
     3987    DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl);
     3988    InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
    36883989    if (!InserterTest.second) {
    3689       eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl;
     3990      DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);
    36903991      performCriticalExit();
    36913992    }
    36923993  }
    36933994
    3694   for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
     3995  for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
    36953996    connectedCircle->push_back(AngleRunner->second);
    36963997  }
     
    37074008ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    37084009{
    3709         Info FunctionInfo(__func__);
     4010  Info FunctionInfo(__func__);
    37104011  map<double, TesselPoint*> anglesOfPoints;
    3711   list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;
     4012  list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ;
    37124013  TesselPointList *connectedPath = NULL;
    37134014  Vector center;
     
    37214022  class BoundaryLineSet *CurrentLine = NULL;
    37224023  class BoundaryLineSet *StartLine = NULL;
    3723 
    37244024  // find the respective boundary point
    37254025  PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
     
    37274027    ReferencePoint = PointRunner->second;
    37284028  } else {
    3729     eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
     4029    DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
    37304030    return NULL;
    37314031  }
    37324032
    3733   map <class BoundaryLineSet *, bool> TouchedLine;
    3734   map <class BoundaryTriangleSet *, bool> TouchedTriangle;
    3735   map <class BoundaryLineSet *, bool>::iterator LineRunner;
    3736   map <class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
     4033  map<class BoundaryLineSet *, bool> TouchedLine;
     4034  map<class BoundaryTriangleSet *, bool> TouchedTriangle;
     4035  map<class BoundaryLineSet *, bool>::iterator LineRunner;
     4036  map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
    37374037  for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
    3738     TouchedLine.insert( pair <class BoundaryLineSet *, bool>(Runner->second, false) );
     4038    TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false));
    37394039    for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
    3740       TouchedTriangle.insert( pair <class BoundaryTriangleSet *, bool>(Sprinter->second, false) );
     4040      TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false));
    37414041  }
    37424042  if (!ReferencePoint->lines.empty()) {
     
    37444044      LineRunner = TouchedLine.find(runner->second);
    37454045      if (LineRunner == TouchedLine.end()) {
    3746         eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl;
     4046        DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);
    37474047      } else if (!LineRunner->second) {
    37484048        LineRunner->second = true;
     
    37524052        StartLine = CurrentLine;
    37534053        CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
    3754         Log() << Verbose(1)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
     4054        DoLog(1) && (Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl);
    37554055        do {
    37564056          // push current one
    3757           Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     4057          DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
    37584058          connectedPath->push_back(CurrentPoint->node);
    37594059
    37604060          // find next triangle
    37614061          for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
    3762             Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
     4062            DoLog(1) && (Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl);
    37634063            if ((Runner->second != triangle)) { // look for first triangle not equal to old one
    37644064              triangle = Runner->second;
     
    37674067                if (!TriangleRunner->second) {
    37684068                  TriangleRunner->second = true;
    3769                   Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl;
     4069                  DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl);
    37704070                  break;
    37714071                } else {
    3772                   Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
     4072                  DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl);
    37734073                  triangle = NULL;
    37744074                }
    37754075              } else {
    3776                 eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl;
     4076                DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);
    37774077                triangle = NULL;
    37784078              }
     
    37824082            break;
    37834083          // find next line
    3784           for (int i=0;i<3;i++) {
     4084          for (int i = 0; i < 3; i++) {
    37854085            if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
    37864086              CurrentLine = triangle->lines[i];
    3787               Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
     4087              DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl);
    37884088              break;
    37894089            }
     
    37914091          LineRunner = TouchedLine.find(CurrentLine);
    37924092          if (LineRunner == TouchedLine.end())
    3793             eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl;
     4093            DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);
    37944094          else
    37954095            LineRunner->second = true;
     
    37994099        } while (CurrentLine != StartLine);
    38004100        // last point is missing, as it's on start line
    3801         Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     4101        DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
    38024102        if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
    38034103          connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
     
    38054105        ListOfPaths->push_back(connectedPath);
    38064106      } else {
    3807         Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
     4107        DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl);
    38084108      }
    38094109    }
    38104110  } else {
    3811     eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl;
     4111    DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);
    38124112  }
    38134113
     
    38234123ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    38244124{
    3825         Info FunctionInfo(__func__);
     4125  Info FunctionInfo(__func__);
    38264126  list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    3827   list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *>;
     4127  list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;
    38284128  TesselPointList *connectedPath = NULL;
    38294129  TesselPointList *newPath = NULL;
    38304130  int count = 0;
    3831 
    3832 
    38334131  TesselPointList::iterator CircleRunner;
    38344132  TesselPointList::iterator CircleStart;
    38354133
    3836   for(list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
     4134  for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
    38374135    connectedPath = *ListRunner;
    38384136
    3839     Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl;
     4137    DoLog(1) && (Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl);
    38404138
    38414139    // go through list, look for reappearance of starting Point and count
    38424140    CircleStart = connectedPath->begin();
    3843 
    38444141    // go through list, look for reappearance of starting Point and create list
    38454142    TesselPointList::iterator Marker = CircleStart;
     
    38474144      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    38484145        // we have a closed circle from Marker to new Marker
    3849         Log() << Verbose(1) << count+1 << ". closed path consists of: ";
     4146        DoLog(1) && (Log() << Verbose(1) << count + 1 << ". closed path consists of: ");
    38504147        newPath = new TesselPointList;
    38514148        TesselPointList::iterator CircleSprinter = Marker;
    38524149        for (; CircleSprinter != CircleRunner; CircleSprinter++) {
    38534150          newPath->push_back(*CircleSprinter);
    3854           Log() << Verbose(0) << (**CircleSprinter) << " <-> ";
     4151          DoLog(0) && (Log() << Verbose(0) << (**CircleSprinter) << " <-> ");
    38554152        }
    3856         Log() << Verbose(0) << ".." << endl;
     4153        DoLog(0) && (Log() << Verbose(0) << ".." << endl);
    38574154        count++;
    38584155        Marker = CircleRunner;
     
    38634160    }
    38644161  }
    3865   Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl;
     4162  DoLog(1) && (Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl);
    38664163
    38674164  // delete list of paths
     
    38694166    connectedPath = *(ListofPaths->begin());
    38704167    ListofPaths->remove(connectedPath);
    3871     delete(connectedPath);
    3872   }
    3873   delete(ListofPaths);
     4168    delete (connectedPath);
     4169  }
     4170  delete (ListofPaths);
    38744171
    38754172  // exit
    38764173  return ListofClosedPaths;
    3877 };
    3878 
     4174}
     4175;
    38794176
    38804177/** Gets all belonging triangles for a given BoundaryPointSet.
     
    38854182TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    38864183{
    3887         Info FunctionInfo(__func__);
    3888         TriangleSet *connectedTriangles = new TriangleSet;
     4184  Info FunctionInfo(__func__);
     4185  TriangleSet *connectedTriangles = new TriangleSet;
    38894186
    38904187  if (Point == NULL) {
    3891     eLog() << Verbose(1) << "Point given is NULL." << endl;
     4188    DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl);
    38924189  } else {
    38934190    // go through its lines and insert all triangles
    38944191    for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
    38954192      for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    3896       connectedTriangles->insert(TriangleRunner->second);
    3897     }
     4193        connectedTriangles->insert(TriangleRunner->second);
     4194      }
    38984195  }
    38994196
    39004197  return connectedTriangles;
    3901 };
    3902 
     4198}
     4199;
    39034200
    39044201/** Removes a boundary point from the envelope while keeping it closed.
     
    39134210 * \return volume added to the volume inside the tesselated surface by the removal
    39144211 */
    3915 double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) {
     4212double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point)
     4213{
    39164214  class BoundaryLineSet *line = NULL;
    39174215  class BoundaryTriangleSet *triangle = NULL;
     
    39214219
    39224220  if (point == NULL) {
    3923     eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl;
     4221    DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);
    39244222    return 0.;
    39254223  } else
    3926     Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl;
     4224    DoLog(0) && (Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl);
    39274225
    39284226  // copy old location for the volume
     
    39314229  // get list of connected points
    39324230  if (point->lines.empty()) {
    3933     eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl;
     4231    DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);
    39344232    return 0.;
    39354233  }
     
    39404238  // gather all triangles
    39414239  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
    3942     count+=LineRunner->second->triangles.size();
     4240    count += LineRunner->second->triangles.size();
    39434241  TriangleMap Candidates;
    39444242  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
     
    39464244    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    39474245      triangle = TriangleRunner->second;
    3948       Candidates.insert( TrianglePair (triangle->Nr, triangle) );
     4246      Candidates.insert(TrianglePair(triangle->Nr, triangle));
    39494247    }
    39504248  }
    39514249
    39524250  // remove all triangles
    3953   count=0;
     4251  count = 0;
    39544252  NormalVector.Zero();
    39554253  for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    3956     Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl;
     4254    DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl);
    39574255    NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
    39584256    RemoveTesselationTriangle(Runner->second);
    39594257    count++;
    39604258  }
    3961   Log() << Verbose(1) << count << " triangles were removed." << endl;
     4259  DoLog(1) && (Log() << Verbose(1) << count << " triangles were removed." << endl);
    39624260
    39634261  list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
     
    39684266  double smallestangle;
    39694267  Vector Point, Reference, OrthogonalVector;
    3970   if (count > 2) {  // less than three triangles, then nothing will be created
     4268  if (count > 2) { // less than three triangles, then nothing will be created
    39714269    class TesselPoint *TriangleCandidates[3];
    39724270    count = 0;
    3973     for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
     4271    for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
    39744272      if (ListAdvance != ListOfClosedPaths->end())
    39754273        ListAdvance++;
    39764274
    39774275      connectedPath = *ListRunner;
    3978 
    39794276      // re-create all triangles by going through connected points list
    39804277      LineList NewLines;
    3981       for (;!connectedPath->empty();) {
     4278      for (; !connectedPath->empty();) {
    39824279        // search middle node with widest angle to next neighbours
    39834280        EndNode = connectedPath->end();
    39844281        smallestangle = 0.;
    39854282        for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
    3986           Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
     4283          DoLog(1) && (Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
    39874284          // construct vectors to next and previous neighbour
    39884285          StartNode = MiddleNode;
     
    40054302          angle = GetAngle(Point, Reference, OrthogonalVector);
    40064303          //if (angle < M_PI)  // no wrong-sided triangles, please?
    4007             if(fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
    4008               smallestangle = angle;
    4009               EndNode = MiddleNode;
    4010             }
     4304          if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
     4305            smallestangle = angle;
     4306            EndNode = MiddleNode;
     4307          }
    40114308        }
    40124309        MiddleNode = EndNode;
    40134310        if (MiddleNode == connectedPath->end()) {
    4014           eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl;
     4311          DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);
    40154312          performCriticalExit();
    40164313        }
     
    40224319        if (EndNode == connectedPath->end())
    40234320          EndNode = connectedPath->begin();
    4024         Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl;
    4025         Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
    4026         Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl;
    4027         Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;
     4321        DoLog(2) && (Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl);
     4322        DoLog(2) && (Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
     4323        DoLog(2) && (Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl);
     4324        DoLog(1) && (Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl);
    40284325        TriangleCandidates[0] = *StartNode;
    40294326        TriangleCandidates[1] = *MiddleNode;
     
    40314328        triangle = GetPresentTriangle(TriangleCandidates);
    40324329        if (triangle != NULL) {
    4033           eLog() << Verbose(0) << "New triangle already present, skipping!" << endl;
     4330          DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl);
    40344331          StartNode++;
    40354332          MiddleNode++;
     
    40434340          continue;
    40444341        }
    4045         Log() << Verbose(3) << "Adding new triangle points."<< endl;
     4342        DoLog(3) && (Log() << Verbose(3) << "Adding new triangle points." << endl);
    40464343        AddTesselationPoint(*StartNode, 0);
    40474344        AddTesselationPoint(*MiddleNode, 1);
    40484345        AddTesselationPoint(*EndNode, 2);
    4049         Log() << Verbose(3) << "Adding new triangle lines."<< endl;
    4050         AddTesselationLine(TPS[0], TPS[1], 0);
    4051         AddTesselationLine(TPS[0], TPS[2], 1);
     4346        DoLog(3) && (Log() << Verbose(3) << "Adding new triangle lines." << endl);
     4347        AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     4348        AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
    40524349        NewLines.push_back(BLS[1]);
    4053         AddTesselationLine(TPS[1], TPS[2], 2);
     4350        AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    40544351        BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    40554352        BTS->GetNormalVector(NormalVector);
     
    40624359        // prepare nodes for next triangle
    40634360        StartNode = EndNode;
    4064         Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
     4361        DoLog(2) && (Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl);
    40654362        connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
    40664363        if (connectedPath->size() == 2) { // we are done
     
    40694366          break;
    40704367        } else if (connectedPath->size() < 2) { // something's gone wrong!
    4071           eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl;
     4368          DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);
    40724369          performCriticalExit();
    40734370        } else {
     
    40894386        do {
    40904387          maxgain = 0;
    4091           for(LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
     4388          for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
    40924389            tmp = PickFarthestofTwoBaselines(*Runner);
    40934390            if (maxgain < tmp) {
     
    40984395          if (maxgain != 0) {
    40994396            volume += maxgain;
    4100             Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
     4397            DoLog(1) && (Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl);
    41014398            OtherBase = FlipBaseline(*Candidate);
    41024399            NewLines.erase(Candidate);
     
    41074404
    41084405      ListOfClosedPaths->remove(connectedPath);
    4109       delete(connectedPath);
    4110     }
    4111     Log() << Verbose(0) << count << " triangles were created." << endl;
     4406      delete (connectedPath);
     4407    }
     4408    DoLog(0) && (Log() << Verbose(0) << count << " triangles were created." << endl);
    41124409  } else {
    41134410    while (!ListOfClosedPaths->empty()) {
     
    41154412      connectedPath = *ListRunner;
    41164413      ListOfClosedPaths->remove(connectedPath);
    4117       delete(connectedPath);
    4118     }
    4119     Log() << Verbose(0) << "No need to create any triangles." << endl;
    4120   }
    4121   delete(ListOfClosedPaths);
    4122 
    4123   Log() << Verbose(0) << "Removed volume is " << volume << "." << endl;
     4414      delete (connectedPath);
     4415    }
     4416    DoLog(0) && (Log() << Verbose(0) << "No need to create any triangles." << endl);
     4417  }
     4418  delete (ListOfClosedPaths);
     4419
     4420  DoLog(0) && (Log() << Verbose(0) << "Removed volume is " << volume << "." << endl);
    41244421
    41254422  return volume;
    4126 };
    4127 
    4128 
     4423}
     4424;
    41294425
    41304426/**
     
    41384434TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    41394435{
    4140         Info FunctionInfo(__func__);
    4141         TriangleList *result = new TriangleList;
     4436  Info FunctionInfo(__func__);
     4437  TriangleList *result = new TriangleList;
    41424438  LineMap::const_iterator FindLine;
    41434439  TriangleMap::const_iterator FindTriangle;
     
    41634459      for (int i = 0; i < 3; i++) {
    41644460        if (TrianglePoints[i] != NULL) {
    4165           for (int j = i+1; j < 3; j++) {
     4461          for (int j = i + 1; j < 3; j++) {
    41664462            if (TrianglePoints[j] != NULL) {
    41674463              for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
    4168                   (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
    4169                   FindLine++) {
    4170                 for (FindTriangle = FindLine->second->triangles.begin();
    4171                     FindTriangle != FindLine->second->triangles.end();
    4172                     FindTriangle++) {
     4464              (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) {
     4465                for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
    41734466                  if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    41744467                    result->push_back(FindTriangle->second);
     
    41854478    case 1: // copy all triangles of the respective line
    41864479    {
    4187       int i=0;
     4480      int i = 0;
    41884481      for (; i < 3; i++)
    41894482        if (TrianglePoints[i] == NULL)
    41904483          break;
    4191       for (FindLine = TrianglePoints[(i+1)%3]->lines.find(TrianglePoints[(i+2)%3]->node->nr); // is a multimap!
    4192           (FindLine != TrianglePoints[(i+1)%3]->lines.end()) && (FindLine->first == TrianglePoints[(i+2)%3]->node->nr);
    4193           FindLine++) {
    4194         for (FindTriangle = FindLine->second->triangles.begin();
    4195             FindTriangle != FindLine->second->triangles.end();
    4196             FindTriangle++) {
     4484      for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap!
     4485      (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) {
     4486        for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
    41974487          if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    41984488            result->push_back(FindTriangle->second);
     
    42044494    case 2: // copy all triangles of the respective point
    42054495    {
    4206       int i=0;
     4496      int i = 0;
    42074497      for (; i < 3; i++)
    42084498        if (TrianglePoints[i] != NULL)
     
    42224512    }
    42234513    default:
    4224       eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl;
     4514      DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);
    42254515      performCriticalExit();
    42264516      break;
     
    42304520}
    42314521
    4232 struct BoundaryLineSetCompare {
    4233   bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) {
     4522struct BoundaryLineSetCompare
     4523{
     4524  bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b)
     4525  {
    42344526    int lowerNra = -1;
    42354527    int lowerNrb = -1;
     
    42494541    else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
    42504542      return false;
    4251     else {  // both lower-numbered endpoints are the same ...
    4252      if (a->endpoints[(lowerNra+1)%2] < b->endpoints[(lowerNrb+1)%2])
    4253        return true;
    4254      else if (a->endpoints[(lowerNra+1)%2] > b->endpoints[(lowerNrb+1)%2])
    4255        return false;
     4543    else { // both lower-numbered endpoints are the same ...
     4544      if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2])
     4545        return true;
     4546      else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2])
     4547        return false;
    42564548    }
    42574549    return false;
    4258   };
     4550  }
     4551  ;
    42594552};
    42604553
     
    42694562IndexToIndex * Tesselation::FindAllDegeneratedLines()
    42704563{
    4271         Info FunctionInfo(__func__);
    4272         UniqueLines AllLines;
     4564  Info FunctionInfo(__func__);
     4565  UniqueLines AllLines;
    42734566  IndexToIndex * DegeneratedLines = new IndexToIndex;
    42744567
    42754568  // sanity check
    42764569  if (LinesOnBoundary.empty()) {
    4277     eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.";
     4570    DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");
    42784571    return DegeneratedLines;
    42794572  }
    4280 
    42814573  LineMap::iterator LineRunner1;
    4282   pair< UniqueLines::iterator, bool> tester;
     4574  pair<UniqueLines::iterator, bool> tester;
    42834575  for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
    4284     tester = AllLines.insert( LineRunner1->second );
     4576    tester = AllLines.insert(LineRunner1->second);
    42854577    if (!tester.second) { // found degenerated line
    4286       DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr) );
    4287       DegeneratedLines->insert ( pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr) );
     4578      DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));
     4579      DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));
    42884580    }
    42894581  }
     
    42914583  AllLines.clear();
    42924584
    4293   Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
     4585  DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl);
    42944586  IndexToIndex::iterator it;
    42954587  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
     
    42974589    const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
    42984590    if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
    4299       Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl;
     4591      DoLog(0) && (Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl);
    43004592    else
    4301       eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl;
     4593      DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);
    43024594  }
    43034595
     
    43134605IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
    43144606{
    4315         Info FunctionInfo(__func__);
     4607  Info FunctionInfo(__func__);
    43164608  IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
    43174609  IndexToIndex * DegeneratedTriangles = new IndexToIndex;
    4318 
    43194610  TriangleMap::iterator TriangleRunner1, TriangleRunner2;
    43204611  LineMap::iterator Liner;
     
    43314622    for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
    43324623      for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
    4333         if ((TriangleRunner1->second != TriangleRunner2->second)
    4334           && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
    4335           DegeneratedTriangles->insert( pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr) );
    4336           DegeneratedTriangles->insert( pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr) );
     4624        if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
     4625          DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr));
     4626          DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr));
    43374627        }
    43384628      }
    43394629    }
    43404630  }
    4341   delete(DegeneratedLines);
    4342 
    4343   Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
     4631  delete (DegeneratedLines);
     4632
     4633  DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl);
    43444634  IndexToIndex::iterator it;
    43454635  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    4346       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     4636    DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
    43474637
    43484638  return DegeneratedTriangles;
     
    43554645void Tesselation::RemoveDegeneratedTriangles()
    43564646{
    4357         Info FunctionInfo(__func__);
     4647  Info FunctionInfo(__func__);
    43584648  IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
    43594649  TriangleMap::iterator finder;
    43604650  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    4361   int count  = 0;
    4362 
    4363   for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
    4364     TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
    4365   ) {
     4651  int count = 0;
     4652
     4653  for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) {
    43664654    finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
    43674655    if (finder != TrianglesOnBoundary.end())
     
    43804668        trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
    43814669
    4382     if (trianglesShareLine
    4383       && (triangle->endpoints[1]->LinesCount > 2)
    4384       && (triangle->endpoints[2]->LinesCount > 2)
    4385       && (triangle->endpoints[0]->LinesCount > 2)
    4386     ) {
     4670    if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) {
    43874671      // check whether we have to fix lines
    43884672      BoundaryTriangleSet *Othertriangle = NULL;
     
    44044688            // the line of triangle receives the degenerated ones
    44054689            triangle->lines[i]->triangles.erase(Othertriangle->Nr);
    4406             triangle->lines[i]->triangles.insert( TrianglePair( partnerTriangle->Nr, partnerTriangle) );
    4407             for (int k=0;k<3;k++)
     4690            triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle));
     4691            for (int k = 0; k < 3; k++)
    44084692              if (triangle->lines[i] == Othertriangle->lines[k]) {
    44094693                Othertriangle->lines[k] = partnerTriangle->lines[j];
     
    44114695              }
    44124696            // the line of partnerTriangle receives the non-degenerated ones
    4413             partnerTriangle->lines[j]->triangles.erase( partnerTriangle->Nr);
    4414             partnerTriangle->lines[j]->triangles.insert( TrianglePair( Othertriangle->Nr, Othertriangle) );
     4697            partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr);
     4698            partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle));
    44154699            partnerTriangle->lines[j] = triangle->lines[i];
    44164700          }
     
    44184702      // erase the pair
    44194703      count += (int) DegeneratedTriangles->erase(triangle->Nr);
    4420       Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
     4704      DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl);
    44214705      RemoveTesselationTriangle(triangle);
    44224706      count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
    4423       Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
     4707      DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl);
    44244708      RemoveTesselationTriangle(partnerTriangle);
    44254709    } else {
    4426       Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
    4427         << " and its partner " << *partnerTriangle << " because it is essential for at"
    4428         << " least one of the endpoints to be kept in the tesselation structure." << endl;
    4429     }
    4430   }
    4431   delete(DegeneratedTriangles);
     4710      DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle << " and its partner " << *partnerTriangle << " because it is essential for at" << " least one of the endpoints to be kept in the tesselation structure." << endl);
     4711    }
     4712  }
     4713  delete (DegeneratedTriangles);
    44324714  if (count > 0)
    44334715    LastTriangle = NULL;
    44344716
    4435   Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
     4717  DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl);
    44364718}
    44374719
     
    44464728void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
    44474729{
    4448         Info FunctionInfo(__func__);
     4730  Info FunctionInfo(__func__);
    44494731  // find nearest boundary point
    44504732  class TesselPoint *BackupPoint = NULL;
     
    44594741    NearestBoundaryPoint = PointRunner->second;
    44604742  } else {
    4461     eLog() << Verbose(1) << "I cannot find the boundary point." << endl;
     4743    DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl);
    44624744    return;
    44634745  }
    4464   Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
     4746  DoLog(0) && (Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl);
    44654747
    44664748  // go through its lines and find the best one to split
     
    44774759    CenterToPoint.SubtractVector(point->node);
    44784760    angle = CenterToPoint.Angle(&BaseLine);
    4479     if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
     4761    if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) {
    44804762      BestAngle = angle;
    44814763      BestLine = Runner->second;
     
    44874769  BestLine->triangles.erase(TempTriangle->Nr);
    44884770  int nr = -1;
    4489   for (int i=0;i<3; i++) {
     4771  for (int i = 0; i < 3; i++) {
    44904772    if (TempTriangle->lines[i] == BestLine) {
    44914773      nr = i;
     
    44954777
    44964778  // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
    4497   Log() << Verbose(2) << "Adding new triangle points."<< endl;
     4779  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
    44984780  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    44994781  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    45004782  AddTesselationPoint(point, 2);
    4501   Log() << Verbose(2) << "Adding new triangle lines."<< endl;
    4502   AddTesselationLine(TPS[0], TPS[1], 0);
    4503   AddTesselationLine(TPS[0], TPS[2], 1);
    4504   AddTesselationLine(TPS[1], TPS[2], 2);
     4783  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
     4784  AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     4785  AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     4786  AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    45054787  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    45064788  BTS->GetNormalVector(TempTriangle->NormalVector);
    45074789  BTS->NormalVector.Scale(-1.);
    4508   Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
     4790  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl);
    45094791  AddTesselationTriangle();
    45104792
    45114793  // create other side of this triangle and close both new sides of the first created triangle
    4512   Log() << Verbose(2) << "Adding new triangle points."<< endl;
     4794  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
    45134795  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    45144796  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    45154797  AddTesselationPoint(point, 2);
    4516   Log() << Verbose(2) << "Adding new triangle lines."<< endl;
    4517   AddTesselationLine(TPS[0], TPS[1], 0);
    4518   AddTesselationLine(TPS[0], TPS[2], 1);
    4519   AddTesselationLine(TPS[1], TPS[2], 2);
     4798  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
     4799  AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     4800  AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     4801  AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    45204802  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    45214803  BTS->GetNormalVector(TempTriangle->NormalVector);
    4522   Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
     4804  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl);
    45234805  AddTesselationTriangle();
    45244806
    45254807  // add removed triangle to the last open line of the second triangle
    4526   for (int i=0;i<3;i++) { // look for the same line as BestLine (only it's its degenerated companion)
     4808  for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion)
    45274809    if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
    4528       if (BestLine == BTS->lines[i]){
    4529         eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl;
     4810      if (BestLine == BTS->lines[i]) {
     4811        DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl);
    45304812        performCriticalExit();
    45314813      }
    4532       BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle) );
     4814      BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));
    45334815      TempTriangle->lines[nr] = BTS->lines[i];
    45344816      break;
    45354817    }
    45364818  }
    4537 };
     4819}
     4820;
    45384821
    45394822/** Writes the envelope to file.
     
    45444827void Tesselation::Output(const char *filename, const PointCloud * const cloud)
    45454828{
    4546         Info FunctionInfo(__func__);
     4829  Info FunctionInfo(__func__);
    45474830  ofstream *tempstream = NULL;
    45484831  string NameofTempFile;
     
    45504833
    45514834  if (LastTriangle != NULL) {
    4552     sprintf(NumberName, "-%04d-%s_%s_%s", (int)TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);
     4835    sprintf(NumberName, "-%04d-%s_%s_%s", (int) TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);
    45534836    if (DoTecplotOutput) {
    45544837      string NameofTempFile(filename);
    45554838      NameofTempFile.append(NumberName);
    4556       for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
    4557       NameofTempFile.erase(npos, 1);
     4839      for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
     4840        NameofTempFile.erase(npos, 1);
    45584841      NameofTempFile.append(TecplotSuffix);
    4559       Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     4842      DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
    45604843      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    45614844      WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
    45624845      tempstream->close();
    45634846      tempstream->flush();
    4564       delete(tempstream);
     4847      delete (tempstream);
    45654848    }
    45664849
     
    45684851      string NameofTempFile(filename);
    45694852      NameofTempFile.append(NumberName);
    4570       for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
    4571       NameofTempFile.erase(npos, 1);
     4853      for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
     4854        NameofTempFile.erase(npos, 1);
    45724855      NameofTempFile.append(Raster3DSuffix);
    4573       Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     4856      DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
    45744857      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    45754858      WriteRaster3dFile(tempstream, this, cloud);
     
    45774860      tempstream->close();
    45784861      tempstream->flush();
    4579       delete(tempstream);
     4862      delete (tempstream);
    45804863    }
    45814864  }
    45824865  if (DoTecplotOutput || DoRaster3DOutput)
    45834866    TriangleFilesWritten++;
    4584 };
    4585 
    4586 struct BoundaryPolygonSetCompare {
    4587   bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const {
     4867}
     4868;
     4869
     4870struct BoundaryPolygonSetCompare
     4871{
     4872  bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const
     4873  {
    45884874    if (s1->endpoints.size() < s2->endpoints.size())
    45894875      return true;
     
    46144900{
    46154901  Info FunctionInfo(__func__);
    4616 
    46174902  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
    46184903  IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
    4619   set < BoundaryPointSet *> EndpointCandidateList;
    4620   pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
    4621   pair < map < int, Vector *>::iterator, bool > TriangleInsertionTester;
     4904  set<BoundaryPointSet *> EndpointCandidateList;
     4905  pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester;
     4906  pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester;
    46224907  for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
    4623     Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl;
    4624     map < int, Vector *> TriangleVectors;
     4908    DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl);
     4909    map<int, Vector *> TriangleVectors;
    46254910    // gather all NormalVectors
    4626     Log() << Verbose(1) << "Gathering triangles ..." << endl;
     4911    DoLog(1) && (Log() << Verbose(1) << "Gathering triangles ..." << endl);
    46274912    for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
    46284913      for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    46294914        if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
    4630           TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) );
     4915          TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));
    46314916          if (TriangleInsertionTester.second)
    4632             Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;
     4917            DoLog(1) && (Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl);
    46334918        } else {
    4634           Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl;
     4919          DoLog(1) && (Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl);
    46354920        }
    46364921      }
    46374922    // check whether there are two that are parallel
    4638     Log() << Verbose(1) << "Finding two parallel triangles ..." << endl;
    4639     for (map < int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
    4640       for (map < int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
     4923    DoLog(1) && (Log() << Verbose(1) << "Finding two parallel triangles ..." << endl);
     4924    for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
     4925      for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
    46414926        if (VectorWalker != VectorRunner) { // skip equals
    4642           const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second);  // ScalarProduct should result in -1. for degenerated triangles
    4643           Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl;
     4927          const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
     4928          DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl);
    46444929          if (fabs(SCP + 1.) < ParallelEpsilon) {
    46454930            InsertionTester = EndpointCandidateList.insert((Runner->second));
    46464931            if (InsertionTester.second)
    4647               Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl;
     4932              DoLog(0) && (Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl);
    46484933            // and break out of both loops
    46494934            VectorWalker = TriangleVectors.end();
     
    46534938        }
    46544939  }
    4655 
     4940  delete (DegeneratedTriangles);
    46564941  /// 3. Find connected endpoint candidates and put them into a polygon
    46574942  UniquePolygonSet ListofDegeneratedPolygons;
     
    46594944  BoundaryPointSet *OtherWalker = NULL;
    46604945  BoundaryPolygonSet *Current = NULL;
    4661   stack <BoundaryPointSet*> ToCheckConnecteds;
     4946  stack<BoundaryPointSet*> ToCheckConnecteds;
    46624947  while (!EndpointCandidateList.empty()) {
    46634948    Walker = *(EndpointCandidateList.begin());
    4664     if (Current == NULL) {  // create a new polygon with current candidate
    4665       Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl;
     4949    if (Current == NULL) { // create a new polygon with current candidate
     4950      DoLog(0) && (Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl);
    46664951      Current = new BoundaryPolygonSet;
    46674952      Current->endpoints.insert(Walker);
     
    46764961      for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
    46774962        OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
    4678         Log() << Verbose(1) << "Checking " << *OtherWalker << endl;
    4679         set < BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
    4680         if (Finder != EndpointCandidateList.end()) {  // found a connected partner
    4681           Log() << Verbose(1) << " Adding to polygon." << endl;
     4963        DoLog(1) && (Log() << Verbose(1) << "Checking " << *OtherWalker << endl);
     4964        set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
     4965        if (Finder != EndpointCandidateList.end()) { // found a connected partner
     4966          DoLog(1) && (Log() << Verbose(1) << " Adding to polygon." << endl);
    46824967          Current->endpoints.insert(OtherWalker);
    4683           EndpointCandidateList.erase(Finder);  // remove from candidates
    4684           ToCheckConnecteds.push(OtherWalker);  // but check its partners too
     4968          EndpointCandidateList.erase(Finder); // remove from candidates
     4969          ToCheckConnecteds.push(OtherWalker); // but check its partners too
    46854970        } else {
    4686           Log() << Verbose(1) << " is not connected to " << *Walker << endl;
     4971          DoLog(1) && (Log() << Verbose(1) << " is not connected to " << *Walker << endl);
    46874972        }
    46884973      }
    46894974    }
    46904975
    4691     Log() << Verbose(0) << "Final polygon is " << *Current << endl;
     4976    DoLog(0) && (Log() << Verbose(0) << "Final polygon is " << *Current << endl);
    46924977    ListofDegeneratedPolygons.insert(Current);
    46934978    Current = NULL;
     
    46964981  const int counter = ListofDegeneratedPolygons.size();
    46974982
    4698   Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl;
     4983  DoLog(0) && (Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl);
    46994984  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
    4700     Log() << Verbose(0) << " " << **PolygonRunner << endl;
     4985    DoLog(0) && (Log() << Verbose(0) << " " << **PolygonRunner << endl);
    47014986
    47024987  /// 4. Go through all these degenerated polygons
    47034988  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
    4704     stack <int> TriangleNrs;
     4989    stack<int> TriangleNrs;
    47054990    Vector NormalVector;
    47064991    /// 4a. Gather all triangles of this polygon
     
    47094994    // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do.
    47104995    if (T->size() == 2) {
    4711       Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl;
    4712       delete(T);
     4996      DoLog(1) && (Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl);
     4997      delete (T);
    47134998      continue;
    47144999    }
     
    47195004    // connections to either polygon ...
    47205005    if (T->size() % 2 != 0) {
    4721       eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl;
     5006      DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);
    47225007      performCriticalExit();
    47235008    }
    4724 
    4725     TriangleSet::iterator TriangleWalker = T->begin();  // is the inner iterator
     5009    TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
    47265010    /// 4a. Get NormalVector for one side (this is "front")
    47275011    NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
    4728     Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl;
     5012    DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl);
    47295013    TriangleWalker++;
    47305014    TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
     
    47355019      triangle = *TriangleWalker;
    47365020      TriangleSprinter++;
    4737       Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl;
     5021      DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl);
    47385022      if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
    4739         Log() << Verbose(1) << " Removing ... " << endl;
     5023        DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl);
    47405024        TriangleNrs.push(triangle->Nr);
    47415025        T->erase(TriangleWalker);
    47425026        RemoveTesselationTriangle(triangle);
    47435027      } else
    4744         Log() << Verbose(1) << " Keeping ... " << endl;
     5028        DoLog(1) && (Log() << Verbose(1) << " Keeping ... " << endl);
    47455029    }
    47465030    /// 4c. Copy all "front" triangles but with inverse NormalVector
    47475031    TriangleWalker = T->begin();
    4748     while (TriangleWalker != T->end()) {  // go through all front triangles
    4749       Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl;
     5032    while (TriangleWalker != T->end()) { // go through all front triangles
     5033      DoLog(1) && (Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl);
    47505034      for (int i = 0; i < 3; i++)
    47515035        AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
    4752       AddTesselationLine(TPS[0], TPS[1], 0);
    4753       AddTesselationLine(TPS[0], TPS[2], 1);
    4754       AddTesselationLine(TPS[1], TPS[2], 2);
     5036      AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     5037      AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     5038      AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    47555039      if (TriangleNrs.empty())
    4756         eLog() << Verbose(0) << "No more free triangle numbers!" << endl;
     5040        DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl);
    47575041      BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
    47585042      AddTesselationTriangle(); // ... and add
     
    47635047    }
    47645048    if (!TriangleNrs.empty()) {
    4765       eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl;
    4766     }
    4767     delete(T);  // remove the triangleset
    4768   }
    4769 
     5049      DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl);
     5050    }
     5051    delete (T); // remove the triangleset
     5052  }
    47705053  IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
    4771   Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
     5054  DoLog(0) && (Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl);
    47725055  IndexToIndex::iterator it;
    47735056  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
    4774       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
    4775   delete(SimplyDegeneratedTriangles);
    4776 
     5057    DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
     5058  delete (SimplyDegeneratedTriangles);
    47775059  /// 5. exit
    47785060  UniquePolygonSet::iterator PolygonRunner;
    47795061  while (!ListofDegeneratedPolygons.empty()) {
    47805062    PolygonRunner = ListofDegeneratedPolygons.begin();
    4781     delete(*PolygonRunner);
     5063    delete (*PolygonRunner);
    47825064    ListofDegeneratedPolygons.erase(PolygonRunner);
    47835065  }
    47845066
    47855067  return counter;
    4786 };
     5068}
     5069;
Note: See TracChangeset for help on using the changeset viewer.