source: src/triangleintersectionlist.cpp@ e670e4

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

Removed Helpers.hpp, deleted Helpers.cpp and libMoleCuilderHelpers.la is history.

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