Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tesselation.cpp

    rb32dbb r27ac00  
    1717#include "triangleintersectionlist.hpp"
    1818#include "vector.hpp"
     19#include "Line.hpp"
    1920#include "vector_ops.hpp"
    2021#include "verbose.hpp"
     
    229230{
    230231  Info FunctionInfo(__func__);
    231   double angle = CalculateConvexity();
    232   if (angle > -MYEPSILON) {
    233     DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
    234     return true;
    235   } else {
    236     DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
    237     return false;
    238   }
    239 }
    240 
    241 
    242 /** Calculates the angle between two triangles with respect to their normal vector.
    243  * We sum the two angles of each height vector with respect to the center of the baseline.
    244  * \return angle > 0 then convex, if < 0 then concave
    245  */
    246 double BoundaryLineSet::CalculateConvexity() const
    247 {
    248   Info FunctionInfo(__func__);
    249232  Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
    250233  // get the two triangles
     
    295278  BaseLineNormal.Scale(-1.);
    296279  double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    297   return (angle - M_PI);
     280  if ((angle - M_PI) > -MYEPSILON) {
     281    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
     282    return true;
     283  } else {
     284    DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
     285    return false;
     286  }
    298287}
    299288
     
    314303/** Returns other endpoint of the line.
    315304 * \param *point other endpoint
    316  * \return NULL - if endpoint not contained in BoundaryLineSet::lines, or pointer to BoundaryPointSet otherwise
     305 * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise
    317306 */
    318307class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
     
    325314  else
    326315    return NULL;
    327 }
    328 ;
    329 
    330 /** Returns other triangle of the line.
    331  * \param *point other endpoint
    332  * \return NULL - if triangle not contained in BoundaryLineSet::triangles, or pointer to BoundaryTriangleSet otherwise
    333  */
    334 class BoundaryTriangleSet *BoundaryLineSet::GetOtherTriangle(const BoundaryTriangleSet * const triangle) const
    335 {
    336   Info FunctionInfo(__func__);
    337   if (triangles.size() == 2) {
    338     for (TriangleMap::const_iterator TriangleRunner = triangles.begin(); TriangleRunner != triangles.end(); ++TriangleRunner)
    339       if (TriangleRunner->second != triangle)
    340         return TriangleRunner->second;
    341   }
    342   return NULL;
    343316}
    344317;
     
    469442
    470443  try {
    471     *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x);
    472   }
    473   catch (LinearDependenceException &excp) {
    474     Log() << Verbose(1) << excp;
    475     DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
    476     return false;
    477   }
    478 
    479   DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl);
    480   DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl);
    481   DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
    482 
    483   if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) {
    484     DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
    485     return true;
    486   }   else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) {
    487     DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
    488     return true;
    489   }   else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) {
    490     DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
    491     return true;
    492   }
    493   // Calculate cross point between one baseline and the line from the third endpoint to intersection
    494   int i = 0;
    495   do {
    496     try {
    497       CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node),
    498                                                     *(endpoints[(i+1)%3]->node->node),
    499                                                     *(endpoints[(i+2)%3]->node->node),
    500                                                     *Intersection);
     444    Line centerLine = makeLineThrough(*MolCenter, *x);
     445    *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(centerLine);
     446
     447    DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl);
     448    DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl);
     449    DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
     450
     451    if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) {
     452      DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
     453      return true;
     454    }   else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) {
     455      DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
     456      return true;
     457    }   else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) {
     458      DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
     459      return true;
     460    }
     461    // Calculate cross point between one baseline and the line from the third endpoint to intersection
     462    int i = 0;
     463    do {
     464      Line line1 = makeLineThrough(*(endpoints[i%3]->node->node),*(endpoints[(i+1)%3]->node->node));
     465      Line line2 = makeLineThrough(*(endpoints[(i+2)%3]->node->node),*Intersection);
     466      CrossPoint = line1.getIntersection(line2);
    501467      helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
    502468      CrossPoint -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     
    505471      if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
    506472        DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
    507         i=4;
    508         break;
     473        return false;
    509474      }
    510475      i++;
    511     } catch (LinearDependenceException &excp){
    512       break;
    513     }
    514   } while (i < 3);
    515   if (i == 3) {
     476    } while (i < 3);
    516477    DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl);
    517478    return true;
    518   } else {
    519     DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl);
     479  }
     480  catch (MathException &excp) {
     481    Log() << Verbose(1) << excp;
     482    DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
    520483    return false;
    521484  }
     
    544507  GetCenter(&Direction);
    545508  try {
    546     *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction);
    547   }
    548   catch (LinearDependenceException &excp) {
     509    Line l = makeLineThrough(*x, Direction);
     510    *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(l);
     511  }
     512  catch (MathException &excp) {
    549513    (*ClosestPoint) = (*x);
    550514  }
     
    569533    Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
    570534    // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
    571     CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
     535    Line l = makeLineThrough(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
     536    CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(l);
    572537    CrossDirection[i] = CrossPoint[i] - InPlane;
    573538    CrossPoint[i] -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     
    697662;
    698663
    699 /** Returns the baseline which does not contain the given boundary point \a *point.
    700  * \param *point endpoint which is neither endpoint of the desired line
    701  * \return pointer to desired third baseline
    702  */
    703 class BoundaryLineSet *BoundaryTriangleSet::GetThirdLine(const BoundaryPointSet * const point) const
    704 {
    705   Info FunctionInfo(__func__);
    706   // sanity check
    707   if (!ContainsBoundaryPoint(point))
    708     return NULL;
    709   for (int i = 0; i < 3; i++)
    710     if (!lines[i]->ContainsBoundaryPoint(point))
    711       return lines[i];
    712   // actually, that' impossible :)
    713   return NULL;
    714 }
    715 ;
    716 
    717664/** Calculates the center point of the triangle.
    718665 * Is third of the sum of all endpoints.
     
    740687}
    741688
     689Vector BoundaryTriangleSet::getEndpoint(int i) const{
     690  ASSERT(i>=0 && i<3,"Index of Endpoint out of Range");
     691
     692  return *endpoints[i]->node->node;
     693}
     694
     695string BoundaryTriangleSet::getEndpointName(int i) const{
     696  ASSERT(i>=0 && i<3,"Index of Endpoint out of Range");
     697
     698  return endpoints[i]->node->getName();
     699}
     700
    742701/** output operator for BoundaryTriangleSet.
    743702 * \param &ost output stream
     
    746705ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
    747706{
    748   ost << "[" << a.Nr << "|" << a.endpoints[0]->node->getName() << "," << a.endpoints[1]->node->getName() << "," << a.endpoints[2]->node->getName() << "]";
     707  ost << "[" << a.Nr << "|" << a.getEndpointName(0) << "," << a.getEndpointName(1) << "," << a.getEndpointName(2) << "]";
    749708  //  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
    750709  //      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
     
    11521111    TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
    11531112
    1154     DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << (*VRunner) << ":" << endl);
     1113    DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl);
    11551114    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    1156       DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->distance(*(*VRunner)) << "." << endl);
     1115      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->distance(OtherOptCenter) << "." << endl);
    11571116
    11581117    // remove baseline's endpoints and candidates
     
    11701129      DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
    11711130      for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    1172         DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << " at distance " << setprecision(13) << (*Runner)->node->distance(*(*VRunner)) << setprecision(6) << "." << endl);
    1173 
    1174       // check with animate_sphere.tcl VMD script
    1175       if (ThirdPoint != NULL) {
    1176         DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
    1177       } else {
    1178         DoeLog(1) && (eLog() << Verbose(1) << "Check by: ... missing third point ..." << endl);
    1179         DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
    1180       }
     1131        DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << endl);
    11811132    }
    11821133    delete (ListofPoints);
    11831134
     1135    // check with animate_sphere.tcl VMD script
     1136    if (ThirdPoint != NULL) {
     1137      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
     1138    } else {
     1139      DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl);
     1140      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
     1141    }
    11841142  }
    11851143  return flag;
     
    15141472        CenterVector.Zero();
    15151473        for (int i = 0; i < 3; i++)
    1516           CenterVector += (*BTS->endpoints[i]->node->node);
     1474          CenterVector += BTS->getEndpoint(i);
    15171475        CenterVector.Scale(1. / 3.);
    15181476        DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
     
    33603318                        }
    33613319                      } else {
    3362                         DoeLog(0) && (eLog() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
     3320                        DoLog(1) && (Log() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
    33633321                      }
    33643322                    } else {
     
    46604618
    46614619  DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl);
    4662   for (IndexToIndex::iterator it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
     4620  IndexToIndex::iterator it;
     4621  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    46634622    DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
    46644623
     
    46784637  int count = 0;
    46794638
    4680   // iterate over all degenerated triangles
    4681   for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); !DegeneratedTriangles->empty(); TriangleKeyRunner = DegeneratedTriangles->begin()) {
    4682     DoLog(0) && (Log() << Verbose(0) << "Checking presence of triangles " << TriangleKeyRunner->first << " and " << TriangleKeyRunner->second << "." << endl);
    4683     // both ways are stored in the map, only use one
    4684     if (TriangleKeyRunner->first > TriangleKeyRunner->second)
    4685       continue;
    4686 
    4687     // determine from the keys in the map the two _present_ triangles
     4639  for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) {
    46884640    finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
    46894641    if (finder != TrianglesOnBoundary.end())
    46904642      triangle = finder->second;
    46914643    else
    4692       continue;
     4644      break;
    46934645    finder = TrianglesOnBoundary.find(TriangleKeyRunner->second);
    46944646    if (finder != TrianglesOnBoundary.end())
    46954647      partnerTriangle = finder->second;
    46964648    else
    4697       continue;
    4698 
    4699     // determine which lines are shared by the two triangles
     4649      break;
     4650
    47004651    bool trianglesShareLine = false;
    47014652    for (int i = 0; i < 3; ++i)
     
    48684819  if (LastTriangle != NULL) {
    48694820    stringstream sstr;
    4870     sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle->endpoints[0]->node->getName() << "_" << LastTriangle->endpoints[1]->node->getName() << "_" << LastTriangle->endpoints[2]->node->getName();
     4821    sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle->getEndpointName(0) << "_" << LastTriangle->getEndpointName(1) << "_" << LastTriangle->getEndpointName(2);
    48714822    NumberName = sstr.str();
    48724823    if (DoTecplotOutput) {
Note: See TracChangeset for help on using the changeset viewer.