Changeset c15ca2


Ignore:
Timestamp:
Dec 29, 2009, 2:48:49 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:
97498a
Parents:
71b20e
Message:

Changes to FindClosest...ToVector() and use of ..Map,..Set,..List defines in tesselation.cpp.

Location:
src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/analysis_correlation.cpp

    r71b20e rc15ca2  
    267267        Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
    268268        if ((type == NULL) || (Walker->type == type)) {
    269           triangle = Surface->FindClosestTriangleToPoint(Walker->node, LC );
     269          triangle = Surface->FindClosestTriangleToVector(Walker->node, LC );
    270270          if (triangle != NULL) {
    271271            distance = DistanceToTrianglePlane(Walker->node, triangle);
     
    327327                checkX.AddVector(&periodicX);
    328328                checkX.MatrixMultiplication(FullMatrix);
    329                 triangle = Surface->FindClosestTriangleToPoint(&checkX, LC );
     329                triangle = Surface->FindClosestTriangleToVector(&checkX, LC );
    330330                if (triangle != NULL) {
    331331                  distance = DistanceToTrianglePlane(&checkX, triangle);
  • src/tesselation.cpp

    r71b20e rc15ca2  
    14231423  TesselPoint *Walker = NULL;
    14241424  Vector *Center = cloud->GetCenter();
    1425   list<BoundaryTriangleSet*> *triangles = NULL;
     1425  TriangleList *triangles = NULL;
    14261426  bool AddFlag = false;
    14271427  LinkedCell *BoundaryPoints = NULL;
     
    14381438    Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;
    14391439    // get the next triangle
    1440     triangles = FindClosestTrianglesToPoint(Walker->node, BoundaryPoints);
     1440    triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
    14411441    BTS = triangles->front();
    14421442    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
     
    23392339
    23402340  // fill the set of neighbours
    2341   Center.CopyVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2342   Center.SubtractVector(TurningPoint->node);
    2343   set<TesselPoint*> SetOfNeighbours;
     2341  TesselPointSet SetOfNeighbours;
    23442342  SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
    23452343  for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
    23462344    SetOfNeighbours.insert(*Runner);
    2347   TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, &Center);
     2345  TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
    23482346
    23492347  // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
     2348  Log() << Verbose(0) << "List of Candidates for Turning Point: " << *TurningPoint << "." << endl;
     2349  for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
     2350    Log() << Verbose(0) << **TesselRunner << endl;
    23502351  TesselPointList::iterator Runner = connectedClosestPoints->begin();
    23512352  TesselPointList::iterator Sprinter = Runner;
     
    23572358    AddTesselationPoint((*Sprinter), 2);
    23582359
    2359 
    23602360    // add the lines
    23612361    AddTesselationLine(TPS[0], TPS[1], 0);
     
    23742374    Runner = Sprinter;
    23752375    Sprinter++;
     2376    Log() << Verbose(0) << "Current Runner is " << **Runner << "." << endl;
     2377    if (Sprinter != connectedClosestPoints->end())
     2378      Log() << Verbose(0) << " There are still more triangles to add." << endl;
    23762379  }
    23772380  delete(connectedClosestPoints);
     
    29582961  const BoundaryLineSet * lines[2] = { line1, line2 };
    29592962  class BoundaryPointSet *node = NULL;
    2960   map<int, class BoundaryPointSet *> OrderMap;
    2961   pair<map<int, class BoundaryPointSet *>::iterator, bool> OrderTest;
     2963  PointMap OrderMap;
     2964  PointTestPair OrderTest;
    29622965  for (int i = 0; i < 2; i++)
    29632966    // for both lines
     
    29792982};
    29802983
    2981 /** Finds the triangle that is closest to a given Vector \a *x.
     2984/** Finds the boundary points that are closest to a given Vector \a *x.
    29822985 * \param *out output stream for debugging
    29832986 * \param *x Vector to look from
    2984  * \return list of BoundaryTriangleSet of nearest triangles or NULL in degenerate case.
    2985  */
    2986 list<BoundaryTriangleSet*> * Tesselation::FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const
    2987 {
    2988         Info FunctionInfo(__func__);
     2987 * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
     2988 */
     2989DistanceMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const
     2990{
     2991  Info FunctionInfo(__func__);
    29892992  PointMap::const_iterator FindPoint;
    29902993  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
     
    30013004  Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    30023005
    3003   set<BoundaryPointSet *> points;
     3006  DistanceMap * points = new DistanceMap;
    30043007  LC->GetNeighbourBounds(Nlower, Nupper);
    30053008  //Log() << Verbose(1) << endl;
     
    30133016            FindPoint = PointsOnBoundary.find((*Runner)->nr);
    30143017            if (FindPoint != PointsOnBoundary.end())
    3015               points.insert(FindPoint->second);
     3018              points->insert(DistancePair (FindPoint->second->node->node->DistanceSquared(x), FindPoint->second) );
    30163019          }
    30173020        } else {
     
    30213024
    30223025  // check whether we found some points
    3023   if (points.empty()) {
    3024     Log() << Verbose(1) << "There is no nearest triangle, too far away from the surface." << endl;
     3026  if (points->empty()) {
     3027    eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
     3028    delete(points);
     3029    return NULL;
     3030  }
     3031  return points;
     3032};
     3033
     3034/** Finds the boundary line that is closest to a given Vector \a *x.
     3035 * \param *out output stream for debugging
     3036 * \param *x Vector to look from
     3037 * \return closest BoundaryLineSet or NULL in degenerate case.
     3038 */
     3039BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const
     3040{
     3041  Info FunctionInfo(__func__);
     3042
     3043  // get closest points
     3044  DistanceMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3045  if (points == NULL) {
     3046    eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
    30253047    return NULL;
    30263048  }
     
    30333055  Vector Center;
    30343056  Vector BaseLine;
    3035   for (set<BoundaryPointSet *>::iterator Runner = points.begin(); Runner != points.end(); Runner++) {
    3036     for (LineMap::iterator LineRunner = (*Runner)->lines.begin(); LineRunner != (*Runner)->lines.end(); LineRunner++) {
     3057  for (DistanceMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
     3058    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    30373059      // calculate closest point on line to desired point
    30383060      helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     
    30673089    }
    30683090  }
     3091  delete(points);
    30693092  // check whether closest line is "too close" :), then it's inside
    30703093  if (ClosestLine == NULL) {
     
    30723095    return NULL;
    30733096  }
    3074   list<BoundaryTriangleSet*> *triangles = new list<BoundaryTriangleSet*>;
     3097  return ClosestLine;
     3098};
     3099
     3100
     3101/** Finds the triangle that is closest to a given Vector \a *x.
     3102 * \param *out output stream for debugging
     3103 * \param *x Vector to look from
     3104 * \return BoundaryTriangleSet of nearest triangle or NULL.
     3105 */
     3106TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
     3107{
     3108        Info FunctionInfo(__func__);
     3109
     3110        // get closest points
     3111        DistanceMap * points = FindClosestBoundaryPointsToVector(x,LC);
     3112  if (points == NULL) {
     3113    eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
     3114    return NULL;
     3115  }
     3116
     3117  // for each point, check its lines, remember closest
     3118  Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl;
     3119  BoundaryLineSet *ClosestLine = NULL;
     3120  double MinDistance = -1.;
     3121  Vector helper;
     3122  Vector Center;
     3123  Vector BaseLine;
     3124  for (DistanceMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
     3125    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
     3126      for (TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++) {
     3127        // calculate closest point on line to desired point
     3128        helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     3129        helper.AddVector((LineRunner->second)->endpoints[1]->node->node);
     3130        helper.Scale(0.5);
     3131        Center.CopyVector(x);
     3132        Center.SubtractVector(&helper);
     3133        BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     3134        BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3135        Center.ProjectOntoPlane(&BaseLine);
     3136        const double distance = Center.NormSquared();
     3137        if ((ClosestLine == NULL) || (distance < MinDistance)) {
     3138          // additionally calculate intersection on line (whether it's on the line section or not)
     3139          helper.CopyVector(x);
     3140          helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
     3141          helper.SubtractVector(&Center);
     3142          const double lengthA = helper.ScalarProduct(&BaseLine);
     3143          helper.CopyVector(x);
     3144          helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3145          helper.SubtractVector(&Center);
     3146          const double lengthB = helper.ScalarProduct(&BaseLine);
     3147          if (lengthB*lengthA < 0) {  // if have different sign
     3148            ClosestLine = LineRunner->second;
     3149            MinDistance = distance;
     3150            Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl;
     3151          } else {
     3152            Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl;
     3153          }
     3154        } else {
     3155          Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl;
     3156        }
     3157      }
     3158    }
     3159  }
     3160  delete(points);
     3161
     3162  // check whether closest line is "too close" :), then it's inside
     3163  if (ClosestLine == NULL) {
     3164    Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
     3165    return NULL;
     3166  }
     3167  TriangleList * candidates = new TriangleList;
    30753168  for (TriangleMap::iterator Runner = ClosestLine->triangles.begin(); Runner != ClosestLine->triangles.end(); Runner++) {
    3076     triangles->push_back(Runner->second);
    3077   }
    3078   return triangles;
     3169    candidates->push_back(Runner->second);
     3170  }
     3171  return candidates;
    30793172};
    30803173
     
    30853178 * \return list of BoundaryTriangleSet of nearest triangles or NULL.
    30863179 */
    3087 class BoundaryTriangleSet * Tesselation::FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const
     3180class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
    30883181{
    30893182        Info FunctionInfo(__func__);
    30903183  class BoundaryTriangleSet *result = NULL;
    3091   list<BoundaryTriangleSet*> *triangles = FindClosestTrianglesToPoint(x, LC);
    3092   list<BoundaryTriangleSet*> candidates;
     3184  TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
     3185  TriangleList candidates;
    30933186  Vector Center;
    30943187  Vector helper;
     
    30993192  // reject all which are not closest
    31003193  double MinDistance = -1.;
    3101   for (list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
     3194  for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
    31023195    (*Runner)->GetCenter(&Center);
    31033196    helper.CopyVector(x);
     
    31493242{
    31503243        Info FunctionInfo(__func__);
    3151   class BoundaryTriangleSet *result = FindClosestTriangleToPoint(&Point, LC);
     3244  class BoundaryTriangleSet *result = FindClosestTriangleToVector(&Point, LC);
    31523245  Vector Center;
    31533246  Vector helper;
     
    31973290}
    31983291
    3199 /**
    3200  * Finds the point which is second closest to the provided one.
    3201  *
    3202  * @param Point to which to find the second closest other point
    3203  * @param linked cell structure
    3204  *
    3205  * @return point which is second closest to the provided one
    3206  * @TODO Optimize me! These finds are unnecessary if we have a LC list of BoundaryPoints only!
    3207  */
    3208 TesselPoint* Tesselation::FindSecondClosestBoundaryPoint(const Vector* Point, const LinkedCell* const LC) const
    3209 {
    3210   Info FunctionInfo(__func__);
    3211   TesselPoint* closestPoint = NULL;
    3212   TesselPoint* secondClosestPoint = NULL;
    3213   double distance = 1e16;
    3214   double secondDistance = 1e16;
    3215   Vector helper;
    3216   int N[NDIM], Nlower[NDIM], Nupper[NDIM];
    3217 
    3218   LC->SetIndexToVector(Point); // ignore status as we calculate bounds below sensibly
    3219   for(int i=0;i<NDIM;i++) // store indices of this cell
    3220     N[i] = LC->n[i];
    3221   Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    3222 
    3223   LC->GetNeighbourBounds(Nlower, Nupper);
    3224   //Log() << Verbose(1) << endl;
    3225   for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    3226     for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    3227       for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    3228         const LinkedNodes *List = LC->GetCurrentCell();
    3229         //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    3230         if (List != NULL) {
    3231           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    3232             helper.CopyVector(Point);
    3233             helper.SubtractVector((*Runner)->node);
    3234             double currentNorm = helper. Norm();
    3235             if (PointsOnBoundary.find((*Runner)->nr) != PointsOnBoundary.end()) {
    3236               if (currentNorm < distance) {
    3237                 // remember second point
    3238                 secondDistance = distance;
    3239                 secondClosestPoint = closestPoint;
    3240                 // mark down new closest point
    3241                 distance = currentNorm;
    3242                 closestPoint = (*Runner);
    3243                 //Log() << Verbose(2) << "INFO: New Second Nearest Neighbour is " << *secondClosestPoint << "." << endl;
    3244               }
    3245             }
    3246           }
    3247         } else {
    3248           eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << ","
    3249             << LC->n[2] << " is invalid!" << endl;
    3250         }
    3251       }
    3252 
    3253   return secondClosestPoint;
    3254 };
    3255 
    3256 /**
    3257  * Finds the point which is closest to the provided one.
    3258  *
    3259  * @param Point to which to find the closest other point
    3260  * @param SecondPoint the second closest other point on return, NULL if none found
    3261  * @param linked cell structure
    3262  *
    3263  * @return point which is closest to the provided one, NULL if none found
    3264  * @TODO Optimize me! These finds are unnecessary if we have a LC list of BoundaryPoints only!
    3265  */
    3266 TesselPoint* Tesselation::FindClosestBoundaryPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC) const
    3267 {
    3268   Info FunctionInfo(__func__);
    3269   TesselPoint* closestPoint = NULL;
    3270   SecondPoint = NULL;
    3271   double distance = 1e16;
    3272   double secondDistance = 1e16;
    3273   Vector helper;
    3274   int N[NDIM], Nlower[NDIM], Nupper[NDIM];
    3275 
    3276   LC->SetIndexToVector(Point); // ignore status as we calculate bounds below sensibly
    3277   for(int i=0;i<NDIM;i++) // store indices of this cell
    3278     N[i] = LC->n[i];
    3279   Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    3280 
    3281   LC->GetNeighbourBounds(Nlower, Nupper);
    3282   //Log() << Verbose(1) << endl;
    3283   for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    3284     for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    3285       for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    3286         const LinkedNodes *List = LC->GetCurrentCell();
    3287         //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    3288         if (List != NULL) {
    3289           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    3290             helper.CopyVector(Point);
    3291             helper.SubtractVector((*Runner)->node);
    3292             double currentNorm = helper.NormSquared();
    3293             if (PointsOnBoundary.find((*Runner)->nr) != PointsOnBoundary.end()) {
    3294               if (currentNorm < distance) {
    3295                 secondDistance = distance;
    3296                 SecondPoint = closestPoint;
    3297                 distance = currentNorm;
    3298                 closestPoint = (*Runner);
    3299                 //Log() << Verbose(1) << "INFO: New Nearest Neighbour is " << *closestPoint << "." << endl;
    3300               } else if (currentNorm < secondDistance) {
    3301                 secondDistance = currentNorm;
    3302                 SecondPoint = (*Runner);
    3303                 //Log() << Verbose(1) << "INFO: New Second Nearest Neighbour is " << *SecondPoint << "." << endl;
    3304               }
    3305             }
    3306           }
    3307         } else {
    3308           eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
    3309         }
    3310       }
    3311   // output
    3312   if ((closestPoint != NULL) && (SecondPoint != NULL)) {
    3313     Log() << Verbose(1) << "Closest point is " << *closestPoint << " and second closest is " << *SecondPoint << "." << endl;
    3314   } else if (closestPoint != NULL) {
    3315     Log() << Verbose(1) << "Closest point is " << *closestPoint << " and second closest is " << SecondPoint << "." << endl;
    3316   } else {
    3317     Log() << Verbose(1) << "No closest point has been found, only " << closestPoint << " and " << SecondPoint << "." << endl;
    3318   }
    3319   return closestPoint;
    3320 };
    3321 
    3322 
    33233292/** Gets all points connected to the provided point by triangulation lines.
    33243293 *
     
    33273296 * @return set of the all points linked to the provided one
    33283297 */
    3329 set<TesselPoint*> * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    3330 {
    3331         Info FunctionInfo(__func__);
    3332   set<TesselPoint*> *connectedPoints = new set<TesselPoint*>;
     3298TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
     3299{
     3300        Info FunctionInfo(__func__);
     3301        TesselPointSet *connectedPoints = new TesselPointSet;
    33333302  class BoundaryPointSet *ReferencePoint = NULL;
    33343303  TesselPoint* current;
     
    33923361 * @return list of the all points linked to the provided one
    33933362 */
    3394 list<TesselPoint*> * Tesselation::GetCircleOfConnectedTriangles(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
     3363TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    33953364{
    33963365        Info FunctionInfo(__func__);
    33973366  map<double, TesselPoint*> anglesOfPoints;
    3398   list<TesselPoint*> *connectedCircle = new list<TesselPoint*>;
     3367  TesselPointList *connectedCircle = new TesselPointList;
    33993368  Vector PlaneNormal;
    34003369  Vector AngleZero;
     
    34023371  Vector helper;
    34033372  const TesselPoint * const TrianglePoints[3] = {Point, NULL, NULL};
    3404   list<BoundaryTriangleSet*> *triangles = NULL;
     3373  TriangleList *triangles = NULL;
    34053374
    34063375  if (SetOfNeighbours == NULL) {
     
    34133382  triangles = FindTriangles(TrianglePoints);
    34143383  if ((triangles != NULL) && (!triangles->empty())) {
    3415     for (list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
     3384    for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    34163385      PlaneNormal.AddVector(&(*Runner)->NormalVector);
    34173386  } else {
     
    34473416
    34483417  // go through all connected points and calculate angle
    3449   for (set<TesselPoint*>::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
     3418  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    34503419    helper.CopyVector((*listRunner)->node);
    34513420    helper.SubtractVector(Point->node);
     
    34693438 * triangle we are looking for.
    34703439 *
    3471  * @param *out output stream for debugging
    34723440 * @param *SetOfNeighbours all points for which the angle should be calculated
    34733441 * @param *Point of which get all connected points
     
    34753443 * @return list of the all points linked to the provided one
    34763444 */
    3477 list<TesselPoint*> * Tesselation::GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
     3445TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
    34783446{
    34793447  Info FunctionInfo(__func__);
    34803448  map<double, TesselPoint*> anglesOfPoints;
    3481   list<TesselPoint*> *connectedCircle = new list<TesselPoint*>;
     3449  TesselPointList *connectedCircle = new TesselPointList;
    34823450  Vector center;
    34833451  Vector PlaneNormal;
     
    34933461
    34943462  // calculate central point
    3495   for (set<TesselPoint*>::const_iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
     3463  for (TesselPointSet::const_iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
    34963464    center.AddVector((*TesselRunner)->node);
    34973465  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
     
    35303498
    35313499  // go through all connected points and calculate angle
    3532   for (set<TesselPoint*>::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
     3500  pair <map<double, TesselPoint*>::iterator, bool > InserterTest;
     3501  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    35333502    helper.CopyVector((*listRunner)->node);
    35343503    helper.SubtractVector(Point->node);
    35353504    helper.ProjectOntoPlane(&PlaneNormal);
    35363505    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    3537     Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
    3538     anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
     3506    Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl;
     3507    InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
     3508    if (!InserterTest.second) {
     3509      eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl;
     3510      performCriticalExit();
     3511    }
    35393512  }
    35403513
     
    35523525 * @return list of the all points linked to the provided one
    35533526 */
    3554 list<list<TesselPoint*> *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
     3527list< TesselPointList *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    35553528{
    35563529        Info FunctionInfo(__func__);
    35573530  map<double, TesselPoint*> anglesOfPoints;
    3558   list<list<TesselPoint*> *> *ListOfPaths = new list<list<TesselPoint*> *>;
    3559   list<TesselPoint*> *connectedPath = NULL;
     3531  list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;
     3532  TesselPointList *connectedPath = NULL;
    35603533  Vector center;
    35613534  Vector PlaneNormal;
     
    35943567      } else if (!LineRunner->second) {
    35953568        LineRunner->second = true;
    3596         connectedPath = new list<TesselPoint*>;
     3569        connectedPath = new TesselPointList;
    35973570        triangle = NULL;
    35983571        CurrentLine = runner->second;
     
    36683641 * @return list of the closed paths
    36693642 */
    3670 list<list<TesselPoint*> *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    3671 {
    3672         Info FunctionInfo(__func__);
    3673   list<list<TesselPoint*> *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    3674   list<list<TesselPoint*> *> *ListofClosedPaths = new list<list<TesselPoint*> *>;
    3675   list<TesselPoint*> *connectedPath = NULL;
    3676   list<TesselPoint*> *newPath = NULL;
     3643list<TesselPointList *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
     3644{
     3645        Info FunctionInfo(__func__);
     3646  list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
     3647  list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *>;
     3648  TesselPointList *connectedPath = NULL;
     3649  TesselPointList *newPath = NULL;
    36773650  int count = 0;
    36783651
    36793652
    3680   list<TesselPoint*>::iterator CircleRunner;
    3681   list<TesselPoint*>::iterator CircleStart;
    3682 
    3683   for(list<list<TesselPoint*> *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
     3653  TesselPointList::iterator CircleRunner;
     3654  TesselPointList::iterator CircleStart;
     3655
     3656  for(list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
    36843657    connectedPath = *ListRunner;
    36853658
     
    36903663
    36913664    // go through list, look for reappearance of starting Point and create list
    3692     list<TesselPoint*>::iterator Marker = CircleStart;
     3665    TesselPointList::iterator Marker = CircleStart;
    36933666    for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
    36943667      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    36953668        // we have a closed circle from Marker to new Marker
    36963669        Log() << Verbose(1) << count+1 << ". closed path consists of: ";
    3697         newPath = new list<TesselPoint*>;
    3698         list<TesselPoint*>::iterator CircleSprinter = Marker;
     3670        newPath = new TesselPointList;
     3671        TesselPointList::iterator CircleSprinter = Marker;
    36993672        for (; CircleSprinter != CircleRunner; CircleSprinter++) {
    37003673          newPath->push_back(*CircleSprinter);
     
    37303703 * \return pointer to allocated list of triangles
    37313704 */
    3732 set<BoundaryTriangleSet*> *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    3733 {
    3734         Info FunctionInfo(__func__);
    3735   set<BoundaryTriangleSet*> *connectedTriangles = new set<BoundaryTriangleSet*>;
     3705TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
     3706{
     3707        Info FunctionInfo(__func__);
     3708        TriangleSet *connectedTriangles = new TriangleSet;
    37363709
    37373710  if (Point == NULL) {
     
    37823755  }
    37833756
    3784   list<list<TesselPoint*> *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
    3785   list<TesselPoint*> *connectedPath = NULL;
     3757  list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
     3758  TesselPointList *connectedPath = NULL;
    37863759
    37873760  // gather all triangles
    37883761  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
    37893762    count+=LineRunner->second->triangles.size();
    3790   map<class BoundaryTriangleSet *, int> Candidates;
     3763  TriangleMap Candidates;
    37913764  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    37923765    line = LineRunner->second;
    37933766    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    37943767      triangle = TriangleRunner->second;
    3795       Candidates.insert( pair<class BoundaryTriangleSet *, int> (triangle, triangle->Nr) );
     3768      Candidates.insert( TrianglePair (triangle->Nr, triangle) );
    37963769    }
    37973770  }
     
    38003773  count=0;
    38013774  NormalVector.Zero();
    3802   for (map<class BoundaryTriangleSet *, int>::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    3803     Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
    3804     NormalVector.SubtractVector(&Runner->first->NormalVector); // has to point inward
    3805     RemoveTesselationTriangle(Runner->first);
     3775  for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
     3776    Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl;
     3777    NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
     3778    RemoveTesselationTriangle(Runner->second);
    38063779    count++;
    38073780  }
    38083781  Log() << Verbose(1) << count << " triangles were removed." << endl;
    38093782
    3810   list<list<TesselPoint*> *>::iterator ListAdvance = ListOfClosedPaths->begin();
    3811   list<list<TesselPoint*> *>::iterator ListRunner = ListAdvance;
    3812   map<class BoundaryTriangleSet *, int>::iterator NumberRunner = Candidates.begin();
    3813   list<TesselPoint*>::iterator StartNode, MiddleNode, EndNode;
     3783  list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
     3784  list<TesselPointList *>::iterator ListRunner = ListAdvance;
     3785  TriangleMap::iterator NumberRunner = Candidates.begin();
     3786  TesselPointList::iterator StartNode, MiddleNode, EndNode;
    38143787  double angle;
    38153788  double smallestangle;
     
    38253798
    38263799      // re-create all triangles by going through connected points list
    3827       list<class BoundaryLineSet *> NewLines;
     3800      LineList NewLines;
    38283801      for (;!connectedPath->empty();) {
    38293802        // search middle node with widest angle to next neighbours
     
    39313904      // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
    39323905      if (NewLines.size() > 1) {
    3933         list<class BoundaryLineSet *>::iterator Candidate;
     3906        LineList::iterator Candidate;
    39343907        class BoundaryLineSet *OtherBase = NULL;
    39353908        double tmp, maxgain;
    39363909        do {
    39373910          maxgain = 0;
    3938           for(list<class BoundaryLineSet *>::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
     3911          for(LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
    39393912            tmp = PickFarthestofTwoBaselines(*Runner);
    39403913            if (maxgain < tmp) {
     
    39833956 *         will usually be one, in case of degeneration, there will be two
    39843957 */
    3985 list<BoundaryTriangleSet*> *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    3986 {
    3987         Info FunctionInfo(__func__);
    3988   list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;
     3958TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
     3959{
     3960        Info FunctionInfo(__func__);
     3961        TriangleList *result = new TriangleList;
    39893962  LineMap::const_iterator FindLine;
    39903963  TriangleMap::const_iterator FindTriangle;
     
    41144087 *         in the list, once as key and once as value
    41154088 */
    4116 map<int, int> * Tesselation::FindAllDegeneratedLines()
     4089IndexToIndex * Tesselation::FindAllDegeneratedLines()
    41174090{
    41184091        Info FunctionInfo(__func__);
    41194092        UniqueLines AllLines;
    4120   map<int, int> * DegeneratedLines = new map<int, int>;
     4093  IndexToIndex * DegeneratedLines = new IndexToIndex;
    41214094
    41224095  // sanity check
     
    41394112
    41404113  Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
    4141   map<int,int>::iterator it;
     4114  IndexToIndex::iterator it;
    41424115  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
    41434116    const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
     
    41584131 *         in the list, once as key and once as value
    41594132 */
    4160 map<int, int> * Tesselation::FindAllDegeneratedTriangles()
    4161 {
    4162         Info FunctionInfo(__func__);
    4163   map<int, int> * DegeneratedLines = FindAllDegeneratedLines();
    4164   map<int, int> * DegeneratedTriangles = new map<int, int>;
     4133IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
     4134{
     4135        Info FunctionInfo(__func__);
     4136  IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
     4137  IndexToIndex * DegeneratedTriangles = new IndexToIndex;
    41654138
    41664139  TriangleMap::iterator TriangleRunner1, TriangleRunner2;
     
    41684141  class BoundaryLineSet *line1 = NULL, *line2 = NULL;
    41694142
    4170   for (map<int, int>::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
     4143  for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
    41714144    // run over both lines' triangles
    41724145    Liner = LinesOnBoundary.find(LineRunner->first);
     
    41894162
    41904163  Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
    4191   map<int,int>::iterator it;
     4164  IndexToIndex::iterator it;
    41924165  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    41934166      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
     
    42034176{
    42044177        Info FunctionInfo(__func__);
    4205   map<int, int> * DegeneratedTriangles = FindAllDegeneratedTriangles();
     4178  IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
    42064179  TriangleMap::iterator finder;
    42074180  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    42084181  int count  = 0;
    42094182
    4210   for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
     4183  for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
    42114184    TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
    42124185  ) {
     
    44634436
    44644437  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
    4465   map <int, int> *DegeneratedTriangles = FindAllDegeneratedTriangles();
     4438  IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
    44664439  set < BoundaryPointSet *> EndpointCandidateList;
    44674440  pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
     
    46154588  }
    46164589
    4617   map<int, int> * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
     4590  IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
    46184591  Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
    4619   map<int,int>::iterator it;
     4592  IndexToIndex::iterator it;
    46204593  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
    46214594      Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
  • src/tesselation.hpp

    r71b20e rc15ca2  
    5252// ======================================================= some template functions =========================================
    5353
     54#define IndexToIndex map <int, int>
     55
    5456#define PointMap map < int, class BoundaryPointSet * >
    5557#define PointSet set < class BoundaryPointSet * >
     
    7678#define PolygonSet set < class BoundaryPolygonSet * >
    7779#define PolygonList list < class BoundaryPolygonSet * >
     80
     81#define DistanceMap multimap <double, class BoundaryPointSet * >
     82#define DistancePair pair <double, class BoundaryPointSet * >
    7883
    7984#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
     
    310315    bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC, const double epsilon = -MYEPSILON) const;
    311316    bool AddBoundaryPoint(TesselPoint * Walker, const int n);
    312     TesselPoint* FindSecondClosestBoundaryPoint(const Vector* Point, const LinkedCell* const LC) const;
    313     TesselPoint* FindClosestBoundaryPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC) const;
     317    DistanceMap * FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const;
     318    BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const;
     319    TriangleList * FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const;
     320    BoundaryTriangleSet* FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const;
    314321
    315322    // print for debugging
  • src/unittests/Makefile.am

    r71b20e rc15ca2  
    44AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
    55
    6 TESTS = ActOnAllUnitTest AnalysisBondsUnitTests AnalysisCorrelationToPointUnitTest AnalysisCorrelationToSurfaceUnitTest AnalysisPairCorrelationUnitTest BondGraphUnitTest InfoUnitTest ListOfBondsUnitTest LogUnitTest MemoryUsageObserverUnitTest MemoryAllocatorUnitTest StackClassUnitTest VectorUnitTest
     6TESTS = ActOnAllUnitTest AnalysisBondsUnitTests AnalysisCorrelationToPointUnitTest AnalysisCorrelationToSurfaceUnitTest AnalysisPairCorrelationUnitTest BondGraphUnitTest InfoUnitTest ListOfBondsUnitTest LogUnitTest MemoryUsageObserverUnitTest MemoryAllocatorUnitTest StackClassUnitTest TesselationUnitTest TesselationInOutsideUnitTest VectorUnitTest
    77check_PROGRAMS = $(TESTS)
    88noinst_PROGRAMS = $(TESTS)
     
    4444StackClassUnitTest_LDADD = ../libmolecuilder.a
    4545
     46TesselationUnitTest_SOURCES = tesselationunittest.cpp tesselationunittest.hpp
     47TesselationUnitTest_LDADD = ../libmolecuilder.a
     48
     49TesselationInOutsideUnitTest_SOURCES = tesselation_insideoutsideunittest.cpp tesselation_insideoutsideunittest.hpp
     50TesselationInOutsideUnitTest_LDADD = ../libmolecuilder.a
     51
    4652VectorUnitTest_SOURCES = vectorunittest.cpp vectorunittest.hpp
    4753VectorUnitTest_LDADD = ../libmolecuilder.a
  • src/unittests/tesselationunittest.cpp

    r71b20e rc15ca2  
    3030  class TesselPoint *Walker;
    3131  Walker = new TesselPoint;
    32   Walker->node = new Vector(1., 0., 0.);
    33   Walker->Name = new char[3];
     32  Walker->node = new Vector(1., 0., -1.);
     33  Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
    3434  strcpy(Walker->Name, "1");
    3535  Walker->nr = 1;
    3636  Corners.push_back(Walker);
    3737  Walker = new TesselPoint;
    38   Walker->node = new Vector(-1., 1., 0.);
    39   Walker->Name = new char[3];
     38  Walker->node = new Vector(-1., 1., -1.);
     39  Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
    4040  strcpy(Walker->Name, "2");
    4141  Walker->nr = 2;
    4242  Corners.push_back(Walker);
    4343  Walker = new TesselPoint;
    44   Walker->node = new Vector(-1., -1., 0.);
    45   Walker->Name = new char[3];
     44  Walker->node = new Vector(-1., -1., -1.);
     45  Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
    4646  strcpy(Walker->Name, "3");
    4747  Walker->nr = 3;
     
    4949  Walker = new TesselPoint;
    5050  Walker->node = new Vector(-1., 0., 1.);
    51   Walker->Name = new char[3];
     51  Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
    5252  strcpy(Walker->Name, "4");
    5353  Walker->nr = 4;
     
    5959  // create tesselation
    6060  TesselStruct = new Tesselation;
    61   TesselStruct->PointsOnBoundary.clear();
    62   TesselStruct->LinesOnBoundary.clear();
    63   TesselStruct->TrianglesOnBoundary.clear();
     61  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
     62  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
     63  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
    6464  TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
    65   bool flag = false;
    6665
    67   LineMap::iterator baseline = TesselStruct->LinesOnBoundary.begin();
    68   while (baseline != TesselStruct->LinesOnBoundary.end()) {
    69     if (baseline->second->triangles.size() == 1) {
    70       flag = TesselStruct->FindNextSuitableTriangle(*(baseline->second), *(((baseline->second->triangles.begin()))->second), SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
     66  CandidateForTesselation *baseline = NULL;
     67  BoundaryTriangleSet *T = NULL;
     68  bool OneLoopWithoutSuccessFlag = true;
     69  bool TesselationFailFlag = false;
     70  while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
     71    // 2a. fill all new OpenLines
     72    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
     73      baseline = Runner->second;
     74      if (baseline->pointlist.empty()) {
     75        T = (((baseline->BaseLine->triangles.begin()))->second);
     76        TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
     77      }
    7178    }
    72     baseline++;
    73     if ((baseline == TesselStruct->LinesOnBoundary.end()) && (flag)) {
    74       baseline = TesselStruct->LinesOnBoundary.begin();   // restart if we reach end due to newly inserted lines
    75       flag = false;
     79
     80    // 2b. search for smallest ShortestAngle among all candidates
     81    double ShortestAngle = 4.*M_PI;
     82    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
     83      if (Runner->second->ShortestAngle < ShortestAngle) {
     84        baseline = Runner->second;
     85        ShortestAngle = baseline->ShortestAngle;
     86      }
     87    }
     88    if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
     89      OneLoopWithoutSuccessFlag = false;
     90    else {
     91      TesselStruct->AddCandidateTriangle(*baseline);
    7692    }
    7793  }
     
    84100  delete(TesselStruct);
    85101  for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
    86     delete[]((*Runner)->Name);
    87102    delete((*Runner)->node);
    88103    delete(*Runner);
    89104  }
    90105  Corners.clear();
    91 };
    92 
    93 /** UnitTest for Tesselation::IsInnerPoint()
    94  */
    95 void TesselationTest::IsInnerPointTest()
    96 {
    97   // true inside points
    98   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.,0.), LinkedList) );
    99   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.5,0.,0.), LinkedList) );
    100   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.5,0.), LinkedList) );
    101   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.,0.5), LinkedList) );
    102 
    103   // corners
    104   for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
    105     CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((*Runner), LinkedList) );
    106 
    107   // true outside points
    108   CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(0.,5.,0.), LinkedList) );
    109   CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(0.,0.,5.), LinkedList) );
    110   CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(1.,1.,1.), LinkedList) );
    111 
    112   // tricky point, there are three equally close triangles
    113   CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(5.,0.,0.), LinkedList) );
    114 
     106  MemoryUsageObserver::purgeInstance();
     107  logger::purgeInstance();
     108  errorLogger::purgeInstance();
    115109};
    116110
  • src/unittests/tesselationunittest.hpp

    r71b20e rc15ca2  
    2121{
    2222    CPPUNIT_TEST_SUITE( TesselationTest) ;
    23     CPPUNIT_TEST ( IsInnerPointTest );
    2423    CPPUNIT_TEST ( GetAllTrianglesTest );
    2524    CPPUNIT_TEST ( ContainmentTest );
     
    2928      void setUp();
    3029      void tearDown();
    31       void IsInnerPointTest();
    3230      void GetAllTrianglesTest();
    3331      void ContainmentTest();
Note: See TracChangeset for help on using the changeset viewer.