Changeset af374d


Ignore:
Timestamp:
Nov 28, 2009, 3:07:42 PM (15 years ago)
Author:
Frederik Heber <heber@…>
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:
2130dd
Parents:
262bae
git-author:
Frederik Heber <heber@…> (11/28/09 14:58:40)
git-committer:
Frederik Heber <heber@…> (11/28/09 15:07:42)
Message:

Correction of degenerated polygons is working.

Signed-off-by: Frederik Heber <heber@…>

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    r262bae raf374d  
    10411041//  TesselStruct->RemoveDegeneratedTriangles();
    10421042
     1043  // correct degenerated polygons
     1044  TesselStruct->CorrectAllDegeneratedPolygons();
     1045
    10431046  // check envelope for consistency
    10441047  status = CheckListOfBaselines(TesselStruct);
  • src/tesselation.cpp

    r262bae raf374d  
    636636  }
    637637  center->Scale(1./(double)counter);
     638  Log() << Verbose(1) << "Center is at " << *center << "." << endl;
    638639}
    639640
     
    654655bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
    655656{
     657  Info FunctionInfo(__func__);
    656658  return ContainsPresentTupel(line->endpoints, 2);
    657659};
     
    664666{
    665667  Info FunctionInfo(__func__);
    666   for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    667     if (point == (*Runner))
     668  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     669    Log() << Verbose(0) << "Checking against " << **Runner << endl;
     670    if (point == (*Runner)) {
     671      Log() << Verbose(0) << " Contained." << endl;
    668672      return true;
     673    }
     674  }
     675  Log() << Verbose(0) << " Not contained." << endl;
    669676  return false;
    670677};
     
    678685  Info FunctionInfo(__func__);
    679686  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    680     if (point == (*Runner)->node)
     687    if (point == (*Runner)->node) {
     688      Log() << Verbose(0) << " Contained." << endl;
    681689      return true;
     690    }
     691  Log() << Verbose(0) << " Not contained." << endl;
    682692  return false;
    683693};
     
    690700bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
    691701{
     702  Info FunctionInfo(__func__);
    692703  int counter = 0;
    693   for(int i=0;i<dim;i++)
    694     if (ContainsBoundaryPoint(Points[i]))
     704  Log() << Verbose(1) << "Polygon is " << *this << endl;
     705  for(int i=0;i<dim;i++) {
     706    Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl;
     707    if (ContainsBoundaryPoint(Points[i])) {
    695708      counter++;
     709    }
     710  }
    696711
    697712  if (counter == dim)
     
    707722bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
    708723{
     724  Info FunctionInfo(__func__);
    709725  size_t counter = 0;
     726  Log() << Verbose(1) << "Polygon is " << *this << endl;
    710727  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     728    Log() << Verbose(1) << " Testing endpoint " << **Runner << endl;
    711729    if (ContainsBoundaryPoint(*Runner))
    712730      counter++;
     
    725743bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
    726744{
    727   Info FunctionInfo(__func__);
    728745  return ContainsPresentTupel((const PointSet)P->endpoints);
    729746};
     
    732749 * \return set of all triangles
    733750 */
    734 TriangleSet * BoundaryPolygonSet::GetAllTrianglesFromEndpoints() const
     751TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
    735752{
    736753  Info FunctionInfo(__func__);
     754  pair <TriangleSet::iterator, bool> Tester;
    737755  TriangleSet *triangles = new TriangleSet;
    738756
    739757  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
    740758    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);
     759      for(TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
     760        //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
     761        if (ContainsBoundaryTriangle(Sprinter->second)) {
     762          Tester = triangles->insert(Sprinter->second);
     763          if (Tester.second)
     764            Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl;
     765        }
     766      }
    743767
    744768  Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl;
     
    748772/** Fills the endpoints of this polygon from the triangles attached to \a *line.
    749773 * \param *line lines with triangles attached
    750  * \return true - polygon contains four points, false - something went wront, polygon does not contain any points
     774 * \return true - polygon contains endpoints, false - line was NULL
    751775 */
    752776bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
    753777{
     778  Info FunctionInfo(__func__);
     779  pair <PointSet::iterator, bool> Tester;
     780  if (line == NULL)
     781    return false;
     782  Log() << Verbose(1) << "Filling polygon from line " << *line << endl;
    754783  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;
     784    for (int i=0;i<3;i++) {
     785      Tester = endpoints.insert((Runner->second)->endpoints[i]);
     786      if (Tester.second)
     787        Log() << Verbose(1) << "  Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl;
     788    }
     789  }
     790
     791  return true;
    764792};
    765793
     
    15771605        // remove existing line from OpenLines
    15781606        CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
    1579         delete(CandidateLine->second);
    1580         OpenLines.erase(CandidateLine);
     1607        if (CandidateLine != OpenLines.end()) {
     1608          Log() << Verbose(1) << " Removing line from OpenLines." << endl;
     1609          delete(CandidateLine->second);
     1610          OpenLines.erase(CandidateLine);
     1611        } else {
     1612          eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl;
     1613        }
    15811614
    15821615        break;
     
    16701703      } else {
    16711704        Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ";
     1705        OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
    16721706        for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
    16731707          Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
     
    23322366    Sprinter++;
    23332367  }
     2368  delete(connectedClosestPoints);
    23342369};
    23352370
     
    37073742}
    37083743
     3744struct BoundaryLineSetCompare {
     3745  bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) {
     3746    int lowerNra = -1;
     3747    int lowerNrb = -1;
     3748
     3749    if (a->endpoints[0] < a->endpoints[1])
     3750      lowerNra = 0;
     3751    else
     3752      lowerNra = 1;
     3753
     3754    if (b->endpoints[0] < b->endpoints[1])
     3755      lowerNrb = 0;
     3756    else
     3757      lowerNrb = 1;
     3758
     3759    if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
     3760      return true;
     3761    else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
     3762      return false;
     3763    else {  // both lower-numbered endpoints are the same ...
     3764     if (a->endpoints[(lowerNra+1)%2] < b->endpoints[(lowerNrb+1)%2])
     3765       return true;
     3766     else if (a->endpoints[(lowerNra+1)%2] > b->endpoints[(lowerNrb+1)%2])
     3767       return false;
     3768    }
     3769    return false;
     3770  };
     3771};
     3772
     3773#define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
     3774
    37093775/**
    37103776 * Finds all degenerated lines within the tesselation structure.
     
    37163782{
    37173783        Info FunctionInfo(__func__);
    3718   map<int, class BoundaryLineSet *> AllLines;
     3784        UniqueLines AllLines;
    37193785  map<int, int> * DegeneratedLines = new map<int, int>;
    37203786
     
    37263792
    37273793  LineMap::iterator LineRunner1;
    3728   pair<LineMap::iterator, bool> tester;
     3794  pair< UniqueLines::iterator, bool> tester;
    37293795  for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
    3730     tester = AllLines.insert( pair<int,BoundaryLineSet *> (LineRunner1->second->endpoints[0]->Nr, LineRunner1->second) );
    3731     if ((!tester.second) && (tester.first->second->endpoints[1]->Nr == LineRunner1->second->endpoints[1]->Nr)) { // found degenerated line
    3732       DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, tester.first->second->Nr) );
    3733       DegeneratedLines->insert ( pair<int, int> (tester.first->second->Nr, LineRunner1->second->Nr) );
     3796    tester = AllLines.insert( LineRunner1->second );
     3797    if (!tester.second) { // found degenerated line
     3798      DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr) );
     3799      DegeneratedLines->insert ( pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr) );
    37343800    }
    37353801  }
     
    37393805  Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
    37403806  map<int,int>::iterator it;
    3741   for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++)
    3742       Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     3807  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
     3808    const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
     3809    const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
     3810    if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
     3811      Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl;
     3812    else
     3813      eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl;
     3814  }
    37433815
    37443816  return DegeneratedLines;
     
    40244096};
    40254097
     4098struct BoundaryPolygonSetCompare {
     4099  bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const {
     4100    if (s1->endpoints.size() < s2->endpoints.size())
     4101      return true;
     4102    else if (s1->endpoints.size() > s2->endpoints.size())
     4103      return false;
     4104    else { // equality of number of endpoints
     4105      PointSet::const_iterator Walker1 = s1->endpoints.begin();
     4106      PointSet::const_iterator Walker2 = s2->endpoints.begin();
     4107      while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
     4108        if ((*Walker1)->Nr < (*Walker2)->Nr)
     4109          return true;
     4110        else if ((*Walker1)->Nr > (*Walker2)->Nr)
     4111          return false;
     4112        Walker1++;
     4113        Walker2++;
     4114      }
     4115      return false;
     4116    }
     4117  }
     4118};
     4119
     4120#define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
     4121
    40264122/** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
    40274123 * \return number of polygons found
     
    40354131
    40364132  /// 2. Go through all lines not contained in degenerated triangles.
    4037   PolygonList ListofFours;
    4038   BoundaryPolygonSet *Four = NULL;
    4039   TriangleSet *T = NULL;
     4133  UniquePolygonSet ListofFours;
    40404134  for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++) {
    4041     Four = new BoundaryPolygonSet;
     4135    Log() << Verbose(1) << "Current Line is: " << *(LineRunner->second) << endl;
     4136
     4137    BoundaryPolygonSet *Four = new BoundaryPolygonSet;
    40424138
    40434139    /// 2a. Get all four endpoints of the two connected triangles.
    40444140    Four->FillPolygonFromTrianglesOfLine((LineRunner->second));
     4141    if (Four->endpoints.size() != 4) {
     4142      Log() << Verbose(0) << "REJECT: There were no four endpoints:" << *Four << endl;
     4143      delete(Four);
     4144      continue;
     4145    }
    40454146
    40464147    /// 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
     4148    TriangleSet *T = Four->GetAllContainedTrianglesFromEndpoints();
     4149
     4150    /// 2c. check whether triangles are not already simply degenerated.
     4151    size_t DegeneratedCount = 0;
     4152    for (TriangleSet::const_iterator Runner = T->begin(); Runner != T->end(); Runner++) {
     4153      if (SimplyDegeneratedTriangles->find((*Runner)->Nr) != SimplyDegeneratedTriangles->end())
     4154        DegeneratedCount++;
     4155    }
     4156    Log() << Verbose(1) << "Found " << DegeneratedCount << " degenerated triangles." << endl;
     4157    if (DegeneratedCount == 0) {
     4158      /// 2c. Find all pairs of those triangles that contain the four endpoints
     4159      const int counter = CountTrianglePairContainingPolygon(Four, T);
     4160      Log() << Verbose(1) << "There are " << counter << " pairs for this polygon of four." << endl;
     4161      if (counter %3 == 0) {
     4162        /// 2d. Check the number of pairs, if greater 1, we have a degenerated polygon (mark down for later use)
     4163        pair < UniquePolygonSet::iterator, bool > Tester = ListofFours.insert(Four);
     4164        if (Tester.second) {
     4165          Log() << Verbose(0) << "ACCEPT: We have a degenerated polygon." << *Four << endl;
     4166        } else {
     4167          Log() << Verbose(0) << "REJECT: Degenerated polygon already present." << *Four << endl;
     4168          delete(Four);
     4169        }
     4170      } else {
     4171        Log() << Verbose(0) << "REJECT: Seems to be the edge line of a degenerated polygon only." << *Four << endl;
     4172        delete(Four);
     4173      }
     4174    } else {
     4175      Log() << Verbose(0) << "REJECT: This polygon contains some simply degenerated triangles." << endl;
    40544176      delete(Four);
     4177    }
    40554178
    40564179    delete(T);
     
    40584181
    40594182  /// 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
     4183  {
     4184    UniquePolygonSet::iterator PolygonWalker;  // is the inner iterator
     4185    UniquePolygonSet::iterator PolygonSprinter; // is the inner advanced iterator
     4186    for (UniquePolygonSet::iterator PolygonRunner = ListofFours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++) {
     4187      const BoundaryPolygonSet *P1 = *PolygonRunner;
     4188      Log() << Verbose(1) << "Current Polygon is : " << *P1 << endl;
     4189      PolygonWalker = PolygonRunner;
     4190      PolygonWalker++;
     4191      PolygonSprinter = PolygonWalker;
     4192      while (PolygonWalker != ListofFours.end()) {
     4193        BoundaryPolygonSet *P2 = *PolygonWalker;
     4194        Log() << Verbose(1) << "Current Other Polygon is : " << *P2 << endl;
     4195        PolygonSprinter++;
     4196        Log() << Verbose(1) << "Are " << *P1 << " and " << *P2 << " edge-connected?" << endl;
     4197        if (ArePolygonsEdgeConnected((*PolygonRunner), (P2))) { // if connected
     4198          Log() << Verbose(0) << "Yes!" << endl;
     4199          CombinePolygons((*PolygonRunner), (P2)); // combined and ...
     4200          ListofFours.erase(PolygonWalker); // ... remove from list
     4201          Log() << Verbose(1) << "  New current Polygon is : " << *P1 << endl;
     4202        } else {
     4203          Log() << Verbose(0) << "No." << endl;
     4204        }
     4205        PolygonWalker = PolygonSprinter;
    40714206      }
    4072       PolygonWalker = PolygonSprinter;
    4073     }
    4074   }
     4207    }
     4208  }
     4209
     4210  Log() << Verbose(0) << "The following degenerated polygons have been found: " << endl;
     4211  for (UniquePolygonSet::iterator PolygonRunner = ListofFours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++)
     4212    Log() << Verbose(0) << " " << **PolygonRunner << endl;
    40754213
    40764214  /// 4. Go through all these degenerated polygons
    4077   Vector NormalVector;
    4078   for (PolygonList::iterator PolygonRunner = ListofFours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++) {
     4215  for (UniquePolygonSet::iterator PolygonRunner = ListofFours.begin(); PolygonRunner != ListofFours.end(); PolygonRunner++) {
     4216    stack <int> TriangleNrs;
     4217    Vector NormalVector;
    40794218    /// 4a. Gather all triangles of this polygon
    4080     T = Four->GetAllTrianglesFromEndpoints();
    4081 
     4219    TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
     4220
     4221    TriangleSet::iterator TriangleWalker = T->begin();  // is the inner iterator
    40824222    /// 4a. Get NormalVector for one side (this is "front")
    4083     NormalVector.CopyVector(&(*(T->begin()))->NormalVector);
    4084 
     4223    NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     4224    Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl;
     4225    TriangleWalker++;
     4226    TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
    40854227    /// 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
     4228    BoundaryTriangleSet *triangle = NULL;
     4229    while (TriangleSprinter != T->end()) {
     4230      TriangleWalker = TriangleSprinter;
     4231      triangle = *TriangleWalker;
     4232      TriangleSprinter++;
     4233      Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl;
     4234      if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
     4235        Log() << Verbose(1) << " Removing ... " << endl;
     4236        TriangleNrs.push(triangle->Nr);
    40954237        T->erase(TriangleWalker);
    4096       }
     4238        RemoveTesselationTriangle(triangle);
     4239      } else
     4240        Log() << Verbose(1) << " Keeping ... " << endl;
    40974241    }
    40984242    /// 4c. Copy all "front" triangles but with inverse NormalVector
    4099     BoundaryTriangleSet *triangle = NULL;
    41004243    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
     4244    while (TriangleWalker != T->end()) {  // go through all front triangles
     4245      Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << BTS->NormalVector << endl;
     4246      for (int i = 0; i < 3; i++)
     4247        AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
     4248      AddTesselationLine(TPS[0], TPS[1], 0);
     4249      AddTesselationLine(TPS[0], TPS[2], 1);
     4250      AddTesselationLine(TPS[1], TPS[2], 2);
     4251      BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
     4252      AddTesselationTriangle(); // ... and add
     4253      TriangleNrs.pop();
     4254      BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     4255      BTS->NormalVector.Scale(-1.);
    41074256      /// 4d. Add all degenerated triangles to the list of simply degenerated triangles
    4108       SimplyDegeneratedTriangles->insert(pair <int, int> ((*TriangleWalker)->Nr, triangle->Nr) );
     4257      SimplyDegeneratedTriangles->insert(pair <int, int> ((*TriangleWalker)->Nr, BTS->Nr) );
     4258      SimplyDegeneratedTriangles->insert(pair <int, int> (BTS->Nr, (*TriangleWalker)->Nr) );
    41094259      TriangleWalker++;
    41104260    }
     4261    if (!TriangleNrs.empty()) {
     4262      eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl;
     4263    }
    41114264    delete(T);  // remove the triangleset
    41124265  }
    41134266
     4267  Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
     4268  map<int,int>::iterator it;
     4269  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
     4270      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     4271
    41144272  /// 5. exit
    4115   PolygonList::iterator PolygonRunner;
    4116   while (ListofFours.empty()) {
     4273  UniquePolygonSet::iterator PolygonRunner;
     4274  while (!ListofFours.empty()) {
    41174275    PolygonRunner = ListofFours.begin();
    41184276    delete(*PolygonRunner);
     
    41204278  }
    41214279
    4122   int counter = SimplyDegeneratedTriangles->size();
     4280  const int counter = SimplyDegeneratedTriangles->size();
    41234281  delete(SimplyDegeneratedTriangles);
    41244282  return counter;
  • src/tesselation.hpp

    r262bae raf374d  
    2323#include <list>
    2424#include <set>
     25#include <stack>
    2526
    2627#include "atom_particleinfo.hpp"
     
    183184    bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
    184185    bool ContainsPresentTupel(const PointSet &endpoints) const;
    185     TriangleSet * GetAllTrianglesFromEndpoints() const;
     186    TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
    186187    bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
    187188
  • src/tesselationhelpers.cpp

    r262bae raf374d  
    956956  }
    957957
     958  Log() << Verbose(0) << "Polygon is " << *P << endl;
    958959  // create each pair, get the endpoints and check whether *P is contained.
    959960  int counter = 0;
     
    969970        for (int i=0;i<3;i++)
    970971          PairTrianglenodes.endpoints.insert((*PairWalker)->endpoints[i]);
    971         Log() << Verbose(1) << "Current pair of triangles: " << PairTrianglenodes << "." << endl;
    972         // now check
    973         if (PairTrianglenodes.ContainsPresentTupel(P)) {
    974           counter++;
    975           Log() << Verbose(1) << "Matches with " << *P << endl;
     972        const int size = PairTrianglenodes.endpoints.size();
     973        if (size == 4) {
     974          Log() << Verbose(0) << " Current pair of triangles: " << **Walker << "," << **PairWalker << " with " << size << " distinct endpoints:" << PairTrianglenodes << endl;
     975          // now check
     976          if (PairTrianglenodes.ContainsPresentTupel(P)) {
     977            counter++;
     978            Log() << Verbose(0) << "  ACCEPT: Matches with " << *P << endl;
     979          } else {
     980            Log() << Verbose(0) << "  REJECT: No match with " << *P << endl;
     981          }
    976982        } else {
    977           Log() << Verbose(1) << "No match with " << *P << endl;
     983          Log() << Verbose(0) << "  REJECT: Less than four endpoints." << endl;
    978984        }
    979985      }
    980986    }
    981     PairTrianglenodes.endpoints.clear();
     987    Trianglenodes.clear();
    982988  }
    983989  return counter;
     
    10101016{
    10111017  Info FunctionInfo(__func__);
    1012   for(PointSet::iterator Runner = P1->endpoints.begin(); Runner != P1->endpoints.end(); Runner++) {
    1013     P1->endpoints.insert((*Runner));
     1018  pair <PointSet::iterator, bool> Tester;
     1019  for(PointSet::iterator Runner = P2->endpoints.begin(); Runner != P2->endpoints.end(); Runner++) {
     1020    Tester = P1->endpoints.insert((*Runner));
     1021    if (Tester.second)
     1022      Log() << Verbose(0) << "Inserting endpoint " << *(*Runner) << " into first polygon." << endl;
    10141023  }
    10151024  P2->endpoints.clear();
Note: See TracChangeset for help on using the changeset viewer.