[357fba] | 1 | /*
|
---|
| 2 | * tesselation.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 3, 2009
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[f66195] | 8 | #include <fstream>
|
---|
[f04f11] | 9 | #include <assert.h>
|
---|
[f66195] | 10 |
|
---|
[a2028e] | 11 | #include "helpers.hpp"
|
---|
[f67b6e] | 12 | #include "info.hpp"
|
---|
[57066a] | 13 | #include "linkedcell.hpp"
|
---|
[e138de] | 14 | #include "log.hpp"
|
---|
[357fba] | 15 | #include "tesselation.hpp"
|
---|
[57066a] | 16 | #include "tesselationhelpers.hpp"
|
---|
[8db598] | 17 | #include "triangleintersectionlist.hpp"
|
---|
[57066a] | 18 | #include "vector.hpp"
|
---|
[0a4f7f] | 19 | #include "vector_ops.hpp"
|
---|
[f66195] | 20 | #include "verbose.hpp"
|
---|
[0a4f7f] | 21 | #include "Plane.hpp"
|
---|
| 22 | #include "Exceptions/LinearDependenceException.hpp"
|
---|
[57066a] | 23 |
|
---|
| 24 | class molecule;
|
---|
[357fba] | 25 |
|
---|
| 26 | // ======================================== Points on Boundary =================================
|
---|
| 27 |
|
---|
[16d866] | 28 | /** Constructor of BoundaryPointSet.
|
---|
| 29 | */
|
---|
[1e168b] | 30 | BoundaryPointSet::BoundaryPointSet() :
|
---|
[6613ec] | 31 | LinesCount(0), value(0.), Nr(-1)
|
---|
[357fba] | 32 | {
|
---|
[6613ec] | 33 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 34 | DoLog(1) && (Log() << Verbose(1) << "Adding noname." << endl);
|
---|
[6613ec] | 35 | }
|
---|
| 36 | ;
|
---|
[357fba] | 37 |
|
---|
[16d866] | 38 | /** Constructor of BoundaryPointSet with Tesselpoint.
|
---|
| 39 | * \param *Walker TesselPoint this boundary point represents
|
---|
| 40 | */
|
---|
[9473f6] | 41 | BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) :
|
---|
[6613ec] | 42 | LinesCount(0), node(Walker), value(0.), Nr(Walker->nr)
|
---|
[357fba] | 43 | {
|
---|
[6613ec] | 44 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 45 | DoLog(1) && (Log() << Verbose(1) << "Adding Node " << *Walker << endl);
|
---|
[6613ec] | 46 | }
|
---|
| 47 | ;
|
---|
[357fba] | 48 |
|
---|
[16d866] | 49 | /** Destructor of BoundaryPointSet.
|
---|
| 50 | * Sets node to NULL to avoid removing the original, represented TesselPoint.
|
---|
| 51 | * \note When removing point from a class Tesselation, use RemoveTesselationPoint()
|
---|
| 52 | */
|
---|
[357fba] | 53 | BoundaryPointSet::~BoundaryPointSet()
|
---|
| 54 | {
|
---|
[6613ec] | 55 | Info FunctionInfo(__func__);
|
---|
[f67b6e] | 56 | //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
|
---|
[357fba] | 57 | if (!lines.empty())
|
---|
[6613ec] | 58 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);
|
---|
[357fba] | 59 | node = NULL;
|
---|
[6613ec] | 60 | }
|
---|
| 61 | ;
|
---|
[357fba] | 62 |
|
---|
[16d866] | 63 | /** Add a line to the LineMap of this point.
|
---|
| 64 | * \param *line line to add
|
---|
| 65 | */
|
---|
[9473f6] | 66 | void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
|
---|
[357fba] | 67 | {
|
---|
[6613ec] | 68 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 69 | DoLog(1) && (Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl);
|
---|
[6613ec] | 70 | if (line->endpoints[0] == this) {
|
---|
| 71 | lines.insert(LinePair(line->endpoints[1]->Nr, line));
|
---|
| 72 | } else {
|
---|
| 73 | lines.insert(LinePair(line->endpoints[0]->Nr, line));
|
---|
| 74 | }
|
---|
[357fba] | 75 | LinesCount++;
|
---|
[6613ec] | 76 | }
|
---|
| 77 | ;
|
---|
[357fba] | 78 |
|
---|
[16d866] | 79 | /** output operator for BoundaryPointSet.
|
---|
| 80 | * \param &ost output stream
|
---|
| 81 | * \param &a boundary point
|
---|
| 82 | */
|
---|
[776b64] | 83 | ostream & operator <<(ostream &ost, const BoundaryPointSet &a)
|
---|
[357fba] | 84 | {
|
---|
[57066a] | 85 | ost << "[" << a.Nr << "|" << a.node->Name << " at " << *a.node->node << "]";
|
---|
[357fba] | 86 | return ost;
|
---|
| 87 | }
|
---|
| 88 | ;
|
---|
| 89 |
|
---|
| 90 | // ======================================== Lines on Boundary =================================
|
---|
| 91 |
|
---|
[16d866] | 92 | /** Constructor of BoundaryLineSet.
|
---|
| 93 | */
|
---|
[1e168b] | 94 | BoundaryLineSet::BoundaryLineSet() :
|
---|
[6613ec] | 95 | Nr(-1)
|
---|
[357fba] | 96 | {
|
---|
[6613ec] | 97 | Info FunctionInfo(__func__);
|
---|
[357fba] | 98 | for (int i = 0; i < 2; i++)
|
---|
| 99 | endpoints[i] = NULL;
|
---|
[6613ec] | 100 | }
|
---|
| 101 | ;
|
---|
[357fba] | 102 |
|
---|
[16d866] | 103 | /** Constructor of BoundaryLineSet with two endpoints.
|
---|
| 104 | * Adds line automatically to each endpoints' LineMap
|
---|
| 105 | * \param *Point[2] array of two boundary points
|
---|
| 106 | * \param number number of the list
|
---|
| 107 | */
|
---|
[9473f6] | 108 | BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
|
---|
[357fba] | 109 | {
|
---|
[6613ec] | 110 | Info FunctionInfo(__func__);
|
---|
[357fba] | 111 | // set number
|
---|
| 112 | Nr = number;
|
---|
| 113 | // set endpoints in ascending order
|
---|
| 114 | SetEndpointsOrdered(endpoints, Point[0], Point[1]);
|
---|
| 115 | // add this line to the hash maps of both endpoints
|
---|
| 116 | Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
|
---|
| 117 | Point[1]->AddLine(this); //
|
---|
[1e168b] | 118 | // set skipped to false
|
---|
| 119 | skipped = false;
|
---|
[357fba] | 120 | // clear triangles list
|
---|
[a67d19] | 121 | DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
|
---|
[6613ec] | 122 | }
|
---|
| 123 | ;
|
---|
[357fba] | 124 |
|
---|
[9473f6] | 125 | /** Constructor of BoundaryLineSet with two endpoints.
|
---|
| 126 | * Adds line automatically to each endpoints' LineMap
|
---|
| 127 | * \param *Point1 first boundary point
|
---|
| 128 | * \param *Point2 second boundary point
|
---|
| 129 | * \param number number of the list
|
---|
| 130 | */
|
---|
| 131 | BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number)
|
---|
| 132 | {
|
---|
| 133 | Info FunctionInfo(__func__);
|
---|
| 134 | // set number
|
---|
| 135 | Nr = number;
|
---|
| 136 | // set endpoints in ascending order
|
---|
| 137 | SetEndpointsOrdered(endpoints, Point1, Point2);
|
---|
| 138 | // add this line to the hash maps of both endpoints
|
---|
| 139 | Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
|
---|
| 140 | Point2->AddLine(this); //
|
---|
| 141 | // set skipped to false
|
---|
| 142 | skipped = false;
|
---|
| 143 | // clear triangles list
|
---|
[a67d19] | 144 | DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
|
---|
[6613ec] | 145 | }
|
---|
| 146 | ;
|
---|
[9473f6] | 147 |
|
---|
[16d866] | 148 | /** Destructor for BoundaryLineSet.
|
---|
| 149 | * Removes itself from each endpoints' LineMap, calling RemoveTrianglePoint() when point not connected anymore.
|
---|
| 150 | * \note When removing lines from a class Tesselation, use RemoveTesselationLine()
|
---|
| 151 | */
|
---|
[357fba] | 152 | BoundaryLineSet::~BoundaryLineSet()
|
---|
| 153 | {
|
---|
[6613ec] | 154 | Info FunctionInfo(__func__);
|
---|
[357fba] | 155 | int Numbers[2];
|
---|
[16d866] | 156 |
|
---|
| 157 | // get other endpoint number of finding copies of same line
|
---|
| 158 | if (endpoints[1] != NULL)
|
---|
| 159 | Numbers[0] = endpoints[1]->Nr;
|
---|
| 160 | else
|
---|
| 161 | Numbers[0] = -1;
|
---|
| 162 | if (endpoints[0] != NULL)
|
---|
| 163 | Numbers[1] = endpoints[0]->Nr;
|
---|
| 164 | else
|
---|
| 165 | Numbers[1] = -1;
|
---|
| 166 |
|
---|
[357fba] | 167 | for (int i = 0; i < 2; i++) {
|
---|
[16d866] | 168 | if (endpoints[i] != NULL) {
|
---|
| 169 | 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
|
---|
| 170 | pair<LineMap::iterator, LineMap::iterator> erasor = endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 171 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 172 | if ((*Runner).second == this) {
|
---|
[f67b6e] | 173 | //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[16d866] | 174 | endpoints[i]->lines.erase(Runner);
|
---|
| 175 | break;
|
---|
| 176 | }
|
---|
| 177 | } else { // there's just a single line left
|
---|
[57066a] | 178 | if (endpoints[i]->lines.erase(Nr)) {
|
---|
[f67b6e] | 179 | //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[57066a] | 180 | }
|
---|
[357fba] | 181 | }
|
---|
[16d866] | 182 | if (endpoints[i]->lines.empty()) {
|
---|
[f67b6e] | 183 | //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
|
---|
[16d866] | 184 | if (endpoints[i] != NULL) {
|
---|
[6613ec] | 185 | delete (endpoints[i]);
|
---|
[16d866] | 186 | endpoints[i] = NULL;
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
[357fba] | 190 | }
|
---|
| 191 | if (!triangles.empty())
|
---|
[6613ec] | 192 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
|
---|
| 193 | }
|
---|
| 194 | ;
|
---|
[357fba] | 195 |
|
---|
[16d866] | 196 | /** Add triangle to TriangleMap of this boundary line.
|
---|
| 197 | * \param *triangle to add
|
---|
| 198 | */
|
---|
[9473f6] | 199 | void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
|
---|
[357fba] | 200 | {
|
---|
[6613ec] | 201 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 202 | DoLog(0) && (Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl);
|
---|
[357fba] | 203 | triangles.insert(TrianglePair(triangle->Nr, triangle));
|
---|
[6613ec] | 204 | }
|
---|
| 205 | ;
|
---|
[357fba] | 206 |
|
---|
| 207 | /** Checks whether we have a common endpoint with given \a *line.
|
---|
| 208 | * \param *line other line to test
|
---|
| 209 | * \return true - common endpoint present, false - not connected
|
---|
| 210 | */
|
---|
[9473f6] | 211 | bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
|
---|
[357fba] | 212 | {
|
---|
[6613ec] | 213 | Info FunctionInfo(__func__);
|
---|
[357fba] | 214 | if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
|
---|
| 215 | return true;
|
---|
| 216 | else
|
---|
| 217 | return false;
|
---|
[6613ec] | 218 | }
|
---|
| 219 | ;
|
---|
[357fba] | 220 |
|
---|
| 221 | /** Checks whether the adjacent triangles of a baseline are convex or not.
|
---|
[57066a] | 222 | * We sum the two angles of each height vector with respect to the center of the baseline.
|
---|
[357fba] | 223 | * If greater/equal M_PI than we are convex.
|
---|
| 224 | * \param *out output stream for debugging
|
---|
| 225 | * \return true - triangles are convex, false - concave or less than two triangles connected
|
---|
| 226 | */
|
---|
[9473f6] | 227 | bool BoundaryLineSet::CheckConvexityCriterion() const
|
---|
[357fba] | 228 | {
|
---|
[6613ec] | 229 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 230 | Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
|
---|
[357fba] | 231 | // get the two triangles
|
---|
[5c7bf8] | 232 | if (triangles.size() != 2) {
|
---|
[6613ec] | 233 | DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
|
---|
[1d9b7aa] | 234 | return true;
|
---|
[357fba] | 235 | }
|
---|
[5c7bf8] | 236 | // check normal vectors
|
---|
[357fba] | 237 | // have a normal vector on the base line pointing outwards
|
---|
[f67b6e] | 238 | //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
|
---|
[273382] | 239 | BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node));
|
---|
| 240 | BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node);
|
---|
[8cbb97] | 241 |
|
---|
[f67b6e] | 242 | //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
|
---|
[357fba] | 243 |
|
---|
[62bb91] | 244 | BaseLineNormal.Zero();
|
---|
[5c7bf8] | 245 | NormalCheck.Zero();
|
---|
| 246 | double sign = -1.;
|
---|
[6613ec] | 247 | int i = 0;
|
---|
[62bb91] | 248 | class BoundaryPointSet *node = NULL;
|
---|
[6613ec] | 249 | for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
|
---|
[f67b6e] | 250 | //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
|
---|
[273382] | 251 | NormalCheck += runner->second->NormalVector;
|
---|
| 252 | NormalCheck *= sign;
|
---|
[5c7bf8] | 253 | sign = -sign;
|
---|
[57066a] | 254 | if (runner->second->NormalVector.NormSquared() > MYEPSILON)
|
---|
[273382] | 255 | BaseLineNormal = runner->second->NormalVector; // yes, copy second on top of first
|
---|
[57066a] | 256 | else {
|
---|
[6613ec] | 257 | DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
|
---|
[57066a] | 258 | }
|
---|
[62bb91] | 259 | node = runner->second->GetThirdEndpoint(this);
|
---|
| 260 | if (node != NULL) {
|
---|
[f67b6e] | 261 | //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
|
---|
[273382] | 262 | helper[i] = (*node->node->node) - BaseLineCenter;
|
---|
[0a4f7f] | 263 | helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles!
|
---|
[f67b6e] | 264 | //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
|
---|
[62bb91] | 265 | i++;
|
---|
| 266 | } else {
|
---|
[6613ec] | 267 | DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
|
---|
[62bb91] | 268 | return true;
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
[f67b6e] | 271 | //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
|
---|
[5c7bf8] | 272 | if (NormalCheck.NormSquared() < MYEPSILON) {
|
---|
[a67d19] | 273 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl);
|
---|
[5c7bf8] | 274 | return true;
|
---|
[62bb91] | 275 | }
|
---|
[57066a] | 276 | BaseLineNormal.Scale(-1.);
|
---|
[f1cccd] | 277 | double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
|
---|
[1d9b7aa] | 278 | if ((angle - M_PI) > -MYEPSILON) {
|
---|
[a67d19] | 279 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
|
---|
[357fba] | 280 | return true;
|
---|
[1d9b7aa] | 281 | } else {
|
---|
[a67d19] | 282 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
|
---|
[357fba] | 283 | return false;
|
---|
[1d9b7aa] | 284 | }
|
---|
[357fba] | 285 | }
|
---|
| 286 |
|
---|
| 287 | /** Checks whether point is any of the two endpoints this line contains.
|
---|
| 288 | * \param *point point to test
|
---|
| 289 | * \return true - point is of the line, false - is not
|
---|
| 290 | */
|
---|
[9473f6] | 291 | bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
[357fba] | 292 | {
|
---|
[6613ec] | 293 | Info FunctionInfo(__func__);
|
---|
| 294 | for (int i = 0; i < 2; i++)
|
---|
[357fba] | 295 | if (point == endpoints[i])
|
---|
| 296 | return true;
|
---|
| 297 | return false;
|
---|
[6613ec] | 298 | }
|
---|
| 299 | ;
|
---|
[357fba] | 300 |
|
---|
[62bb91] | 301 | /** Returns other endpoint of the line.
|
---|
| 302 | * \param *point other endpoint
|
---|
| 303 | * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise
|
---|
| 304 | */
|
---|
[9473f6] | 305 | class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
|
---|
[62bb91] | 306 | {
|
---|
[6613ec] | 307 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 308 | if (endpoints[0] == point)
|
---|
| 309 | return endpoints[1];
|
---|
| 310 | else if (endpoints[1] == point)
|
---|
| 311 | return endpoints[0];
|
---|
| 312 | else
|
---|
| 313 | return NULL;
|
---|
[6613ec] | 314 | }
|
---|
| 315 | ;
|
---|
[62bb91] | 316 |
|
---|
[16d866] | 317 | /** output operator for BoundaryLineSet.
|
---|
| 318 | * \param &ost output stream
|
---|
| 319 | * \param &a boundary line
|
---|
| 320 | */
|
---|
[6613ec] | 321 | ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
|
---|
[357fba] | 322 | {
|
---|
[57066a] | 323 | ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << "," << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "]";
|
---|
[357fba] | 324 | return ost;
|
---|
[6613ec] | 325 | }
|
---|
| 326 | ;
|
---|
[357fba] | 327 |
|
---|
| 328 | // ======================================== Triangles on Boundary =================================
|
---|
| 329 |
|
---|
[16d866] | 330 | /** Constructor for BoundaryTriangleSet.
|
---|
| 331 | */
|
---|
[1e168b] | 332 | BoundaryTriangleSet::BoundaryTriangleSet() :
|
---|
| 333 | Nr(-1)
|
---|
[357fba] | 334 | {
|
---|
[6613ec] | 335 | Info FunctionInfo(__func__);
|
---|
| 336 | for (int i = 0; i < 3; i++) {
|
---|
| 337 | endpoints[i] = NULL;
|
---|
| 338 | lines[i] = NULL;
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | ;
|
---|
[357fba] | 342 |
|
---|
[16d866] | 343 | /** Constructor for BoundaryTriangleSet with three lines.
|
---|
| 344 | * \param *line[3] lines that make up the triangle
|
---|
| 345 | * \param number number of triangle
|
---|
| 346 | */
|
---|
[9473f6] | 347 | BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
|
---|
[1e168b] | 348 | Nr(number)
|
---|
[357fba] | 349 | {
|
---|
[6613ec] | 350 | Info FunctionInfo(__func__);
|
---|
[357fba] | 351 | // set number
|
---|
| 352 | // set lines
|
---|
[f67b6e] | 353 | for (int i = 0; i < 3; i++) {
|
---|
| 354 | lines[i] = line[i];
|
---|
| 355 | lines[i]->AddTriangle(this);
|
---|
| 356 | }
|
---|
[357fba] | 357 | // get ascending order of endpoints
|
---|
[f67b6e] | 358 | PointMap OrderMap;
|
---|
[357fba] | 359 | for (int i = 0; i < 3; i++)
|
---|
| 360 | // for all three lines
|
---|
[f67b6e] | 361 | for (int j = 0; j < 2; j++) { // for both endpoints
|
---|
[6613ec] | 362 | OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
|
---|
[f67b6e] | 363 | // and we don't care whether insertion fails
|
---|
| 364 | }
|
---|
[357fba] | 365 | // set endpoints
|
---|
| 366 | int Counter = 0;
|
---|
[a67d19] | 367 | DoLog(0) && (Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl);
|
---|
[f67b6e] | 368 | for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
|
---|
| 369 | endpoints[Counter] = runner->second;
|
---|
[a67d19] | 370 | DoLog(0) && (Log() << Verbose(0) << " " << *endpoints[Counter] << endl);
|
---|
[f67b6e] | 371 | Counter++;
|
---|
| 372 | }
|
---|
| 373 | if (Counter < 3) {
|
---|
[6613ec] | 374 | DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl);
|
---|
[f67b6e] | 375 | performCriticalExit();
|
---|
| 376 | }
|
---|
[6613ec] | 377 | }
|
---|
| 378 | ;
|
---|
[357fba] | 379 |
|
---|
[16d866] | 380 | /** Destructor of BoundaryTriangleSet.
|
---|
| 381 | * Removes itself from each of its lines' LineMap and removes them if necessary.
|
---|
| 382 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 383 | */
|
---|
[357fba] | 384 | BoundaryTriangleSet::~BoundaryTriangleSet()
|
---|
| 385 | {
|
---|
[6613ec] | 386 | Info FunctionInfo(__func__);
|
---|
[357fba] | 387 | for (int i = 0; i < 3; i++) {
|
---|
[16d866] | 388 | if (lines[i] != NULL) {
|
---|
[57066a] | 389 | if (lines[i]->triangles.erase(Nr)) {
|
---|
[f67b6e] | 390 | //Log() << Verbose(0) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
|
---|
[57066a] | 391 | }
|
---|
[16d866] | 392 | if (lines[i]->triangles.empty()) {
|
---|
[6613ec] | 393 | //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
|
---|
| 394 | delete (lines[i]);
|
---|
| 395 | lines[i] = NULL;
|
---|
[16d866] | 396 | }
|
---|
| 397 | }
|
---|
[357fba] | 398 | }
|
---|
[f67b6e] | 399 | //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
|
---|
[6613ec] | 400 | }
|
---|
| 401 | ;
|
---|
[357fba] | 402 |
|
---|
| 403 | /** Calculates the normal vector for this triangle.
|
---|
| 404 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 405 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 406 | */
|
---|
[9473f6] | 407 | void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
|
---|
[357fba] | 408 | {
|
---|
[6613ec] | 409 | Info FunctionInfo(__func__);
|
---|
[357fba] | 410 | // get normal vector
|
---|
[0a4f7f] | 411 | NormalVector = Plane(*(endpoints[0]->node->node),
|
---|
| 412 | *(endpoints[1]->node->node),
|
---|
| 413 | *(endpoints[2]->node->node)).getNormal();
|
---|
[357fba] | 414 |
|
---|
| 415 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
[273382] | 416 | if (NormalVector.ScalarProduct(OtherVector) > 0.)
|
---|
[357fba] | 417 | NormalVector.Scale(-1.);
|
---|
[a67d19] | 418 | DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl);
|
---|
[6613ec] | 419 | }
|
---|
| 420 | ;
|
---|
[357fba] | 421 |
|
---|
[97498a] | 422 | /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
|
---|
[357fba] | 423 | * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
|
---|
[9473f6] | 424 | * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
[7dea7c] | 425 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 426 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 427 | * the first two basepoints) or not.
|
---|
[357fba] | 428 | * \param *out output stream for debugging
|
---|
| 429 | * \param *MolCenter offset vector of line
|
---|
| 430 | * \param *x second endpoint of line, minus \a *MolCenter is directional vector of line
|
---|
| 431 | * \param *Intersection intersection on plane on return
|
---|
| 432 | * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
|
---|
| 433 | */
|
---|
[8cbb97] | 434 |
|
---|
[9473f6] | 435 | bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
|
---|
[357fba] | 436 | {
|
---|
[fee69b] | 437 | Info FunctionInfo(__func__);
|
---|
[357fba] | 438 | Vector CrossPoint;
|
---|
| 439 | Vector helper;
|
---|
| 440 |
|
---|
[0a4f7f] | 441 | try {
|
---|
| 442 | *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x);
|
---|
| 443 | }
|
---|
| 444 | catch (LinearDependenceException &excp) {
|
---|
| 445 | Log() << Verbose(1) << excp;
|
---|
[6613ec] | 446 | DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
|
---|
[357fba] | 447 | return false;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
[a67d19] | 450 | DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl);
|
---|
| 451 | DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl);
|
---|
| 452 | DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
|
---|
[97498a] | 453 |
|
---|
[273382] | 454 | if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) {
|
---|
[a67d19] | 455 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
|
---|
[fee69b] | 456 | return true;
|
---|
[273382] | 457 | } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) {
|
---|
[a67d19] | 458 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
|
---|
[fee69b] | 459 | return true;
|
---|
[273382] | 460 | } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) {
|
---|
[a67d19] | 461 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
|
---|
[fee69b] | 462 | return true;
|
---|
| 463 | }
|
---|
[357fba] | 464 | // Calculate cross point between one baseline and the line from the third endpoint to intersection
|
---|
[6613ec] | 465 | int i = 0;
|
---|
[357fba] | 466 | do {
|
---|
[0a4f7f] | 467 | try {
|
---|
| 468 | CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node),
|
---|
| 469 | *(endpoints[(i+1)%3]->node->node),
|
---|
| 470 | *(endpoints[(i+2)%3]->node->node),
|
---|
| 471 | *Intersection);
|
---|
[273382] | 472 | helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
|
---|
| 473 | CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
| 474 | const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared();
|
---|
[a67d19] | 475 | DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl);
|
---|
[fee69b] | 476 | if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
|
---|
[a67d19] | 477 | DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
|
---|
[fee69b] | 478 | i=4;
|
---|
| 479 | break;
|
---|
| 480 | }
|
---|
[5c7bf8] | 481 | i++;
|
---|
[0a4f7f] | 482 | } catch (LinearDependenceException &excp){
|
---|
[fcad4b] | 483 | break;
|
---|
[0a4f7f] | 484 | }
|
---|
[6613ec] | 485 | } while (i < 3);
|
---|
| 486 | if (i == 3) {
|
---|
[a67d19] | 487 | DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl);
|
---|
[357fba] | 488 | return true;
|
---|
[fcad4b] | 489 | } else {
|
---|
[a67d19] | 490 | DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl);
|
---|
[357fba] | 491 | return false;
|
---|
| 492 | }
|
---|
[6613ec] | 493 | }
|
---|
| 494 | ;
|
---|
[357fba] | 495 |
|
---|
[8db598] | 496 | /** Finds the point on the triangle to the point \a *x.
|
---|
| 497 | * We call Vector::GetIntersectionWithPlane() with \a * and the center of the triangle to receive an intersection point.
|
---|
| 498 | * Then we check the in-plane part (the part projected down onto plane). We check whether it crosses one of the
|
---|
| 499 | * boundary lines. If it does, we return this intersection as closest point, otherwise the projected point down.
|
---|
[9473f6] | 500 | * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
| 501 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 502 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 503 | * the first two basepoints) or not.
|
---|
| 504 | * \param *x point
|
---|
| 505 | * \param *ClosestPoint desired closest point inside triangle to \a *x, is absolute vector
|
---|
| 506 | * \return Distance squared between \a *x and closest point inside triangle
|
---|
| 507 | */
|
---|
| 508 | double BoundaryTriangleSet::GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const
|
---|
| 509 | {
|
---|
| 510 | Info FunctionInfo(__func__);
|
---|
| 511 | Vector Direction;
|
---|
| 512 |
|
---|
| 513 | // 1. get intersection with plane
|
---|
[a67d19] | 514 | DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl);
|
---|
[9473f6] | 515 | GetCenter(&Direction);
|
---|
[0a4f7f] | 516 | try {
|
---|
| 517 | *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction);
|
---|
| 518 | }
|
---|
| 519 | catch (LinearDependenceException &excp) {
|
---|
[273382] | 520 | (*ClosestPoint) = (*x);
|
---|
[9473f6] | 521 | }
|
---|
| 522 |
|
---|
| 523 | // 2. Calculate in plane part of line (x, intersection)
|
---|
[273382] | 524 | Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point
|
---|
| 525 | InPlane.ProjectOntoPlane(NormalVector);
|
---|
| 526 | InPlane += *ClosestPoint;
|
---|
[9473f6] | 527 |
|
---|
[a67d19] | 528 | DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl);
|
---|
| 529 | DoLog(2) && (Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl);
|
---|
| 530 | DoLog(2) && (Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl);
|
---|
[9473f6] | 531 |
|
---|
| 532 | // Calculate cross point between one baseline and the desired point such that distance is shortest
|
---|
| 533 | double ShortestDistance = -1.;
|
---|
| 534 | bool InsideFlag = false;
|
---|
| 535 | Vector CrossDirection[3];
|
---|
| 536 | Vector CrossPoint[3];
|
---|
| 537 | Vector helper;
|
---|
[6613ec] | 538 | for (int i = 0; i < 3; i++) {
|
---|
[9473f6] | 539 | // 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] | 540 | Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
|
---|
[9473f6] | 541 | // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
|
---|
[0a4f7f] | 542 | CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
|
---|
[273382] | 543 | CrossDirection[i] = CrossPoint[i] - InPlane;
|
---|
| 544 | CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
| 545 | const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared();
|
---|
[a67d19] | 546 | DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl);
|
---|
[9473f6] | 547 | if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
|
---|
[8cbb97] | 548 | CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again
|
---|
[a67d19] | 549 | 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] | 550 | const double distance = CrossPoint[i].DistanceSquared(*x);
|
---|
[9473f6] | 551 | if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
|
---|
| 552 | ShortestDistance = distance;
|
---|
[273382] | 553 | (*ClosestPoint) = CrossPoint[i];
|
---|
[9473f6] | 554 | }
|
---|
| 555 | } else
|
---|
| 556 | CrossPoint[i].Zero();
|
---|
| 557 | }
|
---|
| 558 | InsideFlag = true;
|
---|
[6613ec] | 559 | for (int i = 0; i < 3; i++) {
|
---|
[8cbb97] | 560 | const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 1) % 3]);
|
---|
| 561 | const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 2) % 3]);
|
---|
| 562 |
|
---|
[6613ec] | 563 | if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
|
---|
[9473f6] | 564 | InsideFlag = false;
|
---|
| 565 | }
|
---|
| 566 | if (InsideFlag) {
|
---|
[273382] | 567 | (*ClosestPoint) = InPlane;
|
---|
| 568 | ShortestDistance = InPlane.DistanceSquared(*x);
|
---|
[6613ec] | 569 | } else { // also check endnodes
|
---|
| 570 | for (int i = 0; i < 3; i++) {
|
---|
[273382] | 571 | const double distance = x->DistanceSquared(*endpoints[i]->node->node);
|
---|
[9473f6] | 572 | if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
|
---|
| 573 | ShortestDistance = distance;
|
---|
[273382] | 574 | (*ClosestPoint) = (*endpoints[i]->node->node);
|
---|
[9473f6] | 575 | }
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
[a67d19] | 578 | DoLog(1) && (Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl);
|
---|
[9473f6] | 579 | return ShortestDistance;
|
---|
[6613ec] | 580 | }
|
---|
| 581 | ;
|
---|
[9473f6] | 582 |
|
---|
[357fba] | 583 | /** Checks whether lines is any of the three boundary lines this triangle contains.
|
---|
| 584 | * \param *line line to test
|
---|
| 585 | * \return true - line is of the triangle, false - is not
|
---|
| 586 | */
|
---|
[9473f6] | 587 | bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
|
---|
[357fba] | 588 | {
|
---|
[6613ec] | 589 | Info FunctionInfo(__func__);
|
---|
| 590 | for (int i = 0; i < 3; i++)
|
---|
[357fba] | 591 | if (line == lines[i])
|
---|
| 592 | return true;
|
---|
| 593 | return false;
|
---|
[6613ec] | 594 | }
|
---|
| 595 | ;
|
---|
[357fba] | 596 |
|
---|
| 597 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 598 | * \param *point point to test
|
---|
| 599 | * \return true - point is of the triangle, false - is not
|
---|
| 600 | */
|
---|
[9473f6] | 601 | bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
[357fba] | 602 | {
|
---|
[6613ec] | 603 | Info FunctionInfo(__func__);
|
---|
| 604 | for (int i = 0; i < 3; i++)
|
---|
[357fba] | 605 | if (point == endpoints[i])
|
---|
| 606 | return true;
|
---|
| 607 | return false;
|
---|
[6613ec] | 608 | }
|
---|
| 609 | ;
|
---|
[357fba] | 610 |
|
---|
[7dea7c] | 611 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 612 | * \param *point TesselPoint to test
|
---|
| 613 | * \return true - point is of the triangle, false - is not
|
---|
| 614 | */
|
---|
[9473f6] | 615 | bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
|
---|
[7dea7c] | 616 | {
|
---|
[6613ec] | 617 | Info FunctionInfo(__func__);
|
---|
| 618 | for (int i = 0; i < 3; i++)
|
---|
[7dea7c] | 619 | if (point == endpoints[i]->node)
|
---|
| 620 | return true;
|
---|
| 621 | return false;
|
---|
[6613ec] | 622 | }
|
---|
| 623 | ;
|
---|
[7dea7c] | 624 |
|
---|
[357fba] | 625 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 626 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 627 | * \return true - is the very triangle, false - is not
|
---|
| 628 | */
|
---|
[9473f6] | 629 | bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
|
---|
[357fba] | 630 | {
|
---|
[6613ec] | 631 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 632 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl);
|
---|
[6613ec] | 633 | 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])
|
---|
| 634 |
|
---|
| 635 | ));
|
---|
| 636 | }
|
---|
| 637 | ;
|
---|
[357fba] | 638 |
|
---|
[57066a] | 639 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 640 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 641 | * \return true - is the very triangle, false - is not
|
---|
| 642 | */
|
---|
[9473f6] | 643 | bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
|
---|
[57066a] | 644 | {
|
---|
[6613ec] | 645 | Info FunctionInfo(__func__);
|
---|
| 646 | 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])
|
---|
| 647 |
|
---|
| 648 | ));
|
---|
| 649 | }
|
---|
| 650 | ;
|
---|
[57066a] | 651 |
|
---|
[62bb91] | 652 | /** Returns the endpoint which is not contained in the given \a *line.
|
---|
| 653 | * \param *line baseline defining two endpoints
|
---|
| 654 | * \return pointer third endpoint or NULL if line does not belong to triangle.
|
---|
| 655 | */
|
---|
[9473f6] | 656 | class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
|
---|
[62bb91] | 657 | {
|
---|
[6613ec] | 658 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 659 | // sanity check
|
---|
| 660 | if (!ContainsBoundaryLine(line))
|
---|
| 661 | return NULL;
|
---|
[6613ec] | 662 | for (int i = 0; i < 3; i++)
|
---|
[62bb91] | 663 | if (!line->ContainsBoundaryPoint(endpoints[i]))
|
---|
| 664 | return endpoints[i];
|
---|
| 665 | // actually, that' impossible :)
|
---|
| 666 | return NULL;
|
---|
[6613ec] | 667 | }
|
---|
| 668 | ;
|
---|
[62bb91] | 669 |
|
---|
| 670 | /** Calculates the center point of the triangle.
|
---|
| 671 | * Is third of the sum of all endpoints.
|
---|
| 672 | * \param *center central point on return.
|
---|
| 673 | */
|
---|
[9473f6] | 674 | void BoundaryTriangleSet::GetCenter(Vector * const center) const
|
---|
[62bb91] | 675 | {
|
---|
[6613ec] | 676 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 677 | center->Zero();
|
---|
[6613ec] | 678 | for (int i = 0; i < 3; i++)
|
---|
[273382] | 679 | (*center) += (*endpoints[i]->node->node);
|
---|
[6613ec] | 680 | center->Scale(1. / 3.);
|
---|
[a67d19] | 681 | DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl);
|
---|
[62bb91] | 682 | }
|
---|
| 683 |
|
---|
[16d866] | 684 | /** output operator for BoundaryTriangleSet.
|
---|
| 685 | * \param &ost output stream
|
---|
| 686 | * \param &a boundary triangle
|
---|
| 687 | */
|
---|
[776b64] | 688 | ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
|
---|
[357fba] | 689 | {
|
---|
[f67b6e] | 690 | ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]";
|
---|
[6613ec] | 691 | // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
|
---|
| 692 | // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
|
---|
[357fba] | 693 | return ost;
|
---|
[6613ec] | 694 | }
|
---|
| 695 | ;
|
---|
[357fba] | 696 |
|
---|
[262bae] | 697 | // ======================================== Polygons on Boundary =================================
|
---|
| 698 |
|
---|
| 699 | /** Constructor for BoundaryPolygonSet.
|
---|
| 700 | */
|
---|
| 701 | BoundaryPolygonSet::BoundaryPolygonSet() :
|
---|
| 702 | Nr(-1)
|
---|
| 703 | {
|
---|
| 704 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 705 | }
|
---|
| 706 | ;
|
---|
[262bae] | 707 |
|
---|
| 708 | /** Destructor of BoundaryPolygonSet.
|
---|
| 709 | * Just clears endpoints.
|
---|
| 710 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 711 | */
|
---|
| 712 | BoundaryPolygonSet::~BoundaryPolygonSet()
|
---|
| 713 | {
|
---|
| 714 | Info FunctionInfo(__func__);
|
---|
| 715 | endpoints.clear();
|
---|
[a67d19] | 716 | DoLog(1) && (Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl);
|
---|
[6613ec] | 717 | }
|
---|
| 718 | ;
|
---|
[262bae] | 719 |
|
---|
| 720 | /** Calculates the normal vector for this triangle.
|
---|
| 721 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 722 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 723 | * \return allocated vector in normal direction
|
---|
| 724 | */
|
---|
| 725 | Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
|
---|
| 726 | {
|
---|
| 727 | Info FunctionInfo(__func__);
|
---|
| 728 | // get normal vector
|
---|
| 729 | Vector TemporaryNormal;
|
---|
| 730 | Vector *TotalNormal = new Vector;
|
---|
| 731 | PointSet::const_iterator Runner[3];
|
---|
[6613ec] | 732 | for (int i = 0; i < 3; i++) {
|
---|
[262bae] | 733 | Runner[i] = endpoints.begin();
|
---|
[6613ec] | 734 | for (int j = 0; j < i; j++) { // go as much further
|
---|
[262bae] | 735 | Runner[i]++;
|
---|
| 736 | if (Runner[i] == endpoints.end()) {
|
---|
[6613ec] | 737 | DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
|
---|
[262bae] | 738 | performCriticalExit();
|
---|
| 739 | }
|
---|
| 740 | }
|
---|
| 741 | }
|
---|
| 742 | TotalNormal->Zero();
|
---|
[6613ec] | 743 | int counter = 0;
|
---|
| 744 | for (; Runner[2] != endpoints.end();) {
|
---|
[0a4f7f] | 745 | TemporaryNormal = Plane(*((*Runner[0])->node->node),
|
---|
| 746 | *((*Runner[1])->node->node),
|
---|
| 747 | *((*Runner[2])->node->node)).getNormal();
|
---|
[6613ec] | 748 | for (int i = 0; i < 3; i++) // increase each of them
|
---|
[262bae] | 749 | Runner[i]++;
|
---|
[273382] | 750 | (*TotalNormal) += TemporaryNormal;
|
---|
[262bae] | 751 | }
|
---|
[6613ec] | 752 | TotalNormal->Scale(1. / (double) counter);
|
---|
[262bae] | 753 |
|
---|
| 754 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
[273382] | 755 | if (TotalNormal->ScalarProduct(OtherVector) > 0.)
|
---|
[262bae] | 756 | TotalNormal->Scale(-1.);
|
---|
[a67d19] | 757 | DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
|
---|
[262bae] | 758 |
|
---|
| 759 | return TotalNormal;
|
---|
[6613ec] | 760 | }
|
---|
| 761 | ;
|
---|
[262bae] | 762 |
|
---|
| 763 | /** Calculates the center point of the triangle.
|
---|
| 764 | * Is third of the sum of all endpoints.
|
---|
| 765 | * \param *center central point on return.
|
---|
| 766 | */
|
---|
| 767 | void BoundaryPolygonSet::GetCenter(Vector * const center) const
|
---|
| 768 | {
|
---|
| 769 | Info FunctionInfo(__func__);
|
---|
| 770 | center->Zero();
|
---|
| 771 | int counter = 0;
|
---|
| 772 | for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[273382] | 773 | (*center) += (*(*Runner)->node->node);
|
---|
[262bae] | 774 | counter++;
|
---|
| 775 | }
|
---|
[6613ec] | 776 | center->Scale(1. / (double) counter);
|
---|
[a67d19] | 777 | DoLog(1) && (Log() << Verbose(1) << "Center is at " << *center << "." << endl);
|
---|
[262bae] | 778 | }
|
---|
| 779 |
|
---|
| 780 | /** Checks whether the polygons contains all three endpoints of the triangle.
|
---|
| 781 | * \param *triangle triangle to test
|
---|
| 782 | * \return true - triangle is contained polygon, false - is not
|
---|
| 783 | */
|
---|
| 784 | bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
|
---|
| 785 | {
|
---|
| 786 | Info FunctionInfo(__func__);
|
---|
| 787 | return ContainsPresentTupel(triangle->endpoints, 3);
|
---|
[6613ec] | 788 | }
|
---|
| 789 | ;
|
---|
[262bae] | 790 |
|
---|
| 791 | /** Checks whether the polygons contains both endpoints of the line.
|
---|
| 792 | * \param *line line to test
|
---|
| 793 | * \return true - line is of the triangle, false - is not
|
---|
| 794 | */
|
---|
| 795 | bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
|
---|
| 796 | {
|
---|
[856098] | 797 | Info FunctionInfo(__func__);
|
---|
[262bae] | 798 | return ContainsPresentTupel(line->endpoints, 2);
|
---|
[6613ec] | 799 | }
|
---|
| 800 | ;
|
---|
[262bae] | 801 |
|
---|
| 802 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 803 | * \param *point point to test
|
---|
| 804 | * \return true - point is of the triangle, false - is not
|
---|
| 805 | */
|
---|
| 806 | bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
| 807 | {
|
---|
| 808 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 809 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[a67d19] | 810 | DoLog(0) && (Log() << Verbose(0) << "Checking against " << **Runner << endl);
|
---|
[856098] | 811 | if (point == (*Runner)) {
|
---|
[a67d19] | 812 | DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
|
---|
[262bae] | 813 | return true;
|
---|
[856098] | 814 | }
|
---|
| 815 | }
|
---|
[a67d19] | 816 | DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
|
---|
[262bae] | 817 | return false;
|
---|
[6613ec] | 818 | }
|
---|
| 819 | ;
|
---|
[262bae] | 820 |
|
---|
| 821 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 822 | * \param *point TesselPoint to test
|
---|
| 823 | * \return true - point is of the triangle, false - is not
|
---|
| 824 | */
|
---|
| 825 | bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
|
---|
| 826 | {
|
---|
| 827 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 828 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
|
---|
[856098] | 829 | if (point == (*Runner)->node) {
|
---|
[a67d19] | 830 | DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
|
---|
[262bae] | 831 | return true;
|
---|
[856098] | 832 | }
|
---|
[a67d19] | 833 | DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
|
---|
[262bae] | 834 | return false;
|
---|
[6613ec] | 835 | }
|
---|
| 836 | ;
|
---|
[262bae] | 837 |
|
---|
| 838 | /** Checks whether given array of \a *Points coincide with polygons's endpoints.
|
---|
| 839 | * \param **Points pointer to an array of BoundaryPointSet
|
---|
| 840 | * \param dim dimension of array
|
---|
| 841 | * \return true - set of points is contained in polygon, false - is not
|
---|
| 842 | */
|
---|
| 843 | bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
|
---|
| 844 | {
|
---|
[856098] | 845 | Info FunctionInfo(__func__);
|
---|
[262bae] | 846 | int counter = 0;
|
---|
[a67d19] | 847 | DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
|
---|
[6613ec] | 848 | for (int i = 0; i < dim; i++) {
|
---|
[a67d19] | 849 | DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl);
|
---|
[856098] | 850 | if (ContainsBoundaryPoint(Points[i])) {
|
---|
[262bae] | 851 | counter++;
|
---|
[856098] | 852 | }
|
---|
| 853 | }
|
---|
[262bae] | 854 |
|
---|
| 855 | if (counter == dim)
|
---|
| 856 | return true;
|
---|
| 857 | else
|
---|
| 858 | return false;
|
---|
[6613ec] | 859 | }
|
---|
| 860 | ;
|
---|
[262bae] | 861 |
|
---|
| 862 | /** Checks whether given PointList coincide with polygons's endpoints.
|
---|
| 863 | * \param &endpoints PointList
|
---|
| 864 | * \return true - set of points is contained in polygon, false - is not
|
---|
| 865 | */
|
---|
| 866 | bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
|
---|
| 867 | {
|
---|
[856098] | 868 | Info FunctionInfo(__func__);
|
---|
[262bae] | 869 | size_t counter = 0;
|
---|
[a67d19] | 870 | DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
|
---|
[6613ec] | 871 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[a67d19] | 872 | DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << **Runner << endl);
|
---|
[262bae] | 873 | if (ContainsBoundaryPoint(*Runner))
|
---|
| 874 | counter++;
|
---|
| 875 | }
|
---|
| 876 |
|
---|
| 877 | if (counter == endpoints.size())
|
---|
| 878 | return true;
|
---|
| 879 | else
|
---|
| 880 | return false;
|
---|
[6613ec] | 881 | }
|
---|
| 882 | ;
|
---|
[262bae] | 883 |
|
---|
| 884 | /** Checks whether given set of \a *Points coincide with polygons's endpoints.
|
---|
| 885 | * \param *P pointer to BoundaryPolygonSet
|
---|
| 886 | * \return true - is the very triangle, false - is not
|
---|
| 887 | */
|
---|
| 888 | bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
|
---|
| 889 | {
|
---|
[6613ec] | 890 | return ContainsPresentTupel((const PointSet) P->endpoints);
|
---|
| 891 | }
|
---|
| 892 | ;
|
---|
[262bae] | 893 |
|
---|
| 894 | /** Gathers all the endpoints' triangles in a unique set.
|
---|
| 895 | * \return set of all triangles
|
---|
| 896 | */
|
---|
[856098] | 897 | TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
|
---|
[262bae] | 898 | {
|
---|
| 899 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 900 | pair<TriangleSet::iterator, bool> Tester;
|
---|
[262bae] | 901 | TriangleSet *triangles = new TriangleSet;
|
---|
| 902 |
|
---|
[6613ec] | 903 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
|
---|
| 904 | for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
|
---|
| 905 | for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
|
---|
[856098] | 906 | //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
|
---|
| 907 | if (ContainsBoundaryTriangle(Sprinter->second)) {
|
---|
| 908 | Tester = triangles->insert(Sprinter->second);
|
---|
| 909 | if (Tester.second)
|
---|
[a67d19] | 910 | DoLog(0) && (Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl);
|
---|
[856098] | 911 | }
|
---|
| 912 | }
|
---|
[262bae] | 913 |
|
---|
[a67d19] | 914 | DoLog(1) && (Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl);
|
---|
[262bae] | 915 | return triangles;
|
---|
[6613ec] | 916 | }
|
---|
| 917 | ;
|
---|
[262bae] | 918 |
|
---|
| 919 | /** Fills the endpoints of this polygon from the triangles attached to \a *line.
|
---|
| 920 | * \param *line lines with triangles attached
|
---|
[856098] | 921 | * \return true - polygon contains endpoints, false - line was NULL
|
---|
[262bae] | 922 | */
|
---|
| 923 | bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
|
---|
| 924 | {
|
---|
[856098] | 925 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 926 | pair<PointSet::iterator, bool> Tester;
|
---|
[856098] | 927 | if (line == NULL)
|
---|
| 928 | return false;
|
---|
[a67d19] | 929 | DoLog(1) && (Log() << Verbose(1) << "Filling polygon from line " << *line << endl);
|
---|
[6613ec] | 930 | for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
|
---|
| 931 | for (int i = 0; i < 3; i++) {
|
---|
[856098] | 932 | Tester = endpoints.insert((Runner->second)->endpoints[i]);
|
---|
| 933 | if (Tester.second)
|
---|
[a67d19] | 934 | DoLog(1) && (Log() << Verbose(1) << " Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl);
|
---|
[856098] | 935 | }
|
---|
[262bae] | 936 | }
|
---|
| 937 |
|
---|
[856098] | 938 | return true;
|
---|
[6613ec] | 939 | }
|
---|
| 940 | ;
|
---|
[262bae] | 941 |
|
---|
| 942 | /** output operator for BoundaryPolygonSet.
|
---|
| 943 | * \param &ost output stream
|
---|
| 944 | * \param &a boundary polygon
|
---|
| 945 | */
|
---|
| 946 | ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
|
---|
| 947 | {
|
---|
| 948 | ost << "[" << a.Nr << "|";
|
---|
[6613ec] | 949 | for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
|
---|
| 950 | ost << (*Runner)->node->Name;
|
---|
| 951 | Runner++;
|
---|
| 952 | if (Runner != a.endpoints.end())
|
---|
| 953 | ost << ",";
|
---|
[262bae] | 954 | }
|
---|
[6613ec] | 955 | ost << "]";
|
---|
[262bae] | 956 | return ost;
|
---|
[6613ec] | 957 | }
|
---|
| 958 | ;
|
---|
[262bae] | 959 |
|
---|
[357fba] | 960 | // =========================================================== class TESSELPOINT ===========================================
|
---|
| 961 |
|
---|
| 962 | /** Constructor of class TesselPoint.
|
---|
| 963 | */
|
---|
| 964 | TesselPoint::TesselPoint()
|
---|
| 965 | {
|
---|
[244a84] | 966 | //Info FunctionInfo(__func__);
|
---|
[357fba] | 967 | node = NULL;
|
---|
| 968 | nr = -1;
|
---|
[6613ec] | 969 | Name = NULL;
|
---|
| 970 | }
|
---|
| 971 | ;
|
---|
[357fba] | 972 |
|
---|
| 973 | /** Destructor for class TesselPoint.
|
---|
| 974 | */
|
---|
| 975 | TesselPoint::~TesselPoint()
|
---|
| 976 | {
|
---|
[244a84] | 977 | //Info FunctionInfo(__func__);
|
---|
[6613ec] | 978 | }
|
---|
| 979 | ;
|
---|
[357fba] | 980 |
|
---|
| 981 | /** Prints LCNode to screen.
|
---|
| 982 | */
|
---|
[6613ec] | 983 | ostream & operator <<(ostream &ost, const TesselPoint &a)
|
---|
[357fba] | 984 | {
|
---|
[57066a] | 985 | ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]";
|
---|
[357fba] | 986 | return ost;
|
---|
[6613ec] | 987 | }
|
---|
| 988 | ;
|
---|
[357fba] | 989 |
|
---|
[5c7bf8] | 990 | /** Prints LCNode to screen.
|
---|
| 991 | */
|
---|
[6613ec] | 992 | ostream & TesselPoint::operator <<(ostream &ost)
|
---|
[5c7bf8] | 993 | {
|
---|
[6613ec] | 994 | Info FunctionInfo(__func__);
|
---|
[27bd2f] | 995 | ost << "[" << (nr) << "|" << this << "]";
|
---|
[5c7bf8] | 996 | return ost;
|
---|
[6613ec] | 997 | }
|
---|
| 998 | ;
|
---|
[357fba] | 999 |
|
---|
| 1000 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 1001 |
|
---|
| 1002 | /** Constructor of class PointCloud.
|
---|
| 1003 | */
|
---|
| 1004 | PointCloud::PointCloud()
|
---|
| 1005 | {
|
---|
[6613ec] | 1006 | //Info FunctionInfo(__func__);
|
---|
| 1007 | }
|
---|
| 1008 | ;
|
---|
[357fba] | 1009 |
|
---|
| 1010 | /** Destructor for class PointCloud.
|
---|
| 1011 | */
|
---|
| 1012 | PointCloud::~PointCloud()
|
---|
| 1013 | {
|
---|
[6613ec] | 1014 | //Info FunctionInfo(__func__);
|
---|
| 1015 | }
|
---|
| 1016 | ;
|
---|
[357fba] | 1017 |
|
---|
| 1018 | // ============================ CandidateForTesselation =============================
|
---|
| 1019 |
|
---|
| 1020 | /** Constructor of class CandidateForTesselation.
|
---|
| 1021 | */
|
---|
[6613ec] | 1022 | CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
|
---|
| 1023 | BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
|
---|
[1e168b] | 1024 | {
|
---|
[6613ec] | 1025 | Info FunctionInfo(__func__);
|
---|
| 1026 | }
|
---|
| 1027 | ;
|
---|
[1e168b] | 1028 |
|
---|
| 1029 | /** Constructor of class CandidateForTesselation.
|
---|
| 1030 | */
|
---|
[6613ec] | 1031 | CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
|
---|
| 1032 | BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
|
---|
[1e168b] | 1033 | {
|
---|
[f67b6e] | 1034 | Info FunctionInfo(__func__);
|
---|
[273382] | 1035 | OptCenter = OptCandidateCenter;
|
---|
| 1036 | OtherOptCenter = OtherOptCandidateCenter;
|
---|
[357fba] | 1037 | };
|
---|
| 1038 |
|
---|
| 1039 |
|
---|
| 1040 | /** Destructor for class CandidateForTesselation.
|
---|
| 1041 | */
|
---|
[6613ec] | 1042 | CandidateForTesselation::~CandidateForTesselation()
|
---|
| 1043 | {
|
---|
| 1044 | }
|
---|
| 1045 | ;
|
---|
[357fba] | 1046 |
|
---|
[734816] | 1047 | /** Checks validity of a given sphere of a candidate line.
|
---|
| 1048 | * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside.
|
---|
| 1049 | * \param RADIUS radius of sphere
|
---|
| 1050 | * \param *LC LinkedCell structure with other atoms
|
---|
| 1051 | * \return true - sphere is valid, false - sphere contains other points
|
---|
| 1052 | */
|
---|
| 1053 | bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
|
---|
| 1054 | {
|
---|
[09898c] | 1055 | Info FunctionInfo(__func__);
|
---|
| 1056 |
|
---|
[6613ec] | 1057 | const double radiusSquared = RADIUS * RADIUS;
|
---|
[734816] | 1058 | list<const Vector *> VectorList;
|
---|
| 1059 | VectorList.push_back(&OptCenter);
|
---|
[09898c] | 1060 | //VectorList.push_back(&OtherOptCenter); // don't check the other (wrong) center
|
---|
[734816] | 1061 |
|
---|
[09898c] | 1062 | if (!pointlist.empty())
|
---|
[6613ec] | 1063 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
|
---|
[09898c] | 1064 | else
|
---|
| 1065 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
|
---|
[734816] | 1066 | // check baseline for OptCenter and OtherOptCenter being on sphere's surface
|
---|
| 1067 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
[6613ec] | 1068 | for (int i = 0; i < 2; i++) {
|
---|
[8cbb97] | 1069 | const double distance = fabs((*VRunner)->DistanceSquared(*BaseLine->endpoints[i]->node->node) - radiusSquared);
|
---|
[f07f86d] | 1070 | if (distance > HULLEPSILON) {
|
---|
[6613ec] | 1071 | DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
|
---|
[734816] | 1072 | return false;
|
---|
| 1073 | }
|
---|
[f07f86d] | 1074 | }
|
---|
[734816] | 1075 | }
|
---|
| 1076 |
|
---|
| 1077 | // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
|
---|
[6613ec] | 1078 | for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
|
---|
[734816] | 1079 | const TesselPoint *Walker = *Runner;
|
---|
| 1080 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
[8cbb97] | 1081 | const double distance = fabs((*VRunner)->DistanceSquared(*Walker->node) - radiusSquared);
|
---|
[f07f86d] | 1082 | if (distance > HULLEPSILON) {
|
---|
[6613ec] | 1083 | DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
|
---|
[734816] | 1084 | return false;
|
---|
[6613ec] | 1085 | } else {
|
---|
[a67d19] | 1086 | DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl);
|
---|
[734816] | 1087 | }
|
---|
| 1088 | }
|
---|
| 1089 | }
|
---|
| 1090 |
|
---|
[09898c] | 1091 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
|
---|
[734816] | 1092 | bool flag = true;
|
---|
| 1093 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
| 1094 | // get all points inside the sphere
|
---|
| 1095 | TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
|
---|
[6613ec] | 1096 |
|
---|
[a67d19] | 1097 | DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl);
|
---|
[6613ec] | 1098 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[1513a74] | 1099 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(OtherOptCenter) << "." << endl);
|
---|
[6613ec] | 1100 |
|
---|
[734816] | 1101 | // remove baseline's endpoints and candidates
|
---|
[6613ec] | 1102 | for (int i = 0; i < 2; i++) {
|
---|
[a67d19] | 1103 | DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl);
|
---|
[734816] | 1104 | ListofPoints->remove(BaseLine->endpoints[i]->node);
|
---|
[6613ec] | 1105 | }
|
---|
| 1106 | for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
|
---|
[a67d19] | 1107 | DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl);
|
---|
[734816] | 1108 | ListofPoints->remove(*Runner);
|
---|
[6613ec] | 1109 | }
|
---|
[734816] | 1110 | if (!ListofPoints->empty()) {
|
---|
[6613ec] | 1111 | DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
|
---|
[734816] | 1112 | flag = false;
|
---|
[09898c] | 1113 | DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
|
---|
| 1114 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
| 1115 | DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << endl);
|
---|
[734816] | 1116 | }
|
---|
[6613ec] | 1117 | delete (ListofPoints);
|
---|
[09898c] | 1118 |
|
---|
| 1119 | // check with animate_sphere.tcl VMD script
|
---|
| 1120 | if (ThirdPoint != NULL) {
|
---|
[8cbb97] | 1121 | DoLog(1) && (Log() << 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);
|
---|
[09898c] | 1122 | } else {
|
---|
[a67d19] | 1123 | DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl);
|
---|
[8cbb97] | 1124 | DoLog(1) && (Log() << 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);
|
---|
[09898c] | 1125 | }
|
---|
[734816] | 1126 | }
|
---|
| 1127 | return flag;
|
---|
[6613ec] | 1128 | }
|
---|
| 1129 | ;
|
---|
[357fba] | 1130 |
|
---|
[1e168b] | 1131 | /** output operator for CandidateForTesselation.
|
---|
| 1132 | * \param &ost output stream
|
---|
| 1133 | * \param &a boundary line
|
---|
| 1134 | */
|
---|
[6613ec] | 1135 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
|
---|
[1e168b] | 1136 | {
|
---|
| 1137 | ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with ";
|
---|
[f67b6e] | 1138 | if (a.pointlist.empty())
|
---|
[1e168b] | 1139 | ost << "no candidate.";
|
---|
[f67b6e] | 1140 | else {
|
---|
| 1141 | ost << "candidate";
|
---|
| 1142 | if (a.pointlist.size() != 1)
|
---|
| 1143 | ost << "s ";
|
---|
| 1144 | else
|
---|
| 1145 | ost << " ";
|
---|
| 1146 | for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
|
---|
| 1147 | ost << *(*Runner) << " ";
|
---|
[6613ec] | 1148 | ost << " at angle " << (a.ShortestAngle) << ".";
|
---|
[f67b6e] | 1149 | }
|
---|
[1e168b] | 1150 |
|
---|
| 1151 | return ost;
|
---|
[6613ec] | 1152 | }
|
---|
| 1153 | ;
|
---|
[1e168b] | 1154 |
|
---|
[357fba] | 1155 | // =========================================================== class TESSELATION ===========================================
|
---|
| 1156 |
|
---|
| 1157 | /** Constructor of class Tesselation.
|
---|
| 1158 | */
|
---|
[1e168b] | 1159 | Tesselation::Tesselation() :
|
---|
[6613ec] | 1160 | PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin())
|
---|
[357fba] | 1161 | {
|
---|
[6613ec] | 1162 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1163 | }
|
---|
| 1164 | ;
|
---|
| 1165 |
|
---|
| 1166 | /** Destructor of class Tesselation.
|
---|
| 1167 | * We have to free all points, lines and triangles.
|
---|
| 1168 | */
|
---|
| 1169 | Tesselation::~Tesselation()
|
---|
| 1170 | {
|
---|
[6613ec] | 1171 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1172 | DoLog(0) && (Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl);
|
---|
[357fba] | 1173 | for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
|
---|
| 1174 | if (runner->second != NULL) {
|
---|
| 1175 | delete (runner->second);
|
---|
| 1176 | runner->second = NULL;
|
---|
| 1177 | } else
|
---|
[6613ec] | 1178 | DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);
|
---|
[357fba] | 1179 | }
|
---|
[a67d19] | 1180 | DoLog(0) && (Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl);
|
---|
[357fba] | 1181 | }
|
---|
| 1182 | ;
|
---|
| 1183 |
|
---|
[5c7bf8] | 1184 | /** PointCloud implementation of GetCenter
|
---|
| 1185 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1186 | */
|
---|
[776b64] | 1187 | Vector * Tesselation::GetCenter(ofstream *out) const
|
---|
[5c7bf8] | 1188 | {
|
---|
[6613ec] | 1189 | Info FunctionInfo(__func__);
|
---|
| 1190 | Vector *Center = new Vector(0., 0., 0.);
|
---|
| 1191 | int num = 0;
|
---|
[5c7bf8] | 1192 | for (GoToFirst(); (!IsEnd()); GoToNext()) {
|
---|
[273382] | 1193 | (*Center) += (*GetPoint()->node);
|
---|
[5c7bf8] | 1194 | num++;
|
---|
| 1195 | }
|
---|
[6613ec] | 1196 | Center->Scale(1. / num);
|
---|
[5c7bf8] | 1197 | return Center;
|
---|
[6613ec] | 1198 | }
|
---|
| 1199 | ;
|
---|
[5c7bf8] | 1200 |
|
---|
| 1201 | /** PointCloud implementation of GoPoint
|
---|
| 1202 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1203 | */
|
---|
[776b64] | 1204 | TesselPoint * Tesselation::GetPoint() const
|
---|
[5c7bf8] | 1205 | {
|
---|
[6613ec] | 1206 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1207 | return (InternalPointer->second->node);
|
---|
[6613ec] | 1208 | }
|
---|
| 1209 | ;
|
---|
[5c7bf8] | 1210 |
|
---|
| 1211 | /** PointCloud implementation of GetTerminalPoint.
|
---|
| 1212 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1213 | */
|
---|
[776b64] | 1214 | TesselPoint * Tesselation::GetTerminalPoint() const
|
---|
[5c7bf8] | 1215 | {
|
---|
[6613ec] | 1216 | Info FunctionInfo(__func__);
|
---|
[776b64] | 1217 | PointMap::const_iterator Runner = PointsOnBoundary.end();
|
---|
[5c7bf8] | 1218 | Runner--;
|
---|
| 1219 | return (Runner->second->node);
|
---|
[6613ec] | 1220 | }
|
---|
| 1221 | ;
|
---|
[5c7bf8] | 1222 |
|
---|
| 1223 | /** PointCloud implementation of GoToNext.
|
---|
| 1224 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1225 | */
|
---|
[776b64] | 1226 | void Tesselation::GoToNext() const
|
---|
[5c7bf8] | 1227 | {
|
---|
[6613ec] | 1228 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1229 | if (InternalPointer != PointsOnBoundary.end())
|
---|
| 1230 | InternalPointer++;
|
---|
[6613ec] | 1231 | }
|
---|
| 1232 | ;
|
---|
[5c7bf8] | 1233 |
|
---|
| 1234 | /** PointCloud implementation of GoToPrevious.
|
---|
| 1235 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1236 | */
|
---|
[776b64] | 1237 | void Tesselation::GoToPrevious() const
|
---|
[5c7bf8] | 1238 | {
|
---|
[6613ec] | 1239 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1240 | if (InternalPointer != PointsOnBoundary.begin())
|
---|
| 1241 | InternalPointer--;
|
---|
[6613ec] | 1242 | }
|
---|
| 1243 | ;
|
---|
[5c7bf8] | 1244 |
|
---|
| 1245 | /** PointCloud implementation of GoToFirst.
|
---|
| 1246 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1247 | */
|
---|
[776b64] | 1248 | void Tesselation::GoToFirst() const
|
---|
[5c7bf8] | 1249 | {
|
---|
[6613ec] | 1250 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1251 | InternalPointer = PointsOnBoundary.begin();
|
---|
[6613ec] | 1252 | }
|
---|
| 1253 | ;
|
---|
[5c7bf8] | 1254 |
|
---|
| 1255 | /** PointCloud implementation of GoToLast.
|
---|
| 1256 | * Uses PointsOnBoundary and STL stuff.
|
---|
[776b64] | 1257 | */
|
---|
| 1258 | void Tesselation::GoToLast() const
|
---|
[5c7bf8] | 1259 | {
|
---|
[6613ec] | 1260 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1261 | InternalPointer = PointsOnBoundary.end();
|
---|
| 1262 | InternalPointer--;
|
---|
[6613ec] | 1263 | }
|
---|
| 1264 | ;
|
---|
[5c7bf8] | 1265 |
|
---|
| 1266 | /** PointCloud implementation of IsEmpty.
|
---|
| 1267 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1268 | */
|
---|
[776b64] | 1269 | bool Tesselation::IsEmpty() const
|
---|
[5c7bf8] | 1270 | {
|
---|
[6613ec] | 1271 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1272 | return (PointsOnBoundary.empty());
|
---|
[6613ec] | 1273 | }
|
---|
| 1274 | ;
|
---|
[5c7bf8] | 1275 |
|
---|
| 1276 | /** PointCloud implementation of IsLast.
|
---|
| 1277 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1278 | */
|
---|
[776b64] | 1279 | bool Tesselation::IsEnd() const
|
---|
[5c7bf8] | 1280 | {
|
---|
[6613ec] | 1281 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1282 | return (InternalPointer == PointsOnBoundary.end());
|
---|
[6613ec] | 1283 | }
|
---|
| 1284 | ;
|
---|
[5c7bf8] | 1285 |
|
---|
[357fba] | 1286 | /** Gueses first starting triangle of the convex envelope.
|
---|
| 1287 | * We guess the starting triangle by taking the smallest distance between two points and looking for a fitting third.
|
---|
| 1288 | * \param *out output stream for debugging
|
---|
| 1289 | * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
|
---|
| 1290 | */
|
---|
[244a84] | 1291 | void Tesselation::GuessStartingTriangle()
|
---|
[357fba] | 1292 | {
|
---|
[6613ec] | 1293 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1294 | // 4b. create a starting triangle
|
---|
| 1295 | // 4b1. create all distances
|
---|
| 1296 | DistanceMultiMap DistanceMMap;
|
---|
| 1297 | double distance, tmp;
|
---|
| 1298 | Vector PlaneVector, TrialVector;
|
---|
| 1299 | PointMap::iterator A, B, C; // three nodes of the first triangle
|
---|
| 1300 | A = PointsOnBoundary.begin(); // the first may be chosen arbitrarily
|
---|
| 1301 |
|
---|
| 1302 | // with A chosen, take each pair B,C and sort
|
---|
[6613ec] | 1303 | if (A != PointsOnBoundary.end()) {
|
---|
| 1304 | B = A;
|
---|
| 1305 | B++;
|
---|
| 1306 | for (; B != PointsOnBoundary.end(); B++) {
|
---|
| 1307 | C = B;
|
---|
| 1308 | C++;
|
---|
| 1309 | for (; C != PointsOnBoundary.end(); C++) {
|
---|
[8cbb97] | 1310 | tmp = A->second->node->node->DistanceSquared(*B->second->node->node);
|
---|
[6613ec] | 1311 | distance = tmp * tmp;
|
---|
[8cbb97] | 1312 | tmp = A->second->node->node->DistanceSquared(*C->second->node->node);
|
---|
[6613ec] | 1313 | distance += tmp * tmp;
|
---|
[8cbb97] | 1314 | tmp = B->second->node->node->DistanceSquared(*C->second->node->node);
|
---|
[6613ec] | 1315 | distance += tmp * tmp;
|
---|
| 1316 | DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
|
---|
| 1317 | }
|
---|
[357fba] | 1318 | }
|
---|
[6613ec] | 1319 | }
|
---|
[357fba] | 1320 | // // listing distances
|
---|
[e138de] | 1321 | // Log() << Verbose(1) << "Listing DistanceMMap:";
|
---|
[357fba] | 1322 | // for(DistanceMultiMap::iterator runner = DistanceMMap.begin(); runner != DistanceMMap.end(); runner++) {
|
---|
[e138de] | 1323 | // Log() << Verbose(0) << " " << runner->first << "(" << *runner->second.first->second << ", " << *runner->second.second->second << ")";
|
---|
[357fba] | 1324 | // }
|
---|
[e138de] | 1325 | // Log() << Verbose(0) << endl;
|
---|
[357fba] | 1326 | // 4b2. pick three baselines forming a triangle
|
---|
| 1327 | // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 1328 | DistanceMultiMap::iterator baseline = DistanceMMap.begin();
|
---|
[6613ec] | 1329 | for (; baseline != DistanceMMap.end(); baseline++) {
|
---|
| 1330 | // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 1331 | // 2. next, we have to check whether all points reside on only one side of the triangle
|
---|
| 1332 | // 3. construct plane vector
|
---|
[8cbb97] | 1333 | PlaneVector = Plane(*A->second->node->node,
|
---|
| 1334 | *baseline->second.first->second->node->node,
|
---|
| 1335 | *baseline->second.second->second->node->node).getNormal();
|
---|
[a67d19] | 1336 | DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl);
|
---|
[6613ec] | 1337 | // 4. loop over all points
|
---|
| 1338 | double sign = 0.;
|
---|
| 1339 | PointMap::iterator checker = PointsOnBoundary.begin();
|
---|
| 1340 | for (; checker != PointsOnBoundary.end(); checker++) {
|
---|
| 1341 | // (neglecting A,B,C)
|
---|
| 1342 | if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
|
---|
| 1343 | continue;
|
---|
| 1344 | // 4a. project onto plane vector
|
---|
[8cbb97] | 1345 | TrialVector = (*checker->second->node->node);
|
---|
| 1346 | TrialVector.SubtractVector(*A->second->node->node);
|
---|
| 1347 | distance = TrialVector.ScalarProduct(PlaneVector);
|
---|
[6613ec] | 1348 | if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
|
---|
| 1349 | continue;
|
---|
[a67d19] | 1350 | DoLog(2) && (Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl);
|
---|
[6613ec] | 1351 | tmp = distance / fabs(distance);
|
---|
| 1352 | // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
|
---|
| 1353 | if ((sign != 0) && (tmp != sign)) {
|
---|
| 1354 | // 4c. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
[a67d19] | 1355 | DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leaves " << checker->second->node->Name << " outside the convex hull." << endl);
|
---|
[6613ec] | 1356 | break;
|
---|
| 1357 | } else { // note the sign for later
|
---|
[a67d19] | 1358 | DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leave " << checker->second->node->Name << " inside the convex hull." << endl);
|
---|
[6613ec] | 1359 | sign = tmp;
|
---|
| 1360 | }
|
---|
| 1361 | // 4d. Check whether the point is inside the triangle (check distance to each node
|
---|
[8cbb97] | 1362 | tmp = checker->second->node->node->DistanceSquared(*A->second->node->node);
|
---|
[6613ec] | 1363 | int innerpoint = 0;
|
---|
[8cbb97] | 1364 | 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] | 1365 | innerpoint++;
|
---|
[8cbb97] | 1366 | tmp = checker->second->node->node->DistanceSquared(*baseline->second.first->second->node->node);
|
---|
| 1367 | 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] | 1368 | innerpoint++;
|
---|
[8cbb97] | 1369 | tmp = checker->second->node->node->DistanceSquared(*baseline->second.second->second->node->node);
|
---|
| 1370 | 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] | 1371 | innerpoint++;
|
---|
| 1372 | // 4e. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
| 1373 | if (innerpoint == 3)
|
---|
| 1374 | break;
|
---|
[357fba] | 1375 | }
|
---|
[6613ec] | 1376 | // 5. come this far, all on same side? Then break 1. loop and construct triangle
|
---|
| 1377 | if (checker == PointsOnBoundary.end()) {
|
---|
[a67d19] | 1378 | DoLog(2) && (Log() << Verbose(2) << "Looks like we have a candidate!" << endl);
|
---|
[6613ec] | 1379 | break;
|
---|
[357fba] | 1380 | }
|
---|
[6613ec] | 1381 | }
|
---|
| 1382 | if (baseline != DistanceMMap.end()) {
|
---|
| 1383 | BPS[0] = baseline->second.first->second;
|
---|
| 1384 | BPS[1] = baseline->second.second->second;
|
---|
| 1385 | BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1386 | BPS[0] = A->second;
|
---|
| 1387 | BPS[1] = baseline->second.second->second;
|
---|
| 1388 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1389 | BPS[0] = baseline->second.first->second;
|
---|
| 1390 | BPS[1] = A->second;
|
---|
| 1391 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1392 |
|
---|
| 1393 | // 4b3. insert created triangle
|
---|
| 1394 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 1395 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1396 | TrianglesOnBoundaryCount++;
|
---|
| 1397 | for (int i = 0; i < NDIM; i++) {
|
---|
| 1398 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
|
---|
| 1399 | LinesOnBoundaryCount++;
|
---|
[357fba] | 1400 | }
|
---|
[6613ec] | 1401 |
|
---|
[a67d19] | 1402 | DoLog(1) && (Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl);
|
---|
[6613ec] | 1403 | } else {
|
---|
| 1404 | DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl);
|
---|
| 1405 | }
|
---|
[357fba] | 1406 | }
|
---|
| 1407 | ;
|
---|
| 1408 |
|
---|
| 1409 | /** Tesselates the convex envelope of a cluster from a single starting triangle.
|
---|
| 1410 | * The starting triangle is made out of three baselines. Each line in the final tesselated cluster may belong to at most
|
---|
| 1411 | * 2 triangles. Hence, we go through all current lines:
|
---|
| 1412 | * -# if the lines contains to only one triangle
|
---|
| 1413 | * -# We search all points in the boundary
|
---|
| 1414 | * -# if the triangle is in forward direction of the baseline (at most 90 degrees angle between vector orthogonal to
|
---|
| 1415 | * baseline in triangle plane pointing out of the triangle and normal vector of new triangle)
|
---|
| 1416 | * -# if the triangle with the baseline and the current point has the smallest of angles (comparison between normal vectors)
|
---|
| 1417 | * -# then we have a new triangle, whose baselines we again add (or increase their TriangleCount)
|
---|
| 1418 | * \param *out output stream for debugging
|
---|
| 1419 | * \param *configuration for IsAngstroem
|
---|
| 1420 | * \param *cloud cluster of points
|
---|
| 1421 | */
|
---|
[e138de] | 1422 | void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
|
---|
[357fba] | 1423 | {
|
---|
[6613ec] | 1424 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1425 | bool flag;
|
---|
| 1426 | PointMap::iterator winner;
|
---|
| 1427 | class BoundaryPointSet *peak = NULL;
|
---|
| 1428 | double SmallestAngle, TempAngle;
|
---|
| 1429 | Vector NormalVector, VirtualNormalVector, CenterVector, TempVector, helper, PropagationVector, *Center = NULL;
|
---|
| 1430 | LineMap::iterator LineChecker[2];
|
---|
| 1431 |
|
---|
[e138de] | 1432 | Center = cloud->GetCenter();
|
---|
[357fba] | 1433 | // create a first tesselation with the given BoundaryPoints
|
---|
| 1434 | do {
|
---|
| 1435 | flag = false;
|
---|
| 1436 | for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++)
|
---|
[5c7bf8] | 1437 | if (baseline->second->triangles.size() == 1) {
|
---|
[357fba] | 1438 | // 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)
|
---|
| 1439 | SmallestAngle = M_PI;
|
---|
| 1440 |
|
---|
| 1441 | // get peak point with respect to this base line's only triangle
|
---|
| 1442 | BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
|
---|
[a67d19] | 1443 | DoLog(0) && (Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl);
|
---|
[357fba] | 1444 | for (int i = 0; i < 3; i++)
|
---|
| 1445 | if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
|
---|
| 1446 | peak = BTS->endpoints[i];
|
---|
[a67d19] | 1447 | DoLog(1) && (Log() << Verbose(1) << " and has peak " << *peak << "." << endl);
|
---|
[357fba] | 1448 |
|
---|
| 1449 | // prepare some auxiliary vectors
|
---|
| 1450 | Vector BaseLineCenter, BaseLine;
|
---|
[273382] | 1451 | BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) +
|
---|
| 1452 | (*baseline->second->endpoints[1]->node->node));
|
---|
| 1453 | BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node);
|
---|
[357fba] | 1454 |
|
---|
| 1455 | // offset to center of triangle
|
---|
| 1456 | CenterVector.Zero();
|
---|
| 1457 | for (int i = 0; i < 3; i++)
|
---|
[273382] | 1458 | CenterVector += (*BTS->endpoints[i]->node->node);
|
---|
[357fba] | 1459 | CenterVector.Scale(1. / 3.);
|
---|
[a67d19] | 1460 | DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
|
---|
[357fba] | 1461 |
|
---|
| 1462 | // normal vector of triangle
|
---|
[273382] | 1463 | NormalVector = (*Center) - CenterVector;
|
---|
[357fba] | 1464 | BTS->GetNormalVector(NormalVector);
|
---|
[273382] | 1465 | NormalVector = BTS->NormalVector;
|
---|
[a67d19] | 1466 | DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl);
|
---|
[357fba] | 1467 |
|
---|
| 1468 | // vector in propagation direction (out of triangle)
|
---|
| 1469 | // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
|
---|
[0a4f7f] | 1470 | PropagationVector = Plane(BaseLine, NormalVector,0).getNormal();
|
---|
[273382] | 1471 | TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
|
---|
[f67b6e] | 1472 | //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
|
---|
[273382] | 1473 | if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline
|
---|
[357fba] | 1474 | PropagationVector.Scale(-1.);
|
---|
[a67d19] | 1475 | DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl);
|
---|
[357fba] | 1476 | winner = PointsOnBoundary.end();
|
---|
| 1477 |
|
---|
| 1478 | // loop over all points and calculate angle between normal vector of new and present triangle
|
---|
| 1479 | for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
|
---|
| 1480 | if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
|
---|
[a67d19] | 1481 | DoLog(1) && (Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl);
|
---|
[357fba] | 1482 |
|
---|
| 1483 | // first check direction, so that triangles don't intersect
|
---|
[273382] | 1484 | VirtualNormalVector = (*target->second->node->node) - BaseLineCenter;
|
---|
[8cbb97] | 1485 | VirtualNormalVector.ProjectOntoPlane(NormalVector);
|
---|
[273382] | 1486 | TempAngle = VirtualNormalVector.Angle(PropagationVector);
|
---|
[a67d19] | 1487 | DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl);
|
---|
[6613ec] | 1488 | if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
|
---|
[a67d19] | 1489 | DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl);
|
---|
[357fba] | 1490 | continue;
|
---|
| 1491 | } else
|
---|
[a67d19] | 1492 | DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl);
|
---|
[357fba] | 1493 |
|
---|
| 1494 | // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
|
---|
| 1495 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(target->first);
|
---|
| 1496 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
|
---|
[5c7bf8] | 1497 | if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
|
---|
[a67d19] | 1498 | 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] | 1499 | continue;
|
---|
| 1500 | }
|
---|
[5c7bf8] | 1501 | if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
|
---|
[a67d19] | 1502 | 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] | 1503 | continue;
|
---|
| 1504 | }
|
---|
| 1505 |
|
---|
| 1506 | // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
|
---|
| 1507 | 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] | 1508 | DoLog(4) && (Log() << Verbose(4) << "Current target is peak!" << endl);
|
---|
[357fba] | 1509 | continue;
|
---|
| 1510 | }
|
---|
| 1511 |
|
---|
| 1512 | // check for linear dependence
|
---|
[273382] | 1513 | TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node);
|
---|
| 1514 | helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node);
|
---|
| 1515 | helper.ProjectOntoPlane(TempVector);
|
---|
[357fba] | 1516 | if (fabs(helper.NormSquared()) < MYEPSILON) {
|
---|
[a67d19] | 1517 | DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl);
|
---|
[357fba] | 1518 | continue;
|
---|
| 1519 | }
|
---|
| 1520 |
|
---|
| 1521 | // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
|
---|
| 1522 | flag = true;
|
---|
[0a4f7f] | 1523 | VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node),
|
---|
| 1524 | *(baseline->second->endpoints[1]->node->node),
|
---|
| 1525 | *(target->second->node->node)).getNormal();
|
---|
[273382] | 1526 | TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) +
|
---|
| 1527 | (*baseline->second->endpoints[1]->node->node) +
|
---|
| 1528 | (*target->second->node->node));
|
---|
| 1529 | TempVector -= (*Center);
|
---|
[357fba] | 1530 | // make it always point outward
|
---|
[273382] | 1531 | if (VirtualNormalVector.ScalarProduct(TempVector) < 0)
|
---|
[357fba] | 1532 | VirtualNormalVector.Scale(-1.);
|
---|
| 1533 | // calculate angle
|
---|
[273382] | 1534 | TempAngle = NormalVector.Angle(VirtualNormalVector);
|
---|
[a67d19] | 1535 | DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl);
|
---|
[357fba] | 1536 | if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
|
---|
| 1537 | SmallestAngle = TempAngle;
|
---|
| 1538 | winner = target;
|
---|
[a67d19] | 1539 | DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
|
---|
[357fba] | 1540 | } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
|
---|
| 1541 | // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
|
---|
[273382] | 1542 | helper = (*target->second->node->node) - BaseLineCenter;
|
---|
| 1543 | helper.ProjectOntoPlane(BaseLine);
|
---|
[357fba] | 1544 | // ...the one with the smaller angle is the better candidate
|
---|
[273382] | 1545 | TempVector = (*target->second->node->node) - BaseLineCenter;
|
---|
| 1546 | TempVector.ProjectOntoPlane(VirtualNormalVector);
|
---|
| 1547 | TempAngle = TempVector.Angle(helper);
|
---|
| 1548 | TempVector = (*winner->second->node->node) - BaseLineCenter;
|
---|
| 1549 | TempVector.ProjectOntoPlane(VirtualNormalVector);
|
---|
| 1550 | if (TempAngle < TempVector.Angle(helper)) {
|
---|
| 1551 | TempAngle = NormalVector.Angle(VirtualNormalVector);
|
---|
[357fba] | 1552 | SmallestAngle = TempAngle;
|
---|
| 1553 | winner = target;
|
---|
[a67d19] | 1554 | DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl);
|
---|
[357fba] | 1555 | } else
|
---|
[a67d19] | 1556 | DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl);
|
---|
[357fba] | 1557 | } else
|
---|
[a67d19] | 1558 | DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
|
---|
[357fba] | 1559 | }
|
---|
| 1560 | } // end of loop over all boundary points
|
---|
| 1561 |
|
---|
| 1562 | // 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
|
---|
| 1563 | if (winner != PointsOnBoundary.end()) {
|
---|
[a67d19] | 1564 | DoLog(0) && (Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl);
|
---|
[357fba] | 1565 | // create the lins of not yet present
|
---|
| 1566 | BLS[0] = baseline->second;
|
---|
| 1567 | // 5c. add lines to the line set if those were new (not yet part of a triangle), delete lines that belong to two triangles)
|
---|
| 1568 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(winner->first);
|
---|
| 1569 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(winner->first);
|
---|
| 1570 | if (LineChecker[0] == baseline->second->endpoints[0]->lines.end()) { // create
|
---|
| 1571 | BPS[0] = baseline->second->endpoints[0];
|
---|
| 1572 | BPS[1] = winner->second;
|
---|
| 1573 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1574 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[1]));
|
---|
| 1575 | LinesOnBoundaryCount++;
|
---|
| 1576 | } else
|
---|
| 1577 | BLS[1] = LineChecker[0]->second;
|
---|
| 1578 | if (LineChecker[1] == baseline->second->endpoints[1]->lines.end()) { // create
|
---|
| 1579 | BPS[0] = baseline->second->endpoints[1];
|
---|
| 1580 | BPS[1] = winner->second;
|
---|
| 1581 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1582 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[2]));
|
---|
| 1583 | LinesOnBoundaryCount++;
|
---|
| 1584 | } else
|
---|
| 1585 | BLS[2] = LineChecker[1]->second;
|
---|
| 1586 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[62bb91] | 1587 | BTS->GetCenter(&helper);
|
---|
[273382] | 1588 | helper -= (*Center);
|
---|
| 1589 | helper *= -1;
|
---|
[62bb91] | 1590 | BTS->GetNormalVector(helper);
|
---|
[357fba] | 1591 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1592 | TrianglesOnBoundaryCount++;
|
---|
| 1593 | } else {
|
---|
[6613ec] | 1594 | DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);
|
---|
[357fba] | 1595 | }
|
---|
| 1596 |
|
---|
| 1597 | // 5d. If the set of lines is not yet empty, go to 5. and continue
|
---|
| 1598 | } else
|
---|
[a67d19] | 1599 | DoLog(0) && (Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl);
|
---|
[357fba] | 1600 | } while (flag);
|
---|
| 1601 |
|
---|
| 1602 | // exit
|
---|
[6613ec] | 1603 | delete (Center);
|
---|
| 1604 | }
|
---|
| 1605 | ;
|
---|
[357fba] | 1606 |
|
---|
[62bb91] | 1607 | /** Inserts all points outside of the tesselated surface into it by adding new triangles.
|
---|
[357fba] | 1608 | * \param *out output stream for debugging
|
---|
| 1609 | * \param *cloud cluster of points
|
---|
[62bb91] | 1610 | * \param *LC LinkedCell structure to find nearest point quickly
|
---|
[357fba] | 1611 | * \return true - all straddling points insert, false - something went wrong
|
---|
| 1612 | */
|
---|
[e138de] | 1613 | bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
|
---|
[357fba] | 1614 | {
|
---|
[6613ec] | 1615 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1616 | Vector Intersection, Normal;
|
---|
[357fba] | 1617 | TesselPoint *Walker = NULL;
|
---|
[e138de] | 1618 | Vector *Center = cloud->GetCenter();
|
---|
[c15ca2] | 1619 | TriangleList *triangles = NULL;
|
---|
[7dea7c] | 1620 | bool AddFlag = false;
|
---|
| 1621 | LinkedCell *BoundaryPoints = NULL;
|
---|
[62bb91] | 1622 |
|
---|
[357fba] | 1623 | cloud->GoToFirst();
|
---|
[7dea7c] | 1624 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
[6613ec] | 1625 | while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
|
---|
[7dea7c] | 1626 | if (AddFlag) {
|
---|
[6613ec] | 1627 | delete (BoundaryPoints);
|
---|
[7dea7c] | 1628 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
| 1629 | AddFlag = false;
|
---|
| 1630 | }
|
---|
[357fba] | 1631 | Walker = cloud->GetPoint();
|
---|
[a67d19] | 1632 | DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Walker << "." << endl);
|
---|
[357fba] | 1633 | // get the next triangle
|
---|
[c15ca2] | 1634 | triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
|
---|
[7dea7c] | 1635 | BTS = triangles->front();
|
---|
| 1636 | if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
|
---|
[a67d19] | 1637 | DoLog(0) && (Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl);
|
---|
[62bb91] | 1638 | cloud->GoToNext();
|
---|
| 1639 | continue;
|
---|
| 1640 | } else {
|
---|
[357fba] | 1641 | }
|
---|
[a67d19] | 1642 | DoLog(0) && (Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl);
|
---|
[357fba] | 1643 | // get the intersection point
|
---|
[e138de] | 1644 | if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
|
---|
[a67d19] | 1645 | DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl);
|
---|
[357fba] | 1646 | // we have the intersection, check whether in- or outside of boundary
|
---|
[273382] | 1647 | if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) {
|
---|
[357fba] | 1648 | // inside, next!
|
---|
[a67d19] | 1649 | DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1650 | } else {
|
---|
| 1651 | // outside!
|
---|
[a67d19] | 1652 | DoLog(0) && (Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1653 | class BoundaryLineSet *OldLines[3], *NewLines[3];
|
---|
| 1654 | class BoundaryPointSet *OldPoints[3], *NewPoint;
|
---|
| 1655 | // store the three old lines and old points
|
---|
[6613ec] | 1656 | for (int i = 0; i < 3; i++) {
|
---|
[357fba] | 1657 | OldLines[i] = BTS->lines[i];
|
---|
| 1658 | OldPoints[i] = BTS->endpoints[i];
|
---|
| 1659 | }
|
---|
[273382] | 1660 | Normal = BTS->NormalVector;
|
---|
[357fba] | 1661 | // add Walker to boundary points
|
---|
[a67d19] | 1662 | DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl);
|
---|
[7dea7c] | 1663 | AddFlag = true;
|
---|
[6613ec] | 1664 | if (AddBoundaryPoint(Walker, 0))
|
---|
[357fba] | 1665 | NewPoint = BPS[0];
|
---|
| 1666 | else
|
---|
| 1667 | continue;
|
---|
| 1668 | // remove triangle
|
---|
[a67d19] | 1669 | DoLog(0) && (Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1670 | TrianglesOnBoundary.erase(BTS->Nr);
|
---|
[6613ec] | 1671 | delete (BTS);
|
---|
[357fba] | 1672 | // create three new boundary lines
|
---|
[6613ec] | 1673 | for (int i = 0; i < 3; i++) {
|
---|
[357fba] | 1674 | BPS[0] = NewPoint;
|
---|
| 1675 | BPS[1] = OldPoints[i];
|
---|
| 1676 | NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
[a67d19] | 1677 | DoLog(1) && (Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl);
|
---|
[357fba] | 1678 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
|
---|
| 1679 | LinesOnBoundaryCount++;
|
---|
| 1680 | }
|
---|
| 1681 | // create three new triangle with new point
|
---|
[6613ec] | 1682 | for (int i = 0; i < 3; i++) { // find all baselines
|
---|
[357fba] | 1683 | BLS[0] = OldLines[i];
|
---|
| 1684 | int n = 1;
|
---|
[6613ec] | 1685 | for (int j = 0; j < 3; j++) {
|
---|
[357fba] | 1686 | if (NewLines[j]->IsConnectedTo(BLS[0])) {
|
---|
[6613ec] | 1687 | if (n > 2) {
|
---|
| 1688 | DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);
|
---|
[357fba] | 1689 | return false;
|
---|
| 1690 | } else
|
---|
| 1691 | BLS[n++] = NewLines[j];
|
---|
| 1692 | }
|
---|
| 1693 | }
|
---|
| 1694 | // create the triangle
|
---|
| 1695 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[5c7bf8] | 1696 | Normal.Scale(-1.);
|
---|
| 1697 | BTS->GetNormalVector(Normal);
|
---|
| 1698 | Normal.Scale(-1.);
|
---|
[a67d19] | 1699 | DoLog(0) && (Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1700 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1701 | TrianglesOnBoundaryCount++;
|
---|
| 1702 | }
|
---|
| 1703 | }
|
---|
| 1704 | } else { // something is wrong with FindClosestTriangleToPoint!
|
---|
[6613ec] | 1705 | DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl);
|
---|
[357fba] | 1706 | return false;
|
---|
| 1707 | }
|
---|
| 1708 | cloud->GoToNext();
|
---|
| 1709 | }
|
---|
| 1710 |
|
---|
| 1711 | // exit
|
---|
[6613ec] | 1712 | delete (Center);
|
---|
[357fba] | 1713 | return true;
|
---|
[6613ec] | 1714 | }
|
---|
| 1715 | ;
|
---|
[357fba] | 1716 |
|
---|
[16d866] | 1717 | /** Adds a point to the tesselation::PointsOnBoundary list.
|
---|
[62bb91] | 1718 | * \param *Walker point to add
|
---|
[08ef35] | 1719 | * \param n TesselStruct::BPS index to put pointer into
|
---|
| 1720 | * \return true - new point was added, false - point already present
|
---|
[357fba] | 1721 | */
|
---|
[776b64] | 1722 | bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
|
---|
[357fba] | 1723 | {
|
---|
[6613ec] | 1724 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1725 | PointTestPair InsertUnique;
|
---|
[08ef35] | 1726 | BPS[n] = new class BoundaryPointSet(Walker);
|
---|
| 1727 | InsertUnique = PointsOnBoundary.insert(PointPair(Walker->nr, BPS[n]));
|
---|
| 1728 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
[357fba] | 1729 | PointsOnBoundaryCount++;
|
---|
[08ef35] | 1730 | return true;
|
---|
| 1731 | } else {
|
---|
[6613ec] | 1732 | delete (BPS[n]);
|
---|
[08ef35] | 1733 | BPS[n] = InsertUnique.first->second;
|
---|
| 1734 | return false;
|
---|
[357fba] | 1735 | }
|
---|
| 1736 | }
|
---|
| 1737 | ;
|
---|
| 1738 |
|
---|
| 1739 | /** Adds point to Tesselation::PointsOnBoundary if not yet present.
|
---|
| 1740 | * Tesselation::TPS is set to either this new BoundaryPointSet or to the existing one of not unique.
|
---|
| 1741 | * @param Candidate point to add
|
---|
| 1742 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1743 | */
|
---|
[776b64] | 1744 | void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
|
---|
[357fba] | 1745 | {
|
---|
[6613ec] | 1746 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1747 | PointTestPair InsertUnique;
|
---|
| 1748 | TPS[n] = new class BoundaryPointSet(Candidate);
|
---|
| 1749 | InsertUnique = PointsOnBoundary.insert(PointPair(Candidate->nr, TPS[n]));
|
---|
| 1750 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
| 1751 | PointsOnBoundaryCount++;
|
---|
| 1752 | } else {
|
---|
| 1753 | delete TPS[n];
|
---|
[a67d19] | 1754 | DoLog(0) && (Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl);
|
---|
[357fba] | 1755 | TPS[n] = (InsertUnique.first)->second;
|
---|
| 1756 | }
|
---|
| 1757 | }
|
---|
| 1758 | ;
|
---|
| 1759 |
|
---|
[f1ef60a] | 1760 | /** Sets point to a present Tesselation::PointsOnBoundary.
|
---|
| 1761 | * Tesselation::TPS is set to the existing one or NULL if not found.
|
---|
| 1762 | * @param Candidate point to set to
|
---|
| 1763 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1764 | */
|
---|
| 1765 | void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
|
---|
| 1766 | {
|
---|
[6613ec] | 1767 | Info FunctionInfo(__func__);
|
---|
[f1ef60a] | 1768 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
|
---|
| 1769 | if (FindPoint != PointsOnBoundary.end())
|
---|
| 1770 | TPS[n] = FindPoint->second;
|
---|
| 1771 | else
|
---|
| 1772 | TPS[n] = NULL;
|
---|
[6613ec] | 1773 | }
|
---|
| 1774 | ;
|
---|
[f1ef60a] | 1775 |
|
---|
[357fba] | 1776 | /** Function tries to add line from current Points in BPS to BoundaryLineSet.
|
---|
| 1777 | * If successful it raises the line count and inserts the new line into the BLS,
|
---|
| 1778 | * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
|
---|
[f07f86d] | 1779 | * @param *OptCenter desired OptCenter if there are more than one candidate line
|
---|
[d5fea7] | 1780 | * @param *candidate third point of the triangle to be, for checking between multiple open line candidates
|
---|
[357fba] | 1781 | * @param *a first endpoint
|
---|
| 1782 | * @param *b second endpoint
|
---|
| 1783 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1784 | */
|
---|
[6613ec] | 1785 | void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
|
---|
| 1786 | {
|
---|
[357fba] | 1787 | bool insertNewLine = true;
|
---|
[b998c3] | 1788 | LineMap::iterator FindLine = a->lines.find(b->node->nr);
|
---|
[d5fea7] | 1789 | BoundaryLineSet *WinningLine = NULL;
|
---|
[b998c3] | 1790 | if (FindLine != a->lines.end()) {
|
---|
[a67d19] | 1791 | DoLog(1) && (Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl);
|
---|
[b998c3] | 1792 |
|
---|
[6613ec] | 1793 | pair<LineMap::iterator, LineMap::iterator> FindPair;
|
---|
[357fba] | 1794 | FindPair = a->lines.equal_range(b->node->nr);
|
---|
| 1795 |
|
---|
[6613ec] | 1796 | for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) {
|
---|
[a67d19] | 1797 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
|
---|
[357fba] | 1798 | // If there is a line with less than two attached triangles, we don't need a new line.
|
---|
[d5fea7] | 1799 | if (FindLine->second->triangles.size() == 1) {
|
---|
| 1800 | CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
|
---|
[f07f86d] | 1801 | if (!Finder->second->pointlist.empty())
|
---|
[a67d19] | 1802 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
|
---|
[f07f86d] | 1803 | else
|
---|
[a67d19] | 1804 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl);
|
---|
[f07f86d] | 1805 | // get open line
|
---|
[6613ec] | 1806 | for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
|
---|
[8cbb97] | 1807 | if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
|
---|
[b0a5f1] | 1808 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl);
|
---|
[6613ec] | 1809 | insertNewLine = false;
|
---|
| 1810 | WinningLine = FindLine->second;
|
---|
| 1811 | break;
|
---|
[b0a5f1] | 1812 | } else {
|
---|
| 1813 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *(*CandidateChecker) << "'s center " << Finder->second->OptCenter << " does not match desired on " << *OptCenter << "." << endl);
|
---|
[6613ec] | 1814 | }
|
---|
[856098] | 1815 | }
|
---|
[357fba] | 1816 | }
|
---|
| 1817 | }
|
---|
| 1818 | }
|
---|
| 1819 |
|
---|
| 1820 | if (insertNewLine) {
|
---|
[474961] | 1821 | AddNewTesselationTriangleLine(a, b, n);
|
---|
[d5fea7] | 1822 | } else {
|
---|
| 1823 | AddExistingTesselationTriangleLine(WinningLine, n);
|
---|
[357fba] | 1824 | }
|
---|
| 1825 | }
|
---|
| 1826 | ;
|
---|
| 1827 |
|
---|
| 1828 | /**
|
---|
| 1829 | * Adds lines from each of the current points in the BPS to BoundaryLineSet.
|
---|
| 1830 | * Raises the line count and inserts the new line into the BLS.
|
---|
| 1831 | *
|
---|
| 1832 | * @param *a first endpoint
|
---|
| 1833 | * @param *b second endpoint
|
---|
| 1834 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1835 | */
|
---|
[474961] | 1836 | void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
|
---|
[357fba] | 1837 | {
|
---|
[6613ec] | 1838 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1839 | DoLog(0) && (Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl);
|
---|
[357fba] | 1840 | BPS[0] = a;
|
---|
| 1841 | BPS[1] = b;
|
---|
[6613ec] | 1842 | BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
|
---|
[357fba] | 1843 | // add line to global map
|
---|
| 1844 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
|
---|
| 1845 | // increase counter
|
---|
| 1846 | LinesOnBoundaryCount++;
|
---|
[1e168b] | 1847 | // also add to open lines
|
---|
| 1848 | CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
|
---|
[6613ec] | 1849 | OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
|
---|
| 1850 | }
|
---|
| 1851 | ;
|
---|
[357fba] | 1852 |
|
---|
[474961] | 1853 | /** Uses an existing line for a new triangle.
|
---|
| 1854 | * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines.
|
---|
| 1855 | * \param *FindLine the line to add
|
---|
| 1856 | * \param n index of the line to set in Tesselation::BLS
|
---|
| 1857 | */
|
---|
| 1858 | void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n)
|
---|
| 1859 | {
|
---|
| 1860 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1861 | DoLog(0) && (Log() << Verbose(0) << "Using existing line " << *Line << endl);
|
---|
[474961] | 1862 |
|
---|
| 1863 | // set endpoints and line
|
---|
| 1864 | BPS[0] = Line->endpoints[0];
|
---|
| 1865 | BPS[1] = Line->endpoints[1];
|
---|
| 1866 | BLS[n] = Line;
|
---|
| 1867 | // remove existing line from OpenLines
|
---|
| 1868 | CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
|
---|
| 1869 | if (CandidateLine != OpenLines.end()) {
|
---|
[a67d19] | 1870 | DoLog(1) && (Log() << Verbose(1) << " Removing line from OpenLines." << endl);
|
---|
[6613ec] | 1871 | delete (CandidateLine->second);
|
---|
[474961] | 1872 | OpenLines.erase(CandidateLine);
|
---|
| 1873 | } else {
|
---|
[6613ec] | 1874 | DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
|
---|
[474961] | 1875 | }
|
---|
[6613ec] | 1876 | }
|
---|
| 1877 | ;
|
---|
[357fba] | 1878 |
|
---|
[7dea7c] | 1879 | /** Function adds triangle to global list.
|
---|
| 1880 | * Furthermore, the triangle receives the next free id and id counter \a TrianglesOnBoundaryCount is increased.
|
---|
[357fba] | 1881 | */
|
---|
[16d866] | 1882 | void Tesselation::AddTesselationTriangle()
|
---|
[357fba] | 1883 | {
|
---|
[6613ec] | 1884 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1885 | DoLog(1) && (Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl);
|
---|
[357fba] | 1886 |
|
---|
| 1887 | // add triangle to global map
|
---|
| 1888 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1889 | TrianglesOnBoundaryCount++;
|
---|
| 1890 |
|
---|
[57066a] | 1891 | // set as last new triangle
|
---|
| 1892 | LastTriangle = BTS;
|
---|
| 1893 |
|
---|
[357fba] | 1894 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
[6613ec] | 1895 | }
|
---|
| 1896 | ;
|
---|
[16d866] | 1897 |
|
---|
[7dea7c] | 1898 | /** Function adds triangle to global list.
|
---|
| 1899 | * Furthermore, the triangle number is set to \a nr.
|
---|
| 1900 | * \param nr triangle number
|
---|
| 1901 | */
|
---|
[776b64] | 1902 | void Tesselation::AddTesselationTriangle(const int nr)
|
---|
[7dea7c] | 1903 | {
|
---|
[6613ec] | 1904 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1905 | DoLog(0) && (Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl);
|
---|
[7dea7c] | 1906 |
|
---|
| 1907 | // add triangle to global map
|
---|
| 1908 | TrianglesOnBoundary.insert(TrianglePair(nr, BTS));
|
---|
| 1909 |
|
---|
| 1910 | // set as last new triangle
|
---|
| 1911 | LastTriangle = BTS;
|
---|
| 1912 |
|
---|
| 1913 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
[6613ec] | 1914 | }
|
---|
| 1915 | ;
|
---|
[7dea7c] | 1916 |
|
---|
[16d866] | 1917 | /** Removes a triangle from the tesselation.
|
---|
| 1918 | * Removes itself from the TriangleMap's of its lines, calls for them RemoveTriangleLine() if they are no more connected.
|
---|
| 1919 | * Removes itself from memory.
|
---|
| 1920 | * \param *triangle to remove
|
---|
| 1921 | */
|
---|
| 1922 | void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
|
---|
| 1923 | {
|
---|
[6613ec] | 1924 | Info FunctionInfo(__func__);
|
---|
[16d866] | 1925 | if (triangle == NULL)
|
---|
| 1926 | return;
|
---|
| 1927 | for (int i = 0; i < 3; i++) {
|
---|
| 1928 | if (triangle->lines[i] != NULL) {
|
---|
[a67d19] | 1929 | DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl);
|
---|
[16d866] | 1930 | triangle->lines[i]->triangles.erase(triangle->Nr);
|
---|
| 1931 | if (triangle->lines[i]->triangles.empty()) {
|
---|
[a67d19] | 1932 | DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl);
|
---|
[6613ec] | 1933 | RemoveTesselationLine(triangle->lines[i]);
|
---|
[065e82] | 1934 | } else {
|
---|
[a67d19] | 1935 | DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ");
|
---|
[6613ec] | 1936 | OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
|
---|
| 1937 | for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
|
---|
[a67d19] | 1938 | DoLog(0) && (Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t");
|
---|
| 1939 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[6613ec] | 1940 | // for (int j=0;j<2;j++) {
|
---|
| 1941 | // Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
|
---|
| 1942 | // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
|
---|
| 1943 | // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
|
---|
| 1944 | // Log() << Verbose(0) << endl;
|
---|
| 1945 | // }
|
---|
[065e82] | 1946 | }
|
---|
[6613ec] | 1947 | triangle->lines[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 1948 | } else
|
---|
[6613ec] | 1949 | DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl);
|
---|
[16d866] | 1950 | }
|
---|
| 1951 |
|
---|
| 1952 | if (TrianglesOnBoundary.erase(triangle->Nr))
|
---|
[a67d19] | 1953 | DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl);
|
---|
[6613ec] | 1954 | delete (triangle);
|
---|
| 1955 | }
|
---|
| 1956 | ;
|
---|
[16d866] | 1957 |
|
---|
| 1958 | /** Removes a line from the tesselation.
|
---|
| 1959 | * Removes itself from each endpoints' LineMap, then removes itself from global LinesOnBoundary list and free's the line.
|
---|
| 1960 | * \param *line line to remove
|
---|
| 1961 | */
|
---|
| 1962 | void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
|
---|
| 1963 | {
|
---|
[6613ec] | 1964 | Info FunctionInfo(__func__);
|
---|
[16d866] | 1965 | int Numbers[2];
|
---|
| 1966 |
|
---|
| 1967 | if (line == NULL)
|
---|
| 1968 | return;
|
---|
[065e82] | 1969 | // get other endpoint number for finding copies of same line
|
---|
[16d866] | 1970 | if (line->endpoints[1] != NULL)
|
---|
| 1971 | Numbers[0] = line->endpoints[1]->Nr;
|
---|
| 1972 | else
|
---|
| 1973 | Numbers[0] = -1;
|
---|
| 1974 | if (line->endpoints[0] != NULL)
|
---|
| 1975 | Numbers[1] = line->endpoints[0]->Nr;
|
---|
| 1976 | else
|
---|
| 1977 | Numbers[1] = -1;
|
---|
| 1978 |
|
---|
| 1979 | for (int i = 0; i < 2; i++) {
|
---|
| 1980 | if (line->endpoints[i] != NULL) {
|
---|
| 1981 | 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
|
---|
| 1982 | pair<LineMap::iterator, LineMap::iterator> erasor = line->endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 1983 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 1984 | if ((*Runner).second == line) {
|
---|
[a67d19] | 1985 | DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
|
---|
[16d866] | 1986 | line->endpoints[i]->lines.erase(Runner);
|
---|
| 1987 | break;
|
---|
| 1988 | }
|
---|
| 1989 | } else { // there's just a single line left
|
---|
| 1990 | if (line->endpoints[i]->lines.erase(line->Nr))
|
---|
[a67d19] | 1991 | DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
|
---|
[16d866] | 1992 | }
|
---|
| 1993 | if (line->endpoints[i]->lines.empty()) {
|
---|
[a67d19] | 1994 | DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl);
|
---|
[16d866] | 1995 | RemoveTesselationPoint(line->endpoints[i]);
|
---|
[065e82] | 1996 | } else {
|
---|
[a67d19] | 1997 | DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ");
|
---|
[6613ec] | 1998 | for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
|
---|
[a67d19] | 1999 | DoLog(0) && (Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t");
|
---|
| 2000 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[065e82] | 2001 | }
|
---|
[6613ec] | 2002 | line->endpoints[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 2003 | } else
|
---|
[6613ec] | 2004 | DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);
|
---|
[16d866] | 2005 | }
|
---|
| 2006 | if (!line->triangles.empty())
|
---|
[6613ec] | 2007 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);
|
---|
[16d866] | 2008 |
|
---|
| 2009 | if (LinesOnBoundary.erase(line->Nr))
|
---|
[a67d19] | 2010 | DoLog(0) && (Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl);
|
---|
[6613ec] | 2011 | delete (line);
|
---|
| 2012 | }
|
---|
| 2013 | ;
|
---|
[16d866] | 2014 |
|
---|
| 2015 | /** Removes a point from the tesselation.
|
---|
| 2016 | * Checks whether there are still lines connected, removes from global PointsOnBoundary list, then free's the point.
|
---|
| 2017 | * \note If a point should be removed, while keep the tesselated surface intact (i.e. closed), use RemovePointFromTesselatedSurface()
|
---|
| 2018 | * \param *point point to remove
|
---|
| 2019 | */
|
---|
| 2020 | void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
|
---|
| 2021 | {
|
---|
[6613ec] | 2022 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2023 | if (point == NULL)
|
---|
| 2024 | return;
|
---|
| 2025 | if (PointsOnBoundary.erase(point->Nr))
|
---|
[a67d19] | 2026 | DoLog(0) && (Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl);
|
---|
[6613ec] | 2027 | delete (point);
|
---|
| 2028 | }
|
---|
| 2029 | ;
|
---|
[f07f86d] | 2030 |
|
---|
| 2031 | /** Checks validity of a given sphere of a candidate line.
|
---|
| 2032 | * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
|
---|
[6613ec] | 2033 | * We check CandidateForTesselation::OtherOptCenter
|
---|
| 2034 | * \param &CandidateLine contains other degenerated candidates which we have to subtract as well
|
---|
[f07f86d] | 2035 | * \param RADIUS radius of sphere
|
---|
| 2036 | * \param *LC LinkedCell structure with other atoms
|
---|
| 2037 | * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
|
---|
| 2038 | */
|
---|
[6613ec] | 2039 | bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const
|
---|
[f07f86d] | 2040 | {
|
---|
| 2041 | Info FunctionInfo(__func__);
|
---|
| 2042 |
|
---|
| 2043 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
|
---|
| 2044 | bool flag = true;
|
---|
| 2045 |
|
---|
[8cbb97] | 2046 | DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30" << endl);
|
---|
[f07f86d] | 2047 | // get all points inside the sphere
|
---|
[6613ec] | 2048 | TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
|
---|
[f07f86d] | 2049 |
|
---|
[a67d19] | 2050 | DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
|
---|
[f07f86d] | 2051 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[1513a74] | 2052 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(CandidateLine.OtherOptCenter) << "." << endl);
|
---|
[f07f86d] | 2053 |
|
---|
| 2054 | // remove triangles's endpoints
|
---|
[6613ec] | 2055 | for (int i = 0; i < 2; i++)
|
---|
| 2056 | ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node);
|
---|
| 2057 |
|
---|
| 2058 | // remove other candidates
|
---|
| 2059 | for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner)
|
---|
| 2060 | ListofPoints->remove(*Runner);
|
---|
[f07f86d] | 2061 |
|
---|
| 2062 | // check for other points
|
---|
| 2063 | if (!ListofPoints->empty()) {
|
---|
[a67d19] | 2064 | DoLog(1) && (Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
|
---|
[f07f86d] | 2065 | flag = false;
|
---|
[a67d19] | 2066 | DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
|
---|
[f07f86d] | 2067 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[1513a74] | 2068 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(CandidateLine.OtherOptCenter) << "." << endl);
|
---|
[f07f86d] | 2069 | }
|
---|
[6613ec] | 2070 | delete (ListofPoints);
|
---|
[f07f86d] | 2071 |
|
---|
| 2072 | return flag;
|
---|
[6613ec] | 2073 | }
|
---|
| 2074 | ;
|
---|
[357fba] | 2075 |
|
---|
[62bb91] | 2076 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
[357fba] | 2077 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 2078 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 2079 | * returned.
|
---|
| 2080 | * \param *out output stream for debugging
|
---|
| 2081 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 2082 | * \return integer 0 if no triangle exists, 1 if one triangle exists, 2 if two
|
---|
| 2083 | * triangles exist which is the maximum for three points
|
---|
| 2084 | */
|
---|
[f1ef60a] | 2085 | int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
|
---|
| 2086 | {
|
---|
[6613ec] | 2087 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2088 | int adjacentTriangleCount = 0;
|
---|
| 2089 | class BoundaryPointSet *Points[3];
|
---|
| 2090 |
|
---|
| 2091 | // builds a triangle point set (Points) of the end points
|
---|
| 2092 | for (int i = 0; i < 3; i++) {
|
---|
[f1ef60a] | 2093 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
[357fba] | 2094 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2095 | Points[i] = FindPoint->second;
|
---|
| 2096 | } else {
|
---|
| 2097 | Points[i] = NULL;
|
---|
| 2098 | }
|
---|
| 2099 | }
|
---|
| 2100 |
|
---|
| 2101 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 2102 | for (int i = 0; i < 3; i++) {
|
---|
| 2103 | if (Points[i] != NULL) {
|
---|
| 2104 | for (int j = i; j < 3; j++) {
|
---|
| 2105 | if (Points[j] != NULL) {
|
---|
[f1ef60a] | 2106 | LineMap::const_iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
[357fba] | 2107 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 2108 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
[a67d19] | 2109 | DoLog(1) && (Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl);
|
---|
[f1ef60a] | 2110 | for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
[357fba] | 2111 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 2112 | adjacentTriangleCount++;
|
---|
| 2113 | }
|
---|
| 2114 | }
|
---|
[a67d19] | 2115 | DoLog(1) && (Log() << Verbose(1) << "end." << endl);
|
---|
[357fba] | 2116 | }
|
---|
| 2117 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[f67b6e] | 2118 | //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 2119 | //return adjacentTriangleCount;
|
---|
[357fba] | 2120 | }
|
---|
| 2121 | }
|
---|
| 2122 | }
|
---|
| 2123 | }
|
---|
| 2124 |
|
---|
[a67d19] | 2125 | DoLog(0) && (Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl);
|
---|
[357fba] | 2126 | return adjacentTriangleCount;
|
---|
[6613ec] | 2127 | }
|
---|
| 2128 | ;
|
---|
[357fba] | 2129 |
|
---|
[065e82] | 2130 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
| 2131 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 2132 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 2133 | * returned.
|
---|
| 2134 | * \param *out output stream for debugging
|
---|
| 2135 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 2136 | * \return NULL - none found or pointer to triangle
|
---|
| 2137 | */
|
---|
[e138de] | 2138 | class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
|
---|
[065e82] | 2139 | {
|
---|
[6613ec] | 2140 | Info FunctionInfo(__func__);
|
---|
[065e82] | 2141 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 2142 | class BoundaryPointSet *Points[3];
|
---|
| 2143 |
|
---|
| 2144 | // builds a triangle point set (Points) of the end points
|
---|
| 2145 | for (int i = 0; i < 3; i++) {
|
---|
| 2146 | PointMap::iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
| 2147 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2148 | Points[i] = FindPoint->second;
|
---|
| 2149 | } else {
|
---|
| 2150 | Points[i] = NULL;
|
---|
| 2151 | }
|
---|
| 2152 | }
|
---|
| 2153 |
|
---|
| 2154 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 2155 | for (int i = 0; i < 3; i++) {
|
---|
| 2156 | if (Points[i] != NULL) {
|
---|
| 2157 | for (int j = i; j < 3; j++) {
|
---|
| 2158 | if (Points[j] != NULL) {
|
---|
| 2159 | LineMap::iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
| 2160 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 2161 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
| 2162 | for (TriangleMap::iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
| 2163 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 2164 | if ((triangle == NULL) || (triangle->Nr > FindTriangle->second->Nr))
|
---|
| 2165 | triangle = FindTriangle->second;
|
---|
| 2166 | }
|
---|
| 2167 | }
|
---|
| 2168 | }
|
---|
| 2169 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[f67b6e] | 2170 | //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 2171 | //return adjacentTriangleCount;
|
---|
| 2172 | }
|
---|
| 2173 | }
|
---|
| 2174 | }
|
---|
| 2175 | }
|
---|
| 2176 |
|
---|
| 2177 | return triangle;
|
---|
[6613ec] | 2178 | }
|
---|
| 2179 | ;
|
---|
[357fba] | 2180 |
|
---|
[f1cccd] | 2181 | /** Finds the starting triangle for FindNonConvexBorder().
|
---|
| 2182 | * Looks at the outermost point per axis, then FindSecondPointForTesselation()
|
---|
| 2183 | * for the second and FindNextSuitablePointViaAngleOfSphere() for the third
|
---|
[357fba] | 2184 | * point are called.
|
---|
| 2185 | * \param *out output stream for debugging
|
---|
| 2186 | * \param RADIUS radius of virtual rolling sphere
|
---|
| 2187 | * \param *LC LinkedCell structure with neighbouring TesselPoint's
|
---|
[ce70970] | 2188 | * \return true - a starting triangle has been created, false - no valid triple of points found
|
---|
[357fba] | 2189 | */
|
---|
[ce70970] | 2190 | bool Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2191 | {
|
---|
[6613ec] | 2192 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2193 | int i = 0;
|
---|
[62bb91] | 2194 | TesselPoint* MaxPoint[NDIM];
|
---|
[7273fc] | 2195 | TesselPoint* Temporary;
|
---|
[f1cccd] | 2196 | double maxCoordinate[NDIM];
|
---|
[f07f86d] | 2197 | BoundaryLineSet *BaseLine = NULL;
|
---|
[357fba] | 2198 | Vector helper;
|
---|
| 2199 | Vector Chord;
|
---|
| 2200 | Vector SearchDirection;
|
---|
[6613ec] | 2201 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
[b998c3] | 2202 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 2203 | Vector SphereCenter;
|
---|
| 2204 | Vector NormalVector;
|
---|
[357fba] | 2205 |
|
---|
[b998c3] | 2206 | NormalVector.Zero();
|
---|
[357fba] | 2207 |
|
---|
| 2208 | for (i = 0; i < 3; i++) {
|
---|
[62bb91] | 2209 | MaxPoint[i] = NULL;
|
---|
[f1cccd] | 2210 | maxCoordinate[i] = -1;
|
---|
[357fba] | 2211 | }
|
---|
| 2212 |
|
---|
[62bb91] | 2213 | // 1. searching topmost point with respect to each axis
|
---|
[6613ec] | 2214 | for (int i = 0; i < NDIM; i++) { // each axis
|
---|
| 2215 | LC->n[i] = LC->N[i] - 1; // current axis is topmost cell
|
---|
| 2216 | for (LC->n[(i + 1) % NDIM] = 0; LC->n[(i + 1) % NDIM] < LC->N[(i + 1) % NDIM]; LC->n[(i + 1) % NDIM]++)
|
---|
| 2217 | for (LC->n[(i + 2) % NDIM] = 0; LC->n[(i + 2) % NDIM] < LC->N[(i + 2) % NDIM]; LC->n[(i + 2) % NDIM]++) {
|
---|
[734816] | 2218 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 2219 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2220 | if (List != NULL) {
|
---|
[6613ec] | 2221 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[0a4f7f] | 2222 | if ((*Runner)->node->at(i) > maxCoordinate[i]) {
|
---|
[a67d19] | 2223 | DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl);
|
---|
[0a4f7f] | 2224 | maxCoordinate[i] = (*Runner)->node->at(i);
|
---|
[62bb91] | 2225 | MaxPoint[i] = (*Runner);
|
---|
[357fba] | 2226 | }
|
---|
| 2227 | }
|
---|
| 2228 | } else {
|
---|
[6613ec] | 2229 | DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
|
---|
[357fba] | 2230 | }
|
---|
| 2231 | }
|
---|
| 2232 | }
|
---|
| 2233 |
|
---|
[a67d19] | 2234 | DoLog(1) && (Log() << Verbose(1) << "Found maximum coordinates: ");
|
---|
[6613ec] | 2235 | for (int i = 0; i < NDIM; i++)
|
---|
[a67d19] | 2236 | DoLog(0) && (Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t");
|
---|
| 2237 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[357fba] | 2238 |
|
---|
| 2239 | BTS = NULL;
|
---|
[6613ec] | 2240 | for (int k = 0; k < NDIM; k++) {
|
---|
[b998c3] | 2241 | NormalVector.Zero();
|
---|
[0a4f7f] | 2242 | NormalVector[k] = 1.;
|
---|
[f07f86d] | 2243 | BaseLine = new BoundaryLineSet();
|
---|
| 2244 | BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
|
---|
[a67d19] | 2245 | DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
|
---|
[357fba] | 2246 |
|
---|
| 2247 | double ShortestAngle;
|
---|
| 2248 | 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.
|
---|
| 2249 |
|
---|
[cfe56d] | 2250 | Temporary = NULL;
|
---|
[f07f86d] | 2251 | 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] | 2252 | if (Temporary == NULL) {
|
---|
| 2253 | // have we found a second point?
|
---|
| 2254 | delete BaseLine;
|
---|
[357fba] | 2255 | continue;
|
---|
[711ac2] | 2256 | }
|
---|
[f07f86d] | 2257 | BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
|
---|
[357fba] | 2258 |
|
---|
[b998c3] | 2259 | // construct center of circle
|
---|
[8cbb97] | 2260 | CircleCenter = 0.5 * ((*BaseLine->endpoints[0]->node->node) + (*BaseLine->endpoints[1]->node->node));
|
---|
[b998c3] | 2261 |
|
---|
| 2262 | // construct normal vector of circle
|
---|
[8cbb97] | 2263 | CirclePlaneNormal = (*BaseLine->endpoints[0]->node->node) - (*BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2264 |
|
---|
[b998c3] | 2265 | double radius = CirclePlaneNormal.NormSquared();
|
---|
[6613ec] | 2266 | double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
|
---|
[b998c3] | 2267 |
|
---|
[273382] | 2268 | NormalVector.ProjectOntoPlane(CirclePlaneNormal);
|
---|
[b998c3] | 2269 | NormalVector.Normalize();
|
---|
[6613ec] | 2270 | ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
|
---|
[b998c3] | 2271 |
|
---|
[273382] | 2272 | SphereCenter = (CircleRadius * NormalVector) + CircleCenter;
|
---|
[b998c3] | 2273 | // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
|
---|
[357fba] | 2274 |
|
---|
| 2275 | // look in one direction of baseline for initial candidate
|
---|
[0a4f7f] | 2276 | SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ...
|
---|
[357fba] | 2277 |
|
---|
[5c7bf8] | 2278 | // adding point 1 and point 2 and add the line between them
|
---|
[a67d19] | 2279 | DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
|
---|
| 2280 | DoLog(0) && (Log() << Verbose(0) << "Found second point is at " << *BaseLine->endpoints[1]->node << ".\n");
|
---|
[357fba] | 2281 |
|
---|
[f67b6e] | 2282 | //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
|
---|
[f07f86d] | 2283 | CandidateForTesselation OptCandidates(BaseLine);
|
---|
[b998c3] | 2284 | FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
|
---|
[a67d19] | 2285 | DoLog(0) && (Log() << Verbose(0) << "List of third Points is:" << endl);
|
---|
[f67b6e] | 2286 | for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
|
---|
[a67d19] | 2287 | DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
|
---|
[357fba] | 2288 | }
|
---|
[f07f86d] | 2289 | if (!OptCandidates.pointlist.empty()) {
|
---|
| 2290 | BTS = NULL;
|
---|
| 2291 | AddCandidatePolygon(OptCandidates, RADIUS, LC);
|
---|
| 2292 | } else {
|
---|
| 2293 | delete BaseLine;
|
---|
| 2294 | continue;
|
---|
[357fba] | 2295 | }
|
---|
| 2296 |
|
---|
[711ac2] | 2297 | if (BTS != NULL) { // we have created one starting triangle
|
---|
| 2298 | delete BaseLine;
|
---|
[357fba] | 2299 | break;
|
---|
[711ac2] | 2300 | } else {
|
---|
[357fba] | 2301 | // remove all candidates from the list and then the list itself
|
---|
[7273fc] | 2302 | OptCandidates.pointlist.clear();
|
---|
[357fba] | 2303 | }
|
---|
[f07f86d] | 2304 | delete BaseLine;
|
---|
[357fba] | 2305 | }
|
---|
[ce70970] | 2306 |
|
---|
| 2307 | return (BTS != NULL);
|
---|
[6613ec] | 2308 | }
|
---|
| 2309 | ;
|
---|
[357fba] | 2310 |
|
---|
[f1ef60a] | 2311 | /** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
|
---|
| 2312 | * This is supposed to prevent early closing of the tesselation.
|
---|
[f67b6e] | 2313 | * \param CandidateLine CandidateForTesselation with baseline and shortestangle , i.e. not \a *OptCandidate
|
---|
[f1ef60a] | 2314 | * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
|
---|
| 2315 | * \param RADIUS radius of sphere
|
---|
| 2316 | * \param *LC LinkedCell structure
|
---|
| 2317 | * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
|
---|
| 2318 | */
|
---|
[f67b6e] | 2319 | //bool Tesselation::HasOtherBaselineBetterCandidate(CandidateForTesselation &CandidateLine, const TesselPoint * const ThirdNode, double RADIUS, const LinkedCell * const LC) const
|
---|
| 2320 | //{
|
---|
| 2321 | // Info FunctionInfo(__func__);
|
---|
| 2322 | // bool result = false;
|
---|
| 2323 | // Vector CircleCenter;
|
---|
| 2324 | // Vector CirclePlaneNormal;
|
---|
| 2325 | // Vector OldSphereCenter;
|
---|
| 2326 | // Vector SearchDirection;
|
---|
| 2327 | // Vector helper;
|
---|
| 2328 | // TesselPoint *OtherOptCandidate = NULL;
|
---|
| 2329 | // double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
|
---|
| 2330 | // double radius, CircleRadius;
|
---|
| 2331 | // BoundaryLineSet *Line = NULL;
|
---|
| 2332 | // BoundaryTriangleSet *T = NULL;
|
---|
| 2333 | //
|
---|
| 2334 | // // check both other lines
|
---|
| 2335 | // PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
|
---|
| 2336 | // if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2337 | // for (int i=0;i<2;i++) {
|
---|
| 2338 | // LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
|
---|
| 2339 | // if (FindLine != (FindPoint->second)->lines.end()) {
|
---|
| 2340 | // Line = FindLine->second;
|
---|
| 2341 | // Log() << Verbose(0) << "Found line " << *Line << "." << endl;
|
---|
| 2342 | // if (Line->triangles.size() == 1) {
|
---|
| 2343 | // T = Line->triangles.begin()->second;
|
---|
| 2344 | // // construct center of circle
|
---|
| 2345 | // CircleCenter.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2346 | // CircleCenter.AddVector(Line->endpoints[1]->node->node);
|
---|
| 2347 | // CircleCenter.Scale(0.5);
|
---|
| 2348 | //
|
---|
| 2349 | // // construct normal vector of circle
|
---|
| 2350 | // CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2351 | // CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
|
---|
| 2352 | //
|
---|
| 2353 | // // calculate squared radius of circle
|
---|
| 2354 | // radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
|
---|
| 2355 | // if (radius/4. < RADIUS*RADIUS) {
|
---|
| 2356 | // CircleRadius = RADIUS*RADIUS - radius/4.;
|
---|
| 2357 | // CirclePlaneNormal.Normalize();
|
---|
| 2358 | // //Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
| 2359 | //
|
---|
| 2360 | // // construct old center
|
---|
| 2361 | // GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
|
---|
| 2362 | // helper.CopyVector(&T->NormalVector); // normal vector ensures that this is correct center of the two possible ones
|
---|
| 2363 | // radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
|
---|
| 2364 | // helper.Scale(sqrt(RADIUS*RADIUS - radius));
|
---|
| 2365 | // OldSphereCenter.AddVector(&helper);
|
---|
| 2366 | // OldSphereCenter.SubtractVector(&CircleCenter);
|
---|
| 2367 | // //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
|
---|
| 2368 | //
|
---|
| 2369 | // // construct SearchDirection
|
---|
| 2370 | // SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
|
---|
| 2371 | // helper.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2372 | // helper.SubtractVector(ThirdNode->node);
|
---|
| 2373 | // if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
| 2374 | // SearchDirection.Scale(-1.);
|
---|
| 2375 | // SearchDirection.ProjectOntoPlane(&OldSphereCenter);
|
---|
| 2376 | // SearchDirection.Normalize();
|
---|
| 2377 | // Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
| 2378 | // if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
|
---|
| 2379 | // // rotated the wrong way!
|
---|
[58ed4a] | 2380 | // DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
|
---|
[f67b6e] | 2381 | // }
|
---|
| 2382 | //
|
---|
| 2383 | // // add third point
|
---|
| 2384 | // FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, OptCandidates, ThirdNode, RADIUS, LC);
|
---|
| 2385 | // for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); ++it) {
|
---|
| 2386 | // if (((*it) == BaseRay->endpoints[0]->node) || ((*it) == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
|
---|
| 2387 | // continue;
|
---|
| 2388 | // Log() << Verbose(0) << " Third point candidate is " << (*it)
|
---|
| 2389 | // << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
|
---|
| 2390 | // Log() << Verbose(0) << " Baseline is " << *BaseRay << endl;
|
---|
| 2391 | //
|
---|
| 2392 | // // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
|
---|
| 2393 | // TesselPoint *PointCandidates[3];
|
---|
| 2394 | // PointCandidates[0] = (*it);
|
---|
| 2395 | // PointCandidates[1] = BaseRay->endpoints[0]->node;
|
---|
| 2396 | // PointCandidates[2] = BaseRay->endpoints[1]->node;
|
---|
| 2397 | // bool check=false;
|
---|
| 2398 | // int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
|
---|
| 2399 | // // If there is no triangle, add it regularly.
|
---|
| 2400 | // if (existentTrianglesCount == 0) {
|
---|
| 2401 | // SetTesselationPoint((*it), 0);
|
---|
| 2402 | // SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2403 | // SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2404 | //
|
---|
| 2405 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
|
---|
| 2406 | // OtherOptCandidate = (*it);
|
---|
| 2407 | // check = true;
|
---|
| 2408 | // }
|
---|
| 2409 | // } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
|
---|
| 2410 | // SetTesselationPoint((*it), 0);
|
---|
| 2411 | // SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2412 | // SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2413 | //
|
---|
| 2414 | // // 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)
|
---|
| 2415 | // // i.e. at least one of the three lines must be present with TriangleCount <= 1
|
---|
| 2416 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
|
---|
| 2417 | // OtherOptCandidate = (*it);
|
---|
| 2418 | // check = true;
|
---|
| 2419 | // }
|
---|
| 2420 | // }
|
---|
| 2421 | //
|
---|
| 2422 | // if (check) {
|
---|
| 2423 | // if (ShortestAngle > OtherShortestAngle) {
|
---|
| 2424 | // Log() << Verbose(0) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
|
---|
| 2425 | // result = true;
|
---|
| 2426 | // break;
|
---|
| 2427 | // }
|
---|
| 2428 | // }
|
---|
| 2429 | // }
|
---|
| 2430 | // delete(OptCandidates);
|
---|
| 2431 | // if (result)
|
---|
| 2432 | // break;
|
---|
| 2433 | // } else {
|
---|
| 2434 | // Log() << Verbose(0) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
|
---|
| 2435 | // }
|
---|
| 2436 | // } else {
|
---|
[58ed4a] | 2437 | // DoeLog(2) && (eLog()<< Verbose(2) << "Baseline is connected to two triangles already?" << endl);
|
---|
[f67b6e] | 2438 | // }
|
---|
| 2439 | // } else {
|
---|
| 2440 | // Log() << Verbose(1) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
|
---|
| 2441 | // }
|
---|
| 2442 | // }
|
---|
| 2443 | // } else {
|
---|
[58ed4a] | 2444 | // DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl);
|
---|
[f67b6e] | 2445 | // }
|
---|
| 2446 | //
|
---|
| 2447 | // return result;
|
---|
| 2448 | //};
|
---|
[357fba] | 2449 |
|
---|
| 2450 | /** This function finds a triangle to a line, adjacent to an existing one.
|
---|
| 2451 | * @param out output stream for debugging
|
---|
[1e168b] | 2452 | * @param CandidateLine current cadndiate baseline to search from
|
---|
[357fba] | 2453 | * @param T current triangle which \a Line is edge of
|
---|
| 2454 | * @param RADIUS radius of the rolling ball
|
---|
| 2455 | * @param N number of found triangles
|
---|
[62bb91] | 2456 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 2457 | */
|
---|
[f07f86d] | 2458 | bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2459 | {
|
---|
[6613ec] | 2460 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2461 | Vector CircleCenter;
|
---|
| 2462 | Vector CirclePlaneNormal;
|
---|
[b998c3] | 2463 | Vector RelativeSphereCenter;
|
---|
[357fba] | 2464 | Vector SearchDirection;
|
---|
| 2465 | Vector helper;
|
---|
[09898c] | 2466 | BoundaryPointSet *ThirdPoint = NULL;
|
---|
[357fba] | 2467 | LineMap::iterator testline;
|
---|
| 2468 | double radius, CircleRadius;
|
---|
| 2469 |
|
---|
[6613ec] | 2470 | for (int i = 0; i < 3; i++)
|
---|
[09898c] | 2471 | if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
|
---|
| 2472 | ThirdPoint = T.endpoints[i];
|
---|
[b998c3] | 2473 | break;
|
---|
| 2474 | }
|
---|
[a67d19] | 2475 | DoLog(0) && (Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << "." << endl);
|
---|
[09898c] | 2476 |
|
---|
| 2477 | CandidateLine.T = &T;
|
---|
[357fba] | 2478 |
|
---|
| 2479 | // construct center of circle
|
---|
[273382] | 2480 | CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
|
---|
| 2481 | (*CandidateLine.BaseLine->endpoints[1]->node->node));
|
---|
[357fba] | 2482 |
|
---|
| 2483 | // construct normal vector of circle
|
---|
[273382] | 2484 | CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
|
---|
| 2485 | (*CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2486 |
|
---|
| 2487 | // calculate squared radius of circle
|
---|
[273382] | 2488 | radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal);
|
---|
[6613ec] | 2489 | if (radius / 4. < RADIUS * RADIUS) {
|
---|
[b998c3] | 2490 | // construct relative sphere center with now known CircleCenter
|
---|
[273382] | 2491 | RelativeSphereCenter = T.SphereCenter - CircleCenter;
|
---|
[b998c3] | 2492 |
|
---|
[6613ec] | 2493 | CircleRadius = RADIUS * RADIUS - radius / 4.;
|
---|
[357fba] | 2494 | CirclePlaneNormal.Normalize();
|
---|
[a67d19] | 2495 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
[357fba] | 2496 |
|
---|
[a67d19] | 2497 | DoLog(1) && (Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl);
|
---|
[b998c3] | 2498 |
|
---|
| 2499 | // construct SearchDirection and an "outward pointer"
|
---|
[0a4f7f] | 2500 | SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal();
|
---|
[8cbb97] | 2501 | helper = CircleCenter - (*ThirdPoint->node->node);
|
---|
[273382] | 2502 | if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
[357fba] | 2503 | SearchDirection.Scale(-1.);
|
---|
[a67d19] | 2504 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
[273382] | 2505 | if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) {
|
---|
[357fba] | 2506 | // rotated the wrong way!
|
---|
[6613ec] | 2507 | DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
|
---|
[357fba] | 2508 | }
|
---|
| 2509 |
|
---|
| 2510 | // add third point
|
---|
[09898c] | 2511 | FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC);
|
---|
[357fba] | 2512 |
|
---|
| 2513 | } else {
|
---|
[a67d19] | 2514 | DoLog(0) && (Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl);
|
---|
[357fba] | 2515 | }
|
---|
| 2516 |
|
---|
[f67b6e] | 2517 | if (CandidateLine.pointlist.empty()) {
|
---|
[6613ec] | 2518 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl);
|
---|
[357fba] | 2519 | return false;
|
---|
| 2520 | }
|
---|
[a67d19] | 2521 | DoLog(0) && (Log() << Verbose(0) << "Third Points are: " << endl);
|
---|
[f67b6e] | 2522 | for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
|
---|
[a67d19] | 2523 | DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
|
---|
[357fba] | 2524 | }
|
---|
| 2525 |
|
---|
[f67b6e] | 2526 | return true;
|
---|
[6613ec] | 2527 | }
|
---|
| 2528 | ;
|
---|
[f67b6e] | 2529 |
|
---|
[6613ec] | 2530 | /** Walks through Tesselation::OpenLines() and finds candidates for newly created ones.
|
---|
| 2531 | * \param *&LCList atoms in LinkedCell list
|
---|
| 2532 | * \param RADIUS radius of the virtual sphere
|
---|
| 2533 | * \return true - for all open lines without candidates so far, a candidate has been found,
|
---|
| 2534 | * false - at least one open line without candidate still
|
---|
| 2535 | */
|
---|
| 2536 | bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList)
|
---|
| 2537 | {
|
---|
| 2538 | bool TesselationFailFlag = true;
|
---|
| 2539 | CandidateForTesselation *baseline = NULL;
|
---|
| 2540 | BoundaryTriangleSet *T = NULL;
|
---|
| 2541 |
|
---|
| 2542 | for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
|
---|
| 2543 | baseline = Runner->second;
|
---|
| 2544 | if (baseline->pointlist.empty()) {
|
---|
[f04f11] | 2545 | assert((baseline->BaseLine->triangles.size() == 1) && ("Open line without exactly one attached triangle"));
|
---|
[6613ec] | 2546 | T = (((baseline->BaseLine->triangles.begin()))->second);
|
---|
[a67d19] | 2547 | DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl);
|
---|
[6613ec] | 2548 | TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
|
---|
| 2549 | }
|
---|
| 2550 | }
|
---|
| 2551 | return TesselationFailFlag;
|
---|
| 2552 | }
|
---|
| 2553 | ;
|
---|
[357fba] | 2554 |
|
---|
[1e168b] | 2555 | /** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
|
---|
[f67b6e] | 2556 | * \param CandidateLine triangle to add
|
---|
[474961] | 2557 | * \param RADIUS Radius of sphere
|
---|
| 2558 | * \param *LC LinkedCell structure
|
---|
| 2559 | * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in
|
---|
| 2560 | * AddTesselationLine() in AddCandidateTriangle()
|
---|
[1e168b] | 2561 | */
|
---|
[474961] | 2562 | void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC)
|
---|
[1e168b] | 2563 | {
|
---|
[ebb50e] | 2564 | Info FunctionInfo(__func__);
|
---|
[1e168b] | 2565 | Vector Center;
|
---|
[27bd2f] | 2566 | TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
|
---|
[09898c] | 2567 | TesselPointList::iterator Runner;
|
---|
| 2568 | TesselPointList::iterator Sprinter;
|
---|
[27bd2f] | 2569 |
|
---|
| 2570 | // fill the set of neighbours
|
---|
[c15ca2] | 2571 | TesselPointSet SetOfNeighbours;
|
---|
[27bd2f] | 2572 | SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
|
---|
| 2573 | for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
|
---|
| 2574 | SetOfNeighbours.insert(*Runner);
|
---|
[c15ca2] | 2575 | TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[27bd2f] | 2576 |
|
---|
[a67d19] | 2577 | DoLog(0) && (Log() << Verbose(0) << "List of Candidates for Turning Point " << *TurningPoint << ":" << endl);
|
---|
[c15ca2] | 2578 | for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
|
---|
[a67d19] | 2579 | DoLog(0) && (Log() << Verbose(0) << " " << **TesselRunner << endl);
|
---|
[09898c] | 2580 |
|
---|
| 2581 | // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
|
---|
| 2582 | Runner = connectedClosestPoints->begin();
|
---|
| 2583 | Sprinter = Runner;
|
---|
[27bd2f] | 2584 | Sprinter++;
|
---|
[6613ec] | 2585 | while (Sprinter != connectedClosestPoints->end()) {
|
---|
[a67d19] | 2586 | DoLog(0) && (Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl);
|
---|
[f67b6e] | 2587 |
|
---|
[f07f86d] | 2588 | AddTesselationPoint(TurningPoint, 0);
|
---|
| 2589 | AddTesselationPoint(*Runner, 1);
|
---|
| 2590 | AddTesselationPoint(*Sprinter, 2);
|
---|
[1e168b] | 2591 |
|
---|
[6613ec] | 2592 | AddCandidateTriangle(CandidateLine, Opt);
|
---|
[1e168b] | 2593 |
|
---|
[27bd2f] | 2594 | Runner = Sprinter;
|
---|
| 2595 | Sprinter++;
|
---|
[6613ec] | 2596 | if (Sprinter != connectedClosestPoints->end()) {
|
---|
| 2597 | // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
|
---|
[f04f11] | 2598 | FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); // Assume BTS contains last triangle
|
---|
[a67d19] | 2599 | DoLog(0) && (Log() << Verbose(0) << " There are still more triangles to add." << endl);
|
---|
[6613ec] | 2600 | }
|
---|
| 2601 | // pick candidates for other open lines as well
|
---|
| 2602 | FindCandidatesforOpenLines(RADIUS, LC);
|
---|
| 2603 |
|
---|
[f07f86d] | 2604 | // check whether we add a degenerate or a normal triangle
|
---|
[6613ec] | 2605 | if (CheckDegeneracy(CandidateLine, RADIUS, LC)) {
|
---|
[f07f86d] | 2606 | // add normal and degenerate triangles
|
---|
[a67d19] | 2607 | DoLog(1) && (Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl);
|
---|
[6613ec] | 2608 | AddCandidateTriangle(CandidateLine, OtherOpt);
|
---|
| 2609 |
|
---|
| 2610 | if (Sprinter != connectedClosestPoints->end()) {
|
---|
| 2611 | // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
|
---|
| 2612 | FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter);
|
---|
| 2613 | }
|
---|
| 2614 | // pick candidates for other open lines as well
|
---|
| 2615 | FindCandidatesforOpenLines(RADIUS, LC);
|
---|
[474961] | 2616 | }
|
---|
[6613ec] | 2617 | }
|
---|
| 2618 | delete (connectedClosestPoints);
|
---|
| 2619 | };
|
---|
[474961] | 2620 |
|
---|
[6613ec] | 2621 | /** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate.
|
---|
| 2622 | * \param *Sprinter next candidate to which internal open lines are set
|
---|
| 2623 | * \param *OptCenter OptCenter for this candidate
|
---|
| 2624 | */
|
---|
| 2625 | void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter)
|
---|
| 2626 | {
|
---|
| 2627 | Info FunctionInfo(__func__);
|
---|
| 2628 |
|
---|
| 2629 | pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr);
|
---|
| 2630 | for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
|
---|
[a67d19] | 2631 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
|
---|
[6613ec] | 2632 | // If there is a line with less than two attached triangles, we don't need a new line.
|
---|
| 2633 | if (FindLine->second->triangles.size() == 1) {
|
---|
| 2634 | CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
|
---|
| 2635 | if (!Finder->second->pointlist.empty())
|
---|
[a67d19] | 2636 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
|
---|
[6613ec] | 2637 | else {
|
---|
[a67d19] | 2638 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl);
|
---|
[f04f11] | 2639 | Finder->second->T = BTS; // is last triangle
|
---|
[6613ec] | 2640 | Finder->second->pointlist.push_back(Sprinter);
|
---|
| 2641 | Finder->second->ShortestAngle = 0.;
|
---|
[8cbb97] | 2642 | Finder->second->OptCenter = *OptCenter;
|
---|
[6613ec] | 2643 | }
|
---|
| 2644 | }
|
---|
[f67b6e] | 2645 | }
|
---|
[1e168b] | 2646 | };
|
---|
| 2647 |
|
---|
[f07f86d] | 2648 | /** If a given \a *triangle is degenerated, this adds both sides.
|
---|
[474961] | 2649 | * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction.
|
---|
[f07f86d] | 2650 | * Note that endpoints are stored in Tesselation::TPS
|
---|
| 2651 | * \param CandidateLine CanddiateForTesselation structure for the desired BoundaryLine
|
---|
[474961] | 2652 | * \param RADIUS radius of sphere
|
---|
| 2653 | * \param *LC pointer to LinkedCell structure
|
---|
| 2654 | */
|
---|
[711ac2] | 2655 | void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
|
---|
[474961] | 2656 | {
|
---|
| 2657 | Info FunctionInfo(__func__);
|
---|
[f07f86d] | 2658 | Vector Center;
|
---|
| 2659 | CandidateMap::const_iterator CandidateCheck = OpenLines.end();
|
---|
[711ac2] | 2660 | BoundaryTriangleSet *triangle = NULL;
|
---|
[f07f86d] | 2661 |
|
---|
[711ac2] | 2662 | /// 1. Create or pick the lines for the first triangle
|
---|
[a67d19] | 2663 | DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl);
|
---|
[6613ec] | 2664 | for (int i = 0; i < 3; i++) {
|
---|
[711ac2] | 2665 | BLS[i] = NULL;
|
---|
[a67d19] | 2666 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[6613ec] | 2667 | AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
|
---|
[474961] | 2668 | }
|
---|
[f07f86d] | 2669 |
|
---|
[711ac2] | 2670 | /// 2. create the first triangle and NormalVector and so on
|
---|
[a67d19] | 2671 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl);
|
---|
[f07f86d] | 2672 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2673 | AddTesselationTriangle();
|
---|
[711ac2] | 2674 |
|
---|
[f07f86d] | 2675 | // create normal vector
|
---|
| 2676 | BTS->GetCenter(&Center);
|
---|
[8cbb97] | 2677 | Center -= CandidateLine.OptCenter;
|
---|
| 2678 | BTS->SphereCenter = CandidateLine.OptCenter;
|
---|
[f07f86d] | 2679 | BTS->GetNormalVector(Center);
|
---|
| 2680 | // give some verbose output about the whole procedure
|
---|
| 2681 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2682 | DoLog(0) && (Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
|
---|
[f07f86d] | 2683 | else
|
---|
[a67d19] | 2684 | DoLog(0) && (Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[f07f86d] | 2685 | triangle = BTS;
|
---|
| 2686 |
|
---|
[711ac2] | 2687 | /// 3. Gather candidates for each new line
|
---|
[a67d19] | 2688 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl);
|
---|
[6613ec] | 2689 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2690 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[f07f86d] | 2691 | CandidateCheck = OpenLines.find(BLS[i]);
|
---|
| 2692 | if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
|
---|
| 2693 | if (CandidateCheck->second->T == NULL)
|
---|
| 2694 | CandidateCheck->second->T = triangle;
|
---|
| 2695 | FindNextSuitableTriangle(*(CandidateCheck->second), *CandidateCheck->second->T, RADIUS, LC);
|
---|
[474961] | 2696 | }
|
---|
[f07f86d] | 2697 | }
|
---|
[d5fea7] | 2698 |
|
---|
[711ac2] | 2699 | /// 4. Create or pick the lines for the second triangle
|
---|
[a67d19] | 2700 | DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl);
|
---|
[6613ec] | 2701 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2702 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[6613ec] | 2703 | AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
|
---|
[474961] | 2704 | }
|
---|
[f07f86d] | 2705 |
|
---|
[711ac2] | 2706 | /// 5. create the second triangle and NormalVector and so on
|
---|
[a67d19] | 2707 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl);
|
---|
[f07f86d] | 2708 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2709 | AddTesselationTriangle();
|
---|
[711ac2] | 2710 |
|
---|
[8cbb97] | 2711 | BTS->SphereCenter = CandidateLine.OtherOptCenter;
|
---|
[f07f86d] | 2712 | // create normal vector in other direction
|
---|
[8cbb97] | 2713 | BTS->GetNormalVector(triangle->NormalVector);
|
---|
[f07f86d] | 2714 | BTS->NormalVector.Scale(-1.);
|
---|
| 2715 | // give some verbose output about the whole procedure
|
---|
| 2716 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2717 | DoLog(0) && (Log() << Verbose(0) << "--> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
|
---|
[f07f86d] | 2718 | else
|
---|
[a67d19] | 2719 | DoLog(0) && (Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[f07f86d] | 2720 |
|
---|
[711ac2] | 2721 | /// 6. Adding triangle to new lines
|
---|
[a67d19] | 2722 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl);
|
---|
[6613ec] | 2723 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2724 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[711ac2] | 2725 | CandidateCheck = OpenLines.find(BLS[i]);
|
---|
| 2726 | if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
|
---|
| 2727 | if (CandidateCheck->second->T == NULL)
|
---|
| 2728 | CandidateCheck->second->T = BTS;
|
---|
| 2729 | }
|
---|
| 2730 | }
|
---|
[6613ec] | 2731 | }
|
---|
| 2732 | ;
|
---|
[474961] | 2733 |
|
---|
| 2734 | /** Adds a triangle to the Tesselation structure from three given TesselPoint's.
|
---|
[f07f86d] | 2735 | * Note that endpoints are in Tesselation::TPS.
|
---|
| 2736 | * \param CandidateLine CandidateForTesselation structure contains other information
|
---|
[6613ec] | 2737 | * \param type which opt center to add (i.e. which side) and thus which NormalVector to take
|
---|
[474961] | 2738 | */
|
---|
[6613ec] | 2739 | void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type)
|
---|
[474961] | 2740 | {
|
---|
| 2741 | Info FunctionInfo(__func__);
|
---|
[f07f86d] | 2742 | Vector Center;
|
---|
[6613ec] | 2743 | Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter;
|
---|
[474961] | 2744 |
|
---|
| 2745 | // add the lines
|
---|
[6613ec] | 2746 | AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0);
|
---|
| 2747 | AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1);
|
---|
| 2748 | AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2);
|
---|
[474961] | 2749 |
|
---|
| 2750 | // add the triangles
|
---|
| 2751 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2752 | AddTesselationTriangle();
|
---|
[f07f86d] | 2753 |
|
---|
| 2754 | // create normal vector
|
---|
| 2755 | BTS->GetCenter(&Center);
|
---|
[8cbb97] | 2756 | Center.SubtractVector(*OptCenter);
|
---|
| 2757 | BTS->SphereCenter = *OptCenter;
|
---|
[f07f86d] | 2758 | BTS->GetNormalVector(Center);
|
---|
| 2759 |
|
---|
| 2760 | // give some verbose output about the whole procedure
|
---|
| 2761 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2762 | 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] | 2763 | else
|
---|
[a67d19] | 2764 | DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[6613ec] | 2765 | }
|
---|
| 2766 | ;
|
---|
[474961] | 2767 |
|
---|
[16d866] | 2768 | /** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
|
---|
| 2769 | * We look whether the closest point on \a *Base with respect to the other baseline is outside
|
---|
| 2770 | * of the segment formed by both endpoints (concave) or not (convex).
|
---|
| 2771 | * \param *out output stream for debugging
|
---|
| 2772 | * \param *Base line to be flipped
|
---|
[57066a] | 2773 | * \return NULL - convex, otherwise endpoint that makes it concave
|
---|
[16d866] | 2774 | */
|
---|
[e138de] | 2775 | class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
|
---|
[16d866] | 2776 | {
|
---|
[6613ec] | 2777 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2778 | class BoundaryPointSet *Spot = NULL;
|
---|
| 2779 | class BoundaryLineSet *OtherBase;
|
---|
[0077b5] | 2780 | Vector *ClosestPoint;
|
---|
[16d866] | 2781 |
|
---|
[6613ec] | 2782 | int m = 0;
|
---|
| 2783 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2784 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2785 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2786 | BPS[m++] = runner->second->endpoints[j];
|
---|
[6613ec] | 2787 | OtherBase = new class BoundaryLineSet(BPS, -1);
|
---|
[16d866] | 2788 |
|
---|
[a67d19] | 2789 | DoLog(1) && (Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl);
|
---|
| 2790 | DoLog(1) && (Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl);
|
---|
[16d866] | 2791 |
|
---|
| 2792 | // get the closest point on each line to the other line
|
---|
[e138de] | 2793 | ClosestPoint = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
[16d866] | 2794 |
|
---|
| 2795 | // delete the temporary other base line
|
---|
[6613ec] | 2796 | delete (OtherBase);
|
---|
[16d866] | 2797 |
|
---|
| 2798 | // get the distance vector from Base line to OtherBase line
|
---|
[0077b5] | 2799 | Vector DistanceToIntersection[2], BaseLine;
|
---|
| 2800 | double distance[2];
|
---|
[273382] | 2801 | BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node);
|
---|
[6613ec] | 2802 | for (int i = 0; i < 2; i++) {
|
---|
[273382] | 2803 | DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node);
|
---|
| 2804 | distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]);
|
---|
[16d866] | 2805 | }
|
---|
[6613ec] | 2806 | delete (ClosestPoint);
|
---|
| 2807 | if ((distance[0] * distance[1]) > 0) { // have same sign?
|
---|
[a67d19] | 2808 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl);
|
---|
[0077b5] | 2809 | if (distance[0] < distance[1]) {
|
---|
| 2810 | Spot = Base->endpoints[0];
|
---|
| 2811 | } else {
|
---|
| 2812 | Spot = Base->endpoints[1];
|
---|
| 2813 | }
|
---|
[16d866] | 2814 | return Spot;
|
---|
[6613ec] | 2815 | } else { // different sign, i.e. we are in between
|
---|
[a67d19] | 2816 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl);
|
---|
[16d866] | 2817 | return NULL;
|
---|
| 2818 | }
|
---|
| 2819 |
|
---|
[6613ec] | 2820 | }
|
---|
| 2821 | ;
|
---|
[16d866] | 2822 |
|
---|
[776b64] | 2823 | void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
|
---|
[0077b5] | 2824 | {
|
---|
[6613ec] | 2825 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2826 | // print all lines
|
---|
[a67d19] | 2827 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl);
|
---|
[6613ec] | 2828 | for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)
|
---|
[a67d19] | 2829 | DoLog(0) && (Log() << Verbose(0) << *(PointRunner->second) << endl);
|
---|
[6613ec] | 2830 | }
|
---|
| 2831 | ;
|
---|
[0077b5] | 2832 |
|
---|
[776b64] | 2833 | void Tesselation::PrintAllBoundaryLines(ofstream *out) const
|
---|
[0077b5] | 2834 | {
|
---|
[6613ec] | 2835 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2836 | // print all lines
|
---|
[a67d19] | 2837 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl);
|
---|
[776b64] | 2838 | for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
|
---|
[a67d19] | 2839 | DoLog(0) && (Log() << Verbose(0) << *(LineRunner->second) << endl);
|
---|
[6613ec] | 2840 | }
|
---|
| 2841 | ;
|
---|
[0077b5] | 2842 |
|
---|
[776b64] | 2843 | void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
|
---|
[0077b5] | 2844 | {
|
---|
[6613ec] | 2845 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2846 | // print all triangles
|
---|
[a67d19] | 2847 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl);
|
---|
[776b64] | 2848 | for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
|
---|
[a67d19] | 2849 | DoLog(0) && (Log() << Verbose(0) << *(TriangleRunner->second) << endl);
|
---|
[6613ec] | 2850 | }
|
---|
| 2851 | ;
|
---|
[357fba] | 2852 |
|
---|
[16d866] | 2853 | /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
|
---|
[357fba] | 2854 | * \param *out output stream for debugging
|
---|
[16d866] | 2855 | * \param *Base line to be flipped
|
---|
[57066a] | 2856 | * \return volume change due to flipping (0 - then no flipped occured)
|
---|
[357fba] | 2857 | */
|
---|
[e138de] | 2858 | double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
|
---|
[357fba] | 2859 | {
|
---|
[6613ec] | 2860 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2861 | class BoundaryLineSet *OtherBase;
|
---|
| 2862 | Vector *ClosestPoint[2];
|
---|
[57066a] | 2863 | double volume;
|
---|
[16d866] | 2864 |
|
---|
[6613ec] | 2865 | int m = 0;
|
---|
| 2866 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2867 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2868 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2869 | BPS[m++] = runner->second->endpoints[j];
|
---|
[6613ec] | 2870 | OtherBase = new class BoundaryLineSet(BPS, -1);
|
---|
[62bb91] | 2871 |
|
---|
[a67d19] | 2872 | DoLog(0) && (Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl);
|
---|
| 2873 | DoLog(0) && (Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl);
|
---|
[62bb91] | 2874 |
|
---|
[16d866] | 2875 | // get the closest point on each line to the other line
|
---|
[e138de] | 2876 | ClosestPoint[0] = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
| 2877 | ClosestPoint[1] = GetClosestPointBetweenLine(OtherBase, Base);
|
---|
[16d866] | 2878 |
|
---|
| 2879 | // get the distance vector from Base line to OtherBase line
|
---|
[273382] | 2880 | Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]);
|
---|
[16d866] | 2881 |
|
---|
[57066a] | 2882 | // calculate volume
|
---|
[c0f6c6] | 2883 | volume = CalculateVolumeofGeneralTetraeder(*Base->endpoints[1]->node->node, *OtherBase->endpoints[0]->node->node, *OtherBase->endpoints[1]->node->node, *Base->endpoints[0]->node->node);
|
---|
[57066a] | 2884 |
|
---|
[0077b5] | 2885 | // delete the temporary other base line and the closest points
|
---|
[6613ec] | 2886 | delete (ClosestPoint[0]);
|
---|
| 2887 | delete (ClosestPoint[1]);
|
---|
| 2888 | delete (OtherBase);
|
---|
[16d866] | 2889 |
|
---|
| 2890 | if (Distance.NormSquared() < MYEPSILON) { // check for intersection
|
---|
[a67d19] | 2891 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl);
|
---|
[16d866] | 2892 | return false;
|
---|
| 2893 | } else { // check for sign against BaseLineNormal
|
---|
| 2894 | Vector BaseLineNormal;
|
---|
[5c7bf8] | 2895 | BaseLineNormal.Zero();
|
---|
| 2896 | if (Base->triangles.size() < 2) {
|
---|
[6613ec] | 2897 | DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
|
---|
[57066a] | 2898 | return 0.;
|
---|
[5c7bf8] | 2899 | }
|
---|
| 2900 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[8cbb97] | 2901 | DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
|
---|
[273382] | 2902 | BaseLineNormal += (runner->second->NormalVector);
|
---|
[5c7bf8] | 2903 | }
|
---|
[6613ec] | 2904 | BaseLineNormal.Scale(1. / 2.);
|
---|
[357fba] | 2905 |
|
---|
[273382] | 2906 | if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
|
---|
[a67d19] | 2907 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl);
|
---|
[57066a] | 2908 | // calculate volume summand as a general tetraeder
|
---|
| 2909 | return volume;
|
---|
[6613ec] | 2910 | } else { // Base higher than OtherBase -> do nothing
|
---|
[a67d19] | 2911 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl);
|
---|
[57066a] | 2912 | return 0.;
|
---|
[16d866] | 2913 | }
|
---|
| 2914 | }
|
---|
[6613ec] | 2915 | }
|
---|
| 2916 | ;
|
---|
[357fba] | 2917 |
|
---|
[16d866] | 2918 | /** For a given baseline and its two connected triangles, flips the baseline.
|
---|
| 2919 | * I.e. we create the new baseline between the other two endpoints of these four
|
---|
| 2920 | * endpoints and reconstruct the two triangles accordingly.
|
---|
| 2921 | * \param *out output stream for debugging
|
---|
| 2922 | * \param *Base line to be flipped
|
---|
[57066a] | 2923 | * \return pointer to allocated new baseline - flipping successful, NULL - something went awry
|
---|
[16d866] | 2924 | */
|
---|
[e138de] | 2925 | class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
|
---|
[16d866] | 2926 | {
|
---|
[6613ec] | 2927 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2928 | class BoundaryLineSet *OldLines[4], *NewLine;
|
---|
| 2929 | class BoundaryPointSet *OldPoints[2];
|
---|
| 2930 | Vector BaseLineNormal;
|
---|
| 2931 | int OldTriangleNrs[2], OldBaseLineNr;
|
---|
[6613ec] | 2932 | int i, m;
|
---|
[16d866] | 2933 |
|
---|
| 2934 | // calculate NormalVector for later use
|
---|
| 2935 | BaseLineNormal.Zero();
|
---|
| 2936 | if (Base->triangles.size() < 2) {
|
---|
[6613ec] | 2937 | DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
|
---|
[57066a] | 2938 | return NULL;
|
---|
[16d866] | 2939 | }
|
---|
| 2940 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[a67d19] | 2941 | DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
|
---|
[273382] | 2942 | BaseLineNormal += (runner->second->NormalVector);
|
---|
[16d866] | 2943 | }
|
---|
[6613ec] | 2944 | BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
|
---|
[16d866] | 2945 |
|
---|
| 2946 | // get the two triangles
|
---|
| 2947 | // gather four endpoints and four lines
|
---|
[6613ec] | 2948 | for (int j = 0; j < 4; j++)
|
---|
[16d866] | 2949 | OldLines[j] = NULL;
|
---|
[6613ec] | 2950 | for (int j = 0; j < 2; j++)
|
---|
[16d866] | 2951 | OldPoints[j] = NULL;
|
---|
[6613ec] | 2952 | i = 0;
|
---|
| 2953 | m = 0;
|
---|
[a67d19] | 2954 | DoLog(0) && (Log() << Verbose(0) << "The four old lines are: ");
|
---|
[6613ec] | 2955 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2956 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2957 | if (runner->second->lines[j] != Base) { // pick not the central baseline
|
---|
| 2958 | OldLines[i++] = runner->second->lines[j];
|
---|
[a67d19] | 2959 | DoLog(0) && (Log() << Verbose(0) << *runner->second->lines[j] << "\t");
|
---|
[357fba] | 2960 | }
|
---|
[a67d19] | 2961 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
| 2962 | DoLog(0) && (Log() << Verbose(0) << "The two old points are: ");
|
---|
[6613ec] | 2963 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2964 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2965 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
|
---|
| 2966 | OldPoints[m++] = runner->second->endpoints[j];
|
---|
[a67d19] | 2967 | DoLog(0) && (Log() << Verbose(0) << *runner->second->endpoints[j] << "\t");
|
---|
[16d866] | 2968 | }
|
---|
[a67d19] | 2969 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[16d866] | 2970 |
|
---|
| 2971 | // check whether everything is in place to create new lines and triangles
|
---|
[6613ec] | 2972 | if (i < 4) {
|
---|
| 2973 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
|
---|
[57066a] | 2974 | return NULL;
|
---|
[16d866] | 2975 | }
|
---|
[6613ec] | 2976 | for (int j = 0; j < 4; j++)
|
---|
[16d866] | 2977 | if (OldLines[j] == NULL) {
|
---|
[6613ec] | 2978 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
|
---|
[57066a] | 2979 | return NULL;
|
---|
[16d866] | 2980 | }
|
---|
[6613ec] | 2981 | for (int j = 0; j < 2; j++)
|
---|
[16d866] | 2982 | if (OldPoints[j] == NULL) {
|
---|
[6613ec] | 2983 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl);
|
---|
[57066a] | 2984 | return NULL;
|
---|
[357fba] | 2985 | }
|
---|
[16d866] | 2986 |
|
---|
| 2987 | // remove triangles and baseline removes itself
|
---|
[a67d19] | 2988 | DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl);
|
---|
[16d866] | 2989 | OldBaseLineNr = Base->Nr;
|
---|
[6613ec] | 2990 | m = 0;
|
---|
| 2991 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[a67d19] | 2992 | DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl);
|
---|
[16d866] | 2993 | OldTriangleNrs[m++] = runner->second->Nr;
|
---|
| 2994 | RemoveTesselationTriangle(runner->second);
|
---|
| 2995 | }
|
---|
| 2996 |
|
---|
| 2997 | // construct new baseline (with same number as old one)
|
---|
| 2998 | BPS[0] = OldPoints[0];
|
---|
| 2999 | BPS[1] = OldPoints[1];
|
---|
| 3000 | NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
|
---|
| 3001 | LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
|
---|
[a67d19] | 3002 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl);
|
---|
[16d866] | 3003 |
|
---|
| 3004 | // construct new triangles with flipped baseline
|
---|
[6613ec] | 3005 | i = -1;
|
---|
[16d866] | 3006 | if (OldLines[0]->IsConnectedTo(OldLines[2]))
|
---|
[6613ec] | 3007 | i = 2;
|
---|
[16d866] | 3008 | if (OldLines[0]->IsConnectedTo(OldLines[3]))
|
---|
[6613ec] | 3009 | i = 3;
|
---|
| 3010 | if (i != -1) {
|
---|
[16d866] | 3011 | BLS[0] = OldLines[0];
|
---|
| 3012 | BLS[1] = OldLines[i];
|
---|
| 3013 | BLS[2] = NewLine;
|
---|
| 3014 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[0]);
|
---|
| 3015 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 3016 | AddTesselationTriangle(OldTriangleNrs[0]);
|
---|
[a67d19] | 3017 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
|
---|
[16d866] | 3018 |
|
---|
[6613ec] | 3019 | BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]);
|
---|
[16d866] | 3020 | BLS[1] = OldLines[1];
|
---|
| 3021 | BLS[2] = NewLine;
|
---|
| 3022 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[1]);
|
---|
| 3023 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 3024 | AddTesselationTriangle(OldTriangleNrs[1]);
|
---|
[a67d19] | 3025 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
|
---|
[16d866] | 3026 | } else {
|
---|
[6613ec] | 3027 | DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);
|
---|
[57066a] | 3028 | return NULL;
|
---|
[357fba] | 3029 | }
|
---|
[16d866] | 3030 |
|
---|
[57066a] | 3031 | return NewLine;
|
---|
[6613ec] | 3032 | }
|
---|
| 3033 | ;
|
---|
[16d866] | 3034 |
|
---|
[357fba] | 3035 | /** Finds the second point of starting triangle.
|
---|
| 3036 | * \param *a first node
|
---|
| 3037 | * \param Oben vector indicating the outside
|
---|
[f1cccd] | 3038 | * \param OptCandidate reference to recommended candidate on return
|
---|
[357fba] | 3039 | * \param Storage[3] array storing angles and other candidate information
|
---|
| 3040 | * \param RADIUS radius of virtual sphere
|
---|
[62bb91] | 3041 | * \param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 3042 | */
|
---|
[776b64] | 3043 | void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 3044 | {
|
---|
[6613ec] | 3045 | Info FunctionInfo(__func__);
|
---|
[357fba] | 3046 | Vector AngleCheck;
|
---|
[57066a] | 3047 | class TesselPoint* Candidate = NULL;
|
---|
[776b64] | 3048 | double norm = -1.;
|
---|
| 3049 | double angle = 0.;
|
---|
| 3050 | int N[NDIM];
|
---|
| 3051 | int Nlower[NDIM];
|
---|
| 3052 | int Nupper[NDIM];
|
---|
[357fba] | 3053 |
|
---|
[6613ec] | 3054 | if (LC->SetIndexToNode(a)) { // get cell for the starting point
|
---|
| 3055 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
[357fba] | 3056 | N[i] = LC->n[i];
|
---|
| 3057 | } else {
|
---|
[6613ec] | 3058 | DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);
|
---|
[357fba] | 3059 | return;
|
---|
| 3060 | }
|
---|
[62bb91] | 3061 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[6613ec] | 3062 | for (int i = 0; i < NDIM; i++) {
|
---|
| 3063 | Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
|
---|
| 3064 | Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
|
---|
[357fba] | 3065 | }
|
---|
[a67d19] | 3066 | 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] | 3067 |
|
---|
| 3068 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3069 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3070 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3071 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 3072 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3073 | if (List != NULL) {
|
---|
[734816] | 3074 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 3075 | Candidate = (*Runner);
|
---|
| 3076 | // check if we only have one unique point yet ...
|
---|
| 3077 | if (a != Candidate) {
|
---|
| 3078 | // Calculate center of the circle with radius RADIUS through points a and Candidate
|
---|
[f1cccd] | 3079 | Vector OrthogonalizedOben, aCandidate, Center;
|
---|
[357fba] | 3080 | double distance, scaleFactor;
|
---|
| 3081 |
|
---|
[273382] | 3082 | OrthogonalizedOben = Oben;
|
---|
| 3083 | aCandidate = (*a->node) - (*Candidate->node);
|
---|
| 3084 | OrthogonalizedOben.ProjectOntoPlane(aCandidate);
|
---|
[357fba] | 3085 | OrthogonalizedOben.Normalize();
|
---|
[f1cccd] | 3086 | distance = 0.5 * aCandidate.Norm();
|
---|
[357fba] | 3087 | scaleFactor = sqrt(((RADIUS * RADIUS) - (distance * distance)));
|
---|
| 3088 | OrthogonalizedOben.Scale(scaleFactor);
|
---|
| 3089 |
|
---|
[273382] | 3090 | Center = 0.5 * ((*Candidate->node) + (*a->node));
|
---|
| 3091 | Center += OrthogonalizedOben;
|
---|
[357fba] | 3092 |
|
---|
[273382] | 3093 | AngleCheck = Center - (*a->node);
|
---|
[f1cccd] | 3094 | norm = aCandidate.Norm();
|
---|
[357fba] | 3095 | // second point shall have smallest angle with respect to Oben vector
|
---|
[6613ec] | 3096 | if (norm < RADIUS * 2.) {
|
---|
[273382] | 3097 | angle = AngleCheck.Angle(Oben);
|
---|
[357fba] | 3098 | if (angle < Storage[0]) {
|
---|
[f67b6e] | 3099 | //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
|
---|
[a67d19] | 3100 | DoLog(1) && (Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n");
|
---|
[f1cccd] | 3101 | OptCandidate = Candidate;
|
---|
[357fba] | 3102 | Storage[0] = angle;
|
---|
[f67b6e] | 3103 | //Log() << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
|
---|
[357fba] | 3104 | } else {
|
---|
[f67b6e] | 3105 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
|
---|
[357fba] | 3106 | }
|
---|
| 3107 | } else {
|
---|
[f67b6e] | 3108 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
|
---|
[357fba] | 3109 | }
|
---|
| 3110 | } else {
|
---|
[f67b6e] | 3111 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
|
---|
[357fba] | 3112 | }
|
---|
| 3113 | }
|
---|
| 3114 | } else {
|
---|
[a67d19] | 3115 | DoLog(0) && (Log() << Verbose(0) << "Linked cell list is empty." << endl);
|
---|
[357fba] | 3116 | }
|
---|
| 3117 | }
|
---|
[6613ec] | 3118 | }
|
---|
| 3119 | ;
|
---|
[357fba] | 3120 |
|
---|
| 3121 | /** This recursive function finds a third point, to form a triangle with two given ones.
|
---|
| 3122 | * Note that this function is for the starting triangle.
|
---|
| 3123 | * The idea is as follows: A sphere with fixed radius is (almost) uniquely defined in space by three points
|
---|
| 3124 | * that sit on its boundary. Hence, when two points are given and we look for the (next) third point, then
|
---|
| 3125 | * the center of the sphere is still fixed up to a single parameter. The band of possible values
|
---|
| 3126 | * describes a circle in 3D-space. The old center of the sphere for the current base triangle gives
|
---|
| 3127 | * us the "null" on this circle, the new center of the candidate point will be some way along this
|
---|
| 3128 | * circle. The shorter the way the better is the candidate. Note that the direction is clearly given
|
---|
| 3129 | * by the normal vector of the base triangle that always points outwards by construction.
|
---|
| 3130 | * Hence, we construct a Center of this circle which sits right in the middle of the current base line.
|
---|
| 3131 | * We construct the normal vector that defines the plane this circle lies in, it is just in the
|
---|
| 3132 | * direction of the baseline. And finally, we need the radius of the circle, which is given by the rest
|
---|
| 3133 | * with respect to the length of the baseline and the sphere's fixed \a RADIUS.
|
---|
| 3134 | * Note that there is one difficulty: The circumcircle is uniquely defined, but for the circumsphere's center
|
---|
| 3135 | * there are two possibilities which becomes clear from the construction as seen below. Hence, we must check
|
---|
| 3136 | * both.
|
---|
| 3137 | * Note also that the acos() function is not unique on [0, 2.*M_PI). Hence, we need an additional check
|
---|
| 3138 | * to decide for one of the two possible angles. Therefore we need a SearchDirection and to make this check
|
---|
| 3139 | * sensible we need OldSphereCenter to be orthogonal to it. Either we construct SearchDirection orthogonal
|
---|
| 3140 | * right away, or -- what we do here -- we rotate the relative sphere centers such that this orthogonality
|
---|
| 3141 | * holds. Then, the normalized projection onto the SearchDirection is either +1 or -1 and thus states whether
|
---|
| 3142 | * the angle is uniquely in either (0,M_PI] or [M_PI, 2.*M_PI).
|
---|
[f1cccd] | 3143 | * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa FindStartingTriangle())
|
---|
[357fba] | 3144 | * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
|
---|
| 3145 | * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
|
---|
[f67b6e] | 3146 | * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
|
---|
[09898c] | 3147 | * @param ThirdPoint third point to avoid in search
|
---|
[357fba] | 3148 | * @param RADIUS radius of sphere
|
---|
[62bb91] | 3149 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 3150 | */
|
---|
[6613ec] | 3151 | 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] | 3152 | {
|
---|
[6613ec] | 3153 | Info FunctionInfo(__func__);
|
---|
| 3154 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
[357fba] | 3155 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 3156 | Vector SphereCenter;
|
---|
[6613ec] | 3157 | Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
|
---|
| 3158 | Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
|
---|
| 3159 | Vector NewNormalVector; // normal vector of the Candidate's triangle
|
---|
[357fba] | 3160 | Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
|
---|
[b998c3] | 3161 | Vector RelativeOldSphereCenter;
|
---|
| 3162 | Vector NewPlaneCenter;
|
---|
[357fba] | 3163 | double CircleRadius; // radius of this circle
|
---|
| 3164 | double radius;
|
---|
[b998c3] | 3165 | double otherradius;
|
---|
[357fba] | 3166 | double alpha, Otheralpha; // angles (i.e. parameter for the circle).
|
---|
| 3167 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
| 3168 | TesselPoint *Candidate = NULL;
|
---|
| 3169 |
|
---|
[a67d19] | 3170 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl);
|
---|
[357fba] | 3171 |
|
---|
[09898c] | 3172 | // copy old center
|
---|
[8cbb97] | 3173 | CandidateLine.OldCenter = OldSphereCenter;
|
---|
[09898c] | 3174 | CandidateLine.ThirdPoint = ThirdPoint;
|
---|
| 3175 | CandidateLine.pointlist.clear();
|
---|
[357fba] | 3176 |
|
---|
| 3177 | // construct center of circle
|
---|
[273382] | 3178 | CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
|
---|
| 3179 | (*CandidateLine.BaseLine->endpoints[1]->node->node));
|
---|
[357fba] | 3180 |
|
---|
| 3181 | // construct normal vector of circle
|
---|
[273382] | 3182 | CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
|
---|
| 3183 | (*CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 3184 |
|
---|
[273382] | 3185 | RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
|
---|
[b998c3] | 3186 |
|
---|
[09898c] | 3187 | // calculate squared radius TesselPoint *ThirdPoint,f circle
|
---|
[6613ec] | 3188 | radius = CirclePlaneNormal.NormSquared() / 4.;
|
---|
| 3189 | if (radius < RADIUS * RADIUS) {
|
---|
| 3190 | CircleRadius = RADIUS * RADIUS - radius;
|
---|
[357fba] | 3191 | CirclePlaneNormal.Normalize();
|
---|
[a67d19] | 3192 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
[357fba] | 3193 |
|
---|
| 3194 | // test whether old center is on the band's plane
|
---|
[273382] | 3195 | if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
|
---|
[8cbb97] | 3196 | 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] | 3197 | RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal);
|
---|
[357fba] | 3198 | }
|
---|
[b998c3] | 3199 | radius = RelativeOldSphereCenter.NormSquared();
|
---|
[357fba] | 3200 | if (fabs(radius - CircleRadius) < HULLEPSILON) {
|
---|
[a67d19] | 3201 | DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl);
|
---|
[357fba] | 3202 |
|
---|
| 3203 | // check SearchDirection
|
---|
[a67d19] | 3204 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
[8cbb97] | 3205 | if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
|
---|
[6613ec] | 3206 | DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
|
---|
[357fba] | 3207 | }
|
---|
| 3208 |
|
---|
[62bb91] | 3209 | // get cell for the starting point
|
---|
[357fba] | 3210 | if (LC->SetIndexToVector(&CircleCenter)) {
|
---|
[6613ec] | 3211 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
| 3212 | N[i] = LC->n[i];
|
---|
[f67b6e] | 3213 | //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3214 | } else {
|
---|
[6613ec] | 3215 | DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);
|
---|
[357fba] | 3216 | return;
|
---|
| 3217 | }
|
---|
[62bb91] | 3218 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[f67b6e] | 3219 | //Log() << Verbose(1) << "LC Intervals:";
|
---|
[6613ec] | 3220 | for (int i = 0; i < NDIM; i++) {
|
---|
| 3221 | Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
|
---|
| 3222 | Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
|
---|
[e138de] | 3223 | //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
|
---|
[357fba] | 3224 | }
|
---|
[e138de] | 3225 | //Log() << Verbose(0) << endl;
|
---|
[357fba] | 3226 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3227 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3228 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3229 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 3230 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3231 | if (List != NULL) {
|
---|
[734816] | 3232 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 3233 | Candidate = (*Runner);
|
---|
| 3234 |
|
---|
| 3235 | // check for three unique points
|
---|
[a67d19] | 3236 | DoLog(2) && (Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl);
|
---|
[6613ec] | 3237 | if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) {
|
---|
[357fba] | 3238 |
|
---|
[b998c3] | 3239 | // find center on the plane
|
---|
| 3240 | GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
|
---|
[a67d19] | 3241 | DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl);
|
---|
[357fba] | 3242 |
|
---|
[0a4f7f] | 3243 | try {
|
---|
| 3244 | NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node),
|
---|
[8cbb97] | 3245 | *(CandidateLine.BaseLine->endpoints[1]->node->node),
|
---|
| 3246 | *(Candidate->node)).getNormal();
|
---|
[a67d19] | 3247 | DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl);
|
---|
[273382] | 3248 | radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter);
|
---|
[a67d19] | 3249 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
| 3250 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
| 3251 | DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl);
|
---|
[6613ec] | 3252 | if (radius < RADIUS * RADIUS) {
|
---|
[273382] | 3253 | otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter);
|
---|
[620a3f] | 3254 | if (fabs(radius - otherradius) < HULLEPSILON) {
|
---|
| 3255 | // construct both new centers
|
---|
[8cbb97] | 3256 | NewSphereCenter = NewPlaneCenter;
|
---|
| 3257 | OtherNewSphereCenter= NewPlaneCenter;
|
---|
| 3258 | helper = NewNormalVector;
|
---|
[620a3f] | 3259 | helper.Scale(sqrt(RADIUS * RADIUS - radius));
|
---|
| 3260 | 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] | 3261 | NewSphereCenter += helper;
|
---|
[620a3f] | 3262 | DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl);
|
---|
| 3263 | // OtherNewSphereCenter is created by the same vector just in the other direction
|
---|
| 3264 | helper.Scale(-1.);
|
---|
[8cbb97] | 3265 | OtherNewSphereCenter += helper;
|
---|
[620a3f] | 3266 | DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl);
|
---|
| 3267 | alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
| 3268 | Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
[b1a6d8] | 3269 | if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
|
---|
[8cbb97] | 3270 | if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter))
|
---|
[b1a6d8] | 3271 | alpha = Otheralpha;
|
---|
| 3272 | } else
|
---|
| 3273 | alpha = min(alpha, Otheralpha);
|
---|
[620a3f] | 3274 | // if there is a better candidate, drop the current list and add the new candidate
|
---|
| 3275 | // otherwise ignore the new candidate and keep the list
|
---|
| 3276 | if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
|
---|
| 3277 | if (fabs(alpha - Otheralpha) > MYEPSILON) {
|
---|
[8cbb97] | 3278 | CandidateLine.OptCenter = NewSphereCenter;
|
---|
| 3279 | CandidateLine.OtherOptCenter = OtherNewSphereCenter;
|
---|
[620a3f] | 3280 | } else {
|
---|
[8cbb97] | 3281 | CandidateLine.OptCenter = OtherNewSphereCenter;
|
---|
| 3282 | CandidateLine.OtherOptCenter = NewSphereCenter;
|
---|
[620a3f] | 3283 | }
|
---|
| 3284 | // if there is an equal candidate, add it to the list without clearing the list
|
---|
| 3285 | if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
|
---|
| 3286 | CandidateLine.pointlist.push_back(Candidate);
|
---|
| 3287 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
|
---|
| 3288 | } else {
|
---|
| 3289 | // remove all candidates from the list and then the list itself
|
---|
| 3290 | CandidateLine.pointlist.clear();
|
---|
| 3291 | CandidateLine.pointlist.push_back(Candidate);
|
---|
| 3292 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
|
---|
| 3293 | }
|
---|
| 3294 | CandidateLine.ShortestAngle = alpha;
|
---|
| 3295 | DoLog(0) && (Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl);
|
---|
[357fba] | 3296 | } else {
|
---|
[620a3f] | 3297 | if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
|
---|
| 3298 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl);
|
---|
| 3299 | } else {
|
---|
| 3300 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl);
|
---|
| 3301 | }
|
---|
[357fba] | 3302 | }
|
---|
| 3303 | } else {
|
---|
[620a3f] | 3304 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
|
---|
[357fba] | 3305 | }
|
---|
| 3306 | } else {
|
---|
[a67d19] | 3307 | DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl);
|
---|
[357fba] | 3308 | }
|
---|
[0a4f7f] | 3309 | }
|
---|
| 3310 | catch (LinearDependenceException &excp){
|
---|
| 3311 | Log() << Verbose(1) << excp;
|
---|
[f67b6e] | 3312 | Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
|
---|
[357fba] | 3313 | }
|
---|
| 3314 | } else {
|
---|
[09898c] | 3315 | if (ThirdPoint != NULL) {
|
---|
[a67d19] | 3316 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << "." << endl);
|
---|
[357fba] | 3317 | } else {
|
---|
[a67d19] | 3318 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl);
|
---|
[357fba] | 3319 | }
|
---|
| 3320 | }
|
---|
| 3321 | }
|
---|
| 3322 | }
|
---|
| 3323 | }
|
---|
| 3324 | } else {
|
---|
[6613ec] | 3325 | DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
|
---|
[357fba] | 3326 | }
|
---|
| 3327 | } else {
|
---|
[09898c] | 3328 | if (ThirdPoint != NULL)
|
---|
[a67d19] | 3329 | DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!" << endl);
|
---|
[357fba] | 3330 | else
|
---|
[a67d19] | 3331 | DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl);
|
---|
[357fba] | 3332 | }
|
---|
| 3333 |
|
---|
[734816] | 3334 | DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl);
|
---|
[f67b6e] | 3335 | if (CandidateLine.pointlist.size() > 1) {
|
---|
| 3336 | CandidateLine.pointlist.unique();
|
---|
| 3337 | CandidateLine.pointlist.sort(); //SortCandidates);
|
---|
[357fba] | 3338 | }
|
---|
[6613ec] | 3339 |
|
---|
| 3340 | if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
|
---|
| 3341 | DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
|
---|
| 3342 | performCriticalExit();
|
---|
| 3343 | }
|
---|
| 3344 | }
|
---|
| 3345 | ;
|
---|
[357fba] | 3346 |
|
---|
| 3347 | /** Finds the endpoint two lines are sharing.
|
---|
| 3348 | * \param *line1 first line
|
---|
| 3349 | * \param *line2 second line
|
---|
| 3350 | * \return point which is shared or NULL if none
|
---|
| 3351 | */
|
---|
[776b64] | 3352 | class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
|
---|
[357fba] | 3353 | {
|
---|
[6613ec] | 3354 | Info FunctionInfo(__func__);
|
---|
[776b64] | 3355 | const BoundaryLineSet * lines[2] = { line1, line2 };
|
---|
[357fba] | 3356 | class BoundaryPointSet *node = NULL;
|
---|
[c15ca2] | 3357 | PointMap OrderMap;
|
---|
| 3358 | PointTestPair OrderTest;
|
---|
[357fba] | 3359 | for (int i = 0; i < 2; i++)
|
---|
| 3360 | // for both lines
|
---|
[6613ec] | 3361 | for (int j = 0; j < 2; j++) { // for both endpoints
|
---|
| 3362 | OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
|
---|
| 3363 | if (!OrderTest.second) { // if insertion fails, we have common endpoint
|
---|
| 3364 | node = OrderTest.first->second;
|
---|
[a67d19] | 3365 | DoLog(1) && (Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl);
|
---|
[6613ec] | 3366 | j = 2;
|
---|
| 3367 | i = 2;
|
---|
| 3368 | break;
|
---|
[357fba] | 3369 | }
|
---|
[6613ec] | 3370 | }
|
---|
[357fba] | 3371 | return node;
|
---|
[6613ec] | 3372 | }
|
---|
| 3373 | ;
|
---|
[357fba] | 3374 |
|
---|
[c15ca2] | 3375 | /** Finds the boundary points that are closest to a given Vector \a *x.
|
---|
[62bb91] | 3376 | * \param *out output stream for debugging
|
---|
| 3377 | * \param *x Vector to look from
|
---|
[c15ca2] | 3378 | * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
|
---|
[62bb91] | 3379 | */
|
---|
[97498a] | 3380 | DistanceToPointMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 3381 | {
|
---|
[c15ca2] | 3382 | Info FunctionInfo(__func__);
|
---|
[71b20e] | 3383 | PointMap::const_iterator FindPoint;
|
---|
| 3384 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
[62bb91] | 3385 |
|
---|
| 3386 | if (LinesOnBoundary.empty()) {
|
---|
[6613ec] | 3387 | DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);
|
---|
[62bb91] | 3388 | return NULL;
|
---|
| 3389 | }
|
---|
[71b20e] | 3390 |
|
---|
| 3391 | // gather all points close to the desired one
|
---|
| 3392 | LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
|
---|
[6613ec] | 3393 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
[71b20e] | 3394 | N[i] = LC->n[i];
|
---|
[a67d19] | 3395 | DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
|
---|
[97498a] | 3396 | DistanceToPointMap * points = new DistanceToPointMap;
|
---|
[71b20e] | 3397 | LC->GetNeighbourBounds(Nlower, Nupper);
|
---|
| 3398 | //Log() << Verbose(1) << endl;
|
---|
| 3399 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3400 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3401 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3402 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[71b20e] | 3403 | //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
|
---|
| 3404 | if (List != NULL) {
|
---|
[734816] | 3405 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[71b20e] | 3406 | FindPoint = PointsOnBoundary.find((*Runner)->nr);
|
---|
[97498a] | 3407 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
[8cbb97] | 3408 | points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second));
|
---|
[a67d19] | 3409 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl);
|
---|
[97498a] | 3410 | }
|
---|
[71b20e] | 3411 | }
|
---|
| 3412 | } else {
|
---|
[6613ec] | 3413 | DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
|
---|
[99593f] | 3414 | }
|
---|
[57066a] | 3415 | }
|
---|
[62bb91] | 3416 |
|
---|
[71b20e] | 3417 | // check whether we found some points
|
---|
[c15ca2] | 3418 | if (points->empty()) {
|
---|
[6613ec] | 3419 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
| 3420 | delete (points);
|
---|
[c15ca2] | 3421 | return NULL;
|
---|
| 3422 | }
|
---|
| 3423 | return points;
|
---|
[6613ec] | 3424 | }
|
---|
| 3425 | ;
|
---|
[c15ca2] | 3426 |
|
---|
| 3427 | /** Finds the boundary line that is closest to a given Vector \a *x.
|
---|
| 3428 | * \param *out output stream for debugging
|
---|
| 3429 | * \param *x Vector to look from
|
---|
| 3430 | * \return closest BoundaryLineSet or NULL in degenerate case.
|
---|
| 3431 | */
|
---|
| 3432 | BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const
|
---|
| 3433 | {
|
---|
| 3434 | Info FunctionInfo(__func__);
|
---|
| 3435 | // get closest points
|
---|
[6613ec] | 3436 | DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
|
---|
[c15ca2] | 3437 | if (points == NULL) {
|
---|
[6613ec] | 3438 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
[71b20e] | 3439 | return NULL;
|
---|
| 3440 | }
|
---|
[62bb91] | 3441 |
|
---|
[71b20e] | 3442 | // for each point, check its lines, remember closest
|
---|
[a67d19] | 3443 | DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl);
|
---|
[71b20e] | 3444 | BoundaryLineSet *ClosestLine = NULL;
|
---|
| 3445 | double MinDistance = -1.;
|
---|
| 3446 | Vector helper;
|
---|
| 3447 | Vector Center;
|
---|
| 3448 | Vector BaseLine;
|
---|
[97498a] | 3449 | for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
|
---|
[c15ca2] | 3450 | for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
|
---|
[71b20e] | 3451 | // calculate closest point on line to desired point
|
---|
[273382] | 3452 | helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) +
|
---|
| 3453 | (*(LineRunner->second)->endpoints[1]->node->node));
|
---|
| 3454 | Center = (*x) - helper;
|
---|
| 3455 | BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
|
---|
| 3456 | (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3457 | Center.ProjectOntoPlane(BaseLine);
|
---|
[71b20e] | 3458 | const double distance = Center.NormSquared();
|
---|
| 3459 | if ((ClosestLine == NULL) || (distance < MinDistance)) {
|
---|
| 3460 | // additionally calculate intersection on line (whether it's on the line section or not)
|
---|
[273382] | 3461 | helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center;
|
---|
| 3462 | const double lengthA = helper.ScalarProduct(BaseLine);
|
---|
| 3463 | helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center;
|
---|
| 3464 | const double lengthB = helper.ScalarProduct(BaseLine);
|
---|
[6613ec] | 3465 | if (lengthB * lengthA < 0) { // if have different sign
|
---|
[71b20e] | 3466 | ClosestLine = LineRunner->second;
|
---|
| 3467 | MinDistance = distance;
|
---|
[a67d19] | 3468 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl);
|
---|
[71b20e] | 3469 | } else {
|
---|
[a67d19] | 3470 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl);
|
---|
[71b20e] | 3471 | }
|
---|
| 3472 | } else {
|
---|
[a67d19] | 3473 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl);
|
---|
[71b20e] | 3474 | }
|
---|
[99593f] | 3475 | }
|
---|
[57066a] | 3476 | }
|
---|
[6613ec] | 3477 | delete (points);
|
---|
[71b20e] | 3478 | // check whether closest line is "too close" :), then it's inside
|
---|
| 3479 | if (ClosestLine == NULL) {
|
---|
[a67d19] | 3480 | DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
|
---|
[62bb91] | 3481 | return NULL;
|
---|
[71b20e] | 3482 | }
|
---|
[c15ca2] | 3483 | return ClosestLine;
|
---|
[6613ec] | 3484 | }
|
---|
| 3485 | ;
|
---|
[c15ca2] | 3486 |
|
---|
| 3487 | /** Finds the triangle that is closest to a given Vector \a *x.
|
---|
| 3488 | * \param *out output stream for debugging
|
---|
| 3489 | * \param *x Vector to look from
|
---|
| 3490 | * \return BoundaryTriangleSet of nearest triangle or NULL.
|
---|
| 3491 | */
|
---|
| 3492 | TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
|
---|
| 3493 | {
|
---|
[6613ec] | 3494 | Info FunctionInfo(__func__);
|
---|
| 3495 | // get closest points
|
---|
| 3496 | DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
|
---|
[c15ca2] | 3497 | if (points == NULL) {
|
---|
[6613ec] | 3498 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
[c15ca2] | 3499 | return NULL;
|
---|
| 3500 | }
|
---|
| 3501 |
|
---|
| 3502 | // for each point, check its lines, remember closest
|
---|
[a67d19] | 3503 | DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl);
|
---|
[48b47a] | 3504 | LineSet ClosestLines;
|
---|
[97498a] | 3505 | double MinDistance = 1e+16;
|
---|
| 3506 | Vector BaseLineIntersection;
|
---|
[c15ca2] | 3507 | Vector Center;
|
---|
| 3508 | Vector BaseLine;
|
---|
[97498a] | 3509 | Vector BaseLineCenter;
|
---|
| 3510 | for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
|
---|
[c15ca2] | 3511 | for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
|
---|
[97498a] | 3512 |
|
---|
[273382] | 3513 | BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
|
---|
| 3514 | (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
[97498a] | 3515 | const double lengthBase = BaseLine.NormSquared();
|
---|
| 3516 |
|
---|
[273382] | 3517 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node);
|
---|
[97498a] | 3518 | const double lengthEndA = BaseLineIntersection.NormSquared();
|
---|
| 3519 |
|
---|
[273382] | 3520 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
[97498a] | 3521 | const double lengthEndB = BaseLineIntersection.NormSquared();
|
---|
| 3522 |
|
---|
[6613ec] | 3523 | if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
|
---|
[48b47a] | 3524 | const double lengthEnd = Min(lengthEndA, lengthEndB);
|
---|
| 3525 | if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
|
---|
| 3526 | ClosestLines.clear();
|
---|
| 3527 | ClosestLines.insert(LineRunner->second);
|
---|
| 3528 | MinDistance = lengthEnd;
|
---|
[a67d19] | 3529 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl);
|
---|
[6613ec] | 3530 | } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
|
---|
[48b47a] | 3531 | ClosestLines.insert(LineRunner->second);
|
---|
[a67d19] | 3532 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl);
|
---|
[48b47a] | 3533 | } else { // line is worse
|
---|
[a67d19] | 3534 | 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] | 3535 | }
|
---|
| 3536 | } else { // intersection is closer, calculate
|
---|
[c15ca2] | 3537 | // calculate closest point on line to desired point
|
---|
[273382] | 3538 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3539 | Center = BaseLineIntersection;
|
---|
| 3540 | Center.ProjectOntoPlane(BaseLine);
|
---|
| 3541 | BaseLineIntersection -= Center;
|
---|
[97498a] | 3542 | const double distance = BaseLineIntersection.NormSquared();
|
---|
| 3543 | if (Center.NormSquared() > BaseLine.NormSquared()) {
|
---|
[6613ec] | 3544 | DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);
|
---|
[97498a] | 3545 | }
|
---|
[48b47a] | 3546 | if ((ClosestLines.empty()) || (distance < MinDistance)) {
|
---|
| 3547 | ClosestLines.insert(LineRunner->second);
|
---|
[97498a] | 3548 | MinDistance = distance;
|
---|
[a67d19] | 3549 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl);
|
---|
[c15ca2] | 3550 | } else {
|
---|
[a67d19] | 3551 | DoLog(2) && (Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl);
|
---|
[c15ca2] | 3552 | }
|
---|
| 3553 | }
|
---|
| 3554 | }
|
---|
| 3555 | }
|
---|
[6613ec] | 3556 | delete (points);
|
---|
[c15ca2] | 3557 |
|
---|
| 3558 | // check whether closest line is "too close" :), then it's inside
|
---|
[48b47a] | 3559 | if (ClosestLines.empty()) {
|
---|
[a67d19] | 3560 | DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
|
---|
[c15ca2] | 3561 | return NULL;
|
---|
| 3562 | }
|
---|
| 3563 | TriangleList * candidates = new TriangleList;
|
---|
[48b47a] | 3564 | for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
|
---|
| 3565 | for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
|
---|
[6613ec] | 3566 | candidates->push_back(Runner->second);
|
---|
| 3567 | }
|
---|
[c15ca2] | 3568 | return candidates;
|
---|
[6613ec] | 3569 | }
|
---|
| 3570 | ;
|
---|
[62bb91] | 3571 |
|
---|
| 3572 | /** Finds closest triangle to a point.
|
---|
| 3573 | * This basically just takes care of the degenerate case, which is not handled in FindClosestTrianglesToPoint().
|
---|
| 3574 | * \param *out output stream for debugging
|
---|
| 3575 | * \param *x Vector to look from
|
---|
[8db598] | 3576 | * \param &distance contains found distance on return
|
---|
[62bb91] | 3577 | * \return list of BoundaryTriangleSet of nearest triangles or NULL.
|
---|
| 3578 | */
|
---|
[c15ca2] | 3579 | class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 3580 | {
|
---|
[6613ec] | 3581 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 3582 | class BoundaryTriangleSet *result = NULL;
|
---|
[c15ca2] | 3583 | TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
|
---|
| 3584 | TriangleList candidates;
|
---|
[57066a] | 3585 | Vector Center;
|
---|
[71b20e] | 3586 | Vector helper;
|
---|
[62bb91] | 3587 |
|
---|
[71b20e] | 3588 | if ((triangles == NULL) || (triangles->empty()))
|
---|
[62bb91] | 3589 | return NULL;
|
---|
| 3590 |
|
---|
[97498a] | 3591 | // go through all and pick the one with the best alignment to x
|
---|
[6613ec] | 3592 | double MinAlignment = 2. * M_PI;
|
---|
[c15ca2] | 3593 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
|
---|
[71b20e] | 3594 | (*Runner)->GetCenter(&Center);
|
---|
[273382] | 3595 | helper = (*x) - Center;
|
---|
| 3596 | const double Alignment = helper.Angle((*Runner)->NormalVector);
|
---|
[97498a] | 3597 | if (Alignment < MinAlignment) {
|
---|
| 3598 | result = *Runner;
|
---|
| 3599 | MinAlignment = Alignment;
|
---|
[a67d19] | 3600 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl);
|
---|
[71b20e] | 3601 | } else {
|
---|
[a67d19] | 3602 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl);
|
---|
[57066a] | 3603 | }
|
---|
| 3604 | }
|
---|
[6613ec] | 3605 | delete (triangles);
|
---|
[97498a] | 3606 |
|
---|
[62bb91] | 3607 | return result;
|
---|
[6613ec] | 3608 | }
|
---|
| 3609 | ;
|
---|
[62bb91] | 3610 |
|
---|
[9473f6] | 3611 | /** Checks whether the provided Vector is within the Tesselation structure.
|
---|
| 3612 | * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value.
|
---|
| 3613 | * @param point of which to check the position
|
---|
| 3614 | * @param *LC LinkedCell structure
|
---|
| 3615 | *
|
---|
| 3616 | * @return true if the point is inside the Tesselation structure, false otherwise
|
---|
| 3617 | */
|
---|
| 3618 | bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
|
---|
| 3619 | {
|
---|
[8db598] | 3620 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3621 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3622 |
|
---|
| 3623 | return Intersections.IsInside();
|
---|
[9473f6] | 3624 | }
|
---|
[6613ec] | 3625 | ;
|
---|
[9473f6] | 3626 |
|
---|
| 3627 | /** Returns the distance to the surface given by the tesselation.
|
---|
[97498a] | 3628 | * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points
|
---|
[9473f6] | 3629 | * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the
|
---|
| 3630 | * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's
|
---|
| 3631 | * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle().
|
---|
| 3632 | * In the end we additionally find the point on the triangle who was smallest distance to \a Point:
|
---|
| 3633 | * -# Separate distance from point to center in vector in NormalDirection and on the triangle plane.
|
---|
| 3634 | * -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds.
|
---|
| 3635 | * -# If inside, take it to calculate closest distance
|
---|
| 3636 | * -# If not, take intersection with BoundaryLine as distance
|
---|
| 3637 | *
|
---|
| 3638 | * @note distance is squared despite it still contains a sign to determine in-/outside!
|
---|
[62bb91] | 3639 | *
|
---|
| 3640 | * @param point of which to check the position
|
---|
| 3641 | * @param *LC LinkedCell structure
|
---|
| 3642 | *
|
---|
[244a84] | 3643 | * @return >0 if outside, ==0 if on surface, <0 if inside
|
---|
[62bb91] | 3644 | */
|
---|
[244a84] | 3645 | double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
|
---|
[62bb91] | 3646 | {
|
---|
[fcad4b] | 3647 | Info FunctionInfo(__func__);
|
---|
[57066a] | 3648 | Vector Center;
|
---|
[71b20e] | 3649 | Vector helper;
|
---|
[97498a] | 3650 | Vector DistanceToCenter;
|
---|
| 3651 | Vector Intersection;
|
---|
[9473f6] | 3652 | double distance = 0.;
|
---|
[57066a] | 3653 |
|
---|
[244a84] | 3654 | if (triangle == NULL) {// is boundary point or only point in point cloud?
|
---|
[a67d19] | 3655 | DoLog(1) && (Log() << Verbose(1) << "No triangle given!" << endl);
|
---|
[244a84] | 3656 | return -1.;
|
---|
[71b20e] | 3657 | } else {
|
---|
[a67d19] | 3658 | DoLog(1) && (Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl);
|
---|
[57066a] | 3659 | }
|
---|
| 3660 |
|
---|
[244a84] | 3661 | triangle->GetCenter(&Center);
|
---|
[a67d19] | 3662 | DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl);
|
---|
[273382] | 3663 | DistanceToCenter = Center - Point;
|
---|
[a67d19] | 3664 | DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl);
|
---|
[97498a] | 3665 |
|
---|
| 3666 | // check whether we are on boundary
|
---|
[273382] | 3667 | if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) {
|
---|
[97498a] | 3668 | // calculate whether inside of triangle
|
---|
[273382] | 3669 | DistanceToCenter = Point + triangle->NormalVector; // points outside
|
---|
| 3670 | Center = Point - triangle->NormalVector; // points towards MolCenter
|
---|
[a67d19] | 3671 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl);
|
---|
[244a84] | 3672 | if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
|
---|
[a67d19] | 3673 | DoLog(1) && (Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl);
|
---|
[9473f6] | 3674 | return 0.;
|
---|
[97498a] | 3675 | } else {
|
---|
[a67d19] | 3676 | DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl);
|
---|
[97498a] | 3677 | return false;
|
---|
| 3678 | }
|
---|
[57066a] | 3679 | } else {
|
---|
[9473f6] | 3680 | // calculate smallest distance
|
---|
[244a84] | 3681 | distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
|
---|
[a67d19] | 3682 | DoLog(1) && (Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl);
|
---|
[9473f6] | 3683 |
|
---|
| 3684 | // then check direction to boundary
|
---|
[273382] | 3685 | if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) {
|
---|
[a67d19] | 3686 | DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl);
|
---|
[9473f6] | 3687 | return -distance;
|
---|
| 3688 | } else {
|
---|
[a67d19] | 3689 | DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl);
|
---|
[9473f6] | 3690 | return +distance;
|
---|
| 3691 | }
|
---|
[57066a] | 3692 | }
|
---|
[6613ec] | 3693 | }
|
---|
| 3694 | ;
|
---|
[62bb91] | 3695 |
|
---|
[8db598] | 3696 | /** Calculates minimum distance from \a&Point to a tesselated surface.
|
---|
[244a84] | 3697 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
|
---|
| 3698 | * \param &Point point to calculate distance from
|
---|
| 3699 | * \param *LC needed for finding closest points fast
|
---|
| 3700 | * \return distance squared to closest point on surface
|
---|
| 3701 | */
|
---|
[8db598] | 3702 | double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const
|
---|
[244a84] | 3703 | {
|
---|
[8db598] | 3704 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3705 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3706 |
|
---|
| 3707 | return Intersections.GetSmallestDistance();
|
---|
[6613ec] | 3708 | }
|
---|
| 3709 | ;
|
---|
[8db598] | 3710 |
|
---|
| 3711 | /** Calculates minimum distance from \a&Point to a tesselated surface.
|
---|
| 3712 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
|
---|
| 3713 | * \param &Point point to calculate distance from
|
---|
| 3714 | * \param *LC needed for finding closest points fast
|
---|
| 3715 | * \return distance squared to closest point on surface
|
---|
| 3716 | */
|
---|
| 3717 | BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const
|
---|
| 3718 | {
|
---|
| 3719 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3720 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3721 |
|
---|
| 3722 | return Intersections.GetClosestTriangle();
|
---|
[6613ec] | 3723 | }
|
---|
| 3724 | ;
|
---|
[244a84] | 3725 |
|
---|
[62bb91] | 3726 | /** Gets all points connected to the provided point by triangulation lines.
|
---|
| 3727 | *
|
---|
| 3728 | * @param *Point of which get all connected points
|
---|
| 3729 | *
|
---|
[065e82] | 3730 | * @return set of the all points linked to the provided one
|
---|
[62bb91] | 3731 | */
|
---|
[c15ca2] | 3732 | TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
|
---|
[62bb91] | 3733 | {
|
---|
[6613ec] | 3734 | Info FunctionInfo(__func__);
|
---|
| 3735 | TesselPointSet *connectedPoints = new TesselPointSet;
|
---|
[5c7bf8] | 3736 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
[62bb91] | 3737 | TesselPoint* current;
|
---|
| 3738 | bool takePoint = false;
|
---|
[5c7bf8] | 3739 | // find the respective boundary point
|
---|
[776b64] | 3740 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[5c7bf8] | 3741 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 3742 | ReferencePoint = PointRunner->second;
|
---|
| 3743 | } else {
|
---|
[6613ec] | 3744 | DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
|
---|
[5c7bf8] | 3745 | ReferencePoint = NULL;
|
---|
| 3746 | }
|
---|
[62bb91] | 3747 |
|
---|
[065e82] | 3748 | // little trick so that we look just through lines connect to the BoundaryPoint
|
---|
[5c7bf8] | 3749 | // OR fall-back to look through all lines if there is no such BoundaryPoint
|
---|
[6613ec] | 3750 | const LineMap *Lines;
|
---|
| 3751 | ;
|
---|
[5c7bf8] | 3752 | if (ReferencePoint != NULL)
|
---|
| 3753 | Lines = &(ReferencePoint->lines);
|
---|
[776b64] | 3754 | else
|
---|
| 3755 | Lines = &LinesOnBoundary;
|
---|
| 3756 | LineMap::const_iterator findLines = Lines->begin();
|
---|
[5c7bf8] | 3757 | while (findLines != Lines->end()) {
|
---|
[6613ec] | 3758 | takePoint = false;
|
---|
| 3759 |
|
---|
| 3760 | if (findLines->second->endpoints[0]->Nr == Point->nr) {
|
---|
| 3761 | takePoint = true;
|
---|
| 3762 | current = findLines->second->endpoints[1]->node;
|
---|
| 3763 | } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
|
---|
| 3764 | takePoint = true;
|
---|
| 3765 | current = findLines->second->endpoints[0]->node;
|
---|
| 3766 | }
|
---|
[065e82] | 3767 |
|
---|
[6613ec] | 3768 | if (takePoint) {
|
---|
[a67d19] | 3769 | DoLog(1) && (Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl);
|
---|
[6613ec] | 3770 | connectedPoints->insert(current);
|
---|
| 3771 | }
|
---|
[62bb91] | 3772 |
|
---|
[6613ec] | 3773 | findLines++;
|
---|
[62bb91] | 3774 | }
|
---|
| 3775 |
|
---|
[71b20e] | 3776 | if (connectedPoints->empty()) { // if have not found any points
|
---|
[6613ec] | 3777 | DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl);
|
---|
[16d866] | 3778 | return NULL;
|
---|
| 3779 | }
|
---|
[065e82] | 3780 |
|
---|
[16d866] | 3781 | return connectedPoints;
|
---|
[6613ec] | 3782 | }
|
---|
| 3783 | ;
|
---|
[065e82] | 3784 |
|
---|
| 3785 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
[16d866] | 3786 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 3787 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 3788 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 3789 | * triangle we are looking for.
|
---|
| 3790 | *
|
---|
| 3791 | * @param *out output stream for debugging
|
---|
[27bd2f] | 3792 | * @param *SetOfNeighbours all points for which the angle should be calculated
|
---|
[16d866] | 3793 | * @param *Point of which get all connected points
|
---|
[065e82] | 3794 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 3795 | * @return list of the all points linked to the provided one
|
---|
[16d866] | 3796 | */
|
---|
[c15ca2] | 3797 | TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[16d866] | 3798 | {
|
---|
[6613ec] | 3799 | Info FunctionInfo(__func__);
|
---|
[16d866] | 3800 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3801 | TesselPointList *connectedCircle = new TesselPointList;
|
---|
[71b20e] | 3802 | Vector PlaneNormal;
|
---|
| 3803 | Vector AngleZero;
|
---|
| 3804 | Vector OrthogonalVector;
|
---|
| 3805 | Vector helper;
|
---|
[6613ec] | 3806 | const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL };
|
---|
[c15ca2] | 3807 | TriangleList *triangles = NULL;
|
---|
[71b20e] | 3808 |
|
---|
| 3809 | if (SetOfNeighbours == NULL) {
|
---|
[6613ec] | 3810 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
|
---|
| 3811 | delete (connectedCircle);
|
---|
[71b20e] | 3812 | return NULL;
|
---|
| 3813 | }
|
---|
| 3814 |
|
---|
| 3815 | // calculate central point
|
---|
| 3816 | triangles = FindTriangles(TrianglePoints);
|
---|
| 3817 | if ((triangles != NULL) && (!triangles->empty())) {
|
---|
[c15ca2] | 3818 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
|
---|
[273382] | 3819 | PlaneNormal += (*Runner)->NormalVector;
|
---|
[71b20e] | 3820 | } else {
|
---|
[6613ec] | 3821 | DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
|
---|
[71b20e] | 3822 | performCriticalExit();
|
---|
| 3823 | }
|
---|
[6613ec] | 3824 | PlaneNormal.Scale(1.0 / triangles->size());
|
---|
[a67d19] | 3825 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl);
|
---|
[71b20e] | 3826 | PlaneNormal.Normalize();
|
---|
| 3827 |
|
---|
| 3828 | // construct one orthogonal vector
|
---|
| 3829 | if (Reference != NULL) {
|
---|
[273382] | 3830 | AngleZero = (*Reference) - (*Point->node);
|
---|
| 3831 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3832 | }
|
---|
[6613ec] | 3833 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
|
---|
[a67d19] | 3834 | DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
|
---|
[273382] | 3835 | AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
|
---|
| 3836 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3837 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
[6613ec] | 3838 | DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
|
---|
[71b20e] | 3839 | performCriticalExit();
|
---|
| 3840 | }
|
---|
| 3841 | }
|
---|
[a67d19] | 3842 | DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
|
---|
[71b20e] | 3843 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
[0a4f7f] | 3844 | OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
|
---|
[71b20e] | 3845 | else
|
---|
[0a4f7f] | 3846 | OrthogonalVector.MakeNormalTo(PlaneNormal);
|
---|
[a67d19] | 3847 | DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
|
---|
[71b20e] | 3848 |
|
---|
| 3849 | // go through all connected points and calculate angle
|
---|
[c15ca2] | 3850 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
|
---|
[273382] | 3851 | helper = (*(*listRunner)->node) - (*Point->node);
|
---|
| 3852 | helper.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3853 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
[a67d19] | 3854 | DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl);
|
---|
[6613ec] | 3855 | anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
|
---|
[71b20e] | 3856 | }
|
---|
| 3857 |
|
---|
[6613ec] | 3858 | for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
[71b20e] | 3859 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 3860 | }
|
---|
| 3861 |
|
---|
| 3862 | return connectedCircle;
|
---|
| 3863 | }
|
---|
| 3864 |
|
---|
| 3865 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
| 3866 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 3867 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 3868 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 3869 | * triangle we are looking for.
|
---|
| 3870 | *
|
---|
| 3871 | * @param *SetOfNeighbours all points for which the angle should be calculated
|
---|
| 3872 | * @param *Point of which get all connected points
|
---|
| 3873 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 3874 | * @return list of the all points linked to the provided one
|
---|
| 3875 | */
|
---|
[c15ca2] | 3876 | TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[71b20e] | 3877 | {
|
---|
| 3878 | Info FunctionInfo(__func__);
|
---|
| 3879 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3880 | TesselPointList *connectedCircle = new TesselPointList;
|
---|
[065e82] | 3881 | Vector center;
|
---|
| 3882 | Vector PlaneNormal;
|
---|
| 3883 | Vector AngleZero;
|
---|
| 3884 | Vector OrthogonalVector;
|
---|
| 3885 | Vector helper;
|
---|
[62bb91] | 3886 |
|
---|
[27bd2f] | 3887 | if (SetOfNeighbours == NULL) {
|
---|
[6613ec] | 3888 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
|
---|
| 3889 | delete (connectedCircle);
|
---|
[99593f] | 3890 | return NULL;
|
---|
| 3891 | }
|
---|
[a2028e] | 3892 |
|
---|
[97498a] | 3893 | // check whether there's something to do
|
---|
| 3894 | if (SetOfNeighbours->size() < 3) {
|
---|
| 3895 | for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
|
---|
| 3896 | connectedCircle->push_back(*TesselRunner);
|
---|
| 3897 | return connectedCircle;
|
---|
| 3898 | }
|
---|
| 3899 |
|
---|
[a67d19] | 3900 | DoLog(1) && (Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl);
|
---|
[16d866] | 3901 | // calculate central point
|
---|
[97498a] | 3902 | TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
|
---|
| 3903 | TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
|
---|
| 3904 | TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin();
|
---|
| 3905 | TesselB++;
|
---|
| 3906 | TesselC++;
|
---|
| 3907 | TesselC++;
|
---|
| 3908 | int counter = 0;
|
---|
| 3909 | while (TesselC != SetOfNeighbours->end()) {
|
---|
[0a4f7f] | 3910 | helper = Plane(*((*TesselA)->node),
|
---|
| 3911 | *((*TesselB)->node),
|
---|
| 3912 | *((*TesselC)->node)).getNormal();
|
---|
[a67d19] | 3913 | DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl);
|
---|
[97498a] | 3914 | counter++;
|
---|
| 3915 | TesselA++;
|
---|
| 3916 | TesselB++;
|
---|
| 3917 | TesselC++;
|
---|
[273382] | 3918 | PlaneNormal += helper;
|
---|
[97498a] | 3919 | }
|
---|
| 3920 | //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
|
---|
| 3921 | // << "; scale factor " << counter;
|
---|
[6613ec] | 3922 | PlaneNormal.Scale(1.0 / (double) counter);
|
---|
| 3923 | // Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
|
---|
| 3924 | //
|
---|
| 3925 | // // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
|
---|
| 3926 | // PlaneNormal.CopyVector(Point->node);
|
---|
| 3927 | // PlaneNormal.SubtractVector(¢er);
|
---|
| 3928 | // PlaneNormal.Normalize();
|
---|
[a67d19] | 3929 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl);
|
---|
[62bb91] | 3930 |
|
---|
| 3931 | // construct one orthogonal vector
|
---|
[a2028e] | 3932 | if (Reference != NULL) {
|
---|
[273382] | 3933 | AngleZero = (*Reference) - (*Point->node);
|
---|
| 3934 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[a2028e] | 3935 | }
|
---|
| 3936 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
|
---|
[a67d19] | 3937 | DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
|
---|
[273382] | 3938 | AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
|
---|
| 3939 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[a2028e] | 3940 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
[6613ec] | 3941 | DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
|
---|
[a2028e] | 3942 | performCriticalExit();
|
---|
| 3943 | }
|
---|
| 3944 | }
|
---|
[a67d19] | 3945 | DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
|
---|
[a2028e] | 3946 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
[0a4f7f] | 3947 | OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
|
---|
[a2028e] | 3948 | else
|
---|
[0a4f7f] | 3949 | OrthogonalVector.MakeNormalTo(PlaneNormal);
|
---|
[a67d19] | 3950 | DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
|
---|
[16d866] | 3951 |
|
---|
[5c7bf8] | 3952 | // go through all connected points and calculate angle
|
---|
[6613ec] | 3953 | pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
|
---|
[c15ca2] | 3954 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
|
---|
[273382] | 3955 | helper = (*(*listRunner)->node) - (*Point->node);
|
---|
| 3956 | helper.ProjectOntoPlane(PlaneNormal);
|
---|
[f1cccd] | 3957 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
[97498a] | 3958 | if (angle > M_PI) // the correction is of no use here (and not desired)
|
---|
[6613ec] | 3959 | angle = 2. * M_PI - angle;
|
---|
[a67d19] | 3960 | DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl);
|
---|
[6613ec] | 3961 | InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
|
---|
[c15ca2] | 3962 | if (!InserterTest.second) {
|
---|
[6613ec] | 3963 | DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);
|
---|
[c15ca2] | 3964 | performCriticalExit();
|
---|
| 3965 | }
|
---|
[62bb91] | 3966 | }
|
---|
| 3967 |
|
---|
[6613ec] | 3968 | for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
[065e82] | 3969 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 3970 | }
|
---|
[62bb91] | 3971 |
|
---|
[065e82] | 3972 | return connectedCircle;
|
---|
| 3973 | }
|
---|
[62bb91] | 3974 |
|
---|
[065e82] | 3975 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path.
|
---|
| 3976 | *
|
---|
| 3977 | * @param *out output stream for debugging
|
---|
| 3978 | * @param *Point of which get all connected points
|
---|
| 3979 | * @return list of the all points linked to the provided one
|
---|
| 3980 | */
|
---|
[244a84] | 3981 | ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 3982 | {
|
---|
[6613ec] | 3983 | Info FunctionInfo(__func__);
|
---|
[065e82] | 3984 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[6613ec] | 3985 | list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ;
|
---|
[c15ca2] | 3986 | TesselPointList *connectedPath = NULL;
|
---|
[065e82] | 3987 | Vector center;
|
---|
| 3988 | Vector PlaneNormal;
|
---|
| 3989 | Vector AngleZero;
|
---|
| 3990 | Vector OrthogonalVector;
|
---|
| 3991 | Vector helper;
|
---|
| 3992 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
| 3993 | class BoundaryPointSet *CurrentPoint = NULL;
|
---|
| 3994 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 3995 | class BoundaryLineSet *CurrentLine = NULL;
|
---|
| 3996 | class BoundaryLineSet *StartLine = NULL;
|
---|
| 3997 | // find the respective boundary point
|
---|
[776b64] | 3998 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[065e82] | 3999 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 4000 | ReferencePoint = PointRunner->second;
|
---|
| 4001 | } else {
|
---|
[6613ec] | 4002 | DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
|
---|
[065e82] | 4003 | return NULL;
|
---|
| 4004 | }
|
---|
| 4005 |
|
---|
[6613ec] | 4006 | map<class BoundaryLineSet *, bool> TouchedLine;
|
---|
| 4007 | map<class BoundaryTriangleSet *, bool> TouchedTriangle;
|
---|
| 4008 | map<class BoundaryLineSet *, bool>::iterator LineRunner;
|
---|
| 4009 | map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
|
---|
[57066a] | 4010 | for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
|
---|
[6613ec] | 4011 | TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false));
|
---|
[57066a] | 4012 | for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
|
---|
[6613ec] | 4013 | TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false));
|
---|
[57066a] | 4014 | }
|
---|
[065e82] | 4015 | if (!ReferencePoint->lines.empty()) {
|
---|
| 4016 | for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) {
|
---|
[57066a] | 4017 | LineRunner = TouchedLine.find(runner->second);
|
---|
| 4018 | if (LineRunner == TouchedLine.end()) {
|
---|
[6613ec] | 4019 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);
|
---|
[57066a] | 4020 | } else if (!LineRunner->second) {
|
---|
| 4021 | LineRunner->second = true;
|
---|
[c15ca2] | 4022 | connectedPath = new TesselPointList;
|
---|
[065e82] | 4023 | triangle = NULL;
|
---|
| 4024 | CurrentLine = runner->second;
|
---|
| 4025 | StartLine = CurrentLine;
|
---|
| 4026 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
[a67d19] | 4027 | DoLog(1) && (Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl);
|
---|
[065e82] | 4028 | do {
|
---|
| 4029 | // push current one
|
---|
[a67d19] | 4030 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
|
---|
[065e82] | 4031 | connectedPath->push_back(CurrentPoint->node);
|
---|
| 4032 |
|
---|
| 4033 | // find next triangle
|
---|
[57066a] | 4034 | for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
|
---|
[a67d19] | 4035 | DoLog(1) && (Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl);
|
---|
[57066a] | 4036 | if ((Runner->second != triangle)) { // look for first triangle not equal to old one
|
---|
| 4037 | triangle = Runner->second;
|
---|
| 4038 | TriangleRunner = TouchedTriangle.find(triangle);
|
---|
| 4039 | if (TriangleRunner != TouchedTriangle.end()) {
|
---|
| 4040 | if (!TriangleRunner->second) {
|
---|
| 4041 | TriangleRunner->second = true;
|
---|
[a67d19] | 4042 | DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl);
|
---|
[57066a] | 4043 | break;
|
---|
| 4044 | } else {
|
---|
[a67d19] | 4045 | DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl);
|
---|
[57066a] | 4046 | triangle = NULL;
|
---|
| 4047 | }
|
---|
| 4048 | } else {
|
---|
[6613ec] | 4049 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);
|
---|
[57066a] | 4050 | triangle = NULL;
|
---|
| 4051 | }
|
---|
[065e82] | 4052 | }
|
---|
| 4053 | }
|
---|
[57066a] | 4054 | if (triangle == NULL)
|
---|
| 4055 | break;
|
---|
[065e82] | 4056 | // find next line
|
---|
[6613ec] | 4057 | for (int i = 0; i < 3; i++) {
|
---|
[065e82] | 4058 | if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
|
---|
| 4059 | CurrentLine = triangle->lines[i];
|
---|
[a67d19] | 4060 | DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl);
|
---|
[065e82] | 4061 | break;
|
---|
| 4062 | }
|
---|
| 4063 | }
|
---|
[57066a] | 4064 | LineRunner = TouchedLine.find(CurrentLine);
|
---|
| 4065 | if (LineRunner == TouchedLine.end())
|
---|
[6613ec] | 4066 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);
|
---|
[065e82] | 4067 | else
|
---|
[57066a] | 4068 | LineRunner->second = true;
|
---|
[065e82] | 4069 | // find next point
|
---|
| 4070 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
| 4071 |
|
---|
| 4072 | } while (CurrentLine != StartLine);
|
---|
| 4073 | // last point is missing, as it's on start line
|
---|
[a67d19] | 4074 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
|
---|
[57066a] | 4075 | if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
|
---|
| 4076 | connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
|
---|
[065e82] | 4077 |
|
---|
| 4078 | ListOfPaths->push_back(connectedPath);
|
---|
| 4079 | } else {
|
---|
[a67d19] | 4080 | DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl);
|
---|
[065e82] | 4081 | }
|
---|
| 4082 | }
|
---|
| 4083 | } else {
|
---|
[6613ec] | 4084 | DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);
|
---|
[065e82] | 4085 | }
|
---|
| 4086 |
|
---|
| 4087 | return ListOfPaths;
|
---|
[62bb91] | 4088 | }
|
---|
| 4089 |
|
---|
[065e82] | 4090 | /** Gets all closed paths on the circle of points connected to the provided point by triangulation lines, if this very point is removed.
|
---|
| 4091 | * From GetPathsOfConnectedPoints() extracts all single loops of intracrossing paths in the list of closed paths.
|
---|
| 4092 | * @param *out output stream for debugging
|
---|
| 4093 | * @param *Point of which get all connected points
|
---|
| 4094 | * @return list of the closed paths
|
---|
| 4095 | */
|
---|
[244a84] | 4096 | ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 4097 | {
|
---|
[6613ec] | 4098 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4099 | list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
|
---|
[6613ec] | 4100 | list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;
|
---|
[c15ca2] | 4101 | TesselPointList *connectedPath = NULL;
|
---|
| 4102 | TesselPointList *newPath = NULL;
|
---|
[065e82] | 4103 | int count = 0;
|
---|
[c15ca2] | 4104 | TesselPointList::iterator CircleRunner;
|
---|
| 4105 | TesselPointList::iterator CircleStart;
|
---|
[065e82] | 4106 |
|
---|
[6613ec] | 4107 | for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
|
---|
[065e82] | 4108 | connectedPath = *ListRunner;
|
---|
| 4109 |
|
---|
[a67d19] | 4110 | DoLog(1) && (Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl);
|
---|
[065e82] | 4111 |
|
---|
| 4112 | // go through list, look for reappearance of starting Point and count
|
---|
| 4113 | CircleStart = connectedPath->begin();
|
---|
| 4114 | // go through list, look for reappearance of starting Point and create list
|
---|
[c15ca2] | 4115 | TesselPointList::iterator Marker = CircleStart;
|
---|
[065e82] | 4116 | for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
|
---|
| 4117 | if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
|
---|
| 4118 | // we have a closed circle from Marker to new Marker
|
---|
[a67d19] | 4119 | DoLog(1) && (Log() << Verbose(1) << count + 1 << ". closed path consists of: ");
|
---|
[c15ca2] | 4120 | newPath = new TesselPointList;
|
---|
| 4121 | TesselPointList::iterator CircleSprinter = Marker;
|
---|
[065e82] | 4122 | for (; CircleSprinter != CircleRunner; CircleSprinter++) {
|
---|
| 4123 | newPath->push_back(*CircleSprinter);
|
---|
[a67d19] | 4124 | DoLog(0) && (Log() << Verbose(0) << (**CircleSprinter) << " <-> ");
|
---|
[065e82] | 4125 | }
|
---|
[a67d19] | 4126 | DoLog(0) && (Log() << Verbose(0) << ".." << endl);
|
---|
[065e82] | 4127 | count++;
|
---|
| 4128 | Marker = CircleRunner;
|
---|
| 4129 |
|
---|
| 4130 | // add to list
|
---|
| 4131 | ListofClosedPaths->push_back(newPath);
|
---|
| 4132 | }
|
---|
| 4133 | }
|
---|
| 4134 | }
|
---|
[a67d19] | 4135 | DoLog(1) && (Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl);
|
---|
[065e82] | 4136 |
|
---|
| 4137 | // delete list of paths
|
---|
| 4138 | while (!ListofPaths->empty()) {
|
---|
| 4139 | connectedPath = *(ListofPaths->begin());
|
---|
| 4140 | ListofPaths->remove(connectedPath);
|
---|
[6613ec] | 4141 | delete (connectedPath);
|
---|
[065e82] | 4142 | }
|
---|
[6613ec] | 4143 | delete (ListofPaths);
|
---|
[065e82] | 4144 |
|
---|
| 4145 | // exit
|
---|
| 4146 | return ListofClosedPaths;
|
---|
[6613ec] | 4147 | }
|
---|
| 4148 | ;
|
---|
[065e82] | 4149 |
|
---|
| 4150 | /** Gets all belonging triangles for a given BoundaryPointSet.
|
---|
| 4151 | * \param *out output stream for debugging
|
---|
| 4152 | * \param *Point BoundaryPoint
|
---|
| 4153 | * \return pointer to allocated list of triangles
|
---|
| 4154 | */
|
---|
[c15ca2] | 4155 | TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
|
---|
[065e82] | 4156 | {
|
---|
[6613ec] | 4157 | Info FunctionInfo(__func__);
|
---|
| 4158 | TriangleSet *connectedTriangles = new TriangleSet;
|
---|
[065e82] | 4159 |
|
---|
| 4160 | if (Point == NULL) {
|
---|
[6613ec] | 4161 | DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl);
|
---|
[065e82] | 4162 | } else {
|
---|
| 4163 | // go through its lines and insert all triangles
|
---|
[776b64] | 4164 | for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
|
---|
[065e82] | 4165 | for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
[6613ec] | 4166 | connectedTriangles->insert(TriangleRunner->second);
|
---|
| 4167 | }
|
---|
[065e82] | 4168 | }
|
---|
| 4169 |
|
---|
| 4170 | return connectedTriangles;
|
---|
[6613ec] | 4171 | }
|
---|
| 4172 | ;
|
---|
[065e82] | 4173 |
|
---|
[16d866] | 4174 | /** Removes a boundary point from the envelope while keeping it closed.
|
---|
[57066a] | 4175 | * We remove the old triangles connected to the point and re-create new triangles to close the surface following this ansatz:
|
---|
| 4176 | * -# a closed path(s) of boundary points surrounding the point to be removed is constructed
|
---|
| 4177 | * -# on each closed path, we pick three adjacent points, create a triangle with them and subtract the middle point from the path
|
---|
| 4178 | * -# we advance two points (i.e. the next triangle will start at the ending point of the last triangle) and continue as before
|
---|
| 4179 | * -# the surface is closed, when the path is empty
|
---|
| 4180 | * Thereby, we (hopefully) make sure that the removed points remains beneath the surface (this is checked via IsInnerPoint eventually).
|
---|
[16d866] | 4181 | * \param *out output stream for debugging
|
---|
| 4182 | * \param *point point to be removed
|
---|
| 4183 | * \return volume added to the volume inside the tesselated surface by the removal
|
---|
| 4184 | */
|
---|
[6613ec] | 4185 | double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point)
|
---|
| 4186 | {
|
---|
[16d866] | 4187 | class BoundaryLineSet *line = NULL;
|
---|
| 4188 | class BoundaryTriangleSet *triangle = NULL;
|
---|
[57066a] | 4189 | Vector OldPoint, NormalVector;
|
---|
[16d866] | 4190 | double volume = 0;
|
---|
| 4191 | int count = 0;
|
---|
| 4192 |
|
---|
[1d9b7aa] | 4193 | if (point == NULL) {
|
---|
[6613ec] | 4194 | DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);
|
---|
[1d9b7aa] | 4195 | return 0.;
|
---|
| 4196 | } else
|
---|
[a67d19] | 4197 | DoLog(0) && (Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl);
|
---|
[1d9b7aa] | 4198 |
|
---|
[16d866] | 4199 | // copy old location for the volume
|
---|
[273382] | 4200 | OldPoint = (*point->node->node);
|
---|
[16d866] | 4201 |
|
---|
| 4202 | // get list of connected points
|
---|
| 4203 | if (point->lines.empty()) {
|
---|
[6613ec] | 4204 | DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);
|
---|
[16d866] | 4205 | return 0.;
|
---|
| 4206 | }
|
---|
| 4207 |
|
---|
[c15ca2] | 4208 | list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
|
---|
| 4209 | TesselPointList *connectedPath = NULL;
|
---|
[065e82] | 4210 |
|
---|
| 4211 | // gather all triangles
|
---|
[16d866] | 4212 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
|
---|
[6613ec] | 4213 | count += LineRunner->second->triangles.size();
|
---|
[c15ca2] | 4214 | TriangleMap Candidates;
|
---|
[57066a] | 4215 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
|
---|
[16d866] | 4216 | line = LineRunner->second;
|
---|
| 4217 | for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
|
---|
| 4218 | triangle = TriangleRunner->second;
|
---|
[6613ec] | 4219 | Candidates.insert(TrianglePair(triangle->Nr, triangle));
|
---|
[16d866] | 4220 | }
|
---|
| 4221 | }
|
---|
| 4222 |
|
---|
[065e82] | 4223 | // remove all triangles
|
---|
[6613ec] | 4224 | count = 0;
|
---|
[57066a] | 4225 | NormalVector.Zero();
|
---|
[c15ca2] | 4226 | for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
|
---|
[a67d19] | 4227 | DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl);
|
---|
[273382] | 4228 | NormalVector -= Runner->second->NormalVector; // has to point inward
|
---|
[c15ca2] | 4229 | RemoveTesselationTriangle(Runner->second);
|
---|
[065e82] | 4230 | count++;
|
---|
| 4231 | }
|
---|
[a67d19] | 4232 | DoLog(1) && (Log() << Verbose(1) << count << " triangles were removed." << endl);
|
---|
[065e82] | 4233 |
|
---|
[c15ca2] | 4234 | list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
|
---|
| 4235 | list<TesselPointList *>::iterator ListRunner = ListAdvance;
|
---|
| 4236 | TriangleMap::iterator NumberRunner = Candidates.begin();
|
---|
| 4237 | TesselPointList::iterator StartNode, MiddleNode, EndNode;
|
---|
[57066a] | 4238 | double angle;
|
---|
| 4239 | double smallestangle;
|
---|
| 4240 | Vector Point, Reference, OrthogonalVector;
|
---|
[6613ec] | 4241 | if (count > 2) { // less than three triangles, then nothing will be created
|
---|
[065e82] | 4242 | class TesselPoint *TriangleCandidates[3];
|
---|
| 4243 | count = 0;
|
---|
[6613ec] | 4244 | for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
|
---|
[065e82] | 4245 | if (ListAdvance != ListOfClosedPaths->end())
|
---|
| 4246 | ListAdvance++;
|
---|
| 4247 |
|
---|
| 4248 | connectedPath = *ListRunner;
|
---|
| 4249 | // re-create all triangles by going through connected points list
|
---|
[c15ca2] | 4250 | LineList NewLines;
|
---|
[6613ec] | 4251 | for (; !connectedPath->empty();) {
|
---|
[57066a] | 4252 | // search middle node with widest angle to next neighbours
|
---|
| 4253 | EndNode = connectedPath->end();
|
---|
| 4254 | smallestangle = 0.;
|
---|
| 4255 | for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
|
---|
[a67d19] | 4256 | DoLog(1) && (Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
|
---|
[57066a] | 4257 | // construct vectors to next and previous neighbour
|
---|
| 4258 | StartNode = MiddleNode;
|
---|
| 4259 | if (StartNode == connectedPath->begin())
|
---|
| 4260 | StartNode = connectedPath->end();
|
---|
| 4261 | StartNode--;
|
---|
[e138de] | 4262 | //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl;
|
---|
[273382] | 4263 | Point = (*(*StartNode)->node) - (*(*MiddleNode)->node);
|
---|
[57066a] | 4264 | StartNode = MiddleNode;
|
---|
| 4265 | StartNode++;
|
---|
| 4266 | if (StartNode == connectedPath->end())
|
---|
| 4267 | StartNode = connectedPath->begin();
|
---|
[e138de] | 4268 | //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl;
|
---|
[273382] | 4269 | Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node);
|
---|
| 4270 | OrthogonalVector = (*(*MiddleNode)->node) - OldPoint;
|
---|
[0a4f7f] | 4271 | OrthogonalVector.MakeNormalTo(Reference);
|
---|
[57066a] | 4272 | angle = GetAngle(Point, Reference, OrthogonalVector);
|
---|
| 4273 | //if (angle < M_PI) // no wrong-sided triangles, please?
|
---|
[6613ec] | 4274 | if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
|
---|
| 4275 | smallestangle = angle;
|
---|
| 4276 | EndNode = MiddleNode;
|
---|
| 4277 | }
|
---|
[57066a] | 4278 | }
|
---|
| 4279 | MiddleNode = EndNode;
|
---|
| 4280 | if (MiddleNode == connectedPath->end()) {
|
---|
[6613ec] | 4281 | DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);
|
---|
[f67b6e] | 4282 | performCriticalExit();
|
---|
[57066a] | 4283 | }
|
---|
| 4284 | StartNode = MiddleNode;
|
---|
| 4285 | if (StartNode == connectedPath->begin())
|
---|
| 4286 | StartNode = connectedPath->end();
|
---|
| 4287 | StartNode--;
|
---|
| 4288 | EndNode++;
|
---|
| 4289 | if (EndNode == connectedPath->end())
|
---|
| 4290 | EndNode = connectedPath->begin();
|
---|
[a67d19] | 4291 | DoLog(2) && (Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl);
|
---|
| 4292 | DoLog(2) && (Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
|
---|
| 4293 | DoLog(2) && (Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl);
|
---|
| 4294 | DoLog(1) && (Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl);
|
---|
[57066a] | 4295 | TriangleCandidates[0] = *StartNode;
|
---|
| 4296 | TriangleCandidates[1] = *MiddleNode;
|
---|
| 4297 | TriangleCandidates[2] = *EndNode;
|
---|
[e138de] | 4298 | triangle = GetPresentTriangle(TriangleCandidates);
|
---|
[57066a] | 4299 | if (triangle != NULL) {
|
---|
[6613ec] | 4300 | DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl);
|
---|
[57066a] | 4301 | StartNode++;
|
---|
| 4302 | MiddleNode++;
|
---|
| 4303 | EndNode++;
|
---|
| 4304 | if (StartNode == connectedPath->end())
|
---|
| 4305 | StartNode = connectedPath->begin();
|
---|
| 4306 | if (MiddleNode == connectedPath->end())
|
---|
| 4307 | MiddleNode = connectedPath->begin();
|
---|
| 4308 | if (EndNode == connectedPath->end())
|
---|
| 4309 | EndNode = connectedPath->begin();
|
---|
| 4310 | continue;
|
---|
| 4311 | }
|
---|
[a67d19] | 4312 | DoLog(3) && (Log() << Verbose(3) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4313 | AddTesselationPoint(*StartNode, 0);
|
---|
| 4314 | AddTesselationPoint(*MiddleNode, 1);
|
---|
| 4315 | AddTesselationPoint(*EndNode, 2);
|
---|
[a67d19] | 4316 | DoLog(3) && (Log() << Verbose(3) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4317 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4318 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
[57066a] | 4319 | NewLines.push_back(BLS[1]);
|
---|
[f07f86d] | 4320 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[065e82] | 4321 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[57066a] | 4322 | BTS->GetNormalVector(NormalVector);
|
---|
[065e82] | 4323 | AddTesselationTriangle();
|
---|
| 4324 | // calculate volume summand as a general tetraeder
|
---|
[c0f6c6] | 4325 | volume += CalculateVolumeofGeneralTetraeder(*TPS[0]->node->node, *TPS[1]->node->node, *TPS[2]->node->node, OldPoint);
|
---|
[065e82] | 4326 | // advance number
|
---|
| 4327 | count++;
|
---|
[57066a] | 4328 |
|
---|
| 4329 | // prepare nodes for next triangle
|
---|
| 4330 | StartNode = EndNode;
|
---|
[a67d19] | 4331 | DoLog(2) && (Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl);
|
---|
[57066a] | 4332 | connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
|
---|
| 4333 | if (connectedPath->size() == 2) { // we are done
|
---|
| 4334 | connectedPath->remove(*StartNode); // remove the start node
|
---|
| 4335 | connectedPath->remove(*EndNode); // remove the end node
|
---|
| 4336 | break;
|
---|
| 4337 | } else if (connectedPath->size() < 2) { // something's gone wrong!
|
---|
[6613ec] | 4338 | DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);
|
---|
[f67b6e] | 4339 | performCriticalExit();
|
---|
[57066a] | 4340 | } else {
|
---|
| 4341 | MiddleNode = StartNode;
|
---|
| 4342 | MiddleNode++;
|
---|
| 4343 | if (MiddleNode == connectedPath->end())
|
---|
| 4344 | MiddleNode = connectedPath->begin();
|
---|
| 4345 | EndNode = MiddleNode;
|
---|
| 4346 | EndNode++;
|
---|
| 4347 | if (EndNode == connectedPath->end())
|
---|
| 4348 | EndNode = connectedPath->begin();
|
---|
| 4349 | }
|
---|
[065e82] | 4350 | }
|
---|
[57066a] | 4351 | // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
|
---|
| 4352 | if (NewLines.size() > 1) {
|
---|
[c15ca2] | 4353 | LineList::iterator Candidate;
|
---|
[57066a] | 4354 | class BoundaryLineSet *OtherBase = NULL;
|
---|
| 4355 | double tmp, maxgain;
|
---|
| 4356 | do {
|
---|
| 4357 | maxgain = 0;
|
---|
[6613ec] | 4358 | for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
|
---|
[e138de] | 4359 | tmp = PickFarthestofTwoBaselines(*Runner);
|
---|
[57066a] | 4360 | if (maxgain < tmp) {
|
---|
| 4361 | maxgain = tmp;
|
---|
| 4362 | Candidate = Runner;
|
---|
| 4363 | }
|
---|
| 4364 | }
|
---|
| 4365 | if (maxgain != 0) {
|
---|
| 4366 | volume += maxgain;
|
---|
[a67d19] | 4367 | DoLog(1) && (Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl);
|
---|
[e138de] | 4368 | OtherBase = FlipBaseline(*Candidate);
|
---|
[57066a] | 4369 | NewLines.erase(Candidate);
|
---|
| 4370 | NewLines.push_back(OtherBase);
|
---|
| 4371 | }
|
---|
| 4372 | } while (maxgain != 0.);
|
---|
| 4373 | }
|
---|
| 4374 |
|
---|
[065e82] | 4375 | ListOfClosedPaths->remove(connectedPath);
|
---|
[6613ec] | 4376 | delete (connectedPath);
|
---|
[16d866] | 4377 | }
|
---|
[a67d19] | 4378 | DoLog(0) && (Log() << Verbose(0) << count << " triangles were created." << endl);
|
---|
[065e82] | 4379 | } else {
|
---|
| 4380 | while (!ListOfClosedPaths->empty()) {
|
---|
| 4381 | ListRunner = ListOfClosedPaths->begin();
|
---|
| 4382 | connectedPath = *ListRunner;
|
---|
| 4383 | ListOfClosedPaths->remove(connectedPath);
|
---|
[6613ec] | 4384 | delete (connectedPath);
|
---|
[065e82] | 4385 | }
|
---|
[a67d19] | 4386 | DoLog(0) && (Log() << Verbose(0) << "No need to create any triangles." << endl);
|
---|
[16d866] | 4387 | }
|
---|
[6613ec] | 4388 | delete (ListOfClosedPaths);
|
---|
[16d866] | 4389 |
|
---|
[a67d19] | 4390 | DoLog(0) && (Log() << Verbose(0) << "Removed volume is " << volume << "." << endl);
|
---|
[357fba] | 4391 |
|
---|
[57066a] | 4392 | return volume;
|
---|
[6613ec] | 4393 | }
|
---|
| 4394 | ;
|
---|
[ab1932] | 4395 |
|
---|
| 4396 | /**
|
---|
[62bb91] | 4397 | * Finds triangles belonging to the three provided points.
|
---|
[ab1932] | 4398 | *
|
---|
[71b20e] | 4399 | * @param *Points[3] list, is expected to contain three points (NULL means wildcard)
|
---|
[ab1932] | 4400 | *
|
---|
[62bb91] | 4401 | * @return triangles which belong to the provided points, will be empty if there are none,
|
---|
[ab1932] | 4402 | * will usually be one, in case of degeneration, there will be two
|
---|
| 4403 | */
|
---|
[c15ca2] | 4404 | TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
|
---|
[ab1932] | 4405 | {
|
---|
[6613ec] | 4406 | Info FunctionInfo(__func__);
|
---|
| 4407 | TriangleList *result = new TriangleList;
|
---|
[776b64] | 4408 | LineMap::const_iterator FindLine;
|
---|
| 4409 | TriangleMap::const_iterator FindTriangle;
|
---|
[ab1932] | 4410 | class BoundaryPointSet *TrianglePoints[3];
|
---|
[71b20e] | 4411 | size_t NoOfWildcards = 0;
|
---|
[ab1932] | 4412 |
|
---|
| 4413 | for (int i = 0; i < 3; i++) {
|
---|
[71b20e] | 4414 | if (Points[i] == NULL) {
|
---|
| 4415 | NoOfWildcards++;
|
---|
[ab1932] | 4416 | TrianglePoints[i] = NULL;
|
---|
[71b20e] | 4417 | } else {
|
---|
| 4418 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
|
---|
| 4419 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 4420 | TrianglePoints[i] = FindPoint->second;
|
---|
| 4421 | } else {
|
---|
| 4422 | TrianglePoints[i] = NULL;
|
---|
| 4423 | }
|
---|
[ab1932] | 4424 | }
|
---|
| 4425 | }
|
---|
| 4426 |
|
---|
[71b20e] | 4427 | switch (NoOfWildcards) {
|
---|
| 4428 | case 0: // checks lines between the points in the Points for their adjacent triangles
|
---|
| 4429 | for (int i = 0; i < 3; i++) {
|
---|
| 4430 | if (TrianglePoints[i] != NULL) {
|
---|
[6613ec] | 4431 | for (int j = i + 1; j < 3; j++) {
|
---|
[71b20e] | 4432 | if (TrianglePoints[j] != NULL) {
|
---|
| 4433 | for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
|
---|
[6613ec] | 4434 | (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) {
|
---|
| 4435 | for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
|
---|
[71b20e] | 4436 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 4437 | result->push_back(FindTriangle->second);
|
---|
| 4438 | }
|
---|
| 4439 | }
|
---|
[ab1932] | 4440 | }
|
---|
[71b20e] | 4441 | // Is it sufficient to consider one of the triangle lines for this.
|
---|
| 4442 | return result;
|
---|
[ab1932] | 4443 | }
|
---|
| 4444 | }
|
---|
| 4445 | }
|
---|
| 4446 | }
|
---|
[71b20e] | 4447 | break;
|
---|
| 4448 | case 1: // copy all triangles of the respective line
|
---|
| 4449 | {
|
---|
[6613ec] | 4450 | int i = 0;
|
---|
[71b20e] | 4451 | for (; i < 3; i++)
|
---|
| 4452 | if (TrianglePoints[i] == NULL)
|
---|
| 4453 | break;
|
---|
[6613ec] | 4454 | for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap!
|
---|
| 4455 | (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) {
|
---|
| 4456 | for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
|
---|
[71b20e] | 4457 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 4458 | result->push_back(FindTriangle->second);
|
---|
| 4459 | }
|
---|
| 4460 | }
|
---|
| 4461 | }
|
---|
| 4462 | break;
|
---|
| 4463 | }
|
---|
| 4464 | case 2: // copy all triangles of the respective point
|
---|
| 4465 | {
|
---|
[6613ec] | 4466 | int i = 0;
|
---|
[71b20e] | 4467 | for (; i < 3; i++)
|
---|
| 4468 | if (TrianglePoints[i] != NULL)
|
---|
| 4469 | break;
|
---|
| 4470 | for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++)
|
---|
| 4471 | for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++)
|
---|
| 4472 | result->push_back(triangle->second);
|
---|
| 4473 | result->sort();
|
---|
| 4474 | result->unique();
|
---|
| 4475 | break;
|
---|
| 4476 | }
|
---|
| 4477 | case 3: // copy all triangles
|
---|
| 4478 | {
|
---|
| 4479 | for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++)
|
---|
| 4480 | result->push_back(triangle->second);
|
---|
| 4481 | break;
|
---|
[ab1932] | 4482 | }
|
---|
[71b20e] | 4483 | default:
|
---|
[6613ec] | 4484 | DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);
|
---|
[71b20e] | 4485 | performCriticalExit();
|
---|
| 4486 | break;
|
---|
[ab1932] | 4487 | }
|
---|
| 4488 |
|
---|
| 4489 | return result;
|
---|
| 4490 | }
|
---|
| 4491 |
|
---|
[6613ec] | 4492 | struct BoundaryLineSetCompare
|
---|
| 4493 | {
|
---|
| 4494 | bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b)
|
---|
| 4495 | {
|
---|
[856098] | 4496 | int lowerNra = -1;
|
---|
| 4497 | int lowerNrb = -1;
|
---|
| 4498 |
|
---|
| 4499 | if (a->endpoints[0] < a->endpoints[1])
|
---|
| 4500 | lowerNra = 0;
|
---|
| 4501 | else
|
---|
| 4502 | lowerNra = 1;
|
---|
| 4503 |
|
---|
| 4504 | if (b->endpoints[0] < b->endpoints[1])
|
---|
| 4505 | lowerNrb = 0;
|
---|
| 4506 | else
|
---|
| 4507 | lowerNrb = 1;
|
---|
| 4508 |
|
---|
| 4509 | if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
|
---|
| 4510 | return true;
|
---|
| 4511 | else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
|
---|
| 4512 | return false;
|
---|
[6613ec] | 4513 | else { // both lower-numbered endpoints are the same ...
|
---|
| 4514 | if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2])
|
---|
| 4515 | return true;
|
---|
| 4516 | else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2])
|
---|
| 4517 | return false;
|
---|
[856098] | 4518 | }
|
---|
| 4519 | return false;
|
---|
[6613ec] | 4520 | }
|
---|
| 4521 | ;
|
---|
[856098] | 4522 | };
|
---|
| 4523 |
|
---|
| 4524 | #define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
|
---|
| 4525 |
|
---|
[7c14ec] | 4526 | /**
|
---|
[57066a] | 4527 | * Finds all degenerated lines within the tesselation structure.
|
---|
[7c14ec] | 4528 | *
|
---|
[57066a] | 4529 | * @return map of keys of degenerated line pairs, each line occurs twice
|
---|
[7c14ec] | 4530 | * in the list, once as key and once as value
|
---|
| 4531 | */
|
---|
[c15ca2] | 4532 | IndexToIndex * Tesselation::FindAllDegeneratedLines()
|
---|
[7c14ec] | 4533 | {
|
---|
[6613ec] | 4534 | Info FunctionInfo(__func__);
|
---|
| 4535 | UniqueLines AllLines;
|
---|
[c15ca2] | 4536 | IndexToIndex * DegeneratedLines = new IndexToIndex;
|
---|
[7c14ec] | 4537 |
|
---|
| 4538 | // sanity check
|
---|
| 4539 | if (LinesOnBoundary.empty()) {
|
---|
[6613ec] | 4540 | DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");
|
---|
[57066a] | 4541 | return DegeneratedLines;
|
---|
[7c14ec] | 4542 | }
|
---|
[57066a] | 4543 | LineMap::iterator LineRunner1;
|
---|
[6613ec] | 4544 | pair<UniqueLines::iterator, bool> tester;
|
---|
[7c14ec] | 4545 | for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
|
---|
[6613ec] | 4546 | tester = AllLines.insert(LineRunner1->second);
|
---|
[856098] | 4547 | if (!tester.second) { // found degenerated line
|
---|
[6613ec] | 4548 | DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));
|
---|
| 4549 | DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));
|
---|
[57066a] | 4550 | }
|
---|
| 4551 | }
|
---|
| 4552 |
|
---|
| 4553 | AllLines.clear();
|
---|
| 4554 |
|
---|
[a67d19] | 4555 | DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl);
|
---|
[c15ca2] | 4556 | IndexToIndex::iterator it;
|
---|
[856098] | 4557 | for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
|
---|
| 4558 | const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
|
---|
| 4559 | const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
|
---|
| 4560 | if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
|
---|
[a67d19] | 4561 | DoLog(0) && (Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl);
|
---|
[856098] | 4562 | else
|
---|
[6613ec] | 4563 | DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);
|
---|
[856098] | 4564 | }
|
---|
[57066a] | 4565 |
|
---|
| 4566 | return DegeneratedLines;
|
---|
| 4567 | }
|
---|
| 4568 |
|
---|
| 4569 | /**
|
---|
| 4570 | * Finds all degenerated triangles within the tesselation structure.
|
---|
| 4571 | *
|
---|
| 4572 | * @return map of keys of degenerated triangle pairs, each triangle occurs twice
|
---|
| 4573 | * in the list, once as key and once as value
|
---|
| 4574 | */
|
---|
[c15ca2] | 4575 | IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
|
---|
[57066a] | 4576 | {
|
---|
[6613ec] | 4577 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4578 | IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
|
---|
| 4579 | IndexToIndex * DegeneratedTriangles = new IndexToIndex;
|
---|
[57066a] | 4580 | TriangleMap::iterator TriangleRunner1, TriangleRunner2;
|
---|
| 4581 | LineMap::iterator Liner;
|
---|
| 4582 | class BoundaryLineSet *line1 = NULL, *line2 = NULL;
|
---|
| 4583 |
|
---|
[c15ca2] | 4584 | for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
|
---|
[57066a] | 4585 | // run over both lines' triangles
|
---|
| 4586 | Liner = LinesOnBoundary.find(LineRunner->first);
|
---|
| 4587 | if (Liner != LinesOnBoundary.end())
|
---|
| 4588 | line1 = Liner->second;
|
---|
| 4589 | Liner = LinesOnBoundary.find(LineRunner->second);
|
---|
| 4590 | if (Liner != LinesOnBoundary.end())
|
---|
| 4591 | line2 = Liner->second;
|
---|
| 4592 | for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
|
---|
| 4593 | for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
|
---|
[6613ec] | 4594 | if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
|
---|
| 4595 | DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr));
|
---|
| 4596 | DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr));
|
---|
[7c14ec] | 4597 | }
|
---|
| 4598 | }
|
---|
| 4599 | }
|
---|
| 4600 | }
|
---|
[6613ec] | 4601 | delete (DegeneratedLines);
|
---|
[7c14ec] | 4602 |
|
---|
[a67d19] | 4603 | DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl);
|
---|
[c15ca2] | 4604 | IndexToIndex::iterator it;
|
---|
[57066a] | 4605 | for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
|
---|
[a67d19] | 4606 | DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
|
---|
[7c14ec] | 4607 |
|
---|
| 4608 | return DegeneratedTriangles;
|
---|
| 4609 | }
|
---|
| 4610 |
|
---|
| 4611 | /**
|
---|
| 4612 | * Purges degenerated triangles from the tesselation structure if they are not
|
---|
| 4613 | * necessary to keep a single point within the structure.
|
---|
| 4614 | */
|
---|
| 4615 | void Tesselation::RemoveDegeneratedTriangles()
|
---|
| 4616 | {
|
---|
[6613ec] | 4617 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4618 | IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[57066a] | 4619 | TriangleMap::iterator finder;
|
---|
| 4620 | BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
|
---|
[6613ec] | 4621 | int count = 0;
|
---|
[7c14ec] | 4622 |
|
---|
[6613ec] | 4623 | for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) {
|
---|
[57066a] | 4624 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
|
---|
| 4625 | if (finder != TrianglesOnBoundary.end())
|
---|
| 4626 | triangle = finder->second;
|
---|
| 4627 | else
|
---|
| 4628 | break;
|
---|
| 4629 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->second);
|
---|
| 4630 | if (finder != TrianglesOnBoundary.end())
|
---|
| 4631 | partnerTriangle = finder->second;
|
---|
| 4632 | else
|
---|
| 4633 | break;
|
---|
[7c14ec] | 4634 |
|
---|
| 4635 | bool trianglesShareLine = false;
|
---|
| 4636 | for (int i = 0; i < 3; ++i)
|
---|
| 4637 | for (int j = 0; j < 3; ++j)
|
---|
| 4638 | trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
|
---|
| 4639 |
|
---|
[6613ec] | 4640 | if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) {
|
---|
[57066a] | 4641 | // check whether we have to fix lines
|
---|
| 4642 | BoundaryTriangleSet *Othertriangle = NULL;
|
---|
| 4643 | BoundaryTriangleSet *OtherpartnerTriangle = NULL;
|
---|
| 4644 | TriangleMap::iterator TriangleRunner;
|
---|
| 4645 | for (int i = 0; i < 3; ++i)
|
---|
| 4646 | for (int j = 0; j < 3; ++j)
|
---|
| 4647 | if (triangle->lines[i] != partnerTriangle->lines[j]) {
|
---|
| 4648 | // get the other two triangles
|
---|
| 4649 | for (TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 4650 | if (TriangleRunner->second != triangle) {
|
---|
| 4651 | Othertriangle = TriangleRunner->second;
|
---|
| 4652 | }
|
---|
| 4653 | for (TriangleRunner = partnerTriangle->lines[i]->triangles.begin(); TriangleRunner != partnerTriangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 4654 | if (TriangleRunner->second != partnerTriangle) {
|
---|
| 4655 | OtherpartnerTriangle = TriangleRunner->second;
|
---|
| 4656 | }
|
---|
| 4657 | /// interchanges their lines so that triangle->lines[i] == partnerTriangle->lines[j]
|
---|
| 4658 | // the line of triangle receives the degenerated ones
|
---|
| 4659 | triangle->lines[i]->triangles.erase(Othertriangle->Nr);
|
---|
[6613ec] | 4660 | triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle));
|
---|
| 4661 | for (int k = 0; k < 3; k++)
|
---|
[57066a] | 4662 | if (triangle->lines[i] == Othertriangle->lines[k]) {
|
---|
| 4663 | Othertriangle->lines[k] = partnerTriangle->lines[j];
|
---|
| 4664 | break;
|
---|
| 4665 | }
|
---|
| 4666 | // the line of partnerTriangle receives the non-degenerated ones
|
---|
[6613ec] | 4667 | partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr);
|
---|
| 4668 | partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle));
|
---|
[57066a] | 4669 | partnerTriangle->lines[j] = triangle->lines[i];
|
---|
| 4670 | }
|
---|
| 4671 |
|
---|
| 4672 | // erase the pair
|
---|
| 4673 | count += (int) DegeneratedTriangles->erase(triangle->Nr);
|
---|
[a67d19] | 4674 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl);
|
---|
[7c14ec] | 4675 | RemoveTesselationTriangle(triangle);
|
---|
[57066a] | 4676 | count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
|
---|
[a67d19] | 4677 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl);
|
---|
[7c14ec] | 4678 | RemoveTesselationTriangle(partnerTriangle);
|
---|
| 4679 | } else {
|
---|
[a67d19] | 4680 | 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] | 4681 | }
|
---|
| 4682 | }
|
---|
[6613ec] | 4683 | delete (DegeneratedTriangles);
|
---|
[6a7f78c] | 4684 | if (count > 0)
|
---|
| 4685 | LastTriangle = NULL;
|
---|
[57066a] | 4686 |
|
---|
[a67d19] | 4687 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl);
|
---|
[7c14ec] | 4688 | }
|
---|
| 4689 |
|
---|
[57066a] | 4690 | /** Adds an outside Tesselpoint to the envelope via (two) degenerated triangles.
|
---|
| 4691 | * We look for the closest point on the boundary, we look through its connected boundary lines and
|
---|
| 4692 | * seek the one with the minimum angle between its center point and the new point and this base line.
|
---|
| 4693 | * We open up the line by adding a degenerated triangle, whose other side closes the base line again.
|
---|
| 4694 | * \param *out output stream for debugging
|
---|
| 4695 | * \param *point point to add
|
---|
| 4696 | * \param *LC Linked Cell structure to find nearest point
|
---|
[ab1932] | 4697 | */
|
---|
[e138de] | 4698 | void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
|
---|
[ab1932] | 4699 | {
|
---|
[6613ec] | 4700 | Info FunctionInfo(__func__);
|
---|
[57066a] | 4701 | // find nearest boundary point
|
---|
| 4702 | class TesselPoint *BackupPoint = NULL;
|
---|
[71b20e] | 4703 | class TesselPoint *NearestPoint = FindClosestTesselPoint(point->node, BackupPoint, LC);
|
---|
[57066a] | 4704 | class BoundaryPointSet *NearestBoundaryPoint = NULL;
|
---|
| 4705 | PointMap::iterator PointRunner;
|
---|
| 4706 |
|
---|
| 4707 | if (NearestPoint == point)
|
---|
| 4708 | NearestPoint = BackupPoint;
|
---|
| 4709 | PointRunner = PointsOnBoundary.find(NearestPoint->nr);
|
---|
| 4710 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 4711 | NearestBoundaryPoint = PointRunner->second;
|
---|
| 4712 | } else {
|
---|
[6613ec] | 4713 | DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl);
|
---|
[57066a] | 4714 | return;
|
---|
| 4715 | }
|
---|
[a67d19] | 4716 | DoLog(0) && (Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl);
|
---|
[57066a] | 4717 |
|
---|
| 4718 | // go through its lines and find the best one to split
|
---|
| 4719 | Vector CenterToPoint;
|
---|
| 4720 | Vector BaseLine;
|
---|
| 4721 | double angle, BestAngle = 0.;
|
---|
| 4722 | class BoundaryLineSet *BestLine = NULL;
|
---|
| 4723 | for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
|
---|
[273382] | 4724 | BaseLine = (*Runner->second->endpoints[0]->node->node) -
|
---|
| 4725 | (*Runner->second->endpoints[1]->node->node);
|
---|
| 4726 | CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) +
|
---|
| 4727 | (*Runner->second->endpoints[1]->node->node));
|
---|
| 4728 | CenterToPoint -= (*point->node);
|
---|
| 4729 | angle = CenterToPoint.Angle(BaseLine);
|
---|
[57066a] | 4730 | if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
|
---|
| 4731 | BestAngle = angle;
|
---|
| 4732 | BestLine = Runner->second;
|
---|
| 4733 | }
|
---|
[ab1932] | 4734 | }
|
---|
| 4735 |
|
---|
[57066a] | 4736 | // remove one triangle from the chosen line
|
---|
| 4737 | class BoundaryTriangleSet *TempTriangle = (BestLine->triangles.begin())->second;
|
---|
| 4738 | BestLine->triangles.erase(TempTriangle->Nr);
|
---|
| 4739 | int nr = -1;
|
---|
[6613ec] | 4740 | for (int i = 0; i < 3; i++) {
|
---|
[57066a] | 4741 | if (TempTriangle->lines[i] == BestLine) {
|
---|
| 4742 | nr = i;
|
---|
| 4743 | break;
|
---|
| 4744 | }
|
---|
| 4745 | }
|
---|
[ab1932] | 4746 |
|
---|
[57066a] | 4747 | // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
|
---|
[a67d19] | 4748 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4749 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 4750 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 4751 | AddTesselationPoint(point, 2);
|
---|
[a67d19] | 4752 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4753 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4754 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 4755 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[57066a] | 4756 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 4757 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
| 4758 | BTS->NormalVector.Scale(-1.);
|
---|
[a67d19] | 4759 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl);
|
---|
[57066a] | 4760 | AddTesselationTriangle();
|
---|
| 4761 |
|
---|
| 4762 | // create other side of this triangle and close both new sides of the first created triangle
|
---|
[a67d19] | 4763 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4764 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 4765 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 4766 | AddTesselationPoint(point, 2);
|
---|
[a67d19] | 4767 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4768 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4769 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 4770 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[57066a] | 4771 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 4772 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
[a67d19] | 4773 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl);
|
---|
[57066a] | 4774 | AddTesselationTriangle();
|
---|
| 4775 |
|
---|
| 4776 | // add removed triangle to the last open line of the second triangle
|
---|
[6613ec] | 4777 | for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion)
|
---|
[57066a] | 4778 | if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
|
---|
[6613ec] | 4779 | if (BestLine == BTS->lines[i]) {
|
---|
| 4780 | DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl);
|
---|
[f67b6e] | 4781 | performCriticalExit();
|
---|
[57066a] | 4782 | }
|
---|
[6613ec] | 4783 | BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));
|
---|
[57066a] | 4784 | TempTriangle->lines[nr] = BTS->lines[i];
|
---|
| 4785 | break;
|
---|
| 4786 | }
|
---|
| 4787 | }
|
---|
[6613ec] | 4788 | }
|
---|
| 4789 | ;
|
---|
[57066a] | 4790 |
|
---|
| 4791 | /** Writes the envelope to file.
|
---|
| 4792 | * \param *out otuput stream for debugging
|
---|
| 4793 | * \param *filename basename of output file
|
---|
| 4794 | * \param *cloud PointCloud structure with all nodes
|
---|
| 4795 | */
|
---|
[e138de] | 4796 | void Tesselation::Output(const char *filename, const PointCloud * const cloud)
|
---|
[57066a] | 4797 | {
|
---|
[6613ec] | 4798 | Info FunctionInfo(__func__);
|
---|
[57066a] | 4799 | ofstream *tempstream = NULL;
|
---|
| 4800 | string NameofTempFile;
|
---|
| 4801 | char NumberName[255];
|
---|
| 4802 |
|
---|
| 4803 | if (LastTriangle != NULL) {
|
---|
[6613ec] | 4804 | sprintf(NumberName, "-%04d-%s_%s_%s", (int) TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);
|
---|
[57066a] | 4805 | if (DoTecplotOutput) {
|
---|
| 4806 | string NameofTempFile(filename);
|
---|
| 4807 | NameofTempFile.append(NumberName);
|
---|
[6613ec] | 4808 | for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 4809 | NameofTempFile.erase(npos, 1);
|
---|
[57066a] | 4810 | NameofTempFile.append(TecplotSuffix);
|
---|
[a67d19] | 4811 | DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
|
---|
[57066a] | 4812 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 4813 | WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
|
---|
[57066a] | 4814 | tempstream->close();
|
---|
| 4815 | tempstream->flush();
|
---|
[6613ec] | 4816 | delete (tempstream);
|
---|
[57066a] | 4817 | }
|
---|
| 4818 |
|
---|
| 4819 | if (DoRaster3DOutput) {
|
---|
| 4820 | string NameofTempFile(filename);
|
---|
| 4821 | NameofTempFile.append(NumberName);
|
---|
[6613ec] | 4822 | for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 4823 | NameofTempFile.erase(npos, 1);
|
---|
[57066a] | 4824 | NameofTempFile.append(Raster3DSuffix);
|
---|
[a67d19] | 4825 | DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
|
---|
[57066a] | 4826 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 4827 | WriteRaster3dFile(tempstream, this, cloud);
|
---|
| 4828 | IncludeSphereinRaster3D(tempstream, this, cloud);
|
---|
[57066a] | 4829 | tempstream->close();
|
---|
| 4830 | tempstream->flush();
|
---|
[6613ec] | 4831 | delete (tempstream);
|
---|
[57066a] | 4832 | }
|
---|
| 4833 | }
|
---|
| 4834 | if (DoTecplotOutput || DoRaster3DOutput)
|
---|
| 4835 | TriangleFilesWritten++;
|
---|
[6613ec] | 4836 | }
|
---|
| 4837 | ;
|
---|
[262bae] | 4838 |
|
---|
[6613ec] | 4839 | struct BoundaryPolygonSetCompare
|
---|
| 4840 | {
|
---|
| 4841 | bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const
|
---|
| 4842 | {
|
---|
[856098] | 4843 | if (s1->endpoints.size() < s2->endpoints.size())
|
---|
| 4844 | return true;
|
---|
| 4845 | else if (s1->endpoints.size() > s2->endpoints.size())
|
---|
| 4846 | return false;
|
---|
| 4847 | else { // equality of number of endpoints
|
---|
| 4848 | PointSet::const_iterator Walker1 = s1->endpoints.begin();
|
---|
| 4849 | PointSet::const_iterator Walker2 = s2->endpoints.begin();
|
---|
| 4850 | while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
|
---|
| 4851 | if ((*Walker1)->Nr < (*Walker2)->Nr)
|
---|
| 4852 | return true;
|
---|
| 4853 | else if ((*Walker1)->Nr > (*Walker2)->Nr)
|
---|
| 4854 | return false;
|
---|
| 4855 | Walker1++;
|
---|
| 4856 | Walker2++;
|
---|
| 4857 | }
|
---|
| 4858 | return false;
|
---|
| 4859 | }
|
---|
| 4860 | }
|
---|
| 4861 | };
|
---|
| 4862 |
|
---|
| 4863 | #define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
|
---|
| 4864 |
|
---|
[262bae] | 4865 | /** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
|
---|
| 4866 | * \return number of polygons found
|
---|
| 4867 | */
|
---|
| 4868 | int Tesselation::CorrectAllDegeneratedPolygons()
|
---|
| 4869 | {
|
---|
| 4870 | Info FunctionInfo(__func__);
|
---|
[fad93c] | 4871 | /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
|
---|
[c15ca2] | 4872 | IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[6613ec] | 4873 | set<BoundaryPointSet *> EndpointCandidateList;
|
---|
| 4874 | pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester;
|
---|
| 4875 | pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester;
|
---|
[fad93c] | 4876 | for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
|
---|
[a67d19] | 4877 | DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl);
|
---|
[6613ec] | 4878 | map<int, Vector *> TriangleVectors;
|
---|
[fad93c] | 4879 | // gather all NormalVectors
|
---|
[a67d19] | 4880 | DoLog(1) && (Log() << Verbose(1) << "Gathering triangles ..." << endl);
|
---|
[fad93c] | 4881 | for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
|
---|
| 4882 | for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
[b998c3] | 4883 | if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
|
---|
[6613ec] | 4884 | TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));
|
---|
[b998c3] | 4885 | if (TriangleInsertionTester.second)
|
---|
[a67d19] | 4886 | DoLog(1) && (Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl);
|
---|
[b998c3] | 4887 | } else {
|
---|
[a67d19] | 4888 | DoLog(1) && (Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl);
|
---|
[b998c3] | 4889 | }
|
---|
[fad93c] | 4890 | }
|
---|
| 4891 | // check whether there are two that are parallel
|
---|
[a67d19] | 4892 | DoLog(1) && (Log() << Verbose(1) << "Finding two parallel triangles ..." << endl);
|
---|
[6613ec] | 4893 | for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
|
---|
| 4894 | for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
|
---|
[fad93c] | 4895 | if (VectorWalker != VectorRunner) { // skip equals
|
---|
[8cbb97] | 4896 | const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
|
---|
[a67d19] | 4897 | DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl);
|
---|
[fad93c] | 4898 | if (fabs(SCP + 1.) < ParallelEpsilon) {
|
---|
| 4899 | InsertionTester = EndpointCandidateList.insert((Runner->second));
|
---|
| 4900 | if (InsertionTester.second)
|
---|
[a67d19] | 4901 | DoLog(0) && (Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl);
|
---|
[fad93c] | 4902 | // and break out of both loops
|
---|
| 4903 | VectorWalker = TriangleVectors.end();
|
---|
| 4904 | VectorRunner = TriangleVectors.end();
|
---|
| 4905 | break;
|
---|
| 4906 | }
|
---|
| 4907 | }
|
---|
| 4908 | }
|
---|
[9d4c20] | 4909 | delete DegeneratedTriangles;
|
---|
[856098] | 4910 |
|
---|
[fad93c] | 4911 | /// 3. Find connected endpoint candidates and put them into a polygon
|
---|
| 4912 | UniquePolygonSet ListofDegeneratedPolygons;
|
---|
| 4913 | BoundaryPointSet *Walker = NULL;
|
---|
| 4914 | BoundaryPointSet *OtherWalker = NULL;
|
---|
| 4915 | BoundaryPolygonSet *Current = NULL;
|
---|
[6613ec] | 4916 | stack<BoundaryPointSet*> ToCheckConnecteds;
|
---|
[fad93c] | 4917 | while (!EndpointCandidateList.empty()) {
|
---|
| 4918 | Walker = *(EndpointCandidateList.begin());
|
---|
[6613ec] | 4919 | if (Current == NULL) { // create a new polygon with current candidate
|
---|
[a67d19] | 4920 | DoLog(0) && (Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl);
|
---|
[fad93c] | 4921 | Current = new BoundaryPolygonSet;
|
---|
| 4922 | Current->endpoints.insert(Walker);
|
---|
| 4923 | EndpointCandidateList.erase(Walker);
|
---|
| 4924 | ToCheckConnecteds.push(Walker);
|
---|
[856098] | 4925 | }
|
---|
[262bae] | 4926 |
|
---|
[fad93c] | 4927 | // go through to-check stack
|
---|
| 4928 | while (!ToCheckConnecteds.empty()) {
|
---|
| 4929 | Walker = ToCheckConnecteds.top(); // fetch ...
|
---|
| 4930 | ToCheckConnecteds.pop(); // ... and remove
|
---|
| 4931 | for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
|
---|
| 4932 | OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
|
---|
[a67d19] | 4933 | DoLog(1) && (Log() << Verbose(1) << "Checking " << *OtherWalker << endl);
|
---|
[6613ec] | 4934 | set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
|
---|
| 4935 | if (Finder != EndpointCandidateList.end()) { // found a connected partner
|
---|
[a67d19] | 4936 | DoLog(1) && (Log() << Verbose(1) << " Adding to polygon." << endl);
|
---|
[fad93c] | 4937 | Current->endpoints.insert(OtherWalker);
|
---|
[6613ec] | 4938 | EndpointCandidateList.erase(Finder); // remove from candidates
|
---|
| 4939 | ToCheckConnecteds.push(OtherWalker); // but check its partners too
|
---|
[856098] | 4940 | } else {
|
---|
[a67d19] | 4941 | DoLog(1) && (Log() << Verbose(1) << " is not connected to " << *Walker << endl);
|
---|
[856098] | 4942 | }
|
---|
| 4943 | }
|
---|
| 4944 | }
|
---|
[262bae] | 4945 |
|
---|
[a67d19] | 4946 | DoLog(0) && (Log() << Verbose(0) << "Final polygon is " << *Current << endl);
|
---|
[fad93c] | 4947 | ListofDegeneratedPolygons.insert(Current);
|
---|
| 4948 | Current = NULL;
|
---|
[262bae] | 4949 | }
|
---|
| 4950 |
|
---|
[fad93c] | 4951 | const int counter = ListofDegeneratedPolygons.size();
|
---|
[262bae] | 4952 |
|
---|
[a67d19] | 4953 | DoLog(0) && (Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl);
|
---|
[fad93c] | 4954 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
|
---|
[a67d19] | 4955 | DoLog(0) && (Log() << Verbose(0) << " " << **PolygonRunner << endl);
|
---|
[856098] | 4956 |
|
---|
[262bae] | 4957 | /// 4. Go through all these degenerated polygons
|
---|
[fad93c] | 4958 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
|
---|
[6613ec] | 4959 | stack<int> TriangleNrs;
|
---|
[856098] | 4960 | Vector NormalVector;
|
---|
[262bae] | 4961 | /// 4a. Gather all triangles of this polygon
|
---|
[856098] | 4962 | TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
|
---|
[262bae] | 4963 |
|
---|
[125b3c] | 4964 | // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do.
|
---|
[b998c3] | 4965 | if (T->size() == 2) {
|
---|
[a67d19] | 4966 | DoLog(1) && (Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl);
|
---|
[6613ec] | 4967 | delete (T);
|
---|
[b998c3] | 4968 | continue;
|
---|
| 4969 | }
|
---|
| 4970 |
|
---|
[125b3c] | 4971 | // check whether number is even
|
---|
| 4972 | // If this case occurs, we have to think about it!
|
---|
| 4973 | // The Problem is probably due to two degenerated polygons being connected by a bridging, non-degenerated polygon, as somehow one node has
|
---|
| 4974 | // connections to either polygon ...
|
---|
| 4975 | if (T->size() % 2 != 0) {
|
---|
[6613ec] | 4976 | DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);
|
---|
[125b3c] | 4977 | performCriticalExit();
|
---|
| 4978 | }
|
---|
[6613ec] | 4979 | TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
|
---|
[262bae] | 4980 | /// 4a. Get NormalVector for one side (this is "front")
|
---|
[273382] | 4981 | NormalVector = (*TriangleWalker)->NormalVector;
|
---|
[a67d19] | 4982 | DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl);
|
---|
[856098] | 4983 | TriangleWalker++;
|
---|
| 4984 | TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
|
---|
[262bae] | 4985 | /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back")
|
---|
[856098] | 4986 | BoundaryTriangleSet *triangle = NULL;
|
---|
| 4987 | while (TriangleSprinter != T->end()) {
|
---|
| 4988 | TriangleWalker = TriangleSprinter;
|
---|
| 4989 | triangle = *TriangleWalker;
|
---|
| 4990 | TriangleSprinter++;
|
---|
[a67d19] | 4991 | DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl);
|
---|
[273382] | 4992 | if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list
|
---|
[a67d19] | 4993 | DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl);
|
---|
[856098] | 4994 | TriangleNrs.push(triangle->Nr);
|
---|
[262bae] | 4995 | T->erase(TriangleWalker);
|
---|
[856098] | 4996 | RemoveTesselationTriangle(triangle);
|
---|
| 4997 | } else
|
---|
[a67d19] | 4998 | DoLog(1) && (Log() << Verbose(1) << " Keeping ... " << endl);
|
---|
[262bae] | 4999 | }
|
---|
| 5000 | /// 4c. Copy all "front" triangles but with inverse NormalVector
|
---|
| 5001 | TriangleWalker = T->begin();
|
---|
[6613ec] | 5002 | while (TriangleWalker != T->end()) { // go through all front triangles
|
---|
[a67d19] | 5003 | DoLog(1) && (Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl);
|
---|
[856098] | 5004 | for (int i = 0; i < 3; i++)
|
---|
| 5005 | AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
|
---|
[f07f86d] | 5006 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 5007 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 5008 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[fad93c] | 5009 | if (TriangleNrs.empty())
|
---|
[6613ec] | 5010 | DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl);
|
---|
[856098] | 5011 | BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
|
---|
| 5012 | AddTesselationTriangle(); // ... and add
|
---|
| 5013 | TriangleNrs.pop();
|
---|
[273382] | 5014 | BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector;
|
---|
[262bae] | 5015 | TriangleWalker++;
|
---|
| 5016 | }
|
---|
[856098] | 5017 | if (!TriangleNrs.empty()) {
|
---|
[6613ec] | 5018 | DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl);
|
---|
[856098] | 5019 | }
|
---|
[6613ec] | 5020 | delete (T); // remove the triangleset
|
---|
[262bae] | 5021 | }
|
---|
[c15ca2] | 5022 | IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[a67d19] | 5023 | DoLog(0) && (Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl);
|
---|
[c15ca2] | 5024 | IndexToIndex::iterator it;
|
---|
[856098] | 5025 | for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
|
---|
[a67d19] | 5026 | DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
|
---|
[6613ec] | 5027 | delete (SimplyDegeneratedTriangles);
|
---|
[262bae] | 5028 | /// 5. exit
|
---|
[856098] | 5029 | UniquePolygonSet::iterator PolygonRunner;
|
---|
[fad93c] | 5030 | while (!ListofDegeneratedPolygons.empty()) {
|
---|
| 5031 | PolygonRunner = ListofDegeneratedPolygons.begin();
|
---|
[6613ec] | 5032 | delete (*PolygonRunner);
|
---|
[fad93c] | 5033 | ListofDegeneratedPolygons.erase(PolygonRunner);
|
---|
[262bae] | 5034 | }
|
---|
| 5035 |
|
---|
| 5036 | return counter;
|
---|
[6613ec] | 5037 | }
|
---|
| 5038 | ;
|
---|