Changeset fad93c for src/tesselation.cpp
- Timestamp:
- Nov 28, 2009, 6:01:00 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:
- a8eb4a
- Parents:
- 856098
- git-author:
- Frederik Heber <heber@…> (11/28/09 17:52:05)
- git-committer:
- Frederik Heber <heber@…> (11/28/09 18:01:00)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tesselation.cpp
r856098 rfad93c 4127 4127 Info FunctionInfo(__func__); 4128 4128 4129 /// 1. Find all simply degenerated triangles and sort into a list with each endpoint as key 4130 map<int, int> * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles(); 4131 4132 /// 2. Go through all lines not contained in degenerated triangles. 4133 UniquePolygonSet ListofFours; 4134 UniquePolygonSet TestedPolygons; 4135 for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++) { 4136 Log() << Verbose(1) << "Current Line is: " << *(LineRunner->second) << endl; 4137 4138 BoundaryPolygonSet *Four = new BoundaryPolygonSet; 4139 4140 /// 2a. Get all four endpoints of the two connected triangles. 4141 Four->FillPolygonFromTrianglesOfLine((LineRunner->second)); 4142 if (Four->endpoints.size() != 4) { 4143 Log() << Verbose(0) << "REJECT: There were no four endpoints:" << *Four << endl; 4144 delete(Four); 4145 continue; 4146 } 4147 4148 /// 2b. Get the triangles of all those endpoints 4149 TriangleSet *T = Four->GetAllContainedTrianglesFromEndpoints(); 4150 4151 /// 2c1. Check whether all triangles have (besides sign) same normal vector) 4152 TriangleSet::const_iterator Runner = T->begin(); 4153 Vector NormalVector; 4154 NormalVector.CopyVector(&(*Runner)->NormalVector); 4155 Runner++; 4156 bool IsPlanar = true; 4157 for (; Runner != T->end(); Runner++) { 4158 if (fabs(fabs(NormalVector.ScalarProduct(&(*Runner)->NormalVector)) - 1.) > MYEPSILON) // check whether all NormalVectors are parallel 4159 IsPlanar = false; 4160 } 4161 4162 /// 2c2. check whether triangles are not already simply degenerated. 4163 size_t DegeneratedCount = 0; 4164 for (TriangleSet::const_iterator Runner = T->begin(); Runner != T->end(); Runner++) { 4165 if (SimplyDegeneratedTriangles->find((*Runner)->Nr) != SimplyDegeneratedTriangles->end()) 4166 DegeneratedCount++; 4167 } 4168 Log() << Verbose(1) << "Found " << DegeneratedCount << " degenerated triangles." << endl; 4169 4170 if (IsPlanar) { 4171 if(DegeneratedCount == 0) { 4172 /// 2c. Find all pairs of those triangles that contain the four endpoints 4173 const int counter = CountTrianglePairContainingPolygon(Four, T); 4174 Log() << Verbose(1) << "There are " << counter << " pairs for this polygon of four." << endl; 4175 if (counter %3 == 0) { 4176 /// 2d. Check the number of pairs, if greater 1, we have a degenerated polygon (mark down for later use) 4177 pair < UniquePolygonSet::iterator, bool > Tester = ListofFours.insert(Four); 4178 if (Tester.second) { 4179 Log() << Verbose(0) << "ACCEPT: We have a degenerated polygon." << *Four << endl; 4180 } else { 4181 Log() << Verbose(0) << "REJECT: Degenerated polygon already present." << *Four << endl; 4182 delete(Four); 4129 /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector 4130 set < BoundaryPointSet *> EndpointCandidateList; 4131 pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester; 4132 pair < map < int, Vector *>::iterator, bool > TriangleInsertionTester; 4133 for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) { 4134 Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl; 4135 map < int, Vector *> TriangleVectors; 4136 // gather all NormalVectors 4137 Log() << Verbose(1) << "Gathering triangles ..." << endl; 4138 for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++) 4139 for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) { 4140 TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) ); 4141 if (TriangleInsertionTester.second) 4142 Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl; 4143 } 4144 // check whether there are two that are parallel 4145 Log() << Verbose(1) << "Finding two parallel triangles ..." << endl; 4146 for (map < int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++) 4147 for (map < int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++) 4148 if (VectorWalker != VectorRunner) { // skip equals 4149 const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles 4150 Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl; 4151 if (fabs(SCP + 1.) < ParallelEpsilon) { 4152 InsertionTester = EndpointCandidateList.insert((Runner->second)); 4153 if (InsertionTester.second) 4154 Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl; 4155 // and break out of both loops 4156 VectorWalker = TriangleVectors.end(); 4157 VectorRunner = TriangleVectors.end(); 4158 break; 4183 4159 } 4160 } 4161 } 4162 4163 /// 3. Find connected endpoint candidates and put them into a polygon 4164 UniquePolygonSet ListofDegeneratedPolygons; 4165 BoundaryPointSet *Walker = NULL; 4166 BoundaryPointSet *OtherWalker = NULL; 4167 BoundaryPolygonSet *Current = NULL; 4168 stack <BoundaryPointSet*> ToCheckConnecteds; 4169 while (!EndpointCandidateList.empty()) { 4170 Walker = *(EndpointCandidateList.begin()); 4171 if (Current == NULL) { // create a new polygon with current candidate 4172 Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl; 4173 Current = new BoundaryPolygonSet; 4174 Current->endpoints.insert(Walker); 4175 EndpointCandidateList.erase(Walker); 4176 ToCheckConnecteds.push(Walker); 4177 } 4178 4179 // go through to-check stack 4180 while (!ToCheckConnecteds.empty()) { 4181 Walker = ToCheckConnecteds.top(); // fetch ... 4182 ToCheckConnecteds.pop(); // ... and remove 4183 for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) { 4184 OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker); 4185 Log() << Verbose(1) << "Checking " << *OtherWalker << endl; 4186 set < BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker); 4187 if (Finder != EndpointCandidateList.end()) { // found a connected partner 4188 Log() << Verbose(1) << " Adding to polygon." << endl; 4189 Current->endpoints.insert(OtherWalker); 4190 EndpointCandidateList.erase(Finder); // remove from candidates 4191 ToCheckConnecteds.push(OtherWalker); // but check its partners too 4184 4192 } else { 4185 Log() << Verbose(0) << "REJECT: Seems to be the edge line of a degenerated polygon only." << *Four << endl; 4186 delete(Four); 4193 Log() << Verbose(1) << " is not connected to " << *Walker << endl; 4187 4194 } 4188 } else {4189 Log() << Verbose(0) << "REJECT: This polygon contains some simply degenerated triangles." << endl;4190 delete(Four);4191 4195 } 4192 } else { 4193 Log() << Verbose(0) << "REJECT: This polygon does not lay on a plane." << endl; 4194 delete(Four); 4195 } 4196 4197 delete(T); 4198 } 4199 4200 /// 3. Combine all edge-connected degenerated polygons 4201 { 4202 UniquePolygonSet::iterator PolygonWalker; // is the inner iterator 4203 UniquePolygonSet::iterator PolygonSprinter; // is the inner advanced iterator 4204 for (UniquePolygonSet::iterator PolygonRunner = ListofFours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++) { 4205 const BoundaryPolygonSet *P1 = *PolygonRunner; 4206 Log() << Verbose(1) << "Current Polygon is : " << *P1 << endl; 4207 PolygonWalker = PolygonRunner; 4208 PolygonWalker++; 4209 PolygonSprinter = PolygonWalker; 4210 while (PolygonWalker != ListofFours.end()) { 4211 BoundaryPolygonSet *P2 = *PolygonWalker; 4212 Log() << Verbose(1) << "Current Other Polygon is : " << *P2 << endl; 4213 PolygonSprinter++; 4214 Log() << Verbose(1) << "Are " << *P1 << " and " << *P2 << " edge-connected?" << endl; 4215 if (ArePolygonsEdgeConnected((*PolygonRunner), (P2))) { // if connected 4216 Log() << Verbose(0) << "Yes!" << endl; 4217 CombinePolygons((*PolygonRunner), (P2)); // combined and ... 4218 ListofFours.erase(PolygonWalker); // ... remove from list 4219 Log() << Verbose(1) << " New current Polygon is : " << *P1 << endl; 4220 } else { 4221 Log() << Verbose(0) << "No." << endl; 4222 } 4223 PolygonWalker = PolygonSprinter; 4224 } 4225 } 4226 } 4227 4228 Log() << Verbose(0) << "The following degenerated polygons have been found: " << endl; 4229 for (UniquePolygonSet::iterator PolygonRunner = ListofFours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++) 4196 } 4197 4198 Log() << Verbose(0) << "Final polygon is " << *Current << endl; 4199 ListofDegeneratedPolygons.insert(Current); 4200 Current = NULL; 4201 } 4202 4203 const int counter = ListofDegeneratedPolygons.size(); 4204 4205 Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl; 4206 for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) 4230 4207 Log() << Verbose(0) << " " << **PolygonRunner << endl; 4231 4208 4232 4209 /// 4. Go through all these degenerated polygons 4233 for (UniquePolygonSet::iterator PolygonRunner = Listof Fours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++) {4210 for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) { 4234 4211 stack <int> TriangleNrs; 4235 4212 Vector NormalVector; … … 4261 4238 TriangleWalker = T->begin(); 4262 4239 while (TriangleWalker != T->end()) { // go through all front triangles 4263 Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << BTS->NormalVector << endl;4240 Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl; 4264 4241 for (int i = 0; i < 3; i++) 4265 4242 AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i); … … 4267 4244 AddTesselationLine(TPS[0], TPS[2], 1); 4268 4245 AddTesselationLine(TPS[1], TPS[2], 2); 4246 if (TriangleNrs.empty()) 4247 eLog() << Verbose(0) << "No more free triangle numbers!" << endl; 4269 4248 BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ... 4270 4249 AddTesselationTriangle(); // ... and add … … 4272 4251 BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector); 4273 4252 BTS->NormalVector.Scale(-1.); 4274 /// 4d. Add all degenerated triangles to the list of simply degenerated triangles4275 SimplyDegeneratedTriangles->insert(pair <int, int> ((*TriangleWalker)->Nr, BTS->Nr) );4276 SimplyDegeneratedTriangles->insert(pair <int, int> (BTS->Nr, (*TriangleWalker)->Nr) );4277 4253 TriangleWalker++; 4278 4254 } … … 4283 4259 } 4284 4260 4261 map<int, int> * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles(); 4285 4262 Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl; 4286 4263 map<int,int>::iterator it; 4287 4264 for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++) 4288 4265 Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl; 4266 delete(SimplyDegeneratedTriangles); 4289 4267 4290 4268 /// 5. exit 4291 4269 UniquePolygonSet::iterator PolygonRunner; 4292 while (!Listof Fours.empty()) {4293 PolygonRunner = Listof Fours.begin();4270 while (!ListofDegeneratedPolygons.empty()) { 4271 PolygonRunner = ListofDegeneratedPolygons.begin(); 4294 4272 delete(*PolygonRunner); 4295 ListofFours.erase(PolygonRunner); 4296 } 4297 4298 const int counter = SimplyDegeneratedTriangles->size(); 4299 delete(SimplyDegeneratedTriangles); 4273 ListofDegeneratedPolygons.erase(PolygonRunner); 4274 } 4275 4300 4276 return counter; 4301 4277 };
Note:
See TracChangeset
for help on using the changeset viewer.