- Timestamp:
- Aug 21, 2009, 12:19:08 PM (15 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- d04966
- Parents:
- d4fa23
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tesselation.cpp
rd4fa23 r065e82 1179 1179 } else { 1180 1180 delete TPS[n]; 1181 cout << Verbose( 3) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;1181 cout << Verbose(4) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl; 1182 1182 TPS[n] = (InsertUnique.first)->second; 1183 1183 } … … 1196 1196 1197 1197 if (a->lines.find(b->node->nr) != a->lines.end()) { 1198 LineMap::iterator FindLine ;1198 LineMap::iterator FindLine = a->lines.find(b->node->nr); 1199 1199 pair<LineMap::iterator,LineMap::iterator> FindPair; 1200 1200 FindPair = a->lines.equal_range(b->node->nr); 1201 1202 for (FindLine = FindPair.first; FindLine != FindPair.second; ++FindLine) { 1201 cout << Verbose(5) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl; 1202 1203 for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) { 1203 1204 // If there is a line with less than two attached triangles, we don't need a new line. 1204 1205 if (FindLine->second->triangles.size() < 2) { 1205 1206 insertNewLine = false; 1206 cout << Verbose( 3) << "Using existing line " << *FindLine->second << endl;1207 cout << Verbose(4) << "Using existing line " << *FindLine->second << endl; 1207 1208 1208 1209 BPS[0] = FindLine->second->endpoints[0]; … … 1231 1232 void Tesselation::AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n) 1232 1233 { 1233 cout << Verbose( 3) << "Adding line between " << *(a->node) << " and " << *(b->node) << "." << endl;1234 cout << Verbose(4) << "Adding line between " << *(a->node) << " and " << *(b->node) << "." << endl; 1234 1235 BPS[0] = a; 1235 1236 BPS[1] = b; … … 1271 1272 cout << Verbose(5) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl; 1272 1273 RemoveTesselationLine(triangle->lines[i]); 1273 triangle->lines[i] = NULL; 1274 } else 1275 cout << Verbose(5) << *triangle->lines[i] << " is still attached to another triangle." << endl; 1274 } else { 1275 cout << Verbose(5) << *triangle->lines[i] << " is still attached to another triangle: "; 1276 for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++) 1277 cout << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t"; 1278 cout << endl; 1279 // for (int j=0;j<2;j++) { 1280 // cout << Verbose(5) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": "; 1281 // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++) 1282 // cout << "[" << *(LineRunner->second) << "] \t"; 1283 // cout << endl; 1284 // } 1285 } 1286 triangle->lines[i] = NULL; // free'd or not: disconnect 1276 1287 } else 1277 1288 cerr << "ERROR: This line " << i << " has already been free'd." << endl; … … 1293 1304 if (line == NULL) 1294 1305 return; 1295 // get other endpoint number offinding copies of same line1306 // get other endpoint number for finding copies of same line 1296 1307 if (line->endpoints[1] != NULL) 1297 1308 Numbers[0] = line->endpoints[1]->Nr; … … 1320 1331 cout << Verbose(5) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl; 1321 1332 RemoveTesselationPoint(line->endpoints[i]); 1322 line->endpoints[i] = NULL; 1323 } else 1324 cout << Verbose(5) << *line->endpoints[i] << " has still lines it's attached to." << endl; 1333 } else { 1334 cout << Verbose(5) << *line->endpoints[i] << " has still lines it's attached to: "; 1335 for(LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++) 1336 cout << "[" << *(LineRunner->second) << "] \t"; 1337 cout << endl; 1338 } 1339 line->endpoints[i] = NULL; // free'd or not: disconnect 1325 1340 } else 1326 1341 cerr << "ERROR: Endpoint " << i << " has already been free'd." << endl; … … 1389 1404 } 1390 1405 // Only one of the triangle lines must be considered for the triangle count. 1391 *out << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;1392 return adjacentTriangleCount;1406 //*out << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl; 1407 //return adjacentTriangleCount; 1393 1408 } 1394 1409 } … … 1399 1414 *out << Verbose(2) << "End of CheckPresenceOfTriangle" << endl; 1400 1415 return adjacentTriangleCount; 1416 }; 1417 1418 /** Checks whether the triangle consisting of the three points is already present. 1419 * Searches for the points in Tesselation::PointsOnBoundary and checks their 1420 * lines. If any of the three edges already has two triangles attached, false is 1421 * returned. 1422 * \param *out output stream for debugging 1423 * \param *Candidates endpoints of the triangle candidate 1424 * \return NULL - none found or pointer to triangle 1425 */ 1426 class BoundaryTriangleSet * Tesselation::GetPresentTriangle(ofstream *out, TesselPoint *Candidates[3]) 1427 { 1428 class BoundaryTriangleSet *triangle = NULL; 1429 class BoundaryPointSet *Points[3]; 1430 1431 // builds a triangle point set (Points) of the end points 1432 for (int i = 0; i < 3; i++) { 1433 PointMap::iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr); 1434 if (FindPoint != PointsOnBoundary.end()) { 1435 Points[i] = FindPoint->second; 1436 } else { 1437 Points[i] = NULL; 1438 } 1439 } 1440 1441 // checks lines between the points in the Points for their adjacent triangles 1442 for (int i = 0; i < 3; i++) { 1443 if (Points[i] != NULL) { 1444 for (int j = i; j < 3; j++) { 1445 if (Points[j] != NULL) { 1446 LineMap::iterator FindLine = Points[i]->lines.find(Points[j]->node->nr); 1447 for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) { 1448 TriangleMap *triangles = &FindLine->second->triangles; 1449 for (TriangleMap::iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) { 1450 if (FindTriangle->second->IsPresentTupel(Points)) { 1451 if ((triangle == NULL) || (triangle->Nr > FindTriangle->second->Nr)) 1452 triangle = FindTriangle->second; 1453 } 1454 } 1455 } 1456 // Only one of the triangle lines must be considered for the triangle count. 1457 //*out << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl; 1458 //return adjacentTriangleCount; 1459 } 1460 } 1461 } 1462 } 1463 1464 return triangle; 1401 1465 }; 1402 1466 … … 2408 2472 return NULL; 2409 2473 } 2410 list<TesselPoint*> *connectedPoints = GetCircleOfConnectedPoints(out, trianglePoints[0]); 2411 list<TesselPoint*> *connectedClosestPoints = GetNeighboursOnCircleOfConnectedPoints(out, connectedPoints, trianglePoints[0], x); 2412 delete(connectedPoints); 2474 list<TesselPoint*> *connectedClosestPoints = GetCircleOfConnectedPoints(out, trianglePoints[0], x); 2413 2475 trianglePoints[1] = connectedClosestPoints->front(); 2414 2476 trianglePoints[2] = connectedClosestPoints->back(); … … 2495 2557 * @param *Point of which get all connected points 2496 2558 * 2497 * @return list of the all points linked to the provided one2498 */ 2499 list<TesselPoint*> * Tesselation::GetCircleOfConnectedPoints(ofstream *out, TesselPoint* Point)2500 { 2501 list<TesselPoint*> *connectedPoints = new list<TesselPoint*>;2559 * @return set of the all points linked to the provided one 2560 */ 2561 set<TesselPoint*> * Tesselation::GetAllConnectedPoints(ofstream *out, TesselPoint* Point) 2562 { 2563 set<TesselPoint*> *connectedPoints = new set<TesselPoint*>; 2502 2564 class BoundaryPointSet *ReferencePoint = NULL; 2503 2565 TesselPoint* current; … … 2509 2571 ReferencePoint = PointRunner->second; 2510 2572 } else { 2511 *out << Verbose(2) << " getCircleOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;2573 *out << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl; 2512 2574 ReferencePoint = NULL; 2513 2575 } 2514 2576 2515 // little trick so that we look just through lines connect to the BoundaryPoint 2577 // little trick so that we look just through lines connect to the BoundaryPoint 2516 2578 // OR fall-back to look through all lines if there is no such BoundaryPoint 2517 2579 LineMap *Lines = &LinesOnBoundary; … … 2520 2582 LineMap::iterator findLines = Lines->begin(); 2521 2583 while (findLines != Lines->end()) { 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 *out << Verbose(3) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is taken into the circle." << endl;2534 connectedPoints->push_back(current);2535 2536 2537 2584 takePoint = false; 2585 2586 if (findLines->second->endpoints[0]->Nr == Point->nr) { 2587 takePoint = true; 2588 current = findLines->second->endpoints[1]->node; 2589 } else if (findLines->second->endpoints[1]->Nr == Point->nr) { 2590 takePoint = true; 2591 current = findLines->second->endpoints[0]->node; 2592 } 2593 2594 if (takePoint) { 2595 *out << Verbose(5) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl; 2596 connectedPoints->insert(current); 2597 } 2598 2599 findLines++; 2538 2600 } 2539 2601 … … 2542 2604 return NULL; 2543 2605 } 2606 2544 2607 return connectedPoints; 2545 } 2546 2547 /** Gets the two neighbouring points with respect to a reference line to the provided point. 2608 }; 2609 2610 2611 /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point. 2548 2612 * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points 2549 2613 * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given … … 2552 2616 * 2553 2617 * @param *out output stream for debugging 2554 * @param *connectedPoints list of connected points to the central \a *Point2555 2618 * @param *Point of which get all connected points 2556 * @param *Reference Vector to be checked whether it is an inner point 2557 * 2558 * @return list of the two points linked to the provided one and closest to the point to be checked, 2559 */ 2560 list<TesselPoint*> * Tesselation::GetNeighboursOnCircleOfConnectedPoints(ofstream *out, list<TesselPoint*> *connectedPoints, TesselPoint* Point, Vector* Reference) 2619 * @param *Reference Reference vector for zero angle or NULL for no preference 2620 * @return list of the all points linked to the provided one 2621 */ 2622 list<TesselPoint*> * Tesselation::GetCircleOfConnectedPoints(ofstream *out, TesselPoint* Point, Vector *Reference) 2561 2623 { 2562 2624 map<double, TesselPoint*> anglesOfPoints; 2563 map<double, TesselPoint*>::iterator runner; 2564 ; 2565 Vector center, PlaneNormal, OrthogonalVector, helper, AngleZero; 2566 2567 if (connectedPoints->size() == 0) { // if have not found any points 2568 *out << Verbose(1) << "ERROR: We have not found any connected points to " << *Point<< "." << endl; 2569 return NULL; 2570 } 2625 set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(out, Point); 2626 list<TesselPoint*> *connectedCircle = new list<TesselPoint*>; 2627 Vector center; 2628 Vector PlaneNormal; 2629 Vector AngleZero; 2630 Vector OrthogonalVector; 2631 Vector helper; 2571 2632 2572 2633 // calculate central point 2573 for ( list<TesselPoint*>::iterator TesselRunner = connectedPoints->begin(); TesselRunner != connectedPoints->end(); TesselRunner++)2634 for (set<TesselPoint*>::iterator TesselRunner = connectedPoints->begin(); TesselRunner != connectedPoints->end(); TesselRunner++) 2574 2635 center.AddVector((*TesselRunner)->node); 2575 2636 //*out << "Summed vectors " << center << "; number of points " << connectedPoints.size() … … 2585 2646 2586 2647 // construct one orthogonal vector 2587 AngleZero.CopyVector(Reference); 2648 if (Reference != NULL) 2649 AngleZero.CopyVector(Reference); 2650 else 2651 AngleZero.CopyVector((*connectedPoints->begin())->node); 2588 2652 AngleZero.SubtractVector(Point->node); 2589 2653 AngleZero.ProjectOntoPlane(&PlaneNormal); … … 2593 2657 2594 2658 // go through all connected points and calculate angle 2595 for ( list<TesselPoint*>::iterator listRunner = connectedPoints->begin(); listRunner != connectedPoints->end(); listRunner++) {2659 for (set<TesselPoint*>::iterator listRunner = connectedPoints->begin(); listRunner != connectedPoints->end(); listRunner++) { 2596 2660 helper.CopyVector((*listRunner)->node); 2597 2661 helper.SubtractVector(Point->node); 2598 2662 helper.ProjectOntoPlane(&PlaneNormal); 2599 2663 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 2600 *out << Verbose( 2) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;2664 *out << Verbose(3) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl; 2601 2665 anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner))); 2602 2666 } 2603 2667 2604 list<TesselPoint*> *result = new list<TesselPoint*>; 2605 runner = anglesOfPoints.begin(); 2606 result->push_back(runner->second); 2607 runner = anglesOfPoints.end(); 2608 runner--; 2609 result->push_back(runner->second); 2610 2611 *out << Verbose(2) << "List of closest points has " << result->size() << " elements, which are " 2612 << *(result->front()) << " and " << *(result->back()) << endl; 2613 2614 return result; 2668 for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) { 2669 connectedCircle->push_back(AngleRunner->second); 2670 } 2671 2672 delete(connectedPoints); 2673 return connectedCircle; 2615 2674 } 2675 2676 /** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path. 2677 * 2678 * @param *out output stream for debugging 2679 * @param *Point of which get all connected points 2680 * @return list of the all points linked to the provided one 2681 */ 2682 list<list<TesselPoint*> *> * Tesselation::GetPathsOfConnectedPoints(ofstream *out, TesselPoint* Point) 2683 { 2684 map<double, TesselPoint*> anglesOfPoints; 2685 list<list<TesselPoint*> *> *ListOfPaths = new list<list<TesselPoint*> *>; 2686 list<TesselPoint*> *connectedPath = NULL; 2687 Vector center; 2688 Vector PlaneNormal; 2689 Vector AngleZero; 2690 Vector OrthogonalVector; 2691 Vector helper; 2692 class BoundaryPointSet *ReferencePoint = NULL; 2693 class BoundaryPointSet *CurrentPoint = NULL; 2694 class BoundaryTriangleSet *triangle = NULL; 2695 class BoundaryLineSet *CurrentLine = NULL; 2696 class BoundaryLineSet *StartLine = NULL; 2697 2698 // find the respective boundary point 2699 PointMap::iterator PointRunner = PointsOnBoundary.find(Point->nr); 2700 if (PointRunner != PointsOnBoundary.end()) { 2701 ReferencePoint = PointRunner->second; 2702 } else { 2703 *out << Verbose(2) << "ERROR: GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl; 2704 return NULL; 2705 } 2706 2707 map <class BoundaryLineSet *, bool> Touched; 2708 map <class BoundaryLineSet *, bool>::iterator line; 2709 for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) 2710 Touched.insert( pair <class BoundaryLineSet *, bool>(runner->second, false) ); 2711 if (!ReferencePoint->lines.empty()) { 2712 for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) { 2713 line = Touched.find(runner->second); 2714 if (line == Touched.end()) { 2715 *out << Verbose(2) << "ERROR: I could not find " << *runner->second << " in the touched list." << endl; 2716 } else if (!line->second) { 2717 line->second = true; 2718 connectedPath = new list<TesselPoint*>; 2719 triangle = NULL; 2720 CurrentLine = runner->second; 2721 StartLine = CurrentLine; 2722 CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint); 2723 *out << Verbose(3)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl; 2724 do { 2725 // push current one 2726 *out << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl; 2727 connectedPath->push_back(CurrentPoint->node); 2728 2729 // find next triangle 2730 for (TriangleMap::iterator TriangleRunner = CurrentLine->triangles.begin(); TriangleRunner != CurrentLine->triangles.end(); TriangleRunner++) { 2731 if (TriangleRunner->second != triangle) { // look for first triangle not equal to old one 2732 triangle = TriangleRunner->second; 2733 break; 2734 } 2735 } 2736 // find next line 2737 for (int i=0;i<3;i++) { 2738 if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point 2739 CurrentLine = triangle->lines[i]; 2740 2741 break; 2742 } 2743 } 2744 line = Touched.find(CurrentLine); 2745 if (line == Touched.end()) 2746 *out << Verbose(2) << "ERROR: I could not find " << *CurrentLine << " in the touched list." << endl; 2747 else 2748 line->second = true; 2749 // find next point 2750 CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint); 2751 2752 } while (CurrentLine != StartLine); 2753 // last point is missing, as it's on start line 2754 *out << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl; 2755 connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node); 2756 2757 ListOfPaths->push_back(connectedPath); 2758 } else { 2759 *out << Verbose(3) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl; 2760 } 2761 } 2762 } else { 2763 *out << Verbose(1) << "ERROR: There are no lines attached to " << *ReferencePoint << "." << endl; 2764 } 2765 2766 return ListOfPaths; 2767 } 2768 2769 /** Gets all closed paths on the circle of points connected to the provided point by triangulation lines, if this very point is removed. 2770 * From GetPathsOfConnectedPoints() extracts all single loops of intracrossing paths in the list of closed paths. 2771 * @param *out output stream for debugging 2772 * @param *Point of which get all connected points 2773 * @return list of the closed paths 2774 */ 2775 list<list<TesselPoint*> *> * Tesselation::GetClosedPathsOfConnectedPoints(ofstream *out, TesselPoint* Point) 2776 { 2777 list<list<TesselPoint*> *> *ListofPaths = GetPathsOfConnectedPoints(out, Point); 2778 list<list<TesselPoint*> *> *ListofClosedPaths = new list<list<TesselPoint*> *>; 2779 list<TesselPoint*> *connectedPath = NULL; 2780 list<TesselPoint*> *newPath = NULL; 2781 int count = 0; 2782 2783 2784 list<TesselPoint*>::iterator CircleRunner; 2785 list<TesselPoint*>::iterator CircleStart; 2786 2787 for(list<list<TesselPoint*> *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) { 2788 connectedPath = *ListRunner; 2789 2790 *out << Verbose(2) << "INFO: Current path is " << connectedPath << "." << endl; 2791 2792 // go through list, look for reappearance of starting Point and count 2793 CircleStart = connectedPath->begin(); 2794 2795 // go through list, look for reappearance of starting Point and create list 2796 list<TesselPoint*>::iterator Marker = CircleStart; 2797 for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) { 2798 if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point 2799 // we have a closed circle from Marker to new Marker 2800 *out << Verbose(3) << count+1 << ". closed path consists of: "; 2801 newPath = new list<TesselPoint*>; 2802 list<TesselPoint*>::iterator CircleSprinter = Marker; 2803 for (; CircleSprinter != CircleRunner; CircleSprinter++) { 2804 newPath->push_back(*CircleSprinter); 2805 *out << (**CircleSprinter) << " <-> "; 2806 } 2807 *out << ".." << endl; 2808 count++; 2809 Marker = CircleRunner; 2810 2811 // add to list 2812 ListofClosedPaths->push_back(newPath); 2813 } 2814 } 2815 } 2816 *out << Verbose(3) << "INFO: " << count << " closed additional path(s) have been created." << endl; 2817 2818 // delete list of paths 2819 while (!ListofPaths->empty()) { 2820 connectedPath = *(ListofPaths->begin()); 2821 ListofPaths->remove(connectedPath); 2822 delete(connectedPath); 2823 } 2824 delete(ListofPaths); 2825 2826 // exit 2827 return ListofClosedPaths; 2828 }; 2829 2830 2831 /** Gets all belonging triangles for a given BoundaryPointSet. 2832 * \param *out output stream for debugging 2833 * \param *Point BoundaryPoint 2834 * \return pointer to allocated list of triangles 2835 */ 2836 set<BoundaryTriangleSet*> *Tesselation::GetAllTriangles(ofstream *out, class BoundaryPointSet *Point) 2837 { 2838 set<BoundaryTriangleSet*> *connectedTriangles = new set<BoundaryTriangleSet*>; 2839 2840 if (Point == NULL) { 2841 *out << Verbose(1) << "ERROR: Point given is NULL." << endl; 2842 } else { 2843 // go through its lines and insert all triangles 2844 for (LineMap::iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++) 2845 for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) { 2846 connectedTriangles->insert(TriangleRunner->second); 2847 } 2848 } 2849 2850 return connectedTriangles; 2851 }; 2852 2616 2853 2617 2854 /** Removes a boundary point from the envelope while keeping it closed. … … 2626 2863 Vector OldPoint, TetraederVector[3]; 2627 2864 double volume = 0; 2628 int *numbers = NULL;2629 2865 int count = 0; 2630 int i;2631 2866 2632 2867 if (point == NULL) { … … 2644 2879 return 0.; 2645 2880 } 2646 list<TesselPoint*> *CircleofPoints = GetCircleOfConnectedPoints(out, point->node); 2647 2648 // remove all triangles 2881 2882 list<list<TesselPoint*> *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(out, point->node); 2883 list<TesselPoint*> *connectedPath = NULL; 2884 2885 // gather all triangles 2649 2886 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) 2650 2887 count+=LineRunner->second->triangles.size(); 2651 numbers = new int[count]; 2652 class BoundaryTriangleSet **Candidates = new BoundaryTriangleSet*[count]; 2653 i=0; 2888 map<class BoundaryTriangleSet *, int> Candidates; 2654 2889 for (LineMap::iterator LineRunner = point->lines.begin(); (point != NULL) && (LineRunner != point->lines.end()); LineRunner++) { 2655 2890 line = LineRunner->second; 2656 2891 for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) { 2657 2892 triangle = TriangleRunner->second; 2658 Candidates[i] = triangle; 2659 numbers[i++] = triangle->Nr; 2660 } 2661 } 2662 for (int j=0;j<i;j++) { 2663 RemoveTesselationTriangle(Candidates[j]); 2664 } 2665 delete[](Candidates); 2666 *out << Verbose(1) << i << " triangles were removed." << endl; 2667 2668 // re-create all triangles by going through connected points list 2669 list<TesselPoint*>::iterator CircleRunner = CircleofPoints->begin(); 2670 list<TesselPoint*>::iterator OtherCircleRunner = CircleofPoints->begin(); 2671 class TesselPoint *CentralNode = *CircleRunner; 2672 // advance two with CircleRunner and one with OtherCircleRunner 2673 CircleRunner++; 2674 CircleRunner++; 2675 OtherCircleRunner++; 2676 i=0; 2677 cout << Verbose(2) << "INFO: CentralNode is " << *CentralNode << "." << endl; 2678 for (; (OtherCircleRunner != CircleofPoints->end()) && (CircleRunner != CircleofPoints->end()); (CircleRunner++), (OtherCircleRunner++)) { 2679 cout << Verbose(3) << "INFO: CircleRunner's node is " << **CircleRunner << "." << endl; 2680 cout << Verbose(3) << "INFO: OtherCircleRunner's node is " << **OtherCircleRunner << "." << endl; 2681 *out << Verbose(4) << "Adding new triangle points."<< endl; 2682 AddTesselationPoint(CentralNode, 0); 2683 AddTesselationPoint(*OtherCircleRunner, 1); 2684 AddTesselationPoint(*CircleRunner, 2); 2685 *out << Verbose(4) << "Adding new triangle lines."<< endl; 2686 AddTesselationLine(TPS[0], TPS[1], 0); 2687 AddTesselationLine(TPS[0], TPS[2], 1); 2688 AddTesselationLine(TPS[1], TPS[2], 2); 2689 BTS = new class BoundaryTriangleSet(BLS, numbers[i]); 2690 TrianglesOnBoundary.insert(TrianglePair(numbers[i], BTS)); 2691 *out << Verbose(4) << "Created triangle " << *BTS << "." << endl; 2692 // calculate volume summand as a general tetraeder 2693 for (int j=0;j<3;j++) { 2694 TetraederVector[j].CopyVector(TPS[j]->node->node); 2695 TetraederVector[j].SubtractVector(&OldPoint); 2696 } 2697 OldPoint.CopyVector(&TetraederVector[0]); 2698 OldPoint.VectorProduct(&TetraederVector[1]); 2699 volume += 1./6. * fabs(OldPoint.ScalarProduct(&TetraederVector[2])); 2700 // advance number 2701 i++; 2702 if (i >= count) 2703 *out << Verbose(2) << "WARNING: Maximum of numbers reached!" << endl; 2704 } 2705 *out << Verbose(1) << i << " triangles were created." << endl; 2706 2707 delete[](numbers); 2893 Candidates.insert( pair<class BoundaryTriangleSet *, int> (triangle, triangle->Nr) ); 2894 } 2895 } 2896 2897 // remove all triangles 2898 count=0; 2899 for (map<class BoundaryTriangleSet *, int>::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) { 2900 *out << Verbose(3) << "INFO: Removing triangle " << *(Runner->first) << "." << endl; 2901 RemoveTesselationTriangle(Runner->first); 2902 count++; 2903 } 2904 *out << Verbose(1) << count << " triangles were removed." << endl; 2905 2906 list<list<TesselPoint*> *>::iterator ListAdvance = ListOfClosedPaths->begin(); 2907 list<list<TesselPoint*> *>::iterator ListRunner = ListAdvance; 2908 map<class BoundaryTriangleSet *, int>::iterator NumberRunner = Candidates.begin(); 2909 if (count > 2) { // less than three triangles, then nothing will be created 2910 class TesselPoint *TriangleCandidates[3]; 2911 count = 0; 2912 for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths 2913 if (ListAdvance != ListOfClosedPaths->end()) 2914 ListAdvance++; 2915 2916 connectedPath = *ListRunner; 2917 // initialize the path to start 2918 list<TesselPoint*>::iterator CircleRunner = connectedPath->begin(); 2919 list<TesselPoint*>::iterator OtherCircleRunner = connectedPath->begin(); 2920 class TesselPoint *CentralNode = *CircleRunner; 2921 2922 // re-create all triangles by going through connected points list 2923 // advance two with CircleRunner and one with OtherCircleRunner 2924 CircleRunner++; 2925 CircleRunner++; 2926 OtherCircleRunner++; 2927 cout << Verbose(3) << "INFO: CentralNode is " << *CentralNode << "." << endl; 2928 for (; (OtherCircleRunner != connectedPath->end()) && (CircleRunner != connectedPath->end()); (CircleRunner++), (OtherCircleRunner++)) { 2929 cout << Verbose(4) << "INFO: CircleRunner's node is " << **CircleRunner << "." << endl; 2930 cout << Verbose(4) << "INFO: OtherCircleRunner's node is " << **OtherCircleRunner << "." << endl; 2931 *out << Verbose(3) << "INFO: Creating triangle " << CentralNode->Name << ", " << (*OtherCircleRunner)->Name << " and " << (*CircleRunner)->Name << "." << endl; 2932 *out << Verbose(5) << "Adding new triangle points."<< endl; 2933 TriangleCandidates[0] = CentralNode; 2934 TriangleCandidates[1] = *OtherCircleRunner; 2935 TriangleCandidates[2] = *CircleRunner; 2936 triangle = GetPresentTriangle(out, TriangleCandidates); 2937 AddTesselationPoint(CentralNode, 0); 2938 AddTesselationPoint(*OtherCircleRunner, 1); 2939 AddTesselationPoint(*CircleRunner, 2); 2940 *out << Verbose(5) << "Adding new triangle lines."<< endl; 2941 AddTesselationLine(TPS[0], TPS[1], 0); 2942 AddTesselationLine(TPS[0], TPS[2], 1); 2943 AddTesselationLine(TPS[1], TPS[2], 2); 2944 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 2945 AddTesselationTriangle(); 2946 // calculate volume summand as a general tetraeder 2947 for (int j=0;j<3;j++) { 2948 TetraederVector[j].CopyVector(TPS[j]->node->node); 2949 TetraederVector[j].SubtractVector(&OldPoint); 2950 } 2951 OldPoint.CopyVector(&TetraederVector[0]); 2952 OldPoint.VectorProduct(&TetraederVector[1]); 2953 volume += 1./6. * fabs(OldPoint.ScalarProduct(&TetraederVector[2])); 2954 // advance number 2955 NumberRunner++; 2956 count++; 2957 if (NumberRunner == Candidates.end()) 2958 *out << Verbose(2) << "WARN: Maximum of numbers reached!" << endl; 2959 } 2960 ListOfClosedPaths->remove(connectedPath); 2961 delete(connectedPath); 2962 } 2963 *out << Verbose(1) << count << " triangles were created." << endl; 2964 } else { 2965 while (!ListOfClosedPaths->empty()) { 2966 ListRunner = ListOfClosedPaths->begin(); 2967 connectedPath = *ListRunner; 2968 ListOfClosedPaths->remove(connectedPath); 2969 delete(connectedPath); 2970 } 2971 *out << Verbose(1) << "No need to create any triangles." << endl; 2972 } 2973 2974 delete(ListOfClosedPaths); 2708 2975 2709 2976 return volume; 2710 2977 }; 2978 2979 2711 2980 2712 2981 /** Checks for a new special triangle whether one of its edges is already present with one one triangle connected. … … 3078 3347 } 3079 3348 3080 cout << Verbose( 3) << "INFO: " << point << " has angle " << phi << " with respect to reference " << reference << "." << endl;3349 cout << Verbose(4) << "INFO: " << point << " has angle " << phi << " with respect to reference " << reference << "." << endl; 3081 3350 3082 3351 return phi; -
src/tesselation.hpp
rd4fa23 r065e82 209 209 bool FindNextSuitableTriangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC); 210 210 int CheckPresenceOfTriangle(ofstream *out, class TesselPoint *Candidates[3]); 211 class BoundaryTriangleSet * GetPresentTriangle(ofstream *out, TesselPoint *Candidates[3]); 211 212 212 213 // convex envelope … … 221 222 void RemoveDegeneratedTriangles(); 222 223 223 list<TesselPoint*> * GetCircleOfConnectedPoints(ofstream *out, TesselPoint* Point); 224 list<TesselPoint*> * GetNeighboursOnCircleOfConnectedPoints(ofstream *out, list<TesselPoint*> *connectedPoints, TesselPoint* Point, Vector* Reference); 224 set<TesselPoint*> * GetAllConnectedPoints(ofstream *out, TesselPoint* Point); 225 set<BoundaryTriangleSet*> *GetAllTriangles(ofstream *out, class BoundaryPointSet *Point); 226 list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(ofstream *out, TesselPoint* Point); 227 list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(ofstream *out, TesselPoint* Point); 228 list<TesselPoint*> * GetCircleOfConnectedPoints(ofstream *out, TesselPoint* Point, Vector *Reference = NULL); 225 229 list<BoundaryTriangleSet*> *FindTriangles(TesselPoint* Points[3]); 226 230 list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(ofstream *out, Vector *x, LinkedCell* LC);
Note:
See TracChangeset
for help on using the changeset viewer.