Changeset 711ac2 for src


Ignore:
Timestamp:
Apr 20, 2010, 12:20:10 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:
90f680
Parents:
a26ca5
Message:

Memory leak fixes and code cleanup after tesselation rewrite.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/tesselation.cpp

    ra26ca5 r711ac2  
    326326 */
    327327BoundaryTriangleSet::BoundaryTriangleSet() :
    328   top(NULL),
    329   AngleFromTop(-1.),
    330328  Nr(-1)
    331329{
     
    343341 */
    344342BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
    345   top(NULL),
    346   AngleFromTop(-1.),
    347343  Nr(number)
    348344{
     
    397393  }
    398394  //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
    399 };
    400 
    401 void BoundaryTriangleSet::SetTopNode(const BoundaryTriangleSet * const topnode)
    402 {
    403   top = topnode;
    404395};
    405396
     
    22522243
    22532244    FindSecondPointForTesselation(BaseLine->endpoints[0]->node, NormalVector, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
    2254     if (Temporary == NULL)  // have we found a second point?
     2245    if (Temporary == NULL) {
     2246      // have we found a second point?
     2247      delete BaseLine;
    22552248      continue;
     2249    }
    22562250    BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
    22572251
     
    22992293    }
    23002294
    2301     if (BTS != NULL) // we have created one starting triangle
     2295    if (BTS != NULL) { // we have created one starting triangle
     2296      delete BaseLine;
    23022297      break;
    2303     else {
     2298    } else {
    23042299      // remove all candidates from the list and then the list itself
    23052300      OptCandidates.pointlist.clear();
     
    26552650      // add normal and degenerate triangles
    26562651      Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl;
    2657       BoundaryTriangleSet * const triangle = AddDegeneratedTriangle(CandidateLine, RADIUS, LC);
     2652      AddDegeneratedTriangle(CandidateLine, RADIUS, LC);
    26582653    } else {
    26592654      // add this triangle
     
    26762671 * \param RADIUS radius of sphere
    26772672 * \param *LC pointer to LinkedCell structure
    2678  * \return pointer to created other triangle
    2679  */
    2680 BoundaryTriangleSet * const  Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
     2673 */
     2674void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
    26812675{
    26822676  Info FunctionInfo(__func__);
    2683   BoundaryTriangleSet *triangle = NULL;
    2684   pair<LineMap::iterator,LineMap::iterator> FindPair[3];
    2685   int LineCase[3];
    2686   int count[3];
    26872677  Vector Center;
    26882678  CandidateMap::const_iterator CandidateCheck = OpenLines.end();
    2689 
    2690   /// 1. For each new pair of endpoints, find and count the number of present lines
    2691   Log() << Verbose(0) << "INFO: Counting present open lines ..." << endl;
    2692   for (int i=0;i<3;i++) {
    2693     BLS[i] = NULL;
    2694     LineCase[i] = -1;
    2695     // find already present lines
    2696     FindPair[i] = TPS[(i+0)%3]->lines.equal_range(TPS[(i+1)%3]->Nr);
    2697     // count their number
    2698     count[i] = 0;
    2699     Log() << Verbose(1) << "For line between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
    2700     for (LineMap::iterator FindLine = FindPair[i].first; FindLine != FindPair[i].second; FindLine++)
    2701       if (FindLine->second->triangles.size() == 1) {
    2702         Log() << Verbose(1) << "  open line " << *FindLine->second << "." << endl;
    2703         count[i]++;
    2704       }
    2705     Log() << Verbose(1) << "  SUM: there are " << count[i] << " line(s) present."  << endl;
    2706   }
    2707 
    2708   /// 2. Create or pick the lines for the first triangle
    2709   // for each count we have a different case:
     2679  BoundaryTriangleSet *triangle = NULL;
     2680
     2681  /// 1. Create or pick the lines for the first triangle
     2682  // for each amount of open lines we have a different case:
    27102683  // case 0: no triangles at this line and not closed
    27112684  // case 1: no triangles at new line is closed
     
    27152688  Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl;
    27162689  for (int i=0;i<3;i++) {
     2690    BLS[i] = NULL;
    27172691    Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
    2718     switch (count[i]) {
    2719       case 0:
    2720         AddNewTesselationTriangleLine(TPS[(i+0)%3], TPS[(i+1)%3], i);
    2721         break;
    2722       case 1:
    2723 //        // check whether present line has right candidate
    2724 //        CandidateCheck = OpenLines.find(FindPair[i].first->second);
    2725 //        if (CandidateCheck != OpenLines.end()) {
    2726 //          if (!CandidateCheck->second->pointlist.empty()) {
    2727 //            for (TesselPointList::const_iterator Runner = CandidateCheck->second->pointlist.begin(); Runner != CandidateCheck->second->pointlist.end(); ++Runner) {
    2728 //              Log() << Verbose(1) << "Found candidate " << *(*Runner) << " with Candidate center is " << CandidateCheck->second->OptCenter << ", desired opt center is " << CandidateLine.OptCenter << "." << endl;
    2729 //              if (((*Runner) == TPS[(i+2)%3]->node) && (CandidateLine.OptCenter == CandidateCheck->second->OptCenter)) { // seems like we found a line to connect to
    2730 //                AddExistingTesselationTriangleLine(CandidateCheck->first, i);
    2731 //                break;  // have to break as a AddExistingTesselationTriangleLine changes OpenLines
    2732 //              }
    2733 //            }
    2734 //          } else {
    2735 //            Log() << Verbose(1) << "Open line between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << " has no candidate." << endl;
    2736 //          }
    2737 //        } else {
    2738 //          Log() << Verbose(1) << "No open lines present for line between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << "." << endl;
    2739 //        }
    2740 //        if (BLS[i] == NULL) {
    2741 //          AddNewTesselationTriangleLine(TPS[(i+0)%3], TPS[(i+1)%3], i);
    2742 //        }
    2743         AddTesselationLine(&CandidateLine.OptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
    2744         break;
    2745       default:
    2746       case 2:
    2747         AddTesselationLine(&CandidateLine.OptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
    2748         break;
    2749 //        DoeLog(0) && (eLog() << Verbose(0) << "There are more than two BoundaryPointSets between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << "." << endl);
    2750 //        performCriticalExit();
    2751 //        break;
    2752     }
    2753   }
    2754 
    2755   /// 3. create the first triangle and NormalVector and so on
     2692    AddTesselationLine(&CandidateLine.OptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
     2693  }
     2694
     2695  /// 2. create the first triangle and NormalVector and so on
    27562696  Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl;
    27572697  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    27582698  AddTesselationTriangle();
    2759   // check whether triangle has been created
    2760   BTS->SetTopNode(CandidateLine.T);
    2761   if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
    2762     BTS->AngleFromTop = CandidateLine.ShortestAngle;
    2763   else
    2764     BTS->AngleFromTop = -1.;
     2699
    27652700  // create normal vector
    27662701  BTS->GetCenter(&Center);
     
    27752710  triangle = BTS;
    27762711
    2777   /// 4. Gather candidates for each new line
     2712  /// 3. Gather candidates for each new line
    27782713  Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl;
    27792714  for (int i=0;i<3;i++) {
     
    27872722  }
    27882723
    2789   /// 5. Create or pick the lines for the second triangle
     2724  /// 4. Create or pick the lines for the second triangle
    27902725  Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl;
    27912726  for (int i=0;i<3;i++) {
    27922727    Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
    2793     switch (count[i]) {
    2794       case 0:
    2795         AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
    2796         break;
    2797       case 1:
    2798 //        // check whether present line has right candidate
    2799 //        CandidateCheck = OpenLines.find(BLS[i]);
    2800 //        BLS[i] = NULL;
    2801 //        if (CandidateCheck == OpenLines.end()) {  // first triangle has closed present line
    2802 //          AddNewTesselationTriangleLine(TPS[(i+0)%3], TPS[(i+1)%3], i);
    2803 //        } else {
    2804 //          for (TesselPointList::const_iterator Runner = CandidateCheck->second->pointlist.begin(); Runner != CandidateCheck->second->pointlist.end(); ++Runner) {
    2805 //            Log() << Verbose(1) << "Found candidate " << *(*Runner) << " with Candidate center is " << CandidateCheck->second->OptCenter << ", desired other opt center is " << CandidateLine.OtherOptCenter << "." << endl;
    2806 //            if (((*Runner) == TPS[(i+2)%3]->node) && (CandidateLine.OtherOptCenter == CandidateCheck->second->OptCenter)) { // seems like we found a line to connect to
    2807 //              AddExistingTesselationTriangleLine(CandidateCheck->first, i);
    2808 //              break;  // have to break as a AddExistingTesselationTriangleLine changes OpenLines
    2809 //            }
    2810 //          }
    2811 //        }
    2812 //        if (BLS[i] == NULL) {
    2813 //          DoeLog(0) && (eLog() << Verbose(0) << "BoundaryLine between " << TPS[(i+0)%3] << " and " << TPS[(i+1)%3] << " has not the correct candidate, i.e. the third endpoint: " << *TPS[(i+2)%3] << endl);
    2814 //          performCriticalExit();
    2815 //        }
    2816         AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
    2817         break;
    2818       case 2:
    2819       default:
    2820         AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
    2821         break;
    2822 //        DoeLog(0) && (eLog() << Verbose(0) << "There are more than two BoundaryPointSets between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << "." << endl);
    2823 //        performCriticalExit();
    2824 //        break;
    2825     }
    2826   }
    2827 
    2828   /// 6. create the second triangle and NormalVector and so on
     2728    AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
     2729  }
     2730
     2731  /// 5. create the second triangle and NormalVector and so on
    28292732  Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl;
    28302733  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    28312734  AddTesselationTriangle();
    2832   // check whether triangle has been created
    2833   BTS->SetTopNode(CandidateLine.T);
    2834   if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
    2835     BTS->AngleFromTop = CandidateLine.ShortestAngle;
    2836   else
    2837     BTS->AngleFromTop = -1.;
     2735
    28382736  BTS->SphereCenter.CopyVector(&CandidateLine.OtherOptCenter);
    28392737  // create normal vector in other direction
     
    28462744    Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl;
    28472745
    2848   return triangle;
     2746  /// 6. Adding triangle to new lines
     2747  Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl;
     2748  for (int i=0;i<3;i++) {
     2749    Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
     2750    CandidateCheck = OpenLines.find(BLS[i]);
     2751    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     2752      if (CandidateCheck->second->T == NULL)
     2753        CandidateCheck->second->T = BTS;
     2754    }
     2755  }
    28492756};
    28502757
     
    28662773  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    28672774  AddTesselationTriangle();
    2868   // store values from tesselation procedure therein
    2869   BTS->SetTopNode(CandidateLine.T);
    2870   if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
    2871     BTS->AngleFromTop = CandidateLine.ShortestAngle;
    2872   else
    2873     BTS->AngleFromTop = -1.;
    28742775
    28752776  // create normal vector
     
    50644965        }
    50654966  }
     4967  delete(DegeneratedTriangles);
    50664968
    50674969  /// 3. Find connected endpoint candidates and put them into a polygon
  • src/tesselation.hpp

    ra26ca5 r711ac2  
    163163    bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
    164164    bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
    165     void SetTopNode(const BoundaryTriangleSet * const topnode);
    166165
    167166    class BoundaryPointSet *endpoints[3];
    168167    class BoundaryLineSet *lines[3];
    169     const BoundaryTriangleSet *top; //!< triangle was instantiated during tesselation from this triangle
    170     double AngleFromTop;
    171168    Vector NormalVector;
    172169    Vector SphereCenter;
     
    288285    void AddTesselationTriangle(const int nr);
    289286    void AddCandidateTriangle(CandidateForTesselation &CandidateLine);
    290     BoundaryTriangleSet * const AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
     287    void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
    291288    void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
    292289    void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
Note: See TracChangeset for help on using the changeset viewer.