Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/tesselation.cpp

    rd6b011 r78dac6  
    1616  LinesCount = 0;
    1717  Nr = -1;
     18  value = 0.;
    1819};
    1920
     
    2627  LinesCount = 0;
    2728  Nr = Walker->nr;
     29  value = 0.;
    2830};
    2931
     
    148150void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
    149151{
    150   cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "."
    151       << endl;
     152  cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
    152153  triangles.insert(TrianglePair(triangle->Nr, triangle));
    153154};
     
    177178  if (triangles.size() != 2) {
    178179    *out << Verbose(1) << "ERROR: Baseline " << *this << " is connect to less than two triangles, Tesselation incomplete!" << endl;
    179     return false;
     180    return true;
    180181  }
    181182  // check normal vectors
    182183  // have a normal vector on the base line pointing outwards
    183   *out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
     184  //*out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
    184185  BaseLineCenter.CopyVector(endpoints[0]->node->node);
    185186  BaseLineCenter.AddVector(endpoints[1]->node->node);
     
    187188  BaseLine.CopyVector(endpoints[0]->node->node);
    188189  BaseLine.SubtractVector(endpoints[1]->node->node);
    189   *out << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
     190  //*out << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
    190191
    191192  BaseLineNormal.Zero();
     
    195196  class BoundaryPointSet *node = NULL;
    196197  for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    197     *out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
     198    //*out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    198199    NormalCheck.AddVector(&runner->second->NormalVector);
    199200    NormalCheck.Scale(sign);
     
    202203    node = runner->second->GetThirdEndpoint(this);
    203204    if (node != NULL) {
    204       *out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
     205      //*out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    205206      helper[i].CopyVector(node->node->node);
    206207      helper[i].SubtractVector(&BaseLineCenter);
    207208      helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
    208       *out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
     209      //*out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    209210      i++;
    210211    } else {
    211       *out << Verbose(2) << "WARNING: I cannot find third node in triangle, something's wrong." << endl;
     212      //*out << Verbose(2) << "WARNING: I cannot find third node in triangle, something's wrong." << endl;
    212213      return true;
    213214    }
    214215  }
    215   *out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
     216  //*out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
    216217  if (NormalCheck.NormSquared() < MYEPSILON) {
    217     *out << Verbose(3) << "Normalvectors of both triangles are the same: convex." << endl;
     218    *out << Verbose(2) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
    218219    return true;
    219220  }
    220   double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    221   if ((angle - M_PI) > -MYEPSILON)
     221  double angle = getAngle(helper[0], helper[1], BaseLineNormal);
     222  if ((angle - M_PI) > -MYEPSILON) {
     223    *out << Verbose(2) << "ACCEPT: Angle is greater than pi: convex." << endl;
    222224    return true;
    223   else
     225  } else {
     226    *out << Verbose(2) << "REJECT: Angle is less than pi: concave." << endl;
    224227    return false;
     228  }
    225229}
    226230
     
    349353
    350354  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    351   if (NormalVector.Projection(&OtherVector) > 0)
     355  if (NormalVector.ScalarProduct(&OtherVector) > 0.)
    352356    NormalVector.Scale(-1.);
    353357};
     
    737741          TrialVector.CopyVector(checker->second->node->node);
    738742          TrialVector.SubtractVector(A->second->node->node);
    739           distance = TrialVector.Projection(&PlaneVector);
     743          distance = TrialVector.ScalarProduct(&PlaneVector);
    740744          if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    741745            continue;
     
    897901        TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    898902        //*out << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    899         if (PropagationVector.Projection(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
     903        if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
    900904          PropagationVector.Scale(-1.);
    901905        *out << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl;
     
    957961            TempVector.SubtractVector(Center);
    958962            // make it always point outward
    959             if (VirtualNormalVector.Projection(&TempVector) < 0)
     963            if (VirtualNormalVector.ScalarProduct(&TempVector) < 0)
    960964              VirtualNormalVector.Scale(-1.);
    961965            // calculate angle
     
    13981402
    13991403
    1400 /** Finds the starting triangle for FindNonConvexBorder().
    1401  * Looks at the outermost point per axis, then FindSecondPointForTesselation()
    1402  * for the second and FindNextSuitablePointViaAngleOfSphere() for the third
     1404/** Finds the starting triangle for find_non_convex_border().
     1405 * Looks at the outermost point per axis, then Find_second_point_for_Tesselation()
     1406 * for the second and Find_next_suitable_point_via_Angle_of_Sphere() for the third
    14031407 * point are called.
    14041408 * \param *out output stream for debugging
     
    14061410 * \param *LC LinkedCell structure with neighbouring TesselPoint's
    14071411 */
    1408 void Tesselation::FindStartingTriangle(ofstream *out, const double RADIUS, LinkedCell *LC)
    1409 {
    1410   cout << Verbose(1) << "Begin of FindStartingTriangle\n";
     1412void Tesselation::Find_starting_triangle(ofstream *out, const double RADIUS, LinkedCell *LC)
     1413{
     1414  cout << Verbose(1) << "Begin of Find_starting_triangle\n";
    14111415  int i = 0;
    14121416  LinkedNodes *List = NULL;
     
    14141418  TesselPoint* SecondPoint = NULL;
    14151419  TesselPoint* MaxPoint[NDIM];
    1416   double maxCoordinate[NDIM];
     1420  double max_coordinate[NDIM];
    14171421  Vector Oben;
    14181422  Vector helper;
     
    14241428  for (i = 0; i < 3; i++) {
    14251429    MaxPoint[i] = NULL;
    1426     maxCoordinate[i] = -1;
     1430    max_coordinate[i] = -1;
    14271431  }
    14281432
     
    14361440        if (List != NULL) {
    14371441          for (LinkedNodes::iterator Runner = List->begin();Runner != List->end();Runner++) {
    1438             if ((*Runner)->node->x[i] > maxCoordinate[i]) {
     1442            if ((*Runner)->node->x[i] > max_coordinate[i]) {
    14391443              cout << Verbose(2) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
    1440               maxCoordinate[i] = (*Runner)->node->x[i];
     1444              max_coordinate[i] = (*Runner)->node->x[i];
    14411445              MaxPoint[i] = (*Runner);
    14421446            }
     
    14541458
    14551459  BTS = NULL;
    1456   CandidateList *OptCandidates = new CandidateList();
     1460  CandidateList *Opt_Candidates = new CandidateList();
    14571461  for (int k=0;k<NDIM;k++) {
    14581462    Oben.x[k] = 1.;
     
    14611465
    14621466    double ShortestAngle;
    1463     TesselPoint* OptCandidate = NULL;
     1467    TesselPoint* Opt_Candidate = NULL;
    14641468    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.
    14651469
    1466     FindSecondPointForTesselation(FirstPoint, NULL, Oben, OptCandidate, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
    1467     SecondPoint = OptCandidate;
     1470    Find_second_point_for_Tesselation(FirstPoint, NULL, Oben, Opt_Candidate, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
     1471    SecondPoint = Opt_Candidate;
    14681472    if (SecondPoint == NULL)  // have we found a second point?
    14691473      continue;
     
    14961500
    14971501    //cout << Verbose(2) << "INFO: OldSphereCenter is at " << helper << ".\n";
    1498     FindThirdPointForTesselation(
    1499       Oben, SearchDirection, helper, BLS[0], NULL, *&OptCandidates, &ShortestAngle, RADIUS, LC
     1502    Find_third_point_for_Tesselation(
     1503      Oben, SearchDirection, helper, BLS[0], NULL, *&Opt_Candidates, &ShortestAngle, RADIUS, LC
    15001504    );
    15011505    cout << Verbose(1) << "List of third Points is ";
    1502     for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1506    for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) {
    15031507        cout << " " << *(*it)->point;
    15041508    }
    15051509    cout << endl;
    15061510
    1507     for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1511    for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) {
    15081512      // add third triangle point
    15091513      AddTesselationPoint((*it)->point, 2);
     
    15221526
    15231527      // if we do not reach the end with the next step of iteration, we need to setup a new first line
    1524       if (it != OptCandidates->end()--) {
     1528      if (it != Opt_Candidates->end()--) {
    15251529        FirstPoint = (*it)->BaseLine->endpoints[0]->node;
    15261530        SecondPoint = (*it)->point;
     
    15301534        AddTesselationLine(TPS[0], TPS[1], 0);
    15311535      }
    1532       cout << Verbose(2) << "Projection is " << BTS->NormalVector.Projection(&Oben) << "." << endl;
     1536      cout << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl;
    15331537    }
    15341538    if (BTS != NULL) // we have created one starting triangle
     
    15371541      // remove all candidates from the list and then the list itself
    15381542      class CandidateForTesselation *remover = NULL;
    1539       for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1543      for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) {
    15401544        remover = *it;
    15411545        delete(remover);
    15421546      }
    1543       OptCandidates->clear();
     1547      Opt_Candidates->clear();
    15441548    }
    15451549  }
     
    15471551  // remove all candidates from the list and then the list itself
    15481552  class CandidateForTesselation *remover = NULL;
    1549   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1553  for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) {
    15501554    remover = *it;
    15511555    delete(remover);
    15521556  }
    1553   delete(OptCandidates);
    1554   cout << Verbose(1) << "End of FindStartingTriangle\n";
     1557  delete(Opt_Candidates);
     1558  cout << Verbose(1) << "End of Find_starting_triangle\n";
    15551559};
    15561560
     
    15641568 * @param *LC LinkedCell structure with neighbouring points
    15651569 */
    1566 bool Tesselation::FindNextSuitableTriangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC)
    1567 {
    1568   cout << Verbose(0) << "Begin of FindNextSuitableTriangle\n";
     1570bool Tesselation::Find_next_suitable_triangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC)
     1571{
     1572  cout << Verbose(0) << "Begin of Find_next_suitable_triangle\n";
    15691573  bool result = true;
    1570   CandidateList *OptCandidates = new CandidateList();
     1574  CandidateList *Opt_Candidates = new CandidateList();
    15711575
    15721576  Vector CircleCenter;
     
    16251629
    16261630    // add third point
    1627     FindThirdPointForTesselation(
    1628       T.NormalVector, SearchDirection, OldSphereCenter, &Line, ThirdNode, OptCandidates,
     1631    Find_third_point_for_Tesselation(
     1632      T.NormalVector, SearchDirection, OldSphereCenter, &Line, ThirdNode, Opt_Candidates,
    16291633      &ShortestAngle, RADIUS, LC
    16301634    );
     
    16341638  }
    16351639
    1636   if (OptCandidates->begin() == OptCandidates->end()) {
     1640  if (Opt_Candidates->begin() == Opt_Candidates->end()) {
    16371641    cerr << "WARNING: Could not find a suitable candidate." << endl;
    16381642    return false;
    16391643  }
    16401644  cout << Verbose(1) << "Third Points are ";
    1641   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1645  for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) {
    16421646    cout << " " << *(*it)->point;
    16431647  }
     
    16451649
    16461650  BoundaryLineSet *BaseRay = &Line;
    1647   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1651  for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) {
    16481652    cout << Verbose(1) << " Third point candidate is " << *(*it)->point
    16491653    << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
     
    16641668      AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    16651669
    1666       if (CheckLineCriteriaForDegeneratedTriangle(TPS)) {
     1670      if (CheckLineCriteriaforDegeneratedTriangle(TPS)) {
    16671671        AddTesselationLine(TPS[0], TPS[1], 0);
    16681672        AddTesselationLine(TPS[0], TPS[2], 1);
     
    16931697        // 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)
    16941698        // i.e. at least one of the three lines must be present with TriangleCount <= 1
    1695         if (CheckLineCriteriaForDegeneratedTriangle(TPS)) {
     1699        if (CheckLineCriteriaforDegeneratedTriangle(TPS)) {
    16961700          AddTesselationLine(TPS[0], TPS[1], 0);
    16971701          AddTesselationLine(TPS[0], TPS[2], 1);
     
    17311735  // remove all candidates from the list and then the list itself
    17321736  class CandidateForTesselation *remover = NULL;
    1733   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
     1737  for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) {
    17341738    remover = *it;
    17351739    delete(remover);
    17361740  }
    1737   delete(OptCandidates);
    1738   cout << Verbose(0) << "End of FindNextSuitableTriangle\n";
     1741  delete(Opt_Candidates);
     1742  cout << Verbose(0) << "End of Find_next_suitable_triangle\n";
    17391743  return result;
    17401744};
     
    17511755  class BoundaryPointSet *Spot = NULL;
    17521756  class BoundaryLineSet *OtherBase;
    1753   Vector *ClosestPoint[2];
     1757  Vector *ClosestPoint;
    17541758
    17551759  int m=0;
     
    17641768
    17651769  // get the closest point on each line to the other line
    1766   ClosestPoint[0] = GetClosestPointBetweenLine(out, Base, OtherBase);
    1767   ClosestPoint[1] = GetClosestPointBetweenLine(out, OtherBase, Base);
     1770  ClosestPoint = GetClosestPointBetweenLine(out, Base, OtherBase);
    17681771
    17691772  // delete the temporary other base line
     
    17711774
    17721775  // get the distance vector from Base line to OtherBase line
    1773   Vector DistanceToIntersection, BaseLine;
     1776  Vector DistanceToIntersection[2], BaseLine;
     1777  double distance[2];
    17741778  BaseLine.CopyVector(Base->endpoints[1]->node->node);
    17751779  BaseLine.SubtractVector(Base->endpoints[0]->node->node);
    1776   DistanceToIntersection.CopyVector(ClosestPoint[0]);
    1777   DistanceToIntersection.SubtractVector(Base->endpoints[0]->node->node);
    1778   Spot = Base->endpoints[1];
    1779   if (BaseLine.ScalarProduct(&DistanceToIntersection) < -MYEPSILON) {
    1780     DistanceToIntersection.CopyVector(ClosestPoint[0]);
    1781     DistanceToIntersection.SubtractVector(Base->endpoints[1]->node->node);
    1782     Spot = Base->endpoints[0];
    1783     if (BaseLine.ScalarProduct(&DistanceToIntersection) < -MYEPSILON) {
    1784       *out << Verbose(3) << "ERROR: Something's very wrong here, both SKPs return negative?!" << endl;
    1785       return NULL;
    1786     }
    1787   }
    1788   if ((BaseLine.NormSquared() - DistanceToIntersection.NormSquared()) < -MYEPSILON) {  // distance is smaller: concave
    1789     *out << Verbose(3) << "INFO: Rectangle of triangles of base line " << *Base << " is concave: Base line squared length " << BaseLine.NormSquared() << " against Distance to intersection squared " << DistanceToIntersection.NormSquared() << "." << endl;
     1780  for (int i=0;i<2;i++) {
     1781    DistanceToIntersection[i].CopyVector(ClosestPoint);
     1782    DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
     1783    distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
     1784  }
     1785  delete(ClosestPoint);
     1786  if ((distance[0] * distance[1]) > 0)  { // have same sign?
     1787    *out << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
     1788    if (distance[0] < distance[1]) {
     1789      Spot = Base->endpoints[0];
     1790    } else {
     1791      Spot = Base->endpoints[1];
     1792    }
    17901793    return Spot;
    1791   } else {  // base line is longer: convex
    1792     *out << Verbose(3) << "INFO: Rectangle of triangles of base line " << *Base << " is concave." << endl;
     1794  } else {  // different sign, i.e. we are in between
     1795    *out << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
    17931796    return NULL;
    17941797  }
     
    17961799};
    17971800
     1801void Tesselation::PrintAllBoundaryPoints(ofstream *out)
     1802{
     1803  // print all lines
     1804  *out << Verbose(1) << "Printing all boundary points for debugging:" << endl;
     1805  for (PointMap::iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
     1806    *out << Verbose(2) << *(PointRunner->second) << endl;
     1807};
     1808
     1809void Tesselation::PrintAllBoundaryLines(ofstream *out)
     1810{
     1811  // print all lines
     1812  *out << Verbose(1) << "Printing all boundary lines for debugging:" << endl;
     1813  for (LineMap::iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
     1814    *out << Verbose(2) << *(LineRunner->second) << endl;
     1815};
     1816
     1817void Tesselation::PrintAllBoundaryTriangles(ofstream *out)
     1818{
     1819  // print all triangles
     1820  *out << Verbose(1) << "Printing all boundary triangles for debugging:" << endl;
     1821  for (TriangleMap::iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
     1822    *out << Verbose(2) << *(TriangleRunner->second) << endl;
     1823};
    17981824
    17991825/** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
     
    18261852  Distance.SubtractVector(ClosestPoint[0]);
    18271853
    1828   // delete the temporary other base line
     1854  // delete the temporary other base line and the closest points
     1855  delete(ClosestPoint[0]);
     1856  delete(ClosestPoint[1]);
    18291857  delete(OtherBase);
    18301858
     
    18431871      BaseLineNormal.AddVector(&(runner->second->NormalVector));
    18441872    }
    1845     BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
     1873    BaseLineNormal.Scale(1./2.);
    18461874
    18471875    if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
     
    18661894  // construct the plane of the two baselines (i.e. take both their directional vectors)
    18671895  Vector Normal;
    1868   Vector OtherBaseline;
    1869   Normal.CopyVector(Base->endpoints[1]->node->node);
    1870   Normal.SubtractVector(Base->endpoints[0]->node->node);
     1896  Vector Baseline, OtherBaseline;
     1897  Baseline.CopyVector(Base->endpoints[1]->node->node);
     1898  Baseline.SubtractVector(Base->endpoints[0]->node->node);
    18711899  OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node);
    18721900  OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node);
     1901  Normal.CopyVector(&Baseline);
    18731902  Normal.VectorProduct(&OtherBaseline);
    18741903  Normal.Normalize();
    1875 
    1876   // project one offset point of OtherBase onto this plane
     1904  *out << Verbose(4) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl;
     1905
     1906  // project one offset point of OtherBase onto this plane (and add plane offset vector)
    18771907  Vector NewOffset;
    18781908  NewOffset.CopyVector(OtherBase->endpoints[0]->node->node);
     1909  NewOffset.SubtractVector(Base->endpoints[0]->node->node);
    18791910  NewOffset.ProjectOntoPlane(&Normal);
     1911  NewOffset.AddVector(Base->endpoints[0]->node->node);
    18801912  Vector NewDirection;
    1881   NewDirection.CopyVector(OtherBase->endpoints[1]->node->node);
    1882   NewDirection.ProjectOntoPlane(&Normal);
     1913  NewDirection.CopyVector(&NewOffset);
     1914  NewDirection.AddVector(&OtherBaseline);
    18831915
    18841916  // calculate the intersection between this projected baseline and Base
    18851917  Vector *Intersection = new Vector;
    18861918  Intersection->GetIntersectionOfTwoLinesOnPlane(out, Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &NewDirection, &Normal);
     1919  Normal.CopyVector(Intersection);
     1920  Normal.SubtractVector(Base->endpoints[0]->node->node);
     1921  *out << Verbose(3) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl;
    18871922
    18881923  return Intersection;
     
    20122047 * \param *Candidate pointer to candidate node on return
    20132048 * \param Oben vector indicating the outside
    2014  * \param OptCandidate reference to recommended candidate on return
     2049 * \param Opt_Candidate reference to recommended candidate on return
    20152050 * \param Storage[3] array storing angles and other candidate information
    20162051 * \param RADIUS radius of virtual sphere
    20172052 * \param *LC LinkedCell structure with neighbouring points
    20182053 */
    2019 void Tesselation::FindSecondPointForTesselation(TesselPoint* a, TesselPoint* Candidate, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, LinkedCell *LC)
    2020 {
    2021   cout << Verbose(2) << "Begin of FindSecondPointForTesselation" << endl;
     2054void Tesselation::Find_second_point_for_Tesselation(TesselPoint* a, TesselPoint* Candidate, Vector Oben, TesselPoint*& Opt_Candidate, double Storage[3], double RADIUS, LinkedCell *LC)
     2055{
     2056  cout << Verbose(2) << "Begin of Find_second_point_for_Tesselation" << endl;
    20222057  Vector AngleCheck;
    20232058  double norm = -1., angle;
     
    20572092            if (a != Candidate) {
    20582093              // Calculate center of the circle with radius RADIUS through points a and Candidate
    2059               Vector OrthogonalizedOben, aCandidate, Center;
     2094              Vector OrthogonalizedOben, a_Candidate, Center;
    20602095              double distance, scaleFactor;
    20612096
    20622097              OrthogonalizedOben.CopyVector(&Oben);
    2063               aCandidate.CopyVector(a->node);
    2064               aCandidate.SubtractVector(Candidate->node);
    2065               OrthogonalizedOben.ProjectOntoPlane(&aCandidate);
     2098              a_Candidate.CopyVector(a->node);
     2099              a_Candidate.SubtractVector(Candidate->node);
     2100              OrthogonalizedOben.ProjectOntoPlane(&a_Candidate);
    20662101              OrthogonalizedOben.Normalize();
    2067               distance = 0.5 * aCandidate.Norm();
     2102              distance = 0.5 * a_Candidate.Norm();
    20682103              scaleFactor = sqrt(((RADIUS * RADIUS) - (distance * distance)));
    20692104              OrthogonalizedOben.Scale(scaleFactor);
     
    20762111              AngleCheck.CopyVector(&Center);
    20772112              AngleCheck.SubtractVector(a->node);
    2078               norm = aCandidate.Norm();
     2113              norm = a_Candidate.Norm();
    20792114              // second point shall have smallest angle with respect to Oben vector
    20802115              if (norm < RADIUS*2.) {
     
    20832118                  //cout << Verbose(3) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
    20842119                  cout << Verbose(3) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
    2085                   OptCandidate = Candidate;
     2120                  Opt_Candidate = Candidate;
    20862121                  Storage[0] = angle;
    20872122                  //cout << Verbose(3) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
    20882123                } else {
    2089                   //cout << Verbose(3) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
     2124                  //cout << Verbose(3) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *Opt_Candidate << endl;
    20902125                }
    20912126              } else {
     
    21002135        }
    21012136      }
    2102   cout << Verbose(2) << "End of FindSecondPointForTesselation" << endl;
     2137  cout << Verbose(2) << "End of Find_second_point_for_Tesselation" << endl;
    21032138};
    21042139
     
    21262161 * holds. Then, the normalized projection onto the SearchDirection is either +1 or -1 and thus states whether
    21272162 * the angle is uniquely in either (0,M_PI] or [M_PI, 2.*M_PI).
    2128  * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa FindStartingTriangle())
     2163 * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa Find_starting_triangle())
    21292164 * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
    21302165 * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
     
    21322167 * @param ThirdNode third point to avoid in search
    21332168 * @param candidates list of equally good candidates to return
    2134  * @param ShortestAngle the current path length on this circle band for the current OptCandidate
     2169 * @param ShortestAngle the current path length on this circle band for the current Opt_Candidate
    21352170 * @param RADIUS radius of sphere
    21362171 * @param *LC LinkedCell structure with neighbouring points
    21372172 */
    2138 void Tesselation::FindThirdPointForTesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint  *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, LinkedCell *LC)
     2173void Tesselation::Find_third_point_for_Tesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint  *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, LinkedCell *LC)
    21392174{
    21402175  Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     
    21532188  CandidateForTesselation *optCandidate = NULL;
    21542189
    2155   cout << Verbose(1) << "Begin of FindThirdPointForTesselation" << endl;
     2190  cout << Verbose(1) << "Begin of Find_third_point_for_Tesselation" << endl;
    21562191
    21572192  //cout << Verbose(2) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
     
    23102345  if (candidates->size() > 1) {
    23112346    candidates->unique();
    2312     candidates->sort(SortCandidates);
    2313   }
    2314 
    2315   cout << Verbose(1) << "End of FindThirdPointForTesselation" << endl;
     2347    candidates->sort(sortCandidates);
     2348  }
     2349
     2350  cout << Verbose(1) << "End of Find_third_point_for_Tesselation" << endl;
    23162351};
    23172352
     
    23622397  }
    23632398
    2364   trianglePoints[0] = FindClosestPoint(x, SecondPoint, LC);
     2399  trianglePoints[0] = findClosestPoint(x, SecondPoint, LC);
    23652400 
    23662401  // check whether closest point is "too close" :), then it's inside
     
    23732408    return NULL;
    23742409  }
    2375   list<TesselPoint*> *connectedPoints = GetCircleOfConnectedPoints(out, trianglePoints[0]);
    2376   list<TesselPoint*> *connectedClosestPoints = GetNeighboursOnCircleOfConnectedPoints(out, connectedPoints, trianglePoints[0], x);
     2410  list<TesselPoint*> *connectedPoints = getCircleOfConnectedPoints(out, trianglePoints[0]);
     2411  list<TesselPoint*> *connectedClosestPoints = getNeighboursonCircleofConnectedPoints(out, connectedPoints, trianglePoints[0], x);
    23772412  delete(connectedPoints);
    23782413  trianglePoints[1] = connectedClosestPoints->front();
     
    24622497 * @return list of the all points linked to the provided one
    24632498 */
    2464 list<TesselPoint*> * Tesselation::GetCircleOfConnectedPoints(ofstream *out, TesselPoint* Point)
     2499list<TesselPoint*> * Tesselation::getCircleOfConnectedPoints(ofstream *out, TesselPoint* Point)
    24652500{
    24662501  list<TesselPoint*> *connectedPoints = new list<TesselPoint*>;
     
    25232558 * @return list of the two points linked to the provided one and closest to the point to be checked,
    25242559 */
    2525 list<TesselPoint*> * Tesselation::GetNeighboursOnCircleOfConnectedPoints(ofstream *out, list<TesselPoint*> *connectedPoints, TesselPoint* Point, Vector* Reference)
     2560list<TesselPoint*> * Tesselation::getNeighboursonCircleofConnectedPoints(ofstream *out, list<TesselPoint*> *connectedPoints, TesselPoint* Point, Vector* Reference)
    25262561{
    25272562  map<double, TesselPoint*> anglesOfPoints;
     
    25622597    helper.SubtractVector(Point->node);
    25632598    helper.ProjectOntoPlane(&PlaneNormal);
    2564     double angle = GetAngle(helper, AngleZero, OrthogonalVector);
     2599    double angle = getAngle(helper, AngleZero, OrthogonalVector);
    25652600    *out << Verbose(2) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
    25662601    anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
     
    25952630  int i;
    25962631
     2632  if (point == NULL) {
     2633    *out << Verbose(1) << "ERROR: Cannot remove the point " << point << ", it's NULL!" << endl;
     2634    return 0.;
     2635  } else
     2636    *out << Verbose(2) << "Removing point " << *point << " from tesselated boundary ..." << endl;
     2637
    25972638  // copy old location for the volume
    25982639  OldPoint.CopyVector(point->node->node);
     
    26032644    return 0.;
    26042645  }
    2605   list<TesselPoint*> *CircleofPoints = GetCircleOfConnectedPoints(out, point->node);
     2646  list<TesselPoint*> *CircleofPoints = getCircleOfConnectedPoints(out, point->node);
    26062647
    26072648  // remove all triangles
     
    26092650    count+=LineRunner->second->triangles.size();
    26102651  numbers = new int[count];
     2652  class BoundaryTriangleSet **Candidates = new BoundaryTriangleSet*[count];
    26112653  i=0;
    26122654  for (LineMap::iterator LineRunner = point->lines.begin(); (point != NULL) && (LineRunner != point->lines.end()); LineRunner++) {
     
    26142656    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    26152657      triangle = TriangleRunner->second;
    2616       *out << Verbose(2) << "Erasing triangle " << *triangle << "." << endl;
     2658      Candidates[i] = triangle;
    26172659      numbers[i++] = triangle->Nr;
    2618       RemoveTesselationTriangle(triangle);
    2619       triangle = NULL;
    2620     }
    2621   }
     2660    }
     2661  }
     2662  for (int j=0;j<i;j++) {
     2663    RemoveTesselationTriangle(Candidates[j]);
     2664  }
     2665  delete[](Candidates);
    26222666  *out << Verbose(1) << i << " triangles were removed." << endl;
    26232667
     
    26722716 * \return true - there is such a line (i.e. creation of degenerated triangle is valid), false - no such line (don't create)
    26732717 */
    2674 bool CheckLineCriteriaForDegeneratedTriangle(class BoundaryPointSet *nodes[3])
     2718bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3])
    26752719{
    26762720  bool result = false;
     
    27062750/** Sort function for the candidate list.
    27072751 */
    2708 bool SortCandidates(CandidateForTesselation* candidate1, CandidateForTesselation* candidate2)
     2752bool sortCandidates(CandidateForTesselation* candidate1, CandidateForTesselation* candidate2)
    27092753{
    27102754  Vector BaseLineVector, OrthogonalVector, helper;
     
    27562800 * @return point which is second closest to the provided one
    27572801 */
    2758 TesselPoint* FindSecondClosestPoint(const Vector* Point, LinkedCell* LC)
     2802TesselPoint* findSecondClosestPoint(const Vector* Point, LinkedCell* LC)
    27592803{
    27602804  LinkedNodes *List = NULL;
     
    28022846};
    28032847
     2848
     2849
    28042850/**
    28052851 * Finds the point which is closest to the provided one.
     
    28112857 * @return point which is closest to the provided one, NULL if none found
    28122858 */
    2813 TesselPoint* FindClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, LinkedCell* LC)
     2859TesselPoint* findClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, LinkedCell* LC)
    28142860{
    28152861  LinkedNodes *List = NULL;
     
    28582904  return closestPoint;
    28592905};
     2906
    28602907
    28612908/**
     
    29242971}
    29252972
    2926 /**
    2927  * Finds all degenerated triangles within the tesselation structure.
    2928  *
    2929  * @return map of keys of degenerated triangle pairs, each triangle occurs twice
    2930  *         in the list, once as key and once as value
    2931  */
    2932 map<int, int> Tesselation::FindAllDegeneratedTriangles()
    2933 {
    2934   map<int, int> DegeneratedTriangles;
    2935 
    2936   // sanity check
    2937   if (LinesOnBoundary.empty()) {
    2938     cout << Verbose(1) << "Warning: FindAllDegeneratedTriangles() was called without any tesselation structure.";
    2939     return DegeneratedTriangles;
    2940   }
    2941 
    2942   LineMap::iterator LineRunner1, LineRunner2;
    2943 
    2944   for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
    2945     for (LineRunner2 = LinesOnBoundary.begin(); LineRunner2 != LinesOnBoundary.end(); ++LineRunner2) {
    2946       if ((LineRunner1->second != LineRunner2->second)
    2947         && (LineRunner1->second->endpoints[0] == LineRunner2->second->endpoints[0])
    2948         && (LineRunner1->second->endpoints[1] == LineRunner2->second->endpoints[1])
    2949       ) {
    2950         TriangleMap::iterator TriangleRunner1 = LineRunner1->second->triangles.begin(),
    2951           TriangleRunner2 = LineRunner2->second->triangles.begin();
    2952 
    2953         for (; TriangleRunner1 != LineRunner1->second->triangles.end(); ++TriangleRunner1) {
    2954           for (; TriangleRunner2 != LineRunner2->second->triangles.end(); ++TriangleRunner2) {
    2955             if ((TriangleRunner1->second != TriangleRunner2->second)
    2956               && (TriangleRunner1->second->endpoints[0] == TriangleRunner2->second->endpoints[0])
    2957               && (TriangleRunner1->second->endpoints[1] == TriangleRunner2->second->endpoints[1])
    2958               && (TriangleRunner1->second->endpoints[2] == TriangleRunner2->second->endpoints[2])
    2959             ) {
    2960               DegeneratedTriangles[TriangleRunner1->second->Nr] = TriangleRunner2->second->Nr;
    2961               DegeneratedTriangles[TriangleRunner2->second->Nr] = TriangleRunner1->second->Nr;
    2962             }
    2963           }
    2964         }
    2965       }
    2966     }
    2967   }
    2968 
    2969   cout << Verbose(1) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles.size() << " triangles." << endl;
    2970   map<int,int>::iterator it;
    2971   for (it = DegeneratedTriangles.begin(); it != DegeneratedTriangles.end(); it++)
    2972       cout << Verbose(2) << (*it).first << " => " << (*it).second << endl;
    2973 
    2974   return DegeneratedTriangles;
    2975 }
    2976 
    2977 /**
    2978  * Purges degenerated triangles from the tesselation structure if they are not
    2979  * necessary to keep a single point within the structure.
    2980  */
    2981 void Tesselation::RemoveDegeneratedTriangles()
    2982 {
    2983   map<int, int> DegeneratedTriangles = FindAllDegeneratedTriangles();
    2984 
    2985   for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles.begin();
    2986     TriangleKeyRunner != DegeneratedTriangles.end(); ++TriangleKeyRunner
    2987   ) {
    2988     BoundaryTriangleSet *triangle = TrianglesOnBoundary.find(TriangleKeyRunner->first)->second,
    2989       *partnerTriangle = TrianglesOnBoundary.find(TriangleKeyRunner->second)->second;
    2990 
    2991     bool trianglesShareLine = false;
    2992     for (int i = 0; i < 3; ++i)
    2993       for (int j = 0; j < 3; ++j)
    2994         trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
    2995 
    2996     if (trianglesShareLine
    2997       && (triangle->endpoints[1]->LinesCount > 2)
    2998       && (triangle->endpoints[2]->LinesCount > 2)
    2999       && (triangle->endpoints[0]->LinesCount > 2)
    3000     ) {
    3001       cout << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
    3002       RemoveTesselationTriangle(triangle);
    3003       cout << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
    3004       RemoveTesselationTriangle(partnerTriangle);
    3005       DegeneratedTriangles.erase(DegeneratedTriangles.find(partnerTriangle->Nr));
    3006     } else {
    3007       cout << Verbose(1) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
    3008         << " and its partner " << *partnerTriangle << " because it is essential for at"
    3009         << " least one of the endpoints to be kept in the tesselation structure." << endl;
    3010     }
    3011   }
    3012 }
    3013 
    30142973/** Gets the angle between a point and a reference relative to the provided center.
    30152974 * We have two shanks point and reference between which the angle is calculated
     
    30212980 * @return angle between point and reference
    30222981 */
    3023 double GetAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector)
    3024 {
    3025   if (reference.IsNull())
     2982double getAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector)
     2983{
     2984  if (reference.IsZero())
    30262985    return M_PI;
    30272986
    30282987  // calculate both angles and correct with in-plane vector
    3029   if (point.IsNull())
     2988  if (point.IsZero())
    30302989    return M_PI;
    30312990  double phi = point.Angle(&reference);
Note: See TracChangeset for help on using the changeset viewer.