source: src/BoundaryPolygonSet.cpp@ 2d292d

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 2d292d was 8f4df1, checked in by Frederik Heber <heber@…>, 14 years ago

Merge branch 'AtomicPositionEncapsulation' into stable

Conflicts:

src/Actions/AtomAction/ChangeElementAction.cpp
src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp
src/Makefile.am
src/UIElements/TextUI/TextDialog.cpp
src/analysis_correlation.hpp
src/atom.cpp
src/atom_atominfo.hpp
src/bond.cpp
src/boundary.cpp
src/molecule_geometry.cpp
src/tesselation.cpp
src/tesselationhelpers.cpp
src/triangleintersectionlist.cpp
src/unittests/Makefile.am

  • fixed #includes due to moves to Helpers and LinearAlgebra
  • moved VectorInterface.* and vector_ops.* to LinearAlgebra
  • no more direct access of atom::node, remapped to set/getPosition()
  • no more direct access to atom::type, remapped to set/getType() (also in atom due to derivation and atominfo::AtomicElement is private not protected).
  • Property mode set to 100644
File size: 9.2 KB
Line 
1/*
2 * BoundaryPolygonSet.cpp
3 *
4 * Created on: Jul 29, 2010
5 * Author: heber
6 */
7
8#include "BoundaryPolygonSet.hpp"
9
10#include <iostream>
11
12#include "BoundaryLineSet.hpp"
13#include "BoundaryPointSet.hpp"
14#include "BoundaryTriangleSet.hpp"
15#include "TesselPoint.hpp"
16
17#include "Helpers/Assert.hpp"
18#include "Helpers/helpers.hpp"
19#include "Helpers/Info.hpp"
20#include "Helpers/Log.hpp"
21#include "LinearAlgebra/Plane.hpp"
22#include "LinearAlgebra/Vector.hpp"
23#include "Helpers/Verbose.hpp"
24
25using namespace std;
26
27/** Constructor for BoundaryPolygonSet.
28 */
29BoundaryPolygonSet::BoundaryPolygonSet() :
30 Nr(-1)
31{
32 Info FunctionInfo(__func__);
33}
34;
35
36/** Destructor of BoundaryPolygonSet.
37 * Just clears endpoints.
38 * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
39 */
40BoundaryPolygonSet::~BoundaryPolygonSet()
41{
42 Info FunctionInfo(__func__);
43 endpoints.clear();
44 DoLog(1) && (Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl);
45}
46;
47
48/** Calculates the normal vector for this triangle.
49 * Is made unique by comparison with \a OtherVector to point in the other direction.
50 * \param &OtherVector direction vector to make normal vector unique.
51 * \return allocated vector in normal direction
52 */
53Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
54{
55 Info FunctionInfo(__func__);
56 // get normal vector
57 Vector TemporaryNormal;
58 Vector *TotalNormal = new Vector;
59 PointSet::const_iterator Runner[3];
60 for (int i = 0; i < 3; i++) {
61 Runner[i] = endpoints.begin();
62 for (int j = 0; j < i; j++) { // go as much further
63 Runner[i]++;
64 if (Runner[i] == endpoints.end()) {
65 DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
66 performCriticalExit();
67 }
68 }
69 }
70 TotalNormal->Zero();
71 int counter = 0;
72 for (; Runner[2] != endpoints.end();) {
73 TemporaryNormal = Plane(((*Runner[0])->node->getPosition()),
74 ((*Runner[1])->node->getPosition()),
75 ((*Runner[2])->node->getPosition())).getNormal();
76 for (int i = 0; i < 3; i++) // increase each of them
77 Runner[i]++;
78 (*TotalNormal) += TemporaryNormal;
79 }
80 TotalNormal->Scale(1. / (double) counter);
81
82 // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
83 if (TotalNormal->ScalarProduct(OtherVector) > 0.)
84 TotalNormal->Scale(-1.);
85 DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
86
87 return TotalNormal;
88}
89;
90
91/** Calculates the center point of the triangle.
92 * Is third of the sum of all endpoints.
93 * \param *center central point on return.
94 */
95void BoundaryPolygonSet::GetCenter(Vector * const center) const
96{
97 Info FunctionInfo(__func__);
98 center->Zero();
99 int counter = 0;
100 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
101 (*center) += ((*Runner)->node->getPosition());
102 counter++;
103 }
104 center->Scale(1. / (double) counter);
105 DoLog(1) && (Log() << Verbose(1) << "Center is at " << *center << "." << endl);
106}
107
108/** Checks whether the polygons contains all three endpoints of the triangle.
109 * \param *triangle triangle to test
110 * \return true - triangle is contained polygon, false - is not
111 */
112bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
113{
114 Info FunctionInfo(__func__);
115 return ContainsPresentTupel(triangle->endpoints, 3);
116}
117;
118
119/** Checks whether the polygons contains both endpoints of the line.
120 * \param *line line to test
121 * \return true - line is of the triangle, false - is not
122 */
123bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
124{
125 Info FunctionInfo(__func__);
126 return ContainsPresentTupel(line->endpoints, 2);
127}
128;
129
130/** Checks whether point is any of the three endpoints this triangle contains.
131 * \param *point point to test
132 * \return true - point is of the triangle, false - is not
133 */
134bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
135{
136 Info FunctionInfo(__func__);
137 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
138 DoLog(0) && (Log() << Verbose(0) << "Checking against " << **Runner << endl);
139 if (point == (*Runner)) {
140 DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
141 return true;
142 }
143 }
144 DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
145 return false;
146}
147;
148
149/** Checks whether point is any of the three endpoints this triangle contains.
150 * \param *point TesselPoint to test
151 * \return true - point is of the triangle, false - is not
152 */
153bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
154{
155 Info FunctionInfo(__func__);
156 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
157 if (point == (*Runner)->node) {
158 DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
159 return true;
160 }
161 DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
162 return false;
163}
164;
165
166/** Checks whether given array of \a *Points coincide with polygons's endpoints.
167 * \param **Points pointer to an array of BoundaryPointSet
168 * \param dim dimension of array
169 * \return true - set of points is contained in polygon, false - is not
170 */
171bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
172{
173 Info FunctionInfo(__func__);
174 int counter = 0;
175 DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
176 for (int i = 0; i < dim; i++) {
177 DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl);
178 if (ContainsBoundaryPoint(Points[i])) {
179 counter++;
180 }
181 }
182
183 if (counter == dim)
184 return true;
185 else
186 return false;
187}
188;
189
190/** Checks whether given PointList coincide with polygons's endpoints.
191 * \param &endpoints PointList
192 * \return true - set of points is contained in polygon, false - is not
193 */
194bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
195{
196 Info FunctionInfo(__func__);
197 size_t counter = 0;
198 DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
199 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
200 DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << **Runner << endl);
201 if (ContainsBoundaryPoint(*Runner))
202 counter++;
203 }
204
205 if (counter == endpoints.size())
206 return true;
207 else
208 return false;
209}
210;
211
212/** Checks whether given set of \a *Points coincide with polygons's endpoints.
213 * \param *P pointer to BoundaryPolygonSet
214 * \return true - is the very triangle, false - is not
215 */
216bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
217{
218 return ContainsPresentTupel((const PointSet) P->endpoints);
219}
220;
221
222/** Gathers all the endpoints' triangles in a unique set.
223 * \return set of all triangles
224 */
225TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
226{
227 Info FunctionInfo(__func__);
228 pair<TriangleSet::iterator, bool> Tester;
229 TriangleSet *triangles = new TriangleSet;
230
231 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
232 for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
233 for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
234 //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
235 if (ContainsBoundaryTriangle(Sprinter->second)) {
236 Tester = triangles->insert(Sprinter->second);
237 if (Tester.second)
238 DoLog(0) && (Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl);
239 }
240 }
241
242 DoLog(1) && (Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl);
243 return triangles;
244}
245;
246
247/** Fills the endpoints of this polygon from the triangles attached to \a *line.
248 * \param *line lines with triangles attached
249 * \return true - polygon contains endpoints, false - line was NULL
250 */
251bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
252{
253 Info FunctionInfo(__func__);
254 pair<PointSet::iterator, bool> Tester;
255 if (line == NULL)
256 return false;
257 DoLog(1) && (Log() << Verbose(1) << "Filling polygon from line " << *line << endl);
258 for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
259 for (int i = 0; i < 3; i++) {
260 Tester = endpoints.insert((Runner->second)->endpoints[i]);
261 if (Tester.second)
262 DoLog(1) && (Log() << Verbose(1) << " Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl);
263 }
264 }
265
266 return true;
267}
268;
269
270/** output operator for BoundaryPolygonSet.
271 * \param &ost output stream
272 * \param &a boundary polygon
273 */
274ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
275{
276 ost << "[" << a.Nr << "|";
277 for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
278 ost << (*Runner)->node->getName();
279 Runner++;
280 if (Runner != a.endpoints.end())
281 ost << ",";
282 }
283 ost << "]";
284 return ost;
285}
286;
287
Note: See TracBrowser for help on using the repository browser.