source: src/Tesselation/BoundaryPolygonSet.cpp@ b4f72c

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 b4f72c was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 9.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * BoundaryPolygonSet.cpp
25 *
26 * Created on: Jul 29, 2010
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "BoundaryPolygonSet.hpp"
38
39#include <iostream>
40
41#include "BoundaryLineSet.hpp"
42#include "BoundaryPointSet.hpp"
43#include "BoundaryTriangleSet.hpp"
44#include "Atom/TesselPoint.hpp"
45
46#include "CodePatterns/Assert.hpp"
47#include "CodePatterns/Info.hpp"
48#include "CodePatterns/Log.hpp"
49#include "CodePatterns/Verbose.hpp"
50#include "Helpers/helpers.hpp"
51#include "LinearAlgebra/Plane.hpp"
52#include "LinearAlgebra/Vector.hpp"
53
54using namespace std;
55
56/** Constructor for BoundaryPolygonSet.
57 */
58BoundaryPolygonSet::BoundaryPolygonSet() :
59 Nr(-1)
60{
61 //Info FunctionInfo(__func__);
62}
63;
64
65/** Destructor of BoundaryPolygonSet.
66 * Just clears endpoints.
67 * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
68 */
69BoundaryPolygonSet::~BoundaryPolygonSet()
70{
71 //Info FunctionInfo(__func__);
72 endpoints.clear();
73 LOG(5, "DEBUG: Erasing polygon Nr." << Nr << " itself.");
74}
75;
76
77/** Calculates the normal vector for this triangle.
78 * Is made unique by comparison with \a OtherVector to point in the other direction.
79 * \param &OtherVector direction vector to make normal vector unique.
80 * \return allocated vector in normal direction
81 */
82Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
83{
84 //Info FunctionInfo(__func__);
85 // get normal vector
86 Vector TemporaryNormal;
87 Vector *TotalNormal = new Vector;
88 PointSet::const_iterator Runner[3];
89 for (int i = 0; i < 3; i++) {
90 Runner[i] = endpoints.begin();
91 for (int j = 0; j < i; j++) { // go as much further
92 Runner[i]++;
93 if (Runner[i] == endpoints.end()) {
94 ELOG(0, "There are less than three endpoints in the polygon!");
95 performCriticalExit();
96 }
97 }
98 }
99 TotalNormal->Zero();
100 int counter = 0;
101 for (; Runner[2] != endpoints.end();) {
102 TemporaryNormal = Plane(((*Runner[0])->node->getPosition()),
103 ((*Runner[1])->node->getPosition()),
104 ((*Runner[2])->node->getPosition())).getNormal();
105 for (int i = 0; i < 3; i++) // increase each of them
106 Runner[i]++;
107 (*TotalNormal) += TemporaryNormal;
108 }
109 TotalNormal->Scale(1. / (double) counter);
110
111 // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
112 if (TotalNormal->ScalarProduct(OtherVector) > 0.)
113 TotalNormal->Scale(-1.);
114 LOG(4, "DEBUG: Normal Vector is " << *TotalNormal << ".");
115
116 return TotalNormal;
117}
118;
119
120/** Calculates the center point of the triangle.
121 * Is third of the sum of all endpoints.
122 * \param *center central point on return.
123 */
124void BoundaryPolygonSet::GetCenter(Vector * const center) const
125{
126 //Info FunctionInfo(__func__);
127 center->Zero();
128 int counter = 0;
129 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
130 (*center) += ((*Runner)->node->getPosition());
131 counter++;
132 }
133 center->Scale(1. / (double) counter);
134 LOG(4, "DEBUG: Center of BoundaryPolygonSet is at " << *center << ".");
135}
136
137/** Checks whether the polygons contains all three endpoints of the triangle.
138 * \param *triangle triangle to test
139 * \return true - triangle is contained polygon, false - is not
140 */
141bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
142{
143 //Info FunctionInfo(__func__);
144 return ContainsPresentTupel(triangle->endpoints, 3);
145}
146;
147
148/** Checks whether the polygons contains both endpoints of the line.
149 * \param *line line to test
150 * \return true - line is of the triangle, false - is not
151 */
152bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
153{
154 //Info FunctionInfo(__func__);
155 return ContainsPresentTupel(line->endpoints, 2);
156}
157;
158
159/** Checks whether point is any of the three endpoints this triangle contains.
160 * \param *point point to test
161 * \return true - point is of the triangle, false - is not
162 */
163bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
164{
165 //Info FunctionInfo(__func__);
166 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
167 if (point == (*Runner)) {
168 LOG(4, "DEBUG: Checking against " << **Runner << ": Contained.");
169 return true;
170 }
171 }
172 return false;
173}
174;
175
176/** Checks whether point is any of the three endpoints this triangle contains.
177 * \param *point TesselPoint to test
178 * \return true - point is of the triangle, false - is not
179 */
180bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
181{
182 //Info FunctionInfo(__func__);
183 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
184 if (point == (*Runner)->node) {
185 LOG(4, "DEBUG: Checking against " << **Runner << ": Contained.");
186 return true;
187 }
188 return false;
189}
190;
191
192/** Checks whether given array of \a *Points coincide with polygons's endpoints.
193 * \param **Points pointer to an array of BoundaryPointSet
194 * \param dim dimension of array
195 * \return true - set of points is contained in polygon, false - is not
196 */
197bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
198{
199 //Info FunctionInfo(__func__);
200 int counter = 0;
201 LOG(5, "DEBUG Polygon is " << *this);
202 for (int i = 0; i < dim; i++) {
203 LOG(5, "DEBUG: Testing endpoint " << *Points[i]);
204 if (ContainsBoundaryPoint(Points[i])) {
205 counter++;
206 }
207 }
208
209 if (counter == dim)
210 return true;
211 else
212 return false;
213}
214;
215
216/** Checks whether given PointList coincide with polygons's endpoints.
217 * \param &endpoints PointList
218 * \return true - set of points is contained in polygon, false - is not
219 */
220bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
221{
222 //Info FunctionInfo(__func__);
223 size_t counter = 0;
224 LOG(5, "DEBUG: Polygon is " << *this);
225 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
226 LOG(5, "DEBUG: Testing endpoint " << **Runner);
227 if (ContainsBoundaryPoint(*Runner))
228 counter++;
229 }
230
231 if (counter == endpoints.size())
232 return true;
233 else
234 return false;
235}
236;
237
238/** Checks whether given set of \a *Points coincide with polygons's endpoints.
239 * \param *P pointer to BoundaryPolygonSet
240 * \return true - is the very triangle, false - is not
241 */
242bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
243{
244 return ContainsPresentTupel((const PointSet) P->endpoints);
245}
246;
247
248/** Gathers all the endpoints' triangles in a unique set.
249 * \return set of all triangles
250 */
251TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
252{
253 //Info FunctionInfo(__func__);
254 pair<TriangleSet::iterator, bool> Tester;
255 TriangleSet *triangles = new TriangleSet;
256
257 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
258 for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
259 for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
260 //LOG(0, " Testing triangle " << *(Sprinter->second));
261 if (ContainsBoundaryTriangle(Sprinter->second)) {
262 Tester = triangles->insert(Sprinter->second);
263 if (Tester.second)
264 LOG(4, "DEBUG: Adding triangle " << *(Sprinter->second));
265 }
266 }
267
268 LOG(3, "DEBUG: The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total.");
269 return triangles;
270}
271;
272
273/** Fills the endpoints of this polygon from the triangles attached to \a *line.
274 * \param *line lines with triangles attached
275 * \return true - polygon contains endpoints, false - line was NULL
276 */
277bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
278{
279 //Info FunctionInfo(__func__);
280 pair<PointSet::iterator, bool> Tester;
281 if (line == NULL)
282 return false;
283 LOG(3, "DEBUG: Filling polygon from line " << *line);
284 for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
285 for (int i = 0; i < 3; i++) {
286 Tester = endpoints.insert((Runner->second)->endpoints[i]);
287 if (Tester.second)
288 LOG(4, "DEBUG: Inserting endpoint " << *((Runner->second)->endpoints[i]));
289 }
290 }
291
292 return true;
293}
294;
295
296/** output operator for BoundaryPolygonSet.
297 * \param &ost output stream
298 * \param &a boundary polygon
299 */
300ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
301{
302 ost << "[" << a.Nr << "|";
303 for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
304 ost << (*Runner)->node->getName();
305 Runner++;
306 if (Runner != a.endpoints.end())
307 ost << ",";
308 }
309 ost << "]";
310 return ost;
311}
312;
313
Note: See TracBrowser for help on using the repository browser.