source: src/triangleintersectionlist.cpp@ 8db598

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
Last change on this file since 8db598 was 8db598, checked in by Frederik Heber <heber@…>, 15 years ago

New class TriangleIntersection List and (hopefully) final fix of CorrelationToSurface().

  • Distances to surface were still calculated between the vector and the triangle plane not the triangle itself. Although functions such as BoundaryTriangleSet::GetClosestPointInsideTriangle had already been written.
  • As in class Tesselation there were many functions that all did the same: Calculate intersections between a point and all closeby triangles and then get the intersection or calculate this minimum distance and so ...
  • ... this was all put into a new class (in a new file): TriangleIntersectionList whose constructor scans all nearby triangles and put the calculates Intersections in the triangle into a list.
  • Functions as IsInside(), GetSmallestDistance(), GetClosestIntersection() and GetClosestTriangle() bring the desired functionality to the outside.
  • Respective functions in class Tesselation just make use of this new class and its member functions.
  • CorrelationToSurface() also directly instantiates this class to effectively use two of its functions.
  • Makefile.am has this new file in its SOURCES and HEADERS.
  • Tesselation:GetDistanceSquaredToSurface() -> Tesselation:GetDistanceToSurface(), FillBoxWithMolecule() has been adapted to this change.

AnalysisCorrelationToSurfaceUnitTest:

  • still has errors in it, as the distance were wrong before (because with respect to triangle plane, not triangle). Hence, the test was corrected.

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

  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 * triangleintersectionlist.cpp
