Changeset b32dbb


Ignore:
Timestamp:
May 29, 2010, 12:59:31 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:
a7c344
Parents:
bfd839
git-author:
Frederik Heber <heber@…> (05/27/10 11:04:42)
git-committer:
Frederik Heber <heber@…> (05/29/10 12:59:31)
Message:

Fixes and changes to tesselation and concavity measurements.

Here, we implement two attempts for a concavity measure:

  1. Measure concavity per point by looking at neighbouring triangles
    • BoundaryLineSet::CheckConvexityCriterion() split up (calculation of angle outsourced to CalculateConvexity())
    • CHANGE: CalculateConcavityPerBoundaryPoint() uses new concavity measure per BoundaryPointSet containing:
      • concavity per line uses angle instead of +/-1 for line, averaged by number of lines
      • also concavity over all attached triangles uses area of triangle and only in case of concavity, averaged by total area
    • new functions
      • BoundaryLineSet::CalculateConvexity() - calculates the angle between two triangles.
      • BoundaryLineSet::GetOtherTriangle() - for a closed line returns the other triangle for a given one
      • BoundaryTriangleSet::GetThirdLine() - for a given boundary point returns the line of the three which does not contain it (opposite line to a point)
      • CalculateAreaofGeneralTriangle() - calculates area of arbitrary triangle
  1. Measure concavity by the distance to a more convex envelope (i.e. created with bigger sphere radius)

