Changes in src/tesselation.cpp [9473f6:241485]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tesselation.cpp
r9473f6 r241485 35 35 * \param *Walker TesselPoint this boundary point represents 36 36 */ 37 BoundaryPointSet::BoundaryPointSet(TesselPoint * constWalker) :37 BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker) : 38 38 LinesCount(0), 39 39 node(Walker), … … 61 61 * \param *line line to add 62 62 */ 63 void BoundaryPointSet::AddLine( BoundaryLineSet * constline)63 void BoundaryPointSet::AddLine(class BoundaryLineSet *line) 64 64 { 65 65 Info FunctionInfo(__func__); … … 105 105 * \param number number of the list 106 106 */ 107 BoundaryLineSet::BoundaryLineSet( BoundaryPointSet * constPoint[2], const int number)107 BoundaryLineSet::BoundaryLineSet(class BoundaryPointSet *Point[2], const int number) 108 108 { 109 109 Info FunctionInfo(__func__); … … 115 115 Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding. 116 116 Point[1]->AddLine(this); // 117 // set skipped to false118 skipped = false;119 // clear triangles list120 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' LineMap125 * \param *Point1 first boundary point126 * \param *Point2 second boundary point127 * \param number number of the list128 */129 BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number)130 {131 Info FunctionInfo(__func__);132 // set number133 Nr = number;134 // set endpoints in ascending order135 SetEndpointsOrdered(endpoints, Point1, Point2);136 // add this line to the hash maps of both endpoints137 Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.138 Point2->AddLine(this); //139 117 // set skipped to false 140 118 skipped = false; … … 193 171 * \param *triangle to add 194 172 */ 195 void BoundaryLineSet::AddTriangle( BoundaryTriangleSet * consttriangle)173 void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle) 196 174 { 197 175 Info FunctionInfo(__func__); … … 204 182 * \return true - common endpoint present, false - not connected 205 183 */ 206 bool BoundaryLineSet::IsConnectedTo(c onst BoundaryLineSet * const line) const184 bool BoundaryLineSet::IsConnectedTo(class BoundaryLineSet *line) 207 185 { 208 186 Info FunctionInfo(__func__); … … 219 197 * \return true - triangles are convex, false - concave or less than two triangles connected 220 198 */ 221 bool BoundaryLineSet::CheckConvexityCriterion() const199 bool BoundaryLineSet::CheckConvexityCriterion() 222 200 { 223 201 Info FunctionInfo(__func__); … … 243 221 int i=0; 244 222 class BoundaryPointSet *node = NULL; 245 for(TriangleMap:: const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {223 for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 246 224 //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 247 225 NormalCheck.AddVector(&runner->second->NormalVector); … … 286 264 * \return true - point is of the line, false - is not 287 265 */ 288 bool BoundaryLineSet::ContainsBoundaryPoint(c onst BoundaryPointSet * const point) const266 bool BoundaryLineSet::ContainsBoundaryPoint(class BoundaryPointSet *point) 289 267 { 290 268 Info FunctionInfo(__func__); … … 299 277 * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise 300 278 */ 301 class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(c onst BoundaryPointSet * const point) const279 class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(class BoundaryPointSet *point) 302 280 { 303 281 Info FunctionInfo(__func__); … … 339 317 * \param number number of triangle 340 318 */ 341 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], constint number) :319 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number) : 342 320 Nr(number) 343 321 { … … 398 376 * \param &OtherVector direction vector to make normal vector unique. 399 377 */ 400 void BoundaryTriangleSet::GetNormalVector( constVector &OtherVector)378 void BoundaryTriangleSet::GetNormalVector(Vector &OtherVector) 401 379 { 402 380 Info FunctionInfo(__func__); … … 412 390 /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses. 413 391 * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane 414 * Th us we test if it's really on the plane and whether it's inside the triangle on the plane or not.392 * This we test if it's really on the plane and whether it's inside the triangle on the plane or not. 415 393 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line 416 394 * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between … … 422 400 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle. 423 401 */ 424 bool BoundaryTriangleSet::GetIntersectionInsideTriangle( const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const402 bool BoundaryTriangleSet::GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection) 425 403 { 426 404 Info FunctionInfo(__func__); … … 474 452 }; 475 453 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 plane478 * 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 line480 * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between481 * the first two basepoints) or not.482 * \param *x point483 * \param *ClosestPoint desired closest point inside triangle to \a *x, is absolute vector484 * \return Distance squared between \a *x and closest point inside triangle485 */486 double BoundaryTriangleSet::GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const487 {488 Info FunctionInfo(__func__);489 Vector Direction;490 491 // 1. get intersection with plane492 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 point502 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 shortest510 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 point517 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 vector524 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 again528 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 } else535 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 sign542 InsideFlag = false;543 }544 if (InsideFlag) {545 ClosestPoint->CopyVector(&InPlane);546 ShortestDistance = InPlane.DistanceSquared(x);547 } else { // also check endnodes548 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;558 };559 560 454 /** Checks whether lines is any of the three boundary lines this triangle contains. 561 455 * \param *line line to test 562 456 * \return true - line is of the triangle, false - is not 563 457 */ 564 bool BoundaryTriangleSet::ContainsBoundaryLine(c onst BoundaryLineSet * const line) const458 bool BoundaryTriangleSet::ContainsBoundaryLine(class BoundaryLineSet *line) 565 459 { 566 460 Info FunctionInfo(__func__); … … 575 469 * \return true - point is of the triangle, false - is not 576 470 */ 577 bool BoundaryTriangleSet::ContainsBoundaryPoint(c onst BoundaryPointSet * const point) const471 bool BoundaryTriangleSet::ContainsBoundaryPoint(class BoundaryPointSet *point) 578 472 { 579 473 Info FunctionInfo(__func__); … … 588 482 * \return true - point is of the triangle, false - is not 589 483 */ 590 bool BoundaryTriangleSet::ContainsBoundaryPoint(c onst TesselPoint * const point) const484 bool BoundaryTriangleSet::ContainsBoundaryPoint(class TesselPoint *point) 591 485 { 592 486 Info FunctionInfo(__func__); … … 601 495 * \return true - is the very triangle, false - is not 602 496 */ 603 bool BoundaryTriangleSet::IsPresentTupel(c onst BoundaryPointSet * const Points[3]) const497 bool BoundaryTriangleSet::IsPresentTupel(class BoundaryPointSet *Points[3]) 604 498 { 605 499 Info FunctionInfo(__func__); … … 624 518 * \return true - is the very triangle, false - is not 625 519 */ 626 bool BoundaryTriangleSet::IsPresentTupel(c onst BoundaryTriangleSet * const T) const520 bool BoundaryTriangleSet::IsPresentTupel(class BoundaryTriangleSet *T) 627 521 { 628 522 Info FunctionInfo(__func__); … … 646 540 * \return pointer third endpoint or NULL if line does not belong to triangle. 647 541 */ 648 class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(c onst BoundaryLineSet * const line) const542 class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(class BoundaryLineSet *line) 649 543 { 650 544 Info FunctionInfo(__func__); … … 663 557 * \param *center central point on return. 664 558 */ 665 void BoundaryTriangleSet::GetCenter(Vector * const center) const559 void BoundaryTriangleSet::GetCenter(Vector *center) 666 560 { 667 561 Info FunctionInfo(__func__); … … 670 564 center->AddVector(endpoints[i]->node->node); 671 565 center->Scale(1./3.); 672 Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl;673 566 } 674 567 … … 3242 3135 // for each point, check its lines, remember closest 3243 3136 Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl; 3244 LineSet ClosestLines;3137 BoundaryLineSet *ClosestLine = NULL; 3245 3138 double MinDistance = 1e+16; 3246 3139 Vector BaseLineIntersection; … … 3264 3157 3265 3158 if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint 3266 const double lengthEnd = Min(lengthEndA, lengthEndB); 3267 if (lengthEnd - MinDistance < -MYEPSILON) { // new best line 3268 ClosestLines.clear(); 3269 ClosestLines.insert(LineRunner->second); 3270 MinDistance = lengthEnd; 3271 Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl; 3272 } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate 3273 ClosestLines.insert(LineRunner->second); 3274 Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl; 3275 } else { // line is worse 3159 if ((lengthEndA < MinDistance) && (lengthEndA < lengthEndB)) { 3160 ClosestLine = LineRunner->second; 3161 MinDistance = lengthEndA; 3162 Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEndA << "." << endl; 3163 } else if (lengthEndB < MinDistance) { 3164 ClosestLine = LineRunner->second; 3165 MinDistance = lengthEndB; 3166 Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is closer with " << lengthEndB << "." << endl; 3167 } else { 3276 3168 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; 3277 3169 } … … 3287 3179 eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl; 3288 3180 } 3289 if ((ClosestLine s.empty()) || (distance < MinDistance)) {3290 ClosestLine s.insert(LineRunner->second);3181 if ((ClosestLine == NULL) || (distance < MinDistance)) { 3182 ClosestLine = LineRunner->second; 3291 3183 MinDistance = distance; 3292 Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLine s.begin()<< " with projected distance " << MinDistance << "." << endl;3184 Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl; 3293 3185 } else { 3294 3186 Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl; … … 3300 3192 3301 3193 // check whether closest line is "too close" :), then it's inside 3302 if (ClosestLine s.empty()) {3194 if (ClosestLine == NULL) { 3303 3195 Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl; 3304 3196 return NULL; 3305 3197 } 3306 3198 TriangleList * candidates = new TriangleList; 3307 for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++) 3308 for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) { 3199 for (TriangleMap::iterator Runner = ClosestLine->triangles.begin(); Runner != ClosestLine->triangles.end(); Runner++) { 3309 3200 candidates->push_back(Runner->second); 3310 3201 } … … 3350 3241 }; 3351 3242 3352 /** Checks whether the provided Vector is within the Tesselation structure. 3353 * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value. 3354 * @param point of which to check the position 3355 * @param *LC LinkedCell structure 3356 * 3357 * @return true if the point is inside the Tesselation structure, false otherwise 3358 */ 3359 bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const 3360 { 3361 return (GetDistanceSquaredToSurface(Point, LC) > MYEPSILON); 3362 } 3363 3364 /** Returns the distance to the surface given by the tesselation. 3243 /** Checks whether the provided Vector is within the tesselation structure. 3365 3244 * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points 3366 * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the 3367 * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's 3368 * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle(). 3369 * In the end we additionally find the point on the triangle who was smallest distance to \a Point: 3370 * -# Separate distance from point to center in vector in NormalDirection and on the triangle plane. 3371 * -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds. 3372 * -# If inside, take it to calculate closest distance 3373 * -# If not, take intersection with BoundaryLine as distance 3374 * 3375 * @note distance is squared despite it still contains a sign to determine in-/outside! 3245 * towards or away from the given \a &Point. 3376 3246 * 3377 3247 * @param point of which to check the position 3378 3248 * @param *LC LinkedCell structure 3379 3249 * 3380 * @return >0 if outside, ==0 if on surface, <0 if inside (Note that distance can be at most LinkedCell::RADIUS.)3381 */ 3382 double Tesselation::GetDistanceSquaredToSurface(const Vector &Point, const LinkedCell* const LC) const3250 * @return true if the point is inside the tesselation structure, false otherwise 3251 */ 3252 bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const 3383 3253 { 3384 3254 Info FunctionInfo(__func__); … … 3388 3258 Vector DistanceToCenter; 3389 3259 Vector Intersection; 3390 double distance = 0.;3391 3260 3392 3261 if (result == NULL) {// is boundary point or only point in point cloud? 3393 3262 Log() << Verbose(1) << Point << " is the only point in vicinity." << endl; 3394 return LC->RADIUS;3263 return false; 3395 3264 } else { 3396 3265 Log() << Verbose(1) << "INFO: Closest triangle found is " << *result << " with normal vector " << result->NormalVector << "." << endl; … … 3413 3282 if (result->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) { 3414 3283 Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl; 3415 return 0.;3284 return true; 3416 3285 } else { 3417 3286 Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl; 3418 3287 return false; 3419 3288 } 3289 } 3290 3291 // then check direction to boundary 3292 if (DistanceToCenter.ScalarProduct(&result->NormalVector) > MYEPSILON) { 3293 Log() << Verbose(1) << Point << " is an inner point." << endl; 3294 return true; 3420 3295 } else { 3421 // calculate smallest distance 3422 distance = result->GetClosestPointInsideTriangle(&Point, &Intersection); 3423 Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl; 3424 distance = Min(distance, (LC->RADIUS*LC->RADIUS)); 3425 3426 // then check direction to boundary 3427 if (DistanceToCenter.ScalarProduct(&result->NormalVector) > MYEPSILON) { 3428 Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl; 3429 return -distance; 3430 } else { 3431 Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl; 3432 return +distance; 3433 } 3434 } 3435 }; 3296 Log() << Verbose(1) << Point << " is NOT an inner point." << endl; 3297 return false; 3298 } 3299 } 3436 3300 3437 3301 /** Gets all points connected to the provided point by triangulation lines.
Note:
See TracChangeset
for help on using the changeset viewer.