Changeset 6613ec


Ignore:
Timestamp:
Apr 21, 2010, 12:07:01 PM (15 years ago)
Author:
Frederik Heber <heber@…>
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, 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:
a67d19
Parents:
bc84ffc
git-author:
Frederik Heber <heber@…> (04/21/10 11:51:53)
git-committer:
Frederik Heber <heber@…> (04/21/10 12:07:01)
Message:

Rewrite of tesselation: treatment of degenerated triangles and polygons

several tricks have been necessary to make it work for heptane:

  • AddDegeneratedTriangle() is not used, instead AddCandidateTriangle() gets told which OptCenter to use, i.e. which triangle side to add
  • afterwards, in the case of a polygon (multiple candidates for a baseline) we have to set the candidate of internal edges in the polygon to the next point, such that AddTesselationLine() picks the right one
  • The we fill other open lines, needed in case of a degenerated triangle
  • If CheckDegeneracy() - which removes all candidates from the ListOfPoints, not just the first - results in true
  • Then we call AddCandidateTriangle() for the other side of it
  • and again in the case of a polygon, set the candidate for the internal edge accordingly.

Signed-off-by: Frederik Heber <heber@…>

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    rbc84ffc r6613ec  
    960960  bool freeLC = false;
    961961  bool status = false;
    962   CandidateForTesselation *baseline;
    963   LineMap::iterator testline;
     962  CandidateForTesselation *baseline = NULL;
    964963  bool OneLoopWithoutSuccessFlag = true;  // marks whether we went once through all baselines without finding any without two triangles
    965964  bool TesselationFailFlag = false;
    966   BoundaryTriangleSet *T = NULL;
    967965
    968966  if (TesselStruct == NULL) {
     
    997995
    998996    // 2b. find best candidate for each OpenLine
    999     for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
    1000       baseline = Runner->second;
    1001       if (baseline->pointlist.empty()) {
    1002         T = (((baseline->BaseLine->triangles.begin()))->second);
    1003         Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl;
    1004         TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
    1005       }
    1006     }
     997    TesselationFailFlag = TesselStruct->FindCandidatesforOpenLines(RADIUS, LCList);
    1007998
    1008999    // 2c. print OpenLines with candidates again
     
    10621053  StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
    10631054
    1064   // correct degenerated polygons
    1065   TesselStruct->CorrectAllDegeneratedPolygons();
    1066 
    1067   // check envelope for consistency
    1068   status = CheckListOfBaselines(TesselStruct);
     1055//  // correct degenerated polygons
     1056//  TesselStruct->CorrectAllDegeneratedPolygons();
     1057//
     1058//  // check envelope for consistency
     1059//  status = CheckListOfBaselines(TesselStruct);
    10691060
    10701061  // write final envelope
  • src/tesselation.cpp

    rbc84ffc r6613ec  
    2525 */
    2626BoundaryPointSet::BoundaryPointSet() :
    27     LinesCount(0),
    28     value(0.),
    29     Nr(-1)
    30 {
    31         Info FunctionInfo(__func__);
    32         Log() << Verbose(1) << "Adding noname." << endl;
    33 };
     27  LinesCount(0), value(0.), Nr(-1)
     28{
     29  Info FunctionInfo(__func__);
     30  Log() << Verbose(1) << "Adding noname." << endl;
     31}
     32;
    3433
    3534/** Constructor of BoundaryPointSet with Tesselpoint.
     
    3736 */
    3837BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) :
    39   LinesCount(0),
    40   node(Walker),
    41   value(0.),
    42   Nr(Walker->nr)
    43 {
    44         Info FunctionInfo(__func__);
     38  LinesCount(0), node(Walker), value(0.), Nr(Walker->nr)
     39{
     40  Info FunctionInfo(__func__);
    4541  Log() << Verbose(1) << "Adding Node " << *Walker << endl;
    46 };
     42}
     43;
    4744
    4845/** Destructor of BoundaryPointSet.
     
    5249BoundaryPointSet::~BoundaryPointSet()
    5350{
    54         Info FunctionInfo(__func__);
     51  Info FunctionInfo(__func__);
    5552  //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
    5653  if (!lines.empty())
    57     DoeLog(2) && (eLog()<< Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);
     54    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);
    5855  node = NULL;
    59 };
     56}
     57;
    6058
    6159/** Add a line to the LineMap of this point.
     
    6462void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
    6563{
    66         Info FunctionInfo(__func__);
    67   Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "."
    68       << endl;
    69   if (line->endpoints[0] == this)
    70     {
    71       lines.insert(LinePair(line->endpoints[1]->Nr, line));
    72     }
    73   else
    74     {
    75       lines.insert(LinePair(line->endpoints[0]->Nr, line));
    76     }
     64  Info FunctionInfo(__func__);
     65  Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl;
     66  if (line->endpoints[0] == this) {
     67    lines.insert(LinePair(line->endpoints[1]->Nr, line));
     68  } else {
     69    lines.insert(LinePair(line->endpoints[0]->Nr, line));
     70  }
    7771  LinesCount++;
    78 };
     72}
     73;
    7974
    8075/** output operator for BoundaryPointSet.
     
    9489 */
    9590BoundaryLineSet::BoundaryLineSet() :
    96     Nr(-1)
    97 {
    98         Info FunctionInfo(__func__);
     91  Nr(-1)
     92{
     93  Info FunctionInfo(__func__);
    9994  for (int i = 0; i < 2; i++)
    10095    endpoints[i] = NULL;
    101 };
     96}
     97;
    10298
    10399/** Constructor of BoundaryLineSet with two endpoints.
     
    108104BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
    109105{
    110         Info FunctionInfo(__func__);
     106  Info FunctionInfo(__func__);
    111107  // set number
    112108  Nr = number;
     
    120116  // clear triangles list
    121117  Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
    122 };
     118}
     119;
    123120
    124121/** Constructor of BoundaryLineSet with two endpoints.
     
    142139  // clear triangles list
    143140  Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
    144 };
     141}
     142;
    145143
    146144/** Destructor for BoundaryLineSet.
     
    150148BoundaryLineSet::~BoundaryLineSet()
    151149{
    152         Info FunctionInfo(__func__);
     150  Info FunctionInfo(__func__);
    153151  int Numbers[2];
    154152
     
    181179        //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
    182180        if (endpoints[i] != NULL) {
    183           delete(endpoints[i]);
     181          delete (endpoints[i]);
    184182          endpoints[i] = NULL;
    185183        }
     
    188186  }
    189187  if (!triangles.empty())
    190     DoeLog(2) && (eLog()<< Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
    191 };
     188    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
     189}
     190;
    192191
    193192/** Add triangle to TriangleMap of this boundary line.
     
    196195void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
    197196{
    198         Info FunctionInfo(__func__);
     197  Info FunctionInfo(__func__);
    199198  Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
    200199  triangles.insert(TrianglePair(triangle->Nr, triangle));
    201 };
     200}
     201;
    202202
    203203/** Checks whether we have a common endpoint with given \a *line.
     
    207207bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
    208208{
    209         Info FunctionInfo(__func__);
     209  Info FunctionInfo(__func__);
    210210  if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
    211211    return true;
    212212  else
    213213    return false;
    214 };
     214}
     215;
    215216
    216217/** Checks whether the adjacent triangles of a baseline are convex or not.
     
    222223bool BoundaryLineSet::CheckConvexityCriterion() const
    223224{
    224         Info FunctionInfo(__func__);
     225  Info FunctionInfo(__func__);
    225226  Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
    226227  // get the two triangles
    227228  if (triangles.size() != 2) {
    228     DoeLog(0) && (eLog()<< Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
     229    DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
    229230    return true;
    230231  }
     
    234235  BaseLineCenter.CopyVector(endpoints[0]->node->node);
    235236  BaseLineCenter.AddVector(endpoints[1]->node->node);
    236   BaseLineCenter.Scale(1./2.);
     237  BaseLineCenter.Scale(1. / 2.);
    237238  BaseLine.CopyVector(endpoints[0]->node->node);
    238239  BaseLine.SubtractVector(endpoints[1]->node->node);
     
    242243  NormalCheck.Zero();
    243244  double sign = -1.;
    244   int i=0;
     245  int i = 0;
    245246  class BoundaryPointSet *node = NULL;
    246   for(TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
     247  for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    247248    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    248249    NormalCheck.AddVector(&runner->second->NormalVector);
     
    250251    sign = -sign;
    251252    if (runner->second->NormalVector.NormSquared() > MYEPSILON)
    252       BaseLineNormal.CopyVector(&runner->second->NormalVector);   // yes, copy second on top of first
     253      BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first
    253254    else {
    254       DoeLog(0) && (eLog()<< Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
     255      DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
    255256    }
    256257    node = runner->second->GetThirdEndpoint(this);
     
    259260      helper[i].CopyVector(node->node->node);
    260261      helper[i].SubtractVector(&BaseLineCenter);
    261       helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
     262      helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles!
    262263      //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    263264      i++;
    264265    } else {
    265       DoeLog(1) && (eLog()<< Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
     266      DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
    266267      return true;
    267268    }
     
    289290bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    290291{
    291         Info FunctionInfo(__func__);
    292   for(int i=0;i<2;i++)
     292  Info FunctionInfo(__func__);
     293  for (int i = 0; i < 2; i++)
    293294    if (point == endpoints[i])
    294295      return true;
    295296  return false;
    296 };
     297}
     298;
    297299
    298300/** Returns other endpoint of the line.
     
    302304class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
    303305{
    304         Info FunctionInfo(__func__);
     306  Info FunctionInfo(__func__);
    305307  if (endpoints[0] == point)
    306308    return endpoints[1];
     
    309311  else
    310312    return NULL;
    311 };
     313}
     314;
    312315
    313316/** output operator for BoundaryLineSet.
     
    315318 * \param &a boundary line
    316319 */
    317 ostream & operator <<(ostream &ost, const  BoundaryLineSet &a)
     320ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
    318321{
    319322  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 << "]";
    320323  return ost;
    321 };
     324}
     325;
    322326
    323327// ======================================== Triangles on Boundary =================================
     
    328332  Nr(-1)
    329333{
    330         Info FunctionInfo(__func__);
    331   for (int i = 0; i < 3; i++)
    332     {
    333       endpoints[i] = NULL;
    334       lines[i] = NULL;
    335     }
    336 };
     334  Info FunctionInfo(__func__);
     335  for (int i = 0; i < 3; i++) {
     336    endpoints[i] = NULL;
     337    lines[i] = NULL;
     338  }
     339}
     340;
    337341
    338342/** Constructor for BoundaryTriangleSet with three lines.
     
    343347  Nr(number)
    344348{
    345         Info FunctionInfo(__func__);
     349  Info FunctionInfo(__func__);
    346350  // set number
    347351  // set lines
     
    355359    // for all three lines
    356360    for (int j = 0; j < 2; j++) { // for both endpoints
    357       OrderMap.insert(pair<int, class BoundaryPointSet *> (
    358           line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
     361      OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
    359362      // and we don't care whether insertion fails
    360363    }
     
    368371  }
    369372  if (Counter < 3) {
    370     DoeLog(0) && (eLog()<< Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl);
     373    DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl);
    371374    performCriticalExit();
    372375  }
    373 };
     376}
     377;
    374378
    375379/** Destructor of BoundaryTriangleSet.
     
    379383BoundaryTriangleSet::~BoundaryTriangleSet()
    380384{
    381         Info FunctionInfo(__func__);
     385  Info FunctionInfo(__func__);
    382386  for (int i = 0; i < 3; i++) {
    383387    if (lines[i] != NULL) {
     
    386390      }
    387391      if (lines[i]->triangles.empty()) {
    388           //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
    389           delete (lines[i]);
    390           lines[i] = NULL;
     392        //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
     393        delete (lines[i]);
     394        lines[i] = NULL;
    391395      }
    392396    }
    393397  }
    394398  //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
    395 };
     399}
     400;
    396401
    397402/** Calculates the normal vector for this triangle.
     
    401406void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
    402407{
    403         Info FunctionInfo(__func__);
     408  Info FunctionInfo(__func__);
    404409  // get normal vector
    405410  NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     
    409414    NormalVector.Scale(-1.);
    410415  Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl;
    411 };
     416}
     417;
    412418
    413419/** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
     
    430436
    431437  if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
    432     DoeLog(1) && (eLog()<< Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
     438    DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
    433439    return false;
    434440  }
     
    441447    Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl;
    442448    return true;
    443   }   else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
     449  } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
    444450    Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl;
    445451    return true;
    446   }   else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
     452  } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
    447453    Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl;
    448454    return true;
    449455  }
    450456  // Calculate cross point between one baseline and the line from the third endpoint to intersection
    451   int i=0;
     457  int i = 0;
    452458  do {
    453     if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) {
    454       helper.CopyVector(endpoints[(i+1)%3]->node->node);
    455       helper.SubtractVector(endpoints[i%3]->node->node);
    456       CrossPoint.SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector
    457       const double s = CrossPoint.ScalarProduct(&helper)/helper.NormSquared();
     459    if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) {
     460      helper.CopyVector(endpoints[(i + 1) % 3]->node->node);
     461      helper.SubtractVector(endpoints[i % 3]->node->node);
     462      CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
     463      const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared();
    458464      Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl;
    459       if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
     465      if ((s < -MYEPSILON) || ((s - 1.) > MYEPSILON)) {
    460466        Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl;
    461         i=4;
     467        i = 4;
    462468        break;
    463469      }
    464470      i++;
    465     } else 
     471    } else
    466472      break;
    467   } while (i<3);
    468   if (i==3) {
     473  } while (i < 3);
     474  if (i == 3) {
    469475    Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl;
    470476    return true;
     
    473479    return false;
    474480  }
    475 };
     481}
     482;
    476483
    477484/** Finds the point on the triangle to the point \a *x.
     
    502509  Vector InPlane;
    503510  InPlane.CopyVector(x);
    504   InPlane.SubtractVector(ClosestPoint);  // points from plane intersection to straight-down point
     511  InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point
    505512  InPlane.ProjectOntoPlane(&NormalVector);
    506513  InPlane.AddVector(ClosestPoint);
     
    516523  Vector CrossPoint[3];
    517524  Vector helper;
    518   for (int i=0;i<3;i++) {
     525  for (int i = 0; i < 3; i++) {
    519526    // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
    520     Direction.CopyVector(endpoints[(i+1)%3]->node->node);
    521     Direction.SubtractVector(endpoints[i%3]->node->node);
     527    Direction.CopyVector(endpoints[(i + 1) % 3]->node->node);
     528    Direction.SubtractVector(endpoints[i % 3]->node->node);
    522529    // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
    523     CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node);
     530    CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node);
    524531    CrossDirection[i].CopyVector(&CrossPoint[i]);
    525532    CrossDirection[i].SubtractVector(&InPlane);
    526     CrossPoint[i].SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector
    527     const double s = CrossPoint[i].ScalarProduct(&Direction)/Direction.NormSquared();
     533    CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
     534    const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared();
    528535    Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl;
    529     if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
    530       CrossPoint[i].AddVector(endpoints[i%3]->node->node); // make cross point absolute again
    531       Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i%3]->node->node << " and " << *endpoints[(i+1)%3]->node->node << "." << endl;
     536    if ((s >= -MYEPSILON) && ((s - 1.) <= MYEPSILON)) {
     537      CrossPoint[i].AddVector(endpoints[i % 3]->node->node); // make cross point absolute again
     538      Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl;
    532539      const double distance = CrossPoint[i].DistanceSquared(x);
    533540      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
     
    539546  }
    540547  InsideFlag = true;
    541   for (int i=0;i<3;i++) {
    542     const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+1)%3]);
    543     const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+2)%3]);;
    544     if ((sign > -MYEPSILON) && (othersign > -MYEPSILON))  // have different sign
     548  for (int i = 0; i < 3; i++) {
     549    const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 1) % 3]);
     550    const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 2) % 3]);
     551    ;
     552    if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
    545553      InsideFlag = false;
    546554  }
     
    548556    ClosestPoint->CopyVector(&InPlane);
    549557    ShortestDistance = InPlane.DistanceSquared(x);
    550   } else {  // also check endnodes
    551     for (int i=0;i<3;i++) {
     558  } else { // also check endnodes
     559    for (int i = 0; i < 3; i++) {
    552560      const double distance = x->DistanceSquared(endpoints[i]->node->node);
    553561      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
     
    559567  Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl;
    560568  return ShortestDistance;
    561 };
     569}
     570;
    562571
    563572/** Checks whether lines is any of the three boundary lines this triangle contains.
     
    567576bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
    568577{
    569         Info FunctionInfo(__func__);
    570   for(int i=0;i<3;i++)
     578  Info FunctionInfo(__func__);
     579  for (int i = 0; i < 3; i++)
    571580    if (line == lines[i])
    572581      return true;
    573582  return false;
    574 };
     583}
     584;
    575585
    576586/** Checks whether point is any of the three endpoints this triangle contains.
     
    580590bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    581591{
    582         Info FunctionInfo(__func__);
    583   for(int i=0;i<3;i++)
     592  Info FunctionInfo(__func__);
     593  for (int i = 0; i < 3; i++)
    584594    if (point == endpoints[i])
    585595      return true;
    586596  return false;
    587 };
     597}
     598;
    588599
    589600/** Checks whether point is any of the three endpoints this triangle contains.
     
    593604bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
    594605{
    595         Info FunctionInfo(__func__);
    596   for(int i=0;i<3;i++)
     606  Info FunctionInfo(__func__);
     607  for (int i = 0; i < 3; i++)
    597608    if (point == endpoints[i]->node)
    598609      return true;
    599610  return false;
    600 };
     611}
     612;
    601613
    602614/** Checks whether three given \a *Points coincide with triangle's endpoints.
     
    606618bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
    607619{
    608         Info FunctionInfo(__func__);
    609         Log() << Verbose(1) << "INFO: Checking " << Points[0] << ","  << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl;
    610   return (((endpoints[0] == Points[0])
    611             || (endpoints[0] == Points[1])
    612             || (endpoints[0] == Points[2])
    613           ) && (
    614             (endpoints[1] == Points[0])
    615             || (endpoints[1] == Points[1])
    616             || (endpoints[1] == Points[2])
    617           ) && (
    618             (endpoints[2] == Points[0])
    619             || (endpoints[2] == Points[1])
    620             || (endpoints[2] == Points[2])
    621 
    622           ));
    623 };
     620  Info FunctionInfo(__func__);
     621  Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl;
     622  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])
     623
     624  ));
     625}
     626;
    624627
    625628/** Checks whether three given \a *Points coincide with triangle's endpoints.
     
    629632bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
    630633{
    631         Info FunctionInfo(__func__);
    632   return (((endpoints[0] == T->endpoints[0])
    633             || (endpoints[0] == T->endpoints[1])
    634             || (endpoints[0] == T->endpoints[2])
    635           ) && (
    636             (endpoints[1] == T->endpoints[0])
    637             || (endpoints[1] == T->endpoints[1])
    638             || (endpoints[1] == T->endpoints[2])
    639           ) && (
    640             (endpoints[2] == T->endpoints[0])
    641             || (endpoints[2] == T->endpoints[1])
    642             || (endpoints[2] == T->endpoints[2])
    643 
    644           ));
    645 };
     634  Info FunctionInfo(__func__);
     635  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])
     636
     637  ));
     638}
     639;
    646640
    647641/** Returns the endpoint which is not contained in the given \a *line.
     
    651645class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
    652646{
    653         Info FunctionInfo(__func__);
     647  Info FunctionInfo(__func__);
    654648  // sanity check
    655649  if (!ContainsBoundaryLine(line))
    656650    return NULL;
    657   for(int i=0;i<3;i++)
     651  for (int i = 0; i < 3; i++)
    658652    if (!line->ContainsBoundaryPoint(endpoints[i]))
    659653      return endpoints[i];
    660654  // actually, that' impossible :)
    661655  return NULL;
    662 };
     656}
     657;
    663658
    664659/** Calculates the center point of the triangle.
     
    668663void BoundaryTriangleSet::GetCenter(Vector * const center) const
    669664{
    670         Info FunctionInfo(__func__);
     665  Info FunctionInfo(__func__);
    671666  center->Zero();
    672   for(int i=0;i<3;i++)
     667  for (int i = 0; i < 3; i++)
    673668    center->AddVector(endpoints[i]->node->node);
    674   center->Scale(1./3.);
     669  center->Scale(1. / 3.);
    675670  Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl;
    676671}
     
    683678{
    684679  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]";
    685 //  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
    686 //      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
     680  //  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
     681  //      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
    687682  return ost;
    688 };
     683}
     684;
    689685
    690686// ======================================== Polygons on Boundary =================================
     
    696692{
    697693  Info FunctionInfo(__func__);
    698 };
     694}
     695;
    699696
    700697/** Destructor of BoundaryPolygonSet.
     
    707704  endpoints.clear();
    708705  Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl;
    709 };
     706}
     707;
    710708
    711709/** Calculates the normal vector for this triangle.
     
    721719  Vector *TotalNormal = new Vector;
    722720  PointSet::const_iterator Runner[3];
    723   for (int i=0;i<3; i++) {
     721  for (int i = 0; i < 3; i++) {
    724722    Runner[i] = endpoints.begin();
    725     for (int j = 0; j<i; j++) { // go as much further
     723    for (int j = 0; j < i; j++) { // go as much further
    726724      Runner[i]++;
    727725      if (Runner[i] == endpoints.end()) {
    728         DoeLog(0) && (eLog()<< Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
     726        DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
    729727        performCriticalExit();
    730728      }
     
    732730  }
    733731  TotalNormal->Zero();
    734   int counter=0;
    735   for (; Runner[2] != endpoints.end(); ) {
     732  int counter = 0;
     733  for (; Runner[2] != endpoints.end();) {
    736734    TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
    737     for (int i=0;i<3;i++) // increase each of them
     735    for (int i = 0; i < 3; i++) // increase each of them
    738736      Runner[i]++;
    739737    TotalNormal->AddVector(&TemporaryNormal);
    740738  }
    741   TotalNormal->Scale(1./(double)counter);
     739  TotalNormal->Scale(1. / (double) counter);
    742740
    743741  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
     
    747745
    748746  return TotalNormal;
    749 };
     747}
     748;
    750749
    751750/** Calculates the center point of the triangle.
     
    758757  center->Zero();
    759758  int counter = 0;
    760   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     759  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    761760    center->AddVector((*Runner)->node->node);
    762761    counter++;
    763762  }
    764   center->Scale(1./(double)counter);
     763  center->Scale(1. / (double) counter);
    765764  Log() << Verbose(1) << "Center is at " << *center << "." << endl;
    766765}
     
    774773  Info FunctionInfo(__func__);
    775774  return ContainsPresentTupel(triangle->endpoints, 3);
    776 };
     775}
     776;
    777777
    778778/** Checks whether the polygons contains both endpoints of the line.
     
    784784  Info FunctionInfo(__func__);
    785785  return ContainsPresentTupel(line->endpoints, 2);
    786 };
     786}
     787;
    787788
    788789/** Checks whether point is any of the three endpoints this triangle contains.
     
    793794{
    794795  Info FunctionInfo(__func__);
    795   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     796  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    796797    Log() << Verbose(0) << "Checking against " << **Runner << endl;
    797798    if (point == (*Runner)) {
     
    802803  Log() << Verbose(0) << " Not contained." << endl;
    803804  return false;
    804 };
     805}
     806;
    805807
    806808/** Checks whether point is any of the three endpoints this triangle contains.
     
    811813{
    812814  Info FunctionInfo(__func__);
    813   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     815  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    814816    if (point == (*Runner)->node) {
    815817      Log() << Verbose(0) << " Contained." << endl;
     
    818820  Log() << Verbose(0) << " Not contained." << endl;
    819821  return false;
    820 };
     822}
     823;
    821824
    822825/** Checks whether given array of \a *Points coincide with polygons's endpoints.
     
    830833  int counter = 0;
    831834  Log() << Verbose(1) << "Polygon is " << *this << endl;
    832   for(int i=0;i<dim;i++) {
     835  for (int i = 0; i < dim; i++) {
    833836    Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl;
    834837    if (ContainsBoundaryPoint(Points[i])) {
     
    841844  else
    842845    return false;
    843 };
     846}
     847;
    844848
    845849/** Checks whether given PointList coincide with polygons's endpoints.
     
    852856  size_t counter = 0;
    853857  Log() << Verbose(1) << "Polygon is " << *this << endl;
    854   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     858  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    855859    Log() << Verbose(1) << " Testing endpoint " << **Runner << endl;
    856860    if (ContainsBoundaryPoint(*Runner))
     
    862866  else
    863867    return false;
    864 };
     868}
     869;
    865870
    866871/** Checks whether given set of \a *Points coincide with polygons's endpoints.
     
    870875bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
    871876{
    872   return ContainsPresentTupel((const PointSet)P->endpoints);
    873 };
     877  return ContainsPresentTupel((const PointSet) P->endpoints);
     878}
     879;
    874880
    875881/** Gathers all the endpoints' triangles in a unique set.
     
    879885{
    880886  Info FunctionInfo(__func__);
    881   pair <TriangleSet::iterator, bool> Tester;
     887  pair<TriangleSet::iterator, bool> Tester;
    882888  TriangleSet *triangles = new TriangleSet;
    883889
    884   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    885     for(LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
    886       for(TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
     890  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     891    for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
     892      for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
    887893        //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
    888894        if (ContainsBoundaryTriangle(Sprinter->second)) {
     
    895901  Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl;
    896902  return triangles;
    897 };
     903}
     904;
    898905
    899906/** Fills the endpoints of this polygon from the triangles attached to \a *line.
     
    904911{
    905912  Info FunctionInfo(__func__);
    906   pair <PointSet::iterator, bool> Tester;
     913  pair<PointSet::iterator, bool> Tester;
    907914  if (line == NULL)
    908915    return false;
    909916  Log() << Verbose(1) << "Filling polygon from line " << *line << endl;
    910   for(TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
    911     for (int i=0;i<3;i++) {
     917  for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
     918    for (int i = 0; i < 3; i++) {
    912919      Tester = endpoints.insert((Runner->second)->endpoints[i]);
    913920      if (Tester.second)
     
    917924
    918925  return true;
    919 };
     926}
     927;
    920928
    921929/** output operator for BoundaryPolygonSet.
     
    926934{
    927935  ost << "[" << a.Nr << "|";
    928   for(PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
    929    ost << (*Runner)->node->Name;
    930    Runner++;
    931    if (Runner != a.endpoints.end())
    932      ost << ",";
    933   }
    934   ost<< "]";
     936  for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
     937    ost << (*Runner)->node->Name;
     938    Runner++;
     939    if (Runner != a.endpoints.end())
     940      ost << ",";
     941  }
     942  ost << "]";
    935943  return ost;
    936 };
     944}
     945;
    937946
    938947// =========================================================== class TESSELPOINT ===========================================
     
    945954  node = NULL;
    946955  nr = -1;
    947   Name =  NULL;
    948 };
     956  Name = NULL;
     957}
     958;
    949959
    950960/** Destructor for class TesselPoint.
     
    953963{
    954964  //Info FunctionInfo(__func__);
    955 };
     965}
     966;
    956967
    957968/** Prints LCNode to screen.
    958969 */
    959 ostream & operator << (ostream &ost, const TesselPoint &a)
     970ostream & operator <<(ostream &ost, const TesselPoint &a)
    960971{
    961972  ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]";
    962973  return ost;
    963 };
     974}
     975;
    964976
    965977/** Prints LCNode to screen.
    966978 */
    967 ostream & TesselPoint::operator << (ostream &ost)
    968 {
    969         Info FunctionInfo(__func__);
     979ostream & TesselPoint::operator <<(ostream &ost)
     980{
     981  Info FunctionInfo(__func__);
    970982  ost << "[" << (nr) << "|" << this << "]";
    971983  return ost;
    972 };
    973 
     984}
     985;
    974986
    975987// =========================================================== class POINTCLOUD ============================================
     
    979991PointCloud::PointCloud()
    980992{
    981         //Info FunctionInfo(__func__);
    982 };
     993  //Info FunctionInfo(__func__);
     994}
     995;
    983996
    984997/** Destructor for class PointCloud.
     
    986999PointCloud::~PointCloud()
    9871000{
    988         //Info FunctionInfo(__func__);
    989 };
     1001  //Info FunctionInfo(__func__);
     1002}
     1003;
    9901004
    9911005// ============================ CandidateForTesselation =============================
     
    9931007/** Constructor of class CandidateForTesselation.
    9941008 */
    995 CandidateForTesselation::CandidateForTesselation (BoundaryLineSet* line) :
    996   BaseLine(line),
    997   ThirdPoint(NULL),
    998   T(NULL),
    999   ShortestAngle(2.*M_PI),
    1000   OtherShortestAngle(2.*M_PI)
    1001 {
    1002         Info FunctionInfo(__func__);
    1003 };
    1004 
     1009CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
     1010  BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
     1011{
     1012  Info FunctionInfo(__func__);
     1013}
     1014;
    10051015
    10061016/** Constructor of class CandidateForTesselation.
    10071017 */
    1008 CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
    1009     BaseLine(line),
    1010     ThirdPoint(point),
    1011     T(NULL),
    1012     ShortestAngle(2.*M_PI),
    1013     OtherShortestAngle(2.*M_PI)
    1014 {
    1015         Info FunctionInfo(__func__);
     1018CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
     1019  BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
     1020{
     1021  Info FunctionInfo(__func__);
    10161022  OptCenter.CopyVector(&OptCandidateCenter);
    10171023  OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
    1018 };
     1024}
     1025;
    10191026
    10201027/** Destructor for class CandidateForTesselation.
    10211028 */
    1022 CandidateForTesselation::~CandidateForTesselation() {
    1023 };
     1029CandidateForTesselation::~CandidateForTesselation()
     1030{
     1031}
     1032;
    10241033
    10251034/** Checks validity of a given sphere of a candidate line.
     
    10331042  Info FunctionInfo(__func__);
    10341043
    1035   const double radiusSquared = RADIUS*RADIUS;
     1044  const double radiusSquared = RADIUS * RADIUS;
    10361045  list<const Vector *> VectorList;
    10371046  VectorList.push_back(&OptCenter);
     
    10391048
    10401049  if (!pointlist.empty())
    1041     DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list " << *(*pointlist.begin()) << " and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
     1050    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
    10421051  else
    10431052    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
    10441053  // check baseline for OptCenter and OtherOptCenter being on sphere's surface
    10451054  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
    1046     for (int i=0;i<2;i++) {
     1055    for (int i = 0; i < 2; i++) {
    10471056      const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->node) - radiusSquared);
    10481057      if (distance > HULLEPSILON) {
    1049         DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << setprecision(13) << distance << "." << endl);
     1058        DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
    10501059        return false;
    10511060      }
     
    10541063
    10551064  // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
    1056   for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.begin(); ++Runner) {
     1065  for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
    10571066    const TesselPoint *Walker = *Runner;
    10581067    for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
    10591068      const double distance = fabs((*VRunner)->DistanceSquared(Walker->node) - radiusSquared);
    10601069      if (distance > HULLEPSILON) {
    1061         DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << Walker << " is out of sphere at " << *(*VRunner) << " by " << setprecision(13) << distance << "." << endl);
     1070        DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
    10621071        return false;
     1072      } else {
     1073        Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl;
    10631074      }
    10641075    }
     
    10701081    // get all points inside the sphere
    10711082    TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
     1083
     1084    Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl;
     1085    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     1086      Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&OtherOptCenter) << "." << endl;
     1087
    10721088    // remove baseline's endpoints and candidates
    1073     for (int i=0;i<2;i++)
     1089    for (int i = 0; i < 2; i++) {
     1090      Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl;
    10741091      ListofPoints->remove(BaseLine->endpoints[i]->node);
    1075     for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner)
     1092    }
     1093    for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
     1094      Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl;
    10761095      ListofPoints->remove(*Runner);
     1096    }
    10771097    if (!ListofPoints->empty()) {
    1078       cout << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl;
     1098      DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
    10791099      flag = false;
    10801100      DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
     
    10821102        DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << endl);
    10831103    }
    1084     delete(ListofPoints);
     1104    delete (ListofPoints);
    10851105
    10861106    // check with animate_sphere.tcl VMD script
    10871107    if (ThirdPoint != NULL) {
    1088       cout << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr+1 << " " << BaseLine->endpoints[1]->Nr+1 << " " << ThirdPoint->Nr+1 << " " << RADIUS << " ";
    1089       cout << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " ";
    1090       cout << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl;
     1108      Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl;
    10911109    } else {
    1092       cout << Verbose(1) << "Check by: ... missing third point ..." << endl;
    1093       cout << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr+1 << " " << BaseLine->endpoints[1]->Nr+1 << " ??? " << RADIUS << " ";
    1094       cout << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " ";
    1095       cout << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl;
     1110      Log() << Verbose(1) << "Check by: ... missing third point ..." << endl;
     1111      Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl;
    10961112    }
    10971113  }
    10981114  return flag;
    1099 };
     1115}
     1116;
    11001117
    11011118/** output operator for CandidateForTesselation.
     
    11031120 * \param &a boundary line
    11041121 */
    1105 ostream & operator <<(ostream &ost, const  CandidateForTesselation &a)
     1122ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
    11061123{
    11071124  ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with ";
     
    11161133    for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
    11171134      ost << *(*Runner) << " ";
    1118     ost << " at angle " << (a.ShortestAngle)<< ".";
     1135    ost << " at angle " << (a.ShortestAngle) << ".";
    11191136  }
    11201137
    11211138  return ost;
    1122 };
    1123 
     1139}
     1140;
    11241141
    11251142// =========================================================== class TESSELATION ===========================================
     
    11281145 */
    11291146Tesselation::Tesselation() :
    1130   PointsOnBoundaryCount(0),
    1131   LinesOnBoundaryCount(0),
    1132   TrianglesOnBoundaryCount(0),
    1133   LastTriangle(NULL),
    1134   TriangleFilesWritten(0),
    1135   InternalPointer(PointsOnBoundary.begin())
    1136 {
    1137         Info FunctionInfo(__func__);
     1147  PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin())
     1148{
     1149  Info FunctionInfo(__func__);
    11381150}
    11391151;
     
    11441156Tesselation::~Tesselation()
    11451157{
    1146         Info FunctionInfo(__func__);
     1158  Info FunctionInfo(__func__);
    11471159  Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl;
    11481160  for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
     
    11511163      runner->second = NULL;
    11521164    } else
    1153       DoeLog(1) && (eLog()<< Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);
     1165      DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);
    11541166  }
    11551167  Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
     
    11591171/** PointCloud implementation of GetCenter
    11601172 * Uses PointsOnBoundary and STL stuff.
    1161  */   
     1173 */
    11621174Vector * Tesselation::GetCenter(ofstream *out) const
    11631175{
    1164         Info FunctionInfo(__func__);
    1165   Vector *Center = new Vector(0.,0.,0.);
    1166   int num=0;
     1176  Info FunctionInfo(__func__);
     1177  Vector *Center = new Vector(0., 0., 0.);
     1178  int num = 0;
    11671179  for (GoToFirst(); (!IsEnd()); GoToNext()) {
    11681180    Center->AddVector(GetPoint()->node);
    11691181    num++;
    11701182  }
    1171   Center->Scale(1./num);
     1183  Center->Scale(1. / num);
    11721184  return Center;
    1173 };
     1185}
     1186;
    11741187
    11751188/** PointCloud implementation of GoPoint
    11761189 * Uses PointsOnBoundary and STL stuff.
    1177  */   
     1190 */
    11781191TesselPoint * Tesselation::GetPoint() const
    11791192{
    1180         Info FunctionInfo(__func__);
     1193  Info FunctionInfo(__func__);
    11811194  return (InternalPointer->second->node);
    1182 };
     1195}
     1196;
    11831197
    11841198/** PointCloud implementation of GetTerminalPoint.
    11851199 * Uses PointsOnBoundary and STL stuff.
    1186  */   
     1200 */
    11871201TesselPoint * Tesselation::GetTerminalPoint() const
    11881202{
    1189         Info FunctionInfo(__func__);
     1203  Info FunctionInfo(__func__);
    11901204  PointMap::const_iterator Runner = PointsOnBoundary.end();
    11911205  Runner--;
    11921206  return (Runner->second->node);
    1193 };
     1207}
     1208;
    11941209
    11951210/** PointCloud implementation of GoToNext.
    11961211 * Uses PointsOnBoundary and STL stuff.
    1197  */   
     1212 */
    11981213void Tesselation::GoToNext() const
    11991214{
    1200         Info FunctionInfo(__func__);
     1215  Info FunctionInfo(__func__);
    12011216  if (InternalPointer != PointsOnBoundary.end())
    12021217    InternalPointer++;
    1203 };
     1218}
     1219;
    12041220
    12051221/** PointCloud implementation of GoToPrevious.
    12061222 * Uses PointsOnBoundary and STL stuff.
    1207  */   
     1223 */
    12081224void Tesselation::GoToPrevious() const
    12091225{
    1210         Info FunctionInfo(__func__);
     1226  Info FunctionInfo(__func__);
    12111227  if (InternalPointer != PointsOnBoundary.begin())
    12121228    InternalPointer--;
    1213 };
     1229}
     1230;
    12141231
    12151232/** PointCloud implementation of GoToFirst.
    12161233 * Uses PointsOnBoundary and STL stuff.
    1217  */   
     1234 */
    12181235void Tesselation::GoToFirst() const
    12191236{
    1220         Info FunctionInfo(__func__);
     1237  Info FunctionInfo(__func__);
    12211238  InternalPointer = PointsOnBoundary.begin();
    1222 };
     1239}
     1240;
    12231241
    12241242/** PointCloud implementation of GoToLast.
     
    12271245void Tesselation::GoToLast() const
    12281246{
    1229         Info FunctionInfo(__func__);
     1247  Info FunctionInfo(__func__);
    12301248  InternalPointer = PointsOnBoundary.end();
    12311249  InternalPointer--;
    1232 };
     1250}
     1251;
    12331252
    12341253/** PointCloud implementation of IsEmpty.
    12351254 * Uses PointsOnBoundary and STL stuff.
    1236  */   
     1255 */
    12371256bool Tesselation::IsEmpty() const
    12381257{
    1239         Info FunctionInfo(__func__);
     1258  Info FunctionInfo(__func__);
    12401259  return (PointsOnBoundary.empty());
    1241 };
     1260}
     1261;
    12421262
    12431263/** PointCloud implementation of IsLast.
    12441264 * Uses PointsOnBoundary and STL stuff.
    1245  */   
     1265 */
    12461266bool Tesselation::IsEnd() const
    12471267{
    1248         Info FunctionInfo(__func__);
     1268  Info FunctionInfo(__func__);
    12491269  return (InternalPointer == PointsOnBoundary.end());
    1250 };
    1251 
     1270}
     1271;
    12521272
    12531273/** Gueses first starting triangle of the convex envelope.
     
    12581278void Tesselation::GuessStartingTriangle()
    12591279{
    1260         Info FunctionInfo(__func__);
     1280  Info FunctionInfo(__func__);
    12611281  // 4b. create a starting triangle
    12621282  // 4b1. create all distances
     
    12681288
    12691289  // with A chosen, take each pair B,C and sort
    1270   if (A != PointsOnBoundary.end())
    1271     {
    1272       B = A;
    1273       B++;
    1274       for (; B != PointsOnBoundary.end(); B++)
    1275         {
    1276           C = B;
    1277           C++;
    1278           for (; C != PointsOnBoundary.end(); C++)
    1279             {
    1280               tmp = A->second->node->node->DistanceSquared(B->second->node->node);
    1281               distance = tmp * tmp;
    1282               tmp = A->second->node->node->DistanceSquared(C->second->node->node);
    1283               distance += tmp * tmp;
    1284               tmp = B->second->node->node->DistanceSquared(C->second->node->node);
    1285               distance += tmp * tmp;
    1286               DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
    1287             }
    1288         }
    1289     }
     1290  if (A != PointsOnBoundary.end()) {
     1291    B = A;
     1292    B++;
     1293    for (; B != PointsOnBoundary.end(); B++) {
     1294      C = B;
     1295      C++;
     1296      for (; C != PointsOnBoundary.end(); C++) {
     1297        tmp = A->second->node->node->DistanceSquared(B->second->node->node);
     1298        distance = tmp * tmp;
     1299        tmp = A->second->node->node->DistanceSquared(C->second->node->node);
     1300        distance += tmp * tmp;
     1301        tmp = B->second->node->node->DistanceSquared(C->second->node->node);
     1302        distance += tmp * tmp;
     1303        DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
     1304      }
     1305    }
     1306  }
    12901307  //    // listing distances
    12911308  //    Log() << Verbose(1) << "Listing DistanceMMap:";
     
    12971314  // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
    12981315  DistanceMultiMap::iterator baseline = DistanceMMap.begin();
    1299   for (; baseline != DistanceMMap.end(); baseline++)
    1300     {
    1301       // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
    1302       // 2. next, we have to check whether all points reside on only one side of the triangle
    1303       // 3. construct plane vector
    1304       PlaneVector.MakeNormalVector(A->second->node->node,
    1305           baseline->second.first->second->node->node,
    1306           baseline->second.second->second->node->node);
    1307       Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl;
    1308       // 4. loop over all points
    1309       double sign = 0.;
    1310       PointMap::iterator checker = PointsOnBoundary.begin();
    1311       for (; checker != PointsOnBoundary.end(); checker++)
    1312         {
    1313           // (neglecting A,B,C)
    1314           if ((checker == A) || (checker == baseline->second.first) || (checker
    1315               == baseline->second.second))
    1316             continue;
    1317           // 4a. project onto plane vector
    1318           TrialVector.CopyVector(checker->second->node->node);
    1319           TrialVector.SubtractVector(A->second->node->node);
    1320           distance = TrialVector.ScalarProduct(&PlaneVector);
    1321           if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    1322             continue;
    1323           Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl;
    1324           tmp = distance / fabs(distance);
    1325           // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
    1326           if ((sign != 0) && (tmp != sign))
    1327             {
    1328               // 4c. If so, break 4. loop and continue with next candidate in 1. loop
    1329               Log() << Verbose(2) << "Current candidates: "
    1330                   << A->second->node->Name << ","
    1331                   << baseline->second.first->second->node->Name << ","
    1332                   << baseline->second.second->second->node->Name << " leaves "
    1333                   << checker->second->node->Name << " outside the convex hull."
    1334                   << endl;
    1335               break;
    1336             }
    1337           else
    1338             { // note the sign for later
    1339               Log() << Verbose(2) << "Current candidates: "
    1340                   << A->second->node->Name << ","
    1341                   << baseline->second.first->second->node->Name << ","
    1342                   << baseline->second.second->second->node->Name << " leave "
    1343                   << checker->second->node->Name << " inside the convex hull."
    1344                   << endl;
    1345               sign = tmp;
    1346             }
    1347           // 4d. Check whether the point is inside the triangle (check distance to each node
    1348           tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
    1349           int innerpoint = 0;
    1350           if ((tmp < A->second->node->node->DistanceSquared(
    1351               baseline->second.first->second->node->node)) && (tmp
    1352               < A->second->node->node->DistanceSquared(
    1353                   baseline->second.second->second->node->node)))
    1354             innerpoint++;
    1355           tmp = checker->second->node->node->DistanceSquared(
    1356               baseline->second.first->second->node->node);
    1357           if ((tmp < baseline->second.first->second->node->node->DistanceSquared(
    1358               A->second->node->node)) && (tmp
    1359               < baseline->second.first->second->node->node->DistanceSquared(
    1360                   baseline->second.second->second->node->node)))
    1361             innerpoint++;
    1362           tmp = checker->second->node->node->DistanceSquared(
    1363               baseline->second.second->second->node->node);
    1364           if ((tmp < baseline->second.second->second->node->node->DistanceSquared(
    1365               baseline->second.first->second->node->node)) && (tmp
    1366               < baseline->second.second->second->node->node->DistanceSquared(
    1367                   A->second->node->node)))
    1368             innerpoint++;
    1369           // 4e. If so, break 4. loop and continue with next candidate in 1. loop
    1370           if (innerpoint == 3)
    1371             break;
    1372         }
    1373       // 5. come this far, all on same side? Then break 1. loop and construct triangle
    1374       if (checker == PointsOnBoundary.end())
    1375         {
    1376           Log() << Verbose(2) << "Looks like we have a candidate!" << endl;
    1377           break;
    1378         }
    1379     }
    1380   if (baseline != DistanceMMap.end())
    1381     {
    1382       BPS[0] = baseline->second.first->second;
    1383       BPS[1] = baseline->second.second->second;
    1384       BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1385       BPS[0] = A->second;
    1386       BPS[1] = baseline->second.second->second;
    1387       BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1388       BPS[0] = baseline->second.first->second;
    1389       BPS[1] = A->second;
    1390       BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1391 
    1392       // 4b3. insert created triangle
    1393       BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    1394       TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    1395       TrianglesOnBoundaryCount++;
    1396       for (int i = 0; i < NDIM; i++)
    1397         {
    1398           LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
    1399           LinesOnBoundaryCount++;
    1400         }
    1401 
    1402       Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl;
    1403     }
    1404   else
    1405     {
    1406       DoeLog(0) && (eLog()<< Verbose(0) << "No starting triangle found." << endl);
    1407     }
     1316  for (; baseline != DistanceMMap.end(); baseline++) {
     1317    // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
     1318    // 2. next, we have to check whether all points reside on only one side of the triangle
     1319    // 3. construct plane vector
     1320    PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node);
     1321    Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl;
     1322    // 4. loop over all points
     1323    double sign = 0.;
     1324    PointMap::iterator checker = PointsOnBoundary.begin();
     1325    for (; checker != PointsOnBoundary.end(); checker++) {
     1326      // (neglecting A,B,C)
     1327      if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
     1328        continue;
     1329      // 4a. project onto plane vector
     1330      TrialVector.CopyVector(checker->second->node->node);
     1331      TrialVector.SubtractVector(A->second->node->node);
     1332      distance = TrialVector.ScalarProduct(&PlaneVector);
     1333      if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
     1334        continue;
     1335      Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl;
     1336      tmp = distance / fabs(distance);
     1337      // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
     1338      if ((sign != 0) && (tmp != sign)) {
     1339        // 4c. If so, break 4. loop and continue with next candidate in 1. loop
     1340        Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leaves " << checker->second->node->Name << " outside the convex hull." << endl;
     1341        break;
     1342      } else { // note the sign for later
     1343        Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leave " << checker->second->node->Name << " inside the convex hull." << endl;
     1344        sign = tmp;
     1345      }
     1346      // 4d. Check whether the point is inside the triangle (check distance to each node
     1347      tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
     1348      int innerpoint = 0;
     1349      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)))
     1350        innerpoint++;
     1351      tmp = checker->second->node->node->DistanceSquared(baseline->second.first->second->node->node);
     1352      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)))
     1353        innerpoint++;
     1354      tmp = checker->second->node->node->DistanceSquared(baseline->second.second->second->node->node);
     1355      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)))
     1356        innerpoint++;
     1357      // 4e. If so, break 4. loop and continue with next candidate in 1. loop
     1358      if (innerpoint == 3)
     1359        break;
     1360    }
     1361    // 5. come this far, all on same side? Then break 1. loop and construct triangle
     1362    if (checker == PointsOnBoundary.end()) {
     1363      Log() << Verbose(2) << "Looks like we have a candidate!" << endl;
     1364      break;
     1365    }
     1366  }
     1367  if (baseline != DistanceMMap.end()) {
     1368    BPS[0] = baseline->second.first->second;
     1369    BPS[1] = baseline->second.second->second;
     1370    BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1371    BPS[0] = A->second;
     1372    BPS[1] = baseline->second.second->second;
     1373    BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1374    BPS[0] = baseline->second.first->second;
     1375    BPS[1] = A->second;
     1376    BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1377
     1378    // 4b3. insert created triangle
     1379    BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     1380    TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
     1381    TrianglesOnBoundaryCount++;
     1382    for (int i = 0; i < NDIM; i++) {
     1383      LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
     1384      LinesOnBoundaryCount++;
     1385    }
     1386
     1387    Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl;
     1388  } else {
     1389    DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl);
     1390  }
    14081391}
    14091392;
     
    14241407void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
    14251408{
    1426         Info FunctionInfo(__func__);
     1409  Info FunctionInfo(__func__);
    14271410  bool flag;
    14281411  PointMap::iterator winner;
     
    14931476            TempAngle = VirtualNormalVector.Angle(&PropagationVector);
    14941477            Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
    1495             if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees)
     1478            if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
    14961479              Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
    14971480              continue;
     
    15341517            TempVector.AddVector(baseline->second->endpoints[1]->node->node);
    15351518            TempVector.AddVector(target->second->node->node);
    1536             TempVector.Scale(1./3.);
     1519            TempVector.Scale(1. / 3.);
    15371520            TempVector.SubtractVector(Center);
    15381521            // make it always point outward
     
    16031586          TrianglesOnBoundaryCount++;
    16041587        } else {
    1605           DoeLog(2) && (eLog()<< Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);
     1588          DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);
    16061589        }
    16071590
     
    16121595
    16131596  // exit
    1614   delete(Center);
    1615 };
     1597  delete (Center);
     1598}
     1599;
    16161600
    16171601/** Inserts all points outside of the tesselated surface into it by adding new triangles.
     
    16231607bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
    16241608{
    1625         Info FunctionInfo(__func__);
     1609  Info FunctionInfo(__func__);
    16261610  Vector Intersection, Normal;
    16271611  TesselPoint *Walker = NULL;
     
    16331617  cloud->GoToFirst();
    16341618  BoundaryPoints = new LinkedCell(this, 5.);
    1635   while (!cloud->IsEnd()) {  // we only have to go once through all points, as boundary can become only bigger
     1619  while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
    16361620    if (AddFlag) {
    1637       delete(BoundaryPoints);
     1621      delete (BoundaryPoints);
    16381622      BoundaryPoints = new LinkedCell(this, 5.);
    16391623      AddFlag = false;
     
    16641648        class BoundaryPointSet *OldPoints[3], *NewPoint;
    16651649        // store the three old lines and old points
    1666         for (int i=0;i<3;i++) {
     1650        for (int i = 0; i < 3; i++) {
    16671651          OldLines[i] = BTS->lines[i];
    16681652          OldPoints[i] = BTS->endpoints[i];
     
    16721656        Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl;
    16731657        AddFlag = true;
    1674         if (AddBoundaryPoint(Walker,0))
     1658        if (AddBoundaryPoint(Walker, 0))
    16751659          NewPoint = BPS[0];
    16761660        else
     
    16791663        Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl;
    16801664        TrianglesOnBoundary.erase(BTS->Nr);
    1681         delete(BTS);
     1665        delete (BTS);
    16821666        // create three new boundary lines
    1683         for (int i=0;i<3;i++) {
     1667        for (int i = 0; i < 3; i++) {
    16841668          BPS[0] = NewPoint;
    16851669          BPS[1] = OldPoints[i];
     
    16901674        }
    16911675        // create three new triangle with new point
    1692         for (int i=0;i<3;i++) { // find all baselines
     1676        for (int i = 0; i < 3; i++) { // find all baselines
    16931677          BLS[0] = OldLines[i];
    16941678          int n = 1;
    1695           for (int j=0;j<3;j++) {
     1679          for (int j = 0; j < 3; j++) {
    16961680            if (NewLines[j]->IsConnectedTo(BLS[0])) {
    1697               if (n>2) {
    1698                 DoeLog(2) && (eLog()<< Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);
     1681              if (n > 2) {
     1682                DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);
    16991683                return false;
    17001684              } else
     
    17131697      }
    17141698    } else { // something is wrong with FindClosestTriangleToPoint!
    1715       DoeLog(1) && (eLog()<< Verbose(1) << "The closest triangle did not produce an intersection!" << endl);
     1699      DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl);
    17161700      return false;
    17171701    }
     
    17201704
    17211705  // exit
    1722   delete(Center);
     1706  delete (Center);
    17231707  return true;
    1724 };
     1708}
     1709;
    17251710
    17261711/** Adds a point to the tesselation::PointsOnBoundary list.
     
    17311716bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
    17321717{
    1733         Info FunctionInfo(__func__);
     1718  Info FunctionInfo(__func__);
    17341719  PointTestPair InsertUnique;
    17351720  BPS[n] = new class BoundaryPointSet(Walker);
     
    17391724    return true;
    17401725  } else {
    1741     delete(BPS[n]);
     1726    delete (BPS[n]);
    17421727    BPS[n] = InsertUnique.first->second;
    17431728    return false;
     
    17531738void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
    17541739{
    1755         Info FunctionInfo(__func__);
     1740  Info FunctionInfo(__func__);
    17561741  PointTestPair InsertUnique;
    17571742  TPS[n] = new class BoundaryPointSet(Candidate);
     
    17741759void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
    17751760{
    1776         Info FunctionInfo(__func__);
     1761  Info FunctionInfo(__func__);
    17771762  PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
    17781763  if (FindPoint != PointsOnBoundary.end())
     
    17801765  else
    17811766    TPS[n] = NULL;
    1782 };
     1767}
     1768;
    17831769
    17841770/** Function tries to add line from current Points in BPS to BoundaryLineSet.
     
    17911777 * @param n index of Tesselation::BLS giving the line with both endpoints
    17921778 */
    1793 void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) {
     1779void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     1780{
    17941781  bool insertNewLine = true;
    1795 
    17961782  LineMap::iterator FindLine = a->lines.find(b->node->nr);
    17971783  BoundaryLineSet *WinningLine = NULL;
     
    17991785    Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
    18001786
    1801     pair<LineMap::iterator,LineMap::iterator> FindPair;
     1787    pair<LineMap::iterator, LineMap::iterator> FindPair;
    18021788    FindPair = a->lines.equal_range(b->node->nr);
    18031789
    1804     for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     1790    for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) {
    18051791      Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl;
    18061792      // If there is a line with less than two attached triangles, we don't need a new line.
     
    18121798          Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl;
    18131799        // get open line
    1814         if ((!Finder->second->pointlist.empty()) && (*(Finder->second->pointlist.begin()) == candidate->node)
    1815             && (OptCenter == NULL || *OptCenter == Finder->second->OptCenter)) { // stop searching if candidate matches
    1816           insertNewLine = false;
    1817           WinningLine = FindLine->second;
    1818           break;
     1800        for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
     1801          if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || *OptCenter == Finder->second->OptCenter)) { // stop searching if candidate matches
     1802            insertNewLine = false;
     1803            WinningLine = FindLine->second;
     1804            break;
     1805          }
    18191806        }
    18201807      }
     
    18401827void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
    18411828{
    1842         Info FunctionInfo(__func__);
     1829  Info FunctionInfo(__func__);
    18431830  Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
    18441831  BPS[0] = a;
    18451832  BPS[1] = b;
    1846   BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);  // this also adds the line to the local maps
     1833  BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
    18471834  // add line to global map
    18481835  LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
     
    18511838  // also add to open lines
    18521839  CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
    1853   OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
    1854 };
     1840  OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
     1841}
     1842;
    18551843
    18561844/** Uses an existing line for a new triangle.
     
    18681856  BPS[1] = Line->endpoints[1];
    18691857  BLS[n] = Line;
    1870 
    18711858  // remove existing line from OpenLines
    18721859  CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
    18731860  if (CandidateLine != OpenLines.end()) {
    18741861    Log() << Verbose(1) << " Removing line from OpenLines." << endl;
    1875     delete(CandidateLine->second);
     1862    delete (CandidateLine->second);
    18761863    OpenLines.erase(CandidateLine);
    18771864  } else {
    1878     DoeLog(1) && (eLog()<< Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
    1879   }
    1880 };
     1865    DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
     1866  }
     1867}
     1868;
    18811869
    18821870/** Function adds triangle to global list.
     
    18851873void Tesselation::AddTesselationTriangle()
    18861874{
    1887         Info FunctionInfo(__func__);
     1875  Info FunctionInfo(__func__);
    18881876  Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
    18891877
     
    18961884
    18971885  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
    1898 };
     1886}
     1887;
    18991888
    19001889/** Function adds triangle to global list.
     
    19041893void Tesselation::AddTesselationTriangle(const int nr)
    19051894{
    1906         Info FunctionInfo(__func__);
     1895  Info FunctionInfo(__func__);
    19071896  Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl;
    19081897
     
    19141903
    19151904  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
    1916 };
     1905}
     1906;
    19171907
    19181908/** Removes a triangle from the tesselation.
     
    19231913void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
    19241914{
    1925         Info FunctionInfo(__func__);
     1915  Info FunctionInfo(__func__);
    19261916  if (triangle == NULL)
    19271917    return;
     
    19311921      triangle->lines[i]->triangles.erase(triangle->Nr);
    19321922      if (triangle->lines[i]->triangles.empty()) {
    1933           Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
    1934           RemoveTesselationLine(triangle->lines[i]);
     1923        Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
     1924        RemoveTesselationLine(triangle->lines[i]);
    19351925      } else {
    19361926        Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ";
    1937         OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
    1938         for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
     1927        OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
     1928        for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
    19391929          Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
    19401930        Log() << Verbose(0) << endl;
    1941 //        for (int j=0;j<2;j++) {
    1942 //          Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
    1943 //          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
    1944 //            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
    1945 //          Log() << Verbose(0) << endl;
    1946 //        }
     1931        //        for (int j=0;j<2;j++) {
     1932        //          Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
     1933        //          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
     1934        //            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
     1935        //          Log() << Verbose(0) << endl;
     1936        //        }
    19471937      }
    1948       triangle->lines[i] = NULL;  // free'd or not: disconnect
     1938      triangle->lines[i] = NULL; // free'd or not: disconnect
    19491939    } else
    1950       DoeLog(1) && (eLog()<< Verbose(1) << "This line " << i << " has already been free'd." << endl);
     1940      DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl);
    19511941  }
    19521942
    19531943  if (TrianglesOnBoundary.erase(triangle->Nr))
    19541944    Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
    1955   delete(triangle);
    1956 };
     1945  delete (triangle);
     1946}
     1947;
    19571948
    19581949/** Removes a line from the tesselation.
     
    19621953void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
    19631954{
    1964         Info FunctionInfo(__func__);
     1955  Info FunctionInfo(__func__);
    19651956  int Numbers[2];
    19661957
     
    19961987      } else {
    19971988        Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ";
    1998         for(LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
     1989        for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
    19991990          Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
    20001991        Log() << Verbose(0) << endl;
    20011992      }
    2002       line->endpoints[i] = NULL;  // free'd or not: disconnect
     1993      line->endpoints[i] = NULL; // free'd or not: disconnect
    20031994    } else
    2004       DoeLog(1) && (eLog()<< Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);
     1995      DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);
    20051996  }
    20061997  if (!line->triangles.empty())
    2007     DoeLog(2) && (eLog()<< Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);
     1998    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);
    20081999
    20092000  if (LinesOnBoundary.erase(line->Nr))
    20102001    Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl;
    2011   delete(line);
    2012 };
     2002  delete (line);
     2003}
     2004;
    20132005
    20142006/** Removes a point from the tesselation.
     
    20192011void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
    20202012{
    2021         Info FunctionInfo(__func__);
     2013  Info FunctionInfo(__func__);
    20222014  if (point == NULL)
    20232015    return;
    20242016  if (PointsOnBoundary.erase(point->Nr))
    20252017    Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl;
    2026   delete(point);
    2027 };
    2028 
     2018  delete (point);
     2019}
     2020;
    20292021
    20302022/** Checks validity of a given sphere of a candidate line.
    20312023 * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
    2032  * Note that endpoints are stored in Tesselation::TPS.
    2033  * \param *OtherOptCenter center of the other triangle
     2024 * We check CandidateForTesselation::OtherOptCenter
     2025 * \param &CandidateLine contains other degenerated candidates which we have to subtract as well
    20342026 * \param RADIUS radius of sphere
    20352027 * \param *LC LinkedCell structure with other atoms
    20362028 * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
    20372029 */
    2038 bool Tesselation::CheckDegeneracy(Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC) const
     2030bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const
    20392031{
    20402032  Info FunctionInfo(__func__);
     
    20432035  bool flag = true;
    20442036
    2045   cout << Verbose(1) << "Check by: draw sphere {" << OtherOptCenter->x[0] << " " << OtherOptCenter->x[1] << " " << OtherOptCenter->x[2] << "} radius " << RADIUS << " resolution 30" << endl;
    2046 
     2037  Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter.x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl;
    20472038  // get all points inside the sphere
    2048   TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, OtherOptCenter);
    2049 
    2050   Log() << Verbose(1) << "The following atoms are inside sphere at " << *OtherOptCenter << ":" << endl;
     2039  TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
     2040
     2041  Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl;
    20512042  for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    2052     Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(OtherOptCenter) << "." << endl;
     2043    Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl;
    20532044
    20542045  // remove triangles's endpoints
    2055   for (int i=0;i<3;i++)
    2056     ListofPoints->remove(TPS[i]->node);
     2046  for (int i = 0; i < 2; i++)
     2047    ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node);
     2048
     2049  // remove other candidates
     2050  for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner)
     2051    ListofPoints->remove(*Runner);
    20572052
    20582053  // check for other points
     
    20602055    Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl;
    20612056    flag = false;
    2062     Log() << Verbose(1) << "External atoms inside of sphere at " << *OtherOptCenter << ":" << endl;
     2057    Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl;
    20632058    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    2064       Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(OtherOptCenter) << "." << endl;
    2065   }
    2066   delete(ListofPoints);
     2059      Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl;
     2060  }
     2061  delete (ListofPoints);
    20672062
    20682063  return flag;
    2069 };
    2070 
     2064}
     2065;
    20712066
    20722067/** Checks whether the triangle consisting of the three points is already present.
     
    20812076int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
    20822077{
    2083         Info FunctionInfo(__func__);
     2078  Info FunctionInfo(__func__);
    20842079  int adjacentTriangleCount = 0;
    20852080  class BoundaryPointSet *Points[3];
     
    21212116  Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    21222117  return adjacentTriangleCount;
    2123 };
     2118}
     2119;
    21242120
    21252121/** Checks whether the triangle consisting of the three points is already present.
     
    21332129class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
    21342130{
    2135         Info FunctionInfo(__func__);
     2131  Info FunctionInfo(__func__);
    21362132  class BoundaryTriangleSet *triangle = NULL;
    21372133  class BoundaryPointSet *Points[3];
     
    21712167
    21722168  return triangle;
    2173 };
    2174 
     2169}
     2170;
    21752171
    21762172/** Finds the starting triangle for FindNonConvexBorder().
     
    21842180void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
    21852181{
    2186         Info FunctionInfo(__func__);
     2182  Info FunctionInfo(__func__);
    21872183  int i = 0;
    21882184  TesselPoint* MaxPoint[NDIM];
     
    21932189  Vector Chord;
    21942190  Vector SearchDirection;
    2195   Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     2191  Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
    21962192  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
    21972193  Vector SphereCenter;
     
    22062202
    22072203  // 1. searching topmost point with respect to each axis
    2208   for (int i=0;i<NDIM;i++) { // each axis
    2209     LC->n[i] = LC->N[i]-1; // current axis is topmost cell
    2210     for (LC->n[(i+1)%NDIM]=0;LC->n[(i+1)%NDIM]<LC->N[(i+1)%NDIM];LC->n[(i+1)%NDIM]++)
    2211       for (LC->n[(i+2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {
     2204  for (int i = 0; i < NDIM; i++) { // each axis
     2205    LC->n[i] = LC->N[i] - 1; // current axis is topmost cell
     2206    for (LC->n[(i + 1) % NDIM] = 0; LC->n[(i + 1) % NDIM] < LC->N[(i + 1) % NDIM]; LC->n[(i + 1) % NDIM]++)
     2207      for (LC->n[(i + 2) % NDIM] = 0; LC->n[(i + 2) % NDIM] < LC->N[(i + 2) % NDIM]; LC->n[(i + 2) % NDIM]++) {
    22122208        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    22132209        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    22142210        if (List != NULL) {
    2215           for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
     2211          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    22162212            if ((*Runner)->node->x[i] > maxCoordinate[i]) {
    22172213              Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
     
    22212217          }
    22222218        } else {
    2223           DoeLog(1) && (eLog()<< Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
     2219          DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
    22242220        }
    22252221      }
     
    22272223
    22282224  Log() << Verbose(1) << "Found maximum coordinates: ";
    2229   for (int i=0;i<NDIM;i++)
     2225  for (int i = 0; i < NDIM; i++)
    22302226    Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t";
    22312227  Log() << Verbose(0) << endl;
    22322228
    22332229  BTS = NULL;
    2234   for (int k=0;k<NDIM;k++) {
     2230  for (int k = 0; k < NDIM; k++) {
    22352231    NormalVector.Zero();
    22362232    NormalVector.x[k] = 1.;
     
    22602256
    22612257    double radius = CirclePlaneNormal.NormSquared();
    2262     double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
     2258    double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
    22632259
    22642260    NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
    22652261    NormalVector.Normalize();
    2266     ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
     2262    ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
    22672263
    22682264    SphereCenter.CopyVector(&NormalVector);
     
    22722268
    22732269    // look in one direction of baseline for initial candidate
    2274     SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector);  // whether we look "left" first or "right" first is not important ...
     2270    SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ...
    22752271
    22762272    // adding point 1 and point 2 and add the line between them
     
    22832279    Log() << Verbose(0) << "List of third Points is:" << endl;
    22842280    for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
    2285         Log() << Verbose(0) << " " << *(*it) << endl;
     2281      Log() << Verbose(0) << " " << *(*it) << endl;
    22862282    }
    22872283    if (!OptCandidates.pointlist.empty()) {
     
    23022298    delete BaseLine;
    23032299  }
    2304 };
     2300}
     2301;
    23052302
    23062303/** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
     
    24532450bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
    24542451{
    2455         Info FunctionInfo(__func__);
    2456   bool result = true;
    2457 
     2452  Info FunctionInfo(__func__);
    24582453  Vector CircleCenter;
    24592454  Vector CirclePlaneNormal;
     
    24652460  double radius, CircleRadius;
    24662461
    2467   for (int i=0;i<3;i++)
     2462  for (int i = 0; i < 3; i++)
    24682463    if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
    24692464      ThirdPoint = T.endpoints[i];
     
    24852480  // calculate squared radius of circle
    24862481  radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    2487   if (radius/4. < RADIUS*RADIUS) {
     2482  if (radius / 4. < RADIUS * RADIUS) {
    24882483    // construct relative sphere center with now known CircleCenter
    24892484    RelativeSphereCenter.CopyVector(&T.SphereCenter);
    24902485    RelativeSphereCenter.SubtractVector(&CircleCenter);
    24912486
    2492     CircleRadius = RADIUS*RADIUS - radius/4.;
     2487    CircleRadius = RADIUS * RADIUS - radius / 4.;
    24932488    CirclePlaneNormal.Normalize();
    24942489    Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     
    25052500    if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    25062501      // rotated the wrong way!
    2507       DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
     2502      DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
    25082503    }
    25092504
     
    25162511
    25172512  if (CandidateLine.pointlist.empty()) {
    2518     DoeLog(2) && (eLog()<< Verbose(2) << "Could not find a suitable candidate." << endl);
     2513    DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl);
    25192514    return false;
    25202515  }
     
    25252520
    25262521  return true;
    2527 
    2528 //  BoundaryLineSet *BaseRay = CandidateLine.BaseLine;
    2529 //  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    2530 //    Log() << Verbose(0) << "Third point candidate is " << *(*it)->point
    2531 //    << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
    2532 //    Log() << Verbose(0) << "Baseline is " << *BaseRay << endl;
    2533 //
    2534 //    // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
    2535 //    TesselPoint *PointCandidates[3];
    2536 //    PointCandidates[0] = (*it)->point;
    2537 //    PointCandidates[1] = BaseRay->endpoints[0]->node;
    2538 //    PointCandidates[2] = BaseRay->endpoints[1]->node;
    2539 //    int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
    2540 //
    2541 //    BTS = NULL;
    2542 //    // check for present edges and whether we reach better candidates from them
    2543 //    //if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) {
    2544 //    if (0) {
    2545 //      result = false;
    2546 //      break;
    2547 //    } else {
    2548 //      // If there is no triangle, add it regularly.
    2549 //      if (existentTrianglesCount == 0) {
    2550 //        AddTesselationPoint((*it)->point, 0);
    2551 //        AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    2552 //        AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    2553 //
    2554 //        if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
    2555 //          CandidateLine.point = (*it)->point;
    2556 //          CandidateLine.OptCenter.CopyVector(&((*it)->OptCenter));
    2557 //          CandidateLine.OtherOptCenter.CopyVector(&((*it)->OtherOptCenter));
    2558 //          CandidateLine.ShortestAngle = ShortestAngle;
    2559 //        } else {
    2560 ////          DoeLog(1) && (eLog()<< Verbose(1) << "This triangle consisting of ");
    2561 ////          Log() << Verbose(0) << *(*it)->point << ", ";
    2562 ////          Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    2563 ////          Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    2564 ////          Log() << Verbose(0) << "exists and is not added, as it 0x80000000006fc150(does not seem helpful!" << endl;
    2565 //          result = false;
    2566 //        }
    2567 //      } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
    2568 //          AddTesselationPoint((*it)->point, 0);
    2569 //          AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    2570 //          AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    2571 //
    2572 //          // 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)
    2573 //          // i.e. at least one of the three lines must be present with TriangleCount <= 1
    2574 //          if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS) || CandidateLine.BaseLine->skipped) {
    2575 //            CandidateLine.point = (*it)->point;
    2576 //            CandidateLine.OptCenter.CopyVector(&(*it)->OptCenter);
    2577 //            CandidateLine.OtherOptCenter.CopyVector(&(*it)->OtherOptCenter);
    2578 //            CandidateLine.ShortestAngle = ShortestAngle+2.*M_PI;
    2579 //
    2580 //          } else {
    2581 ////            DoeLog(1) && (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);
    2582 //            result = false;
    2583 //          }
    2584 //      } else {
    2585 ////        Log() << Verbose(1) << "This triangle consisting of ";
    2586 ////        Log() << Verbose(0) << *(*it)->point << ", ";
    2587 ////        Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    2588 ////        Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    2589 ////        Log() << Verbose(0) << "is invalid!" << endl;
    2590 //        result = false;
    2591 //      }
    2592 //    }
    2593 //
    2594 //    // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
    2595 //    BaseRay = BLS[0];
    2596 //    if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
    2597 //      DoeLog(1) && (eLog()<< Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl);
    2598 //      exit(255);
    2599 //    }
    2600 //
    2601 //  }
    2602 //
    2603 //  // remove all candidates from the list and then the list itself
    2604 //  class CandidateForTesselation *remover = NULL;
    2605 //  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    2606 //    remover = *it;
    2607 //    delete(remover);
    2608 //  }
    2609 //  delete(OptCandidates);
    2610   return result;
    2611 };
     2522}
     2523;
     2524
     2525/** Walks through Tesselation::OpenLines() and finds candidates for newly created ones.
     2526 * \param *&LCList atoms in LinkedCell list
     2527 * \param RADIUS radius of the virtual sphere
     2528 * \return true - for all open lines without candidates so far, a candidate has been found,
     2529 *         false - at least one open line without candidate still
     2530 */
     2531bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList)
     2532{
     2533  bool TesselationFailFlag = true;
     2534  CandidateForTesselation *baseline = NULL;
     2535  BoundaryTriangleSet *T = NULL;
     2536
     2537  for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
     2538    baseline = Runner->second;
     2539    if (baseline->pointlist.empty()) {
     2540      T = (((baseline->BaseLine->triangles.begin()))->second);
     2541      Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl;
     2542      TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
     2543    }
     2544  }
     2545  return TesselationFailFlag;
     2546}
     2547;
    26122548
    26132549/** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
     
    26412577  Sprinter = Runner;
    26422578  Sprinter++;
    2643   while(Sprinter != connectedClosestPoints->end()) {
     2579  while (Sprinter != connectedClosestPoints->end()) {
     2580    Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl;
     2581
    26442582    AddTesselationPoint(TurningPoint, 0);
    26452583    AddTesselationPoint(*Runner, 1);
    26462584    AddTesselationPoint(*Sprinter, 2);
    26472585
     2586    AddCandidateTriangle(CandidateLine, Opt);
     2587
     2588    Runner = Sprinter;
     2589    Sprinter++;
     2590    if (Sprinter != connectedClosestPoints->end()) {
     2591      // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
     2592      FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter);
     2593      Log() << Verbose(0) << " There are still more triangles to add." << endl;
     2594    }
     2595    // pick candidates for other open lines as well
     2596    FindCandidatesforOpenLines(RADIUS, LC);
     2597
    26482598    // check whether we add a degenerate or a normal triangle
    2649     if (CheckDegeneracy(&CandidateLine.OtherOptCenter, RADIUS, LC)) {
     2599    if (CheckDegeneracy(CandidateLine, RADIUS, LC)) {
    26502600      // add normal and degenerate triangles
    26512601      Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl;
    2652       AddDegeneratedTriangle(CandidateLine, RADIUS, LC);
    2653     } else {
    2654       // add this triangle
    2655       AddCandidateTriangle(CandidateLine);
    2656     }
    2657 
    2658     Runner = Sprinter;
    2659     Sprinter++;
    2660     Log() << Verbose(0) << "Current Runner is " << **Runner << "." << endl;
    2661     if (Sprinter != connectedClosestPoints->end())
    2662       Log() << Verbose(0) << " There are still more triangles to add." << endl;
    2663   }
    2664   delete(connectedClosestPoints);
     2602      AddCandidateTriangle(CandidateLine, OtherOpt);
     2603
     2604      if (Sprinter != connectedClosestPoints->end()) {
     2605        // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
     2606        FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter);
     2607      }
     2608      // pick candidates for other open lines as well
     2609      FindCandidatesforOpenLines(RADIUS, LC);
     2610    }
     2611  }
     2612  delete (connectedClosestPoints);
     2613};
     2614
     2615/** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate.
     2616 * \param *Sprinter next candidate to which internal open lines are set
     2617 * \param *OptCenter OptCenter for this candidate
     2618 */
     2619void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter)
     2620{
     2621  Info FunctionInfo(__func__);
     2622
     2623  pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr);
     2624  for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     2625    Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl;
     2626    // If there is a line with less than two attached triangles, we don't need a new line.
     2627    if (FindLine->second->triangles.size() == 1) {
     2628      CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
     2629      if (!Finder->second->pointlist.empty())
     2630        Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl;
     2631      else {
     2632        Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl;
     2633        Finder->second->pointlist.push_back(Sprinter);
     2634        Finder->second->ShortestAngle = 0.;
     2635        Finder->second->OptCenter.CopyVector(OptCenter);
     2636      }
     2637    }
     2638  }
    26652639};
    26662640
     
    26802654
    26812655  /// 1. Create or pick the lines for the first triangle
    2682   // for each amount of open lines we have a different case:
    2683   // case 0: no triangles at this line and not closed
    2684   // case 1: no triangles at new line is closed
    2685   // case 2: one line with one triangle attached, one will used this line
    2686   // case 3: one line with two triangles attached, new line will be used by both degenerate triangles
    2687   // case 4: two lines with one triangle each, each new triangle will pick one
    26882656  Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl;
    2689   for (int i=0;i<3;i++) {
     2657  for (int i = 0; i < 3; i++) {
    26902658    BLS[i] = NULL;
    2691     Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
    2692     AddTesselationLine(&CandidateLine.OptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
     2659    Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl;
     2660    AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
    26932661  }
    26942662
     
    27122680  /// 3. Gather candidates for each new line
    27132681  Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl;
    2714   for (int i=0;i<3;i++) {
    2715     Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
     2682  for (int i = 0; i < 3; i++) {
     2683    Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl;
    27162684    CandidateCheck = OpenLines.find(BLS[i]);
    27172685    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     
    27242692  /// 4. Create or pick the lines for the second triangle
    27252693  Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl;
    2726   for (int i=0;i<3;i++) {
    2727     Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
    2728     AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
     2694  for (int i = 0; i < 3; i++) {
     2695    Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl;
     2696    AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
    27292697  }
    27302698
     
    27462714  /// 6. Adding triangle to new lines
    27472715  Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl;
    2748   for (int i=0;i<3;i++) {
    2749     Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
     2716  for (int i = 0; i < 3; i++) {
     2717    Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl;
    27502718    CandidateCheck = OpenLines.find(BLS[i]);
    27512719    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     
    27542722    }
    27552723  }
    2756 };
     2724}
     2725;
    27572726
    27582727/** Adds a triangle to the Tesselation structure from three given TesselPoint's.
    27592728 * Note that endpoints are in Tesselation::TPS.
    27602729 * \param CandidateLine CandidateForTesselation structure contains other information
    2761  */
    2762 void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine)
     2730 * \param type which opt center to add (i.e. which side) and thus which NormalVector to take
     2731 */
     2732void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type)
    27632733{
    27642734  Info FunctionInfo(__func__);
    27652735  Vector Center;
     2736  Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter;
    27662737
    27672738  // add the lines
    2768   AddTesselationLine(&CandidateLine.OptCenter, TPS[2], TPS[0], TPS[1], 0);
    2769   AddTesselationLine(&CandidateLine.OptCenter, TPS[1], TPS[0], TPS[2], 1);
    2770   AddTesselationLine(&CandidateLine.OptCenter, TPS[0], TPS[1], TPS[2], 2);
     2739  AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0);
     2740  AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1);
     2741  AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2);
    27712742
    27722743  // add the triangles
     
    27762747  // create normal vector
    27772748  BTS->GetCenter(&Center);
    2778   Center.SubtractVector(&CandidateLine.OptCenter);
    2779   BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
     2749  Center.SubtractVector(OptCenter);
     2750  BTS->SphereCenter.CopyVector(OptCenter);
    27802751  BTS->GetNormalVector(Center);
    27812752
    27822753  // give some verbose output about the whole procedure
    27832754  if (CandidateLine.T != NULL)
    2784     Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl;
     2755    Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl;
    27852756  else
    2786     Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl;
    2787 };
     2757    Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl;
     2758}
     2759;
    27882760
    27892761/** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
     
    27962768class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
    27972769{
    2798         Info FunctionInfo(__func__);
     2770  Info FunctionInfo(__func__);
    27992771  class BoundaryPointSet *Spot = NULL;
    28002772  class BoundaryLineSet *OtherBase;
    28012773  Vector *ClosestPoint;
    28022774
    2803   int m=0;
    2804   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2805     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2775  int m = 0;
     2776  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2777    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    28062778      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
    28072779        BPS[m++] = runner->second->endpoints[j];
    2808   OtherBase = new class BoundaryLineSet(BPS,-1);
     2780  OtherBase = new class BoundaryLineSet(BPS, -1);
    28092781
    28102782  Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl;
     
    28152787
    28162788  // delete the temporary other base line
    2817   delete(OtherBase);
     2789  delete (OtherBase);
    28182790
    28192791  // get the distance vector from Base line to OtherBase line
     
    28222794  BaseLine.CopyVector(Base->endpoints[1]->node->node);
    28232795  BaseLine.SubtractVector(Base->endpoints[0]->node->node);
    2824   for (int i=0;i<2;i++) {
     2796  for (int i = 0; i < 2; i++) {
    28252797    DistanceToIntersection[i].CopyVector(ClosestPoint);
    28262798    DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
    28272799    distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
    28282800  }
    2829   delete(ClosestPoint);
    2830   if ((distance[0] * distance[1]) > 0)  { // have same sign?
    2831     Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
     2801  delete (ClosestPoint);
     2802  if ((distance[0] * distance[1]) > 0) { // have same sign?
     2803    Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl;
    28322804    if (distance[0] < distance[1]) {
    28332805      Spot = Base->endpoints[0];
     
    28362808    }
    28372809    return Spot;
    2838   } else {  // different sign, i.e. we are in between
     2810  } else { // different sign, i.e. we are in between
    28392811    Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
    28402812    return NULL;
    28412813  }
    28422814
    2843 };
     2815}
     2816;
    28442817
    28452818void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
    28462819{
    2847         Info FunctionInfo(__func__);
     2820  Info FunctionInfo(__func__);
    28482821  // print all lines
    28492822  Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl;
    2850   for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
     2823  for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)
    28512824    Log() << Verbose(0) << *(PointRunner->second) << endl;
    2852 };
     2825}
     2826;
    28532827
    28542828void Tesselation::PrintAllBoundaryLines(ofstream *out) const
    28552829{
    2856         Info FunctionInfo(__func__);
     2830  Info FunctionInfo(__func__);
    28572831  // print all lines
    28582832  Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl;
    28592833  for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
    28602834    Log() << Verbose(0) << *(LineRunner->second) << endl;
    2861 };
     2835}
     2836;
    28622837
    28632838void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
    28642839{
    2865         Info FunctionInfo(__func__);
     2840  Info FunctionInfo(__func__);
    28662841  // print all triangles
    28672842  Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl;
    28682843  for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
    28692844    Log() << Verbose(0) << *(TriangleRunner->second) << endl;
    2870 };
     2845}
     2846;
    28712847
    28722848/** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
     
    28772853double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
    28782854{
    2879         Info FunctionInfo(__func__);
     2855  Info FunctionInfo(__func__);
    28802856  class BoundaryLineSet *OtherBase;
    28812857  Vector *ClosestPoint[2];
    28822858  double volume;
    28832859
    2884   int m=0;
    2885   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2886     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2860  int m = 0;
     2861  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2862    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    28872863      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
    28882864        BPS[m++] = runner->second->endpoints[j];
    2889   OtherBase = new class BoundaryLineSet(BPS,-1);
     2865  OtherBase = new class BoundaryLineSet(BPS, -1);
    28902866
    28912867  Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl;
     
    29052881
    29062882  // delete the temporary other base line and the closest points
    2907   delete(ClosestPoint[0]);
    2908   delete(ClosestPoint[1]);
    2909   delete(OtherBase);
     2883  delete (ClosestPoint[0]);
     2884  delete (ClosestPoint[1]);
     2885  delete (OtherBase);
    29102886
    29112887  if (Distance.NormSquared() < MYEPSILON) { // check for intersection
     
    29162892    BaseLineNormal.Zero();
    29172893    if (Base->triangles.size() < 2) {
    2918       DoeLog(1) && (eLog()<< Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
     2894      DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
    29192895      return 0.;
    29202896    }
     
    29232899      BaseLineNormal.AddVector(&(runner->second->NormalVector));
    29242900    }
    2925     BaseLineNormal.Scale(1./2.);
     2901    BaseLineNormal.Scale(1. / 2.);
    29262902
    29272903    if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
     
    29292905      // calculate volume summand as a general tetraeder
    29302906      return volume;
    2931     } else {  // Base higher than OtherBase -> do nothing
     2907    } else { // Base higher than OtherBase -> do nothing
    29322908      Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl;
    29332909      return 0.;
    29342910    }
    29352911  }
    2936 };
     2912}
     2913;
    29372914
    29382915/** For a given baseline and its two connected triangles, flips the baseline.
     
    29452922class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
    29462923{
    2947         Info FunctionInfo(__func__);
     2924  Info FunctionInfo(__func__);
    29482925  class BoundaryLineSet *OldLines[4], *NewLine;
    29492926  class BoundaryPointSet *OldPoints[2];
    29502927  Vector BaseLineNormal;
    29512928  int OldTriangleNrs[2], OldBaseLineNr;
    2952   int i,m;
     2929  int i, m;
    29532930
    29542931  // calculate NormalVector for later use
    29552932  BaseLineNormal.Zero();
    29562933  if (Base->triangles.size() < 2) {
    2957     DoeLog(1) && (eLog()<< Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
     2934    DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
    29582935    return NULL;
    29592936  }
     
    29622939    BaseLineNormal.AddVector(&(runner->second->NormalVector));
    29632940  }
    2964   BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
     2941  BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
    29652942
    29662943  // get the two triangles
    29672944  // gather four endpoints and four lines
    2968   for (int j=0;j<4;j++)
     2945  for (int j = 0; j < 4; j++)
    29692946    OldLines[j] = NULL;
    2970   for (int j=0;j<2;j++)
     2947  for (int j = 0; j < 2; j++)
    29712948    OldPoints[j] = NULL;
    2972   i=0;
    2973   m=0;
     2949  i = 0;
     2950  m = 0;
    29742951  Log() << Verbose(0) << "The four old lines are: ";
    2975   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2976     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2952  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2953    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    29772954      if (runner->second->lines[j] != Base) { // pick not the central baseline
    29782955        OldLines[i++] = runner->second->lines[j];
     
    29812958  Log() << Verbose(0) << endl;
    29822959  Log() << Verbose(0) << "The two old points are: ";
    2983   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2984     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2960  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2961    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    29852962      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
    29862963        OldPoints[m++] = runner->second->endpoints[j];
     
    29902967
    29912968  // check whether everything is in place to create new lines and triangles
    2992   if (i<4) {
    2993     DoeLog(1) && (eLog()<< Verbose(1) << "We have not gathered enough baselines!" << endl);
     2969  if (i < 4) {
     2970    DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
    29942971    return NULL;
    29952972  }
    2996   for (int j=0;j<4;j++)
     2973  for (int j = 0; j < 4; j++)
    29972974    if (OldLines[j] == NULL) {
    2998       DoeLog(1) && (eLog()<< Verbose(1) << "We have not gathered enough baselines!" << endl);
     2975      DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
    29992976      return NULL;
    30002977    }
    3001   for (int j=0;j<2;j++)
     2978  for (int j = 0; j < 2; j++)
    30022979    if (OldPoints[j] == NULL) {
    3003       DoeLog(1) && (eLog()<< Verbose(1) << "We have not gathered enough endpoints!" << endl);
     2980      DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl);
    30042981      return NULL;
    30052982    }
     
    30082985  Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
    30092986  OldBaseLineNr = Base->Nr;
    3010   m=0;
    3011   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
     2987  m = 0;
     2988  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    30122989    Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
    30132990    OldTriangleNrs[m++] = runner->second->Nr;
     
    30233000
    30243001  // construct new triangles with flipped baseline
    3025   i=-1;
     3002  i = -1;
    30263003  if (OldLines[0]->IsConnectedTo(OldLines[2]))
    3027     i=2;
     3004    i = 2;
    30283005  if (OldLines[0]->IsConnectedTo(OldLines[3]))
    3029     i=3;
    3030   if (i!=-1) {
     3006    i = 3;
     3007  if (i != -1) {
    30313008    BLS[0] = OldLines[0];
    30323009    BLS[1] = OldLines[i];
     
    30373014    Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
    30383015
    3039     BLS[0] = (i==2 ? OldLines[3] : OldLines[2]);
     3016    BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]);
    30403017    BLS[1] = OldLines[1];
    30413018    BLS[2] = NewLine;
     
    30453022    Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
    30463023  } else {
    3047     DoeLog(0) && (eLog()<< Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);
     3024    DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);
    30483025    return NULL;
    30493026  }
    30503027
    30513028  return NewLine;
    3052 };
    3053 
     3029}
     3030;
    30543031
    30553032/** Finds the second point of starting triangle.
     
    30633040void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
    30643041{
    3065         Info FunctionInfo(__func__);
     3042  Info FunctionInfo(__func__);
    30663043  Vector AngleCheck;
    30673044  class TesselPoint* Candidate = NULL;
     
    30723049  int Nupper[NDIM];
    30733050
    3074   if (LC->SetIndexToNode(a)) {  // get cell for the starting point
    3075     for(int i=0;i<NDIM;i++) // store indices of this cell
     3051  if (LC->SetIndexToNode(a)) { // get cell for the starting point
     3052    for (int i = 0; i < NDIM; i++) // store indices of this cell
    30763053      N[i] = LC->n[i];
    30773054  } else {
    3078     DoeLog(1) && (eLog()<< Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);
     3055    DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);
    30793056    return;
    30803057  }
    30813058  // then go through the current and all neighbouring cells and check the contained points for possible candidates
    3082   for (int i=0;i<NDIM;i++) {
    3083     Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
    3084     Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
    3085   }
    3086   Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :"
    3087     << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl;
     3059  for (int i = 0; i < NDIM; i++) {
     3060    Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
     3061    Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
     3062  }
     3063  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;
    30883064
    30893065  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
     
    31193095              norm = aCandidate.Norm();
    31203096              // second point shall have smallest angle with respect to Oben vector
    3121               if (norm < RADIUS*2.) {
     3097              if (norm < RADIUS * 2.) {
    31223098                angle = AngleCheck.Angle(&Oben);
    31233099                if (angle < Storage[0]) {
     
    31413117        }
    31423118      }
    3143 };
    3144 
     3119}
     3120;
    31453121
    31463122/** This recursive function finds a third point, to form a triangle with two given ones.
     
    31743150 * @param *LC LinkedCell structure with neighbouring points
    31753151 */
    3176 void 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
    3177 {
    3178         Info FunctionInfo(__func__);
    3179   Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     3152void 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
     3153{
     3154  Info FunctionInfo(__func__);
     3155  Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
    31803156  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
    31813157  Vector SphereCenter;
    3182   Vector NewSphereCenter;   // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
    3183   Vector OtherNewSphereCenter;   // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
    3184   Vector NewNormalVector;   // normal vector of the Candidate's triangle
     3158  Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
     3159  Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
     3160  Vector NewNormalVector; // normal vector of the Candidate's triangle
    31853161  Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
    31863162  Vector RelativeOldSphereCenter;
     
    32133189
    32143190  // calculate squared radius TesselPoint *ThirdPoint,f circle
    3215   radius = CirclePlaneNormal.NormSquared()/4.;
    3216   if (radius < RADIUS*RADIUS) {
    3217     CircleRadius = RADIUS*RADIUS - radius;
     3191  radius = CirclePlaneNormal.NormSquared() / 4.;
     3192  if (radius < RADIUS * RADIUS) {
     3193    CircleRadius = RADIUS * RADIUS - radius;
    32183194    CirclePlaneNormal.Normalize();
    32193195    Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     
    32213197    // test whether old center is on the band's plane
    32223198    if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    3223       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);
     3199      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);
    32243200      RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
    32253201    }
     
    32303206      // check SearchDirection
    32313207      Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    3232       if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {  // rotated the wrong way!
    3233         DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
     3208      if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
     3209        DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
    32343210      }
    32353211
    32363212      // get cell for the starting point
    32373213      if (LC->SetIndexToVector(&CircleCenter)) {
    3238         for(int i=0;i<NDIM;i++) // store indices of this cell
    3239         N[i] = LC->n[i];
     3214        for (int i = 0; i < NDIM; i++) // store indices of this cell
     3215          N[i] = LC->n[i];
    32403216        //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    32413217      } else {
    3242         DoeLog(1) && (eLog()<< Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);
     3218        DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);
    32433219        return;
    32443220      }
    32453221      // then go through the current and all neighbouring cells and check the contained points for possible candidates
    32463222      //Log() << Verbose(1) << "LC Intervals:";
    3247       for (int i=0;i<NDIM;i++) {
    3248         Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
    3249         Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
     3223      for (int i = 0; i < NDIM; i++) {
     3224        Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
     3225        Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
    32503226        //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
    32513227      }
     
    32623238                // check for three unique points
    32633239                Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl;
    3264                 if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node) ){
     3240                if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) {
    32653241
    32663242                  // find center on the plane
     
    32683244                  Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl;
    32693245
    3270                   if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node)
    3271                   && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)
    3272                   ) {
     3246                  if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) {
    32733247                    Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
    32743248                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
     
    32763250                    Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    32773251                    Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl;
    3278                     if (radius < RADIUS*RADIUS) {
     3252                    if (radius < RADIUS * RADIUS) {
    32793253                      otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
    32803254                      if (fabs(radius - otherradius) > HULLEPSILON) {
    3281                         DoeLog(1) && (eLog()<< Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl);
     3255                        DoeLog(1) && (eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
    32823256                      }
    32833257                      // construct both new centers
     
    32853259                      OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
    32863260                      helper.CopyVector(&NewNormalVector);
    3287                       helper.Scale(sqrt(RADIUS*RADIUS - radius));
     3261                      helper.Scale(sqrt(RADIUS * RADIUS - radius));
    32883262                      Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl;
    32893263                      NewSphereCenter.AddVector(&helper);
     
    33113285                        if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
    33123286                          CandidateLine.pointlist.push_back(Candidate);
    3313                           Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
    3314                             << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     3287                          Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    33153288                        } else {
    33163289                          // remove all candidates from the list and then the list itself
    33173290                          CandidateLine.pointlist.clear();
    33183291                          CandidateLine.pointlist.push_back(Candidate);
    3319                           Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
    3320                             << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     3292                          Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    33213293                        }
    33223294                        CandidateLine.ShortestAngle = alpha;
     
    33463318          }
    33473319    } else {
    3348       DoeLog(1) && (eLog()<< Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
     3320      DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
    33493321    }
    33503322  } else {
     
    33553327  }
    33563328
    3357   if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
    3358     DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
    3359     performCriticalExit();
    3360   }
    3361 
    33623329  DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl);
    33633330  if (CandidateLine.pointlist.size() > 1) {
     
    33653332    CandidateLine.pointlist.sort(); //SortCandidates);
    33663333  }
    3367 };
     3334
     3335  if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
     3336    DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
     3337    performCriticalExit();
     3338  }
     3339}
     3340;
    33683341
    33693342/** Finds the endpoint two lines are sharing.
     
    33743347class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
    33753348{
    3376         Info FunctionInfo(__func__);
     3349  Info FunctionInfo(__func__);
    33773350  const BoundaryLineSet * lines[2] = { line1, line2 };
    33783351  class BoundaryPointSet *node = NULL;
     
    33813354  for (int i = 0; i < 2; i++)
    33823355    // for both lines
    3383     for (int j = 0; j < 2; j++)
    3384       { // for both endpoints
    3385         OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (
    3386             lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
    3387         if (!OrderTest.second)
    3388           { // if insertion fails, we have common endpoint
    3389             node = OrderTest.first->second;
    3390             Log() << Verbose(1) << "Common endpoint of lines " << *line1
    3391                 << " and " << *line2 << " is: " << *node << "." << endl;
    3392             j = 2;
    3393             i = 2;
    3394             break;
    3395           }
     3356    for (int j = 0; j < 2; j++) { // for both endpoints
     3357      OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
     3358      if (!OrderTest.second) { // if insertion fails, we have common endpoint
     3359        node = OrderTest.first->second;
     3360        Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl;
     3361        j = 2;
     3362        i = 2;
     3363        break;
    33963364      }
     3365    }
    33973366  return node;
    3398 };
     3367}
     3368;
    33993369
    34003370/** Finds the boundary points that are closest to a given Vector \a *x.
     
    34103380
    34113381  if (LinesOnBoundary.empty()) {
    3412     DoeLog(1) && (eLog()<< Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);
     3382    DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);
    34133383    return NULL;
    34143384  }
     
    34163386  // gather all points close to the desired one
    34173387  LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
    3418   for(int i=0;i<NDIM;i++) // store indices of this cell
     3388  for (int i = 0; i < NDIM; i++) // store indices of this cell
    34193389    N[i] = LC->n[i];
    34203390  Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    3421 
    34223391  DistanceToPointMap * points = new DistanceToPointMap;
    34233392  LC->GetNeighbourBounds(Nlower, Nupper);
     
    34323401            FindPoint = PointsOnBoundary.find((*Runner)->nr);
    34333402            if (FindPoint != PointsOnBoundary.end()) {
    3434               points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(x), FindPoint->second) );
     3403              points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(x), FindPoint->second));
    34353404              Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl;
    34363405            }
    34373406          }
    34383407        } else {
    3439           DoeLog(1) && (eLog()<< Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
     3408          DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
    34403409        }
    34413410      }
     
    34433412  // check whether we found some points
    34443413  if (points->empty()) {
    3445     DoeLog(1) && (eLog()<< Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
    3446     delete(points);
     3414    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
     3415    delete (points);
    34473416    return NULL;
    34483417  }
    34493418  return points;
    3450 };
     3419}
     3420;
    34513421
    34523422/** Finds the boundary line that is closest to a given Vector \a *x.
     
    34583428{
    34593429  Info FunctionInfo(__func__);
    3460 
    34613430  // get closest points
    3462   DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3431  DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
    34633432  if (points == NULL) {
    3464     DoeLog(1) && (eLog()<< Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
     3433    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
    34653434    return NULL;
    34663435  }
     
    34953464        helper.SubtractVector(&Center);
    34963465        const double lengthB = helper.ScalarProduct(&BaseLine);
    3497         if (lengthB*lengthA < 0) { // if have different sign
     3466        if (lengthB * lengthA < 0) { // if have different sign
    34983467          ClosestLine = LineRunner->second;
    34993468          MinDistance = distance;
     
    35073476    }
    35083477  }
    3509   delete(points);
     3478  delete (points);
    35103479  // check whether closest line is "too close" :), then it's inside
    35113480  if (ClosestLine == NULL) {
     
    35143483  }
    35153484  return ClosestLine;
    3516 };
     3485}
     3486;
    35173487
    35183488/** Finds the triangle that is closest to a given Vector \a *x.
     
    35233493TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
    35243494{
    3525         Info FunctionInfo(__func__);
    3526 
    3527         // get closest points
    3528         DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3495  Info FunctionInfo(__func__);
     3496  // get closest points
     3497  DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
    35293498  if (points == NULL) {
    3530     DoeLog(1) && (eLog()<< Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
     3499    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
    35313500    return NULL;
    35323501  }
     
    35553524      const double lengthEndB = BaseLineIntersection.NormSquared();
    35563525
    3557       if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) {  // intersection would be outside, take closer endpoint
     3526      if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
    35583527        const double lengthEnd = Min(lengthEndA, lengthEndB);
    35593528        if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
     
    35623531          MinDistance = lengthEnd;
    35633532          Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl;
    3564         } else if  (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
     3533        } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
    35653534          ClosestLines.insert(LineRunner->second);
    35663535          Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl;
     
    35773546        const double distance = BaseLineIntersection.NormSquared();
    35783547        if (Center.NormSquared() > BaseLine.NormSquared()) {
    3579           DoeLog(0) && (eLog()<< Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);
     3548          DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);
    35803549        }
    35813550        if ((ClosestLines.empty()) || (distance < MinDistance)) {
     
    35893558    }
    35903559  }
    3591   delete(points);
     3560  delete (points);
    35923561
    35933562  // check whether closest line is "too close" :), then it's inside
     
    35993568  for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
    36003569    for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
    3601     candidates->push_back(Runner->second);
    3602   }
     3570      candidates->push_back(Runner->second);
     3571    }
    36033572  return candidates;
    3604 };
     3573}
     3574;
    36053575
    36063576/** Finds closest triangle to a point.
     
    36133583class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
    36143584{
    3615         Info FunctionInfo(__func__);
     3585  Info FunctionInfo(__func__);
    36163586  class BoundaryTriangleSet *result = NULL;
    36173587  TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
     
    36243594
    36253595  // go through all and pick the one with the best alignment to x
    3626   double MinAlignment = 2.*M_PI;
     3596  double MinAlignment = 2. * M_PI;
    36273597  for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
    36283598    (*Runner)->GetCenter(&Center);
     
    36383608    }
    36393609  }
    3640   delete(triangles);
     3610  delete (triangles);
    36413611
    36423612  return result;
    3643 };
     3613}
     3614;
    36443615
    36453616/** Checks whether the provided Vector is within the Tesselation structure.
     
    36533624{
    36543625  Info FunctionInfo(__func__);
    3655   TriangleIntersectionList Intersections(&Point,this,LC);
     3626  TriangleIntersectionList Intersections(&Point, this, LC);
    36563627
    36573628  return Intersections.IsInside();
    3658 };
     3629}
     3630;
    36593631
    36603632/** Returns the distance to the surface given by the tesselation.
     
    37273699    }
    37283700  }
    3729 };
     3701}
     3702;
    37303703
    37313704/** Calculates minimum distance from \a&Point to a tesselated surface.
     
    37383711{
    37393712  Info FunctionInfo(__func__);
    3740   TriangleIntersectionList Intersections(&Point,this,LC);
     3713  TriangleIntersectionList Intersections(&Point, this, LC);
    37413714
    37423715  return Intersections.GetSmallestDistance();
    3743 };
     3716}
     3717;
    37443718
    37453719/** Calculates minimum distance from \a&Point to a tesselated surface.
     
    37523726{
    37533727  Info FunctionInfo(__func__);
    3754   TriangleIntersectionList Intersections(&Point,this,LC);
     3728  TriangleIntersectionList Intersections(&Point, this, LC);
    37553729
    37563730  return Intersections.GetClosestTriangle();
    3757 };
     3731}
     3732;
    37583733
    37593734/** Gets all points connected to the provided point by triangulation lines.
     
    37653740TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    37663741{
    3767         Info FunctionInfo(__func__);
    3768         TesselPointSet *connectedPoints = new TesselPointSet;
     3742  Info FunctionInfo(__func__);
     3743  TesselPointSet *connectedPoints = new TesselPointSet;
    37693744  class BoundaryPointSet *ReferencePoint = NULL;
    37703745  TesselPoint* current;
    37713746  bool takePoint = false;
    3772 
    37733747  // find the respective boundary point
    37743748  PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
     
    37763750    ReferencePoint = PointRunner->second;
    37773751  } else {
    3778     DoeLog(2) && (eLog()<< Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
     3752    DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
    37793753    ReferencePoint = NULL;
    37803754  }
     
    37823756  // little trick so that we look just through lines connect to the BoundaryPoint
    37833757  // OR fall-back to look through all lines if there is no such BoundaryPoint
    3784   const LineMap *Lines;;
     3758  const LineMap *Lines;
     3759  ;
    37853760  if (ReferencePoint != NULL)
    37863761    Lines = &(ReferencePoint->lines);
     
    37893764  LineMap::const_iterator findLines = Lines->begin();
    37903765  while (findLines != Lines->end()) {
    3791    takePoint = false;
    3792 
    3793    if (findLines->second->endpoints[0]->Nr == Point->nr) {
    3794      takePoint = true;
    3795      current = findLines->second->endpoints[1]->node;
    3796    } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
    3797      takePoint = true;
    3798      current = findLines->second->endpoints[0]->node;
    3799    }
    3800 
    3801    if (takePoint) {
    3802      Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
    3803      connectedPoints->insert(current);
    3804    }
    3805 
    3806    findLines++;
     3766    takePoint = false;
     3767
     3768    if (findLines->second->endpoints[0]->Nr == Point->nr) {
     3769      takePoint = true;
     3770      current = findLines->second->endpoints[1]->node;
     3771    } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
     3772      takePoint = true;
     3773      current = findLines->second->endpoints[0]->node;
     3774    }
     3775
     3776    if (takePoint) {
     3777      Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
     3778      connectedPoints->insert(current);
     3779    }
     3780
     3781    findLines++;
    38073782  }
    38083783
    38093784  if (connectedPoints->empty()) { // if have not found any points
    3810     DoeLog(1) && (eLog()<< Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl);
     3785    DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl);
    38113786    return NULL;
    38123787  }
    38133788
    38143789  return connectedPoints;
    3815 };
    3816 
     3790}
     3791;
    38173792
    38183793/** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
     
    38303805TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    38313806{
    3832         Info FunctionInfo(__func__);
     3807  Info FunctionInfo(__func__);
    38333808  map<double, TesselPoint*> anglesOfPoints;
    38343809  TesselPointList *connectedCircle = new TesselPointList;
     
    38373812  Vector OrthogonalVector;
    38383813  Vector helper;
    3839   const TesselPoint * const TrianglePoints[3] = {Point, NULL, NULL};
     3814  const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL };
    38403815  TriangleList *triangles = NULL;
    38413816
    38423817  if (SetOfNeighbours == NULL) {
    3843     DoeLog(2) && (eLog()<< Verbose(2) << "Could not find any connected points!" << endl);
    3844     delete(connectedCircle);
     3818    DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
     3819    delete (connectedCircle);
    38453820    return NULL;
    38463821  }
     
    38523827      PlaneNormal.AddVector(&(*Runner)->NormalVector);
    38533828  } else {
    3854     DoeLog(0) && (eLog()<< Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
     3829    DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
    38553830    performCriticalExit();
    38563831  }
    3857   PlaneNormal.Scale(1.0/triangles->size());
     3832  PlaneNormal.Scale(1.0 / triangles->size());
    38583833  Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl;
    38593834  PlaneNormal.Normalize();
     
    38653840    AngleZero.ProjectOntoPlane(&PlaneNormal);
    38663841  }
    3867   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
     3842  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
    38683843    Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
    38693844    AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
     
    38713846    AngleZero.ProjectOntoPlane(&PlaneNormal);
    38723847    if (AngleZero.NormSquared() < MYEPSILON) {
    3873       DoeLog(0) && (eLog()<< Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
     3848      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
    38743849      performCriticalExit();
    38753850    }
     
    38893864    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    38903865    Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
    3891     anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
    3892   }
    3893 
    3894   for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
     3866    anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
     3867  }
     3868
     3869  for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
    38953870    connectedCircle->push_back(AngleRunner->second);
    38963871  }
     
    39223897
    39233898  if (SetOfNeighbours == NULL) {
    3924     DoeLog(2) && (eLog()<< Verbose(2) << "Could not find any connected points!" << endl);
    3925     delete(connectedCircle);
     3899    DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
     3900    delete (connectedCircle);
    39263901    return NULL;
    39273902  }
     
    39363911  Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl;
    39373912  // calculate central point
    3938 
    39393913  TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
    39403914  TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
     
    39553929  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
    39563930  //  << "; scale factor " << counter;
    3957   PlaneNormal.Scale(1.0/(double)counter);
    3958 //  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
    3959 //
    3960 //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
    3961 //  PlaneNormal.CopyVector(Point->node);
    3962 //  PlaneNormal.SubtractVector(&center);
    3963 //  PlaneNormal.Normalize();
     3931  PlaneNormal.Scale(1.0 / (double) counter);
     3932  //  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
     3933  //
     3934  //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
     3935  //  PlaneNormal.CopyVector(Point->node);
     3936  //  PlaneNormal.SubtractVector(&center);
     3937  //  PlaneNormal.Normalize();
    39643938  Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
    39653939
     
    39703944    AngleZero.ProjectOntoPlane(&PlaneNormal);
    39713945  }
    3972   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
     3946  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
    39733947    Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
    39743948    AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
     
    39763950    AngleZero.ProjectOntoPlane(&PlaneNormal);
    39773951    if (AngleZero.NormSquared() < MYEPSILON) {
    3978       DoeLog(0) && (eLog()<< Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
     3952      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
    39793953      performCriticalExit();
    39803954    }
     
    39883962
    39893963  // go through all connected points and calculate angle
    3990   pair <map<double, TesselPoint*>::iterator, bool > InserterTest;
     3964  pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
    39913965  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    39923966    helper.CopyVector((*listRunner)->node);
     
    39953969    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    39963970    if (angle > M_PI) // the correction is of no use here (and not desired)
    3997       angle = 2.*M_PI - angle;
     3971      angle = 2. * M_PI - angle;
    39983972    Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl;
    3999     InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
     3973    InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
    40003974    if (!InserterTest.second) {
    4001       DoeLog(0) && (eLog()<< Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);
     3975      DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);
    40023976      performCriticalExit();
    40033977    }
    40043978  }
    40053979
    4006   for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
     3980  for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
    40073981    connectedCircle->push_back(AngleRunner->second);
    40083982  }
     
    40193993ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    40203994{
    4021         Info FunctionInfo(__func__);
     3995  Info FunctionInfo(__func__);
    40223996  map<double, TesselPoint*> anglesOfPoints;
    4023   list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;
     3997  list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ;
    40243998  TesselPointList *connectedPath = NULL;
    40253999  Vector center;
     
    40334007  class BoundaryLineSet *CurrentLine = NULL;
    40344008  class BoundaryLineSet *StartLine = NULL;
    4035 
    40364009  // find the respective boundary point
    40374010  PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
     
    40394012    ReferencePoint = PointRunner->second;
    40404013  } else {
    4041     DoeLog(1) && (eLog()<< Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
     4014    DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
    40424015    return NULL;
    40434016  }
    40444017
    4045   map <class BoundaryLineSet *, bool> TouchedLine;
    4046   map <class BoundaryTriangleSet *, bool> TouchedTriangle;
    4047   map <class BoundaryLineSet *, bool>::iterator LineRunner;
    4048   map <class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
     4018  map<class BoundaryLineSet *, bool> TouchedLine;
     4019  map<class BoundaryTriangleSet *, bool> TouchedTriangle;
     4020  map<class BoundaryLineSet *, bool>::iterator LineRunner;
     4021  map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
    40494022  for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
    4050     TouchedLine.insert( pair <class BoundaryLineSet *, bool>(Runner->second, false) );
     4023    TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false));
    40514024    for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
    4052       TouchedTriangle.insert( pair <class BoundaryTriangleSet *, bool>(Sprinter->second, false) );
     4025      TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false));
    40534026  }
    40544027  if (!ReferencePoint->lines.empty()) {
     
    40564029      LineRunner = TouchedLine.find(runner->second);
    40574030      if (LineRunner == TouchedLine.end()) {
    4058         DoeLog(1) && (eLog()<< Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);
     4031        DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);
    40594032      } else if (!LineRunner->second) {
    40604033        LineRunner->second = true;
     
    40644037        StartLine = CurrentLine;
    40654038        CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
    4066         Log() << Verbose(1)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
     4039        Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
    40674040        do {
    40684041          // push current one
     
    40864059                }
    40874060              } else {
    4088                 DoeLog(1) && (eLog()<< Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);
     4061                DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);
    40894062                triangle = NULL;
    40904063              }
     
    40944067            break;
    40954068          // find next line
    4096           for (int i=0;i<3;i++) {
     4069          for (int i = 0; i < 3; i++) {
    40974070            if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
    40984071              CurrentLine = triangle->lines[i];
     
    41034076          LineRunner = TouchedLine.find(CurrentLine);
    41044077          if (LineRunner == TouchedLine.end())
    4105             DoeLog(1) && (eLog()<< Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);
     4078            DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);
    41064079          else
    41074080            LineRunner->second = true;
     
    41214094    }
    41224095  } else {
    4123     DoeLog(1) && (eLog()<< Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);
     4096    DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);
    41244097  }
    41254098
     
    41354108ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    41364109{
    4137         Info FunctionInfo(__func__);
     4110  Info FunctionInfo(__func__);
    41384111  list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    4139   list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *>;
     4112  list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;
    41404113  TesselPointList *connectedPath = NULL;
    41414114  TesselPointList *newPath = NULL;
    41424115  int count = 0;
    4143 
    4144 
    41454116  TesselPointList::iterator CircleRunner;
    41464117  TesselPointList::iterator CircleStart;
    41474118
    4148   for(list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
     4119  for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
    41494120    connectedPath = *ListRunner;
    41504121
     
    41534124    // go through list, look for reappearance of starting Point and count
    41544125    CircleStart = connectedPath->begin();
    4155 
    41564126    // go through list, look for reappearance of starting Point and create list
    41574127    TesselPointList::iterator Marker = CircleStart;
     
    41594129      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    41604130        // we have a closed circle from Marker to new Marker
    4161         Log() << Verbose(1) << count+1 << ". closed path consists of: ";
     4131        Log() << Verbose(1) << count + 1 << ". closed path consists of: ";
    41624132        newPath = new TesselPointList;
    41634133        TesselPointList::iterator CircleSprinter = Marker;
     
    41814151    connectedPath = *(ListofPaths->begin());
    41824152    ListofPaths->remove(connectedPath);
    4183     delete(connectedPath);
    4184   }
    4185   delete(ListofPaths);
     4153    delete (connectedPath);
     4154  }
     4155  delete (ListofPaths);
    41864156
    41874157  // exit
    41884158  return ListofClosedPaths;
    4189 };
    4190 
     4159}
     4160;
    41914161
    41924162/** Gets all belonging triangles for a given BoundaryPointSet.
     
    41974167TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    41984168{
    4199         Info FunctionInfo(__func__);
    4200         TriangleSet *connectedTriangles = new TriangleSet;
     4169  Info FunctionInfo(__func__);
     4170  TriangleSet *connectedTriangles = new TriangleSet;
    42014171
    42024172  if (Point == NULL) {
    4203     DoeLog(1) && (eLog()<< Verbose(1) << "Point given is NULL." << endl);
     4173    DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl);
    42044174  } else {
    42054175    // go through its lines and insert all triangles
    42064176    for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
    42074177      for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    4208       connectedTriangles->insert(TriangleRunner->second);
    4209     }
     4178        connectedTriangles->insert(TriangleRunner->second);
     4179      }
    42104180  }
    42114181
    42124182  return connectedTriangles;
    4213 };
    4214 
     4183}
     4184;
    42154185
    42164186/** Removes a boundary point from the envelope while keeping it closed.
     
    42254195 * \return volume added to the volume inside the tesselated surface by the removal
    42264196 */
    4227 double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) {
     4197double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point)
     4198{
    42284199  class BoundaryLineSet *line = NULL;
    42294200  class BoundaryTriangleSet *triangle = NULL;
     
    42334204
    42344205  if (point == NULL) {
    4235     DoeLog(1) && (eLog()<< Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);
     4206    DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);
    42364207    return 0.;
    42374208  } else
     
    42434214  // get list of connected points
    42444215  if (point->lines.empty()) {
    4245     DoeLog(1) && (eLog()<< Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);
     4216    DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);
    42464217    return 0.;
    42474218  }
     
    42524223  // gather all triangles
    42534224  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
    4254     count+=LineRunner->second->triangles.size();
     4225    count += LineRunner->second->triangles.size();
    42554226  TriangleMap Candidates;
    42564227  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
     
    42584229    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    42594230      triangle = TriangleRunner->second;
    4260       Candidates.insert( TrianglePair (triangle->Nr, triangle) );
     4231      Candidates.insert(TrianglePair(triangle->Nr, triangle));
    42614232    }
    42624233  }
    42634234
    42644235  // remove all triangles
    4265   count=0;
     4236  count = 0;
    42664237  NormalVector.Zero();
    42674238  for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
     
    42804251  double smallestangle;
    42814252  Vector Point, Reference, OrthogonalVector;
    4282   if (count > 2) {  // less than three triangles, then nothing will be created
     4253  if (count > 2) { // less than three triangles, then nothing will be created
    42834254    class TesselPoint *TriangleCandidates[3];
    42844255    count = 0;
    4285     for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
     4256    for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
    42864257      if (ListAdvance != ListOfClosedPaths->end())
    42874258        ListAdvance++;
    42884259
    42894260      connectedPath = *ListRunner;
    4290 
    42914261      // re-create all triangles by going through connected points list
    42924262      LineList NewLines;
    4293       for (;!connectedPath->empty();) {
     4263      for (; !connectedPath->empty();) {
    42944264        // search middle node with widest angle to next neighbours
    42954265        EndNode = connectedPath->end();
     
    43174287          angle = GetAngle(Point, Reference, OrthogonalVector);
    43184288          //if (angle < M_PI)  // no wrong-sided triangles, please?
    4319             if(fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
    4320               smallestangle = angle;
    4321               EndNode = MiddleNode;
    4322             }
     4289          if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
     4290            smallestangle = angle;
     4291            EndNode = MiddleNode;
     4292          }
    43234293        }
    43244294        MiddleNode = EndNode;
    43254295        if (MiddleNode == connectedPath->end()) {
    4326           DoeLog(0) && (eLog()<< Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);
     4296          DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);
    43274297          performCriticalExit();
    43284298        }
     
    43434313        triangle = GetPresentTriangle(TriangleCandidates);
    43444314        if (triangle != NULL) {
    4345           DoeLog(0) && (eLog()<< Verbose(0) << "New triangle already present, skipping!" << endl);
     4315          DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl);
    43464316          StartNode++;
    43474317          MiddleNode++;
     
    43554325          continue;
    43564326        }
    4357         Log() << Verbose(3) << "Adding new triangle points."<< endl;
     4327        Log() << Verbose(3) << "Adding new triangle points." << endl;
    43584328        AddTesselationPoint(*StartNode, 0);
    43594329        AddTesselationPoint(*MiddleNode, 1);
    43604330        AddTesselationPoint(*EndNode, 2);
    4361         Log() << Verbose(3) << "Adding new triangle lines."<< endl;
     4331        Log() << Verbose(3) << "Adding new triangle lines." << endl;
    43624332        AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
    43634333        AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     
    43814351          break;
    43824352        } else if (connectedPath->size() < 2) { // something's gone wrong!
    4383           DoeLog(0) && (eLog()<< Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);
     4353          DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);
    43844354          performCriticalExit();
    43854355        } else {
     
    44014371        do {
    44024372          maxgain = 0;
    4403           for(LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
     4373          for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
    44044374            tmp = PickFarthestofTwoBaselines(*Runner);
    44054375            if (maxgain < tmp) {
     
    44194389
    44204390      ListOfClosedPaths->remove(connectedPath);
    4421       delete(connectedPath);
     4391      delete (connectedPath);
    44224392    }
    44234393    Log() << Verbose(0) << count << " triangles were created." << endl;
     
    44274397      connectedPath = *ListRunner;
    44284398      ListOfClosedPaths->remove(connectedPath);
    4429       delete(connectedPath);
     4399      delete (connectedPath);
    44304400    }
    44314401    Log() << Verbose(0) << "No need to create any triangles." << endl;
    44324402  }
    4433   delete(ListOfClosedPaths);
     4403  delete (ListOfClosedPaths);
    44344404
    44354405  Log() << Verbose(0) << "Removed volume is " << volume << "." << endl;
    44364406
    44374407  return volume;
    4438 };
    4439 
    4440 
     4408}
     4409;
    44414410
    44424411/**
     
    44504419TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    44514420{
    4452         Info FunctionInfo(__func__);
    4453         TriangleList *result = new TriangleList;
     4421  Info FunctionInfo(__func__);
     4422  TriangleList *result = new TriangleList;
    44544423  LineMap::const_iterator FindLine;
    44554424  TriangleMap::const_iterator FindTriangle;
     
    44754444      for (int i = 0; i < 3; i++) {
    44764445        if (TrianglePoints[i] != NULL) {
    4477           for (int j = i+1; j < 3; j++) {
     4446          for (int j = i + 1; j < 3; j++) {
    44784447            if (TrianglePoints[j] != NULL) {
    44794448              for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
    4480                   (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
    4481                   FindLine++) {
    4482                 for (FindTriangle = FindLine->second->triangles.begin();
    4483                     FindTriangle != FindLine->second->triangles.end();
    4484                     FindTriangle++) {
     4449              (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) {
     4450                for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
    44854451                  if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    44864452                    result->push_back(FindTriangle->second);
     
    44974463    case 1: // copy all triangles of the respective line
    44984464    {
    4499       int i=0;
     4465      int i = 0;
    45004466      for (; i < 3; i++)
    45014467        if (TrianglePoints[i] == NULL)
    45024468          break;
    4503       for (FindLine = TrianglePoints[(i+1)%3]->lines.find(TrianglePoints[(i+2)%3]->node->nr); // is a multimap!
    4504           (FindLine != TrianglePoints[(i+1)%3]->lines.end()) && (FindLine->first == TrianglePoints[(i+2)%3]->node->nr);
    4505           FindLine++) {
    4506         for (FindTriangle = FindLine->second->triangles.begin();
    4507             FindTriangle != FindLine->second->triangles.end();
    4508             FindTriangle++) {
     4469      for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap!
     4470      (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) {
     4471        for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
    45094472          if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    45104473            result->push_back(FindTriangle->second);
     
    45164479    case 2: // copy all triangles of the respective point
    45174480    {
    4518       int i=0;
     4481      int i = 0;
    45194482      for (; i < 3; i++)
    45204483        if (TrianglePoints[i] != NULL)
     
    45344497    }
    45354498    default:
    4536       DoeLog(0) && (eLog()<< Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);
     4499      DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);
    45374500      performCriticalExit();
    45384501      break;
     
    45424505}
    45434506
    4544 struct BoundaryLineSetCompare {
    4545   bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) {
     4507struct BoundaryLineSetCompare
     4508{
     4509  bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b)
     4510  {
    45464511    int lowerNra = -1;
    45474512    int lowerNrb = -1;
     
    45614526    else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
    45624527      return false;
    4563     else {  // both lower-numbered endpoints are the same ...
    4564      if (a->endpoints[(lowerNra+1)%2] < b->endpoints[(lowerNrb+1)%2])
    4565        return true;
    4566      else if (a->endpoints[(lowerNra+1)%2] > b->endpoints[(lowerNrb+1)%2])
    4567        return false;
     4528    else { // both lower-numbered endpoints are the same ...
     4529      if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2])
     4530        return true;
     4531      else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2])
     4532        return false;
    45684533    }
    45694534    return false;
    4570   };
     4535  }
     4536  ;
    45714537};
    45724538
     
    45814547IndexToIndex * Tesselation::FindAllDegeneratedLines()
    45824548{
    4583         Info FunctionInfo(__func__);
    4584         UniqueLines AllLines;
     4549  Info FunctionInfo(__func__);
     4550  UniqueLines AllLines;
    45854551  IndexToIndex * DegeneratedLines = new IndexToIndex;
    45864552
    45874553  // sanity check
    45884554  if (LinesOnBoundary.empty()) {
    4589     DoeLog(2) && (eLog()<< Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");
     4555    DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");
    45904556    return DegeneratedLines;
    45914557  }
    4592 
    45934558  LineMap::iterator LineRunner1;
    4594   pair< UniqueLines::iterator, bool> tester;
     4559  pair<UniqueLines::iterator, bool> tester;
    45954560  for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
    4596     tester = AllLines.insert( LineRunner1->second );
     4561    tester = AllLines.insert(LineRunner1->second);
    45974562    if (!tester.second) { // found degenerated line
    4598       DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr) );
    4599       DegeneratedLines->insert ( pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr) );
     4563      DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));
     4564      DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));
    46004565    }
    46014566  }
     
    46114576      Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl;
    46124577    else
    4613       DoeLog(1) && (eLog()<< Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);
     4578      DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);
    46144579  }
    46154580
     
    46254590IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
    46264591{
    4627         Info FunctionInfo(__func__);
     4592  Info FunctionInfo(__func__);
    46284593  IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
    46294594  IndexToIndex * DegeneratedTriangles = new IndexToIndex;
    4630 
    46314595  TriangleMap::iterator TriangleRunner1, TriangleRunner2;
    46324596  LineMap::iterator Liner;
     
    46434607    for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
    46444608      for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
    4645         if ((TriangleRunner1->second != TriangleRunner2->second)
    4646           && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
    4647           DegeneratedTriangles->insert( pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr) );
    4648           DegeneratedTriangles->insert( pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr) );
     4609        if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
     4610          DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr));
     4611          DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr));
    46494612        }
    46504613      }
    46514614    }
    46524615  }
    4653   delete(DegeneratedLines);
     4616  delete (DegeneratedLines);
    46544617
    46554618  Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
    46564619  IndexToIndex::iterator it;
    46574620  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    4658       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     4621    Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
    46594622
    46604623  return DegeneratedTriangles;
     
    46674630void Tesselation::RemoveDegeneratedTriangles()
    46684631{
    4669         Info FunctionInfo(__func__);
     4632  Info FunctionInfo(__func__);
    46704633  IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
    46714634  TriangleMap::iterator finder;
    46724635  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    4673   int count  = 0;
    4674 
    4675   for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
    4676     TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
    4677   ) {
     4636  int count = 0;
     4637
     4638  for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) {
    46784639    finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
    46794640    if (finder != TrianglesOnBoundary.end())
     
    46924653        trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
    46934654
    4694     if (trianglesShareLine
    4695       && (triangle->endpoints[1]->LinesCount > 2)
    4696       && (triangle->endpoints[2]->LinesCount > 2)
    4697       && (triangle->endpoints[0]->LinesCount > 2)
    4698     ) {
     4655    if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) {
    46994656      // check whether we have to fix lines
    47004657      BoundaryTriangleSet *Othertriangle = NULL;
     
    47164673            // the line of triangle receives the degenerated ones
    47174674            triangle->lines[i]->triangles.erase(Othertriangle->Nr);
    4718             triangle->lines[i]->triangles.insert( TrianglePair( partnerTriangle->Nr, partnerTriangle) );
    4719             for (int k=0;k<3;k++)
     4675            triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle));
     4676            for (int k = 0; k < 3; k++)
    47204677              if (triangle->lines[i] == Othertriangle->lines[k]) {
    47214678                Othertriangle->lines[k] = partnerTriangle->lines[j];
     
    47234680              }
    47244681            // the line of partnerTriangle receives the non-degenerated ones
    4725             partnerTriangle->lines[j]->triangles.erase( partnerTriangle->Nr);
    4726             partnerTriangle->lines[j]->triangles.insert( TrianglePair( Othertriangle->Nr, Othertriangle) );
     4682            partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr);
     4683            partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle));
    47274684            partnerTriangle->lines[j] = triangle->lines[i];
    47284685          }
     
    47364693      RemoveTesselationTriangle(partnerTriangle);
    47374694    } else {
    4738       Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
    4739         << " and its partner " << *partnerTriangle << " because it is essential for at"
    4740         << " least one of the endpoints to be kept in the tesselation structure." << endl;
    4741     }
    4742   }
    4743   delete(DegeneratedTriangles);
     4695      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;
     4696    }
     4697  }
     4698  delete (DegeneratedTriangles);
    47444699  if (count > 0)
    47454700    LastTriangle = NULL;
     
    47584713void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
    47594714{
    4760         Info FunctionInfo(__func__);
     4715  Info FunctionInfo(__func__);
    47614716  // find nearest boundary point
    47624717  class TesselPoint *BackupPoint = NULL;
     
    47714726    NearestBoundaryPoint = PointRunner->second;
    47724727  } else {
    4773     DoeLog(1) && (eLog()<< Verbose(1) << "I cannot find the boundary point." << endl);
     4728    DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl);
    47744729    return;
    47754730  }
     
    47894744    CenterToPoint.SubtractVector(point->node);
    47904745    angle = CenterToPoint.Angle(&BaseLine);
    4791     if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
     4746    if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) {
    47924747      BestAngle = angle;
    47934748      BestLine = Runner->second;
     
    47994754  BestLine->triangles.erase(TempTriangle->Nr);
    48004755  int nr = -1;
    4801   for (int i=0;i<3; i++) {
     4756  for (int i = 0; i < 3; i++) {
    48024757    if (TempTriangle->lines[i] == BestLine) {
    48034758      nr = i;
     
    48074762
    48084763  // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
    4809   Log() << Verbose(2) << "Adding new triangle points."<< endl;
     4764  Log() << Verbose(2) << "Adding new triangle points." << endl;
    48104765  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    48114766  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    48124767  AddTesselationPoint(point, 2);
    4813   Log() << Verbose(2) << "Adding new triangle lines."<< endl;
     4768  Log() << Verbose(2) << "Adding new triangle lines." << endl;
    48144769  AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
    48154770  AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     
    48224777
    48234778  // create other side of this triangle and close both new sides of the first created triangle
    4824   Log() << Verbose(2) << "Adding new triangle points."<< endl;
     4779  Log() << Verbose(2) << "Adding new triangle points." << endl;
    48254780  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    48264781  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    48274782  AddTesselationPoint(point, 2);
    4828   Log() << Verbose(2) << "Adding new triangle lines."<< endl;
     4783  Log() << Verbose(2) << "Adding new triangle lines." << endl;
    48294784  AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
    48304785  AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     
    48364791
    48374792  // add removed triangle to the last open line of the second triangle
    4838   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)
    48394794    if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
    4840       if (BestLine == BTS->lines[i]){
    4841         DoeLog(0) && (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);
    48424797        performCriticalExit();
    48434798      }
    4844       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));
    48454800      TempTriangle->lines[nr] = BTS->lines[i];
    48464801      break;
    48474802    }
    48484803  }
    4849 };
     4804}
     4805;
    48504806
    48514807/** Writes the envelope to file.
     
    48564812void Tesselation::Output(const char *filename, const PointCloud * const cloud)
    48574813{
    4858         Info FunctionInfo(__func__);
     4814  Info FunctionInfo(__func__);
    48594815  ofstream *tempstream = NULL;
    48604816  string NameofTempFile;
     
    48624818
    48634819  if (LastTriangle != NULL) {
    4864     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    sprintf(NumberName, "-%04d-%s_%s_%s", (int) TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);
    48654821    if (DoTecplotOutput) {
    48664822      string NameofTempFile(filename);
    48674823      NameofTempFile.append(NumberName);
    4868       for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
    4869       NameofTempFile.erase(npos, 1);
     4824      for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
     4825        NameofTempFile.erase(npos, 1);
    48704826      NameofTempFile.append(TecplotSuffix);
    48714827      Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     
    48744830      tempstream->close();
    48754831      tempstream->flush();
    4876       delete(tempstream);
     4832      delete (tempstream);
    48774833    }
    48784834
     
    48804836      string NameofTempFile(filename);
    48814837      NameofTempFile.append(NumberName);
    4882       for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
    4883       NameofTempFile.erase(npos, 1);
     4838      for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
     4839        NameofTempFile.erase(npos, 1);
    48844840      NameofTempFile.append(Raster3DSuffix);
    48854841      Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     
    48894845      tempstream->close();
    48904846      tempstream->flush();
    4891       delete(tempstream);
     4847      delete (tempstream);
    48924848    }
    48934849  }
    48944850  if (DoTecplotOutput || DoRaster3DOutput)
    48954851    TriangleFilesWritten++;
    4896 };
    4897 
    4898 struct BoundaryPolygonSetCompare {
    4899   bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const {
     4852}
     4853;
     4854
     4855struct BoundaryPolygonSetCompare
     4856{
     4857  bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const
     4858  {
    49004859    if (s1->endpoints.size() < s2->endpoints.size())
    49014860      return true;
     
    49264885{
    49274886  Info FunctionInfo(__func__);
    4928 
    49294887  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
    49304888  IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
    4931   set < BoundaryPointSet *> EndpointCandidateList;
    4932   pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
    4933   pair < map < int, Vector *>::iterator, bool > TriangleInsertionTester;
     4889  set<BoundaryPointSet *> EndpointCandidateList;
     4890  pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester;
     4891  pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester;
    49344892  for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
    49354893    Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl;
    4936     map < int, Vector *> TriangleVectors;
     4894    map<int, Vector *> TriangleVectors;
    49374895    // gather all NormalVectors
    49384896    Log() << Verbose(1) << "Gathering triangles ..." << endl;
     
    49404898      for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    49414899        if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
    4942           TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) );
     4900          TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));
    49434901          if (TriangleInsertionTester.second)
    49444902            Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;
     
    49494907    // check whether there are two that are parallel
    49504908    Log() << Verbose(1) << "Finding two parallel triangles ..." << endl;
    4951     for (map < int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
    4952       for (map < int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
     4909    for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
     4910      for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
    49534911        if (VectorWalker != VectorRunner) { // skip equals
    4954           const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second);  // ScalarProduct should result in -1. for degenerated triangles
    4955           Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl;
     4912          const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
     4913          Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl;
    49564914          if (fabs(SCP + 1.) < ParallelEpsilon) {
    49574915            InsertionTester = EndpointCandidateList.insert((Runner->second));
     
    49654923        }
    49664924  }
    4967   delete(DegeneratedTriangles);
    4968 
     4925  delete (DegeneratedTriangles);
    49694926  /// 3. Find connected endpoint candidates and put them into a polygon
    49704927  UniquePolygonSet ListofDegeneratedPolygons;
     
    49724929  BoundaryPointSet *OtherWalker = NULL;
    49734930  BoundaryPolygonSet *Current = NULL;
    4974   stack <BoundaryPointSet*> ToCheckConnecteds;
     4931  stack<BoundaryPointSet*> ToCheckConnecteds;
    49754932  while (!EndpointCandidateList.empty()) {
    49764933    Walker = *(EndpointCandidateList.begin());
    4977     if (Current == NULL) {  // create a new polygon with current candidate
     4934    if (Current == NULL) { // create a new polygon with current candidate
    49784935      Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl;
    49794936      Current = new BoundaryPolygonSet;
     
    49904947        OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
    49914948        Log() << Verbose(1) << "Checking " << *OtherWalker << endl;
    4992         set < BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
    4993         if (Finder != EndpointCandidateList.end()) {  // found a connected partner
     4949        set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
     4950        if (Finder != EndpointCandidateList.end()) { // found a connected partner
    49944951          Log() << Verbose(1) << " Adding to polygon." << endl;
    49954952          Current->endpoints.insert(OtherWalker);
    4996           EndpointCandidateList.erase(Finder);  // remove from candidates
    4997           ToCheckConnecteds.push(OtherWalker);  // but check its partners too
     4953          EndpointCandidateList.erase(Finder); // remove from candidates
     4954          ToCheckConnecteds.push(OtherWalker); // but check its partners too
    49984955        } else {
    49994956          Log() << Verbose(1) << " is not connected to " << *Walker << endl;
     
    50154972  /// 4. Go through all these degenerated polygons
    50164973  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
    5017     stack <int> TriangleNrs;
     4974    stack<int> TriangleNrs;
    50184975    Vector NormalVector;
    50194976    /// 4a. Gather all triangles of this polygon
     
    50234980    if (T->size() == 2) {
    50244981      Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl;
    5025       delete(T);
     4982      delete (T);
    50264983      continue;
    50274984    }
     
    50324989    // connections to either polygon ...
    50334990    if (T->size() % 2 != 0) {
    5034       DoeLog(0) && (eLog()<< Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);
     4991      DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);
    50354992      performCriticalExit();
    50364993    }
    5037 
    5038     TriangleSet::iterator TriangleWalker = T->begin();  // is the inner iterator
     4994    TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
    50394995    /// 4a. Get NormalVector for one side (this is "front")
    50404996    NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     
    50595015    /// 4c. Copy all "front" triangles but with inverse NormalVector
    50605016    TriangleWalker = T->begin();
    5061     while (TriangleWalker != T->end()) {  // go through all front triangles
     5017    while (TriangleWalker != T->end()) { // go through all front triangles
    50625018      Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl;
    50635019      for (int i = 0; i < 3; i++)
     
    50675023      AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    50685024      if (TriangleNrs.empty())
    5069         DoeLog(0) && (eLog()<< Verbose(0) << "No more free triangle numbers!" << endl);
     5025        DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl);
    50705026      BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
    50715027      AddTesselationTriangle(); // ... and add
     
    50765032    }
    50775033    if (!TriangleNrs.empty()) {
    5078       DoeLog(0) && (eLog()<< Verbose(0) << "There have been less triangles created than removed!" << endl);
    5079     }
    5080     delete(T);  // remove the triangleset
    5081   }
    5082 
     5034      DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl);
     5035    }
     5036    delete (T); // remove the triangleset
     5037  }
    50835038  IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
    50845039  Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
    50855040  IndexToIndex::iterator it;
    50865041  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
    5087       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
    5088   delete(SimplyDegeneratedTriangles);
    5089 
     5042    Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     5043  delete (SimplyDegeneratedTriangles);
    50905044  /// 5. exit
    50915045  UniquePolygonSet::iterator PolygonRunner;
    50925046  while (!ListofDegeneratedPolygons.empty()) {
    50935047    PolygonRunner = ListofDegeneratedPolygons.begin();
    5094     delete(*PolygonRunner);
     5048    delete (*PolygonRunner);
    50955049    ListofDegeneratedPolygons.erase(PolygonRunner);
    50965050  }
    50975051
    50985052  return counter;
    5099 };
     5053}
     5054;
  • src/tesselation.hpp

    rbc84ffc r6613ec  
    8989
    9090#define ListOfTesselPointList list<list <TesselPoint *> *>
     91
     92enum centers {Opt, OtherOpt};
    9193
    9294/********************************************** declarations *******************************/
     
    284286    void AddTesselationTriangle();
    285287    void AddTesselationTriangle(const int nr);
    286     void AddCandidateTriangle(CandidateForTesselation &CandidateLine);
     288    void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
    287289    void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
    288290    void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
     
    290292    void RemoveTesselationLine(class BoundaryLineSet *line);
    291293    void RemoveTesselationPoint(class BoundaryPointSet *point);
    292     bool CheckDegeneracy(Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC) const;
     294    bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const;
    293295
    294296
     
    298300    void FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
    299301    bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
     302    bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList);
    300303    int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
    301304    class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
     
    372375
    373376    //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
     377    void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter);
    374378};
    375379
Note: See TracChangeset for help on using the changeset viewer.