source: src/triangleintersectionlist.cpp@ d74077

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 d74077 was d74077, checked in by Frederik Heber <heber@…>, 15 years ago

Member variable Vector and element of class atom are now private.

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