source: src/BoundaryLineSet.cpp@ 1a6bda

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

CodePatterns places all includes now in subfolder CodePatterns/.

  • change all includes accordingly.
  • this was necessary as Helpers and Patterns are not very distinctive names for include folders. Already now, we had a conflict between Helpers from CodePatterns and Helpers from this project.
  • changed compilation test in ax_codepatterns.m4 when changing CodePatterns includes.
  • Property mode set to 100644
File size: 10.6 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 * BoundaryLineSet.cpp
10 *
11 * Created on: Jul 29, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "BoundaryLineSet.hpp"
23
24#include <iostream>
25
26#include "BoundaryPointSet.hpp"
27#include "BoundaryTriangleSet.hpp"
28#include "TesselPoint.hpp"
29
30#include "CodePatterns/Assert.hpp"
31#include "CodePatterns/Info.hpp"
32#include "CodePatterns/Log.hpp"
33#include "CodePatterns/Verbose.hpp"
34#include "tesselationhelpers.hpp"
35#include "LinearAlgebra/Vector.hpp"
36
37using namespace std;
38
39/** Constructor of BoundaryLineSet.
40 */
41BoundaryLineSet::BoundaryLineSet() :
42 Nr(-1)
43{
44 Info FunctionInfo(__func__);
45 for (int i = 0; i < 2; i++)
46 endpoints[i] = NULL;
47}
48;
49
50/** Constructor of BoundaryLineSet with two endpoints.
51 * Adds line automatically to each endpoints' LineMap
52 * \param *Point[2] array of two boundary points
53 * \param number number of the list
54 */
55BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
56{
57 Info FunctionInfo(__func__);
58 // set number
59 Nr = number;
60 // set endpoints in ascending order
61 SetEndpointsOrdered(endpoints, Point[0], Point[1]);
62 // add this line to the hash maps of both endpoints
63 Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
64 Point[1]->AddLine(this); //
65 // set skipped to false
66 skipped = false;
67 // clear triangles list
68 DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
69}
70;
71
72/** Constructor of BoundaryLineSet with two endpoints.
73 * Adds line automatically to each endpoints' LineMap
74 * \param *Point1 first boundary point
75 * \param *Point2 second boundary point
76 * \param number number of the list
77 */
78BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number) :
79 Nr(number),
80 skipped(false)
81{
82 Info FunctionInfo(__func__);
83 // set endpoints in ascending order
84 SetEndpointsOrdered(endpoints, Point1, Point2);
85 // add this line to the hash maps of both endpoints
86 Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
87 Point2->AddLine(this); //
88 // clear triangles list
89 DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
90}
91;
92
93/** Destructor for BoundaryLineSet.
94 * Removes itself from each endpoints' LineMap, calling RemoveTrianglePoint() when point not connected anymore.
95 * \note When removing lines from a class Tesselation, use RemoveTesselationLine()
96 */
97BoundaryLineSet::~BoundaryLineSet()
98{
99 Info FunctionInfo(__func__);
100 int Numbers[2];
101
102 // get other endpoint number of finding copies of same line
103 if (endpoints[1] != NULL)
104 Numbers[0] = endpoints[1]->Nr;
105 else
106 Numbers[0] = -1;
107 if (endpoints[0] != NULL)
108 Numbers[1] = endpoints[0]->Nr;
109 else
110 Numbers[1] = -1;
111
112 for (int i = 0; i < 2; i++) {
113 if (endpoints[i] != NULL) {
114 if (Numbers[i] != -1) { // as there may be multiple lines with same endpoints, we have to go through each and find in the endpoint's line list this line set
115 pair<LineMap::iterator, LineMap::iterator> erasor = endpoints[i]->lines.equal_range(Numbers[i]);
116 for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
117 if ((*Runner).second == this) {
118 //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
119 endpoints[i]->lines.erase(Runner);
120 break;
121 }
122 } else { // there's just a single line left
123 if (endpoints[i]->lines.erase(Nr)) {
124 //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
125 }
126 }
127 if (endpoints[i]->lines.empty()) {
128 //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
129 if (endpoints[i] != NULL) {
130 delete (endpoints[i]);
131 endpoints[i] = NULL;
132 }
133 }
134 }
135 }
136 if (!triangles.empty())
137 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
138}
139;
140
141/** Add triangle to TriangleMap of this boundary line.
142 * \param *triangle to add
143 */
144void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
145{
146 Info FunctionInfo(__func__);
147 DoLog(0) && (Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl);
148 triangles.insert(TrianglePair(triangle->Nr, triangle));
149}
150;
151
152/** Checks whether we have a common endpoint with given \a *line.
153 * \param *line other line to test
154 * \return true - common endpoint present, false - not connected
155 */
156bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
157{
158 Info FunctionInfo(__func__);
159 if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
160 return true;
161 else
162 return false;
163}
164;
165
166/** Checks whether the adjacent triangles of a baseline are convex or not.
167 * We sum the two angles of each height vector with respect to the center of the baseline.
168 * If greater/equal M_PI than we are convex.
169 * \param *out output stream for debugging
170 * \return true - triangles are convex, false - concave or less than two triangles connected
171 */
172bool BoundaryLineSet::CheckConvexityCriterion() const
173{
174 Info FunctionInfo(__func__);
175 double angle = CalculateConvexity();
176 if (angle > -MYEPSILON) {
177 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
178 return true;
179 } else {
180 DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
181 return false;
182 }
183}
184
185
186/** Calculates the angle between two triangles with respect to their normal vector.
187 * We sum the two angles of each height vector with respect to the center of the baseline.
188 * \return angle > 0 then convex, if < 0 then concave
189 */
190double BoundaryLineSet::CalculateConvexity() const
191{
192 Info FunctionInfo(__func__);
193 Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
194 // get the two triangles
195 if (triangles.size() != 2) {
196 DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
197 return true;
198 }
199 // check normal vectors
200 // have a normal vector on the base line pointing outwards
201 //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
202 BaseLineCenter = (1./2.)*((endpoints[0]->node->getPosition()) + (endpoints[1]->node->getPosition()));
203 BaseLine = (endpoints[0]->node->getPosition()) - (endpoints[1]->node->getPosition());
204
205 //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
206
207 BaseLineNormal.Zero();
208 NormalCheck.Zero();
209 double sign = -1.;
210 int i = 0;
211 class BoundaryPointSet *node = NULL;
212 for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
213 //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
214 NormalCheck += runner->second->NormalVector;
215 NormalCheck *= sign;
216 sign = -sign;
217 if (runner->second->NormalVector.NormSquared() > MYEPSILON)
218 BaseLineNormal = runner->second->NormalVector; // yes, copy second on top of first
219 else {
220 DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
221 }
222 node = runner->second->GetThirdEndpoint(this);
223 if (node != NULL) {
224 //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
225 helper[i] = (node->node->getPosition()) - BaseLineCenter;
226 helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles!
227 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
228 i++;
229 } else {
230 DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
231 return true;
232 }
233 }
234 //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
235 if (NormalCheck.NormSquared() < MYEPSILON) {
236 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl);
237 return true;
238 }
239 BaseLineNormal.Scale(-1.);
240 double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
241 return (angle - M_PI);
242}
243
244/** Checks whether point is any of the two endpoints this line contains.
245 * \param *point point to test
246 * \return true - point is of the line, false - is not
247 */
248bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
249{
250 Info FunctionInfo(__func__);
251 for (int i = 0; i < 2; i++)
252 if (point == endpoints[i])
253 return true;
254 return false;
255}
256;
257
258/** Returns other endpoint of the line.
259 * \param *point other endpoint
260 * \return NULL - if endpoint not contained in BoundaryLineSet::lines, or pointer to BoundaryPointSet otherwise
261 */
262class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
263{
264 Info FunctionInfo(__func__);
265 if (endpoints[0] == point)
266 return endpoints[1];
267 else if (endpoints[1] == point)
268 return endpoints[0];
269 else
270 return NULL;
271}
272;
273
274/** Returns other triangle of the line.
275 * \param *point other endpoint
276 * \return NULL - if triangle not contained in BoundaryLineSet::triangles, or pointer to BoundaryTriangleSet otherwise
277 */
278class BoundaryTriangleSet *BoundaryLineSet::GetOtherTriangle(const BoundaryTriangleSet * const triangle) const
279{
280 Info FunctionInfo(__func__);
281 if (triangles.size() == 2) {
282 for (TriangleMap::const_iterator TriangleRunner = triangles.begin(); TriangleRunner != triangles.end(); ++TriangleRunner)
283 if (TriangleRunner->second != triangle)
284 return TriangleRunner->second;
285 }
286 return NULL;
287}
288;
289
290/** output operator for BoundaryLineSet.
291 * \param &ost output stream
292 * \param &a boundary line
293 */
294ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
295{
296 ost << "[" << a.Nr << "|" << a.endpoints[0]->node->getName() << " at " << a.endpoints[0]->node->getPosition() << "," << a.endpoints[1]->node->getName() << " at " << a.endpoints[1]->node->getPosition() << "]";
297 return ost;
298}
299;
Note: See TracBrowser for help on using the repository browser.