Other unrelated stuff:

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

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    rbfd839 rb32dbb  
    10411041//  // Purges surplus triangles.
    10421042//  TesselStruct->RemoveDegeneratedTriangles();
    1043 
    1044   // check envelope for consistency
    1045   status = CheckListOfBaselines(TesselStruct);
     1043//
     1044//  // check envelope for consistency
     1045//  status = CheckListOfBaselines(TesselStruct);
    10461046
    10471047  // store before correction
  • src/builder.cpp

    rbfd839 rb32dbb  
    21032103              } else {
    21042104                class Tesselation *T = NULL;
     2105                class Tesselation *Convex = NULL;
    21052106                const LinkedCell *LCList = NULL;
     2107                const LinkedCell *LCListConvex = NULL;
    21062108                molecule * Boundary = NULL;
    21072109                //string filename(argv[argptr+1]);
     
    21232125                if (!FindNonConvexBorder(Boundary, T, LCList, atof(argv[argptr]), argv[argptr+1]))
    21242126                  ExitFlag = 255;
     2127                const double ConvexRadius = 20.;
     2128                LCListConvex = new LinkedCell(Boundary, 2.*ConvexRadius);
     2129//                setVerbosity(3);
     2130                if (!FindNonConvexBorder(Boundary, Convex, LCListConvex, ConvexRadius, "ConvexEnvelope"))
     2131                  ExitFlag = 255;
     2132                CalculateConstrictionPerBoundaryPoint(T, Convex);
     2133                StoreTrianglesinFile(mol, (const Tesselation *&)T, argv[argptr+1], "");
    21252134                //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str());
    21262135                end = clock();
  • src/tesselation.cpp

    rbfd839 rb32dbb  
    229229{
    230230  Info FunctionInfo(__func__);
     231  double angle = CalculateConvexity();
     232  if (angle > -MYEPSILON) {
     233    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
     234    return true;
     235  } else {
     236    DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
     237    return false;
     238  }
     239}
     240
     241
     242/** Calculates the angle between two triangles with respect to their normal vector.
     243 * We sum the two angles of each height vector with respect to the center of the baseline.
     244 * \return angle > 0 then convex, if < 0 then concave
     245 */
     246double BoundaryLineSet::CalculateConvexity() const
     247{
     248  Info FunctionInfo(__func__);
    231249  Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
    232250  // get the two triangles
     
    277295  BaseLineNormal.Scale(-1.);
    278296  double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    279   if ((angle - M_PI) > -MYEPSILON) {
    280     DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
    281     return true;
    282   } else {
    283     DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
    284     return false;
    285   }
     297  return (angle - M_PI);
    286298}
    287299
     
    302314/** Returns other endpoint of the line.
    303315 * \param *point other endpoint
    304  * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise
     316 * \return NULL - if endpoint not contained in BoundaryLineSet::lines, or pointer to BoundaryPointSet otherwise
    305317 */
    306318class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
     
    313325  else
    314326    return NULL;
     327}
     328;
     329
     330/** Returns other triangle of the line.
     331 * \param *point other endpoint
     332 * \return NULL - if triangle not contained in BoundaryLineSet::triangles, or pointer to BoundaryTriangleSet otherwise
     333 */
     334class BoundaryTriangleSet *BoundaryLineSet::GetOtherTriangle(const BoundaryTriangleSet * const triangle) const
     335{
     336  Info FunctionInfo(__func__);
     337  if (triangles.size() == 2) {
     338    for (TriangleMap::const_iterator TriangleRunner = triangles.begin(); TriangleRunner != triangles.end(); ++TriangleRunner)
     339      if (TriangleRunner->second != triangle)
     340        return TriangleRunner->second;
     341  }
     342  return NULL;
    315343}
    316344;
     
    669697;
    670698
     699/** Returns the baseline which does not contain the given boundary point \a *point.
     700 * \param *point endpoint which is neither endpoint of the desired line
     701 * \return pointer to desired third baseline
     702 */
     703class BoundaryLineSet *BoundaryTriangleSet::GetThirdLine(const BoundaryPointSet * const point) const
     704{
     705  Info FunctionInfo(__func__);
     706  // sanity check
     707  if (!ContainsBoundaryPoint(point))
     708    return NULL;
     709  for (int i = 0; i < 3; i++)
     710    if (!lines[i]->ContainsBoundaryPoint(point))
     711      return lines[i];
     712  // actually, that' impossible :)
     713  return NULL;
     714}
     715;
     716
    671717/** Calculates the center point of the triangle.
    672718 * Is third of the sum of all endpoints.
     
    11061152    TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
    11071153
    1108     DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl);
     1154    DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << (*VRunner) << ":" << endl);
    11091155    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    1110       DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->distance(OtherOptCenter) << "." << endl);
     1156      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->distance(*(*VRunner)) << "." << endl);
    11111157
    11121158    // remove baseline's endpoints and candidates
     
    11241170      DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
    11251171      for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    1126         DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << endl);
     1172        DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << " at distance " << setprecision(13) << (*Runner)->node->distance(*(*VRunner)) << setprecision(6) << "." << endl);
     1173
     1174      // check with animate_sphere.tcl VMD script
     1175      if (ThirdPoint != NULL) {
     1176        DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
     1177      } else {
     1178        DoeLog(1) && (eLog() << Verbose(1) << "Check by: ... missing third point ..." << endl);
     1179        DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
     1180      }
    11271181    }
    11281182    delete (ListofPoints);
    11291183
    1130     // check with animate_sphere.tcl VMD script
    1131     if (ThirdPoint != NULL) {
    1132       DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
    1133     } else {
    1134       DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl);
    1135       DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
    1136     }
    11371184  }
    11381185  return flag;
     
    33133360                        }
    33143361                      } else {
    3315                         DoLog(1) && (Log() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
     3362                        DoeLog(0) && (eLog() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
    33163363                      }
    33173364                    } else {
     
    46134660
    46144661  DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl);
    4615   IndexToIndex::iterator it;
    4616   for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
     4662  for (IndexToIndex::iterator it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    46174663    DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
    46184664
     
    46324678  int count = 0;
    46334679
    4634   for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) {
     4680  // iterate over all degenerated triangles
     4681  for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); !DegeneratedTriangles->empty(); TriangleKeyRunner = DegeneratedTriangles->begin()) {
     4682    DoLog(0) && (Log() << Verbose(0) << "Checking presence of triangles " << TriangleKeyRunner->first << " and " << TriangleKeyRunner->second << "." << endl);
     4683    // both ways are stored in the map, only use one
     4684    if (TriangleKeyRunner->first > TriangleKeyRunner->second)
     4685      continue;
     4686
     4687    // determine from the keys in the map the two _present_ triangles
    46354688    finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
    46364689    if (finder != TrianglesOnBoundary.end())
    46374690      triangle = finder->second;
    46384691    else
    4639       break;
     4692      continue;
    46404693    finder = TrianglesOnBoundary.find(TriangleKeyRunner->second);
    46414694    if (finder != TrianglesOnBoundary.end())
    46424695      partnerTriangle = finder->second;
    46434696    else
    4644       break;
    4645 
     4697      continue;
     4698
     4699    // determine which lines are shared by the two triangles
    46464700    bool trianglesShareLine = false;
    46474701    for (int i = 0; i < 3; ++i)
  • src/tesselation.hpp

    rbfd839 rb32dbb  
    138138    bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
    139139    bool CheckConvexityCriterion() const;
     140    double CalculateConvexity() const;
    140141    class BoundaryPointSet *GetOtherEndpoint(const BoundaryPointSet * const point) const;
     142    class BoundaryTriangleSet *GetOtherTriangle(const BoundaryTriangleSet * const triangle) const;
    141143
    142144    class BoundaryPointSet *endpoints[2];
     
    164166    bool ContainsBoundaryPoint(const TesselPoint * const point) const;
    165167    class BoundaryPointSet *GetThirdEndpoint(const BoundaryLineSet * const line) const;
     168    class BoundaryLineSet *GetThirdLine(const BoundaryPointSet * const point) const;
    166169    bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
    167170    bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
  • src/tesselationhelpers.cpp

    rbfd839 rb32dbb  
    1010#include "info.hpp"
    1111#include "linkedcell.hpp"
     12#include "linearsystemofequations.hpp"
    1213#include "log.hpp"
    1314#include "tesselation.hpp"
     
    182183  beta = M_PI - SideC.Angle(SideA);
    183184  gamma = M_PI - SideA.Angle(SideB);
    184   //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;
     185  Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;
    185186  if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) {
    186187    DoeLog(2) && (eLog()<< Verbose(2) << "GetCenterofCircumcircle: Sum of angles " << (alpha+beta+gamma)/M_PI*180. << " > 180 degrees by " << fabs(M_PI - alpha - beta - gamma)/M_PI*180. << "!" << endl);
     
    195196  (*Center) += helper;
    196197  Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
     198  Log() << Verbose(1) << "INFO: Center (1st algo) is at " << *Center << "." << endl;
     199
     200//  LinearSystemOfEquations LSofEq(NDIM,NDIM);
     201//  double *matrix = new double[NDIM*NDIM];
     202//  matrix[0] = 0.;
     203//  matrix[1] = a.DistanceSquared(b);
     204//  matrix[2] = a.DistanceSquared(c);
     205//  matrix[3] = a.DistanceSquared(b);
     206//  matrix[4] = 0.;
     207//  matrix[5] = b.DistanceSquared(c);
     208//  matrix[6] = a.DistanceSquared(c);
     209//  matrix[7] = b.DistanceSquared(c);
     210//  matrix[8] = 0.;
     211//  cout << "Matrix is: ";
     212//  for (int i=0;i<NDIM*NDIM;i++)
     213//    cout << matrix[i] << "\t";
     214//  cout << endl;
     215//  LSofEq.SetA(matrix);
     216//  delete[](matrix);
     217//  LSofEq.Setb(new Vector(1.,1.,1.));
     218//  LSofEq.SetSymmetric(true);
     219//  helper.Zero();
     220//  if (!LSofEq.GetSolutionAsVector(helper)) {
     221//    DoLog(0) && (eLog()<< Verbose(0) << "Could not solve the linear system in GetCenterofCircumCircle()!" << endl);
     222//  }
     223//  cout << "Solution is " << helper << endl;
     224  // is equivalent to the three lines below
     225  helper[0] = SideA.NormSquared()*(SideB.NormSquared()+SideC.NormSquared() - SideA.NormSquared());
     226  helper[1] = SideB.NormSquared()*(SideC.NormSquared()+SideA.NormSquared() - SideB.NormSquared());
     227  helper[2] = SideC.NormSquared()*(SideA.NormSquared()+SideB.NormSquared() - SideC.NormSquared());
     228
     229  Center->Zero();
     230  *Center += helper[0] * a;
     231  *Center += helper[1] * b;
     232  *Center += helper[2] * c;
     233  Center->Scale(1./(helper[0]+helper[1]+helper[2]));
     234  Log() << Verbose(1) << "INFO: Center (2nd algo) is at " << *Center << "." << endl;
    197235};
    198236
     
    416454/** Calculates the volume of a general tetraeder.
    417455 * \param *a first vector
    418  * \param *a first vector
    419  * \param *a first vector
    420  * \param *a first vector
     456 * \param *b second vector
     457 * \param *c third vector
     458 * \param *d fourth vector
    421459 * \return \f$ \frac{1}{6} \cdot ((a-d) \times (a-c) \cdot  (a-b)) \f$
    422460 */
     
    436474  volume = 1./6. * fabs(Point.ScalarProduct(TetraederVector[2]));
    437475  return volume;
     476};
     477
     478/** Calculates the area of a general triangle.
     479 * We use the Heron's formula of area, [Bronstein, S. 138]
     480 * \param &A first vector
     481 * \param &B second vector
     482 * \param &C third vector
     483 * \return \f$ \frac{1}{6} \cdot ((a-d) \times (a-c) \cdot  (a-b)) \f$
     484 */
     485double CalculateAreaofGeneralTriangle(const Vector &A, const Vector &B, const Vector &C)
     486{
     487  Info FunctionInfo(__func__);
     488
     489  const double sidea = B.distance(C);
     490  const double sideb = A.distance(C);
     491  const double sidec = A.distance(B);
     492  const double s = (sidea+sideb+sidec)/2.;
     493
     494  const double area = sqrt(s*(s-sidea)*(s-sideb)*(s-sidec));
     495  return area;
    438496};
    439497
     
    870928  class BoundaryPointSet *point = NULL;
    871929  class BoundaryLineSet *line = NULL;
    872 
    873   // calculate remaining concavity
     930  class BoundaryTriangleSet *triangle = NULL;
     931  double ConcavityPerLine = 0.;
     932  double ConcavityPerTriangle = 0.;
     933  double area = 0.;
     934  double totalarea = 0.;
     935
    874936  for (PointMap::const_iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
    875937    point = PointRunner->second;
    876938    DoLog(1) && (Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl);
    877     point->value = 0;
     939
     940    // calculate mean concavity over all connected line
     941    ConcavityPerLine = 0.;
    878942    for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    879943      line = LineRunner->second;
    880944      //Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
    881       if (!line->CheckConvexityCriterion())
    882         point->value += 1;
    883     }
    884   }
    885 };
    886 
     945      ConcavityPerLine -= line->CalculateConvexity();
     946    }
     947    ConcavityPerLine /= point->lines.size();
     948
     949    // weigh with total area of the surrounding triangles
     950    totalarea  = 0.;
     951    TriangleSet *triangles = TesselStruct->GetAllTriangles(PointRunner->second);
     952    for (TriangleSet::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); ++TriangleRunner) {
     953      totalarea += CalculateAreaofGeneralTriangle(*(*TriangleRunner)->endpoints[0]->node->node, *(*TriangleRunner)->endpoints[1]->node->node, *(*TriangleRunner)->endpoints[2]->node->node);
     954    }
     955    ConcavityPerLine *= totalarea;
     956
     957    // calculate mean concavity over all attached triangles
     958    ConcavityPerTriangle = 0.;
     959    for (TriangleSet::const_iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); ++TriangleRunner) {
     960      line = (*TriangleRunner)->GetThirdLine(PointRunner->second);
     961      triangle = line->GetOtherTriangle(*TriangleRunner);
     962      area = CalculateAreaofGeneralTriangle(*triangle->endpoints[0]->node->node, *triangle->endpoints[1]->node->node, *triangle->endpoints[2]->node->node);
     963      area += CalculateAreaofGeneralTriangle(*(*TriangleRunner)->endpoints[0]->node->node, *(*TriangleRunner)->endpoints[1]->node->node, *(*TriangleRunner)->endpoints[2]->node->node);
     964      area *= -line->CalculateConvexity();
     965      if (area > 0)
     966        ConcavityPerTriangle += area;
     967//      else
     968//        ConcavityPerTriangle -= area;
     969    }
     970    ConcavityPerTriangle /= triangles->size()/totalarea;
     971    delete(triangles);
     972
     973    // add up
     974    point->value = ConcavityPerLine + ConcavityPerTriangle;
     975  }
     976};
     977
     978
     979
     980/** Calculates the concavity for each of the BoundaryPointSet's in a Tesselation.
     981 * Sets BoundaryPointSet::value equal to the nearest distance to convex envelope.
     982 * \param *out output stream for debugging
     983 * \param *TesselStruct pointer to Tesselation structure
     984 * \param *Convex pointer to convex Tesselation structure as reference
     985 */
     986void CalculateConstrictionPerBoundaryPoint(const Tesselation * const TesselStruct, const Tesselation * const Convex)
     987{
     988  Info FunctionInfo(__func__);
     989  double distance = 0.;
     990
     991  for (PointMap::const_iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
     992    DoeLog(1) && (eLog() << Verbose(1) << "INFO: Current point is " << * PointRunner->second << "." << endl);
     993
     994    distance = 0.;
     995    for (TriangleMap::const_iterator TriangleRunner = Convex->TrianglesOnBoundary.begin(); TriangleRunner != Convex->TrianglesOnBoundary.end(); TriangleRunner++) {
     996      const double CurrentDistance = Convex->GetDistanceSquaredToTriangle(*PointRunner->second->node->node, TriangleRunner->second);
     997      if (CurrentDistance < distance)
     998        distance = CurrentDistance;
     999    }
     1000
     1001    PointRunner->second->value = distance;
     1002  }
     1003};
    8871004
    8881005/** Checks whether each BoundaryLineSet in the Tesselation has two triangles.
  • src/tesselationhelpers.hpp

    rbfd839 rb32dbb  
    4343/********************************************** definitions *********************************/
    4444
    45 #define HULLEPSILON 1e-10
     45#define HULLEPSILON 1e-9 //!< TODO: Get rid of HULLEPSILON, points to numerical instabilities
    4646
    4747/********************************************** declarations *******************************/
     
    5555bool existsIntersection(const Vector &point1, const Vector &point2, const Vector &point3, const Vector &point4);
    5656double CalculateVolumeofGeneralTetraeder(const Vector &a, const Vector &b, const Vector &c, const Vector &d);
     57double CalculateAreaofGeneralTriangle(const Vector &A, const Vector &B, const Vector &C);
    5758double GetAngle(const Vector &point, const Vector &reference, const Vector &OrthogonalVector);
    5859
     
    6869void WriteVrmlFile(ofstream * const vrmlfile, const Tesselation * const Tess, const PointCloud * const cloud);
    6970void CalculateConcavityPerBoundaryPoint(const Tesselation * const TesselStruct);
     71void CalculateConstrictionPerBoundaryPoint(const Tesselation * const TesselStruct, const Tesselation * const Convex);
    7072double DistanceToTrianglePlane(const Vector *x, const BoundaryTriangleSet * const triangle);
    7173
Note: See TracChangeset for help on using the changeset viewer.