Changes in / [482373:0b2dd2]


Ignore:
Files:
8 added
38 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r482373 r0b2dd2  
    55ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
    66
    7 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
    8 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     7SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
     8HEADER = ${ANALYSISHEADER} ${ATOMHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
    99
    1010BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB)
     
    2525
    2626#EXTRA_DIST = ${molecuilder_DATA}
     27
     28FORCE:
     29$(srcdir)/.git-version: FORCE
     30        @if (test -d $(top_srcdir)/../.git && cd $(srcdir) && git describe HEAD) > .git-version-t 2>/dev/null \
     31          && ! diff .git-version-t $(srcdir)/.git-version >/dev/null 2>&1; then \
     32          mv -f .git-version-t $(srcdir)/.git-version; \
     33        else \
     34          rm -f .git-version-t; \
     35        fi
     36
     37EXTRA_DIST = $(srcdir)/.git-version
     38
     39$(srcdir)/version.c: $(srcdir)/.git-version
     40        echo "const char *ESPACKVersion = \"$(PACKAGE_NAME) -- git version: "`cat $(srcdir)/.git-version`"\";" > $@
     41
     42molecuilder_SOURCES += $(srcdir)/version.c
  • src/atom_bondedparticle.cpp

    r482373 r0b2dd2  
    121121  bond *CandidateBond = NULL;
    122122
     123  NoBonds = CountBonds();
    123124  //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    124   NoBonds = CountBonds();
    125125  if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
    126126    for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
    127127      OtherWalker = (*Runner)->GetOtherAtom(this);
    128128      OtherNoBonds = OtherWalker->CountBonds();
    129       //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    130       if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate
     129      //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl;
     130      if ((int)(OtherWalker->type->NoValenceOrbitals) > OtherNoBonds) { // check if possible candidate
    131131        if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first
    132132          CandidateBond = (*Runner);
     
    137137    if ((CandidateBond != NULL)) {
    138138      CandidateBond->BondDegree++;
    139       Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
     139      //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
    140140    } else {
    141       //Log() << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl;
     141      eLog() << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl;
    142142      FalseBondDegree++;
    143143    }
  • src/bondgraph.cpp

    r482373 r0b2dd2  
    3535/** Parses the bond lengths in a given file and puts them int a matrix form.
    3636 * Allocates \a MatrixContainer for BondGraph::BondLengthMatrix, using MatrixContainer::ParseMatrix(),
    37  * but only if parsing is successfull. Otherwise variable is left as NULL.
     37 * but only if parsing is successful. Otherwise variable is left as NULL.
    3838 * \param *out output stream for debugging
    3939 * \param filename file with bond lengths to parse
  • src/boundary.cpp

    r482373 r0b2dd2  
    1010#include "element.hpp"
    1111#include "helpers.hpp"
     12#include "info.hpp"
    1213#include "linkedcell.hpp"
    1314#include "log.hpp"
     
    3334double *GetDiametersOfCluster(const Boundaries *BoundaryPtr, const molecule *mol, Tesselation *&TesselStruct, const bool IsAngstroem)
    3435{
     36        Info FunctionInfo(__func__);
    3537  // get points on boundary of NULL was given as parameter
    3638  bool BoundaryFreeFlag = false;
     
    5355  } else {
    5456    BoundaryPoints = BoundaryPtr;
    55     Log() << Verbose(1) << "Using given boundary points set." << endl;
     57    Log() << Verbose(0) << "Using given boundary points set." << endl;
    5658  }
    5759  // determine biggest "diameter" of cluster for each axis
     
    6769          //Log() << Verbose(1) << "Current component is " << component << ", Othercomponent is " << Othercomponent << "." << endl;
    6870          for (Boundaries::const_iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
    69               //Log() << Verbose(2) << "Current runner is " << *(runner->second.second) << "." << endl;
     71              //Log() << Verbose(1) << "Current runner is " << *(runner->second.second) << "." << endl;
    7072              // seek for the neighbours pair where the Othercomponent sign flips
    7173              Neighbour = runner;
     
    8284                  DistanceVector.CopyVector(&runner->second.second->x);
    8385                  DistanceVector.SubtractVector(&Neighbour->second.second->x);
    84                   //Log() << Verbose(3) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl;
     86                  //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl;
    8587                } while ((runner != Neighbour) && (fabs(OldComponent / fabs(
    8688                  OldComponent) - DistanceVector.x[Othercomponent] / fabs(
     
    9193                    OtherNeighbour = BoundaryPoints[axis].end();
    9294                  OtherNeighbour--;
    93                   //Log() << Verbose(2) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl;
     95                  //Log() << Verbose(1) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl;
    9496                  // now we have found the pair: Neighbour and OtherNeighbour
    9597                  OtherVector.CopyVector(&runner->second.second->x);
    9698                  OtherVector.SubtractVector(&OtherNeighbour->second.second->x);
    97                   //Log() << Verbose(2) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl;
    98                   //Log() << Verbose(2) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl;
     99                  //Log() << Verbose(1) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl;
     100                  //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl;
    99101                  // do linear interpolation between points (is exact) to extract exact intersection between Neighbour and OtherNeighbour
    100102                  w1 = fabs(OtherVector.x[Othercomponent]);
     
    103105                      * OtherVector.x[component]) / (w1 + w2));
    104106                  // mark if it has greater diameter
    105                   //Log() << Verbose(2) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl;
     107                  //Log() << Verbose(1) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl;
    106108                  GreatestDiameter[component] = (GreatestDiameter[component]
    107109                      > tmp) ? GreatestDiameter[component] : tmp;
    108110                } //else
    109               //Log() << Verbose(2) << "Saw no sign flip, probably top or bottom node." << endl;
     111              //Log() << Verbose(1) << "Saw no sign flip, probably top or bottom node." << endl;
    110112            }
    111113        }
     
    135137Boundaries *GetBoundaryPoints(const molecule *mol, Tesselation *&TesselStruct)
    136138{
     139        Info FunctionInfo(__func__);
    137140  atom *Walker = NULL;
    138141  PointMap PointsOnBoundary;
     
    149152  double angle = 0.;
    150153
    151   Log() << Verbose(1) << "Finding all boundary points." << endl;
    152154  // 3a. Go through every axis
    153155  for (int axis = 0; axis < NDIM; axis++) {
     
    176178        angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues
    177179
    178       //Log() << Verbose(2) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
     180      //Log() << Verbose(1) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
    179181      if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) {
    180182        angle = 2. * M_PI - angle;
    181183      }
    182       Log() << Verbose(2) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl;
     184      Log() << Verbose(1) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl;
    183185      BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, Walker)));
    184186      if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity
     
    210212    // printing all inserted for debugging
    211213    //    {
    212     //      Log() << Verbose(2) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
     214    //      Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
    213215    //      int i=0;
    214216    //      for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
    215217    //        if (runner != BoundaryPoints[axis].begin())
    216     //          Log() << Verbose(2) << ", " << i << ": " << *runner->second.second;
     218    //          Log() << Verbose(0) << ", " << i << ": " << *runner->second.second;
    217219    //        else
    218     //          Log() << Verbose(2) << i << ": " << *runner->second.second;
     220    //          Log() << Verbose(0) << i << ": " << *runner->second.second;
    219221    //        i++;
    220222    //      }
    221     //      Log() << Verbose(2) << endl;
     223    //      Log() << Verbose(0) << endl;
    222224    //    }
    223225    // 3c. throw out points whose distance is less than the mean of left and right neighbours
     
    249251          SideA.SubtractVector(MolCenter);
    250252          SideA.ProjectOntoPlane(&AxisVector);
    251           //          Log() << Verbose(0) << "SideA: " << SideA << endl;
     253          //          Log() << Verbose(1) << "SideA: " << SideA << endl;
    252254
    253255          SideB.CopyVector(&right->second.second->x);
    254256          SideB.SubtractVector(MolCenter);
    255257          SideB.ProjectOntoPlane(&AxisVector);
    256           //          Log() << Verbose(0) << "SideB: " << SideB << endl;
     258          //          Log() << Verbose(1) << "SideB: " << SideB << endl;
    257259
    258260          SideC.CopyVector(&left->second.second->x);
    259261          SideC.SubtractVector(&right->second.second->x);
    260262          SideC.ProjectOntoPlane(&AxisVector);
    261           //          Log() << Verbose(0) << "SideC: " << SideC << endl;
     263          //          Log() << Verbose(1) << "SideC: " << SideC << endl;
    262264
    263265          SideH.CopyVector(&runner->second.second->x);
    264266          SideH.SubtractVector(MolCenter);
    265267          SideH.ProjectOntoPlane(&AxisVector);
    266           //          Log() << Verbose(0) << "SideH: " << SideH << endl;
     268          //          Log() << Verbose(1) << "SideH: " << SideH << endl;
    267269
    268270          // calculate each length
     
    277279          const double delta = SideC.Angle(&SideH);
    278280          const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.);
    279           //Log() << Verbose(2) << " I calculated: a = " << a << ", h = " << h << ", beta(" << left->second.second->Name << "," << left->second.second->Name << "-" << right->second.second->Name << ") = " << beta << ", delta(" << left->second.second->Name << "," << runner->second.second->Name << ") = " << delta << ", Min = " << MinDistance << "." << endl;
     281          //Log() << Verbose(1) << " I calculated: a = " << a << ", h = " << h << ", beta(" << left->second.second->Name << "," << left->second.second->Name << "-" << right->second.second->Name << ") = " << beta << ", delta(" << left->second.second->Name << "," << runner->second.second->Name << ") = " << delta << ", Min = " << MinDistance << "." << endl;
    280282          Log() << Verbose(1) << "Checking CoG distance of runner " << *runner->second.second << " " << h << " against triangle's side length spanned by (" << *left->second.second << "," << *right->second.second << ") of " << MinDistance << "." << endl;
    281283          if ((fabs(h / fabs(h) - MinDistance / fabs(MinDistance)) < MYEPSILON) && ((h - MinDistance)) < -MYEPSILON) {
     
    303305void FindConvexBorder(const molecule* mol, Tesselation *&TesselStruct, const LinkedCell *LCList, const char *filename)
    304306{
     307        Info FunctionInfo(__func__);
    305308  bool BoundaryFreeFlag = false;
    306309  Boundaries *BoundaryPoints = NULL;
    307 
    308   Log() << Verbose(1) << "Begin of FindConvexBorder" << endl;
    309310
    310311  if (TesselStruct != NULL) // free if allocated
     
    317318      BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
    318319  } else {
    319       Log() << Verbose(1) << "Using given boundary points set." << endl;
     320      Log() << Verbose(0) << "Using given boundary points set." << endl;
    320321  }
    321322
     
    323324  for (int axis=0; axis < NDIM; axis++)
    324325    {
    325       Log() << Verbose(2) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
     326      Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
    326327      int i=0;
    327328      for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
    328329        if (runner != BoundaryPoints[axis].begin())
    329           Log() << Verbose(2) << ", " << i << ": " << *runner->second.second;
     330          Log() << Verbose(0) << ", " << i << ": " << *runner->second.second;
    330331        else
    331           Log() << Verbose(2) << i << ": " << *runner->second.second;
     332          Log() << Verbose(0) << i << ": " << *runner->second.second;
    332333        i++;
    333334      }
    334       Log() << Verbose(2) << endl;
     335      Log() << Verbose(0) << endl;
    335336    }
    336337
     
    341342          eLog() << Verbose(2) << "Point " << *(runner->second.second) << " is already present!" << endl;
    342343
    343   Log() << Verbose(2) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl;
     344  Log() << Verbose(0) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl;
    344345  // now we have the whole set of edge points in the BoundaryList
    345346
     
    347348  //  Log() << Verbose(1) << "Listing PointsOnBoundary:";
    348349  //  for(PointMap::iterator runner = PointsOnBoundary.begin(); runner != PointsOnBoundary.end(); runner++) {
    349   //    Log() << Verbose(1) << " " << *runner->second;
     350  //    Log() << Verbose(0) << " " << *runner->second;
    350351  //  }
    351   //  Log() << Verbose(1) << endl;
     352  //  Log() << Verbose(0) << endl;
    352353
    353354  // 3a. guess starting triangle
     
    359360  // 3c. check whether all atoms lay inside the boundary, if not, add to boundary points, segment triangle into three with the new point
    360361  if (!TesselStruct->InsertStraddlingPoints(mol, LCList))
    361     Log() << Verbose(1) << "Insertion of straddling points failed!" << endl;
    362 
    363   Log() << Verbose(2) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " intermediate triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl;
     362    eLog() << Verbose(1) << "Insertion of straddling points failed!" << endl;
     363
     364  Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " intermediate triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl;
    364365
    365366  // 4. Store triangles in tecplot file
     
    411412//    Log() << Verbose(1) << "Correction of concave tesselpoints failed!" << endl;
    412413
    413   Log() << Verbose(2) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl;
     414  Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl;
    414415
    415416  // 4. Store triangles in tecplot file
     
    437438  if (BoundaryFreeFlag)
    438439    delete[] (BoundaryPoints);
    439 
    440   Log() << Verbose(1) << "End of FindConvexBorder" << endl;
    441440};
    442441
     
    450449bool RemoveAllBoundaryPoints(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename)
    451450{
     451        Info FunctionInfo(__func__);
    452452  int i=0;
    453453  char number[MAXSTRINGSIZE];
     
    460460  PointMap::iterator PointRunner;
    461461  while (!TesselStruct->PointsOnBoundary.empty()) {
    462     Log() << Verbose(2) << "Remaining points are: ";
     462    Log() << Verbose(1) << "Remaining points are: ";
    463463    for (PointMap::iterator PointSprinter = TesselStruct->PointsOnBoundary.begin(); PointSprinter != TesselStruct->PointsOnBoundary.end(); PointSprinter++)
    464       Log() << Verbose(2) << *(PointSprinter->second) << "\t";
    465     Log() << Verbose(2) << endl;
     464      Log() << Verbose(0) << *(PointSprinter->second) << "\t";
     465    Log() << Verbose(0) << endl;
    466466
    467467    PointRunner = TesselStruct->PointsOnBoundary.begin();
     
    503503double ConvexizeNonconvexEnvelope(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename)
    504504{
     505        Info FunctionInfo(__func__);
    505506  double volume = 0;
    506507  class BoundaryPointSet *point = NULL;
     
    516517  int run = 0;
    517518
    518   Log() << Verbose(0) << "Begin of ConvexizeNonconvexEnvelope" << endl;
    519 
    520519  // check whether there is something to work on
    521520  if (TesselStruct == NULL) {
     
    539538      for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    540539        line = LineRunner->second;
    541         Log() << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
     540        Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
    542541        if (!line->CheckConvexityCriterion()) {
    543542          // remove the point if needed
     
    604603
    605604  // end
    606   Log() << Verbose(1) << "Volume is " << volume << "." << endl;
    607   Log() << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl;
     605  Log() << Verbose(0) << "Volume is " << volume << "." << endl;
    608606  return volume;
    609607};
     
    619617double VolumeOfConvexEnvelope(class Tesselation *TesselStruct, class config *configuration)
    620618{
     619        Info FunctionInfo(__func__);
    621620  bool IsAngstroem = configuration->GetIsAngstroem();
    622621  double volume = 0.;
     
    625624
    626625  // 6a. Every triangle forms a pyramid with the center of gravity as its peak, sum up the volumes
    627   Log() << Verbose(1)
    628       << "Calculating the volume of the pyramids formed out of triangles and center of gravity."
    629       << endl;
    630626  for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++)
    631627    { // go through every triangle, calculate volume of its pyramid with CoG as peak
     
    642638      const double h = x.Norm(); // distance of CoG to triangle
    643639      const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
    644       Log() << Verbose(2) << "Area of triangle is " << setprecision(10) << G << " "
     640      Log() << Verbose(1) << "Area of triangle is " << setprecision(10) << G << " "
    645641          << (IsAngstroem ? "angstrom" : "atomiclength") << "^2, height is "
    646642          << h << " and the volume is " << PyramidVolume << " "
     
    664660void StoreTrianglesinFile(const molecule * const mol, const Tesselation *&TesselStruct, const char *filename, const char *extraSuffix)
    665661{
     662        Info FunctionInfo(__func__);
    666663  // 4. Store triangles in tecplot file
    667664  if (filename != NULL) {
     
    671668      OutputName.append(TecplotSuffix);
    672669      ofstream *tecplot = new ofstream(OutputName.c_str());
    673       WriteTecplotFile(tecplot, TesselStruct, mol, 0);
     670      WriteTecplotFile(tecplot, TesselStruct, mol, -1);
    674671      tecplot->close();
    675672      delete(tecplot);
     
    698695void PrepareClustersinWater(config *configuration, molecule *mol, double ClusterVolume, double celldensity)
    699696{
     697        Info FunctionInfo(__func__);
    700698  bool IsAngstroem = true;
    701699  double *GreatestDiameter = NULL;
     
    798796molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, double distance[NDIM], double RandomAtomDisplacement, double RandomMolDisplacement, bool DoRandomRotation)
    799797{
     798        Info FunctionInfo(__func__);
    800799  molecule *Filling = new molecule(filler->elemente);
    801800  Vector CurrentPosition;
     
    814813  double phi[NDIM];
    815814  class Tesselation *TesselStruct[List->ListOfMolecules.size()];
    816 
    817   Log() << Verbose(0) << "Begin of FillBoxWithMolecule" << endl;
    818815
    819816  i=0;
     
    877874          for (int i=0;i<NDIM;i++)
    878875            FillerTranslations.x[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);
    879           Log() << Verbose(3) << "INFO: Translating this filler by " << FillerTranslations << "." << endl;
     876          Log() << Verbose(2) << "INFO: Translating this filler by " << FillerTranslations << "." << endl;
    880877
    881878          // go through all atoms
     
    938935        delete(TesselStruct[i]);
    939936  }
    940   Log() << Verbose(0) << "End of FillBoxWithMolecule" << endl;
    941 
    942937  return Filling;
    943938};
     
    951946 * \param RADIUS radius of the virtual sphere
    952947 * \param *filename filename prefix for output of vertex data
    953  */
    954 void FindNonConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LCList, const double RADIUS, const char *filename = NULL)
     948 * \return true - tesselation successful, false - tesselation failed
     949 */
     950bool FindNonConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LCList, const double RADIUS, const char *filename = NULL)
    955951{
     952        Info FunctionInfo(__func__);
    956953  bool freeLC = false;
    957   LineMap::iterator baseline;
     954  bool status = false;
     955  CandidateForTesselation *baseline;
    958956  LineMap::iterator testline;
    959   bool OneLoopWithoutSuccessFlag = false;  // marks whether we went once through all baselines without finding any without two triangles
     957  bool OneLoopWithoutSuccessFlag = true;  // marks whether we went once through all baselines without finding any without two triangles
    960958  bool TesselationFailFlag = false;
    961 
    962   Log() << Verbose(1) << "Entering search for non convex hull. " << endl;
     959  BoundaryTriangleSet *T = NULL;
     960
    963961  if (TesselStruct == NULL) {
    964962    Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl;
     
    970968  }
    971969
    972   Log() << Verbose(0) << "Begin of FindNonConvexBorder\n";
    973 
    974970  // initialise Linked Cell
    975971  if (LCList == NULL) {
     
    982978
    983979  // 2. expand from there
    984   baseline = TesselStruct->LinesOnBoundary.begin();
    985   baseline++; // skip first line
    986   while ((baseline != TesselStruct->LinesOnBoundary.end()) || (OneLoopWithoutSuccessFlag)) {
    987     if (baseline->second->triangles.size() == 1) {
    988       CheckListOfBaselines(TesselStruct);
    989       // 3. find next triangle
    990       TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*(baseline->second), *(((baseline->second->triangles.begin()))->second), RADIUS, LCList); //the line is there, so there is a triangle, but only one.
    991       OneLoopWithoutSuccessFlag = OneLoopWithoutSuccessFlag || TesselationFailFlag;
    992       if (!TesselationFailFlag)
    993         eLog() << Verbose(2) << "FindNextSuitableTriangle failed." << endl;
    994 
    995       // write temporary envelope
    996       if (filename != NULL) {
    997         if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration
    998           TesselStruct->Output(filename, mol);
    999         }
     980  while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
     981    // 2a. fill all new OpenLines
     982    Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for candidates:" << endl;
     983    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
     984      Log() << Verbose(2) << *(Runner->second) << endl;
     985
     986    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
     987      baseline = Runner->second;
     988      if (baseline->pointlist.empty()) {
     989        T = (((baseline->BaseLine->triangles.begin()))->second);
     990        Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl;
     991        TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
    1000992      }
    1001       if (TesselationFailFlag) {
    1002         baseline = TesselStruct->LinesOnBoundary.begin();
    1003         OneLoopWithoutSuccessFlag = false;
    1004         Log() << Verbose(2) << "Baseline set to begin." << endl;
     993    }
     994
     995    // 2b. search for smallest ShortestAngle among all candidates
     996    double ShortestAngle = 4.*M_PI;
     997    Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl;
     998    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
     999      Log() << Verbose(2) << *(Runner->second) << endl;
     1000
     1001    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
     1002      if (Runner->second->ShortestAngle < ShortestAngle) {
     1003        baseline = Runner->second;
     1004        ShortestAngle = baseline->ShortestAngle;
     1005        //Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *baseline->point << " and angle " << baseline->ShortestAngle << endl;
    10051006      }
    1006     } else {
    1007       //Log() << Verbose(1) << "Line " << *baseline->second << " has " << baseline->second->triangles.size() << " triangles adjacent" << endl;
    1008       if (baseline->second->triangles.size() != 2) {
    1009         eLog() << Verbose(0) << "TESSELATION FINISHED WITH INVALID TRIANGLE COUNT!" << endl;
    1010         performCriticalExit();
     1007    }
     1008    if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
     1009      OneLoopWithoutSuccessFlag = false;
     1010    else {
     1011      TesselStruct->AddCandidateTriangle(*baseline);
     1012    }
     1013
     1014    // write temporary envelope
     1015    if (filename != NULL) {
     1016      if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration
     1017        TesselStruct->Output(filename, mol);
    10111018      }
    10121019    }
    1013 
    1014     if ((baseline == TesselStruct->LinesOnBoundary.end()) && (OneLoopWithoutSuccessFlag)) {
    1015       baseline = TesselStruct->LinesOnBoundary.begin();   // restart if we reach end due to newly inserted lines
    1016       OneLoopWithoutSuccessFlag = false;
    1017     }
    1018     baseline++;
    1019   }
    1020   // check envelope for consistency
    1021   CheckListOfBaselines(TesselStruct);
    1022 
    1023   // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles
    1024   //->InsertStraddlingPoints(mol, LCList);
     1020  }
     1021//  // check envelope for consistency
     1022//  status = CheckListOfBaselines(TesselStruct);
     1023//
     1024//  // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles
     1025//  //->InsertStraddlingPoints(mol, LCList);
    10251026//  mol->GoToFirst();
    10261027//  class TesselPoint *Runner = NULL;
     
    10371038//  }
    10381039
    1039   // Purges surplus triangles.
    1040   TesselStruct->RemoveDegeneratedTriangles();
     1040//  // Purges surplus triangles.
     1041//  TesselStruct->RemoveDegeneratedTriangles();
    10411042
    10421043  // check envelope for consistency
    1043   CheckListOfBaselines(TesselStruct);
     1044  status = CheckListOfBaselines(TesselStruct);
     1045
     1046  // store before correction
     1047  StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
     1048
     1049  // correct degenerated polygons
     1050  TesselStruct->CorrectAllDegeneratedPolygons();
     1051
     1052  // check envelope for consistency
     1053  status = CheckListOfBaselines(TesselStruct);
    10441054
    10451055  // write final envelope
     
    10491059  if (freeLC)
    10501060    delete(LCList);
    1051   Log() << Verbose(0) << "End of FindNonConvexBorder\n";
     1061
     1062  return status;
    10521063};
    10531064
     
    10611072Vector* FindEmbeddingHole(MoleculeListClass *mols, molecule *srcmol)
    10621073{
     1074        Info FunctionInfo(__func__);
    10631075  Vector *Center = new Vector;
    10641076  Center->Zero();
  • src/boundary.hpp

    r482373 r0b2dd2  
    3535
    3636#define DEBUG 1
    37 #define DoSingleStepOutput 1
    38 #define SingleStepWidth 1
     37#define DoSingleStepOutput 0
     38#define SingleStepWidth 10
    3939
    4040#define DistancePair pair < double, atom* >
     
    5353Vector* FindEmbeddingHole(MoleculeListClass *mols, molecule *srcmol);
    5454void FindNextSuitablePoint(class BoundaryTriangleSet *BaseTriangle, class BoundaryLineSet *BaseLine, atom*& OptCandidate, Vector *OptCandidateCenter, double *ShortestAngle, const double RADIUS, LinkedCell *LC);
    55 void FindNonConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LC, const double RADIUS, const char *tempbasename);
     55bool FindNonConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LC, const double RADIUS, const char *tempbasename);
    5656Boundaries *GetBoundaryPoints(const molecule *mol, Tesselation *&TesselStruct);
    5757double * GetDiametersOfCluster(const Boundaries *BoundaryPtr, const molecule *mol, Tesselation *&TesselStruct, const bool IsAngstroem);
  • src/builder.cpp

    r482373 r0b2dd2  
    6565#include "molecule.hpp"
    6666#include "periodentafel.hpp"
     67#include "version.h"
    6768
    6869/********************************************* Subsubmenu routine ************************************/
     
    12471248  ofstream output;
    12481249  molecule *mol = new molecule(periode);
     1250  mol->SetNameFromFilename(ConfigFileName);
    12491251
    12501252  if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
     
    13851387  int argptr;
    13861388  molecule *mol = NULL;
    1387   string BondGraphFileName("");
     1389  string BondGraphFileName("\n");
    13881390  int verbosity = 0;
    13891391  strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);
     
    15391541       mol = new molecule(periode);
    15401542       mol->ActiveFlag = true;
     1543       if (ConfigFileName != NULL)
     1544         mol->SetNameFromFilename(ConfigFileName);
    15411545       molecules->insert(mol);
     1546     }
     1547     if (configuration.BG == NULL) {
     1548       configuration.BG = new BondGraph(configuration.GetIsAngstroem());
     1549       if ((BondGraphFileName.empty()) && (configuration.BG->LoadBondLengthTable(BondGraphFileName))) {
     1550         Log() << Verbose(0) << "Bond length table loaded successfully." << endl;
     1551       } else {
     1552         eLog() << Verbose(1) << "Bond length table loading failed." << endl;
     1553       }
    15421554     }
    15431555
     
    15631575                else {
    15641576                  Log() << Verbose(2) << "File found and parsed." << endl;
     1577                  // @TODO rather do the dissection afterwards
     1578//                  mol->SetNameFromFilename(argv[argptr]);
     1579//                  molecules->ListOfMolecules.remove(mol);
     1580//                  molecules->DissectMoleculeIntoConnectedSubgraphs(mol,&configuration);
     1581//                  delete(mol);
     1582//                  if (molecules->ListOfMolecules.size() != 0) {
     1583//                    for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
     1584//                      if ((*ListRunner)->ActiveFlag) {
     1585//                        mol = *ListRunner;
     1586//                        break;
     1587//                      }
     1588//                  }
    15651589                  configPresent = present;
    15661590                }
     
    17811805                start = clock();
    17821806                LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.);
    1783                 FindNonConvexBorder(Boundary, T, LCList, atof(argv[argptr]), argv[argptr+1]);
     1807                if (!FindNonConvexBorder(Boundary, T, LCList, atof(argv[argptr]), argv[argptr+1]))
     1808                  ExitFlag = 255;
    17841809                //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str());
    17851810                end = clock();
    17861811                Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
    17871812                delete(LCList);
     1813                delete(T);
    17881814                argptr+=2;
    17891815              }
     
    21972223  int j;
    21982224
     2225  cout << ESPACKVersion << endl;
     2226
    21992227  setVerbosity(0);
    22002228
  • src/config.cpp

    r482373 r0b2dd2  
    140140void ConfigFileBuffer::MapIonTypesInBuffer(const int NoAtoms)
    141141{
    142   map<const char *, int, IonTypeCompare> LineList;
     142  map<const char *, int, IonTypeCompare> IonTypeLineMap;
    143143  if (LineMapping == NULL) {
    144144    eLog() << Verbose(0) << "map pointer is NULL: " << LineMapping << endl;
     
    149149  // put all into hashed map
    150150  for (int i=0; i<NoAtoms; ++i) {
    151     LineList.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
     151    IonTypeLineMap.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
    152152  }
    153153
    154154  // fill map
    155155  int nr=0;
    156   for (map<const char *, int, IonTypeCompare>::iterator runner = LineList.begin(); runner != LineList.end(); ++runner) {
     156  for (map<const char *, int, IonTypeCompare>::iterator runner = IonTypeLineMap.begin(); runner != IonTypeLineMap.end(); ++runner) {
    157157    if (CurrentLine+nr < NoLines)
    158158      LineMapping[CurrentLine+(nr++)] = runner->second;
     
    10561056
    10571057  // 2. parse the bond graph file if given
    1058   BG = new BondGraph(IsAngstroem);
    1059   if (BG->LoadBondLengthTable(BondGraphFileName)) {
    1060     Log() << Verbose(0) << "Bond length table loaded successfully." << endl;
    1061   } else {
    1062     Log() << Verbose(0) << "Bond length table loading failed." << endl;
     1058  if (BG == NULL) {
     1059    BG = new BondGraph(IsAngstroem);
     1060    if (BG->LoadBondLengthTable(BondGraphFileName)) {
     1061      Log() << Verbose(0) << "Bond length table loaded successfully." << endl;
     1062    } else {
     1063      eLog() << Verbose(1) << "Bond length table loading failed." << endl;
     1064    }
    10631065  }
    10641066
    10651067  // 3. parse the molecule in
    10661068  LoadMolecule(mol, FileBuffer, periode, FastParsing);
     1069  mol->SetNameFromFilename(filename);
    10671070  mol->ActiveFlag = true;
     1071  MolList->insert(mol);
    10681072
    10691073  // 4. dissect the molecule into connected subgraphs
    1070   MolList->DissectMoleculeIntoConnectedSubgraphs(mol,this);
    1071 
    1072   delete(mol);
     1074  // don't do this here ...
     1075  //MolList->DissectMoleculeIntoConnectedSubgraphs(mol,this);
     1076  //delete(mol);
     1077
    10731078  delete(FileBuffer);
    10741079};
  • src/errorlogger.cpp

    r482373 r0b2dd2  
    8282  l.nix->clear();
    8383  if (v.DoOutput(verbosityLevel)) {
    84     v.print(cout);
    8584    switch(v.Verbosity) {
    8685      case 0:
    87         cout << "CRITICAL: ";
     86        cerr << "CRITICAL: ";
    8887        break;
    8988      case 1:
    90         cout << "ERROR: ";
     89        cerr << "ERROR: ";
    9190        break;
    9291      case 2:
    93         cout << "WARNING: ";
     92        cerr << "WARNING: ";
    9493        break;
    9594      default:
    9695        break;
    9796    }
     97    v.print(cerr);
    9898    return cerr;
    9999  } else
     
    105105  l->nix->clear();
    106106  if (v.DoOutput(verbosityLevel)) {
    107     v.print(cout);
    108107    switch(v.Verbosity) {
    109108      case 0:
    110         cout << "CRITICAL: ";
     109        cerr << "CRITICAL: ";
    111110        break;
    112111      case 1:
    113         cout << "ERROR: ";
     112        cerr << "ERROR: ";
    114113        break;
    115114      case 2:
    116         cout << "WARNING: ";
     115        cerr << "WARNING: ";
    117116        break;
    118117      default:
    119118        break;
    120119    }
     120    v.print(cerr);
    121121    return cerr;
    122122  } else
  • src/molecule.hpp

    r482373 r0b2dd2  
    106106
    107107  // re-definition of virtual functions from PointCloud
     108  const char * const GetName() const;
    108109  Vector *GetCenter() const ;
    109110  TesselPoint *GetPoint() const ;
  • src/molecule_pointcloud.cpp

    r482373 r0b2dd2  
    1313/************************************* Functions for class molecule *********************************/
    1414
     15/** Returns a name for this point cloud, here the molecule's name.
     16 * \return name of point cloud
     17 */
     18const char * const molecule::GetName() const
     19{
     20  return name;
     21};
    1522
    1623/** Determine center of all atoms.
  • src/moleculelist.cpp

    r482373 r0b2dd2  
    759759  // 4a. create array of molecules to fill
    760760  const int MolCount = Subgraphs->next->Count();
     761  char number[MAXSTRINGSIZE];
    761762  molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules");
    762763  for (int i=0;i<MolCount;i++) {
    763764    molecules[i] = (molecule*) new molecule(mol->elemente);
    764765    molecules[i]->ActiveFlag = true;
     766    strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE);
     767    if (MolCount > 1) {
     768      sprintf(number, "-%d", i+1);
     769      strncat(molecules[i]->name, number, MAXSTRINGSIZE - strlen(mol->name) - 1);
     770    }
     771    cout << "MolName is " << molecules[i]->name << endl;
    765772    insert(molecules[i]);
    766773  }
     
    799806    }
    800807  }
    801   // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintained their ListOfBonds, but we have to remove them from first..last list
     808  // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintain their ListOfBonds, but we have to remove them from first..last list
    802809  bond *Binder = mol->first;
    803810  while (mol->first->next != mol->last) {
  • src/parser.cpp

    r482373 r0b2dd2  
    158158  //Log() << Verbose(0) << "Opening " << name << " ... "  << input << endl;
    159159  if (input == NULL) {
    160     eLog() << Verbose(0) << endl << "Unable to open " << name << ", is the directory correct?" << endl;
    161     performCriticalExit();
     160    eLog() << Verbose(1) << endl << "Unable to open " << name << ", is the directory correct?" << endl;
     161    //performCriticalExit();
    162162    return false;
    163163  }
  • src/tesselation.cpp

    r482373 r0b2dd2  
    99
    1010#include "helpers.hpp"
     11#include "info.hpp"
    1112#include "linkedcell.hpp"
    1213#include "log.hpp"
     
    2223/** Constructor of BoundaryPointSet.
    2324 */
    24 BoundaryPointSet::BoundaryPointSet()
    25 {
    26   LinesCount = 0;
    27   Nr = -1;
    28   value = 0.;
     25BoundaryPointSet::BoundaryPointSet() :
     26    LinesCount(0),
     27    value(0.),
     28    Nr(-1)
     29{
     30        Info FunctionInfo(__func__);
     31        Log() << Verbose(1) << "Adding noname." << endl;
    2932};
    3033
     
    3235 * \param *Walker TesselPoint this boundary point represents
    3336 */
    34 BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker)
    35 {
    36   node = Walker;
    37   LinesCount = 0;
    38   Nr = Walker->nr;
    39   value = 0.;
     37BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker) :
     38  LinesCount(0),
     39  node(Walker),
     40  value(0.),
     41  Nr(Walker->nr)
     42{
     43        Info FunctionInfo(__func__);
     44  Log() << Verbose(1) << "Adding Node " << *Walker << endl;
    4045};
    4146
     
    4651BoundaryPointSet::~BoundaryPointSet()
    4752{
    48   //Log() << Verbose(5) << "Erasing point nr. " << Nr << "." << endl;
     53        Info FunctionInfo(__func__);
     54  //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
    4955  if (!lines.empty())
    5056    eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl;
     
    5763void BoundaryPointSet::AddLine(class BoundaryLineSet *line)
    5864{
    59   Log() << Verbose(6) << "Adding " << *this << " to line " << *line << "."
     65        Info FunctionInfo(__func__);
     66  Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "."
    6067      << endl;
    6168  if (line->endpoints[0] == this)
     
    8592/** Constructor of BoundaryLineSet.
    8693 */
    87 BoundaryLineSet::BoundaryLineSet()
    88 {
     94BoundaryLineSet::BoundaryLineSet() :
     95    Nr(-1)
     96{
     97        Info FunctionInfo(__func__);
    8998  for (int i = 0; i < 2; i++)
    9099    endpoints[i] = NULL;
    91   Nr = -1;
    92100};
    93101
     
    99107BoundaryLineSet::BoundaryLineSet(class BoundaryPointSet *Point[2], const int number)
    100108{
     109        Info FunctionInfo(__func__);
    101110  // set number
    102111  Nr = number;
     
    106115  Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
    107116  Point[1]->AddLine(this); //
     117  // set skipped to false
     118  skipped = false;
    108119  // clear triangles list
    109   Log() << Verbose(5) << "New Line with endpoints " << *this << "." << endl;
     120  Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
    110121};
    111122
     
    116127BoundaryLineSet::~BoundaryLineSet()
    117128{
     129        Info FunctionInfo(__func__);
    118130  int Numbers[2];
    119131
     
    134146        for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
    135147          if ((*Runner).second == this) {
    136             //Log() << Verbose(5) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
     148            //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
    137149            endpoints[i]->lines.erase(Runner);
    138150            break;
     
    140152      } else { // there's just a single line left
    141153        if (endpoints[i]->lines.erase(Nr)) {
    142           //Log() << Verbose(5) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
     154          //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
    143155        }
    144156      }
    145157      if (endpoints[i]->lines.empty()) {
    146         //Log() << Verbose(5) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
     158        //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
    147159        if (endpoints[i] != NULL) {
    148160          delete(endpoints[i]);
     
    161173void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
    162174{
    163   Log() << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
     175        Info FunctionInfo(__func__);
     176  Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
    164177  triangles.insert(TrianglePair(triangle->Nr, triangle));
    165178};
     
    171184bool BoundaryLineSet::IsConnectedTo(class BoundaryLineSet *line)
    172185{
     186        Info FunctionInfo(__func__);
    173187  if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
    174188    return true;
     
    185199bool BoundaryLineSet::CheckConvexityCriterion()
    186200{
     201        Info FunctionInfo(__func__);
    187202  Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
    188203  // get the two triangles
    189204  if (triangles.size() != 2) {
    190     eLog() << Verbose(1) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
     205    eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
    191206    return true;
    192207  }
    193208  // check normal vectors
    194209  // have a normal vector on the base line pointing outwards
    195   //Log() << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
     210  //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
    196211  BaseLineCenter.CopyVector(endpoints[0]->node->node);
    197212  BaseLineCenter.AddVector(endpoints[1]->node->node);
     
    199214  BaseLine.CopyVector(endpoints[0]->node->node);
    200215  BaseLine.SubtractVector(endpoints[1]->node->node);
    201   //Log() << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
     216  //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
    202217
    203218  BaseLineNormal.Zero();
     
    207222  class BoundaryPointSet *node = NULL;
    208223  for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    209     //Log() << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
     224    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    210225    NormalCheck.AddVector(&runner->second->NormalVector);
    211226    NormalCheck.Scale(sign);
     
    214229      BaseLineNormal.CopyVector(&runner->second->NormalVector);   // yes, copy second on top of first
    215230    else {
    216       Log() << Verbose(1) << "CRITICAL: Triangle " << *runner->second << " has zero normal vector!" << endl;
    217       exit(255);
     231      eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl;
    218232    }
    219233    node = runner->second->GetThirdEndpoint(this);
    220234    if (node != NULL) {
    221       //Log() << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
     235      //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    222236      helper[i].CopyVector(node->node->node);
    223237      helper[i].SubtractVector(&BaseLineCenter);
    224238      helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
    225       //Log() << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
     239      //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    226240      i++;
    227241    } else {
    228       //eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;
     242      eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;
    229243      return true;
    230244    }
    231245  }
    232   //Log() << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
     246  //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
    233247  if (NormalCheck.NormSquared() < MYEPSILON) {
    234     Log() << Verbose(3) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
     248    Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
    235249    return true;
    236250  }
     
    238252  double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    239253  if ((angle - M_PI) > -MYEPSILON) {
    240     Log() << Verbose(3) << "ACCEPT: Angle is greater than pi: convex." << endl;
     254    Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl;
    241255    return true;
    242256  } else {
    243     Log() << Verbose(3) << "REJECT: Angle is less than pi: concave." << endl;
     257    Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl;
    244258    return false;
    245259  }
     
    252266bool BoundaryLineSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
    253267{
     268        Info FunctionInfo(__func__);
    254269  for(int i=0;i<2;i++)
    255270    if (point == endpoints[i])
     
    264279class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(class BoundaryPointSet *point)
    265280{
     281        Info FunctionInfo(__func__);
    266282  if (endpoints[0] == point)
    267283    return endpoints[1];
     
    286302/** Constructor for BoundaryTriangleSet.
    287303 */
    288 BoundaryTriangleSet::BoundaryTriangleSet()
    289 {
     304BoundaryTriangleSet::BoundaryTriangleSet() :
     305  Nr(-1)
     306{
     307        Info FunctionInfo(__func__);
    290308  for (int i = 0; i < 3; i++)
    291309    {
     
    293311      lines[i] = NULL;
    294312    }
    295   Nr = -1;
    296313};
    297314
     
    300317 * \param number number of triangle
    301318 */
    302 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number)
    303 {
     319BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number) :
     320  Nr(number)
     321{
     322        Info FunctionInfo(__func__);
    304323  // set number
    305   Nr = number;
    306324  // set lines
    307   Log() << Verbose(5) << "New triangle " << Nr << ":" << endl;
    308   for (int i = 0; i < 3; i++)
    309     {
    310       lines[i] = line[i];
    311       lines[i]->AddTriangle(this);
    312     }
     325  for (int i = 0; i < 3; i++) {
     326    lines[i] = line[i];
     327    lines[i]->AddTriangle(this);
     328  }
    313329  // get ascending order of endpoints
    314   map<int, class BoundaryPointSet *> OrderMap;
     330  PointMap OrderMap;
    315331  for (int i = 0; i < 3; i++)
    316332    // for all three lines
    317     for (int j = 0; j < 2; j++)
    318       { // for both endpoints
    319         OrderMap.insert(pair<int, class BoundaryPointSet *> (
    320             line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
    321         // and we don't care whether insertion fails
    322       }
     333    for (int j = 0; j < 2; j++) { // for both endpoints
     334      OrderMap.insert(pair<int, class BoundaryPointSet *> (
     335          line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
     336      // and we don't care whether insertion fails
     337    }
    323338  // set endpoints
    324339  int Counter = 0;
    325   Log() << Verbose(6) << " with end points ";
    326   for (map<int, class BoundaryPointSet *>::iterator runner = OrderMap.begin(); runner
    327       != OrderMap.end(); runner++)
    328     {
    329       endpoints[Counter] = runner->second;
    330       Log() << Verbose(0) << " " << *endpoints[Counter];
    331       Counter++;
    332     }
    333   if (Counter < 3)
    334     {
    335       eLog() << Verbose(0) << "ERROR! We have a triangle with only two distinct endpoints!" << endl;
    336       performCriticalExit();
    337     }
    338   Log() << Verbose(0) << "." << endl;
     340  Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl;
     341  for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
     342    endpoints[Counter] = runner->second;
     343    Log() << Verbose(0) << " " << *endpoints[Counter] << endl;
     344    Counter++;
     345  }
     346  if (Counter < 3) {
     347    eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl;
     348    performCriticalExit();
     349  }
    339350};
    340351
     
    345356BoundaryTriangleSet::~BoundaryTriangleSet()
    346357{
     358        Info FunctionInfo(__func__);
    347359  for (int i = 0; i < 3; i++) {
    348360    if (lines[i] != NULL) {
    349361      if (lines[i]->triangles.erase(Nr)) {
    350         //Log() << Verbose(5) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
     362        //Log() << Verbose(0) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
    351363      }
    352364      if (lines[i]->triangles.empty()) {
    353           //Log() << Verbose(5) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
     365          //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
    354366          delete (lines[i]);
    355367          lines[i] = NULL;
     
    357369    }
    358370  }
    359   //Log() << Verbose(5) << "Erasing triangle Nr." << Nr << " itself." << endl;
     371  //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
    360372};
    361373
     
    366378void BoundaryTriangleSet::GetNormalVector(Vector &OtherVector)
    367379{
     380        Info FunctionInfo(__func__);
    368381  // get normal vector
    369382  NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     
    372385  if (NormalVector.ScalarProduct(&OtherVector) > 0.)
    373386    NormalVector.Scale(-1.);
     387  Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl;
    374388};
    375389
     
    388402bool BoundaryTriangleSet::GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection)
    389403{
     404        Info FunctionInfo(__func__);
    390405  Vector CrossPoint;
    391406  Vector helper;
    392407
    393408  if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
    394     Log() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
     409    eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
    395410    return false;
    396411  }
     
    408423  } while (CrossPoint.NormSquared() < MYEPSILON);
    409424  if (i==3) {
    410     eLog() << Verbose(1) << "Could not find any cross points, something's utterly wrong here!" << endl;
    411     exit(255);
     425    eLog() << Verbose(0) << "Could not find any cross points, something's utterly wrong here!" << endl;
    412426  }
    413427  CrossPoint.SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     
    428442bool BoundaryTriangleSet::ContainsBoundaryLine(class BoundaryLineSet *line)
    429443{
     444        Info FunctionInfo(__func__);
    430445  for(int i=0;i<3;i++)
    431446    if (line == lines[i])
     
    440455bool BoundaryTriangleSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
    441456{
     457        Info FunctionInfo(__func__);
    442458  for(int i=0;i<3;i++)
    443459    if (point == endpoints[i])
     
    452468bool BoundaryTriangleSet::ContainsBoundaryPoint(class TesselPoint *point)
    453469{
     470        Info FunctionInfo(__func__);
    454471  for(int i=0;i<3;i++)
    455472    if (point == endpoints[i]->node)
     
    464481bool BoundaryTriangleSet::IsPresentTupel(class BoundaryPointSet *Points[3])
    465482{
     483        Info FunctionInfo(__func__);
    466484  return (((endpoints[0] == Points[0])
    467485            || (endpoints[0] == Points[1])
     
    485503bool BoundaryTriangleSet::IsPresentTupel(class BoundaryTriangleSet *T)
    486504{
     505        Info FunctionInfo(__func__);
    487506  return (((endpoints[0] == T->endpoints[0])
    488507            || (endpoints[0] == T->endpoints[1])
     
    506525class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(class BoundaryLineSet *line)
    507526{
     527        Info FunctionInfo(__func__);
    508528  // sanity check
    509529  if (!ContainsBoundaryLine(line))
     
    522542void BoundaryTriangleSet::GetCenter(Vector *center)
    523543{
     544        Info FunctionInfo(__func__);
    524545  center->Zero();
    525546  for(int i=0;i<3;i++)
     
    534555ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
    535556{
    536   ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
    537       << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
     557  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]";
     558//  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
     559//      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
    538560  return ost;
    539561};
    540562
     563// ======================================== Polygons on Boundary =================================
     564
     565/** Constructor for BoundaryPolygonSet.
     566 */
     567BoundaryPolygonSet::BoundaryPolygonSet() :
     568  Nr(-1)
     569{
     570  Info FunctionInfo(__func__);
     571};
     572
     573/** Destructor of BoundaryPolygonSet.
     574 * Just clears endpoints.
     575 * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
     576 */
     577BoundaryPolygonSet::~BoundaryPolygonSet()
     578{
     579  Info FunctionInfo(__func__);
     580  endpoints.clear();
     581  Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl;
     582};
     583
     584/** Calculates the normal vector for this triangle.
     585 * Is made unique by comparison with \a OtherVector to point in the other direction.
     586 * \param &OtherVector direction vector to make normal vector unique.
     587 * \return allocated vector in normal direction
     588 */
     589Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
     590{
     591  Info FunctionInfo(__func__);
     592  // get normal vector
     593  Vector TemporaryNormal;
     594  Vector *TotalNormal = new Vector;
     595  PointSet::const_iterator Runner[3];
     596  for (int i=0;i<3; i++) {
     597    Runner[i] = endpoints.begin();
     598    for (int j = 0; j<i; j++) { // go as much further
     599      Runner[i]++;
     600      if (Runner[i] == endpoints.end()) {
     601        eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl;
     602        performCriticalExit();
     603      }
     604    }
     605  }
     606  TotalNormal->Zero();
     607  int counter=0;
     608  for (; Runner[2] != endpoints.end(); ) {
     609    TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
     610    for (int i=0;i<3;i++) // increase each of them
     611      Runner[i]++;
     612    TotalNormal->AddVector(&TemporaryNormal);
     613  }
     614  TotalNormal->Scale(1./(double)counter);
     615
     616  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
     617  if (TotalNormal->ScalarProduct(&OtherVector) > 0.)
     618    TotalNormal->Scale(-1.);
     619  Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl;
     620
     621  return TotalNormal;
     622};
     623
     624/** Calculates the center point of the triangle.
     625 * Is third of the sum of all endpoints.
     626 * \param *center central point on return.
     627 */
     628void BoundaryPolygonSet::GetCenter(Vector * const center) const
     629{
     630  Info FunctionInfo(__func__);
     631  center->Zero();
     632  int counter = 0;
     633  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     634    center->AddVector((*Runner)->node->node);
     635    counter++;
     636  }
     637  center->Scale(1./(double)counter);
     638  Log() << Verbose(1) << "Center is at " << *center << "." << endl;
     639}
     640
     641/** Checks whether the polygons contains all three endpoints of the triangle.
     642 * \param *triangle triangle to test
     643 * \return true - triangle is contained polygon, false - is not
     644 */
     645bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
     646{
     647  Info FunctionInfo(__func__);
     648  return ContainsPresentTupel(triangle->endpoints, 3);
     649};
     650
     651/** Checks whether the polygons contains both endpoints of the line.
     652 * \param *line line to test
     653 * \return true - line is of the triangle, false - is not
     654 */
     655bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
     656{
     657  Info FunctionInfo(__func__);
     658  return ContainsPresentTupel(line->endpoints, 2);
     659};
     660
     661/** Checks whether point is any of the three endpoints this triangle contains.
     662 * \param *point point to test
     663 * \return true - point is of the triangle, false - is not
     664 */
     665bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
     666{
     667  Info FunctionInfo(__func__);
     668  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     669    Log() << Verbose(0) << "Checking against " << **Runner << endl;
     670    if (point == (*Runner)) {
     671      Log() << Verbose(0) << " Contained." << endl;
     672      return true;
     673    }
     674  }
     675  Log() << Verbose(0) << " Not contained." << endl;
     676  return false;
     677};
     678
     679/** Checks whether point is any of the three endpoints this triangle contains.
     680 * \param *point TesselPoint to test
     681 * \return true - point is of the triangle, false - is not
     682 */
     683bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
     684{
     685  Info FunctionInfo(__func__);
     686  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     687    if (point == (*Runner)->node) {
     688      Log() << Verbose(0) << " Contained." << endl;
     689      return true;
     690    }
     691  Log() << Verbose(0) << " Not contained." << endl;
     692  return false;
     693};
     694
     695/** Checks whether given array of \a *Points coincide with polygons's endpoints.
     696 * \param **Points pointer to an array of BoundaryPointSet
     697 * \param dim dimension of array
     698 * \return true - set of points is contained in polygon, false - is not
     699 */
     700bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
     701{
     702  Info FunctionInfo(__func__);
     703  int counter = 0;
     704  Log() << Verbose(1) << "Polygon is " << *this << endl;
     705  for(int i=0;i<dim;i++) {
     706    Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl;
     707    if (ContainsBoundaryPoint(Points[i])) {
     708      counter++;
     709    }
     710  }
     711
     712  if (counter == dim)
     713    return true;
     714  else
     715    return false;
     716};
     717
     718/** Checks whether given PointList coincide with polygons's endpoints.
     719 * \param &endpoints PointList
     720 * \return true - set of points is contained in polygon, false - is not
     721 */
     722bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
     723{
     724  Info FunctionInfo(__func__);
     725  size_t counter = 0;
     726  Log() << Verbose(1) << "Polygon is " << *this << endl;
     727  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     728    Log() << Verbose(1) << " Testing endpoint " << **Runner << endl;
     729    if (ContainsBoundaryPoint(*Runner))
     730      counter++;
     731  }
     732
     733  if (counter == endpoints.size())
     734    return true;
     735  else
     736    return false;
     737};
     738
     739/** Checks whether given set of \a *Points coincide with polygons's endpoints.
     740 * \param *P pointer to BoundaryPolygonSet
     741 * \return true - is the very triangle, false - is not
     742 */
     743bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
     744{
     745  return ContainsPresentTupel((const PointSet)P->endpoints);
     746};
     747
     748/** Gathers all the endpoints' triangles in a unique set.
     749 * \return set of all triangles
     750 */
     751TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
     752{
     753  Info FunctionInfo(__func__);
     754  pair <TriangleSet::iterator, bool> Tester;
     755  TriangleSet *triangles = new TriangleSet;
     756
     757  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     758    for(LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
     759      for(TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
     760        //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
     761        if (ContainsBoundaryTriangle(Sprinter->second)) {
     762          Tester = triangles->insert(Sprinter->second);
     763          if (Tester.second)
     764            Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl;
     765        }
     766      }
     767
     768  Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl;
     769  return triangles;
     770};
     771
     772/** Fills the endpoints of this polygon from the triangles attached to \a *line.
     773 * \param *line lines with triangles attached
     774 * \return true - polygon contains endpoints, false - line was NULL
     775 */
     776bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
     777{
     778  Info FunctionInfo(__func__);
     779  pair <PointSet::iterator, bool> Tester;
     780  if (line == NULL)
     781    return false;
     782  Log() << Verbose(1) << "Filling polygon from line " << *line << endl;
     783  for(TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
     784    for (int i=0;i<3;i++) {
     785      Tester = endpoints.insert((Runner->second)->endpoints[i]);
     786      if (Tester.second)
     787        Log() << Verbose(1) << "  Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl;
     788    }
     789  }
     790
     791  return true;
     792};
     793
     794/** output operator for BoundaryPolygonSet.
     795 * \param &ost output stream
     796 * \param &a boundary polygon
     797 */
     798ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
     799{
     800  ost << "[" << a.Nr << "|";
     801  for(PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
     802   ost << (*Runner)->node->Name;
     803   Runner++;
     804   if (Runner != a.endpoints.end())
     805     ost << ",";
     806  }
     807  ost<< "]";
     808  return ost;
     809};
     810
    541811// =========================================================== class TESSELPOINT ===========================================
    542812
     
    545815TesselPoint::TesselPoint()
    546816{
     817  Info FunctionInfo(__func__);
    547818  node = NULL;
    548819  nr = -1;
     
    554825TesselPoint::~TesselPoint()
    555826{
     827  Info FunctionInfo(__func__);
    556828};
    557829
     
    568840ostream & TesselPoint::operator << (ostream &ost)
    569841{
    570   ost << "[" << (Name) << "|" << this << "]";
     842        Info FunctionInfo(__func__);
     843  ost << "[" << (nr) << "|" << this << "]";
    571844  return ost;
    572845};
     
    579852PointCloud::PointCloud()
    580853{
    581 
     854        Info FunctionInfo(__func__);
    582855};
    583856
     
    586859PointCloud::~PointCloud()
    587860{
    588 
     861        Info FunctionInfo(__func__);
    589862};
    590863
     
    593866/** Constructor of class CandidateForTesselation.
    594867 */
    595 CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) {
    596   point = candidate;
    597   BaseLine = line;
     868CandidateForTesselation::CandidateForTesselation (BoundaryLineSet* line) :
     869  BaseLine(line),
     870  ShortestAngle(2.*M_PI),
     871  OtherShortestAngle(2.*M_PI)
     872{
     873        Info FunctionInfo(__func__);
     874};
     875
     876
     877/** Constructor of class CandidateForTesselation.
     878 */
     879CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
     880    BaseLine(line),
     881    IsDegenerated(false),
     882    ShortestAngle(2.*M_PI),
     883    OtherShortestAngle(2.*M_PI)
     884{
     885        Info FunctionInfo(__func__);
    598886  OptCenter.CopyVector(&OptCandidateCenter);
    599887  OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
     
    603891 */
    604892CandidateForTesselation::~CandidateForTesselation() {
    605   point = NULL;
    606893  BaseLine = NULL;
    607894};
    608895
     896/** output operator for CandidateForTesselation.
     897 * \param &ost output stream
     898 * \param &a boundary line
     899 */
     900ostream & operator <<(ostream &ost, const  CandidateForTesselation &a)
     901{
     902  ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with ";
     903  if (a.pointlist.empty())
     904    ost << "no candidate.";
     905  else {
     906    ost << "candidate";
     907    if (a.pointlist.size() != 1)
     908      ost << "s ";
     909    else
     910      ost << " ";
     911    for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
     912      ost << *(*Runner) << " ";
     913    ost << " at angle " << (a.ShortestAngle)<< ".";
     914  }
     915
     916  return ost;
     917};
     918
     919
    609920// =========================================================== class TESSELATION ===========================================
    610921
    611922/** Constructor of class Tesselation.
    612923 */
    613 Tesselation::Tesselation()
    614 {
    615   PointsOnBoundaryCount = 0;
    616   LinesOnBoundaryCount = 0;
    617   TrianglesOnBoundaryCount = 0;
    618   InternalPointer = PointsOnBoundary.begin();
    619   LastTriangle = NULL;
    620   TriangleFilesWritten = 0;
     924Tesselation::Tesselation() :
     925  PointsOnBoundaryCount(0),
     926  LinesOnBoundaryCount(0),
     927  TrianglesOnBoundaryCount(0),
     928  LastTriangle(NULL),
     929  TriangleFilesWritten(0),
     930  InternalPointer(PointsOnBoundary.begin())
     931{
     932        Info FunctionInfo(__func__);
    621933}
    622934;
     
    627939Tesselation::~Tesselation()
    628940{
    629   Log() << Verbose(1) << "Free'ing TesselStruct ... " << endl;
     941        Info FunctionInfo(__func__);
     942  Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl;
    630943  for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
    631944    if (runner->second != NULL) {
     
    635948      eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl;
    636949  }
    637   Log() << Verbose(1) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
     950  Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
    638951}
    639952;
     
    644957Vector * Tesselation::GetCenter(ofstream *out) const
    645958{
     959        Info FunctionInfo(__func__);
    646960  Vector *Center = new Vector(0.,0.,0.);
    647961  int num=0;
     
    659973TesselPoint * Tesselation::GetPoint() const
    660974{
     975        Info FunctionInfo(__func__);
    661976  return (InternalPointer->second->node);
    662977};
     
    667982TesselPoint * Tesselation::GetTerminalPoint() const
    668983{
     984        Info FunctionInfo(__func__);
    669985  PointMap::const_iterator Runner = PointsOnBoundary.end();
    670986  Runner--;
     
    677993void Tesselation::GoToNext() const
    678994{
     995        Info FunctionInfo(__func__);
    679996  if (InternalPointer != PointsOnBoundary.end())
    680997    InternalPointer++;
     
    6861003void Tesselation::GoToPrevious() const
    6871004{
     1005        Info FunctionInfo(__func__);
    6881006  if (InternalPointer != PointsOnBoundary.begin())
    6891007    InternalPointer--;
     
    6951013void Tesselation::GoToFirst() const
    6961014{
     1015        Info FunctionInfo(__func__);
    6971016  InternalPointer = PointsOnBoundary.begin();
    6981017};
     
    7031022void Tesselation::GoToLast() const
    7041023{
     1024        Info FunctionInfo(__func__);
    7051025  InternalPointer = PointsOnBoundary.end();
    7061026  InternalPointer--;
     
    7121032bool Tesselation::IsEmpty() const
    7131033{
     1034        Info FunctionInfo(__func__);
    7141035  return (PointsOnBoundary.empty());
    7151036};
     
    7201041bool Tesselation::IsEnd() const
    7211042{
     1043        Info FunctionInfo(__func__);
    7221044  return (InternalPointer == PointsOnBoundary.end());
    7231045};
     
    7321054Tesselation::GuessStartingTriangle()
    7331055{
     1056        Info FunctionInfo(__func__);
    7341057  // 4b. create a starting triangle
    7351058  // 4b1. create all distances
     
    7781101          baseline->second.first->second->node->node,
    7791102          baseline->second.second->second->node->node);
    780       Log() << Verbose(2) << "Plane vector of candidate triangle is ";
    781       PlaneVector.Output();
    782       Log() << Verbose(0) << endl;
     1103      Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl;
    7831104      // 4. loop over all points
    7841105      double sign = 0.;
     
    7961117          if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    7971118            continue;
    798           Log() << Verbose(3) << "Projection of " << checker->second->node->Name
    799               << " yields distance of " << distance << "." << endl;
     1119          Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl;
    8001120          tmp = distance / fabs(distance);
    8011121          // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
     
    8501170      if (checker == PointsOnBoundary.end())
    8511171        {
    852           Log() << Verbose(0) << "Looks like we have a candidate!" << endl;
     1172          Log() << Verbose(2) << "Looks like we have a candidate!" << endl;
    8531173          break;
    8541174        }
     
    8801200  else
    8811201    {
    882       Log() << Verbose(1) << "No starting triangle found." << endl;
    883       exit(255);
     1202      eLog() << Verbose(0) << "No starting triangle found." << endl;
    8841203    }
    8851204}
     
    9011220void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
    9021221{
     1222        Info FunctionInfo(__func__);
    9031223  bool flag;
    9041224  PointMap::iterator winner;
     
    9191239        // get peak point with respect to this base line's only triangle
    9201240        BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
    921         Log() << Verbose(2) << "Current baseline is between " << *(baseline->second) << "." << endl;
     1241        Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl;
    9221242        for (int i = 0; i < 3; i++)
    9231243          if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
    9241244            peak = BTS->endpoints[i];
    925         Log() << Verbose(3) << " and has peak " << *peak << "." << endl;
     1245        Log() << Verbose(1) << " and has peak " << *peak << "." << endl;
    9261246
    9271247        // prepare some auxiliary vectors
     
    9381258          CenterVector.AddVector(BTS->endpoints[i]->node->node);
    9391259        CenterVector.Scale(1. / 3.);
    940         Log() << Verbose(4) << "CenterVector of base triangle is " << CenterVector << endl;
     1260        Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl;
    9411261
    9421262        // normal vector of triangle
     
    9451265        BTS->GetNormalVector(NormalVector);
    9461266        NormalVector.CopyVector(&BTS->NormalVector);
    947         Log() << Verbose(4) << "NormalVector of base triangle is " << NormalVector << endl;
     1267        Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl;
    9481268
    9491269        // vector in propagation direction (out of triangle)
     
    9521272        TempVector.CopyVector(&CenterVector);
    9531273        TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    954         //Log() << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
     1274        //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    9551275        if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
    9561276          PropagationVector.Scale(-1.);
    957         Log() << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl;
     1277        Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl;
    9581278        winner = PointsOnBoundary.end();
    9591279
     
    9611281        for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
    9621282          if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
    963             Log() << Verbose(3) << "Target point is " << *(target->second) << ":" << endl;
     1283            Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl;
    9641284
    9651285            // first check direction, so that triangles don't intersect
     
    9681288            VirtualNormalVector.ProjectOntoPlane(&NormalVector);
    9691289            TempAngle = VirtualNormalVector.Angle(&PropagationVector);
    970             Log() << Verbose(4) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
     1290            Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
    9711291            if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees)
    972               Log() << Verbose(4) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
     1292              Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
    9731293              continue;
    9741294            } else
    975               Log() << Verbose(4) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
     1295              Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
    9761296
    9771297            // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
     
    9791299            LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
    9801300            if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
    981               Log() << Verbose(4) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl;
     1301              Log() << Verbose(2) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl;
    9821302              continue;
    9831303            }
    9841304            if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
    985               Log() << Verbose(4) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl;
     1305              Log() << Verbose(2) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl;
    9861306              continue;
    9871307            }
     
    10001320            helper.ProjectOntoPlane(&TempVector);
    10011321            if (fabs(helper.NormSquared()) < MYEPSILON) {
    1002               Log() << Verbose(4) << "Chosen set of vectors is linear dependent." << endl;
     1322              Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl;
    10031323              continue;
    10041324            }
     
    10171337            // calculate angle
    10181338            TempAngle = NormalVector.Angle(&VirtualNormalVector);
    1019             Log() << Verbose(4) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
     1339            Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
    10201340            if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
    10211341              SmallestAngle = TempAngle;
    10221342              winner = target;
    1023               Log() << Verbose(4) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1343              Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
    10241344            } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
    10251345              // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
     
    10391359                SmallestAngle = TempAngle;
    10401360                winner = target;
    1041                 Log() << Verbose(4) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
     1361                Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
    10421362              } else
    1043                 Log() << Verbose(4) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
     1363                Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
    10441364            } else
    1045               Log() << Verbose(4) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1365              Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
    10461366          }
    10471367        } // end of loop over all boundary points
     
    10491369        // 5b. The point of the above whose triangle has the greatest angle with the triangle the current line belongs to (it only belongs to one, remember!): New triangle
    10501370        if (winner != PointsOnBoundary.end()) {
    1051           Log() << Verbose(2) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
     1371          Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
    10521372          // create the lins of not yet present
    10531373          BLS[0] = baseline->second;
     
    10791399          TrianglesOnBoundaryCount++;
    10801400        } else {
    1081           Log() << Verbose(1) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
     1401          eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
    10821402        }
    10831403
    10841404        // 5d. If the set of lines is not yet empty, go to 5. and continue
    10851405      } else
    1086         Log() << Verbose(2) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
     1406        Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
    10871407  } while (flag);
    10881408
     
    10991419bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
    11001420{
     1421        Info FunctionInfo(__func__);
    11011422  Vector Intersection, Normal;
    11021423  TesselPoint *Walker = NULL;
     
    11051426  bool AddFlag = false;
    11061427  LinkedCell *BoundaryPoints = NULL;
    1107 
    1108   Log() << Verbose(1) << "Begin of InsertStraddlingPoints" << endl;
    11091428
    11101429  cloud->GoToFirst();
     
    11171436    }
    11181437    Walker = cloud->GetPoint();
    1119     Log() << Verbose(2) << "Current point is " << *Walker << "." << endl;
     1438    Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;
    11201439    // get the next triangle
    11211440    triangles = FindClosestTrianglesToPoint(Walker->node, BoundaryPoints);
    11221441    BTS = triangles->front();
    11231442    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
    1124       Log() << Verbose(2) << "No triangles found, probably a tesselation point itself." << endl;
     1443      Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl;
    11251444      cloud->GoToNext();
    11261445      continue;
    11271446    } else {
    11281447    }
    1129     Log() << Verbose(2) << "Closest triangle is " << *BTS << "." << endl;
     1448    Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl;
    11301449    // get the intersection point
    11311450    if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
    1132       Log() << Verbose(2) << "We have an intersection at " << Intersection << "." << endl;
     1451      Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl;
    11331452      // we have the intersection, check whether in- or outside of boundary
    11341453      if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
    11351454        // inside, next!
    1136         Log() << Verbose(2) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
     1455        Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
    11371456      } else {
    11381457        // outside!
    1139         Log() << Verbose(2) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
     1458        Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
    11401459        class BoundaryLineSet *OldLines[3], *NewLines[3];
    11411460        class BoundaryPointSet *OldPoints[3], *NewPoint;
     
    11471466        Normal.CopyVector(&BTS->NormalVector);
    11481467        // add Walker to boundary points
    1149         Log() << Verbose(2) << "Adding " << *Walker << " to BoundaryPoints." << endl;
     1468        Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl;
    11501469        AddFlag = true;
    11511470        if (AddBoundaryPoint(Walker,0))
     
    11541473          continue;
    11551474        // remove triangle
    1156         Log() << Verbose(2) << "Erasing triangle " << *BTS << "." << endl;
     1475        Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl;
    11571476        TrianglesOnBoundary.erase(BTS->Nr);
    11581477        delete(BTS);
     
    11621481          BPS[1] = OldPoints[i];
    11631482          NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1164           Log() << Verbose(3) << "Creating new line " << *NewLines[i] << "." << endl;
     1483          Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl;
    11651484          LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
    11661485          LinesOnBoundaryCount++;
     
    11731492            if (NewLines[j]->IsConnectedTo(BLS[0])) {
    11741493              if (n>2) {
    1175                 Log() << Verbose(1) << BLS[0] << " connects to all of the new lines?!" << endl;
     1494                eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl;
    11761495                return false;
    11771496              } else
     
    11841503          BTS->GetNormalVector(Normal);
    11851504          Normal.Scale(-1.);
    1186           Log() << Verbose(2) << "Created new triangle " << *BTS << "." << endl;
     1505          Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl;
    11871506          TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    11881507          TrianglesOnBoundaryCount++;
     
    11981517  // exit
    11991518  delete(Center);
    1200   Log() << Verbose(1) << "End of InsertStraddlingPoints" << endl;
    12011519  return true;
    12021520};
     
    12091527bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
    12101528{
     1529        Info FunctionInfo(__func__);
    12111530  PointTestPair InsertUnique;
    12121531  BPS[n] = new class BoundaryPointSet(Walker);
     
    12301549void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
    12311550{
     1551        Info FunctionInfo(__func__);
    12321552  PointTestPair InsertUnique;
    12331553  TPS[n] = new class BoundaryPointSet(Candidate);
     
    12371557  } else {
    12381558    delete TPS[n];
    1239     Log() << Verbose(4) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
     1559    Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
    12401560    TPS[n] = (InsertUnique.first)->second;
    12411561  }
     
    12501570void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
    12511571{
     1572        Info FunctionInfo(__func__);
    12521573  PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
    12531574  if (FindPoint != PointsOnBoundary.end())
     
    12671588  bool insertNewLine = true;
    12681589
    1269   if (a->lines.find(b->node->nr) != a->lines.end()) {
    1270     LineMap::iterator FindLine = a->lines.find(b->node->nr);
     1590  LineMap::iterator FindLine = a->lines.find(b->node->nr);
     1591  if (FindLine != a->lines.end()) {
     1592    Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
     1593
    12711594    pair<LineMap::iterator,LineMap::iterator> FindPair;
    12721595    FindPair = a->lines.equal_range(b->node->nr);
    1273     Log() << Verbose(5) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
    12741596
    12751597    for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     
    12771599      if (FindLine->second->triangles.size() < 2) {
    12781600        insertNewLine = false;
    1279         Log() << Verbose(4) << "Using existing line " << *FindLine->second << endl;
     1601        Log() << Verbose(0) << "Using existing line " << *FindLine->second << endl;
    12801602
    12811603        BPS[0] = FindLine->second->endpoints[0];
    12821604        BPS[1] = FindLine->second->endpoints[1];
    12831605        BLS[n] = FindLine->second;
     1606
     1607        // remove existing line from OpenLines
     1608        CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
     1609        if (CandidateLine != OpenLines.end()) {
     1610          Log() << Verbose(1) << " Removing line from OpenLines." << endl;
     1611          delete(CandidateLine->second);
     1612          OpenLines.erase(CandidateLine);
     1613        } else {
     1614          eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl;
     1615        }
    12841616
    12851617        break;
     
    13041636void Tesselation::AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
    13051637{
    1306   Log() << Verbose(4) << "Adding line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
     1638        Info FunctionInfo(__func__);
     1639  Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
    13071640  BPS[0] = a;
    13081641  BPS[1] = b;
     
    13121645  // increase counter
    13131646  LinesOnBoundaryCount++;
     1647  // also add to open lines
     1648  CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
     1649  OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
    13141650};
    13151651
     
    13191655void Tesselation::AddTesselationTriangle()
    13201656{
     1657        Info FunctionInfo(__func__);
    13211658  Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
    13221659
     
    13371674void Tesselation::AddTesselationTriangle(const int nr)
    13381675{
    1339   Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1676        Info FunctionInfo(__func__);
     1677  Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl;
    13401678
    13411679  // add triangle to global map
     
    13551693void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
    13561694{
     1695        Info FunctionInfo(__func__);
    13571696  if (triangle == NULL)
    13581697    return;
    13591698  for (int i = 0; i < 3; i++) {
    13601699    if (triangle->lines[i] != NULL) {
    1361       Log() << Verbose(5) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
     1700      Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
    13621701      triangle->lines[i]->triangles.erase(triangle->Nr);
    13631702      if (triangle->lines[i]->triangles.empty()) {
    1364           Log() << Verbose(5) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
     1703          Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
    13651704          RemoveTesselationLine(triangle->lines[i]);
    13661705      } else {
    1367         Log() << Verbose(5) << *triangle->lines[i] << " is still attached to another triangle: ";
     1706        Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ";
     1707        OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
    13681708        for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
    13691709          Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
    13701710        Log() << Verbose(0) << endl;
    13711711//        for (int j=0;j<2;j++) {
    1372 //          Log() << Verbose(5) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
     1712//          Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
    13731713//          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
    13741714//            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
     
    13821722
    13831723  if (TrianglesOnBoundary.erase(triangle->Nr))
    1384     Log() << Verbose(5) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
     1724    Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
    13851725  delete(triangle);
    13861726};
     
    13921732void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
    13931733{
     1734        Info FunctionInfo(__func__);
    13941735  int Numbers[2];
    13951736
     
    14121753        for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
    14131754          if ((*Runner).second == line) {
    1414             Log() << Verbose(5) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     1755            Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
    14151756            line->endpoints[i]->lines.erase(Runner);
    14161757            break;
     
    14181759      } else { // there's just a single line left
    14191760        if (line->endpoints[i]->lines.erase(line->Nr))
    1420           Log() << Verbose(5) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     1761          Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
    14211762      }
    14221763      if (line->endpoints[i]->lines.empty()) {
    1423         Log() << Verbose(5) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
     1764        Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
    14241765        RemoveTesselationPoint(line->endpoints[i]);
    14251766      } else {
    1426         Log() << Verbose(5) << *line->endpoints[i] << " has still lines it's attached to: ";
     1767        Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ";
    14271768        for(LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
    14281769          Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
     
    14371778
    14381779  if (LinesOnBoundary.erase(line->Nr))
    1439     Log() << Verbose(5) << "Removing line Nr. " << line->Nr << "." << endl;
     1780    Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl;
    14401781  delete(line);
    14411782};
     
    14481789void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
    14491790{
     1791        Info FunctionInfo(__func__);
    14501792  if (point == NULL)
    14511793    return;
    14521794  if (PointsOnBoundary.erase(point->Nr))
    1453     Log() << Verbose(5) << "Removing point Nr. " << point->Nr << "." << endl;
     1795    Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl;
    14541796  delete(point);
    14551797};
     
    14661808int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
    14671809{
     1810        Info FunctionInfo(__func__);
    14681811  int adjacentTriangleCount = 0;
    14691812  class BoundaryPointSet *Points[3];
    14701813
    1471   Log() << Verbose(2) << "Begin of CheckPresenceOfTriangle" << endl;
    14721814  // builds a triangle point set (Points) of the end points
    14731815  for (int i = 0; i < 3; i++) {
     
    14881830          for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
    14891831            TriangleMap *triangles = &FindLine->second->triangles;
    1490             Log() << Verbose(3) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
     1832            Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
    14911833            for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
    14921834              if (FindTriangle->second->IsPresentTupel(Points)) {
     
    14941836              }
    14951837            }
    1496             Log() << Verbose(3) << "end." << endl;
     1838            Log() << Verbose(1) << "end." << endl;
    14971839          }
    14981840          // Only one of the triangle lines must be considered for the triangle count.
    1499           //Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     1841          //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    15001842          //return adjacentTriangleCount;
    15011843        }
     
    15041846  }
    15051847
    1506   Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    1507   Log() << Verbose(2) << "End of CheckPresenceOfTriangle" << endl;
     1848  Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    15081849  return adjacentTriangleCount;
    15091850};
     
    15191860class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
    15201861{
     1862        Info FunctionInfo(__func__);
    15211863  class BoundaryTriangleSet *triangle = NULL;
    15221864  class BoundaryPointSet *Points[3];
     
    15481890          }
    15491891          // Only one of the triangle lines must be considered for the triangle count.
    1550           //Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     1892          //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    15511893          //return adjacentTriangleCount;
    15521894        }
     
    15691911void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
    15701912{
    1571   Log() << Verbose(1) << "Begin of FindStartingTriangle\n";
     1913        Info FunctionInfo(__func__);
    15721914  int i = 0;
    1573   TesselPoint* FirstPoint = NULL;
    1574   TesselPoint* SecondPoint = NULL;
    15751915  TesselPoint* MaxPoint[NDIM];
     1916  TesselPoint* Temporary;
    15761917  double maxCoordinate[NDIM];
    1577   Vector Oben;
     1918  BoundaryLineSet BaseLine;
    15781919  Vector helper;
    15791920  Vector Chord;
    15801921  Vector SearchDirection;
    1581 
    1582   Oben.Zero();
     1922  Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     1923  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
     1924  Vector SphereCenter;
     1925  Vector NormalVector;
     1926
     1927  NormalVector.Zero();
    15831928
    15841929  for (i = 0; i < 3; i++) {
     
    15931938      for (LC->n[(i+2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {
    15941939        const LinkedNodes *List = LC->GetCurrentCell();
    1595         //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     1940        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    15961941        if (List != NULL) {
    15971942          for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
    15981943            if ((*Runner)->node->x[i] > maxCoordinate[i]) {
    1599               Log() << Verbose(2) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
     1944              Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
    16001945              maxCoordinate[i] = (*Runner)->node->x[i];
    16011946              MaxPoint[i] = (*Runner);
     
    16081953  }
    16091954
    1610   Log() << Verbose(2) << "Found maximum coordinates: ";
     1955  Log() << Verbose(1) << "Found maximum coordinates: ";
    16111956  for (int i=0;i<NDIM;i++)
    16121957    Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t";
     
    16141959
    16151960  BTS = NULL;
    1616   CandidateList *OptCandidates = new CandidateList();
    16171961  for (int k=0;k<NDIM;k++) {
    1618     Oben.Zero();
    1619     Oben.x[k] = 1.;
    1620     FirstPoint = MaxPoint[k];
    1621     Log() << Verbose(1) << "Coordinates of start node at " << *FirstPoint->node << "." << endl;
     1962    NormalVector.Zero();
     1963    NormalVector.x[k] = 1.;
     1964    BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
     1965    Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
    16221966
    16231967    double ShortestAngle;
    1624     TesselPoint* OptCandidate = NULL;
    16251968    ShortestAngle = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
    16261969
    1627     FindSecondPointForTesselation(FirstPoint, Oben, OptCandidate, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
    1628     SecondPoint = OptCandidate;
    1629     if (SecondPoint == NULL)  // have we found a second point?
     1970    FindSecondPointForTesselation(BaseLine.endpoints[0]->node, NormalVector, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
     1971    if (Temporary == NULL)  // have we found a second point?
    16301972      continue;
    1631 
    1632     helper.CopyVector(FirstPoint->node);
    1633     helper.SubtractVector(SecondPoint->node);
    1634     helper.Normalize();
    1635     Oben.ProjectOntoPlane(&helper);
    1636     Oben.Normalize();
    1637     helper.VectorProduct(&Oben);
     1973    BaseLine.endpoints[1] = new BoundaryPointSet(Temporary);
     1974
     1975    // construct center of circle
     1976    CircleCenter.CopyVector(BaseLine.endpoints[0]->node->node);
     1977    CircleCenter.AddVector(BaseLine.endpoints[1]->node->node);
     1978    CircleCenter.Scale(0.5);
     1979
     1980    // construct normal vector of circle
     1981    CirclePlaneNormal.CopyVector(BaseLine.endpoints[0]->node->node);
     1982    CirclePlaneNormal.SubtractVector(BaseLine.endpoints[1]->node->node);
     1983
     1984    double radius = CirclePlaneNormal.NormSquared();
     1985    double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
     1986
     1987    NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
     1988    NormalVector.Normalize();
    16381989    ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    16391990
    1640     Chord.CopyVector(FirstPoint->node); // bring into calling function
    1641     Chord.SubtractVector(SecondPoint->node);
    1642     double radius = Chord.ScalarProduct(&Chord);
    1643     double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
    1644     helper.CopyVector(&Oben);
    1645     helper.Scale(CircleRadius);
    1646     // Now, oben and helper are two orthonormalized vectors in the plane defined by Chord (not normalized)
     1991    SphereCenter.CopyVector(&NormalVector);
     1992    SphereCenter.Scale(CircleRadius);
     1993    SphereCenter.AddVector(&CircleCenter);
     1994    // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
    16471995
    16481996    // look in one direction of baseline for initial candidate
    1649     SearchDirection.MakeNormalVector(&Chord, &Oben);  // whether we look "left" first or "right" first is not important ...
     1997    SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector);  // whether we look "left" first or "right" first is not important ...
    16501998
    16511999    // adding point 1 and point 2 and add the line between them
    1652     Log() << Verbose(1) << "Coordinates of start node at " << *FirstPoint->node << "." << endl;
    1653     AddTesselationPoint(FirstPoint, 0);
    1654     Log() << Verbose(1) << "Found second point is at " << *SecondPoint->node << ".\n";
    1655     AddTesselationPoint(SecondPoint, 1);
    1656     AddTesselationLine(TPS[0], TPS[1], 0);
    1657 
    1658     //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << helper << ".\n";
    1659     FindThirdPointForTesselation(Oben, SearchDirection, helper, BLS[0], NULL, *&OptCandidates, &ShortestAngle, RADIUS, LC);
    1660     Log() << Verbose(1) << "List of third Points is ";
    1661     for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1662         Log() << Verbose(0) << " " << *(*it)->point;
    1663     }
    1664     Log() << Verbose(0) << endl;
    1665 
    1666     for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1667       // add third triangle point
    1668       AddTesselationPoint((*it)->point, 2);
    1669       // add the second and third line
    1670       AddTesselationLine(TPS[1], TPS[2], 1);
    1671       AddTesselationLine(TPS[0], TPS[2], 2);
    1672       // ... and triangles to the Maps of the Tesselation class
    1673       BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    1674       AddTesselationTriangle();
    1675       // ... and calculate its normal vector (with correct orientation)
    1676       (*it)->OptCenter.Scale(-1.);
    1677       Log() << Verbose(2) << "Anti-Oben is currently " << (*it)->OptCenter << "." << endl;
    1678       BTS->GetNormalVector((*it)->OptCenter);  // vector to compare with should point inwards
    1679       Log() << Verbose(0) << "==> Found starting triangle consists of " << *FirstPoint << ", " << *SecondPoint << " and "
    1680       << *(*it)->point << " with normal vector " << BTS->NormalVector << ".\n";
    1681 
    1682       // if we do not reach the end with the next step of iteration, we need to setup a new first line
    1683       if (it != OptCandidates->end()--) {
    1684         FirstPoint = (*it)->BaseLine->endpoints[0]->node;
    1685         SecondPoint = (*it)->point;
    1686         // adding point 1 and point 2 and the line between them
    1687         AddTesselationPoint(FirstPoint, 0);
    1688         AddTesselationPoint(SecondPoint, 1);
    1689         AddTesselationLine(TPS[0], TPS[1], 0);
    1690       }
    1691       Log() << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl;
    1692     }
     2000    Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
     2001    Log() << Verbose(0) << "Found second point is at " << *BaseLine.endpoints[1]->node << ".\n";
     2002
     2003    //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
     2004    CandidateForTesselation OptCandidates(&BaseLine);
     2005    FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
     2006    Log() << Verbose(0) << "List of third Points is:" << endl;
     2007    for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
     2008        Log() << Verbose(0) << " " << *(*it) << endl;
     2009    }
     2010
     2011    BTS = NULL;
     2012    AddCandidateTriangle(OptCandidates);
     2013//    delete(BaseLine.endpoints[0]);
     2014//    delete(BaseLine.endpoints[1]);
     2015
    16932016    if (BTS != NULL) // we have created one starting triangle
    16942017      break;
    16952018    else {
    16962019      // remove all candidates from the list and then the list itself
    1697       class CandidateForTesselation *remover = NULL;
    1698       for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1699         remover = *it;
    1700         delete(remover);
    1701       }
    1702       OptCandidates->clear();
    1703     }
    1704   }
    1705 
    1706   // remove all candidates from the list and then the list itself
    1707   class CandidateForTesselation *remover = NULL;
    1708   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1709     remover = *it;
    1710     delete(remover);
    1711   }
    1712   delete(OptCandidates);
    1713   Log() << Verbose(1) << "End of FindStartingTriangle\n";
     2020      OptCandidates.pointlist.clear();
     2021    }
     2022  }
    17142023};
    17152024
    17162025/** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
    17172026 * This is supposed to prevent early closing of the tesselation.
    1718  * \param *BaseRay baseline, i.e. not \a *OptCandidate
     2027 * \param CandidateLine CandidateForTesselation with baseline and shortestangle , i.e. not \a *OptCandidate
    17192028 * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
    1720  * \param ShortestAngle path length on this circle band for the current \a *ThirdNode
    17212029 * \param RADIUS radius of sphere
    17222030 * \param *LC LinkedCell structure
    17232031 * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
    17242032 */
    1725 bool Tesselation::HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const ThirdNode, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const
    1726 {
    1727   bool result = false;
    1728   Vector CircleCenter;
    1729   Vector CirclePlaneNormal;
    1730   Vector OldSphereCenter;
    1731   Vector SearchDirection;
    1732   Vector helper;
    1733   TesselPoint *OtherOptCandidate = NULL;
    1734   double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    1735   double radius, CircleRadius;
    1736   BoundaryLineSet *Line = NULL;
    1737   BoundaryTriangleSet *T = NULL;
    1738 
    1739   Log() << Verbose(1) << "Begin of HasOtherBaselineBetterCandidate" << endl;
    1740 
    1741   // check both other lines
    1742   PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
    1743   if (FindPoint != PointsOnBoundary.end()) {
    1744     for (int i=0;i<2;i++) {
    1745       LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
    1746       if (FindLine != (FindPoint->second)->lines.end()) {
    1747         Line = FindLine->second;
    1748         Log() << Verbose(1) << "Found line " << *Line << "." << endl;
    1749         if (Line->triangles.size() == 1) {
    1750           T = Line->triangles.begin()->second;
    1751           // construct center of circle
    1752           CircleCenter.CopyVector(Line->endpoints[0]->node->node);
    1753           CircleCenter.AddVector(Line->endpoints[1]->node->node);
    1754           CircleCenter.Scale(0.5);
    1755 
    1756           // construct normal vector of circle
    1757           CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
    1758           CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
    1759 
    1760           // calculate squared radius of circle
    1761           radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    1762           if (radius/4. < RADIUS*RADIUS) {
    1763             CircleRadius = RADIUS*RADIUS - radius/4.;
    1764             CirclePlaneNormal.Normalize();
    1765             //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    1766 
    1767             // construct old center
    1768             GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
    1769             helper.CopyVector(&T->NormalVector);  // normal vector ensures that this is correct center of the two possible ones
    1770             radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
    1771             helper.Scale(sqrt(RADIUS*RADIUS - radius));
    1772             OldSphereCenter.AddVector(&helper);
    1773             OldSphereCenter.SubtractVector(&CircleCenter);
    1774             //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
    1775 
    1776             // construct SearchDirection
    1777             SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
    1778             helper.CopyVector(Line->endpoints[0]->node->node);
    1779             helper.SubtractVector(ThirdNode->node);
    1780             if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    1781               SearchDirection.Scale(-1.);
    1782             SearchDirection.ProjectOntoPlane(&OldSphereCenter);
    1783             SearchDirection.Normalize();
    1784             Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    1785             if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    1786               // rotated the wrong way!
    1787               eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
    1788             }
    1789 
    1790             // add third point
    1791             CandidateList *OptCandidates = new CandidateList();
    1792             FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, Line, ThirdNode, OptCandidates, &OtherShortestAngle, RADIUS, LC);
    1793             for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1794               if (((*it)->point == BaseRay->endpoints[0]->node) || ((*it)->point == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
    1795                 continue;
    1796               Log() << Verbose(1) << " Third point candidate is " << *(*it)->point
    1797               << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
    1798               Log() << Verbose(1) << " Baseline is " << *BaseRay << endl;
    1799 
    1800               // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
    1801               TesselPoint *PointCandidates[3];
    1802               PointCandidates[0] = (*it)->point;
    1803               PointCandidates[1] = BaseRay->endpoints[0]->node;
    1804               PointCandidates[2] = BaseRay->endpoints[1]->node;
    1805               bool check=false;
    1806               int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
    1807               // If there is no triangle, add it regularly.
    1808               if (existentTrianglesCount == 0) {
    1809                 SetTesselationPoint((*it)->point, 0);
    1810                 SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
    1811                 SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
    1812 
    1813                 if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
    1814                   OtherOptCandidate = (*it)->point;
    1815                   check = true;
    1816                 }
    1817               } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
    1818                 SetTesselationPoint((*it)->point, 0);
    1819                 SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
    1820                 SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
    1821 
    1822                 // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
    1823                 // i.e. at least one of the three lines must be present with TriangleCount <= 1
    1824                 if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
    1825                   OtherOptCandidate = (*it)->point;
    1826                   check = true;
    1827                 }
    1828               }
    1829 
    1830               if (check) {
    1831                 if (ShortestAngle > OtherShortestAngle) {
    1832                   Log() << Verbose(1) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
    1833                   result = true;
    1834                   break;
    1835                 }
    1836               }
    1837             }
    1838             delete(OptCandidates);
    1839             if (result)
    1840               break;
    1841           } else {
    1842             Log() << Verbose(1) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
    1843           }
    1844         } else {
    1845           eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;
    1846         }
    1847       } else {
    1848         Log() << Verbose(2) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
    1849       }
    1850     }
    1851   } else {
    1852     eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;
    1853   }
    1854 
    1855   Log() << Verbose(1) << "End of HasOtherBaselineBetterCandidate" << endl;
    1856 
    1857   return result;
    1858 };
     2033//bool Tesselation::HasOtherBaselineBetterCandidate(CandidateForTesselation &CandidateLine, const TesselPoint * const ThirdNode, double RADIUS, const LinkedCell * const LC) const
     2034//{
     2035//      Info FunctionInfo(__func__);
     2036//  bool result = false;
     2037//  Vector CircleCenter;
     2038//  Vector CirclePlaneNormal;
     2039//  Vector OldSphereCenter;
     2040//  Vector SearchDirection;
     2041//  Vector helper;
     2042//  TesselPoint *OtherOptCandidate = NULL;
     2043//  double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
     2044//  double radius, CircleRadius;
     2045//  BoundaryLineSet *Line = NULL;
     2046//  BoundaryTriangleSet *T = NULL;
     2047//
     2048//  // check both other lines
     2049//  PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
     2050//  if (FindPoint != PointsOnBoundary.end()) {
     2051//    for (int i=0;i<2;i++) {
     2052//      LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
     2053//      if (FindLine != (FindPoint->second)->lines.end()) {
     2054//        Line = FindLine->second;
     2055//        Log() << Verbose(0) << "Found line " << *Line << "." << endl;
     2056//        if (Line->triangles.size() == 1) {
     2057//          T = Line->triangles.begin()->second;
     2058//          // construct center of circle
     2059//          CircleCenter.CopyVector(Line->endpoints[0]->node->node);
     2060//          CircleCenter.AddVector(Line->endpoints[1]->node->node);
     2061//          CircleCenter.Scale(0.5);
     2062//
     2063//          // construct normal vector of circle
     2064//          CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
     2065//          CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
     2066//
     2067//          // calculate squared radius of circle
     2068//          radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
     2069//          if (radius/4. < RADIUS*RADIUS) {
     2070//            CircleRadius = RADIUS*RADIUS - radius/4.;
     2071//            CirclePlaneNormal.Normalize();
     2072//            //Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     2073//
     2074//            // construct old center
     2075//            GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
     2076//            helper.CopyVector(&T->NormalVector);  // normal vector ensures that this is correct center of the two possible ones
     2077//            radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
     2078//            helper.Scale(sqrt(RADIUS*RADIUS - radius));
     2079//            OldSphereCenter.AddVector(&helper);
     2080//            OldSphereCenter.SubtractVector(&CircleCenter);
     2081//            //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
     2082//
     2083//            // construct SearchDirection
     2084//            SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
     2085//            helper.CopyVector(Line->endpoints[0]->node->node);
     2086//            helper.SubtractVector(ThirdNode->node);
     2087//            if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
     2088//              SearchDirection.Scale(-1.);
     2089//            SearchDirection.ProjectOntoPlane(&OldSphereCenter);
     2090//            SearchDirection.Normalize();
     2091//            Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2092//            if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     2093//              // rotated the wrong way!
     2094//              eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     2095//            }
     2096//
     2097//            // add third point
     2098//            FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, OptCandidates, ThirdNode, RADIUS, LC);
     2099//            for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); ++it) {
     2100//              if (((*it) == BaseRay->endpoints[0]->node) || ((*it) == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
     2101//                continue;
     2102//              Log() << Verbose(0) << " Third point candidate is " << (*it)
     2103//              << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
     2104//              Log() << Verbose(0) << " Baseline is " << *BaseRay << endl;
     2105//
     2106//              // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
     2107//              TesselPoint *PointCandidates[3];
     2108//              PointCandidates[0] = (*it);
     2109//              PointCandidates[1] = BaseRay->endpoints[0]->node;
     2110//              PointCandidates[2] = BaseRay->endpoints[1]->node;
     2111//              bool check=false;
     2112//              int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
     2113//              // If there is no triangle, add it regularly.
     2114//              if (existentTrianglesCount == 0) {
     2115//                SetTesselationPoint((*it), 0);
     2116//                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
     2117//                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
     2118//
     2119//                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
     2120//                  OtherOptCandidate = (*it);
     2121//                  check = true;
     2122//                }
     2123//              } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
     2124//                SetTesselationPoint((*it), 0);
     2125//                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
     2126//                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
     2127//
     2128//                // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
     2129//                // i.e. at least one of the three lines must be present with TriangleCount <= 1
     2130//                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
     2131//                  OtherOptCandidate = (*it);
     2132//                  check = true;
     2133//                }
     2134//              }
     2135//
     2136//              if (check) {
     2137//                if (ShortestAngle > OtherShortestAngle) {
     2138//                  Log() << Verbose(0) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
     2139//                  result = true;
     2140//                  break;
     2141//                }
     2142//              }
     2143//            }
     2144//            delete(OptCandidates);
     2145//            if (result)
     2146//              break;
     2147//          } else {
     2148//            Log() << Verbose(0) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
     2149//          }
     2150//        } else {
     2151//          eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;
     2152//        }
     2153//      } else {
     2154//        Log() << Verbose(1) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
     2155//      }
     2156//    }
     2157//  } else {
     2158//    eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;
     2159//  }
     2160//
     2161//  return result;
     2162//};
    18592163
    18602164/** This function finds a triangle to a line, adjacent to an existing one.
    18612165 * @param out output stream for debugging
    1862  * @param Line current baseline to search from
     2166 * @param CandidateLine current cadndiate baseline to search from
    18632167 * @param T current triangle which \a Line is edge of
    18642168 * @param RADIUS radius of the rolling ball
     
    18662170 * @param *LC LinkedCell structure with neighbouring points
    18672171 */
    1868 bool Tesselation::FindNextSuitableTriangle(BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
    1869 {
    1870   Log() << Verbose(0) << "Begin of FindNextSuitableTriangle\n";
     2172bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
     2173{
     2174        Info FunctionInfo(__func__);
    18712175  bool result = true;
    1872   CandidateList *OptCandidates = new CandidateList();
    18732176
    18742177  Vector CircleCenter;
    18752178  Vector CirclePlaneNormal;
    1876   Vector OldSphereCenter;
     2179  Vector RelativeSphereCenter;
    18772180  Vector SearchDirection;
    18782181  Vector helper;
    18792182  TesselPoint *ThirdNode = NULL;
    18802183  LineMap::iterator testline;
    1881   double ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    18822184  double radius, CircleRadius;
    18832185
    1884   Log() << Verbose(1) << "Current baseline is " << Line << " of triangle " << T << "." << endl;
    18852186  for (int i=0;i<3;i++)
    1886     if ((T.endpoints[i]->node != Line.endpoints[0]->node) && (T.endpoints[i]->node != Line.endpoints[1]->node))
     2187    if ((T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[0]->node) && (T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[1]->node)) {
    18872188      ThirdNode = T.endpoints[i]->node;
     2189      break;
     2190    }
     2191  Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdNode " << *ThirdNode << " of triangle " << T << "." << endl;
    18882192
    18892193  // construct center of circle
    1890   CircleCenter.CopyVector(Line.endpoints[0]->node->node);
    1891   CircleCenter.AddVector(Line.endpoints[1]->node->node);
     2194  CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     2195  CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    18922196  CircleCenter.Scale(0.5);
    18932197
    18942198  // construct normal vector of circle
    1895   CirclePlaneNormal.CopyVector(Line.endpoints[0]->node->node);
    1896   CirclePlaneNormal.SubtractVector(Line.endpoints[1]->node->node);
     2199  CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     2200  CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    18972201
    18982202  // calculate squared radius of circle
    18992203  radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    19002204  if (radius/4. < RADIUS*RADIUS) {
     2205    // construct relative sphere center with now known CircleCenter
     2206    RelativeSphereCenter.CopyVector(&T.SphereCenter);
     2207    RelativeSphereCenter.SubtractVector(&CircleCenter);
     2208
    19012209    CircleRadius = RADIUS*RADIUS - radius/4.;
    19022210    CirclePlaneNormal.Normalize();
    1903     //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    1904 
    1905     // construct old center
    1906     GetCenterofCircumcircle(&OldSphereCenter, *T.endpoints[0]->node->node, *T.endpoints[1]->node->node, *T.endpoints[2]->node->node);
    1907     helper.CopyVector(&T.NormalVector);  // normal vector ensures that this is correct center of the two possible ones
    1908     radius = Line.endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
    1909     helper.Scale(sqrt(RADIUS*RADIUS - radius));
    1910     OldSphereCenter.AddVector(&helper);
    1911     OldSphereCenter.SubtractVector(&CircleCenter);
    1912     //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
    1913 
    1914     // construct SearchDirection
    1915     SearchDirection.MakeNormalVector(&T.NormalVector, &CirclePlaneNormal);
    1916     helper.CopyVector(Line.endpoints[0]->node->node);
     2211    Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     2212
     2213    Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl;
     2214
     2215    // construct SearchDirection and an "outward pointer"
     2216    SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
     2217    helper.CopyVector(&CircleCenter);
    19172218    helper.SubtractVector(ThirdNode->node);
    19182219    if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    19192220      SearchDirection.Scale(-1.);
    1920     SearchDirection.ProjectOntoPlane(&OldSphereCenter);
    1921     SearchDirection.Normalize();
    1922     Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    1923     if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     2221    Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2222    if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    19242223      // rotated the wrong way!
    19252224      eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     
    19272226
    19282227    // add third point
    1929     FindThirdPointForTesselation(T.NormalVector, SearchDirection, OldSphereCenter, &Line, ThirdNode, OptCandidates, &ShortestAngle, RADIUS, LC);
     2228    FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdNode, RADIUS, LC);
    19302229
    19312230  } else {
    1932     Log() << Verbose(1) << "Circumcircle for base line " << Line << " and base triangle " << T << " is too big!" << endl;
    1933   }
    1934 
    1935   if (OptCandidates->begin() == OptCandidates->end()) {
     2231    Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl;
     2232  }
     2233
     2234  if (CandidateLine.pointlist.empty()) {
    19362235    eLog() << Verbose(2) << "Could not find a suitable candidate." << endl;
    19372236    return false;
    19382237  }
    1939   Log() << Verbose(1) << "Third Points are ";
    1940   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1941     Log() << Verbose(1) << " " << *(*it)->point << endl;
    1942   }
    1943 
    1944   BoundaryLineSet *BaseRay = &Line;
    1945   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1946     Log() << Verbose(1) << " Third point candidate is " << *(*it)->point
    1947     << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
    1948     Log() << Verbose(1) << " Baseline is " << *BaseRay << endl;
    1949 
    1950     // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
    1951     TesselPoint *PointCandidates[3];
    1952     PointCandidates[0] = (*it)->point;
    1953     PointCandidates[1] = BaseRay->endpoints[0]->node;
    1954     PointCandidates[2] = BaseRay->endpoints[1]->node;
    1955     int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
    1956 
    1957     BTS = NULL;
    1958     // check for present edges and whether we reach better candidates from them
    1959     if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) {
    1960       result = false;
    1961       break;
    1962     } else {
    1963       // If there is no triangle, add it regularly.
    1964       if (existentTrianglesCount == 0) {
    1965         AddTesselationPoint((*it)->point, 0);
    1966         AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    1967         AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    1968 
    1969         if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
    1970           AddTesselationLine(TPS[0], TPS[1], 0);
    1971           AddTesselationLine(TPS[0], TPS[2], 1);
    1972           AddTesselationLine(TPS[1], TPS[2], 2);
    1973 
    1974           BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    1975           AddTesselationTriangle();
    1976           (*it)->OptCenter.Scale(-1.);
    1977           BTS->GetNormalVector((*it)->OptCenter);
    1978           (*it)->OptCenter.Scale(-1.);
    1979 
    1980           Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector
    1981             << " for this triangle ... " << endl;
    1982         //Log() << Verbose(1) << "We have "<< TrianglesOnBoundaryCount << " for line " << *BaseRay << "." << endl;
    1983         } else {
    1984           eLog() << Verbose(2) << "This triangle consisting of ";
    1985           Log() << Verbose(0) << *(*it)->point << ", ";
    1986           Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    1987           Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    1988           Log() << Verbose(0) << "exists and is not added, as it does not seem helpful!" << endl;
    1989           result = false;
    1990         }
    1991       } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
    1992           AddTesselationPoint((*it)->point, 0);
    1993           AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    1994           AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    1995 
    1996           // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
    1997           // i.e. at least one of the three lines must be present with TriangleCount <= 1
    1998           if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
    1999             AddTesselationLine(TPS[0], TPS[1], 0);
    2000             AddTesselationLine(TPS[0], TPS[2], 1);
    2001             AddTesselationLine(TPS[1], TPS[2], 2);
    2002 
    2003             BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    2004             AddTesselationTriangle();  // add to global map
    2005 
    2006             (*it)->OtherOptCenter.Scale(-1.);
    2007             BTS->GetNormalVector((*it)->OtherOptCenter);
    2008             (*it)->OtherOptCenter.Scale(-1.);
    2009 
    2010             eLog() << Verbose(2) << "--> WARNING: Special new triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " for this triangle ... " << endl;
    2011             Log() << Verbose(1) << "We have "<< BaseRay->triangles.size() << " for line " << BaseRay << "." << endl;
    2012           } else {
    2013             eLog() << Verbose(2) << "This triangle consisting of " << *(*it)->point << ", " << *BaseRay->endpoints[0]->node << " and " << *BaseRay->endpoints[1]->node << " " << "exists and is not added, as it does not seem helpful!" << endl;
    2014             result = false;
    2015           }
    2016       } else {
    2017         Log() << Verbose(1) << "This triangle consisting of ";
    2018         Log() << Verbose(0) << *(*it)->point << ", ";
    2019         Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    2020         Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    2021         Log() << Verbose(0) << "is invalid!" << endl;
    2022         result = false;
    2023       }
    2024     }
    2025 
    2026     // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
    2027     BaseRay = BLS[0];
    2028     if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
    2029       eLog() << Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl;
    2030       exit(255);
    2031     }
    2032 
    2033   }
    2034 
    2035   // remove all candidates from the list and then the list itself
    2036   class CandidateForTesselation *remover = NULL;
    2037   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    2038     remover = *it;
    2039     delete(remover);
    2040   }
    2041   delete(OptCandidates);
    2042   Log() << Verbose(0) << "End of FindNextSuitableTriangle\n";
     2238  Log() << Verbose(0) << "Third Points are: " << endl;
     2239  for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
     2240    Log() << Verbose(0) << " " << *(*it) << endl;
     2241  }
     2242
     2243  return true;
     2244
     2245//  BoundaryLineSet *BaseRay = CandidateLine.BaseLine;
     2246//  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     2247//    Log() << Verbose(0) << "Third point candidate is " << *(*it)->point
     2248//    << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
     2249//    Log() << Verbose(0) << "Baseline is " << *BaseRay << endl;
     2250//
     2251//    // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
     2252//    TesselPoint *PointCandidates[3];
     2253//    PointCandidates[0] = (*it)->point;
     2254//    PointCandidates[1] = BaseRay->endpoints[0]->node;
     2255//    PointCandidates[2] = BaseRay->endpoints[1]->node;
     2256//    int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
     2257//
     2258//    BTS = NULL;
     2259//    // check for present edges and whether we reach better candidates from them
     2260//    //if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) {
     2261//    if (0) {
     2262//      result = false;
     2263//      break;
     2264//    } else {
     2265//      // If there is no triangle, add it regularly.
     2266//      if (existentTrianglesCount == 0) {
     2267//        AddTesselationPoint((*it)->point, 0);
     2268//        AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
     2269//        AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
     2270//
     2271//        if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
     2272//          CandidateLine.point = (*it)->point;
     2273//          CandidateLine.OptCenter.CopyVector(&((*it)->OptCenter));
     2274//          CandidateLine.OtherOptCenter.CopyVector(&((*it)->OtherOptCenter));
     2275//          CandidateLine.ShortestAngle = ShortestAngle;
     2276//        } else {
     2277////          eLog() << Verbose(1) << "This triangle consisting of ";
     2278////          Log() << Verbose(0) << *(*it)->point << ", ";
     2279////          Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
     2280////          Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
     2281////          Log() << Verbose(0) << "exists and is not added, as it 0x80000000006fc150(does not seem helpful!" << endl;
     2282//          result = false;
     2283//        }
     2284//      } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
     2285//          AddTesselationPoint((*it)->point, 0);
     2286//          AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
     2287//          AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
     2288//
     2289//          // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
     2290//          // i.e. at least one of the three lines must be present with TriangleCount <= 1
     2291//          if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS) || CandidateLine.BaseLine->skipped) {
     2292//            CandidateLine.point = (*it)->point;
     2293//            CandidateLine.OptCenter.CopyVector(&(*it)->OptCenter);
     2294//            CandidateLine.OtherOptCenter.CopyVector(&(*it)->OtherOptCenter);
     2295//            CandidateLine.ShortestAngle = ShortestAngle+2.*M_PI;
     2296//
     2297//          } else {
     2298////            eLog() << Verbose(1) << "This triangle consisting of " << *(*it)->point << ", " << *BaseRay->endpoints[0]->node << " and " << *BaseRay->endpoints[1]->node << " " << "exists and is not added, as it does not seem helpful!" << endl;
     2299//            result = false;
     2300//          }
     2301//      } else {
     2302////        Log() << Verbose(1) << "This triangle consisting of ";
     2303////        Log() << Verbose(0) << *(*it)->point << ", ";
     2304////        Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
     2305////        Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
     2306////        Log() << Verbose(0) << "is invalid!" << endl;
     2307//        result = false;
     2308//      }
     2309//    }
     2310//
     2311//    // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
     2312//    BaseRay = BLS[0];
     2313//    if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
     2314//      eLog() << Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl;
     2315//      exit(255);
     2316//    }
     2317//
     2318//  }
     2319//
     2320//  // remove all candidates from the list and then the list itself
     2321//  class CandidateForTesselation *remover = NULL;
     2322//  for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     2323//    remover = *it;
     2324//    delete(remover);
     2325//  }
     2326//  delete(OptCandidates);
    20432327  return result;
     2328};
     2329
     2330/** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
     2331 * \param CandidateLine triangle to add
     2332 * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in AddTesselationLine()
     2333 */
     2334void Tesselation::AddCandidateTriangle(CandidateForTesselation CandidateLine)
     2335{
     2336        Info FunctionInfo(__func__);
     2337  Vector Center;
     2338  TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
     2339
     2340  // fill the set of neighbours
     2341  Center.CopyVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     2342  Center.SubtractVector(TurningPoint->node);
     2343  set<TesselPoint*> SetOfNeighbours;
     2344  SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
     2345  for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
     2346    SetOfNeighbours.insert(*Runner);
     2347  TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, &Center);
     2348
     2349  // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
     2350  TesselPointList::iterator Runner = connectedClosestPoints->begin();
     2351  TesselPointList::iterator Sprinter = Runner;
     2352  Sprinter++;
     2353  while(Sprinter != connectedClosestPoints->end()) {
     2354    // add the points
     2355    AddTesselationPoint(TurningPoint, 0);
     2356    AddTesselationPoint((*Runner), 1);
     2357    AddTesselationPoint((*Sprinter), 2);
     2358
     2359
     2360    // add the lines
     2361    AddTesselationLine(TPS[0], TPS[1], 0);
     2362    AddTesselationLine(TPS[0], TPS[2], 1);
     2363    AddTesselationLine(TPS[1], TPS[2], 2);
     2364
     2365    // add the triangles
     2366    BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2367    AddTesselationTriangle();
     2368    BTS->GetCenter(&Center);
     2369    Center.SubtractVector(&CandidateLine.OptCenter);
     2370    BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
     2371    BTS->GetNormalVector(Center);
     2372
     2373    Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << "." << endl;
     2374    Runner = Sprinter;
     2375    Sprinter++;
     2376  }
     2377  delete(connectedClosestPoints);
    20442378};
    20452379
     
    20532387class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
    20542388{
     2389        Info FunctionInfo(__func__);
    20552390  class BoundaryPointSet *Spot = NULL;
    20562391  class BoundaryLineSet *OtherBase;
     
    20642399  OtherBase = new class BoundaryLineSet(BPS,-1);
    20652400
    2066   Log() << Verbose(3) << "INFO: Current base line is " << *Base << "." << endl;
    2067   Log() << Verbose(3) << "INFO: Other base line is " << *OtherBase << "." << endl;
     2401  Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl;
     2402  Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl;
    20682403
    20692404  // get the closest point on each line to the other line
     
    20852420  delete(ClosestPoint);
    20862421  if ((distance[0] * distance[1]) > 0)  { // have same sign?
    2087     Log() << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
     2422    Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
    20882423    if (distance[0] < distance[1]) {
    20892424      Spot = Base->endpoints[0];
     
    20932428    return Spot;
    20942429  } else {  // different sign, i.e. we are in between
    2095     Log() << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
     2430    Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
    20962431    return NULL;
    20972432  }
     
    21012436void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
    21022437{
     2438        Info FunctionInfo(__func__);
    21032439  // print all lines
    2104   Log() << Verbose(1) << "Printing all boundary points for debugging:" << endl;
     2440  Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl;
    21052441  for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
    2106     Log() << Verbose(2) << *(PointRunner->second) << endl;
     2442    Log() << Verbose(0) << *(PointRunner->second) << endl;
    21072443};
    21082444
    21092445void Tesselation::PrintAllBoundaryLines(ofstream *out) const
    21102446{
     2447        Info FunctionInfo(__func__);
    21112448  // print all lines
    2112   Log() << Verbose(1) << "Printing all boundary lines for debugging:" << endl;
     2449  Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl;
    21132450  for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
    2114     Log() << Verbose(2) << *(LineRunner->second) << endl;
     2451    Log() << Verbose(0) << *(LineRunner->second) << endl;
    21152452};
    21162453
    21172454void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
    21182455{
     2456        Info FunctionInfo(__func__);
    21192457  // print all triangles
    2120   Log() << Verbose(1) << "Printing all boundary triangles for debugging:" << endl;
     2458  Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl;
    21212459  for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
    2122     Log() << Verbose(2) << *(TriangleRunner->second) << endl;
     2460    Log() << Verbose(0) << *(TriangleRunner->second) << endl;
    21232461};
    21242462
     
    21302468double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
    21312469{
     2470        Info FunctionInfo(__func__);
    21322471  class BoundaryLineSet *OtherBase;
    21332472  Vector *ClosestPoint[2];
     
    21412480  OtherBase = new class BoundaryLineSet(BPS,-1);
    21422481
    2143   Log() << Verbose(3) << "INFO: Current base line is " << *Base << "." << endl;
    2144   Log() << Verbose(3) << "INFO: Other base line is " << *OtherBase << "." << endl;
     2482  Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl;
     2483  Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl;
    21452484
    21462485  // get the closest point on each line to the other line
     
    21622501
    21632502  if (Distance.NormSquared() < MYEPSILON) { // check for intersection
    2164     Log() << Verbose(3) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
     2503    Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
    21652504    return false;
    21662505  } else { // check for sign against BaseLineNormal
     
    21722511    }
    21732512    for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2174       Log() << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
     2513      Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
    21752514      BaseLineNormal.AddVector(&(runner->second->NormalVector));
    21762515    }
     
    21782517
    21792518    if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
    2180       Log() << Verbose(2) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;
     2519      Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;
    21812520      // calculate volume summand as a general tetraeder
    21822521      return volume;
    21832522    } else {  // Base higher than OtherBase -> do nothing
    2184       Log() << Verbose(2) << "REJECT: Base line is higher: Nothing to do." << endl;
     2523      Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl;
    21852524      return 0.;
    21862525    }
     
    21972536class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
    21982537{
     2538        Info FunctionInfo(__func__);
    21992539  class BoundaryLineSet *OldLines[4], *NewLine;
    22002540  class BoundaryPointSet *OldPoints[2];
     
    22032543  int i,m;
    22042544
    2205   Log() << Verbose(1) << "Begin of FlipBaseline" << endl;
    2206 
    22072545  // calculate NormalVector for later use
    22082546  BaseLineNormal.Zero();
     
    22122550  }
    22132551  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2214     Log() << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
     2552    Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
    22152553    BaseLineNormal.AddVector(&(runner->second->NormalVector));
    22162554  }
     
    22252563  i=0;
    22262564  m=0;
    2227   Log() << Verbose(3) << "The four old lines are: ";
     2565  Log() << Verbose(0) << "The four old lines are: ";
    22282566  for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    22292567    for (int j=0;j<3;j++) // all of their endpoints and baselines
     
    22332571      }
    22342572  Log() << Verbose(0) << endl;
    2235   Log() << Verbose(3) << "The two old points are: ";
     2573  Log() << Verbose(0) << "The two old points are: ";
    22362574  for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    22372575    for (int j=0;j<3;j++) // all of their endpoints and baselines
     
    22592597
    22602598  // remove triangles and baseline removes itself
    2261   Log() << Verbose(3) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
     2599  Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
    22622600  OldBaseLineNr = Base->Nr;
    22632601  m=0;
    22642602  for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2265     Log() << Verbose(3) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
     2603    Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
    22662604    OldTriangleNrs[m++] = runner->second->Nr;
    22672605    RemoveTesselationTriangle(runner->second);
     
    22732611  NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
    22742612  LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
    2275   Log() << Verbose(3) << "INFO: Created new baseline " << *NewLine << "." << endl;
     2613  Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl;
    22762614
    22772615  // construct new triangles with flipped baseline
     
    22882626    BTS->GetNormalVector(BaseLineNormal);
    22892627    AddTesselationTriangle(OldTriangleNrs[0]);
    2290     Log() << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
     2628    Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
    22912629
    22922630    BLS[0] = (i==2 ? OldLines[3] : OldLines[2]);
     
    22962634    BTS->GetNormalVector(BaseLineNormal);
    22972635    AddTesselationTriangle(OldTriangleNrs[1]);
    2298     Log() << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
     2636    Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
    22992637  } else {
    2300     Log() << Verbose(1) << "The four old lines do not connect, something's utterly wrong here!" << endl;
     2638    eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl;
    23012639    return NULL;
    23022640  }
    23032641
    2304   Log() << Verbose(1) << "End of FlipBaseline" << endl;
    23052642  return NewLine;
    23062643};
     
    23172654void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
    23182655{
    2319   Log() << Verbose(2) << "Begin of FindSecondPointForTesselation" << endl;
     2656        Info FunctionInfo(__func__);
    23202657  Vector AngleCheck;
    23212658  class TesselPoint* Candidate = NULL;
     
    23382675    Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
    23392676  }
    2340   Log() << Verbose(3) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :"
     2677  Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :"
    23412678    << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl;
    23422679
     
    23452682      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    23462683        const LinkedNodes *List = LC->GetCurrentCell();
    2347         //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     2684        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    23482685        if (List != NULL) {
    23492686          for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     
    23762713                angle = AngleCheck.Angle(&Oben);
    23772714                if (angle < Storage[0]) {
    2378                   //Log() << Verbose(3) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
    2379                   Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
     2715                  //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
     2716                  Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
    23802717                  OptCandidate = Candidate;
    23812718                  Storage[0] = angle;
    2382                   //Log() << Verbose(3) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
     2719                  //Log() << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
    23832720                } else {
    2384                   //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
     2721                  //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
    23852722                }
    23862723              } else {
    2387                 //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
     2724                //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
    23882725              }
    23892726            } else {
    2390               //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
     2727              //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
    23912728            }
    23922729          }
    23932730        } else {
    2394           Log() << Verbose(3) << "Linked cell list is empty." << endl;
     2731          Log() << Verbose(0) << "Linked cell list is empty." << endl;
    23952732        }
    23962733      }
    2397   Log() << Verbose(2) << "End of FindSecondPointForTesselation" << endl;
    23982734};
    23992735
     
    24242760 * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
    24252761 * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
    2426  * @param BaseLine BoundaryLineSet with the current base line
     2762 * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
    24272763 * @param ThirdNode third point to avoid in search
    2428  * @param candidates list of equally good candidates to return
    2429  * @param ShortestAngle the current path length on this circle band for the current OptCandidate
    24302764 * @param RADIUS radius of sphere
    24312765 * @param *LC LinkedCell structure with neighbouring points
    24322766 */
    2433 void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, class BoundaryLineSet *BaseLine, const class TesselPoint  * const ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC) const
    2434 {
     2767void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const
     2768{
     2769        Info FunctionInfo(__func__);
    24352770  Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
    24362771  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
     
    24402775  Vector NewNormalVector;   // normal vector of the Candidate's triangle
    24412776  Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
     2777  Vector RelativeOldSphereCenter;
     2778  Vector NewPlaneCenter;
    24422779  double CircleRadius; // radius of this circle
    24432780  double radius;
     2781  double otherradius;
    24442782  double alpha, Otheralpha; // angles (i.e. parameter for the circle).
     2783  bool IsDegenerated;
    24452784  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
    24462785  TesselPoint *Candidate = NULL;
    2447   CandidateForTesselation *optCandidate = NULL;
    2448 
    2449   Log() << Verbose(1) << "Begin of FindThirdPointForTesselation" << endl;
    2450 
    2451   Log() << Verbose(2) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
     2786  TesselPoint *CandidateTriangle[3];
     2787
     2788  Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
    24522789
    24532790  // construct center of circle
    2454   CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node);
    2455   CircleCenter.AddVector(BaseLine->endpoints[1]->node->node);
     2791  CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     2792  CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    24562793  CircleCenter.Scale(0.5);
    24572794
    24582795  // construct normal vector of circle
    2459   CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node);
    2460   CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
     2796  CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     2797  CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     2798
     2799  RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
     2800  RelativeOldSphereCenter.SubtractVector(&CircleCenter);
     2801
     2802  CandidateTriangle[0] = CandidateLine.BaseLine->endpoints[0]->node;
     2803  CandidateTriangle[1] = CandidateLine.BaseLine->endpoints[1]->node;
    24612804
    24622805  // calculate squared radius TesselPoint *ThirdNode,f circle
    2463   radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    2464   if (radius/4. < RADIUS*RADIUS) {
    2465     CircleRadius = RADIUS*RADIUS - radius/4.;
     2806  radius = CirclePlaneNormal.NormSquared()/4.;
     2807  if (radius < RADIUS*RADIUS) {
     2808    CircleRadius = RADIUS*RADIUS - radius;
    24662809    CirclePlaneNormal.Normalize();
    2467     //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     2810    Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    24682811
    24692812    // test whether old center is on the band's plane
    2470     if (fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    2471       eLog() << Verbose(1) << "Something's very wrong here: OldSphereCenter is not on the band's plane as desired by " << fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
    2472       OldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
    2473     }
    2474     radius = OldSphereCenter.ScalarProduct(&OldSphereCenter);
     2813    if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
     2814      eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
     2815      RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
     2816    }
     2817    radius = RelativeOldSphereCenter.NormSquared();
    24752818    if (fabs(radius - CircleRadius) < HULLEPSILON) {
    2476       //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
     2819      Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl;
    24772820
    24782821      // check SearchDirection
    2479       //Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2480       if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {  // rotated the wrong way!
     2822      Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2823      if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {  // rotated the wrong way!
    24812824        eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl;
    24822825      }
     
    24862829        for(int i=0;i<NDIM;i++) // store indices of this cell
    24872830        N[i] = LC->n[i];
    2488         //Log() << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     2831        //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    24892832      } else {
    24902833        eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl;
     
    24922835      }
    24932836      // then go through the current and all neighbouring cells and check the contained points for possible candidates
    2494       //Log() << Verbose(2) << "LC Intervals:";
     2837      //Log() << Verbose(1) << "LC Intervals:";
    24952838      for (int i=0;i<NDIM;i++) {
    24962839        Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
     
    25032846          for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    25042847            const LinkedNodes *List = LC->GetCurrentCell();
    2505             //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     2848            //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    25062849            if (List != NULL) {
    25072850              for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     
    25092852
    25102853                // check for three unique points
    2511                 //Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " at " << Candidate->node << "." << endl;
    2512                 if ((Candidate != BaseLine->endpoints[0]->node) && (Candidate != BaseLine->endpoints[1]->node) ){
    2513 
    2514                   // construct both new centers
    2515                   GetCenterofCircumcircle(&NewSphereCenter, *BaseLine->endpoints[0]->node->node, *BaseLine->endpoints[1]->node->node, *Candidate->node);
    2516                   OtherNewSphereCenter.CopyVector(&NewSphereCenter);
    2517 
    2518                   if ((NewNormalVector.MakeNormalVector(BaseLine->endpoints[0]->node->node, BaseLine->endpoints[1]->node->node, Candidate->node))
    2519                   && (fabs(NewNormalVector.ScalarProduct(&NewNormalVector)) > HULLEPSILON)
     2854                Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl;
     2855                if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node) ){
     2856
     2857                  // find center on the plane
     2858                  GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
     2859                  Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl;
     2860
     2861                  if ((NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node))
     2862                  && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)
    25202863                  ) {
    2521                     helper.CopyVector(&NewNormalVector);
    2522                     //Log() << Verbose(2) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
    2523                     radius = BaseLine->endpoints[0]->node->node->DistanceSquared(&NewSphereCenter);
     2864                    Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
     2865                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
     2866                    Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     2867                    Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2868                    Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl;
    25242869                    if (radius < RADIUS*RADIUS) {
     2870                      otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
     2871                      if (fabs(radius - otherradius) > HULLEPSILON) {
     2872                        eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl;
     2873                      }
     2874                      // construct both new centers
     2875                      NewSphereCenter.CopyVector(&NewPlaneCenter);
     2876                      OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
     2877                      helper.CopyVector(&NewNormalVector);
    25252878                      helper.Scale(sqrt(RADIUS*RADIUS - radius));
    2526                       //Log() << Verbose(2) << "INFO: Distance of NewCircleCenter to NewSphereCenter is " << helper.Norm() << " with sphere radius " << RADIUS << "." << endl;
     2879                      Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl;
    25272880                      NewSphereCenter.AddVector(&helper);
    2528                       NewSphereCenter.SubtractVector(&CircleCenter);
    2529                       //Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
    2530 
     2881                      Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
    25312882                      // OtherNewSphereCenter is created by the same vector just in the other direction
    25322883                      helper.Scale(-1.);
    25332884                      OtherNewSphereCenter.AddVector(&helper);
    2534                       OtherNewSphereCenter.SubtractVector(&CircleCenter);
    2535                       //Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
     2885                      Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
    25362886
    25372887                      alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    25382888                      Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    25392889                      alpha = min(alpha, Otheralpha);
    2540                       // if there is a better candidate, drop the current list and add the new candidate
    2541                       // otherwise ignore the new candidate and keep the list
    2542                       if (*ShortestAngle > (alpha - HULLEPSILON)) {
    2543                         optCandidate = new CandidateForTesselation(Candidate, BaseLine, OptCandidateCenter, OtherOptCandidateCenter);
    2544                         if (fabs(alpha - Otheralpha) > MYEPSILON) {
    2545                           optCandidate->OptCenter.CopyVector(&NewSphereCenter);
    2546                           optCandidate->OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     2890
     2891                      CandidateTriangle[2] = Candidate;
     2892                      // the idea of the IsDegenerated flag is not to put a penalty on degenerated triangles, but to push them to the
     2893                      // very end of the Tesselation::OpenLines list.
     2894                      IsDegenerated = (CheckPresenceOfTriangle(CandidateTriangle) >= 3);
     2895                      if (!IsDegenerated && CandidateLine.IsDegenerated) {  // if current is not, but old one was, comparison would be unfair
     2896                        // if there is a better candidate, drop the current list and add the new candidate
     2897                        // otherwise ignore the new candidate and keep the list
     2898                        if (CandidateLine.ShortestAngle-2.*M_PI > (alpha - HULLEPSILON)) {
     2899                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
     2900                            CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
     2901                            CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     2902                          } else {
     2903                            CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
     2904                            CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     2905                          }
     2906                          // if there is an equal candidate, add it to the list without clearing the list
     2907                          if ((CandidateLine.ShortestAngle-2.*M_PI - HULLEPSILON) < alpha) {
     2908                            CandidateLine.pointlist.push_back(Candidate);
     2909                            Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
     2910                              << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2911                          } else {
     2912                            // remove all candidates from the list and then the list itself
     2913                            CandidateLine.pointlist.clear();
     2914                            CandidateLine.pointlist.push_back(Candidate);
     2915                            Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
     2916                              << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2917                          }
     2918                          CandidateLine.ShortestAngle = alpha;
     2919                          CandidateLine.IsDegenerated = IsDegenerated;
     2920                          if (IsDegenerated)
     2921                            CandidateLine.ShortestAngle += 2.*M_PI;
     2922                          Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
    25472923                        } else {
    2548                           optCandidate->OptCenter.CopyVector(&OtherNewSphereCenter);
    2549                           optCandidate->OtherOptCenter.CopyVector(&NewSphereCenter);
     2924                          if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
     2925                            Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
     2926                          } else {
     2927                            Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
     2928                          }
    25502929                        }
    2551                         // if there is an equal candidate, add it to the list without clearing the list
    2552                         if ((*ShortestAngle - HULLEPSILON) < alpha) {
    2553                           candidates->push_back(optCandidate);
    2554                           Log() << Verbose(2) << "ACCEPT: We have found an equally good candidate: " << *(optCandidate->point) << " with "
    2555                             << alpha << " and circumsphere's center at " << optCandidate->OptCenter << "." << endl;
     2930                      } else {
     2931                        // if there is a better candidate, drop the current list and add the new candidate
     2932                        // otherwise ignore the new candidate and keep the list
     2933                        if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
     2934                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
     2935                            CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
     2936                            CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     2937                          } else {
     2938                            CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
     2939                            CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     2940                          }
     2941                          // if there is an equal candidate, add it to the list without clearing the list
     2942                          if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
     2943                            CandidateLine.pointlist.push_back(Candidate);
     2944                            Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
     2945                              << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2946                          } else {
     2947                            // remove all candidates from the list and then the list itself
     2948                            CandidateLine.pointlist.clear();
     2949                            CandidateLine.pointlist.push_back(Candidate);
     2950                            Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
     2951                              << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2952                          }
     2953                          CandidateLine.ShortestAngle = alpha;
     2954                          Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
    25562955                        } else {
    2557                           // remove all candidates from the list and then the list itself
    2558                           class CandidateForTesselation *remover = NULL;
    2559                           for (CandidateList::iterator it = candidates->begin(); it != candidates->end(); ++it) {
    2560                             remover = *it;
    2561                             delete(remover);
     2956                          if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
     2957                            Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
     2958                          } else {
     2959                            Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
    25622960                          }
    2563                           candidates->clear();
    2564                           candidates->push_back(optCandidate);
    2565                           Log() << Verbose(2) << "ACCEPT: We have found a better candidate: " << *(optCandidate->point) << " with "
    2566                             << alpha << " and circumsphere's center at " << optCandidate->OptCenter << "." << endl;
    2567                         }
    2568                         *ShortestAngle = alpha;
    2569                         //Log() << Verbose(2) << "INFO: There are " << candidates->size() << " candidates in the list now." << endl;
    2570                       } else {
    2571                         if ((optCandidate != NULL) && (optCandidate->point != NULL)) {
    2572                           //Log() << Verbose(2) << "REJECT: Old candidate " << *(optCandidate->point) << " with " << *ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
    2573                         } else {
    2574                           //Log() << Verbose(2) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
    25752961                        }
    25762962                      }
    25772963
    25782964                    } else {
    2579                       //Log() << Verbose(2) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
     2965                      Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
    25802966                    }
    25812967                  } else {
    2582                     //Log() << Verbose(2) << "REJECT: Three points from " << *BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
     2968                    Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
    25832969                  }
    25842970                } else {
    25852971                  if (ThirdNode != NULL) {
    2586                     //Log() << Verbose(2) << "REJECT: Base triangle " << *BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
     2972                    Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
    25872973                  } else {
    2588                     //Log() << Verbose(2) << "REJECT: Base triangle " << *BaseLine << " contains Candidate " << *Candidate << "." << endl;
     2974                    Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl;
    25892975                  }
    25902976                }
     
    25972983  } else {
    25982984    if (ThirdNode != NULL)
    2599       Log() << Verbose(2) << "Circumcircle for base line " << *BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
     2985      Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
    26002986    else
    2601       Log() << Verbose(2) << "Circumcircle for base line " << *BaseLine << " is too big!" << endl;
    2602   }
    2603 
    2604   //Log() << Verbose(2) << "INFO: Sorting candidate list ..." << endl;
    2605   if (candidates->size() > 1) {
    2606     candidates->unique();
    2607     candidates->sort(SortCandidates);
    2608   }
    2609 
    2610   Log() << Verbose(1) << "End of FindThirdPointForTesselation" << endl;
     2987      Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl;
     2988  }
     2989
     2990  Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl;
     2991  if (CandidateLine.pointlist.size() > 1) {
     2992    CandidateLine.pointlist.unique();
     2993    CandidateLine.pointlist.sort(); //SortCandidates);
     2994  }
    26112995};
    26122996
     
    26183002class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
    26193003{
     3004        Info FunctionInfo(__func__);
    26203005  const BoundaryLineSet * lines[2] = { line1, line2 };
    26213006  class BoundaryPointSet *node = NULL;
     
    26313016          { // if insertion fails, we have common endpoint
    26323017            node = OrderTest.first->second;
    2633             Log() << Verbose(5) << "Common endpoint of lines " << *line1
     3018            Log() << Verbose(1) << "Common endpoint of lines " << *line1
    26343019                << " and " << *line2 << " is: " << *node << "." << endl;
    26353020            j = 2;
     
    26483033list<BoundaryTriangleSet*> * Tesselation::FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const
    26493034{
     3035        Info FunctionInfo(__func__);
    26503036  TesselPoint *trianglePoints[3];
    26513037  TesselPoint *SecondPoint = NULL;
     
    26533039
    26543040  if (LinesOnBoundary.empty()) {
    2655     Log() << Verbose(0) << "Error: There is no tesselation structure to compare the point with, please create one first.";
     3041    eLog() << Verbose(1) << "Error: There is no tesselation structure to compare the point with, please create one first.";
    26563042    return NULL;
    26573043  }
     
    26613047  // check whether closest point is "too close" :), then it's inside
    26623048  if (trianglePoints[0] == NULL) {
    2663     Log() << Verbose(2) << "Is the only point, no one else is closeby." << endl;
     3049    Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
    26643050    return NULL;
    26653051  }
    26663052  if (trianglePoints[0]->node->DistanceSquared(x) < MYEPSILON) {
    2667     Log() << Verbose(3) << "Point is right on a tesselation point, no nearest triangle." << endl;
     3053    Log() << Verbose(1) << "Point is right on a tesselation point, no nearest triangle." << endl;
    26683054    PointMap::const_iterator PointRunner = PointsOnBoundary.find(trianglePoints[0]->nr);
    26693055    triangles = new list<BoundaryTriangleSet*>;
     
    26893075    }
    26903076  } else {
    2691     list<TesselPoint*> *connectedClosestPoints = GetCircleOfConnectedPoints(trianglePoints[0], x);
     3077    set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(trianglePoints[0]);
     3078    TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(connectedPoints, trianglePoints[0], x);
     3079    delete(connectedPoints);
    26923080    if (connectedClosestPoints != NULL) {
    26933081      trianglePoints[1] = connectedClosestPoints->front();
     
    26973085          eLog() << Verbose(1) << "IsInnerPoint encounters serious error, point " << i << " not found." << endl;
    26983086        }
    2699         //Log() << Verbose(2) << "List of triangle points:" << endl;
    2700         //Log() << Verbose(3) << *trianglePoints[i] << endl;
     3087        //Log() << Verbose(1) << "List of triangle points:" << endl;
     3088        //Log() << Verbose(2) << *trianglePoints[i] << endl;
    27013089      }
    27023090
    27033091      triangles = FindTriangles(trianglePoints);
    2704       Log() << Verbose(2) << "List of possible triangles:" << endl;
     3092      Log() << Verbose(1) << "List of possible triangles:" << endl;
    27053093      for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    2706         Log() << Verbose(3) << **Runner << endl;
     3094        Log() << Verbose(2) << **Runner << endl;
    27073095
    27083096      delete(connectedClosestPoints);
    27093097    } else {
    27103098      triangles = NULL;
    2711       Log() << Verbose(1) << "There is no circle of connected points!" << endl;
     3099      eLog() << Verbose(2) << "There is no circle of connected points!" << endl;
    27123100    }
    27133101  }
     
    27293117class BoundaryTriangleSet * Tesselation::FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const
    27303118{
     3119        Info FunctionInfo(__func__);
    27313120  class BoundaryTriangleSet *result = NULL;
    27323121  list<BoundaryTriangleSet*> *triangles = FindClosestTrianglesToPoint(x, LC);
     
    27383127  if (triangles->size() == 1) { // there is no degenerate case
    27393128    result = triangles->front();
    2740     Log() << Verbose(2) << "Normal Vector of this triangle is " << result->NormalVector << "." << endl;
     3129    Log() << Verbose(1) << "Normal Vector of this triangle is " << result->NormalVector << "." << endl;
    27413130  } else {
    27423131    result = triangles->front();
    27433132    result->GetCenter(&Center);
    27443133    Center.SubtractVector(x);
    2745     Log() << Verbose(2) << "Normal Vector of this front side is " << result->NormalVector << "." << endl;
     3134    Log() << Verbose(1) << "Normal Vector of this front side is " << result->NormalVector << "." << endl;
    27463135    if (Center.ScalarProduct(&result->NormalVector) < 0) {
    27473136      result = triangles->back();
    2748       Log() << Verbose(2) << "Normal Vector of this back side is " << result->NormalVector << "." << endl;
     3137      Log() << Verbose(1) << "Normal Vector of this back side is " << result->NormalVector << "." << endl;
    27493138      if (Center.ScalarProduct(&result->NormalVector) < 0) {
    27503139        eLog() << Verbose(1) << "Front and back side yield NormalVector in wrong direction!" << endl;
     
    27653154bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
    27663155{
     3156        Info FunctionInfo(__func__);
    27673157  class BoundaryTriangleSet *result = FindClosestTriangleToPoint(&Point, LC);
    27683158  Vector Center;
     
    27743164
    27753165  result->GetCenter(&Center);
    2776   Log() << Verbose(3) << "INFO: Central point of the triangle is " << Center << "." << endl;
     3166  Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
    27773167  Center.SubtractVector(&Point);
    2778   Log() << Verbose(3) << "INFO: Vector from center to point to test is " << Center << "." << endl;
     3168  Log() << Verbose(2) << "INFO: Vector from center to point to test is " << Center << "." << endl;
    27793169  if (Center.ScalarProduct(&result->NormalVector) > -MYEPSILON) {
    27803170    Log() << Verbose(1) << Point << " is an inner point." << endl;
     
    27953185bool Tesselation::IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const
    27963186{
     3187        Info FunctionInfo(__func__);
    27973188  return IsInnerPoint(*(Point->node), LC);
    27983189}
     
    28063197set<TesselPoint*> * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    28073198{
     3199        Info FunctionInfo(__func__);
    28083200  set<TesselPoint*> *connectedPoints = new set<TesselPoint*>;
    28093201  class BoundaryPointSet *ReferencePoint = NULL;
    28103202  TesselPoint* current;
    28113203  bool takePoint = false;
    2812 
    2813   Log() << Verbose(3) << "Begin of GetAllConnectedPoints" << endl;
    28143204
    28153205  // find the respective boundary point
     
    28183208    ReferencePoint = PointRunner->second;
    28193209  } else {
    2820     Log() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
     3210    eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
    28213211    ReferencePoint = NULL;
    28223212  }
     
    28423232
    28433233   if (takePoint) {
    2844      Log() << Verbose(5) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
     3234     Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
    28453235     connectedPoints->insert(current);
    28463236   }
     
    28543244  }
    28553245
    2856   Log() << Verbose(3) << "End of GetAllConnectedPoints" << endl;
    28573246  return connectedPoints;
    28583247};
     
    28663255 *
    28673256 * @param *out output stream for debugging
     3257 * @param *SetOfNeighbours all points for which the angle should be calculated
    28683258 * @param *Point of which get all connected points
    28693259 * @param *Reference Reference vector for zero angle or NULL for no preference
    28703260 * @return list of the all points linked to the provided one
    28713261 */
    2872 list<TesselPoint*> * Tesselation::GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference) const
    2873 {
     3262list<TesselPoint*> * Tesselation::GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
     3263{
     3264        Info FunctionInfo(__func__);
    28743265  map<double, TesselPoint*> anglesOfPoints;
    2875   set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(Point);
    28763266  list<TesselPoint*> *connectedCircle = new list<TesselPoint*>;
    28773267  Vector center;
     
    28813271  Vector helper;
    28823272
    2883   if (connectedPoints == NULL) {
    2884     Log() << Verbose(2) << "Could not find any connected points!" << endl;
     3273  if (SetOfNeighbours == NULL) {
     3274    eLog() << Verbose(2) << "Could not find any connected points!" << endl;
    28853275    delete(connectedCircle);
    28863276    return NULL;
    28873277  }
    2888   Log() << Verbose(2) << "Begin of GetCircleOfConnectedPoints" << endl;
    28893278
    28903279  // calculate central point
    2891   for (set<TesselPoint*>::const_iterator TesselRunner = connectedPoints->begin(); TesselRunner != connectedPoints->end(); TesselRunner++)
     3280  for (set<TesselPoint*>::const_iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
    28923281    center.AddVector((*TesselRunner)->node);
    28933282  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
    28943283  //  << "; scale factor " << 1.0/connectedPoints.size();
    2895   center.Scale(1.0/connectedPoints->size());
    2896   Log() << Verbose(4) << "INFO: Calculated center of all circle points is " << center << "." << endl;
     3284  center.Scale(1.0/SetOfNeighbours->size());
     3285  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
    28973286
    28983287  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
     
    29003289  PlaneNormal.SubtractVector(&center);
    29013290  PlaneNormal.Normalize();
    2902   Log() << Verbose(4) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
     3291  Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
    29033292
    29043293  // construct one orthogonal vector
     
    29093298  }
    29103299  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    2911     Log() << Verbose(4) << "Using alternatively " << *(*connectedPoints->begin())->node << " as angle 0 referencer." << endl;
    2912     AngleZero.CopyVector((*connectedPoints->begin())->node);
     3300    Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
     3301    AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    29133302    AngleZero.SubtractVector(Point->node);
    29143303    AngleZero.ProjectOntoPlane(&PlaneNormal);
     
    29183307    }
    29193308  }
    2920   Log() << Verbose(4) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
     3309  Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
    29213310  if (AngleZero.NormSquared() > MYEPSILON)
    29223311    OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
    29233312  else
    29243313    OrthogonalVector.MakeNormalVector(&PlaneNormal);
    2925   Log() << Verbose(4) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
     3314  Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
    29263315
    29273316  // go through all connected points and calculate angle
    2928   for (set<TesselPoint*>::iterator listRunner = connectedPoints->begin(); listRunner != connectedPoints->end(); listRunner++) {
     3317  for (set<TesselPoint*>::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    29293318    helper.CopyVector((*listRunner)->node);
    29303319    helper.SubtractVector(Point->node);
    29313320    helper.ProjectOntoPlane(&PlaneNormal);
    29323321    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    2933     Log() << Verbose(3) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
     3322    Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
    29343323    anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
    29353324  }
     
    29383327    connectedCircle->push_back(AngleRunner->second);
    29393328  }
    2940 
    2941   delete(connectedPoints);
    2942 
    2943   Log() << Verbose(2) << "End of GetCircleOfConnectedPoints" << endl;
    29443329
    29453330  return connectedCircle;
     
    29543339list<list<TesselPoint*> *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    29553340{
     3341        Info FunctionInfo(__func__);
    29563342  map<double, TesselPoint*> anglesOfPoints;
    29573343  list<list<TesselPoint*> *> *ListOfPaths = new list<list<TesselPoint*> *>;
     
    29983384        StartLine = CurrentLine;
    29993385        CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
    3000         Log() << Verbose(3)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
     3386        Log() << Verbose(1)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
    30013387        do {
    30023388          // push current one
    3003           Log() << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     3389          Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
    30043390          connectedPath->push_back(CurrentPoint->node);
    30053391
    30063392          // find next triangle
    30073393          for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
    3008             Log() << Verbose(3) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
     3394            Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
    30093395            if ((Runner->second != triangle)) { // look for first triangle not equal to old one
    30103396              triangle = Runner->second;
     
    30133399                if (!TriangleRunner->second) {
    30143400                  TriangleRunner->second = true;
    3015                   Log() << Verbose(3) << "INFO: Connecting triangle is " << *triangle << "." << endl;
     3401                  Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl;
    30163402                  break;
    30173403                } else {
    3018                   Log() << Verbose(3) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
     3404                  Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
    30193405                  triangle = NULL;
    30203406                }
     
    30313417            if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
    30323418              CurrentLine = triangle->lines[i];
    3033               Log() << Verbose(3) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
     3419              Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
    30343420              break;
    30353421            }
     
    30453431        } while (CurrentLine != StartLine);
    30463432        // last point is missing, as it's on start line
    3047         Log() << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     3433        Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
    30483434        if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
    30493435          connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
     
    30513437        ListOfPaths->push_back(connectedPath);
    30523438      } else {
    3053         Log() << Verbose(3) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
     3439        Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
    30543440      }
    30553441    }
     
    30693455list<list<TesselPoint*> *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    30703456{
     3457        Info FunctionInfo(__func__);
    30713458  list<list<TesselPoint*> *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    30723459  list<list<TesselPoint*> *> *ListofClosedPaths = new list<list<TesselPoint*> *>;
     
    30823469    connectedPath = *ListRunner;
    30833470
    3084     Log() << Verbose(2) << "INFO: Current path is " << connectedPath << "." << endl;
     3471    Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl;
    30853472
    30863473    // go through list, look for reappearance of starting Point and count
     
    30923479      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    30933480        // we have a closed circle from Marker to new Marker
    3094         Log() << Verbose(3) << count+1 << ". closed path consists of: ";
     3481        Log() << Verbose(1) << count+1 << ". closed path consists of: ";
    30953482        newPath = new list<TesselPoint*>;
    30963483        list<TesselPoint*>::iterator CircleSprinter = Marker;
     
    31083495    }
    31093496  }
    3110   Log() << Verbose(3) << "INFO: " << count << " closed additional path(s) have been created." << endl;
     3497  Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl;
    31113498
    31123499  // delete list of paths
     
    31303517set<BoundaryTriangleSet*> *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    31313518{
     3519        Info FunctionInfo(__func__);
    31323520  set<BoundaryTriangleSet*> *connectedTriangles = new set<BoundaryTriangleSet*>;
    31333521
     
    31683556    return 0.;
    31693557  } else
    3170     Log() << Verbose(2) << "Removing point " << *point << " from tesselated boundary ..." << endl;
     3558    Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl;
    31713559
    31723560  // copy old location for the volume
     
    31983586  NormalVector.Zero();
    31993587  for (map<class BoundaryTriangleSet *, int>::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    3200     Log() << Verbose(3) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
     3588    Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
    32013589    NormalVector.SubtractVector(&Runner->first->NormalVector); // has to point inward
    32023590    RemoveTesselationTriangle(Runner->first);
     
    32283616        smallestangle = 0.;
    32293617        for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
    3230           Log() << Verbose(3) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
     3618          Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
    32313619          // construct vectors to next and previous neighbour
    32323620          StartNode = MiddleNode;
     
    32563644        MiddleNode = EndNode;
    32573645        if (MiddleNode == connectedPath->end()) {
    3258           Log() << Verbose(1) << "CRITICAL: Could not find a smallest angle!" << endl;
    3259           exit(255);
     3646          eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl;
     3647          performCriticalExit();
    32603648        }
    32613649        StartNode = MiddleNode;
     
    32663654        if (EndNode == connectedPath->end())
    32673655          EndNode = connectedPath->begin();
    3268         Log() << Verbose(4) << "INFO: StartNode is " << **StartNode << "." << endl;
    3269         Log() << Verbose(4) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
    3270         Log() << Verbose(4) << "INFO: EndNode is " << **EndNode << "." << endl;
    3271         Log() << Verbose(3) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;
     3656        Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl;
     3657        Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
     3658        Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl;
     3659        Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;
    32723660        TriangleCandidates[0] = *StartNode;
    32733661        TriangleCandidates[1] = *MiddleNode;
     
    32753663        triangle = GetPresentTriangle(TriangleCandidates);
    32763664        if (triangle != NULL) {
    3277           eLog() << Verbose(2) << "New triangle already present, skipping!" << endl;
     3665          eLog() << Verbose(0) << "New triangle already present, skipping!" << endl;
    32783666          StartNode++;
    32793667          MiddleNode++;
     
    32873675          continue;
    32883676        }
    3289         Log() << Verbose(5) << "Adding new triangle points."<< endl;
     3677        Log() << Verbose(3) << "Adding new triangle points."<< endl;
    32903678        AddTesselationPoint(*StartNode, 0);
    32913679        AddTesselationPoint(*MiddleNode, 1);
    32923680        AddTesselationPoint(*EndNode, 2);
    3293         Log() << Verbose(5) << "Adding new triangle lines."<< endl;
     3681        Log() << Verbose(3) << "Adding new triangle lines."<< endl;
    32943682        AddTesselationLine(TPS[0], TPS[1], 0);
    32953683        AddTesselationLine(TPS[0], TPS[2], 1);
     
    33063694        // prepare nodes for next triangle
    33073695        StartNode = EndNode;
    3308         Log() << Verbose(4) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
     3696        Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
    33093697        connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
    33103698        if (connectedPath->size() == 2) { // we are done
     
    33133701          break;
    33143702        } else if (connectedPath->size() < 2) { // something's gone wrong!
    3315           Log() << Verbose(1) << "CRITICAL: There are only two endpoints left!" << endl;
    3316           exit(255);
     3703          eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl;
     3704          performCriticalExit();
    33173705        } else {
    33183706          MiddleNode = StartNode;
     
    33423730          if (maxgain != 0) {
    33433731            volume += maxgain;
    3344             Log() << Verbose(3) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
     3732            Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
    33453733            OtherBase = FlipBaseline(*Candidate);
    33463734            NewLines.erase(Candidate);
     
    33533741      delete(connectedPath);
    33543742    }
    3355     Log() << Verbose(1) << count << " triangles were created." << endl;
     3743    Log() << Verbose(0) << count << " triangles were created." << endl;
    33563744  } else {
    33573745    while (!ListOfClosedPaths->empty()) {
     
    33613749      delete(connectedPath);
    33623750    }
    3363     Log() << Verbose(1) << "No need to create any triangles." << endl;
     3751    Log() << Verbose(0) << "No need to create any triangles." << endl;
    33643752  }
    33653753  delete(ListOfClosedPaths);
    33663754
    3367   Log() << Verbose(1) << "Removed volume is " << volume << "." << endl;
     3755  Log() << Verbose(0) << "Removed volume is " << volume << "." << endl;
    33683756
    33693757  return volume;
     
    33823770list<BoundaryTriangleSet*> *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    33833771{
     3772        Info FunctionInfo(__func__);
    33843773  list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;
    33853774  LineMap::const_iterator FindLine;
     
    34223811}
    34233812
     3813struct BoundaryLineSetCompare {
     3814  bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) {
     3815    int lowerNra = -1;
     3816    int lowerNrb = -1;
     3817
     3818    if (a->endpoints[0] < a->endpoints[1])
     3819      lowerNra = 0;
     3820    else
     3821      lowerNra = 1;
     3822
     3823    if (b->endpoints[0] < b->endpoints[1])
     3824      lowerNrb = 0;
     3825    else
     3826      lowerNrb = 1;
     3827
     3828    if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
     3829      return true;
     3830    else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
     3831      return false;
     3832    else {  // both lower-numbered endpoints are the same ...
     3833     if (a->endpoints[(lowerNra+1)%2] < b->endpoints[(lowerNrb+1)%2])
     3834       return true;
     3835     else if (a->endpoints[(lowerNra+1)%2] > b->endpoints[(lowerNrb+1)%2])
     3836       return false;
     3837    }
     3838    return false;
     3839  };
     3840};
     3841
     3842#define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
     3843
    34243844/**
    34253845 * Finds all degenerated lines within the tesselation structure.
     
    34303850map<int, int> * Tesselation::FindAllDegeneratedLines()
    34313851{
    3432   map<int, class BoundaryLineSet *> AllLines;
     3852        Info FunctionInfo(__func__);
     3853        UniqueLines AllLines;
    34333854  map<int, int> * DegeneratedLines = new map<int, int>;
    34343855
    34353856  // sanity check
    34363857  if (LinesOnBoundary.empty()) {
    3437     Log() << Verbose(1) << "Warning: FindAllDegeneratedTriangles() was called without any tesselation structure.";
     3858    eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.";
    34383859    return DegeneratedLines;
    34393860  }
    34403861
    34413862  LineMap::iterator LineRunner1;
    3442   pair<LineMap::iterator, bool> tester;
     3863  pair< UniqueLines::iterator, bool> tester;
    34433864  for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
    3444     tester = AllLines.insert( pair<int,BoundaryLineSet *> (LineRunner1->second->endpoints[0]->Nr, LineRunner1->second) );
    3445     if ((!tester.second) && (tester.first->second->endpoints[1]->Nr == LineRunner1->second->endpoints[1]->Nr)) { // found degenerated line
    3446       DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, tester.first->second->Nr) );
    3447       DegeneratedLines->insert ( pair<int, int> (tester.first->second->Nr, LineRunner1->second->Nr) );
     3865    tester = AllLines.insert( LineRunner1->second );
     3866    if (!tester.second) { // found degenerated line
     3867      DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr) );
     3868      DegeneratedLines->insert ( pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr) );
    34483869    }
    34493870  }
     
    34513872  AllLines.clear();
    34523873
    3453   Log() << Verbose(1) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
     3874  Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
    34543875  map<int,int>::iterator it;
    3455   for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++)
    3456       Log() << Verbose(2) << (*it).first << " => " << (*it).second << endl;
     3876  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
     3877    const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
     3878    const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
     3879    if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
     3880      Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl;
     3881    else
     3882      eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl;
     3883  }
    34573884
    34583885  return DegeneratedLines;
     
    34673894map<int, int> * Tesselation::FindAllDegeneratedTriangles()
    34683895{
     3896        Info FunctionInfo(__func__);
    34693897  map<int, int> * DegeneratedLines = FindAllDegeneratedLines();
    34703898  map<int, int> * DegeneratedTriangles = new map<int, int>;
     
    34943922  delete(DegeneratedLines);
    34953923
    3496   Log() << Verbose(1) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
     3924  Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
    34973925  map<int,int>::iterator it;
    34983926  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    3499       Log() << Verbose(2) << (*it).first << " => " << (*it).second << endl;
     3927      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
    35003928
    35013929  return DegeneratedTriangles;
     
    35083936void Tesselation::RemoveDegeneratedTriangles()
    35093937{
     3938        Info FunctionInfo(__func__);
    35103939  map<int, int> * DegeneratedTriangles = FindAllDegeneratedTriangles();
    35113940  TriangleMap::iterator finder;
    35123941  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    35133942  int count  = 0;
    3514 
    3515   Log() << Verbose(1) << "Begin of RemoveDegeneratedTriangles" << endl;
    35163943
    35173944  for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
     
    35723999      // erase the pair
    35734000      count += (int) DegeneratedTriangles->erase(triangle->Nr);
    3574       Log() << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
     4001      Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
    35754002      RemoveTesselationTriangle(triangle);
    35764003      count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
    3577       Log() << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
     4004      Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
    35784005      RemoveTesselationTriangle(partnerTriangle);
    35794006    } else {
    3580       Log() << Verbose(1) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
     4007      Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
    35814008        << " and its partner " << *partnerTriangle << " because it is essential for at"
    35824009        << " least one of the endpoints to be kept in the tesselation structure." << endl;
     
    35844011  }
    35854012  delete(DegeneratedTriangles);
    3586 
    3587   Log() << Verbose(1) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
    3588   Log() << Verbose(1) << "End of RemoveDegeneratedTriangles" << endl;
     4013  if (count > 0)
     4014    LastTriangle = NULL;
     4015
     4016  Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
    35894017}
    35904018
     
    35994027void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
    36004028{
    3601   Log() << Verbose(2) << "Begin of AddBoundaryPointByDegeneratedTriangle" << endl;
    3602 
     4029        Info FunctionInfo(__func__);
    36034030  // find nearest boundary point
    36044031  class TesselPoint *BackupPoint = NULL;
     
    36164043    return;
    36174044  }
    3618   Log() << Verbose(2) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
     4045  Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
    36194046
    36204047  // go through its lines and find the best one to split
     
    36494076
    36504077  // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
    3651   Log() << Verbose(5) << "Adding new triangle points."<< endl;
     4078  Log() << Verbose(2) << "Adding new triangle points."<< endl;
    36524079  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    36534080  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    36544081  AddTesselationPoint(point, 2);
    3655   Log() << Verbose(5) << "Adding new triangle lines."<< endl;
     4082  Log() << Verbose(2) << "Adding new triangle lines."<< endl;
    36564083  AddTesselationLine(TPS[0], TPS[1], 0);
    36574084  AddTesselationLine(TPS[0], TPS[2], 1);
     
    36604087  BTS->GetNormalVector(TempTriangle->NormalVector);
    36614088  BTS->NormalVector.Scale(-1.);
    3662   Log() << Verbose(3) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
     4089  Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
    36634090  AddTesselationTriangle();
    36644091
    36654092  // create other side of this triangle and close both new sides of the first created triangle
    3666   Log() << Verbose(5) << "Adding new triangle points."<< endl;
     4093  Log() << Verbose(2) << "Adding new triangle points."<< endl;
    36674094  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    36684095  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    36694096  AddTesselationPoint(point, 2);
    3670   Log() << Verbose(5) << "Adding new triangle lines."<< endl;
     4097  Log() << Verbose(2) << "Adding new triangle lines."<< endl;
    36714098  AddTesselationLine(TPS[0], TPS[1], 0);
    36724099  AddTesselationLine(TPS[0], TPS[2], 1);
     
    36744101  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    36754102  BTS->GetNormalVector(TempTriangle->NormalVector);
    3676   Log() << Verbose(3) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
     4103  Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
    36774104  AddTesselationTriangle();
    36784105
     
    36814108    if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
    36824109      if (BestLine == BTS->lines[i]){
    3683         Log() << Verbose(1) << "CRITICAL: BestLine is same as found line, something's wrong here!" << endl;
    3684         exit(255);
     4110        eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl;
     4111        performCriticalExit();
    36854112      }
    36864113      BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle) );
     
    36894116    }
    36904117  }
    3691 
    3692   // exit
    3693   Log() << Verbose(2) << "End of AddBoundaryPointByDegeneratedTriangle" << endl;
    36944118};
    36954119
     
    37014125void Tesselation::Output(const char *filename, const PointCloud * const cloud)
    37024126{
     4127        Info FunctionInfo(__func__);
    37034128  ofstream *tempstream = NULL;
    37044129  string NameofTempFile;
     
    37134138      NameofTempFile.erase(npos, 1);
    37144139      NameofTempFile.append(TecplotSuffix);
    3715       Log() << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     4140      Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
    37164141      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    37174142      WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
     
    37274152      NameofTempFile.erase(npos, 1);
    37284153      NameofTempFile.append(Raster3DSuffix);
    3729       Log() << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     4154      Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
    37304155      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    37314156      WriteRaster3dFile(tempstream, this, cloud);
     
    37394164    TriangleFilesWritten++;
    37404165};
     4166
     4167struct BoundaryPolygonSetCompare {
     4168  bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const {
     4169    if (s1->endpoints.size() < s2->endpoints.size())
     4170      return true;
     4171    else if (s1->endpoints.size() > s2->endpoints.size())
     4172      return false;
     4173    else { // equality of number of endpoints
     4174      PointSet::const_iterator Walker1 = s1->endpoints.begin();
     4175      PointSet::const_iterator Walker2 = s2->endpoints.begin();
     4176      while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
     4177        if ((*Walker1)->Nr < (*Walker2)->Nr)
     4178          return true;
     4179        else if ((*Walker1)->Nr > (*Walker2)->Nr)
     4180          return false;
     4181        Walker1++;
     4182        Walker2++;
     4183      }
     4184      return false;
     4185    }
     4186  }
     4187};
     4188
     4189#define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
     4190
     4191/** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
     4192 * \return number of polygons found
     4193 */
     4194int Tesselation::CorrectAllDegeneratedPolygons()
     4195{
     4196  Info FunctionInfo(__func__);
     4197
     4198  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
     4199  map <int, int> *DegeneratedTriangles = FindAllDegeneratedTriangles();
     4200  set < BoundaryPointSet *> EndpointCandidateList;
     4201  pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
     4202  pair < map < int, Vector *>::iterator, bool > TriangleInsertionTester;
     4203  for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
     4204    Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl;
     4205    map < int, Vector *> TriangleVectors;
     4206    // gather all NormalVectors
     4207    Log() << Verbose(1) << "Gathering triangles ..." << endl;
     4208    for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
     4209      for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
     4210        if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
     4211          TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) );
     4212          if (TriangleInsertionTester.second)
     4213            Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;
     4214        } else {
     4215          Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl;
     4216        }
     4217      }
     4218    // check whether there are two that are parallel
     4219    Log() << Verbose(1) << "Finding two parallel triangles ..." << endl;
     4220    for (map < int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
     4221      for (map < int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
     4222        if (VectorWalker != VectorRunner) { // skip equals
     4223          const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second);  // ScalarProduct should result in -1. for degenerated triangles
     4224          Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl;
     4225          if (fabs(SCP + 1.) < ParallelEpsilon) {
     4226            InsertionTester = EndpointCandidateList.insert((Runner->second));
     4227            if (InsertionTester.second)
     4228              Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl;
     4229            // and break out of both loops
     4230            VectorWalker = TriangleVectors.end();
     4231            VectorRunner = TriangleVectors.end();
     4232            break;
     4233          }
     4234        }
     4235  }
     4236
     4237  /// 3. Find connected endpoint candidates and put them into a polygon
     4238  UniquePolygonSet ListofDegeneratedPolygons;
     4239  BoundaryPointSet *Walker = NULL;
     4240  BoundaryPointSet *OtherWalker = NULL;
     4241  BoundaryPolygonSet *Current = NULL;
     4242  stack <BoundaryPointSet*> ToCheckConnecteds;
     4243  while (!EndpointCandidateList.empty()) {
     4244    Walker = *(EndpointCandidateList.begin());
     4245    if (Current == NULL) {  // create a new polygon with current candidate
     4246      Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl;
     4247      Current = new BoundaryPolygonSet;
     4248      Current->endpoints.insert(Walker);
     4249      EndpointCandidateList.erase(Walker);
     4250      ToCheckConnecteds.push(Walker);
     4251    }
     4252
     4253    // go through to-check stack
     4254    while (!ToCheckConnecteds.empty()) {
     4255      Walker = ToCheckConnecteds.top(); // fetch ...
     4256      ToCheckConnecteds.pop(); // ... and remove
     4257      for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
     4258        OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
     4259        Log() << Verbose(1) << "Checking " << *OtherWalker << endl;
     4260        set < BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
     4261        if (Finder != EndpointCandidateList.end()) {  // found a connected partner
     4262          Log() << Verbose(1) << " Adding to polygon." << endl;
     4263          Current->endpoints.insert(OtherWalker);
     4264          EndpointCandidateList.erase(Finder);  // remove from candidates
     4265          ToCheckConnecteds.push(OtherWalker);  // but check its partners too
     4266        } else {
     4267          Log() << Verbose(1) << " is not connected to " << *Walker << endl;
     4268        }
     4269      }
     4270    }
     4271
     4272    Log() << Verbose(0) << "Final polygon is " << *Current << endl;
     4273    ListofDegeneratedPolygons.insert(Current);
     4274    Current = NULL;
     4275  }
     4276
     4277  const int counter = ListofDegeneratedPolygons.size();
     4278
     4279  Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl;
     4280  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
     4281    Log() << Verbose(0) << " " << **PolygonRunner << endl;
     4282
     4283  /// 4. Go through all these degenerated polygons
     4284  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
     4285    stack <int> TriangleNrs;
     4286    Vector NormalVector;
     4287    /// 4a. Gather all triangles of this polygon
     4288    TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
     4289
     4290    if (T->size() == 2) {
     4291      Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl;
     4292      delete(T);
     4293      continue;
     4294    }
     4295
     4296    TriangleSet::iterator TriangleWalker = T->begin();  // is the inner iterator
     4297    /// 4a. Get NormalVector for one side (this is "front")
     4298    NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     4299    Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl;
     4300    TriangleWalker++;
     4301    TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
     4302    /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back")
     4303    BoundaryTriangleSet *triangle = NULL;
     4304    while (TriangleSprinter != T->end()) {
     4305      TriangleWalker = TriangleSprinter;
     4306      triangle = *TriangleWalker;
     4307      TriangleSprinter++;
     4308      Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl;
     4309      if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
     4310        Log() << Verbose(1) << " Removing ... " << endl;
     4311        TriangleNrs.push(triangle->Nr);
     4312        T->erase(TriangleWalker);
     4313        RemoveTesselationTriangle(triangle);
     4314      } else
     4315        Log() << Verbose(1) << " Keeping ... " << endl;
     4316    }
     4317    /// 4c. Copy all "front" triangles but with inverse NormalVector
     4318    TriangleWalker = T->begin();
     4319    while (TriangleWalker != T->end()) {  // go through all front triangles
     4320      Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl;
     4321      for (int i = 0; i < 3; i++)
     4322        AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
     4323      AddTesselationLine(TPS[0], TPS[1], 0);
     4324      AddTesselationLine(TPS[0], TPS[2], 1);
     4325      AddTesselationLine(TPS[1], TPS[2], 2);
     4326      if (TriangleNrs.empty())
     4327        eLog() << Verbose(0) << "No more free triangle numbers!" << endl;
     4328      BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
     4329      AddTesselationTriangle(); // ... and add
     4330      TriangleNrs.pop();
     4331      BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     4332      BTS->NormalVector.Scale(-1.);
     4333      TriangleWalker++;
     4334    }
     4335    if (!TriangleNrs.empty()) {
     4336      eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl;
     4337    }
     4338    delete(T);  // remove the triangleset
     4339  }
     4340
     4341  map<int, int> * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
     4342  Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
     4343  map<int,int>::iterator it;
     4344  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
     4345      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     4346  delete(SimplyDegeneratedTriangles);
     4347
     4348  /// 5. exit
     4349  UniquePolygonSet::iterator PolygonRunner;
     4350  while (!ListofDegeneratedPolygons.empty()) {
     4351    PolygonRunner = ListofDegeneratedPolygons.begin();
     4352    delete(*PolygonRunner);
     4353    ListofDegeneratedPolygons.erase(PolygonRunner);
     4354  }
     4355
     4356  return counter;
     4357};
  • src/tesselation.hpp

    r482373 r0b2dd2  
    2323#include <list>
    2424#include <set>
     25#include <stack>
    2526
    2627#include "atom_particleinfo.hpp"
     
    4748#define VRMLSUffix ".wrl"
    4849
     50#define ParallelEpsilon 1e-3
     51
    4952// ======================================================= some template functions =========================================
    5053
    5154#define PointMap map < int, class BoundaryPointSet * >
     55#define PointSet set < class BoundaryPointSet * >
     56#define PointList list < class BoundaryPointSet * >
    5257#define PointPair pair < int, class BoundaryPointSet * >
    5358#define PointTestPair pair < PointMap::iterator, bool >
     59
    5460#define CandidateList list <class CandidateForTesselation *>
     61#define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
    5562
    5663#define LineMap multimap < int, class BoundaryLineSet * >
     64#define LineSet set < class BoundaryLineSet * >
     65#define LineList list < class BoundaryLineSet * >
    5766#define LinePair pair < int, class BoundaryLineSet * >
    5867#define LineTestPair pair < LineMap::iterator, bool >
    5968
    6069#define TriangleMap map < int, class BoundaryTriangleSet * >
     70#define TriangleSet set < class BoundaryTriangleSet * >
     71#define TriangleList list < class BoundaryTriangleSet * >
    6172#define TrianglePair pair < int, class BoundaryTriangleSet * >
    6273#define TriangleTestPair pair < TrianglePair::iterator, bool >
    6374
     75#define PolygonMap map < int, class BoundaryPolygonSet * >
     76#define PolygonSet set < class BoundaryPolygonSet * >
     77#define PolygonList list < class BoundaryPolygonSet * >
     78
    6479#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
    6580#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
     81
     82#define TesselPointList list <TesselPoint *>
     83#define TesselPointSet set <TesselPoint *>
    6684
    6785/********************************************** declarations *******************************/
     
    114132    TriangleMap triangles;
    115133    int Nr;
     134    bool skipped;
    116135};
    117136
     
    139158    class BoundaryLineSet *lines[3];
    140159    Vector NormalVector;
     160    Vector SphereCenter;
    141161    int Nr;
    142162};
    143163
    144164ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
     165
     166
     167// ======================================================== class BoundaryTriangleSet =======================================
     168
     169/** Set of BoundaryPointSet.
     170 * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
     171 * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
     172 * class (i.e. no allocation, no deletion).
     173 * \note we assume that the set of endpoints reside (more or less) on a plane.
     174 */
     175class BoundaryPolygonSet {
     176  public:
     177    BoundaryPolygonSet();
     178    ~BoundaryPolygonSet();
     179
     180    Vector * GetNormalVector(const Vector &NormalVector) const;
     181    void GetCenter(Vector *center) const;
     182    bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
     183    bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
     184    bool ContainsBoundaryPoint(const TesselPoint * const point) const;
     185    bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
     186    bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
     187    bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
     188    bool ContainsPresentTupel(const PointSet &endpoints) const;
     189    TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
     190    bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
     191
     192    PointSet endpoints;
     193    int Nr;
     194};
     195
     196ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
    145197
    146198// =========================================================== class TESSELPOINT ===========================================
     
    170222  virtual ~PointCloud();
    171223
     224  virtual const char * const GetName() const { return "unknown"; };
    172225  virtual Vector *GetCenter() const { return NULL; };
    173226  virtual TesselPoint *GetPoint() const { return NULL; };
     
    177230  virtual void GoToFirst() const {};
    178231  virtual void GoToLast() const {};
    179   virtual bool IsEmpty() const { return false; };
    180   virtual bool IsEnd() const { return false; };
     232  virtual bool IsEmpty() const { return true; };
     233  virtual bool IsEnd() const { return true; };
    181234};
    182235
     
    185238class CandidateForTesselation {
    186239  public :
     240  CandidateForTesselation(BoundaryLineSet* currentBaseLine);
    187241  CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
    188242  ~CandidateForTesselation();
    189243
    190   TesselPoint *point;
     244  TesselPointList pointlist;
    191245  BoundaryLineSet *BaseLine;
    192246  Vector OptCenter;
    193247  Vector OtherOptCenter;
    194 };
     248  bool IsDegenerated;
     249  double ShortestAngle;
     250  double OtherShortestAngle;
     251};
     252
     253ostream & operator <<(ostream &ost, const  CandidateForTesselation &a);
    195254
    196255// =========================================================== class TESSELATION ===========================================
     
    210269    void AddTesselationTriangle();
    211270    void AddTesselationTriangle(const int nr);
     271    void AddCandidateTriangle(CandidateForTesselation CandidateLine);
    212272    void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
    213273    void RemoveTesselationLine(class BoundaryLineSet *line);
     
    218278    void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
    219279    void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
    220     void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, class BoundaryLineSet *BaseLine, const class TesselPoint * const ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC) const;
    221     bool FindNextSuitableTriangle(BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
     280    void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
     281    bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
    222282    int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
    223283    class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
     
    235295    void RemoveDegeneratedTriangles();
    236296    void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
     297    int CorrectAllDegeneratedPolygons();
    237298
    238299    set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
     
    240301    list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
    241302    list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
    242     list<TesselPoint*> * GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference = NULL) const;
     303    list<TesselPoint*> * GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
    243304    class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
    244305    list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
     
    259320    PointMap PointsOnBoundary;
    260321    LineMap LinesOnBoundary;
     322    CandidateMap OpenLines;
    261323    TriangleMap TrianglesOnBoundary;
    262324    int PointsOnBoundaryCount;
     
    286348    mutable PointMap::const_iterator InternalPointer;
    287349
    288     bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
     350    //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
    289351};
    290352
  • src/tesselationhelpers.cpp

    r482373 r0b2dd2  
    88#include <fstream>
    99
     10#include "info.hpp"
    1011#include "linkedcell.hpp"
    1112#include "log.hpp"
     
    1516#include "verbose.hpp"
    1617
    17 double DetGet(gsl_matrix * const A, const int inPlace) {
     18double DetGet(gsl_matrix * const A, const int inPlace)
     19{
     20        Info FunctionInfo(__func__);
    1821  /*
    1922  inPlace = 1 => A is replaced with the LU decomposed copy.
     
    4548void GetSphere(Vector * const center, const Vector &a, const Vector &b, const Vector &c, const double RADIUS)
    4649{
     50        Info FunctionInfo(__func__);
    4751  gsl_matrix *A = gsl_matrix_calloc(3,3);
    4852  double m11, m12, m13, m14;
     
    111115    const double HalfplaneIndicator, const double AlternativeIndicator, const double alpha, const double beta, const double gamma, const double RADIUS, const double Umkreisradius)
    112116{
     117        Info FunctionInfo(__func__);
    113118  Vector TempNormal, helper;
    114119  double Restradius;
    115120  Vector OtherCenter;
    116   Log() << Verbose(3) << "Begin of GetCenterOfSphere.\n";
    117121  Center->Zero();
    118122  helper.CopyVector(&a);
     
    128132  Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
    129133  NewUmkreismittelpunkt->CopyVector(Center);
    130   Log() << Verbose(4) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n";
     134  Log() << Verbose(1) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n";
    131135  // Here we calculated center of circumscribing circle, using barycentric coordinates
    132   Log() << Verbose(4) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n";
     136  Log() << Verbose(1) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n";
    133137
    134138  TempNormal.CopyVector(&a);
     
    154158  TempNormal.Normalize();
    155159  Restradius = sqrt(RADIUS*RADIUS - Umkreisradius*Umkreisradius);
    156   Log() << Verbose(4) << "Height of center of circumference to center of sphere is " << Restradius << ".\n";
     160  Log() << Verbose(1) << "Height of center of circumference to center of sphere is " << Restradius << ".\n";
    157161  TempNormal.Scale(Restradius);
    158   Log() << Verbose(4) << "Shift vector to sphere of circumference is " << TempNormal << ".\n";
     162  Log() << Verbose(1) << "Shift vector to sphere of circumference is " << TempNormal << ".\n";
    159163
    160164  Center->AddVector(&TempNormal);
    161   Log() << Verbose(0) << "Center of sphere of circumference is " << *Center << ".\n";
     165  Log() << Verbose(1) << "Center of sphere of circumference is " << *Center << ".\n";
    162166  GetSphere(&OtherCenter, a, b, c, RADIUS);
    163   Log() << Verbose(0) << "OtherCenter of sphere of circumference is " << OtherCenter << ".\n";
    164   Log() << Verbose(3) << "End of GetCenterOfSphere.\n";
     167  Log() << Verbose(1) << "OtherCenter of sphere of circumference is " << OtherCenter << ".\n";
    165168};
    166169
     
    174177void GetCenterofCircumcircle(Vector * const Center, const Vector &a, const Vector &b, const Vector &c)
    175178{
     179        Info FunctionInfo(__func__);
    176180  Vector helper;
    177181  double alpha, beta, gamma;
     
    186190  beta = M_PI - SideC.Angle(&SideA);
    187191  gamma = M_PI - SideA.Angle(&SideB);
    188   //Log() << Verbose(3) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;
     192  //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;
    189193  if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) {
    190     eLog() << Verbose(0) << "GetCenterofCircumcircle: Sum of angles " << (alpha+beta+gamma)/M_PI*180. << " > 180 degrees by " << fabs(M_PI - alpha - beta - gamma)/M_PI*180. << "!" << endl;
    191     performCriticalExit();
     194    eLog() << Verbose(1) << "GetCenterofCircumcircle: Sum of angles " << (alpha+beta+gamma)/M_PI*180. << " > 180 degrees by " << fabs(M_PI - alpha - beta - gamma)/M_PI*180. << "!" << endl;
    192195  }
    193196
     
    220223double GetPathLengthonCircumCircle(const Vector &CircleCenter, const Vector &CirclePlaneNormal, const double CircleRadius, const Vector &NewSphereCenter, const Vector &OldSphereCenter, const Vector &NormalVector, const Vector &SearchDirection)
    221224{
     225        Info FunctionInfo(__func__);
    222226  Vector helper;
    223227  double radius, alpha;
    224 
    225   helper.CopyVector(&NewSphereCenter);
     228  Vector RelativeOldSphereCenter;
     229  Vector RelativeNewSphereCenter;
     230
     231  RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
     232  RelativeOldSphereCenter.SubtractVector(&CircleCenter);
     233  RelativeNewSphereCenter.CopyVector(&NewSphereCenter);
     234  RelativeNewSphereCenter.SubtractVector(&CircleCenter);
     235  helper.CopyVector(&RelativeNewSphereCenter);
    226236  // test whether new center is on the parameter circle's plane
    227237  if (fabs(helper.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
     
    229239    helper.ProjectOntoPlane(&CirclePlaneNormal);
    230240  }
    231   radius = helper.ScalarProduct(&helper);
     241  radius = helper.NormSquared();
    232242  // test whether the new center vector has length of CircleRadius
    233243  if (fabs(radius - CircleRadius) > HULLEPSILON)
    234244    eLog() << Verbose(1) << "The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;
    235   alpha = helper.Angle(&OldSphereCenter);
     245  alpha = helper.Angle(&RelativeOldSphereCenter);
    236246  // make the angle unique by checking the halfplanes/search direction
    237247  if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)  // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals
    238248    alpha = 2.*M_PI - alpha;
    239   //Log() << Verbose(2) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << OldSphereCenter << " and resulting angle is " << alpha << "." << endl;
    240   radius = helper.Distance(&OldSphereCenter);
     249  Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << RelativeOldSphereCenter << " and resulting angle is " << alpha << "." << endl;
     250  radius = helper.Distance(&RelativeOldSphereCenter);
    241251  helper.ProjectOntoPlane(&NormalVector);
    242252  // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles
    243253  if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) {
    244     //Log() << Verbose(2) << "INFO: Distance between old and new center is " << radius << " and between new center and baseline center is " << helper.Norm() << "." << endl;
     254    Log() << Verbose(1) << "INFO: Distance between old and new center is " << radius << " and between new center and baseline center is " << helper.Norm() << "." << endl;
    245255    return alpha;
    246256  } else {
    247     //Log() << Verbose(1) << "INFO: NewSphereCenter " << helper << " is too close to OldSphereCenter" << OldSphereCenter << "." << endl;
     257    Log() << Verbose(1) << "INFO: NewSphereCenter " << RelativeNewSphereCenter << " is too close to RelativeOldSphereCenter" << RelativeOldSphereCenter << "." << endl;
    248258    return 2.*M_PI;
    249259  }
     
    265275double MinIntersectDistance(const gsl_vector * x, void *params)
    266276{
     277        Info FunctionInfo(__func__);
    267278  double retval = 0;
    268279  struct Intersection *I = (struct Intersection *)params;
     
    285296
    286297  retval = HeightA.ScalarProduct(&HeightA) + HeightB.ScalarProduct(&HeightB);
    287   //Log() << Verbose(2) << "MinIntersectDistance called, result: " << retval << endl;
     298  //Log() << Verbose(1) << "MinIntersectDistance called, result: " << retval << endl;
    288299
    289300  return retval;
     
    305316bool existsIntersection(const Vector &point1, const Vector &point2, const Vector &point3, const Vector &point4)
    306317{
     318        Info FunctionInfo(__func__);
    307319  bool result;
    308320
     
    352364
    353365        if (status == GSL_SUCCESS) {
    354           Log() << Verbose(2) << "converged to minimum" <<  endl;
     366          Log() << Verbose(1) << "converged to minimum" <<  endl;
    355367        }
    356368    } while (status == GSL_CONTINUE && iter < 100);
     
    377389  t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB);
    378390
    379   Log() << Verbose(2) << "Intersection " << intersection << " is at "
     391  Log() << Verbose(1) << "Intersection " << intersection << " is at "
    380392    << t1 << " for (" << point1 << "," << point2 << ") and at "
    381393    << t2 << " for (" << point3 << "," << point4 << "): ";
    382394
    383395  if (((t1 >= 0) && (t1 <= 1)) && ((t2 >= 0) && (t2 <= 1))) {
    384     Log() << Verbose(0) << "true intersection." << endl;
     396    Log() << Verbose(1) << "true intersection." << endl;
    385397    result = true;
    386398  } else {
    387     Log() << Verbose(0) << "intersection out of region of interest." << endl;
     399    Log() << Verbose(1) << "intersection out of region of interest." << endl;
    388400    result = false;
    389401  }
     
    408420double GetAngle(const Vector &point, const Vector &reference, const Vector &OrthogonalVector)
    409421{
     422        Info FunctionInfo(__func__);
    410423  if (reference.IsZero())
    411424    return M_PI;
     
    419432  }
    420433
    421   Log() << Verbose(4) << "INFO: " << point << " has angle " << phi << " with respect to reference " << reference << "." << endl;
     434  Log() << Verbose(1) << "INFO: " << point << " has angle " << phi << " with respect to reference " << reference << "." << endl;
    422435
    423436  return phi;
     
    434447double CalculateVolumeofGeneralTetraeder(const Vector &a, const Vector &b, const Vector &c, const Vector &d)
    435448{
     449        Info FunctionInfo(__func__);
    436450  Vector Point, TetraederVector[3];
    437451  double volume;
     
    457471bool CheckLineCriteriaForDegeneratedTriangle(const BoundaryPointSet * const nodes[3])
    458472{
     473        Info FunctionInfo(__func__);
    459474  bool result = false;
    460475  int counter = 0;
     
    483498    }
    484499  if ((!result) && (counter > 1)) {
    485     Log() << Verbose(2) << "INFO: Degenerate triangle is ok, at least two, here " << counter << ", existing lines are used." << endl;
     500    Log() << Verbose(1) << "INFO: Degenerate triangle is ok, at least two, here " << counter << ", existing lines are used." << endl;
    486501    result = true;
    487502  }
     
    490505
    491506
    492 /** Sort function for the candidate list.
    493  */
    494 bool SortCandidates(const CandidateForTesselation* candidate1, const CandidateForTesselation* candidate2)
    495 {
    496   Vector BaseLineVector, OrthogonalVector, helper;
    497   if (candidate1->BaseLine != candidate2->BaseLine) {  // sanity check
    498     eLog() << Verbose(1) << "sortCandidates was called for two different baselines: " << candidate1->BaseLine << " and " << candidate2->BaseLine << "." << endl;
    499     //return false;
    500     exit(1);
    501   }
    502   // create baseline vector
    503   BaseLineVector.CopyVector(candidate1->BaseLine->endpoints[1]->node->node);
    504   BaseLineVector.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
    505   BaseLineVector.Normalize();
    506 
    507   // create normal in-plane vector to cope with acos() non-uniqueness on [0,2pi] (note that is pointing in the "right" direction already, hence ">0" test!)
    508   helper.CopyVector(candidate1->BaseLine->endpoints[0]->node->node);
    509   helper.SubtractVector(candidate1->point->node);
    510   OrthogonalVector.CopyVector(&helper);
    511   helper.VectorProduct(&BaseLineVector);
    512   OrthogonalVector.SubtractVector(&helper);
    513   OrthogonalVector.Normalize();
    514 
    515   // calculate both angles and correct with in-plane vector
    516   helper.CopyVector(candidate1->point->node);
    517   helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
    518   double phi = BaseLineVector.Angle(&helper);
    519   if (OrthogonalVector.ScalarProduct(&helper) > 0) {
    520     phi = 2.*M_PI - phi;
    521   }
    522   helper.CopyVector(candidate2->point->node);
    523   helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
    524   double psi = BaseLineVector.Angle(&helper);
    525   if (OrthogonalVector.ScalarProduct(&helper) > 0) {
    526     psi = 2.*M_PI - psi;
    527   }
    528 
    529   Log() << Verbose(2) << *candidate1->point << " has angle " << phi << endl;
    530   Log() << Verbose(2) << *candidate2->point << " has angle " << psi << endl;
    531 
    532   // return comparison
    533   return phi < psi;
    534 };
     507///** Sort function for the candidate list.
     508// */
     509//bool SortCandidates(const CandidateForTesselation* candidate1, const CandidateForTesselation* candidate2)
     510//{
     511//      Info FunctionInfo(__func__);
     512//  Vector BaseLineVector, OrthogonalVector, helper;
     513//  if (candidate1->BaseLine != candidate2->BaseLine) {  // sanity check
     514//    eLog() << Verbose(1) << "sortCandidates was called for two different baselines: " << candidate1->BaseLine << " and " << candidate2->BaseLine << "." << endl;
     515//    //return false;
     516//    exit(1);
     517//  }
     518//  // create baseline vector
     519//  BaseLineVector.CopyVector(candidate1->BaseLine->endpoints[1]->node->node);
     520//  BaseLineVector.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
     521//  BaseLineVector.Normalize();
     522//
     523//  // create normal in-plane vector to cope with acos() non-uniqueness on [0,2pi] (note that is pointing in the "right" direction already, hence ">0" test!)
     524//  helper.CopyVector(candidate1->BaseLine->endpoints[0]->node->node);
     525//  helper.SubtractVector(candidate1->point->node);
     526//  OrthogonalVector.CopyVector(&helper);
     527//  helper.VectorProduct(&BaseLineVector);
     528//  OrthogonalVector.SubtractVector(&helper);
     529//  OrthogonalVector.Normalize();
     530//
     531//  // calculate both angles and correct with in-plane vector
     532//  helper.CopyVector(candidate1->point->node);
     533//  helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
     534//  double phi = BaseLineVector.Angle(&helper);
     535//  if (OrthogonalVector.ScalarProduct(&helper) > 0) {
     536//    phi = 2.*M_PI - phi;
     537//  }
     538//  helper.CopyVector(candidate2->point->node);
     539//  helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
     540//  double psi = BaseLineVector.Angle(&helper);
     541//  if (OrthogonalVector.ScalarProduct(&helper) > 0) {
     542//    psi = 2.*M_PI - psi;
     543//  }
     544//
     545//  Log() << Verbose(1) << *candidate1->point << " has angle " << phi << endl;
     546//  Log() << Verbose(1) << *candidate2->point << " has angle " << psi << endl;
     547//
     548//  // return comparison
     549//  return phi < psi;
     550//};
    535551
    536552/**
     
    544560TesselPoint* FindSecondClosestPoint(const Vector* Point, const LinkedCell* const LC)
    545561{
     562        Info FunctionInfo(__func__);
    546563  TesselPoint* closestPoint = NULL;
    547564  TesselPoint* secondClosestPoint = NULL;
     
    554571  for(int i=0;i<NDIM;i++) // store indices of this cell
    555572    N[i] = LC->n[i];
    556   Log() << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     573  Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    557574
    558575  LC->GetNeighbourBounds(Nlower, Nupper);
    559   //Log() << Verbose(0) << endl;
     576  //Log() << Verbose(1) << endl;
    560577  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    561578    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    562579      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    563580        const LinkedNodes *List = LC->GetCurrentCell();
    564         //Log() << Verbose(3) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
     581        //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    565582        if (List != NULL) {
    566583          for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     
    598615TesselPoint* FindClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC)
    599616{
     617        Info FunctionInfo(__func__);
    600618  TesselPoint* closestPoint = NULL;
    601619  SecondPoint = NULL;
     
    608626  for(int i=0;i<NDIM;i++) // store indices of this cell
    609627    N[i] = LC->n[i];
    610   Log() << Verbose(3) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     628  Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    611629
    612630  LC->GetNeighbourBounds(Nlower, Nupper);
    613   //Log() << Verbose(0) << endl;
     631  //Log() << Verbose(1) << endl;
    614632  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    615633    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    616634      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    617635        const LinkedNodes *List = LC->GetCurrentCell();
    618         //Log() << Verbose(3) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
     636        //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    619637        if (List != NULL) {
    620638          for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     
    627645              distance = currentNorm;
    628646              closestPoint = (*Runner);
    629               //Log() << Verbose(2) << "INFO: New Nearest Neighbour is " << *closestPoint << "." << endl;
     647              //Log() << Verbose(1) << "INFO: New Nearest Neighbour is " << *closestPoint << "." << endl;
    630648            } else if (currentNorm < secondDistance) {
    631649              secondDistance = currentNorm;
    632650              SecondPoint = (*Runner);
    633               //Log() << Verbose(2) << "INFO: New Second Nearest Neighbour is " << *SecondPoint << "." << endl;
     651              //Log() << Verbose(1) << "INFO: New Second Nearest Neighbour is " << *SecondPoint << "." << endl;
    634652            }
    635653          }
     
    641659  // output
    642660  if (closestPoint != NULL) {
    643     Log() << Verbose(2) << "Closest point is " << *closestPoint;
     661    Log() << Verbose(1) << "Closest point is " << *closestPoint;
    644662    if (SecondPoint != NULL)
    645663      Log() << Verbose(0) << " and second closest is " << *SecondPoint;
     
    657675Vector * GetClosestPointBetweenLine(const BoundaryLineSet * const Base, const BoundaryLineSet * const OtherBase)
    658676{
     677        Info FunctionInfo(__func__);
    659678  // construct the plane of the two baselines (i.e. take both their directional vectors)
    660679  Vector Normal;
     
    667686  Normal.VectorProduct(&OtherBaseline);
    668687  Normal.Normalize();
    669   Log() << Verbose(4) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl;
     688  Log() << Verbose(1) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl;
    670689
    671690  // project one offset point of OtherBase onto this plane (and add plane offset vector)
     
    684703  Normal.CopyVector(Intersection);
    685704  Normal.SubtractVector(Base->endpoints[0]->node->node);
    686   Log() << Verbose(3) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl;
     705  Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl;
    687706
    688707  return Intersection;
     
    697716double DistanceToTrianglePlane(const Vector *x, const BoundaryTriangleSet * const triangle)
    698717{
     718        Info FunctionInfo(__func__);
    699719  double distance = 0.;
    700720  if (x == NULL) {
     
    713733void WriteVrmlFile(ofstream * const vrmlfile, const Tesselation * const Tess, const PointCloud * const cloud)
    714734{
     735        Info FunctionInfo(__func__);
    715736  TesselPoint *Walker = NULL;
    716737  int i;
     
    756777void IncludeSphereinRaster3D(ofstream * const rasterfile, const Tesselation * const Tess, const PointCloud * const cloud)
    757778{
     779        Info FunctionInfo(__func__);
    758780  Vector helper;
    759   // include the current position of the virtual sphere in the temporary raster3d file
    760   Vector *center = cloud->GetCenter();
    761   // make the circumsphere's center absolute again
    762   helper.CopyVector(Tess->LastTriangle->endpoints[0]->node->node);
    763   helper.AddVector(Tess->LastTriangle->endpoints[1]->node->node);
    764   helper.AddVector(Tess->LastTriangle->endpoints[2]->node->node);
    765   helper.Scale(1./3.);
    766   helper.SubtractVector(center);
    767   // and add to file plus translucency object
    768   *rasterfile << "# current virtual sphere\n";
    769   *rasterfile << "8\n  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0\n";
    770   *rasterfile << "2\n  " << helper.x[0] << " " << helper.x[1] << " " << helper.x[2] << "\t" << 5. << "\t1 0 0\n";
    771   *rasterfile << "9\n  terminating special property\n";
    772   delete(center);
     781
     782  if (Tess->LastTriangle != NULL) {
     783    // include the current position of the virtual sphere in the temporary raster3d file
     784    Vector *center = cloud->GetCenter();
     785    // make the circumsphere's center absolute again
     786    helper.CopyVector(Tess->LastTriangle->endpoints[0]->node->node);
     787    helper.AddVector(Tess->LastTriangle->endpoints[1]->node->node);
     788    helper.AddVector(Tess->LastTriangle->endpoints[2]->node->node);
     789    helper.Scale(1./3.);
     790    helper.SubtractVector(center);
     791    // and add to file plus translucency object
     792    *rasterfile << "# current virtual sphere\n";
     793    *rasterfile << "8\n  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0\n";
     794    *rasterfile << "2\n  " << helper.x[0] << " " << helper.x[1] << " " << helper.x[2] << "\t" << 5. << "\t1 0 0\n";
     795    *rasterfile << "9\n  terminating special property\n";
     796    delete(center);
     797  }
    773798};
    774799
     
    781806void WriteRaster3dFile(ofstream * const rasterfile, const Tesselation * const Tess, const PointCloud * const cloud)
    782807{
     808        Info FunctionInfo(__func__);
    783809  TesselPoint *Walker = NULL;
    784810  int i;
     
    826852void WriteTecplotFile(ofstream * const tecplot, const Tesselation * const TesselStruct, const PointCloud * const cloud, const int N)
    827853{
     854        Info FunctionInfo(__func__);
    828855  if ((tecplot != NULL) && (TesselStruct != NULL)) {
    829856    // write header
    830857    *tecplot << "TITLE = \"3D CONVEX SHELL\"" << endl;
    831858    *tecplot << "VARIABLES = \"X\" \"Y\" \"Z\" \"U\"" << endl;
    832     *tecplot << "ZONE T=\"" << N << "-";
    833     for (int i=0;i<3;i++)
    834       *tecplot << (i==0 ? "" : "_") << TesselStruct->LastTriangle->endpoints[i]->node->Name;
     859    *tecplot << "ZONE T=\"";
     860    if (N < 0) {
     861      *tecplot << cloud->GetName();
     862    } else {
     863      *tecplot << N << "-";
     864      for (int i=0;i<3;i++)
     865        *tecplot << (i==0 ? "" : "_") << TesselStruct->LastTriangle->endpoints[i]->node->Name;
     866    }
    835867    *tecplot << "\", N=" << TesselStruct->PointsOnBoundary.size() << ", E=" << TesselStruct->TrianglesOnBoundary.size() << ", DATAPACKING=POINT, ZONETYPE=FETRIANGLE" << endl;
    836868    int i=0;
     
    841873
    842874    // print atom coordinates
    843     Log() << Verbose(2) << "The following triangles were created:";
    844875    int Counter = 1;
    845876    TesselPoint *Walker = NULL;
     
    851882    *tecplot << endl;
    852883    // print connectivity
     884    Log() << Verbose(1) << "The following triangles were created:" << endl;
    853885    for (TriangleMap::const_iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++) {
    854       Log() << Verbose(0) << " " << runner->second->endpoints[0]->node->Name << "<->" << runner->second->endpoints[1]->node->Name << "<->" << runner->second->endpoints[2]->node->Name;
     886      Log() << Verbose(1) << " " << runner->second->endpoints[0]->node->Name << "<->" << runner->second->endpoints[1]->node->Name << "<->" << runner->second->endpoints[2]->node->Name << endl;
    855887      *tecplot << LookupList[runner->second->endpoints[0]->node->nr] << " " << LookupList[runner->second->endpoints[1]->node->nr] << " " << LookupList[runner->second->endpoints[2]->node->nr] << endl;
    856888    }
    857889    delete[] (LookupList);
    858     Log() << Verbose(0) << endl;
    859890  }
    860891};
     
    867898void CalculateConcavityPerBoundaryPoint(const Tesselation * const TesselStruct)
    868899{
     900        Info FunctionInfo(__func__);
    869901  class BoundaryPointSet *point = NULL;
    870902  class BoundaryLineSet *line = NULL;
    871903
    872   //Log() << Verbose(2) << "Begin of CalculateConcavityPerBoundaryPoint" << endl;
    873904  // calculate remaining concavity
    874905  for (PointMap::const_iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
     
    878909    for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    879910      line = LineRunner->second;
    880       //Log() << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
     911      //Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
    881912      if (!line->CheckConvexityCriterion())
    882913        point->value += 1;
    883914    }
    884915  }
    885   //Log() << Verbose(2) << "End of CalculateConcavityPerBoundaryPoint" << endl;
    886916};
    887917
     
    894924bool CheckListOfBaselines(const Tesselation * const TesselStruct)
    895925{
     926        Info FunctionInfo(__func__);
    896927  LineMap::const_iterator testline;
    897928  bool result = false;
     
    901932  for (testline = TesselStruct->LinesOnBoundary.begin(); testline != TesselStruct->LinesOnBoundary.end(); testline++) {
    902933    if (testline->second->triangles.size() != 2) {
    903       Log() << Verbose(1) << *testline->second << "\t" << testline->second->triangles.size() << endl;
     934      Log() << Verbose(2) << *testline->second << "\t" << testline->second->triangles.size() << endl;
    904935      counter++;
    905936    }
     
    912943}
    913944
     945/** Counts the number of triangle pairs that contain the given polygon.
     946 * \param *P polygon with endpoints to look for
     947 * \param *T set of triangles to create pairs from containing \a *P
     948 */
     949int CountTrianglePairContainingPolygon(const BoundaryPolygonSet * const P, const TriangleSet * const T)
     950{
     951  Info FunctionInfo(__func__);
     952  // check number of endpoints in *P
     953  if (P->endpoints.size() != 4) {
     954    eLog() << Verbose(1) << "CountTrianglePairContainingPolygon works only on polygons with 4 nodes!" << endl;
     955    return 0;
     956  }
     957
     958  // check number of triangles in *T
     959  if (T->size() < 2) {
     960    eLog() << Verbose(1) << "Not enough triangles to have pairs!" << endl;
     961    return 0;
     962  }
     963
     964  Log() << Verbose(0) << "Polygon is " << *P << endl;
     965  // create each pair, get the endpoints and check whether *P is contained.
     966  int counter = 0;
     967  PointSet Trianglenodes;
     968  class BoundaryPolygonSet PairTrianglenodes;
     969  for(TriangleSet::iterator Walker = T->begin(); Walker != T->end(); Walker++) {
     970    for (int i=0;i<3;i++)
     971      Trianglenodes.insert((*Walker)->endpoints[i]);
     972
     973    for(TriangleSet::iterator PairWalker = Walker; PairWalker != T->end(); PairWalker++) {
     974      if (Walker != PairWalker) { // skip first
     975        PairTrianglenodes.endpoints = Trianglenodes;
     976        for (int i=0;i<3;i++)
     977          PairTrianglenodes.endpoints.insert((*PairWalker)->endpoints[i]);
     978        const int size = PairTrianglenodes.endpoints.size();
     979        if (size == 4) {
     980          Log() << Verbose(0) << " Current pair of triangles: " << **Walker << "," << **PairWalker << " with " << size << " distinct endpoints:" << PairTrianglenodes << endl;
     981          // now check
     982          if (PairTrianglenodes.ContainsPresentTupel(P)) {
     983            counter++;
     984            Log() << Verbose(0) << "  ACCEPT: Matches with " << *P << endl;
     985          } else {
     986            Log() << Verbose(0) << "  REJECT: No match with " << *P << endl;
     987          }
     988        } else {
     989          Log() << Verbose(0) << "  REJECT: Less than four endpoints." << endl;
     990        }
     991      }
     992    }
     993    Trianglenodes.clear();
     994  }
     995  return counter;
     996};
     997
     998/** Checks whether two give polygons have two or more points in common.
     999 * \param *P1 first polygon
     1000 * \param *P2 second polygon
     1001 * \return true - are connected, false = are note
     1002 */
     1003bool ArePolygonsEdgeConnected(const BoundaryPolygonSet * const P1, const BoundaryPolygonSet * const P2)
     1004{
     1005  Info FunctionInfo(__func__);
     1006  int counter = 0;
     1007  for(PointSet::const_iterator Runner = P1->endpoints.begin(); Runner != P1->endpoints.end(); Runner++) {
     1008    if (P2->ContainsBoundaryPoint((*Runner))) {
     1009      counter++;
     1010      Log() << Verbose(1) << *(*Runner) << " of second polygon is found in the first one." << endl;
     1011      return true;
     1012    }
     1013  }
     1014  return false;
     1015};
     1016
     1017/** Combines second into the first and deletes the second.
     1018 * \param *P1 first polygon, contains all nodes on return
     1019 * \param *&P2 second polygon, is deleted.
     1020 */
     1021void CombinePolygons(BoundaryPolygonSet * const P1, BoundaryPolygonSet * &P2)
     1022{
     1023  Info FunctionInfo(__func__);
     1024  pair <PointSet::iterator, bool> Tester;
     1025  for(PointSet::iterator Runner = P2->endpoints.begin(); Runner != P2->endpoints.end(); Runner++) {
     1026    Tester = P1->endpoints.insert((*Runner));
     1027    if (Tester.second)
     1028      Log() << Verbose(0) << "Inserting endpoint " << *(*Runner) << " into first polygon." << endl;
     1029  }
     1030  P2->endpoints.clear();
     1031  delete(P2);
     1032};
     1033
  • src/tesselationhelpers.hpp

    r482373 r0b2dd2  
    7272bool CheckListOfBaselines(const Tesselation * const TesselStruct);
    7373
     74int CountTrianglePairContainingPolygon(const BoundaryPolygonSet * const P, const TriangleSet * const T);
     75bool ArePolygonsEdgeConnected(const BoundaryPolygonSet * const P1, const BoundaryPolygonSet * const P2);
     76void CombinePolygons(BoundaryPolygonSet * const P1, BoundaryPolygonSet * &P2);
     77
    7478
    7579#endif /* TESSELATIONHELPERS_HPP_ */
  • src/unittests/Makefile.am

    r482373 r0b2dd2  
    44AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
    55
    6 TESTS = ActOnAllUnitTest AnalysisBondsUnitTests AnalysisCorrelationToPointUnitTest AnalysisCorrelationToSurfaceUnitTest AnalysisPairCorrelationUnitTest BondGraphUnitTest ListOfBondsUnitTest LogUnitTest MemoryUsageObserverUnitTest MemoryAllocatorUnitTest StackClassUnitTest VectorUnitTest
     6TESTS = ActOnAllUnitTest AnalysisBondsUnitTests AnalysisCorrelationToPointUnitTest AnalysisCorrelationToSurfaceUnitTest AnalysisPairCorrelationUnitTest BondGraphUnitTest InfoUnitTest ListOfBondsUnitTest LogUnitTest MemoryUsageObserverUnitTest MemoryAllocatorUnitTest StackClassUnitTest VectorUnitTest
    77check_PROGRAMS = $(TESTS)
    88noinst_PROGRAMS = $(TESTS)
     
    2525BondGraphUnitTest_SOURCES = bondgraphunittest.cpp bondgraphunittest.hpp
    2626BondGraphUnitTest_LDADD = ../libmolecuilder.a
     27
     28InfoUnitTest_SOURCES = infounittest.cpp infounittest.hpp
     29InfoUnitTest_LDADD = ../libmolecuilder.a
    2730
    2831ListOfBondsUnitTest_SOURCES = listofbondsunittest.cpp listofbondsunittest.hpp
  • src/vector.cpp

    r482373 r0b2dd2  
    480480  else
    481481    return false;
     482};
     483
     484/** Checks whether vector is normal to \a *normal.
     485 * @return true - vector is normalized, false - vector is not
     486 */
     487bool Vector::IsEqualTo(const Vector * const a) const
     488{
     489  bool status = true;
     490  for (int i=0;i<NDIM;i++) {
     491    if (fabs(x[i] - a->x[i]) > MYEPSILON)
     492      status = false;
     493  }
     494  return status;
    482495};
    483496
  • src/vector.hpp

    r482373 r0b2dd2  
    4242  bool IsOne() const;
    4343  bool IsNormalTo(const Vector * const normal) const;
     44  bool IsEqualTo(const Vector * const a) const;
    4445
    4546  void AddVector(const Vector * const y);
  • src/verbose.cpp

    r482373 r0b2dd2  
    11using namespace std;
    22
     3#include "info.hpp"
    34#include "verbose.hpp"
    45
     
    910ostream& Verbose::print (ostream &ost) const
    1011{
    11   for (int i=Verbosity;i--;)
     12  for (int i=Verbosity+Info::verbosity;i--;)
    1213    ost.put('\t');
    1314  //Log() << Verbose(0) << "Verbose(.) called." << endl;
     
    2223bool Verbose::DoOutput(int verbosityLevel) const
    2324{
    24   return (verbosityLevel >= Verbosity);
     25  return (verbosityLevel >= Verbosity+Info::verbosity);
    2526};
    2627
  • tests/Tesselations/1_2-dimethoxyethane/NonConvexEnvelope-1_2-dimethoxyethane.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H10_ H15_ H16", N=12, E=20, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="1_2-dimethoxyethane", N=12, E=20, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    449.6489 7.0567 6.6101 2
    556.8975 7.0567 5.9709 2
  • tests/Tesselations/1_2-dimethylbenzene/NonConvexEnvelope-1_2-dimethylbenzene.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- C07_ C08_ H09", N=14, E=25, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="1_2-dimethylbenzene", N=14, E=25, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    448.3296 6.7712 6.0321 3
    558.3296 8.1534 6.0305 3
  • tests/Tesselations/2-methylcyclohexanone/NonConvexEnvelope-2-methylcyclohexanone.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H15_ H18_ H19", N=13, E=22, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="2-methylcyclohexanone", N=13, E=22, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    449.2731 9.0957 6.144 1
    5510.8392 7.1885 6.8694 0
  • tests/Tesselations/C16_0-Torus/NonConvexEnvelope-C16_0-Torus.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- C818_ C1839_ C1904", N=8208, E=16416, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="C16_0-Torus", N=8208, E=16416, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    4457.0669 28.4968 10.0318 2
    5553.7124 30.5841 10.0363 2
  • tests/Tesselations/Makefile.am

    r482373 r0b2dd2  
    221_2-dimethylbenzene.test \
    332-methylcyclohexanone.test \
     4benzene.test \
    45cholesterol.test \
    56cluster.test \
  • tests/Tesselations/N_N-dimethylacetamide/NonConvexEnvelope-N_N-dimethylacetamide.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- C03_ O06_ H12", N=11, E=18, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="N_N-dimethylacetamide", N=11, E=18, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    446.4232 7.1074 8.3151 3
    556.5832 7.8674 9.2351 1
  • tests/Tesselations/cholesterol/NonConvexEnvelope-cholesterol.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H49_ H50_ H51", N=44, E=86, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="cholesterol", N=44, E=86, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    4419.4519 9.7871 8.0824 1
    5512.9054 5.0485 9.284 1
  • tests/Tesselations/cluster/NonConvexEnvelope-cluster.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- O4864_ O4865_ O5836", N=434, E=782, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="cluster", N=434, E=782, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    4459.3961 67.9193 74.1709 1
    5560.8097 66.4885 71.9891 1
  • tests/Tesselations/cycloheptane/NonConvexEnvelope-cycloheptane.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H08_ H12_ H13", N=14, E=24, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="cycloheptane", N=14, E=24, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    445 8.6586 6.1486 0
    555.8635 8.4046 7.6783 0
  • tests/Tesselations/dimethyl_bromomalonate/NonConvexEnvelope-dimethyl_bromomalonate.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H12_ H13_ H14", N=12, E=20, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="dimethyl_bromomalonate", N=12, E=20, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    448.1538 5 6.6665 1
    556.8226 7.583 6.9158 4
  • tests/Tesselations/glucose/NonConvexEnvelope-glucose.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- C09_ O12_ H17", N=19, E=34, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="glucose", N=19, E=34, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    449.5866 5 7.577 1
    558.4149 7.4116 8.4659 1
  • tests/Tesselations/heptan/NonConvexEnvelope-heptan.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H07_ H08_ H11", N=16, E=28, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="heptan", N=16, E=28, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    449.6377 5 6.78 0
    559.6377 5 5 0
  • tests/Tesselations/isoleucine/NonConvexEnvelope-isoleucine.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H20_ H21_ H22", N=17, E=30, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="isoleucine", N=17, E=30, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    4410.8909 7.216 6.6663 5
    559.4763 5.271 6.3191 1
  • tests/Tesselations/neohexane/NonConvexEnvelope-neohexane.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H10_ H15_ H20", N=14, E=24, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="neohexane", N=14, E=24, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    447.1525 6.2503 8.0589 1
    557.1525 8.0303 8.0578 1
  • tests/Tesselations/proline/NonConvexEnvelope-proline.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H10_ H13_ H17", N=13, E=22, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="proline", N=13, E=22, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    449.2095 7.1856 6.6953 4
    559.3187 7.948 7.6262 2
  • tests/Tesselations/putrescine/NonConvexEnvelope-putrescine.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- N06_ H17_ H18", N=14, E=24, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="putrescine", N=14, E=24, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    4410.8857 5.9511 6.2964 1
    555.5257 8.9311 6.4164 1
  • tests/Tesselations/round_cluster/NonConvexEnvelope-round_cluster.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- O633_ O960_ O1013", N=467, E=930, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="round_cluster", N=467, E=930, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    4441.4883 31.1464 29.9646 2
    5535.0153 37.6127 31.0313 4
  • tests/Tesselations/tartaric_acid/NonConvexEnvelope-tartaric_acid.dat

    r482373 r0b2dd2  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- C05_ O09_ H12", N=14, E=24, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="tartaric_acid", N=14, E=24, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    4410.156 6.9295 6.2926 4
    558.5078 5.7627 5 1
Note: See TracChangeset for help on using the changeset viewer.