Changeset 262bae for src/tesselation.cpp
- Timestamp:
- Nov 27, 2009, 2:39:06 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:
- 856098, af374d
- Parents:
- 523917
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tesselation.cpp
r523917 r262bae 558 558 // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << "," 559 559 // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]"; 560 return ost; 561 }; 562 563 // ======================================== Polygons on Boundary ================================= 564 565 /** Constructor for BoundaryPolygonSet. 566 */ 567 BoundaryPolygonSet::BoundaryPolygonSet() : 568 Nr(-1) 569 { 570 Info FunctionInfo(__func__); 571 }; 572 573 /** Destructor of BoundaryPolygonSet. 574 * Just clears endpoints. 575 * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle() 576 */ 577 BoundaryPolygonSet::~BoundaryPolygonSet() 578 { 579 Info FunctionInfo(__func__); 580 endpoints.clear(); 581 Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl; 582 }; 583 584 /** Calculates the normal vector for this triangle. 585 * Is made unique by comparison with \a OtherVector to point in the other direction. 586 * \param &OtherVector direction vector to make normal vector unique. 587 * \return allocated vector in normal direction 588 */ 589 Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const 590 { 591 Info FunctionInfo(__func__); 592 // get normal vector 593 Vector TemporaryNormal; 594 Vector *TotalNormal = new Vector; 595 PointSet::const_iterator Runner[3]; 596 for (int i=0;i<3; i++) { 597 Runner[i] = endpoints.begin(); 598 for (int j = 0; j<i; j++) { // go as much further 599 Runner[i]++; 600 if (Runner[i] == endpoints.end()) { 601 eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl; 602 performCriticalExit(); 603 } 604 } 605 } 606 TotalNormal->Zero(); 607 int counter=0; 608 for (; Runner[2] != endpoints.end(); ) { 609 TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node); 610 for (int i=0;i<3;i++) // increase each of them 611 Runner[i]++; 612 TotalNormal->AddVector(&TemporaryNormal); 613 } 614 TotalNormal->Scale(1./(double)counter); 615 616 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 617 if (TotalNormal->ScalarProduct(&OtherVector) > 0.) 618 TotalNormal->Scale(-1.); 619 Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl; 620 621 return TotalNormal; 622 }; 623 624 /** Calculates the center point of the triangle. 625 * Is third of the sum of all endpoints. 626 * \param *center central point on return. 627 */ 628 void BoundaryPolygonSet::GetCenter(Vector * const center) const 629 { 630 Info FunctionInfo(__func__); 631 center->Zero(); 632 int counter = 0; 633 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 634 center->AddVector((*Runner)->node->node); 635 counter++; 636 } 637 center->Scale(1./(double)counter); 638 } 639 640 /** Checks whether the polygons contains all three endpoints of the triangle. 641 * \param *triangle triangle to test 642 * \return true - triangle is contained polygon, false - is not 643 */ 644 bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const 645 { 646 Info FunctionInfo(__func__); 647 return ContainsPresentTupel(triangle->endpoints, 3); 648 }; 649 650 /** Checks whether the polygons contains both endpoints of the line. 651 * \param *line line to test 652 * \return true - line is of the triangle, false - is not 653 */ 654 bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const 655 { 656 return ContainsPresentTupel(line->endpoints, 2); 657 }; 658 659 /** Checks whether point is any of the three endpoints this triangle contains. 660 * \param *point point to test 661 * \return true - point is of the triangle, false - is not 662 */ 663 bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const 664 { 665 Info FunctionInfo(__func__); 666 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) 667 if (point == (*Runner)) 668 return true; 669 return false; 670 }; 671 672 /** Checks whether point is any of the three endpoints this triangle contains. 673 * \param *point TesselPoint to test 674 * \return true - point is of the triangle, false - is not 675 */ 676 bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const 677 { 678 Info FunctionInfo(__func__); 679 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) 680 if (point == (*Runner)->node) 681 return true; 682 return false; 683 }; 684 685 /** Checks whether given array of \a *Points coincide with polygons's endpoints. 686 * \param **Points pointer to an array of BoundaryPointSet 687 * \param dim dimension of array 688 * \return true - set of points is contained in polygon, false - is not 689 */ 690 bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const 691 { 692 int counter = 0; 693 for(int i=0;i<dim;i++) 694 if (ContainsBoundaryPoint(Points[i])) 695 counter++; 696 697 if (counter == dim) 698 return true; 699 else 700 return false; 701 }; 702 703 /** Checks whether given PointList coincide with polygons's endpoints. 704 * \param &endpoints PointList 705 * \return true - set of points is contained in polygon, false - is not 706 */ 707 bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const 708 { 709 size_t counter = 0; 710 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 711 if (ContainsBoundaryPoint(*Runner)) 712 counter++; 713 } 714 715 if (counter == endpoints.size()) 716 return true; 717 else 718 return false; 719 }; 720 721 /** Checks whether given set of \a *Points coincide with polygons's endpoints. 722 * \param *P pointer to BoundaryPolygonSet 723 * \return true - is the very triangle, false - is not 724 */ 725 bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const 726 { 727 Info FunctionInfo(__func__); 728 return ContainsPresentTupel((const PointSet)P->endpoints); 729 }; 730 731 /** Gathers all the endpoints' triangles in a unique set. 732 * \return set of all triangles 733 */ 734 TriangleSet * BoundaryPolygonSet::GetAllTrianglesFromEndpoints() const 735 { 736 Info FunctionInfo(__func__); 737 TriangleSet *triangles = new TriangleSet; 738 739 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) 740 for(LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++) 741 for(TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) 742 triangles->insert(Sprinter->second); 743 744 Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl; 745 return triangles; 746 }; 747 748 /** Fills the endpoints of this polygon from the triangles attached to \a *line. 749 * \param *line lines with triangles attached 750 * \return true - polygon contains four points, false - something went wront, polygon does not contain any points 751 */ 752 bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line) 753 { 754 for(TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) { 755 for (int i=0;i<3;i++) 756 endpoints.insert((Runner->second)->endpoints[i]); 757 } 758 759 if (endpoints.size() != 4) {// remove all points on error 760 endpoints.clear(); 761 return false; 762 } else 763 return true; 764 }; 765 766 /** output operator for BoundaryPolygonSet. 767 * \param &ost output stream 768 * \param &a boundary polygon 769 */ 770 ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a) 771 { 772 ost << "[" << a.Nr << "|"; 773 for(PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) { 774 ost << (*Runner)->node->Name; 775 Runner++; 776 if (Runner != a.endpoints.end()) 777 ost << ","; 778 } 779 ost<< "]"; 560 780 return ost; 561 781 }; … … 3803 4023 TriangleFilesWritten++; 3804 4024 }; 4025 4026 /** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/ 4027 * \return number of polygons found 4028 */ 4029 int Tesselation::CorrectAllDegeneratedPolygons() 4030 { 4031 Info FunctionInfo(__func__); 4032 4033 /// 1. Find all simply degenerated triangles and sort into a list with each endpoint as key 4034 map<int, int> * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles(); 4035 4036 /// 2. Go through all lines not contained in degenerated triangles. 4037 PolygonList ListofFours; 4038 BoundaryPolygonSet *Four = NULL; 4039 TriangleSet *T = NULL; 4040 for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++) { 4041 Four = new BoundaryPolygonSet; 4042 4043 /// 2a. Get all four endpoints of the two connected triangles. 4044 Four->FillPolygonFromTrianglesOfLine((LineRunner->second)); 4045 4046 /// 2b. Get the triangles of all those endpoints 4047 T = Four->GetAllTrianglesFromEndpoints(); 4048 4049 /// 2c. Find all pairs of those triangles that contain the four endpoints 4050 if (CountTrianglePairContainingPolygon(Four, T) > 1) { 4051 /// 2d. Check the number of pairs, if greater 1, we have a degenerated polygon (mark down for later use) 4052 ListofFours.push_back(Four); 4053 } else 4054 delete(Four); 4055 4056 delete(T); 4057 } 4058 4059 /// 3. Combine all edge-connected degenerated polygons 4060 PolygonList::iterator PolygonWalker; // is the inner iterator 4061 PolygonList::iterator PolygonSprinter; // is the inner advanced iterator 4062 for (PolygonList::iterator PolygonRunner = ListofFours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++) { 4063 PolygonWalker = PolygonRunner; 4064 PolygonWalker++; 4065 PolygonSprinter = PolygonWalker; 4066 while (PolygonWalker != ListofFours.end()) { 4067 PolygonSprinter++; 4068 if (ArePolygonsEdgeConnected((*PolygonRunner), (*PolygonWalker))) { // if connected 4069 CombinePolygons((*PolygonRunner), (*PolygonWalker)); // combined and ... 4070 ListofFours.erase(PolygonWalker); // ... remove from list 4071 } 4072 PolygonWalker = PolygonSprinter; 4073 } 4074 } 4075 4076 /// 4. Go through all these degenerated polygons 4077 Vector NormalVector; 4078 for (PolygonList::iterator PolygonRunner = ListofFours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++) { 4079 /// 4a. Gather all triangles of this polygon 4080 T = Four->GetAllTrianglesFromEndpoints(); 4081 4082 /// 4a. Get NormalVector for one side (this is "front") 4083 NormalVector.CopyVector(&(*(T->begin()))->NormalVector); 4084 4085 /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back") 4086 TriangleSet::const_iterator TriangleWalker; // is the inner iterator 4087 TriangleSet::const_iterator TriangleSprinter; // is the inner advanced iterator 4088 PolygonWalker = PolygonRunner; 4089 PolygonWalker++; 4090 PolygonSprinter = PolygonWalker; 4091 while (PolygonWalker != ListofFours.end()) { 4092 PolygonSprinter++; 4093 if ((*TriangleWalker)->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list 4094 delete(*TriangleWalker); // remove triangle 4095 T->erase(TriangleWalker); 4096 } 4097 } 4098 /// 4c. Copy all "front" triangles but with inverse NormalVector 4099 BoundaryTriangleSet *triangle = NULL; 4100 TriangleWalker = T->begin(); 4101 TriangleSprinter = T->end(); 4102 TriangleSprinter--; // set onto last "front" triangle 4103 while (TriangleWalker != TriangleSprinter) { // go through all front triangles 4104 triangle = new BoundaryTriangleSet(*(*TriangleWalker)); // copy triangle ... 4105 triangle->NormalVector.Scale(-1.); 4106 T->insert(triangle); // ... and add 4107 /// 4d. Add all degenerated triangles to the list of simply degenerated triangles 4108 SimplyDegeneratedTriangles->insert(pair <int, int> ((*TriangleWalker)->Nr, triangle->Nr) ); 4109 TriangleWalker++; 4110 } 4111 delete(T); // remove the triangleset 4112 } 4113 4114 /// 5. exit 4115 PolygonList::iterator PolygonRunner; 4116 while (ListofFours.empty()) { 4117 PolygonRunner = ListofFours.begin(); 4118 delete(*PolygonRunner); 4119 ListofFours.erase(PolygonRunner); 4120 } 4121 4122 int counter = SimplyDegeneratedTriangles->size(); 4123 delete(SimplyDegeneratedTriangles); 4124 return counter; 4125 };
Note:
See TracChangeset
for help on using the changeset viewer.