Changeset 190326 for src/tesselation.cpp


Ignore:
Timestamp:
Jun 2, 2010, 11:19:27 AM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, Candidate_v1.7.0, Candidate_v1.7.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
5f5a7b, 67c75b
Parents:
9cf88c (diff), 27ac00 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'StructureRefactoring' into MenuRefactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tesselation.cpp

    r9cf88c r190326  
    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"
     19#include "Line.hpp"
     20#include "vector_ops.hpp"
    1721#include "verbose.hpp"
     22#include "Plane.hpp"
     23#include "Exceptions/LinearDependenceException.hpp"
     24#include "Helpers/Assert.hpp"
    1825
    1926class molecule;
     
    2431 */
    2532BoundaryPointSet::BoundaryPointSet() :
    26     LinesCount(0),
    27     value(0.),
    28     Nr(-1)
    29 {
    30         Info FunctionInfo(__func__);
    31         Log() << Verbose(1) << "Adding noname." << endl;
    32 };
     33  LinesCount(0), value(0.), Nr(-1)
     34{
     35  Info FunctionInfo(__func__);
     36  DoLog(1) && (Log() << Verbose(1) << "Adding noname." << endl);
     37}
     38;
    3339
    3440/** Constructor of BoundaryPointSet with Tesselpoint.
     
    3642 */
    3743BoundaryPointSet::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 };
     44  LinesCount(0), node(Walker), value(0.), Nr(Walker->nr)
     45{
     46  Info FunctionInfo(__func__);
     47  DoLog(1) && (Log() << Verbose(1) << "Adding Node " << *Walker << endl);
     48}
     49;
    4650
    4751/** Destructor of BoundaryPointSet.
     
    5155BoundaryPointSet::~BoundaryPointSet()
    5256{
    53         Info FunctionInfo(__func__);
     57  Info FunctionInfo(__func__);
    5458  //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
    5559  if (!lines.empty())
    56     eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl;
     60    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);
    5761  node = NULL;
    58 };
     62}
     63;
    5964
    6065/** Add a line to the LineMap of this point.
     
    6368void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
    6469{
    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     }
     70  Info FunctionInfo(__func__);
     71  DoLog(1) && (Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl);
     72  if (line->endpoints[0] == this) {
     73    lines.insert(LinePair(line->endpoints[1]->Nr, line));
     74  } else {
     75    lines.insert(LinePair(line->endpoints[0]->Nr, line));
     76  }
    7677  LinesCount++;
    77 };
     78}
     79;
    7880
    7981/** output operator for BoundaryPointSet.
     
    8385ostream & operator <<(ostream &ost, const BoundaryPointSet &a)
    8486{
    85   ost << "[" << a.Nr << "|" << a.node->Name << " at " << *a.node->node << "]";
     87  ost << "[" << a.Nr << "|" << a.node->getName() << " at " << *a.node->node << "]";
    8688  return ost;
    8789}
     
    9395 */
    9496BoundaryLineSet::BoundaryLineSet() :
    95     Nr(-1)
    96 {
    97         Info FunctionInfo(__func__);
     97  Nr(-1)
     98{
     99  Info FunctionInfo(__func__);
    98100  for (int i = 0; i < 2; i++)
    99101    endpoints[i] = NULL;
    100 };
     102}
     103;
    101104
    102105/** Constructor of BoundaryLineSet with two endpoints.
     
    107110BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
    108111{
    109         Info FunctionInfo(__func__);
     112  Info FunctionInfo(__func__);
    110113  // set number
    111114  Nr = number;
     
    118121  skipped = false;
    119122  // clear triangles list
    120   Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
    121 };
     123  DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
     124}
     125;
    122126
    123127/** Constructor of BoundaryLineSet with two endpoints.
     
    140144  skipped = false;
    141145  // clear triangles list
    142   Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
    143 };
     146  DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
     147}
     148;
    144149
    145150/** Destructor for BoundaryLineSet.
     
    149154BoundaryLineSet::~BoundaryLineSet()
    150155{
    151         Info FunctionInfo(__func__);
     156  Info FunctionInfo(__func__);
    152157  int Numbers[2];
    153158
     
    180185        //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
    181186        if (endpoints[i] != NULL) {
    182           delete(endpoints[i]);
     187          delete (endpoints[i]);
    183188          endpoints[i] = NULL;
    184189        }
     
    187192  }
    188193  if (!triangles.empty())
    189     eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl;
    190 };
     194    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
     195}
     196;
    191197
    192198/** Add triangle to TriangleMap of this boundary line.
     
    195201void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
    196202{
    197         Info FunctionInfo(__func__);
    198   Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
     203  Info FunctionInfo(__func__);
     204  DoLog(0) && (Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl);
    199205  triangles.insert(TrianglePair(triangle->Nr, triangle));
    200 };
     206}
     207;
    201208
    202209/** Checks whether we have a common endpoint with given \a *line.
     
    206213bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
    207214{
    208         Info FunctionInfo(__func__);
     215  Info FunctionInfo(__func__);
    209216  if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
    210217    return true;
    211218  else
    212219    return false;
    213 };
     220}
     221;
    214222
    215223/** Checks whether the adjacent triangles of a baseline are convex or not.
     
    221229bool BoundaryLineSet::CheckConvexityCriterion() const
    222230{
    223         Info FunctionInfo(__func__);
     231  Info FunctionInfo(__func__);
    224232  Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
    225233  // get the two triangles
    226234  if (triangles.size() != 2) {
    227     eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
     235    DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
    228236    return true;
    229237  }
     
    231239  // have a normal vector on the base line pointing outwards
    232240  //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
    233   BaseLineCenter.CopyVector(endpoints[0]->node->node);
    234   BaseLineCenter.AddVector(endpoints[1]->node->node);
    235   BaseLineCenter.Scale(1./2.);
    236   BaseLine.CopyVector(endpoints[0]->node->node);
    237   BaseLine.SubtractVector(endpoints[1]->node->node);
     241  BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node));
     242  BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node);
     243
    238244  //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
    239245
     
    241247  NormalCheck.Zero();
    242248  double sign = -1.;
    243   int i=0;
     249  int i = 0;
    244250  class BoundaryPointSet *node = NULL;
    245   for(TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
     251  for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    246252    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    247     NormalCheck.AddVector(&runner->second->NormalVector);
    248     NormalCheck.Scale(sign);
     253    NormalCheck += runner->second->NormalVector;
     254    NormalCheck *= sign;
    249255    sign = -sign;
    250256    if (runner->second->NormalVector.NormSquared() > MYEPSILON)
    251       BaseLineNormal.CopyVector(&runner->second->NormalVector);   // yes, copy second on top of first
     257      BaseLineNormal = runner->second->NormalVector;   // yes, copy second on top of first
    252258    else {
    253       eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl;
     259      DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
    254260    }
    255261    node = runner->second->GetThirdEndpoint(this);
    256262    if (node != NULL) {
    257263      //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    258       helper[i].CopyVector(node->node->node);
    259       helper[i].SubtractVector(&BaseLineCenter);
    260       helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
     264      helper[i] = (*node->node->node) - BaseLineCenter;
     265      helper[i].MakeNormalTo(BaseLine);  // we want to compare the triangle's heights' angles!
    261266      //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    262267      i++;
    263268    } else {
    264       eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;
     269      DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
    265270      return true;
    266271    }
     
    268273  //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
    269274  if (NormalCheck.NormSquared() < MYEPSILON) {
    270     Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
     275    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl);
    271276    return true;
    272277  }
     
    274279  double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    275280  if ((angle - M_PI) > -MYEPSILON) {
    276     Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl;
     281    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
    277282    return true;
    278283  } else {
    279     Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl;
     284    DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
    280285    return false;
    281286  }
     
    288293bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    289294{
    290         Info FunctionInfo(__func__);
    291   for(int i=0;i<2;i++)
     295  Info FunctionInfo(__func__);
     296  for (int i = 0; i < 2; i++)
    292297    if (point == endpoints[i])
    293298      return true;
    294299  return false;
    295 };
     300}
     301;
    296302
    297303/** Returns other endpoint of the line.
     
    301307class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
    302308{
    303         Info FunctionInfo(__func__);
     309  Info FunctionInfo(__func__);
    304310  if (endpoints[0] == point)
    305311    return endpoints[1];
     
    308314  else
    309315    return NULL;
    310 };
     316}
     317;
    311318
    312319/** output operator for BoundaryLineSet.
     
    314321 * \param &a boundary line
    315322 */
    316 ostream & operator <<(ostream &ost, const  BoundaryLineSet &a)
    317 {
    318   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 << "]";
     323ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
     324{
     325  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->getName() << " at " << *a.endpoints[0]->node->node << "," << a.endpoints[1]->node->getName() << " at " << *a.endpoints[1]->node->node << "]";
    319326  return ost;
    320 };
     327}
     328;
    321329
    322330// ======================================== Triangles on Boundary =================================
     
    327335  Nr(-1)
    328336{
    329         Info FunctionInfo(__func__);
    330   for (int i = 0; i < 3; i++)
    331     {
    332       endpoints[i] = NULL;
    333       lines[i] = NULL;
    334     }
    335 };
     337  Info FunctionInfo(__func__);
     338  for (int i = 0; i < 3; i++) {
     339    endpoints[i] = NULL;
     340    lines[i] = NULL;
     341  }
     342}
     343;
    336344
    337345/** Constructor for BoundaryTriangleSet with three lines.
     
    342350  Nr(number)
    343351{
    344         Info FunctionInfo(__func__);
     352  Info FunctionInfo(__func__);
    345353  // set number
    346354  // set lines
     
    354362    // for all three lines
    355363    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]));
     364      OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
    358365      // and we don't care whether insertion fails
    359366    }
    360367  // set endpoints
    361368  int Counter = 0;
    362   Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl;
     369  DoLog(0) && (Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl);
    363370  for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
    364371    endpoints[Counter] = runner->second;
    365     Log() << Verbose(0) << " " << *endpoints[Counter] << endl;
     372    DoLog(0) && (Log() << Verbose(0) << " " << *endpoints[Counter] << endl);
    366373    Counter++;
    367374  }
    368375  if (Counter < 3) {
    369     eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl;
     376    DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl);
    370377    performCriticalExit();
    371378  }
    372 };
     379}
     380;
    373381
    374382/** Destructor of BoundaryTriangleSet.
     
    378386BoundaryTriangleSet::~BoundaryTriangleSet()
    379387{
    380         Info FunctionInfo(__func__);
     388  Info FunctionInfo(__func__);
    381389  for (int i = 0; i < 3; i++) {
    382390    if (lines[i] != NULL) {
     
    385393      }
    386394      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;
     395        //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
     396        delete (lines[i]);
     397        lines[i] = NULL;
    390398      }
    391399    }
    392400  }
    393401  //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
    394 };
     402}
     403;
    395404
    396405/** Calculates the normal vector for this triangle.
     
    400409void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
    401410{
    402         Info FunctionInfo(__func__);
     411  Info FunctionInfo(__func__);
    403412  // get normal vector
    404   NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     413  NormalVector = Plane(*(endpoints[0]->node->node),
     414                       *(endpoints[1]->node->node),
     415                       *(endpoints[2]->node->node)).getNormal();
    405416
    406417  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    407   if (NormalVector.ScalarProduct(&OtherVector) > 0.)
     418  if (NormalVector.ScalarProduct(OtherVector) > 0.)
    408419    NormalVector.Scale(-1.);
    409   Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl;
    410 };
     420  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl);
     421}
     422;
    411423
    412424/** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
     
    422434 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
    423435 */
     436
    424437bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
    425438{
     
    428441  Vector helper;
    429442
    430   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;
    432     return false;
    433   }
    434 
    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;
    438 
    439   if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) {
    440     Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl;
    441     return true;
    442   }   else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
    443     Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl;
    444     return true;
    445   }   else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
    446     Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl;
    447     return true;
    448   }
    449   // Calculate cross point between one baseline and the line from the third endpoint to intersection
    450   int i=0;
    451   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;
     443  try {
     444    Line centerLine = makeLineThrough(*MolCenter, *x);
     445    *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(centerLine);
     446
     447    DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl);
     448    DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl);
     449    DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
     450
     451    if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) {
     452      DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
     453      return true;
     454    }   else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) {
     455      DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
     456      return true;
     457    }   else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) {
     458      DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
     459      return true;
     460    }
     461    // Calculate cross point between one baseline and the line from the third endpoint to intersection
     462    int i = 0;
     463    do {
     464      Line line1 = makeLineThrough(*(endpoints[i%3]->node->node),*(endpoints[(i+1)%3]->node->node));
     465      Line line2 = makeLineThrough(*(endpoints[(i+2)%3]->node->node),*Intersection);
     466      CrossPoint = line1.getIntersection(line2);
     467      helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
     468      CrossPoint -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     469      const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared();
     470      DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl);
    458471      if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
    459         Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl;
    460         i=4;
    461         break;
     472        DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
     473        return false;
    462474      }
    463475      i++;
    464     } else
    465       break;
    466   } while (i<3);
    467   if (i==3) {
    468     Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl;
     476    } while (i < 3);
     477    DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl);
    469478    return true;
    470   } else {
    471     Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl;
     479  }
     480  catch (MathException &excp) {
     481    Log() << Verbose(1) << excp;
     482    DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
    472483    return false;
    473484  }
    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
     485}
     486;
     487
     488/** Finds the point on the triangle to the point \a *x.
     489 * We call Vector::GetIntersectionWithPlane() with \a * and the center of the triangle to receive an intersection point.
     490 * Then we check the in-plane part (the part projected down onto plane). We check whether it crosses one of the
     491 * boundary lines. If it does, we return this intersection as closest point, otherwise the projected point down.
    478492 * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
    479493 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
     
    490504
    491505  // 1. get intersection with plane
    492   Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl;
     506  DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl);
    493507  GetCenter(&Direction);
    494   if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
    495     ClosestPoint->CopyVector(x);
     508  try {
     509    Line l = makeLineThrough(*x, Direction);
     510    *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(l);
     511  }
     512  catch (MathException &excp) {
     513    (*ClosestPoint) = (*x);
    496514  }
    497515
    498516  // 2. Calculate in plane part of line (x, intersection)
    499   Vector InPlane;
    500   InPlane.CopyVector(x);
    501   InPlane.SubtractVector(ClosestPoint);  // points from plane intersection to straight-down point
    502   InPlane.ProjectOntoPlane(&NormalVector);
    503   InPlane.AddVector(ClosestPoint);
    504 
    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;
     517  Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point
     518  InPlane.ProjectOntoPlane(NormalVector);
     519  InPlane += *ClosestPoint;
     520
     521  DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl);
     522  DoLog(2) && (Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl);
     523  DoLog(2) && (Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl);
    508524
    509525  // Calculate cross point between one baseline and the desired point such that distance is shortest
     
    513529  Vector CrossPoint[3];
    514530  Vector helper;
    515   for (int i=0;i<3;i++) {
     531  for (int i = 0; i < 3; i++) {
    516532    // 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);
     533    Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
    519534    // 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);
    521     CrossDirection[i].CopyVector(&CrossPoint[i]);
    522     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;
     535    Line l = makeLineThrough(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
     536    CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(l);
     537    CrossDirection[i] = CrossPoint[i] - InPlane;
     538    CrossPoint[i] -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     539    const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared();
     540    DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl);
    526541    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;
    529       const double distance = CrossPoint[i].DistanceSquared(x);
     542          CrossPoint[i] += (*endpoints[i%3]->node->node);  // make cross point absolute again
     543      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);
     544      const double distance = CrossPoint[i].DistanceSquared(*x);
    530545      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
    531546        ShortestDistance = distance;
    532         ClosestPoint->CopyVector(&CrossPoint[i]);
     547        (*ClosestPoint) = CrossPoint[i];
    533548      }
    534549    } else
     
    536551  }
    537552  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
     553  for (int i = 0; i < 3; i++) {
     554    const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 1) % 3]);
     555    const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 2) % 3]);
     556
     557    if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
    542558      InsideFlag = false;
    543559  }
    544560  if (InsideFlag) {
    545     ClosestPoint->CopyVector(&InPlane);
    546     ShortestDistance = InPlane.DistanceSquared(x);
    547   } else {  // also check endnodes
    548     for (int i=0;i<3;i++) {
    549       const double distance = x->DistanceSquared(endpoints[i]->node->node);
     561    (*ClosestPoint) = InPlane;
     562    ShortestDistance = InPlane.DistanceSquared(*x);
     563  } else { // also check endnodes
     564    for (int i = 0; i < 3; i++) {
     565      const double distance = x->DistanceSquared(*endpoints[i]->node->node);
    550566      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
    551567        ShortestDistance = distance;
    552         ClosestPoint->CopyVector(endpoints[i]->node->node);
     568        (*ClosestPoint) = (*endpoints[i]->node->node);
    553569      }
    554570    }
    555571  }
    556   Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl;
     572  DoLog(1) && (Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl);
    557573  return ShortestDistance;
    558 };
     574}
     575;
    559576
    560577/** Checks whether lines is any of the three boundary lines this triangle contains.
     
    564581bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
    565582{
    566         Info FunctionInfo(__func__);
    567   for(int i=0;i<3;i++)
     583  Info FunctionInfo(__func__);
     584  for (int i = 0; i < 3; i++)
    568585    if (line == lines[i])
    569586      return true;
    570587  return false;
    571 };
     588}
     589;
    572590
    573591/** Checks whether point is any of the three endpoints this triangle contains.
     
    577595bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    578596{
    579         Info FunctionInfo(__func__);
    580   for(int i=0;i<3;i++)
     597  Info FunctionInfo(__func__);
     598  for (int i = 0; i < 3; i++)
    581599    if (point == endpoints[i])
    582600      return true;
    583601  return false;
    584 };
     602}
     603;
    585604
    586605/** Checks whether point is any of the three endpoints this triangle contains.
     
    590609bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
    591610{
    592         Info FunctionInfo(__func__);
    593   for(int i=0;i<3;i++)
     611  Info FunctionInfo(__func__);
     612  for (int i = 0; i < 3; i++)
    594613    if (point == endpoints[i]->node)
    595614      return true;
    596615  return false;
    597 };
     616}
     617;
    598618
    599619/** Checks whether three given \a *Points coincide with triangle's endpoints.
     
    603623bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
    604624{
    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 };
     625  Info FunctionInfo(__func__);
     626  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl);
     627  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])
     628
     629  ));
     630}
     631;
    621632
    622633/** Checks whether three given \a *Points coincide with triangle's endpoints.
     
    626637bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
    627638{
    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 };
     639  Info FunctionInfo(__func__);
     640  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])
     641
     642  ));
     643}
     644;
    643645
    644646/** Returns the endpoint which is not contained in the given \a *line.
     
    648650class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
    649651{
    650         Info FunctionInfo(__func__);
     652  Info FunctionInfo(__func__);
    651653  // sanity check
    652654  if (!ContainsBoundaryLine(line))
    653655    return NULL;
    654   for(int i=0;i<3;i++)
     656  for (int i = 0; i < 3; i++)
    655657    if (!line->ContainsBoundaryPoint(endpoints[i]))
    656658      return endpoints[i];
    657659  // actually, that' impossible :)
    658660  return NULL;
    659 };
     661}
     662;
    660663
    661664/** Calculates the center point of the triangle.
     
    665668void BoundaryTriangleSet::GetCenter(Vector * const center) const
    666669{
    667         Info FunctionInfo(__func__);
     670  Info FunctionInfo(__func__);
    668671  center->Zero();
    669   for(int i=0;i<3;i++)
    670     center->AddVector(endpoints[i]->node->node);
    671   center->Scale(1./3.);
    672   Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl;
     672  for (int i = 0; i < 3; i++)
     673    (*center) += (*endpoints[i]->node->node);
     674  center->Scale(1. / 3.);
     675  DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl);
     676}
     677
     678/**
     679 * gets the Plane defined by the three triangle Basepoints
     680 */
     681Plane BoundaryTriangleSet::getPlane() const{
     682  ASSERT(endpoints[0] && endpoints[1] && endpoints[2], "Triangle not fully defined");
     683
     684  return Plane(*endpoints[0]->node->node,
     685               *endpoints[1]->node->node,
     686               *endpoints[2]->node->node);
     687}
     688
     689Vector BoundaryTriangleSet::getEndpoint(int i) const{
     690  ASSERT(i>=0 && i<3,"Index of Endpoint out of Range");
     691
     692  return *endpoints[i]->node->node;
     693}
     694
     695string BoundaryTriangleSet::getEndpointName(int i) const{
     696  ASSERT(i>=0 && i<3,"Index of Endpoint out of Range");
     697
     698  return endpoints[i]->node->getName();
    673699}
    674700
     
    679705ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
    680706{
    681   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 << "]";
     707  ost << "[" << a.Nr << "|" << a.getEndpointName(0) << "," << a.getEndpointName(1) << "," << a.getEndpointName(2) << "]";
     708  //  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
     709  //      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
    684710  return ost;
    685 };
     711}
     712;
    686713
    687714// ======================================== Polygons on Boundary =================================
     
    693720{
    694721  Info FunctionInfo(__func__);
    695 };
     722}
     723;
    696724
    697725/** Destructor of BoundaryPolygonSet.
     
    703731  Info FunctionInfo(__func__);
    704732  endpoints.clear();
    705   Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl;
    706 };
     733  DoLog(1) && (Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl);
     734}
     735;
    707736
    708737/** Calculates the normal vector for this triangle.
     
    718747  Vector *TotalNormal = new Vector;
    719748  PointSet::const_iterator Runner[3];
    720   for (int i=0;i<3; i++) {
     749  for (int i = 0; i < 3; i++) {
    721750    Runner[i] = endpoints.begin();
    722     for (int j = 0; j<i; j++) { // go as much further
     751    for (int j = 0; j < i; j++) { // go as much further
    723752      Runner[i]++;
    724753      if (Runner[i] == endpoints.end()) {
    725         eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl;
     754        DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
    726755        performCriticalExit();
    727756      }
     
    729758  }
    730759  TotalNormal->Zero();
    731   int counter=0;
    732   for (; Runner[2] != endpoints.end(); ) {
    733     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
     760  int counter = 0;
     761  for (; Runner[2] != endpoints.end();) {
     762    TemporaryNormal = Plane(*((*Runner[0])->node->node),
     763                            *((*Runner[1])->node->node),
     764                            *((*Runner[2])->node->node)).getNormal();
     765    for (int i = 0; i < 3; i++) // increase each of them
    735766      Runner[i]++;
    736     TotalNormal->AddVector(&TemporaryNormal);
    737   }
    738   TotalNormal->Scale(1./(double)counter);
     767    (*TotalNormal) += TemporaryNormal;
     768  }
     769  TotalNormal->Scale(1. / (double) counter);
    739770
    740771  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    741   if (TotalNormal->ScalarProduct(&OtherVector) > 0.)
     772  if (TotalNormal->ScalarProduct(OtherVector) > 0.)
    742773    TotalNormal->Scale(-1.);
    743   Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl;
     774  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
    744775
    745776  return TotalNormal;
    746 };
     777}
     778;
    747779
    748780/** Calculates the center point of the triangle.
     
    756788  int counter = 0;
    757789  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    758     center->AddVector((*Runner)->node->node);
     790    (*center) += (*(*Runner)->node->node);
    759791    counter++;
    760792  }
    761   center->Scale(1./(double)counter);
    762   Log() << Verbose(1) << "Center is at " << *center << "." << endl;
     793  center->Scale(1. / (double) counter);
     794  DoLog(1) && (Log() << Verbose(1) << "Center is at " << *center << "." << endl);
    763795}
    764796
     
    771803  Info FunctionInfo(__func__);
    772804  return ContainsPresentTupel(triangle->endpoints, 3);
    773 };
     805}
     806;
    774807
    775808/** Checks whether the polygons contains both endpoints of the line.
     
    781814  Info FunctionInfo(__func__);
    782815  return ContainsPresentTupel(line->endpoints, 2);
    783 };
     816}
     817;
    784818
    785819/** Checks whether point is any of the three endpoints this triangle contains.
     
    790824{
    791825  Info FunctionInfo(__func__);
    792   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    793     Log() << Verbose(0) << "Checking against " << **Runner << endl;
     826  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     827    DoLog(0) && (Log() << Verbose(0) << "Checking against " << **Runner << endl);
    794828    if (point == (*Runner)) {
    795       Log() << Verbose(0) << " Contained." << endl;
     829      DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
    796830      return true;
    797831    }
    798832  }
    799   Log() << Verbose(0) << " Not contained." << endl;
     833  DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
    800834  return false;
    801 };
     835}
     836;
    802837
    803838/** Checks whether point is any of the three endpoints this triangle contains.
     
    808843{
    809844  Info FunctionInfo(__func__);
    810   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     845  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    811846    if (point == (*Runner)->node) {
    812       Log() << Verbose(0) << " Contained." << endl;
     847      DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
    813848      return true;
    814849    }
    815   Log() << Verbose(0) << " Not contained." << endl;
     850  DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
    816851  return false;
    817 };
     852}
     853;
    818854
    819855/** Checks whether given array of \a *Points coincide with polygons's endpoints.
     
    826862  Info FunctionInfo(__func__);
    827863  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;
     864  DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
     865  for (int i = 0; i < dim; i++) {
     866    DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl);
    831867    if (ContainsBoundaryPoint(Points[i])) {
    832868      counter++;
     
    838874  else
    839875    return false;
    840 };
     876}
     877;
    841878
    842879/** Checks whether given PointList coincide with polygons's endpoints.
     
    848885  Info FunctionInfo(__func__);
    849886  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;
     887  DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
     888  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     889    DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << **Runner << endl);
    853890    if (ContainsBoundaryPoint(*Runner))
    854891      counter++;
     
    859896  else
    860897    return false;
    861 };
     898}
     899;
    862900
    863901/** Checks whether given set of \a *Points coincide with polygons's endpoints.
     
    867905bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
    868906{
    869   return ContainsPresentTupel((const PointSet)P->endpoints);
    870 };
     907  return ContainsPresentTupel((const PointSet) P->endpoints);
     908}
     909;
    871910
    872911/** Gathers all the endpoints' triangles in a unique set.
     
    876915{
    877916  Info FunctionInfo(__func__);
    878   pair <TriangleSet::iterator, bool> Tester;
     917  pair<TriangleSet::iterator, bool> Tester;
    879918  TriangleSet *triangles = new TriangleSet;
    880919
    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++) {
     920  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     921    for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
     922      for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
    884923        //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
    885924        if (ContainsBoundaryTriangle(Sprinter->second)) {
    886925          Tester = triangles->insert(Sprinter->second);
    887926          if (Tester.second)
    888             Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl;
     927            DoLog(0) && (Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl);
    889928        }
    890929      }
    891930
    892   Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl;
     931  DoLog(1) && (Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl);
    893932  return triangles;
    894 };
     933}
     934;
    895935
    896936/** Fills the endpoints of this polygon from the triangles attached to \a *line.
     
    901941{
    902942  Info FunctionInfo(__func__);
    903   pair <PointSet::iterator, bool> Tester;
     943  pair<PointSet::iterator, bool> Tester;
    904944  if (line == NULL)
    905945    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++) {
     946  DoLog(1) && (Log() << Verbose(1) << "Filling polygon from line " << *line << endl);
     947  for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
     948    for (int i = 0; i < 3; i++) {
    909949      Tester = endpoints.insert((Runner->second)->endpoints[i]);
    910950      if (Tester.second)
    911         Log() << Verbose(1) << "  Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl;
     951        DoLog(1) && (Log() << Verbose(1) << "  Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl);
    912952    }
    913953  }
    914954
    915955  return true;
    916 };
     956}
     957;
    917958
    918959/** output operator for BoundaryPolygonSet.
     
    923964{
    924965  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<< "]";
     966  for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
     967    ost << (*Runner)->node->getName();
     968    Runner++;
     969    if (Runner != a.endpoints.end())
     970      ost << ",";
     971  }
     972  ost << "]";
    932973  return ost;
    933 };
     974}
     975;
    934976
    935977// =========================================================== class TESSELPOINT ===========================================
     
    942984  node = NULL;
    943985  nr = -1;
    944   Name =  NULL;
    945 };
     986}
     987;
    946988
    947989/** Destructor for class TesselPoint.
     
    950992{
    951993  //Info FunctionInfo(__func__);
    952 };
     994}
     995;
    953996
    954997/** Prints LCNode to screen.
    955998 */
    956 ostream & operator << (ostream &ost, const TesselPoint &a)
    957 {
    958   ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]";
     999ostream & operator <<(ostream &ost, const TesselPoint &a)
     1000{
     1001  ost << "[" << a.getName() << "|" << *a.node << "]";
    9591002  return ost;
    960 };
     1003}
     1004;
    9611005
    9621006/** Prints LCNode to screen.
    9631007 */
    964 ostream & TesselPoint::operator << (ostream &ost)
    965 {
    966         Info FunctionInfo(__func__);
     1008ostream & TesselPoint::operator <<(ostream &ost)
     1009{
     1010  Info FunctionInfo(__func__);
    9671011  ost << "[" << (nr) << "|" << this << "]";
    9681012  return ost;
     1013}
     1014;
     1015
     1016// =========================================================== class POINTCLOUD ============================================
     1017
     1018/** Constructor of class PointCloud.
     1019 */
     1020PointCloud::PointCloud()
     1021{
     1022  //Info FunctionInfo(__func__);
     1023}
     1024;
     1025
     1026/** Destructor for class PointCloud.
     1027 */
     1028PointCloud::~PointCloud()
     1029{
     1030  //Info FunctionInfo(__func__);
     1031}
     1032;
     1033
     1034// ============================ CandidateForTesselation =============================
     1035
     1036/** Constructor of class CandidateForTesselation.
     1037 */
     1038CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
     1039  BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
     1040{
     1041  Info FunctionInfo(__func__);
     1042}
     1043;
     1044
     1045/** Constructor of class CandidateForTesselation.
     1046 */
     1047CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
     1048  BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
     1049{
     1050        Info FunctionInfo(__func__);
     1051  OptCenter = OptCandidateCenter;
     1052  OtherOptCenter = OtherOptCandidateCenter;
    9691053};
    9701054
    9711055
    972 // =========================================================== class POINTCLOUD ============================================
    973 
    974 /** Constructor of class PointCloud.
    975  */
    976 PointCloud::PointCloud()
    977 {
    978         //Info FunctionInfo(__func__);
    979 };
    980 
    981 /** Destructor for class PointCloud.
    982  */
    983 PointCloud::~PointCloud()
    984 {
    985         //Info FunctionInfo(__func__);
    986 };
    987 
    988 // ============================ CandidateForTesselation =============================
    989 
    990 /** Constructor of class CandidateForTesselation.
    991  */
    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 
    1000 
    1001 /** Constructor of class CandidateForTesselation.
    1002  */
    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__);
    1009   OptCenter.CopyVector(&OptCandidateCenter);
    1010   OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
    1011 };
    1012 
    10131056/** Destructor for class CandidateForTesselation.
    10141057 */
    1015 CandidateForTesselation::~CandidateForTesselation() {
    1016   BaseLine = NULL;
    1017 };
     1058CandidateForTesselation::~CandidateForTesselation()
     1059{
     1060}
     1061;
     1062
     1063/** Checks validity of a given sphere of a candidate line.
     1064 * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside.
     1065 * \param RADIUS radius of sphere
     1066 * \param *LC LinkedCell structure with other atoms
     1067 * \return true - sphere is valid, false - sphere contains other points
     1068 */
     1069bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
     1070{
     1071  Info FunctionInfo(__func__);
     1072
     1073  const double radiusSquared = RADIUS * RADIUS;
     1074  list<const Vector *> VectorList;
     1075  VectorList.push_back(&OptCenter);
     1076  //VectorList.push_back(&OtherOptCenter);  // don't check the other (wrong) center
     1077
     1078  if (!pointlist.empty())
     1079    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
     1080  else
     1081    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
     1082  // check baseline for OptCenter and OtherOptCenter being on sphere's surface
     1083  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1084    for (int i = 0; i < 2; i++) {
     1085      const double distance = fabs((*VRunner)->DistanceSquared(*BaseLine->endpoints[i]->node->node) - radiusSquared);
     1086      if (distance > HULLEPSILON) {
     1087        DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     1088        return false;
     1089      }
     1090    }
     1091  }
     1092
     1093  // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
     1094  for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
     1095    const TesselPoint *Walker = *Runner;
     1096    for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1097      const double distance = fabs((*VRunner)->DistanceSquared(*Walker->node) - radiusSquared);
     1098      if (distance > HULLEPSILON) {
     1099        DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     1100        return false;
     1101      } else {
     1102        DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl);
     1103      }
     1104    }
     1105  }
     1106
     1107  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
     1108  bool flag = true;
     1109  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1110    // get all points inside the sphere
     1111    TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
     1112
     1113    DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl);
     1114    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     1115      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->distance(OtherOptCenter) << "." << endl);
     1116
     1117    // remove baseline's endpoints and candidates
     1118    for (int i = 0; i < 2; i++) {
     1119      DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl);
     1120      ListofPoints->remove(BaseLine->endpoints[i]->node);
     1121    }
     1122    for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
     1123      DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl);
     1124      ListofPoints->remove(*Runner);
     1125    }
     1126    if (!ListofPoints->empty()) {
     1127      DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
     1128      flag = false;
     1129      DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
     1130      for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     1131        DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << endl);
     1132    }
     1133    delete (ListofPoints);
     1134
     1135    // check with animate_sphere.tcl VMD script
     1136    if (ThirdPoint != NULL) {
     1137      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[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
     1138    } else {
     1139      DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl);
     1140      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
     1141    }
     1142  }
     1143  return flag;
     1144}
     1145;
    10181146
    10191147/** output operator for CandidateForTesselation.
     
    10211149 * \param &a boundary line
    10221150 */
    1023 ostream & operator <<(ostream &ost, const  CandidateForTesselation &a)
    1024 {
    1025   ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with ";
     1151ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
     1152{
     1153  ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->getName() << "," << a.BaseLine->endpoints[1]->node->getName() << "] with ";
    10261154  if (a.pointlist.empty())
    10271155    ost << "no candidate.";
     
    10341162    for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
    10351163      ost << *(*Runner) << " ";
    1036     ost << " at angle " << (a.ShortestAngle)<< ".";
     1164    ost << " at angle " << (a.ShortestAngle) << ".";
    10371165  }
    10381166
    10391167  return ost;
    1040 };
    1041 
     1168}
     1169;
    10421170
    10431171// =========================================================== class TESSELATION ===========================================
     
    10461174 */
    10471175Tesselation::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__);
     1176  PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin())
     1177{
     1178  Info FunctionInfo(__func__);
    10561179}
    10571180;
     
    10621185Tesselation::~Tesselation()
    10631186{
    1064         Info FunctionInfo(__func__);
    1065   Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl;
     1187  Info FunctionInfo(__func__);
     1188  DoLog(0) && (Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl);
    10661189  for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
    10671190    if (runner->second != NULL) {
     
    10691192      runner->second = NULL;
    10701193    } 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;
     1194      DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);
     1195  }
     1196  DoLog(0) && (Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl);
    10741197}
    10751198;
     
    10771200/** PointCloud implementation of GetCenter
    10781201 * Uses PointsOnBoundary and STL stuff.
    1079  */   
     1202 */
    10801203Vector * Tesselation::GetCenter(ofstream *out) const
    10811204{
    1082         Info FunctionInfo(__func__);
    1083   Vector *Center = new Vector(0.,0.,0.);
    1084   int num=0;
     1205  Info FunctionInfo(__func__);
     1206  Vector *Center = new Vector(0., 0., 0.);
     1207  int num = 0;
    10851208  for (GoToFirst(); (!IsEnd()); GoToNext()) {
    1086     Center->AddVector(GetPoint()->node);
     1209    (*Center) += (*GetPoint()->node);
    10871210    num++;
    10881211  }
    1089   Center->Scale(1./num);
     1212  Center->Scale(1. / num);
    10901213  return Center;
    1091 };
     1214}
     1215;
    10921216
    10931217/** PointCloud implementation of GoPoint
    10941218 * Uses PointsOnBoundary and STL stuff.
    1095  */   
     1219 */
    10961220TesselPoint * Tesselation::GetPoint() const
    10971221{
    1098         Info FunctionInfo(__func__);
     1222  Info FunctionInfo(__func__);
    10991223  return (InternalPointer->second->node);
    1100 };
     1224}
     1225;
    11011226
    11021227/** PointCloud implementation of GetTerminalPoint.
    11031228 * Uses PointsOnBoundary and STL stuff.
    1104  */   
     1229 */
    11051230TesselPoint * Tesselation::GetTerminalPoint() const
    11061231{
    1107         Info FunctionInfo(__func__);
     1232  Info FunctionInfo(__func__);
    11081233  PointMap::const_iterator Runner = PointsOnBoundary.end();
    11091234  Runner--;
    11101235  return (Runner->second->node);
    1111 };
     1236}
     1237;
    11121238
    11131239/** PointCloud implementation of GoToNext.
    11141240 * Uses PointsOnBoundary and STL stuff.
    1115  */   
     1241 */
    11161242void Tesselation::GoToNext() const
    11171243{
    1118         Info FunctionInfo(__func__);
     1244  Info FunctionInfo(__func__);
    11191245  if (InternalPointer != PointsOnBoundary.end())
    11201246    InternalPointer++;
    1121 };
     1247}
     1248;
    11221249
    11231250/** PointCloud implementation of GoToPrevious.
    11241251 * Uses PointsOnBoundary and STL stuff.
    1125  */   
     1252 */
    11261253void Tesselation::GoToPrevious() const
    11271254{
    1128         Info FunctionInfo(__func__);
     1255  Info FunctionInfo(__func__);
    11291256  if (InternalPointer != PointsOnBoundary.begin())
    11301257    InternalPointer--;
    1131 };
     1258}
     1259;
    11321260
    11331261/** PointCloud implementation of GoToFirst.
    11341262 * Uses PointsOnBoundary and STL stuff.
    1135  */   
     1263 */
    11361264void Tesselation::GoToFirst() const
    11371265{
    1138         Info FunctionInfo(__func__);
     1266  Info FunctionInfo(__func__);
    11391267  InternalPointer = PointsOnBoundary.begin();
    1140 };
     1268}
     1269;
    11411270
    11421271/** PointCloud implementation of GoToLast.
     
    11451274void Tesselation::GoToLast() const
    11461275{
    1147         Info FunctionInfo(__func__);
     1276  Info FunctionInfo(__func__);
    11481277  InternalPointer = PointsOnBoundary.end();
    11491278  InternalPointer--;
    1150 };
     1279}
     1280;
    11511281
    11521282/** PointCloud implementation of IsEmpty.
    11531283 * Uses PointsOnBoundary and STL stuff.
    1154  */   
     1284 */
    11551285bool Tesselation::IsEmpty() const
    11561286{
    1157         Info FunctionInfo(__func__);
     1287  Info FunctionInfo(__func__);
    11581288  return (PointsOnBoundary.empty());
    1159 };
     1289}
     1290;
    11601291
    11611292/** PointCloud implementation of IsLast.
    11621293 * Uses PointsOnBoundary and STL stuff.
    1163  */   
     1294 */
    11641295bool Tesselation::IsEnd() const
    11651296{
    1166         Info FunctionInfo(__func__);
     1297  Info FunctionInfo(__func__);
    11671298  return (InternalPointer == PointsOnBoundary.end());
    1168 };
    1169 
     1299}
     1300;
    11701301
    11711302/** Gueses first starting triangle of the convex envelope.
     
    11761307void Tesselation::GuessStartingTriangle()
    11771308{
    1178         Info FunctionInfo(__func__);
     1309  Info FunctionInfo(__func__);
    11791310  // 4b. create a starting triangle
    11801311  // 4b1. create all distances
     
    11861317
    11871318  // 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     }
     1319  if (A != PointsOnBoundary.end()) {
     1320    B = A;
     1321    B++;
     1322    for (; B != PointsOnBoundary.end(); B++) {
     1323      C = B;
     1324      C++;
     1325      for (; C != PointsOnBoundary.end(); C++) {
     1326        tmp = A->second->node->node->DistanceSquared(*B->second->node->node);
     1327        distance = tmp * tmp;
     1328        tmp = A->second->node->node->DistanceSquared(*C->second->node->node);
     1329        distance += tmp * tmp;
     1330        tmp = B->second->node->node->DistanceSquared(*C->second->node->node);
     1331        distance += tmp * tmp;
     1332        DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
     1333      }
     1334    }
     1335  }
    12081336  //    // listing distances
    12091337  //    Log() << Verbose(1) << "Listing DistanceMMap:";
     
    12151343  // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
    12161344  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     }
     1345  for (; baseline != DistanceMMap.end(); baseline++) {
     1346    // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
     1347    // 2. next, we have to check whether all points reside on only one side of the triangle
     1348    // 3. construct plane vector
     1349    PlaneVector = Plane(*A->second->node->node,
     1350                        *baseline->second.first->second->node->node,
     1351                        *baseline->second.second->second->node->node).getNormal();
     1352    DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl);
     1353    // 4. loop over all points
     1354    double sign = 0.;
     1355    PointMap::iterator checker = PointsOnBoundary.begin();
     1356    for (; checker != PointsOnBoundary.end(); checker++) {
     1357      // (neglecting A,B,C)
     1358      if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
     1359        continue;
     1360      // 4a. project onto plane vector
     1361      TrialVector = (*checker->second->node->node);
     1362      TrialVector.SubtractVector(*A->second->node->node);
     1363      distance = TrialVector.ScalarProduct(PlaneVector);
     1364      if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
     1365        continue;
     1366      DoLog(2) && (Log() << Verbose(2) << "Projection of " << checker->second->node->getName() << " yields distance of " << distance << "." << endl);
     1367      tmp = distance / fabs(distance);
     1368      // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
     1369      if ((sign != 0) && (tmp != sign)) {
     1370        // 4c. If so, break 4. loop and continue with next candidate in 1. loop
     1371        DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->getName() << "," << baseline->second.first->second->node->getName() << "," << baseline->second.second->second->node->getName() << " leaves " << checker->second->node->getName() << " outside the convex hull." << endl);
     1372        break;
     1373      } else { // note the sign for later
     1374        DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->getName() << "," << baseline->second.first->second->node->getName() << "," << baseline->second.second->second->node->getName() << " leave " << checker->second->node->getName() << " inside the convex hull." << endl);
     1375        sign = tmp;
     1376      }
     1377      // 4d. Check whether the point is inside the triangle (check distance to each node
     1378      tmp = checker->second->node->node->DistanceSquared(*A->second->node->node);
     1379      int innerpoint = 0;
     1380      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)))
     1381        innerpoint++;
     1382      tmp = checker->second->node->node->DistanceSquared(*baseline->second.first->second->node->node);
     1383      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)))
     1384        innerpoint++;
     1385      tmp = checker->second->node->node->DistanceSquared(*baseline->second.second->second->node->node);
     1386      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)))
     1387        innerpoint++;
     1388      // 4e. If so, break 4. loop and continue with next candidate in 1. loop
     1389      if (innerpoint == 3)
     1390        break;
     1391    }
     1392    // 5. come this far, all on same side? Then break 1. loop and construct triangle
     1393    if (checker == PointsOnBoundary.end()) {
     1394      DoLog(2) && (Log() << Verbose(2) << "Looks like we have a candidate!" << endl);
     1395      break;
     1396    }
     1397  }
     1398  if (baseline != DistanceMMap.end()) {
     1399    BPS[0] = baseline->second.first->second;
     1400    BPS[1] = baseline->second.second->second;
     1401    BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1402    BPS[0] = A->second;
     1403    BPS[1] = baseline->second.second->second;
     1404    BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1405    BPS[0] = baseline->second.first->second;
     1406    BPS[1] = A->second;
     1407    BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1408
     1409    // 4b3. insert created triangle
     1410    BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     1411    TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
     1412    TrianglesOnBoundaryCount++;
     1413    for (int i = 0; i < NDIM; i++) {
     1414      LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
     1415      LinesOnBoundaryCount++;
     1416    }
     1417
     1418    DoLog(1) && (Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl);
     1419  } else {
     1420    DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl);
     1421  }
    13261422}
    13271423;
     
    13421438void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
    13431439{
    1344         Info FunctionInfo(__func__);
     1440  Info FunctionInfo(__func__);
    13451441  bool flag;
    13461442  PointMap::iterator winner;
     
    13611457        // get peak point with respect to this base line's only triangle
    13621458        BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
    1363         Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl;
     1459        DoLog(0) && (Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl);
    13641460        for (int i = 0; i < 3; i++)
    13651461          if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
    13661462            peak = BTS->endpoints[i];
    1367         Log() << Verbose(1) << " and has peak " << *peak << "." << endl;
     1463        DoLog(1) && (Log() << Verbose(1) << " and has peak " << *peak << "." << endl);
    13681464
    13691465        // prepare some auxiliary vectors
    13701466        Vector BaseLineCenter, BaseLine;
    1371         BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node);
    1372         BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node);
    1373         BaseLineCenter.Scale(1. / 2.); // points now to center of base line
    1374         BaseLine.CopyVector(baseline->second->endpoints[0]->node->node);
    1375         BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node);
     1467        BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) +
     1468                                (*baseline->second->endpoints[1]->node->node));
     1469        BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node);
    13761470
    13771471        // offset to center of triangle
    13781472        CenterVector.Zero();
    13791473        for (int i = 0; i < 3; i++)
    1380           CenterVector.AddVector(BTS->endpoints[i]->node->node);
     1474          CenterVector += BTS->getEndpoint(i);
    13811475        CenterVector.Scale(1. / 3.);
    1382         Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl;
     1476        DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
    13831477
    13841478        // normal vector of triangle
    1385         NormalVector.CopyVector(Center);
    1386         NormalVector.SubtractVector(&CenterVector);
     1479        NormalVector = (*Center) - CenterVector;
    13871480        BTS->GetNormalVector(NormalVector);
    1388         NormalVector.CopyVector(&BTS->NormalVector);
    1389         Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl;
     1481        NormalVector = BTS->NormalVector;
     1482        DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl);
    13901483
    13911484        // vector in propagation direction (out of triangle)
    13921485        // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
    1393         PropagationVector.MakeNormalVector(&BaseLine, &NormalVector);
    1394         TempVector.CopyVector(&CenterVector);
    1395         TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
     1486        PropagationVector = Plane(BaseLine, NormalVector,0).getNormal();
     1487        TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    13961488        //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    1397         if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
     1489        if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline
    13981490          PropagationVector.Scale(-1.);
    1399         Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl;
     1491        DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl);
    14001492        winner = PointsOnBoundary.end();
    14011493
     
    14031495        for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
    14041496          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;
     1497            DoLog(1) && (Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl);
    14061498
    14071499            // first check direction, so that triangles don't intersect
    1408             VirtualNormalVector.CopyVector(target->second->node->node);
    1409             VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target
    1410             VirtualNormalVector.ProjectOntoPlane(&NormalVector);
    1411             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;
     1500            VirtualNormalVector = (*target->second->node->node) - BaseLineCenter;
     1501            VirtualNormalVector.ProjectOntoPlane(NormalVector);
     1502            TempAngle = VirtualNormalVector.Angle(PropagationVector);
     1503            DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl);
     1504            if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
     1505              DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl);
    14151506              continue;
    14161507            } else
    1417               Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
     1508              DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl);
    14181509
    14191510            // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
     
    14211512            LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
    14221513            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;
     1514              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);
    14241515              continue;
    14251516            }
    14261517            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;
     1518              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);
    14281519              continue;
    14291520            }
     
    14311522            // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
    14321523            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;
     1524              DoLog(4) && (Log() << Verbose(4) << "Current target is peak!" << endl);
    14341525              continue;
    14351526            }
    14361527
    14371528            // check for linear dependence
    1438             TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
    1439             TempVector.SubtractVector(target->second->node->node);
    1440             helper.CopyVector(baseline->second->endpoints[1]->node->node);
    1441             helper.SubtractVector(target->second->node->node);
    1442             helper.ProjectOntoPlane(&TempVector);
     1529            TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node);
     1530            helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node);
     1531            helper.ProjectOntoPlane(TempVector);
    14431532            if (fabs(helper.NormSquared()) < MYEPSILON) {
    1444               Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl;
     1533              DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl);
    14451534              continue;
    14461535            }
     
    14481537            // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
    14491538            flag = true;
    1450             VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node);
    1451             TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
    1452             TempVector.AddVector(baseline->second->endpoints[1]->node->node);
    1453             TempVector.AddVector(target->second->node->node);
    1454             TempVector.Scale(1./3.);
    1455             TempVector.SubtractVector(Center);
     1539            VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node),
     1540                                        *(baseline->second->endpoints[1]->node->node),
     1541                                        *(target->second->node->node)).getNormal();
     1542            TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) +
     1543                                    (*baseline->second->endpoints[1]->node->node) +
     1544                                    (*target->second->node->node));
     1545            TempVector -= (*Center);
    14561546            // make it always point outward
    1457             if (VirtualNormalVector.ScalarProduct(&TempVector) < 0)
     1547            if (VirtualNormalVector.ScalarProduct(TempVector) < 0)
    14581548              VirtualNormalVector.Scale(-1.);
    14591549            // calculate angle
    1460             TempAngle = NormalVector.Angle(&VirtualNormalVector);
    1461             Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
     1550            TempAngle = NormalVector.Angle(VirtualNormalVector);
     1551            DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl);
    14621552            if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
    14631553              SmallestAngle = TempAngle;
    14641554              winner = target;
    1465               Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1555              DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
    14661556            } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
    14671557              // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
    1468               helper.CopyVector(target->second->node->node);
    1469               helper.SubtractVector(&BaseLineCenter);
    1470               helper.ProjectOntoPlane(&BaseLine);
     1558              helper = (*target->second->node->node) - BaseLineCenter;
     1559              helper.ProjectOntoPlane(BaseLine);
    14711560              // ...the one with the smaller angle is the better candidate
    1472               TempVector.CopyVector(target->second->node->node);
    1473               TempVector.SubtractVector(&BaseLineCenter);
    1474               TempVector.ProjectOntoPlane(&VirtualNormalVector);
    1475               TempAngle = TempVector.Angle(&helper);
    1476               TempVector.CopyVector(winner->second->node->node);
    1477               TempVector.SubtractVector(&BaseLineCenter);
    1478               TempVector.ProjectOntoPlane(&VirtualNormalVector);
    1479               if (TempAngle < TempVector.Angle(&helper)) {
    1480                 TempAngle = NormalVector.Angle(&VirtualNormalVector);
     1561              TempVector = (*target->second->node->node) - BaseLineCenter;
     1562              TempVector.ProjectOntoPlane(VirtualNormalVector);
     1563              TempAngle = TempVector.Angle(helper);
     1564              TempVector = (*winner->second->node->node) - BaseLineCenter;
     1565              TempVector.ProjectOntoPlane(VirtualNormalVector);
     1566              if (TempAngle < TempVector.Angle(helper)) {
     1567                TempAngle = NormalVector.Angle(VirtualNormalVector);
    14811568                SmallestAngle = TempAngle;
    14821569                winner = target;
    1483                 Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
     1570                DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl);
    14841571              } else
    1485                 Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
     1572                DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl);
    14861573            } else
    1487               Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1574              DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
    14881575          }
    14891576        } // end of loop over all boundary points
     
    14911578        // 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
    14921579        if (winner != PointsOnBoundary.end()) {
    1493           Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
     1580          DoLog(0) && (Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl);
    14941581          // create the lins of not yet present
    14951582          BLS[0] = baseline->second;
     
    15151602          BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    15161603          BTS->GetCenter(&helper);
    1517           helper.SubtractVector(Center);
    1518           helper.Scale(-1);
     1604          helper -= (*Center);
     1605          helper *= -1;
    15191606          BTS->GetNormalVector(helper);
    15201607          TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    15211608          TrianglesOnBoundaryCount++;
    15221609        } else {
    1523           eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
     1610          DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);
    15241611        }
    15251612
    15261613        // 5d. If the set of lines is not yet empty, go to 5. and continue
    15271614      } else
    1528         Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
     1615        DoLog(0) && (Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl);
    15291616  } while (flag);
    15301617
    15311618  // exit
    1532   delete(Center);
    1533 };
     1619  delete (Center);
     1620}
     1621;
    15341622
    15351623/** Inserts all points outside of the tesselated surface into it by adding new triangles.
     
    15411629bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
    15421630{
    1543         Info FunctionInfo(__func__);
     1631  Info FunctionInfo(__func__);
    15441632  Vector Intersection, Normal;
    15451633  TesselPoint *Walker = NULL;
     
    15511639  cloud->GoToFirst();
    15521640  BoundaryPoints = new LinkedCell(this, 5.);
    1553   while (!cloud->IsEnd()) {  // we only have to go once through all points, as boundary can become only bigger
     1641  while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
    15541642    if (AddFlag) {
    1555       delete(BoundaryPoints);
     1643      delete (BoundaryPoints);
    15561644      BoundaryPoints = new LinkedCell(this, 5.);
    15571645      AddFlag = false;
    15581646    }
    15591647    Walker = cloud->GetPoint();
    1560     Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;
     1648    DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Walker << "." << endl);
    15611649    // get the next triangle
    15621650    triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
    15631651    BTS = triangles->front();
    15641652    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
    1565       Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl;
     1653      DoLog(0) && (Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl);
    15661654      cloud->GoToNext();
    15671655      continue;
    15681656    } else {
    15691657    }
    1570     Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl;
     1658    DoLog(0) && (Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl);
    15711659    // get the intersection point
    15721660    if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
    1573       Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl;
     1661      DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl);
    15741662      // we have the intersection, check whether in- or outside of boundary
    1575       if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
     1663      if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) {
    15761664        // inside, next!
    1577         Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
     1665        DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl);
    15781666      } else {
    15791667        // outside!
    1580         Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
     1668        DoLog(0) && (Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl);
    15811669        class BoundaryLineSet *OldLines[3], *NewLines[3];
    15821670        class BoundaryPointSet *OldPoints[3], *NewPoint;
    15831671        // store the three old lines and old points
    1584         for (int i=0;i<3;i++) {
     1672        for (int i = 0; i < 3; i++) {
    15851673          OldLines[i] = BTS->lines[i];
    15861674          OldPoints[i] = BTS->endpoints[i];
    15871675        }
    1588         Normal.CopyVector(&BTS->NormalVector);
     1676        Normal = BTS->NormalVector;
    15891677        // add Walker to boundary points
    1590         Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl;
     1678        DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl);
    15911679        AddFlag = true;
    1592         if (AddBoundaryPoint(Walker,0))
     1680        if (AddBoundaryPoint(Walker, 0))
    15931681          NewPoint = BPS[0];
    15941682        else
    15951683          continue;
    15961684        // remove triangle
    1597         Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl;
     1685        DoLog(0) && (Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl);
    15981686        TrianglesOnBoundary.erase(BTS->Nr);
    1599         delete(BTS);
     1687        delete (BTS);
    16001688        // create three new boundary lines
    1601         for (int i=0;i<3;i++) {
     1689        for (int i = 0; i < 3; i++) {
    16021690          BPS[0] = NewPoint;
    16031691          BPS[1] = OldPoints[i];
    16041692          NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1605           Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl;
     1693          DoLog(1) && (Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl);
    16061694          LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
    16071695          LinesOnBoundaryCount++;
    16081696        }
    16091697        // create three new triangle with new point
    1610         for (int i=0;i<3;i++) { // find all baselines
     1698        for (int i = 0; i < 3; i++) { // find all baselines
    16111699          BLS[0] = OldLines[i];
    16121700          int n = 1;
    1613           for (int j=0;j<3;j++) {
     1701          for (int j = 0; j < 3; j++) {
    16141702            if (NewLines[j]->IsConnectedTo(BLS[0])) {
    1615               if (n>2) {
    1616                 eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl;
     1703              if (n > 2) {
     1704                DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);
    16171705                return false;
    16181706              } else
     
    16251713          BTS->GetNormalVector(Normal);
    16261714          Normal.Scale(-1.);
    1627           Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl;
     1715          DoLog(0) && (Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl);
    16281716          TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    16291717          TrianglesOnBoundaryCount++;
     
    16311719      }
    16321720    } else { // something is wrong with FindClosestTriangleToPoint!
    1633       eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl;
     1721      DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl);
    16341722      return false;
    16351723    }
     
    16381726
    16391727  // exit
    1640   delete(Center);
     1728  delete (Center);
    16411729  return true;
    1642 };
     1730}
     1731;
    16431732
    16441733/** Adds a point to the tesselation::PointsOnBoundary list.
     
    16491738bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
    16501739{
    1651         Info FunctionInfo(__func__);
     1740  Info FunctionInfo(__func__);
    16521741  PointTestPair InsertUnique;
    16531742  BPS[n] = new class BoundaryPointSet(Walker);
     
    16571746    return true;
    16581747  } else {
    1659     delete(BPS[n]);
     1748    delete (BPS[n]);
    16601749    BPS[n] = InsertUnique.first->second;
    16611750    return false;
     
    16711760void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
    16721761{
    1673         Info FunctionInfo(__func__);
     1762  Info FunctionInfo(__func__);
    16741763  PointTestPair InsertUnique;
    16751764  TPS[n] = new class BoundaryPointSet(Candidate);
     
    16791768  } else {
    16801769    delete TPS[n];
    1681     Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
     1770    DoLog(0) && (Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl);
    16821771    TPS[n] = (InsertUnique.first)->second;
    16831772  }
     
    16921781void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
    16931782{
    1694         Info FunctionInfo(__func__);
     1783  Info FunctionInfo(__func__);
    16951784  PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
    16961785  if (FindPoint != PointsOnBoundary.end())
     
    16981787  else
    16991788    TPS[n] = NULL;
    1700 };
     1789}
     1790;
    17011791
    17021792/** Function tries to add line from current Points in BPS to BoundaryLineSet.
    17031793 * If successful it raises the line count and inserts the new line into the BLS,
    17041794 * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
     1795 * @param *OptCenter desired OptCenter if there are more than one candidate line
     1796 * @param *candidate third point of the triangle to be, for checking between multiple open line candidates
    17051797 * @param *a first endpoint
    17061798 * @param *b second endpoint
    17071799 * @param n index of Tesselation::BLS giving the line with both endpoints
    17081800 */
    1709 void Tesselation::AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) {
     1801void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     1802{
    17101803  bool insertNewLine = true;
    1711 
    17121804  LineMap::iterator FindLine = a->lines.find(b->node->nr);
     1805  BoundaryLineSet *WinningLine = NULL;
    17131806  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;
     1807    DoLog(1) && (Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl);
     1808
     1809    pair<LineMap::iterator, LineMap::iterator> FindPair;
    17171810    FindPair = a->lines.equal_range(b->node->nr);
    17181811
    1719     for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     1812    for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) {
     1813      DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
    17201814      // 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;
     1815      if (FindLine->second->triangles.size() == 1) {
     1816        CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
     1817        if (!Finder->second->pointlist.empty())
     1818          DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
     1819        else
     1820          DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl);
     1821        // get open line
     1822        for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
     1823          if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
     1824            DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl);
     1825            insertNewLine = false;
     1826            WinningLine = FindLine->second;
     1827            break;
     1828          } else {
     1829            DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *(*CandidateChecker) << "'s center " << Finder->second->OptCenter << " does not match desired on " << *OptCenter << "." << endl);
     1830          }
    17371831        }
    1738 
    1739         break;
    17401832      }
    17411833    }
     
    17431835
    17441836  if (insertNewLine) {
    1745     AlwaysAddTesselationTriangleLine(a, b, n);
     1837    AddNewTesselationTriangleLine(a, b, n);
     1838  } else {
     1839    AddExistingTesselationTriangleLine(WinningLine, n);
    17461840  }
    17471841}
     
    17561850 * @param n index of Tesselation::BLS giving the line with both endpoints
    17571851 */
    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;
     1852void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     1853{
     1854  Info FunctionInfo(__func__);
     1855  DoLog(0) && (Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl);
    17621856  BPS[0] = a;
    17631857  BPS[1] = b;
    1764   BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);  // this also adds the line to the local maps
     1858  BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
    17651859  // add line to global map
    17661860  LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
     
    17691863  // also add to open lines
    17701864  CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
    1771   OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
    1772 };
     1865  OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
     1866}
     1867;
     1868
     1869/** Uses an existing line for a new triangle.
     1870 * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines.
     1871 * \param *FindLine the line to add
     1872 * \param n index of the line to set in Tesselation::BLS
     1873 */
     1874void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n)
     1875{
     1876  Info FunctionInfo(__func__);
     1877  DoLog(0) && (Log() << Verbose(0) << "Using existing line " << *Line << endl);
     1878
     1879  // set endpoints and line
     1880  BPS[0] = Line->endpoints[0];
     1881  BPS[1] = Line->endpoints[1];
     1882  BLS[n] = Line;
     1883  // remove existing line from OpenLines
     1884  CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
     1885  if (CandidateLine != OpenLines.end()) {
     1886    DoLog(1) && (Log() << Verbose(1) << " Removing line from OpenLines." << endl);
     1887    delete (CandidateLine->second);
     1888    OpenLines.erase(CandidateLine);
     1889  } else {
     1890    DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
     1891  }
     1892}
     1893;
    17731894
    17741895/** Function adds triangle to global list.
     
    17771898void Tesselation::AddTesselationTriangle()
    17781899{
    1779         Info FunctionInfo(__func__);
    1780   Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1900  Info FunctionInfo(__func__);
     1901  DoLog(1) && (Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl);
    17811902
    17821903  // add triangle to global map
     
    17881909
    17891910  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
    1790 };
     1911}
     1912;
    17911913
    17921914/** Function adds triangle to global list.
     
    17961918void Tesselation::AddTesselationTriangle(const int nr)
    17971919{
    1798         Info FunctionInfo(__func__);
    1799   Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1920  Info FunctionInfo(__func__);
     1921  DoLog(0) && (Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl);
    18001922
    18011923  // add triangle to global map
     
    18061928
    18071929  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
    1808 };
     1930}
     1931;
    18091932
    18101933/** Removes a triangle from the tesselation.
     
    18151938void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
    18161939{
    1817         Info FunctionInfo(__func__);
     1940  Info FunctionInfo(__func__);
    18181941  if (triangle == NULL)
    18191942    return;
    18201943  for (int i = 0; i < 3; i++) {
    18211944    if (triangle->lines[i] != NULL) {
    1822       Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
     1945      DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl);
    18231946      triangle->lines[i]->triangles.erase(triangle->Nr);
    18241947      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]);
     1948        DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl);
     1949        RemoveTesselationLine(triangle->lines[i]);
    18271950      } 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 //        }
     1951        DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ");
     1952        OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
     1953        for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
     1954          DoLog(0) && (Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t");
     1955        DoLog(0) && (Log() << Verbose(0) << endl);
     1956        //        for (int j=0;j<2;j++) {
     1957        //          Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
     1958        //          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
     1959        //            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
     1960        //          Log() << Verbose(0) << endl;
     1961        //        }
    18391962      }
    1840       triangle->lines[i] = NULL;  // free'd or not: disconnect
     1963      triangle->lines[i] = NULL; // free'd or not: disconnect
    18411964    } else
    1842       eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl;
     1965      DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl);
    18431966  }
    18441967
    18451968  if (TrianglesOnBoundary.erase(triangle->Nr))
    1846     Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
    1847   delete(triangle);
    1848 };
     1969    DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl);
     1970  delete (triangle);
     1971}
     1972;
    18491973
    18501974/** Removes a line from the tesselation.
     
    18541978void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
    18551979{
    1856         Info FunctionInfo(__func__);
     1980  Info FunctionInfo(__func__);
    18571981  int Numbers[2];
    18581982
     
    18751999        for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
    18762000          if ((*Runner).second == line) {
    1877             Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     2001            DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
    18782002            line->endpoints[i]->lines.erase(Runner);
    18792003            break;
     
    18812005      } else { // there's just a single line left
    18822006        if (line->endpoints[i]->lines.erase(line->Nr))
    1883           Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     2007          DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
    18842008      }
    18852009      if (line->endpoints[i]->lines.empty()) {
    1886         Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
     2010        DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl);
    18872011        RemoveTesselationPoint(line->endpoints[i]);
    18882012      } 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;
     2013        DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ");
     2014        for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
     2015          DoLog(0) && (Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t");
     2016        DoLog(0) && (Log() << Verbose(0) << endl);
    18932017      }
    1894       line->endpoints[i] = NULL;  // free'd or not: disconnect
     2018      line->endpoints[i] = NULL; // free'd or not: disconnect
    18952019    } else
    1896       eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl;
     2020      DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);
    18972021  }
    18982022  if (!line->triangles.empty())
    1899     eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl;
     2023    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);
    19002024
    19012025  if (LinesOnBoundary.erase(line->Nr))
    1902     Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl;
    1903   delete(line);
    1904 };
     2026    DoLog(0) && (Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl);
     2027  delete (line);
     2028}
     2029;
    19052030
    19062031/** Removes a point from the tesselation.
     
    19112036void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
    19122037{
    1913         Info FunctionInfo(__func__);
     2038  Info FunctionInfo(__func__);
    19142039  if (point == NULL)
    19152040    return;
    19162041  if (PointsOnBoundary.erase(point->Nr))
    1917     Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl;
    1918   delete(point);
    1919 };
     2042    DoLog(0) && (Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl);
     2043  delete (point);
     2044}
     2045;
     2046
     2047/** Checks validity of a given sphere of a candidate line.
     2048 * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
     2049 * We check CandidateForTesselation::OtherOptCenter
     2050 * \param &CandidateLine contains other degenerated candidates which we have to subtract as well
     2051 * \param RADIUS radius of sphere
     2052 * \param *LC LinkedCell structure with other atoms
     2053 * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
     2054 */
     2055bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const
     2056{
     2057  Info FunctionInfo(__func__);
     2058
     2059  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
     2060  bool flag = true;
     2061
     2062  DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30" << endl);
     2063  // get all points inside the sphere
     2064  TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
     2065
     2066  DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
     2067  for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     2068    DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->distance(CandidateLine.OtherOptCenter) << "." << endl);
     2069
     2070  // remove triangles's endpoints
     2071  for (int i = 0; i < 2; i++)
     2072    ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node);
     2073
     2074  // remove other candidates
     2075  for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner)
     2076    ListofPoints->remove(*Runner);
     2077
     2078  // check for other points
     2079  if (!ListofPoints->empty()) {
     2080    DoLog(1) && (Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
     2081    flag = false;
     2082    DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
     2083    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     2084      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->distance(CandidateLine.OtherOptCenter) << "." << endl);
     2085  }
     2086  delete (ListofPoints);
     2087
     2088  return flag;
     2089}
     2090;
    19202091
    19212092/** Checks whether the triangle consisting of the three points is already present.
     
    19302101int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
    19312102{
    1932         Info FunctionInfo(__func__);
     2103  Info FunctionInfo(__func__);
    19332104  int adjacentTriangleCount = 0;
    19342105  class BoundaryPointSet *Points[3];
     
    19522123          for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
    19532124            TriangleMap *triangles = &FindLine->second->triangles;
    1954             Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
     2125            DoLog(1) && (Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl);
    19552126            for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
    19562127              if (FindTriangle->second->IsPresentTupel(Points)) {
     
    19582129              }
    19592130            }
    1960             Log() << Verbose(1) << "end." << endl;
     2131            DoLog(1) && (Log() << Verbose(1) << "end." << endl);
    19612132          }
    19622133          // Only one of the triangle lines must be considered for the triangle count.
     
    19682139  }
    19692140
    1970   Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     2141  DoLog(0) && (Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl);
    19712142  return adjacentTriangleCount;
    1972 };
     2143}
     2144;
    19732145
    19742146/** Checks whether the triangle consisting of the three points is already present.
     
    19822154class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
    19832155{
    1984         Info FunctionInfo(__func__);
     2156  Info FunctionInfo(__func__);
    19852157  class BoundaryTriangleSet *triangle = NULL;
    19862158  class BoundaryPointSet *Points[3];
     
    20202192
    20212193  return triangle;
    2022 };
    2023 
     2194}
     2195;
    20242196
    20252197/** Finds the starting triangle for FindNonConvexBorder().
     
    20302202 * \param RADIUS radius of virtual rolling sphere
    20312203 * \param *LC LinkedCell structure with neighbouring TesselPoint's
    2032  */
    2033 void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
    2034 {
    2035         Info FunctionInfo(__func__);
     2204 * \return true - a starting triangle has been created, false - no valid triple of points found
     2205 */
     2206bool Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
     2207{
     2208  Info FunctionInfo(__func__);
    20362209  int i = 0;
    20372210  TesselPoint* MaxPoint[NDIM];
    20382211  TesselPoint* Temporary;
    20392212  double maxCoordinate[NDIM];
    2040   BoundaryLineSet BaseLine;
     2213  BoundaryLineSet *BaseLine = NULL;
    20412214  Vector helper;
    20422215  Vector Chord;
    20432216  Vector SearchDirection;
    2044   Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     2217  Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
    20452218  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
    20462219  Vector SphereCenter;
     
    20552228
    20562229  // 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();
     2230  for (int i = 0; i < NDIM; i++) { // each axis
     2231    LC->n[i] = LC->N[i] - 1; // current axis is topmost cell
     2232    for (LC->n[(i + 1) % NDIM] = 0; LC->n[(i + 1) % NDIM] < LC->N[(i + 1) % NDIM]; LC->n[(i + 1) % NDIM]++)
     2233      for (LC->n[(i + 2) % NDIM] = 0; LC->n[(i + 2) % NDIM] < LC->N[(i + 2) % NDIM]; LC->n[(i + 2) % NDIM]++) {
     2234        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    20622235        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    20632236        if (List != NULL) {
    2064           for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
    2065             if ((*Runner)->node->x[i] > maxCoordinate[i]) {
    2066               Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
    2067               maxCoordinate[i] = (*Runner)->node->x[i];
     2237          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     2238            if ((*Runner)->node->at(i) > maxCoordinate[i]) {
     2239              DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl);
     2240              maxCoordinate[i] = (*Runner)->node->at(i);
    20682241              MaxPoint[i] = (*Runner);
    20692242            }
    20702243          }
    20712244        } else {
    2072           eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
     2245          DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
    20732246        }
    20742247      }
    20752248  }
    20762249
    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;
     2250  DoLog(1) && (Log() << Verbose(1) << "Found maximum coordinates: ");
     2251  for (int i = 0; i < NDIM; i++)
     2252    DoLog(0) && (Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t");
     2253  DoLog(0) && (Log() << Verbose(0) << endl);
    20812254
    20822255  BTS = NULL;
    2083   for (int k=0;k<NDIM;k++) {
     2256  for (int k = 0; k < NDIM; k++) {
    20842257    NormalVector.Zero();
    2085     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;
     2258    NormalVector[k] = 1.;
     2259    BaseLine = new BoundaryLineSet();
     2260    BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
     2261    DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
    20882262
    20892263    double ShortestAngle;
    20902264    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.
    20912265
    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?
     2266    Temporary = NULL;
     2267    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_...
     2268    if (Temporary == NULL) {
     2269      // have we found a second point?
     2270      delete BaseLine;
    20942271      continue;
    2095     BaseLine.endpoints[1] = new BoundaryPointSet(Temporary);
     2272    }
     2273    BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
    20962274
    20972275    // construct center of circle
    2098     CircleCenter.CopyVector(BaseLine.endpoints[0]->node->node);
    2099     CircleCenter.AddVector(BaseLine.endpoints[1]->node->node);
    2100     CircleCenter.Scale(0.5);
     2276    CircleCenter = 0.5 * ((*BaseLine->endpoints[0]->node->node) + (*BaseLine->endpoints[1]->node->node));
    21012277
    21022278    // construct normal vector of circle
    2103     CirclePlaneNormal.CopyVector(BaseLine.endpoints[0]->node->node);
    2104     CirclePlaneNormal.SubtractVector(BaseLine.endpoints[1]->node->node);
     2279    CirclePlaneNormal = (*BaseLine->endpoints[0]->node->node) - (*BaseLine->endpoints[1]->node->node);
    21052280
    21062281    double radius = CirclePlaneNormal.NormSquared();
    2107     double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
    2108 
    2109     NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
     2282    double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
     2283
     2284    NormalVector.ProjectOntoPlane(CirclePlaneNormal);
    21102285    NormalVector.Normalize();
    2111     ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    2112 
    2113     SphereCenter.CopyVector(&NormalVector);
    2114     SphereCenter.Scale(CircleRadius);
    2115     SphereCenter.AddVector(&CircleCenter);
     2286    ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
     2287
     2288    SphereCenter = (CircleRadius * NormalVector) +  CircleCenter;
    21162289    // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
    21172290
    21182291    // 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 ...
     2292    SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal();  // whether we look "left" first or "right" first is not important ...
    21202293
    21212294    // 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";
     2295    DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
     2296    DoLog(0) && (Log() << Verbose(0) << "Found second point is at " << *BaseLine->endpoints[1]->node << ".\n");
    21242297
    21252298    //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
    2126     CandidateForTesselation OptCandidates(&BaseLine);
     2299    CandidateForTesselation OptCandidates(BaseLine);
    21272300    FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
    2128     Log() << Verbose(0) << "List of third Points is:" << endl;
     2301    DoLog(0) && (Log() << Verbose(0) << "List of third Points is:" << endl);
    21292302    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
     2303      DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
     2304    }
     2305    if (!OptCandidates.pointlist.empty()) {
     2306      BTS = NULL;
     2307      AddCandidatePolygon(OptCandidates, RADIUS, LC);
     2308    } else {
     2309      delete BaseLine;
     2310      continue;
     2311    }
     2312
     2313    if (BTS != NULL) { // we have created one starting triangle
     2314      delete BaseLine;
    21392315      break;
    2140     else {
     2316    } else {
    21412317      // remove all candidates from the list and then the list itself
    21422318      OptCandidates.pointlist.clear();
    21432319    }
    2144   }
    2145 };
     2320    delete BaseLine;
     2321  }
     2322
     2323  return (BTS != NULL);
     2324}
     2325;
    21462326
    21472327/** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
     
    22142394//            if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    22152395//              // rotated the wrong way!
    2216 //              eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     2396//              DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
    22172397//            }
    22182398//
     
    22712451//          }
    22722452//        } else {
    2273 //          eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;
     2453//          DoeLog(2) && (eLog()<< Verbose(2) << "Baseline is connected to two triangles already?" << endl);
    22742454//        }
    22752455//      } else {
     
    22782458//    }
    22792459//  } else {
    2280 //    eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;
     2460//    DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl);
    22812461//  }
    22822462//
     
    22922472 * @param *LC LinkedCell structure with neighbouring points
    22932473 */
    2294 bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
    2295 {
    2296         Info FunctionInfo(__func__);
    2297   bool result = true;
    2298 
     2474bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
     2475{
     2476  Info FunctionInfo(__func__);
    22992477  Vector CircleCenter;
    23002478  Vector CirclePlaneNormal;
     
    23022480  Vector SearchDirection;
    23032481  Vector helper;
    2304   TesselPoint *ThirdNode = NULL;
     2482  BoundaryPointSet *ThirdPoint = NULL;
    23052483  LineMap::iterator testline;
    23062484  double radius, CircleRadius;
    23072485
    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;
     2486  for (int i = 0; i < 3; i++)
     2487    if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
     2488      ThirdPoint = T.endpoints[i];
    23112489      break;
    23122490    }
    2313   Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdNode " << *ThirdNode << " of triangle " << T << "." << endl;
     2491  DoLog(0) && (Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << "." << endl);
     2492
     2493  CandidateLine.T = &T;
    23142494
    23152495  // construct center of circle
    2316   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2317   CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2318   CircleCenter.Scale(0.5);
     2496  CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
     2497                        (*CandidateLine.BaseLine->endpoints[1]->node->node));
    23192498
    23202499  // construct normal vector of circle
    2321   CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2322   CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     2500  CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
     2501                      (*CandidateLine.BaseLine->endpoints[1]->node->node);
    23232502
    23242503  // calculate squared radius of circle
    2325   radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    2326   if (radius/4. < RADIUS*RADIUS) {
     2504  radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal);
     2505  if (radius / 4. < RADIUS * RADIUS) {
    23272506    // construct relative sphere center with now known CircleCenter
    2328     RelativeSphereCenter.CopyVector(&T.SphereCenter);
    2329     RelativeSphereCenter.SubtractVector(&CircleCenter);
    2330 
    2331     CircleRadius = RADIUS*RADIUS - radius/4.;
     2507    RelativeSphereCenter = T.SphereCenter - CircleCenter;
     2508
     2509    CircleRadius = RADIUS * RADIUS - radius / 4.;
    23322510    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;
     2511    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
     2512
     2513    DoLog(1) && (Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl);
    23362514
    23372515    // construct SearchDirection and an "outward pointer"
    2338     SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
    2339     helper.CopyVector(&CircleCenter);
    2340     helper.SubtractVector(ThirdNode->node);
    2341     if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
     2516    SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal();
     2517    helper = CircleCenter - (*ThirdPoint->node->node);
     2518    if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    23422519      SearchDirection.Scale(-1.);
    2343     Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2344     if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     2520    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
     2521    if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) {
    23452522      // rotated the wrong way!
    2346       eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     2523      DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
    23472524    }
    23482525
    23492526    // add third point
    2350     FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdNode, RADIUS, LC);
     2527    FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC);
    23512528
    23522529  } else {
    2353     Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl;
     2530    DoLog(0) && (Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl);
    23542531  }
    23552532
    23562533  if (CandidateLine.pointlist.empty()) {
    2357     eLog() << Verbose(2) << "Could not find a suitable candidate." << endl;
     2534    DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl);
    23582535    return false;
    23592536  }
    2360   Log() << Verbose(0) << "Third Points are: " << endl;
     2537  DoLog(0) && (Log() << Verbose(0) << "Third Points are: " << endl);
    23612538  for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
    2362     Log() << Verbose(0) << " " << *(*it) << endl;
     2539    DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
    23632540  }
    23642541
    23652542  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 };
     2543}
     2544;
     2545
     2546/** Walks through Tesselation::OpenLines() and finds candidates for newly created ones.
     2547 * \param *&LCList atoms in LinkedCell list
     2548 * \param RADIUS radius of the virtual sphere
     2549 * \return true - for all open lines without candidates so far, a candidate has been found,
     2550 *         false - at least one open line without candidate still
     2551 */
     2552bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList)
     2553{
     2554  bool TesselationFailFlag = true;
     2555  CandidateForTesselation *baseline = NULL;
     2556  BoundaryTriangleSet *T = NULL;
     2557
     2558  for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
     2559    baseline = Runner->second;
     2560    if (baseline->pointlist.empty()) {
     2561      assert((baseline->BaseLine->triangles.size() == 1) && ("Open line without exactly one attached triangle"));
     2562      T = (((baseline->BaseLine->triangles.begin()))->second);
     2563      DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl);
     2564      TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
     2565    }
     2566  }
     2567  return TesselationFailFlag;
     2568}
     2569;
    24512570
    24522571/** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
    24532572 * \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__);
     2573 * \param RADIUS Radius of sphere
     2574 * \param *LC LinkedCell structure
     2575 * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in
     2576 * AddTesselationLine() in AddCandidateTriangle()
     2577 */
     2578void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC)
     2579{
     2580  Info FunctionInfo(__func__);
    24592581  Vector Center;
    24602582  TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
     2583  TesselPointList::iterator Runner;
     2584  TesselPointList::iterator Sprinter;
    24612585
    24622586  // fill the set of neighbours
     
    24672591  TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
    24682592
     2593  DoLog(0) && (Log() << Verbose(0) << "List of Candidates for Turning Point " << *TurningPoint << ":" << endl);
     2594  for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
     2595    DoLog(0) && (Log() << Verbose(0) << " " << **TesselRunner << endl);
     2596
    24692597  // 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;
     2598  Runner = connectedClosestPoints->begin();
     2599  Sprinter = Runner;
    24752600  Sprinter++;
    2476   while(Sprinter != connectedClosestPoints->end()) {
    2477     // add the points
     2601  while (Sprinter != connectedClosestPoints->end()) {
     2602    DoLog(0) && (Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl);
     2603
    24782604    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;
     2605    AddTesselationPoint(*Runner, 1);
     2606    AddTesselationPoint(*Sprinter, 2);
     2607
     2608    AddCandidateTriangle(CandidateLine, Opt);
     2609
    24962610    Runner = Sprinter;
    24972611    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);
     2612    if (Sprinter != connectedClosestPoints->end()) {
     2613      // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
     2614      FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); // Assume BTS contains last triangle
     2615      DoLog(0) && (Log() << Verbose(0) << " There are still more triangles to add." << endl);
     2616    }
     2617    // pick candidates for other open lines as well
     2618    FindCandidatesforOpenLines(RADIUS, LC);
     2619
     2620    // check whether we add a degenerate or a normal triangle
     2621    if (CheckDegeneracy(CandidateLine, RADIUS, LC)) {
     2622      // add normal and degenerate triangles
     2623      DoLog(1) && (Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl);
     2624      AddCandidateTriangle(CandidateLine, OtherOpt);
     2625
     2626      if (Sprinter != connectedClosestPoints->end()) {
     2627        // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
     2628        FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter);
     2629      }
     2630      // pick candidates for other open lines as well
     2631      FindCandidatesforOpenLines(RADIUS, LC);
     2632    }
     2633  }
     2634  delete (connectedClosestPoints);
    25032635};
     2636
     2637/** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate.
     2638 * \param *Sprinter next candidate to which internal open lines are set
     2639 * \param *OptCenter OptCenter for this candidate
     2640 */
     2641void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter)
     2642{
     2643  Info FunctionInfo(__func__);
     2644
     2645  pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr);
     2646  for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     2647    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
     2648    // If there is a line with less than two attached triangles, we don't need a new line.
     2649    if (FindLine->second->triangles.size() == 1) {
     2650      CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
     2651      if (!Finder->second->pointlist.empty())
     2652        DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
     2653      else {
     2654        DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl);
     2655        Finder->second->T = BTS;  // is last triangle
     2656        Finder->second->pointlist.push_back(Sprinter);
     2657        Finder->second->ShortestAngle = 0.;
     2658        Finder->second->OptCenter = *OptCenter;
     2659      }
     2660    }
     2661  }
     2662};
     2663
     2664/** If a given \a *triangle is degenerated, this adds both sides.
     2665 * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction.
     2666 * Note that endpoints are stored in Tesselation::TPS
     2667 * \param CandidateLine CanddiateForTesselation structure for the desired BoundaryLine
     2668 * \param RADIUS radius of sphere
     2669 * \param *LC pointer to LinkedCell structure
     2670 */
     2671void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
     2672{
     2673  Info FunctionInfo(__func__);
     2674  Vector Center;
     2675  CandidateMap::const_iterator CandidateCheck = OpenLines.end();
     2676  BoundaryTriangleSet *triangle = NULL;
     2677
     2678  /// 1. Create or pick the lines for the first triangle
     2679  DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl);
     2680  for (int i = 0; i < 3; i++) {
     2681    BLS[i] = NULL;
     2682    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2683    AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
     2684  }
     2685
     2686  /// 2. create the first triangle and NormalVector and so on
     2687  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl);
     2688  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2689  AddTesselationTriangle();
     2690
     2691  // create normal vector
     2692  BTS->GetCenter(&Center);
     2693  Center -= CandidateLine.OptCenter;
     2694  BTS->SphereCenter = CandidateLine.OptCenter;
     2695  BTS->GetNormalVector(Center);
     2696  // give some verbose output about the whole procedure
     2697  if (CandidateLine.T != NULL)
     2698    DoLog(0) && (Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
     2699  else
     2700    DoLog(0) && (Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2701  triangle = BTS;
     2702
     2703  /// 3. Gather candidates for each new line
     2704  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl);
     2705  for (int i = 0; i < 3; i++) {
     2706    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2707    CandidateCheck = OpenLines.find(BLS[i]);
     2708    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     2709      if (CandidateCheck->second->T == NULL)
     2710        CandidateCheck->second->T = triangle;
     2711      FindNextSuitableTriangle(*(CandidateCheck->second), *CandidateCheck->second->T, RADIUS, LC);
     2712    }
     2713  }
     2714
     2715  /// 4. Create or pick the lines for the second triangle
     2716  DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl);
     2717  for (int i = 0; i < 3; i++) {
     2718    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2719    AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
     2720  }
     2721
     2722  /// 5. create the second triangle and NormalVector and so on
     2723  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl);
     2724  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2725  AddTesselationTriangle();
     2726
     2727  BTS->SphereCenter = CandidateLine.OtherOptCenter;
     2728  // create normal vector in other direction
     2729  BTS->GetNormalVector(triangle->NormalVector);
     2730  BTS->NormalVector.Scale(-1.);
     2731  // give some verbose output about the whole procedure
     2732  if (CandidateLine.T != NULL)
     2733    DoLog(0) && (Log() << Verbose(0) << "--> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
     2734  else
     2735    DoLog(0) && (Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2736
     2737  /// 6. Adding triangle to new lines
     2738  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl);
     2739  for (int i = 0; i < 3; i++) {
     2740    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2741    CandidateCheck = OpenLines.find(BLS[i]);
     2742    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     2743      if (CandidateCheck->second->T == NULL)
     2744        CandidateCheck->second->T = BTS;
     2745    }
     2746  }
     2747}
     2748;
     2749
     2750/** Adds a triangle to the Tesselation structure from three given TesselPoint's.
     2751 * Note that endpoints are in Tesselation::TPS.
     2752 * \param CandidateLine CandidateForTesselation structure contains other information
     2753 * \param type which opt center to add (i.e. which side) and thus which NormalVector to take
     2754 */
     2755void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type)
     2756{
     2757  Info FunctionInfo(__func__);
     2758  Vector Center;
     2759  Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter;
     2760
     2761  // add the lines
     2762  AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0);
     2763  AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1);
     2764  AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2);
     2765
     2766  // add the triangles
     2767  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2768  AddTesselationTriangle();
     2769
     2770  // create normal vector
     2771  BTS->GetCenter(&Center);
     2772  Center.SubtractVector(*OptCenter);
     2773  BTS->SphereCenter = *OptCenter;
     2774  BTS->GetNormalVector(Center);
     2775
     2776  // give some verbose output about the whole procedure
     2777  if (CandidateLine.T != NULL)
     2778    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);
     2779  else
     2780    DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2781}
     2782;
    25042783
    25052784/** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
     
    25122791class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
    25132792{
    2514         Info FunctionInfo(__func__);
     2793  Info FunctionInfo(__func__);
    25152794  class BoundaryPointSet *Spot = NULL;
    25162795  class BoundaryLineSet *OtherBase;
    25172796  Vector *ClosestPoint;
    25182797
    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
     2798  int m = 0;
     2799  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2800    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    25222801      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
    25232802        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;
     2803  OtherBase = new class BoundaryLineSet(BPS, -1);
     2804
     2805  DoLog(1) && (Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl);
     2806  DoLog(1) && (Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl);
    25282807
    25292808  // get the closest point on each line to the other line
     
    25312810
    25322811  // delete the temporary other base line
    2533   delete(OtherBase);
     2812  delete (OtherBase);
    25342813
    25352814  // get the distance vector from Base line to OtherBase line
    25362815  Vector DistanceToIntersection[2], BaseLine;
    25372816  double distance[2];
    2538   BaseLine.CopyVector(Base->endpoints[1]->node->node);
    2539   BaseLine.SubtractVector(Base->endpoints[0]->node->node);
    2540   for (int i=0;i<2;i++) {
    2541     DistanceToIntersection[i].CopyVector(ClosestPoint);
    2542     DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
    2543     distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
    2544   }
    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;
     2817  BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node);
     2818  for (int i = 0; i < 2; i++) {
     2819    DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node);
     2820    distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]);
     2821  }
     2822  delete (ClosestPoint);
     2823  if ((distance[0] * distance[1]) > 0) { // have same sign?
     2824    DoLog(1) && (Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl);
    25482825    if (distance[0] < distance[1]) {
    25492826      Spot = Base->endpoints[0];
     
    25522829    }
    25532830    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;
     2831  } else { // different sign, i.e. we are in between
     2832    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl);
    25562833    return NULL;
    25572834  }
    25582835
    2559 };
     2836}
     2837;
    25602838
    25612839void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
    25622840{
    2563         Info FunctionInfo(__func__);
     2841  Info FunctionInfo(__func__);
    25642842  // 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 };
     2843  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl);
     2844  for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)
     2845    DoLog(0) && (Log() << Verbose(0) << *(PointRunner->second) << endl);
     2846}
     2847;
    25692848
    25702849void Tesselation::PrintAllBoundaryLines(ofstream *out) const
    25712850{
    2572         Info FunctionInfo(__func__);
     2851  Info FunctionInfo(__func__);
    25732852  // print all lines
    2574   Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl;
     2853  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl);
    25752854  for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
    2576     Log() << Verbose(0) << *(LineRunner->second) << endl;
    2577 };
     2855    DoLog(0) && (Log() << Verbose(0) << *(LineRunner->second) << endl);
     2856}
     2857;
    25782858
    25792859void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
    25802860{
    2581         Info FunctionInfo(__func__);
     2861  Info FunctionInfo(__func__);
    25822862  // print all triangles
    2583   Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl;
     2863  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl);
    25842864  for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
    2585     Log() << Verbose(0) << *(TriangleRunner->second) << endl;
    2586 };
     2865    DoLog(0) && (Log() << Verbose(0) << *(TriangleRunner->second) << endl);
     2866}
     2867;
    25872868
    25882869/** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
     
    25932874double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
    25942875{
    2595         Info FunctionInfo(__func__);
     2876  Info FunctionInfo(__func__);
    25962877  class BoundaryLineSet *OtherBase;
    25972878  Vector *ClosestPoint[2];
    25982879  double volume;
    25992880
    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
     2881  int m = 0;
     2882  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2883    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    26032884      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
    26042885        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;
     2886  OtherBase = new class BoundaryLineSet(BPS, -1);
     2887
     2888  DoLog(0) && (Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl);
     2889  DoLog(0) && (Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl);
    26092890
    26102891  // get the closest point on each line to the other line
     
    26132894
    26142895  // get the distance vector from Base line to OtherBase line
    2615   Vector Distance;
    2616   Distance.CopyVector(ClosestPoint[1]);
    2617   Distance.SubtractVector(ClosestPoint[0]);
     2896  Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]);
    26182897
    26192898  // calculate volume
     
    26212900
    26222901  // delete the temporary other base line and the closest points
    2623   delete(ClosestPoint[0]);
    2624   delete(ClosestPoint[1]);
    2625   delete(OtherBase);
     2902  delete (ClosestPoint[0]);
     2903  delete (ClosestPoint[1]);
     2904  delete (OtherBase);
    26262905
    26272906  if (Distance.NormSquared() < MYEPSILON) { // check for intersection
    2628     Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
     2907    DoLog(0) && (Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl);
    26292908    return false;
    26302909  } else { // check for sign against BaseLineNormal
     
    26322911    BaseLineNormal.Zero();
    26332912    if (Base->triangles.size() < 2) {
    2634       eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;
     2913      DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
    26352914      return 0.;
    26362915    }
    26372916    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;
    2639       BaseLineNormal.AddVector(&(runner->second->NormalVector));
    2640     }
    2641     BaseLineNormal.Scale(1./2.);
    2642 
    2643     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;
     2917    DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
     2918      BaseLineNormal += (runner->second->NormalVector);
     2919    }
     2920    BaseLineNormal.Scale(1. / 2.);
     2921
     2922    if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
     2923      DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl);
    26452924      // calculate volume summand as a general tetraeder
    26462925      return volume;
    2647     } else {  // Base higher than OtherBase -> do nothing
    2648       Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl;
     2926    } else { // Base higher than OtherBase -> do nothing
     2927      DoLog(0) && (Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl);
    26492928      return 0.;
    26502929    }
    26512930  }
    2652 };
     2931}
     2932;
    26532933
    26542934/** For a given baseline and its two connected triangles, flips the baseline.
     
    26612941class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
    26622942{
    2663         Info FunctionInfo(__func__);
     2943  Info FunctionInfo(__func__);
    26642944  class BoundaryLineSet *OldLines[4], *NewLine;
    26652945  class BoundaryPointSet *OldPoints[2];
    26662946  Vector BaseLineNormal;
    26672947  int OldTriangleNrs[2], OldBaseLineNr;
    2668   int i,m;
     2948  int i, m;
    26692949
    26702950  // calculate NormalVector for later use
    26712951  BaseLineNormal.Zero();
    26722952  if (Base->triangles.size() < 2) {
    2673     eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;
     2953    DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
    26742954    return NULL;
    26752955  }
    26762956  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;
    2678     BaseLineNormal.AddVector(&(runner->second->NormalVector));
    2679   }
    2680   BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
     2957    DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
     2958    BaseLineNormal += (runner->second->NormalVector);
     2959  }
     2960  BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
    26812961
    26822962  // get the two triangles
    26832963  // gather four endpoints and four lines
    2684   for (int j=0;j<4;j++)
     2964  for (int j = 0; j < 4; j++)
    26852965    OldLines[j] = NULL;
    2686   for (int j=0;j<2;j++)
     2966  for (int j = 0; j < 2; j++)
    26872967    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
     2968  i = 0;
     2969  m = 0;
     2970  DoLog(0) && (Log() << Verbose(0) << "The four old lines are: ");
     2971  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2972    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    26932973      if (runner->second->lines[j] != Base) { // pick not the central baseline
    26942974        OldLines[i++] = runner->second->lines[j];
    2695         Log() << Verbose(0) << *runner->second->lines[j] << "\t";
     2975        DoLog(0) && (Log() << Verbose(0) << *runner->second->lines[j] << "\t");
    26962976      }
    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
     2977  DoLog(0) && (Log() << Verbose(0) << endl);
     2978  DoLog(0) && (Log() << Verbose(0) << "The two old points are: ");
     2979  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2980    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    27012981      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
    27022982        OldPoints[m++] = runner->second->endpoints[j];
    2703         Log() << Verbose(0) << *runner->second->endpoints[j] << "\t";
     2983        DoLog(0) && (Log() << Verbose(0) << *runner->second->endpoints[j] << "\t");
    27042984      }
    2705   Log() << Verbose(0) << endl;
     2985  DoLog(0) && (Log() << Verbose(0) << endl);
    27062986
    27072987  // 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;
     2988  if (i < 4) {
     2989    DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
    27102990    return NULL;
    27112991  }
    2712   for (int j=0;j<4;j++)
     2992  for (int j = 0; j < 4; j++)
    27132993    if (OldLines[j] == NULL) {
    2714       eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;
     2994      DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
    27152995      return NULL;
    27162996    }
    2717   for (int j=0;j<2;j++)
     2997  for (int j = 0; j < 2; j++)
    27182998    if (OldPoints[j] == NULL) {
    2719       eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl;
     2999      DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl);
    27203000      return NULL;
    27213001    }
    27223002
    27233003  // remove triangles and baseline removes itself
    2724   Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
     3004  DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl);
    27253005  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;
     3006  m = 0;
     3007  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
     3008    DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl);
    27293009    OldTriangleNrs[m++] = runner->second->Nr;
    27303010    RemoveTesselationTriangle(runner->second);
     
    27363016  NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
    27373017  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;
     3018  DoLog(0) && (Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl);
    27393019
    27403020  // construct new triangles with flipped baseline
    2741   i=-1;
     3021  i = -1;
    27423022  if (OldLines[0]->IsConnectedTo(OldLines[2]))
    2743     i=2;
     3023    i = 2;
    27443024  if (OldLines[0]->IsConnectedTo(OldLines[3]))
    2745     i=3;
    2746   if (i!=-1) {
     3025    i = 3;
     3026  if (i != -1) {
    27473027    BLS[0] = OldLines[0];
    27483028    BLS[1] = OldLines[i];
     
    27513031    BTS->GetNormalVector(BaseLineNormal);
    27523032    AddTesselationTriangle(OldTriangleNrs[0]);
    2753     Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
    2754 
    2755     BLS[0] = (i==2 ? OldLines[3] : OldLines[2]);
     3033    DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
     3034
     3035    BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]);
    27563036    BLS[1] = OldLines[1];
    27573037    BLS[2] = NewLine;
     
    27593039    BTS->GetNormalVector(BaseLineNormal);
    27603040    AddTesselationTriangle(OldTriangleNrs[1]);
    2761     Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
     3041    DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
    27623042  } else {
    2763     eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl;
     3043    DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);
    27643044    return NULL;
    27653045  }
    27663046
    27673047  return NewLine;
    2768 };
    2769 
     3048}
     3049;
    27703050
    27713051/** Finds the second point of starting triangle.
     
    27793059void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
    27803060{
    2781         Info FunctionInfo(__func__);
     3061  Info FunctionInfo(__func__);
    27823062  Vector AngleCheck;
    27833063  class TesselPoint* Candidate = NULL;
     
    27883068  int Nupper[NDIM];
    27893069
    2790   if (LC->SetIndexToNode(a)) {  // get cell for the starting point
    2791     for(int i=0;i<NDIM;i++) // store indices of this cell
     3070  if (LC->SetIndexToNode(a)) { // get cell for the starting point
     3071    for (int i = 0; i < NDIM; i++) // store indices of this cell
    27923072      N[i] = LC->n[i];
    27933073  } else {
    2794     eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl;
     3074    DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);
    27953075    return;
    27963076  }
    27973077  // 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;
     3078  for (int i = 0; i < NDIM; i++) {
     3079    Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
     3080    Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
     3081  }
     3082  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);
    28043083
    28053084  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    28063085    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    28073086      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    2808         const LinkedNodes *List = LC->GetCurrentCell();
     3087        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    28093088        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    28103089        if (List != NULL) {
    2811           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3090          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    28123091            Candidate = (*Runner);
    28133092            // check if we only have one unique point yet ...
     
    28173096              double distance, scaleFactor;
    28183097
    2819               OrthogonalizedOben.CopyVector(&Oben);
    2820               aCandidate.CopyVector(a->node);
    2821               aCandidate.SubtractVector(Candidate->node);
    2822               OrthogonalizedOben.ProjectOntoPlane(&aCandidate);
     3098              OrthogonalizedOben = Oben;
     3099              aCandidate = (*a->node) - (*Candidate->node);
     3100              OrthogonalizedOben.ProjectOntoPlane(aCandidate);
    28233101              OrthogonalizedOben.Normalize();
    28243102              distance = 0.5 * aCandidate.Norm();
     
    28263104              OrthogonalizedOben.Scale(scaleFactor);
    28273105
    2828               Center.CopyVector(Candidate->node);
    2829               Center.AddVector(a->node);
    2830               Center.Scale(0.5);
    2831               Center.AddVector(&OrthogonalizedOben);
    2832 
    2833               AngleCheck.CopyVector(&Center);
    2834               AngleCheck.SubtractVector(a->node);
     3106              Center = 0.5 * ((*Candidate->node) + (*a->node));
     3107              Center += OrthogonalizedOben;
     3108
     3109              AngleCheck = Center - (*a->node);
    28353110              norm = aCandidate.Norm();
    28363111              // second point shall have smallest angle with respect to Oben vector
    2837               if (norm < RADIUS*2.) {
    2838                 angle = AngleCheck.Angle(&Oben);
     3112              if (norm < RADIUS * 2.) {
     3113                angle = AngleCheck.Angle(Oben);
    28393114                if (angle < Storage[0]) {
    28403115                  //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";
     3116                  DoLog(1) && (Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n");
    28423117                  OptCandidate = Candidate;
    28433118                  Storage[0] = angle;
     
    28543129          }
    28553130        } else {
    2856           Log() << Verbose(0) << "Linked cell list is empty." << endl;
     3131          DoLog(0) && (Log() << Verbose(0) << "Linked cell list is empty." << endl);
    28573132        }
    28583133      }
    2859 };
    2860 
     3134}
     3135;
    28613136
    28623137/** This recursive function finds a third point, to form a triangle with two given ones.
     
    28863161 * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
    28873162 * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
    2888  * @param ThirdNode third point to avoid in search
     3163 * @param ThirdPoint third point to avoid in search
    28893164 * @param RADIUS radius of sphere
    28903165 * @param *LC LinkedCell structure with neighbouring points
    28913166 */
    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
     3167void 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
     3168{
     3169  Info FunctionInfo(__func__);
     3170  Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
    28963171  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
    28973172  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
     3173  Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
     3174  Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
     3175  Vector NewNormalVector; // normal vector of the Candidate's triangle
    29013176  Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
    29023177  Vector RelativeOldSphereCenter;
     
    29093184  TesselPoint *Candidate = NULL;
    29103185
    2911   Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
     3186  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl);
     3187
     3188  // copy old center
     3189  CandidateLine.OldCenter = OldSphereCenter;
     3190  CandidateLine.ThirdPoint = ThirdPoint;
     3191  CandidateLine.pointlist.clear();
    29123192
    29133193  // construct center of circle
    2914   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2915   CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2916   CircleCenter.Scale(0.5);
     3194  CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
     3195                        (*CandidateLine.BaseLine->endpoints[1]->node->node));
    29173196
    29183197  // construct normal vector of circle
    2919   CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2920   CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2921 
    2922   RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
    2923   RelativeOldSphereCenter.SubtractVector(&CircleCenter);
    2924 
    2925   // calculate squared radius TesselPoint *ThirdNode,f circle
    2926   radius = CirclePlaneNormal.NormSquared()/4.;
    2927   if (radius < RADIUS*RADIUS) {
    2928     CircleRadius = RADIUS*RADIUS - radius;
     3198  CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
     3199                      (*CandidateLine.BaseLine->endpoints[1]->node->node);
     3200
     3201  RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
     3202
     3203  // calculate squared radius TesselPoint *ThirdPoint,f circle
     3204  radius = CirclePlaneNormal.NormSquared() / 4.;
     3205  if (radius < RADIUS * RADIUS) {
     3206    CircleRadius = RADIUS * RADIUS - radius;
    29293207    CirclePlaneNormal.Normalize();
    2930     Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     3208    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
    29313209
    29323210    // test whether old center is on the band's plane
    2933     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;
    2935       RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
     3211    if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
     3212      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);
     3213      RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal);
    29363214    }
    29373215    radius = RelativeOldSphereCenter.NormSquared();
    29383216    if (fabs(radius - CircleRadius) < HULLEPSILON) {
    2939       Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl;
     3217      DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl);
    29403218
    29413219      // 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;
     3220      DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
     3221      if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
     3222        DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
    29453223      }
    29463224
    29473225      // get cell for the starting point
    29483226      if (LC->SetIndexToVector(&CircleCenter)) {
    2949         for(int i=0;i<NDIM;i++) // store indices of this cell
    2950         N[i] = LC->n[i];
     3227        for (int i = 0; i < NDIM; i++) // store indices of this cell
     3228          N[i] = LC->n[i];
    29513229        //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    29523230      } else {
    2953         eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl;
     3231        DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);
    29543232        return;
    29553233      }
    29563234      // then go through the current and all neighbouring cells and check the contained points for possible candidates
    29573235      //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;
     3236      for (int i = 0; i < NDIM; i++) {
     3237        Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
     3238        Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
    29613239        //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
    29623240      }
     
    29653243        for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    29663244          for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    2967             const LinkedNodes *List = LC->GetCurrentCell();
     3245            const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    29683246            //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    29693247            if (List != NULL) {
    2970               for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3248              for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    29713249                Candidate = (*Runner);
    29723250
    29733251                // 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) ){
     3252                DoLog(2) && (Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl);
     3253                if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) {
    29763254
    29773255                  // find center on the plane
    29783256                  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;
    2985                     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) {
    2990                       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);
     3257                  DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl);
     3258
     3259                  try {
     3260                    NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node),
     3261                                            *(CandidateLine.BaseLine->endpoints[1]->node->node),
     3262                                            *(Candidate->node)).getNormal();
     3263                    DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl);
     3264                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter);
     3265                    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
     3266                    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
     3267                    DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl);
     3268                    if (radius < RADIUS * RADIUS) {
     3269                      otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter);
     3270                      if (fabs(radius - otherradius) < HULLEPSILON) {
     3271                        // construct both new centers
     3272                        NewSphereCenter = NewPlaneCenter;
     3273                        OtherNewSphereCenter= NewPlaneCenter;
     3274                        helper = NewNormalVector;
     3275                        helper.Scale(sqrt(RADIUS * RADIUS - radius));
     3276                        DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl);
     3277                        NewSphereCenter += helper;
     3278                        DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl);
     3279                        // OtherNewSphereCenter is created by the same vector just in the other direction
     3280                        helper.Scale(-1.);
     3281                        OtherNewSphereCenter += helper;
     3282                        DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl);
     3283                        alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
     3284                        Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
     3285                        if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
     3286                          if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter))
     3287                            alpha = Otheralpha;
     3288                        } else
     3289                          alpha = min(alpha, Otheralpha);
     3290                        // if there is a better candidate, drop the current list and add the new candidate
     3291                        // otherwise ignore the new candidate and keep the list
     3292                        if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
     3293                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
     3294                            CandidateLine.OptCenter = NewSphereCenter;
     3295                            CandidateLine.OtherOptCenter = OtherNewSphereCenter;
     3296                          } else {
     3297                            CandidateLine.OptCenter = OtherNewSphereCenter;
     3298                            CandidateLine.OtherOptCenter = NewSphereCenter;
     3299                          }
     3300                          // if there is an equal candidate, add it to the list without clearing the list
     3301                          if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
     3302                            CandidateLine.pointlist.push_back(Candidate);
     3303                            DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
     3304                          } else {
     3305                            // remove all candidates from the list and then the list itself
     3306                            CandidateLine.pointlist.clear();
     3307                            CandidateLine.pointlist.push_back(Candidate);
     3308                            DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
     3309                          }
     3310                          CandidateLine.ShortestAngle = alpha;
     3311                          DoLog(0) && (Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl);
    30173312                        } else {
    3018                           CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
    3019                           CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     3313                          if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
     3314                            DoLog(1) && (Log() << Verbose(1) << "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl);
     3315                          } else {
     3316                            DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl);
     3317                          }
    30203318                        }
    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;
    30353319                      } 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                         }
     3320                        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);
    30413321                      }
    30423322                    } else {
    3043                       Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
     3323                      DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl);
    30443324                    }
    3045                   } else {
     3325                  }
     3326                  catch (LinearDependenceException &excp){
     3327                    Log() << Verbose(1) << excp;
    30463328                    Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
    30473329                  }
    30483330                } else {
    3049                   if (ThirdNode != NULL) {
    3050                     Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
     3331                  if (ThirdPoint != NULL) {
     3332                    DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << "." << endl);
    30513333                  } else {
    3052                     Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl;
     3334                    DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl);
    30533335                  }
    30543336                }
     
    30573339          }
    30583340    } else {
    3059       eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;
     3341      DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
    30603342    }
    30613343  } else {
    3062     if (ThirdNode != NULL)
    3063       Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
     3344    if (ThirdPoint != NULL)
     3345      DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!" << endl);
    30643346    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;
     3347      DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl);
     3348  }
     3349
     3350  DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl);
    30693351  if (CandidateLine.pointlist.size() > 1) {
    30703352    CandidateLine.pointlist.unique();
    30713353    CandidateLine.pointlist.sort(); //SortCandidates);
    30723354  }
    3073 };
     3355
     3356  if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
     3357    DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
     3358    performCriticalExit();
     3359  }
     3360}
     3361;
    30743362
    30753363/** Finds the endpoint two lines are sharing.
     
    30803368class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
    30813369{
    3082         Info FunctionInfo(__func__);
     3370  Info FunctionInfo(__func__);
    30833371  const BoundaryLineSet * lines[2] = { line1, line2 };
    30843372  class BoundaryPointSet *node = NULL;
     
    30873375  for (int i = 0; i < 2; i++)
    30883376    // 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           }
     3377    for (int j = 0; j < 2; j++) { // for both endpoints
     3378      OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
     3379      if (!OrderTest.second) { // if insertion fails, we have common endpoint
     3380        node = OrderTest.first->second;
     3381        DoLog(1) && (Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl);
     3382        j = 2;
     3383        i = 2;
     3384        break;
    31023385      }
     3386    }
    31033387  return node;
    3104 };
     3388}
     3389;
    31053390
    31063391/** Finds the boundary points that are closest to a given Vector \a *x.
     
    31163401
    31173402  if (LinesOnBoundary.empty()) {
    3118     eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl;
     3403    DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);
    31193404    return NULL;
    31203405  }
     
    31223407  // gather all points close to the desired one
    31233408  LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
    3124   for(int i=0;i<NDIM;i++) // store indices of this cell
     3409  for (int i = 0; i < NDIM; i++) // store indices of this cell
    31253410    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 
     3411  DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
    31283412  DistanceToPointMap * points = new DistanceToPointMap;
    31293413  LC->GetNeighbourBounds(Nlower, Nupper);
     
    31323416    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    31333417      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    3134         const LinkedNodes *List = LC->GetCurrentCell();
     3418        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    31353419        //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    31363420        if (List != NULL) {
    3137           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3421          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    31383422            FindPoint = PointsOnBoundary.find((*Runner)->nr);
    31393423            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;
     3424              points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second));
     3425              DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl);
    31423426            }
    31433427          }
    31443428        } else {
    3145           eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
     3429          DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
    31463430        }
    31473431      }
     
    31493433  // check whether we found some points
    31503434  if (points->empty()) {
    3151     eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
    3152     delete(points);
     3435    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
     3436    delete (points);
    31533437    return NULL;
    31543438  }
    31553439  return points;
    3156 };
     3440}
     3441;
    31573442
    31583443/** Finds the boundary line that is closest to a given Vector \a *x.
     
    31643449{
    31653450  Info FunctionInfo(__func__);
    3166 
    31673451  // get closest points
    3168   DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3452  DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
    31693453  if (points == NULL) {
    3170     eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
     3454    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
    31713455    return NULL;
    31723456  }
    31733457
    31743458  // for each point, check its lines, remember closest
    3175   Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl;
     3459  DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl);
    31763460  BoundaryLineSet *ClosestLine = NULL;
    31773461  double MinDistance = -1.;
     
    31823466    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    31833467      // calculate closest point on line to desired point
    3184       helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3185       helper.AddVector((LineRunner->second)->endpoints[1]->node->node);
    3186       helper.Scale(0.5);
    3187       Center.CopyVector(x);
    3188       Center.SubtractVector(&helper);
    3189       BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3190       BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3191       Center.ProjectOntoPlane(&BaseLine);
     3468      helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) +
     3469                      (*(LineRunner->second)->endpoints[1]->node->node));
     3470      Center = (*x) - helper;
     3471      BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
     3472                 (*(LineRunner->second)->endpoints[1]->node->node);
     3473      Center.ProjectOntoPlane(BaseLine);
    31923474      const double distance = Center.NormSquared();
    31933475      if ((ClosestLine == NULL) || (distance < MinDistance)) {
    31943476        // additionally calculate intersection on line (whether it's on the line section or not)
    3195         helper.CopyVector(x);
    3196         helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
    3197         helper.SubtractVector(&Center);
    3198         const double lengthA = helper.ScalarProduct(&BaseLine);
    3199         helper.CopyVector(x);
    3200         helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3201         helper.SubtractVector(&Center);
    3202         const double lengthB = helper.ScalarProduct(&BaseLine);
    3203         if (lengthB*lengthA < 0) {  // if have different sign
     3477        helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center;
     3478        const double lengthA = helper.ScalarProduct(BaseLine);
     3479        helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center;
     3480        const double lengthB = helper.ScalarProduct(BaseLine);
     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;
     
    32503527    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    32513528
    3252       BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3253       BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3529      BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
     3530                 (*(LineRunner->second)->endpoints[1]->node->node);
    32543531      const double lengthBase = BaseLine.NormSquared();
    32553532
    3256       BaseLineIntersection.CopyVector(x);
    3257       BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
     3533      BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node);
    32583534      const double lengthEndA = BaseLineIntersection.NormSquared();
    32593535
    3260       BaseLineIntersection.CopyVector(x);
    3261       BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3536      BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
    32623537      const double lengthEndB = BaseLineIntersection.NormSquared();
    32633538
    3264       if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) {  // intersection would be outside, take closer endpoint
     3539      if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
    32653540        const double lengthEnd = Min(lengthEndA, lengthEndB);
    32663541        if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
     
    32683543          ClosestLines.insert(LineRunner->second);
    32693544          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
     3545          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl);
     3546        } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
    32723547          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;
     3548          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl);
    32743549        } 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;
     3550          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);
    32763551        }
    32773552      } else { // intersection is closer, calculate
    32783553        // calculate closest point on line to desired point
    3279         BaseLineIntersection.CopyVector(x);
    3280         BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3281         Center.CopyVector(&BaseLineIntersection);
    3282         Center.ProjectOntoPlane(&BaseLine);
    3283         BaseLineIntersection.SubtractVector(&Center);
     3554        BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
     3555        Center = BaseLineIntersection;
     3556        Center.ProjectOntoPlane(BaseLine);
     3557        BaseLineIntersection -= Center;
    32843558        const double distance = BaseLineIntersection.NormSquared();
    32853559        if (Center.NormSquared() > BaseLine.NormSquared()) {
    3286           eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl;
     3560          DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);
    32873561        }
    32883562        if ((ClosestLines.empty()) || (distance < MinDistance)) {
    32893563          ClosestLines.insert(LineRunner->second);
    32903564          MinDistance = distance;
    3291           Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl;
     3565          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl);
    32923566        } else {
    3293           Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl;
     3567          DoLog(2) && (Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl);
    32943568        }
    32953569      }
    32963570    }
    32973571  }
    3298   delete(points);
     3572  delete (points);
    32993573
    33003574  // check whether closest line is "too close" :), then it's inside
    33013575  if (ClosestLines.empty()) {
    3302     Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
     3576    DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
    33033577    return NULL;
    33043578  }
     
    33063580  for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
    33073581    for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
    3308     candidates->push_back(Runner->second);
    3309   }
     3582      candidates->push_back(Runner->second);
     3583    }
    33103584  return candidates;
    3311 };
     3585}
     3586;
    33123587
    33133588/** Finds closest triangle to a point.
     
    33153590 * \param *out output stream for debugging
    33163591 * \param *x Vector to look from
     3592 * \param &distance contains found distance on return
    33173593 * \return list of BoundaryTriangleSet of nearest triangles or NULL.
    33183594 */
    33193595class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
    33203596{
    3321         Info FunctionInfo(__func__);
     3597  Info FunctionInfo(__func__);
    33223598  class BoundaryTriangleSet *result = NULL;
    33233599  TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
     
    33303606
    33313607  // go through all and pick the one with the best alignment to x
    3332   double MinAlignment = 2.*M_PI;
     3608  double MinAlignment = 2. * M_PI;
    33333609  for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
    33343610    (*Runner)->GetCenter(&Center);
    3335     helper.CopyVector(x);
    3336     helper.SubtractVector(&Center);
    3337     const double Alignment = helper.Angle(&(*Runner)->NormalVector);
     3611    helper = (*x) - Center;
     3612    const double Alignment = helper.Angle((*Runner)->NormalVector);
    33383613    if (Alignment < MinAlignment) {
    33393614      result = *Runner;
    33403615      MinAlignment = Alignment;
    3341       Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl;
     3616      DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl);
    33423617    } else {
    3343       Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl;
    3344     }
    3345   }
    3346   delete(triangles);
     3618      DoLog(1) && (Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl);
     3619    }
     3620  }
     3621  delete (triangles);
    33473622
    33483623  return result;
    3349 };
     3624}
     3625;
    33503626
    33513627/** Checks whether the provided Vector is within the Tesselation structure.
     
    33583634bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
    33593635{
    3360   return (GetDistanceSquaredToSurface(Point, LC) < MYEPSILON);
    3361 }
     3636  Info FunctionInfo(__func__);
     3637  TriangleIntersectionList Intersections(&Point, this, LC);
     3638
     3639  return Intersections.IsInside();
     3640}
     3641;
    33623642
    33633643/** Returns the distance to the surface given by the tesselation.
     
    33893669
    33903670  if (triangle == NULL) {// is boundary point or only point in point cloud?
    3391     Log() << Verbose(1) << "No triangle given!" << endl;
     3671    DoLog(1) && (Log() << Verbose(1) << "No triangle given!" << endl);
    33923672    return -1.;
    33933673  } else {
    3394     Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl;
     3674    DoLog(1) && (Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl);
    33953675  }
    33963676
    33973677  triangle->GetCenter(&Center);
    3398   Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
    3399   DistanceToCenter.CopyVector(&Center);
    3400   DistanceToCenter.SubtractVector(&Point);
    3401   Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl;
     3678  DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl);
     3679  DistanceToCenter = Center - Point;
     3680  DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl);
    34023681
    34033682  // check whether we are on boundary
    3404   if (fabs(DistanceToCenter.ScalarProduct(&triangle->NormalVector)) < MYEPSILON) {
     3683  if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) {
    34053684    // calculate whether inside of triangle
    3406     DistanceToCenter.CopyVector(&Point);
    3407     Center.CopyVector(&Point);
    3408     Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
    3409     DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
    3410     Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl;
     3685    DistanceToCenter = Point + triangle->NormalVector; // points outside
     3686    Center = Point - triangle->NormalVector; // points towards MolCenter
     3687    DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl);
    34113688    if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
    3412       Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl;
     3689      DoLog(1) && (Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl);
    34133690      return 0.;
    34143691    } else {
    3415       Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl;
     3692      DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl);
    34163693      return false;
    34173694    }
     
    34193696    // calculate smallest distance
    34203697    distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
    3421     Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl;
     3698    DoLog(1) && (Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl);
    34223699
    34233700    // then check direction to boundary
    3424     if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
    3425       Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl;
     3701    if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) {
     3702      DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl);
    34263703      return -distance;
    34273704    } else {
    3428       Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl;
     3705      DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl);
    34293706      return +distance;
    34303707    }
    34313708  }
    3432 };
    3433 
    3434 /** Calculates distance to a tesselated surface.
     3709}
     3710;
     3711
     3712/** Calculates minimum distance from \a&Point to a tesselated surface.
    34353713 * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
    34363714 * \param &Point point to calculate distance from
     
    34383716 * \return distance squared to closest point on surface
    34393717 */
    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 };
     3718double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const
     3719{
     3720  Info FunctionInfo(__func__);
     3721  TriangleIntersectionList Intersections(&Point, this, LC);
     3722
     3723  return Intersections.GetSmallestDistance();
     3724}
     3725;
     3726
     3727/** Calculates minimum distance from \a&Point to a tesselated surface.
     3728 * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
     3729 * \param &Point point to calculate distance from
     3730 * \param *LC needed for finding closest points fast
     3731 * \return distance squared to closest point on surface
     3732 */
     3733BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const
     3734{
     3735  Info FunctionInfo(__func__);
     3736  TriangleIntersectionList Intersections(&Point, this, LC);
     3737
     3738  return Intersections.GetClosestTriangle();
     3739}
     3740;
    34463741
    34473742/** Gets all points connected to the provided point by triangulation lines.
     
    34533748TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    34543749{
    3455         Info FunctionInfo(__func__);
    3456         TesselPointSet *connectedPoints = new TesselPointSet;
     3750  Info FunctionInfo(__func__);
     3751  TesselPointSet *connectedPoints = new TesselPointSet;
    34573752  class BoundaryPointSet *ReferencePoint = NULL;
    34583753  TesselPoint* current;
    34593754  bool takePoint = false;
    3460 
    34613755  // find the respective boundary point
    34623756  PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
     
    34643758    ReferencePoint = PointRunner->second;
    34653759  } else {
    3466     eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
     3760    DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
    34673761    ReferencePoint = NULL;
    34683762  }
     
    34703764  // little trick so that we look just through lines connect to the BoundaryPoint
    34713765  // OR fall-back to look through all lines if there is no such BoundaryPoint
    3472   const LineMap *Lines;;
     3766  const LineMap *Lines;
     3767  ;
    34733768  if (ReferencePoint != NULL)
    34743769    Lines = &(ReferencePoint->lines);
     
    34773772  LineMap::const_iterator findLines = Lines->begin();
    34783773  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++;
     3774    takePoint = false;
     3775
     3776    if (findLines->second->endpoints[0]->Nr == Point->nr) {
     3777      takePoint = true;
     3778      current = findLines->second->endpoints[1]->node;
     3779    } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
     3780      takePoint = true;
     3781      current = findLines->second->endpoints[0]->node;
     3782    }
     3783
     3784    if (takePoint) {
     3785      DoLog(1) && (Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl);
     3786      connectedPoints->insert(current);
     3787    }
     3788
     3789    findLines++;
    34953790  }
    34963791
    34973792  if (connectedPoints->empty()) { // if have not found any points
    3498     eLog() << Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl;
     3793    DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl);
    34993794    return NULL;
    35003795  }
    35013796
    35023797  return connectedPoints;
    3503 };
    3504 
     3798}
     3799;
    35053800
    35063801/** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
     
    35183813TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    35193814{
    3520         Info FunctionInfo(__func__);
     3815  Info FunctionInfo(__func__);
    35213816  map<double, TesselPoint*> anglesOfPoints;
    35223817  TesselPointList *connectedCircle = new TesselPointList;
     
    35253820  Vector OrthogonalVector;
    35263821  Vector helper;
    3527   const TesselPoint * const TrianglePoints[3] = {Point, NULL, NULL};
     3822  const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL };
    35283823  TriangleList *triangles = NULL;
    35293824
    35303825  if (SetOfNeighbours == NULL) {
    3531     eLog() << Verbose(2) << "Could not find any connected points!" << endl;
    3532     delete(connectedCircle);
     3826    DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
     3827    delete (connectedCircle);
    35333828    return NULL;
    35343829  }
     
    35383833  if ((triangles != NULL) && (!triangles->empty())) {
    35393834    for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    3540       PlaneNormal.AddVector(&(*Runner)->NormalVector);
     3835      PlaneNormal += (*Runner)->NormalVector;
    35413836  } else {
    3542     eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl;
     3837    DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
    35433838    performCriticalExit();
    35443839  }
    3545   PlaneNormal.Scale(1.0/triangles->size());
    3546   Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl;
     3840  PlaneNormal.Scale(1.0 / triangles->size());
     3841  DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl);
    35473842  PlaneNormal.Normalize();
    35483843
    35493844  // construct one orthogonal vector
    35503845  if (Reference != NULL) {
    3551     AngleZero.CopyVector(Reference);
    3552     AngleZero.SubtractVector(Point->node);
    3553     AngleZero.ProjectOntoPlane(&PlaneNormal);
    3554   }
    3555   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    3556     Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
    3557     AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    3558     AngleZero.SubtractVector(Point->node);
    3559     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3846    AngleZero = (*Reference) - (*Point->node);
     3847    AngleZero.ProjectOntoPlane(PlaneNormal);
     3848  }
     3849  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
     3850    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
     3851    AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
     3852    AngleZero.ProjectOntoPlane(PlaneNormal);
    35603853    if (AngleZero.NormSquared() < MYEPSILON) {
    3561       eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
     3854      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
    35623855      performCriticalExit();
    35633856    }
    35643857  }
    3565   Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
     3858  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    35663859  if (AngleZero.NormSquared() > MYEPSILON)
    3567     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3860    OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
    35683861  else
    3569     OrthogonalVector.MakeNormalVector(&PlaneNormal);
    3570   Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
     3862    OrthogonalVector.MakeNormalTo(PlaneNormal);
     3863  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    35713864
    35723865  // go through all connected points and calculate angle
    35733866  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    3574     helper.CopyVector((*listRunner)->node);
    3575     helper.SubtractVector(Point->node);
    3576     helper.ProjectOntoPlane(&PlaneNormal);
     3867    helper = (*(*listRunner)->node) - (*Point->node);
     3868    helper.ProjectOntoPlane(PlaneNormal);
    35773869    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++) {
     3870    DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl);
     3871    anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
     3872  }
     3873
     3874  for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
    35833875    connectedCircle->push_back(AngleRunner->second);
    35843876  }
     
    36103902
    36113903  if (SetOfNeighbours == NULL) {
    3612     eLog() << Verbose(2) << "Could not find any connected points!" << endl;
    3613     delete(connectedCircle);
     3904    DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
     3905    delete (connectedCircle);
    36143906    return NULL;
    36153907  }
     
    36223914  }
    36233915
    3624   Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl;
     3916  DoLog(1) && (Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl);
    36253917  // calculate central point
    3626 
    36273918  TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
    36283919  TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
     
    36333924  int counter = 0;
    36343925  while (TesselC != SetOfNeighbours->end()) {
    3635     helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
    3636     Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl;
     3926    helper = Plane(*((*TesselA)->node),
     3927                   *((*TesselB)->node),
     3928                   *((*TesselC)->node)).getNormal();
     3929    DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl);
    36373930    counter++;
    36383931    TesselA++;
    36393932    TesselB++;
    36403933    TesselC++;
    3641     PlaneNormal.AddVector(&helper);
     3934    PlaneNormal += helper;
    36423935  }
    36433936  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
    36443937  //  << "; 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;
     3938  PlaneNormal.Scale(1.0 / (double) counter);
     3939  //  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
     3940  //
     3941  //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
     3942  //  PlaneNormal.CopyVector(Point->node);
     3943  //  PlaneNormal.SubtractVector(&center);
     3944  //  PlaneNormal.Normalize();
     3945  DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl);
    36533946
    36543947  // construct one orthogonal vector
    36553948  if (Reference != NULL) {
    3656     AngleZero.CopyVector(Reference);
    3657     AngleZero.SubtractVector(Point->node);
    3658     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3949    AngleZero = (*Reference) - (*Point->node);
     3950    AngleZero.ProjectOntoPlane(PlaneNormal);
    36593951  }
    36603952  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    3661     Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
    3662     AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    3663     AngleZero.SubtractVector(Point->node);
    3664     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3953    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
     3954    AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
     3955    AngleZero.ProjectOntoPlane(PlaneNormal);
    36653956    if (AngleZero.NormSquared() < MYEPSILON) {
    3666       eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
     3957      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
    36673958      performCriticalExit();
    36683959    }
    36693960  }
    3670   Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
     3961  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    36713962  if (AngleZero.NormSquared() > MYEPSILON)
    3672     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3963    OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
    36733964  else
    3674     OrthogonalVector.MakeNormalVector(&PlaneNormal);
    3675   Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
     3965    OrthogonalVector.MakeNormalTo(PlaneNormal);
     3966  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    36763967
    36773968  // go through all connected points and calculate angle
    3678   pair <map<double, TesselPoint*>::iterator, bool > InserterTest;
     3969  pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
    36793970  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    3680     helper.CopyVector((*listRunner)->node);
    3681     helper.SubtractVector(Point->node);
    3682     helper.ProjectOntoPlane(&PlaneNormal);
     3971    helper = (*(*listRunner)->node) - (*Point->node);
     3972    helper.ProjectOntoPlane(PlaneNormal);
    36833973    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    36843974    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)));
     3975      angle = 2. * M_PI - angle;
     3976    DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl);
     3977    InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
    36883978    if (!InserterTest.second) {
    3689       eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl;
     3979      DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);
    36903980      performCriticalExit();
    36913981    }
    36923982  }
    36933983
    3694   for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
     3984  for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
    36953985    connectedCircle->push_back(AngleRunner->second);
    36963986  }
     
    37073997ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    37083998{
    3709         Info FunctionInfo(__func__);
     3999  Info FunctionInfo(__func__);
    37104000  map<double, TesselPoint*> anglesOfPoints;
    3711   list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;
     4001  list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ;
    37124002  TesselPointList *connectedPath = NULL;
    37134003  Vector center;
     
    37214011  class BoundaryLineSet *CurrentLine = NULL;
    37224012  class BoundaryLineSet *StartLine = NULL;
    3723 
    37244013  // find the respective boundary point
    37254014  PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
     
    37274016    ReferencePoint = PointRunner->second;
    37284017  } else {
    3729     eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
     4018    DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
    37304019    return NULL;
    37314020  }
    37324021
    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;
     4022  map<class BoundaryLineSet *, bool> TouchedLine;
     4023  map<class BoundaryTriangleSet *, bool> TouchedTriangle;
     4024  map<class BoundaryLineSet *, bool>::iterator LineRunner;
     4025  map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
    37374026  for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
    3738     TouchedLine.insert( pair <class BoundaryLineSet *, bool>(Runner->second, false) );
     4027    TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false));
    37394028    for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
    3740       TouchedTriangle.insert( pair <class BoundaryTriangleSet *, bool>(Sprinter->second, false) );
     4029      TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false));
    37414030  }
    37424031  if (!ReferencePoint->lines.empty()) {
     
    37444033      LineRunner = TouchedLine.find(runner->second);
    37454034      if (LineRunner == TouchedLine.end()) {
    3746         eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl;
     4035        DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);
    37474036      } else if (!LineRunner->second) {
    37484037        LineRunner->second = true;
     
    37524041        StartLine = CurrentLine;
    37534042        CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
    3754         Log() << Verbose(1)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
     4043        DoLog(1) && (Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl);
    37554044        do {
    37564045          // push current one
    3757           Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     4046          DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
    37584047          connectedPath->push_back(CurrentPoint->node);
    37594048
    37604049          // find next triangle
    37614050          for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
    3762             Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
     4051            DoLog(1) && (Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl);
    37634052            if ((Runner->second != triangle)) { // look for first triangle not equal to old one
    37644053              triangle = Runner->second;
     
    37674056                if (!TriangleRunner->second) {
    37684057                  TriangleRunner->second = true;
    3769                   Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl;
     4058                  DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl);
    37704059                  break;
    37714060                } else {
    3772                   Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
     4061                  DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl);
    37734062                  triangle = NULL;
    37744063                }
    37754064              } else {
    3776                 eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl;
     4065                DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);
    37774066                triangle = NULL;
    37784067              }
     
    37824071            break;
    37834072          // find next line
    3784           for (int i=0;i<3;i++) {
     4073          for (int i = 0; i < 3; i++) {
    37854074            if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
    37864075              CurrentLine = triangle->lines[i];
    3787               Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
     4076              DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl);
    37884077              break;
    37894078            }
     
    37914080          LineRunner = TouchedLine.find(CurrentLine);
    37924081          if (LineRunner == TouchedLine.end())
    3793             eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl;
     4082            DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);
    37944083          else
    37954084            LineRunner->second = true;
     
    37994088        } while (CurrentLine != StartLine);
    38004089        // last point is missing, as it's on start line
    3801         Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     4090        DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
    38024091        if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
    38034092          connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
     
    38054094        ListOfPaths->push_back(connectedPath);
    38064095      } else {
    3807         Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
     4096        DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl);
    38084097      }
    38094098    }
    38104099  } else {
    3811     eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl;
     4100    DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);
    38124101  }
    38134102
     
    38234112ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    38244113{
    3825         Info FunctionInfo(__func__);
     4114  Info FunctionInfo(__func__);
    38264115  list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    3827   list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *>;
     4116  list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;
    38284117  TesselPointList *connectedPath = NULL;
    38294118  TesselPointList *newPath = NULL;
    38304119  int count = 0;
    3831 
    3832 
    38334120  TesselPointList::iterator CircleRunner;
    38344121  TesselPointList::iterator CircleStart;
    38354122
    3836   for(list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
     4123  for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
    38374124    connectedPath = *ListRunner;
    38384125
    3839     Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl;
     4126    DoLog(1) && (Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl);
    38404127
    38414128    // go through list, look for reappearance of starting Point and count
    38424129    CircleStart = connectedPath->begin();
    3843 
    38444130    // go through list, look for reappearance of starting Point and create list
    38454131    TesselPointList::iterator Marker = CircleStart;
     
    38474133      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    38484134        // we have a closed circle from Marker to new Marker
    3849         Log() << Verbose(1) << count+1 << ". closed path consists of: ";
     4135        DoLog(1) && (Log() << Verbose(1) << count + 1 << ". closed path consists of: ");
    38504136        newPath = new TesselPointList;
    38514137        TesselPointList::iterator CircleSprinter = Marker;
    38524138        for (; CircleSprinter != CircleRunner; CircleSprinter++) {
    38534139          newPath->push_back(*CircleSprinter);
    3854           Log() << Verbose(0) << (**CircleSprinter) << " <-> ";
     4140          DoLog(0) && (Log() << Verbose(0) << (**CircleSprinter) << " <-> ");
    38554141        }
    3856         Log() << Verbose(0) << ".." << endl;
     4142        DoLog(0) && (Log() << Verbose(0) << ".." << endl);
    38574143        count++;
    38584144        Marker = CircleRunner;
     
    38634149    }
    38644150  }
    3865   Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl;
     4151  DoLog(1) && (Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl);
    38664152
    38674153  // delete list of paths
     
    38694155    connectedPath = *(ListofPaths->begin());
    38704156    ListofPaths->remove(connectedPath);
    3871     delete(connectedPath);
    3872   }
    3873   delete(ListofPaths);
     4157    delete (connectedPath);
     4158  }
     4159  delete (ListofPaths);
    38744160
    38754161  // exit
    38764162  return ListofClosedPaths;
    3877 };
    3878 
     4163}
     4164;
    38794165
    38804166/** Gets all belonging triangles for a given BoundaryPointSet.
     
    38854171TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    38864172{
    3887         Info FunctionInfo(__func__);
    3888         TriangleSet *connectedTriangles = new TriangleSet;
     4173  Info FunctionInfo(__func__);
     4174  TriangleSet *connectedTriangles = new TriangleSet;
    38894175
    38904176  if (Point == NULL) {
    3891     eLog() << Verbose(1) << "Point given is NULL." << endl;
     4177    DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl);
    38924178  } else {
    38934179    // go through its lines and insert all triangles
    38944180    for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
    38954181      for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    3896       connectedTriangles->insert(TriangleRunner->second);
    3897     }
     4182        connectedTriangles->insert(TriangleRunner->second);
     4183      }
    38984184  }
    38994185
    39004186  return connectedTriangles;
    3901 };
    3902 
     4187}
     4188;
    39034189
    39044190/** Removes a boundary point from the envelope while keeping it closed.
     
    39134199 * \return volume added to the volume inside the tesselated surface by the removal
    39144200 */
    3915 double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) {
     4201double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point)
     4202{
    39164203  class BoundaryLineSet *line = NULL;
    39174204  class BoundaryTriangleSet *triangle = NULL;
     
    39214208
    39224209  if (point == NULL) {
    3923     eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl;
     4210    DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);
    39244211    return 0.;
    39254212  } else
    3926     Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl;
     4213    DoLog(0) && (Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl);
    39274214
    39284215  // copy old location for the volume
    3929   OldPoint.CopyVector(point->node->node);
     4216  OldPoint = (*point->node->node);
    39304217
    39314218  // get list of connected points
    39324219  if (point->lines.empty()) {
    3933     eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl;
     4220    DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);
    39344221    return 0.;
    39354222  }
     
    39404227  // gather all triangles
    39414228  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
    3942     count+=LineRunner->second->triangles.size();
     4229    count += LineRunner->second->triangles.size();
    39434230  TriangleMap Candidates;
    39444231  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
     
    39464233    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    39474234      triangle = TriangleRunner->second;
    3948       Candidates.insert( TrianglePair (triangle->Nr, triangle) );
     4235      Candidates.insert(TrianglePair(triangle->Nr, triangle));
    39494236    }
    39504237  }
    39514238
    39524239  // remove all triangles
    3953   count=0;
     4240  count = 0;
    39544241  NormalVector.Zero();
    39554242  for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    3956     Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl;
    3957     NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
     4243    DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl);
     4244    NormalVector -= Runner->second->NormalVector; // has to point inward
    39584245    RemoveTesselationTriangle(Runner->second);
    39594246    count++;
    39604247  }
    3961   Log() << Verbose(1) << count << " triangles were removed." << endl;
     4248  DoLog(1) && (Log() << Verbose(1) << count << " triangles were removed." << endl);
    39624249
    39634250  list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
     
    39684255  double smallestangle;
    39694256  Vector Point, Reference, OrthogonalVector;
    3970   if (count > 2) {  // less than three triangles, then nothing will be created
     4257  if (count > 2) { // less than three triangles, then nothing will be created
    39714258    class TesselPoint *TriangleCandidates[3];
    39724259    count = 0;
    3973     for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
     4260    for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
    39744261      if (ListAdvance != ListOfClosedPaths->end())
    39754262        ListAdvance++;
    39764263
    39774264      connectedPath = *ListRunner;
    3978 
    39794265      // re-create all triangles by going through connected points list
    39804266      LineList NewLines;
    3981       for (;!connectedPath->empty();) {
     4267      for (; !connectedPath->empty();) {
    39824268        // search middle node with widest angle to next neighbours
    39834269        EndNode = connectedPath->end();
    39844270        smallestangle = 0.;
    39854271        for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
    3986           Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
     4272          DoLog(1) && (Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
    39874273          // construct vectors to next and previous neighbour
    39884274          StartNode = MiddleNode;
     
    39914277          StartNode--;
    39924278          //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl;
    3993           Point.CopyVector((*StartNode)->node);
    3994           Point.SubtractVector((*MiddleNode)->node);
     4279          Point = (*(*StartNode)->node) - (*(*MiddleNode)->node);
    39954280          StartNode = MiddleNode;
    39964281          StartNode++;
     
    39984283            StartNode = connectedPath->begin();
    39994284          //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl;
    4000           Reference.CopyVector((*StartNode)->node);
    4001           Reference.SubtractVector((*MiddleNode)->node);
    4002           OrthogonalVector.CopyVector((*MiddleNode)->node);
    4003           OrthogonalVector.SubtractVector(&OldPoint);
    4004           OrthogonalVector.MakeNormalVector(&Reference);
     4285          Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node);
     4286          OrthogonalVector = (*(*MiddleNode)->node) - OldPoint;
     4287          OrthogonalVector.MakeNormalTo(Reference);
    40054288          angle = GetAngle(Point, Reference, OrthogonalVector);
    40064289          //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             }
     4290          if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
     4291            smallestangle = angle;
     4292            EndNode = MiddleNode;
     4293          }
    40114294        }
    40124295        MiddleNode = EndNode;
    40134296        if (MiddleNode == connectedPath->end()) {
    4014           eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl;
     4297          DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);
    40154298          performCriticalExit();
    40164299        }
     
    40224305        if (EndNode == connectedPath->end())
    40234306          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;
     4307        DoLog(2) && (Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl);
     4308        DoLog(2) && (Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
     4309        DoLog(2) && (Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl);
     4310        DoLog(1) && (Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->getName() << ", " << (*MiddleNode)->getName() << " and " << (*EndNode)->getName() << "." << endl);
    40284311        TriangleCandidates[0] = *StartNode;
    40294312        TriangleCandidates[1] = *MiddleNode;
     
    40314314        triangle = GetPresentTriangle(TriangleCandidates);
    40324315        if (triangle != NULL) {
    4033           eLog() << Verbose(0) << "New triangle already present, skipping!" << endl;
     4316          DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl);
    40344317          StartNode++;
    40354318          MiddleNode++;
     
    40434326          continue;
    40444327        }
    4045         Log() << Verbose(3) << "Adding new triangle points."<< endl;
     4328        DoLog(3) && (Log() << Verbose(3) << "Adding new triangle points." << endl);
    40464329        AddTesselationPoint(*StartNode, 0);
    40474330        AddTesselationPoint(*MiddleNode, 1);
    40484331        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);
     4332        DoLog(3) && (Log() << Verbose(3) << "Adding new triangle lines." << endl);
     4333        AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     4334        AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
    40524335        NewLines.push_back(BLS[1]);
    4053         AddTesselationLine(TPS[1], TPS[2], 2);
     4336        AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    40544337        BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    40554338        BTS->GetNormalVector(NormalVector);
     
    40624345        // prepare nodes for next triangle
    40634346        StartNode = EndNode;
    4064         Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
     4347        DoLog(2) && (Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl);
    40654348        connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
    40664349        if (connectedPath->size() == 2) { // we are done
     
    40694352          break;
    40704353        } else if (connectedPath->size() < 2) { // something's gone wrong!
    4071           eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl;
     4354          DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);
    40724355          performCriticalExit();
    40734356        } else {
     
    40894372        do {
    40904373          maxgain = 0;
    4091           for(LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
     4374          for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
    40924375            tmp = PickFarthestofTwoBaselines(*Runner);
    40934376            if (maxgain < tmp) {
     
    40984381          if (maxgain != 0) {
    40994382            volume += maxgain;
    4100             Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
     4383            DoLog(1) && (Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl);
    41014384            OtherBase = FlipBaseline(*Candidate);
    41024385            NewLines.erase(Candidate);
     
    41074390
    41084391      ListOfClosedPaths->remove(connectedPath);
    4109       delete(connectedPath);
    4110     }
    4111     Log() << Verbose(0) << count << " triangles were created." << endl;
     4392      delete (connectedPath);
     4393    }
     4394    DoLog(0) && (Log() << Verbose(0) << count << " triangles were created." << endl);
    41124395  } else {
    41134396    while (!ListOfClosedPaths->empty()) {
     
    41154398      connectedPath = *ListRunner;
    41164399      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;
     4400      delete (connectedPath);
     4401    }
     4402    DoLog(0) && (Log() << Verbose(0) << "No need to create any triangles." << endl);
     4403  }
     4404  delete (ListOfClosedPaths);
     4405
     4406  DoLog(0) && (Log() << Verbose(0) << "Removed volume is " << volume << "." << endl);
    41244407
    41254408  return volume;
    4126 };
    4127 
    4128 
     4409}
     4410;
    41294411
    41304412/**
     
    41384420TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    41394421{
    4140         Info FunctionInfo(__func__);
    4141         TriangleList *result = new TriangleList;
     4422  Info FunctionInfo(__func__);
     4423  TriangleList *result = new TriangleList;
    41424424  LineMap::const_iterator FindLine;
    41434425  TriangleMap::const_iterator FindTriangle;
     
    41634445      for (int i = 0; i < 3; i++) {
    41644446        if (TrianglePoints[i] != NULL) {
    4165           for (int j = i+1; j < 3; j++) {
     4447          for (int j = i + 1; j < 3; j++) {
    41664448            if (TrianglePoints[j] != NULL) {
    41674449              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++) {
     4450              (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) {
     4451                for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
    41734452                  if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    41744453                    result->push_back(FindTriangle->second);
     
    41854464    case 1: // copy all triangles of the respective line
    41864465    {
    4187       int i=0;
     4466      int i = 0;
    41884467      for (; i < 3; i++)
    41894468        if (TrianglePoints[i] == NULL)
    41904469          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++) {
     4470      for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap!
     4471      (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) {
     4472        for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
    41974473          if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    41984474            result->push_back(FindTriangle->second);
     
    42044480    case 2: // copy all triangles of the respective point
    42054481    {
    4206       int i=0;
     4482      int i = 0;
    42074483      for (; i < 3; i++)
    42084484        if (TrianglePoints[i] != NULL)
     
    42224498    }
    42234499    default:
    4224       eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl;
     4500      DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);
    42254501      performCriticalExit();
    42264502      break;
     
    42304506}
    42314507
    4232 struct BoundaryLineSetCompare {
    4233   bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) {
     4508struct BoundaryLineSetCompare
     4509{
     4510  bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b)
     4511  {
    42344512    int lowerNra = -1;
    42354513    int lowerNrb = -1;
     
    42494527    else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
    42504528      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;
     4529    else { // both lower-numbered endpoints are the same ...
     4530      if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2])
     4531        return true;
     4532      else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2])
     4533        return false;
    42564534    }
    42574535    return false;
    4258   };
     4536  }
     4537  ;
    42594538};
    42604539
     
    42694548IndexToIndex * Tesselation::FindAllDegeneratedLines()
    42704549{
    4271         Info FunctionInfo(__func__);
    4272         UniqueLines AllLines;
     4550  Info FunctionInfo(__func__);
     4551  UniqueLines AllLines;
    42734552  IndexToIndex * DegeneratedLines = new IndexToIndex;
    42744553
    42754554  // sanity check
    42764555  if (LinesOnBoundary.empty()) {
    4277     eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.";
     4556    DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");
    42784557    return DegeneratedLines;
    42794558  }
    4280 
    42814559  LineMap::iterator LineRunner1;
    4282   pair< UniqueLines::iterator, bool> tester;
     4560  pair<UniqueLines::iterator, bool> tester;
    42834561  for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
    4284     tester = AllLines.insert( LineRunner1->second );
     4562    tester = AllLines.insert(LineRunner1->second);
    42854563    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) );
     4564      DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));
     4565      DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));
    42884566    }
    42894567  }
     
    42914569  AllLines.clear();
    42924570
    4293   Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
     4571  DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl);
    42944572  IndexToIndex::iterator it;
    42954573  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
     
    42974575    const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
    42984576    if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
    4299       Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl;
     4577      DoLog(0) && (Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl);
    43004578    else
    4301       eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl;
     4579      DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);
    43024580  }
    43034581
     
    43134591IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
    43144592{
    4315         Info FunctionInfo(__func__);
     4593  Info FunctionInfo(__func__);
    43164594  IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
    43174595  IndexToIndex * DegeneratedTriangles = new IndexToIndex;
    4318 
    43194596  TriangleMap::iterator TriangleRunner1, TriangleRunner2;
    43204597  LineMap::iterator Liner;
     
    43314608    for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
    43324609      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) );
     4610        if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
     4611          DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr));
     4612          DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr));
    43374613        }
    43384614      }
    43394615    }
    43404616  }
    4341   delete(DegeneratedLines);
    4342 
    4343   Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
     4617  delete (DegeneratedLines);
     4618
     4619  DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl);
    43444620  IndexToIndex::iterator it;
    43454621  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    4346       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     4622    DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
    43474623
    43484624  return DegeneratedTriangles;
     
    43554631void Tesselation::RemoveDegeneratedTriangles()
    43564632{
    4357         Info FunctionInfo(__func__);
     4633  Info FunctionInfo(__func__);
    43584634  IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
    43594635  TriangleMap::iterator finder;
    43604636  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    4361   int count  = 0;
    4362 
    4363   for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
    4364     TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
    4365   ) {
     4637  int count = 0;
     4638
     4639  for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) {
    43664640    finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
    43674641    if (finder != TrianglesOnBoundary.end())
     
    43804654        trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
    43814655
    4382     if (trianglesShareLine
    4383       && (triangle->endpoints[1]->LinesCount > 2)
    4384       && (triangle->endpoints[2]->LinesCount > 2)
    4385       && (triangle->endpoints[0]->LinesCount > 2)
    4386     ) {
     4656    if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) {
    43874657      // check whether we have to fix lines
    43884658      BoundaryTriangleSet *Othertriangle = NULL;
     
    44044674            // the line of triangle receives the degenerated ones
    44054675            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++)
     4676            triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle));
     4677            for (int k = 0; k < 3; k++)
    44084678              if (triangle->lines[i] == Othertriangle->lines[k]) {
    44094679                Othertriangle->lines[k] = partnerTriangle->lines[j];
     
    44114681              }
    44124682            // 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) );
     4683            partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr);
     4684            partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle));
    44154685            partnerTriangle->lines[j] = triangle->lines[i];
    44164686          }
     
    44184688      // erase the pair
    44194689      count += (int) DegeneratedTriangles->erase(triangle->Nr);
    4420       Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
     4690      DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl);
    44214691      RemoveTesselationTriangle(triangle);
    44224692      count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
    4423       Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
     4693      DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl);
    44244694      RemoveTesselationTriangle(partnerTriangle);
    44254695    } 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);
     4696      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);
     4697    }
     4698  }
     4699  delete (DegeneratedTriangles);
    44324700  if (count > 0)
    44334701    LastTriangle = NULL;
    44344702
    4435   Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
     4703  DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl);
    44364704}
    44374705
     
    44464714void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
    44474715{
    4448         Info FunctionInfo(__func__);
     4716  Info FunctionInfo(__func__);
    44494717  // find nearest boundary point
    44504718  class TesselPoint *BackupPoint = NULL;
     
    44594727    NearestBoundaryPoint = PointRunner->second;
    44604728  } else {
    4461     eLog() << Verbose(1) << "I cannot find the boundary point." << endl;
     4729    DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl);
    44624730    return;
    44634731  }
    4464   Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
     4732  DoLog(0) && (Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->getName() << "." << endl);
    44654733
    44664734  // go through its lines and find the best one to split
     
    44704738  class BoundaryLineSet *BestLine = NULL;
    44714739  for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
    4472     BaseLine.CopyVector(Runner->second->endpoints[0]->node->node);
    4473     BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node);
    4474     CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node);
    4475     CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node);
    4476     CenterToPoint.Scale(0.5);
    4477     CenterToPoint.SubtractVector(point->node);
    4478     angle = CenterToPoint.Angle(&BaseLine);
     4740    BaseLine = (*Runner->second->endpoints[0]->node->node) -
     4741               (*Runner->second->endpoints[1]->node->node);
     4742    CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) +
     4743                           (*Runner->second->endpoints[1]->node->node));
     4744    CenterToPoint -= (*point->node);
     4745    angle = CenterToPoint.Angle(BaseLine);
    44794746    if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
    44804747      BestAngle = angle;
     
    44874754  BestLine->triangles.erase(TempTriangle->Nr);
    44884755  int nr = -1;
    4489   for (int i=0;i<3; i++) {
     4756  for (int i = 0; i < 3; i++) {
    44904757    if (TempTriangle->lines[i] == BestLine) {
    44914758      nr = i;
     
    44954762
    44964763  // 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;
     4764  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
    44984765  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    44994766  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    45004767  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);
     4768  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
     4769  AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     4770  AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     4771  AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    45054772  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    45064773  BTS->GetNormalVector(TempTriangle->NormalVector);
    45074774  BTS->NormalVector.Scale(-1.);
    4508   Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
     4775  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl);
    45094776  AddTesselationTriangle();
    45104777
    45114778  // 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;
     4779  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
    45134780  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    45144781  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    45154782  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);
     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);
    45204787  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    45214788  BTS->GetNormalVector(TempTriangle->NormalVector);
    4522   Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
     4789  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl);
    45234790  AddTesselationTriangle();
    45244791
    45254792  // 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)
     4793  for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion)
    45274794    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;
     4795      if (BestLine == BTS->lines[i]) {
     4796        DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl);
    45304797        performCriticalExit();
    45314798      }
    4532       BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle) );
     4799      BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));
    45334800      TempTriangle->lines[nr] = BTS->lines[i];
    45344801      break;
    45354802    }
    45364803  }
    4537 };
     4804}
     4805;
    45384806
    45394807/** Writes the envelope to file.
     
    45444812void Tesselation::Output(const char *filename, const PointCloud * const cloud)
    45454813{
    4546         Info FunctionInfo(__func__);
     4814  Info FunctionInfo(__func__);
    45474815  ofstream *tempstream = NULL;
    45484816  string NameofTempFile;
    4549   char NumberName[255];
     4817  string NumberName;
    45504818
    45514819  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);
     4820    stringstream sstr;
     4821    sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle->getEndpointName(0) << "_" << LastTriangle->getEndpointName(1) << "_" << LastTriangle->getEndpointName(2);
     4822    NumberName = sstr.str();
    45534823    if (DoTecplotOutput) {
    45544824      string NameofTempFile(filename);
    45554825      NameofTempFile.append(NumberName);
    4556       for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
    4557       NameofTempFile.erase(npos, 1);
     4826      for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
     4827        NameofTempFile.erase(npos, 1);
    45584828      NameofTempFile.append(TecplotSuffix);
    4559       Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     4829      DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
    45604830      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    45614831      WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
    45624832      tempstream->close();
    45634833      tempstream->flush();
    4564       delete(tempstream);
     4834      delete (tempstream);
    45654835    }
    45664836
     
    45684838      string NameofTempFile(filename);
    45694839      NameofTempFile.append(NumberName);
    4570       for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
    4571       NameofTempFile.erase(npos, 1);
     4840      for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
     4841        NameofTempFile.erase(npos, 1);
    45724842      NameofTempFile.append(Raster3DSuffix);
    4573       Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     4843      DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
    45744844      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    45754845      WriteRaster3dFile(tempstream, this, cloud);
     
    45774847      tempstream->close();
    45784848      tempstream->flush();
    4579       delete(tempstream);
     4849      delete (tempstream);
    45804850    }
    45814851  }
    45824852  if (DoTecplotOutput || DoRaster3DOutput)
    45834853    TriangleFilesWritten++;
    4584 };
    4585 
    4586 struct BoundaryPolygonSetCompare {
    4587   bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const {
     4854}
     4855;
     4856
     4857struct BoundaryPolygonSetCompare
     4858{
     4859  bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const
     4860  {
    45884861    if (s1->endpoints.size() < s2->endpoints.size())
    45894862      return true;
     
    46144887{
    46154888  Info FunctionInfo(__func__);
    4616 
    46174889  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
    46184890  IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
    4619   set < BoundaryPointSet *> EndpointCandidateList;
    4620   pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
    4621   pair < map < int, Vector *>::iterator, bool > TriangleInsertionTester;
     4891  set<BoundaryPointSet *> EndpointCandidateList;
     4892  pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester;
     4893  pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester;
    46224894  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;
     4895    DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl);
     4896    map<int, Vector *> TriangleVectors;
    46254897    // gather all NormalVectors
    4626     Log() << Verbose(1) << "Gathering triangles ..." << endl;
     4898    DoLog(1) && (Log() << Verbose(1) << "Gathering triangles ..." << endl);
    46274899    for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
    46284900      for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    46294901        if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
    4630           TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) );
     4902          TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));
    46314903          if (TriangleInsertionTester.second)
    4632             Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;
     4904            DoLog(1) && (Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl);
    46334905        } else {
    4634           Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl;
     4906          DoLog(1) && (Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl);
    46354907        }
    46364908      }
    46374909    // 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++)
     4910    DoLog(1) && (Log() << Verbose(1) << "Finding two parallel triangles ..." << endl);
     4911    for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
     4912      for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
    46414913        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;
     4914          const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
     4915          DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl);
    46444916          if (fabs(SCP + 1.) < ParallelEpsilon) {
    46454917            InsertionTester = EndpointCandidateList.insert((Runner->second));
    46464918            if (InsertionTester.second)
    4647               Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl;
     4919              DoLog(0) && (Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl);
    46484920            // and break out of both loops
    46494921            VectorWalker = TriangleVectors.end();
     
    46604932  BoundaryPointSet *OtherWalker = NULL;
    46614933  BoundaryPolygonSet *Current = NULL;
    4662   stack <BoundaryPointSet*> ToCheckConnecteds;
     4934  stack<BoundaryPointSet*> ToCheckConnecteds;
    46634935  while (!EndpointCandidateList.empty()) {
    46644936    Walker = *(EndpointCandidateList.begin());
    4665     if (Current == NULL) {  // create a new polygon with current candidate
    4666       Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl;
     4937    if (Current == NULL) { // create a new polygon with current candidate
     4938      DoLog(0) && (Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl);
    46674939      Current = new BoundaryPolygonSet;
    46684940      Current->endpoints.insert(Walker);
     
    46774949      for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
    46784950        OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
    4679         Log() << Verbose(1) << "Checking " << *OtherWalker << endl;
    4680         set < BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
    4681         if (Finder != EndpointCandidateList.end()) {  // found a connected partner
    4682           Log() << Verbose(1) << " Adding to polygon." << endl;
     4951        DoLog(1) && (Log() << Verbose(1) << "Checking " << *OtherWalker << endl);
     4952        set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
     4953        if (Finder != EndpointCandidateList.end()) { // found a connected partner
     4954          DoLog(1) && (Log() << Verbose(1) << " Adding to polygon." << endl);
    46834955          Current->endpoints.insert(OtherWalker);
    4684           EndpointCandidateList.erase(Finder);  // remove from candidates
    4685           ToCheckConnecteds.push(OtherWalker);  // but check its partners too
     4956          EndpointCandidateList.erase(Finder); // remove from candidates
     4957          ToCheckConnecteds.push(OtherWalker); // but check its partners too
    46864958        } else {
    4687           Log() << Verbose(1) << " is not connected to " << *Walker << endl;
     4959          DoLog(1) && (Log() << Verbose(1) << " is not connected to " << *Walker << endl);
    46884960        }
    46894961      }
    46904962    }
    46914963
    4692     Log() << Verbose(0) << "Final polygon is " << *Current << endl;
     4964    DoLog(0) && (Log() << Verbose(0) << "Final polygon is " << *Current << endl);
    46934965    ListofDegeneratedPolygons.insert(Current);
    46944966    Current = NULL;
     
    46974969  const int counter = ListofDegeneratedPolygons.size();
    46984970
    4699   Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl;
     4971  DoLog(0) && (Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl);
    47004972  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
    4701     Log() << Verbose(0) << " " << **PolygonRunner << endl;
     4973    DoLog(0) && (Log() << Verbose(0) << " " << **PolygonRunner << endl);
    47024974
    47034975  /// 4. Go through all these degenerated polygons
    47044976  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
    4705     stack <int> TriangleNrs;
     4977    stack<int> TriangleNrs;
    47064978    Vector NormalVector;
    47074979    /// 4a. Gather all triangles of this polygon
     
    47104982    // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do.
    47114983    if (T->size() == 2) {
    4712       Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl;
    4713       delete(T);
     4984      DoLog(1) && (Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl);
     4985      delete (T);
    47144986      continue;
    47154987    }
     
    47204992    // connections to either polygon ...
    47214993    if (T->size() % 2 != 0) {
    4722       eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl;
     4994      DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);
    47234995      performCriticalExit();
    47244996    }
    4725 
    4726     TriangleSet::iterator TriangleWalker = T->begin();  // is the inner iterator
     4997    TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
    47274998    /// 4a. Get NormalVector for one side (this is "front")
    4728     NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
    4729     Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl;
     4999    NormalVector = (*TriangleWalker)->NormalVector;
     5000    DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl);
    47305001    TriangleWalker++;
    47315002    TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
     
    47365007      triangle = *TriangleWalker;
    47375008      TriangleSprinter++;
    4738       Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl;
    4739       if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
    4740         Log() << Verbose(1) << " Removing ... " << endl;
     5009      DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl);
     5010      if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list
     5011        DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl);
    47415012        TriangleNrs.push(triangle->Nr);
    47425013        T->erase(TriangleWalker);
    47435014        RemoveTesselationTriangle(triangle);
    47445015      } else
    4745         Log() << Verbose(1) << " Keeping ... " << endl;
     5016        DoLog(1) && (Log() << Verbose(1) << " Keeping ... " << endl);
    47465017    }
    47475018    /// 4c. Copy all "front" triangles but with inverse NormalVector
    47485019    TriangleWalker = T->begin();
    4749     while (TriangleWalker != T->end()) {  // go through all front triangles
    4750       Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl;
     5020    while (TriangleWalker != T->end()) { // go through all front triangles
     5021      DoLog(1) && (Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl);
    47515022      for (int i = 0; i < 3; i++)
    47525023        AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
    4753       AddTesselationLine(TPS[0], TPS[1], 0);
    4754       AddTesselationLine(TPS[0], TPS[2], 1);
    4755       AddTesselationLine(TPS[1], TPS[2], 2);
     5024      AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     5025      AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     5026      AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    47565027      if (TriangleNrs.empty())
    4757         eLog() << Verbose(0) << "No more free triangle numbers!" << endl;
     5028        DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl);
    47585029      BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
    47595030      AddTesselationTriangle(); // ... and add
    47605031      TriangleNrs.pop();
    4761       BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
    4762       BTS->NormalVector.Scale(-1.);
     5032      BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector;
    47635033      TriangleWalker++;
    47645034    }
    47655035    if (!TriangleNrs.empty()) {
    4766       eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl;
    4767     }
    4768     delete(T);  // remove the triangleset
    4769   }
    4770 
     5036      DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl);
     5037    }
     5038    delete (T); // remove the triangleset
     5039  }
    47715040  IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
    4772   Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
     5041  DoLog(0) && (Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl);
    47735042  IndexToIndex::iterator it;
    47745043  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
    4775       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
    4776   delete(SimplyDegeneratedTriangles);
    4777 
     5044    DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
     5045  delete (SimplyDegeneratedTriangles);
    47785046  /// 5. exit
    47795047  UniquePolygonSet::iterator PolygonRunner;
    47805048  while (!ListofDegeneratedPolygons.empty()) {
    47815049    PolygonRunner = ListofDegeneratedPolygons.begin();
    4782     delete(*PolygonRunner);
     5050    delete (*PolygonRunner);
    47835051    ListofDegeneratedPolygons.erase(PolygonRunner);
    47845052  }
    47855053
    47865054  return counter;
    4787 };
     5055}
     5056;
Note: See TracChangeset for help on using the changeset viewer.