[357fba] | 1 | /*
|
---|
| 2 | * tesselation.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 3, 2009
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[f66195] | 10 | #include <fstream>
|
---|
[36166d] | 11 | #include <iomanip>
|
---|
[f66195] | 12 |
|
---|
[a2028e] | 13 | #include "helpers.hpp"
|
---|
[f67b6e] | 14 | #include "info.hpp"
|
---|
[57066a] | 15 | #include "linkedcell.hpp"
|
---|
[e138de] | 16 | #include "log.hpp"
|
---|
[357fba] | 17 | #include "tesselation.hpp"
|
---|
[57066a] | 18 | #include "tesselationhelpers.hpp"
|
---|
[8db598] | 19 | #include "triangleintersectionlist.hpp"
|
---|
[57066a] | 20 | #include "vector.hpp"
|
---|
[643e76] | 21 | #include "Line.hpp"
|
---|
[0a4f7f] | 22 | #include "vector_ops.hpp"
|
---|
[f66195] | 23 | #include "verbose.hpp"
|
---|
[0a4f7f] | 24 | #include "Plane.hpp"
|
---|
| 25 | #include "Exceptions/LinearDependenceException.hpp"
|
---|
[d4c9ae] | 26 | #include "Helpers/Assert.hpp"
|
---|
[57066a] | 27 |
|
---|
| 28 | class molecule;
|
---|
[357fba] | 29 |
|
---|
| 30 | // ======================================== Points on Boundary =================================
|
---|
| 31 |
|
---|
[16d866] | 32 | /** Constructor of BoundaryPointSet.
|
---|
| 33 | */
|
---|
[1e168b] | 34 | BoundaryPointSet::BoundaryPointSet() :
|
---|
[6613ec] | 35 | LinesCount(0), value(0.), Nr(-1)
|
---|
[357fba] | 36 | {
|
---|
[6613ec] | 37 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 38 | DoLog(1) && (Log() << Verbose(1) << "Adding noname." << endl);
|
---|
[6613ec] | 39 | }
|
---|
| 40 | ;
|
---|
[357fba] | 41 |
|
---|
[16d866] | 42 | /** Constructor of BoundaryPointSet with Tesselpoint.
|
---|
| 43 | * \param *Walker TesselPoint this boundary point represents
|
---|
| 44 | */
|
---|
[9473f6] | 45 | BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) :
|
---|
[6613ec] | 46 | LinesCount(0), node(Walker), value(0.), Nr(Walker->nr)
|
---|
[357fba] | 47 | {
|
---|
[6613ec] | 48 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 49 | DoLog(1) && (Log() << Verbose(1) << "Adding Node " << *Walker << endl);
|
---|
[6613ec] | 50 | }
|
---|
| 51 | ;
|
---|
[357fba] | 52 |
|
---|
[16d866] | 53 | /** Destructor of BoundaryPointSet.
|
---|
| 54 | * Sets node to NULL to avoid removing the original, represented TesselPoint.
|
---|
| 55 | * \note When removing point from a class Tesselation, use RemoveTesselationPoint()
|
---|
| 56 | */
|
---|
[357fba] | 57 | BoundaryPointSet::~BoundaryPointSet()
|
---|
| 58 | {
|
---|
[6613ec] | 59 | Info FunctionInfo(__func__);
|
---|
[f67b6e] | 60 | //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
|
---|
[357fba] | 61 | if (!lines.empty())
|
---|
[6613ec] | 62 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);
|
---|
[357fba] | 63 | node = NULL;
|
---|
[6613ec] | 64 | }
|
---|
| 65 | ;
|
---|
[357fba] | 66 |
|
---|
[16d866] | 67 | /** Add a line to the LineMap of this point.
|
---|
| 68 | * \param *line line to add
|
---|
| 69 | */
|
---|
[9473f6] | 70 | void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
|
---|
[357fba] | 71 | {
|
---|
[6613ec] | 72 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 73 | DoLog(1) && (Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl);
|
---|
[6613ec] | 74 | if (line->endpoints[0] == this) {
|
---|
| 75 | lines.insert(LinePair(line->endpoints[1]->Nr, line));
|
---|
| 76 | } else {
|
---|
| 77 | lines.insert(LinePair(line->endpoints[0]->Nr, line));
|
---|
| 78 | }
|
---|
[357fba] | 79 | LinesCount++;
|
---|
[6613ec] | 80 | }
|
---|
| 81 | ;
|
---|
[357fba] | 82 |
|
---|
[16d866] | 83 | /** output operator for BoundaryPointSet.
|
---|
| 84 | * \param &ost output stream
|
---|
| 85 | * \param &a boundary point
|
---|
| 86 | */
|
---|
[776b64] | 87 | ostream & operator <<(ostream &ost, const BoundaryPointSet &a)
|
---|
[357fba] | 88 | {
|
---|
[68f03d] | 89 | ost << "[" << a.Nr << "|" << a.node->getName() << " at " << *a.node->node << "]";
|
---|
[357fba] | 90 | return ost;
|
---|
| 91 | }
|
---|
| 92 | ;
|
---|
| 93 |
|
---|
| 94 | // ======================================== Lines on Boundary =================================
|
---|
| 95 |
|
---|
[16d866] | 96 | /** Constructor of BoundaryLineSet.
|
---|
| 97 | */
|
---|
[1e168b] | 98 | BoundaryLineSet::BoundaryLineSet() :
|
---|
[6613ec] | 99 | Nr(-1)
|
---|
[357fba] | 100 | {
|
---|
[6613ec] | 101 | Info FunctionInfo(__func__);
|
---|
[357fba] | 102 | for (int i = 0; i < 2; i++)
|
---|
| 103 | endpoints[i] = NULL;
|
---|
[6613ec] | 104 | }
|
---|
| 105 | ;
|
---|
[357fba] | 106 |
|
---|
[16d866] | 107 | /** Constructor of BoundaryLineSet with two endpoints.
|
---|
| 108 | * Adds line automatically to each endpoints' LineMap
|
---|
| 109 | * \param *Point[2] array of two boundary points
|
---|
| 110 | * \param number number of the list
|
---|
| 111 | */
|
---|
[9473f6] | 112 | BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
|
---|
[357fba] | 113 | {
|
---|
[6613ec] | 114 | Info FunctionInfo(__func__);
|
---|
[357fba] | 115 | // set number
|
---|
| 116 | Nr = number;
|
---|
| 117 | // set endpoints in ascending order
|
---|
| 118 | SetEndpointsOrdered(endpoints, Point[0], Point[1]);
|
---|
| 119 | // add this line to the hash maps of both endpoints
|
---|
| 120 | Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
|
---|
| 121 | Point[1]->AddLine(this); //
|
---|
[1e168b] | 122 | // set skipped to false
|
---|
| 123 | skipped = false;
|
---|
[357fba] | 124 | // clear triangles list
|
---|
[a67d19] | 125 | DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
|
---|
[6613ec] | 126 | }
|
---|
| 127 | ;
|
---|
[357fba] | 128 |
|
---|
[9473f6] | 129 | /** Constructor of BoundaryLineSet with two endpoints.
|
---|
| 130 | * Adds line automatically to each endpoints' LineMap
|
---|
| 131 | * \param *Point1 first boundary point
|
---|
| 132 | * \param *Point2 second boundary point
|
---|
| 133 | * \param number number of the list
|
---|
| 134 | */
|
---|
| 135 | BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number)
|
---|
| 136 | {
|
---|
| 137 | Info FunctionInfo(__func__);
|
---|
| 138 | // set number
|
---|
| 139 | Nr = number;
|
---|
| 140 | // set endpoints in ascending order
|
---|
| 141 | SetEndpointsOrdered(endpoints, Point1, Point2);
|
---|
| 142 | // add this line to the hash maps of both endpoints
|
---|
| 143 | Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
|
---|
| 144 | Point2->AddLine(this); //
|
---|
| 145 | // set skipped to false
|
---|
| 146 | skipped = false;
|
---|
| 147 | // clear triangles list
|
---|
[a67d19] | 148 | DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
|
---|
[6613ec] | 149 | }
|
---|
| 150 | ;
|
---|
[9473f6] | 151 |
|
---|
[16d866] | 152 | /** Destructor for BoundaryLineSet.
|
---|
| 153 | * Removes itself from each endpoints' LineMap, calling RemoveTrianglePoint() when point not connected anymore.
|
---|
| 154 | * \note When removing lines from a class Tesselation, use RemoveTesselationLine()
|
---|
| 155 | */
|
---|
[357fba] | 156 | BoundaryLineSet::~BoundaryLineSet()
|
---|
| 157 | {
|
---|
[6613ec] | 158 | Info FunctionInfo(__func__);
|
---|
[357fba] | 159 | int Numbers[2];
|
---|
[16d866] | 160 |
|
---|
| 161 | // get other endpoint number of finding copies of same line
|
---|
| 162 | if (endpoints[1] != NULL)
|
---|
| 163 | Numbers[0] = endpoints[1]->Nr;
|
---|
| 164 | else
|
---|
| 165 | Numbers[0] = -1;
|
---|
| 166 | if (endpoints[0] != NULL)
|
---|
| 167 | Numbers[1] = endpoints[0]->Nr;
|
---|
| 168 | else
|
---|
| 169 | Numbers[1] = -1;
|
---|
| 170 |
|
---|
[357fba] | 171 | for (int i = 0; i < 2; i++) {
|
---|
[16d866] | 172 | if (endpoints[i] != NULL) {
|
---|
| 173 | 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
|
---|
| 174 | pair<LineMap::iterator, LineMap::iterator> erasor = endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 175 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 176 | if ((*Runner).second == this) {
|
---|
[f67b6e] | 177 | //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[16d866] | 178 | endpoints[i]->lines.erase(Runner);
|
---|
| 179 | break;
|
---|
| 180 | }
|
---|
| 181 | } else { // there's just a single line left
|
---|
[57066a] | 182 | if (endpoints[i]->lines.erase(Nr)) {
|
---|
[f67b6e] | 183 | //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[57066a] | 184 | }
|
---|
[357fba] | 185 | }
|
---|
[16d866] | 186 | if (endpoints[i]->lines.empty()) {
|
---|
[f67b6e] | 187 | //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
|
---|
[16d866] | 188 | if (endpoints[i] != NULL) {
|
---|
[6613ec] | 189 | delete (endpoints[i]);
|
---|
[16d866] | 190 | endpoints[i] = NULL;
|
---|
| 191 | }
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
[357fba] | 194 | }
|
---|
| 195 | if (!triangles.empty())
|
---|
[6613ec] | 196 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
|
---|
| 197 | }
|
---|
| 198 | ;
|
---|
[357fba] | 199 |
|
---|
[16d866] | 200 | /** Add triangle to TriangleMap of this boundary line.
|
---|
| 201 | * \param *triangle to add
|
---|
| 202 | */
|
---|
[9473f6] | 203 | void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
|
---|
[357fba] | 204 | {
|
---|
[6613ec] | 205 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 206 | DoLog(0) && (Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl);
|
---|
[357fba] | 207 | triangles.insert(TrianglePair(triangle->Nr, triangle));
|
---|
[6613ec] | 208 | }
|
---|
| 209 | ;
|
---|
[357fba] | 210 |
|
---|
| 211 | /** Checks whether we have a common endpoint with given \a *line.
|
---|
| 212 | * \param *line other line to test
|
---|
| 213 | * \return true - common endpoint present, false - not connected
|
---|
| 214 | */
|
---|
[9473f6] | 215 | bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
|
---|
[357fba] | 216 | {
|
---|
[6613ec] | 217 | Info FunctionInfo(__func__);
|
---|
[357fba] | 218 | if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
|
---|
| 219 | return true;
|
---|
| 220 | else
|
---|
| 221 | return false;
|
---|
[6613ec] | 222 | }
|
---|
| 223 | ;
|
---|
[357fba] | 224 |
|
---|
| 225 | /** Checks whether the adjacent triangles of a baseline are convex or not.
|
---|
[57066a] | 226 | * We sum the two angles of each height vector with respect to the center of the baseline.
|
---|
[357fba] | 227 | * If greater/equal M_PI than we are convex.
|
---|
| 228 | * \param *out output stream for debugging
|
---|
| 229 | * \return true - triangles are convex, false - concave or less than two triangles connected
|
---|
| 230 | */
|
---|
[9473f6] | 231 | bool BoundaryLineSet::CheckConvexityCriterion() const
|
---|
[b32dbb] | 232 | {
|
---|
| 233 | Info FunctionInfo(__func__);
|
---|
| 234 | double angle = CalculateConvexity();
|
---|
| 235 | if (angle > -MYEPSILON) {
|
---|
| 236 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
|
---|
| 237 | return true;
|
---|
| 238 | } else {
|
---|
| 239 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
|
---|
| 240 | return false;
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 | /** Calculates the angle between two triangles with respect to their normal vector.
|
---|
| 246 | * We sum the two angles of each height vector with respect to the center of the baseline.
|
---|
| 247 | * \return angle > 0 then convex, if < 0 then concave
|
---|
| 248 | */
|
---|
| 249 | double BoundaryLineSet::CalculateConvexity() const
|
---|
[357fba] | 250 | {
|
---|
[6613ec] | 251 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 252 | Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
|
---|
[357fba] | 253 | // get the two triangles
|
---|
[5c7bf8] | 254 | if (triangles.size() != 2) {
|
---|
[6613ec] | 255 | DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
|
---|
[1d9b7aa] | 256 | return true;
|
---|
[357fba] | 257 | }
|
---|
[5c7bf8] | 258 | // check normal vectors
|
---|
[357fba] | 259 | // have a normal vector on the base line pointing outwards
|
---|
[f67b6e] | 260 | //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
|
---|
[273382] | 261 | BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node));
|
---|
| 262 | BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node);
|
---|
[8cbb97] | 263 |
|
---|
[f67b6e] | 264 | //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
|
---|
[357fba] | 265 |
|
---|
[62bb91] | 266 | BaseLineNormal.Zero();
|
---|
[5c7bf8] | 267 | NormalCheck.Zero();
|
---|
| 268 | double sign = -1.;
|
---|
[6613ec] | 269 | int i = 0;
|
---|
[62bb91] | 270 | class BoundaryPointSet *node = NULL;
|
---|
[6613ec] | 271 | for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
|
---|
[f67b6e] | 272 | //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
|
---|
[273382] | 273 | NormalCheck += runner->second->NormalVector;
|
---|
| 274 | NormalCheck *= sign;
|
---|
[5c7bf8] | 275 | sign = -sign;
|
---|
[57066a] | 276 | if (runner->second->NormalVector.NormSquared() > MYEPSILON)
|
---|
[273382] | 277 | BaseLineNormal = runner->second->NormalVector; // yes, copy second on top of first
|
---|
[57066a] | 278 | else {
|
---|
[6613ec] | 279 | DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
|
---|
[57066a] | 280 | }
|
---|
[62bb91] | 281 | node = runner->second->GetThirdEndpoint(this);
|
---|
| 282 | if (node != NULL) {
|
---|
[f67b6e] | 283 | //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
|
---|
[273382] | 284 | helper[i] = (*node->node->node) - BaseLineCenter;
|
---|
[0a4f7f] | 285 | helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles!
|
---|
[f67b6e] | 286 | //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
|
---|
[62bb91] | 287 | i++;
|
---|
| 288 | } else {
|
---|
[6613ec] | 289 | DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
|
---|
[62bb91] | 290 | return true;
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
[f67b6e] | 293 | //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
|
---|
[5c7bf8] | 294 | if (NormalCheck.NormSquared() < MYEPSILON) {
|
---|
[a67d19] | 295 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl);
|
---|
[5c7bf8] | 296 | return true;
|
---|
[62bb91] | 297 | }
|
---|
[57066a] | 298 | BaseLineNormal.Scale(-1.);
|
---|
[f1cccd] | 299 | double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
|
---|
[b32dbb] | 300 | return (angle - M_PI);
|
---|
[357fba] | 301 | }
|
---|
| 302 |
|
---|
| 303 | /** Checks whether point is any of the two endpoints this line contains.
|
---|
| 304 | * \param *point point to test
|
---|
| 305 | * \return true - point is of the line, false - is not
|
---|
| 306 | */
|
---|
[9473f6] | 307 | bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
[357fba] | 308 | {
|
---|
[6613ec] | 309 | Info FunctionInfo(__func__);
|
---|
| 310 | for (int i = 0; i < 2; i++)
|
---|
[357fba] | 311 | if (point == endpoints[i])
|
---|
| 312 | return true;
|
---|
| 313 | return false;
|
---|
[6613ec] | 314 | }
|
---|
| 315 | ;
|
---|
[357fba] | 316 |
|
---|
[62bb91] | 317 | /** Returns other endpoint of the line.
|
---|
| 318 | * \param *point other endpoint
|
---|
[b32dbb] | 319 | * \return NULL - if endpoint not contained in BoundaryLineSet::lines, or pointer to BoundaryPointSet otherwise
|
---|
[62bb91] | 320 | */
|
---|
[9473f6] | 321 | class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
|
---|
[62bb91] | 322 | {
|
---|
[6613ec] | 323 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 324 | if (endpoints[0] == point)
|
---|
| 325 | return endpoints[1];
|
---|
| 326 | else if (endpoints[1] == point)
|
---|
| 327 | return endpoints[0];
|
---|
| 328 | else
|
---|
| 329 | return NULL;
|
---|
[6613ec] | 330 | }
|
---|
| 331 | ;
|
---|
[62bb91] | 332 |
|
---|
[b32dbb] | 333 | /** Returns other triangle of the line.
|
---|
| 334 | * \param *point other endpoint
|
---|
| 335 | * \return NULL - if triangle not contained in BoundaryLineSet::triangles, or pointer to BoundaryTriangleSet otherwise
|
---|
| 336 | */
|
---|
| 337 | class BoundaryTriangleSet *BoundaryLineSet::GetOtherTriangle(const BoundaryTriangleSet * const triangle) const
|
---|
| 338 | {
|
---|
| 339 | Info FunctionInfo(__func__);
|
---|
| 340 | if (triangles.size() == 2) {
|
---|
| 341 | for (TriangleMap::const_iterator TriangleRunner = triangles.begin(); TriangleRunner != triangles.end(); ++TriangleRunner)
|
---|
| 342 | if (TriangleRunner->second != triangle)
|
---|
| 343 | return TriangleRunner->second;
|
---|
| 344 | }
|
---|
| 345 | return NULL;
|
---|
| 346 | }
|
---|
| 347 | ;
|
---|
| 348 |
|
---|
[16d866] | 349 | /** output operator for BoundaryLineSet.
|
---|
| 350 | * \param &ost output stream
|
---|
| 351 | * \param &a boundary line
|
---|
| 352 | */
|
---|
[6613ec] | 353 | ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
|
---|
[357fba] | 354 | {
|
---|
[68f03d] | 355 | ost << "[" << a.Nr << "|" << a.endpoints[0]->node->getName() << " at " << *a.endpoints[0]->node->node << "," << a.endpoints[1]->node->getName() << " at " << *a.endpoints[1]->node->node << "]";
|
---|
[357fba] | 356 | return ost;
|
---|
[6613ec] | 357 | }
|
---|
| 358 | ;
|
---|
[357fba] | 359 |
|
---|
| 360 | // ======================================== Triangles on Boundary =================================
|
---|
| 361 |
|
---|
[16d866] | 362 | /** Constructor for BoundaryTriangleSet.
|
---|
| 363 | */
|
---|
[1e168b] | 364 | BoundaryTriangleSet::BoundaryTriangleSet() :
|
---|
| 365 | Nr(-1)
|
---|
[357fba] | 366 | {
|
---|
[6613ec] | 367 | Info FunctionInfo(__func__);
|
---|
| 368 | for (int i = 0; i < 3; i++) {
|
---|
| 369 | endpoints[i] = NULL;
|
---|
| 370 | lines[i] = NULL;
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
| 373 | ;
|
---|
[357fba] | 374 |
|
---|
[16d866] | 375 | /** Constructor for BoundaryTriangleSet with three lines.
|
---|
| 376 | * \param *line[3] lines that make up the triangle
|
---|
| 377 | * \param number number of triangle
|
---|
| 378 | */
|
---|
[9473f6] | 379 | BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
|
---|
[1e168b] | 380 | Nr(number)
|
---|
[357fba] | 381 | {
|
---|
[6613ec] | 382 | Info FunctionInfo(__func__);
|
---|
[357fba] | 383 | // set number
|
---|
| 384 | // set lines
|
---|
[f67b6e] | 385 | for (int i = 0; i < 3; i++) {
|
---|
| 386 | lines[i] = line[i];
|
---|
| 387 | lines[i]->AddTriangle(this);
|
---|
| 388 | }
|
---|
[357fba] | 389 | // get ascending order of endpoints
|
---|
[f67b6e] | 390 | PointMap OrderMap;
|
---|
[a7b761b] | 391 | for (int i = 0; i < 3; i++) {
|
---|
[357fba] | 392 | // for all three lines
|
---|
[f67b6e] | 393 | for (int j = 0; j < 2; j++) { // for both endpoints
|
---|
[6613ec] | 394 | OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
|
---|
[f67b6e] | 395 | // and we don't care whether insertion fails
|
---|
| 396 | }
|
---|
[a7b761b] | 397 | }
|
---|
[357fba] | 398 | // set endpoints
|
---|
| 399 | int Counter = 0;
|
---|
[a67d19] | 400 | DoLog(0) && (Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl);
|
---|
[f67b6e] | 401 | for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
|
---|
| 402 | endpoints[Counter] = runner->second;
|
---|
[a67d19] | 403 | DoLog(0) && (Log() << Verbose(0) << " " << *endpoints[Counter] << endl);
|
---|
[f67b6e] | 404 | Counter++;
|
---|
| 405 | }
|
---|
[8d2772] | 406 | ASSERT(Counter >= 3,"We have a triangle with only two distinct endpoints!");
|
---|
[16d866] | 407 | };
|
---|
[357fba] | 408 |
|
---|
| 409 |
|
---|
[16d866] | 410 | /** Destructor of BoundaryTriangleSet.
|
---|
| 411 | * Removes itself from each of its lines' LineMap and removes them if necessary.
|
---|
| 412 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 413 | */
|
---|
[357fba] | 414 | BoundaryTriangleSet::~BoundaryTriangleSet()
|
---|
| 415 | {
|
---|
[6613ec] | 416 | Info FunctionInfo(__func__);
|
---|
[357fba] | 417 | for (int i = 0; i < 3; i++) {
|
---|
[16d866] | 418 | if (lines[i] != NULL) {
|
---|
[57066a] | 419 | if (lines[i]->triangles.erase(Nr)) {
|
---|
[f67b6e] | 420 | //Log() << Verbose(0) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
|
---|
[57066a] | 421 | }
|
---|
[16d866] | 422 | if (lines[i]->triangles.empty()) {
|
---|
[6613ec] | 423 | //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
|
---|
| 424 | delete (lines[i]);
|
---|
| 425 | lines[i] = NULL;
|
---|
[16d866] | 426 | }
|
---|
| 427 | }
|
---|
[357fba] | 428 | }
|
---|
[f67b6e] | 429 | //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
|
---|
[6613ec] | 430 | }
|
---|
| 431 | ;
|
---|
[357fba] | 432 |
|
---|
| 433 | /** Calculates the normal vector for this triangle.
|
---|
| 434 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 435 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 436 | */
|
---|
[9473f6] | 437 | void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
|
---|
[357fba] | 438 | {
|
---|
[6613ec] | 439 | Info FunctionInfo(__func__);
|
---|
[357fba] | 440 | // get normal vector
|
---|
[0a4f7f] | 441 | NormalVector = Plane(*(endpoints[0]->node->node),
|
---|
| 442 | *(endpoints[1]->node->node),
|
---|
| 443 | *(endpoints[2]->node->node)).getNormal();
|
---|
[357fba] | 444 |
|
---|
| 445 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
[273382] | 446 | if (NormalVector.ScalarProduct(OtherVector) > 0.)
|
---|
[357fba] | 447 | NormalVector.Scale(-1.);
|
---|
[a67d19] | 448 | DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl);
|
---|
[6613ec] | 449 | }
|
---|
| 450 | ;
|
---|
[357fba] | 451 |
|
---|
[97498a] | 452 | /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
|
---|
[357fba] | 453 | * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
|
---|
[9473f6] | 454 | * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
[7dea7c] | 455 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 456 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 457 | * the first two basepoints) or not.
|
---|
[357fba] | 458 | * \param *out output stream for debugging
|
---|
| 459 | * \param *MolCenter offset vector of line
|
---|
| 460 | * \param *x second endpoint of line, minus \a *MolCenter is directional vector of line
|
---|
| 461 | * \param *Intersection intersection on plane on return
|
---|
| 462 | * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
|
---|
| 463 | */
|
---|
[8cbb97] | 464 |
|
---|
[9473f6] | 465 | bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
|
---|
[357fba] | 466 | {
|
---|
[fee69b] | 467 | Info FunctionInfo(__func__);
|
---|
[357fba] | 468 | Vector CrossPoint;
|
---|
| 469 | Vector helper;
|
---|
| 470 |
|
---|
[0a4f7f] | 471 | try {
|
---|
[27ac00] | 472 | Line centerLine = makeLineThrough(*MolCenter, *x);
|
---|
| 473 | *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(centerLine);
|
---|
[357fba] | 474 |
|
---|
[215df0] | 475 | DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl);
|
---|
| 476 | DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl);
|
---|
| 477 | DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
|
---|
[97498a] | 478 |
|
---|
[215df0] | 479 | if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) {
|
---|
| 480 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
|
---|
| 481 | return true;
|
---|
| 482 | } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) {
|
---|
| 483 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
|
---|
| 484 | return true;
|
---|
| 485 | } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) {
|
---|
| 486 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
|
---|
| 487 | return true;
|
---|
| 488 | }
|
---|
| 489 | // Calculate cross point between one baseline and the line from the third endpoint to intersection
|
---|
| 490 | int i = 0;
|
---|
| 491 | do {
|
---|
[643e76] | 492 | Line line1 = makeLineThrough(*(endpoints[i%3]->node->node),*(endpoints[(i+1)%3]->node->node));
|
---|
| 493 | Line line2 = makeLineThrough(*(endpoints[(i+2)%3]->node->node),*Intersection);
|
---|
| 494 | CrossPoint = line1.getIntersection(line2);
|
---|
[273382] | 495 | helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
|
---|
| 496 | CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
| 497 | const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared();
|
---|
[a67d19] | 498 | DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl);
|
---|
[fee69b] | 499 | if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
|
---|
[a67d19] | 500 | DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
|
---|
[215df0] | 501 | return false;
|
---|
[fee69b] | 502 | }
|
---|
[5c7bf8] | 503 | i++;
|
---|
[215df0] | 504 | } while (i < 3);
|
---|
[a67d19] | 505 | DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl);
|
---|
[357fba] | 506 | return true;
|
---|
[215df0] | 507 | }
|
---|
| 508 | catch (MathException &excp) {
|
---|
| 509 | Log() << Verbose(1) << excp;
|
---|
| 510 | DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
|
---|
[357fba] | 511 | return false;
|
---|
| 512 | }
|
---|
[6613ec] | 513 | }
|
---|
| 514 | ;
|
---|
[357fba] | 515 |
|
---|
[8db598] | 516 | /** Finds the point on the triangle to the point \a *x.
|
---|
| 517 | * We call Vector::GetIntersectionWithPlane() with \a * and the center of the triangle to receive an intersection point.
|
---|
| 518 | * Then we check the in-plane part (the part projected down onto plane). We check whether it crosses one of the
|
---|
| 519 | * boundary lines. If it does, we return this intersection as closest point, otherwise the projected point down.
|
---|
[9473f6] | 520 | * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
| 521 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 522 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 523 | * the first two basepoints) or not.
|
---|
| 524 | * \param *x point
|
---|
| 525 | * \param *ClosestPoint desired closest point inside triangle to \a *x, is absolute vector
|
---|
| 526 | * \return Distance squared between \a *x and closest point inside triangle
|
---|
| 527 | */
|
---|
| 528 | double BoundaryTriangleSet::GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const
|
---|
| 529 | {
|
---|
| 530 | Info FunctionInfo(__func__);
|
---|
| 531 | Vector Direction;
|
---|
| 532 |
|
---|
| 533 | // 1. get intersection with plane
|
---|
[a67d19] | 534 | DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl);
|
---|
[9473f6] | 535 | GetCenter(&Direction);
|
---|
[0a4f7f] | 536 | try {
|
---|
[27ac00] | 537 | Line l = makeLineThrough(*x, Direction);
|
---|
| 538 | *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(l);
|
---|
[0a4f7f] | 539 | }
|
---|
[27ac00] | 540 | catch (MathException &excp) {
|
---|
[273382] | 541 | (*ClosestPoint) = (*x);
|
---|
[9473f6] | 542 | }
|
---|
| 543 |
|
---|
| 544 | // 2. Calculate in plane part of line (x, intersection)
|
---|
[273382] | 545 | Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point
|
---|
| 546 | InPlane.ProjectOntoPlane(NormalVector);
|
---|
| 547 | InPlane += *ClosestPoint;
|
---|
[9473f6] | 548 |
|
---|
[a67d19] | 549 | DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl);
|
---|
| 550 | DoLog(2) && (Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl);
|
---|
| 551 | DoLog(2) && (Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl);
|
---|
[9473f6] | 552 |
|
---|
| 553 | // Calculate cross point between one baseline and the desired point such that distance is shortest
|
---|
| 554 | double ShortestDistance = -1.;
|
---|
| 555 | bool InsideFlag = false;
|
---|
| 556 | Vector CrossDirection[3];
|
---|
| 557 | Vector CrossPoint[3];
|
---|
| 558 | Vector helper;
|
---|
[6613ec] | 559 | for (int i = 0; i < 3; i++) {
|
---|
[9473f6] | 560 | // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
|
---|
[273382] | 561 | Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
|
---|
[9473f6] | 562 | // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
|
---|
[27ac00] | 563 | Line l = makeLineThrough(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
|
---|
| 564 | CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(l);
|
---|
[273382] | 565 | CrossDirection[i] = CrossPoint[i] - InPlane;
|
---|
| 566 | CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
| 567 | const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared();
|
---|
[a67d19] | 568 | DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl);
|
---|
[9473f6] | 569 | if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
|
---|
[8cbb97] | 570 | CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again
|
---|
[a67d19] | 571 | DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl);
|
---|
[273382] | 572 | const double distance = CrossPoint[i].DistanceSquared(*x);
|
---|
[9473f6] | 573 | if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
|
---|
| 574 | ShortestDistance = distance;
|
---|
[273382] | 575 | (*ClosestPoint) = CrossPoint[i];
|
---|
[9473f6] | 576 | }
|
---|
| 577 | } else
|
---|
| 578 | CrossPoint[i].Zero();
|
---|
| 579 | }
|
---|
| 580 | InsideFlag = true;
|
---|
[6613ec] | 581 | for (int i = 0; i < 3; i++) {
|
---|
[8cbb97] | 582 | const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 1) % 3]);
|
---|
| 583 | const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 2) % 3]);
|
---|
| 584 |
|
---|
[6613ec] | 585 | if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
|
---|
[9473f6] | 586 | InsideFlag = false;
|
---|
| 587 | }
|
---|
| 588 | if (InsideFlag) {
|
---|
[273382] | 589 | (*ClosestPoint) = InPlane;
|
---|
| 590 | ShortestDistance = InPlane.DistanceSquared(*x);
|
---|
[6613ec] | 591 | } else { // also check endnodes
|
---|
| 592 | for (int i = 0; i < 3; i++) {
|
---|
[273382] | 593 | const double distance = x->DistanceSquared(*endpoints[i]->node->node);
|
---|
[9473f6] | 594 | if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
|
---|
| 595 | ShortestDistance = distance;
|
---|
[273382] | 596 | (*ClosestPoint) = (*endpoints[i]->node->node);
|
---|
[9473f6] | 597 | }
|
---|
| 598 | }
|
---|
| 599 | }
|
---|
[a67d19] | 600 | DoLog(1) && (Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl);
|
---|
[9473f6] | 601 | return ShortestDistance;
|
---|
[6613ec] | 602 | }
|
---|
| 603 | ;
|
---|
[9473f6] | 604 |
|
---|
[357fba] | 605 | /** Checks whether lines is any of the three boundary lines this triangle contains.
|
---|
| 606 | * \param *line line to test
|
---|
| 607 | * \return true - line is of the triangle, false - is not
|
---|
| 608 | */
|
---|
[9473f6] | 609 | bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
|
---|
[357fba] | 610 | {
|
---|
[6613ec] | 611 | Info FunctionInfo(__func__);
|
---|
| 612 | for (int i = 0; i < 3; i++)
|
---|
[357fba] | 613 | if (line == lines[i])
|
---|
| 614 | return true;
|
---|
| 615 | return false;
|
---|
[6613ec] | 616 | }
|
---|
| 617 | ;
|
---|
[357fba] | 618 |
|
---|
| 619 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 620 | * \param *point point to test
|
---|
| 621 | * \return true - point is of the triangle, false - is not
|
---|
| 622 | */
|
---|
[9473f6] | 623 | bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
[357fba] | 624 | {
|
---|
[6613ec] | 625 | Info FunctionInfo(__func__);
|
---|
| 626 | for (int i = 0; i < 3; i++)
|
---|
[357fba] | 627 | if (point == endpoints[i])
|
---|
| 628 | return true;
|
---|
| 629 | return false;
|
---|
[6613ec] | 630 | }
|
---|
| 631 | ;
|
---|
[357fba] | 632 |
|
---|
[7dea7c] | 633 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 634 | * \param *point TesselPoint to test
|
---|
| 635 | * \return true - point is of the triangle, false - is not
|
---|
| 636 | */
|
---|
[9473f6] | 637 | bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
|
---|
[7dea7c] | 638 | {
|
---|
[6613ec] | 639 | Info FunctionInfo(__func__);
|
---|
| 640 | for (int i = 0; i < 3; i++)
|
---|
[7dea7c] | 641 | if (point == endpoints[i]->node)
|
---|
| 642 | return true;
|
---|
| 643 | return false;
|
---|
[6613ec] | 644 | }
|
---|
| 645 | ;
|
---|
[7dea7c] | 646 |
|
---|
[357fba] | 647 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 648 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 649 | * \return true - is the very triangle, false - is not
|
---|
| 650 | */
|
---|
[9473f6] | 651 | bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
|
---|
[357fba] | 652 | {
|
---|
[6613ec] | 653 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 654 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl);
|
---|
[6613ec] | 655 | return (((endpoints[0] == Points[0]) || (endpoints[0] == Points[1]) || (endpoints[0] == Points[2])) && ((endpoints[1] == Points[0]) || (endpoints[1] == Points[1]) || (endpoints[1] == Points[2])) && ((endpoints[2] == Points[0]) || (endpoints[2] == Points[1]) || (endpoints[2] == Points[2])
|
---|
| 656 |
|
---|
| 657 | ));
|
---|
| 658 | }
|
---|
| 659 | ;
|
---|
[357fba] | 660 |
|
---|
[57066a] | 661 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 662 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 663 | * \return true - is the very triangle, false - is not
|
---|
| 664 | */
|
---|
[9473f6] | 665 | bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
|
---|
[57066a] | 666 | {
|
---|
[6613ec] | 667 | Info FunctionInfo(__func__);
|
---|
| 668 | return (((endpoints[0] == T->endpoints[0]) || (endpoints[0] == T->endpoints[1]) || (endpoints[0] == T->endpoints[2])) && ((endpoints[1] == T->endpoints[0]) || (endpoints[1] == T->endpoints[1]) || (endpoints[1] == T->endpoints[2])) && ((endpoints[2] == T->endpoints[0]) || (endpoints[2] == T->endpoints[1]) || (endpoints[2] == T->endpoints[2])
|
---|
| 669 |
|
---|
| 670 | ));
|
---|
| 671 | }
|
---|
| 672 | ;
|
---|
[57066a] | 673 |
|
---|
[62bb91] | 674 | /** Returns the endpoint which is not contained in the given \a *line.
|
---|
| 675 | * \param *line baseline defining two endpoints
|
---|
| 676 | * \return pointer third endpoint or NULL if line does not belong to triangle.
|
---|
| 677 | */
|
---|
[9473f6] | 678 | class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
|
---|
[62bb91] | 679 | {
|
---|
[6613ec] | 680 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 681 | // sanity check
|
---|
| 682 | if (!ContainsBoundaryLine(line))
|
---|
| 683 | return NULL;
|
---|
[6613ec] | 684 | for (int i = 0; i < 3; i++)
|
---|
[62bb91] | 685 | if (!line->ContainsBoundaryPoint(endpoints[i]))
|
---|
| 686 | return endpoints[i];
|
---|
| 687 | // actually, that' impossible :)
|
---|
| 688 | return NULL;
|
---|
[6613ec] | 689 | }
|
---|
| 690 | ;
|
---|
[62bb91] | 691 |
|
---|
[b32dbb] | 692 | /** Returns the baseline which does not contain the given boundary point \a *point.
|
---|
| 693 | * \param *point endpoint which is neither endpoint of the desired line
|
---|
| 694 | * \return pointer to desired third baseline
|
---|
| 695 | */
|
---|
| 696 | class BoundaryLineSet *BoundaryTriangleSet::GetThirdLine(const BoundaryPointSet * const point) const
|
---|
| 697 | {
|
---|
| 698 | Info FunctionInfo(__func__);
|
---|
| 699 | // sanity check
|
---|
| 700 | if (!ContainsBoundaryPoint(point))
|
---|
| 701 | return NULL;
|
---|
| 702 | for (int i = 0; i < 3; i++)
|
---|
| 703 | if (!lines[i]->ContainsBoundaryPoint(point))
|
---|
| 704 | return lines[i];
|
---|
| 705 | // actually, that' impossible :)
|
---|
| 706 | return NULL;
|
---|
| 707 | }
|
---|
| 708 | ;
|
---|
| 709 |
|
---|
[62bb91] | 710 | /** Calculates the center point of the triangle.
|
---|
| 711 | * Is third of the sum of all endpoints.
|
---|
| 712 | * \param *center central point on return.
|
---|
| 713 | */
|
---|
[9473f6] | 714 | void BoundaryTriangleSet::GetCenter(Vector * const center) const
|
---|
[62bb91] | 715 | {
|
---|
[6613ec] | 716 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 717 | center->Zero();
|
---|
[6613ec] | 718 | for (int i = 0; i < 3; i++)
|
---|
[273382] | 719 | (*center) += (*endpoints[i]->node->node);
|
---|
[6613ec] | 720 | center->Scale(1. / 3.);
|
---|
[a67d19] | 721 | DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl);
|
---|
[62bb91] | 722 | }
|
---|
| 723 |
|
---|
[d4c9ae] | 724 | /**
|
---|
| 725 | * gets the Plane defined by the three triangle Basepoints
|
---|
| 726 | */
|
---|
| 727 | Plane BoundaryTriangleSet::getPlane() const{
|
---|
| 728 | ASSERT(endpoints[0] && endpoints[1] && endpoints[2], "Triangle not fully defined");
|
---|
| 729 |
|
---|
| 730 | return Plane(*endpoints[0]->node->node,
|
---|
| 731 | *endpoints[1]->node->node,
|
---|
| 732 | *endpoints[2]->node->node);
|
---|
| 733 | }
|
---|
| 734 |
|
---|
[8f215d] | 735 | Vector BoundaryTriangleSet::getEndpoint(int i) const{
|
---|
| 736 | ASSERT(i>=0 && i<3,"Index of Endpoint out of Range");
|
---|
| 737 |
|
---|
| 738 | return *endpoints[i]->node->node;
|
---|
| 739 | }
|
---|
| 740 |
|
---|
| 741 | string BoundaryTriangleSet::getEndpointName(int i) const{
|
---|
| 742 | ASSERT(i>=0 && i<3,"Index of Endpoint out of Range");
|
---|
| 743 |
|
---|
| 744 | return endpoints[i]->node->getName();
|
---|
| 745 | }
|
---|
| 746 |
|
---|
[16d866] | 747 | /** output operator for BoundaryTriangleSet.
|
---|
| 748 | * \param &ost output stream
|
---|
| 749 | * \param &a boundary triangle
|
---|
| 750 | */
|
---|
[776b64] | 751 | ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
|
---|
[357fba] | 752 | {
|
---|
[8f215d] | 753 | ost << "[" << a.Nr << "|" << a.getEndpointName(0) << "," << a.getEndpointName(1) << "," << a.getEndpointName(2) << "]";
|
---|
[6613ec] | 754 | // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
|
---|
| 755 | // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
|
---|
[357fba] | 756 | return ost;
|
---|
[6613ec] | 757 | }
|
---|
| 758 | ;
|
---|
[357fba] | 759 |
|
---|
[262bae] | 760 | // ======================================== Polygons on Boundary =================================
|
---|
| 761 |
|
---|
| 762 | /** Constructor for BoundaryPolygonSet.
|
---|
| 763 | */
|
---|
| 764 | BoundaryPolygonSet::BoundaryPolygonSet() :
|
---|
| 765 | Nr(-1)
|
---|
| 766 | {
|
---|
| 767 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 768 | }
|
---|
| 769 | ;
|
---|
[262bae] | 770 |
|
---|
| 771 | /** Destructor of BoundaryPolygonSet.
|
---|
| 772 | * Just clears endpoints.
|
---|
| 773 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 774 | */
|
---|
| 775 | BoundaryPolygonSet::~BoundaryPolygonSet()
|
---|
| 776 | {
|
---|
| 777 | Info FunctionInfo(__func__);
|
---|
| 778 | endpoints.clear();
|
---|
[a67d19] | 779 | DoLog(1) && (Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl);
|
---|
[6613ec] | 780 | }
|
---|
| 781 | ;
|
---|
[262bae] | 782 |
|
---|
| 783 | /** Calculates the normal vector for this triangle.
|
---|
| 784 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 785 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 786 | * \return allocated vector in normal direction
|
---|
| 787 | */
|
---|
| 788 | Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
|
---|
| 789 | {
|
---|
| 790 | Info FunctionInfo(__func__);
|
---|
| 791 | // get normal vector
|
---|
| 792 | Vector TemporaryNormal;
|
---|
| 793 | Vector *TotalNormal = new Vector;
|
---|
| 794 | PointSet::const_iterator Runner[3];
|
---|
[6613ec] | 795 | for (int i = 0; i < 3; i++) {
|
---|
[262bae] | 796 | Runner[i] = endpoints.begin();
|
---|
[6613ec] | 797 | for (int j = 0; j < i; j++) { // go as much further
|
---|
[262bae] | 798 | Runner[i]++;
|
---|
| 799 | if (Runner[i] == endpoints.end()) {
|
---|
[6613ec] | 800 | DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
|
---|
[262bae] | 801 | performCriticalExit();
|
---|
| 802 | }
|
---|
| 803 | }
|
---|
| 804 | }
|
---|
| 805 | TotalNormal->Zero();
|
---|
[6613ec] | 806 | int counter = 0;
|
---|
| 807 | for (; Runner[2] != endpoints.end();) {
|
---|
[0a4f7f] | 808 | TemporaryNormal = Plane(*((*Runner[0])->node->node),
|
---|
| 809 | *((*Runner[1])->node->node),
|
---|
| 810 | *((*Runner[2])->node->node)).getNormal();
|
---|
[6613ec] | 811 | for (int i = 0; i < 3; i++) // increase each of them
|
---|
[262bae] | 812 | Runner[i]++;
|
---|
[273382] | 813 | (*TotalNormal) += TemporaryNormal;
|
---|
[262bae] | 814 | }
|
---|
[6613ec] | 815 | TotalNormal->Scale(1. / (double) counter);
|
---|
[262bae] | 816 |
|
---|
| 817 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
[273382] | 818 | if (TotalNormal->ScalarProduct(OtherVector) > 0.)
|
---|
[262bae] | 819 | TotalNormal->Scale(-1.);
|
---|
[a67d19] | 820 | DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
|
---|
[262bae] | 821 |
|
---|
| 822 | return TotalNormal;
|
---|
[6613ec] | 823 | }
|
---|
| 824 | ;
|
---|
[262bae] | 825 |
|
---|
| 826 | /** Calculates the center point of the triangle.
|
---|
| 827 | * Is third of the sum of all endpoints.
|
---|
| 828 | * \param *center central point on return.
|
---|
| 829 | */
|
---|
| 830 | void BoundaryPolygonSet::GetCenter(Vector * const center) const
|
---|
| 831 | {
|
---|
| 832 | Info FunctionInfo(__func__);
|
---|
| 833 | center->Zero();
|
---|
| 834 | int counter = 0;
|
---|
| 835 | for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[273382] | 836 | (*center) += (*(*Runner)->node->node);
|
---|
[262bae] | 837 | counter++;
|
---|
| 838 | }
|
---|
[6613ec] | 839 | center->Scale(1. / (double) counter);
|
---|
[a67d19] | 840 | DoLog(1) && (Log() << Verbose(1) << "Center is at " << *center << "." << endl);
|
---|
[262bae] | 841 | }
|
---|
| 842 |
|
---|
| 843 | /** Checks whether the polygons contains all three endpoints of the triangle.
|
---|
| 844 | * \param *triangle triangle to test
|
---|
| 845 | * \return true - triangle is contained polygon, false - is not
|
---|
| 846 | */
|
---|
| 847 | bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
|
---|
| 848 | {
|
---|
| 849 | Info FunctionInfo(__func__);
|
---|
| 850 | return ContainsPresentTupel(triangle->endpoints, 3);
|
---|
[6613ec] | 851 | }
|
---|
| 852 | ;
|
---|
[262bae] | 853 |
|
---|
| 854 | /** Checks whether the polygons contains both endpoints of the line.
|
---|
| 855 | * \param *line line to test
|
---|
| 856 | * \return true - line is of the triangle, false - is not
|
---|
| 857 | */
|
---|
| 858 | bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
|
---|
| 859 | {
|
---|
[856098] | 860 | Info FunctionInfo(__func__);
|
---|
[262bae] | 861 | return ContainsPresentTupel(line->endpoints, 2);
|
---|
[6613ec] | 862 | }
|
---|
| 863 | ;
|
---|
[262bae] | 864 |
|
---|
| 865 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 866 | * \param *point point to test
|
---|
| 867 | * \return true - point is of the triangle, false - is not
|
---|
| 868 | */
|
---|
| 869 | bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
| 870 | {
|
---|
| 871 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 872 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[a67d19] | 873 | DoLog(0) && (Log() << Verbose(0) << "Checking against " << **Runner << endl);
|
---|
[856098] | 874 | if (point == (*Runner)) {
|
---|
[a67d19] | 875 | DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
|
---|
[262bae] | 876 | return true;
|
---|
[856098] | 877 | }
|
---|
| 878 | }
|
---|
[a67d19] | 879 | DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
|
---|
[262bae] | 880 | return false;
|
---|
[6613ec] | 881 | }
|
---|
| 882 | ;
|
---|
[262bae] | 883 |
|
---|
| 884 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 885 | * \param *point TesselPoint to test
|
---|
| 886 | * \return true - point is of the triangle, false - is not
|
---|
| 887 | */
|
---|
| 888 | bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
|
---|
| 889 | {
|
---|
| 890 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 891 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
|
---|
[856098] | 892 | if (point == (*Runner)->node) {
|
---|
[a67d19] | 893 | DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
|
---|
[262bae] | 894 | return true;
|
---|
[856098] | 895 | }
|
---|
[a67d19] | 896 | DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
|
---|
[262bae] | 897 | return false;
|
---|
[6613ec] | 898 | }
|
---|
| 899 | ;
|
---|
[262bae] | 900 |
|
---|
| 901 | /** Checks whether given array of \a *Points coincide with polygons's endpoints.
|
---|
| 902 | * \param **Points pointer to an array of BoundaryPointSet
|
---|
| 903 | * \param dim dimension of array
|
---|
| 904 | * \return true - set of points is contained in polygon, false - is not
|
---|
| 905 | */
|
---|
| 906 | bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
|
---|
| 907 | {
|
---|
[856098] | 908 | Info FunctionInfo(__func__);
|
---|
[262bae] | 909 | int counter = 0;
|
---|
[a67d19] | 910 | DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
|
---|
[6613ec] | 911 | for (int i = 0; i < dim; i++) {
|
---|
[a67d19] | 912 | DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl);
|
---|
[856098] | 913 | if (ContainsBoundaryPoint(Points[i])) {
|
---|
[262bae] | 914 | counter++;
|
---|
[856098] | 915 | }
|
---|
| 916 | }
|
---|
[262bae] | 917 |
|
---|
| 918 | if (counter == dim)
|
---|
| 919 | return true;
|
---|
| 920 | else
|
---|
| 921 | return false;
|
---|
[6613ec] | 922 | }
|
---|
| 923 | ;
|
---|
[262bae] | 924 |
|
---|
| 925 | /** Checks whether given PointList coincide with polygons's endpoints.
|
---|
| 926 | * \param &endpoints PointList
|
---|
| 927 | * \return true - set of points is contained in polygon, false - is not
|
---|
| 928 | */
|
---|
| 929 | bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
|
---|
| 930 | {
|
---|
[856098] | 931 | Info FunctionInfo(__func__);
|
---|
[262bae] | 932 | size_t counter = 0;
|
---|
[a67d19] | 933 | DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
|
---|
[6613ec] | 934 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[a67d19] | 935 | DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << **Runner << endl);
|
---|
[262bae] | 936 | if (ContainsBoundaryPoint(*Runner))
|
---|
| 937 | counter++;
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | if (counter == endpoints.size())
|
---|
| 941 | return true;
|
---|
| 942 | else
|
---|
| 943 | return false;
|
---|
[6613ec] | 944 | }
|
---|
| 945 | ;
|
---|
[262bae] | 946 |
|
---|
| 947 | /** Checks whether given set of \a *Points coincide with polygons's endpoints.
|
---|
| 948 | * \param *P pointer to BoundaryPolygonSet
|
---|
| 949 | * \return true - is the very triangle, false - is not
|
---|
| 950 | */
|
---|
| 951 | bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
|
---|
| 952 | {
|
---|
[6613ec] | 953 | return ContainsPresentTupel((const PointSet) P->endpoints);
|
---|
| 954 | }
|
---|
| 955 | ;
|
---|
[262bae] | 956 |
|
---|
| 957 | /** Gathers all the endpoints' triangles in a unique set.
|
---|
| 958 | * \return set of all triangles
|
---|
| 959 | */
|
---|
[856098] | 960 | TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
|
---|
[262bae] | 961 | {
|
---|
| 962 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 963 | pair<TriangleSet::iterator, bool> Tester;
|
---|
[262bae] | 964 | TriangleSet *triangles = new TriangleSet;
|
---|
| 965 |
|
---|
[6613ec] | 966 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
|
---|
| 967 | for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
|
---|
| 968 | for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
|
---|
[856098] | 969 | //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
|
---|
| 970 | if (ContainsBoundaryTriangle(Sprinter->second)) {
|
---|
| 971 | Tester = triangles->insert(Sprinter->second);
|
---|
| 972 | if (Tester.second)
|
---|
[a67d19] | 973 | DoLog(0) && (Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl);
|
---|
[856098] | 974 | }
|
---|
| 975 | }
|
---|
[262bae] | 976 |
|
---|
[a67d19] | 977 | DoLog(1) && (Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl);
|
---|
[262bae] | 978 | return triangles;
|
---|
[6613ec] | 979 | }
|
---|
| 980 | ;
|
---|
[262bae] | 981 |
|
---|
| 982 | /** Fills the endpoints of this polygon from the triangles attached to \a *line.
|
---|
| 983 | * \param *line lines with triangles attached
|
---|
[856098] | 984 | * \return true - polygon contains endpoints, false - line was NULL
|
---|
[262bae] | 985 | */
|
---|
| 986 | bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
|
---|
| 987 | {
|
---|
[856098] | 988 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 989 | pair<PointSet::iterator, bool> Tester;
|
---|
[856098] | 990 | if (line == NULL)
|
---|
| 991 | return false;
|
---|
[a67d19] | 992 | DoLog(1) && (Log() << Verbose(1) << "Filling polygon from line " << *line << endl);
|
---|
[6613ec] | 993 | for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
|
---|
| 994 | for (int i = 0; i < 3; i++) {
|
---|
[856098] | 995 | Tester = endpoints.insert((Runner->second)->endpoints[i]);
|
---|
| 996 | if (Tester.second)
|
---|
[a67d19] | 997 | DoLog(1) && (Log() << Verbose(1) << " Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl);
|
---|
[856098] | 998 | }
|
---|
[262bae] | 999 | }
|
---|
| 1000 |
|
---|
[856098] | 1001 | return true;
|
---|
[6613ec] | 1002 | }
|
---|
| 1003 | ;
|
---|
[262bae] | 1004 |
|
---|
| 1005 | /** output operator for BoundaryPolygonSet.
|
---|
| 1006 | * \param &ost output stream
|
---|
| 1007 | * \param &a boundary polygon
|
---|
| 1008 | */
|
---|
| 1009 | ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
|
---|
| 1010 | {
|
---|
| 1011 | ost << "[" << a.Nr << "|";
|
---|
[6613ec] | 1012 | for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
|
---|
[68f03d] | 1013 | ost << (*Runner)->node->getName();
|
---|
[6613ec] | 1014 | Runner++;
|
---|
| 1015 | if (Runner != a.endpoints.end())
|
---|
| 1016 | ost << ",";
|
---|
[262bae] | 1017 | }
|
---|
[6613ec] | 1018 | ost << "]";
|
---|
[262bae] | 1019 | return ost;
|
---|
[6613ec] | 1020 | }
|
---|
| 1021 | ;
|
---|
[262bae] | 1022 |
|
---|
[357fba] | 1023 | // =========================================================== class TESSELPOINT ===========================================
|
---|
| 1024 |
|
---|
| 1025 | /** Constructor of class TesselPoint.
|
---|
| 1026 | */
|
---|
| 1027 | TesselPoint::TesselPoint()
|
---|
| 1028 | {
|
---|
[244a84] | 1029 | //Info FunctionInfo(__func__);
|
---|
[357fba] | 1030 | node = NULL;
|
---|
| 1031 | nr = -1;
|
---|
[6613ec] | 1032 | }
|
---|
| 1033 | ;
|
---|
[357fba] | 1034 |
|
---|
| 1035 | /** Destructor for class TesselPoint.
|
---|
| 1036 | */
|
---|
| 1037 | TesselPoint::~TesselPoint()
|
---|
| 1038 | {
|
---|
[244a84] | 1039 | //Info FunctionInfo(__func__);
|
---|
[6613ec] | 1040 | }
|
---|
| 1041 | ;
|
---|
[357fba] | 1042 |
|
---|
| 1043 | /** Prints LCNode to screen.
|
---|
| 1044 | */
|
---|
[6613ec] | 1045 | ostream & operator <<(ostream &ost, const TesselPoint &a)
|
---|
[357fba] | 1046 | {
|
---|
[68f03d] | 1047 | ost << "[" << a.getName() << "|" << *a.node << "]";
|
---|
[357fba] | 1048 | return ost;
|
---|
[6613ec] | 1049 | }
|
---|
| 1050 | ;
|
---|
[357fba] | 1051 |
|
---|
[5c7bf8] | 1052 | /** Prints LCNode to screen.
|
---|
| 1053 | */
|
---|
[6613ec] | 1054 | ostream & TesselPoint::operator <<(ostream &ost)
|
---|
[5c7bf8] | 1055 | {
|
---|
[6613ec] | 1056 | Info FunctionInfo(__func__);
|
---|
[27bd2f] | 1057 | ost << "[" << (nr) << "|" << this << "]";
|
---|
[5c7bf8] | 1058 | return ost;
|
---|
[6613ec] | 1059 | }
|
---|
| 1060 | ;
|
---|
[357fba] | 1061 |
|
---|
| 1062 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 1063 |
|
---|
| 1064 | /** Constructor of class PointCloud.
|
---|
| 1065 | */
|
---|
| 1066 | PointCloud::PointCloud()
|
---|
| 1067 | {
|
---|
[6613ec] | 1068 | //Info FunctionInfo(__func__);
|
---|
| 1069 | }
|
---|
| 1070 | ;
|
---|
[357fba] | 1071 |
|
---|
| 1072 | /** Destructor for class PointCloud.
|
---|
| 1073 | */
|
---|
| 1074 | PointCloud::~PointCloud()
|
---|
| 1075 | {
|
---|
[6613ec] | 1076 | //Info FunctionInfo(__func__);
|
---|
| 1077 | }
|
---|
| 1078 | ;
|
---|
[357fba] | 1079 |
|
---|
| 1080 | // ============================ CandidateForTesselation =============================
|
---|
| 1081 |
|
---|
| 1082 | /** Constructor of class CandidateForTesselation.
|
---|
| 1083 | */
|
---|
[6613ec] | 1084 | CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
|
---|
| 1085 | BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
|
---|
[1e168b] | 1086 | {
|
---|
[6613ec] | 1087 | Info FunctionInfo(__func__);
|
---|
| 1088 | }
|
---|
| 1089 | ;
|
---|
[1e168b] | 1090 |
|
---|
| 1091 | /** Constructor of class CandidateForTesselation.
|
---|
| 1092 | */
|
---|
[6613ec] | 1093 | CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
|
---|
| 1094 | BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
|
---|
[1e168b] | 1095 | {
|
---|
[f67b6e] | 1096 | Info FunctionInfo(__func__);
|
---|
[273382] | 1097 | OptCenter = OptCandidateCenter;
|
---|
| 1098 | OtherOptCenter = OtherOptCandidateCenter;
|
---|
[357fba] | 1099 | };
|
---|
| 1100 |
|
---|
| 1101 |
|
---|
| 1102 | /** Destructor for class CandidateForTesselation.
|
---|
| 1103 | */
|
---|
[6613ec] | 1104 | CandidateForTesselation::~CandidateForTesselation()
|
---|
| 1105 | {
|
---|
| 1106 | }
|
---|
| 1107 | ;
|
---|
[357fba] | 1108 |
|
---|
[734816] | 1109 | /** Checks validity of a given sphere of a candidate line.
|
---|
| 1110 | * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside.
|
---|
| 1111 | * \param RADIUS radius of sphere
|
---|
| 1112 | * \param *LC LinkedCell structure with other atoms
|
---|
| 1113 | * \return true - sphere is valid, false - sphere contains other points
|
---|
| 1114 | */
|
---|
| 1115 | bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
|
---|
| 1116 | {
|
---|
[09898c] | 1117 | Info FunctionInfo(__func__);
|
---|
| 1118 |
|
---|
[6613ec] | 1119 | const double radiusSquared = RADIUS * RADIUS;
|
---|
[734816] | 1120 | list<const Vector *> VectorList;
|
---|
| 1121 | VectorList.push_back(&OptCenter);
|
---|
[09898c] | 1122 | //VectorList.push_back(&OtherOptCenter); // don't check the other (wrong) center
|
---|
[734816] | 1123 |
|
---|
[09898c] | 1124 | if (!pointlist.empty())
|
---|
[6613ec] | 1125 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
|
---|
[09898c] | 1126 | else
|
---|
| 1127 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
|
---|
[734816] | 1128 | // check baseline for OptCenter and OtherOptCenter being on sphere's surface
|
---|
| 1129 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
[6613ec] | 1130 | for (int i = 0; i < 2; i++) {
|
---|
[8cbb97] | 1131 | const double distance = fabs((*VRunner)->DistanceSquared(*BaseLine->endpoints[i]->node->node) - radiusSquared);
|
---|
[f07f86d] | 1132 | if (distance > HULLEPSILON) {
|
---|
[6613ec] | 1133 | DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
|
---|
[734816] | 1134 | return false;
|
---|
| 1135 | }
|
---|
[f07f86d] | 1136 | }
|
---|
[734816] | 1137 | }
|
---|
| 1138 |
|
---|
| 1139 | // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
|
---|
[6613ec] | 1140 | for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
|
---|
[734816] | 1141 | const TesselPoint *Walker = *Runner;
|
---|
| 1142 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
[8cbb97] | 1143 | const double distance = fabs((*VRunner)->DistanceSquared(*Walker->node) - radiusSquared);
|
---|
[f07f86d] | 1144 | if (distance > HULLEPSILON) {
|
---|
[6613ec] | 1145 | DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
|
---|
[734816] | 1146 | return false;
|
---|
[6613ec] | 1147 | } else {
|
---|
[a67d19] | 1148 | DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl);
|
---|
[734816] | 1149 | }
|
---|
| 1150 | }
|
---|
| 1151 | }
|
---|
| 1152 |
|
---|
[09898c] | 1153 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
|
---|
[734816] | 1154 | bool flag = true;
|
---|
| 1155 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
| 1156 | // get all points inside the sphere
|
---|
| 1157 | TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
|
---|
[6613ec] | 1158 |
|
---|
[b32dbb] | 1159 | DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << (*VRunner) << ":" << endl);
|
---|
[6613ec] | 1160 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[b32dbb] | 1161 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(*(*VRunner)) << "." << endl);
|
---|
[6613ec] | 1162 |
|
---|
[734816] | 1163 | // remove baseline's endpoints and candidates
|
---|
[6613ec] | 1164 | for (int i = 0; i < 2; i++) {
|
---|
[a67d19] | 1165 | DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl);
|
---|
[734816] | 1166 | ListofPoints->remove(BaseLine->endpoints[i]->node);
|
---|
[6613ec] | 1167 | }
|
---|
| 1168 | for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
|
---|
[a67d19] | 1169 | DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl);
|
---|
[734816] | 1170 | ListofPoints->remove(*Runner);
|
---|
[6613ec] | 1171 | }
|
---|
[734816] | 1172 | if (!ListofPoints->empty()) {
|
---|
[6613ec] | 1173 | DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
|
---|
[734816] | 1174 | flag = false;
|
---|
[09898c] | 1175 | DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
|
---|
| 1176 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[b32dbb] | 1177 | DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << " at distance " << setprecision(13) << (*Runner)->node->distance(*(*VRunner)) << setprecision(6) << "." << endl);
|
---|
| 1178 |
|
---|
| 1179 | // check with animate_sphere.tcl VMD script
|
---|
| 1180 | if (ThirdPoint != NULL) {
|
---|
| 1181 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
|
---|
| 1182 | } else {
|
---|
| 1183 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: ... missing third point ..." << endl);
|
---|
| 1184 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
|
---|
| 1185 | }
|
---|
[734816] | 1186 | }
|
---|
[6613ec] | 1187 | delete (ListofPoints);
|
---|
[09898c] | 1188 |
|
---|
[734816] | 1189 | }
|
---|
| 1190 | return flag;
|
---|
[6613ec] | 1191 | }
|
---|
| 1192 | ;
|
---|
[357fba] | 1193 |
|
---|
[1e168b] | 1194 | /** output operator for CandidateForTesselation.
|
---|
| 1195 | * \param &ost output stream
|
---|
| 1196 | * \param &a boundary line
|
---|
| 1197 | */
|
---|
[6613ec] | 1198 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
|
---|
[1e168b] | 1199 | {
|
---|
[68f03d] | 1200 | ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->getName() << "," << a.BaseLine->endpoints[1]->node->getName() << "] with ";
|
---|
[f67b6e] | 1201 | if (a.pointlist.empty())
|
---|
[1e168b] | 1202 | ost << "no candidate.";
|
---|
[f67b6e] | 1203 | else {
|
---|
| 1204 | ost << "candidate";
|
---|
| 1205 | if (a.pointlist.size() != 1)
|
---|
| 1206 | ost << "s ";
|
---|
| 1207 | else
|
---|
| 1208 | ost << " ";
|
---|
| 1209 | for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
|
---|
| 1210 | ost << *(*Runner) << " ";
|
---|
[6613ec] | 1211 | ost << " at angle " << (a.ShortestAngle) << ".";
|
---|
[f67b6e] | 1212 | }
|
---|
[1e168b] | 1213 |
|
---|
| 1214 | return ost;
|
---|
[6613ec] | 1215 | }
|
---|
| 1216 | ;
|
---|
[1e168b] | 1217 |
|
---|
[357fba] | 1218 | // =========================================================== class TESSELATION ===========================================
|
---|
| 1219 |
|
---|
| 1220 | /** Constructor of class Tesselation.
|
---|
| 1221 | */
|
---|
[1e168b] | 1222 | Tesselation::Tesselation() :
|
---|
[6613ec] | 1223 | PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin())
|
---|
[357fba] | 1224 | {
|
---|
[6613ec] | 1225 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1226 | }
|
---|
| 1227 | ;
|
---|
| 1228 |
|
---|
| 1229 | /** Destructor of class Tesselation.
|
---|
| 1230 | * We have to free all points, lines and triangles.
|
---|
| 1231 | */
|
---|
| 1232 | Tesselation::~Tesselation()
|
---|
| 1233 | {
|
---|
[6613ec] | 1234 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1235 | DoLog(0) && (Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl);
|
---|
[357fba] | 1236 | for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
|
---|
| 1237 | if (runner->second != NULL) {
|
---|
| 1238 | delete (runner->second);
|
---|
| 1239 | runner->second = NULL;
|
---|
| 1240 | } else
|
---|
[6613ec] | 1241 | DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);
|
---|
[357fba] | 1242 | }
|
---|
[a67d19] | 1243 | DoLog(0) && (Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl);
|
---|
[357fba] | 1244 | }
|
---|
| 1245 | ;
|
---|
| 1246 |
|
---|
[5c7bf8] | 1247 | /** PointCloud implementation of GetCenter
|
---|
| 1248 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1249 | */
|
---|
[776b64] | 1250 | Vector * Tesselation::GetCenter(ofstream *out) const
|
---|
[5c7bf8] | 1251 | {
|
---|
[6613ec] | 1252 | Info FunctionInfo(__func__);
|
---|
| 1253 | Vector *Center = new Vector(0., 0., 0.);
|
---|
| 1254 | int num = 0;
|
---|
[5c7bf8] | 1255 | for (GoToFirst(); (!IsEnd()); GoToNext()) {
|
---|
[273382] | 1256 | (*Center) += (*GetPoint()->node);
|
---|
[5c7bf8] | 1257 | num++;
|
---|
| 1258 | }
|
---|
[6613ec] | 1259 | Center->Scale(1. / num);
|
---|
[5c7bf8] | 1260 | return Center;
|
---|
[6613ec] | 1261 | }
|
---|
| 1262 | ;
|
---|
[5c7bf8] | 1263 |
|
---|
| 1264 | /** PointCloud implementation of GoPoint
|
---|
| 1265 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1266 | */
|
---|
[776b64] | 1267 | TesselPoint * Tesselation::GetPoint() const
|
---|
[5c7bf8] | 1268 | {
|
---|
[6613ec] | 1269 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1270 | return (InternalPointer->second->node);
|
---|
[6613ec] | 1271 | }
|
---|
| 1272 | ;
|
---|
[5c7bf8] | 1273 |
|
---|
| 1274 | /** PointCloud implementation of GoToNext.
|
---|
| 1275 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1276 | */
|
---|
[776b64] | 1277 | void Tesselation::GoToNext() const
|
---|
[5c7bf8] | 1278 | {
|
---|
[6613ec] | 1279 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1280 | if (InternalPointer != PointsOnBoundary.end())
|
---|
| 1281 | InternalPointer++;
|
---|
[6613ec] | 1282 | }
|
---|
| 1283 | ;
|
---|
[5c7bf8] | 1284 |
|
---|
| 1285 | /** PointCloud implementation of GoToFirst.
|
---|
| 1286 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1287 | */
|
---|
[776b64] | 1288 | void Tesselation::GoToFirst() const
|
---|
[5c7bf8] | 1289 | {
|
---|
[6613ec] | 1290 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1291 | InternalPointer = PointsOnBoundary.begin();
|
---|
[6613ec] | 1292 | }
|
---|
| 1293 | ;
|
---|
[5c7bf8] | 1294 |
|
---|
| 1295 | /** PointCloud implementation of IsEmpty.
|
---|
| 1296 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1297 | */
|
---|
[776b64] | 1298 | bool Tesselation::IsEmpty() const
|
---|
[5c7bf8] | 1299 | {
|
---|
[6613ec] | 1300 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1301 | return (PointsOnBoundary.empty());
|
---|
[6613ec] | 1302 | }
|
---|
| 1303 | ;
|
---|
[5c7bf8] | 1304 |
|
---|
| 1305 | /** PointCloud implementation of IsLast.
|
---|
| 1306 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1307 | */
|
---|
[776b64] | 1308 | bool Tesselation::IsEnd() const
|
---|
[5c7bf8] | 1309 | {
|
---|
[6613ec] | 1310 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1311 | return (InternalPointer == PointsOnBoundary.end());
|
---|
[6613ec] | 1312 | }
|
---|
| 1313 | ;
|
---|
[5c7bf8] | 1314 |
|
---|
[357fba] | 1315 | /** Gueses first starting triangle of the convex envelope.
|
---|
| 1316 | * We guess the starting triangle by taking the smallest distance between two points and looking for a fitting third.
|
---|
| 1317 | * \param *out output stream for debugging
|
---|
| 1318 | * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
|
---|
| 1319 | */
|
---|
[244a84] | 1320 | void Tesselation::GuessStartingTriangle()
|
---|
[357fba] | 1321 | {
|
---|
[6613ec] | 1322 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1323 | // 4b. create a starting triangle
|
---|
| 1324 | // 4b1. create all distances
|
---|
| 1325 | DistanceMultiMap DistanceMMap;
|
---|
| 1326 | double distance, tmp;
|
---|
| 1327 | Vector PlaneVector, TrialVector;
|
---|
| 1328 | PointMap::iterator A, B, C; // three nodes of the first triangle
|
---|
| 1329 | A = PointsOnBoundary.begin(); // the first may be chosen arbitrarily
|
---|
| 1330 |
|
---|
| 1331 | // with A chosen, take each pair B,C and sort
|
---|
[6613ec] | 1332 | if (A != PointsOnBoundary.end()) {
|
---|
| 1333 | B = A;
|
---|
| 1334 | B++;
|
---|
| 1335 | for (; B != PointsOnBoundary.end(); B++) {
|
---|
| 1336 | C = B;
|
---|
| 1337 | C++;
|
---|
| 1338 | for (; C != PointsOnBoundary.end(); C++) {
|
---|
[8cbb97] | 1339 | tmp = A->second->node->node->DistanceSquared(*B->second->node->node);
|
---|
[6613ec] | 1340 | distance = tmp * tmp;
|
---|
[8cbb97] | 1341 | tmp = A->second->node->node->DistanceSquared(*C->second->node->node);
|
---|
[6613ec] | 1342 | distance += tmp * tmp;
|
---|
[8cbb97] | 1343 | tmp = B->second->node->node->DistanceSquared(*C->second->node->node);
|
---|
[6613ec] | 1344 | distance += tmp * tmp;
|
---|
| 1345 | DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
|
---|
| 1346 | }
|
---|
[357fba] | 1347 | }
|
---|
[6613ec] | 1348 | }
|
---|
[357fba] | 1349 | // // listing distances
|
---|
[e138de] | 1350 | // Log() << Verbose(1) << "Listing DistanceMMap:";
|
---|
[357fba] | 1351 | // for(DistanceMultiMap::iterator runner = DistanceMMap.begin(); runner != DistanceMMap.end(); runner++) {
|
---|
[e138de] | 1352 | // Log() << Verbose(0) << " " << runner->first << "(" << *runner->second.first->second << ", " << *runner->second.second->second << ")";
|
---|
[357fba] | 1353 | // }
|
---|
[e138de] | 1354 | // Log() << Verbose(0) << endl;
|
---|
[357fba] | 1355 | // 4b2. pick three baselines forming a triangle
|
---|
| 1356 | // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 1357 | DistanceMultiMap::iterator baseline = DistanceMMap.begin();
|
---|
[6613ec] | 1358 | for (; baseline != DistanceMMap.end(); baseline++) {
|
---|
| 1359 | // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 1360 | // 2. next, we have to check whether all points reside on only one side of the triangle
|
---|
| 1361 | // 3. construct plane vector
|
---|
[8cbb97] | 1362 | PlaneVector = Plane(*A->second->node->node,
|
---|
| 1363 | *baseline->second.first->second->node->node,
|
---|
| 1364 | *baseline->second.second->second->node->node).getNormal();
|
---|
[a67d19] | 1365 | DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl);
|
---|
[6613ec] | 1366 | // 4. loop over all points
|
---|
| 1367 | double sign = 0.;
|
---|
| 1368 | PointMap::iterator checker = PointsOnBoundary.begin();
|
---|
| 1369 | for (; checker != PointsOnBoundary.end(); checker++) {
|
---|
| 1370 | // (neglecting A,B,C)
|
---|
| 1371 | if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
|
---|
| 1372 | continue;
|
---|
| 1373 | // 4a. project onto plane vector
|
---|
[8cbb97] | 1374 | TrialVector = (*checker->second->node->node);
|
---|
| 1375 | TrialVector.SubtractVector(*A->second->node->node);
|
---|
| 1376 | distance = TrialVector.ScalarProduct(PlaneVector);
|
---|
[6613ec] | 1377 | if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
|
---|
| 1378 | continue;
|
---|
[68f03d] | 1379 | DoLog(2) && (Log() << Verbose(2) << "Projection of " << checker->second->node->getName() << " yields distance of " << distance << "." << endl);
|
---|
[6613ec] | 1380 | tmp = distance / fabs(distance);
|
---|
| 1381 | // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
|
---|
| 1382 | if ((sign != 0) && (tmp != sign)) {
|
---|
| 1383 | // 4c. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
[68f03d] | 1384 | DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->getName() << "," << baseline->second.first->second->node->getName() << "," << baseline->second.second->second->node->getName() << " leaves " << checker->second->node->getName() << " outside the convex hull." << endl);
|
---|
[6613ec] | 1385 | break;
|
---|
| 1386 | } else { // note the sign for later
|
---|
[68f03d] | 1387 | DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->getName() << "," << baseline->second.first->second->node->getName() << "," << baseline->second.second->second->node->getName() << " leave " << checker->second->node->getName() << " inside the convex hull." << endl);
|
---|
[6613ec] | 1388 | sign = tmp;
|
---|
| 1389 | }
|
---|
| 1390 | // 4d. Check whether the point is inside the triangle (check distance to each node
|
---|
[8cbb97] | 1391 | tmp = checker->second->node->node->DistanceSquared(*A->second->node->node);
|
---|
[6613ec] | 1392 | int innerpoint = 0;
|
---|
[8cbb97] | 1393 | if ((tmp < A->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(*baseline->second.second->second->node->node)))
|
---|
[6613ec] | 1394 | innerpoint++;
|
---|
[8cbb97] | 1395 | tmp = checker->second->node->node->DistanceSquared(*baseline->second.first->second->node->node);
|
---|
| 1396 | if ((tmp < baseline->second.first->second->node->node->DistanceSquared(*A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(*baseline->second.second->second->node->node)))
|
---|
[6613ec] | 1397 | innerpoint++;
|
---|
[8cbb97] | 1398 | tmp = checker->second->node->node->DistanceSquared(*baseline->second.second->second->node->node);
|
---|
| 1399 | if ((tmp < baseline->second.second->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(*A->second->node->node)))
|
---|
[6613ec] | 1400 | innerpoint++;
|
---|
| 1401 | // 4e. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
| 1402 | if (innerpoint == 3)
|
---|
| 1403 | break;
|
---|
[357fba] | 1404 | }
|
---|
[6613ec] | 1405 | // 5. come this far, all on same side? Then break 1. loop and construct triangle
|
---|
| 1406 | if (checker == PointsOnBoundary.end()) {
|
---|
[a67d19] | 1407 | DoLog(2) && (Log() << Verbose(2) << "Looks like we have a candidate!" << endl);
|
---|
[6613ec] | 1408 | break;
|
---|
[357fba] | 1409 | }
|
---|
[6613ec] | 1410 | }
|
---|
| 1411 | if (baseline != DistanceMMap.end()) {
|
---|
| 1412 | BPS[0] = baseline->second.first->second;
|
---|
| 1413 | BPS[1] = baseline->second.second->second;
|
---|
| 1414 | BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1415 | BPS[0] = A->second;
|
---|
| 1416 | BPS[1] = baseline->second.second->second;
|
---|
| 1417 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1418 | BPS[0] = baseline->second.first->second;
|
---|
| 1419 | BPS[1] = A->second;
|
---|
| 1420 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1421 |
|
---|
| 1422 | // 4b3. insert created triangle
|
---|
| 1423 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 1424 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1425 | TrianglesOnBoundaryCount++;
|
---|
| 1426 | for (int i = 0; i < NDIM; i++) {
|
---|
| 1427 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
|
---|
| 1428 | LinesOnBoundaryCount++;
|
---|
[357fba] | 1429 | }
|
---|
[6613ec] | 1430 |
|
---|
[a67d19] | 1431 | DoLog(1) && (Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl);
|
---|
[6613ec] | 1432 | } else {
|
---|
| 1433 | DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl);
|
---|
| 1434 | }
|
---|
[357fba] | 1435 | }
|
---|
| 1436 | ;
|
---|
| 1437 |
|
---|
| 1438 | /** Tesselates the convex envelope of a cluster from a single starting triangle.
|
---|
| 1439 | * The starting triangle is made out of three baselines. Each line in the final tesselated cluster may belong to at most
|
---|
| 1440 | * 2 triangles. Hence, we go through all current lines:
|
---|
| 1441 | * -# if the lines contains to only one triangle
|
---|
| 1442 | * -# We search all points in the boundary
|
---|
| 1443 | * -# if the triangle is in forward direction of the baseline (at most 90 degrees angle between vector orthogonal to
|
---|
| 1444 | * baseline in triangle plane pointing out of the triangle and normal vector of new triangle)
|
---|
| 1445 | * -# if the triangle with the baseline and the current point has the smallest of angles (comparison between normal vectors)
|
---|
| 1446 | * -# then we have a new triangle, whose baselines we again add (or increase their TriangleCount)
|
---|
| 1447 | * \param *out output stream for debugging
|
---|
| 1448 | * \param *configuration for IsAngstroem
|
---|
| 1449 | * \param *cloud cluster of points
|
---|
| 1450 | */
|
---|
[e138de] | 1451 | void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
|
---|
[357fba] | 1452 | {
|
---|
[6613ec] | 1453 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1454 | bool flag;
|
---|
| 1455 | PointMap::iterator winner;
|
---|
| 1456 | class BoundaryPointSet *peak = NULL;
|
---|
| 1457 | double SmallestAngle, TempAngle;
|
---|
| 1458 | Vector NormalVector, VirtualNormalVector, CenterVector, TempVector, helper, PropagationVector, *Center = NULL;
|
---|
| 1459 | LineMap::iterator LineChecker[2];
|
---|
| 1460 |
|
---|
[e138de] | 1461 | Center = cloud->GetCenter();
|
---|
[357fba] | 1462 | // create a first tesselation with the given BoundaryPoints
|
---|
| 1463 | do {
|
---|
| 1464 | flag = false;
|
---|
| 1465 | for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++)
|
---|
[5c7bf8] | 1466 | if (baseline->second->triangles.size() == 1) {
|
---|
[357fba] | 1467 | // 5a. go through each boundary point if not _both_ edges between either endpoint of the current line and this point exist (and belong to 2 triangles)
|
---|
| 1468 | SmallestAngle = M_PI;
|
---|
| 1469 |
|
---|
| 1470 | // get peak point with respect to this base line's only triangle
|
---|
| 1471 | BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
|
---|
[a67d19] | 1472 | DoLog(0) && (Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl);
|
---|
[357fba] | 1473 | for (int i = 0; i < 3; i++)
|
---|
| 1474 | if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
|
---|
| 1475 | peak = BTS->endpoints[i];
|
---|
[a67d19] | 1476 | DoLog(1) && (Log() << Verbose(1) << " and has peak " << *peak << "." << endl);
|
---|
[357fba] | 1477 |
|
---|
| 1478 | // prepare some auxiliary vectors
|
---|
| 1479 | Vector BaseLineCenter, BaseLine;
|
---|
[273382] | 1480 | BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) +
|
---|
| 1481 | (*baseline->second->endpoints[1]->node->node));
|
---|
| 1482 | BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node);
|
---|
[357fba] | 1483 |
|
---|
| 1484 | // offset to center of triangle
|
---|
| 1485 | CenterVector.Zero();
|
---|
| 1486 | for (int i = 0; i < 3; i++)
|
---|
[8f215d] | 1487 | CenterVector += BTS->getEndpoint(i);
|
---|
[357fba] | 1488 | CenterVector.Scale(1. / 3.);
|
---|
[a67d19] | 1489 | DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
|
---|
[357fba] | 1490 |
|
---|
| 1491 | // normal vector of triangle
|
---|
[273382] | 1492 | NormalVector = (*Center) - CenterVector;
|
---|
[357fba] | 1493 | BTS->GetNormalVector(NormalVector);
|
---|
[273382] | 1494 | NormalVector = BTS->NormalVector;
|
---|
[a67d19] | 1495 | DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl);
|
---|
[357fba] | 1496 |
|
---|
| 1497 | // vector in propagation direction (out of triangle)
|
---|
| 1498 | // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
|
---|
[0a4f7f] | 1499 | PropagationVector = Plane(BaseLine, NormalVector,0).getNormal();
|
---|
[273382] | 1500 | TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
|
---|
[f67b6e] | 1501 | //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
|
---|
[273382] | 1502 | if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline
|
---|
[357fba] | 1503 | PropagationVector.Scale(-1.);
|
---|
[a67d19] | 1504 | DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl);
|
---|
[357fba] | 1505 | winner = PointsOnBoundary.end();
|
---|
| 1506 |
|
---|
| 1507 | // loop over all points and calculate angle between normal vector of new and present triangle
|
---|
| 1508 | for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
|
---|
| 1509 | if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
|
---|
[a67d19] | 1510 | DoLog(1) && (Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl);
|
---|
[357fba] | 1511 |
|
---|
| 1512 | // first check direction, so that triangles don't intersect
|
---|
[273382] | 1513 | VirtualNormalVector = (*target->second->node->node) - BaseLineCenter;
|
---|
[8cbb97] | 1514 | VirtualNormalVector.ProjectOntoPlane(NormalVector);
|
---|
[273382] | 1515 | TempAngle = VirtualNormalVector.Angle(PropagationVector);
|
---|
[a67d19] | 1516 | DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl);
|
---|
[6613ec] | 1517 | if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
|
---|
[a67d19] | 1518 | DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl);
|
---|
[357fba] | 1519 | continue;
|
---|
| 1520 | } else
|
---|
[a67d19] | 1521 | DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl);
|
---|
[357fba] | 1522 |
|
---|
| 1523 | // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
|
---|
| 1524 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(target->first);
|
---|
| 1525 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
|
---|
[5c7bf8] | 1526 | if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
|
---|
[a67d19] | 1527 | DoLog(2) && (Log() << Verbose(2) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl);
|
---|
[357fba] | 1528 | continue;
|
---|
| 1529 | }
|
---|
[5c7bf8] | 1530 | if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
|
---|
[a67d19] | 1531 | DoLog(2) && (Log() << Verbose(2) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl);
|
---|
[357fba] | 1532 | continue;
|
---|
| 1533 | }
|
---|
| 1534 |
|
---|
| 1535 | // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
|
---|
| 1536 | if ((((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (GetCommonEndpoint(LineChecker[0]->second, LineChecker[1]->second) == peak)))) {
|
---|
[a67d19] | 1537 | DoLog(4) && (Log() << Verbose(4) << "Current target is peak!" << endl);
|
---|
[357fba] | 1538 | continue;
|
---|
| 1539 | }
|
---|
| 1540 |
|
---|
| 1541 | // check for linear dependence
|
---|
[273382] | 1542 | TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node);
|
---|
| 1543 | helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node);
|
---|
| 1544 | helper.ProjectOntoPlane(TempVector);
|
---|
[357fba] | 1545 | if (fabs(helper.NormSquared()) < MYEPSILON) {
|
---|
[a67d19] | 1546 | DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl);
|
---|
[357fba] | 1547 | continue;
|
---|
| 1548 | }
|
---|
| 1549 |
|
---|
| 1550 | // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
|
---|
| 1551 | flag = true;
|
---|
[0a4f7f] | 1552 | VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node),
|
---|
| 1553 | *(baseline->second->endpoints[1]->node->node),
|
---|
| 1554 | *(target->second->node->node)).getNormal();
|
---|
[273382] | 1555 | TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) +
|
---|
| 1556 | (*baseline->second->endpoints[1]->node->node) +
|
---|
| 1557 | (*target->second->node->node));
|
---|
| 1558 | TempVector -= (*Center);
|
---|
[357fba] | 1559 | // make it always point outward
|
---|
[273382] | 1560 | if (VirtualNormalVector.ScalarProduct(TempVector) < 0)
|
---|
[357fba] | 1561 | VirtualNormalVector.Scale(-1.);
|
---|
| 1562 | // calculate angle
|
---|
[273382] | 1563 | TempAngle = NormalVector.Angle(VirtualNormalVector);
|
---|
[a67d19] | 1564 | DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl);
|
---|
[357fba] | 1565 | if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
|
---|
| 1566 | SmallestAngle = TempAngle;
|
---|
| 1567 | winner = target;
|
---|
[a67d19] | 1568 | DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
|
---|
[357fba] | 1569 | } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
|
---|
| 1570 | // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
|
---|
[273382] | 1571 | helper = (*target->second->node->node) - BaseLineCenter;
|
---|
| 1572 | helper.ProjectOntoPlane(BaseLine);
|
---|
[357fba] | 1573 | // ...the one with the smaller angle is the better candidate
|
---|
[273382] | 1574 | TempVector = (*target->second->node->node) - BaseLineCenter;
|
---|
| 1575 | TempVector.ProjectOntoPlane(VirtualNormalVector);
|
---|
| 1576 | TempAngle = TempVector.Angle(helper);
|
---|
| 1577 | TempVector = (*winner->second->node->node) - BaseLineCenter;
|
---|
| 1578 | TempVector.ProjectOntoPlane(VirtualNormalVector);
|
---|
| 1579 | if (TempAngle < TempVector.Angle(helper)) {
|
---|
| 1580 | TempAngle = NormalVector.Angle(VirtualNormalVector);
|
---|
[357fba] | 1581 | SmallestAngle = TempAngle;
|
---|
| 1582 | winner = target;
|
---|
[a67d19] | 1583 | DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl);
|
---|
[357fba] | 1584 | } else
|
---|
[a67d19] | 1585 | DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl);
|
---|
[357fba] | 1586 | } else
|
---|
[a67d19] | 1587 | DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
|
---|
[357fba] | 1588 | }
|
---|
| 1589 | } // end of loop over all boundary points
|
---|
| 1590 |
|
---|
| 1591 | // 5b. The point of the above whose triangle has the greatest angle with the triangle the current line belongs to (it only belongs to one, remember!): New triangle
|
---|
| 1592 | if (winner != PointsOnBoundary.end()) {
|
---|
[a67d19] | 1593 | DoLog(0) && (Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl);
|
---|
[357fba] | 1594 | // create the lins of not yet present
|
---|
| 1595 | BLS[0] = baseline->second;
|
---|
| 1596 | // 5c. add lines to the line set if those were new (not yet part of a triangle), delete lines that belong to two triangles)
|
---|
| 1597 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(winner->first);
|
---|
| 1598 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(winner->first);
|
---|
| 1599 | if (LineChecker[0] == baseline->second->endpoints[0]->lines.end()) { // create
|
---|
| 1600 | BPS[0] = baseline->second->endpoints[0];
|
---|
| 1601 | BPS[1] = winner->second;
|
---|
| 1602 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1603 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[1]));
|
---|
| 1604 | LinesOnBoundaryCount++;
|
---|
| 1605 | } else
|
---|
| 1606 | BLS[1] = LineChecker[0]->second;
|
---|
| 1607 | if (LineChecker[1] == baseline->second->endpoints[1]->lines.end()) { // create
|
---|
| 1608 | BPS[0] = baseline->second->endpoints[1];
|
---|
| 1609 | BPS[1] = winner->second;
|
---|
| 1610 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1611 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[2]));
|
---|
| 1612 | LinesOnBoundaryCount++;
|
---|
| 1613 | } else
|
---|
| 1614 | BLS[2] = LineChecker[1]->second;
|
---|
| 1615 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[62bb91] | 1616 | BTS->GetCenter(&helper);
|
---|
[273382] | 1617 | helper -= (*Center);
|
---|
| 1618 | helper *= -1;
|
---|
[62bb91] | 1619 | BTS->GetNormalVector(helper);
|
---|
[357fba] | 1620 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1621 | TrianglesOnBoundaryCount++;
|
---|
| 1622 | } else {
|
---|
[6613ec] | 1623 | DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);
|
---|
[357fba] | 1624 | }
|
---|
| 1625 |
|
---|
| 1626 | // 5d. If the set of lines is not yet empty, go to 5. and continue
|
---|
| 1627 | } else
|
---|
[a67d19] | 1628 | DoLog(0) && (Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl);
|
---|
[357fba] | 1629 | } while (flag);
|
---|
| 1630 |
|
---|
| 1631 | // exit
|
---|
[6613ec] | 1632 | delete (Center);
|
---|
| 1633 | }
|
---|
| 1634 | ;
|
---|
[357fba] | 1635 |
|
---|
[62bb91] | 1636 | /** Inserts all points outside of the tesselated surface into it by adding new triangles.
|
---|
[357fba] | 1637 | * \param *out output stream for debugging
|
---|
| 1638 | * \param *cloud cluster of points
|
---|
[62bb91] | 1639 | * \param *LC LinkedCell structure to find nearest point quickly
|
---|
[357fba] | 1640 | * \return true - all straddling points insert, false - something went wrong
|
---|
| 1641 | */
|
---|
[e138de] | 1642 | bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
|
---|
[357fba] | 1643 | {
|
---|
[6613ec] | 1644 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1645 | Vector Intersection, Normal;
|
---|
[357fba] | 1646 | TesselPoint *Walker = NULL;
|
---|
[e138de] | 1647 | Vector *Center = cloud->GetCenter();
|
---|
[c15ca2] | 1648 | TriangleList *triangles = NULL;
|
---|
[7dea7c] | 1649 | bool AddFlag = false;
|
---|
| 1650 | LinkedCell *BoundaryPoints = NULL;
|
---|
[bdc91e] | 1651 | bool SuccessFlag = true;
|
---|
[62bb91] | 1652 |
|
---|
[357fba] | 1653 | cloud->GoToFirst();
|
---|
[7dea7c] | 1654 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
[6613ec] | 1655 | while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
|
---|
[7dea7c] | 1656 | if (AddFlag) {
|
---|
[6613ec] | 1657 | delete (BoundaryPoints);
|
---|
[7dea7c] | 1658 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
| 1659 | AddFlag = false;
|
---|
| 1660 | }
|
---|
[357fba] | 1661 | Walker = cloud->GetPoint();
|
---|
[a67d19] | 1662 | DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Walker << "." << endl);
|
---|
[357fba] | 1663 | // get the next triangle
|
---|
[c15ca2] | 1664 | triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
|
---|
[bdc91e] | 1665 | if (triangles != NULL)
|
---|
| 1666 | BTS = triangles->front();
|
---|
| 1667 | else
|
---|
| 1668 | BTS = NULL;
|
---|
| 1669 | delete triangles;
|
---|
| 1670 | if ((BTS == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
|
---|
[a67d19] | 1671 | DoLog(0) && (Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl);
|
---|
[62bb91] | 1672 | cloud->GoToNext();
|
---|
| 1673 | continue;
|
---|
| 1674 | } else {
|
---|
[357fba] | 1675 | }
|
---|
[a67d19] | 1676 | DoLog(0) && (Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl);
|
---|
[357fba] | 1677 | // get the intersection point
|
---|
[e138de] | 1678 | if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
|
---|
[a67d19] | 1679 | DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl);
|
---|
[357fba] | 1680 | // we have the intersection, check whether in- or outside of boundary
|
---|
[273382] | 1681 | if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) {
|
---|
[357fba] | 1682 | // inside, next!
|
---|
[a67d19] | 1683 | DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1684 | } else {
|
---|
| 1685 | // outside!
|
---|
[a67d19] | 1686 | DoLog(0) && (Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1687 | class BoundaryLineSet *OldLines[3], *NewLines[3];
|
---|
| 1688 | class BoundaryPointSet *OldPoints[3], *NewPoint;
|
---|
| 1689 | // store the three old lines and old points
|
---|
[6613ec] | 1690 | for (int i = 0; i < 3; i++) {
|
---|
[357fba] | 1691 | OldLines[i] = BTS->lines[i];
|
---|
| 1692 | OldPoints[i] = BTS->endpoints[i];
|
---|
| 1693 | }
|
---|
[273382] | 1694 | Normal = BTS->NormalVector;
|
---|
[357fba] | 1695 | // add Walker to boundary points
|
---|
[a67d19] | 1696 | DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl);
|
---|
[7dea7c] | 1697 | AddFlag = true;
|
---|
[6613ec] | 1698 | if (AddBoundaryPoint(Walker, 0))
|
---|
[357fba] | 1699 | NewPoint = BPS[0];
|
---|
| 1700 | else
|
---|
| 1701 | continue;
|
---|
| 1702 | // remove triangle
|
---|
[a67d19] | 1703 | DoLog(0) && (Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1704 | TrianglesOnBoundary.erase(BTS->Nr);
|
---|
[6613ec] | 1705 | delete (BTS);
|
---|
[357fba] | 1706 | // create three new boundary lines
|
---|
[6613ec] | 1707 | for (int i = 0; i < 3; i++) {
|
---|
[357fba] | 1708 | BPS[0] = NewPoint;
|
---|
| 1709 | BPS[1] = OldPoints[i];
|
---|
| 1710 | NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
[a67d19] | 1711 | DoLog(1) && (Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl);
|
---|
[357fba] | 1712 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
|
---|
| 1713 | LinesOnBoundaryCount++;
|
---|
| 1714 | }
|
---|
| 1715 | // create three new triangle with new point
|
---|
[6613ec] | 1716 | for (int i = 0; i < 3; i++) { // find all baselines
|
---|
[357fba] | 1717 | BLS[0] = OldLines[i];
|
---|
| 1718 | int n = 1;
|
---|
[6613ec] | 1719 | for (int j = 0; j < 3; j++) {
|
---|
[357fba] | 1720 | if (NewLines[j]->IsConnectedTo(BLS[0])) {
|
---|
[6613ec] | 1721 | if (n > 2) {
|
---|
| 1722 | DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);
|
---|
[357fba] | 1723 | return false;
|
---|
| 1724 | } else
|
---|
| 1725 | BLS[n++] = NewLines[j];
|
---|
| 1726 | }
|
---|
| 1727 | }
|
---|
| 1728 | // create the triangle
|
---|
| 1729 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[5c7bf8] | 1730 | Normal.Scale(-1.);
|
---|
| 1731 | BTS->GetNormalVector(Normal);
|
---|
| 1732 | Normal.Scale(-1.);
|
---|
[a67d19] | 1733 | DoLog(0) && (Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1734 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1735 | TrianglesOnBoundaryCount++;
|
---|
| 1736 | }
|
---|
| 1737 | }
|
---|
| 1738 | } else { // something is wrong with FindClosestTriangleToPoint!
|
---|
[6613ec] | 1739 | DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl);
|
---|
[bdc91e] | 1740 | SuccessFlag = false;
|
---|
| 1741 | break;
|
---|
[357fba] | 1742 | }
|
---|
| 1743 | cloud->GoToNext();
|
---|
| 1744 | }
|
---|
| 1745 |
|
---|
| 1746 | // exit
|
---|
[6613ec] | 1747 | delete (Center);
|
---|
[bdc91e] | 1748 | delete (BoundaryPoints);
|
---|
| 1749 | return SuccessFlag;
|
---|
[6613ec] | 1750 | }
|
---|
| 1751 | ;
|
---|
[357fba] | 1752 |
|
---|
[16d866] | 1753 | /** Adds a point to the tesselation::PointsOnBoundary list.
|
---|
[62bb91] | 1754 | * \param *Walker point to add
|
---|
[08ef35] | 1755 | * \param n TesselStruct::BPS index to put pointer into
|
---|
| 1756 | * \return true - new point was added, false - point already present
|
---|
[357fba] | 1757 | */
|
---|
[776b64] | 1758 | bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
|
---|
[357fba] | 1759 | {
|
---|
[6613ec] | 1760 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1761 | PointTestPair InsertUnique;
|
---|
[08ef35] | 1762 | BPS[n] = new class BoundaryPointSet(Walker);
|
---|
| 1763 | InsertUnique = PointsOnBoundary.insert(PointPair(Walker->nr, BPS[n]));
|
---|
| 1764 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
[357fba] | 1765 | PointsOnBoundaryCount++;
|
---|
[08ef35] | 1766 | return true;
|
---|
| 1767 | } else {
|
---|
[6613ec] | 1768 | delete (BPS[n]);
|
---|
[08ef35] | 1769 | BPS[n] = InsertUnique.first->second;
|
---|
| 1770 | return false;
|
---|
[357fba] | 1771 | }
|
---|
| 1772 | }
|
---|
| 1773 | ;
|
---|
| 1774 |
|
---|
| 1775 | /** Adds point to Tesselation::PointsOnBoundary if not yet present.
|
---|
| 1776 | * Tesselation::TPS is set to either this new BoundaryPointSet or to the existing one of not unique.
|
---|
| 1777 | * @param Candidate point to add
|
---|
| 1778 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1779 | */
|
---|
[776b64] | 1780 | void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
|
---|
[357fba] | 1781 | {
|
---|
[6613ec] | 1782 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1783 | PointTestPair InsertUnique;
|
---|
| 1784 | TPS[n] = new class BoundaryPointSet(Candidate);
|
---|
| 1785 | InsertUnique = PointsOnBoundary.insert(PointPair(Candidate->nr, TPS[n]));
|
---|
| 1786 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
| 1787 | PointsOnBoundaryCount++;
|
---|
| 1788 | } else {
|
---|
| 1789 | delete TPS[n];
|
---|
[a67d19] | 1790 | DoLog(0) && (Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl);
|
---|
[357fba] | 1791 | TPS[n] = (InsertUnique.first)->second;
|
---|
| 1792 | }
|
---|
| 1793 | }
|
---|
| 1794 | ;
|
---|
| 1795 |
|
---|
[f1ef60a] | 1796 | /** Sets point to a present Tesselation::PointsOnBoundary.
|
---|
| 1797 | * Tesselation::TPS is set to the existing one or NULL if not found.
|
---|
| 1798 | * @param Candidate point to set to
|
---|
| 1799 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1800 | */
|
---|
| 1801 | void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
|
---|
| 1802 | {
|
---|
[6613ec] | 1803 | Info FunctionInfo(__func__);
|
---|
[f1ef60a] | 1804 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
|
---|
| 1805 | if (FindPoint != PointsOnBoundary.end())
|
---|
| 1806 | TPS[n] = FindPoint->second;
|
---|
| 1807 | else
|
---|
| 1808 | TPS[n] = NULL;
|
---|
[6613ec] | 1809 | }
|
---|
| 1810 | ;
|
---|
[f1ef60a] | 1811 |
|
---|
[357fba] | 1812 | /** Function tries to add line from current Points in BPS to BoundaryLineSet.
|
---|
| 1813 | * If successful it raises the line count and inserts the new line into the BLS,
|
---|
| 1814 | * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
|
---|
[f07f86d] | 1815 | * @param *OptCenter desired OptCenter if there are more than one candidate line
|
---|
[d5fea7] | 1816 | * @param *candidate third point of the triangle to be, for checking between multiple open line candidates
|
---|
[357fba] | 1817 | * @param *a first endpoint
|
---|
| 1818 | * @param *b second endpoint
|
---|
| 1819 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1820 | */
|
---|
[6613ec] | 1821 | void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
|
---|
| 1822 | {
|
---|
[357fba] | 1823 | bool insertNewLine = true;
|
---|
[b998c3] | 1824 | LineMap::iterator FindLine = a->lines.find(b->node->nr);
|
---|
[d5fea7] | 1825 | BoundaryLineSet *WinningLine = NULL;
|
---|
[b998c3] | 1826 | if (FindLine != a->lines.end()) {
|
---|
[a67d19] | 1827 | DoLog(1) && (Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl);
|
---|
[b998c3] | 1828 |
|
---|
[6613ec] | 1829 | pair<LineMap::iterator, LineMap::iterator> FindPair;
|
---|
[357fba] | 1830 | FindPair = a->lines.equal_range(b->node->nr);
|
---|
| 1831 |
|
---|
[6613ec] | 1832 | for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) {
|
---|
[a67d19] | 1833 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
|
---|
[357fba] | 1834 | // If there is a line with less than two attached triangles, we don't need a new line.
|
---|
[d5fea7] | 1835 | if (FindLine->second->triangles.size() == 1) {
|
---|
| 1836 | CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
|
---|
[f07f86d] | 1837 | if (!Finder->second->pointlist.empty())
|
---|
[a67d19] | 1838 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
|
---|
[f07f86d] | 1839 | else
|
---|
[a67d19] | 1840 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl);
|
---|
[f07f86d] | 1841 | // get open line
|
---|
[6613ec] | 1842 | for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
|
---|
[8cbb97] | 1843 | if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
|
---|
[b0a5f1] | 1844 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl);
|
---|
[6613ec] | 1845 | insertNewLine = false;
|
---|
| 1846 | WinningLine = FindLine->second;
|
---|
| 1847 | break;
|
---|
[b0a5f1] | 1848 | } else {
|
---|
| 1849 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *(*CandidateChecker) << "'s center " << Finder->second->OptCenter << " does not match desired on " << *OptCenter << "." << endl);
|
---|
[6613ec] | 1850 | }
|
---|
[856098] | 1851 | }
|
---|
[357fba] | 1852 | }
|
---|
| 1853 | }
|
---|
| 1854 | }
|
---|
| 1855 |
|
---|
| 1856 | if (insertNewLine) {
|
---|
[474961] | 1857 | AddNewTesselationTriangleLine(a, b, n);
|
---|
[d5fea7] | 1858 | } else {
|
---|
| 1859 | AddExistingTesselationTriangleLine(WinningLine, n);
|
---|
[357fba] | 1860 | }
|
---|
| 1861 | }
|
---|
| 1862 | ;
|
---|
| 1863 |
|
---|
| 1864 | /**
|
---|
| 1865 | * Adds lines from each of the current points in the BPS to BoundaryLineSet.
|
---|
| 1866 | * Raises the line count and inserts the new line into the BLS.
|
---|
| 1867 | *
|
---|
| 1868 | * @param *a first endpoint
|
---|
| 1869 | * @param *b second endpoint
|
---|
| 1870 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1871 | */
|
---|
[474961] | 1872 | void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
|
---|
[357fba] | 1873 | {
|
---|
[6613ec] | 1874 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1875 | DoLog(0) && (Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl);
|
---|
[357fba] | 1876 | BPS[0] = a;
|
---|
| 1877 | BPS[1] = b;
|
---|
[6613ec] | 1878 | BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
|
---|
[357fba] | 1879 | // add line to global map
|
---|
| 1880 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
|
---|
| 1881 | // increase counter
|
---|
| 1882 | LinesOnBoundaryCount++;
|
---|
[1e168b] | 1883 | // also add to open lines
|
---|
| 1884 | CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
|
---|
[6613ec] | 1885 | OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
|
---|
| 1886 | }
|
---|
| 1887 | ;
|
---|
[357fba] | 1888 |
|
---|
[474961] | 1889 | /** Uses an existing line for a new triangle.
|
---|
| 1890 | * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines.
|
---|
| 1891 | * \param *FindLine the line to add
|
---|
| 1892 | * \param n index of the line to set in Tesselation::BLS
|
---|
| 1893 | */
|
---|
| 1894 | void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n)
|
---|
| 1895 | {
|
---|
| 1896 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1897 | DoLog(0) && (Log() << Verbose(0) << "Using existing line " << *Line << endl);
|
---|
[474961] | 1898 |
|
---|
| 1899 | // set endpoints and line
|
---|
| 1900 | BPS[0] = Line->endpoints[0];
|
---|
| 1901 | BPS[1] = Line->endpoints[1];
|
---|
| 1902 | BLS[n] = Line;
|
---|
| 1903 | // remove existing line from OpenLines
|
---|
| 1904 | CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
|
---|
| 1905 | if (CandidateLine != OpenLines.end()) {
|
---|
[a67d19] | 1906 | DoLog(1) && (Log() << Verbose(1) << " Removing line from OpenLines." << endl);
|
---|
[6613ec] | 1907 | delete (CandidateLine->second);
|
---|
[474961] | 1908 | OpenLines.erase(CandidateLine);
|
---|
| 1909 | } else {
|
---|
[6613ec] | 1910 | DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
|
---|
[474961] | 1911 | }
|
---|
[6613ec] | 1912 | }
|
---|
| 1913 | ;
|
---|
[357fba] | 1914 |
|
---|
[7dea7c] | 1915 | /** Function adds triangle to global list.
|
---|
| 1916 | * Furthermore, the triangle receives the next free id and id counter \a TrianglesOnBoundaryCount is increased.
|
---|
[357fba] | 1917 | */
|
---|
[16d866] | 1918 | void Tesselation::AddTesselationTriangle()
|
---|
[357fba] | 1919 | {
|
---|
[6613ec] | 1920 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1921 | DoLog(1) && (Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl);
|
---|
[357fba] | 1922 |
|
---|
| 1923 | // add triangle to global map
|
---|
| 1924 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1925 | TrianglesOnBoundaryCount++;
|
---|
| 1926 |
|
---|
[57066a] | 1927 | // set as last new triangle
|
---|
| 1928 | LastTriangle = BTS;
|
---|
| 1929 |
|
---|
[357fba] | 1930 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
[6613ec] | 1931 | }
|
---|
| 1932 | ;
|
---|
[16d866] | 1933 |
|
---|
[7dea7c] | 1934 | /** Function adds triangle to global list.
|
---|
| 1935 | * Furthermore, the triangle number is set to \a nr.
|
---|
| 1936 | * \param nr triangle number
|
---|
| 1937 | */
|
---|
[776b64] | 1938 | void Tesselation::AddTesselationTriangle(const int nr)
|
---|
[7dea7c] | 1939 | {
|
---|
[6613ec] | 1940 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1941 | DoLog(0) && (Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl);
|
---|
[7dea7c] | 1942 |
|
---|
| 1943 | // add triangle to global map
|
---|
| 1944 | TrianglesOnBoundary.insert(TrianglePair(nr, BTS));
|
---|
| 1945 |
|
---|
| 1946 | // set as last new triangle
|
---|
| 1947 | LastTriangle = BTS;
|
---|
| 1948 |
|
---|
| 1949 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
[6613ec] | 1950 | }
|
---|
| 1951 | ;
|
---|
[7dea7c] | 1952 |
|
---|
[16d866] | 1953 | /** Removes a triangle from the tesselation.
|
---|
| 1954 | * Removes itself from the TriangleMap's of its lines, calls for them RemoveTriangleLine() if they are no more connected.
|
---|
| 1955 | * Removes itself from memory.
|
---|
| 1956 | * \param *triangle to remove
|
---|
| 1957 | */
|
---|
| 1958 | void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
|
---|
| 1959 | {
|
---|
[6613ec] | 1960 | Info FunctionInfo(__func__);
|
---|
[16d866] | 1961 | if (triangle == NULL)
|
---|
| 1962 | return;
|
---|
| 1963 | for (int i = 0; i < 3; i++) {
|
---|
| 1964 | if (triangle->lines[i] != NULL) {
|
---|
[a67d19] | 1965 | DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl);
|
---|
[16d866] | 1966 | triangle->lines[i]->triangles.erase(triangle->Nr);
|
---|
| 1967 | if (triangle->lines[i]->triangles.empty()) {
|
---|
[a67d19] | 1968 | DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl);
|
---|
[6613ec] | 1969 | RemoveTesselationLine(triangle->lines[i]);
|
---|
[065e82] | 1970 | } else {
|
---|
[accebe] | 1971 | DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: " << endl);
|
---|
[6613ec] | 1972 | OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
|
---|
| 1973 | for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
|
---|
[accebe] | 1974 | DoLog(0) && (Log() << Verbose(0) << "\t[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t");
|
---|
[a67d19] | 1975 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[6613ec] | 1976 | // for (int j=0;j<2;j++) {
|
---|
| 1977 | // Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
|
---|
| 1978 | // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
|
---|
| 1979 | // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
|
---|
| 1980 | // Log() << Verbose(0) << endl;
|
---|
| 1981 | // }
|
---|
[065e82] | 1982 | }
|
---|
[6613ec] | 1983 | triangle->lines[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 1984 | } else
|
---|
[6613ec] | 1985 | DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl);
|
---|
[16d866] | 1986 | }
|
---|
| 1987 |
|
---|
| 1988 | if (TrianglesOnBoundary.erase(triangle->Nr))
|
---|
[a67d19] | 1989 | DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl);
|
---|
[6613ec] | 1990 | delete (triangle);
|
---|
| 1991 | }
|
---|
| 1992 | ;
|
---|
[16d866] | 1993 |
|
---|
| 1994 | /** Removes a line from the tesselation.
|
---|
| 1995 | * Removes itself from each endpoints' LineMap, then removes itself from global LinesOnBoundary list and free's the line.
|
---|
| 1996 | * \param *line line to remove
|
---|
| 1997 | */
|
---|
| 1998 | void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
|
---|
| 1999 | {
|
---|
[6613ec] | 2000 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2001 | int Numbers[2];
|
---|
| 2002 |
|
---|
| 2003 | if (line == NULL)
|
---|
| 2004 | return;
|
---|
[065e82] | 2005 | // get other endpoint number for finding copies of same line
|
---|
[16d866] | 2006 | if (line->endpoints[1] != NULL)
|
---|
| 2007 | Numbers[0] = line->endpoints[1]->Nr;
|
---|
| 2008 | else
|
---|
| 2009 | Numbers[0] = -1;
|
---|
| 2010 | if (line->endpoints[0] != NULL)
|
---|
| 2011 | Numbers[1] = line->endpoints[0]->Nr;
|
---|
| 2012 | else
|
---|
| 2013 | Numbers[1] = -1;
|
---|
| 2014 |
|
---|
| 2015 | for (int i = 0; i < 2; i++) {
|
---|
| 2016 | if (line->endpoints[i] != NULL) {
|
---|
| 2017 | 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
|
---|
| 2018 | pair<LineMap::iterator, LineMap::iterator> erasor = line->endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 2019 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 2020 | if ((*Runner).second == line) {
|
---|
[a67d19] | 2021 | DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
|
---|
[16d866] | 2022 | line->endpoints[i]->lines.erase(Runner);
|
---|
| 2023 | break;
|
---|
| 2024 | }
|
---|
| 2025 | } else { // there's just a single line left
|
---|
| 2026 | if (line->endpoints[i]->lines.erase(line->Nr))
|
---|
[a67d19] | 2027 | DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
|
---|
[16d866] | 2028 | }
|
---|
| 2029 | if (line->endpoints[i]->lines.empty()) {
|
---|
[a67d19] | 2030 | DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl);
|
---|
[16d866] | 2031 | RemoveTesselationPoint(line->endpoints[i]);
|
---|
[065e82] | 2032 | } else {
|
---|
[a67d19] | 2033 | DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ");
|
---|
[6613ec] | 2034 | for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
|
---|
[a67d19] | 2035 | DoLog(0) && (Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t");
|
---|
| 2036 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[065e82] | 2037 | }
|
---|
[6613ec] | 2038 | line->endpoints[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 2039 | } else
|
---|
[6613ec] | 2040 | DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);
|
---|
[16d866] | 2041 | }
|
---|
| 2042 | if (!line->triangles.empty())
|
---|
[6613ec] | 2043 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);
|
---|
[16d866] | 2044 |
|
---|
| 2045 | if (LinesOnBoundary.erase(line->Nr))
|
---|
[a67d19] | 2046 | DoLog(0) && (Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl);
|
---|
[6613ec] | 2047 | delete (line);
|
---|
| 2048 | }
|
---|
| 2049 | ;
|
---|
[16d866] | 2050 |
|
---|
| 2051 | /** Removes a point from the tesselation.
|
---|
| 2052 | * Checks whether there are still lines connected, removes from global PointsOnBoundary list, then free's the point.
|
---|
| 2053 | * \note If a point should be removed, while keep the tesselated surface intact (i.e. closed), use RemovePointFromTesselatedSurface()
|
---|
| 2054 | * \param *point point to remove
|
---|
| 2055 | */
|
---|
| 2056 | void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
|
---|
| 2057 | {
|
---|
[6613ec] | 2058 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2059 | if (point == NULL)
|
---|
| 2060 | return;
|
---|
| 2061 | if (PointsOnBoundary.erase(point->Nr))
|
---|
[a67d19] | 2062 | DoLog(0) && (Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl);
|
---|
[6613ec] | 2063 | delete (point);
|
---|
| 2064 | }
|
---|
| 2065 | ;
|
---|
[f07f86d] | 2066 |
|
---|
| 2067 | /** Checks validity of a given sphere of a candidate line.
|
---|
| 2068 | * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
|
---|
[6613ec] | 2069 | * We check CandidateForTesselation::OtherOptCenter
|
---|
| 2070 | * \param &CandidateLine contains other degenerated candidates which we have to subtract as well
|
---|
[f07f86d] | 2071 | * \param RADIUS radius of sphere
|
---|
| 2072 | * \param *LC LinkedCell structure with other atoms
|
---|
| 2073 | * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
|
---|
| 2074 | */
|
---|
[6613ec] | 2075 | bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const
|
---|
[f07f86d] | 2076 | {
|
---|
| 2077 | Info FunctionInfo(__func__);
|
---|
| 2078 |
|
---|
| 2079 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
|
---|
| 2080 | bool flag = true;
|
---|
| 2081 |
|
---|
[8cbb97] | 2082 | DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30" << endl);
|
---|
[f07f86d] | 2083 | // get all points inside the sphere
|
---|
[6613ec] | 2084 | TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
|
---|
[f07f86d] | 2085 |
|
---|
[a67d19] | 2086 | DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
|
---|
[f07f86d] | 2087 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[1513a74] | 2088 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(CandidateLine.OtherOptCenter) << "." << endl);
|
---|
[f07f86d] | 2089 |
|
---|
| 2090 | // remove triangles's endpoints
|
---|
[6613ec] | 2091 | for (int i = 0; i < 2; i++)
|
---|
| 2092 | ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node);
|
---|
| 2093 |
|
---|
| 2094 | // remove other candidates
|
---|
| 2095 | for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner)
|
---|
| 2096 | ListofPoints->remove(*Runner);
|
---|
[f07f86d] | 2097 |
|
---|
| 2098 | // check for other points
|
---|
| 2099 | if (!ListofPoints->empty()) {
|
---|
[a67d19] | 2100 | DoLog(1) && (Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
|
---|
[f07f86d] | 2101 | flag = false;
|
---|
[a67d19] | 2102 | DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
|
---|
[f07f86d] | 2103 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[1513a74] | 2104 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(CandidateLine.OtherOptCenter) << "." << endl);
|
---|
[f07f86d] | 2105 | }
|
---|
[6613ec] | 2106 | delete (ListofPoints);
|
---|
[f07f86d] | 2107 |
|
---|
| 2108 | return flag;
|
---|
[6613ec] | 2109 | }
|
---|
| 2110 | ;
|
---|
[357fba] | 2111 |
|
---|
[62bb91] | 2112 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
[357fba] | 2113 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 2114 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 2115 | * returned.
|
---|
| 2116 | * \param *out output stream for debugging
|
---|
| 2117 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 2118 | * \return integer 0 if no triangle exists, 1 if one triangle exists, 2 if two
|
---|
| 2119 | * triangles exist which is the maximum for three points
|
---|
| 2120 | */
|
---|
[f1ef60a] | 2121 | int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
|
---|
| 2122 | {
|
---|
[6613ec] | 2123 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2124 | int adjacentTriangleCount = 0;
|
---|
| 2125 | class BoundaryPointSet *Points[3];
|
---|
| 2126 |
|
---|
| 2127 | // builds a triangle point set (Points) of the end points
|
---|
| 2128 | for (int i = 0; i < 3; i++) {
|
---|
[f1ef60a] | 2129 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
[357fba] | 2130 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2131 | Points[i] = FindPoint->second;
|
---|
| 2132 | } else {
|
---|
| 2133 | Points[i] = NULL;
|
---|
| 2134 | }
|
---|
| 2135 | }
|
---|
| 2136 |
|
---|
| 2137 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 2138 | for (int i = 0; i < 3; i++) {
|
---|
| 2139 | if (Points[i] != NULL) {
|
---|
| 2140 | for (int j = i; j < 3; j++) {
|
---|
| 2141 | if (Points[j] != NULL) {
|
---|
[f1ef60a] | 2142 | LineMap::const_iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
[357fba] | 2143 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 2144 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
[a67d19] | 2145 | DoLog(1) && (Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl);
|
---|
[f1ef60a] | 2146 | for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
[357fba] | 2147 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 2148 | adjacentTriangleCount++;
|
---|
| 2149 | }
|
---|
| 2150 | }
|
---|
[a67d19] | 2151 | DoLog(1) && (Log() << Verbose(1) << "end." << endl);
|
---|
[357fba] | 2152 | }
|
---|
| 2153 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[f67b6e] | 2154 | //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 2155 | //return adjacentTriangleCount;
|
---|
[357fba] | 2156 | }
|
---|
| 2157 | }
|
---|
| 2158 | }
|
---|
| 2159 | }
|
---|
| 2160 |
|
---|
[a67d19] | 2161 | DoLog(0) && (Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl);
|
---|
[357fba] | 2162 | return adjacentTriangleCount;
|
---|
[6613ec] | 2163 | }
|
---|
| 2164 | ;
|
---|
[357fba] | 2165 |
|
---|
[065e82] | 2166 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
| 2167 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 2168 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 2169 | * returned.
|
---|
| 2170 | * \param *out output stream for debugging
|
---|
| 2171 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 2172 | * \return NULL - none found or pointer to triangle
|
---|
| 2173 | */
|
---|
[e138de] | 2174 | class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
|
---|
[065e82] | 2175 | {
|
---|
[6613ec] | 2176 | Info FunctionInfo(__func__);
|
---|
[065e82] | 2177 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 2178 | class BoundaryPointSet *Points[3];
|
---|
| 2179 |
|
---|
| 2180 | // builds a triangle point set (Points) of the end points
|
---|
| 2181 | for (int i = 0; i < 3; i++) {
|
---|
| 2182 | PointMap::iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
| 2183 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2184 | Points[i] = FindPoint->second;
|
---|
| 2185 | } else {
|
---|
| 2186 | Points[i] = NULL;
|
---|
| 2187 | }
|
---|
| 2188 | }
|
---|
| 2189 |
|
---|
| 2190 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 2191 | for (int i = 0; i < 3; i++) {
|
---|
| 2192 | if (Points[i] != NULL) {
|
---|
| 2193 | for (int j = i; j < 3; j++) {
|
---|
| 2194 | if (Points[j] != NULL) {
|
---|
| 2195 | LineMap::iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
| 2196 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 2197 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
| 2198 | for (TriangleMap::iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
| 2199 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 2200 | if ((triangle == NULL) || (triangle->Nr > FindTriangle->second->Nr))
|
---|
| 2201 | triangle = FindTriangle->second;
|
---|
| 2202 | }
|
---|
| 2203 | }
|
---|
| 2204 | }
|
---|
| 2205 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[f67b6e] | 2206 | //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 2207 | //return adjacentTriangleCount;
|
---|
| 2208 | }
|
---|
| 2209 | }
|
---|
| 2210 | }
|
---|
| 2211 | }
|
---|
| 2212 |
|
---|
| 2213 | return triangle;
|
---|
[6613ec] | 2214 | }
|
---|
| 2215 | ;
|
---|
[357fba] | 2216 |
|
---|
[f1cccd] | 2217 | /** Finds the starting triangle for FindNonConvexBorder().
|
---|
| 2218 | * Looks at the outermost point per axis, then FindSecondPointForTesselation()
|
---|
| 2219 | * for the second and FindNextSuitablePointViaAngleOfSphere() for the third
|
---|
[357fba] | 2220 | * point are called.
|
---|
| 2221 | * \param *out output stream for debugging
|
---|
| 2222 | * \param RADIUS radius of virtual rolling sphere
|
---|
| 2223 | * \param *LC LinkedCell structure with neighbouring TesselPoint's
|
---|
[ce70970] | 2224 | * \return true - a starting triangle has been created, false - no valid triple of points found
|
---|
[357fba] | 2225 | */
|
---|
[ce70970] | 2226 | bool Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2227 | {
|
---|
[6613ec] | 2228 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2229 | int i = 0;
|
---|
[62bb91] | 2230 | TesselPoint* MaxPoint[NDIM];
|
---|
[7273fc] | 2231 | TesselPoint* Temporary;
|
---|
[f1cccd] | 2232 | double maxCoordinate[NDIM];
|
---|
[f07f86d] | 2233 | BoundaryLineSet *BaseLine = NULL;
|
---|
[357fba] | 2234 | Vector helper;
|
---|
| 2235 | Vector Chord;
|
---|
| 2236 | Vector SearchDirection;
|
---|
[6613ec] | 2237 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
[b998c3] | 2238 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 2239 | Vector SphereCenter;
|
---|
| 2240 | Vector NormalVector;
|
---|
[357fba] | 2241 |
|
---|
[b998c3] | 2242 | NormalVector.Zero();
|
---|
[357fba] | 2243 |
|
---|
| 2244 | for (i = 0; i < 3; i++) {
|
---|
[62bb91] | 2245 | MaxPoint[i] = NULL;
|
---|
[f1cccd] | 2246 | maxCoordinate[i] = -1;
|
---|
[357fba] | 2247 | }
|
---|
| 2248 |
|
---|
[62bb91] | 2249 | // 1. searching topmost point with respect to each axis
|
---|
[6613ec] | 2250 | for (int i = 0; i < NDIM; i++) { // each axis
|
---|
| 2251 | LC->n[i] = LC->N[i] - 1; // current axis is topmost cell
|
---|
[bdc91e] | 2252 | const int map[NDIM] = {i, (i + 1) % NDIM, (i + 2) % NDIM};
|
---|
| 2253 | for (LC->n[map[1]] = 0; LC->n[map[1]] < LC->N[map[1]]; LC->n[map[1]]++)
|
---|
| 2254 | for (LC->n[map[2]] = 0; LC->n[map[2]] < LC->N[map[2]]; LC->n[map[2]]++) {
|
---|
[734816] | 2255 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 2256 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2257 | if (List != NULL) {
|
---|
[6613ec] | 2258 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[bdc91e] | 2259 | if ((*Runner)->node->at(map[0]) > maxCoordinate[map[0]]) {
|
---|
| 2260 | DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << map[0] << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl);
|
---|
| 2261 | maxCoordinate[map[0]] = (*Runner)->node->at(map[0]);
|
---|
| 2262 | MaxPoint[map[0]] = (*Runner);
|
---|
[357fba] | 2263 | }
|
---|
| 2264 | }
|
---|
| 2265 | } else {
|
---|
[6613ec] | 2266 | DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
|
---|
[357fba] | 2267 | }
|
---|
| 2268 | }
|
---|
| 2269 | }
|
---|
| 2270 |
|
---|
[a67d19] | 2271 | DoLog(1) && (Log() << Verbose(1) << "Found maximum coordinates: ");
|
---|
[6613ec] | 2272 | for (int i = 0; i < NDIM; i++)
|
---|
[a67d19] | 2273 | DoLog(0) && (Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t");
|
---|
| 2274 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[357fba] | 2275 |
|
---|
| 2276 | BTS = NULL;
|
---|
[6613ec] | 2277 | for (int k = 0; k < NDIM; k++) {
|
---|
[b998c3] | 2278 | NormalVector.Zero();
|
---|
[0a4f7f] | 2279 | NormalVector[k] = 1.;
|
---|
[f07f86d] | 2280 | BaseLine = new BoundaryLineSet();
|
---|
| 2281 | BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
|
---|
[a67d19] | 2282 | DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
|
---|
[357fba] | 2283 |
|
---|
| 2284 | double ShortestAngle;
|
---|
| 2285 | ShortestAngle = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
|
---|
| 2286 |
|
---|
[cfe56d] | 2287 | Temporary = NULL;
|
---|
[f07f86d] | 2288 | FindSecondPointForTesselation(BaseLine->endpoints[0]->node, NormalVector, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
|
---|
[711ac2] | 2289 | if (Temporary == NULL) {
|
---|
| 2290 | // have we found a second point?
|
---|
| 2291 | delete BaseLine;
|
---|
[357fba] | 2292 | continue;
|
---|
[711ac2] | 2293 | }
|
---|
[f07f86d] | 2294 | BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
|
---|
[357fba] | 2295 |
|
---|
[b998c3] | 2296 | // construct center of circle
|
---|
[8cbb97] | 2297 | CircleCenter = 0.5 * ((*BaseLine->endpoints[0]->node->node) + (*BaseLine->endpoints[1]->node->node));
|
---|
[b998c3] | 2298 |
|
---|
| 2299 | // construct normal vector of circle
|
---|
[8cbb97] | 2300 | CirclePlaneNormal = (*BaseLine->endpoints[0]->node->node) - (*BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2301 |
|
---|
[b998c3] | 2302 | double radius = CirclePlaneNormal.NormSquared();
|
---|
[6613ec] | 2303 | double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
|
---|
[b998c3] | 2304 |
|
---|
[273382] | 2305 | NormalVector.ProjectOntoPlane(CirclePlaneNormal);
|
---|
[b998c3] | 2306 | NormalVector.Normalize();
|
---|
[6613ec] | 2307 | ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
|
---|
[b998c3] | 2308 |
|
---|
[273382] | 2309 | SphereCenter = (CircleRadius * NormalVector) + CircleCenter;
|
---|
[b998c3] | 2310 | // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
|
---|
[357fba] | 2311 |
|
---|
| 2312 | // look in one direction of baseline for initial candidate
|
---|
[0a4f7f] | 2313 | SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ...
|
---|
[357fba] | 2314 |
|
---|
[5c7bf8] | 2315 | // adding point 1 and point 2 and add the line between them
|
---|
[a67d19] | 2316 | DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
|
---|
| 2317 | DoLog(0) && (Log() << Verbose(0) << "Found second point is at " << *BaseLine->endpoints[1]->node << ".\n");
|
---|
[357fba] | 2318 |
|
---|
[f67b6e] | 2319 | //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
|
---|
[f07f86d] | 2320 | CandidateForTesselation OptCandidates(BaseLine);
|
---|
[b998c3] | 2321 | FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
|
---|
[a67d19] | 2322 | DoLog(0) && (Log() << Verbose(0) << "List of third Points is:" << endl);
|
---|
[f67b6e] | 2323 | for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
|
---|
[a67d19] | 2324 | DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
|
---|
[357fba] | 2325 | }
|
---|
[f07f86d] | 2326 | if (!OptCandidates.pointlist.empty()) {
|
---|
| 2327 | BTS = NULL;
|
---|
| 2328 | AddCandidatePolygon(OptCandidates, RADIUS, LC);
|
---|
| 2329 | } else {
|
---|
| 2330 | delete BaseLine;
|
---|
| 2331 | continue;
|
---|
[357fba] | 2332 | }
|
---|
| 2333 |
|
---|
[711ac2] | 2334 | if (BTS != NULL) { // we have created one starting triangle
|
---|
| 2335 | delete BaseLine;
|
---|
[357fba] | 2336 | break;
|
---|
[711ac2] | 2337 | } else {
|
---|
[357fba] | 2338 | // remove all candidates from the list and then the list itself
|
---|
[7273fc] | 2339 | OptCandidates.pointlist.clear();
|
---|
[357fba] | 2340 | }
|
---|
[f07f86d] | 2341 | delete BaseLine;
|
---|
[357fba] | 2342 | }
|
---|
[ce70970] | 2343 |
|
---|
| 2344 | return (BTS != NULL);
|
---|
[6613ec] | 2345 | }
|
---|
| 2346 | ;
|
---|
[357fba] | 2347 |
|
---|
[f1ef60a] | 2348 | /** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
|
---|
| 2349 | * This is supposed to prevent early closing of the tesselation.
|
---|
[f67b6e] | 2350 | * \param CandidateLine CandidateForTesselation with baseline and shortestangle , i.e. not \a *OptCandidate
|
---|
[f1ef60a] | 2351 | * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
|
---|
| 2352 | * \param RADIUS radius of sphere
|
---|
| 2353 | * \param *LC LinkedCell structure
|
---|
| 2354 | * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
|
---|
| 2355 | */
|
---|
[f67b6e] | 2356 | //bool Tesselation::HasOtherBaselineBetterCandidate(CandidateForTesselation &CandidateLine, const TesselPoint * const ThirdNode, double RADIUS, const LinkedCell * const LC) const
|
---|
| 2357 | //{
|
---|
| 2358 | // Info FunctionInfo(__func__);
|
---|
| 2359 | // bool result = false;
|
---|
| 2360 | // Vector CircleCenter;
|
---|
| 2361 | // Vector CirclePlaneNormal;
|
---|
| 2362 | // Vector OldSphereCenter;
|
---|
| 2363 | // Vector SearchDirection;
|
---|
| 2364 | // Vector helper;
|
---|
| 2365 | // TesselPoint *OtherOptCandidate = NULL;
|
---|
| 2366 | // double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
|
---|
| 2367 | // double radius, CircleRadius;
|
---|
| 2368 | // BoundaryLineSet *Line = NULL;
|
---|
| 2369 | // BoundaryTriangleSet *T = NULL;
|
---|
| 2370 | //
|
---|
| 2371 | // // check both other lines
|
---|
| 2372 | // PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
|
---|
| 2373 | // if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2374 | // for (int i=0;i<2;i++) {
|
---|
| 2375 | // LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
|
---|
| 2376 | // if (FindLine != (FindPoint->second)->lines.end()) {
|
---|
| 2377 | // Line = FindLine->second;
|
---|
| 2378 | // Log() << Verbose(0) << "Found line " << *Line << "." << endl;
|
---|
| 2379 | // if (Line->triangles.size() == 1) {
|
---|
| 2380 | // T = Line->triangles.begin()->second;
|
---|
| 2381 | // // construct center of circle
|
---|
| 2382 | // CircleCenter.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2383 | // CircleCenter.AddVector(Line->endpoints[1]->node->node);
|
---|
| 2384 | // CircleCenter.Scale(0.5);
|
---|
| 2385 | //
|
---|
| 2386 | // // construct normal vector of circle
|
---|
| 2387 | // CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2388 | // CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
|
---|
| 2389 | //
|
---|
| 2390 | // // calculate squared radius of circle
|
---|
| 2391 | // radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
|
---|
| 2392 | // if (radius/4. < RADIUS*RADIUS) {
|
---|
| 2393 | // CircleRadius = RADIUS*RADIUS - radius/4.;
|
---|
| 2394 | // CirclePlaneNormal.Normalize();
|
---|
| 2395 | // //Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
| 2396 | //
|
---|
| 2397 | // // construct old center
|
---|
| 2398 | // GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
|
---|
| 2399 | // helper.CopyVector(&T->NormalVector); // normal vector ensures that this is correct center of the two possible ones
|
---|
| 2400 | // radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
|
---|
| 2401 | // helper.Scale(sqrt(RADIUS*RADIUS - radius));
|
---|
| 2402 | // OldSphereCenter.AddVector(&helper);
|
---|
| 2403 | // OldSphereCenter.SubtractVector(&CircleCenter);
|
---|
| 2404 | // //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
|
---|
| 2405 | //
|
---|
| 2406 | // // construct SearchDirection
|
---|
| 2407 | // SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
|
---|
| 2408 | // helper.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2409 | // helper.SubtractVector(ThirdNode->node);
|
---|
| 2410 | // if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
| 2411 | // SearchDirection.Scale(-1.);
|
---|
| 2412 | // SearchDirection.ProjectOntoPlane(&OldSphereCenter);
|
---|
| 2413 | // SearchDirection.Normalize();
|
---|
| 2414 | // Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
| 2415 | // if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
|
---|
| 2416 | // // rotated the wrong way!
|
---|
[58ed4a] | 2417 | // DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
|
---|
[f67b6e] | 2418 | // }
|
---|
| 2419 | //
|
---|
| 2420 | // // add third point
|
---|
| 2421 | // FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, OptCandidates, ThirdNode, RADIUS, LC);
|
---|
| 2422 | // for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); ++it) {
|
---|
| 2423 | // if (((*it) == BaseRay->endpoints[0]->node) || ((*it) == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
|
---|
| 2424 | // continue;
|
---|
| 2425 | // Log() << Verbose(0) << " Third point candidate is " << (*it)
|
---|
| 2426 | // << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
|
---|
| 2427 | // Log() << Verbose(0) << " Baseline is " << *BaseRay << endl;
|
---|
| 2428 | //
|
---|
| 2429 | // // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
|
---|
| 2430 | // TesselPoint *PointCandidates[3];
|
---|
| 2431 | // PointCandidates[0] = (*it);
|
---|
| 2432 | // PointCandidates[1] = BaseRay->endpoints[0]->node;
|
---|
| 2433 | // PointCandidates[2] = BaseRay->endpoints[1]->node;
|
---|
| 2434 | // bool check=false;
|
---|
| 2435 | // int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
|
---|
| 2436 | // // If there is no triangle, add it regularly.
|
---|
| 2437 | // if (existentTrianglesCount == 0) {
|
---|
| 2438 | // SetTesselationPoint((*it), 0);
|
---|
| 2439 | // SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2440 | // SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2441 | //
|
---|
| 2442 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
|
---|
| 2443 | // OtherOptCandidate = (*it);
|
---|
| 2444 | // check = true;
|
---|
| 2445 | // }
|
---|
| 2446 | // } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
|
---|
| 2447 | // SetTesselationPoint((*it), 0);
|
---|
| 2448 | // SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2449 | // SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2450 | //
|
---|
| 2451 | // // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
|
---|
| 2452 | // // i.e. at least one of the three lines must be present with TriangleCount <= 1
|
---|
| 2453 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
|
---|
| 2454 | // OtherOptCandidate = (*it);
|
---|
| 2455 | // check = true;
|
---|
| 2456 | // }
|
---|
| 2457 | // }
|
---|
| 2458 | //
|
---|
| 2459 | // if (check) {
|
---|
| 2460 | // if (ShortestAngle > OtherShortestAngle) {
|
---|
| 2461 | // Log() << Verbose(0) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
|
---|
| 2462 | // result = true;
|
---|
| 2463 | // break;
|
---|
| 2464 | // }
|
---|
| 2465 | // }
|
---|
| 2466 | // }
|
---|
| 2467 | // delete(OptCandidates);
|
---|
| 2468 | // if (result)
|
---|
| 2469 | // break;
|
---|
| 2470 | // } else {
|
---|
| 2471 | // Log() << Verbose(0) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
|
---|
| 2472 | // }
|
---|
| 2473 | // } else {
|
---|
[58ed4a] | 2474 | // DoeLog(2) && (eLog()<< Verbose(2) << "Baseline is connected to two triangles already?" << endl);
|
---|
[f67b6e] | 2475 | // }
|
---|
| 2476 | // } else {
|
---|
| 2477 | // Log() << Verbose(1) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
|
---|
| 2478 | // }
|
---|
| 2479 | // }
|
---|
| 2480 | // } else {
|
---|
[58ed4a] | 2481 | // DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl);
|
---|
[f67b6e] | 2482 | // }
|
---|
| 2483 | //
|
---|
| 2484 | // return result;
|
---|
| 2485 | //};
|
---|
[357fba] | 2486 |
|
---|
| 2487 | /** This function finds a triangle to a line, adjacent to an existing one.
|
---|
| 2488 | * @param out output stream for debugging
|
---|
[1e168b] | 2489 | * @param CandidateLine current cadndiate baseline to search from
|
---|
[357fba] | 2490 | * @param T current triangle which \a Line is edge of
|
---|
| 2491 | * @param RADIUS radius of the rolling ball
|
---|
| 2492 | * @param N number of found triangles
|
---|
[62bb91] | 2493 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 2494 | */
|
---|
[f07f86d] | 2495 | bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2496 | {
|
---|
[6613ec] | 2497 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2498 | Vector CircleCenter;
|
---|
| 2499 | Vector CirclePlaneNormal;
|
---|
[b998c3] | 2500 | Vector RelativeSphereCenter;
|
---|
[357fba] | 2501 | Vector SearchDirection;
|
---|
| 2502 | Vector helper;
|
---|
[09898c] | 2503 | BoundaryPointSet *ThirdPoint = NULL;
|
---|
[357fba] | 2504 | LineMap::iterator testline;
|
---|
| 2505 | double radius, CircleRadius;
|
---|
| 2506 |
|
---|
[6613ec] | 2507 | for (int i = 0; i < 3; i++)
|
---|
[09898c] | 2508 | if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
|
---|
| 2509 | ThirdPoint = T.endpoints[i];
|
---|
[b998c3] | 2510 | break;
|
---|
| 2511 | }
|
---|
[a67d19] | 2512 | DoLog(0) && (Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << "." << endl);
|
---|
[09898c] | 2513 |
|
---|
| 2514 | CandidateLine.T = &T;
|
---|
[357fba] | 2515 |
|
---|
| 2516 | // construct center of circle
|
---|
[273382] | 2517 | CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
|
---|
| 2518 | (*CandidateLine.BaseLine->endpoints[1]->node->node));
|
---|
[357fba] | 2519 |
|
---|
| 2520 | // construct normal vector of circle
|
---|
[273382] | 2521 | CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
|
---|
| 2522 | (*CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2523 |
|
---|
| 2524 | // calculate squared radius of circle
|
---|
[273382] | 2525 | radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal);
|
---|
[6613ec] | 2526 | if (radius / 4. < RADIUS * RADIUS) {
|
---|
[b998c3] | 2527 | // construct relative sphere center with now known CircleCenter
|
---|
[273382] | 2528 | RelativeSphereCenter = T.SphereCenter - CircleCenter;
|
---|
[b998c3] | 2529 |
|
---|
[6613ec] | 2530 | CircleRadius = RADIUS * RADIUS - radius / 4.;
|
---|
[357fba] | 2531 | CirclePlaneNormal.Normalize();
|
---|
[a67d19] | 2532 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
[357fba] | 2533 |
|
---|
[a67d19] | 2534 | DoLog(1) && (Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl);
|
---|
[b998c3] | 2535 |
|
---|
| 2536 | // construct SearchDirection and an "outward pointer"
|
---|
[0a4f7f] | 2537 | SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal();
|
---|
[8cbb97] | 2538 | helper = CircleCenter - (*ThirdPoint->node->node);
|
---|
[273382] | 2539 | if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
[357fba] | 2540 | SearchDirection.Scale(-1.);
|
---|
[a67d19] | 2541 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
[273382] | 2542 | if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) {
|
---|
[357fba] | 2543 | // rotated the wrong way!
|
---|
[6613ec] | 2544 | DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
|
---|
[357fba] | 2545 | }
|
---|
| 2546 |
|
---|
| 2547 | // add third point
|
---|
[09898c] | 2548 | FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC);
|
---|
[357fba] | 2549 |
|
---|
| 2550 | } else {
|
---|
[a67d19] | 2551 | DoLog(0) && (Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl);
|
---|
[357fba] | 2552 | }
|
---|
| 2553 |
|
---|
[f67b6e] | 2554 | if (CandidateLine.pointlist.empty()) {
|
---|
[6613ec] | 2555 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl);
|
---|
[357fba] | 2556 | return false;
|
---|
| 2557 | }
|
---|
[a67d19] | 2558 | DoLog(0) && (Log() << Verbose(0) << "Third Points are: " << endl);
|
---|
[f67b6e] | 2559 | for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
|
---|
[a67d19] | 2560 | DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
|
---|
[357fba] | 2561 | }
|
---|
| 2562 |
|
---|
[f67b6e] | 2563 | return true;
|
---|
[6613ec] | 2564 | }
|
---|
| 2565 | ;
|
---|
[f67b6e] | 2566 |
|
---|
[6613ec] | 2567 | /** Walks through Tesselation::OpenLines() and finds candidates for newly created ones.
|
---|
| 2568 | * \param *&LCList atoms in LinkedCell list
|
---|
| 2569 | * \param RADIUS radius of the virtual sphere
|
---|
| 2570 | * \return true - for all open lines without candidates so far, a candidate has been found,
|
---|
| 2571 | * false - at least one open line without candidate still
|
---|
| 2572 | */
|
---|
| 2573 | bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList)
|
---|
| 2574 | {
|
---|
| 2575 | bool TesselationFailFlag = true;
|
---|
| 2576 | CandidateForTesselation *baseline = NULL;
|
---|
| 2577 | BoundaryTriangleSet *T = NULL;
|
---|
| 2578 |
|
---|
| 2579 | for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
|
---|
| 2580 | baseline = Runner->second;
|
---|
| 2581 | if (baseline->pointlist.empty()) {
|
---|
[6d574a] | 2582 | ASSERT((baseline->BaseLine->triangles.size() == 1),"Open line without exactly one attached triangle");
|
---|
[6613ec] | 2583 | T = (((baseline->BaseLine->triangles.begin()))->second);
|
---|
[a67d19] | 2584 | DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl);
|
---|
[6613ec] | 2585 | TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
|
---|
| 2586 | }
|
---|
| 2587 | }
|
---|
| 2588 | return TesselationFailFlag;
|
---|
| 2589 | }
|
---|
| 2590 | ;
|
---|
[357fba] | 2591 |
|
---|
[1e168b] | 2592 | /** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
|
---|
[f67b6e] | 2593 | * \param CandidateLine triangle to add
|
---|
[474961] | 2594 | * \param RADIUS Radius of sphere
|
---|
| 2595 | * \param *LC LinkedCell structure
|
---|
| 2596 | * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in
|
---|
| 2597 | * AddTesselationLine() in AddCandidateTriangle()
|
---|
[1e168b] | 2598 | */
|
---|
[474961] | 2599 | void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC)
|
---|
[1e168b] | 2600 | {
|
---|
[ebb50e] | 2601 | Info FunctionInfo(__func__);
|
---|
[1e168b] | 2602 | Vector Center;
|
---|
[27bd2f] | 2603 | TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
|
---|
[09898c] | 2604 | TesselPointList::iterator Runner;
|
---|
| 2605 | TesselPointList::iterator Sprinter;
|
---|
[27bd2f] | 2606 |
|
---|
| 2607 | // fill the set of neighbours
|
---|
[c15ca2] | 2608 | TesselPointSet SetOfNeighbours;
|
---|
[8d2772] | 2609 |
|
---|
[27bd2f] | 2610 | SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
|
---|
| 2611 | for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
|
---|
| 2612 | SetOfNeighbours.insert(*Runner);
|
---|
[c15ca2] | 2613 | TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[27bd2f] | 2614 |
|
---|
[a67d19] | 2615 | DoLog(0) && (Log() << Verbose(0) << "List of Candidates for Turning Point " << *TurningPoint << ":" << endl);
|
---|
[c15ca2] | 2616 | for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
|
---|
[a67d19] | 2617 | DoLog(0) && (Log() << Verbose(0) << " " << **TesselRunner << endl);
|
---|
[09898c] | 2618 |
|
---|
| 2619 | // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
|
---|
| 2620 | Runner = connectedClosestPoints->begin();
|
---|
| 2621 | Sprinter = Runner;
|
---|
[27bd2f] | 2622 | Sprinter++;
|
---|
[6613ec] | 2623 | while (Sprinter != connectedClosestPoints->end()) {
|
---|
[a67d19] | 2624 | DoLog(0) && (Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl);
|
---|
[f67b6e] | 2625 |
|
---|
[f07f86d] | 2626 | AddTesselationPoint(TurningPoint, 0);
|
---|
| 2627 | AddTesselationPoint(*Runner, 1);
|
---|
| 2628 | AddTesselationPoint(*Sprinter, 2);
|
---|
[1e168b] | 2629 |
|
---|
[6613ec] | 2630 | AddCandidateTriangle(CandidateLine, Opt);
|
---|
[1e168b] | 2631 |
|
---|
[27bd2f] | 2632 | Runner = Sprinter;
|
---|
| 2633 | Sprinter++;
|
---|
[6613ec] | 2634 | if (Sprinter != connectedClosestPoints->end()) {
|
---|
| 2635 | // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
|
---|
[f04f11] | 2636 | FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); // Assume BTS contains last triangle
|
---|
[a67d19] | 2637 | DoLog(0) && (Log() << Verbose(0) << " There are still more triangles to add." << endl);
|
---|
[6613ec] | 2638 | }
|
---|
| 2639 | // pick candidates for other open lines as well
|
---|
| 2640 | FindCandidatesforOpenLines(RADIUS, LC);
|
---|
| 2641 |
|
---|
[f07f86d] | 2642 | // check whether we add a degenerate or a normal triangle
|
---|
[6613ec] | 2643 | if (CheckDegeneracy(CandidateLine, RADIUS, LC)) {
|
---|
[f07f86d] | 2644 | // add normal and degenerate triangles
|
---|
[a67d19] | 2645 | DoLog(1) && (Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl);
|
---|
[6613ec] | 2646 | AddCandidateTriangle(CandidateLine, OtherOpt);
|
---|
| 2647 |
|
---|
| 2648 | if (Sprinter != connectedClosestPoints->end()) {
|
---|
| 2649 | // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
|
---|
| 2650 | FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter);
|
---|
| 2651 | }
|
---|
| 2652 | // pick candidates for other open lines as well
|
---|
| 2653 | FindCandidatesforOpenLines(RADIUS, LC);
|
---|
[474961] | 2654 | }
|
---|
[6613ec] | 2655 | }
|
---|
| 2656 | delete (connectedClosestPoints);
|
---|
| 2657 | };
|
---|
[474961] | 2658 |
|
---|
[6613ec] | 2659 | /** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate.
|
---|
| 2660 | * \param *Sprinter next candidate to which internal open lines are set
|
---|
| 2661 | * \param *OptCenter OptCenter for this candidate
|
---|
| 2662 | */
|
---|
| 2663 | void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter)
|
---|
| 2664 | {
|
---|
| 2665 | Info FunctionInfo(__func__);
|
---|
| 2666 |
|
---|
| 2667 | pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr);
|
---|
| 2668 | for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
|
---|
[a67d19] | 2669 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
|
---|
[6613ec] | 2670 | // If there is a line with less than two attached triangles, we don't need a new line.
|
---|
| 2671 | if (FindLine->second->triangles.size() == 1) {
|
---|
| 2672 | CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
|
---|
| 2673 | if (!Finder->second->pointlist.empty())
|
---|
[a67d19] | 2674 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
|
---|
[6613ec] | 2675 | else {
|
---|
[a67d19] | 2676 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl);
|
---|
[f04f11] | 2677 | Finder->second->T = BTS; // is last triangle
|
---|
[6613ec] | 2678 | Finder->second->pointlist.push_back(Sprinter);
|
---|
| 2679 | Finder->second->ShortestAngle = 0.;
|
---|
[8cbb97] | 2680 | Finder->second->OptCenter = *OptCenter;
|
---|
[6613ec] | 2681 | }
|
---|
| 2682 | }
|
---|
[f67b6e] | 2683 | }
|
---|
[1e168b] | 2684 | };
|
---|
| 2685 |
|
---|
[f07f86d] | 2686 | /** If a given \a *triangle is degenerated, this adds both sides.
|
---|
[474961] | 2687 | * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction.
|
---|
[f07f86d] | 2688 | * Note that endpoints are stored in Tesselation::TPS
|
---|
| 2689 | * \param CandidateLine CanddiateForTesselation structure for the desired BoundaryLine
|
---|
[474961] | 2690 | * \param RADIUS radius of sphere
|
---|
| 2691 | * \param *LC pointer to LinkedCell structure
|
---|
| 2692 | */
|
---|
[711ac2] | 2693 | void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
|
---|
[474961] | 2694 | {
|
---|
| 2695 | Info FunctionInfo(__func__);
|
---|
[f07f86d] | 2696 | Vector Center;
|
---|
| 2697 | CandidateMap::const_iterator CandidateCheck = OpenLines.end();
|
---|
[711ac2] | 2698 | BoundaryTriangleSet *triangle = NULL;
|
---|
[f07f86d] | 2699 |
|
---|
[711ac2] | 2700 | /// 1. Create or pick the lines for the first triangle
|
---|
[a67d19] | 2701 | DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl);
|
---|
[6613ec] | 2702 | for (int i = 0; i < 3; i++) {
|
---|
[711ac2] | 2703 | BLS[i] = NULL;
|
---|
[a67d19] | 2704 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[6613ec] | 2705 | AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
|
---|
[474961] | 2706 | }
|
---|
[f07f86d] | 2707 |
|
---|
[711ac2] | 2708 | /// 2. create the first triangle and NormalVector and so on
|
---|
[a67d19] | 2709 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl);
|
---|
[f07f86d] | 2710 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2711 | AddTesselationTriangle();
|
---|
[711ac2] | 2712 |
|
---|
[f07f86d] | 2713 | // create normal vector
|
---|
| 2714 | BTS->GetCenter(&Center);
|
---|
[8cbb97] | 2715 | Center -= CandidateLine.OptCenter;
|
---|
| 2716 | BTS->SphereCenter = CandidateLine.OptCenter;
|
---|
[f07f86d] | 2717 | BTS->GetNormalVector(Center);
|
---|
| 2718 | // give some verbose output about the whole procedure
|
---|
| 2719 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2720 | DoLog(0) && (Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
|
---|
[f07f86d] | 2721 | else
|
---|
[a67d19] | 2722 | DoLog(0) && (Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[f07f86d] | 2723 | triangle = BTS;
|
---|
| 2724 |
|
---|
[711ac2] | 2725 | /// 3. Gather candidates for each new line
|
---|
[a67d19] | 2726 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl);
|
---|
[6613ec] | 2727 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2728 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[f07f86d] | 2729 | CandidateCheck = OpenLines.find(BLS[i]);
|
---|
| 2730 | if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
|
---|
| 2731 | if (CandidateCheck->second->T == NULL)
|
---|
| 2732 | CandidateCheck->second->T = triangle;
|
---|
| 2733 | FindNextSuitableTriangle(*(CandidateCheck->second), *CandidateCheck->second->T, RADIUS, LC);
|
---|
[474961] | 2734 | }
|
---|
[f07f86d] | 2735 | }
|
---|
[d5fea7] | 2736 |
|
---|
[711ac2] | 2737 | /// 4. Create or pick the lines for the second triangle
|
---|
[a67d19] | 2738 | DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl);
|
---|
[6613ec] | 2739 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2740 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[6613ec] | 2741 | AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
|
---|
[474961] | 2742 | }
|
---|
[f07f86d] | 2743 |
|
---|
[711ac2] | 2744 | /// 5. create the second triangle and NormalVector and so on
|
---|
[a67d19] | 2745 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl);
|
---|
[f07f86d] | 2746 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2747 | AddTesselationTriangle();
|
---|
[711ac2] | 2748 |
|
---|
[8cbb97] | 2749 | BTS->SphereCenter = CandidateLine.OtherOptCenter;
|
---|
[f07f86d] | 2750 | // create normal vector in other direction
|
---|
[8cbb97] | 2751 | BTS->GetNormalVector(triangle->NormalVector);
|
---|
[f07f86d] | 2752 | BTS->NormalVector.Scale(-1.);
|
---|
| 2753 | // give some verbose output about the whole procedure
|
---|
| 2754 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2755 | DoLog(0) && (Log() << Verbose(0) << "--> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
|
---|
[f07f86d] | 2756 | else
|
---|
[a67d19] | 2757 | DoLog(0) && (Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[f07f86d] | 2758 |
|
---|
[711ac2] | 2759 | /// 6. Adding triangle to new lines
|
---|
[a67d19] | 2760 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl);
|
---|
[6613ec] | 2761 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2762 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[711ac2] | 2763 | CandidateCheck = OpenLines.find(BLS[i]);
|
---|
| 2764 | if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
|
---|
| 2765 | if (CandidateCheck->second->T == NULL)
|
---|
| 2766 | CandidateCheck->second->T = BTS;
|
---|
| 2767 | }
|
---|
| 2768 | }
|
---|
[6613ec] | 2769 | }
|
---|
| 2770 | ;
|
---|
[474961] | 2771 |
|
---|
| 2772 | /** Adds a triangle to the Tesselation structure from three given TesselPoint's.
|
---|
[f07f86d] | 2773 | * Note that endpoints are in Tesselation::TPS.
|
---|
| 2774 | * \param CandidateLine CandidateForTesselation structure contains other information
|
---|
[6613ec] | 2775 | * \param type which opt center to add (i.e. which side) and thus which NormalVector to take
|
---|
[474961] | 2776 | */
|
---|
[6613ec] | 2777 | void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type)
|
---|
[474961] | 2778 | {
|
---|
| 2779 | Info FunctionInfo(__func__);
|
---|
[f07f86d] | 2780 | Vector Center;
|
---|
[6613ec] | 2781 | Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter;
|
---|
[474961] | 2782 |
|
---|
| 2783 | // add the lines
|
---|
[6613ec] | 2784 | AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0);
|
---|
| 2785 | AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1);
|
---|
| 2786 | AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2);
|
---|
[474961] | 2787 |
|
---|
| 2788 | // add the triangles
|
---|
| 2789 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2790 | AddTesselationTriangle();
|
---|
[f07f86d] | 2791 |
|
---|
| 2792 | // create normal vector
|
---|
| 2793 | BTS->GetCenter(&Center);
|
---|
[8cbb97] | 2794 | Center.SubtractVector(*OptCenter);
|
---|
| 2795 | BTS->SphereCenter = *OptCenter;
|
---|
[f07f86d] | 2796 | BTS->GetNormalVector(Center);
|
---|
| 2797 |
|
---|
| 2798 | // give some verbose output about the whole procedure
|
---|
| 2799 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2800 | DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
|
---|
[f07f86d] | 2801 | else
|
---|
[a67d19] | 2802 | DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[6613ec] | 2803 | }
|
---|
| 2804 | ;
|
---|
[474961] | 2805 |
|
---|
[16d866] | 2806 | /** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
|
---|
| 2807 | * We look whether the closest point on \a *Base with respect to the other baseline is outside
|
---|
| 2808 | * of the segment formed by both endpoints (concave) or not (convex).
|
---|
| 2809 | * \param *out output stream for debugging
|
---|
| 2810 | * \param *Base line to be flipped
|
---|
[57066a] | 2811 | * \return NULL - convex, otherwise endpoint that makes it concave
|
---|
[16d866] | 2812 | */
|
---|
[e138de] | 2813 | class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
|
---|
[16d866] | 2814 | {
|
---|
[6613ec] | 2815 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2816 | class BoundaryPointSet *Spot = NULL;
|
---|
| 2817 | class BoundaryLineSet *OtherBase;
|
---|
[0077b5] | 2818 | Vector *ClosestPoint;
|
---|
[16d866] | 2819 |
|
---|
[6613ec] | 2820 | int m = 0;
|
---|
| 2821 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2822 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2823 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2824 | BPS[m++] = runner->second->endpoints[j];
|
---|
[6613ec] | 2825 | OtherBase = new class BoundaryLineSet(BPS, -1);
|
---|
[16d866] | 2826 |
|
---|
[a67d19] | 2827 | DoLog(1) && (Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl);
|
---|
| 2828 | DoLog(1) && (Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl);
|
---|
[16d866] | 2829 |
|
---|
| 2830 | // get the closest point on each line to the other line
|
---|
[e138de] | 2831 | ClosestPoint = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
[16d866] | 2832 |
|
---|
| 2833 | // delete the temporary other base line
|
---|
[6613ec] | 2834 | delete (OtherBase);
|
---|
[16d866] | 2835 |
|
---|
| 2836 | // get the distance vector from Base line to OtherBase line
|
---|
[0077b5] | 2837 | Vector DistanceToIntersection[2], BaseLine;
|
---|
| 2838 | double distance[2];
|
---|
[273382] | 2839 | BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node);
|
---|
[6613ec] | 2840 | for (int i = 0; i < 2; i++) {
|
---|
[273382] | 2841 | DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node);
|
---|
| 2842 | distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]);
|
---|
[16d866] | 2843 | }
|
---|
[6613ec] | 2844 | delete (ClosestPoint);
|
---|
| 2845 | if ((distance[0] * distance[1]) > 0) { // have same sign?
|
---|
[a67d19] | 2846 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl);
|
---|
[0077b5] | 2847 | if (distance[0] < distance[1]) {
|
---|
| 2848 | Spot = Base->endpoints[0];
|
---|
| 2849 | } else {
|
---|
| 2850 | Spot = Base->endpoints[1];
|
---|
| 2851 | }
|
---|
[16d866] | 2852 | return Spot;
|
---|
[6613ec] | 2853 | } else { // different sign, i.e. we are in between
|
---|
[a67d19] | 2854 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl);
|
---|
[16d866] | 2855 | return NULL;
|
---|
| 2856 | }
|
---|
| 2857 |
|
---|
[6613ec] | 2858 | }
|
---|
| 2859 | ;
|
---|
[16d866] | 2860 |
|
---|
[776b64] | 2861 | void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
|
---|
[0077b5] | 2862 | {
|
---|
[6613ec] | 2863 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2864 | // print all lines
|
---|
[a67d19] | 2865 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl);
|
---|
[6613ec] | 2866 | for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)
|
---|
[a67d19] | 2867 | DoLog(0) && (Log() << Verbose(0) << *(PointRunner->second) << endl);
|
---|
[6613ec] | 2868 | }
|
---|
| 2869 | ;
|
---|
[0077b5] | 2870 |
|
---|
[776b64] | 2871 | void Tesselation::PrintAllBoundaryLines(ofstream *out) const
|
---|
[0077b5] | 2872 | {
|
---|
[6613ec] | 2873 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2874 | // print all lines
|
---|
[a67d19] | 2875 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl);
|
---|
[776b64] | 2876 | for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
|
---|
[a67d19] | 2877 | DoLog(0) && (Log() << Verbose(0) << *(LineRunner->second) << endl);
|
---|
[6613ec] | 2878 | }
|
---|
| 2879 | ;
|
---|
[0077b5] | 2880 |
|
---|
[776b64] | 2881 | void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
|
---|
[0077b5] | 2882 | {
|
---|
[6613ec] | 2883 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2884 | // print all triangles
|
---|
[a67d19] | 2885 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl);
|
---|
[776b64] | 2886 | for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
|
---|
[a67d19] | 2887 | DoLog(0) && (Log() << Verbose(0) << *(TriangleRunner->second) << endl);
|
---|
[6613ec] | 2888 | }
|
---|
| 2889 | ;
|
---|
[357fba] | 2890 |
|
---|
[16d866] | 2891 | /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
|
---|
[357fba] | 2892 | * \param *out output stream for debugging
|
---|
[16d866] | 2893 | * \param *Base line to be flipped
|
---|
[57066a] | 2894 | * \return volume change due to flipping (0 - then no flipped occured)
|
---|
[357fba] | 2895 | */
|
---|
[e138de] | 2896 | double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
|
---|
[357fba] | 2897 | {
|
---|
[6613ec] | 2898 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2899 | class BoundaryLineSet *OtherBase;
|
---|
| 2900 | Vector *ClosestPoint[2];
|
---|
[57066a] | 2901 | double volume;
|
---|
[16d866] | 2902 |
|
---|
[6613ec] | 2903 | int m = 0;
|
---|
| 2904 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2905 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2906 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2907 | BPS[m++] = runner->second->endpoints[j];
|
---|
[6613ec] | 2908 | OtherBase = new class BoundaryLineSet(BPS, -1);
|
---|
[62bb91] | 2909 |
|
---|
[a67d19] | 2910 | DoLog(0) && (Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl);
|
---|
| 2911 | DoLog(0) && (Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl);
|
---|
[62bb91] | 2912 |
|
---|
[16d866] | 2913 | // get the closest point on each line to the other line
|
---|
[e138de] | 2914 | ClosestPoint[0] = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
| 2915 | ClosestPoint[1] = GetClosestPointBetweenLine(OtherBase, Base);
|
---|
[16d866] | 2916 |
|
---|
| 2917 | // get the distance vector from Base line to OtherBase line
|
---|
[273382] | 2918 | Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]);
|
---|
[16d866] | 2919 |
|
---|
[57066a] | 2920 | // calculate volume
|
---|
[c0f6c6] | 2921 | volume = CalculateVolumeofGeneralTetraeder(*Base->endpoints[1]->node->node, *OtherBase->endpoints[0]->node->node, *OtherBase->endpoints[1]->node->node, *Base->endpoints[0]->node->node);
|
---|
[57066a] | 2922 |
|
---|
[0077b5] | 2923 | // delete the temporary other base line and the closest points
|
---|
[6613ec] | 2924 | delete (ClosestPoint[0]);
|
---|
| 2925 | delete (ClosestPoint[1]);
|
---|
| 2926 | delete (OtherBase);
|
---|
[16d866] | 2927 |
|
---|
| 2928 | if (Distance.NormSquared() < MYEPSILON) { // check for intersection
|
---|
[a67d19] | 2929 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl);
|
---|
[16d866] | 2930 | return false;
|
---|
| 2931 | } else { // check for sign against BaseLineNormal
|
---|
| 2932 | Vector BaseLineNormal;
|
---|
[5c7bf8] | 2933 | BaseLineNormal.Zero();
|
---|
| 2934 | if (Base->triangles.size() < 2) {
|
---|
[6613ec] | 2935 | DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
|
---|
[57066a] | 2936 | return 0.;
|
---|
[5c7bf8] | 2937 | }
|
---|
| 2938 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[8cbb97] | 2939 | DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
|
---|
[273382] | 2940 | BaseLineNormal += (runner->second->NormalVector);
|
---|
[5c7bf8] | 2941 | }
|
---|
[6613ec] | 2942 | BaseLineNormal.Scale(1. / 2.);
|
---|
[357fba] | 2943 |
|
---|
[273382] | 2944 | if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
|
---|
[a67d19] | 2945 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl);
|
---|
[57066a] | 2946 | // calculate volume summand as a general tetraeder
|
---|
| 2947 | return volume;
|
---|
[6613ec] | 2948 | } else { // Base higher than OtherBase -> do nothing
|
---|
[a67d19] | 2949 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl);
|
---|
[57066a] | 2950 | return 0.;
|
---|
[16d866] | 2951 | }
|
---|
| 2952 | }
|
---|
[6613ec] | 2953 | }
|
---|
| 2954 | ;
|
---|
[357fba] | 2955 |
|
---|
[16d866] | 2956 | /** For a given baseline and its two connected triangles, flips the baseline.
|
---|
| 2957 | * I.e. we create the new baseline between the other two endpoints of these four
|
---|
| 2958 | * endpoints and reconstruct the two triangles accordingly.
|
---|
| 2959 | * \param *out output stream for debugging
|
---|
| 2960 | * \param *Base line to be flipped
|
---|
[57066a] | 2961 | * \return pointer to allocated new baseline - flipping successful, NULL - something went awry
|
---|
[16d866] | 2962 | */
|
---|
[e138de] | 2963 | class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
|
---|
[16d866] | 2964 | {
|
---|
[6613ec] | 2965 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2966 | class BoundaryLineSet *OldLines[4], *NewLine;
|
---|
| 2967 | class BoundaryPointSet *OldPoints[2];
|
---|
| 2968 | Vector BaseLineNormal;
|
---|
| 2969 | int OldTriangleNrs[2], OldBaseLineNr;
|
---|
[6613ec] | 2970 | int i, m;
|
---|
[16d866] | 2971 |
|
---|
| 2972 | // calculate NormalVector for later use
|
---|
| 2973 | BaseLineNormal.Zero();
|
---|
| 2974 | if (Base->triangles.size() < 2) {
|
---|
[6613ec] | 2975 | DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
|
---|
[57066a] | 2976 | return NULL;
|
---|
[16d866] | 2977 | }
|
---|
| 2978 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[a67d19] | 2979 | DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
|
---|
[273382] | 2980 | BaseLineNormal += (runner->second->NormalVector);
|
---|
[16d866] | 2981 | }
|
---|
[6613ec] | 2982 | BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
|
---|
[16d866] | 2983 |
|
---|
| 2984 | // get the two triangles
|
---|
| 2985 | // gather four endpoints and four lines
|
---|
[6613ec] | 2986 | for (int j = 0; j < 4; j++)
|
---|
[16d866] | 2987 | OldLines[j] = NULL;
|
---|
[6613ec] | 2988 | for (int j = 0; j < 2; j++)
|
---|
[16d866] | 2989 | OldPoints[j] = NULL;
|
---|
[6613ec] | 2990 | i = 0;
|
---|
| 2991 | m = 0;
|
---|
[a67d19] | 2992 | DoLog(0) && (Log() << Verbose(0) << "The four old lines are: ");
|
---|
[6613ec] | 2993 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2994 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2995 | if (runner->second->lines[j] != Base) { // pick not the central baseline
|
---|
| 2996 | OldLines[i++] = runner->second->lines[j];
|
---|
[a67d19] | 2997 | DoLog(0) && (Log() << Verbose(0) << *runner->second->lines[j] << "\t");
|
---|
[357fba] | 2998 | }
|
---|
[a67d19] | 2999 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
| 3000 | DoLog(0) && (Log() << Verbose(0) << "The two old points are: ");
|
---|
[6613ec] | 3001 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 3002 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 3003 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
|
---|
| 3004 | OldPoints[m++] = runner->second->endpoints[j];
|
---|
[a67d19] | 3005 | DoLog(0) && (Log() << Verbose(0) << *runner->second->endpoints[j] << "\t");
|
---|
[16d866] | 3006 | }
|
---|
[a67d19] | 3007 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[16d866] | 3008 |
|
---|
| 3009 | // check whether everything is in place to create new lines and triangles
|
---|
[6613ec] | 3010 | if (i < 4) {
|
---|
| 3011 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
|
---|
[57066a] | 3012 | return NULL;
|
---|
[16d866] | 3013 | }
|
---|
[6613ec] | 3014 | for (int j = 0; j < 4; j++)
|
---|
[16d866] | 3015 | if (OldLines[j] == NULL) {
|
---|
[6613ec] | 3016 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
|
---|
[57066a] | 3017 | return NULL;
|
---|
[16d866] | 3018 | }
|
---|
[6613ec] | 3019 | for (int j = 0; j < 2; j++)
|
---|
[16d866] | 3020 | if (OldPoints[j] == NULL) {
|
---|
[6613ec] | 3021 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl);
|
---|
[57066a] | 3022 | return NULL;
|
---|
[357fba] | 3023 | }
|
---|
[16d866] | 3024 |
|
---|
| 3025 | // remove triangles and baseline removes itself
|
---|
[a67d19] | 3026 | DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl);
|
---|
[16d866] | 3027 | OldBaseLineNr = Base->Nr;
|
---|
[6613ec] | 3028 | m = 0;
|
---|
[accebe] | 3029 | // first obtain all triangle to delete ... (otherwise we pull the carpet (Base) from under the for-loop's feet)
|
---|
| 3030 | list <BoundaryTriangleSet *> TrianglesOfBase;
|
---|
| 3031 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); ++runner)
|
---|
| 3032 | TrianglesOfBase.push_back(runner->second);
|
---|
| 3033 | // .. then delete each triangle (which deletes the line as well)
|
---|
| 3034 | for (list <BoundaryTriangleSet *>::iterator runner = TrianglesOfBase.begin(); !TrianglesOfBase.empty(); runner = TrianglesOfBase.begin()) {
|
---|
| 3035 | DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting triangle " << *(*runner) << "." << endl);
|
---|
| 3036 | OldTriangleNrs[m++] = (*runner)->Nr;
|
---|
| 3037 | RemoveTesselationTriangle((*runner));
|
---|
| 3038 | TrianglesOfBase.erase(runner);
|
---|
[16d866] | 3039 | }
|
---|
| 3040 |
|
---|
| 3041 | // construct new baseline (with same number as old one)
|
---|
| 3042 | BPS[0] = OldPoints[0];
|
---|
| 3043 | BPS[1] = OldPoints[1];
|
---|
| 3044 | NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
|
---|
| 3045 | LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
|
---|
[a67d19] | 3046 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl);
|
---|
[16d866] | 3047 |
|
---|
| 3048 | // construct new triangles with flipped baseline
|
---|
[6613ec] | 3049 | i = -1;
|
---|
[16d866] | 3050 | if (OldLines[0]->IsConnectedTo(OldLines[2]))
|
---|
[6613ec] | 3051 | i = 2;
|
---|
[16d866] | 3052 | if (OldLines[0]->IsConnectedTo(OldLines[3]))
|
---|
[6613ec] | 3053 | i = 3;
|
---|
| 3054 | if (i != -1) {
|
---|
[16d866] | 3055 | BLS[0] = OldLines[0];
|
---|
| 3056 | BLS[1] = OldLines[i];
|
---|
| 3057 | BLS[2] = NewLine;
|
---|
| 3058 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[0]);
|
---|
| 3059 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 3060 | AddTesselationTriangle(OldTriangleNrs[0]);
|
---|
[a67d19] | 3061 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
|
---|
[16d866] | 3062 |
|
---|
[6613ec] | 3063 | BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]);
|
---|
[16d866] | 3064 | BLS[1] = OldLines[1];
|
---|
| 3065 | BLS[2] = NewLine;
|
---|
| 3066 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[1]);
|
---|
| 3067 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 3068 | AddTesselationTriangle(OldTriangleNrs[1]);
|
---|
[a67d19] | 3069 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
|
---|
[16d866] | 3070 | } else {
|
---|
[6613ec] | 3071 | DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);
|
---|
[57066a] | 3072 | return NULL;
|
---|
[357fba] | 3073 | }
|
---|
[16d866] | 3074 |
|
---|
[57066a] | 3075 | return NewLine;
|
---|
[6613ec] | 3076 | }
|
---|
| 3077 | ;
|
---|
[16d866] | 3078 |
|
---|
[357fba] | 3079 | /** Finds the second point of starting triangle.
|
---|
| 3080 | * \param *a first node
|
---|
| 3081 | * \param Oben vector indicating the outside
|
---|
[f1cccd] | 3082 | * \param OptCandidate reference to recommended candidate on return
|
---|
[357fba] | 3083 | * \param Storage[3] array storing angles and other candidate information
|
---|
| 3084 | * \param RADIUS radius of virtual sphere
|
---|
[62bb91] | 3085 | * \param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 3086 | */
|
---|
[776b64] | 3087 | void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 3088 | {
|
---|
[6613ec] | 3089 | Info FunctionInfo(__func__);
|
---|
[357fba] | 3090 | Vector AngleCheck;
|
---|
[57066a] | 3091 | class TesselPoint* Candidate = NULL;
|
---|
[776b64] | 3092 | double norm = -1.;
|
---|
| 3093 | double angle = 0.;
|
---|
| 3094 | int N[NDIM];
|
---|
| 3095 | int Nlower[NDIM];
|
---|
| 3096 | int Nupper[NDIM];
|
---|
[357fba] | 3097 |
|
---|
[6613ec] | 3098 | if (LC->SetIndexToNode(a)) { // get cell for the starting point
|
---|
| 3099 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
[357fba] | 3100 | N[i] = LC->n[i];
|
---|
| 3101 | } else {
|
---|
[6613ec] | 3102 | DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);
|
---|
[357fba] | 3103 | return;
|
---|
| 3104 | }
|
---|
[62bb91] | 3105 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[6613ec] | 3106 | for (int i = 0; i < NDIM; i++) {
|
---|
| 3107 | Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
|
---|
| 3108 | Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
|
---|
[357fba] | 3109 | }
|
---|
[a67d19] | 3110 | DoLog(0) && (Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :" << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl);
|
---|
[357fba] | 3111 |
|
---|
| 3112 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3113 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3114 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3115 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 3116 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3117 | if (List != NULL) {
|
---|
[734816] | 3118 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 3119 | Candidate = (*Runner);
|
---|
| 3120 | // check if we only have one unique point yet ...
|
---|
| 3121 | if (a != Candidate) {
|
---|
| 3122 | // Calculate center of the circle with radius RADIUS through points a and Candidate
|
---|
[f1cccd] | 3123 | Vector OrthogonalizedOben, aCandidate, Center;
|
---|
[357fba] | 3124 | double distance, scaleFactor;
|
---|
| 3125 |
|
---|
[273382] | 3126 | OrthogonalizedOben = Oben;
|
---|
| 3127 | aCandidate = (*a->node) - (*Candidate->node);
|
---|
| 3128 | OrthogonalizedOben.ProjectOntoPlane(aCandidate);
|
---|
[357fba] | 3129 | OrthogonalizedOben.Normalize();
|
---|
[f1cccd] | 3130 | distance = 0.5 * aCandidate.Norm();
|
---|
[357fba] | 3131 | scaleFactor = sqrt(((RADIUS * RADIUS) - (distance * distance)));
|
---|
| 3132 | OrthogonalizedOben.Scale(scaleFactor);
|
---|
| 3133 |
|
---|
[273382] | 3134 | Center = 0.5 * ((*Candidate->node) + (*a->node));
|
---|
| 3135 | Center += OrthogonalizedOben;
|
---|
[357fba] | 3136 |
|
---|
[273382] | 3137 | AngleCheck = Center - (*a->node);
|
---|
[f1cccd] | 3138 | norm = aCandidate.Norm();
|
---|
[357fba] | 3139 | // second point shall have smallest angle with respect to Oben vector
|
---|
[6613ec] | 3140 | if (norm < RADIUS * 2.) {
|
---|
[273382] | 3141 | angle = AngleCheck.Angle(Oben);
|
---|
[357fba] | 3142 | if (angle < Storage[0]) {
|
---|
[f67b6e] | 3143 | //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
|
---|
[a67d19] | 3144 | DoLog(1) && (Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n");
|
---|
[f1cccd] | 3145 | OptCandidate = Candidate;
|
---|
[357fba] | 3146 | Storage[0] = angle;
|
---|
[f67b6e] | 3147 | //Log() << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
|
---|
[357fba] | 3148 | } else {
|
---|
[f67b6e] | 3149 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
|
---|
[357fba] | 3150 | }
|
---|
| 3151 | } else {
|
---|
[f67b6e] | 3152 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
|
---|
[357fba] | 3153 | }
|
---|
| 3154 | } else {
|
---|
[f67b6e] | 3155 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
|
---|
[357fba] | 3156 | }
|
---|
| 3157 | }
|
---|
| 3158 | } else {
|
---|
[a67d19] | 3159 | DoLog(0) && (Log() << Verbose(0) << "Linked cell list is empty." << endl);
|
---|
[357fba] | 3160 | }
|
---|
| 3161 | }
|
---|
[6613ec] | 3162 | }
|
---|
| 3163 | ;
|
---|
[357fba] | 3164 |
|
---|
| 3165 | /** This recursive function finds a third point, to form a triangle with two given ones.
|
---|
| 3166 | * Note that this function is for the starting triangle.
|
---|
| 3167 | * The idea is as follows: A sphere with fixed radius is (almost) uniquely defined in space by three points
|
---|
| 3168 | * that sit on its boundary. Hence, when two points are given and we look for the (next) third point, then
|
---|
| 3169 | * the center of the sphere is still fixed up to a single parameter. The band of possible values
|
---|
| 3170 | * describes a circle in 3D-space. The old center of the sphere for the current base triangle gives
|
---|
| 3171 | * us the "null" on this circle, the new center of the candidate point will be some way along this
|
---|
| 3172 | * circle. The shorter the way the better is the candidate. Note that the direction is clearly given
|
---|
| 3173 | * by the normal vector of the base triangle that always points outwards by construction.
|
---|
| 3174 | * Hence, we construct a Center of this circle which sits right in the middle of the current base line.
|
---|
| 3175 | * We construct the normal vector that defines the plane this circle lies in, it is just in the
|
---|
| 3176 | * direction of the baseline. And finally, we need the radius of the circle, which is given by the rest
|
---|
| 3177 | * with respect to the length of the baseline and the sphere's fixed \a RADIUS.
|
---|
| 3178 | * Note that there is one difficulty: The circumcircle is uniquely defined, but for the circumsphere's center
|
---|
| 3179 | * there are two possibilities which becomes clear from the construction as seen below. Hence, we must check
|
---|
| 3180 | * both.
|
---|
| 3181 | * Note also that the acos() function is not unique on [0, 2.*M_PI). Hence, we need an additional check
|
---|
| 3182 | * to decide for one of the two possible angles. Therefore we need a SearchDirection and to make this check
|
---|
| 3183 | * sensible we need OldSphereCenter to be orthogonal to it. Either we construct SearchDirection orthogonal
|
---|
| 3184 | * right away, or -- what we do here -- we rotate the relative sphere centers such that this orthogonality
|
---|
| 3185 | * holds. Then, the normalized projection onto the SearchDirection is either +1 or -1 and thus states whether
|
---|
| 3186 | * the angle is uniquely in either (0,M_PI] or [M_PI, 2.*M_PI).
|
---|
[f1cccd] | 3187 | * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa FindStartingTriangle())
|
---|
[357fba] | 3188 | * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
|
---|
| 3189 | * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
|
---|
[f67b6e] | 3190 | * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
|
---|
[09898c] | 3191 | * @param ThirdPoint third point to avoid in search
|
---|
[357fba] | 3192 | * @param RADIUS radius of sphere
|
---|
[62bb91] | 3193 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 3194 | */
|
---|
[6613ec] | 3195 | void Tesselation::FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdPoint, const double RADIUS, const LinkedCell *LC) const
|
---|
[357fba] | 3196 | {
|
---|
[6613ec] | 3197 | Info FunctionInfo(__func__);
|
---|
| 3198 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
[357fba] | 3199 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 3200 | Vector SphereCenter;
|
---|
[6613ec] | 3201 | Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
|
---|
| 3202 | Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
|
---|
| 3203 | Vector NewNormalVector; // normal vector of the Candidate's triangle
|
---|
[357fba] | 3204 | Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
|
---|
[b998c3] | 3205 | Vector RelativeOldSphereCenter;
|
---|
| 3206 | Vector NewPlaneCenter;
|
---|
[357fba] | 3207 | double CircleRadius; // radius of this circle
|
---|
| 3208 | double radius;
|
---|
[b998c3] | 3209 | double otherradius;
|
---|
[357fba] | 3210 | double alpha, Otheralpha; // angles (i.e. parameter for the circle).
|
---|
| 3211 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
| 3212 | TesselPoint *Candidate = NULL;
|
---|
| 3213 |
|
---|
[a67d19] | 3214 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl);
|
---|
[357fba] | 3215 |
|
---|
[09898c] | 3216 | // copy old center
|
---|
[8cbb97] | 3217 | CandidateLine.OldCenter = OldSphereCenter;
|
---|
[09898c] | 3218 | CandidateLine.ThirdPoint = ThirdPoint;
|
---|
| 3219 | CandidateLine.pointlist.clear();
|
---|
[357fba] | 3220 |
|
---|
| 3221 | // construct center of circle
|
---|
[273382] | 3222 | CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
|
---|
| 3223 | (*CandidateLine.BaseLine->endpoints[1]->node->node));
|
---|
[357fba] | 3224 |
|
---|
| 3225 | // construct normal vector of circle
|
---|
[273382] | 3226 | CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
|
---|
| 3227 | (*CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 3228 |
|
---|
[273382] | 3229 | RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
|
---|
[b998c3] | 3230 |
|
---|
[09898c] | 3231 | // calculate squared radius TesselPoint *ThirdPoint,f circle
|
---|
[6613ec] | 3232 | radius = CirclePlaneNormal.NormSquared() / 4.;
|
---|
| 3233 | if (radius < RADIUS * RADIUS) {
|
---|
| 3234 | CircleRadius = RADIUS * RADIUS - radius;
|
---|
[357fba] | 3235 | CirclePlaneNormal.Normalize();
|
---|
[a67d19] | 3236 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
[357fba] | 3237 |
|
---|
| 3238 | // test whether old center is on the band's plane
|
---|
[273382] | 3239 | if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
|
---|
[8cbb97] | 3240 | DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!" << endl);
|
---|
[273382] | 3241 | RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal);
|
---|
[357fba] | 3242 | }
|
---|
[b998c3] | 3243 | radius = RelativeOldSphereCenter.NormSquared();
|
---|
[357fba] | 3244 | if (fabs(radius - CircleRadius) < HULLEPSILON) {
|
---|
[a67d19] | 3245 | DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl);
|
---|
[357fba] | 3246 |
|
---|
| 3247 | // check SearchDirection
|
---|
[a67d19] | 3248 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
[8cbb97] | 3249 | if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
|
---|
[6613ec] | 3250 | DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
|
---|
[357fba] | 3251 | }
|
---|
| 3252 |
|
---|
[62bb91] | 3253 | // get cell for the starting point
|
---|
[357fba] | 3254 | if (LC->SetIndexToVector(&CircleCenter)) {
|
---|
[6613ec] | 3255 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
| 3256 | N[i] = LC->n[i];
|
---|
[f67b6e] | 3257 | //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3258 | } else {
|
---|
[6613ec] | 3259 | DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);
|
---|
[357fba] | 3260 | return;
|
---|
| 3261 | }
|
---|
[62bb91] | 3262 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[f67b6e] | 3263 | //Log() << Verbose(1) << "LC Intervals:";
|
---|
[6613ec] | 3264 | for (int i = 0; i < NDIM; i++) {
|
---|
| 3265 | Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
|
---|
| 3266 | Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
|
---|
[e138de] | 3267 | //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
|
---|
[357fba] | 3268 | }
|
---|
[e138de] | 3269 | //Log() << Verbose(0) << endl;
|
---|
[357fba] | 3270 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3271 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3272 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3273 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 3274 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3275 | if (List != NULL) {
|
---|
[734816] | 3276 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 3277 | Candidate = (*Runner);
|
---|
| 3278 |
|
---|
| 3279 | // check for three unique points
|
---|
[a67d19] | 3280 | DoLog(2) && (Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl);
|
---|
[6613ec] | 3281 | if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) {
|
---|
[357fba] | 3282 |
|
---|
[b998c3] | 3283 | // find center on the plane
|
---|
| 3284 | GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
|
---|
[a67d19] | 3285 | DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl);
|
---|
[357fba] | 3286 |
|
---|
[0a4f7f] | 3287 | try {
|
---|
| 3288 | NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node),
|
---|
[8cbb97] | 3289 | *(CandidateLine.BaseLine->endpoints[1]->node->node),
|
---|
| 3290 | *(Candidate->node)).getNormal();
|
---|
[a67d19] | 3291 | DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl);
|
---|
[273382] | 3292 | radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter);
|
---|
[a67d19] | 3293 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
| 3294 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
| 3295 | DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl);
|
---|
[6613ec] | 3296 | if (radius < RADIUS * RADIUS) {
|
---|
[273382] | 3297 | otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter);
|
---|
[620a3f] | 3298 | if (fabs(radius - otherradius) < HULLEPSILON) {
|
---|
| 3299 | // construct both new centers
|
---|
[8cbb97] | 3300 | NewSphereCenter = NewPlaneCenter;
|
---|
| 3301 | OtherNewSphereCenter= NewPlaneCenter;
|
---|
| 3302 | helper = NewNormalVector;
|
---|
[620a3f] | 3303 | helper.Scale(sqrt(RADIUS * RADIUS - radius));
|
---|
| 3304 | DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl);
|
---|
[8cbb97] | 3305 | NewSphereCenter += helper;
|
---|
[620a3f] | 3306 | DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl);
|
---|
| 3307 | // OtherNewSphereCenter is created by the same vector just in the other direction
|
---|
| 3308 | helper.Scale(-1.);
|
---|
[8cbb97] | 3309 | OtherNewSphereCenter += helper;
|
---|
[620a3f] | 3310 | DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl);
|
---|
| 3311 | alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
| 3312 | Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
[b1a6d8] | 3313 | if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
|
---|
[8cbb97] | 3314 | if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter))
|
---|
[b1a6d8] | 3315 | alpha = Otheralpha;
|
---|
| 3316 | } else
|
---|
| 3317 | alpha = min(alpha, Otheralpha);
|
---|
[620a3f] | 3318 | // if there is a better candidate, drop the current list and add the new candidate
|
---|
| 3319 | // otherwise ignore the new candidate and keep the list
|
---|
| 3320 | if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
|
---|
| 3321 | if (fabs(alpha - Otheralpha) > MYEPSILON) {
|
---|
[8cbb97] | 3322 | CandidateLine.OptCenter = NewSphereCenter;
|
---|
| 3323 | CandidateLine.OtherOptCenter = OtherNewSphereCenter;
|
---|
[620a3f] | 3324 | } else {
|
---|
[8cbb97] | 3325 | CandidateLine.OptCenter = OtherNewSphereCenter;
|
---|
| 3326 | CandidateLine.OtherOptCenter = NewSphereCenter;
|
---|
[620a3f] | 3327 | }
|
---|
| 3328 | // if there is an equal candidate, add it to the list without clearing the list
|
---|
| 3329 | if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
|
---|
| 3330 | CandidateLine.pointlist.push_back(Candidate);
|
---|
| 3331 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
|
---|
| 3332 | } else {
|
---|
| 3333 | // remove all candidates from the list and then the list itself
|
---|
| 3334 | CandidateLine.pointlist.clear();
|
---|
| 3335 | CandidateLine.pointlist.push_back(Candidate);
|
---|
| 3336 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
|
---|
| 3337 | }
|
---|
| 3338 | CandidateLine.ShortestAngle = alpha;
|
---|
| 3339 | DoLog(0) && (Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl);
|
---|
[357fba] | 3340 | } else {
|
---|
[620a3f] | 3341 | if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
|
---|
| 3342 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl);
|
---|
| 3343 | } else {
|
---|
| 3344 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl);
|
---|
| 3345 | }
|
---|
[357fba] | 3346 | }
|
---|
| 3347 | } else {
|
---|
[b32dbb] | 3348 | DoeLog(0) && (eLog() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
|
---|
[357fba] | 3349 | }
|
---|
| 3350 | } else {
|
---|
[a67d19] | 3351 | DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl);
|
---|
[357fba] | 3352 | }
|
---|
[0a4f7f] | 3353 | }
|
---|
| 3354 | catch (LinearDependenceException &excp){
|
---|
| 3355 | Log() << Verbose(1) << excp;
|
---|
[f67b6e] | 3356 | Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
|
---|
[357fba] | 3357 | }
|
---|
| 3358 | } else {
|
---|
[09898c] | 3359 | if (ThirdPoint != NULL) {
|
---|
[a67d19] | 3360 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << "." << endl);
|
---|
[357fba] | 3361 | } else {
|
---|
[a67d19] | 3362 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl);
|
---|
[357fba] | 3363 | }
|
---|
| 3364 | }
|
---|
| 3365 | }
|
---|
| 3366 | }
|
---|
| 3367 | }
|
---|
| 3368 | } else {
|
---|
[6613ec] | 3369 | DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
|
---|
[357fba] | 3370 | }
|
---|
| 3371 | } else {
|
---|
[09898c] | 3372 | if (ThirdPoint != NULL)
|
---|
[a67d19] | 3373 | DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!" << endl);
|
---|
[357fba] | 3374 | else
|
---|
[a67d19] | 3375 | DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl);
|
---|
[357fba] | 3376 | }
|
---|
| 3377 |
|
---|
[734816] | 3378 | DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl);
|
---|
[f67b6e] | 3379 | if (CandidateLine.pointlist.size() > 1) {
|
---|
| 3380 | CandidateLine.pointlist.unique();
|
---|
| 3381 | CandidateLine.pointlist.sort(); //SortCandidates);
|
---|
[357fba] | 3382 | }
|
---|
[6613ec] | 3383 |
|
---|
| 3384 | if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
|
---|
| 3385 | DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
|
---|
| 3386 | performCriticalExit();
|
---|
| 3387 | }
|
---|
| 3388 | }
|
---|
| 3389 | ;
|
---|
[357fba] | 3390 |
|
---|
| 3391 | /** Finds the endpoint two lines are sharing.
|
---|
| 3392 | * \param *line1 first line
|
---|
| 3393 | * \param *line2 second line
|
---|
| 3394 | * \return point which is shared or NULL if none
|
---|
| 3395 | */
|
---|
[776b64] | 3396 | class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
|
---|
[357fba] | 3397 | {
|
---|
[6613ec] | 3398 | Info FunctionInfo(__func__);
|
---|
[776b64] | 3399 | const BoundaryLineSet * lines[2] = { line1, line2 };
|
---|
[357fba] | 3400 | class BoundaryPointSet *node = NULL;
|
---|
[c15ca2] | 3401 | PointMap OrderMap;
|
---|
| 3402 | PointTestPair OrderTest;
|
---|
[357fba] | 3403 | for (int i = 0; i < 2; i++)
|
---|
| 3404 | // for both lines
|
---|
[6613ec] | 3405 | for (int j = 0; j < 2; j++) { // for both endpoints
|
---|
| 3406 | OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
|
---|
| 3407 | if (!OrderTest.second) { // if insertion fails, we have common endpoint
|
---|
| 3408 | node = OrderTest.first->second;
|
---|
[a67d19] | 3409 | DoLog(1) && (Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl);
|
---|
[6613ec] | 3410 | j = 2;
|
---|
| 3411 | i = 2;
|
---|
| 3412 | break;
|
---|
[357fba] | 3413 | }
|
---|
[6613ec] | 3414 | }
|
---|
[357fba] | 3415 | return node;
|
---|
[6613ec] | 3416 | }
|
---|
| 3417 | ;
|
---|
[357fba] | 3418 |
|
---|
[c15ca2] | 3419 | /** Finds the boundary points that are closest to a given Vector \a *x.
|
---|
[62bb91] | 3420 | * \param *out output stream for debugging
|
---|
| 3421 | * \param *x Vector to look from
|
---|
[c15ca2] | 3422 | * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
|
---|
[62bb91] | 3423 | */
|
---|
[97498a] | 3424 | DistanceToPointMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 3425 | {
|
---|
[c15ca2] | 3426 | Info FunctionInfo(__func__);
|
---|
[71b20e] | 3427 | PointMap::const_iterator FindPoint;
|
---|
| 3428 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
[62bb91] | 3429 |
|
---|
| 3430 | if (LinesOnBoundary.empty()) {
|
---|
[6613ec] | 3431 | DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);
|
---|
[62bb91] | 3432 | return NULL;
|
---|
| 3433 | }
|
---|
[71b20e] | 3434 |
|
---|
| 3435 | // gather all points close to the desired one
|
---|
| 3436 | LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
|
---|
[6613ec] | 3437 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
[71b20e] | 3438 | N[i] = LC->n[i];
|
---|
[a67d19] | 3439 | DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
|
---|
[97498a] | 3440 | DistanceToPointMap * points = new DistanceToPointMap;
|
---|
[71b20e] | 3441 | LC->GetNeighbourBounds(Nlower, Nupper);
|
---|
| 3442 | //Log() << Verbose(1) << endl;
|
---|
| 3443 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3444 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3445 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3446 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[71b20e] | 3447 | //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
|
---|
| 3448 | if (List != NULL) {
|
---|
[734816] | 3449 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[71b20e] | 3450 | FindPoint = PointsOnBoundary.find((*Runner)->nr);
|
---|
[97498a] | 3451 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
[8cbb97] | 3452 | points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second));
|
---|
[a67d19] | 3453 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl);
|
---|
[97498a] | 3454 | }
|
---|
[71b20e] | 3455 | }
|
---|
| 3456 | } else {
|
---|
[6613ec] | 3457 | DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
|
---|
[99593f] | 3458 | }
|
---|
[57066a] | 3459 | }
|
---|
[62bb91] | 3460 |
|
---|
[71b20e] | 3461 | // check whether we found some points
|
---|
[c15ca2] | 3462 | if (points->empty()) {
|
---|
[6613ec] | 3463 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
| 3464 | delete (points);
|
---|
[c15ca2] | 3465 | return NULL;
|
---|
| 3466 | }
|
---|
| 3467 | return points;
|
---|
[6613ec] | 3468 | }
|
---|
| 3469 | ;
|
---|
[c15ca2] | 3470 |
|
---|
| 3471 | /** Finds the boundary line that is closest to a given Vector \a *x.
|
---|
| 3472 | * \param *out output stream for debugging
|
---|
| 3473 | * \param *x Vector to look from
|
---|
| 3474 | * \return closest BoundaryLineSet or NULL in degenerate case.
|
---|
| 3475 | */
|
---|
| 3476 | BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const
|
---|
| 3477 | {
|
---|
| 3478 | Info FunctionInfo(__func__);
|
---|
| 3479 | // get closest points
|
---|
[6613ec] | 3480 | DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
|
---|
[c15ca2] | 3481 | if (points == NULL) {
|
---|
[6613ec] | 3482 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
[71b20e] | 3483 | return NULL;
|
---|
| 3484 | }
|
---|
[62bb91] | 3485 |
|
---|
[71b20e] | 3486 | // for each point, check its lines, remember closest
|
---|
[a67d19] | 3487 | DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl);
|
---|
[71b20e] | 3488 | BoundaryLineSet *ClosestLine = NULL;
|
---|
| 3489 | double MinDistance = -1.;
|
---|
| 3490 | Vector helper;
|
---|
| 3491 | Vector Center;
|
---|
| 3492 | Vector BaseLine;
|
---|
[97498a] | 3493 | for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
|
---|
[c15ca2] | 3494 | for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
|
---|
[71b20e] | 3495 | // calculate closest point on line to desired point
|
---|
[273382] | 3496 | helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) +
|
---|
| 3497 | (*(LineRunner->second)->endpoints[1]->node->node));
|
---|
| 3498 | Center = (*x) - helper;
|
---|
| 3499 | BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
|
---|
| 3500 | (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3501 | Center.ProjectOntoPlane(BaseLine);
|
---|
[71b20e] | 3502 | const double distance = Center.NormSquared();
|
---|
| 3503 | if ((ClosestLine == NULL) || (distance < MinDistance)) {
|
---|
| 3504 | // additionally calculate intersection on line (whether it's on the line section or not)
|
---|
[273382] | 3505 | helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center;
|
---|
| 3506 | const double lengthA = helper.ScalarProduct(BaseLine);
|
---|
| 3507 | helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center;
|
---|
| 3508 | const double lengthB = helper.ScalarProduct(BaseLine);
|
---|
[6613ec] | 3509 | if (lengthB * lengthA < 0) { // if have different sign
|
---|
[71b20e] | 3510 | ClosestLine = LineRunner->second;
|
---|
| 3511 | MinDistance = distance;
|
---|
[a67d19] | 3512 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl);
|
---|
[71b20e] | 3513 | } else {
|
---|
[a67d19] | 3514 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl);
|
---|
[71b20e] | 3515 | }
|
---|
| 3516 | } else {
|
---|
[a67d19] | 3517 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl);
|
---|
[71b20e] | 3518 | }
|
---|
[99593f] | 3519 | }
|
---|
[57066a] | 3520 | }
|
---|
[6613ec] | 3521 | delete (points);
|
---|
[71b20e] | 3522 | // check whether closest line is "too close" :), then it's inside
|
---|
| 3523 | if (ClosestLine == NULL) {
|
---|
[a67d19] | 3524 | DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
|
---|
[62bb91] | 3525 | return NULL;
|
---|
[71b20e] | 3526 | }
|
---|
[c15ca2] | 3527 | return ClosestLine;
|
---|
[6613ec] | 3528 | }
|
---|
| 3529 | ;
|
---|
[c15ca2] | 3530 |
|
---|
| 3531 | /** Finds the triangle that is closest to a given Vector \a *x.
|
---|
| 3532 | * \param *out output stream for debugging
|
---|
| 3533 | * \param *x Vector to look from
|
---|
| 3534 | * \return BoundaryTriangleSet of nearest triangle or NULL.
|
---|
| 3535 | */
|
---|
| 3536 | TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
|
---|
| 3537 | {
|
---|
[6613ec] | 3538 | Info FunctionInfo(__func__);
|
---|
| 3539 | // get closest points
|
---|
| 3540 | DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
|
---|
[c15ca2] | 3541 | if (points == NULL) {
|
---|
[6613ec] | 3542 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
[c15ca2] | 3543 | return NULL;
|
---|
| 3544 | }
|
---|
| 3545 |
|
---|
| 3546 | // for each point, check its lines, remember closest
|
---|
[a67d19] | 3547 | DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl);
|
---|
[48b47a] | 3548 | LineSet ClosestLines;
|
---|
[97498a] | 3549 | double MinDistance = 1e+16;
|
---|
| 3550 | Vector BaseLineIntersection;
|
---|
[c15ca2] | 3551 | Vector Center;
|
---|
| 3552 | Vector BaseLine;
|
---|
[97498a] | 3553 | Vector BaseLineCenter;
|
---|
| 3554 | for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
|
---|
[c15ca2] | 3555 | for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
|
---|
[97498a] | 3556 |
|
---|
[273382] | 3557 | BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
|
---|
| 3558 | (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
[97498a] | 3559 | const double lengthBase = BaseLine.NormSquared();
|
---|
| 3560 |
|
---|
[273382] | 3561 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node);
|
---|
[97498a] | 3562 | const double lengthEndA = BaseLineIntersection.NormSquared();
|
---|
| 3563 |
|
---|
[273382] | 3564 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
[97498a] | 3565 | const double lengthEndB = BaseLineIntersection.NormSquared();
|
---|
| 3566 |
|
---|
[6613ec] | 3567 | if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
|
---|
[48b47a] | 3568 | const double lengthEnd = Min(lengthEndA, lengthEndB);
|
---|
| 3569 | if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
|
---|
| 3570 | ClosestLines.clear();
|
---|
| 3571 | ClosestLines.insert(LineRunner->second);
|
---|
| 3572 | MinDistance = lengthEnd;
|
---|
[a67d19] | 3573 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl);
|
---|
[6613ec] | 3574 | } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
|
---|
[48b47a] | 3575 | ClosestLines.insert(LineRunner->second);
|
---|
[a67d19] | 3576 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl);
|
---|
[48b47a] | 3577 | } else { // line is worse
|
---|
[a67d19] | 3578 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << "." << endl);
|
---|
[97498a] | 3579 | }
|
---|
| 3580 | } else { // intersection is closer, calculate
|
---|
[c15ca2] | 3581 | // calculate closest point on line to desired point
|
---|
[273382] | 3582 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3583 | Center = BaseLineIntersection;
|
---|
| 3584 | Center.ProjectOntoPlane(BaseLine);
|
---|
| 3585 | BaseLineIntersection -= Center;
|
---|
[97498a] | 3586 | const double distance = BaseLineIntersection.NormSquared();
|
---|
| 3587 | if (Center.NormSquared() > BaseLine.NormSquared()) {
|
---|
[6613ec] | 3588 | DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);
|
---|
[97498a] | 3589 | }
|
---|
[48b47a] | 3590 | if ((ClosestLines.empty()) || (distance < MinDistance)) {
|
---|
| 3591 | ClosestLines.insert(LineRunner->second);
|
---|
[97498a] | 3592 | MinDistance = distance;
|
---|
[a67d19] | 3593 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl);
|
---|
[c15ca2] | 3594 | } else {
|
---|
[a67d19] | 3595 | DoLog(2) && (Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl);
|
---|
[c15ca2] | 3596 | }
|
---|
| 3597 | }
|
---|
| 3598 | }
|
---|
| 3599 | }
|
---|
[6613ec] | 3600 | delete (points);
|
---|
[c15ca2] | 3601 |
|
---|
| 3602 | // check whether closest line is "too close" :), then it's inside
|
---|
[48b47a] | 3603 | if (ClosestLines.empty()) {
|
---|
[a67d19] | 3604 | DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
|
---|
[c15ca2] | 3605 | return NULL;
|
---|
| 3606 | }
|
---|
| 3607 | TriangleList * candidates = new TriangleList;
|
---|
[48b47a] | 3608 | for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
|
---|
| 3609 | for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
|
---|
[6613ec] | 3610 | candidates->push_back(Runner->second);
|
---|
| 3611 | }
|
---|
[c15ca2] | 3612 | return candidates;
|
---|
[6613ec] | 3613 | }
|
---|
| 3614 | ;
|
---|
[62bb91] | 3615 |
|
---|
| 3616 | /** Finds closest triangle to a point.
|
---|
| 3617 | * This basically just takes care of the degenerate case, which is not handled in FindClosestTrianglesToPoint().
|
---|
| 3618 | * \param *out output stream for debugging
|
---|
| 3619 | * \param *x Vector to look from
|
---|
[8db598] | 3620 | * \param &distance contains found distance on return
|
---|
[62bb91] | 3621 | * \return list of BoundaryTriangleSet of nearest triangles or NULL.
|
---|
| 3622 | */
|
---|
[c15ca2] | 3623 | class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 3624 | {
|
---|
[6613ec] | 3625 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 3626 | class BoundaryTriangleSet *result = NULL;
|
---|
[c15ca2] | 3627 | TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
|
---|
| 3628 | TriangleList candidates;
|
---|
[57066a] | 3629 | Vector Center;
|
---|
[71b20e] | 3630 | Vector helper;
|
---|
[62bb91] | 3631 |
|
---|
[71b20e] | 3632 | if ((triangles == NULL) || (triangles->empty()))
|
---|
[62bb91] | 3633 | return NULL;
|
---|
| 3634 |
|
---|
[97498a] | 3635 | // go through all and pick the one with the best alignment to x
|
---|
[6613ec] | 3636 | double MinAlignment = 2. * M_PI;
|
---|
[c15ca2] | 3637 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
|
---|
[71b20e] | 3638 | (*Runner)->GetCenter(&Center);
|
---|
[273382] | 3639 | helper = (*x) - Center;
|
---|
| 3640 | const double Alignment = helper.Angle((*Runner)->NormalVector);
|
---|
[97498a] | 3641 | if (Alignment < MinAlignment) {
|
---|
| 3642 | result = *Runner;
|
---|
| 3643 | MinAlignment = Alignment;
|
---|
[a67d19] | 3644 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl);
|
---|
[71b20e] | 3645 | } else {
|
---|
[a67d19] | 3646 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl);
|
---|
[57066a] | 3647 | }
|
---|
| 3648 | }
|
---|
[6613ec] | 3649 | delete (triangles);
|
---|
[97498a] | 3650 |
|
---|
[62bb91] | 3651 | return result;
|
---|
[6613ec] | 3652 | }
|
---|
| 3653 | ;
|
---|
[62bb91] | 3654 |
|
---|
[9473f6] | 3655 | /** Checks whether the provided Vector is within the Tesselation structure.
|
---|
| 3656 | * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value.
|
---|
| 3657 | * @param point of which to check the position
|
---|
| 3658 | * @param *LC LinkedCell structure
|
---|
| 3659 | *
|
---|
| 3660 | * @return true if the point is inside the Tesselation structure, false otherwise
|
---|
| 3661 | */
|
---|
| 3662 | bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
|
---|
| 3663 | {
|
---|
[8db598] | 3664 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3665 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3666 |
|
---|
| 3667 | return Intersections.IsInside();
|
---|
[9473f6] | 3668 | }
|
---|
[6613ec] | 3669 | ;
|
---|
[9473f6] | 3670 |
|
---|
| 3671 | /** Returns the distance to the surface given by the tesselation.
|
---|
[97498a] | 3672 | * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points
|
---|
[9473f6] | 3673 | * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the
|
---|
| 3674 | * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's
|
---|
| 3675 | * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle().
|
---|
| 3676 | * In the end we additionally find the point on the triangle who was smallest distance to \a Point:
|
---|
| 3677 | * -# Separate distance from point to center in vector in NormalDirection and on the triangle plane.
|
---|
| 3678 | * -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds.
|
---|
| 3679 | * -# If inside, take it to calculate closest distance
|
---|
| 3680 | * -# If not, take intersection with BoundaryLine as distance
|
---|
| 3681 | *
|
---|
| 3682 | * @note distance is squared despite it still contains a sign to determine in-/outside!
|
---|
[62bb91] | 3683 | *
|
---|
| 3684 | * @param point of which to check the position
|
---|
| 3685 | * @param *LC LinkedCell structure
|
---|
| 3686 | *
|
---|
[244a84] | 3687 | * @return >0 if outside, ==0 if on surface, <0 if inside
|
---|
[62bb91] | 3688 | */
|
---|
[244a84] | 3689 | double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
|
---|
[62bb91] | 3690 | {
|
---|
[fcad4b] | 3691 | Info FunctionInfo(__func__);
|
---|
[57066a] | 3692 | Vector Center;
|
---|
[71b20e] | 3693 | Vector helper;
|
---|
[97498a] | 3694 | Vector DistanceToCenter;
|
---|
| 3695 | Vector Intersection;
|
---|
[9473f6] | 3696 | double distance = 0.;
|
---|
[57066a] | 3697 |
|
---|
[244a84] | 3698 | if (triangle == NULL) {// is boundary point or only point in point cloud?
|
---|
[a67d19] | 3699 | DoLog(1) && (Log() << Verbose(1) << "No triangle given!" << endl);
|
---|
[244a84] | 3700 | return -1.;
|
---|
[71b20e] | 3701 | } else {
|
---|
[a67d19] | 3702 | DoLog(1) && (Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl);
|
---|
[57066a] | 3703 | }
|
---|
| 3704 |
|
---|
[244a84] | 3705 | triangle->GetCenter(&Center);
|
---|
[a67d19] | 3706 | DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl);
|
---|
[273382] | 3707 | DistanceToCenter = Center - Point;
|
---|
[a67d19] | 3708 | DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl);
|
---|
[97498a] | 3709 |
|
---|
| 3710 | // check whether we are on boundary
|
---|
[273382] | 3711 | if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) {
|
---|
[97498a] | 3712 | // calculate whether inside of triangle
|
---|
[273382] | 3713 | DistanceToCenter = Point + triangle->NormalVector; // points outside
|
---|
| 3714 | Center = Point - triangle->NormalVector; // points towards MolCenter
|
---|
[a67d19] | 3715 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl);
|
---|
[244a84] | 3716 | if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
|
---|
[a67d19] | 3717 | DoLog(1) && (Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl);
|
---|
[9473f6] | 3718 | return 0.;
|
---|
[97498a] | 3719 | } else {
|
---|
[a67d19] | 3720 | DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl);
|
---|
[97498a] | 3721 | return false;
|
---|
| 3722 | }
|
---|
[57066a] | 3723 | } else {
|
---|
[9473f6] | 3724 | // calculate smallest distance
|
---|
[244a84] | 3725 | distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
|
---|
[a67d19] | 3726 | DoLog(1) && (Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl);
|
---|
[9473f6] | 3727 |
|
---|
| 3728 | // then check direction to boundary
|
---|
[273382] | 3729 | if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) {
|
---|
[a67d19] | 3730 | DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl);
|
---|
[9473f6] | 3731 | return -distance;
|
---|
| 3732 | } else {
|
---|
[a67d19] | 3733 | DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl);
|
---|
[9473f6] | 3734 | return +distance;
|
---|
| 3735 | }
|
---|
[57066a] | 3736 | }
|
---|
[6613ec] | 3737 | }
|
---|
| 3738 | ;
|
---|
[62bb91] | 3739 |
|
---|
[8db598] | 3740 | /** Calculates minimum distance from \a&Point to a tesselated surface.
|
---|
[244a84] | 3741 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
|
---|
| 3742 | * \param &Point point to calculate distance from
|
---|
| 3743 | * \param *LC needed for finding closest points fast
|
---|
| 3744 | * \return distance squared to closest point on surface
|
---|
| 3745 | */
|
---|
[8db598] | 3746 | double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const
|
---|
[244a84] | 3747 | {
|
---|
[8db598] | 3748 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3749 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3750 |
|
---|
| 3751 | return Intersections.GetSmallestDistance();
|
---|
[6613ec] | 3752 | }
|
---|
| 3753 | ;
|
---|
[8db598] | 3754 |
|
---|
| 3755 | /** Calculates minimum distance from \a&Point to a tesselated surface.
|
---|
| 3756 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
|
---|
| 3757 | * \param &Point point to calculate distance from
|
---|
| 3758 | * \param *LC needed for finding closest points fast
|
---|
| 3759 | * \return distance squared to closest point on surface
|
---|
| 3760 | */
|
---|
| 3761 | BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const
|
---|
| 3762 | {
|
---|
| 3763 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3764 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3765 |
|
---|
| 3766 | return Intersections.GetClosestTriangle();
|
---|
[6613ec] | 3767 | }
|
---|
| 3768 | ;
|
---|
[244a84] | 3769 |
|
---|
[62bb91] | 3770 | /** Gets all points connected to the provided point by triangulation lines.
|
---|
| 3771 | *
|
---|
| 3772 | * @param *Point of which get all connected points
|
---|
| 3773 | *
|
---|
[065e82] | 3774 | * @return set of the all points linked to the provided one
|
---|
[62bb91] | 3775 | */
|
---|
[c15ca2] | 3776 | TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
|
---|
[62bb91] | 3777 | {
|
---|
[6613ec] | 3778 | Info FunctionInfo(__func__);
|
---|
| 3779 | TesselPointSet *connectedPoints = new TesselPointSet;
|
---|
[5c7bf8] | 3780 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
[62bb91] | 3781 | TesselPoint* current;
|
---|
| 3782 | bool takePoint = false;
|
---|
[5c7bf8] | 3783 | // find the respective boundary point
|
---|
[776b64] | 3784 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[5c7bf8] | 3785 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 3786 | ReferencePoint = PointRunner->second;
|
---|
| 3787 | } else {
|
---|
[6613ec] | 3788 | DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
|
---|
[5c7bf8] | 3789 | ReferencePoint = NULL;
|
---|
| 3790 | }
|
---|
[62bb91] | 3791 |
|
---|
[065e82] | 3792 | // little trick so that we look just through lines connect to the BoundaryPoint
|
---|
[5c7bf8] | 3793 | // OR fall-back to look through all lines if there is no such BoundaryPoint
|
---|
[6613ec] | 3794 | const LineMap *Lines;
|
---|
| 3795 | ;
|
---|
[5c7bf8] | 3796 | if (ReferencePoint != NULL)
|
---|
| 3797 | Lines = &(ReferencePoint->lines);
|
---|
[776b64] | 3798 | else
|
---|
| 3799 | Lines = &LinesOnBoundary;
|
---|
| 3800 | LineMap::const_iterator findLines = Lines->begin();
|
---|
[5c7bf8] | 3801 | while (findLines != Lines->end()) {
|
---|
[6613ec] | 3802 | takePoint = false;
|
---|
| 3803 |
|
---|
| 3804 | if (findLines->second->endpoints[0]->Nr == Point->nr) {
|
---|
| 3805 | takePoint = true;
|
---|
| 3806 | current = findLines->second->endpoints[1]->node;
|
---|
| 3807 | } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
|
---|
| 3808 | takePoint = true;
|
---|
| 3809 | current = findLines->second->endpoints[0]->node;
|
---|
| 3810 | }
|
---|
[065e82] | 3811 |
|
---|
[6613ec] | 3812 | if (takePoint) {
|
---|
[a67d19] | 3813 | DoLog(1) && (Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl);
|
---|
[6613ec] | 3814 | connectedPoints->insert(current);
|
---|
| 3815 | }
|
---|
[62bb91] | 3816 |
|
---|
[6613ec] | 3817 | findLines++;
|
---|
[62bb91] | 3818 | }
|
---|
| 3819 |
|
---|
[71b20e] | 3820 | if (connectedPoints->empty()) { // if have not found any points
|
---|
[6613ec] | 3821 | DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl);
|
---|
[16d866] | 3822 | return NULL;
|
---|
| 3823 | }
|
---|
[065e82] | 3824 |
|
---|
[16d866] | 3825 | return connectedPoints;
|
---|
[6613ec] | 3826 | }
|
---|
| 3827 | ;
|
---|
[065e82] | 3828 |
|
---|
| 3829 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
[16d866] | 3830 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 3831 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 3832 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 3833 | * triangle we are looking for.
|
---|
| 3834 | *
|
---|
| 3835 | * @param *out output stream for debugging
|
---|
[27bd2f] | 3836 | * @param *SetOfNeighbours all points for which the angle should be calculated
|
---|
[16d866] | 3837 | * @param *Point of which get all connected points
|
---|
[065e82] | 3838 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 3839 | * @return list of the all points linked to the provided one
|
---|
[16d866] | 3840 | */
|
---|
[c15ca2] | 3841 | TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[16d866] | 3842 | {
|
---|
[6613ec] | 3843 | Info FunctionInfo(__func__);
|
---|
[16d866] | 3844 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3845 | TesselPointList *connectedCircle = new TesselPointList;
|
---|
[71b20e] | 3846 | Vector PlaneNormal;
|
---|
| 3847 | Vector AngleZero;
|
---|
| 3848 | Vector OrthogonalVector;
|
---|
| 3849 | Vector helper;
|
---|
[6613ec] | 3850 | const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL };
|
---|
[c15ca2] | 3851 | TriangleList *triangles = NULL;
|
---|
[71b20e] | 3852 |
|
---|
| 3853 | if (SetOfNeighbours == NULL) {
|
---|
[6613ec] | 3854 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
|
---|
| 3855 | delete (connectedCircle);
|
---|
[71b20e] | 3856 | return NULL;
|
---|
| 3857 | }
|
---|
| 3858 |
|
---|
| 3859 | // calculate central point
|
---|
| 3860 | triangles = FindTriangles(TrianglePoints);
|
---|
| 3861 | if ((triangles != NULL) && (!triangles->empty())) {
|
---|
[c15ca2] | 3862 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
|
---|
[273382] | 3863 | PlaneNormal += (*Runner)->NormalVector;
|
---|
[71b20e] | 3864 | } else {
|
---|
[6613ec] | 3865 | DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
|
---|
[71b20e] | 3866 | performCriticalExit();
|
---|
| 3867 | }
|
---|
[6613ec] | 3868 | PlaneNormal.Scale(1.0 / triangles->size());
|
---|
[a67d19] | 3869 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl);
|
---|
[71b20e] | 3870 | PlaneNormal.Normalize();
|
---|
| 3871 |
|
---|
| 3872 | // construct one orthogonal vector
|
---|
| 3873 | if (Reference != NULL) {
|
---|
[273382] | 3874 | AngleZero = (*Reference) - (*Point->node);
|
---|
| 3875 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3876 | }
|
---|
[6613ec] | 3877 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
|
---|
[a67d19] | 3878 | DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
|
---|
[273382] | 3879 | AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
|
---|
| 3880 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3881 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
[6613ec] | 3882 | DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
|
---|
[71b20e] | 3883 | performCriticalExit();
|
---|
| 3884 | }
|
---|
| 3885 | }
|
---|
[a67d19] | 3886 | DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
|
---|
[71b20e] | 3887 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
[0a4f7f] | 3888 | OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
|
---|
[71b20e] | 3889 | else
|
---|
[0a4f7f] | 3890 | OrthogonalVector.MakeNormalTo(PlaneNormal);
|
---|
[a67d19] | 3891 | DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
|
---|
[71b20e] | 3892 |
|
---|
| 3893 | // go through all connected points and calculate angle
|
---|
[c15ca2] | 3894 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
|
---|
[273382] | 3895 | helper = (*(*listRunner)->node) - (*Point->node);
|
---|
| 3896 | helper.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3897 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
[a67d19] | 3898 | DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl);
|
---|
[6613ec] | 3899 | anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
|
---|
[71b20e] | 3900 | }
|
---|
| 3901 |
|
---|
[6613ec] | 3902 | for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
[71b20e] | 3903 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 3904 | }
|
---|
| 3905 |
|
---|
| 3906 | return connectedCircle;
|
---|
| 3907 | }
|
---|
| 3908 |
|
---|
| 3909 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
| 3910 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 3911 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 3912 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 3913 | * triangle we are looking for.
|
---|
| 3914 | *
|
---|
| 3915 | * @param *SetOfNeighbours all points for which the angle should be calculated
|
---|
| 3916 | * @param *Point of which get all connected points
|
---|
| 3917 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 3918 | * @return list of the all points linked to the provided one
|
---|
| 3919 | */
|
---|
[c15ca2] | 3920 | TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[71b20e] | 3921 | {
|
---|
| 3922 | Info FunctionInfo(__func__);
|
---|
| 3923 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3924 | TesselPointList *connectedCircle = new TesselPointList;
|
---|
[065e82] | 3925 | Vector center;
|
---|
| 3926 | Vector PlaneNormal;
|
---|
| 3927 | Vector AngleZero;
|
---|
| 3928 | Vector OrthogonalVector;
|
---|
| 3929 | Vector helper;
|
---|
[62bb91] | 3930 |
|
---|
[27bd2f] | 3931 | if (SetOfNeighbours == NULL) {
|
---|
[6613ec] | 3932 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
|
---|
| 3933 | delete (connectedCircle);
|
---|
[99593f] | 3934 | return NULL;
|
---|
| 3935 | }
|
---|
[a2028e] | 3936 |
|
---|
[97498a] | 3937 | // check whether there's something to do
|
---|
| 3938 | if (SetOfNeighbours->size() < 3) {
|
---|
| 3939 | for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
|
---|
| 3940 | connectedCircle->push_back(*TesselRunner);
|
---|
| 3941 | return connectedCircle;
|
---|
| 3942 | }
|
---|
| 3943 |
|
---|
[a67d19] | 3944 | DoLog(1) && (Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl);
|
---|
[16d866] | 3945 | // calculate central point
|
---|
[97498a] | 3946 | TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
|
---|
| 3947 | TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
|
---|
| 3948 | TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin();
|
---|
| 3949 | TesselB++;
|
---|
| 3950 | TesselC++;
|
---|
| 3951 | TesselC++;
|
---|
| 3952 | int counter = 0;
|
---|
| 3953 | while (TesselC != SetOfNeighbours->end()) {
|
---|
[0a4f7f] | 3954 | helper = Plane(*((*TesselA)->node),
|
---|
| 3955 | *((*TesselB)->node),
|
---|
| 3956 | *((*TesselC)->node)).getNormal();
|
---|
[a67d19] | 3957 | DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl);
|
---|
[97498a] | 3958 | counter++;
|
---|
| 3959 | TesselA++;
|
---|
| 3960 | TesselB++;
|
---|
| 3961 | TesselC++;
|
---|
[273382] | 3962 | PlaneNormal += helper;
|
---|
[97498a] | 3963 | }
|
---|
| 3964 | //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
|
---|
| 3965 | // << "; scale factor " << counter;
|
---|
[6613ec] | 3966 | PlaneNormal.Scale(1.0 / (double) counter);
|
---|
| 3967 | // Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
|
---|
| 3968 | //
|
---|
| 3969 | // // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
|
---|
| 3970 | // PlaneNormal.CopyVector(Point->node);
|
---|
| 3971 | // PlaneNormal.SubtractVector(¢er);
|
---|
| 3972 | // PlaneNormal.Normalize();
|
---|
[a67d19] | 3973 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl);
|
---|
[62bb91] | 3974 |
|
---|
| 3975 | // construct one orthogonal vector
|
---|
[a2028e] | 3976 | if (Reference != NULL) {
|
---|
[273382] | 3977 | AngleZero = (*Reference) - (*Point->node);
|
---|
| 3978 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[a2028e] | 3979 | }
|
---|
| 3980 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
|
---|
[a67d19] | 3981 | DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
|
---|
[273382] | 3982 | AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
|
---|
| 3983 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[a2028e] | 3984 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
[6613ec] | 3985 | DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
|
---|
[a2028e] | 3986 | performCriticalExit();
|
---|
| 3987 | }
|
---|
| 3988 | }
|
---|
[a67d19] | 3989 | DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
|
---|
[a2028e] | 3990 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
[0a4f7f] | 3991 | OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
|
---|
[a2028e] | 3992 | else
|
---|
[0a4f7f] | 3993 | OrthogonalVector.MakeNormalTo(PlaneNormal);
|
---|
[a67d19] | 3994 | DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
|
---|
[16d866] | 3995 |
|
---|
[5c7bf8] | 3996 | // go through all connected points and calculate angle
|
---|
[6613ec] | 3997 | pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
|
---|
[c15ca2] | 3998 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
|
---|
[273382] | 3999 | helper = (*(*listRunner)->node) - (*Point->node);
|
---|
| 4000 | helper.ProjectOntoPlane(PlaneNormal);
|
---|
[f1cccd] | 4001 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
[97498a] | 4002 | if (angle > M_PI) // the correction is of no use here (and not desired)
|
---|
[6613ec] | 4003 | angle = 2. * M_PI - angle;
|
---|
[a67d19] | 4004 | DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl);
|
---|
[6613ec] | 4005 | InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
|
---|
[c15ca2] | 4006 | if (!InserterTest.second) {
|
---|
[6613ec] | 4007 | DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);
|
---|
[c15ca2] | 4008 | performCriticalExit();
|
---|
| 4009 | }
|
---|
[62bb91] | 4010 | }
|
---|
| 4011 |
|
---|
[6613ec] | 4012 | for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
[065e82] | 4013 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 4014 | }
|
---|
[62bb91] | 4015 |
|
---|
[065e82] | 4016 | return connectedCircle;
|
---|
| 4017 | }
|
---|
[62bb91] | 4018 |
|
---|
[065e82] | 4019 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path.
|
---|
| 4020 | *
|
---|
| 4021 | * @param *out output stream for debugging
|
---|
| 4022 | * @param *Point of which get all connected points
|
---|
| 4023 | * @return list of the all points linked to the provided one
|
---|
| 4024 | */
|
---|
[244a84] | 4025 | ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 4026 | {
|
---|
[6613ec] | 4027 | Info FunctionInfo(__func__);
|
---|
[065e82] | 4028 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[6613ec] | 4029 | list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ;
|
---|
[c15ca2] | 4030 | TesselPointList *connectedPath = NULL;
|
---|
[065e82] | 4031 | Vector center;
|
---|
| 4032 | Vector PlaneNormal;
|
---|
| 4033 | Vector AngleZero;
|
---|
| 4034 | Vector OrthogonalVector;
|
---|
| 4035 | Vector helper;
|
---|
| 4036 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
| 4037 | class BoundaryPointSet *CurrentPoint = NULL;
|
---|
| 4038 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 4039 | class BoundaryLineSet *CurrentLine = NULL;
|
---|
| 4040 | class BoundaryLineSet *StartLine = NULL;
|
---|
| 4041 | // find the respective boundary point
|
---|
[776b64] | 4042 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[065e82] | 4043 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 4044 | ReferencePoint = PointRunner->second;
|
---|
| 4045 | } else {
|
---|
[6613ec] | 4046 | DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
|
---|
[065e82] | 4047 | return NULL;
|
---|
| 4048 | }
|
---|
| 4049 |
|
---|
[6613ec] | 4050 | map<class BoundaryLineSet *, bool> TouchedLine;
|
---|
| 4051 | map<class BoundaryTriangleSet *, bool> TouchedTriangle;
|
---|
| 4052 | map<class BoundaryLineSet *, bool>::iterator LineRunner;
|
---|
| 4053 | map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
|
---|
[57066a] | 4054 | for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
|
---|
[6613ec] | 4055 | TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false));
|
---|
[57066a] | 4056 | for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
|
---|
[6613ec] | 4057 | TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false));
|
---|
[57066a] | 4058 | }
|
---|
[065e82] | 4059 | if (!ReferencePoint->lines.empty()) {
|
---|
| 4060 | for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) {
|
---|
[57066a] | 4061 | LineRunner = TouchedLine.find(runner->second);
|
---|
| 4062 | if (LineRunner == TouchedLine.end()) {
|
---|
[6613ec] | 4063 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);
|
---|
[57066a] | 4064 | } else if (!LineRunner->second) {
|
---|
| 4065 | LineRunner->second = true;
|
---|
[c15ca2] | 4066 | connectedPath = new TesselPointList;
|
---|
[065e82] | 4067 | triangle = NULL;
|
---|
| 4068 | CurrentLine = runner->second;
|
---|
| 4069 | StartLine = CurrentLine;
|
---|
| 4070 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
[a67d19] | 4071 | DoLog(1) && (Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl);
|
---|
[065e82] | 4072 | do {
|
---|
| 4073 | // push current one
|
---|
[a67d19] | 4074 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
|
---|
[065e82] | 4075 | connectedPath->push_back(CurrentPoint->node);
|
---|
| 4076 |
|
---|
| 4077 | // find next triangle
|
---|
[57066a] | 4078 | for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
|
---|
[a67d19] | 4079 | DoLog(1) && (Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl);
|
---|
[57066a] | 4080 | if ((Runner->second != triangle)) { // look for first triangle not equal to old one
|
---|
| 4081 | triangle = Runner->second;
|
---|
| 4082 | TriangleRunner = TouchedTriangle.find(triangle);
|
---|
| 4083 | if (TriangleRunner != TouchedTriangle.end()) {
|
---|
| 4084 | if (!TriangleRunner->second) {
|
---|
| 4085 | TriangleRunner->second = true;
|
---|
[a67d19] | 4086 | DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl);
|
---|
[57066a] | 4087 | break;
|
---|
| 4088 | } else {
|
---|
[a67d19] | 4089 | DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl);
|
---|
[57066a] | 4090 | triangle = NULL;
|
---|
| 4091 | }
|
---|
| 4092 | } else {
|
---|
[6613ec] | 4093 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);
|
---|
[57066a] | 4094 | triangle = NULL;
|
---|
| 4095 | }
|
---|
[065e82] | 4096 | }
|
---|
| 4097 | }
|
---|
[57066a] | 4098 | if (triangle == NULL)
|
---|
| 4099 | break;
|
---|
[065e82] | 4100 | // find next line
|
---|
[6613ec] | 4101 | for (int i = 0; i < 3; i++) {
|
---|
[065e82] | 4102 | if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
|
---|
| 4103 | CurrentLine = triangle->lines[i];
|
---|
[a67d19] | 4104 | DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl);
|
---|
[065e82] | 4105 | break;
|
---|
| 4106 | }
|
---|
| 4107 | }
|
---|
[57066a] | 4108 | LineRunner = TouchedLine.find(CurrentLine);
|
---|
| 4109 | if (LineRunner == TouchedLine.end())
|
---|
[6613ec] | 4110 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);
|
---|
[065e82] | 4111 | else
|
---|
[57066a] | 4112 | LineRunner->second = true;
|
---|
[065e82] | 4113 | // find next point
|
---|
| 4114 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
| 4115 |
|
---|
| 4116 | } while (CurrentLine != StartLine);
|
---|
| 4117 | // last point is missing, as it's on start line
|
---|
[a67d19] | 4118 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
|
---|
[57066a] | 4119 | if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
|
---|
| 4120 | connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
|
---|
[065e82] | 4121 |
|
---|
| 4122 | ListOfPaths->push_back(connectedPath);
|
---|
| 4123 | } else {
|
---|
[a67d19] | 4124 | DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl);
|
---|
[065e82] | 4125 | }
|
---|
| 4126 | }
|
---|
| 4127 | } else {
|
---|
[6613ec] | 4128 | DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);
|
---|
[065e82] | 4129 | }
|
---|
| 4130 |
|
---|
| 4131 | return ListOfPaths;
|
---|
[62bb91] | 4132 | }
|
---|
| 4133 |
|
---|
[065e82] | 4134 | /** Gets all closed paths on the circle of points connected to the provided point by triangulation lines, if this very point is removed.
|
---|
| 4135 | * From GetPathsOfConnectedPoints() extracts all single loops of intracrossing paths in the list of closed paths.
|
---|
| 4136 | * @param *out output stream for debugging
|
---|
| 4137 | * @param *Point of which get all connected points
|
---|
| 4138 | * @return list of the closed paths
|
---|
| 4139 | */
|
---|
[244a84] | 4140 | ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 4141 | {
|
---|
[6613ec] | 4142 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4143 | list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
|
---|
[6613ec] | 4144 | list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;
|
---|
[c15ca2] | 4145 | TesselPointList *connectedPath = NULL;
|
---|
| 4146 | TesselPointList *newPath = NULL;
|
---|
[065e82] | 4147 | int count = 0;
|
---|
[c15ca2] | 4148 | TesselPointList::iterator CircleRunner;
|
---|
| 4149 | TesselPointList::iterator CircleStart;
|
---|
[065e82] | 4150 |
|
---|
[6613ec] | 4151 | for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
|
---|
[065e82] | 4152 | connectedPath = *ListRunner;
|
---|
| 4153 |
|
---|
[a67d19] | 4154 | DoLog(1) && (Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl);
|
---|
[065e82] | 4155 |
|
---|
| 4156 | // go through list, look for reappearance of starting Point and count
|
---|
| 4157 | CircleStart = connectedPath->begin();
|
---|
| 4158 | // go through list, look for reappearance of starting Point and create list
|
---|
[c15ca2] | 4159 | TesselPointList::iterator Marker = CircleStart;
|
---|
[065e82] | 4160 | for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
|
---|
| 4161 | if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
|
---|
| 4162 | // we have a closed circle from Marker to new Marker
|
---|
[a67d19] | 4163 | DoLog(1) && (Log() << Verbose(1) << count + 1 << ". closed path consists of: ");
|
---|
[c15ca2] | 4164 | newPath = new TesselPointList;
|
---|
| 4165 | TesselPointList::iterator CircleSprinter = Marker;
|
---|
[065e82] | 4166 | for (; CircleSprinter != CircleRunner; CircleSprinter++) {
|
---|
| 4167 | newPath->push_back(*CircleSprinter);
|
---|
[a67d19] | 4168 | DoLog(0) && (Log() << Verbose(0) << (**CircleSprinter) << " <-> ");
|
---|
[065e82] | 4169 | }
|
---|
[a67d19] | 4170 | DoLog(0) && (Log() << Verbose(0) << ".." << endl);
|
---|
[065e82] | 4171 | count++;
|
---|
| 4172 | Marker = CircleRunner;
|
---|
| 4173 |
|
---|
| 4174 | // add to list
|
---|
| 4175 | ListofClosedPaths->push_back(newPath);
|
---|
| 4176 | }
|
---|
| 4177 | }
|
---|
| 4178 | }
|
---|
[a67d19] | 4179 | DoLog(1) && (Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl);
|
---|
[065e82] | 4180 |
|
---|
| 4181 | // delete list of paths
|
---|
| 4182 | while (!ListofPaths->empty()) {
|
---|
| 4183 | connectedPath = *(ListofPaths->begin());
|
---|
| 4184 | ListofPaths->remove(connectedPath);
|
---|
[6613ec] | 4185 | delete (connectedPath);
|
---|
[065e82] | 4186 | }
|
---|
[6613ec] | 4187 | delete (ListofPaths);
|
---|
[065e82] | 4188 |
|
---|
| 4189 | // exit
|
---|
| 4190 | return ListofClosedPaths;
|
---|
[6613ec] | 4191 | }
|
---|
| 4192 | ;
|
---|
[065e82] | 4193 |
|
---|
| 4194 | /** Gets all belonging triangles for a given BoundaryPointSet.
|
---|
| 4195 | * \param *out output stream for debugging
|
---|
| 4196 | * \param *Point BoundaryPoint
|
---|
| 4197 | * \return pointer to allocated list of triangles
|
---|
| 4198 | */
|
---|
[c15ca2] | 4199 | TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
|
---|
[065e82] | 4200 | {
|
---|
[6613ec] | 4201 | Info FunctionInfo(__func__);
|
---|
| 4202 | TriangleSet *connectedTriangles = new TriangleSet;
|
---|
[065e82] | 4203 |
|
---|
| 4204 | if (Point == NULL) {
|
---|
[6613ec] | 4205 | DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl);
|
---|
[065e82] | 4206 | } else {
|
---|
| 4207 | // go through its lines and insert all triangles
|
---|
[776b64] | 4208 | for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
|
---|
[065e82] | 4209 | for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
[6613ec] | 4210 | connectedTriangles->insert(TriangleRunner->second);
|
---|
| 4211 | }
|
---|
[065e82] | 4212 | }
|
---|
| 4213 |
|
---|
| 4214 | return connectedTriangles;
|
---|
[6613ec] | 4215 | }
|
---|
| 4216 | ;
|
---|
[065e82] | 4217 |
|
---|
[16d866] | 4218 | /** Removes a boundary point from the envelope while keeping it closed.
|
---|
[57066a] | 4219 | * We remove the old triangles connected to the point and re-create new triangles to close the surface following this ansatz:
|
---|
| 4220 | * -# a closed path(s) of boundary points surrounding the point to be removed is constructed
|
---|
| 4221 | * -# on each closed path, we pick three adjacent points, create a triangle with them and subtract the middle point from the path
|
---|
| 4222 | * -# we advance two points (i.e. the next triangle will start at the ending point of the last triangle) and continue as before
|
---|
| 4223 | * -# the surface is closed, when the path is empty
|
---|
| 4224 | * Thereby, we (hopefully) make sure that the removed points remains beneath the surface (this is checked via IsInnerPoint eventually).
|
---|
[16d866] | 4225 | * \param *out output stream for debugging
|
---|
| 4226 | * \param *point point to be removed
|
---|
| 4227 | * \return volume added to the volume inside the tesselated surface by the removal
|
---|
| 4228 | */
|
---|
[6613ec] | 4229 | double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point)
|
---|
| 4230 | {
|
---|
[16d866] | 4231 | class BoundaryLineSet *line = NULL;
|
---|
| 4232 | class BoundaryTriangleSet *triangle = NULL;
|
---|
[57066a] | 4233 | Vector OldPoint, NormalVector;
|
---|
[16d866] | 4234 | double volume = 0;
|
---|
| 4235 | int count = 0;
|
---|
| 4236 |
|
---|
[1d9b7aa] | 4237 | if (point == NULL) {
|
---|
[6613ec] | 4238 | DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);
|
---|
[1d9b7aa] | 4239 | return 0.;
|
---|
| 4240 | } else
|
---|
[a67d19] | 4241 | DoLog(0) && (Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl);
|
---|
[1d9b7aa] | 4242 |
|
---|
[16d866] | 4243 | // copy old location for the volume
|
---|
[273382] | 4244 | OldPoint = (*point->node->node);
|
---|
[16d866] | 4245 |
|
---|
| 4246 | // get list of connected points
|
---|
| 4247 | if (point->lines.empty()) {
|
---|
[6613ec] | 4248 | DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);
|
---|
[16d866] | 4249 | return 0.;
|
---|
| 4250 | }
|
---|
| 4251 |
|
---|
[c15ca2] | 4252 | list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
|
---|
| 4253 | TesselPointList *connectedPath = NULL;
|
---|
[065e82] | 4254 |
|
---|
| 4255 | // gather all triangles
|
---|
[16d866] | 4256 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
|
---|
[6613ec] | 4257 | count += LineRunner->second->triangles.size();
|
---|
[c15ca2] | 4258 | TriangleMap Candidates;
|
---|
[57066a] | 4259 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
|
---|
[16d866] | 4260 | line = LineRunner->second;
|
---|
| 4261 | for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
|
---|
| 4262 | triangle = TriangleRunner->second;
|
---|
[6613ec] | 4263 | Candidates.insert(TrianglePair(triangle->Nr, triangle));
|
---|
[16d866] | 4264 | }
|
---|
| 4265 | }
|
---|
| 4266 |
|
---|
[065e82] | 4267 | // remove all triangles
|
---|
[6613ec] | 4268 | count = 0;
|
---|
[57066a] | 4269 | NormalVector.Zero();
|
---|
[c15ca2] | 4270 | for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
|
---|
[a67d19] | 4271 | DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl);
|
---|
[273382] | 4272 | NormalVector -= Runner->second->NormalVector; // has to point inward
|
---|
[c15ca2] | 4273 | RemoveTesselationTriangle(Runner->second);
|
---|
[065e82] | 4274 | count++;
|
---|
| 4275 | }
|
---|
[a67d19] | 4276 | DoLog(1) && (Log() << Verbose(1) << count << " triangles were removed." << endl);
|
---|
[065e82] | 4277 |
|
---|
[c15ca2] | 4278 | list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
|
---|
| 4279 | list<TesselPointList *>::iterator ListRunner = ListAdvance;
|
---|
| 4280 | TriangleMap::iterator NumberRunner = Candidates.begin();
|
---|
| 4281 | TesselPointList::iterator StartNode, MiddleNode, EndNode;
|
---|
[57066a] | 4282 | double angle;
|
---|
| 4283 | double smallestangle;
|
---|
| 4284 | Vector Point, Reference, OrthogonalVector;
|
---|
[6613ec] | 4285 | if (count > 2) { // less than three triangles, then nothing will be created
|
---|
[065e82] | 4286 | class TesselPoint *TriangleCandidates[3];
|
---|
| 4287 | count = 0;
|
---|
[6613ec] | 4288 | for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
|
---|
[065e82] | 4289 | if (ListAdvance != ListOfClosedPaths->end())
|
---|
| 4290 | ListAdvance++;
|
---|
| 4291 |
|
---|
| 4292 | connectedPath = *ListRunner;
|
---|
| 4293 | // re-create all triangles by going through connected points list
|
---|
[c15ca2] | 4294 | LineList NewLines;
|
---|
[6613ec] | 4295 | for (; !connectedPath->empty();) {
|
---|
[57066a] | 4296 | // search middle node with widest angle to next neighbours
|
---|
| 4297 | EndNode = connectedPath->end();
|
---|
| 4298 | smallestangle = 0.;
|
---|
| 4299 | for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
|
---|
[a67d19] | 4300 | DoLog(1) && (Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
|
---|
[57066a] | 4301 | // construct vectors to next and previous neighbour
|
---|
| 4302 | StartNode = MiddleNode;
|
---|
| 4303 | if (StartNode == connectedPath->begin())
|
---|
| 4304 | StartNode = connectedPath->end();
|
---|
| 4305 | StartNode--;
|
---|
[e138de] | 4306 | //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl;
|
---|
[273382] | 4307 | Point = (*(*StartNode)->node) - (*(*MiddleNode)->node);
|
---|
[57066a] | 4308 | StartNode = MiddleNode;
|
---|
| 4309 | StartNode++;
|
---|
| 4310 | if (StartNode == connectedPath->end())
|
---|
| 4311 | StartNode = connectedPath->begin();
|
---|
[e138de] | 4312 | //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl;
|
---|
[273382] | 4313 | Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node);
|
---|
| 4314 | OrthogonalVector = (*(*MiddleNode)->node) - OldPoint;
|
---|
[0a4f7f] | 4315 | OrthogonalVector.MakeNormalTo(Reference);
|
---|
[57066a] | 4316 | angle = GetAngle(Point, Reference, OrthogonalVector);
|
---|
| 4317 | //if (angle < M_PI) // no wrong-sided triangles, please?
|
---|
[6613ec] | 4318 | if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
|
---|
| 4319 | smallestangle = angle;
|
---|
| 4320 | EndNode = MiddleNode;
|
---|
| 4321 | }
|
---|
[57066a] | 4322 | }
|
---|
| 4323 | MiddleNode = EndNode;
|
---|
| 4324 | if (MiddleNode == connectedPath->end()) {
|
---|
[6613ec] | 4325 | DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);
|
---|
[f67b6e] | 4326 | performCriticalExit();
|
---|
[57066a] | 4327 | }
|
---|
| 4328 | StartNode = MiddleNode;
|
---|
| 4329 | if (StartNode == connectedPath->begin())
|
---|
| 4330 | StartNode = connectedPath->end();
|
---|
| 4331 | StartNode--;
|
---|
| 4332 | EndNode++;
|
---|
| 4333 | if (EndNode == connectedPath->end())
|
---|
| 4334 | EndNode = connectedPath->begin();
|
---|
[a67d19] | 4335 | DoLog(2) && (Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl);
|
---|
| 4336 | DoLog(2) && (Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
|
---|
| 4337 | DoLog(2) && (Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl);
|
---|
[68f03d] | 4338 | DoLog(1) && (Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->getName() << ", " << (*MiddleNode)->getName() << " and " << (*EndNode)->getName() << "." << endl);
|
---|
[57066a] | 4339 | TriangleCandidates[0] = *StartNode;
|
---|
| 4340 | TriangleCandidates[1] = *MiddleNode;
|
---|
| 4341 | TriangleCandidates[2] = *EndNode;
|
---|
[e138de] | 4342 | triangle = GetPresentTriangle(TriangleCandidates);
|
---|
[57066a] | 4343 | if (triangle != NULL) {
|
---|
[6613ec] | 4344 | DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl);
|
---|
[57066a] | 4345 | StartNode++;
|
---|
| 4346 | MiddleNode++;
|
---|
| 4347 | EndNode++;
|
---|
| 4348 | if (StartNode == connectedPath->end())
|
---|
| 4349 | StartNode = connectedPath->begin();
|
---|
| 4350 | if (MiddleNode == connectedPath->end())
|
---|
| 4351 | MiddleNode = connectedPath->begin();
|
---|
| 4352 | if (EndNode == connectedPath->end())
|
---|
| 4353 | EndNode = connectedPath->begin();
|
---|
| 4354 | continue;
|
---|
| 4355 | }
|
---|
[a67d19] | 4356 | DoLog(3) && (Log() << Verbose(3) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4357 | AddTesselationPoint(*StartNode, 0);
|
---|
| 4358 | AddTesselationPoint(*MiddleNode, 1);
|
---|
| 4359 | AddTesselationPoint(*EndNode, 2);
|
---|
[a67d19] | 4360 | DoLog(3) && (Log() << Verbose(3) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4361 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4362 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
[57066a] | 4363 | NewLines.push_back(BLS[1]);
|
---|
[f07f86d] | 4364 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[065e82] | 4365 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[57066a] | 4366 | BTS->GetNormalVector(NormalVector);
|
---|
[065e82] | 4367 | AddTesselationTriangle();
|
---|
| 4368 | // calculate volume summand as a general tetraeder
|
---|
[c0f6c6] | 4369 | volume += CalculateVolumeofGeneralTetraeder(*TPS[0]->node->node, *TPS[1]->node->node, *TPS[2]->node->node, OldPoint);
|
---|
[065e82] | 4370 | // advance number
|
---|
| 4371 | count++;
|
---|
[57066a] | 4372 |
|
---|
| 4373 | // prepare nodes for next triangle
|
---|
| 4374 | StartNode = EndNode;
|
---|
[a67d19] | 4375 | DoLog(2) && (Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl);
|
---|
[57066a] | 4376 | connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
|
---|
| 4377 | if (connectedPath->size() == 2) { // we are done
|
---|
| 4378 | connectedPath->remove(*StartNode); // remove the start node
|
---|
| 4379 | connectedPath->remove(*EndNode); // remove the end node
|
---|
| 4380 | break;
|
---|
| 4381 | } else if (connectedPath->size() < 2) { // something's gone wrong!
|
---|
[6613ec] | 4382 | DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);
|
---|
[f67b6e] | 4383 | performCriticalExit();
|
---|
[57066a] | 4384 | } else {
|
---|
| 4385 | MiddleNode = StartNode;
|
---|
| 4386 | MiddleNode++;
|
---|
| 4387 | if (MiddleNode == connectedPath->end())
|
---|
| 4388 | MiddleNode = connectedPath->begin();
|
---|
| 4389 | EndNode = MiddleNode;
|
---|
| 4390 | EndNode++;
|
---|
| 4391 | if (EndNode == connectedPath->end())
|
---|
| 4392 | EndNode = connectedPath->begin();
|
---|
| 4393 | }
|
---|
[065e82] | 4394 | }
|
---|
[57066a] | 4395 | // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
|
---|
| 4396 | if (NewLines.size() > 1) {
|
---|
[c15ca2] | 4397 | LineList::iterator Candidate;
|
---|
[57066a] | 4398 | class BoundaryLineSet *OtherBase = NULL;
|
---|
| 4399 | double tmp, maxgain;
|
---|
| 4400 | do {
|
---|
| 4401 | maxgain = 0;
|
---|
[6613ec] | 4402 | for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
|
---|
[e138de] | 4403 | tmp = PickFarthestofTwoBaselines(*Runner);
|
---|
[57066a] | 4404 | if (maxgain < tmp) {
|
---|
| 4405 | maxgain = tmp;
|
---|
| 4406 | Candidate = Runner;
|
---|
| 4407 | }
|
---|
| 4408 | }
|
---|
| 4409 | if (maxgain != 0) {
|
---|
| 4410 | volume += maxgain;
|
---|
[a67d19] | 4411 | DoLog(1) && (Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl);
|
---|
[e138de] | 4412 | OtherBase = FlipBaseline(*Candidate);
|
---|
[57066a] | 4413 | NewLines.erase(Candidate);
|
---|
| 4414 | NewLines.push_back(OtherBase);
|
---|
| 4415 | }
|
---|
| 4416 | } while (maxgain != 0.);
|
---|
| 4417 | }
|
---|
| 4418 |
|
---|
[065e82] | 4419 | ListOfClosedPaths->remove(connectedPath);
|
---|
[6613ec] | 4420 | delete (connectedPath);
|
---|
[16d866] | 4421 | }
|
---|
[a67d19] | 4422 | DoLog(0) && (Log() << Verbose(0) << count << " triangles were created." << endl);
|
---|
[065e82] | 4423 | } else {
|
---|
| 4424 | while (!ListOfClosedPaths->empty()) {
|
---|
| 4425 | ListRunner = ListOfClosedPaths->begin();
|
---|
| 4426 | connectedPath = *ListRunner;
|
---|
| 4427 | ListOfClosedPaths->remove(connectedPath);
|
---|
[6613ec] | 4428 | delete (connectedPath);
|
---|
[065e82] | 4429 | }
|
---|
[a67d19] | 4430 | DoLog(0) && (Log() << Verbose(0) << "No need to create any triangles." << endl);
|
---|
[16d866] | 4431 | }
|
---|
[6613ec] | 4432 | delete (ListOfClosedPaths);
|
---|
[16d866] | 4433 |
|
---|
[a67d19] | 4434 | DoLog(0) && (Log() << Verbose(0) << "Removed volume is " << volume << "." << endl);
|
---|
[357fba] | 4435 |
|
---|
[57066a] | 4436 | return volume;
|
---|
[6613ec] | 4437 | }
|
---|
| 4438 | ;
|
---|
[ab1932] | 4439 |
|
---|
| 4440 | /**
|
---|
[62bb91] | 4441 | * Finds triangles belonging to the three provided points.
|
---|
[ab1932] | 4442 | *
|
---|
[71b20e] | 4443 | * @param *Points[3] list, is expected to contain three points (NULL means wildcard)
|
---|
[ab1932] | 4444 | *
|
---|
[62bb91] | 4445 | * @return triangles which belong to the provided points, will be empty if there are none,
|
---|
[ab1932] | 4446 | * will usually be one, in case of degeneration, there will be two
|
---|
| 4447 | */
|
---|
[c15ca2] | 4448 | TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
|
---|
[ab1932] | 4449 | {
|
---|
[6613ec] | 4450 | Info FunctionInfo(__func__);
|
---|
| 4451 | TriangleList *result = new TriangleList;
|
---|
[776b64] | 4452 | LineMap::const_iterator FindLine;
|
---|
| 4453 | TriangleMap::const_iterator FindTriangle;
|
---|
[ab1932] | 4454 | class BoundaryPointSet *TrianglePoints[3];
|
---|
[71b20e] | 4455 | size_t NoOfWildcards = 0;
|
---|
[ab1932] | 4456 |
|
---|
| 4457 | for (int i = 0; i < 3; i++) {
|
---|
[71b20e] | 4458 | if (Points[i] == NULL) {
|
---|
| 4459 | NoOfWildcards++;
|
---|
[ab1932] | 4460 | TrianglePoints[i] = NULL;
|
---|
[71b20e] | 4461 | } else {
|
---|
| 4462 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
|
---|
| 4463 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 4464 | TrianglePoints[i] = FindPoint->second;
|
---|
| 4465 | } else {
|
---|
| 4466 | TrianglePoints[i] = NULL;
|
---|
| 4467 | }
|
---|
[ab1932] | 4468 | }
|
---|
| 4469 | }
|
---|
| 4470 |
|
---|
[71b20e] | 4471 | switch (NoOfWildcards) {
|
---|
| 4472 | case 0: // checks lines between the points in the Points for their adjacent triangles
|
---|
| 4473 | for (int i = 0; i < 3; i++) {
|
---|
| 4474 | if (TrianglePoints[i] != NULL) {
|
---|
[6613ec] | 4475 | for (int j = i + 1; j < 3; j++) {
|
---|
[71b20e] | 4476 | if (TrianglePoints[j] != NULL) {
|
---|
| 4477 | for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
|
---|
[6613ec] | 4478 | (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) {
|
---|
| 4479 | for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
|
---|
[71b20e] | 4480 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 4481 | result->push_back(FindTriangle->second);
|
---|
| 4482 | }
|
---|
| 4483 | }
|
---|
[ab1932] | 4484 | }
|
---|
[71b20e] | 4485 | // Is it sufficient to consider one of the triangle lines for this.
|
---|
| 4486 | return result;
|
---|
[ab1932] | 4487 | }
|
---|
| 4488 | }
|
---|
| 4489 | }
|
---|
| 4490 | }
|
---|
[71b20e] | 4491 | break;
|
---|
| 4492 | case 1: // copy all triangles of the respective line
|
---|
| 4493 | {
|
---|
[6613ec] | 4494 | int i = 0;
|
---|
[71b20e] | 4495 | for (; i < 3; i++)
|
---|
| 4496 | if (TrianglePoints[i] == NULL)
|
---|
| 4497 | break;
|
---|
[6613ec] | 4498 | for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap!
|
---|
| 4499 | (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) {
|
---|
| 4500 | for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
|
---|
[71b20e] | 4501 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 4502 | result->push_back(FindTriangle->second);
|
---|
| 4503 | }
|
---|
| 4504 | }
|
---|
| 4505 | }
|
---|
| 4506 | break;
|
---|
| 4507 | }
|
---|
| 4508 | case 2: // copy all triangles of the respective point
|
---|
| 4509 | {
|
---|
[6613ec] | 4510 | int i = 0;
|
---|
[71b20e] | 4511 | for (; i < 3; i++)
|
---|
| 4512 | if (TrianglePoints[i] != NULL)
|
---|
| 4513 | break;
|
---|
| 4514 | for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++)
|
---|
| 4515 | for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++)
|
---|
| 4516 | result->push_back(triangle->second);
|
---|
| 4517 | result->sort();
|
---|
| 4518 | result->unique();
|
---|
| 4519 | break;
|
---|
| 4520 | }
|
---|
| 4521 | case 3: // copy all triangles
|
---|
| 4522 | {
|
---|
| 4523 | for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++)
|
---|
| 4524 | result->push_back(triangle->second);
|
---|
| 4525 | break;
|
---|
[ab1932] | 4526 | }
|
---|
[71b20e] | 4527 | default:
|
---|
[6613ec] | 4528 | DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);
|
---|
[71b20e] | 4529 | performCriticalExit();
|
---|
| 4530 | break;
|
---|
[ab1932] | 4531 | }
|
---|
| 4532 |
|
---|
| 4533 | return result;
|
---|
| 4534 | }
|
---|
| 4535 |
|
---|
[6613ec] | 4536 | struct BoundaryLineSetCompare
|
---|
| 4537 | {
|
---|
| 4538 | bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b)
|
---|
| 4539 | {
|
---|
[856098] | 4540 | int lowerNra = -1;
|
---|
| 4541 | int lowerNrb = -1;
|
---|
| 4542 |
|
---|
| 4543 | if (a->endpoints[0] < a->endpoints[1])
|
---|
| 4544 | lowerNra = 0;
|
---|
| 4545 | else
|
---|
| 4546 | lowerNra = 1;
|
---|
| 4547 |
|
---|
| 4548 | if (b->endpoints[0] < b->endpoints[1])
|
---|
| 4549 | lowerNrb = 0;
|
---|
| 4550 | else
|
---|
| 4551 | lowerNrb = 1;
|
---|
| 4552 |
|
---|
| 4553 | if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
|
---|
| 4554 | return true;
|
---|
| 4555 | else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
|
---|
| 4556 | return false;
|
---|
[6613ec] | 4557 | else { // both lower-numbered endpoints are the same ...
|
---|
| 4558 | if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2])
|
---|
| 4559 | return true;
|
---|
| 4560 | else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2])
|
---|
| 4561 | return false;
|
---|
[856098] | 4562 | }
|
---|
| 4563 | return false;
|
---|
[6613ec] | 4564 | }
|
---|
| 4565 | ;
|
---|
[856098] | 4566 | };
|
---|
| 4567 |
|
---|
| 4568 | #define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
|
---|
| 4569 |
|
---|
[7c14ec] | 4570 | /**
|
---|
[57066a] | 4571 | * Finds all degenerated lines within the tesselation structure.
|
---|
[7c14ec] | 4572 | *
|
---|
[57066a] | 4573 | * @return map of keys of degenerated line pairs, each line occurs twice
|
---|
[7c14ec] | 4574 | * in the list, once as key and once as value
|
---|
| 4575 | */
|
---|
[c15ca2] | 4576 | IndexToIndex * Tesselation::FindAllDegeneratedLines()
|
---|
[7c14ec] | 4577 | {
|
---|
[6613ec] | 4578 | Info FunctionInfo(__func__);
|
---|
| 4579 | UniqueLines AllLines;
|
---|
[c15ca2] | 4580 | IndexToIndex * DegeneratedLines = new IndexToIndex;
|
---|
[7c14ec] | 4581 |
|
---|
| 4582 | // sanity check
|
---|
| 4583 | if (LinesOnBoundary.empty()) {
|
---|
[6613ec] | 4584 | DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");
|
---|
[57066a] | 4585 | return DegeneratedLines;
|
---|
[7c14ec] | 4586 | }
|
---|
[57066a] | 4587 | LineMap::iterator LineRunner1;
|
---|
[6613ec] | 4588 | pair<UniqueLines::iterator, bool> tester;
|
---|
[7c14ec] | 4589 | for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
|
---|
[6613ec] | 4590 | tester = AllLines.insert(LineRunner1->second);
|
---|
[856098] | 4591 | if (!tester.second) { // found degenerated line
|
---|
[6613ec] | 4592 | DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));
|
---|
| 4593 | DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));
|
---|
[57066a] | 4594 | }
|
---|
| 4595 | }
|
---|
| 4596 |
|
---|
| 4597 | AllLines.clear();
|
---|
| 4598 |
|
---|
[a67d19] | 4599 | DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl);
|
---|
[c15ca2] | 4600 | IndexToIndex::iterator it;
|
---|
[856098] | 4601 | for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
|
---|
| 4602 | const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
|
---|
| 4603 | const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
|
---|
| 4604 | if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
|
---|
[a67d19] | 4605 | DoLog(0) && (Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl);
|
---|
[856098] | 4606 | else
|
---|
[6613ec] | 4607 | DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);
|
---|
[856098] | 4608 | }
|
---|
[57066a] | 4609 |
|
---|
| 4610 | return DegeneratedLines;
|
---|
| 4611 | }
|
---|
| 4612 |
|
---|
| 4613 | /**
|
---|
| 4614 | * Finds all degenerated triangles within the tesselation structure.
|
---|
| 4615 | *
|
---|
| 4616 | * @return map of keys of degenerated triangle pairs, each triangle occurs twice
|
---|
| 4617 | * in the list, once as key and once as value
|
---|
| 4618 | */
|
---|
[c15ca2] | 4619 | IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
|
---|
[57066a] | 4620 | {
|
---|
[6613ec] | 4621 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4622 | IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
|
---|
| 4623 | IndexToIndex * DegeneratedTriangles = new IndexToIndex;
|
---|
[57066a] | 4624 | TriangleMap::iterator TriangleRunner1, TriangleRunner2;
|
---|
| 4625 | LineMap::iterator Liner;
|
---|
| 4626 | class BoundaryLineSet *line1 = NULL, *line2 = NULL;
|
---|
| 4627 |
|
---|
[c15ca2] | 4628 | for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
|
---|
[57066a] | 4629 | // run over both lines' triangles
|
---|
| 4630 | Liner = LinesOnBoundary.find(LineRunner->first);
|
---|
| 4631 | if (Liner != LinesOnBoundary.end())
|
---|
| 4632 | line1 = Liner->second;
|
---|
| 4633 | Liner = LinesOnBoundary.find(LineRunner->second);
|
---|
| 4634 | if (Liner != LinesOnBoundary.end())
|
---|
| 4635 | line2 = Liner->second;
|
---|
| 4636 | for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
|
---|
| 4637 | for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
|
---|
[6613ec] | 4638 | if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
|
---|
| 4639 | DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr));
|
---|
| 4640 | DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr));
|
---|
[7c14ec] | 4641 | }
|
---|
| 4642 | }
|
---|
| 4643 | }
|
---|
| 4644 | }
|
---|
[6613ec] | 4645 | delete (DegeneratedLines);
|
---|
[7c14ec] | 4646 |
|
---|
[a67d19] | 4647 | DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl);
|
---|
[b32dbb] | 4648 | for (IndexToIndex::iterator it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
|
---|
[a67d19] | 4649 | DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
|
---|
[7c14ec] | 4650 |
|
---|
| 4651 | return DegeneratedTriangles;
|
---|
| 4652 | }
|
---|
| 4653 |
|
---|
| 4654 | /**
|
---|
| 4655 | * Purges degenerated triangles from the tesselation structure if they are not
|
---|
| 4656 | * necessary to keep a single point within the structure.
|
---|
| 4657 | */
|
---|
| 4658 | void Tesselation::RemoveDegeneratedTriangles()
|
---|
| 4659 | {
|
---|
[6613ec] | 4660 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4661 | IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[57066a] | 4662 | TriangleMap::iterator finder;
|
---|
| 4663 | BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
|
---|
[6613ec] | 4664 | int count = 0;
|
---|
[7c14ec] | 4665 |
|
---|
[b32dbb] | 4666 | // iterate over all degenerated triangles
|
---|
| 4667 | for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); !DegeneratedTriangles->empty(); TriangleKeyRunner = DegeneratedTriangles->begin()) {
|
---|
| 4668 | DoLog(0) && (Log() << Verbose(0) << "Checking presence of triangles " << TriangleKeyRunner->first << " and " << TriangleKeyRunner->second << "." << endl);
|
---|
| 4669 | // both ways are stored in the map, only use one
|
---|
| 4670 | if (TriangleKeyRunner->first > TriangleKeyRunner->second)
|
---|
| 4671 | continue;
|
---|
| 4672 |
|
---|
| 4673 | // determine from the keys in the map the two _present_ triangles
|
---|
[57066a] | 4674 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
|
---|
| 4675 | if (finder != TrianglesOnBoundary.end())
|
---|
| 4676 | triangle = finder->second;
|
---|
| 4677 | else
|
---|
[b32dbb] | 4678 | continue;
|
---|
[57066a] | 4679 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->second);
|
---|
| 4680 | if (finder != TrianglesOnBoundary.end())
|
---|
| 4681 | partnerTriangle = finder->second;
|
---|
| 4682 | else
|
---|
[b32dbb] | 4683 | continue;
|
---|
[7c14ec] | 4684 |
|
---|
[b32dbb] | 4685 | // determine which lines are shared by the two triangles
|
---|
[7c14ec] | 4686 | bool trianglesShareLine = false;
|
---|
| 4687 | for (int i = 0; i < 3; ++i)
|
---|
| 4688 | for (int j = 0; j < 3; ++j)
|
---|
| 4689 | trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
|
---|
| 4690 |
|
---|
[6613ec] | 4691 | if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) {
|
---|
[57066a] | 4692 | // check whether we have to fix lines
|
---|
| 4693 | BoundaryTriangleSet *Othertriangle = NULL;
|
---|
| 4694 | BoundaryTriangleSet *OtherpartnerTriangle = NULL;
|
---|
| 4695 | TriangleMap::iterator TriangleRunner;
|
---|
| 4696 | for (int i = 0; i < 3; ++i)
|
---|
| 4697 | for (int j = 0; j < 3; ++j)
|
---|
| 4698 | if (triangle->lines[i] != partnerTriangle->lines[j]) {
|
---|
| 4699 | // get the other two triangles
|
---|
| 4700 | for (TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 4701 | if (TriangleRunner->second != triangle) {
|
---|
| 4702 | Othertriangle = TriangleRunner->second;
|
---|
| 4703 | }
|
---|
| 4704 | for (TriangleRunner = partnerTriangle->lines[i]->triangles.begin(); TriangleRunner != partnerTriangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 4705 | if (TriangleRunner->second != partnerTriangle) {
|
---|
| 4706 | OtherpartnerTriangle = TriangleRunner->second;
|
---|
| 4707 | }
|
---|
| 4708 | /// interchanges their lines so that triangle->lines[i] == partnerTriangle->lines[j]
|
---|
| 4709 | // the line of triangle receives the degenerated ones
|
---|
| 4710 | triangle->lines[i]->triangles.erase(Othertriangle->Nr);
|
---|
[6613ec] | 4711 | triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle));
|
---|
| 4712 | for (int k = 0; k < 3; k++)
|
---|
[57066a] | 4713 | if (triangle->lines[i] == Othertriangle->lines[k]) {
|
---|
| 4714 | Othertriangle->lines[k] = partnerTriangle->lines[j];
|
---|
| 4715 | break;
|
---|
| 4716 | }
|
---|
| 4717 | // the line of partnerTriangle receives the non-degenerated ones
|
---|
[6613ec] | 4718 | partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr);
|
---|
| 4719 | partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle));
|
---|
[57066a] | 4720 | partnerTriangle->lines[j] = triangle->lines[i];
|
---|
| 4721 | }
|
---|
| 4722 |
|
---|
| 4723 | // erase the pair
|
---|
| 4724 | count += (int) DegeneratedTriangles->erase(triangle->Nr);
|
---|
[a67d19] | 4725 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl);
|
---|
[7c14ec] | 4726 | RemoveTesselationTriangle(triangle);
|
---|
[57066a] | 4727 | count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
|
---|
[a67d19] | 4728 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl);
|
---|
[7c14ec] | 4729 | RemoveTesselationTriangle(partnerTriangle);
|
---|
| 4730 | } else {
|
---|
[a67d19] | 4731 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle << " and its partner " << *partnerTriangle << " because it is essential for at" << " least one of the endpoints to be kept in the tesselation structure." << endl);
|
---|
[7c14ec] | 4732 | }
|
---|
| 4733 | }
|
---|
[6613ec] | 4734 | delete (DegeneratedTriangles);
|
---|
[6a7f78c] | 4735 | if (count > 0)
|
---|
| 4736 | LastTriangle = NULL;
|
---|
[57066a] | 4737 |
|
---|
[a67d19] | 4738 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl);
|
---|
[7c14ec] | 4739 | }
|
---|
| 4740 |
|
---|
[57066a] | 4741 | /** Adds an outside Tesselpoint to the envelope via (two) degenerated triangles.
|
---|
| 4742 | * We look for the closest point on the boundary, we look through its connected boundary lines and
|
---|
| 4743 | * seek the one with the minimum angle between its center point and the new point and this base line.
|
---|
| 4744 | * We open up the line by adding a degenerated triangle, whose other side closes the base line again.
|
---|
| 4745 | * \param *out output stream for debugging
|
---|
| 4746 | * \param *point point to add
|
---|
| 4747 | * \param *LC Linked Cell structure to find nearest point
|
---|
[ab1932] | 4748 | */
|
---|
[e138de] | 4749 | void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
|
---|
[ab1932] | 4750 | {
|
---|
[6613ec] | 4751 | Info FunctionInfo(__func__);
|
---|
[57066a] | 4752 | // find nearest boundary point
|
---|
| 4753 | class TesselPoint *BackupPoint = NULL;
|
---|
[71b20e] | 4754 | class TesselPoint *NearestPoint = FindClosestTesselPoint(point->node, BackupPoint, LC);
|
---|
[57066a] | 4755 | class BoundaryPointSet *NearestBoundaryPoint = NULL;
|
---|
| 4756 | PointMap::iterator PointRunner;
|
---|
| 4757 |
|
---|
| 4758 | if (NearestPoint == point)
|
---|
| 4759 | NearestPoint = BackupPoint;
|
---|
| 4760 | PointRunner = PointsOnBoundary.find(NearestPoint->nr);
|
---|
| 4761 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 4762 | NearestBoundaryPoint = PointRunner->second;
|
---|
| 4763 | } else {
|
---|
[6613ec] | 4764 | DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl);
|
---|
[57066a] | 4765 | return;
|
---|
| 4766 | }
|
---|
[68f03d] | 4767 | DoLog(0) && (Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->getName() << "." << endl);
|
---|
[57066a] | 4768 |
|
---|
| 4769 | // go through its lines and find the best one to split
|
---|
| 4770 | Vector CenterToPoint;
|
---|
| 4771 | Vector BaseLine;
|
---|
| 4772 | double angle, BestAngle = 0.;
|
---|
| 4773 | class BoundaryLineSet *BestLine = NULL;
|
---|
| 4774 | for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
|
---|
[273382] | 4775 | BaseLine = (*Runner->second->endpoints[0]->node->node) -
|
---|
| 4776 | (*Runner->second->endpoints[1]->node->node);
|
---|
| 4777 | CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) +
|
---|
| 4778 | (*Runner->second->endpoints[1]->node->node));
|
---|
| 4779 | CenterToPoint -= (*point->node);
|
---|
| 4780 | angle = CenterToPoint.Angle(BaseLine);
|
---|
[57066a] | 4781 | if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
|
---|
| 4782 | BestAngle = angle;
|
---|
| 4783 | BestLine = Runner->second;
|
---|
| 4784 | }
|
---|
[ab1932] | 4785 | }
|
---|
| 4786 |
|
---|
[57066a] | 4787 | // remove one triangle from the chosen line
|
---|
| 4788 | class BoundaryTriangleSet *TempTriangle = (BestLine->triangles.begin())->second;
|
---|
| 4789 | BestLine->triangles.erase(TempTriangle->Nr);
|
---|
| 4790 | int nr = -1;
|
---|
[6613ec] | 4791 | for (int i = 0; i < 3; i++) {
|
---|
[57066a] | 4792 | if (TempTriangle->lines[i] == BestLine) {
|
---|
| 4793 | nr = i;
|
---|
| 4794 | break;
|
---|
| 4795 | }
|
---|
| 4796 | }
|
---|
[ab1932] | 4797 |
|
---|
[57066a] | 4798 | // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
|
---|
[a67d19] | 4799 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4800 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 4801 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 4802 | AddTesselationPoint(point, 2);
|
---|
[a67d19] | 4803 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4804 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4805 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 4806 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[57066a] | 4807 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 4808 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
| 4809 | BTS->NormalVector.Scale(-1.);
|
---|
[a67d19] | 4810 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl);
|
---|
[57066a] | 4811 | AddTesselationTriangle();
|
---|
| 4812 |
|
---|
| 4813 | // create other side of this triangle and close both new sides of the first created triangle
|
---|
[a67d19] | 4814 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4815 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 4816 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 4817 | AddTesselationPoint(point, 2);
|
---|
[a67d19] | 4818 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4819 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4820 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 4821 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[57066a] | 4822 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 4823 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
[a67d19] | 4824 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl);
|
---|
[57066a] | 4825 | AddTesselationTriangle();
|
---|
| 4826 |
|
---|
| 4827 | // add removed triangle to the last open line of the second triangle
|
---|
[6613ec] | 4828 | for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion)
|
---|
[57066a] | 4829 | if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
|
---|
[6613ec] | 4830 | if (BestLine == BTS->lines[i]) {
|
---|
| 4831 | DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl);
|
---|
[f67b6e] | 4832 | performCriticalExit();
|
---|
[57066a] | 4833 | }
|
---|
[6613ec] | 4834 | BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));
|
---|
[57066a] | 4835 | TempTriangle->lines[nr] = BTS->lines[i];
|
---|
| 4836 | break;
|
---|
| 4837 | }
|
---|
| 4838 | }
|
---|
[6613ec] | 4839 | }
|
---|
| 4840 | ;
|
---|
[57066a] | 4841 |
|
---|
| 4842 | /** Writes the envelope to file.
|
---|
| 4843 | * \param *out otuput stream for debugging
|
---|
| 4844 | * \param *filename basename of output file
|
---|
| 4845 | * \param *cloud PointCloud structure with all nodes
|
---|
| 4846 | */
|
---|
[e138de] | 4847 | void Tesselation::Output(const char *filename, const PointCloud * const cloud)
|
---|
[57066a] | 4848 | {
|
---|
[6613ec] | 4849 | Info FunctionInfo(__func__);
|
---|
[57066a] | 4850 | ofstream *tempstream = NULL;
|
---|
| 4851 | string NameofTempFile;
|
---|
[68f03d] | 4852 | string NumberName;
|
---|
[57066a] | 4853 |
|
---|
| 4854 | if (LastTriangle != NULL) {
|
---|
[68f03d] | 4855 | stringstream sstr;
|
---|
[8f215d] | 4856 | sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle->getEndpointName(0) << "_" << LastTriangle->getEndpointName(1) << "_" << LastTriangle->getEndpointName(2);
|
---|
[68f03d] | 4857 | NumberName = sstr.str();
|
---|
[57066a] | 4858 | if (DoTecplotOutput) {
|
---|
| 4859 | string NameofTempFile(filename);
|
---|
| 4860 | NameofTempFile.append(NumberName);
|
---|
[6613ec] | 4861 | for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 4862 | NameofTempFile.erase(npos, 1);
|
---|
[57066a] | 4863 | NameofTempFile.append(TecplotSuffix);
|
---|
[a67d19] | 4864 | DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
|
---|
[57066a] | 4865 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 4866 | WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
|
---|
[57066a] | 4867 | tempstream->close();
|
---|
| 4868 | tempstream->flush();
|
---|
[6613ec] | 4869 | delete (tempstream);
|
---|
[57066a] | 4870 | }
|
---|
| 4871 |
|
---|
| 4872 | if (DoRaster3DOutput) {
|
---|
| 4873 | string NameofTempFile(filename);
|
---|
| 4874 | NameofTempFile.append(NumberName);
|
---|
[6613ec] | 4875 | for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 4876 | NameofTempFile.erase(npos, 1);
|
---|
[57066a] | 4877 | NameofTempFile.append(Raster3DSuffix);
|
---|
[a67d19] | 4878 | DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
|
---|
[57066a] | 4879 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 4880 | WriteRaster3dFile(tempstream, this, cloud);
|
---|
| 4881 | IncludeSphereinRaster3D(tempstream, this, cloud);
|
---|
[57066a] | 4882 | tempstream->close();
|
---|
| 4883 | tempstream->flush();
|
---|
[6613ec] | 4884 | delete (tempstream);
|
---|
[57066a] | 4885 | }
|
---|
| 4886 | }
|
---|
| 4887 | if (DoTecplotOutput || DoRaster3DOutput)
|
---|
| 4888 | TriangleFilesWritten++;
|
---|
[6613ec] | 4889 | }
|
---|
| 4890 | ;
|
---|
[262bae] | 4891 |
|
---|
[6613ec] | 4892 | struct BoundaryPolygonSetCompare
|
---|
| 4893 | {
|
---|
| 4894 | bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const
|
---|
| 4895 | {
|
---|
[856098] | 4896 | if (s1->endpoints.size() < s2->endpoints.size())
|
---|
| 4897 | return true;
|
---|
| 4898 | else if (s1->endpoints.size() > s2->endpoints.size())
|
---|
| 4899 | return false;
|
---|
| 4900 | else { // equality of number of endpoints
|
---|
| 4901 | PointSet::const_iterator Walker1 = s1->endpoints.begin();
|
---|
| 4902 | PointSet::const_iterator Walker2 = s2->endpoints.begin();
|
---|
| 4903 | while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
|
---|
| 4904 | if ((*Walker1)->Nr < (*Walker2)->Nr)
|
---|
| 4905 | return true;
|
---|
| 4906 | else if ((*Walker1)->Nr > (*Walker2)->Nr)
|
---|
| 4907 | return false;
|
---|
| 4908 | Walker1++;
|
---|
| 4909 | Walker2++;
|
---|
| 4910 | }
|
---|
| 4911 | return false;
|
---|
| 4912 | }
|
---|
| 4913 | }
|
---|
| 4914 | };
|
---|
| 4915 |
|
---|
| 4916 | #define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
|
---|
| 4917 |
|
---|
[262bae] | 4918 | /** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
|
---|
| 4919 | * \return number of polygons found
|
---|
| 4920 | */
|
---|
| 4921 | int Tesselation::CorrectAllDegeneratedPolygons()
|
---|
| 4922 | {
|
---|
| 4923 | Info FunctionInfo(__func__);
|
---|
[fad93c] | 4924 | /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
|
---|
[c15ca2] | 4925 | IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[6613ec] | 4926 | set<BoundaryPointSet *> EndpointCandidateList;
|
---|
| 4927 | pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester;
|
---|
| 4928 | pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester;
|
---|
[fad93c] | 4929 | for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
|
---|
[a67d19] | 4930 | DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl);
|
---|
[6613ec] | 4931 | map<int, Vector *> TriangleVectors;
|
---|
[fad93c] | 4932 | // gather all NormalVectors
|
---|
[a67d19] | 4933 | DoLog(1) && (Log() << Verbose(1) << "Gathering triangles ..." << endl);
|
---|
[fad93c] | 4934 | for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
|
---|
| 4935 | for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
[b998c3] | 4936 | if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
|
---|
[6613ec] | 4937 | TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));
|
---|
[b998c3] | 4938 | if (TriangleInsertionTester.second)
|
---|
[a67d19] | 4939 | DoLog(1) && (Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl);
|
---|
[b998c3] | 4940 | } else {
|
---|
[a67d19] | 4941 | DoLog(1) && (Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl);
|
---|
[b998c3] | 4942 | }
|
---|
[fad93c] | 4943 | }
|
---|
| 4944 | // check whether there are two that are parallel
|
---|
[a67d19] | 4945 | DoLog(1) && (Log() << Verbose(1) << "Finding two parallel triangles ..." << endl);
|
---|
[6613ec] | 4946 | for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
|
---|
| 4947 | for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
|
---|
[fad93c] | 4948 | if (VectorWalker != VectorRunner) { // skip equals
|
---|
[8cbb97] | 4949 | const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
|
---|
[a67d19] | 4950 | DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl);
|
---|
[fad93c] | 4951 | if (fabs(SCP + 1.) < ParallelEpsilon) {
|
---|
| 4952 | InsertionTester = EndpointCandidateList.insert((Runner->second));
|
---|
| 4953 | if (InsertionTester.second)
|
---|
[a67d19] | 4954 | DoLog(0) && (Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl);
|
---|
[fad93c] | 4955 | // and break out of both loops
|
---|
| 4956 | VectorWalker = TriangleVectors.end();
|
---|
| 4957 | VectorRunner = TriangleVectors.end();
|
---|
| 4958 | break;
|
---|
| 4959 | }
|
---|
| 4960 | }
|
---|
| 4961 | }
|
---|
[9d4c20] | 4962 | delete DegeneratedTriangles;
|
---|
[856098] | 4963 |
|
---|
[fad93c] | 4964 | /// 3. Find connected endpoint candidates and put them into a polygon
|
---|
| 4965 | UniquePolygonSet ListofDegeneratedPolygons;
|
---|
| 4966 | BoundaryPointSet *Walker = NULL;
|
---|
| 4967 | BoundaryPointSet *OtherWalker = NULL;
|
---|
| 4968 | BoundaryPolygonSet *Current = NULL;
|
---|
[6613ec] | 4969 | stack<BoundaryPointSet*> ToCheckConnecteds;
|
---|
[fad93c] | 4970 | while (!EndpointCandidateList.empty()) {
|
---|
| 4971 | Walker = *(EndpointCandidateList.begin());
|
---|
[6613ec] | 4972 | if (Current == NULL) { // create a new polygon with current candidate
|
---|
[a67d19] | 4973 | DoLog(0) && (Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl);
|
---|
[fad93c] | 4974 | Current = new BoundaryPolygonSet;
|
---|
| 4975 | Current->endpoints.insert(Walker);
|
---|
| 4976 | EndpointCandidateList.erase(Walker);
|
---|
| 4977 | ToCheckConnecteds.push(Walker);
|
---|
[856098] | 4978 | }
|
---|
[262bae] | 4979 |
|
---|
[fad93c] | 4980 | // go through to-check stack
|
---|
| 4981 | while (!ToCheckConnecteds.empty()) {
|
---|
| 4982 | Walker = ToCheckConnecteds.top(); // fetch ...
|
---|
| 4983 | ToCheckConnecteds.pop(); // ... and remove
|
---|
| 4984 | for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
|
---|
| 4985 | OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
|
---|
[a67d19] | 4986 | DoLog(1) && (Log() << Verbose(1) << "Checking " << *OtherWalker << endl);
|
---|
[6613ec] | 4987 | set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
|
---|
| 4988 | if (Finder != EndpointCandidateList.end()) { // found a connected partner
|
---|
[a67d19] | 4989 | DoLog(1) && (Log() << Verbose(1) << " Adding to polygon." << endl);
|
---|
[fad93c] | 4990 | Current->endpoints.insert(OtherWalker);
|
---|
[6613ec] | 4991 | EndpointCandidateList.erase(Finder); // remove from candidates
|
---|
| 4992 | ToCheckConnecteds.push(OtherWalker); // but check its partners too
|
---|
[856098] | 4993 | } else {
|
---|
[a67d19] | 4994 | DoLog(1) && (Log() << Verbose(1) << " is not connected to " << *Walker << endl);
|
---|
[856098] | 4995 | }
|
---|
| 4996 | }
|
---|
| 4997 | }
|
---|
[262bae] | 4998 |
|
---|
[a67d19] | 4999 | DoLog(0) && (Log() << Verbose(0) << "Final polygon is " << *Current << endl);
|
---|
[fad93c] | 5000 | ListofDegeneratedPolygons.insert(Current);
|
---|
| 5001 | Current = NULL;
|
---|
[262bae] | 5002 | }
|
---|
| 5003 |
|
---|
[fad93c] | 5004 | const int counter = ListofDegeneratedPolygons.size();
|
---|
[262bae] | 5005 |
|
---|
[a67d19] | 5006 | DoLog(0) && (Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl);
|
---|
[fad93c] | 5007 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
|
---|
[a67d19] | 5008 | DoLog(0) && (Log() << Verbose(0) << " " << **PolygonRunner << endl);
|
---|
[856098] | 5009 |
|
---|
[262bae] | 5010 | /// 4. Go through all these degenerated polygons
|
---|
[fad93c] | 5011 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
|
---|
[6613ec] | 5012 | stack<int> TriangleNrs;
|
---|
[856098] | 5013 | Vector NormalVector;
|
---|
[262bae] | 5014 | /// 4a. Gather all triangles of this polygon
|
---|
[856098] | 5015 | TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
|
---|
[262bae] | 5016 |
|
---|
[125b3c] | 5017 | // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do.
|
---|
[b998c3] | 5018 | if (T->size() == 2) {
|
---|
[a67d19] | 5019 | DoLog(1) && (Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl);
|
---|
[6613ec] | 5020 | delete (T);
|
---|
[b998c3] | 5021 | continue;
|
---|
| 5022 | }
|
---|
| 5023 |
|
---|
[125b3c] | 5024 | // check whether number is even
|
---|
| 5025 | // If this case occurs, we have to think about it!
|
---|
| 5026 | // The Problem is probably due to two degenerated polygons being connected by a bridging, non-degenerated polygon, as somehow one node has
|
---|
| 5027 | // connections to either polygon ...
|
---|
| 5028 | if (T->size() % 2 != 0) {
|
---|
[6613ec] | 5029 | DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);
|
---|
[125b3c] | 5030 | performCriticalExit();
|
---|
| 5031 | }
|
---|
[6613ec] | 5032 | TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
|
---|
[262bae] | 5033 | /// 4a. Get NormalVector for one side (this is "front")
|
---|
[273382] | 5034 | NormalVector = (*TriangleWalker)->NormalVector;
|
---|
[a67d19] | 5035 | DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl);
|
---|
[856098] | 5036 | TriangleWalker++;
|
---|
| 5037 | TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
|
---|
[262bae] | 5038 | /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back")
|
---|
[856098] | 5039 | BoundaryTriangleSet *triangle = NULL;
|
---|
| 5040 | while (TriangleSprinter != T->end()) {
|
---|
| 5041 | TriangleWalker = TriangleSprinter;
|
---|
| 5042 | triangle = *TriangleWalker;
|
---|
| 5043 | TriangleSprinter++;
|
---|
[a67d19] | 5044 | DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl);
|
---|
[273382] | 5045 | if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list
|
---|
[a67d19] | 5046 | DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl);
|
---|
[856098] | 5047 | TriangleNrs.push(triangle->Nr);
|
---|
[262bae] | 5048 | T->erase(TriangleWalker);
|
---|
[856098] | 5049 | RemoveTesselationTriangle(triangle);
|
---|
| 5050 | } else
|
---|
[a67d19] | 5051 | DoLog(1) && (Log() << Verbose(1) << " Keeping ... " << endl);
|
---|
[262bae] | 5052 | }
|
---|
| 5053 | /// 4c. Copy all "front" triangles but with inverse NormalVector
|
---|
| 5054 | TriangleWalker = T->begin();
|
---|
[6613ec] | 5055 | while (TriangleWalker != T->end()) { // go through all front triangles
|
---|
[a67d19] | 5056 | DoLog(1) && (Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl);
|
---|
[856098] | 5057 | for (int i = 0; i < 3; i++)
|
---|
| 5058 | AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
|
---|
[f07f86d] | 5059 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 5060 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 5061 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[fad93c] | 5062 | if (TriangleNrs.empty())
|
---|
[6613ec] | 5063 | DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl);
|
---|
[856098] | 5064 | BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
|
---|
| 5065 | AddTesselationTriangle(); // ... and add
|
---|
| 5066 | TriangleNrs.pop();
|
---|
[273382] | 5067 | BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector;
|
---|
[262bae] | 5068 | TriangleWalker++;
|
---|
| 5069 | }
|
---|
[856098] | 5070 | if (!TriangleNrs.empty()) {
|
---|
[6613ec] | 5071 | DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl);
|
---|
[856098] | 5072 | }
|
---|
[6613ec] | 5073 | delete (T); // remove the triangleset
|
---|
[262bae] | 5074 | }
|
---|
[c15ca2] | 5075 | IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[a67d19] | 5076 | DoLog(0) && (Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl);
|
---|
[c15ca2] | 5077 | IndexToIndex::iterator it;
|
---|
[856098] | 5078 | for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
|
---|
[a67d19] | 5079 | DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
|
---|
[6613ec] | 5080 | delete (SimplyDegeneratedTriangles);
|
---|
[262bae] | 5081 | /// 5. exit
|
---|
[856098] | 5082 | UniquePolygonSet::iterator PolygonRunner;
|
---|
[fad93c] | 5083 | while (!ListofDegeneratedPolygons.empty()) {
|
---|
| 5084 | PolygonRunner = ListofDegeneratedPolygons.begin();
|
---|
[6613ec] | 5085 | delete (*PolygonRunner);
|
---|
[fad93c] | 5086 | ListofDegeneratedPolygons.erase(PolygonRunner);
|
---|
[262bae] | 5087 | }
|
---|
| 5088 |
|
---|
| 5089 | return counter;
|
---|
[6613ec] | 5090 | }
|
---|
| 5091 | ;
|
---|