source: src/triangleintersectionlist.cpp@ bf3817

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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