3 *
4 * This files encapsulates the TriangleIntersectionList class where all matters related to points in space being how close to
5 * a tesselated surface are answered, i.e. distance, is inside, ...
6 *
7 * Created on: Mar 1, 2010
8 * Author: heber
9 */
10
11#include "triangleintersectionlist.hpp"
12
13#include "info.hpp"
14#include "tesselation.hpp"
15#include "vector.hpp"
16
17/** Constructor for class TriangleIntersectionList.
18 *
19 */
20TriangleIntersectionList::TriangleIntersectionList(const Vector *x, const Tesselation *surface, const LinkedCell* LC) :
21 Point(x),
22 Tess(surface),
23 Vicinity(LC)
24{
25 Info FunctionInfo(__func__);
26 GatherIntersectionsWithTriangles();
27};
28
29/** Destructor for class TriangleIntersectionList.
30 * Free's all allocated intersection vectors
31 */
32TriangleIntersectionList::~TriangleIntersectionList()
33{
34 Info FunctionInfo(__func__);
35 for (TriangleVectorMap::iterator Runner = IntersectionList.begin(); Runner != IntersectionList.end(); Runner++)
36 delete((*Runner).second);
37};
38
39/** Returns the smallest distance between TriangleIntersectionList::Point and the surface given by
40 * TriangleIntersectionList::Tess.
41 * \return distance >=0, -1 if no specific distance could be found
42 */
43double TriangleIntersectionList::GetSmallestDistance() const
44{
45 Info FunctionInfo(__func__);
46 FillDistanceList();
47 if (!DistanceList.empty())
48 return DistanceList.begin()->first;
49 else
50 // return reference, if none can be found
51 return -1.;
52};
53
54/** Returns the vector of closest intersection between TriangleIntersectionList::Point and the surface
55 * TriangleIntersectionList::Tess.
56 * \return Intersection vector or TriangleIntersectionList::Point if none could be found
57 */
58Vector TriangleIntersectionList::GetClosestIntersection() const
59{
60 Info FunctionInfo(__func__);
61 TriangleVectorMap::const_iterator runner;
62 runner = GetIteratortoSmallestDistance();
63 if (runner != IntersectionList.end()) {
64 return *((*runner).second);
65 }
66 // return reference, if none can be found
67 return *Point;
68};
69
70/** Returns the triangle closest to TriangleIntersectionList::Point and the surface
71 * TriangleIntersectionList::Tess.
72 * \return pointer to triangle or NULL if none could be found
73 */
74BoundaryTriangleSet * TriangleIntersectionList::GetClosestTriangle() const
75{
76 Info FunctionInfo(__func__);
77 TriangleVectorMap::const_iterator runner;
78 runner = GetIteratortoSmallestDistance();
79 if (runner != IntersectionList.end()) {
80 return ((*runner).first);
81 }
82 // return reference, if none can be found
83 return NULL;
84};
85
86/** Checks whether reference TriangleIntersectionList::Point of this class is inside or outside.
87 * \return true - TriangleIntersectionList::Point is inside, false - is outside
88 */
89bool TriangleIntersectionList::IsInside() const
90{
91 Info FunctionInfo(__func__);
92 TriangleVectorMap::const_iterator runner;
93 runner = GetIteratortoSmallestDistance();
94 if (runner != IntersectionList.end()) {
95 // if we have found one, check Scalarproduct between the vector
96 Vector TestVector(Point);
97 TestVector.SubtractVector((*runner).second);
98 if (fabs(TestVector.NormSquared()) < MYEPSILON) //
99 return true;
100 const double sign = (*runner).first->NormalVector.ScalarProduct(&TestVector);
101 if (sign < 0) {
102 return true;
103 } else {
104 return false;
105 }
106 }
107 // so far away from surface that there are no triangles in list
108 return false;
109};
110
111/** Puts all triangles in vicinity (by \a *LC) into a hash map with Intersection vectors.
112 * Private function for constructor of TriangleIntersectionList.
113 */
114void TriangleIntersectionList::GatherIntersectionsWithTriangles()
115{
116 Info FunctionInfo(__func__);
117
118 // get closest points
119 DistanceToPointMap * points = Tess->FindClosestBoundaryPointsToVector(Point,Vicinity);
120 if (points == NULL) {
121 eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
122 return;
123 }
124
125 // gather all triangles in *LC-neighbourhood
126 TriangleSet triangles;
127 for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++)
128 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++)
129 for (TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
130 triangles.insert(TriangleRunner->second);
131
132 Vector *Intersection = NULL;
133 for (TriangleSet::const_iterator TriangleRunner = triangles.begin(); TriangleRunner != triangles.end(); TriangleRunner++) {
134 // get intersection with triangle plane
135 Intersection = new Vector;
136 (*TriangleRunner)->GetClosestPointInsideTriangle(Point, Intersection);
137 //cout << "Intersection between " << *Point << " and " << **TriangleRunner << " is at " << *Intersection << "." << endl;
138 IntersectionList.insert( pair<BoundaryTriangleSet *, Vector * > (*TriangleRunner, Intersection) );
139 }
140};
141
142/** Fills the private distance list
143 */
144void TriangleIntersectionList::FillDistanceList() const
145{
146 Info FunctionInfo(__func__);
147 if (DistanceList.empty())
148 for (TriangleVectorMap::const_iterator runner = IntersectionList.begin(); runner != IntersectionList.end(); runner++)
149 DistanceList.insert( pair<double, BoundaryTriangleSet *> (Point->Distance((*runner).second), (*runner).first) );
150
151 //for (DistanceTriangleMap::const_iterator runner = DistanceList.begin(); runner != DistanceList.end(); runner++)
152 // cout << (*runner).first << " away from " << *(*runner).second << endl;
153};
154
155
156/** Returns the iterator in VectorTriangleMap to the smallest distance.
157 * This is a private helper function as the iterator is then evaluated in some other functions.
158 * \return iterator or TriangleIntersectionList::IntersectionList.end() if none could be found
159 */
160TriangleVectorMap::const_iterator TriangleIntersectionList::GetIteratortoSmallestDistance() const
161{
162 Info FunctionInfo(__func__);
163 FillDistanceList();
164
165 // do we have any intersections?
166 TriangleVectorMap::const_iterator runner;
167 if (!DistanceList.empty()) {
168 // get closest triangle
169 runner = IntersectionList.find(DistanceList.begin()->second);
170 }
171 return runner;
172};
173
Note: See TracBrowser for help on using the repository browser.