Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tesselation.cpp

    r125b3c r244a84  
    3535 * \param *Walker TesselPoint this boundary point represents
    3636 */
    37 BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker) :
     37BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) :
    3838  LinesCount(0),
    3939  node(Walker),
     
    6161 * \param *line line to add
    6262 */
    63 void BoundaryPointSet::AddLine(class BoundaryLineSet *line)
     63void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
    6464{
    6565        Info FunctionInfo(__func__);
     
    105105 * \param number number of the list
    106106 */
    107 BoundaryLineSet::BoundaryLineSet(class BoundaryPointSet *Point[2], const int number)
     107BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
    108108{
    109109        Info FunctionInfo(__func__);
     
    115115  Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
    116116  Point[1]->AddLine(this); //
     117  // set skipped to false
     118  skipped = false;
     119  // clear triangles list
     120  Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
     121};
     122
     123/** Constructor of BoundaryLineSet with two endpoints.
     124 * Adds line automatically to each endpoints' LineMap
     125 * \param *Point1 first boundary point
     126 * \param *Point2 second boundary point
     127 * \param number number of the list
     128 */
     129BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number)
     130{
     131  Info FunctionInfo(__func__);
     132  // set number
     133  Nr = number;
     134  // set endpoints in ascending order
     135  SetEndpointsOrdered(endpoints, Point1, Point2);
     136  // add this line to the hash maps of both endpoints
     137  Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
     138  Point2->AddLine(this); //
    117139  // set skipped to false
    118140  skipped = false;
     
    171193 * \param *triangle to add
    172194 */
    173 void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
     195void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
    174196{
    175197        Info FunctionInfo(__func__);
     
    182204 * \return true - common endpoint present, false - not connected
    183205 */
    184 bool BoundaryLineSet::IsConnectedTo(class BoundaryLineSet *line)
     206bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
    185207{
    186208        Info FunctionInfo(__func__);
     
    197219 * \return true - triangles are convex, false - concave or less than two triangles connected
    198220 */
    199 bool BoundaryLineSet::CheckConvexityCriterion()
     221bool BoundaryLineSet::CheckConvexityCriterion() const
    200222{
    201223        Info FunctionInfo(__func__);
     
    221243  int i=0;
    222244  class BoundaryPointSet *node = NULL;
    223   for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
     245  for(TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    224246    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    225247    NormalCheck.AddVector(&runner->second->NormalVector);
     
    264286 * \return true - point is of the line, false - is not
    265287 */
    266 bool BoundaryLineSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
     288bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    267289{
    268290        Info FunctionInfo(__func__);
     
    277299 * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise
    278300 */
    279 class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(class BoundaryPointSet *point)
     301class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
    280302{
    281303        Info FunctionInfo(__func__);
     
    317339 * \param number number of triangle
    318340 */
    319 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number) :
     341BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
    320342  Nr(number)
    321343{
     
    376398 * \param &OtherVector direction vector to make normal vector unique.
    377399 */
    378 void BoundaryTriangleSet::GetNormalVector(Vector &OtherVector)
     400void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
    379401{
    380402        Info FunctionInfo(__func__);
     
    388410};
    389411
    390 /** Finds the point on the triangle \a *BTS the line defined by \a *MolCenter and \a *x crosses through.
     412/** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
    391413 * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
    392  * This we test if it's really on the plane and whether it's inside the triangle on the plane or not.
     414 * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
    393415 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
    394416 * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
     
    400422 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
    401423 */
    402 bool BoundaryTriangleSet::GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection)
    403 {
    404         Info FunctionInfo(__func__);
     424bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
     425{
     426  Info FunctionInfo(__func__);
    405427  Vector CrossPoint;
    406428  Vector helper;
     
    411433  }
    412434
     435  Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl;
     436  Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl;
     437  Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl;
     438
     439  if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) {
     440    Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl;
     441    return true;
     442  }   else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
     443    Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl;
     444    return true;
     445  }   else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
     446    Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl;
     447    return true;
     448  }
    413449  // Calculate cross point between one baseline and the line from the third endpoint to intersection
    414450  int i=0;
     
    417453      helper.CopyVector(endpoints[(i+1)%3]->node->node);
    418454      helper.SubtractVector(endpoints[i%3]->node->node);
     455      CrossPoint.SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     456      const double s = CrossPoint.ScalarProduct(&helper)/helper.NormSquared();
     457      Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl;
     458      if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
     459        Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl;
     460        i=4;
     461        break;
     462      }
     463      i++;
    419464    } else
    420       i++;
    421     if (i>2)
    422465      break;
    423   } while (CrossPoint.NormSquared() < MYEPSILON);
     466  } while (i<3);
    424467  if (i==3) {
    425     eLog() << Verbose(0) << "Could not find any cross points, something's utterly wrong here!" << endl;
    426   }
    427   CrossPoint.SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
    428 
    429   // check whether intersection is inside or not by comparing length of intersection and length of cross point
    430   if ((CrossPoint.NormSquared() - helper.NormSquared()) < MYEPSILON) { // inside
     468    Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl;
    431469    return true;
    432   } else { // outside!
    433     Intersection->Zero();
     470  } else {
     471    Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl;
    434472    return false;
    435473  }
     474};
     475
     476/** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
     477 * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
     478 * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
     479 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
     480 * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
     481 * the first two basepoints) or not.
     482 * \param *x point
     483 * \param *ClosestPoint desired closest point inside triangle to \a *x, is absolute vector
     484 * \return Distance squared between \a *x and closest point inside triangle
     485 */
     486double BoundaryTriangleSet::GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const
     487{
     488  Info FunctionInfo(__func__);
     489  Vector Direction;
     490
     491  // 1. get intersection with plane
     492  Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl;
     493  GetCenter(&Direction);
     494  if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
     495    ClosestPoint->CopyVector(x);
     496  }
     497
     498  // 2. Calculate in plane part of line (x, intersection)
     499  Vector InPlane;
     500  InPlane.CopyVector(x);
     501  InPlane.SubtractVector(ClosestPoint);  // points from plane intersection to straight-down point
     502  InPlane.ProjectOntoPlane(&NormalVector);
     503  InPlane.AddVector(ClosestPoint);
     504
     505  Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl;
     506  Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl;
     507  Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl;
     508
     509  // Calculate cross point between one baseline and the desired point such that distance is shortest
     510  double ShortestDistance = -1.;
     511  bool InsideFlag = false;
     512  Vector CrossDirection[3];
     513  Vector CrossPoint[3];
     514  Vector helper;
     515  for (int i=0;i<3;i++) {
     516    // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
     517    Direction.CopyVector(endpoints[(i+1)%3]->node->node);
     518    Direction.SubtractVector(endpoints[i%3]->node->node);
     519    // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
     520    CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node);
     521    CrossDirection[i].CopyVector(&CrossPoint[i]);
     522    CrossDirection[i].SubtractVector(&InPlane);
     523    CrossPoint[i].SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     524    const double s = CrossPoint[i].ScalarProduct(&Direction)/Direction.NormSquared();
     525    Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl;
     526    if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
     527      CrossPoint[i].AddVector(endpoints[i%3]->node->node);  // make cross point absolute again
     528      Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i%3]->node->node << " and " << *endpoints[(i+1)%3]->node->node << "." << endl;
     529      const double distance = CrossPoint[i].DistanceSquared(x);
     530      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
     531        ShortestDistance = distance;
     532        ClosestPoint->CopyVector(&CrossPoint[i]);
     533      }
     534    } else
     535      CrossPoint[i].Zero();
     536  }
     537  InsideFlag = true;
     538  for (int i=0;i<3;i++) {
     539    const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+1)%3]);
     540    const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+2)%3]);;
     541    if ((sign > -MYEPSILON) && (othersign > -MYEPSILON))  // have different sign
     542      InsideFlag = false;
     543  }
     544  if (InsideFlag) {
     545    ClosestPoint->CopyVector(&InPlane);
     546    ShortestDistance = InPlane.DistanceSquared(x);
     547  } else {  // also check endnodes
     548    for (int i=0;i<3;i++) {
     549      const double distance = x->DistanceSquared(endpoints[i]->node->node);
     550      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
     551        ShortestDistance = distance;
     552        ClosestPoint->CopyVector(endpoints[i]->node->node);
     553      }
     554    }
     555  }
     556  Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl;
     557  return ShortestDistance;
    436558};
    437559
     
    440562 * \return true - line is of the triangle, false - is not
    441563 */
    442 bool BoundaryTriangleSet::ContainsBoundaryLine(class BoundaryLineSet *line)
     564bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
    443565{
    444566        Info FunctionInfo(__func__);
     
    453575 * \return true - point is of the triangle, false - is not
    454576 */
    455 bool BoundaryTriangleSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
     577bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
    456578{
    457579        Info FunctionInfo(__func__);
     
    466588 * \return true - point is of the triangle, false - is not
    467589 */
    468 bool BoundaryTriangleSet::ContainsBoundaryPoint(class TesselPoint *point)
     590bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
    469591{
    470592        Info FunctionInfo(__func__);
     
    479601 * \return true - is the very triangle, false - is not
    480602 */
    481 bool BoundaryTriangleSet::IsPresentTupel(class BoundaryPointSet *Points[3])
    482 {
    483         Info FunctionInfo(__func__);
     603bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
     604{
     605        Info FunctionInfo(__func__);
     606        Log() << Verbose(1) << "INFO: Checking " << Points[0] << ","  << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl;
    484607  return (((endpoints[0] == Points[0])
    485608            || (endpoints[0] == Points[1])
     
    501624 * \return true - is the very triangle, false - is not
    502625 */
    503 bool BoundaryTriangleSet::IsPresentTupel(class BoundaryTriangleSet *T)
     626bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
    504627{
    505628        Info FunctionInfo(__func__);
     
    523646 * \return pointer third endpoint or NULL if line does not belong to triangle.
    524647 */
    525 class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(class BoundaryLineSet *line)
     648class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
    526649{
    527650        Info FunctionInfo(__func__);
     
    540663 * \param *center central point on return.
    541664 */
    542 void BoundaryTriangleSet::GetCenter(Vector *center)
     665void BoundaryTriangleSet::GetCenter(Vector * const center) const
    543666{
    544667        Info FunctionInfo(__func__);
     
    547670    center->AddVector(endpoints[i]->node->node);
    548671  center->Scale(1./3.);
     672  Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl;
    549673}
    550674
     
    815939TesselPoint::TesselPoint()
    816940{
    817   Info FunctionInfo(__func__);
     941  //Info FunctionInfo(__func__);
    818942  node = NULL;
    819943  nr = -1;
     
    825949TesselPoint::~TesselPoint()
    826950{
    827   Info FunctionInfo(__func__);
     951  //Info FunctionInfo(__func__);
    828952};
    829953
     
    852976PointCloud::PointCloud()
    853977{
    854         Info FunctionInfo(__func__);
     978        //Info FunctionInfo(__func__);
    855979};
    856980
     
    859983PointCloud::~PointCloud()
    860984{
    861         Info FunctionInfo(__func__);
     985        //Info FunctionInfo(__func__);
    862986};
    863987
     
    10501174 * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
    10511175 */
    1052 void
    1053 Tesselation::GuessStartingTriangle()
     1176void Tesselation::GuessStartingTriangle()
    10541177{
    10551178        Info FunctionInfo(__func__);
     
    14221545  TesselPoint *Walker = NULL;
    14231546  Vector *Center = cloud->GetCenter();
    1424   list<BoundaryTriangleSet*> *triangles = NULL;
     1547  TriangleList *triangles = NULL;
    14251548  bool AddFlag = false;
    14261549  LinkedCell *BoundaryPoints = NULL;
     
    14371560    Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;
    14381561    // get the next triangle
    1439     triangles = FindClosestTrianglesToPoint(Walker->node, BoundaryPoints);
     1562    triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
    14401563    BTS = triangles->front();
    14411564    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
     
    23382461
    23392462  // fill the set of neighbours
    2340   Center.CopyVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2341   Center.SubtractVector(TurningPoint->node);
    2342   set<TesselPoint*> SetOfNeighbours;
     2463  TesselPointSet SetOfNeighbours;
    23432464  SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
    23442465  for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
    23452466    SetOfNeighbours.insert(*Runner);
    2346   TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, &Center);
     2467  TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
    23472468
    23482469  // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
     2470  Log() << Verbose(0) << "List of Candidates for Turning Point: " << *TurningPoint << "." << endl;
     2471  for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
     2472    Log() << Verbose(0) << **TesselRunner << endl;
    23492473  TesselPointList::iterator Runner = connectedClosestPoints->begin();
    23502474  TesselPointList::iterator Sprinter = Runner;
     
    23562480    AddTesselationPoint((*Sprinter), 2);
    23572481
    2358 
    23592482    // add the lines
    23602483    AddTesselationLine(TPS[0], TPS[1], 0);
     
    23732496    Runner = Sprinter;
    23742497    Sprinter++;
     2498    Log() << Verbose(0) << "Current Runner is " << **Runner << "." << endl;
     2499    if (Sprinter != connectedClosestPoints->end())
     2500      Log() << Verbose(0) << " There are still more triangles to add." << endl;
    23752501  }
    23762502  delete(connectedClosestPoints);
     
    29573083  const BoundaryLineSet * lines[2] = { line1, line2 };
    29583084  class BoundaryPointSet *node = NULL;
    2959   map<int, class BoundaryPointSet *> OrderMap;
    2960   pair<map<int, class BoundaryPointSet *>::iterator, bool> OrderTest;
     3085  PointMap OrderMap;
     3086  PointTestPair OrderTest;
    29613087  for (int i = 0; i < 2; i++)
    29623088    // for both lines
     
    29783104};
    29793105
     3106/** Finds the boundary points that are closest to a given Vector \a *x.
     3107 * \param *out output stream for debugging
     3108 * \param *x Vector to look from
     3109 * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
     3110 */
     3111DistanceToPointMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const
     3112{
     3113  Info FunctionInfo(__func__);
     3114  PointMap::const_iterator FindPoint;
     3115  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
     3116
     3117  if (LinesOnBoundary.empty()) {
     3118    eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl;
     3119    return NULL;
     3120  }
     3121
     3122  // gather all points close to the desired one
     3123  LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
     3124  for(int i=0;i<NDIM;i++) // store indices of this cell
     3125    N[i] = LC->n[i];
     3126  Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     3127
     3128  DistanceToPointMap * points = new DistanceToPointMap;
     3129  LC->GetNeighbourBounds(Nlower, Nupper);
     3130  //Log() << Verbose(1) << endl;
     3131  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
     3132    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
     3133      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
     3134        const LinkedNodes *List = LC->GetCurrentCell();
     3135        //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
     3136        if (List != NULL) {
     3137          for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3138            FindPoint = PointsOnBoundary.find((*Runner)->nr);
     3139            if (FindPoint != PointsOnBoundary.end()) {
     3140              points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(x), FindPoint->second) );
     3141              Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl;
     3142            }
     3143          }
     3144        } else {
     3145          eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
     3146        }
     3147      }
     3148
     3149  // check whether we found some points
     3150  if (points->empty()) {
     3151    eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
     3152    delete(points);
     3153    return NULL;
     3154  }
     3155  return points;
     3156};
     3157
     3158/** Finds the boundary line that is closest to a given Vector \a *x.
     3159 * \param *out output stream for debugging
     3160 * \param *x Vector to look from
     3161 * \return closest BoundaryLineSet or NULL in degenerate case.
     3162 */
     3163BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const
     3164{
     3165  Info FunctionInfo(__func__);
     3166
     3167  // get closest points
     3168  DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3169  if (points == NULL) {
     3170    eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
     3171    return NULL;
     3172  }
     3173
     3174  // for each point, check its lines, remember closest
     3175  Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl;
     3176  BoundaryLineSet *ClosestLine = NULL;
     3177  double MinDistance = -1.;
     3178  Vector helper;
     3179  Vector Center;
     3180  Vector BaseLine;
     3181  for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
     3182    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
     3183      // calculate closest point on line to desired point
     3184      helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     3185      helper.AddVector((LineRunner->second)->endpoints[1]->node->node);
     3186      helper.Scale(0.5);
     3187      Center.CopyVector(x);
     3188      Center.SubtractVector(&helper);
     3189      BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     3190      BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3191      Center.ProjectOntoPlane(&BaseLine);
     3192      const double distance = Center.NormSquared();
     3193      if ((ClosestLine == NULL) || (distance < MinDistance)) {
     3194        // additionally calculate intersection on line (whether it's on the line section or not)
     3195        helper.CopyVector(x);
     3196        helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
     3197        helper.SubtractVector(&Center);
     3198        const double lengthA = helper.ScalarProduct(&BaseLine);
     3199        helper.CopyVector(x);
     3200        helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3201        helper.SubtractVector(&Center);
     3202        const double lengthB = helper.ScalarProduct(&BaseLine);
     3203        if (lengthB*lengthA < 0) {  // if have different sign
     3204          ClosestLine = LineRunner->second;
     3205          MinDistance = distance;
     3206          Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl;
     3207        } else {
     3208          Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl;
     3209        }
     3210      } else {
     3211        Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl;
     3212      }
     3213    }
     3214  }
     3215  delete(points);
     3216  // check whether closest line is "too close" :), then it's inside
     3217  if (ClosestLine == NULL) {
     3218    Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
     3219    return NULL;
     3220  }
     3221  return ClosestLine;
     3222};
     3223
     3224
    29803225/** Finds the triangle that is closest to a given Vector \a *x.
    29813226 * \param *out output stream for debugging
    29823227 * \param *x Vector to look from
    2983  * \return list of BoundaryTriangleSet of nearest triangles or NULL in degenerate case.
    2984  */
    2985 list<BoundaryTriangleSet*> * Tesselation::FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const
    2986 {
    2987         Info FunctionInfo(__func__);
    2988   TesselPoint *trianglePoints[3];
    2989   TesselPoint *SecondPoint = NULL;
    2990   list<BoundaryTriangleSet*> *triangles = NULL;
    2991 
    2992   if (LinesOnBoundary.empty()) {
    2993     eLog() << Verbose(1) << "Error: There is no tesselation structure to compare the point with, please create one first.";
     3228 * \return BoundaryTriangleSet of nearest triangle or NULL.
     3229 */
     3230TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
     3231{
     3232        Info FunctionInfo(__func__);
     3233
     3234        // get closest points
     3235        DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3236  if (points == NULL) {
     3237    eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
    29943238    return NULL;
    29953239  }
    2996   Log() << Verbose(1) << "Finding closest Tesselpoint to " << *x << " ... " << endl;
    2997   trianglePoints[0] = FindClosestPoint(x, SecondPoint, LC);
    2998  
    2999   // check whether closest point is "too close" :), then it's inside
    3000   if (trianglePoints[0] == NULL) {
     3240
     3241  // for each point, check its lines, remember closest
     3242  Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl;
     3243  LineSet ClosestLines;
     3244  double MinDistance = 1e+16;
     3245  Vector BaseLineIntersection;
     3246  Vector Center;
     3247  Vector BaseLine;
     3248  Vector BaseLineCenter;
     3249  for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
     3250    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
     3251
     3252      BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     3253      BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3254      const double lengthBase = BaseLine.NormSquared();
     3255
     3256      BaseLineIntersection.CopyVector(x);
     3257      BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
     3258      const double lengthEndA = BaseLineIntersection.NormSquared();
     3259
     3260      BaseLineIntersection.CopyVector(x);
     3261      BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3262      const double lengthEndB = BaseLineIntersection.NormSquared();
     3263
     3264      if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) {  // intersection would be outside, take closer endpoint
     3265        const double lengthEnd = Min(lengthEndA, lengthEndB);
     3266        if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
     3267          ClosestLines.clear();
     3268          ClosestLines.insert(LineRunner->second);
     3269          MinDistance = lengthEnd;
     3270          Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl;
     3271        } else if  (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
     3272          ClosestLines.insert(LineRunner->second);
     3273          Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl;
     3274        } else { // line is worse
     3275          Log() << Verbose(1) << "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << "." << endl;
     3276        }
     3277      } else { // intersection is closer, calculate
     3278        // calculate closest point on line to desired point
     3279        BaseLineIntersection.CopyVector(x);
     3280        BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3281        Center.CopyVector(&BaseLineIntersection);
     3282        Center.ProjectOntoPlane(&BaseLine);
     3283        BaseLineIntersection.SubtractVector(&Center);
     3284        const double distance = BaseLineIntersection.NormSquared();
     3285        if (Center.NormSquared() > BaseLine.NormSquared()) {
     3286          eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl;
     3287        }
     3288        if ((ClosestLines.empty()) || (distance < MinDistance)) {
     3289          ClosestLines.insert(LineRunner->second);
     3290          MinDistance = distance;
     3291          Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl;
     3292        } else {
     3293          Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl;
     3294        }
     3295      }
     3296    }
     3297  }
     3298  delete(points);
     3299
     3300  // check whether closest line is "too close" :), then it's inside
     3301  if (ClosestLines.empty()) {
    30013302    Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
    30023303    return NULL;
    30033304  }
    3004   if (trianglePoints[0]->node->DistanceSquared(x) < MYEPSILON) {
    3005     Log() << Verbose(1) << "Point is right on a tesselation point, no nearest triangle." << endl;
    3006     PointMap::const_iterator PointRunner = PointsOnBoundary.find(trianglePoints[0]->nr);
    3007     triangles = new list<BoundaryTriangleSet*>;
    3008     if (PointRunner != PointsOnBoundary.end()) {
    3009       for(LineMap::iterator LineRunner = PointRunner->second->lines.begin(); LineRunner != PointRunner->second->lines.end(); LineRunner++)
    3010         for(TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
    3011           triangles->push_back(TriangleRunner->second);
    3012       triangles->sort();
    3013       triangles->unique();
    3014     } else {
    3015       PointRunner = PointsOnBoundary.find(SecondPoint->nr);
    3016       trianglePoints[0] = SecondPoint;
    3017       if (PointRunner != PointsOnBoundary.end()) {
    3018         for(LineMap::iterator LineRunner = PointRunner->second->lines.begin(); LineRunner != PointRunner->second->lines.end(); LineRunner++)
    3019           for(TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
    3020             triangles->push_back(TriangleRunner->second);
    3021         triangles->sort();
    3022         triangles->unique();
    3023       } else {
    3024         eLog() << Verbose(1) << "I cannot find a boundary point to the tessel point " << *trianglePoints[0] << "." << endl;
    3025         return NULL;
    3026       }
    3027     }
    3028   } else {
    3029     set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(trianglePoints[0]);
    3030     TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(connectedPoints, trianglePoints[0], x);
    3031     delete(connectedPoints);
    3032     if (connectedClosestPoints != NULL) {
    3033       trianglePoints[1] = connectedClosestPoints->front();
    3034       trianglePoints[2] = connectedClosestPoints->back();
    3035       for (int i=0;i<3;i++) {
    3036         if (trianglePoints[i] == NULL) {
    3037           eLog() << Verbose(1) << "IsInnerPoint encounters serious error, point " << i << " not found." << endl;
    3038         }
    3039         //Log() << Verbose(1) << "List of triangle points:" << endl;
    3040         //Log() << Verbose(2) << *trianglePoints[i] << endl;
    3041       }
    3042 
    3043       triangles = FindTriangles(trianglePoints);
    3044       Log() << Verbose(1) << "List of possible triangles:" << endl;
    3045       for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    3046         Log() << Verbose(2) << **Runner << endl;
    3047 
    3048       delete(connectedClosestPoints);
    3049     } else {
    3050       triangles = NULL;
    3051       eLog() << Verbose(2) << "There is no circle of connected points!" << endl;
    3052     }
    3053   }
    3054  
    3055   if ((triangles == NULL) || (triangles->empty())) {
    3056     eLog() << Verbose(1) << "There is no nearest triangle. Please check the tesselation structure.";
    3057     delete(triangles);
    3058     return NULL;
    3059   } else
    3060     return triangles;
     3305  TriangleList * candidates = new TriangleList;
     3306  for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
     3307    for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
     3308    candidates->push_back(Runner->second);
     3309  }
     3310  return candidates;
    30613311};
    30623312
     
    30673317 * \return list of BoundaryTriangleSet of nearest triangles or NULL.
    30683318 */
    3069 class BoundaryTriangleSet * Tesselation::FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const
     3319class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
    30703320{
    30713321        Info FunctionInfo(__func__);
    30723322  class BoundaryTriangleSet *result = NULL;
    3073   list<BoundaryTriangleSet*> *triangles = FindClosestTrianglesToPoint(x, LC);
     3323  TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
     3324  TriangleList candidates;
    30743325  Vector Center;
    3075 
    3076   if (triangles == NULL)
     3326  Vector helper;
     3327
     3328  if ((triangles == NULL) || (triangles->empty()))
    30773329    return NULL;
    30783330
    3079   if (triangles->size() == 1) { // there is no degenerate case
    3080     result = triangles->front();
    3081     Log() << Verbose(1) << "Normal Vector of this triangle is " << result->NormalVector << "." << endl;
    3082   } else {
    3083     result = triangles->front();
    3084     result->GetCenter(&Center);
    3085     Center.SubtractVector(x);
    3086     Log() << Verbose(1) << "Normal Vector of this front side is " << result->NormalVector << "." << endl;
    3087     if (Center.ScalarProduct(&result->NormalVector) < 0) {
    3088       result = triangles->back();
    3089       Log() << Verbose(1) << "Normal Vector of this back side is " << result->NormalVector << "." << endl;
    3090       if (Center.ScalarProduct(&result->NormalVector) < 0) {
    3091         eLog() << Verbose(1) << "Front and back side yield NormalVector in wrong direction!" << endl;
    3092       }
     3331  // go through all and pick the one with the best alignment to x
     3332  double MinAlignment = 2.*M_PI;
     3333  for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
     3334    (*Runner)->GetCenter(&Center);
     3335    helper.CopyVector(x);
     3336    helper.SubtractVector(&Center);
     3337    const double Alignment = helper.Angle(&(*Runner)->NormalVector);
     3338    if (Alignment < MinAlignment) {
     3339      result = *Runner;
     3340      MinAlignment = Alignment;
     3341      Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl;
     3342    } else {
     3343      Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl;
    30933344    }
    30943345  }
    30953346  delete(triangles);
     3347
    30963348  return result;
    30973349};
    30983350
    3099 /** Checks whether the provided Vector is within the tesselation structure.
     3351/** Checks whether the provided Vector is within the Tesselation structure.
     3352 * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value.
     3353 * @param point of which to check the position
     3354 * @param *LC LinkedCell structure
     3355 *
     3356 * @return true if the point is inside the Tesselation structure, false otherwise
     3357 */
     3358bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
     3359{
     3360  return (GetDistanceSquaredToSurface(Point, LC) < MYEPSILON);
     3361}
     3362
     3363/** Returns the distance to the surface given by the tesselation.
     3364 * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points
     3365 * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the
     3366 * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's
     3367 * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle().
     3368 * In the end we additionally find the point on the triangle who was smallest distance to \a Point:
     3369 *  -# Separate distance from point to center in vector in NormalDirection and on the triangle plane.
     3370 *  -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds.
     3371 *  -# If inside, take it to calculate closest distance
     3372 *  -# If not, take intersection with BoundaryLine as distance
     3373 *
     3374 * @note distance is squared despite it still contains a sign to determine in-/outside!
    31003375 *
    31013376 * @param point of which to check the position
    31023377 * @param *LC LinkedCell structure
    31033378 *
    3104  * @return true if the point is inside the tesselation structure, false otherwise
    3105  */
    3106 bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
    3107 {
    3108         Info FunctionInfo(__func__);
    3109   class BoundaryTriangleSet *result = FindClosestTriangleToPoint(&Point, LC);
     3379 * @return >0 if outside, ==0 if on surface, <0 if inside
     3380 */
     3381double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
     3382{
     3383  Info FunctionInfo(__func__);
    31103384  Vector Center;
    3111 
    3112   if (result == NULL) {// is boundary point or only point in point cloud?
    3113     Log() << Verbose(1) << Point << " is the only point in vicinity." << endl;
    3114     return false;
    3115   }
    3116 
    3117   result->GetCenter(&Center);
     3385  Vector helper;
     3386  Vector DistanceToCenter;
     3387  Vector Intersection;
     3388  double distance = 0.;
     3389
     3390  if (triangle == NULL) {// is boundary point or only point in point cloud?
     3391    Log() << Verbose(1) << "No triangle given!" << endl;
     3392    return -1.;
     3393  } else {
     3394    Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl;
     3395  }
     3396
     3397  triangle->GetCenter(&Center);
    31183398  Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
    3119   Center.SubtractVector(&Point);
    3120   Log() << Verbose(2) << "INFO: Vector from center to point to test is " << Center << "." << endl;
    3121   if (Center.ScalarProduct(&result->NormalVector) > -MYEPSILON) {
    3122     Log() << Verbose(1) << Point << " is an inner point." << endl;
    3123     return true;
     3399  DistanceToCenter.CopyVector(&Center);
     3400  DistanceToCenter.SubtractVector(&Point);
     3401  Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl;
     3402
     3403  // check whether we are on boundary
     3404  if (fabs(DistanceToCenter.ScalarProduct(&triangle->NormalVector)) < MYEPSILON) {
     3405    // calculate whether inside of triangle
     3406    DistanceToCenter.CopyVector(&Point);
     3407    Center.CopyVector(&Point);
     3408    Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
     3409    DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
     3410    Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl;
     3411    if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
     3412      Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl;
     3413      return 0.;
     3414    } else {
     3415      Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl;
     3416      return false;
     3417    }
    31243418  } else {
    3125     Log() << Verbose(1) << Point << " is NOT an inner point." << endl;
    3126     return false;
    3127   }
    3128 }
    3129 
    3130 /** Checks whether the provided TesselPoint is within the tesselation structure.
    3131  *
    3132  * @param *Point of which to check the position
    3133  * @param *LC Linked Cell structure
    3134  *
    3135  * @return true if the point is inside the tesselation structure, false otherwise
    3136  */
    3137 bool Tesselation::IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const
    3138 {
    3139         Info FunctionInfo(__func__);
    3140   return IsInnerPoint(*(Point->node), LC);
    3141 }
     3419    // calculate smallest distance
     3420    distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
     3421    Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl;
     3422
     3423    // then check direction to boundary
     3424    if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
     3425      Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl;
     3426      return -distance;
     3427    } else {
     3428      Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl;
     3429      return +distance;
     3430    }
     3431  }
     3432};
     3433
     3434/** Calculates distance to a tesselated surface.
     3435 * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
     3436 * \param &Point point to calculate distance from
     3437 * \param *LC needed for finding closest points fast
     3438 * \return distance squared to closest point on surface
     3439 */
     3440double Tesselation::GetDistanceSquaredToSurface(const Vector &Point, const LinkedCell* const LC) const
     3441{
     3442  BoundaryTriangleSet *triangle = FindClosestTriangleToVector(&Point, LC);
     3443  const double distance = GetDistanceSquaredToTriangle(Point, triangle);
     3444  return Min(distance, LC->RADIUS);
     3445};
    31423446
    31433447/** Gets all points connected to the provided point by triangulation lines.
     
    31473451 * @return set of the all points linked to the provided one
    31483452 */
    3149 set<TesselPoint*> * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    3150 {
    3151         Info FunctionInfo(__func__);
    3152   set<TesselPoint*> *connectedPoints = new set<TesselPoint*>;
     3453TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
     3454{
     3455        Info FunctionInfo(__func__);
     3456        TesselPointSet *connectedPoints = new TesselPointSet;
    31533457  class BoundaryPointSet *ReferencePoint = NULL;
    31543458  TesselPoint* current;
     
    31913495  }
    31923496
    3193   if (connectedPoints->size() == 0) { // if have not found any points
     3497  if (connectedPoints->empty()) { // if have not found any points
    31943498    eLog() << Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl;
    31953499    return NULL;
     
    32123516 * @return list of the all points linked to the provided one
    32133517 */
    3214 list<TesselPoint*> * Tesselation::GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
     3518TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    32153519{
    32163520        Info FunctionInfo(__func__);
    32173521  map<double, TesselPoint*> anglesOfPoints;
    3218   list<TesselPoint*> *connectedCircle = new list<TesselPoint*>;
    3219   Vector center;
     3522  TesselPointList *connectedCircle = new TesselPointList;
    32203523  Vector PlaneNormal;
    32213524  Vector AngleZero;
    32223525  Vector OrthogonalVector;
    32233526  Vector helper;
     3527  const TesselPoint * const TrianglePoints[3] = {Point, NULL, NULL};
     3528  TriangleList *triangles = NULL;
    32243529
    32253530  if (SetOfNeighbours == NULL) {
     
    32303535
    32313536  // calculate central point
    3232   for (set<TesselPoint*>::const_iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
    3233     center.AddVector((*TesselRunner)->node);
    3234   //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
    3235   //  << "; scale factor " << 1.0/connectedPoints.size();
    3236   center.Scale(1.0/SetOfNeighbours->size());
    3237   Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
    3238 
    3239   // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
    3240   PlaneNormal.CopyVector(Point->node);
    3241   PlaneNormal.SubtractVector(&center);
     3537  triangles = FindTriangles(TrianglePoints);
     3538  if ((triangles != NULL) && (!triangles->empty())) {
     3539    for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
     3540      PlaneNormal.AddVector(&(*Runner)->NormalVector);
     3541  } else {
     3542    eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl;
     3543    performCriticalExit();
     3544  }
     3545  PlaneNormal.Scale(1.0/triangles->size());
     3546  Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl;
    32423547  PlaneNormal.Normalize();
    3243   Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
    32443548
    32453549  // construct one orthogonal vector
     
    32673571
    32683572  // go through all connected points and calculate angle
    3269   for (set<TesselPoint*>::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
     3573  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    32703574    helper.CopyVector((*listRunner)->node);
    32713575    helper.SubtractVector(Point->node);
     
    32833587}
    32843588
     3589/** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
     3590 * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
     3591 * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
     3592 * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
     3593 * triangle we are looking for.
     3594 *
     3595 * @param *SetOfNeighbours all points for which the angle should be calculated
     3596 * @param *Point of which get all connected points
     3597 * @param *Reference Reference vector for zero angle or NULL for no preference
     3598 * @return list of the all points linked to the provided one
     3599 */
     3600TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
     3601{
     3602  Info FunctionInfo(__func__);
     3603  map<double, TesselPoint*> anglesOfPoints;
     3604  TesselPointList *connectedCircle = new TesselPointList;
     3605  Vector center;
     3606  Vector PlaneNormal;
     3607  Vector AngleZero;
     3608  Vector OrthogonalVector;
     3609  Vector helper;
     3610
     3611  if (SetOfNeighbours == NULL) {
     3612    eLog() << Verbose(2) << "Could not find any connected points!" << endl;
     3613    delete(connectedCircle);
     3614    return NULL;
     3615  }
     3616
     3617  // check whether there's something to do
     3618  if (SetOfNeighbours->size() < 3) {
     3619    for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
     3620      connectedCircle->push_back(*TesselRunner);
     3621    return connectedCircle;
     3622  }
     3623
     3624  Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl;
     3625  // calculate central point
     3626
     3627  TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
     3628  TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
     3629  TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin();
     3630  TesselB++;
     3631  TesselC++;
     3632  TesselC++;
     3633  int counter = 0;
     3634  while (TesselC != SetOfNeighbours->end()) {
     3635    helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
     3636    Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl;
     3637    counter++;
     3638    TesselA++;
     3639    TesselB++;
     3640    TesselC++;
     3641    PlaneNormal.AddVector(&helper);
     3642  }
     3643  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
     3644  //  << "; scale factor " << counter;
     3645  PlaneNormal.Scale(1.0/(double)counter);
     3646//  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
     3647//
     3648//  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
     3649//  PlaneNormal.CopyVector(Point->node);
     3650//  PlaneNormal.SubtractVector(&center);
     3651//  PlaneNormal.Normalize();
     3652  Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
     3653
     3654  // construct one orthogonal vector
     3655  if (Reference != NULL) {
     3656    AngleZero.CopyVector(Reference);
     3657    AngleZero.SubtractVector(Point->node);
     3658    AngleZero.ProjectOntoPlane(&PlaneNormal);
     3659  }
     3660  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
     3661    Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
     3662    AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
     3663    AngleZero.SubtractVector(Point->node);
     3664    AngleZero.ProjectOntoPlane(&PlaneNormal);
     3665    if (AngleZero.NormSquared() < MYEPSILON) {
     3666      eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
     3667      performCriticalExit();
     3668    }
     3669  }
     3670  Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
     3671  if (AngleZero.NormSquared() > MYEPSILON)
     3672    OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3673  else
     3674    OrthogonalVector.MakeNormalVector(&PlaneNormal);
     3675  Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
     3676
     3677  // go through all connected points and calculate angle
     3678  pair <map<double, TesselPoint*>::iterator, bool > InserterTest;
     3679  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
     3680    helper.CopyVector((*listRunner)->node);
     3681    helper.SubtractVector(Point->node);
     3682    helper.ProjectOntoPlane(&PlaneNormal);
     3683    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
     3684    if (angle > M_PI) // the correction is of no use here (and not desired)
     3685      angle = 2.*M_PI - angle;
     3686    Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl;
     3687    InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
     3688    if (!InserterTest.second) {
     3689      eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl;
     3690      performCriticalExit();
     3691    }
     3692  }
     3693
     3694  for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
     3695    connectedCircle->push_back(AngleRunner->second);
     3696  }
     3697
     3698  return connectedCircle;
     3699}
     3700
    32853701/** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path.
    32863702 *
     
    32893705 * @return list of the all points linked to the provided one
    32903706 */
    3291 list<list<TesselPoint*> *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
     3707ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    32923708{
    32933709        Info FunctionInfo(__func__);
    32943710  map<double, TesselPoint*> anglesOfPoints;
    3295   list<list<TesselPoint*> *> *ListOfPaths = new list<list<TesselPoint*> *>;
    3296   list<TesselPoint*> *connectedPath = NULL;
     3711  list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;
     3712  TesselPointList *connectedPath = NULL;
    32973713  Vector center;
    32983714  Vector PlaneNormal;
     
    33313747      } else if (!LineRunner->second) {
    33323748        LineRunner->second = true;
    3333         connectedPath = new list<TesselPoint*>;
     3749        connectedPath = new TesselPointList;
    33343750        triangle = NULL;
    33353751        CurrentLine = runner->second;
     
    34053821 * @return list of the closed paths
    34063822 */
    3407 list<list<TesselPoint*> *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    3408 {
    3409         Info FunctionInfo(__func__);
    3410   list<list<TesselPoint*> *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    3411   list<list<TesselPoint*> *> *ListofClosedPaths = new list<list<TesselPoint*> *>;
    3412   list<TesselPoint*> *connectedPath = NULL;
    3413   list<TesselPoint*> *newPath = NULL;
     3823ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
     3824{
     3825        Info FunctionInfo(__func__);
     3826  list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
     3827  list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *>;
     3828  TesselPointList *connectedPath = NULL;
     3829  TesselPointList *newPath = NULL;
    34143830  int count = 0;
    34153831
    34163832
    3417   list<TesselPoint*>::iterator CircleRunner;
    3418   list<TesselPoint*>::iterator CircleStart;
    3419 
    3420   for(list<list<TesselPoint*> *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
     3833  TesselPointList::iterator CircleRunner;
     3834  TesselPointList::iterator CircleStart;
     3835
     3836  for(list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
    34213837    connectedPath = *ListRunner;
    34223838
     
    34273843
    34283844    // go through list, look for reappearance of starting Point and create list
    3429     list<TesselPoint*>::iterator Marker = CircleStart;
     3845    TesselPointList::iterator Marker = CircleStart;
    34303846    for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
    34313847      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    34323848        // we have a closed circle from Marker to new Marker
    34333849        Log() << Verbose(1) << count+1 << ". closed path consists of: ";
    3434         newPath = new list<TesselPoint*>;
    3435         list<TesselPoint*>::iterator CircleSprinter = Marker;
     3850        newPath = new TesselPointList;
     3851        TesselPointList::iterator CircleSprinter = Marker;
    34363852        for (; CircleSprinter != CircleRunner; CircleSprinter++) {
    34373853          newPath->push_back(*CircleSprinter);
     
    34673883 * \return pointer to allocated list of triangles
    34683884 */
    3469 set<BoundaryTriangleSet*> *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    3470 {
    3471         Info FunctionInfo(__func__);
    3472   set<BoundaryTriangleSet*> *connectedTriangles = new set<BoundaryTriangleSet*>;
     3885TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
     3886{
     3887        Info FunctionInfo(__func__);
     3888        TriangleSet *connectedTriangles = new TriangleSet;
    34733889
    34743890  if (Point == NULL) {
     
    35193935  }
    35203936
    3521   list<list<TesselPoint*> *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
    3522   list<TesselPoint*> *connectedPath = NULL;
     3937  list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
     3938  TesselPointList *connectedPath = NULL;
    35233939
    35243940  // gather all triangles
    35253941  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
    35263942    count+=LineRunner->second->triangles.size();
    3527   map<class BoundaryTriangleSet *, int> Candidates;
     3943  TriangleMap Candidates;
    35283944  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    35293945    line = LineRunner->second;
    35303946    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    35313947      triangle = TriangleRunner->second;
    3532       Candidates.insert( pair<class BoundaryTriangleSet *, int> (triangle, triangle->Nr) );
     3948      Candidates.insert( TrianglePair (triangle->Nr, triangle) );
    35333949    }
    35343950  }
     
    35373953  count=0;
    35383954  NormalVector.Zero();
    3539   for (map<class BoundaryTriangleSet *, int>::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    3540     Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
    3541     NormalVector.SubtractVector(&Runner->first->NormalVector); // has to point inward
    3542     RemoveTesselationTriangle(Runner->first);
     3955  for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
     3956    Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl;
     3957    NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
     3958    RemoveTesselationTriangle(Runner->second);
    35433959    count++;
    35443960  }
    35453961  Log() << Verbose(1) << count << " triangles were removed." << endl;
    35463962
    3547   list<list<TesselPoint*> *>::iterator ListAdvance = ListOfClosedPaths->begin();
    3548   list<list<TesselPoint*> *>::iterator ListRunner = ListAdvance;
    3549   map<class BoundaryTriangleSet *, int>::iterator NumberRunner = Candidates.begin();
    3550   list<TesselPoint*>::iterator StartNode, MiddleNode, EndNode;
     3963  list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
     3964  list<TesselPointList *>::iterator ListRunner = ListAdvance;
     3965  TriangleMap::iterator NumberRunner = Candidates.begin();
     3966  TesselPointList::iterator StartNode, MiddleNode, EndNode;
    35513967  double angle;
    35523968  double smallestangle;
     
    35623978
    35633979      // re-create all triangles by going through connected points list
    3564       list<class BoundaryLineSet *> NewLines;
     3980      LineList NewLines;
    35653981      for (;!connectedPath->empty();) {
    35663982        // search middle node with widest angle to next neighbours
     
    36684084      // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
    36694085      if (NewLines.size() > 1) {
    3670         list<class BoundaryLineSet *>::iterator Candidate;
     4086        LineList::iterator Candidate;
    36714087        class BoundaryLineSet *OtherBase = NULL;
    36724088        double tmp, maxgain;
    36734089        do {
    36744090          maxgain = 0;
    3675           for(list<class BoundaryLineSet *>::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
     4091          for(LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
    36764092            tmp = PickFarthestofTwoBaselines(*Runner);
    36774093            if (maxgain < tmp) {
     
    37154131 * Finds triangles belonging to the three provided points.
    37164132 *
    3717  * @param *Points[3] list, is expected to contain three points
     4133 * @param *Points[3] list, is expected to contain three points (NULL means wildcard)
    37184134 *
    37194135 * @return triangles which belong to the provided points, will be empty if there are none,
    37204136 *         will usually be one, in case of degeneration, there will be two
    37214137 */
    3722 list<BoundaryTriangleSet*> *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    3723 {
    3724         Info FunctionInfo(__func__);
    3725   list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;
     4138TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
     4139{
     4140        Info FunctionInfo(__func__);
     4141        TriangleList *result = new TriangleList;
    37264142  LineMap::const_iterator FindLine;
    37274143  TriangleMap::const_iterator FindTriangle;
    37284144  class BoundaryPointSet *TrianglePoints[3];
     4145  size_t NoOfWildcards = 0;
    37294146
    37304147  for (int i = 0; i < 3; i++) {
    3731     PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
    3732     if (FindPoint != PointsOnBoundary.end()) {
    3733       TrianglePoints[i] = FindPoint->second;
     4148    if (Points[i] == NULL) {
     4149      NoOfWildcards++;
     4150      TrianglePoints[i] = NULL;
    37344151    } else {
    3735       TrianglePoints[i] = NULL;
    3736     }
    3737   }
    3738 
    3739   // checks lines between the points in the Points for their adjacent triangles
    3740   for (int i = 0; i < 3; i++) {
    3741     if (TrianglePoints[i] != NULL) {
    3742       for (int j = i+1; j < 3; j++) {
    3743         if (TrianglePoints[j] != NULL) {
    3744           for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
    3745               (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
    3746               FindLine++) {
    3747             for (FindTriangle = FindLine->second->triangles.begin();
    3748                 FindTriangle != FindLine->second->triangles.end();
    3749                 FindTriangle++) {
    3750               if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    3751                 result->push_back(FindTriangle->second);
     4152      PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
     4153      if (FindPoint != PointsOnBoundary.end()) {
     4154        TrianglePoints[i] = FindPoint->second;
     4155      } else {
     4156        TrianglePoints[i] = NULL;
     4157      }
     4158    }
     4159  }
     4160
     4161  switch (NoOfWildcards) {
     4162    case 0: // checks lines between the points in the Points for their adjacent triangles
     4163      for (int i = 0; i < 3; i++) {
     4164        if (TrianglePoints[i] != NULL) {
     4165          for (int j = i+1; j < 3; j++) {
     4166            if (TrianglePoints[j] != NULL) {
     4167              for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
     4168                  (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
     4169                  FindLine++) {
     4170                for (FindTriangle = FindLine->second->triangles.begin();
     4171                    FindTriangle != FindLine->second->triangles.end();
     4172                    FindTriangle++) {
     4173                  if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
     4174                    result->push_back(FindTriangle->second);
     4175                  }
     4176                }
    37524177              }
     4178              // Is it sufficient to consider one of the triangle lines for this.
     4179              return result;
    37534180            }
    37544181          }
    3755           // Is it sufficient to consider one of the triangle lines for this.
    3756           return result;
    37574182        }
    37584183      }
    3759     }
     4184      break;
     4185    case 1: // copy all triangles of the respective line
     4186    {
     4187      int i=0;
     4188      for (; i < 3; i++)
     4189        if (TrianglePoints[i] == NULL)
     4190          break;
     4191      for (FindLine = TrianglePoints[(i+1)%3]->lines.find(TrianglePoints[(i+2)%3]->node->nr); // is a multimap!
     4192          (FindLine != TrianglePoints[(i+1)%3]->lines.end()) && (FindLine->first == TrianglePoints[(i+2)%3]->node->nr);
     4193          FindLine++) {
     4194        for (FindTriangle = FindLine->second->triangles.begin();
     4195            FindTriangle != FindLine->second->triangles.end();
     4196            FindTriangle++) {
     4197          if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
     4198            result->push_back(FindTriangle->second);
     4199          }
     4200        }
     4201      }
     4202      break;
     4203    }
     4204    case 2: // copy all triangles of the respective point
     4205    {
     4206      int i=0;
     4207      for (; i < 3; i++)
     4208        if (TrianglePoints[i] != NULL)
     4209          break;
     4210      for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++)
     4211        for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++)
     4212          result->push_back(triangle->second);
     4213      result->sort();
     4214      result->unique();
     4215      break;
     4216    }
     4217    case 3: // copy all triangles
     4218    {
     4219      for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++)
     4220        result->push_back(triangle->second);
     4221      break;
     4222    }
     4223    default:
     4224      eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl;
     4225      performCriticalExit();
     4226      break;
    37604227  }
    37614228
     
    38004267 *         in the list, once as key and once as value
    38014268 */
    3802 map<int, int> * Tesselation::FindAllDegeneratedLines()
     4269IndexToIndex * Tesselation::FindAllDegeneratedLines()
    38034270{
    38044271        Info FunctionInfo(__func__);
    38054272        UniqueLines AllLines;
    3806   map<int, int> * DegeneratedLines = new map<int, int>;
     4273  IndexToIndex * DegeneratedLines = new IndexToIndex;
    38074274
    38084275  // sanity check
     
    38254292
    38264293  Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
    3827   map<int,int>::iterator it;
     4294  IndexToIndex::iterator it;
    38284295  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
    38294296    const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
     
    38444311 *         in the list, once as key and once as value
    38454312 */
    3846 map<int, int> * Tesselation::FindAllDegeneratedTriangles()
    3847 {
    3848         Info FunctionInfo(__func__);
    3849   map<int, int> * DegeneratedLines = FindAllDegeneratedLines();
    3850   map<int, int> * DegeneratedTriangles = new map<int, int>;
     4313IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
     4314{
     4315        Info FunctionInfo(__func__);
     4316  IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
     4317  IndexToIndex * DegeneratedTriangles = new IndexToIndex;
    38514318
    38524319  TriangleMap::iterator TriangleRunner1, TriangleRunner2;
     
    38544321  class BoundaryLineSet *line1 = NULL, *line2 = NULL;
    38554322
    3856   for (map<int, int>::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
     4323  for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
    38574324    // run over both lines' triangles
    38584325    Liner = LinesOnBoundary.find(LineRunner->first);
     
    38754342
    38764343  Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
    3877   map<int,int>::iterator it;
     4344  IndexToIndex::iterator it;
    38784345  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    38794346      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     
    38894356{
    38904357        Info FunctionInfo(__func__);
    3891   map<int, int> * DegeneratedTriangles = FindAllDegeneratedTriangles();
     4358  IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
    38924359  TriangleMap::iterator finder;
    38934360  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    38944361  int count  = 0;
    38954362
    3896   for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
     4363  for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
    38974364    TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
    38984365  ) {
     
    39824449  // find nearest boundary point
    39834450  class TesselPoint *BackupPoint = NULL;
    3984   class TesselPoint *NearestPoint = FindClosestPoint(point->node, BackupPoint, LC);
     4451  class TesselPoint *NearestPoint = FindClosestTesselPoint(point->node, BackupPoint, LC);
    39854452  class BoundaryPointSet *NearestBoundaryPoint = NULL;
    39864453  PointMap::iterator PointRunner;
     
    41494616
    41504617  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
    4151   map <int, int> *DegeneratedTriangles = FindAllDegeneratedTriangles();
     4618  IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
    41524619  set < BoundaryPointSet *> EndpointCandidateList;
    41534620  pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
     
    43014768  }
    43024769
    4303   map<int, int> * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
     4770  IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
    43044771  Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
    4305   map<int,int>::iterator it;
     4772  IndexToIndex::iterator it;
    43064773  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
    43074774      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
Note: See TracChangeset for help on using the changeset viewer.