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