Ignore:
Timestamp:
Oct 2, 2009, 3:19:51 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
e1f6d7
Parents:
fca6e7
Message:

Fixes to the (Non)ConvexTesselation, working with 1_2_dimethoxyethylene

minor changes:

major changes:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/tesselation.cpp

    rfca6e7 rdaf956  
    215215    node = runner->second->GetThirdEndpoint(this);
    216216    if (node != NULL) {
    217       *out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
     217      //*out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    218218      helper[i].CopyVector(node->node->node);
    219219      helper[i].SubtractVector(&BaseLineCenter);
    220220      helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
    221       *out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
     221      //*out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    222222      i++;
    223223    } else {
     
    226226    }
    227227  }
    228   *out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
     228  //*out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
    229229  if (NormalCheck.NormSquared() < MYEPSILON) {
    230230    *out << Verbose(3) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
     
    374374 * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
    375375 * This we test if it's really on the plane and whether it's inside the triangle on the plane or not.
    376  * The latter is done as follows: if it's really outside, then for any endpoint of the triangle and it's opposite
    377  * base line, the intersection between the line from endpoint to intersection and the base line will have a Vector::NormSquared()
    378  * smaller than the first line.
     376 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
     377 * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
     378 * the first two basepoints) or not.
    379379 * \param *out output stream for debugging
    380380 * \param *MolCenter offset vector of line
     
    408408    exit(255);
    409409  }
    410   CrossPoint.SubtractVector(endpoints[i%3]->node->node);
     410  CrossPoint.SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
    411411
    412412  // check whether intersection is inside or not by comparing length of intersection and length of cross point
    413   if ((CrossPoint.NormSquared() - helper.NormSquared()) > -MYEPSILON) { // inside
     413  if ((CrossPoint.NormSquared() - helper.NormSquared()) < MYEPSILON) { // inside
    414414    return true;
    415415  } else { // outside!
     
    439439  for(int i=0;i<3;i++)
    440440    if (point == endpoints[i])
     441      return true;
     442  return false;
     443};
     444
     445/** Checks whether point is any of the three endpoints this triangle contains.
     446 * \param *point TesselPoint to test
     447 * \return true - point is of the triangle, false - is not
     448 */
     449bool BoundaryTriangleSet::ContainsBoundaryPoint(class TesselPoint *point)
     450{
     451  for(int i=0;i<3;i++)
     452    if (point == endpoints[i]->node)
    441453      return true;
    442454  return false;
     
    10881100  Vector *Center = cloud->GetCenter(out);
    10891101  list<BoundaryTriangleSet*> *triangles = NULL;
     1102  bool AddFlag = false;
     1103  LinkedCell *BoundaryPoints = NULL;
    10901104
    10911105  *out << Verbose(1) << "Begin of InsertStraddlingPoints" << endl;
    10921106
    10931107  cloud->GoToFirst();
     1108  BoundaryPoints = new LinkedCell(this, 5.);
    10941109  while (!cloud->IsEnd()) {  // we only have to go once through all points, as boundary can become only bigger
    1095     LinkedCell BoundaryPoints(this, 5.);
     1110    if (AddFlag) {
     1111      delete(BoundaryPoints);
     1112      BoundaryPoints = new LinkedCell(this, 5.);
     1113      AddFlag = false;
     1114    }
    10961115    Walker = cloud->GetPoint();
    10971116    *out << Verbose(2) << "Current point is " << *Walker << "." << endl;
    10981117    // get the next triangle
    1099     triangles = FindClosestTrianglesToPoint(out, Walker->node, &BoundaryPoints);
    1100     if (triangles == NULL) {
    1101       *out << Verbose(1) << "No triangles found, probably a tesselation point itself." << endl;
     1118    triangles = FindClosestTrianglesToPoint(out, Walker->node, BoundaryPoints);
     1119    BTS = triangles->front();
     1120    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
     1121      *out << Verbose(2) << "No triangles found, probably a tesselation point itself." << endl;
    11021122      cloud->GoToNext();
    11031123      continue;
    11041124    } else {
    1105       BTS = triangles->front();
    11061125    }
    11071126    *out << Verbose(2) << "Closest triangle is " << *BTS << "." << endl;
     
    11261145        // add Walker to boundary points
    11271146        *out << Verbose(2) << "Adding " << *Walker << " to BoundaryPoints." << endl;
     1147        AddFlag = true;
    11281148        if (AddBoundaryPoint(Walker,0))
    11291149          NewPoint = BPS[0];
     
    12791299};
    12801300
    1281 /** Function tries to add Triangle just created to Triangle and remarks if already existent (Failure of algorithm).
    1282  * Furthermore it adds the triangle to all of its lines, in order to recognize those which are saturated later.
     1301/** Function adds triangle to global list.
     1302 * Furthermore, the triangle receives the next free id and id counter \a TrianglesOnBoundaryCount is increased.
    12831303 */
    12841304void Tesselation::AddTesselationTriangle()
     
    12891309  TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    12901310  TrianglesOnBoundaryCount++;
     1311
     1312  // set as last new triangle
     1313  LastTriangle = BTS;
     1314
     1315  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
     1316};
     1317
     1318/** Function adds triangle to global list.
     1319 * Furthermore, the triangle number is set to \a nr.
     1320 * \param nr triangle number
     1321 */
     1322void Tesselation::AddTesselationTriangle(int nr)
     1323{
     1324  cout << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1325
     1326  // add triangle to global map
     1327  TrianglesOnBoundary.insert(TrianglePair(nr, BTS));
    12911328
    12921329  // set as last new triangle
     
    20972134    BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[0]);
    20982135    BTS->GetNormalVector(BaseLineNormal);
    2099     TrianglesOnBoundary.insert(TrianglePair(OldTriangleNrs[0], BTS));
     2136    AddTesselationTriangle(OldTriangleNrs[0]);
    21002137    *out << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
    21012138
     
    21052142    BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[1]);
    21062143    BTS->GetNormalVector(BaseLineNormal);
    2107     TrianglesOnBoundary.insert(TrianglePair(OldTriangleNrs[1], BTS));
     2144    AddTesselationTriangle(OldTriangleNrs[1]);
    21082145    *out << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
    21092146  } else {
     
    24812518  }
    24822519  if (trianglePoints[0]->node->DistanceSquared(x) < MYEPSILON) {
    2483     *out << Verbose(2) << "Point is right on a tesselation point, no nearest triangle." << endl;
     2520    *out << Verbose(3) << "Point is right on a tesselation point, no nearest triangle." << endl;
    24842521    PointMap::iterator PointRunner = PointsOnBoundary.find(trianglePoints[0]->nr);
    24852522    triangles = new list<BoundaryTriangleSet*>;
     
    25122549        *out << Verbose(1) << "ERROR: IsInnerPoint encounters serious error, point " << i << " not found." << endl;
    25132550      }
    2514       *out << Verbose(1) << "List of triangle points:" << endl;
    2515       *out << Verbose(2) << *trianglePoints[i] << endl;
     2551      //*out << Verbose(2) << "List of triangle points:" << endl;
     2552      //*out << Verbose(3) << *trianglePoints[i] << endl;
    25162553    }
    25172554
    25182555    triangles = FindTriangles(trianglePoints);
    2519     *out << Verbose(1) << "List of possible triangles:" << endl;
     2556    *out << Verbose(2) << "List of possible triangles:" << endl;
    25202557    for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    2521       *out << Verbose(2) << **Runner << endl;
     2558      *out << Verbose(3) << **Runner << endl;
    25222559
    25232560    delete(connectedClosestPoints);
     
    32993336  int count  = 0;
    33003337
     3338  cout << Verbose(1) << "Begin of RemoveDegeneratedTriangles" << endl;
     3339
    33013340  for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
    33023341    TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
     
    33703409
    33713410  cout << Verbose(1) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
     3411  cout << Verbose(1) << "End of RemoveDegeneratedTriangles" << endl;
    33723412}
    33733413
Note: See TracChangeset for help on using the changeset viewer.