Changeset b998c3 for src


Ignore:
Timestamp:
Dec 16, 2009, 11:53:06 AM (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:
009e37b
Parents:
5e8f82
Message:

Fix attempts of the Tesselation.

One problem still remains:

  • degenerated triangles are created more than two times.

The following has been changed:

Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/bondgraph.cpp

    r5e8f82 rb998c3  
    3535/** Parses the bond lengths in a given file and puts them int a matrix form.
    3636 * Allocates \a MatrixContainer for BondGraph::BondLengthMatrix, using MatrixContainer::ParseMatrix(),
    37  * but only if parsing is successfull. Otherwise variable is left as NULL.
     37 * but only if parsing is successful. Otherwise variable is left as NULL.
    3838 * \param *out output stream for debugging
    3939 * \param filename file with bond lengths to parse
  • src/boundary.cpp

    r5e8f82 rb998c3  
    10411041//  TesselStruct->RemoveDegeneratedTriangles();
    10421042
     1043  // check envelope for consistency
     1044  status = CheckListOfBaselines(TesselStruct);
     1045
     1046  // store before correction
     1047  StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
     1048
    10431049  // correct degenerated polygons
    10441050  TesselStruct->CorrectAllDegeneratedPolygons();
  • src/boundary.hpp

    r5e8f82 rb998c3  
    3636#define DEBUG 1
    3737#define DoSingleStepOutput 0
    38 #define SingleStepWidth 1
     38#define SingleStepWidth 10
    3939
    4040#define DistancePair pair < double, atom* >
  • src/tesselation.cpp

    r5e8f82 rb998c3  
    879879CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
    880880    BaseLine(line),
     881    IsDegenerated(false),
    881882    ShortestAngle(2.*M_PI),
    882883    OtherShortestAngle(2.*M_PI)
     
    15871588  bool insertNewLine = true;
    15881589
    1589   if (a->lines.find(b->node->nr) != a->lines.end()) {
    1590     LineMap::iterator FindLine = a->lines.find(b->node->nr);
     1590  LineMap::iterator FindLine = a->lines.find(b->node->nr);
     1591  if (FindLine != a->lines.end()) {
     1592    Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
     1593
    15911594    pair<LineMap::iterator,LineMap::iterator> FindPair;
    15921595    FindPair = a->lines.equal_range(b->node->nr);
    1593     Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
    15941596
    15951597    for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     
    19151917  double maxCoordinate[NDIM];
    19161918  BoundaryLineSet BaseLine;
    1917   Vector Oben;
    19181919  Vector helper;
    19191920  Vector Chord;
    19201921  Vector SearchDirection;
    1921 
    1922   Oben.Zero();
     1922  Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     1923  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
     1924  Vector SphereCenter;
     1925  Vector NormalVector;
     1926
     1927  NormalVector.Zero();
    19231928
    19241929  for (i = 0; i < 3; i++) {
     
    19551960  BTS = NULL;
    19561961  for (int k=0;k<NDIM;k++) {
    1957     Oben.Zero();
    1958     Oben.x[k] = 1.;
     1962    NormalVector.Zero();
     1963    NormalVector.x[k] = 1.;
    19591964    BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
    19601965    Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
     
    19631968    ShortestAngle = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
    19641969
    1965     FindSecondPointForTesselation(BaseLine.endpoints[0]->node, Oben, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
     1970    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_...
    19661971    if (Temporary == NULL)  // have we found a second point?
    19671972      continue;
    19681973    BaseLine.endpoints[1] = new BoundaryPointSet(Temporary);
    19691974
    1970     helper.CopyVector(BaseLine.endpoints[0]->node->node);
    1971     helper.SubtractVector(BaseLine.endpoints[1]->node->node);
    1972     helper.Normalize();
    1973     Oben.ProjectOntoPlane(&helper);
    1974     Oben.Normalize();
    1975     helper.VectorProduct(&Oben);
     1975    // construct center of circle
     1976    CircleCenter.CopyVector(BaseLine.endpoints[0]->node->node);
     1977    CircleCenter.AddVector(BaseLine.endpoints[1]->node->node);
     1978    CircleCenter.Scale(0.5);
     1979
     1980    // construct normal vector of circle
     1981    CirclePlaneNormal.CopyVector(BaseLine.endpoints[0]->node->node);
     1982    CirclePlaneNormal.SubtractVector(BaseLine.endpoints[1]->node->node);
     1983
     1984    double radius = CirclePlaneNormal.NormSquared();
     1985    double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
     1986
     1987    NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
     1988    NormalVector.Normalize();
    19761989    ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    19771990
    1978     Chord.CopyVector(BaseLine.endpoints[0]->node->node); // bring into calling function
    1979     Chord.SubtractVector(BaseLine.endpoints[1]->node->node);
    1980     double radius = Chord.ScalarProduct(&Chord);
    1981     double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
    1982     helper.CopyVector(&Oben);
    1983     helper.Scale(CircleRadius);
    1984     // Now, oben and helper are two orthonormalized vectors in the plane defined by Chord (not normalized)
     1991    SphereCenter.CopyVector(&NormalVector);
     1992    SphereCenter.Scale(CircleRadius);
     1993    SphereCenter.AddVector(&CircleCenter);
     1994    // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
    19851995
    19861996    // look in one direction of baseline for initial candidate
    1987     SearchDirection.MakeNormalVector(&Chord, &Oben);  // whether we look "left" first or "right" first is not important ...
     1997    SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector);  // whether we look "left" first or "right" first is not important ...
    19881998
    19891999    // adding point 1 and point 2 and add the line between them
     
    19932003    //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
    19942004    CandidateForTesselation OptCandidates(&BaseLine);
    1995     FindThirdPointForTesselation(Oben, SearchDirection, helper, OptCandidates, NULL, RADIUS, LC);
     2005    FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
    19962006    Log() << Verbose(0) << "List of third Points is:" << endl;
    19972007    for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
     
    21672177  Vector CircleCenter;
    21682178  Vector CirclePlaneNormal;
    2169   Vector OldSphereCenter;
     2179  Vector RelativeSphereCenter;
    21702180  Vector SearchDirection;
    21712181  Vector helper;
     
    21742184  double radius, CircleRadius;
    21752185
    2176   Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " of triangle " << T << "." << endl;
    21772186  for (int i=0;i<3;i++)
    2178     if ((T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[0]->node) && (T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[1]->node))
     2187    if ((T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[0]->node) && (T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[1]->node)) {
    21792188      ThirdNode = T.endpoints[i]->node;
     2189      break;
     2190    }
     2191  Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdNode " << *ThirdNode << " of triangle " << T << "." << endl;
    21802192
    21812193  // construct center of circle
     
    21912203  radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    21922204  if (radius/4. < RADIUS*RADIUS) {
     2205    // construct relative sphere center with now known CircleCenter
     2206    RelativeSphereCenter.CopyVector(&T.SphereCenter);
     2207    RelativeSphereCenter.SubtractVector(&CircleCenter);
     2208
    21932209    CircleRadius = RADIUS*RADIUS - radius/4.;
    21942210    CirclePlaneNormal.Normalize();
    21952211    Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    21962212
    2197     // construct old center
    2198     GetCenterofCircumcircle(&OldSphereCenter, *T.endpoints[0]->node->node, *T.endpoints[1]->node->node, *T.endpoints[2]->node->node);
    2199     helper.CopyVector(&T.NormalVector);  // normal vector ensures that this is correct center of the two possible ones
    2200     radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
    2201     helper.Scale(sqrt(RADIUS*RADIUS - radius));
    2202     OldSphereCenter.AddVector(&helper);
    2203     OldSphereCenter.SubtractVector(&CircleCenter);
    2204     Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
    2205 
    2206     // construct SearchDirection
    2207     SearchDirection.MakeNormalVector(&T.NormalVector, &CirclePlaneNormal);
    2208     helper.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     2213    Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl;
     2214
     2215    // construct SearchDirection and an "outward pointer"
     2216    SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
     2217    helper.CopyVector(&CircleCenter);
    22092218    helper.SubtractVector(ThirdNode->node);
    22102219    if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    22112220      SearchDirection.Scale(-1.);
    2212     SearchDirection.ProjectOntoPlane(&OldSphereCenter);
    2213     SearchDirection.Normalize();
    22142221    Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2215     if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     2222    if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    22162223      // rotated the wrong way!
    22172224      eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     
    22192226
    22202227    // add third point
    2221     FindThirdPointForTesselation(T.NormalVector, SearchDirection, OldSphereCenter, CandidateLine, ThirdNode, RADIUS, LC);
     2228    FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdNode, RADIUS, LC);
    22222229
    22232230  } else {
     
    23502357    AddTesselationPoint((*Sprinter), 2);
    23512358
    2352     Center.CopyVector(&CandidateLine.OptCenter);
     2359
    23532360    // add the lines
    23542361    AddTesselationLine(TPS[0], TPS[1], 0);
     
    23592366    BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    23602367    AddTesselationTriangle();
    2361     Center.Scale(-1.);
     2368    BTS->GetCenter(&Center);
     2369    Center.SubtractVector(&CandidateLine.OptCenter);
     2370    BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
    23622371    BTS->GetNormalVector(Center);
    23632372
     
    27662775  Vector NewNormalVector;   // normal vector of the Candidate's triangle
    27672776  Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
     2777  Vector RelativeOldSphereCenter;
     2778  Vector NewPlaneCenter;
    27682779  double CircleRadius; // radius of this circle
    27692780  double radius;
     2781  double otherradius;
    27702782  double alpha, Otheralpha; // angles (i.e. parameter for the circle).
     2783  bool IsDegenerated;
    27712784  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
    27722785  TesselPoint *Candidate = NULL;
     2786  TesselPoint *CandidateTriangle[3];
    27732787
    27742788  Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
     
    27832797  CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    27842798
     2799  RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
     2800  RelativeOldSphereCenter.SubtractVector(&CircleCenter);
     2801
     2802  CandidateTriangle[0] = CandidateLine.BaseLine->endpoints[0]->node;
     2803  CandidateTriangle[1] = CandidateLine.BaseLine->endpoints[1]->node;
     2804
    27852805  // calculate squared radius TesselPoint *ThirdNode,f circle
    2786   radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    2787   if (radius/4. < RADIUS*RADIUS) {
    2788     CircleRadius = RADIUS*RADIUS - radius/4.;
     2806  radius = CirclePlaneNormal.NormSquared()/4.;
     2807  if (radius < RADIUS*RADIUS) {
     2808    CircleRadius = RADIUS*RADIUS - radius;
    27892809    CirclePlaneNormal.Normalize();
    2790     //Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     2810    Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    27912811
    27922812    // test whether old center is on the band's plane
    2793     if (fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    2794       eLog() << Verbose(1) << "Something's very wrong here: OldSphereCenter is not on the band's plane as desired by " << fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
    2795       OldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
    2796     }
    2797     radius = OldSphereCenter.ScalarProduct(&OldSphereCenter);
     2813    if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
     2814      eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
     2815      RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
     2816    }
     2817    radius = RelativeOldSphereCenter.NormSquared();
    27982818    if (fabs(radius - CircleRadius) < HULLEPSILON) {
    2799       //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
     2819      Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl;
    28002820
    28012821      // check SearchDirection
    2802       //Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2803       if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {  // rotated the wrong way!
     2822      Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2823      if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {  // rotated the wrong way!
    28042824        eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl;
    28052825      }
     
    28322852
    28332853                // check for three unique points
    2834                 Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " at " << *(Candidate->node) << "." << endl;
     2854                Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl;
    28352855                if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node) ){
    28362856
    2837                   // construct both new centers
    2838                   GetCenterofCircumcircle(&NewSphereCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
    2839                   OtherNewSphereCenter.CopyVector(&NewSphereCenter);
     2857                  // find center on the plane
     2858                  GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
     2859                  Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl;
    28402860
    28412861                  if ((NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node))
    2842                   && (fabs(NewNormalVector.ScalarProduct(&NewNormalVector)) > HULLEPSILON)
     2862                  && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)
    28432863                  ) {
    2844                     helper.CopyVector(&NewNormalVector);
    28452864                    Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
    2846                     radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewSphereCenter);
     2865                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
     2866                    Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     2867                    Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2868                    Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl;
    28472869                    if (radius < RADIUS*RADIUS) {
     2870                      otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
     2871                      if (fabs(radius - otherradius) > HULLEPSILON) {
     2872                        eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl;
     2873                      }
     2874                      // construct both new centers
     2875                      NewSphereCenter.CopyVector(&NewPlaneCenter);
     2876                      OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
     2877                      helper.CopyVector(&NewNormalVector);
    28482878                      helper.Scale(sqrt(RADIUS*RADIUS - radius));
    2849                       Log() << Verbose(2) << "INFO: Distance of NewCircleCenter to NewSphereCenter is " << helper.Norm() << " with sphere radius " << RADIUS << "." << endl;
     2879                      Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl;
    28502880                      NewSphereCenter.AddVector(&helper);
    2851                       NewSphereCenter.SubtractVector(&CircleCenter);
    28522881                      Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
    2853 
    28542882                      // OtherNewSphereCenter is created by the same vector just in the other direction
    28552883                      helper.Scale(-1.);
    28562884                      OtherNewSphereCenter.AddVector(&helper);
    2857                       OtherNewSphereCenter.SubtractVector(&CircleCenter);
    28582885                      Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
    28592886
     
    28612888                      Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    28622889                      alpha = min(alpha, Otheralpha);
    2863                       // if there is a better candidate, drop the current list and add the new candidate
    2864                       // otherwise ignore the new candidate and keep the list
    2865                       if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
    2866                         if (fabs(alpha - Otheralpha) > MYEPSILON) {
    2867                           CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
    2868                           CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     2890
     2891                      CandidateTriangle[2] = Candidate;
     2892                      // the idea of the IsDegenerated flag is not to put a penalty on degenerated triangles, but to push them to the
     2893                      // very end of the Tesselation::OpenLines list.
     2894                      IsDegenerated = (CheckPresenceOfTriangle(CandidateTriangle) >= 3);
     2895                      if (!IsDegenerated && CandidateLine.IsDegenerated) {  // if current is not, but old one was, comparison would be unfair
     2896                        // if there is a better candidate, drop the current list and add the new candidate
     2897                        // otherwise ignore the new candidate and keep the list
     2898                        if (CandidateLine.ShortestAngle-2.*M_PI > (alpha - HULLEPSILON)) {
     2899                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
     2900                            CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
     2901                            CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     2902                          } else {
     2903                            CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
     2904                            CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     2905                          }
     2906                          // if there is an equal candidate, add it to the list without clearing the list
     2907                          if ((CandidateLine.ShortestAngle-2.*M_PI - HULLEPSILON) < alpha) {
     2908                            CandidateLine.pointlist.push_back(Candidate);
     2909                            Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
     2910                              << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2911                          } else {
     2912                            // remove all candidates from the list and then the list itself
     2913                            CandidateLine.pointlist.clear();
     2914                            CandidateLine.pointlist.push_back(Candidate);
     2915                            Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
     2916                              << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2917                          }
     2918                          CandidateLine.ShortestAngle = alpha;
     2919                          CandidateLine.IsDegenerated = IsDegenerated;
     2920                          if (IsDegenerated)
     2921                            CandidateLine.ShortestAngle += 2.*M_PI;
     2922                          Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
    28692923                        } else {
    2870                           CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
    2871                           CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     2924                          if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
     2925                            Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
     2926                          } else {
     2927                            Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
     2928                          }
    28722929                        }
    2873                         // if there is an equal candidate, add it to the list without clearing the list
    2874                         if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
    2875                           CandidateLine.pointlist.push_back(Candidate);
    2876                           Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
    2877                             << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2930                      } else {
     2931                        // if there is a better candidate, drop the current list and add the new candidate
     2932                        // otherwise ignore the new candidate and keep the list
     2933                        if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
     2934                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
     2935                            CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
     2936                            CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     2937                          } else {
     2938                            CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
     2939                            CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     2940                          }
     2941                          // if there is an equal candidate, add it to the list without clearing the list
     2942                          if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
     2943                            CandidateLine.pointlist.push_back(Candidate);
     2944                            Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
     2945                              << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2946                          } else {
     2947                            // remove all candidates from the list and then the list itself
     2948                            CandidateLine.pointlist.clear();
     2949                            CandidateLine.pointlist.push_back(Candidate);
     2950                            Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
     2951                              << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
     2952                          }
     2953                          CandidateLine.ShortestAngle = alpha;
     2954                          Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
    28782955                        } else {
    2879                           // remove all candidates from the list and then the list itself
    2880                           CandidateLine.pointlist.clear();
    2881                           CandidateLine.pointlist.push_back(Candidate);
    2882                           Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
    2883                             << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
    2884                         }
    2885                         CandidateLine.ShortestAngle = alpha;
    2886                         Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
    2887                       } else {
    2888                         if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
    2889                           Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
    2890                         } else {
    2891                           Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
     2956                          if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
     2957                            Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
     2958                          } else {
     2959                            Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
     2960                          }
    28922961                        }
    28932962                      }
     
    41284197
    41294198  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
     4199  map <int, int> *DegeneratedTriangles = FindAllDegeneratedTriangles();
    41304200  set < BoundaryPointSet *> EndpointCandidateList;
    41314201  pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
     
    41384208    for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
    41394209      for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    4140         TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) );
    4141         if (TriangleInsertionTester.second)
    4142           Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;
     4210        if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
     4211          TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) );
     4212          if (TriangleInsertionTester.second)
     4213            Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;
     4214        } else {
     4215          Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl;
     4216        }
    41434217      }
    41444218    // check whether there are two that are parallel
     
    42134287    /// 4a. Gather all triangles of this polygon
    42144288    TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
     4289
     4290    if (T->size() == 2) {
     4291      Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl;
     4292      delete(T);
     4293      continue;
     4294    }
    42154295
    42164296    TriangleSet::iterator TriangleWalker = T->begin();  // is the inner iterator
  • src/tesselation.hpp

    r5e8f82 rb998c3  
    158158    class BoundaryLineSet *lines[3];
    159159    Vector NormalVector;
     160    Vector SphereCenter;
    160161    int Nr;
    161162};
     
    245246  Vector OptCenter;
    246247  Vector OtherOptCenter;
     248  bool IsDegenerated;
    247249  double ShortestAngle;
    248250  double OtherShortestAngle;
  • src/tesselationhelpers.cpp

    r5e8f82 rb998c3  
    226226  Vector helper;
    227227  double radius, alpha;
    228 
    229   helper.CopyVector(&NewSphereCenter);
     228  Vector RelativeOldSphereCenter;
     229  Vector RelativeNewSphereCenter;
     230
     231  RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
     232  RelativeOldSphereCenter.SubtractVector(&CircleCenter);
     233  RelativeNewSphereCenter.CopyVector(&NewSphereCenter);
     234  RelativeNewSphereCenter.SubtractVector(&CircleCenter);
     235  helper.CopyVector(&RelativeNewSphereCenter);
    230236  // test whether new center is on the parameter circle's plane
    231237  if (fabs(helper.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
     
    233239    helper.ProjectOntoPlane(&CirclePlaneNormal);
    234240  }
    235   radius = helper.ScalarProduct(&helper);
     241  radius = helper.NormSquared();
    236242  // test whether the new center vector has length of CircleRadius
    237243  if (fabs(radius - CircleRadius) > HULLEPSILON)
    238244    eLog() << Verbose(1) << "The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;
    239   alpha = helper.Angle(&OldSphereCenter);
     245  alpha = helper.Angle(&RelativeOldSphereCenter);
    240246  // make the angle unique by checking the halfplanes/search direction
    241247  if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)  // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals
    242248    alpha = 2.*M_PI - alpha;
    243   //Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << OldSphereCenter << " and resulting angle is " << alpha << "." << endl;
    244   radius = helper.Distance(&OldSphereCenter);
     249  Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << RelativeOldSphereCenter << " and resulting angle is " << alpha << "." << endl;
     250  radius = helper.Distance(&RelativeOldSphereCenter);
    245251  helper.ProjectOntoPlane(&NormalVector);
    246252  // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles
    247253  if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) {
    248     //Log() << Verbose(1) << "INFO: Distance between old and new center is " << radius << " and between new center and baseline center is " << helper.Norm() << "." << endl;
     254    Log() << Verbose(1) << "INFO: Distance between old and new center is " << radius << " and between new center and baseline center is " << helper.Norm() << "." << endl;
    249255    return alpha;
    250256  } else {
    251     //Log() << Verbose(1) << "INFO: NewSphereCenter " << helper << " is too close to OldSphereCenter" << OldSphereCenter << "." << endl;
     257    Log() << Verbose(1) << "INFO: NewSphereCenter " << RelativeNewSphereCenter << " is too close to RelativeOldSphereCenter" << RelativeOldSphereCenter << "." << endl;
    252258    return 2.*M_PI;
    253259  }
  • src/vector.cpp

    r5e8f82 rb998c3  
    480480  else
    481481    return false;
     482};
     483
     484/** Checks whether vector is normal to \a *normal.
     485 * @return true - vector is normalized, false - vector is not
     486 */
     487bool Vector::IsEqualTo(const Vector * const a) const
     488{
     489  bool status = true;
     490  for (int i=0;i<NDIM;i++) {
     491    if (fabs(x[i] - a->x[i]) > MYEPSILON)
     492      status = false;
     493  }
     494  return status;
    482495};
    483496
  • src/vector.hpp

    r5e8f82 rb998c3  
    4242  bool IsOne() const;
    4343  bool IsNormalTo(const Vector * const normal) const;
     44  bool IsEqualTo(const Vector * const a) const;
    4445
    4546  void AddVector(const Vector * const y);
Note: See TracChangeset for help on using the changeset viewer.