[357fba] | 1 | /*
|
---|
| 2 | * tesselation.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 3, 2009
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[f66195] | 8 | #include <fstream>
|
---|
| 9 |
|
---|
[a2028e] | 10 | #include "helpers.hpp"
|
---|
[f67b6e] | 11 | #include "info.hpp"
|
---|
[57066a] | 12 | #include "linkedcell.hpp"
|
---|
[e138de] | 13 | #include "log.hpp"
|
---|
[357fba] | 14 | #include "tesselation.hpp"
|
---|
[57066a] | 15 | #include "tesselationhelpers.hpp"
|
---|
[8db598] | 16 | #include "triangleintersectionlist.hpp"
|
---|
[57066a] | 17 | #include "vector.hpp"
|
---|
[f66195] | 18 | #include "verbose.hpp"
|
---|
[57066a] | 19 |
|
---|
| 20 | class molecule;
|
---|
[357fba] | 21 |
|
---|
| 22 | // ======================================== Points on Boundary =================================
|
---|
| 23 |
|
---|
[16d866] | 24 | /** Constructor of BoundaryPointSet.
|
---|
| 25 | */
|
---|
[1e168b] | 26 | BoundaryPointSet::BoundaryPointSet() :
|
---|
| 27 | LinesCount(0),
|
---|
| 28 | value(0.),
|
---|
| 29 | Nr(-1)
|
---|
[357fba] | 30 | {
|
---|
[f67b6e] | 31 | Info FunctionInfo(__func__);
|
---|
| 32 | Log() << Verbose(1) << "Adding noname." << endl;
|
---|
[16d866] | 33 | };
|
---|
[357fba] | 34 |
|
---|
[16d866] | 35 | /** Constructor of BoundaryPointSet with Tesselpoint.
|
---|
| 36 | * \param *Walker TesselPoint this boundary point represents
|
---|
| 37 | */
|
---|
[9473f6] | 38 | BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) :
|
---|
[f67b6e] | 39 | LinesCount(0),
|
---|
| 40 | node(Walker),
|
---|
| 41 | value(0.),
|
---|
| 42 | Nr(Walker->nr)
|
---|
[357fba] | 43 | {
|
---|
[f67b6e] | 44 | Info FunctionInfo(__func__);
|
---|
[27bd2f] | 45 | Log() << Verbose(1) << "Adding Node " << *Walker << endl;
|
---|
[16d866] | 46 | };
|
---|
[357fba] | 47 |
|
---|
[16d866] | 48 | /** Destructor of BoundaryPointSet.
|
---|
| 49 | * Sets node to NULL to avoid removing the original, represented TesselPoint.
|
---|
| 50 | * \note When removing point from a class Tesselation, use RemoveTesselationPoint()
|
---|
| 51 | */
|
---|
[357fba] | 52 | BoundaryPointSet::~BoundaryPointSet()
|
---|
| 53 | {
|
---|
[f67b6e] | 54 | Info FunctionInfo(__func__);
|
---|
| 55 | //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
|
---|
[357fba] | 56 | if (!lines.empty())
|
---|
[717e0c] | 57 | eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl;
|
---|
[357fba] | 58 | node = NULL;
|
---|
[16d866] | 59 | };
|
---|
[357fba] | 60 |
|
---|
[16d866] | 61 | /** Add a line to the LineMap of this point.
|
---|
| 62 | * \param *line line to add
|
---|
| 63 | */
|
---|
[9473f6] | 64 | void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
|
---|
[357fba] | 65 | {
|
---|
[f67b6e] | 66 | Info FunctionInfo(__func__);
|
---|
| 67 | Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "."
|
---|
[357fba] | 68 | << endl;
|
---|
| 69 | if (line->endpoints[0] == this)
|
---|
| 70 | {
|
---|
| 71 | lines.insert(LinePair(line->endpoints[1]->Nr, line));
|
---|
| 72 | }
|
---|
| 73 | else
|
---|
| 74 | {
|
---|
| 75 | lines.insert(LinePair(line->endpoints[0]->Nr, line));
|
---|
| 76 | }
|
---|
| 77 | LinesCount++;
|
---|
[16d866] | 78 | };
|
---|
[357fba] | 79 |
|
---|
[16d866] | 80 | /** output operator for BoundaryPointSet.
|
---|
| 81 | * \param &ost output stream
|
---|
| 82 | * \param &a boundary point
|
---|
| 83 | */
|
---|
[776b64] | 84 | ostream & operator <<(ostream &ost, const BoundaryPointSet &a)
|
---|
[357fba] | 85 | {
|
---|
[57066a] | 86 | ost << "[" << a.Nr << "|" << a.node->Name << " at " << *a.node->node << "]";
|
---|
[357fba] | 87 | return ost;
|
---|
| 88 | }
|
---|
| 89 | ;
|
---|
| 90 |
|
---|
| 91 | // ======================================== Lines on Boundary =================================
|
---|
| 92 |
|
---|
[16d866] | 93 | /** Constructor of BoundaryLineSet.
|
---|
| 94 | */
|
---|
[1e168b] | 95 | BoundaryLineSet::BoundaryLineSet() :
|
---|
| 96 | Nr(-1)
|
---|
[357fba] | 97 | {
|
---|
[f67b6e] | 98 | Info FunctionInfo(__func__);
|
---|
[357fba] | 99 | for (int i = 0; i < 2; i++)
|
---|
| 100 | endpoints[i] = NULL;
|
---|
[16d866] | 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 | {
|
---|
[f67b6e] | 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
|
---|
[f67b6e] | 121 | Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
|
---|
[16d866] | 122 | };
|
---|
[357fba] | 123 |
|
---|
[9473f6] | 124 | /** Constructor of BoundaryLineSet with two endpoints.
|
---|
| 125 | * Adds line automatically to each endpoints' LineMap
|
---|
| 126 | * \param *Point1 first boundary point
|
---|
| 127 | * \param *Point2 second boundary point
|
---|
| 128 | * \param number number of the list
|
---|
| 129 | */
|
---|
| 130 | BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number)
|
---|
| 131 | {
|
---|
| 132 | Info FunctionInfo(__func__);
|
---|
| 133 | // set number
|
---|
| 134 | Nr = number;
|
---|
| 135 | // set endpoints in ascending order
|
---|
| 136 | SetEndpointsOrdered(endpoints, Point1, Point2);
|
---|
| 137 | // add this line to the hash maps of both endpoints
|
---|
| 138 | Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
|
---|
| 139 | Point2->AddLine(this); //
|
---|
| 140 | // set skipped to false
|
---|
| 141 | skipped = false;
|
---|
| 142 | // clear triangles list
|
---|
| 143 | Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl;
|
---|
| 144 | };
|
---|
| 145 |
|
---|
[16d866] | 146 | /** Destructor for BoundaryLineSet.
|
---|
| 147 | * Removes itself from each endpoints' LineMap, calling RemoveTrianglePoint() when point not connected anymore.
|
---|
| 148 | * \note When removing lines from a class Tesselation, use RemoveTesselationLine()
|
---|
| 149 | */
|
---|
[357fba] | 150 | BoundaryLineSet::~BoundaryLineSet()
|
---|
| 151 | {
|
---|
[f67b6e] | 152 | Info FunctionInfo(__func__);
|
---|
[357fba] | 153 | int Numbers[2];
|
---|
[16d866] | 154 |
|
---|
| 155 | // get other endpoint number of finding copies of same line
|
---|
| 156 | if (endpoints[1] != NULL)
|
---|
| 157 | Numbers[0] = endpoints[1]->Nr;
|
---|
| 158 | else
|
---|
| 159 | Numbers[0] = -1;
|
---|
| 160 | if (endpoints[0] != NULL)
|
---|
| 161 | Numbers[1] = endpoints[0]->Nr;
|
---|
| 162 | else
|
---|
| 163 | Numbers[1] = -1;
|
---|
| 164 |
|
---|
[357fba] | 165 | for (int i = 0; i < 2; i++) {
|
---|
[16d866] | 166 | if (endpoints[i] != NULL) {
|
---|
| 167 | 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
|
---|
| 168 | pair<LineMap::iterator, LineMap::iterator> erasor = endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 169 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 170 | if ((*Runner).second == this) {
|
---|
[f67b6e] | 171 | //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[16d866] | 172 | endpoints[i]->lines.erase(Runner);
|
---|
| 173 | break;
|
---|
| 174 | }
|
---|
| 175 | } else { // there's just a single line left
|
---|
[57066a] | 176 | if (endpoints[i]->lines.erase(Nr)) {
|
---|
[f67b6e] | 177 | //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[57066a] | 178 | }
|
---|
[357fba] | 179 | }
|
---|
[16d866] | 180 | if (endpoints[i]->lines.empty()) {
|
---|
[f67b6e] | 181 | //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
|
---|
[16d866] | 182 | if (endpoints[i] != NULL) {
|
---|
| 183 | delete(endpoints[i]);
|
---|
| 184 | endpoints[i] = NULL;
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
[357fba] | 188 | }
|
---|
| 189 | if (!triangles.empty())
|
---|
[717e0c] | 190 | eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl;
|
---|
[16d866] | 191 | };
|
---|
[357fba] | 192 |
|
---|
[16d866] | 193 | /** Add triangle to TriangleMap of this boundary line.
|
---|
| 194 | * \param *triangle to add
|
---|
| 195 | */
|
---|
[9473f6] | 196 | void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
|
---|
[357fba] | 197 | {
|
---|
[f67b6e] | 198 | Info FunctionInfo(__func__);
|
---|
| 199 | Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
|
---|
[357fba] | 200 | triangles.insert(TrianglePair(triangle->Nr, triangle));
|
---|
[16d866] | 201 | };
|
---|
[357fba] | 202 |
|
---|
| 203 | /** Checks whether we have a common endpoint with given \a *line.
|
---|
| 204 | * \param *line other line to test
|
---|
| 205 | * \return true - common endpoint present, false - not connected
|
---|
| 206 | */
|
---|
[9473f6] | 207 | bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
|
---|
[357fba] | 208 | {
|
---|
[f67b6e] | 209 | Info FunctionInfo(__func__);
|
---|
[357fba] | 210 | if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
|
---|
| 211 | return true;
|
---|
| 212 | else
|
---|
| 213 | return false;
|
---|
| 214 | };
|
---|
| 215 |
|
---|
| 216 | /** Checks whether the adjacent triangles of a baseline are convex or not.
|
---|
[57066a] | 217 | * We sum the two angles of each height vector with respect to the center of the baseline.
|
---|
[357fba] | 218 | * If greater/equal M_PI than we are convex.
|
---|
| 219 | * \param *out output stream for debugging
|
---|
| 220 | * \return true - triangles are convex, false - concave or less than two triangles connected
|
---|
| 221 | */
|
---|
[9473f6] | 222 | bool BoundaryLineSet::CheckConvexityCriterion() const
|
---|
[357fba] | 223 | {
|
---|
[f67b6e] | 224 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 225 | Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
|
---|
[357fba] | 226 | // get the two triangles
|
---|
[5c7bf8] | 227 | if (triangles.size() != 2) {
|
---|
[f67b6e] | 228 | eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
|
---|
[1d9b7aa] | 229 | return true;
|
---|
[357fba] | 230 | }
|
---|
[5c7bf8] | 231 | // check normal vectors
|
---|
[357fba] | 232 | // have a normal vector on the base line pointing outwards
|
---|
[f67b6e] | 233 | //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
|
---|
[62bb91] | 234 | BaseLineCenter.CopyVector(endpoints[0]->node->node);
|
---|
| 235 | BaseLineCenter.AddVector(endpoints[1]->node->node);
|
---|
| 236 | BaseLineCenter.Scale(1./2.);
|
---|
| 237 | BaseLine.CopyVector(endpoints[0]->node->node);
|
---|
| 238 | BaseLine.SubtractVector(endpoints[1]->node->node);
|
---|
[f67b6e] | 239 | //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
|
---|
[357fba] | 240 |
|
---|
[62bb91] | 241 | BaseLineNormal.Zero();
|
---|
[5c7bf8] | 242 | NormalCheck.Zero();
|
---|
| 243 | double sign = -1.;
|
---|
[62bb91] | 244 | int i=0;
|
---|
| 245 | class BoundaryPointSet *node = NULL;
|
---|
[9473f6] | 246 | for(TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
|
---|
[f67b6e] | 247 | //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
|
---|
[5c7bf8] | 248 | NormalCheck.AddVector(&runner->second->NormalVector);
|
---|
| 249 | NormalCheck.Scale(sign);
|
---|
| 250 | sign = -sign;
|
---|
[57066a] | 251 | if (runner->second->NormalVector.NormSquared() > MYEPSILON)
|
---|
| 252 | BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first
|
---|
| 253 | else {
|
---|
[f67b6e] | 254 | eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl;
|
---|
[57066a] | 255 | }
|
---|
[62bb91] | 256 | node = runner->second->GetThirdEndpoint(this);
|
---|
| 257 | if (node != NULL) {
|
---|
[f67b6e] | 258 | //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
|
---|
[62bb91] | 259 | helper[i].CopyVector(node->node->node);
|
---|
| 260 | helper[i].SubtractVector(&BaseLineCenter);
|
---|
| 261 | helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles!
|
---|
[f67b6e] | 262 | //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
|
---|
[62bb91] | 263 | i++;
|
---|
| 264 | } else {
|
---|
[f67b6e] | 265 | eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;
|
---|
[62bb91] | 266 | return true;
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
[f67b6e] | 269 | //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
|
---|
[5c7bf8] | 270 | if (NormalCheck.NormSquared() < MYEPSILON) {
|
---|
[f67b6e] | 271 | Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
|
---|
[5c7bf8] | 272 | return true;
|
---|
[62bb91] | 273 | }
|
---|
[57066a] | 274 | BaseLineNormal.Scale(-1.);
|
---|
[f1cccd] | 275 | double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
|
---|
[1d9b7aa] | 276 | if ((angle - M_PI) > -MYEPSILON) {
|
---|
[f67b6e] | 277 | Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl;
|
---|
[357fba] | 278 | return true;
|
---|
[1d9b7aa] | 279 | } else {
|
---|
[f67b6e] | 280 | Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl;
|
---|
[357fba] | 281 | return false;
|
---|
[1d9b7aa] | 282 | }
|
---|
[357fba] | 283 | }
|
---|
| 284 |
|
---|
| 285 | /** Checks whether point is any of the two endpoints this line contains.
|
---|
| 286 | * \param *point point to test
|
---|
| 287 | * \return true - point is of the line, false - is not
|
---|
| 288 | */
|
---|
[9473f6] | 289 | bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
[357fba] | 290 | {
|
---|
[f67b6e] | 291 | Info FunctionInfo(__func__);
|
---|
[357fba] | 292 | for(int i=0;i<2;i++)
|
---|
| 293 | if (point == endpoints[i])
|
---|
| 294 | return true;
|
---|
| 295 | return false;
|
---|
| 296 | };
|
---|
| 297 |
|
---|
[62bb91] | 298 | /** Returns other endpoint of the line.
|
---|
| 299 | * \param *point other endpoint
|
---|
| 300 | * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise
|
---|
| 301 | */
|
---|
[9473f6] | 302 | class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
|
---|
[62bb91] | 303 | {
|
---|
[f67b6e] | 304 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 305 | if (endpoints[0] == point)
|
---|
| 306 | return endpoints[1];
|
---|
| 307 | else if (endpoints[1] == point)
|
---|
| 308 | return endpoints[0];
|
---|
| 309 | else
|
---|
| 310 | return NULL;
|
---|
| 311 | };
|
---|
| 312 |
|
---|
[16d866] | 313 | /** output operator for BoundaryLineSet.
|
---|
| 314 | * \param &ost output stream
|
---|
| 315 | * \param &a boundary line
|
---|
| 316 | */
|
---|
[776b64] | 317 | ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
|
---|
[357fba] | 318 | {
|
---|
[57066a] | 319 | 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] | 320 | return ost;
|
---|
[16d866] | 321 | };
|
---|
[357fba] | 322 |
|
---|
| 323 | // ======================================== Triangles on Boundary =================================
|
---|
| 324 |
|
---|
[16d866] | 325 | /** Constructor for BoundaryTriangleSet.
|
---|
| 326 | */
|
---|
[1e168b] | 327 | BoundaryTriangleSet::BoundaryTriangleSet() :
|
---|
| 328 | Nr(-1)
|
---|
[357fba] | 329 | {
|
---|
[f67b6e] | 330 | Info FunctionInfo(__func__);
|
---|
[357fba] | 331 | for (int i = 0; i < 3; i++)
|
---|
| 332 | {
|
---|
| 333 | endpoints[i] = NULL;
|
---|
| 334 | lines[i] = NULL;
|
---|
| 335 | }
|
---|
[16d866] | 336 | };
|
---|
[357fba] | 337 |
|
---|
[16d866] | 338 | /** Constructor for BoundaryTriangleSet with three lines.
|
---|
| 339 | * \param *line[3] lines that make up the triangle
|
---|
| 340 | * \param number number of triangle
|
---|
| 341 | */
|
---|
[9473f6] | 342 | BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
|
---|
[1e168b] | 343 | Nr(number)
|
---|
[357fba] | 344 | {
|
---|
[f67b6e] | 345 | Info FunctionInfo(__func__);
|
---|
[357fba] | 346 | // set number
|
---|
| 347 | // set lines
|
---|
[f67b6e] | 348 | for (int i = 0; i < 3; i++) {
|
---|
| 349 | lines[i] = line[i];
|
---|
| 350 | lines[i]->AddTriangle(this);
|
---|
| 351 | }
|
---|
[357fba] | 352 | // get ascending order of endpoints
|
---|
[f67b6e] | 353 | PointMap OrderMap;
|
---|
[357fba] | 354 | for (int i = 0; i < 3; i++)
|
---|
| 355 | // for all three lines
|
---|
[f67b6e] | 356 | for (int j = 0; j < 2; j++) { // for both endpoints
|
---|
| 357 | OrderMap.insert(pair<int, class BoundaryPointSet *> (
|
---|
| 358 | line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
|
---|
| 359 | // and we don't care whether insertion fails
|
---|
| 360 | }
|
---|
[357fba] | 361 | // set endpoints
|
---|
| 362 | int Counter = 0;
|
---|
[f67b6e] | 363 | Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl;
|
---|
| 364 | for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
|
---|
| 365 | endpoints[Counter] = runner->second;
|
---|
| 366 | Log() << Verbose(0) << " " << *endpoints[Counter] << endl;
|
---|
| 367 | Counter++;
|
---|
| 368 | }
|
---|
| 369 | if (Counter < 3) {
|
---|
| 370 | eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl;
|
---|
| 371 | performCriticalExit();
|
---|
| 372 | }
|
---|
[16d866] | 373 | };
|
---|
[357fba] | 374 |
|
---|
[16d866] | 375 | /** Destructor of BoundaryTriangleSet.
|
---|
| 376 | * Removes itself from each of its lines' LineMap and removes them if necessary.
|
---|
| 377 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 378 | */
|
---|
[357fba] | 379 | BoundaryTriangleSet::~BoundaryTriangleSet()
|
---|
| 380 | {
|
---|
[f67b6e] | 381 | Info FunctionInfo(__func__);
|
---|
[357fba] | 382 | for (int i = 0; i < 3; i++) {
|
---|
[16d866] | 383 | if (lines[i] != NULL) {
|
---|
[57066a] | 384 | if (lines[i]->triangles.erase(Nr)) {
|
---|
[f67b6e] | 385 | //Log() << Verbose(0) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
|
---|
[57066a] | 386 | }
|
---|
[16d866] | 387 | if (lines[i]->triangles.empty()) {
|
---|
[f67b6e] | 388 | //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
|
---|
[16d866] | 389 | delete (lines[i]);
|
---|
| 390 | lines[i] = NULL;
|
---|
| 391 | }
|
---|
| 392 | }
|
---|
[357fba] | 393 | }
|
---|
[f67b6e] | 394 | //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
|
---|
[16d866] | 395 | };
|
---|
[357fba] | 396 |
|
---|
| 397 | /** Calculates the normal vector for this triangle.
|
---|
| 398 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 399 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 400 | */
|
---|
[9473f6] | 401 | void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
|
---|
[357fba] | 402 | {
|
---|
[f67b6e] | 403 | Info FunctionInfo(__func__);
|
---|
[357fba] | 404 | // get normal vector
|
---|
| 405 | NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
|
---|
| 406 |
|
---|
| 407 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
[658efb] | 408 | if (NormalVector.ScalarProduct(&OtherVector) > 0.)
|
---|
[357fba] | 409 | NormalVector.Scale(-1.);
|
---|
[f67b6e] | 410 | Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl;
|
---|
[357fba] | 411 | };
|
---|
| 412 |
|
---|
[97498a] | 413 | /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
|
---|
[357fba] | 414 | * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
|
---|
[9473f6] | 415 | * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
[7dea7c] | 416 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 417 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 418 | * the first two basepoints) or not.
|
---|
[357fba] | 419 | * \param *out output stream for debugging
|
---|
| 420 | * \param *MolCenter offset vector of line
|
---|
| 421 | * \param *x second endpoint of line, minus \a *MolCenter is directional vector of line
|
---|
| 422 | * \param *Intersection intersection on plane on return
|
---|
| 423 | * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
|
---|
| 424 | */
|
---|
[9473f6] | 425 | bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
|
---|
[357fba] | 426 | {
|
---|
[fee69b] | 427 | Info FunctionInfo(__func__);
|
---|
[357fba] | 428 | Vector CrossPoint;
|
---|
| 429 | Vector helper;
|
---|
| 430 |
|
---|
[e138de] | 431 | if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
|
---|
[f67b6e] | 432 | eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
|
---|
[357fba] | 433 | return false;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
[97498a] | 436 | Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl;
|
---|
| 437 | Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl;
|
---|
| 438 | Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl;
|
---|
| 439 |
|
---|
[fee69b] | 440 | if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) {
|
---|
| 441 | Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl;
|
---|
| 442 | return true;
|
---|
| 443 | } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
|
---|
| 444 | Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl;
|
---|
| 445 | return true;
|
---|
| 446 | } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
|
---|
| 447 | Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl;
|
---|
| 448 | return true;
|
---|
| 449 | }
|
---|
[357fba] | 450 | // Calculate cross point between one baseline and the line from the third endpoint to intersection
|
---|
[5c7bf8] | 451 | int i=0;
|
---|
[357fba] | 452 | do {
|
---|
[e138de] | 453 | if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) {
|
---|
[fee69b] | 454 | helper.CopyVector(endpoints[(i+1)%3]->node->node);
|
---|
| 455 | helper.SubtractVector(endpoints[i%3]->node->node);
|
---|
[97498a] | 456 | CrossPoint.SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
[fee69b] | 457 | const double s = CrossPoint.ScalarProduct(&helper)/helper.NormSquared();
|
---|
| 458 | Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl;
|
---|
| 459 | if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
|
---|
| 460 | Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl;
|
---|
| 461 | i=4;
|
---|
| 462 | break;
|
---|
| 463 | }
|
---|
[5c7bf8] | 464 | i++;
|
---|
[fcad4b] | 465 | } else
|
---|
| 466 | break;
|
---|
[97498a] | 467 | } while (i<3);
|
---|
[5c7bf8] | 468 | if (i==3) {
|
---|
[fcad4b] | 469 | Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl;
|
---|
[357fba] | 470 | return true;
|
---|
[fcad4b] | 471 | } else {
|
---|
| 472 | Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl;
|
---|
[357fba] | 473 | return false;
|
---|
| 474 | }
|
---|
| 475 | };
|
---|
| 476 |
|
---|
[8db598] | 477 | /** Finds the point on the triangle to the point \a *x.
|
---|
| 478 | * We call Vector::GetIntersectionWithPlane() with \a * and the center of the triangle to receive an intersection point.
|
---|
| 479 | * Then we check the in-plane part (the part projected down onto plane). We check whether it crosses one of the
|
---|
| 480 | * boundary lines. If it does, we return this intersection as closest point, otherwise the projected point down.
|
---|
[9473f6] | 481 | * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
| 482 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 483 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 484 | * the first two basepoints) or not.
|
---|
| 485 | * \param *x point
|
---|
| 486 | * \param *ClosestPoint desired closest point inside triangle to \a *x, is absolute vector
|
---|
| 487 | * \return Distance squared between \a *x and closest point inside triangle
|
---|
| 488 | */
|
---|
| 489 | double BoundaryTriangleSet::GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const
|
---|
| 490 | {
|
---|
| 491 | Info FunctionInfo(__func__);
|
---|
| 492 | Vector Direction;
|
---|
| 493 |
|
---|
| 494 | // 1. get intersection with plane
|
---|
| 495 | Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl;
|
---|
| 496 | GetCenter(&Direction);
|
---|
| 497 | if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
|
---|
| 498 | ClosestPoint->CopyVector(x);
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | // 2. Calculate in plane part of line (x, intersection)
|
---|
| 502 | Vector InPlane;
|
---|
| 503 | InPlane.CopyVector(x);
|
---|
| 504 | InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point
|
---|
| 505 | InPlane.ProjectOntoPlane(&NormalVector);
|
---|
| 506 | InPlane.AddVector(ClosestPoint);
|
---|
| 507 |
|
---|
| 508 | Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl;
|
---|
| 509 | Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl;
|
---|
| 510 | Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl;
|
---|
| 511 |
|
---|
| 512 | // Calculate cross point between one baseline and the desired point such that distance is shortest
|
---|
| 513 | double ShortestDistance = -1.;
|
---|
| 514 | bool InsideFlag = false;
|
---|
| 515 | Vector CrossDirection[3];
|
---|
| 516 | Vector CrossPoint[3];
|
---|
| 517 | Vector helper;
|
---|
| 518 | for (int i=0;i<3;i++) {
|
---|
| 519 | // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
|
---|
| 520 | Direction.CopyVector(endpoints[(i+1)%3]->node->node);
|
---|
| 521 | Direction.SubtractVector(endpoints[i%3]->node->node);
|
---|
| 522 | // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
|
---|
| 523 | CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node);
|
---|
| 524 | CrossDirection[i].CopyVector(&CrossPoint[i]);
|
---|
| 525 | CrossDirection[i].SubtractVector(&InPlane);
|
---|
| 526 | CrossPoint[i].SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
| 527 | const double s = CrossPoint[i].ScalarProduct(&Direction)/Direction.NormSquared();
|
---|
| 528 | Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl;
|
---|
| 529 | if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
|
---|
| 530 | CrossPoint[i].AddVector(endpoints[i%3]->node->node); // make cross point absolute again
|
---|
| 531 | Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i%3]->node->node << " and " << *endpoints[(i+1)%3]->node->node << "." << endl;
|
---|
| 532 | const double distance = CrossPoint[i].DistanceSquared(x);
|
---|
| 533 | if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
|
---|
| 534 | ShortestDistance = distance;
|
---|
| 535 | ClosestPoint->CopyVector(&CrossPoint[i]);
|
---|
| 536 | }
|
---|
| 537 | } else
|
---|
| 538 | CrossPoint[i].Zero();
|
---|
| 539 | }
|
---|
| 540 | InsideFlag = true;
|
---|
| 541 | for (int i=0;i<3;i++) {
|
---|
| 542 | const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+1)%3]);
|
---|
| 543 | const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+2)%3]);;
|
---|
| 544 | if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
|
---|
| 545 | InsideFlag = false;
|
---|
| 546 | }
|
---|
| 547 | if (InsideFlag) {
|
---|
| 548 | ClosestPoint->CopyVector(&InPlane);
|
---|
| 549 | ShortestDistance = InPlane.DistanceSquared(x);
|
---|
| 550 | } else { // also check endnodes
|
---|
| 551 | for (int i=0;i<3;i++) {
|
---|
| 552 | const double distance = x->DistanceSquared(endpoints[i]->node->node);
|
---|
| 553 | if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
|
---|
| 554 | ShortestDistance = distance;
|
---|
| 555 | ClosestPoint->CopyVector(endpoints[i]->node->node);
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 | }
|
---|
| 559 | Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl;
|
---|
| 560 | return ShortestDistance;
|
---|
| 561 | };
|
---|
| 562 |
|
---|
[357fba] | 563 | /** Checks whether lines is any of the three boundary lines this triangle contains.
|
---|
| 564 | * \param *line line to test
|
---|
| 565 | * \return true - line is of the triangle, false - is not
|
---|
| 566 | */
|
---|
[9473f6] | 567 | bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
|
---|
[357fba] | 568 | {
|
---|
[f67b6e] | 569 | Info FunctionInfo(__func__);
|
---|
[357fba] | 570 | for(int i=0;i<3;i++)
|
---|
| 571 | if (line == lines[i])
|
---|
| 572 | return true;
|
---|
| 573 | return false;
|
---|
| 574 | };
|
---|
| 575 |
|
---|
| 576 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 577 | * \param *point point to test
|
---|
| 578 | * \return true - point is of the triangle, false - is not
|
---|
| 579 | */
|
---|
[9473f6] | 580 | bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
[357fba] | 581 | {
|
---|
[f67b6e] | 582 | Info FunctionInfo(__func__);
|
---|
[357fba] | 583 | for(int i=0;i<3;i++)
|
---|
| 584 | if (point == endpoints[i])
|
---|
| 585 | return true;
|
---|
| 586 | return false;
|
---|
| 587 | };
|
---|
| 588 |
|
---|
[7dea7c] | 589 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 590 | * \param *point TesselPoint to test
|
---|
| 591 | * \return true - point is of the triangle, false - is not
|
---|
| 592 | */
|
---|
[9473f6] | 593 | bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
|
---|
[7dea7c] | 594 | {
|
---|
[f67b6e] | 595 | Info FunctionInfo(__func__);
|
---|
[7dea7c] | 596 | for(int i=0;i<3;i++)
|
---|
| 597 | if (point == endpoints[i]->node)
|
---|
| 598 | return true;
|
---|
| 599 | return false;
|
---|
| 600 | };
|
---|
| 601 |
|
---|
[357fba] | 602 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 603 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 604 | * \return true - is the very triangle, false - is not
|
---|
| 605 | */
|
---|
[9473f6] | 606 | bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
|
---|
[357fba] | 607 | {
|
---|
[f67b6e] | 608 | Info FunctionInfo(__func__);
|
---|
[71b20e] | 609 | Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl;
|
---|
[357fba] | 610 | return (((endpoints[0] == Points[0])
|
---|
| 611 | || (endpoints[0] == Points[1])
|
---|
| 612 | || (endpoints[0] == Points[2])
|
---|
| 613 | ) && (
|
---|
| 614 | (endpoints[1] == Points[0])
|
---|
| 615 | || (endpoints[1] == Points[1])
|
---|
| 616 | || (endpoints[1] == Points[2])
|
---|
| 617 | ) && (
|
---|
| 618 | (endpoints[2] == Points[0])
|
---|
| 619 | || (endpoints[2] == Points[1])
|
---|
| 620 | || (endpoints[2] == Points[2])
|
---|
[62bb91] | 621 |
|
---|
[357fba] | 622 | ));
|
---|
| 623 | };
|
---|
| 624 |
|
---|
[57066a] | 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 BoundaryTriangleSet * const T) const
|
---|
[57066a] | 630 | {
|
---|
[f67b6e] | 631 | Info FunctionInfo(__func__);
|
---|
[57066a] | 632 | return (((endpoints[0] == T->endpoints[0])
|
---|
| 633 | || (endpoints[0] == T->endpoints[1])
|
---|
| 634 | || (endpoints[0] == T->endpoints[2])
|
---|
| 635 | ) && (
|
---|
| 636 | (endpoints[1] == T->endpoints[0])
|
---|
| 637 | || (endpoints[1] == T->endpoints[1])
|
---|
| 638 | || (endpoints[1] == T->endpoints[2])
|
---|
| 639 | ) && (
|
---|
| 640 | (endpoints[2] == T->endpoints[0])
|
---|
| 641 | || (endpoints[2] == T->endpoints[1])
|
---|
| 642 | || (endpoints[2] == T->endpoints[2])
|
---|
| 643 |
|
---|
| 644 | ));
|
---|
| 645 | };
|
---|
| 646 |
|
---|
[62bb91] | 647 | /** Returns the endpoint which is not contained in the given \a *line.
|
---|
| 648 | * \param *line baseline defining two endpoints
|
---|
| 649 | * \return pointer third endpoint or NULL if line does not belong to triangle.
|
---|
| 650 | */
|
---|
[9473f6] | 651 | class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
|
---|
[62bb91] | 652 | {
|
---|
[f67b6e] | 653 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 654 | // sanity check
|
---|
| 655 | if (!ContainsBoundaryLine(line))
|
---|
| 656 | return NULL;
|
---|
| 657 | for(int i=0;i<3;i++)
|
---|
| 658 | if (!line->ContainsBoundaryPoint(endpoints[i]))
|
---|
| 659 | return endpoints[i];
|
---|
| 660 | // actually, that' impossible :)
|
---|
| 661 | return NULL;
|
---|
| 662 | };
|
---|
| 663 |
|
---|
| 664 | /** Calculates the center point of the triangle.
|
---|
| 665 | * Is third of the sum of all endpoints.
|
---|
| 666 | * \param *center central point on return.
|
---|
| 667 | */
|
---|
[9473f6] | 668 | void BoundaryTriangleSet::GetCenter(Vector * const center) const
|
---|
[62bb91] | 669 | {
|
---|
[f67b6e] | 670 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 671 | center->Zero();
|
---|
| 672 | for(int i=0;i<3;i++)
|
---|
| 673 | center->AddVector(endpoints[i]->node->node);
|
---|
| 674 | center->Scale(1./3.);
|
---|
[9473f6] | 675 | Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl;
|
---|
[62bb91] | 676 | }
|
---|
| 677 |
|
---|
[16d866] | 678 | /** output operator for BoundaryTriangleSet.
|
---|
| 679 | * \param &ost output stream
|
---|
| 680 | * \param &a boundary triangle
|
---|
| 681 | */
|
---|
[776b64] | 682 | ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
|
---|
[357fba] | 683 | {
|
---|
[f67b6e] | 684 | ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]";
|
---|
| 685 | // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
|
---|
| 686 | // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
|
---|
[357fba] | 687 | return ost;
|
---|
[16d866] | 688 | };
|
---|
[357fba] | 689 |
|
---|
[262bae] | 690 | // ======================================== Polygons on Boundary =================================
|
---|
| 691 |
|
---|
| 692 | /** Constructor for BoundaryPolygonSet.
|
---|
| 693 | */
|
---|
| 694 | BoundaryPolygonSet::BoundaryPolygonSet() :
|
---|
| 695 | Nr(-1)
|
---|
| 696 | {
|
---|
| 697 | Info FunctionInfo(__func__);
|
---|
| 698 | };
|
---|
| 699 |
|
---|
| 700 | /** Destructor of BoundaryPolygonSet.
|
---|
| 701 | * Just clears endpoints.
|
---|
| 702 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 703 | */
|
---|
| 704 | BoundaryPolygonSet::~BoundaryPolygonSet()
|
---|
| 705 | {
|
---|
| 706 | Info FunctionInfo(__func__);
|
---|
| 707 | endpoints.clear();
|
---|
| 708 | Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl;
|
---|
| 709 | };
|
---|
| 710 |
|
---|
| 711 | /** Calculates the normal vector for this triangle.
|
---|
| 712 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 713 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 714 | * \return allocated vector in normal direction
|
---|
| 715 | */
|
---|
| 716 | Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
|
---|
| 717 | {
|
---|
| 718 | Info FunctionInfo(__func__);
|
---|
| 719 | // get normal vector
|
---|
| 720 | Vector TemporaryNormal;
|
---|
| 721 | Vector *TotalNormal = new Vector;
|
---|
| 722 | PointSet::const_iterator Runner[3];
|
---|
| 723 | for (int i=0;i<3; i++) {
|
---|
| 724 | Runner[i] = endpoints.begin();
|
---|
| 725 | for (int j = 0; j<i; j++) { // go as much further
|
---|
| 726 | Runner[i]++;
|
---|
| 727 | if (Runner[i] == endpoints.end()) {
|
---|
| 728 | eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl;
|
---|
| 729 | performCriticalExit();
|
---|
| 730 | }
|
---|
| 731 | }
|
---|
| 732 | }
|
---|
| 733 | TotalNormal->Zero();
|
---|
| 734 | int counter=0;
|
---|
| 735 | for (; Runner[2] != endpoints.end(); ) {
|
---|
| 736 | TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
|
---|
| 737 | for (int i=0;i<3;i++) // increase each of them
|
---|
| 738 | Runner[i]++;
|
---|
| 739 | TotalNormal->AddVector(&TemporaryNormal);
|
---|
| 740 | }
|
---|
| 741 | TotalNormal->Scale(1./(double)counter);
|
---|
| 742 |
|
---|
| 743 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
| 744 | if (TotalNormal->ScalarProduct(&OtherVector) > 0.)
|
---|
| 745 | TotalNormal->Scale(-1.);
|
---|
| 746 | Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl;
|
---|
| 747 |
|
---|
| 748 | return TotalNormal;
|
---|
| 749 | };
|
---|
| 750 |
|
---|
| 751 | /** Calculates the center point of the triangle.
|
---|
| 752 | * Is third of the sum of all endpoints.
|
---|
| 753 | * \param *center central point on return.
|
---|
| 754 | */
|
---|
| 755 | void BoundaryPolygonSet::GetCenter(Vector * const center) const
|
---|
| 756 | {
|
---|
| 757 | Info FunctionInfo(__func__);
|
---|
| 758 | center->Zero();
|
---|
| 759 | int counter = 0;
|
---|
| 760 | for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
| 761 | center->AddVector((*Runner)->node->node);
|
---|
| 762 | counter++;
|
---|
| 763 | }
|
---|
| 764 | center->Scale(1./(double)counter);
|
---|
[856098] | 765 | Log() << Verbose(1) << "Center is at " << *center << "." << endl;
|
---|
[262bae] | 766 | }
|
---|
| 767 |
|
---|
| 768 | /** Checks whether the polygons contains all three endpoints of the triangle.
|
---|
| 769 | * \param *triangle triangle to test
|
---|
| 770 | * \return true - triangle is contained polygon, false - is not
|
---|
| 771 | */
|
---|
| 772 | bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
|
---|
| 773 | {
|
---|
| 774 | Info FunctionInfo(__func__);
|
---|
| 775 | return ContainsPresentTupel(triangle->endpoints, 3);
|
---|
| 776 | };
|
---|
| 777 |
|
---|
| 778 | /** Checks whether the polygons contains both endpoints of the line.
|
---|
| 779 | * \param *line line to test
|
---|
| 780 | * \return true - line is of the triangle, false - is not
|
---|
| 781 | */
|
---|
| 782 | bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
|
---|
| 783 | {
|
---|
[856098] | 784 | Info FunctionInfo(__func__);
|
---|
[262bae] | 785 | return ContainsPresentTupel(line->endpoints, 2);
|
---|
| 786 | };
|
---|
| 787 |
|
---|
| 788 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 789 | * \param *point point to test
|
---|
| 790 | * \return true - point is of the triangle, false - is not
|
---|
| 791 | */
|
---|
| 792 | bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
| 793 | {
|
---|
| 794 | Info FunctionInfo(__func__);
|
---|
[856098] | 795 | for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
| 796 | Log() << Verbose(0) << "Checking against " << **Runner << endl;
|
---|
| 797 | if (point == (*Runner)) {
|
---|
| 798 | Log() << Verbose(0) << " Contained." << endl;
|
---|
[262bae] | 799 | return true;
|
---|
[856098] | 800 | }
|
---|
| 801 | }
|
---|
| 802 | Log() << Verbose(0) << " Not contained." << endl;
|
---|
[262bae] | 803 | return false;
|
---|
| 804 | };
|
---|
| 805 |
|
---|
| 806 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 807 | * \param *point TesselPoint to test
|
---|
| 808 | * \return true - point is of the triangle, false - is not
|
---|
| 809 | */
|
---|
| 810 | bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
|
---|
| 811 | {
|
---|
| 812 | Info FunctionInfo(__func__);
|
---|
| 813 | for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
|
---|
[856098] | 814 | if (point == (*Runner)->node) {
|
---|
| 815 | Log() << Verbose(0) << " Contained." << endl;
|
---|
[262bae] | 816 | return true;
|
---|
[856098] | 817 | }
|
---|
| 818 | Log() << Verbose(0) << " Not contained." << endl;
|
---|
[262bae] | 819 | return false;
|
---|
| 820 | };
|
---|
| 821 |
|
---|
| 822 | /** Checks whether given array of \a *Points coincide with polygons's endpoints.
|
---|
| 823 | * \param **Points pointer to an array of BoundaryPointSet
|
---|
| 824 | * \param dim dimension of array
|
---|
| 825 | * \return true - set of points is contained in polygon, false - is not
|
---|
| 826 | */
|
---|
| 827 | bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
|
---|
| 828 | {
|
---|
[856098] | 829 | Info FunctionInfo(__func__);
|
---|
[262bae] | 830 | int counter = 0;
|
---|
[856098] | 831 | Log() << Verbose(1) << "Polygon is " << *this << endl;
|
---|
| 832 | for(int i=0;i<dim;i++) {
|
---|
| 833 | Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl;
|
---|
| 834 | if (ContainsBoundaryPoint(Points[i])) {
|
---|
[262bae] | 835 | counter++;
|
---|
[856098] | 836 | }
|
---|
| 837 | }
|
---|
[262bae] | 838 |
|
---|
| 839 | if (counter == dim)
|
---|
| 840 | return true;
|
---|
| 841 | else
|
---|
| 842 | return false;
|
---|
| 843 | };
|
---|
| 844 |
|
---|
| 845 | /** Checks whether given PointList coincide with polygons's endpoints.
|
---|
| 846 | * \param &endpoints PointList
|
---|
| 847 | * \return true - set of points is contained in polygon, false - is not
|
---|
| 848 | */
|
---|
| 849 | bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
|
---|
| 850 | {
|
---|
[856098] | 851 | Info FunctionInfo(__func__);
|
---|
[262bae] | 852 | size_t counter = 0;
|
---|
[856098] | 853 | Log() << Verbose(1) << "Polygon is " << *this << endl;
|
---|
[262bae] | 854 | for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[856098] | 855 | Log() << Verbose(1) << " Testing endpoint " << **Runner << endl;
|
---|
[262bae] | 856 | if (ContainsBoundaryPoint(*Runner))
|
---|
| 857 | counter++;
|
---|
| 858 | }
|
---|
| 859 |
|
---|
| 860 | if (counter == endpoints.size())
|
---|
| 861 | return true;
|
---|
| 862 | else
|
---|
| 863 | return false;
|
---|
| 864 | };
|
---|
| 865 |
|
---|
| 866 | /** Checks whether given set of \a *Points coincide with polygons's endpoints.
|
---|
| 867 | * \param *P pointer to BoundaryPolygonSet
|
---|
| 868 | * \return true - is the very triangle, false - is not
|
---|
| 869 | */
|
---|
| 870 | bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
|
---|
| 871 | {
|
---|
| 872 | return ContainsPresentTupel((const PointSet)P->endpoints);
|
---|
| 873 | };
|
---|
| 874 |
|
---|
| 875 | /** Gathers all the endpoints' triangles in a unique set.
|
---|
| 876 | * \return set of all triangles
|
---|
| 877 | */
|
---|
[856098] | 878 | TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
|
---|
[262bae] | 879 | {
|
---|
| 880 | Info FunctionInfo(__func__);
|
---|
[856098] | 881 | pair <TriangleSet::iterator, bool> Tester;
|
---|
[262bae] | 882 | TriangleSet *triangles = new TriangleSet;
|
---|
| 883 |
|
---|
| 884 | for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
|
---|
| 885 | for(LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
|
---|
[856098] | 886 | for(TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
|
---|
| 887 | //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
|
---|
| 888 | if (ContainsBoundaryTriangle(Sprinter->second)) {
|
---|
| 889 | Tester = triangles->insert(Sprinter->second);
|
---|
| 890 | if (Tester.second)
|
---|
| 891 | Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl;
|
---|
| 892 | }
|
---|
| 893 | }
|
---|
[262bae] | 894 |
|
---|
| 895 | Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl;
|
---|
| 896 | return triangles;
|
---|
| 897 | };
|
---|
| 898 |
|
---|
| 899 | /** Fills the endpoints of this polygon from the triangles attached to \a *line.
|
---|
| 900 | * \param *line lines with triangles attached
|
---|
[856098] | 901 | * \return true - polygon contains endpoints, false - line was NULL
|
---|
[262bae] | 902 | */
|
---|
| 903 | bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
|
---|
| 904 | {
|
---|
[856098] | 905 | Info FunctionInfo(__func__);
|
---|
| 906 | pair <PointSet::iterator, bool> Tester;
|
---|
| 907 | if (line == NULL)
|
---|
| 908 | return false;
|
---|
| 909 | Log() << Verbose(1) << "Filling polygon from line " << *line << endl;
|
---|
[262bae] | 910 | for(TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
|
---|
[856098] | 911 | for (int i=0;i<3;i++) {
|
---|
| 912 | Tester = endpoints.insert((Runner->second)->endpoints[i]);
|
---|
| 913 | if (Tester.second)
|
---|
| 914 | Log() << Verbose(1) << " Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl;
|
---|
| 915 | }
|
---|
[262bae] | 916 | }
|
---|
| 917 |
|
---|
[856098] | 918 | return true;
|
---|
[262bae] | 919 | };
|
---|
| 920 |
|
---|
| 921 | /** output operator for BoundaryPolygonSet.
|
---|
| 922 | * \param &ost output stream
|
---|
| 923 | * \param &a boundary polygon
|
---|
| 924 | */
|
---|
| 925 | ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
|
---|
| 926 | {
|
---|
| 927 | ost << "[" << a.Nr << "|";
|
---|
| 928 | for(PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
|
---|
| 929 | ost << (*Runner)->node->Name;
|
---|
| 930 | Runner++;
|
---|
| 931 | if (Runner != a.endpoints.end())
|
---|
| 932 | ost << ",";
|
---|
| 933 | }
|
---|
| 934 | ost<< "]";
|
---|
| 935 | return ost;
|
---|
| 936 | };
|
---|
| 937 |
|
---|
[357fba] | 938 | // =========================================================== class TESSELPOINT ===========================================
|
---|
| 939 |
|
---|
| 940 | /** Constructor of class TesselPoint.
|
---|
| 941 | */
|
---|
| 942 | TesselPoint::TesselPoint()
|
---|
| 943 | {
|
---|
[244a84] | 944 | //Info FunctionInfo(__func__);
|
---|
[357fba] | 945 | node = NULL;
|
---|
| 946 | nr = -1;
|
---|
| 947 | Name = NULL;
|
---|
| 948 | };
|
---|
| 949 |
|
---|
| 950 | /** Destructor for class TesselPoint.
|
---|
| 951 | */
|
---|
| 952 | TesselPoint::~TesselPoint()
|
---|
| 953 | {
|
---|
[244a84] | 954 | //Info FunctionInfo(__func__);
|
---|
[357fba] | 955 | };
|
---|
| 956 |
|
---|
| 957 | /** Prints LCNode to screen.
|
---|
| 958 | */
|
---|
| 959 | ostream & operator << (ostream &ost, const TesselPoint &a)
|
---|
| 960 | {
|
---|
[57066a] | 961 | ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]";
|
---|
[357fba] | 962 | return ost;
|
---|
| 963 | };
|
---|
| 964 |
|
---|
[5c7bf8] | 965 | /** Prints LCNode to screen.
|
---|
| 966 | */
|
---|
| 967 | ostream & TesselPoint::operator << (ostream &ost)
|
---|
| 968 | {
|
---|
[f67b6e] | 969 | Info FunctionInfo(__func__);
|
---|
[27bd2f] | 970 | ost << "[" << (nr) << "|" << this << "]";
|
---|
[5c7bf8] | 971 | return ost;
|
---|
| 972 | };
|
---|
| 973 |
|
---|
[357fba] | 974 |
|
---|
| 975 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 976 |
|
---|
| 977 | /** Constructor of class PointCloud.
|
---|
| 978 | */
|
---|
| 979 | PointCloud::PointCloud()
|
---|
| 980 | {
|
---|
[244a84] | 981 | //Info FunctionInfo(__func__);
|
---|
[357fba] | 982 | };
|
---|
| 983 |
|
---|
| 984 | /** Destructor for class PointCloud.
|
---|
| 985 | */
|
---|
| 986 | PointCloud::~PointCloud()
|
---|
| 987 | {
|
---|
[244a84] | 988 | //Info FunctionInfo(__func__);
|
---|
[357fba] | 989 | };
|
---|
| 990 |
|
---|
| 991 | // ============================ CandidateForTesselation =============================
|
---|
| 992 |
|
---|
| 993 | /** Constructor of class CandidateForTesselation.
|
---|
| 994 | */
|
---|
[1e168b] | 995 | CandidateForTesselation::CandidateForTesselation (BoundaryLineSet* line) :
|
---|
| 996 | BaseLine(line),
|
---|
| 997 | ShortestAngle(2.*M_PI),
|
---|
| 998 | OtherShortestAngle(2.*M_PI)
|
---|
| 999 | {
|
---|
[f67b6e] | 1000 | Info FunctionInfo(__func__);
|
---|
[1e168b] | 1001 | };
|
---|
| 1002 |
|
---|
| 1003 |
|
---|
| 1004 | /** Constructor of class CandidateForTesselation.
|
---|
| 1005 | */
|
---|
| 1006 | CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
|
---|
| 1007 | BaseLine(line),
|
---|
| 1008 | ShortestAngle(2.*M_PI),
|
---|
| 1009 | OtherShortestAngle(2.*M_PI)
|
---|
| 1010 | {
|
---|
[f67b6e] | 1011 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1012 | OptCenter.CopyVector(&OptCandidateCenter);
|
---|
| 1013 | OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
|
---|
| 1014 | };
|
---|
| 1015 |
|
---|
| 1016 | /** Destructor for class CandidateForTesselation.
|
---|
| 1017 | */
|
---|
| 1018 | CandidateForTesselation::~CandidateForTesselation() {
|
---|
| 1019 | BaseLine = NULL;
|
---|
| 1020 | };
|
---|
| 1021 |
|
---|
[1e168b] | 1022 | /** output operator for CandidateForTesselation.
|
---|
| 1023 | * \param &ost output stream
|
---|
| 1024 | * \param &a boundary line
|
---|
| 1025 | */
|
---|
| 1026 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
|
---|
| 1027 | {
|
---|
| 1028 | ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with ";
|
---|
[f67b6e] | 1029 | if (a.pointlist.empty())
|
---|
[1e168b] | 1030 | ost << "no candidate.";
|
---|
[f67b6e] | 1031 | else {
|
---|
| 1032 | ost << "candidate";
|
---|
| 1033 | if (a.pointlist.size() != 1)
|
---|
| 1034 | ost << "s ";
|
---|
| 1035 | else
|
---|
| 1036 | ost << " ";
|
---|
| 1037 | for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
|
---|
| 1038 | ost << *(*Runner) << " ";
|
---|
| 1039 | ost << " at angle " << (a.ShortestAngle)<< ".";
|
---|
| 1040 | }
|
---|
[1e168b] | 1041 |
|
---|
| 1042 | return ost;
|
---|
| 1043 | };
|
---|
| 1044 |
|
---|
| 1045 |
|
---|
[357fba] | 1046 | // =========================================================== class TESSELATION ===========================================
|
---|
| 1047 |
|
---|
| 1048 | /** Constructor of class Tesselation.
|
---|
| 1049 | */
|
---|
[1e168b] | 1050 | Tesselation::Tesselation() :
|
---|
| 1051 | PointsOnBoundaryCount(0),
|
---|
| 1052 | LinesOnBoundaryCount(0),
|
---|
| 1053 | TrianglesOnBoundaryCount(0),
|
---|
| 1054 | LastTriangle(NULL),
|
---|
| 1055 | TriangleFilesWritten(0),
|
---|
| 1056 | InternalPointer(PointsOnBoundary.begin())
|
---|
[357fba] | 1057 | {
|
---|
[f67b6e] | 1058 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1059 | }
|
---|
| 1060 | ;
|
---|
| 1061 |
|
---|
| 1062 | /** Destructor of class Tesselation.
|
---|
| 1063 | * We have to free all points, lines and triangles.
|
---|
| 1064 | */
|
---|
| 1065 | Tesselation::~Tesselation()
|
---|
| 1066 | {
|
---|
[f67b6e] | 1067 | Info FunctionInfo(__func__);
|
---|
| 1068 | Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl;
|
---|
[357fba] | 1069 | for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
|
---|
| 1070 | if (runner->second != NULL) {
|
---|
| 1071 | delete (runner->second);
|
---|
| 1072 | runner->second = NULL;
|
---|
| 1073 | } else
|
---|
[717e0c] | 1074 | eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl;
|
---|
[357fba] | 1075 | }
|
---|
[f67b6e] | 1076 | Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
|
---|
[357fba] | 1077 | }
|
---|
| 1078 | ;
|
---|
| 1079 |
|
---|
[5c7bf8] | 1080 | /** PointCloud implementation of GetCenter
|
---|
| 1081 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 1082 | */
|
---|
[776b64] | 1083 | Vector * Tesselation::GetCenter(ofstream *out) const
|
---|
[5c7bf8] | 1084 | {
|
---|
[f67b6e] | 1085 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1086 | Vector *Center = new Vector(0.,0.,0.);
|
---|
| 1087 | int num=0;
|
---|
| 1088 | for (GoToFirst(); (!IsEnd()); GoToNext()) {
|
---|
| 1089 | Center->AddVector(GetPoint()->node);
|
---|
| 1090 | num++;
|
---|
| 1091 | }
|
---|
| 1092 | Center->Scale(1./num);
|
---|
| 1093 | return Center;
|
---|
| 1094 | };
|
---|
| 1095 |
|
---|
| 1096 | /** PointCloud implementation of GoPoint
|
---|
| 1097 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 1098 | */
|
---|
[776b64] | 1099 | TesselPoint * Tesselation::GetPoint() const
|
---|
[5c7bf8] | 1100 | {
|
---|
[f67b6e] | 1101 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1102 | return (InternalPointer->second->node);
|
---|
| 1103 | };
|
---|
| 1104 |
|
---|
| 1105 | /** PointCloud implementation of GetTerminalPoint.
|
---|
| 1106 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 1107 | */
|
---|
[776b64] | 1108 | TesselPoint * Tesselation::GetTerminalPoint() const
|
---|
[5c7bf8] | 1109 | {
|
---|
[f67b6e] | 1110 | Info FunctionInfo(__func__);
|
---|
[776b64] | 1111 | PointMap::const_iterator Runner = PointsOnBoundary.end();
|
---|
[5c7bf8] | 1112 | Runner--;
|
---|
| 1113 | return (Runner->second->node);
|
---|
| 1114 | };
|
---|
| 1115 |
|
---|
| 1116 | /** PointCloud implementation of GoToNext.
|
---|
| 1117 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 1118 | */
|
---|
[776b64] | 1119 | void Tesselation::GoToNext() const
|
---|
[5c7bf8] | 1120 | {
|
---|
[f67b6e] | 1121 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1122 | if (InternalPointer != PointsOnBoundary.end())
|
---|
| 1123 | InternalPointer++;
|
---|
| 1124 | };
|
---|
| 1125 |
|
---|
| 1126 | /** PointCloud implementation of GoToPrevious.
|
---|
| 1127 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 1128 | */
|
---|
[776b64] | 1129 | void Tesselation::GoToPrevious() const
|
---|
[5c7bf8] | 1130 | {
|
---|
[f67b6e] | 1131 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1132 | if (InternalPointer != PointsOnBoundary.begin())
|
---|
| 1133 | InternalPointer--;
|
---|
| 1134 | };
|
---|
| 1135 |
|
---|
| 1136 | /** PointCloud implementation of GoToFirst.
|
---|
| 1137 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 1138 | */
|
---|
[776b64] | 1139 | void Tesselation::GoToFirst() const
|
---|
[5c7bf8] | 1140 | {
|
---|
[f67b6e] | 1141 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1142 | InternalPointer = PointsOnBoundary.begin();
|
---|
| 1143 | };
|
---|
| 1144 |
|
---|
| 1145 | /** PointCloud implementation of GoToLast.
|
---|
| 1146 | * Uses PointsOnBoundary and STL stuff.
|
---|
[776b64] | 1147 | */
|
---|
| 1148 | void Tesselation::GoToLast() const
|
---|
[5c7bf8] | 1149 | {
|
---|
[f67b6e] | 1150 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1151 | InternalPointer = PointsOnBoundary.end();
|
---|
| 1152 | InternalPointer--;
|
---|
| 1153 | };
|
---|
| 1154 |
|
---|
| 1155 | /** PointCloud implementation of IsEmpty.
|
---|
| 1156 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 1157 | */
|
---|
[776b64] | 1158 | bool Tesselation::IsEmpty() const
|
---|
[5c7bf8] | 1159 | {
|
---|
[f67b6e] | 1160 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1161 | return (PointsOnBoundary.empty());
|
---|
| 1162 | };
|
---|
| 1163 |
|
---|
| 1164 | /** PointCloud implementation of IsLast.
|
---|
| 1165 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 1166 | */
|
---|
[776b64] | 1167 | bool Tesselation::IsEnd() const
|
---|
[5c7bf8] | 1168 | {
|
---|
[f67b6e] | 1169 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1170 | return (InternalPointer == PointsOnBoundary.end());
|
---|
| 1171 | };
|
---|
| 1172 |
|
---|
| 1173 |
|
---|
[357fba] | 1174 | /** Gueses first starting triangle of the convex envelope.
|
---|
| 1175 | * We guess the starting triangle by taking the smallest distance between two points and looking for a fitting third.
|
---|
| 1176 | * \param *out output stream for debugging
|
---|
| 1177 | * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
|
---|
| 1178 | */
|
---|
[244a84] | 1179 | void Tesselation::GuessStartingTriangle()
|
---|
[357fba] | 1180 | {
|
---|
[f67b6e] | 1181 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1182 | // 4b. create a starting triangle
|
---|
| 1183 | // 4b1. create all distances
|
---|
| 1184 | DistanceMultiMap DistanceMMap;
|
---|
| 1185 | double distance, tmp;
|
---|
| 1186 | Vector PlaneVector, TrialVector;
|
---|
| 1187 | PointMap::iterator A, B, C; // three nodes of the first triangle
|
---|
| 1188 | A = PointsOnBoundary.begin(); // the first may be chosen arbitrarily
|
---|
| 1189 |
|
---|
| 1190 | // with A chosen, take each pair B,C and sort
|
---|
| 1191 | if (A != PointsOnBoundary.end())
|
---|
| 1192 | {
|
---|
| 1193 | B = A;
|
---|
| 1194 | B++;
|
---|
| 1195 | for (; B != PointsOnBoundary.end(); B++)
|
---|
| 1196 | {
|
---|
| 1197 | C = B;
|
---|
| 1198 | C++;
|
---|
| 1199 | for (; C != PointsOnBoundary.end(); C++)
|
---|
| 1200 | {
|
---|
| 1201 | tmp = A->second->node->node->DistanceSquared(B->second->node->node);
|
---|
| 1202 | distance = tmp * tmp;
|
---|
| 1203 | tmp = A->second->node->node->DistanceSquared(C->second->node->node);
|
---|
| 1204 | distance += tmp * tmp;
|
---|
| 1205 | tmp = B->second->node->node->DistanceSquared(C->second->node->node);
|
---|
| 1206 | distance += tmp * tmp;
|
---|
| 1207 | DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
|
---|
| 1208 | }
|
---|
| 1209 | }
|
---|
| 1210 | }
|
---|
| 1211 | // // listing distances
|
---|
[e138de] | 1212 | // Log() << Verbose(1) << "Listing DistanceMMap:";
|
---|
[357fba] | 1213 | // for(DistanceMultiMap::iterator runner = DistanceMMap.begin(); runner != DistanceMMap.end(); runner++) {
|
---|
[e138de] | 1214 | // Log() << Verbose(0) << " " << runner->first << "(" << *runner->second.first->second << ", " << *runner->second.second->second << ")";
|
---|
[357fba] | 1215 | // }
|
---|
[e138de] | 1216 | // Log() << Verbose(0) << endl;
|
---|
[357fba] | 1217 | // 4b2. pick three baselines forming a triangle
|
---|
| 1218 | // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 1219 | DistanceMultiMap::iterator baseline = DistanceMMap.begin();
|
---|
| 1220 | for (; baseline != DistanceMMap.end(); baseline++)
|
---|
| 1221 | {
|
---|
| 1222 | // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 1223 | // 2. next, we have to check whether all points reside on only one side of the triangle
|
---|
| 1224 | // 3. construct plane vector
|
---|
| 1225 | PlaneVector.MakeNormalVector(A->second->node->node,
|
---|
| 1226 | baseline->second.first->second->node->node,
|
---|
| 1227 | baseline->second.second->second->node->node);
|
---|
[f67b6e] | 1228 | Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl;
|
---|
[357fba] | 1229 | // 4. loop over all points
|
---|
| 1230 | double sign = 0.;
|
---|
| 1231 | PointMap::iterator checker = PointsOnBoundary.begin();
|
---|
| 1232 | for (; checker != PointsOnBoundary.end(); checker++)
|
---|
| 1233 | {
|
---|
| 1234 | // (neglecting A,B,C)
|
---|
| 1235 | if ((checker == A) || (checker == baseline->second.first) || (checker
|
---|
| 1236 | == baseline->second.second))
|
---|
| 1237 | continue;
|
---|
| 1238 | // 4a. project onto plane vector
|
---|
| 1239 | TrialVector.CopyVector(checker->second->node->node);
|
---|
| 1240 | TrialVector.SubtractVector(A->second->node->node);
|
---|
[658efb] | 1241 | distance = TrialVector.ScalarProduct(&PlaneVector);
|
---|
[357fba] | 1242 | if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
|
---|
| 1243 | continue;
|
---|
[f67b6e] | 1244 | Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl;
|
---|
[357fba] | 1245 | tmp = distance / fabs(distance);
|
---|
| 1246 | // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
|
---|
| 1247 | if ((sign != 0) && (tmp != sign))
|
---|
| 1248 | {
|
---|
| 1249 | // 4c. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
[e138de] | 1250 | Log() << Verbose(2) << "Current candidates: "
|
---|
[357fba] | 1251 | << A->second->node->Name << ","
|
---|
| 1252 | << baseline->second.first->second->node->Name << ","
|
---|
| 1253 | << baseline->second.second->second->node->Name << " leaves "
|
---|
| 1254 | << checker->second->node->Name << " outside the convex hull."
|
---|
| 1255 | << endl;
|
---|
| 1256 | break;
|
---|
| 1257 | }
|
---|
| 1258 | else
|
---|
| 1259 | { // note the sign for later
|
---|
[e138de] | 1260 | Log() << Verbose(2) << "Current candidates: "
|
---|
[357fba] | 1261 | << A->second->node->Name << ","
|
---|
| 1262 | << baseline->second.first->second->node->Name << ","
|
---|
| 1263 | << baseline->second.second->second->node->Name << " leave "
|
---|
| 1264 | << checker->second->node->Name << " inside the convex hull."
|
---|
| 1265 | << endl;
|
---|
| 1266 | sign = tmp;
|
---|
| 1267 | }
|
---|
| 1268 | // 4d. Check whether the point is inside the triangle (check distance to each node
|
---|
| 1269 | tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
|
---|
| 1270 | int innerpoint = 0;
|
---|
| 1271 | if ((tmp < A->second->node->node->DistanceSquared(
|
---|
| 1272 | baseline->second.first->second->node->node)) && (tmp
|
---|
| 1273 | < A->second->node->node->DistanceSquared(
|
---|
| 1274 | baseline->second.second->second->node->node)))
|
---|
| 1275 | innerpoint++;
|
---|
| 1276 | tmp = checker->second->node->node->DistanceSquared(
|
---|
| 1277 | baseline->second.first->second->node->node);
|
---|
| 1278 | if ((tmp < baseline->second.first->second->node->node->DistanceSquared(
|
---|
| 1279 | A->second->node->node)) && (tmp
|
---|
| 1280 | < baseline->second.first->second->node->node->DistanceSquared(
|
---|
| 1281 | baseline->second.second->second->node->node)))
|
---|
| 1282 | innerpoint++;
|
---|
| 1283 | tmp = checker->second->node->node->DistanceSquared(
|
---|
| 1284 | baseline->second.second->second->node->node);
|
---|
| 1285 | if ((tmp < baseline->second.second->second->node->node->DistanceSquared(
|
---|
| 1286 | baseline->second.first->second->node->node)) && (tmp
|
---|
| 1287 | < baseline->second.second->second->node->node->DistanceSquared(
|
---|
| 1288 | A->second->node->node)))
|
---|
| 1289 | innerpoint++;
|
---|
| 1290 | // 4e. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
| 1291 | if (innerpoint == 3)
|
---|
| 1292 | break;
|
---|
| 1293 | }
|
---|
| 1294 | // 5. come this far, all on same side? Then break 1. loop and construct triangle
|
---|
| 1295 | if (checker == PointsOnBoundary.end())
|
---|
| 1296 | {
|
---|
[f67b6e] | 1297 | Log() << Verbose(2) << "Looks like we have a candidate!" << endl;
|
---|
[357fba] | 1298 | break;
|
---|
| 1299 | }
|
---|
| 1300 | }
|
---|
| 1301 | if (baseline != DistanceMMap.end())
|
---|
| 1302 | {
|
---|
| 1303 | BPS[0] = baseline->second.first->second;
|
---|
| 1304 | BPS[1] = baseline->second.second->second;
|
---|
| 1305 | BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1306 | BPS[0] = A->second;
|
---|
| 1307 | BPS[1] = baseline->second.second->second;
|
---|
| 1308 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1309 | BPS[0] = baseline->second.first->second;
|
---|
| 1310 | BPS[1] = A->second;
|
---|
| 1311 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1312 |
|
---|
| 1313 | // 4b3. insert created triangle
|
---|
| 1314 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 1315 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1316 | TrianglesOnBoundaryCount++;
|
---|
| 1317 | for (int i = 0; i < NDIM; i++)
|
---|
| 1318 | {
|
---|
| 1319 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
|
---|
| 1320 | LinesOnBoundaryCount++;
|
---|
| 1321 | }
|
---|
| 1322 |
|
---|
[e138de] | 1323 | Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl;
|
---|
[357fba] | 1324 | }
|
---|
| 1325 | else
|
---|
| 1326 | {
|
---|
[f67b6e] | 1327 | eLog() << Verbose(0) << "No starting triangle found." << endl;
|
---|
[357fba] | 1328 | }
|
---|
| 1329 | }
|
---|
| 1330 | ;
|
---|
| 1331 |
|
---|
| 1332 | /** Tesselates the convex envelope of a cluster from a single starting triangle.
|
---|
| 1333 | * The starting triangle is made out of three baselines. Each line in the final tesselated cluster may belong to at most
|
---|
| 1334 | * 2 triangles. Hence, we go through all current lines:
|
---|
| 1335 | * -# if the lines contains to only one triangle
|
---|
| 1336 | * -# We search all points in the boundary
|
---|
| 1337 | * -# if the triangle is in forward direction of the baseline (at most 90 degrees angle between vector orthogonal to
|
---|
| 1338 | * baseline in triangle plane pointing out of the triangle and normal vector of new triangle)
|
---|
| 1339 | * -# if the triangle with the baseline and the current point has the smallest of angles (comparison between normal vectors)
|
---|
| 1340 | * -# then we have a new triangle, whose baselines we again add (or increase their TriangleCount)
|
---|
| 1341 | * \param *out output stream for debugging
|
---|
| 1342 | * \param *configuration for IsAngstroem
|
---|
| 1343 | * \param *cloud cluster of points
|
---|
| 1344 | */
|
---|
[e138de] | 1345 | void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
|
---|
[357fba] | 1346 | {
|
---|
[f67b6e] | 1347 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1348 | bool flag;
|
---|
| 1349 | PointMap::iterator winner;
|
---|
| 1350 | class BoundaryPointSet *peak = NULL;
|
---|
| 1351 | double SmallestAngle, TempAngle;
|
---|
| 1352 | Vector NormalVector, VirtualNormalVector, CenterVector, TempVector, helper, PropagationVector, *Center = NULL;
|
---|
| 1353 | LineMap::iterator LineChecker[2];
|
---|
| 1354 |
|
---|
[e138de] | 1355 | Center = cloud->GetCenter();
|
---|
[357fba] | 1356 | // create a first tesselation with the given BoundaryPoints
|
---|
| 1357 | do {
|
---|
| 1358 | flag = false;
|
---|
| 1359 | for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++)
|
---|
[5c7bf8] | 1360 | if (baseline->second->triangles.size() == 1) {
|
---|
[357fba] | 1361 | // 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)
|
---|
| 1362 | SmallestAngle = M_PI;
|
---|
| 1363 |
|
---|
| 1364 | // get peak point with respect to this base line's only triangle
|
---|
| 1365 | BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
|
---|
[f67b6e] | 1366 | Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl;
|
---|
[357fba] | 1367 | for (int i = 0; i < 3; i++)
|
---|
| 1368 | if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
|
---|
| 1369 | peak = BTS->endpoints[i];
|
---|
[f67b6e] | 1370 | Log() << Verbose(1) << " and has peak " << *peak << "." << endl;
|
---|
[357fba] | 1371 |
|
---|
| 1372 | // prepare some auxiliary vectors
|
---|
| 1373 | Vector BaseLineCenter, BaseLine;
|
---|
| 1374 | BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node);
|
---|
| 1375 | BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node);
|
---|
| 1376 | BaseLineCenter.Scale(1. / 2.); // points now to center of base line
|
---|
| 1377 | BaseLine.CopyVector(baseline->second->endpoints[0]->node->node);
|
---|
| 1378 | BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node);
|
---|
| 1379 |
|
---|
| 1380 | // offset to center of triangle
|
---|
| 1381 | CenterVector.Zero();
|
---|
| 1382 | for (int i = 0; i < 3; i++)
|
---|
| 1383 | CenterVector.AddVector(BTS->endpoints[i]->node->node);
|
---|
| 1384 | CenterVector.Scale(1. / 3.);
|
---|
[f67b6e] | 1385 | Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl;
|
---|
[357fba] | 1386 |
|
---|
| 1387 | // normal vector of triangle
|
---|
| 1388 | NormalVector.CopyVector(Center);
|
---|
| 1389 | NormalVector.SubtractVector(&CenterVector);
|
---|
| 1390 | BTS->GetNormalVector(NormalVector);
|
---|
| 1391 | NormalVector.CopyVector(&BTS->NormalVector);
|
---|
[f67b6e] | 1392 | Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl;
|
---|
[357fba] | 1393 |
|
---|
| 1394 | // vector in propagation direction (out of triangle)
|
---|
| 1395 | // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
|
---|
| 1396 | PropagationVector.MakeNormalVector(&BaseLine, &NormalVector);
|
---|
| 1397 | TempVector.CopyVector(&CenterVector);
|
---|
| 1398 | TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
|
---|
[f67b6e] | 1399 | //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
|
---|
[658efb] | 1400 | if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
|
---|
[357fba] | 1401 | PropagationVector.Scale(-1.);
|
---|
[f67b6e] | 1402 | Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl;
|
---|
[357fba] | 1403 | winner = PointsOnBoundary.end();
|
---|
| 1404 |
|
---|
| 1405 | // loop over all points and calculate angle between normal vector of new and present triangle
|
---|
| 1406 | for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
|
---|
| 1407 | if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
|
---|
[f67b6e] | 1408 | Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl;
|
---|
[357fba] | 1409 |
|
---|
| 1410 | // first check direction, so that triangles don't intersect
|
---|
| 1411 | VirtualNormalVector.CopyVector(target->second->node->node);
|
---|
| 1412 | VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target
|
---|
| 1413 | VirtualNormalVector.ProjectOntoPlane(&NormalVector);
|
---|
| 1414 | TempAngle = VirtualNormalVector.Angle(&PropagationVector);
|
---|
[f67b6e] | 1415 | Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
|
---|
[357fba] | 1416 | if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees)
|
---|
[f67b6e] | 1417 | Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
|
---|
[357fba] | 1418 | continue;
|
---|
| 1419 | } else
|
---|
[f67b6e] | 1420 | Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
|
---|
[357fba] | 1421 |
|
---|
| 1422 | // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
|
---|
| 1423 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(target->first);
|
---|
| 1424 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
|
---|
[5c7bf8] | 1425 | if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
|
---|
[f67b6e] | 1426 | 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] | 1427 | continue;
|
---|
| 1428 | }
|
---|
[5c7bf8] | 1429 | if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
|
---|
[f67b6e] | 1430 | 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] | 1431 | continue;
|
---|
| 1432 | }
|
---|
| 1433 |
|
---|
| 1434 | // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
|
---|
| 1435 | 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)))) {
|
---|
[e138de] | 1436 | Log() << Verbose(4) << "Current target is peak!" << endl;
|
---|
[357fba] | 1437 | continue;
|
---|
| 1438 | }
|
---|
| 1439 |
|
---|
| 1440 | // check for linear dependence
|
---|
| 1441 | TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
|
---|
| 1442 | TempVector.SubtractVector(target->second->node->node);
|
---|
| 1443 | helper.CopyVector(baseline->second->endpoints[1]->node->node);
|
---|
| 1444 | helper.SubtractVector(target->second->node->node);
|
---|
| 1445 | helper.ProjectOntoPlane(&TempVector);
|
---|
| 1446 | if (fabs(helper.NormSquared()) < MYEPSILON) {
|
---|
[f67b6e] | 1447 | Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl;
|
---|
[357fba] | 1448 | continue;
|
---|
| 1449 | }
|
---|
| 1450 |
|
---|
| 1451 | // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
|
---|
| 1452 | flag = true;
|
---|
| 1453 | VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node);
|
---|
| 1454 | TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
|
---|
| 1455 | TempVector.AddVector(baseline->second->endpoints[1]->node->node);
|
---|
| 1456 | TempVector.AddVector(target->second->node->node);
|
---|
| 1457 | TempVector.Scale(1./3.);
|
---|
| 1458 | TempVector.SubtractVector(Center);
|
---|
| 1459 | // make it always point outward
|
---|
[658efb] | 1460 | if (VirtualNormalVector.ScalarProduct(&TempVector) < 0)
|
---|
[357fba] | 1461 | VirtualNormalVector.Scale(-1.);
|
---|
| 1462 | // calculate angle
|
---|
| 1463 | TempAngle = NormalVector.Angle(&VirtualNormalVector);
|
---|
[f67b6e] | 1464 | Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
|
---|
[357fba] | 1465 | if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
|
---|
| 1466 | SmallestAngle = TempAngle;
|
---|
| 1467 | winner = target;
|
---|
[f67b6e] | 1468 | Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
|
---|
[357fba] | 1469 | } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
|
---|
| 1470 | // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
|
---|
| 1471 | helper.CopyVector(target->second->node->node);
|
---|
| 1472 | helper.SubtractVector(&BaseLineCenter);
|
---|
| 1473 | helper.ProjectOntoPlane(&BaseLine);
|
---|
| 1474 | // ...the one with the smaller angle is the better candidate
|
---|
| 1475 | TempVector.CopyVector(target->second->node->node);
|
---|
| 1476 | TempVector.SubtractVector(&BaseLineCenter);
|
---|
| 1477 | TempVector.ProjectOntoPlane(&VirtualNormalVector);
|
---|
| 1478 | TempAngle = TempVector.Angle(&helper);
|
---|
| 1479 | TempVector.CopyVector(winner->second->node->node);
|
---|
| 1480 | TempVector.SubtractVector(&BaseLineCenter);
|
---|
| 1481 | TempVector.ProjectOntoPlane(&VirtualNormalVector);
|
---|
| 1482 | if (TempAngle < TempVector.Angle(&helper)) {
|
---|
| 1483 | TempAngle = NormalVector.Angle(&VirtualNormalVector);
|
---|
| 1484 | SmallestAngle = TempAngle;
|
---|
| 1485 | winner = target;
|
---|
[f67b6e] | 1486 | Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
|
---|
[357fba] | 1487 | } else
|
---|
[f67b6e] | 1488 | Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
|
---|
[357fba] | 1489 | } else
|
---|
[f67b6e] | 1490 | Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
|
---|
[357fba] | 1491 | }
|
---|
| 1492 | } // end of loop over all boundary points
|
---|
| 1493 |
|
---|
| 1494 | // 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
|
---|
| 1495 | if (winner != PointsOnBoundary.end()) {
|
---|
[f67b6e] | 1496 | Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
|
---|
[357fba] | 1497 | // create the lins of not yet present
|
---|
| 1498 | BLS[0] = baseline->second;
|
---|
| 1499 | // 5c. add lines to the line set if those were new (not yet part of a triangle), delete lines that belong to two triangles)
|
---|
| 1500 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(winner->first);
|
---|
| 1501 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(winner->first);
|
---|
| 1502 | if (LineChecker[0] == baseline->second->endpoints[0]->lines.end()) { // create
|
---|
| 1503 | BPS[0] = baseline->second->endpoints[0];
|
---|
| 1504 | BPS[1] = winner->second;
|
---|
| 1505 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1506 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[1]));
|
---|
| 1507 | LinesOnBoundaryCount++;
|
---|
| 1508 | } else
|
---|
| 1509 | BLS[1] = LineChecker[0]->second;
|
---|
| 1510 | if (LineChecker[1] == baseline->second->endpoints[1]->lines.end()) { // create
|
---|
| 1511 | BPS[0] = baseline->second->endpoints[1];
|
---|
| 1512 | BPS[1] = winner->second;
|
---|
| 1513 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1514 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[2]));
|
---|
| 1515 | LinesOnBoundaryCount++;
|
---|
| 1516 | } else
|
---|
| 1517 | BLS[2] = LineChecker[1]->second;
|
---|
| 1518 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[62bb91] | 1519 | BTS->GetCenter(&helper);
|
---|
| 1520 | helper.SubtractVector(Center);
|
---|
| 1521 | helper.Scale(-1);
|
---|
| 1522 | BTS->GetNormalVector(helper);
|
---|
[357fba] | 1523 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1524 | TrianglesOnBoundaryCount++;
|
---|
| 1525 | } else {
|
---|
[f67b6e] | 1526 | eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
|
---|
[357fba] | 1527 | }
|
---|
| 1528 |
|
---|
| 1529 | // 5d. If the set of lines is not yet empty, go to 5. and continue
|
---|
| 1530 | } else
|
---|
[f67b6e] | 1531 | Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
|
---|
[357fba] | 1532 | } while (flag);
|
---|
| 1533 |
|
---|
| 1534 | // exit
|
---|
| 1535 | delete(Center);
|
---|
| 1536 | };
|
---|
| 1537 |
|
---|
[62bb91] | 1538 | /** Inserts all points outside of the tesselated surface into it by adding new triangles.
|
---|
[357fba] | 1539 | * \param *out output stream for debugging
|
---|
| 1540 | * \param *cloud cluster of points
|
---|
[62bb91] | 1541 | * \param *LC LinkedCell structure to find nearest point quickly
|
---|
[357fba] | 1542 | * \return true - all straddling points insert, false - something went wrong
|
---|
| 1543 | */
|
---|
[e138de] | 1544 | bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
|
---|
[357fba] | 1545 | {
|
---|
[f67b6e] | 1546 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1547 | Vector Intersection, Normal;
|
---|
[357fba] | 1548 | TesselPoint *Walker = NULL;
|
---|
[e138de] | 1549 | Vector *Center = cloud->GetCenter();
|
---|
[c15ca2] | 1550 | TriangleList *triangles = NULL;
|
---|
[7dea7c] | 1551 | bool AddFlag = false;
|
---|
| 1552 | LinkedCell *BoundaryPoints = NULL;
|
---|
[62bb91] | 1553 |
|
---|
[357fba] | 1554 | cloud->GoToFirst();
|
---|
[7dea7c] | 1555 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
[1999d8] | 1556 | while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
|
---|
[7dea7c] | 1557 | if (AddFlag) {
|
---|
| 1558 | delete(BoundaryPoints);
|
---|
| 1559 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
| 1560 | AddFlag = false;
|
---|
| 1561 | }
|
---|
[357fba] | 1562 | Walker = cloud->GetPoint();
|
---|
[f67b6e] | 1563 | Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;
|
---|
[357fba] | 1564 | // get the next triangle
|
---|
[c15ca2] | 1565 | triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
|
---|
[7dea7c] | 1566 | BTS = triangles->front();
|
---|
| 1567 | if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
|
---|
[f67b6e] | 1568 | Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl;
|
---|
[62bb91] | 1569 | cloud->GoToNext();
|
---|
| 1570 | continue;
|
---|
| 1571 | } else {
|
---|
[357fba] | 1572 | }
|
---|
[f67b6e] | 1573 | Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl;
|
---|
[357fba] | 1574 | // get the intersection point
|
---|
[e138de] | 1575 | if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
|
---|
[f67b6e] | 1576 | Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl;
|
---|
[357fba] | 1577 | // we have the intersection, check whether in- or outside of boundary
|
---|
| 1578 | if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
|
---|
| 1579 | // inside, next!
|
---|
[f67b6e] | 1580 | Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
|
---|
[357fba] | 1581 | } else {
|
---|
| 1582 | // outside!
|
---|
[f67b6e] | 1583 | Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
|
---|
[357fba] | 1584 | class BoundaryLineSet *OldLines[3], *NewLines[3];
|
---|
| 1585 | class BoundaryPointSet *OldPoints[3], *NewPoint;
|
---|
| 1586 | // store the three old lines and old points
|
---|
| 1587 | for (int i=0;i<3;i++) {
|
---|
| 1588 | OldLines[i] = BTS->lines[i];
|
---|
| 1589 | OldPoints[i] = BTS->endpoints[i];
|
---|
| 1590 | }
|
---|
[5c7bf8] | 1591 | Normal.CopyVector(&BTS->NormalVector);
|
---|
[357fba] | 1592 | // add Walker to boundary points
|
---|
[f67b6e] | 1593 | Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl;
|
---|
[7dea7c] | 1594 | AddFlag = true;
|
---|
[16d866] | 1595 | if (AddBoundaryPoint(Walker,0))
|
---|
[357fba] | 1596 | NewPoint = BPS[0];
|
---|
| 1597 | else
|
---|
| 1598 | continue;
|
---|
| 1599 | // remove triangle
|
---|
[f67b6e] | 1600 | Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl;
|
---|
[357fba] | 1601 | TrianglesOnBoundary.erase(BTS->Nr);
|
---|
[5c7bf8] | 1602 | delete(BTS);
|
---|
[357fba] | 1603 | // create three new boundary lines
|
---|
| 1604 | for (int i=0;i<3;i++) {
|
---|
| 1605 | BPS[0] = NewPoint;
|
---|
| 1606 | BPS[1] = OldPoints[i];
|
---|
| 1607 | NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
[f67b6e] | 1608 | Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl;
|
---|
[357fba] | 1609 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
|
---|
| 1610 | LinesOnBoundaryCount++;
|
---|
| 1611 | }
|
---|
| 1612 | // create three new triangle with new point
|
---|
| 1613 | for (int i=0;i<3;i++) { // find all baselines
|
---|
| 1614 | BLS[0] = OldLines[i];
|
---|
| 1615 | int n = 1;
|
---|
| 1616 | for (int j=0;j<3;j++) {
|
---|
| 1617 | if (NewLines[j]->IsConnectedTo(BLS[0])) {
|
---|
| 1618 | if (n>2) {
|
---|
[f67b6e] | 1619 | eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl;
|
---|
[357fba] | 1620 | return false;
|
---|
| 1621 | } else
|
---|
| 1622 | BLS[n++] = NewLines[j];
|
---|
| 1623 | }
|
---|
| 1624 | }
|
---|
| 1625 | // create the triangle
|
---|
| 1626 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[5c7bf8] | 1627 | Normal.Scale(-1.);
|
---|
| 1628 | BTS->GetNormalVector(Normal);
|
---|
| 1629 | Normal.Scale(-1.);
|
---|
[f67b6e] | 1630 | Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl;
|
---|
[357fba] | 1631 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1632 | TrianglesOnBoundaryCount++;
|
---|
| 1633 | }
|
---|
| 1634 | }
|
---|
| 1635 | } else { // something is wrong with FindClosestTriangleToPoint!
|
---|
[717e0c] | 1636 | eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl;
|
---|
[357fba] | 1637 | return false;
|
---|
| 1638 | }
|
---|
| 1639 | cloud->GoToNext();
|
---|
| 1640 | }
|
---|
| 1641 |
|
---|
| 1642 | // exit
|
---|
| 1643 | delete(Center);
|
---|
| 1644 | return true;
|
---|
| 1645 | };
|
---|
| 1646 |
|
---|
[16d866] | 1647 | /** Adds a point to the tesselation::PointsOnBoundary list.
|
---|
[62bb91] | 1648 | * \param *Walker point to add
|
---|
[08ef35] | 1649 | * \param n TesselStruct::BPS index to put pointer into
|
---|
| 1650 | * \return true - new point was added, false - point already present
|
---|
[357fba] | 1651 | */
|
---|
[776b64] | 1652 | bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
|
---|
[357fba] | 1653 | {
|
---|
[f67b6e] | 1654 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1655 | PointTestPair InsertUnique;
|
---|
[08ef35] | 1656 | BPS[n] = new class BoundaryPointSet(Walker);
|
---|
| 1657 | InsertUnique = PointsOnBoundary.insert(PointPair(Walker->nr, BPS[n]));
|
---|
| 1658 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
[357fba] | 1659 | PointsOnBoundaryCount++;
|
---|
[08ef35] | 1660 | return true;
|
---|
| 1661 | } else {
|
---|
| 1662 | delete(BPS[n]);
|
---|
| 1663 | BPS[n] = InsertUnique.first->second;
|
---|
| 1664 | return false;
|
---|
[357fba] | 1665 | }
|
---|
| 1666 | }
|
---|
| 1667 | ;
|
---|
| 1668 |
|
---|
| 1669 | /** Adds point to Tesselation::PointsOnBoundary if not yet present.
|
---|
| 1670 | * Tesselation::TPS is set to either this new BoundaryPointSet or to the existing one of not unique.
|
---|
| 1671 | * @param Candidate point to add
|
---|
| 1672 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1673 | */
|
---|
[776b64] | 1674 | void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
|
---|
[357fba] | 1675 | {
|
---|
[f67b6e] | 1676 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1677 | PointTestPair InsertUnique;
|
---|
| 1678 | TPS[n] = new class BoundaryPointSet(Candidate);
|
---|
| 1679 | InsertUnique = PointsOnBoundary.insert(PointPair(Candidate->nr, TPS[n]));
|
---|
| 1680 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
| 1681 | PointsOnBoundaryCount++;
|
---|
| 1682 | } else {
|
---|
| 1683 | delete TPS[n];
|
---|
[f67b6e] | 1684 | Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
|
---|
[357fba] | 1685 | TPS[n] = (InsertUnique.first)->second;
|
---|
| 1686 | }
|
---|
| 1687 | }
|
---|
| 1688 | ;
|
---|
| 1689 |
|
---|
[f1ef60a] | 1690 | /** Sets point to a present Tesselation::PointsOnBoundary.
|
---|
| 1691 | * Tesselation::TPS is set to the existing one or NULL if not found.
|
---|
| 1692 | * @param Candidate point to set to
|
---|
| 1693 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1694 | */
|
---|
| 1695 | void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
|
---|
| 1696 | {
|
---|
[f67b6e] | 1697 | Info FunctionInfo(__func__);
|
---|
[f1ef60a] | 1698 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
|
---|
| 1699 | if (FindPoint != PointsOnBoundary.end())
|
---|
| 1700 | TPS[n] = FindPoint->second;
|
---|
| 1701 | else
|
---|
| 1702 | TPS[n] = NULL;
|
---|
| 1703 | };
|
---|
| 1704 |
|
---|
[357fba] | 1705 | /** Function tries to add line from current Points in BPS to BoundaryLineSet.
|
---|
| 1706 | * If successful it raises the line count and inserts the new line into the BLS,
|
---|
| 1707 | * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
|
---|
| 1708 | * @param *a first endpoint
|
---|
| 1709 | * @param *b second endpoint
|
---|
| 1710 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1711 | */
|
---|
[776b64] | 1712 | void Tesselation::AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) {
|
---|
[357fba] | 1713 | bool insertNewLine = true;
|
---|
| 1714 |
|
---|
[b998c3] | 1715 | LineMap::iterator FindLine = a->lines.find(b->node->nr);
|
---|
| 1716 | if (FindLine != a->lines.end()) {
|
---|
| 1717 | Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
|
---|
| 1718 |
|
---|
[357fba] | 1719 | pair<LineMap::iterator,LineMap::iterator> FindPair;
|
---|
| 1720 | FindPair = a->lines.equal_range(b->node->nr);
|
---|
| 1721 |
|
---|
[065e82] | 1722 | for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
|
---|
[357fba] | 1723 | // If there is a line with less than two attached triangles, we don't need a new line.
|
---|
[5c7bf8] | 1724 | if (FindLine->second->triangles.size() < 2) {
|
---|
[357fba] | 1725 | insertNewLine = false;
|
---|
[f67b6e] | 1726 | Log() << Verbose(0) << "Using existing line " << *FindLine->second << endl;
|
---|
[357fba] | 1727 |
|
---|
| 1728 | BPS[0] = FindLine->second->endpoints[0];
|
---|
| 1729 | BPS[1] = FindLine->second->endpoints[1];
|
---|
| 1730 | BLS[n] = FindLine->second;
|
---|
| 1731 |
|
---|
[1e168b] | 1732 | // remove existing line from OpenLines
|
---|
| 1733 | CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
|
---|
[856098] | 1734 | if (CandidateLine != OpenLines.end()) {
|
---|
| 1735 | Log() << Verbose(1) << " Removing line from OpenLines." << endl;
|
---|
| 1736 | delete(CandidateLine->second);
|
---|
| 1737 | OpenLines.erase(CandidateLine);
|
---|
| 1738 | } else {
|
---|
| 1739 | eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl;
|
---|
| 1740 | }
|
---|
[1e168b] | 1741 |
|
---|
[357fba] | 1742 | break;
|
---|
| 1743 | }
|
---|
| 1744 | }
|
---|
| 1745 | }
|
---|
| 1746 |
|
---|
| 1747 | if (insertNewLine) {
|
---|
[16d866] | 1748 | AlwaysAddTesselationTriangleLine(a, b, n);
|
---|
[357fba] | 1749 | }
|
---|
| 1750 | }
|
---|
| 1751 | ;
|
---|
| 1752 |
|
---|
| 1753 | /**
|
---|
| 1754 | * Adds lines from each of the current points in the BPS to BoundaryLineSet.
|
---|
| 1755 | * Raises the line count and inserts the new line into the BLS.
|
---|
| 1756 | *
|
---|
| 1757 | * @param *a first endpoint
|
---|
| 1758 | * @param *b second endpoint
|
---|
| 1759 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1760 | */
|
---|
[776b64] | 1761 | void Tesselation::AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
|
---|
[357fba] | 1762 | {
|
---|
[f67b6e] | 1763 | Info FunctionInfo(__func__);
|
---|
| 1764 | Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
|
---|
[357fba] | 1765 | BPS[0] = a;
|
---|
| 1766 | BPS[1] = b;
|
---|
| 1767 | BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
|
---|
| 1768 | // add line to global map
|
---|
| 1769 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
|
---|
| 1770 | // increase counter
|
---|
| 1771 | LinesOnBoundaryCount++;
|
---|
[1e168b] | 1772 | // also add to open lines
|
---|
| 1773 | CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
|
---|
| 1774 | OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
|
---|
[357fba] | 1775 | };
|
---|
| 1776 |
|
---|
[7dea7c] | 1777 | /** Function adds triangle to global list.
|
---|
| 1778 | * Furthermore, the triangle receives the next free id and id counter \a TrianglesOnBoundaryCount is increased.
|
---|
[357fba] | 1779 | */
|
---|
[16d866] | 1780 | void Tesselation::AddTesselationTriangle()
|
---|
[357fba] | 1781 | {
|
---|
[f67b6e] | 1782 | Info FunctionInfo(__func__);
|
---|
[e138de] | 1783 | Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
|
---|
[357fba] | 1784 |
|
---|
| 1785 | // add triangle to global map
|
---|
| 1786 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1787 | TrianglesOnBoundaryCount++;
|
---|
| 1788 |
|
---|
[57066a] | 1789 | // set as last new triangle
|
---|
| 1790 | LastTriangle = BTS;
|
---|
| 1791 |
|
---|
[357fba] | 1792 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
[16d866] | 1793 | };
|
---|
| 1794 |
|
---|
[7dea7c] | 1795 | /** Function adds triangle to global list.
|
---|
| 1796 | * Furthermore, the triangle number is set to \a nr.
|
---|
| 1797 | * \param nr triangle number
|
---|
| 1798 | */
|
---|
[776b64] | 1799 | void Tesselation::AddTesselationTriangle(const int nr)
|
---|
[7dea7c] | 1800 | {
|
---|
[f67b6e] | 1801 | Info FunctionInfo(__func__);
|
---|
| 1802 | Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl;
|
---|
[7dea7c] | 1803 |
|
---|
| 1804 | // add triangle to global map
|
---|
| 1805 | TrianglesOnBoundary.insert(TrianglePair(nr, BTS));
|
---|
| 1806 |
|
---|
| 1807 | // set as last new triangle
|
---|
| 1808 | LastTriangle = BTS;
|
---|
| 1809 |
|
---|
| 1810 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
| 1811 | };
|
---|
| 1812 |
|
---|
[16d866] | 1813 | /** Removes a triangle from the tesselation.
|
---|
| 1814 | * Removes itself from the TriangleMap's of its lines, calls for them RemoveTriangleLine() if they are no more connected.
|
---|
| 1815 | * Removes itself from memory.
|
---|
| 1816 | * \param *triangle to remove
|
---|
| 1817 | */
|
---|
| 1818 | void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
|
---|
| 1819 | {
|
---|
[f67b6e] | 1820 | Info FunctionInfo(__func__);
|
---|
[16d866] | 1821 | if (triangle == NULL)
|
---|
| 1822 | return;
|
---|
| 1823 | for (int i = 0; i < 3; i++) {
|
---|
| 1824 | if (triangle->lines[i] != NULL) {
|
---|
[f67b6e] | 1825 | Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
|
---|
[16d866] | 1826 | triangle->lines[i]->triangles.erase(triangle->Nr);
|
---|
| 1827 | if (triangle->lines[i]->triangles.empty()) {
|
---|
[f67b6e] | 1828 | Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
|
---|
[16d866] | 1829 | RemoveTesselationLine(triangle->lines[i]);
|
---|
[065e82] | 1830 | } else {
|
---|
[f67b6e] | 1831 | Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ";
|
---|
[856098] | 1832 | OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
|
---|
[065e82] | 1833 | for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
|
---|
[e138de] | 1834 | Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
|
---|
| 1835 | Log() << Verbose(0) << endl;
|
---|
[065e82] | 1836 | // for (int j=0;j<2;j++) {
|
---|
[f67b6e] | 1837 | // Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
|
---|
[065e82] | 1838 | // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
|
---|
[e138de] | 1839 | // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
|
---|
| 1840 | // Log() << Verbose(0) << endl;
|
---|
[065e82] | 1841 | // }
|
---|
| 1842 | }
|
---|
| 1843 | triangle->lines[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 1844 | } else
|
---|
[717e0c] | 1845 | eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl;
|
---|
[16d866] | 1846 | }
|
---|
| 1847 |
|
---|
| 1848 | if (TrianglesOnBoundary.erase(triangle->Nr))
|
---|
[f67b6e] | 1849 | Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
|
---|
[16d866] | 1850 | delete(triangle);
|
---|
| 1851 | };
|
---|
| 1852 |
|
---|
| 1853 | /** Removes a line from the tesselation.
|
---|
| 1854 | * Removes itself from each endpoints' LineMap, then removes itself from global LinesOnBoundary list and free's the line.
|
---|
| 1855 | * \param *line line to remove
|
---|
| 1856 | */
|
---|
| 1857 | void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
|
---|
| 1858 | {
|
---|
[f67b6e] | 1859 | Info FunctionInfo(__func__);
|
---|
[16d866] | 1860 | int Numbers[2];
|
---|
| 1861 |
|
---|
| 1862 | if (line == NULL)
|
---|
| 1863 | return;
|
---|
[065e82] | 1864 | // get other endpoint number for finding copies of same line
|
---|
[16d866] | 1865 | if (line->endpoints[1] != NULL)
|
---|
| 1866 | Numbers[0] = line->endpoints[1]->Nr;
|
---|
| 1867 | else
|
---|
| 1868 | Numbers[0] = -1;
|
---|
| 1869 | if (line->endpoints[0] != NULL)
|
---|
| 1870 | Numbers[1] = line->endpoints[0]->Nr;
|
---|
| 1871 | else
|
---|
| 1872 | Numbers[1] = -1;
|
---|
| 1873 |
|
---|
| 1874 | for (int i = 0; i < 2; i++) {
|
---|
| 1875 | if (line->endpoints[i] != NULL) {
|
---|
| 1876 | 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
|
---|
| 1877 | pair<LineMap::iterator, LineMap::iterator> erasor = line->endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 1878 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 1879 | if ((*Runner).second == line) {
|
---|
[f67b6e] | 1880 | Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
|
---|
[16d866] | 1881 | line->endpoints[i]->lines.erase(Runner);
|
---|
| 1882 | break;
|
---|
| 1883 | }
|
---|
| 1884 | } else { // there's just a single line left
|
---|
| 1885 | if (line->endpoints[i]->lines.erase(line->Nr))
|
---|
[f67b6e] | 1886 | Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
|
---|
[16d866] | 1887 | }
|
---|
| 1888 | if (line->endpoints[i]->lines.empty()) {
|
---|
[f67b6e] | 1889 | Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
|
---|
[16d866] | 1890 | RemoveTesselationPoint(line->endpoints[i]);
|
---|
[065e82] | 1891 | } else {
|
---|
[f67b6e] | 1892 | Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ";
|
---|
[065e82] | 1893 | for(LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
|
---|
[e138de] | 1894 | Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
|
---|
| 1895 | Log() << Verbose(0) << endl;
|
---|
[065e82] | 1896 | }
|
---|
| 1897 | line->endpoints[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 1898 | } else
|
---|
[717e0c] | 1899 | eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl;
|
---|
[16d866] | 1900 | }
|
---|
| 1901 | if (!line->triangles.empty())
|
---|
[717e0c] | 1902 | eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl;
|
---|
[16d866] | 1903 |
|
---|
| 1904 | if (LinesOnBoundary.erase(line->Nr))
|
---|
[f67b6e] | 1905 | Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl;
|
---|
[16d866] | 1906 | delete(line);
|
---|
| 1907 | };
|
---|
| 1908 |
|
---|
| 1909 | /** Removes a point from the tesselation.
|
---|
| 1910 | * Checks whether there are still lines connected, removes from global PointsOnBoundary list, then free's the point.
|
---|
| 1911 | * \note If a point should be removed, while keep the tesselated surface intact (i.e. closed), use RemovePointFromTesselatedSurface()
|
---|
| 1912 | * \param *point point to remove
|
---|
| 1913 | */
|
---|
| 1914 | void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
|
---|
| 1915 | {
|
---|
[f67b6e] | 1916 | Info FunctionInfo(__func__);
|
---|
[16d866] | 1917 | if (point == NULL)
|
---|
| 1918 | return;
|
---|
| 1919 | if (PointsOnBoundary.erase(point->Nr))
|
---|
[f67b6e] | 1920 | Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl;
|
---|
[16d866] | 1921 | delete(point);
|
---|
| 1922 | };
|
---|
[357fba] | 1923 |
|
---|
[62bb91] | 1924 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
[357fba] | 1925 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 1926 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 1927 | * returned.
|
---|
| 1928 | * \param *out output stream for debugging
|
---|
| 1929 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 1930 | * \return integer 0 if no triangle exists, 1 if one triangle exists, 2 if two
|
---|
| 1931 | * triangles exist which is the maximum for three points
|
---|
| 1932 | */
|
---|
[f1ef60a] | 1933 | int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
|
---|
| 1934 | {
|
---|
[f67b6e] | 1935 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1936 | int adjacentTriangleCount = 0;
|
---|
| 1937 | class BoundaryPointSet *Points[3];
|
---|
| 1938 |
|
---|
| 1939 | // builds a triangle point set (Points) of the end points
|
---|
| 1940 | for (int i = 0; i < 3; i++) {
|
---|
[f1ef60a] | 1941 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
[357fba] | 1942 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 1943 | Points[i] = FindPoint->second;
|
---|
| 1944 | } else {
|
---|
| 1945 | Points[i] = NULL;
|
---|
| 1946 | }
|
---|
| 1947 | }
|
---|
| 1948 |
|
---|
| 1949 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 1950 | for (int i = 0; i < 3; i++) {
|
---|
| 1951 | if (Points[i] != NULL) {
|
---|
| 1952 | for (int j = i; j < 3; j++) {
|
---|
| 1953 | if (Points[j] != NULL) {
|
---|
[f1ef60a] | 1954 | LineMap::const_iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
[357fba] | 1955 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 1956 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
[f67b6e] | 1957 | Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
|
---|
[f1ef60a] | 1958 | for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
[357fba] | 1959 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 1960 | adjacentTriangleCount++;
|
---|
| 1961 | }
|
---|
| 1962 | }
|
---|
[f67b6e] | 1963 | Log() << Verbose(1) << "end." << endl;
|
---|
[357fba] | 1964 | }
|
---|
| 1965 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[f67b6e] | 1966 | //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 1967 | //return adjacentTriangleCount;
|
---|
[357fba] | 1968 | }
|
---|
| 1969 | }
|
---|
| 1970 | }
|
---|
| 1971 | }
|
---|
| 1972 |
|
---|
[f67b6e] | 1973 | Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[357fba] | 1974 | return adjacentTriangleCount;
|
---|
| 1975 | };
|
---|
| 1976 |
|
---|
[065e82] | 1977 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
| 1978 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 1979 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 1980 | * returned.
|
---|
| 1981 | * \param *out output stream for debugging
|
---|
| 1982 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 1983 | * \return NULL - none found or pointer to triangle
|
---|
| 1984 | */
|
---|
[e138de] | 1985 | class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
|
---|
[065e82] | 1986 | {
|
---|
[f67b6e] | 1987 | Info FunctionInfo(__func__);
|
---|
[065e82] | 1988 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 1989 | class BoundaryPointSet *Points[3];
|
---|
| 1990 |
|
---|
| 1991 | // builds a triangle point set (Points) of the end points
|
---|
| 1992 | for (int i = 0; i < 3; i++) {
|
---|
| 1993 | PointMap::iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
| 1994 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 1995 | Points[i] = FindPoint->second;
|
---|
| 1996 | } else {
|
---|
| 1997 | Points[i] = NULL;
|
---|
| 1998 | }
|
---|
| 1999 | }
|
---|
| 2000 |
|
---|
| 2001 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 2002 | for (int i = 0; i < 3; i++) {
|
---|
| 2003 | if (Points[i] != NULL) {
|
---|
| 2004 | for (int j = i; j < 3; j++) {
|
---|
| 2005 | if (Points[j] != NULL) {
|
---|
| 2006 | LineMap::iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
| 2007 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 2008 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
| 2009 | for (TriangleMap::iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
| 2010 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 2011 | if ((triangle == NULL) || (triangle->Nr > FindTriangle->second->Nr))
|
---|
| 2012 | triangle = FindTriangle->second;
|
---|
| 2013 | }
|
---|
| 2014 | }
|
---|
| 2015 | }
|
---|
| 2016 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[f67b6e] | 2017 | //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 2018 | //return adjacentTriangleCount;
|
---|
| 2019 | }
|
---|
| 2020 | }
|
---|
| 2021 | }
|
---|
| 2022 | }
|
---|
| 2023 |
|
---|
| 2024 | return triangle;
|
---|
| 2025 | };
|
---|
| 2026 |
|
---|
[357fba] | 2027 |
|
---|
[f1cccd] | 2028 | /** Finds the starting triangle for FindNonConvexBorder().
|
---|
| 2029 | * Looks at the outermost point per axis, then FindSecondPointForTesselation()
|
---|
| 2030 | * for the second and FindNextSuitablePointViaAngleOfSphere() for the third
|
---|
[357fba] | 2031 | * point are called.
|
---|
| 2032 | * \param *out output stream for debugging
|
---|
| 2033 | * \param RADIUS radius of virtual rolling sphere
|
---|
| 2034 | * \param *LC LinkedCell structure with neighbouring TesselPoint's
|
---|
| 2035 | */
|
---|
[e138de] | 2036 | void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2037 | {
|
---|
[f67b6e] | 2038 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2039 | int i = 0;
|
---|
[62bb91] | 2040 | TesselPoint* MaxPoint[NDIM];
|
---|
[7273fc] | 2041 | TesselPoint* Temporary;
|
---|
[f1cccd] | 2042 | double maxCoordinate[NDIM];
|
---|
[7273fc] | 2043 | BoundaryLineSet BaseLine;
|
---|
[357fba] | 2044 | Vector helper;
|
---|
| 2045 | Vector Chord;
|
---|
| 2046 | Vector SearchDirection;
|
---|
[b998c3] | 2047 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
| 2048 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 2049 | Vector SphereCenter;
|
---|
| 2050 | Vector NormalVector;
|
---|
[357fba] | 2051 |
|
---|
[b998c3] | 2052 | NormalVector.Zero();
|
---|
[357fba] | 2053 |
|
---|
| 2054 | for (i = 0; i < 3; i++) {
|
---|
[62bb91] | 2055 | MaxPoint[i] = NULL;
|
---|
[f1cccd] | 2056 | maxCoordinate[i] = -1;
|
---|
[357fba] | 2057 | }
|
---|
| 2058 |
|
---|
[62bb91] | 2059 | // 1. searching topmost point with respect to each axis
|
---|
[357fba] | 2060 | for (int i=0;i<NDIM;i++) { // each axis
|
---|
| 2061 | LC->n[i] = LC->N[i]-1; // current axis is topmost cell
|
---|
| 2062 | for (LC->n[(i+1)%NDIM]=0;LC->n[(i+1)%NDIM]<LC->N[(i+1)%NDIM];LC->n[(i+1)%NDIM]++)
|
---|
| 2063 | for (LC->n[(i+2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {
|
---|
[776b64] | 2064 | const LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 2065 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2066 | if (List != NULL) {
|
---|
[776b64] | 2067 | for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
|
---|
[f1cccd] | 2068 | if ((*Runner)->node->x[i] > maxCoordinate[i]) {
|
---|
[f67b6e] | 2069 | Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
|
---|
[f1cccd] | 2070 | maxCoordinate[i] = (*Runner)->node->x[i];
|
---|
[62bb91] | 2071 | MaxPoint[i] = (*Runner);
|
---|
[357fba] | 2072 | }
|
---|
| 2073 | }
|
---|
| 2074 | } else {
|
---|
[717e0c] | 2075 | eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
|
---|
[357fba] | 2076 | }
|
---|
| 2077 | }
|
---|
| 2078 | }
|
---|
| 2079 |
|
---|
[f67b6e] | 2080 | Log() << Verbose(1) << "Found maximum coordinates: ";
|
---|
[357fba] | 2081 | for (int i=0;i<NDIM;i++)
|
---|
[e138de] | 2082 | Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t";
|
---|
| 2083 | Log() << Verbose(0) << endl;
|
---|
[357fba] | 2084 |
|
---|
| 2085 | BTS = NULL;
|
---|
| 2086 | for (int k=0;k<NDIM;k++) {
|
---|
[b998c3] | 2087 | NormalVector.Zero();
|
---|
| 2088 | NormalVector.x[k] = 1.;
|
---|
[7273fc] | 2089 | BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
|
---|
| 2090 | Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
|
---|
[357fba] | 2091 |
|
---|
| 2092 | double ShortestAngle;
|
---|
| 2093 | 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.
|
---|
| 2094 |
|
---|
[b998c3] | 2095 | 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_...
|
---|
[7273fc] | 2096 | if (Temporary == NULL) // have we found a second point?
|
---|
[357fba] | 2097 | continue;
|
---|
[7273fc] | 2098 | BaseLine.endpoints[1] = new BoundaryPointSet(Temporary);
|
---|
[357fba] | 2099 |
|
---|
[b998c3] | 2100 | // construct center of circle
|
---|
| 2101 | CircleCenter.CopyVector(BaseLine.endpoints[0]->node->node);
|
---|
| 2102 | CircleCenter.AddVector(BaseLine.endpoints[1]->node->node);
|
---|
| 2103 | CircleCenter.Scale(0.5);
|
---|
| 2104 |
|
---|
| 2105 | // construct normal vector of circle
|
---|
| 2106 | CirclePlaneNormal.CopyVector(BaseLine.endpoints[0]->node->node);
|
---|
| 2107 | CirclePlaneNormal.SubtractVector(BaseLine.endpoints[1]->node->node);
|
---|
[357fba] | 2108 |
|
---|
[b998c3] | 2109 | double radius = CirclePlaneNormal.NormSquared();
|
---|
[357fba] | 2110 | double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
|
---|
[b998c3] | 2111 |
|
---|
| 2112 | NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
|
---|
| 2113 | NormalVector.Normalize();
|
---|
| 2114 | ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
|
---|
| 2115 |
|
---|
| 2116 | SphereCenter.CopyVector(&NormalVector);
|
---|
| 2117 | SphereCenter.Scale(CircleRadius);
|
---|
| 2118 | SphereCenter.AddVector(&CircleCenter);
|
---|
| 2119 | // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
|
---|
[357fba] | 2120 |
|
---|
| 2121 | // look in one direction of baseline for initial candidate
|
---|
[b998c3] | 2122 | SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ...
|
---|
[357fba] | 2123 |
|
---|
[5c7bf8] | 2124 | // adding point 1 and point 2 and add the line between them
|
---|
[7273fc] | 2125 | Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
|
---|
| 2126 | Log() << Verbose(0) << "Found second point is at " << *BaseLine.endpoints[1]->node << ".\n";
|
---|
[357fba] | 2127 |
|
---|
[f67b6e] | 2128 | //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
|
---|
[7273fc] | 2129 | CandidateForTesselation OptCandidates(&BaseLine);
|
---|
[b998c3] | 2130 | FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
|
---|
[f67b6e] | 2131 | Log() << Verbose(0) << "List of third Points is:" << endl;
|
---|
| 2132 | for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
|
---|
| 2133 | Log() << Verbose(0) << " " << *(*it) << endl;
|
---|
[357fba] | 2134 | }
|
---|
| 2135 |
|
---|
[7273fc] | 2136 | BTS = NULL;
|
---|
| 2137 | AddCandidateTriangle(OptCandidates);
|
---|
| 2138 | // delete(BaseLine.endpoints[0]);
|
---|
| 2139 | // delete(BaseLine.endpoints[1]);
|
---|
| 2140 |
|
---|
[357fba] | 2141 | if (BTS != NULL) // we have created one starting triangle
|
---|
| 2142 | break;
|
---|
| 2143 | else {
|
---|
| 2144 | // remove all candidates from the list and then the list itself
|
---|
[7273fc] | 2145 | OptCandidates.pointlist.clear();
|
---|
[357fba] | 2146 | }
|
---|
| 2147 | }
|
---|
| 2148 | };
|
---|
| 2149 |
|
---|
[f1ef60a] | 2150 | /** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
|
---|
| 2151 | * This is supposed to prevent early closing of the tesselation.
|
---|
[f67b6e] | 2152 | * \param CandidateLine CandidateForTesselation with baseline and shortestangle , i.e. not \a *OptCandidate
|
---|
[f1ef60a] | 2153 | * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
|
---|
| 2154 | * \param RADIUS radius of sphere
|
---|
| 2155 | * \param *LC LinkedCell structure
|
---|
| 2156 | * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
|
---|
| 2157 | */
|
---|
[f67b6e] | 2158 | //bool Tesselation::HasOtherBaselineBetterCandidate(CandidateForTesselation &CandidateLine, const TesselPoint * const ThirdNode, double RADIUS, const LinkedCell * const LC) const
|
---|
| 2159 | //{
|
---|
| 2160 | // Info FunctionInfo(__func__);
|
---|
| 2161 | // bool result = false;
|
---|
| 2162 | // Vector CircleCenter;
|
---|
| 2163 | // Vector CirclePlaneNormal;
|
---|
| 2164 | // Vector OldSphereCenter;
|
---|
| 2165 | // Vector SearchDirection;
|
---|
| 2166 | // Vector helper;
|
---|
| 2167 | // TesselPoint *OtherOptCandidate = NULL;
|
---|
| 2168 | // double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
|
---|
| 2169 | // double radius, CircleRadius;
|
---|
| 2170 | // BoundaryLineSet *Line = NULL;
|
---|
| 2171 | // BoundaryTriangleSet *T = NULL;
|
---|
| 2172 | //
|
---|
| 2173 | // // check both other lines
|
---|
| 2174 | // PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
|
---|
| 2175 | // if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2176 | // for (int i=0;i<2;i++) {
|
---|
| 2177 | // LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
|
---|
| 2178 | // if (FindLine != (FindPoint->second)->lines.end()) {
|
---|
| 2179 | // Line = FindLine->second;
|
---|
| 2180 | // Log() << Verbose(0) << "Found line " << *Line << "." << endl;
|
---|
| 2181 | // if (Line->triangles.size() == 1) {
|
---|
| 2182 | // T = Line->triangles.begin()->second;
|
---|
| 2183 | // // construct center of circle
|
---|
| 2184 | // CircleCenter.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2185 | // CircleCenter.AddVector(Line->endpoints[1]->node->node);
|
---|
| 2186 | // CircleCenter.Scale(0.5);
|
---|
| 2187 | //
|
---|
| 2188 | // // construct normal vector of circle
|
---|
| 2189 | // CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2190 | // CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
|
---|
| 2191 | //
|
---|
| 2192 | // // calculate squared radius of circle
|
---|
| 2193 | // radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
|
---|
| 2194 | // if (radius/4. < RADIUS*RADIUS) {
|
---|
| 2195 | // CircleRadius = RADIUS*RADIUS - radius/4.;
|
---|
| 2196 | // CirclePlaneNormal.Normalize();
|
---|
| 2197 | // //Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
| 2198 | //
|
---|
| 2199 | // // construct old center
|
---|
| 2200 | // GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
|
---|
| 2201 | // helper.CopyVector(&T->NormalVector); // normal vector ensures that this is correct center of the two possible ones
|
---|
| 2202 | // radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
|
---|
| 2203 | // helper.Scale(sqrt(RADIUS*RADIUS - radius));
|
---|
| 2204 | // OldSphereCenter.AddVector(&helper);
|
---|
| 2205 | // OldSphereCenter.SubtractVector(&CircleCenter);
|
---|
| 2206 | // //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
|
---|
| 2207 | //
|
---|
| 2208 | // // construct SearchDirection
|
---|
| 2209 | // SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
|
---|
| 2210 | // helper.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2211 | // helper.SubtractVector(ThirdNode->node);
|
---|
| 2212 | // if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
| 2213 | // SearchDirection.Scale(-1.);
|
---|
| 2214 | // SearchDirection.ProjectOntoPlane(&OldSphereCenter);
|
---|
| 2215 | // SearchDirection.Normalize();
|
---|
| 2216 | // Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
| 2217 | // if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
|
---|
| 2218 | // // rotated the wrong way!
|
---|
| 2219 | // eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
|
---|
| 2220 | // }
|
---|
| 2221 | //
|
---|
| 2222 | // // add third point
|
---|
| 2223 | // FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, OptCandidates, ThirdNode, RADIUS, LC);
|
---|
| 2224 | // for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); ++it) {
|
---|
| 2225 | // if (((*it) == BaseRay->endpoints[0]->node) || ((*it) == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
|
---|
| 2226 | // continue;
|
---|
| 2227 | // Log() << Verbose(0) << " Third point candidate is " << (*it)
|
---|
| 2228 | // << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
|
---|
| 2229 | // Log() << Verbose(0) << " Baseline is " << *BaseRay << endl;
|
---|
| 2230 | //
|
---|
| 2231 | // // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
|
---|
| 2232 | // TesselPoint *PointCandidates[3];
|
---|
| 2233 | // PointCandidates[0] = (*it);
|
---|
| 2234 | // PointCandidates[1] = BaseRay->endpoints[0]->node;
|
---|
| 2235 | // PointCandidates[2] = BaseRay->endpoints[1]->node;
|
---|
| 2236 | // bool check=false;
|
---|
| 2237 | // int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
|
---|
| 2238 | // // If there is no triangle, add it regularly.
|
---|
| 2239 | // if (existentTrianglesCount == 0) {
|
---|
| 2240 | // SetTesselationPoint((*it), 0);
|
---|
| 2241 | // SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2242 | // SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2243 | //
|
---|
| 2244 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
|
---|
| 2245 | // OtherOptCandidate = (*it);
|
---|
| 2246 | // check = true;
|
---|
| 2247 | // }
|
---|
| 2248 | // } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
|
---|
| 2249 | // SetTesselationPoint((*it), 0);
|
---|
| 2250 | // SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2251 | // SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2252 | //
|
---|
| 2253 | // // 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)
|
---|
| 2254 | // // i.e. at least one of the three lines must be present with TriangleCount <= 1
|
---|
| 2255 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
|
---|
| 2256 | // OtherOptCandidate = (*it);
|
---|
| 2257 | // check = true;
|
---|
| 2258 | // }
|
---|
| 2259 | // }
|
---|
| 2260 | //
|
---|
| 2261 | // if (check) {
|
---|
| 2262 | // if (ShortestAngle > OtherShortestAngle) {
|
---|
| 2263 | // Log() << Verbose(0) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
|
---|
| 2264 | // result = true;
|
---|
| 2265 | // break;
|
---|
| 2266 | // }
|
---|
| 2267 | // }
|
---|
| 2268 | // }
|
---|
| 2269 | // delete(OptCandidates);
|
---|
| 2270 | // if (result)
|
---|
| 2271 | // break;
|
---|
| 2272 | // } else {
|
---|
| 2273 | // Log() << Verbose(0) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
|
---|
| 2274 | // }
|
---|
| 2275 | // } else {
|
---|
| 2276 | // eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;
|
---|
| 2277 | // }
|
---|
| 2278 | // } else {
|
---|
| 2279 | // Log() << Verbose(1) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
|
---|
| 2280 | // }
|
---|
| 2281 | // }
|
---|
| 2282 | // } else {
|
---|
| 2283 | // eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;
|
---|
| 2284 | // }
|
---|
| 2285 | //
|
---|
| 2286 | // return result;
|
---|
| 2287 | //};
|
---|
[357fba] | 2288 |
|
---|
| 2289 | /** This function finds a triangle to a line, adjacent to an existing one.
|
---|
| 2290 | * @param out output stream for debugging
|
---|
[1e168b] | 2291 | * @param CandidateLine current cadndiate baseline to search from
|
---|
[357fba] | 2292 | * @param T current triangle which \a Line is edge of
|
---|
| 2293 | * @param RADIUS radius of the rolling ball
|
---|
| 2294 | * @param N number of found triangles
|
---|
[62bb91] | 2295 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 2296 | */
|
---|
[1e168b] | 2297 | bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2298 | {
|
---|
[f67b6e] | 2299 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2300 | bool result = true;
|
---|
| 2301 |
|
---|
| 2302 | Vector CircleCenter;
|
---|
| 2303 | Vector CirclePlaneNormal;
|
---|
[b998c3] | 2304 | Vector RelativeSphereCenter;
|
---|
[357fba] | 2305 | Vector SearchDirection;
|
---|
| 2306 | Vector helper;
|
---|
| 2307 | TesselPoint *ThirdNode = NULL;
|
---|
| 2308 | LineMap::iterator testline;
|
---|
| 2309 | double radius, CircleRadius;
|
---|
| 2310 |
|
---|
| 2311 | for (int i=0;i<3;i++)
|
---|
[b998c3] | 2312 | if ((T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[0]->node) && (T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[1]->node)) {
|
---|
[357fba] | 2313 | ThirdNode = T.endpoints[i]->node;
|
---|
[b998c3] | 2314 | break;
|
---|
| 2315 | }
|
---|
| 2316 | Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdNode " << *ThirdNode << " of triangle " << T << "." << endl;
|
---|
[357fba] | 2317 |
|
---|
| 2318 | // construct center of circle
|
---|
[1e168b] | 2319 | CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
|
---|
| 2320 | CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2321 | CircleCenter.Scale(0.5);
|
---|
| 2322 |
|
---|
| 2323 | // construct normal vector of circle
|
---|
[1e168b] | 2324 | CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
|
---|
| 2325 | CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2326 |
|
---|
| 2327 | // calculate squared radius of circle
|
---|
| 2328 | radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
|
---|
| 2329 | if (radius/4. < RADIUS*RADIUS) {
|
---|
[b998c3] | 2330 | // construct relative sphere center with now known CircleCenter
|
---|
| 2331 | RelativeSphereCenter.CopyVector(&T.SphereCenter);
|
---|
| 2332 | RelativeSphereCenter.SubtractVector(&CircleCenter);
|
---|
| 2333 |
|
---|
[357fba] | 2334 | CircleRadius = RADIUS*RADIUS - radius/4.;
|
---|
| 2335 | CirclePlaneNormal.Normalize();
|
---|
[f67b6e] | 2336 | Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
[357fba] | 2337 |
|
---|
[b998c3] | 2338 | Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl;
|
---|
| 2339 |
|
---|
| 2340 | // construct SearchDirection and an "outward pointer"
|
---|
| 2341 | SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
|
---|
| 2342 | helper.CopyVector(&CircleCenter);
|
---|
[357fba] | 2343 | helper.SubtractVector(ThirdNode->node);
|
---|
| 2344 | if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
| 2345 | SearchDirection.Scale(-1.);
|
---|
[f67b6e] | 2346 | Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
[b998c3] | 2347 | if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
|
---|
[357fba] | 2348 | // rotated the wrong way!
|
---|
[717e0c] | 2349 | eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
|
---|
[357fba] | 2350 | }
|
---|
| 2351 |
|
---|
| 2352 | // add third point
|
---|
[b998c3] | 2353 | FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdNode, RADIUS, LC);
|
---|
[357fba] | 2354 |
|
---|
| 2355 | } else {
|
---|
[f67b6e] | 2356 | Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl;
|
---|
[357fba] | 2357 | }
|
---|
| 2358 |
|
---|
[f67b6e] | 2359 | if (CandidateLine.pointlist.empty()) {
|
---|
[717e0c] | 2360 | eLog() << Verbose(2) << "Could not find a suitable candidate." << endl;
|
---|
[357fba] | 2361 | return false;
|
---|
| 2362 | }
|
---|
[f67b6e] | 2363 | Log() << Verbose(0) << "Third Points are: " << endl;
|
---|
| 2364 | for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
|
---|
| 2365 | Log() << Verbose(0) << " " << *(*it) << endl;
|
---|
[357fba] | 2366 | }
|
---|
| 2367 |
|
---|
[f67b6e] | 2368 | return true;
|
---|
| 2369 |
|
---|
| 2370 | // BoundaryLineSet *BaseRay = CandidateLine.BaseLine;
|
---|
| 2371 | // for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
| 2372 | // Log() << Verbose(0) << "Third point candidate is " << *(*it)->point
|
---|
| 2373 | // << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
|
---|
| 2374 | // Log() << Verbose(0) << "Baseline is " << *BaseRay << endl;
|
---|
| 2375 | //
|
---|
| 2376 | // // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
|
---|
| 2377 | // TesselPoint *PointCandidates[3];
|
---|
| 2378 | // PointCandidates[0] = (*it)->point;
|
---|
| 2379 | // PointCandidates[1] = BaseRay->endpoints[0]->node;
|
---|
| 2380 | // PointCandidates[2] = BaseRay->endpoints[1]->node;
|
---|
| 2381 | // int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
|
---|
| 2382 | //
|
---|
| 2383 | // BTS = NULL;
|
---|
| 2384 | // // check for present edges and whether we reach better candidates from them
|
---|
| 2385 | // //if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) {
|
---|
| 2386 | // if (0) {
|
---|
| 2387 | // result = false;
|
---|
| 2388 | // break;
|
---|
| 2389 | // } else {
|
---|
| 2390 | // // If there is no triangle, add it regularly.
|
---|
| 2391 | // if (existentTrianglesCount == 0) {
|
---|
| 2392 | // AddTesselationPoint((*it)->point, 0);
|
---|
| 2393 | // AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2394 | // AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2395 | //
|
---|
| 2396 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
|
---|
| 2397 | // CandidateLine.point = (*it)->point;
|
---|
| 2398 | // CandidateLine.OptCenter.CopyVector(&((*it)->OptCenter));
|
---|
| 2399 | // CandidateLine.OtherOptCenter.CopyVector(&((*it)->OtherOptCenter));
|
---|
| 2400 | // CandidateLine.ShortestAngle = ShortestAngle;
|
---|
| 2401 | // } else {
|
---|
| 2402 | //// eLog() << Verbose(1) << "This triangle consisting of ";
|
---|
| 2403 | //// Log() << Verbose(0) << *(*it)->point << ", ";
|
---|
| 2404 | //// Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
|
---|
| 2405 | //// Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
|
---|
| 2406 | //// Log() << Verbose(0) << "exists and is not added, as it 0x80000000006fc150(does not seem helpful!" << endl;
|
---|
| 2407 | // result = false;
|
---|
| 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 | // AddTesselationPoint((*it)->point, 0);
|
---|
| 2411 | // AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2412 | // AddTesselationPoint(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) || CandidateLine.BaseLine->skipped) {
|
---|
| 2417 | // CandidateLine.point = (*it)->point;
|
---|
| 2418 | // CandidateLine.OptCenter.CopyVector(&(*it)->OptCenter);
|
---|
| 2419 | // CandidateLine.OtherOptCenter.CopyVector(&(*it)->OtherOptCenter);
|
---|
| 2420 | // CandidateLine.ShortestAngle = ShortestAngle+2.*M_PI;
|
---|
| 2421 | //
|
---|
| 2422 | // } else {
|
---|
| 2423 | //// eLog() << Verbose(1) << "This triangle consisting of " << *(*it)->point << ", " << *BaseRay->endpoints[0]->node << " and " << *BaseRay->endpoints[1]->node << " " << "exists and is not added, as it does not seem helpful!" << endl;
|
---|
| 2424 | // result = false;
|
---|
| 2425 | // }
|
---|
| 2426 | // } else {
|
---|
| 2427 | //// Log() << Verbose(1) << "This triangle consisting of ";
|
---|
| 2428 | //// Log() << Verbose(0) << *(*it)->point << ", ";
|
---|
| 2429 | //// Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
|
---|
| 2430 | //// Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
|
---|
| 2431 | //// Log() << Verbose(0) << "is invalid!" << endl;
|
---|
| 2432 | // result = false;
|
---|
| 2433 | // }
|
---|
| 2434 | // }
|
---|
| 2435 | //
|
---|
| 2436 | // // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
|
---|
| 2437 | // BaseRay = BLS[0];
|
---|
| 2438 | // if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
|
---|
| 2439 | // eLog() << Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl;
|
---|
| 2440 | // exit(255);
|
---|
| 2441 | // }
|
---|
| 2442 | //
|
---|
| 2443 | // }
|
---|
| 2444 | //
|
---|
| 2445 | // // remove all candidates from the list and then the list itself
|
---|
| 2446 | // class CandidateForTesselation *remover = NULL;
|
---|
| 2447 | // for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
| 2448 | // remover = *it;
|
---|
| 2449 | // delete(remover);
|
---|
| 2450 | // }
|
---|
| 2451 | // delete(OptCandidates);
|
---|
[357fba] | 2452 | return result;
|
---|
| 2453 | };
|
---|
| 2454 |
|
---|
[1e168b] | 2455 | /** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
|
---|
[f67b6e] | 2456 | * \param CandidateLine triangle to add
|
---|
| 2457 | * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in AddTesselationLine()
|
---|
[1e168b] | 2458 | */
|
---|
[f67b6e] | 2459 | void Tesselation::AddCandidateTriangle(CandidateForTesselation CandidateLine)
|
---|
[1e168b] | 2460 | {
|
---|
[f67b6e] | 2461 | Info FunctionInfo(__func__);
|
---|
[1e168b] | 2462 | Vector Center;
|
---|
[27bd2f] | 2463 | TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
|
---|
| 2464 |
|
---|
| 2465 | // fill the set of neighbours
|
---|
[c15ca2] | 2466 | TesselPointSet SetOfNeighbours;
|
---|
[27bd2f] | 2467 | SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
|
---|
| 2468 | for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
|
---|
| 2469 | SetOfNeighbours.insert(*Runner);
|
---|
[c15ca2] | 2470 | TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[27bd2f] | 2471 |
|
---|
| 2472 | // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
|
---|
[c15ca2] | 2473 | Log() << Verbose(0) << "List of Candidates for Turning Point: " << *TurningPoint << "." << endl;
|
---|
| 2474 | for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
|
---|
| 2475 | Log() << Verbose(0) << **TesselRunner << endl;
|
---|
[27bd2f] | 2476 | TesselPointList::iterator Runner = connectedClosestPoints->begin();
|
---|
| 2477 | TesselPointList::iterator Sprinter = Runner;
|
---|
| 2478 | Sprinter++;
|
---|
| 2479 | while(Sprinter != connectedClosestPoints->end()) {
|
---|
[f67b6e] | 2480 | // add the points
|
---|
[27bd2f] | 2481 | AddTesselationPoint(TurningPoint, 0);
|
---|
| 2482 | AddTesselationPoint((*Runner), 1);
|
---|
| 2483 | AddTesselationPoint((*Sprinter), 2);
|
---|
[f67b6e] | 2484 |
|
---|
| 2485 | // add the lines
|
---|
[27bd2f] | 2486 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 2487 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
| 2488 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
[1e168b] | 2489 |
|
---|
[f67b6e] | 2490 | // add the triangles
|
---|
| 2491 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2492 | AddTesselationTriangle();
|
---|
[b998c3] | 2493 | BTS->GetCenter(&Center);
|
---|
| 2494 | Center.SubtractVector(&CandidateLine.OptCenter);
|
---|
| 2495 | BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
|
---|
[f67b6e] | 2496 | BTS->GetNormalVector(Center);
|
---|
[1e168b] | 2497 |
|
---|
[f67b6e] | 2498 | Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << "." << endl;
|
---|
[27bd2f] | 2499 | Runner = Sprinter;
|
---|
| 2500 | Sprinter++;
|
---|
[c15ca2] | 2501 | Log() << Verbose(0) << "Current Runner is " << **Runner << "." << endl;
|
---|
| 2502 | if (Sprinter != connectedClosestPoints->end())
|
---|
| 2503 | Log() << Verbose(0) << " There are still more triangles to add." << endl;
|
---|
[f67b6e] | 2504 | }
|
---|
[856098] | 2505 | delete(connectedClosestPoints);
|
---|
[1e168b] | 2506 | };
|
---|
| 2507 |
|
---|
[16d866] | 2508 | /** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
|
---|
| 2509 | * We look whether the closest point on \a *Base with respect to the other baseline is outside
|
---|
| 2510 | * of the segment formed by both endpoints (concave) or not (convex).
|
---|
| 2511 | * \param *out output stream for debugging
|
---|
| 2512 | * \param *Base line to be flipped
|
---|
[57066a] | 2513 | * \return NULL - convex, otherwise endpoint that makes it concave
|
---|
[16d866] | 2514 | */
|
---|
[e138de] | 2515 | class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
|
---|
[16d866] | 2516 | {
|
---|
[f67b6e] | 2517 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2518 | class BoundaryPointSet *Spot = NULL;
|
---|
| 2519 | class BoundaryLineSet *OtherBase;
|
---|
[0077b5] | 2520 | Vector *ClosestPoint;
|
---|
[16d866] | 2521 |
|
---|
| 2522 | int m=0;
|
---|
| 2523 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2524 | for (int j=0;j<3;j++) // all of their endpoints and baselines
|
---|
| 2525 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2526 | BPS[m++] = runner->second->endpoints[j];
|
---|
| 2527 | OtherBase = new class BoundaryLineSet(BPS,-1);
|
---|
| 2528 |
|
---|
[f67b6e] | 2529 | Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl;
|
---|
| 2530 | Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl;
|
---|
[16d866] | 2531 |
|
---|
| 2532 | // get the closest point on each line to the other line
|
---|
[e138de] | 2533 | ClosestPoint = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
[16d866] | 2534 |
|
---|
| 2535 | // delete the temporary other base line
|
---|
| 2536 | delete(OtherBase);
|
---|
| 2537 |
|
---|
| 2538 | // get the distance vector from Base line to OtherBase line
|
---|
[0077b5] | 2539 | Vector DistanceToIntersection[2], BaseLine;
|
---|
| 2540 | double distance[2];
|
---|
[16d866] | 2541 | BaseLine.CopyVector(Base->endpoints[1]->node->node);
|
---|
| 2542 | BaseLine.SubtractVector(Base->endpoints[0]->node->node);
|
---|
[0077b5] | 2543 | for (int i=0;i<2;i++) {
|
---|
| 2544 | DistanceToIntersection[i].CopyVector(ClosestPoint);
|
---|
| 2545 | DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
|
---|
| 2546 | distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
|
---|
[16d866] | 2547 | }
|
---|
[1d9b7aa] | 2548 | delete(ClosestPoint);
|
---|
| 2549 | if ((distance[0] * distance[1]) > 0) { // have same sign?
|
---|
[f67b6e] | 2550 | Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl;
|
---|
[0077b5] | 2551 | if (distance[0] < distance[1]) {
|
---|
| 2552 | Spot = Base->endpoints[0];
|
---|
| 2553 | } else {
|
---|
| 2554 | Spot = Base->endpoints[1];
|
---|
| 2555 | }
|
---|
[16d866] | 2556 | return Spot;
|
---|
[0077b5] | 2557 | } else { // different sign, i.e. we are in between
|
---|
[f67b6e] | 2558 | Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
|
---|
[16d866] | 2559 | return NULL;
|
---|
| 2560 | }
|
---|
| 2561 |
|
---|
| 2562 | };
|
---|
| 2563 |
|
---|
[776b64] | 2564 | void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
|
---|
[0077b5] | 2565 | {
|
---|
[f67b6e] | 2566 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2567 | // print all lines
|
---|
[f67b6e] | 2568 | Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl;
|
---|
[776b64] | 2569 | for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
|
---|
[f67b6e] | 2570 | Log() << Verbose(0) << *(PointRunner->second) << endl;
|
---|
[0077b5] | 2571 | };
|
---|
| 2572 |
|
---|
[776b64] | 2573 | void Tesselation::PrintAllBoundaryLines(ofstream *out) const
|
---|
[0077b5] | 2574 | {
|
---|
[f67b6e] | 2575 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2576 | // print all lines
|
---|
[f67b6e] | 2577 | Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl;
|
---|
[776b64] | 2578 | for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
|
---|
[f67b6e] | 2579 | Log() << Verbose(0) << *(LineRunner->second) << endl;
|
---|
[0077b5] | 2580 | };
|
---|
| 2581 |
|
---|
[776b64] | 2582 | void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
|
---|
[0077b5] | 2583 | {
|
---|
[f67b6e] | 2584 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2585 | // print all triangles
|
---|
[f67b6e] | 2586 | Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl;
|
---|
[776b64] | 2587 | for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
|
---|
[f67b6e] | 2588 | Log() << Verbose(0) << *(TriangleRunner->second) << endl;
|
---|
[0077b5] | 2589 | };
|
---|
[357fba] | 2590 |
|
---|
[16d866] | 2591 | /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
|
---|
[357fba] | 2592 | * \param *out output stream for debugging
|
---|
[16d866] | 2593 | * \param *Base line to be flipped
|
---|
[57066a] | 2594 | * \return volume change due to flipping (0 - then no flipped occured)
|
---|
[357fba] | 2595 | */
|
---|
[e138de] | 2596 | double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
|
---|
[357fba] | 2597 | {
|
---|
[f67b6e] | 2598 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2599 | class BoundaryLineSet *OtherBase;
|
---|
| 2600 | Vector *ClosestPoint[2];
|
---|
[57066a] | 2601 | double volume;
|
---|
[16d866] | 2602 |
|
---|
| 2603 | int m=0;
|
---|
| 2604 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2605 | for (int j=0;j<3;j++) // all of their endpoints and baselines
|
---|
| 2606 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2607 | BPS[m++] = runner->second->endpoints[j];
|
---|
| 2608 | OtherBase = new class BoundaryLineSet(BPS,-1);
|
---|
[62bb91] | 2609 |
|
---|
[f67b6e] | 2610 | Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl;
|
---|
| 2611 | Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl;
|
---|
[62bb91] | 2612 |
|
---|
[16d866] | 2613 | // get the closest point on each line to the other line
|
---|
[e138de] | 2614 | ClosestPoint[0] = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
| 2615 | ClosestPoint[1] = GetClosestPointBetweenLine(OtherBase, Base);
|
---|
[16d866] | 2616 |
|
---|
| 2617 | // get the distance vector from Base line to OtherBase line
|
---|
| 2618 | Vector Distance;
|
---|
| 2619 | Distance.CopyVector(ClosestPoint[1]);
|
---|
| 2620 | Distance.SubtractVector(ClosestPoint[0]);
|
---|
| 2621 |
|
---|
[57066a] | 2622 | // calculate volume
|
---|
[c0f6c6] | 2623 | volume = CalculateVolumeofGeneralTetraeder(*Base->endpoints[1]->node->node, *OtherBase->endpoints[0]->node->node, *OtherBase->endpoints[1]->node->node, *Base->endpoints[0]->node->node);
|
---|
[57066a] | 2624 |
|
---|
[0077b5] | 2625 | // delete the temporary other base line and the closest points
|
---|
| 2626 | delete(ClosestPoint[0]);
|
---|
| 2627 | delete(ClosestPoint[1]);
|
---|
[16d866] | 2628 | delete(OtherBase);
|
---|
| 2629 |
|
---|
| 2630 | if (Distance.NormSquared() < MYEPSILON) { // check for intersection
|
---|
[f67b6e] | 2631 | Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
|
---|
[16d866] | 2632 | return false;
|
---|
| 2633 | } else { // check for sign against BaseLineNormal
|
---|
| 2634 | Vector BaseLineNormal;
|
---|
[5c7bf8] | 2635 | BaseLineNormal.Zero();
|
---|
| 2636 | if (Base->triangles.size() < 2) {
|
---|
[717e0c] | 2637 | eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;
|
---|
[57066a] | 2638 | return 0.;
|
---|
[5c7bf8] | 2639 | }
|
---|
| 2640 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[f67b6e] | 2641 | Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
|
---|
[5c7bf8] | 2642 | BaseLineNormal.AddVector(&(runner->second->NormalVector));
|
---|
| 2643 | }
|
---|
[0077b5] | 2644 | BaseLineNormal.Scale(1./2.);
|
---|
[357fba] | 2645 |
|
---|
[16d866] | 2646 | if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
|
---|
[f67b6e] | 2647 | Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;
|
---|
[57066a] | 2648 | // calculate volume summand as a general tetraeder
|
---|
| 2649 | return volume;
|
---|
[16d866] | 2650 | } else { // Base higher than OtherBase -> do nothing
|
---|
[f67b6e] | 2651 | Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl;
|
---|
[57066a] | 2652 | return 0.;
|
---|
[16d866] | 2653 | }
|
---|
| 2654 | }
|
---|
| 2655 | };
|
---|
[357fba] | 2656 |
|
---|
[16d866] | 2657 | /** For a given baseline and its two connected triangles, flips the baseline.
|
---|
| 2658 | * I.e. we create the new baseline between the other two endpoints of these four
|
---|
| 2659 | * endpoints and reconstruct the two triangles accordingly.
|
---|
| 2660 | * \param *out output stream for debugging
|
---|
| 2661 | * \param *Base line to be flipped
|
---|
[57066a] | 2662 | * \return pointer to allocated new baseline - flipping successful, NULL - something went awry
|
---|
[16d866] | 2663 | */
|
---|
[e138de] | 2664 | class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
|
---|
[16d866] | 2665 | {
|
---|
[f67b6e] | 2666 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2667 | class BoundaryLineSet *OldLines[4], *NewLine;
|
---|
| 2668 | class BoundaryPointSet *OldPoints[2];
|
---|
| 2669 | Vector BaseLineNormal;
|
---|
| 2670 | int OldTriangleNrs[2], OldBaseLineNr;
|
---|
| 2671 | int i,m;
|
---|
| 2672 |
|
---|
| 2673 | // calculate NormalVector for later use
|
---|
| 2674 | BaseLineNormal.Zero();
|
---|
| 2675 | if (Base->triangles.size() < 2) {
|
---|
[717e0c] | 2676 | eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;
|
---|
[57066a] | 2677 | return NULL;
|
---|
[16d866] | 2678 | }
|
---|
| 2679 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[f67b6e] | 2680 | Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
|
---|
[16d866] | 2681 | BaseLineNormal.AddVector(&(runner->second->NormalVector));
|
---|
| 2682 | }
|
---|
| 2683 | BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
|
---|
| 2684 |
|
---|
| 2685 | // get the two triangles
|
---|
| 2686 | // gather four endpoints and four lines
|
---|
| 2687 | for (int j=0;j<4;j++)
|
---|
| 2688 | OldLines[j] = NULL;
|
---|
| 2689 | for (int j=0;j<2;j++)
|
---|
| 2690 | OldPoints[j] = NULL;
|
---|
| 2691 | i=0;
|
---|
| 2692 | m=0;
|
---|
[f67b6e] | 2693 | Log() << Verbose(0) << "The four old lines are: ";
|
---|
[16d866] | 2694 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2695 | for (int j=0;j<3;j++) // all of their endpoints and baselines
|
---|
| 2696 | if (runner->second->lines[j] != Base) { // pick not the central baseline
|
---|
| 2697 | OldLines[i++] = runner->second->lines[j];
|
---|
[e138de] | 2698 | Log() << Verbose(0) << *runner->second->lines[j] << "\t";
|
---|
[357fba] | 2699 | }
|
---|
[e138de] | 2700 | Log() << Verbose(0) << endl;
|
---|
[f67b6e] | 2701 | Log() << Verbose(0) << "The two old points are: ";
|
---|
[16d866] | 2702 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2703 | for (int j=0;j<3;j++) // all of their endpoints and baselines
|
---|
| 2704 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
|
---|
| 2705 | OldPoints[m++] = runner->second->endpoints[j];
|
---|
[e138de] | 2706 | Log() << Verbose(0) << *runner->second->endpoints[j] << "\t";
|
---|
[16d866] | 2707 | }
|
---|
[e138de] | 2708 | Log() << Verbose(0) << endl;
|
---|
[16d866] | 2709 |
|
---|
| 2710 | // check whether everything is in place to create new lines and triangles
|
---|
| 2711 | if (i<4) {
|
---|
[717e0c] | 2712 | eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;
|
---|
[57066a] | 2713 | return NULL;
|
---|
[16d866] | 2714 | }
|
---|
| 2715 | for (int j=0;j<4;j++)
|
---|
| 2716 | if (OldLines[j] == NULL) {
|
---|
[717e0c] | 2717 | eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;
|
---|
[57066a] | 2718 | return NULL;
|
---|
[16d866] | 2719 | }
|
---|
| 2720 | for (int j=0;j<2;j++)
|
---|
| 2721 | if (OldPoints[j] == NULL) {
|
---|
[717e0c] | 2722 | eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl;
|
---|
[57066a] | 2723 | return NULL;
|
---|
[357fba] | 2724 | }
|
---|
[16d866] | 2725 |
|
---|
| 2726 | // remove triangles and baseline removes itself
|
---|
[f67b6e] | 2727 | Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
|
---|
[16d866] | 2728 | OldBaseLineNr = Base->Nr;
|
---|
| 2729 | m=0;
|
---|
| 2730 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[f67b6e] | 2731 | Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
|
---|
[16d866] | 2732 | OldTriangleNrs[m++] = runner->second->Nr;
|
---|
| 2733 | RemoveTesselationTriangle(runner->second);
|
---|
| 2734 | }
|
---|
| 2735 |
|
---|
| 2736 | // construct new baseline (with same number as old one)
|
---|
| 2737 | BPS[0] = OldPoints[0];
|
---|
| 2738 | BPS[1] = OldPoints[1];
|
---|
| 2739 | NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
|
---|
| 2740 | LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
|
---|
[f67b6e] | 2741 | Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl;
|
---|
[16d866] | 2742 |
|
---|
| 2743 | // construct new triangles with flipped baseline
|
---|
| 2744 | i=-1;
|
---|
| 2745 | if (OldLines[0]->IsConnectedTo(OldLines[2]))
|
---|
| 2746 | i=2;
|
---|
| 2747 | if (OldLines[0]->IsConnectedTo(OldLines[3]))
|
---|
| 2748 | i=3;
|
---|
| 2749 | if (i!=-1) {
|
---|
| 2750 | BLS[0] = OldLines[0];
|
---|
| 2751 | BLS[1] = OldLines[i];
|
---|
| 2752 | BLS[2] = NewLine;
|
---|
| 2753 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[0]);
|
---|
| 2754 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 2755 | AddTesselationTriangle(OldTriangleNrs[0]);
|
---|
[f67b6e] | 2756 | Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
|
---|
[16d866] | 2757 |
|
---|
| 2758 | BLS[0] = (i==2 ? OldLines[3] : OldLines[2]);
|
---|
| 2759 | BLS[1] = OldLines[1];
|
---|
| 2760 | BLS[2] = NewLine;
|
---|
| 2761 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[1]);
|
---|
| 2762 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 2763 | AddTesselationTriangle(OldTriangleNrs[1]);
|
---|
[f67b6e] | 2764 | Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;
|
---|
[16d866] | 2765 | } else {
|
---|
[f67b6e] | 2766 | eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl;
|
---|
[57066a] | 2767 | return NULL;
|
---|
[357fba] | 2768 | }
|
---|
[16d866] | 2769 |
|
---|
[57066a] | 2770 | return NewLine;
|
---|
[357fba] | 2771 | };
|
---|
| 2772 |
|
---|
[16d866] | 2773 |
|
---|
[357fba] | 2774 | /** Finds the second point of starting triangle.
|
---|
| 2775 | * \param *a first node
|
---|
| 2776 | * \param Oben vector indicating the outside
|
---|
[f1cccd] | 2777 | * \param OptCandidate reference to recommended candidate on return
|
---|
[357fba] | 2778 | * \param Storage[3] array storing angles and other candidate information
|
---|
| 2779 | * \param RADIUS radius of virtual sphere
|
---|
[62bb91] | 2780 | * \param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 2781 | */
|
---|
[776b64] | 2782 | void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2783 | {
|
---|
[f67b6e] | 2784 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2785 | Vector AngleCheck;
|
---|
[57066a] | 2786 | class TesselPoint* Candidate = NULL;
|
---|
[776b64] | 2787 | double norm = -1.;
|
---|
| 2788 | double angle = 0.;
|
---|
| 2789 | int N[NDIM];
|
---|
| 2790 | int Nlower[NDIM];
|
---|
| 2791 | int Nupper[NDIM];
|
---|
[357fba] | 2792 |
|
---|
[62bb91] | 2793 | if (LC->SetIndexToNode(a)) { // get cell for the starting point
|
---|
[357fba] | 2794 | for(int i=0;i<NDIM;i++) // store indices of this cell
|
---|
| 2795 | N[i] = LC->n[i];
|
---|
| 2796 | } else {
|
---|
[717e0c] | 2797 | eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl;
|
---|
[357fba] | 2798 | return;
|
---|
| 2799 | }
|
---|
[62bb91] | 2800 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[357fba] | 2801 | for (int i=0;i<NDIM;i++) {
|
---|
| 2802 | Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
|
---|
| 2803 | Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
|
---|
| 2804 | }
|
---|
[f67b6e] | 2805 | Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :"
|
---|
[f1ef60a] | 2806 | << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl;
|
---|
[357fba] | 2807 |
|
---|
| 2808 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 2809 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 2810 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[776b64] | 2811 | const LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 2812 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2813 | if (List != NULL) {
|
---|
[776b64] | 2814 | for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 2815 | Candidate = (*Runner);
|
---|
| 2816 | // check if we only have one unique point yet ...
|
---|
| 2817 | if (a != Candidate) {
|
---|
| 2818 | // Calculate center of the circle with radius RADIUS through points a and Candidate
|
---|
[f1cccd] | 2819 | Vector OrthogonalizedOben, aCandidate, Center;
|
---|
[357fba] | 2820 | double distance, scaleFactor;
|
---|
| 2821 |
|
---|
| 2822 | OrthogonalizedOben.CopyVector(&Oben);
|
---|
[f1cccd] | 2823 | aCandidate.CopyVector(a->node);
|
---|
| 2824 | aCandidate.SubtractVector(Candidate->node);
|
---|
| 2825 | OrthogonalizedOben.ProjectOntoPlane(&aCandidate);
|
---|
[357fba] | 2826 | OrthogonalizedOben.Normalize();
|
---|
[f1cccd] | 2827 | distance = 0.5 * aCandidate.Norm();
|
---|
[357fba] | 2828 | scaleFactor = sqrt(((RADIUS * RADIUS) - (distance * distance)));
|
---|
| 2829 | OrthogonalizedOben.Scale(scaleFactor);
|
---|
| 2830 |
|
---|
| 2831 | Center.CopyVector(Candidate->node);
|
---|
| 2832 | Center.AddVector(a->node);
|
---|
| 2833 | Center.Scale(0.5);
|
---|
| 2834 | Center.AddVector(&OrthogonalizedOben);
|
---|
| 2835 |
|
---|
| 2836 | AngleCheck.CopyVector(&Center);
|
---|
| 2837 | AngleCheck.SubtractVector(a->node);
|
---|
[f1cccd] | 2838 | norm = aCandidate.Norm();
|
---|
[357fba] | 2839 | // second point shall have smallest angle with respect to Oben vector
|
---|
| 2840 | if (norm < RADIUS*2.) {
|
---|
| 2841 | angle = AngleCheck.Angle(&Oben);
|
---|
| 2842 | if (angle < Storage[0]) {
|
---|
[f67b6e] | 2843 | //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
|
---|
| 2844 | Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
|
---|
[f1cccd] | 2845 | OptCandidate = Candidate;
|
---|
[357fba] | 2846 | Storage[0] = angle;
|
---|
[f67b6e] | 2847 | //Log() << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
|
---|
[357fba] | 2848 | } else {
|
---|
[f67b6e] | 2849 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
|
---|
[357fba] | 2850 | }
|
---|
| 2851 | } else {
|
---|
[f67b6e] | 2852 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
|
---|
[357fba] | 2853 | }
|
---|
| 2854 | } else {
|
---|
[f67b6e] | 2855 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
|
---|
[357fba] | 2856 | }
|
---|
| 2857 | }
|
---|
| 2858 | } else {
|
---|
[f67b6e] | 2859 | Log() << Verbose(0) << "Linked cell list is empty." << endl;
|
---|
[357fba] | 2860 | }
|
---|
| 2861 | }
|
---|
| 2862 | };
|
---|
| 2863 |
|
---|
| 2864 |
|
---|
| 2865 | /** This recursive function finds a third point, to form a triangle with two given ones.
|
---|
| 2866 | * Note that this function is for the starting triangle.
|
---|
| 2867 | * The idea is as follows: A sphere with fixed radius is (almost) uniquely defined in space by three points
|
---|
| 2868 | * that sit on its boundary. Hence, when two points are given and we look for the (next) third point, then
|
---|
| 2869 | * the center of the sphere is still fixed up to a single parameter. The band of possible values
|
---|
| 2870 | * describes a circle in 3D-space. The old center of the sphere for the current base triangle gives
|
---|
| 2871 | * us the "null" on this circle, the new center of the candidate point will be some way along this
|
---|
| 2872 | * circle. The shorter the way the better is the candidate. Note that the direction is clearly given
|
---|
| 2873 | * by the normal vector of the base triangle that always points outwards by construction.
|
---|
| 2874 | * Hence, we construct a Center of this circle which sits right in the middle of the current base line.
|
---|
| 2875 | * We construct the normal vector that defines the plane this circle lies in, it is just in the
|
---|
| 2876 | * direction of the baseline. And finally, we need the radius of the circle, which is given by the rest
|
---|
| 2877 | * with respect to the length of the baseline and the sphere's fixed \a RADIUS.
|
---|
| 2878 | * Note that there is one difficulty: The circumcircle is uniquely defined, but for the circumsphere's center
|
---|
| 2879 | * there are two possibilities which becomes clear from the construction as seen below. Hence, we must check
|
---|
| 2880 | * both.
|
---|
| 2881 | * Note also that the acos() function is not unique on [0, 2.*M_PI). Hence, we need an additional check
|
---|
| 2882 | * to decide for one of the two possible angles. Therefore we need a SearchDirection and to make this check
|
---|
| 2883 | * sensible we need OldSphereCenter to be orthogonal to it. Either we construct SearchDirection orthogonal
|
---|
| 2884 | * right away, or -- what we do here -- we rotate the relative sphere centers such that this orthogonality
|
---|
| 2885 | * holds. Then, the normalized projection onto the SearchDirection is either +1 or -1 and thus states whether
|
---|
| 2886 | * the angle is uniquely in either (0,M_PI] or [M_PI, 2.*M_PI).
|
---|
[f1cccd] | 2887 | * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa FindStartingTriangle())
|
---|
[357fba] | 2888 | * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
|
---|
| 2889 | * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
|
---|
[f67b6e] | 2890 | * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
|
---|
[62bb91] | 2891 | * @param ThirdNode third point to avoid in search
|
---|
[357fba] | 2892 | * @param RADIUS radius of sphere
|
---|
[62bb91] | 2893 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 2894 | */
|
---|
[f67b6e] | 2895 | void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const
|
---|
[357fba] | 2896 | {
|
---|
[f67b6e] | 2897 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2898 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
| 2899 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 2900 | Vector SphereCenter;
|
---|
| 2901 | Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
|
---|
| 2902 | Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
|
---|
| 2903 | Vector NewNormalVector; // normal vector of the Candidate's triangle
|
---|
| 2904 | Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
|
---|
[b998c3] | 2905 | Vector RelativeOldSphereCenter;
|
---|
| 2906 | Vector NewPlaneCenter;
|
---|
[357fba] | 2907 | double CircleRadius; // radius of this circle
|
---|
| 2908 | double radius;
|
---|
[b998c3] | 2909 | double otherradius;
|
---|
[357fba] | 2910 | double alpha, Otheralpha; // angles (i.e. parameter for the circle).
|
---|
| 2911 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
| 2912 | TesselPoint *Candidate = NULL;
|
---|
| 2913 |
|
---|
[f67b6e] | 2914 | Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
|
---|
[357fba] | 2915 |
|
---|
| 2916 | // construct center of circle
|
---|
[f67b6e] | 2917 | CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
|
---|
| 2918 | CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2919 | CircleCenter.Scale(0.5);
|
---|
| 2920 |
|
---|
| 2921 | // construct normal vector of circle
|
---|
[f67b6e] | 2922 | CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
|
---|
| 2923 | CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2924 |
|
---|
[b998c3] | 2925 | RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
|
---|
| 2926 | RelativeOldSphereCenter.SubtractVector(&CircleCenter);
|
---|
| 2927 |
|
---|
[ab1932] | 2928 | // calculate squared radius TesselPoint *ThirdNode,f circle
|
---|
[b998c3] | 2929 | radius = CirclePlaneNormal.NormSquared()/4.;
|
---|
| 2930 | if (radius < RADIUS*RADIUS) {
|
---|
| 2931 | CircleRadius = RADIUS*RADIUS - radius;
|
---|
[357fba] | 2932 | CirclePlaneNormal.Normalize();
|
---|
[b998c3] | 2933 | Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
[357fba] | 2934 |
|
---|
| 2935 | // test whether old center is on the band's plane
|
---|
[b998c3] | 2936 | if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
|
---|
| 2937 | eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
|
---|
| 2938 | RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
|
---|
[357fba] | 2939 | }
|
---|
[b998c3] | 2940 | radius = RelativeOldSphereCenter.NormSquared();
|
---|
[357fba] | 2941 | if (fabs(radius - CircleRadius) < HULLEPSILON) {
|
---|
[b998c3] | 2942 | Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl;
|
---|
[357fba] | 2943 |
|
---|
| 2944 | // check SearchDirection
|
---|
[b998c3] | 2945 | Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
| 2946 | if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
|
---|
[717e0c] | 2947 | eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl;
|
---|
[357fba] | 2948 | }
|
---|
| 2949 |
|
---|
[62bb91] | 2950 | // get cell for the starting point
|
---|
[357fba] | 2951 | if (LC->SetIndexToVector(&CircleCenter)) {
|
---|
| 2952 | for(int i=0;i<NDIM;i++) // store indices of this cell
|
---|
| 2953 | N[i] = LC->n[i];
|
---|
[f67b6e] | 2954 | //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2955 | } else {
|
---|
[717e0c] | 2956 | eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl;
|
---|
[357fba] | 2957 | return;
|
---|
| 2958 | }
|
---|
[62bb91] | 2959 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[f67b6e] | 2960 | //Log() << Verbose(1) << "LC Intervals:";
|
---|
[357fba] | 2961 | for (int i=0;i<NDIM;i++) {
|
---|
| 2962 | Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
|
---|
| 2963 | Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
|
---|
[e138de] | 2964 | //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
|
---|
[357fba] | 2965 | }
|
---|
[e138de] | 2966 | //Log() << Verbose(0) << endl;
|
---|
[357fba] | 2967 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 2968 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 2969 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[776b64] | 2970 | const LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 2971 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2972 | if (List != NULL) {
|
---|
[776b64] | 2973 | for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 2974 | Candidate = (*Runner);
|
---|
| 2975 |
|
---|
| 2976 | // check for three unique points
|
---|
[b998c3] | 2977 | Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl;
|
---|
[f67b6e] | 2978 | if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node) ){
|
---|
[357fba] | 2979 |
|
---|
[b998c3] | 2980 | // find center on the plane
|
---|
| 2981 | GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
|
---|
| 2982 | Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl;
|
---|
[357fba] | 2983 |
|
---|
[125b3c] | 2984 | if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node)
|
---|
[b998c3] | 2985 | && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)
|
---|
[357fba] | 2986 | ) {
|
---|
[f67b6e] | 2987 | Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
|
---|
[b998c3] | 2988 | radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
|
---|
| 2989 | Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
| 2990 | Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
| 2991 | Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl;
|
---|
[357fba] | 2992 | if (radius < RADIUS*RADIUS) {
|
---|
[b998c3] | 2993 | otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
|
---|
| 2994 | if (fabs(radius - otherradius) > HULLEPSILON) {
|
---|
| 2995 | eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl;
|
---|
| 2996 | }
|
---|
| 2997 | // construct both new centers
|
---|
| 2998 | NewSphereCenter.CopyVector(&NewPlaneCenter);
|
---|
| 2999 | OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
|
---|
| 3000 | helper.CopyVector(&NewNormalVector);
|
---|
[357fba] | 3001 | helper.Scale(sqrt(RADIUS*RADIUS - radius));
|
---|
[b998c3] | 3002 | Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl;
|
---|
[357fba] | 3003 | NewSphereCenter.AddVector(&helper);
|
---|
[f67b6e] | 3004 | Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
|
---|
[357fba] | 3005 | // OtherNewSphereCenter is created by the same vector just in the other direction
|
---|
| 3006 | helper.Scale(-1.);
|
---|
| 3007 | OtherNewSphereCenter.AddVector(&helper);
|
---|
[f67b6e] | 3008 | Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
|
---|
[357fba] | 3009 |
|
---|
| 3010 | alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
| 3011 | Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
| 3012 | alpha = min(alpha, Otheralpha);
|
---|
[b998c3] | 3013 |
|
---|
[125b3c] | 3014 | // if there is a better candidate, drop the current list and add the new candidate
|
---|
| 3015 | // otherwise ignore the new candidate and keep the list
|
---|
| 3016 | if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
|
---|
| 3017 | if (fabs(alpha - Otheralpha) > MYEPSILON) {
|
---|
| 3018 | CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
|
---|
| 3019 | CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
|
---|
| 3020 | } else {
|
---|
| 3021 | CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
|
---|
| 3022 | CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
|
---|
| 3023 | }
|
---|
| 3024 | // if there is an equal candidate, add it to the list without clearing the list
|
---|
| 3025 | if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
|
---|
| 3026 | CandidateLine.pointlist.push_back(Candidate);
|
---|
| 3027 | Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "
|
---|
| 3028 | << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
|
---|
[357fba] | 3029 | } else {
|
---|
[125b3c] | 3030 | // remove all candidates from the list and then the list itself
|
---|
| 3031 | CandidateLine.pointlist.clear();
|
---|
| 3032 | CandidateLine.pointlist.push_back(Candidate);
|
---|
| 3033 | Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "
|
---|
| 3034 | << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;
|
---|
[357fba] | 3035 | }
|
---|
[125b3c] | 3036 | CandidateLine.ShortestAngle = alpha;
|
---|
| 3037 | Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;
|
---|
[357fba] | 3038 | } else {
|
---|
[125b3c] | 3039 | if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
|
---|
| 3040 | Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
|
---|
[357fba] | 3041 | } else {
|
---|
[125b3c] | 3042 | Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
|
---|
[357fba] | 3043 | }
|
---|
| 3044 | }
|
---|
| 3045 | } else {
|
---|
[f67b6e] | 3046 | Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
|
---|
[357fba] | 3047 | }
|
---|
| 3048 | } else {
|
---|
[f67b6e] | 3049 | Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
|
---|
[357fba] | 3050 | }
|
---|
| 3051 | } else {
|
---|
| 3052 | if (ThirdNode != NULL) {
|
---|
[f67b6e] | 3053 | Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
|
---|
[357fba] | 3054 | } else {
|
---|
[f67b6e] | 3055 | Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl;
|
---|
[357fba] | 3056 | }
|
---|
| 3057 | }
|
---|
| 3058 | }
|
---|
| 3059 | }
|
---|
| 3060 | }
|
---|
| 3061 | } else {
|
---|
[717e0c] | 3062 | eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;
|
---|
[357fba] | 3063 | }
|
---|
| 3064 | } else {
|
---|
| 3065 | if (ThirdNode != NULL)
|
---|
[f67b6e] | 3066 | Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
|
---|
[357fba] | 3067 | else
|
---|
[f67b6e] | 3068 | Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl;
|
---|
[357fba] | 3069 | }
|
---|
| 3070 |
|
---|
[f67b6e] | 3071 | Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl;
|
---|
| 3072 | if (CandidateLine.pointlist.size() > 1) {
|
---|
| 3073 | CandidateLine.pointlist.unique();
|
---|
| 3074 | CandidateLine.pointlist.sort(); //SortCandidates);
|
---|
[357fba] | 3075 | }
|
---|
| 3076 | };
|
---|
| 3077 |
|
---|
| 3078 | /** Finds the endpoint two lines are sharing.
|
---|
| 3079 | * \param *line1 first line
|
---|
| 3080 | * \param *line2 second line
|
---|
| 3081 | * \return point which is shared or NULL if none
|
---|
| 3082 | */
|
---|
[776b64] | 3083 | class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
|
---|
[357fba] | 3084 | {
|
---|
[f67b6e] | 3085 | Info FunctionInfo(__func__);
|
---|
[776b64] | 3086 | const BoundaryLineSet * lines[2] = { line1, line2 };
|
---|
[357fba] | 3087 | class BoundaryPointSet *node = NULL;
|
---|
[c15ca2] | 3088 | PointMap OrderMap;
|
---|
| 3089 | PointTestPair OrderTest;
|
---|
[357fba] | 3090 | for (int i = 0; i < 2; i++)
|
---|
| 3091 | // for both lines
|
---|
| 3092 | for (int j = 0; j < 2; j++)
|
---|
| 3093 | { // for both endpoints
|
---|
| 3094 | OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (
|
---|
| 3095 | lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
|
---|
| 3096 | if (!OrderTest.second)
|
---|
| 3097 | { // if insertion fails, we have common endpoint
|
---|
| 3098 | node = OrderTest.first->second;
|
---|
[f67b6e] | 3099 | Log() << Verbose(1) << "Common endpoint of lines " << *line1
|
---|
[357fba] | 3100 | << " and " << *line2 << " is: " << *node << "." << endl;
|
---|
| 3101 | j = 2;
|
---|
| 3102 | i = 2;
|
---|
| 3103 | break;
|
---|
| 3104 | }
|
---|
| 3105 | }
|
---|
| 3106 | return node;
|
---|
| 3107 | };
|
---|
| 3108 |
|
---|
[c15ca2] | 3109 | /** Finds the boundary points that are closest to a given Vector \a *x.
|
---|
[62bb91] | 3110 | * \param *out output stream for debugging
|
---|
| 3111 | * \param *x Vector to look from
|
---|
[c15ca2] | 3112 | * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
|
---|
[62bb91] | 3113 | */
|
---|
[97498a] | 3114 | DistanceToPointMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 3115 | {
|
---|
[c15ca2] | 3116 | Info FunctionInfo(__func__);
|
---|
[71b20e] | 3117 | PointMap::const_iterator FindPoint;
|
---|
| 3118 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
[62bb91] | 3119 |
|
---|
| 3120 | if (LinesOnBoundary.empty()) {
|
---|
[71b20e] | 3121 | eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl;
|
---|
[62bb91] | 3122 | return NULL;
|
---|
| 3123 | }
|
---|
[71b20e] | 3124 |
|
---|
| 3125 | // gather all points close to the desired one
|
---|
| 3126 | LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
|
---|
| 3127 | for(int i=0;i<NDIM;i++) // store indices of this cell
|
---|
| 3128 | N[i] = LC->n[i];
|
---|
| 3129 | Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
|
---|
| 3130 |
|
---|
[97498a] | 3131 | DistanceToPointMap * points = new DistanceToPointMap;
|
---|
[71b20e] | 3132 | LC->GetNeighbourBounds(Nlower, Nupper);
|
---|
| 3133 | //Log() << Verbose(1) << endl;
|
---|
| 3134 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3135 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3136 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
| 3137 | const LinkedNodes *List = LC->GetCurrentCell();
|
---|
| 3138 | //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
|
---|
| 3139 | if (List != NULL) {
|
---|
| 3140 | for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
| 3141 | FindPoint = PointsOnBoundary.find((*Runner)->nr);
|
---|
[97498a] | 3142 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 3143 | points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(x), FindPoint->second) );
|
---|
| 3144 | Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl;
|
---|
| 3145 | }
|
---|
[71b20e] | 3146 | }
|
---|
| 3147 | } else {
|
---|
| 3148 | eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
|
---|
[99593f] | 3149 | }
|
---|
[57066a] | 3150 | }
|
---|
[62bb91] | 3151 |
|
---|
[71b20e] | 3152 | // check whether we found some points
|
---|
[c15ca2] | 3153 | if (points->empty()) {
|
---|
| 3154 | eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
|
---|
| 3155 | delete(points);
|
---|
| 3156 | return NULL;
|
---|
| 3157 | }
|
---|
| 3158 | return points;
|
---|
| 3159 | };
|
---|
| 3160 |
|
---|
| 3161 | /** Finds the boundary line that is closest to a given Vector \a *x.
|
---|
| 3162 | * \param *out output stream for debugging
|
---|
| 3163 | * \param *x Vector to look from
|
---|
| 3164 | * \return closest BoundaryLineSet or NULL in degenerate case.
|
---|
| 3165 | */
|
---|
| 3166 | BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const
|
---|
| 3167 | {
|
---|
| 3168 | Info FunctionInfo(__func__);
|
---|
| 3169 |
|
---|
| 3170 | // get closest points
|
---|
[97498a] | 3171 | DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
|
---|
[c15ca2] | 3172 | if (points == NULL) {
|
---|
| 3173 | eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
|
---|
[71b20e] | 3174 | return NULL;
|
---|
| 3175 | }
|
---|
[62bb91] | 3176 |
|
---|
[71b20e] | 3177 | // for each point, check its lines, remember closest
|
---|
| 3178 | Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl;
|
---|
| 3179 | BoundaryLineSet *ClosestLine = NULL;
|
---|
| 3180 | double MinDistance = -1.;
|
---|
| 3181 | Vector helper;
|
---|
| 3182 | Vector Center;
|
---|
| 3183 | Vector BaseLine;
|
---|
[97498a] | 3184 | for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
|
---|
[c15ca2] | 3185 | for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
|
---|
[71b20e] | 3186 | // calculate closest point on line to desired point
|
---|
| 3187 | helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
|
---|
| 3188 | helper.AddVector((LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3189 | helper.Scale(0.5);
|
---|
| 3190 | Center.CopyVector(x);
|
---|
| 3191 | Center.SubtractVector(&helper);
|
---|
| 3192 | BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
|
---|
| 3193 | BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3194 | Center.ProjectOntoPlane(&BaseLine);
|
---|
| 3195 | const double distance = Center.NormSquared();
|
---|
| 3196 | if ((ClosestLine == NULL) || (distance < MinDistance)) {
|
---|
| 3197 | // additionally calculate intersection on line (whether it's on the line section or not)
|
---|
| 3198 | helper.CopyVector(x);
|
---|
| 3199 | helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
|
---|
| 3200 | helper.SubtractVector(&Center);
|
---|
| 3201 | const double lengthA = helper.ScalarProduct(&BaseLine);
|
---|
| 3202 | helper.CopyVector(x);
|
---|
| 3203 | helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3204 | helper.SubtractVector(&Center);
|
---|
| 3205 | const double lengthB = helper.ScalarProduct(&BaseLine);
|
---|
| 3206 | if (lengthB*lengthA < 0) { // if have different sign
|
---|
| 3207 | ClosestLine = LineRunner->second;
|
---|
| 3208 | MinDistance = distance;
|
---|
| 3209 | Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl;
|
---|
| 3210 | } else {
|
---|
| 3211 | Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl;
|
---|
| 3212 | }
|
---|
| 3213 | } else {
|
---|
| 3214 | Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl;
|
---|
| 3215 | }
|
---|
[99593f] | 3216 | }
|
---|
[57066a] | 3217 | }
|
---|
[c15ca2] | 3218 | delete(points);
|
---|
[71b20e] | 3219 | // check whether closest line is "too close" :), then it's inside
|
---|
| 3220 | if (ClosestLine == NULL) {
|
---|
| 3221 | Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
|
---|
[62bb91] | 3222 | return NULL;
|
---|
[71b20e] | 3223 | }
|
---|
[c15ca2] | 3224 | return ClosestLine;
|
---|
| 3225 | };
|
---|
| 3226 |
|
---|
| 3227 | /** Finds the triangle that is closest to a given Vector \a *x.
|
---|
| 3228 | * \param *out output stream for debugging
|
---|
| 3229 | * \param *x Vector to look from
|
---|
| 3230 | * \return BoundaryTriangleSet of nearest triangle or NULL.
|
---|
| 3231 | */
|
---|
| 3232 | TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
|
---|
| 3233 | {
|
---|
| 3234 | Info FunctionInfo(__func__);
|
---|
| 3235 |
|
---|
| 3236 | // get closest points
|
---|
[97498a] | 3237 | DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC);
|
---|
[c15ca2] | 3238 | if (points == NULL) {
|
---|
| 3239 | eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;
|
---|
| 3240 | return NULL;
|
---|
| 3241 | }
|
---|
| 3242 |
|
---|
| 3243 | // for each point, check its lines, remember closest
|
---|
| 3244 | Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl;
|
---|
[48b47a] | 3245 | LineSet ClosestLines;
|
---|
[97498a] | 3246 | double MinDistance = 1e+16;
|
---|
| 3247 | Vector BaseLineIntersection;
|
---|
[c15ca2] | 3248 | Vector Center;
|
---|
| 3249 | Vector BaseLine;
|
---|
[97498a] | 3250 | Vector BaseLineCenter;
|
---|
| 3251 | for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
|
---|
[c15ca2] | 3252 | for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
|
---|
[97498a] | 3253 |
|
---|
| 3254 | BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
|
---|
| 3255 | BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3256 | const double lengthBase = BaseLine.NormSquared();
|
---|
| 3257 |
|
---|
| 3258 | BaseLineIntersection.CopyVector(x);
|
---|
| 3259 | BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
|
---|
| 3260 | const double lengthEndA = BaseLineIntersection.NormSquared();
|
---|
| 3261 |
|
---|
| 3262 | BaseLineIntersection.CopyVector(x);
|
---|
| 3263 | BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3264 | const double lengthEndB = BaseLineIntersection.NormSquared();
|
---|
| 3265 |
|
---|
| 3266 | if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
|
---|
[48b47a] | 3267 | const double lengthEnd = Min(lengthEndA, lengthEndB);
|
---|
| 3268 | if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
|
---|
| 3269 | ClosestLines.clear();
|
---|
| 3270 | ClosestLines.insert(LineRunner->second);
|
---|
| 3271 | MinDistance = lengthEnd;
|
---|
| 3272 | Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl;
|
---|
| 3273 | } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
|
---|
| 3274 | ClosestLines.insert(LineRunner->second);
|
---|
| 3275 | Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl;
|
---|
| 3276 | } else { // line is worse
|
---|
[97498a] | 3277 | 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;
|
---|
| 3278 | }
|
---|
| 3279 | } else { // intersection is closer, calculate
|
---|
[c15ca2] | 3280 | // calculate closest point on line to desired point
|
---|
[97498a] | 3281 | BaseLineIntersection.CopyVector(x);
|
---|
| 3282 | BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3283 | Center.CopyVector(&BaseLineIntersection);
|
---|
[c15ca2] | 3284 | Center.ProjectOntoPlane(&BaseLine);
|
---|
[97498a] | 3285 | BaseLineIntersection.SubtractVector(&Center);
|
---|
| 3286 | const double distance = BaseLineIntersection.NormSquared();
|
---|
| 3287 | if (Center.NormSquared() > BaseLine.NormSquared()) {
|
---|
| 3288 | eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl;
|
---|
| 3289 | }
|
---|
[48b47a] | 3290 | if ((ClosestLines.empty()) || (distance < MinDistance)) {
|
---|
| 3291 | ClosestLines.insert(LineRunner->second);
|
---|
[97498a] | 3292 | MinDistance = distance;
|
---|
[48b47a] | 3293 | Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl;
|
---|
[c15ca2] | 3294 | } else {
|
---|
[97498a] | 3295 | Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl;
|
---|
[c15ca2] | 3296 | }
|
---|
| 3297 | }
|
---|
| 3298 | }
|
---|
| 3299 | }
|
---|
| 3300 | delete(points);
|
---|
| 3301 |
|
---|
| 3302 | // check whether closest line is "too close" :), then it's inside
|
---|
[48b47a] | 3303 | if (ClosestLines.empty()) {
|
---|
[c15ca2] | 3304 | Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
|
---|
| 3305 | return NULL;
|
---|
| 3306 | }
|
---|
| 3307 | TriangleList * candidates = new TriangleList;
|
---|
[48b47a] | 3308 | for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
|
---|
| 3309 | for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
|
---|
[c15ca2] | 3310 | candidates->push_back(Runner->second);
|
---|
[71b20e] | 3311 | }
|
---|
[c15ca2] | 3312 | return candidates;
|
---|
[62bb91] | 3313 | };
|
---|
| 3314 |
|
---|
| 3315 | /** Finds closest triangle to a point.
|
---|
| 3316 | * This basically just takes care of the degenerate case, which is not handled in FindClosestTrianglesToPoint().
|
---|
| 3317 | * \param *out output stream for debugging
|
---|
| 3318 | * \param *x Vector to look from
|
---|
[8db598] | 3319 | * \param &distance contains found distance on return
|
---|
[62bb91] | 3320 | * \return list of BoundaryTriangleSet of nearest triangles or NULL.
|
---|
| 3321 | */
|
---|
[c15ca2] | 3322 | class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 3323 | {
|
---|
[f67b6e] | 3324 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 3325 | class BoundaryTriangleSet *result = NULL;
|
---|
[c15ca2] | 3326 | TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
|
---|
| 3327 | TriangleList candidates;
|
---|
[57066a] | 3328 | Vector Center;
|
---|
[71b20e] | 3329 | Vector helper;
|
---|
[62bb91] | 3330 |
|
---|
[71b20e] | 3331 | if ((triangles == NULL) || (triangles->empty()))
|
---|
[62bb91] | 3332 | return NULL;
|
---|
| 3333 |
|
---|
[97498a] | 3334 | // go through all and pick the one with the best alignment to x
|
---|
| 3335 | double MinAlignment = 2.*M_PI;
|
---|
[c15ca2] | 3336 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
|
---|
[71b20e] | 3337 | (*Runner)->GetCenter(&Center);
|
---|
| 3338 | helper.CopyVector(x);
|
---|
| 3339 | helper.SubtractVector(&Center);
|
---|
[97498a] | 3340 | const double Alignment = helper.Angle(&(*Runner)->NormalVector);
|
---|
| 3341 | if (Alignment < MinAlignment) {
|
---|
| 3342 | result = *Runner;
|
---|
| 3343 | MinAlignment = Alignment;
|
---|
| 3344 | Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl;
|
---|
[71b20e] | 3345 | } else {
|
---|
[97498a] | 3346 | Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl;
|
---|
[57066a] | 3347 | }
|
---|
| 3348 | }
|
---|
[97498a] | 3349 | delete(triangles);
|
---|
| 3350 |
|
---|
[62bb91] | 3351 | return result;
|
---|
| 3352 | };
|
---|
| 3353 |
|
---|
[9473f6] | 3354 | /** Checks whether the provided Vector is within the Tesselation structure.
|
---|
| 3355 | * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value.
|
---|
| 3356 | * @param point of which to check the position
|
---|
| 3357 | * @param *LC LinkedCell structure
|
---|
| 3358 | *
|
---|
| 3359 | * @return true if the point is inside the Tesselation structure, false otherwise
|
---|
| 3360 | */
|
---|
| 3361 | bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
|
---|
| 3362 | {
|
---|
[8db598] | 3363 | Info FunctionInfo(__func__);
|
---|
| 3364 | TriangleIntersectionList Intersections(&Point,this,LC);
|
---|
| 3365 |
|
---|
| 3366 | return Intersections.IsInside();
|
---|
| 3367 | };
|
---|
[9473f6] | 3368 |
|
---|
| 3369 | /** Returns the distance to the surface given by the tesselation.
|
---|
[97498a] | 3370 | * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points
|
---|
[9473f6] | 3371 | * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the
|
---|
| 3372 | * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's
|
---|
| 3373 | * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle().
|
---|
| 3374 | * In the end we additionally find the point on the triangle who was smallest distance to \a Point:
|
---|
| 3375 | * -# Separate distance from point to center in vector in NormalDirection and on the triangle plane.
|
---|
| 3376 | * -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds.
|
---|
| 3377 | * -# If inside, take it to calculate closest distance
|
---|
| 3378 | * -# If not, take intersection with BoundaryLine as distance
|
---|
| 3379 | *
|
---|
| 3380 | * @note distance is squared despite it still contains a sign to determine in-/outside!
|
---|
[62bb91] | 3381 | *
|
---|
| 3382 | * @param point of which to check the position
|
---|
| 3383 | * @param *LC LinkedCell structure
|
---|
| 3384 | *
|
---|
[244a84] | 3385 | * @return >0 if outside, ==0 if on surface, <0 if inside
|
---|
[62bb91] | 3386 | */
|
---|
[244a84] | 3387 | double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
|
---|
[62bb91] | 3388 | {
|
---|
[fcad4b] | 3389 | Info FunctionInfo(__func__);
|
---|
[57066a] | 3390 | Vector Center;
|
---|
[71b20e] | 3391 | Vector helper;
|
---|
[97498a] | 3392 | Vector DistanceToCenter;
|
---|
| 3393 | Vector Intersection;
|
---|
[9473f6] | 3394 | double distance = 0.;
|
---|
[57066a] | 3395 |
|
---|
[244a84] | 3396 | if (triangle == NULL) {// is boundary point or only point in point cloud?
|
---|
| 3397 | Log() << Verbose(1) << "No triangle given!" << endl;
|
---|
| 3398 | return -1.;
|
---|
[71b20e] | 3399 | } else {
|
---|
[244a84] | 3400 | Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl;
|
---|
[57066a] | 3401 | }
|
---|
| 3402 |
|
---|
[244a84] | 3403 | triangle->GetCenter(&Center);
|
---|
[f67b6e] | 3404 | Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
|
---|
[97498a] | 3405 | DistanceToCenter.CopyVector(&Center);
|
---|
| 3406 | DistanceToCenter.SubtractVector(&Point);
|
---|
[fcad4b] | 3407 | Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl;
|
---|
[97498a] | 3408 |
|
---|
| 3409 | // check whether we are on boundary
|
---|
[244a84] | 3410 | if (fabs(DistanceToCenter.ScalarProduct(&triangle->NormalVector)) < MYEPSILON) {
|
---|
[97498a] | 3411 | // calculate whether inside of triangle
|
---|
[fcad4b] | 3412 | DistanceToCenter.CopyVector(&Point);
|
---|
| 3413 | Center.CopyVector(&Point);
|
---|
[244a84] | 3414 | Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
|
---|
| 3415 | DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
|
---|
[97498a] | 3416 | Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl;
|
---|
[244a84] | 3417 | if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
|
---|
[97498a] | 3418 | Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl;
|
---|
[9473f6] | 3419 | return 0.;
|
---|
[97498a] | 3420 | } else {
|
---|
| 3421 | Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl;
|
---|
| 3422 | return false;
|
---|
| 3423 | }
|
---|
[57066a] | 3424 | } else {
|
---|
[9473f6] | 3425 | // calculate smallest distance
|
---|
[244a84] | 3426 | distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
|
---|
[9473f6] | 3427 | Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl;
|
---|
| 3428 |
|
---|
| 3429 | // then check direction to boundary
|
---|
[244a84] | 3430 | if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
|
---|
[9473f6] | 3431 | Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl;
|
---|
| 3432 | return -distance;
|
---|
| 3433 | } else {
|
---|
| 3434 | Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl;
|
---|
| 3435 | return +distance;
|
---|
| 3436 | }
|
---|
[57066a] | 3437 | }
|
---|
[9473f6] | 3438 | };
|
---|
[62bb91] | 3439 |
|
---|
[8db598] | 3440 | /** Calculates minimum distance from \a&Point to a tesselated surface.
|
---|
[244a84] | 3441 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
|
---|
| 3442 | * \param &Point point to calculate distance from
|
---|
| 3443 | * \param *LC needed for finding closest points fast
|
---|
| 3444 | * \return distance squared to closest point on surface
|
---|
| 3445 | */
|
---|
[8db598] | 3446 | double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const
|
---|
[244a84] | 3447 | {
|
---|
[8db598] | 3448 | Info FunctionInfo(__func__);
|
---|
| 3449 | TriangleIntersectionList Intersections(&Point,this,LC);
|
---|
| 3450 |
|
---|
| 3451 | return Intersections.GetSmallestDistance();
|
---|
| 3452 | };
|
---|
| 3453 |
|
---|
| 3454 | /** Calculates minimum distance from \a&Point to a tesselated surface.
|
---|
| 3455 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
|
---|
| 3456 | * \param &Point point to calculate distance from
|
---|
| 3457 | * \param *LC needed for finding closest points fast
|
---|
| 3458 | * \return distance squared to closest point on surface
|
---|
| 3459 | */
|
---|
| 3460 | BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const
|
---|
| 3461 | {
|
---|
| 3462 | Info FunctionInfo(__func__);
|
---|
| 3463 | TriangleIntersectionList Intersections(&Point,this,LC);
|
---|
| 3464 |
|
---|
| 3465 | return Intersections.GetClosestTriangle();
|
---|
[244a84] | 3466 | };
|
---|
| 3467 |
|
---|
[62bb91] | 3468 | /** Gets all points connected to the provided point by triangulation lines.
|
---|
| 3469 | *
|
---|
| 3470 | * @param *Point of which get all connected points
|
---|
| 3471 | *
|
---|
[065e82] | 3472 | * @return set of the all points linked to the provided one
|
---|
[62bb91] | 3473 | */
|
---|
[c15ca2] | 3474 | TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
|
---|
[62bb91] | 3475 | {
|
---|
[f67b6e] | 3476 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 3477 | TesselPointSet *connectedPoints = new TesselPointSet;
|
---|
[5c7bf8] | 3478 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
[62bb91] | 3479 | TesselPoint* current;
|
---|
| 3480 | bool takePoint = false;
|
---|
| 3481 |
|
---|
[5c7bf8] | 3482 | // find the respective boundary point
|
---|
[776b64] | 3483 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[5c7bf8] | 3484 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 3485 | ReferencePoint = PointRunner->second;
|
---|
| 3486 | } else {
|
---|
[f67b6e] | 3487 | eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
|
---|
[5c7bf8] | 3488 | ReferencePoint = NULL;
|
---|
| 3489 | }
|
---|
[62bb91] | 3490 |
|
---|
[065e82] | 3491 | // little trick so that we look just through lines connect to the BoundaryPoint
|
---|
[5c7bf8] | 3492 | // OR fall-back to look through all lines if there is no such BoundaryPoint
|
---|
[776b64] | 3493 | const LineMap *Lines;;
|
---|
[5c7bf8] | 3494 | if (ReferencePoint != NULL)
|
---|
| 3495 | Lines = &(ReferencePoint->lines);
|
---|
[776b64] | 3496 | else
|
---|
| 3497 | Lines = &LinesOnBoundary;
|
---|
| 3498 | LineMap::const_iterator findLines = Lines->begin();
|
---|
[5c7bf8] | 3499 | while (findLines != Lines->end()) {
|
---|
[065e82] | 3500 | takePoint = false;
|
---|
| 3501 |
|
---|
| 3502 | if (findLines->second->endpoints[0]->Nr == Point->nr) {
|
---|
| 3503 | takePoint = true;
|
---|
| 3504 | current = findLines->second->endpoints[1]->node;
|
---|
| 3505 | } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
|
---|
| 3506 | takePoint = true;
|
---|
| 3507 | current = findLines->second->endpoints[0]->node;
|
---|
| 3508 | }
|
---|
| 3509 |
|
---|
| 3510 | if (takePoint) {
|
---|
[f67b6e] | 3511 | Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
|
---|
[065e82] | 3512 | connectedPoints->insert(current);
|
---|
| 3513 | }
|
---|
[62bb91] | 3514 |
|
---|
[065e82] | 3515 | findLines++;
|
---|
[62bb91] | 3516 | }
|
---|
| 3517 |
|
---|
[71b20e] | 3518 | if (connectedPoints->empty()) { // if have not found any points
|
---|
[717e0c] | 3519 | eLog() << Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl;
|
---|
[16d866] | 3520 | return NULL;
|
---|
| 3521 | }
|
---|
[065e82] | 3522 |
|
---|
[16d866] | 3523 | return connectedPoints;
|
---|
[065e82] | 3524 | };
|
---|
[16d866] | 3525 |
|
---|
[065e82] | 3526 |
|
---|
| 3527 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
[16d866] | 3528 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 3529 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 3530 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 3531 | * triangle we are looking for.
|
---|
| 3532 | *
|
---|
| 3533 | * @param *out output stream for debugging
|
---|
[27bd2f] | 3534 | * @param *SetOfNeighbours all points for which the angle should be calculated
|
---|
[16d866] | 3535 | * @param *Point of which get all connected points
|
---|
[065e82] | 3536 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 3537 | * @return list of the all points linked to the provided one
|
---|
[16d866] | 3538 | */
|
---|
[c15ca2] | 3539 | TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[16d866] | 3540 | {
|
---|
[f67b6e] | 3541 | Info FunctionInfo(__func__);
|
---|
[16d866] | 3542 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3543 | TesselPointList *connectedCircle = new TesselPointList;
|
---|
[71b20e] | 3544 | Vector PlaneNormal;
|
---|
| 3545 | Vector AngleZero;
|
---|
| 3546 | Vector OrthogonalVector;
|
---|
| 3547 | Vector helper;
|
---|
| 3548 | const TesselPoint * const TrianglePoints[3] = {Point, NULL, NULL};
|
---|
[c15ca2] | 3549 | TriangleList *triangles = NULL;
|
---|
[71b20e] | 3550 |
|
---|
| 3551 | if (SetOfNeighbours == NULL) {
|
---|
| 3552 | eLog() << Verbose(2) << "Could not find any connected points!" << endl;
|
---|
| 3553 | delete(connectedCircle);
|
---|
| 3554 | return NULL;
|
---|
| 3555 | }
|
---|
| 3556 |
|
---|
| 3557 | // calculate central point
|
---|
| 3558 | triangles = FindTriangles(TrianglePoints);
|
---|
| 3559 | if ((triangles != NULL) && (!triangles->empty())) {
|
---|
[c15ca2] | 3560 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
|
---|
[71b20e] | 3561 | PlaneNormal.AddVector(&(*Runner)->NormalVector);
|
---|
| 3562 | } else {
|
---|
| 3563 | eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl;
|
---|
| 3564 | performCriticalExit();
|
---|
| 3565 | }
|
---|
| 3566 | PlaneNormal.Scale(1.0/triangles->size());
|
---|
| 3567 | Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl;
|
---|
| 3568 | PlaneNormal.Normalize();
|
---|
| 3569 |
|
---|
| 3570 | // construct one orthogonal vector
|
---|
| 3571 | if (Reference != NULL) {
|
---|
| 3572 | AngleZero.CopyVector(Reference);
|
---|
| 3573 | AngleZero.SubtractVector(Point->node);
|
---|
| 3574 | AngleZero.ProjectOntoPlane(&PlaneNormal);
|
---|
| 3575 | }
|
---|
| 3576 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
|
---|
| 3577 | Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
|
---|
| 3578 | AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
|
---|
| 3579 | AngleZero.SubtractVector(Point->node);
|
---|
| 3580 | AngleZero.ProjectOntoPlane(&PlaneNormal);
|
---|
| 3581 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
| 3582 | eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
|
---|
| 3583 | performCriticalExit();
|
---|
| 3584 | }
|
---|
| 3585 | }
|
---|
| 3586 | Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
|
---|
| 3587 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
| 3588 | OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
|
---|
| 3589 | else
|
---|
| 3590 | OrthogonalVector.MakeNormalVector(&PlaneNormal);
|
---|
| 3591 | Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
|
---|
| 3592 |
|
---|
| 3593 | // go through all connected points and calculate angle
|
---|
[c15ca2] | 3594 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
|
---|
[71b20e] | 3595 | helper.CopyVector((*listRunner)->node);
|
---|
| 3596 | helper.SubtractVector(Point->node);
|
---|
| 3597 | helper.ProjectOntoPlane(&PlaneNormal);
|
---|
| 3598 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
| 3599 | Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
|
---|
| 3600 | anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
|
---|
| 3601 | }
|
---|
| 3602 |
|
---|
| 3603 | for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
| 3604 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 3605 | }
|
---|
| 3606 |
|
---|
| 3607 | return connectedCircle;
|
---|
| 3608 | }
|
---|
| 3609 |
|
---|
| 3610 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
| 3611 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 3612 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 3613 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 3614 | * triangle we are looking for.
|
---|
| 3615 | *
|
---|
| 3616 | * @param *SetOfNeighbours all points for which the angle should be calculated
|
---|
| 3617 | * @param *Point of which get all connected points
|
---|
| 3618 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 3619 | * @return list of the all points linked to the provided one
|
---|
| 3620 | */
|
---|
[c15ca2] | 3621 | TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[71b20e] | 3622 | {
|
---|
| 3623 | Info FunctionInfo(__func__);
|
---|
| 3624 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3625 | TesselPointList *connectedCircle = new TesselPointList;
|
---|
[065e82] | 3626 | Vector center;
|
---|
| 3627 | Vector PlaneNormal;
|
---|
| 3628 | Vector AngleZero;
|
---|
| 3629 | Vector OrthogonalVector;
|
---|
| 3630 | Vector helper;
|
---|
[62bb91] | 3631 |
|
---|
[27bd2f] | 3632 | if (SetOfNeighbours == NULL) {
|
---|
[f67b6e] | 3633 | eLog() << Verbose(2) << "Could not find any connected points!" << endl;
|
---|
[99593f] | 3634 | delete(connectedCircle);
|
---|
| 3635 | return NULL;
|
---|
| 3636 | }
|
---|
[a2028e] | 3637 |
|
---|
[97498a] | 3638 | // check whether there's something to do
|
---|
| 3639 | if (SetOfNeighbours->size() < 3) {
|
---|
| 3640 | for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
|
---|
| 3641 | connectedCircle->push_back(*TesselRunner);
|
---|
| 3642 | return connectedCircle;
|
---|
| 3643 | }
|
---|
| 3644 |
|
---|
| 3645 | Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl;
|
---|
[16d866] | 3646 | // calculate central point
|
---|
[5c7bf8] | 3647 |
|
---|
[97498a] | 3648 | TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
|
---|
| 3649 | TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
|
---|
| 3650 | TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin();
|
---|
| 3651 | TesselB++;
|
---|
| 3652 | TesselC++;
|
---|
| 3653 | TesselC++;
|
---|
| 3654 | int counter = 0;
|
---|
| 3655 | while (TesselC != SetOfNeighbours->end()) {
|
---|
| 3656 | helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
|
---|
| 3657 | Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl;
|
---|
| 3658 | counter++;
|
---|
| 3659 | TesselA++;
|
---|
| 3660 | TesselB++;
|
---|
| 3661 | TesselC++;
|
---|
| 3662 | PlaneNormal.AddVector(&helper);
|
---|
| 3663 | }
|
---|
| 3664 | //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
|
---|
| 3665 | // << "; scale factor " << counter;
|
---|
| 3666 | PlaneNormal.Scale(1.0/(double)counter);
|
---|
| 3667 | // Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
|
---|
| 3668 | //
|
---|
| 3669 | // // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
|
---|
| 3670 | // PlaneNormal.CopyVector(Point->node);
|
---|
| 3671 | // PlaneNormal.SubtractVector(¢er);
|
---|
| 3672 | // PlaneNormal.Normalize();
|
---|
[f67b6e] | 3673 | Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
|
---|
[62bb91] | 3674 |
|
---|
| 3675 | // construct one orthogonal vector
|
---|
[a2028e] | 3676 | if (Reference != NULL) {
|
---|
[065e82] | 3677 | AngleZero.CopyVector(Reference);
|
---|
[a2028e] | 3678 | AngleZero.SubtractVector(Point->node);
|
---|
| 3679 | AngleZero.ProjectOntoPlane(&PlaneNormal);
|
---|
| 3680 | }
|
---|
| 3681 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
|
---|
[27bd2f] | 3682 | Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;
|
---|
| 3683 | AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
|
---|
[a2028e] | 3684 | AngleZero.SubtractVector(Point->node);
|
---|
| 3685 | AngleZero.ProjectOntoPlane(&PlaneNormal);
|
---|
| 3686 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
[e138de] | 3687 | eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
|
---|
[a2028e] | 3688 | performCriticalExit();
|
---|
| 3689 | }
|
---|
| 3690 | }
|
---|
[f67b6e] | 3691 | Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
|
---|
[a2028e] | 3692 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
| 3693 | OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
|
---|
| 3694 | else
|
---|
| 3695 | OrthogonalVector.MakeNormalVector(&PlaneNormal);
|
---|
[f67b6e] | 3696 | Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
|
---|
[16d866] | 3697 |
|
---|
[5c7bf8] | 3698 | // go through all connected points and calculate angle
|
---|
[c15ca2] | 3699 | pair <map<double, TesselPoint*>::iterator, bool > InserterTest;
|
---|
| 3700 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
|
---|
[5c7bf8] | 3701 | helper.CopyVector((*listRunner)->node);
|
---|
| 3702 | helper.SubtractVector(Point->node);
|
---|
| 3703 | helper.ProjectOntoPlane(&PlaneNormal);
|
---|
[f1cccd] | 3704 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
[97498a] | 3705 | if (angle > M_PI) // the correction is of no use here (and not desired)
|
---|
| 3706 | angle = 2.*M_PI - angle;
|
---|
[c15ca2] | 3707 | Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl;
|
---|
| 3708 | InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
|
---|
| 3709 | if (!InserterTest.second) {
|
---|
| 3710 | eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl;
|
---|
| 3711 | performCriticalExit();
|
---|
| 3712 | }
|
---|
[62bb91] | 3713 | }
|
---|
| 3714 |
|
---|
[065e82] | 3715 | for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
| 3716 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 3717 | }
|
---|
[62bb91] | 3718 |
|
---|
[065e82] | 3719 | return connectedCircle;
|
---|
| 3720 | }
|
---|
[62bb91] | 3721 |
|
---|
[065e82] | 3722 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path.
|
---|
| 3723 | *
|
---|
| 3724 | * @param *out output stream for debugging
|
---|
| 3725 | * @param *Point of which get all connected points
|
---|
| 3726 | * @return list of the all points linked to the provided one
|
---|
| 3727 | */
|
---|
[244a84] | 3728 | ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 3729 | {
|
---|
[f67b6e] | 3730 | Info FunctionInfo(__func__);
|
---|
[065e82] | 3731 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3732 | list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;
|
---|
| 3733 | TesselPointList *connectedPath = NULL;
|
---|
[065e82] | 3734 | Vector center;
|
---|
| 3735 | Vector PlaneNormal;
|
---|
| 3736 | Vector AngleZero;
|
---|
| 3737 | Vector OrthogonalVector;
|
---|
| 3738 | Vector helper;
|
---|
| 3739 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
| 3740 | class BoundaryPointSet *CurrentPoint = NULL;
|
---|
| 3741 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 3742 | class BoundaryLineSet *CurrentLine = NULL;
|
---|
| 3743 | class BoundaryLineSet *StartLine = NULL;
|
---|
| 3744 |
|
---|
| 3745 | // find the respective boundary point
|
---|
[776b64] | 3746 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[065e82] | 3747 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 3748 | ReferencePoint = PointRunner->second;
|
---|
| 3749 | } else {
|
---|
[717e0c] | 3750 | eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
|
---|
[065e82] | 3751 | return NULL;
|
---|
| 3752 | }
|
---|
| 3753 |
|
---|
[57066a] | 3754 | map <class BoundaryLineSet *, bool> TouchedLine;
|
---|
| 3755 | map <class BoundaryTriangleSet *, bool> TouchedTriangle;
|
---|
| 3756 | map <class BoundaryLineSet *, bool>::iterator LineRunner;
|
---|
| 3757 | map <class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
|
---|
| 3758 | for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
|
---|
| 3759 | TouchedLine.insert( pair <class BoundaryLineSet *, bool>(Runner->second, false) );
|
---|
| 3760 | for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
|
---|
| 3761 | TouchedTriangle.insert( pair <class BoundaryTriangleSet *, bool>(Sprinter->second, false) );
|
---|
| 3762 | }
|
---|
[065e82] | 3763 | if (!ReferencePoint->lines.empty()) {
|
---|
| 3764 | for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) {
|
---|
[57066a] | 3765 | LineRunner = TouchedLine.find(runner->second);
|
---|
| 3766 | if (LineRunner == TouchedLine.end()) {
|
---|
[717e0c] | 3767 | eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl;
|
---|
[57066a] | 3768 | } else if (!LineRunner->second) {
|
---|
| 3769 | LineRunner->second = true;
|
---|
[c15ca2] | 3770 | connectedPath = new TesselPointList;
|
---|
[065e82] | 3771 | triangle = NULL;
|
---|
| 3772 | CurrentLine = runner->second;
|
---|
| 3773 | StartLine = CurrentLine;
|
---|
| 3774 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
[f67b6e] | 3775 | Log() << Verbose(1)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
|
---|
[065e82] | 3776 | do {
|
---|
| 3777 | // push current one
|
---|
[f67b6e] | 3778 | Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
|
---|
[065e82] | 3779 | connectedPath->push_back(CurrentPoint->node);
|
---|
| 3780 |
|
---|
| 3781 | // find next triangle
|
---|
[57066a] | 3782 | for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
|
---|
[f67b6e] | 3783 | Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
|
---|
[57066a] | 3784 | if ((Runner->second != triangle)) { // look for first triangle not equal to old one
|
---|
| 3785 | triangle = Runner->second;
|
---|
| 3786 | TriangleRunner = TouchedTriangle.find(triangle);
|
---|
| 3787 | if (TriangleRunner != TouchedTriangle.end()) {
|
---|
| 3788 | if (!TriangleRunner->second) {
|
---|
| 3789 | TriangleRunner->second = true;
|
---|
[f67b6e] | 3790 | Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl;
|
---|
[57066a] | 3791 | break;
|
---|
| 3792 | } else {
|
---|
[f67b6e] | 3793 | Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
|
---|
[57066a] | 3794 | triangle = NULL;
|
---|
| 3795 | }
|
---|
| 3796 | } else {
|
---|
[717e0c] | 3797 | eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl;
|
---|
[57066a] | 3798 | triangle = NULL;
|
---|
| 3799 | }
|
---|
[065e82] | 3800 | }
|
---|
| 3801 | }
|
---|
[57066a] | 3802 | if (triangle == NULL)
|
---|
| 3803 | break;
|
---|
[065e82] | 3804 | // find next line
|
---|
| 3805 | for (int i=0;i<3;i++) {
|
---|
| 3806 | if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
|
---|
| 3807 | CurrentLine = triangle->lines[i];
|
---|
[f67b6e] | 3808 | Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
|
---|
[065e82] | 3809 | break;
|
---|
| 3810 | }
|
---|
| 3811 | }
|
---|
[57066a] | 3812 | LineRunner = TouchedLine.find(CurrentLine);
|
---|
| 3813 | if (LineRunner == TouchedLine.end())
|
---|
[717e0c] | 3814 | eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl;
|
---|
[065e82] | 3815 | else
|
---|
[57066a] | 3816 | LineRunner->second = true;
|
---|
[065e82] | 3817 | // find next point
|
---|
| 3818 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
| 3819 |
|
---|
| 3820 | } while (CurrentLine != StartLine);
|
---|
| 3821 | // last point is missing, as it's on start line
|
---|
[f67b6e] | 3822 | Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
|
---|
[57066a] | 3823 | if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
|
---|
| 3824 | connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
|
---|
[065e82] | 3825 |
|
---|
| 3826 | ListOfPaths->push_back(connectedPath);
|
---|
| 3827 | } else {
|
---|
[f67b6e] | 3828 | Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
|
---|
[065e82] | 3829 | }
|
---|
| 3830 | }
|
---|
| 3831 | } else {
|
---|
[717e0c] | 3832 | eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl;
|
---|
[065e82] | 3833 | }
|
---|
| 3834 |
|
---|
| 3835 | return ListOfPaths;
|
---|
[62bb91] | 3836 | }
|
---|
| 3837 |
|
---|
[065e82] | 3838 | /** Gets all closed paths on the circle of points connected to the provided point by triangulation lines, if this very point is removed.
|
---|
| 3839 | * From GetPathsOfConnectedPoints() extracts all single loops of intracrossing paths in the list of closed paths.
|
---|
| 3840 | * @param *out output stream for debugging
|
---|
| 3841 | * @param *Point of which get all connected points
|
---|
| 3842 | * @return list of the closed paths
|
---|
| 3843 | */
|
---|
[244a84] | 3844 | ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 3845 | {
|
---|
[f67b6e] | 3846 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 3847 | list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
|
---|
| 3848 | list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *>;
|
---|
| 3849 | TesselPointList *connectedPath = NULL;
|
---|
| 3850 | TesselPointList *newPath = NULL;
|
---|
[065e82] | 3851 | int count = 0;
|
---|
| 3852 |
|
---|
| 3853 |
|
---|
[c15ca2] | 3854 | TesselPointList::iterator CircleRunner;
|
---|
| 3855 | TesselPointList::iterator CircleStart;
|
---|
[065e82] | 3856 |
|
---|
[c15ca2] | 3857 | for(list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
|
---|
[065e82] | 3858 | connectedPath = *ListRunner;
|
---|
| 3859 |
|
---|
[f67b6e] | 3860 | Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl;
|
---|
[065e82] | 3861 |
|
---|
| 3862 | // go through list, look for reappearance of starting Point and count
|
---|
| 3863 | CircleStart = connectedPath->begin();
|
---|
| 3864 |
|
---|
| 3865 | // go through list, look for reappearance of starting Point and create list
|
---|
[c15ca2] | 3866 | TesselPointList::iterator Marker = CircleStart;
|
---|
[065e82] | 3867 | for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
|
---|
| 3868 | if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
|
---|
| 3869 | // we have a closed circle from Marker to new Marker
|
---|
[f67b6e] | 3870 | Log() << Verbose(1) << count+1 << ". closed path consists of: ";
|
---|
[c15ca2] | 3871 | newPath = new TesselPointList;
|
---|
| 3872 | TesselPointList::iterator CircleSprinter = Marker;
|
---|
[065e82] | 3873 | for (; CircleSprinter != CircleRunner; CircleSprinter++) {
|
---|
| 3874 | newPath->push_back(*CircleSprinter);
|
---|
[e138de] | 3875 | Log() << Verbose(0) << (**CircleSprinter) << " <-> ";
|
---|
[065e82] | 3876 | }
|
---|
[e138de] | 3877 | Log() << Verbose(0) << ".." << endl;
|
---|
[065e82] | 3878 | count++;
|
---|
| 3879 | Marker = CircleRunner;
|
---|
| 3880 |
|
---|
| 3881 | // add to list
|
---|
| 3882 | ListofClosedPaths->push_back(newPath);
|
---|
| 3883 | }
|
---|
| 3884 | }
|
---|
| 3885 | }
|
---|
[f67b6e] | 3886 | Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl;
|
---|
[065e82] | 3887 |
|
---|
| 3888 | // delete list of paths
|
---|
| 3889 | while (!ListofPaths->empty()) {
|
---|
| 3890 | connectedPath = *(ListofPaths->begin());
|
---|
| 3891 | ListofPaths->remove(connectedPath);
|
---|
| 3892 | delete(connectedPath);
|
---|
| 3893 | }
|
---|
| 3894 | delete(ListofPaths);
|
---|
| 3895 |
|
---|
| 3896 | // exit
|
---|
| 3897 | return ListofClosedPaths;
|
---|
| 3898 | };
|
---|
| 3899 |
|
---|
| 3900 |
|
---|
| 3901 | /** Gets all belonging triangles for a given BoundaryPointSet.
|
---|
| 3902 | * \param *out output stream for debugging
|
---|
| 3903 | * \param *Point BoundaryPoint
|
---|
| 3904 | * \return pointer to allocated list of triangles
|
---|
| 3905 | */
|
---|
[c15ca2] | 3906 | TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
|
---|
[065e82] | 3907 | {
|
---|
[f67b6e] | 3908 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 3909 | TriangleSet *connectedTriangles = new TriangleSet;
|
---|
[065e82] | 3910 |
|
---|
| 3911 | if (Point == NULL) {
|
---|
[717e0c] | 3912 | eLog() << Verbose(1) << "Point given is NULL." << endl;
|
---|
[065e82] | 3913 | } else {
|
---|
| 3914 | // go through its lines and insert all triangles
|
---|
[776b64] | 3915 | for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
|
---|
[065e82] | 3916 | for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
| 3917 | connectedTriangles->insert(TriangleRunner->second);
|
---|
| 3918 | }
|
---|
| 3919 | }
|
---|
| 3920 |
|
---|
| 3921 | return connectedTriangles;
|
---|
| 3922 | };
|
---|
| 3923 |
|
---|
| 3924 |
|
---|
[16d866] | 3925 | /** Removes a boundary point from the envelope while keeping it closed.
|
---|
[57066a] | 3926 | * We remove the old triangles connected to the point and re-create new triangles to close the surface following this ansatz:
|
---|
| 3927 | * -# a closed path(s) of boundary points surrounding the point to be removed is constructed
|
---|
| 3928 | * -# on each closed path, we pick three adjacent points, create a triangle with them and subtract the middle point from the path
|
---|
| 3929 | * -# we advance two points (i.e. the next triangle will start at the ending point of the last triangle) and continue as before
|
---|
| 3930 | * -# the surface is closed, when the path is empty
|
---|
| 3931 | * Thereby, we (hopefully) make sure that the removed points remains beneath the surface (this is checked via IsInnerPoint eventually).
|
---|
[16d866] | 3932 | * \param *out output stream for debugging
|
---|
| 3933 | * \param *point point to be removed
|
---|
| 3934 | * \return volume added to the volume inside the tesselated surface by the removal
|
---|
| 3935 | */
|
---|
[e138de] | 3936 | double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) {
|
---|
[16d866] | 3937 | class BoundaryLineSet *line = NULL;
|
---|
| 3938 | class BoundaryTriangleSet *triangle = NULL;
|
---|
[57066a] | 3939 | Vector OldPoint, NormalVector;
|
---|
[16d866] | 3940 | double volume = 0;
|
---|
| 3941 | int count = 0;
|
---|
| 3942 |
|
---|
[1d9b7aa] | 3943 | if (point == NULL) {
|
---|
[717e0c] | 3944 | eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl;
|
---|
[1d9b7aa] | 3945 | return 0.;
|
---|
| 3946 | } else
|
---|
[f67b6e] | 3947 | Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl;
|
---|
[1d9b7aa] | 3948 |
|
---|
[16d866] | 3949 | // copy old location for the volume
|
---|
| 3950 | OldPoint.CopyVector(point->node->node);
|
---|
| 3951 |
|
---|
| 3952 | // get list of connected points
|
---|
| 3953 | if (point->lines.empty()) {
|
---|
[717e0c] | 3954 | eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl;
|
---|
[16d866] | 3955 | return 0.;
|
---|
| 3956 | }
|
---|
| 3957 |
|
---|
[c15ca2] | 3958 | list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
|
---|
| 3959 | TesselPointList *connectedPath = NULL;
|
---|
[065e82] | 3960 |
|
---|
| 3961 | // gather all triangles
|
---|
[16d866] | 3962 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
|
---|
| 3963 | count+=LineRunner->second->triangles.size();
|
---|
[c15ca2] | 3964 | TriangleMap Candidates;
|
---|
[57066a] | 3965 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
|
---|
[16d866] | 3966 | line = LineRunner->second;
|
---|
| 3967 | for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
|
---|
| 3968 | triangle = TriangleRunner->second;
|
---|
[c15ca2] | 3969 | Candidates.insert( TrianglePair (triangle->Nr, triangle) );
|
---|
[16d866] | 3970 | }
|
---|
| 3971 | }
|
---|
| 3972 |
|
---|
[065e82] | 3973 | // remove all triangles
|
---|
| 3974 | count=0;
|
---|
[57066a] | 3975 | NormalVector.Zero();
|
---|
[c15ca2] | 3976 | for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
|
---|
| 3977 | Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl;
|
---|
| 3978 | NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
|
---|
| 3979 | RemoveTesselationTriangle(Runner->second);
|
---|
[065e82] | 3980 | count++;
|
---|
| 3981 | }
|
---|
[e138de] | 3982 | Log() << Verbose(1) << count << " triangles were removed." << endl;
|
---|
[065e82] | 3983 |
|
---|
[c15ca2] | 3984 | list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
|
---|
| 3985 | list<TesselPointList *>::iterator ListRunner = ListAdvance;
|
---|
| 3986 | TriangleMap::iterator NumberRunner = Candidates.begin();
|
---|
| 3987 | TesselPointList::iterator StartNode, MiddleNode, EndNode;
|
---|
[57066a] | 3988 | double angle;
|
---|
| 3989 | double smallestangle;
|
---|
| 3990 | Vector Point, Reference, OrthogonalVector;
|
---|
[065e82] | 3991 | if (count > 2) { // less than three triangles, then nothing will be created
|
---|
| 3992 | class TesselPoint *TriangleCandidates[3];
|
---|
| 3993 | count = 0;
|
---|
| 3994 | for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
|
---|
| 3995 | if (ListAdvance != ListOfClosedPaths->end())
|
---|
| 3996 | ListAdvance++;
|
---|
| 3997 |
|
---|
| 3998 | connectedPath = *ListRunner;
|
---|
| 3999 |
|
---|
| 4000 | // re-create all triangles by going through connected points list
|
---|
[c15ca2] | 4001 | LineList NewLines;
|
---|
[57066a] | 4002 | for (;!connectedPath->empty();) {
|
---|
| 4003 | // search middle node with widest angle to next neighbours
|
---|
| 4004 | EndNode = connectedPath->end();
|
---|
| 4005 | smallestangle = 0.;
|
---|
| 4006 | for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
|
---|
[f67b6e] | 4007 | Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
|
---|
[57066a] | 4008 | // construct vectors to next and previous neighbour
|
---|
| 4009 | StartNode = MiddleNode;
|
---|
| 4010 | if (StartNode == connectedPath->begin())
|
---|
| 4011 | StartNode = connectedPath->end();
|
---|
| 4012 | StartNode--;
|
---|
[e138de] | 4013 | //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl;
|
---|
[57066a] | 4014 | Point.CopyVector((*StartNode)->node);
|
---|
| 4015 | Point.SubtractVector((*MiddleNode)->node);
|
---|
| 4016 | StartNode = MiddleNode;
|
---|
| 4017 | StartNode++;
|
---|
| 4018 | if (StartNode == connectedPath->end())
|
---|
| 4019 | StartNode = connectedPath->begin();
|
---|
[e138de] | 4020 | //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl;
|
---|
[57066a] | 4021 | Reference.CopyVector((*StartNode)->node);
|
---|
| 4022 | Reference.SubtractVector((*MiddleNode)->node);
|
---|
| 4023 | OrthogonalVector.CopyVector((*MiddleNode)->node);
|
---|
| 4024 | OrthogonalVector.SubtractVector(&OldPoint);
|
---|
| 4025 | OrthogonalVector.MakeNormalVector(&Reference);
|
---|
| 4026 | angle = GetAngle(Point, Reference, OrthogonalVector);
|
---|
| 4027 | //if (angle < M_PI) // no wrong-sided triangles, please?
|
---|
| 4028 | if(fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
|
---|
| 4029 | smallestangle = angle;
|
---|
| 4030 | EndNode = MiddleNode;
|
---|
| 4031 | }
|
---|
| 4032 | }
|
---|
| 4033 | MiddleNode = EndNode;
|
---|
| 4034 | if (MiddleNode == connectedPath->end()) {
|
---|
[f67b6e] | 4035 | eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl;
|
---|
| 4036 | performCriticalExit();
|
---|
[57066a] | 4037 | }
|
---|
| 4038 | StartNode = MiddleNode;
|
---|
| 4039 | if (StartNode == connectedPath->begin())
|
---|
| 4040 | StartNode = connectedPath->end();
|
---|
| 4041 | StartNode--;
|
---|
| 4042 | EndNode++;
|
---|
| 4043 | if (EndNode == connectedPath->end())
|
---|
| 4044 | EndNode = connectedPath->begin();
|
---|
[f67b6e] | 4045 | Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl;
|
---|
| 4046 | Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
|
---|
| 4047 | Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl;
|
---|
| 4048 | Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;
|
---|
[57066a] | 4049 | TriangleCandidates[0] = *StartNode;
|
---|
| 4050 | TriangleCandidates[1] = *MiddleNode;
|
---|
| 4051 | TriangleCandidates[2] = *EndNode;
|
---|
[e138de] | 4052 | triangle = GetPresentTriangle(TriangleCandidates);
|
---|
[57066a] | 4053 | if (triangle != NULL) {
|
---|
[f67b6e] | 4054 | eLog() << Verbose(0) << "New triangle already present, skipping!" << endl;
|
---|
[57066a] | 4055 | StartNode++;
|
---|
| 4056 | MiddleNode++;
|
---|
| 4057 | EndNode++;
|
---|
| 4058 | if (StartNode == connectedPath->end())
|
---|
| 4059 | StartNode = connectedPath->begin();
|
---|
| 4060 | if (MiddleNode == connectedPath->end())
|
---|
| 4061 | MiddleNode = connectedPath->begin();
|
---|
| 4062 | if (EndNode == connectedPath->end())
|
---|
| 4063 | EndNode = connectedPath->begin();
|
---|
| 4064 | continue;
|
---|
| 4065 | }
|
---|
[f67b6e] | 4066 | Log() << Verbose(3) << "Adding new triangle points."<< endl;
|
---|
[57066a] | 4067 | AddTesselationPoint(*StartNode, 0);
|
---|
| 4068 | AddTesselationPoint(*MiddleNode, 1);
|
---|
| 4069 | AddTesselationPoint(*EndNode, 2);
|
---|
[f67b6e] | 4070 | Log() << Verbose(3) << "Adding new triangle lines."<< endl;
|
---|
[065e82] | 4071 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 4072 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
[57066a] | 4073 | NewLines.push_back(BLS[1]);
|
---|
[065e82] | 4074 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
| 4075 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[57066a] | 4076 | BTS->GetNormalVector(NormalVector);
|
---|
[065e82] | 4077 | AddTesselationTriangle();
|
---|
| 4078 | // calculate volume summand as a general tetraeder
|
---|
[c0f6c6] | 4079 | volume += CalculateVolumeofGeneralTetraeder(*TPS[0]->node->node, *TPS[1]->node->node, *TPS[2]->node->node, OldPoint);
|
---|
[065e82] | 4080 | // advance number
|
---|
| 4081 | count++;
|
---|
[57066a] | 4082 |
|
---|
| 4083 | // prepare nodes for next triangle
|
---|
| 4084 | StartNode = EndNode;
|
---|
[f67b6e] | 4085 | Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
|
---|
[57066a] | 4086 | connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
|
---|
| 4087 | if (connectedPath->size() == 2) { // we are done
|
---|
| 4088 | connectedPath->remove(*StartNode); // remove the start node
|
---|
| 4089 | connectedPath->remove(*EndNode); // remove the end node
|
---|
| 4090 | break;
|
---|
| 4091 | } else if (connectedPath->size() < 2) { // something's gone wrong!
|
---|
[f67b6e] | 4092 | eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl;
|
---|
| 4093 | performCriticalExit();
|
---|
[57066a] | 4094 | } else {
|
---|
| 4095 | MiddleNode = StartNode;
|
---|
| 4096 | MiddleNode++;
|
---|
| 4097 | if (MiddleNode == connectedPath->end())
|
---|
| 4098 | MiddleNode = connectedPath->begin();
|
---|
| 4099 | EndNode = MiddleNode;
|
---|
| 4100 | EndNode++;
|
---|
| 4101 | if (EndNode == connectedPath->end())
|
---|
| 4102 | EndNode = connectedPath->begin();
|
---|
| 4103 | }
|
---|
[065e82] | 4104 | }
|
---|
[57066a] | 4105 | // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
|
---|
| 4106 | if (NewLines.size() > 1) {
|
---|
[c15ca2] | 4107 | LineList::iterator Candidate;
|
---|
[57066a] | 4108 | class BoundaryLineSet *OtherBase = NULL;
|
---|
| 4109 | double tmp, maxgain;
|
---|
| 4110 | do {
|
---|
| 4111 | maxgain = 0;
|
---|
[c15ca2] | 4112 | for(LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
|
---|
[e138de] | 4113 | tmp = PickFarthestofTwoBaselines(*Runner);
|
---|
[57066a] | 4114 | if (maxgain < tmp) {
|
---|
| 4115 | maxgain = tmp;
|
---|
| 4116 | Candidate = Runner;
|
---|
| 4117 | }
|
---|
| 4118 | }
|
---|
| 4119 | if (maxgain != 0) {
|
---|
| 4120 | volume += maxgain;
|
---|
[f67b6e] | 4121 | Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
|
---|
[e138de] | 4122 | OtherBase = FlipBaseline(*Candidate);
|
---|
[57066a] | 4123 | NewLines.erase(Candidate);
|
---|
| 4124 | NewLines.push_back(OtherBase);
|
---|
| 4125 | }
|
---|
| 4126 | } while (maxgain != 0.);
|
---|
| 4127 | }
|
---|
| 4128 |
|
---|
[065e82] | 4129 | ListOfClosedPaths->remove(connectedPath);
|
---|
| 4130 | delete(connectedPath);
|
---|
[16d866] | 4131 | }
|
---|
[f67b6e] | 4132 | Log() << Verbose(0) << count << " triangles were created." << endl;
|
---|
[065e82] | 4133 | } else {
|
---|
| 4134 | while (!ListOfClosedPaths->empty()) {
|
---|
| 4135 | ListRunner = ListOfClosedPaths->begin();
|
---|
| 4136 | connectedPath = *ListRunner;
|
---|
| 4137 | ListOfClosedPaths->remove(connectedPath);
|
---|
| 4138 | delete(connectedPath);
|
---|
| 4139 | }
|
---|
[f67b6e] | 4140 | Log() << Verbose(0) << "No need to create any triangles." << endl;
|
---|
[16d866] | 4141 | }
|
---|
[065e82] | 4142 | delete(ListOfClosedPaths);
|
---|
[16d866] | 4143 |
|
---|
[f67b6e] | 4144 | Log() << Verbose(0) << "Removed volume is " << volume << "." << endl;
|
---|
[357fba] | 4145 |
|
---|
[57066a] | 4146 | return volume;
|
---|
[357fba] | 4147 | };
|
---|
[ab1932] | 4148 |
|
---|
[5c7bf8] | 4149 |
|
---|
[ab1932] | 4150 |
|
---|
| 4151 | /**
|
---|
[62bb91] | 4152 | * Finds triangles belonging to the three provided points.
|
---|
[ab1932] | 4153 | *
|
---|
[71b20e] | 4154 | * @param *Points[3] list, is expected to contain three points (NULL means wildcard)
|
---|
[ab1932] | 4155 | *
|
---|
[62bb91] | 4156 | * @return triangles which belong to the provided points, will be empty if there are none,
|
---|
[ab1932] | 4157 | * will usually be one, in case of degeneration, there will be two
|
---|
| 4158 | */
|
---|
[c15ca2] | 4159 | TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
|
---|
[ab1932] | 4160 | {
|
---|
[f67b6e] | 4161 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4162 | TriangleList *result = new TriangleList;
|
---|
[776b64] | 4163 | LineMap::const_iterator FindLine;
|
---|
| 4164 | TriangleMap::const_iterator FindTriangle;
|
---|
[ab1932] | 4165 | class BoundaryPointSet *TrianglePoints[3];
|
---|
[71b20e] | 4166 | size_t NoOfWildcards = 0;
|
---|
[ab1932] | 4167 |
|
---|
| 4168 | for (int i = 0; i < 3; i++) {
|
---|
[71b20e] | 4169 | if (Points[i] == NULL) {
|
---|
| 4170 | NoOfWildcards++;
|
---|
[ab1932] | 4171 | TrianglePoints[i] = NULL;
|
---|
[71b20e] | 4172 | } else {
|
---|
| 4173 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
|
---|
| 4174 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 4175 | TrianglePoints[i] = FindPoint->second;
|
---|
| 4176 | } else {
|
---|
| 4177 | TrianglePoints[i] = NULL;
|
---|
| 4178 | }
|
---|
[ab1932] | 4179 | }
|
---|
| 4180 | }
|
---|
| 4181 |
|
---|
[71b20e] | 4182 | switch (NoOfWildcards) {
|
---|
| 4183 | case 0: // checks lines between the points in the Points for their adjacent triangles
|
---|
| 4184 | for (int i = 0; i < 3; i++) {
|
---|
| 4185 | if (TrianglePoints[i] != NULL) {
|
---|
| 4186 | for (int j = i+1; j < 3; j++) {
|
---|
| 4187 | if (TrianglePoints[j] != NULL) {
|
---|
| 4188 | for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
|
---|
| 4189 | (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
|
---|
| 4190 | FindLine++) {
|
---|
| 4191 | for (FindTriangle = FindLine->second->triangles.begin();
|
---|
| 4192 | FindTriangle != FindLine->second->triangles.end();
|
---|
| 4193 | FindTriangle++) {
|
---|
| 4194 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 4195 | result->push_back(FindTriangle->second);
|
---|
| 4196 | }
|
---|
| 4197 | }
|
---|
[ab1932] | 4198 | }
|
---|
[71b20e] | 4199 | // Is it sufficient to consider one of the triangle lines for this.
|
---|
| 4200 | return result;
|
---|
[ab1932] | 4201 | }
|
---|
| 4202 | }
|
---|
| 4203 | }
|
---|
| 4204 | }
|
---|
[71b20e] | 4205 | break;
|
---|
| 4206 | case 1: // copy all triangles of the respective line
|
---|
| 4207 | {
|
---|
| 4208 | int i=0;
|
---|
| 4209 | for (; i < 3; i++)
|
---|
| 4210 | if (TrianglePoints[i] == NULL)
|
---|
| 4211 | break;
|
---|
| 4212 | for (FindLine = TrianglePoints[(i+1)%3]->lines.find(TrianglePoints[(i+2)%3]->node->nr); // is a multimap!
|
---|
| 4213 | (FindLine != TrianglePoints[(i+1)%3]->lines.end()) && (FindLine->first == TrianglePoints[(i+2)%3]->node->nr);
|
---|
| 4214 | FindLine++) {
|
---|
| 4215 | for (FindTriangle = FindLine->second->triangles.begin();
|
---|
| 4216 | FindTriangle != FindLine->second->triangles.end();
|
---|
| 4217 | FindTriangle++) {
|
---|
| 4218 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 4219 | result->push_back(FindTriangle->second);
|
---|
| 4220 | }
|
---|
| 4221 | }
|
---|
| 4222 | }
|
---|
| 4223 | break;
|
---|
| 4224 | }
|
---|
| 4225 | case 2: // copy all triangles of the respective point
|
---|
| 4226 | {
|
---|
| 4227 | int i=0;
|
---|
| 4228 | for (; i < 3; i++)
|
---|
| 4229 | if (TrianglePoints[i] != NULL)
|
---|
| 4230 | break;
|
---|
| 4231 | for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++)
|
---|
| 4232 | for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++)
|
---|
| 4233 | result->push_back(triangle->second);
|
---|
| 4234 | result->sort();
|
---|
| 4235 | result->unique();
|
---|
| 4236 | break;
|
---|
| 4237 | }
|
---|
| 4238 | case 3: // copy all triangles
|
---|
| 4239 | {
|
---|
| 4240 | for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++)
|
---|
| 4241 | result->push_back(triangle->second);
|
---|
| 4242 | break;
|
---|
[ab1932] | 4243 | }
|
---|
[71b20e] | 4244 | default:
|
---|
| 4245 | eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl;
|
---|
| 4246 | performCriticalExit();
|
---|
| 4247 | break;
|
---|
[ab1932] | 4248 | }
|
---|
| 4249 |
|
---|
| 4250 | return result;
|
---|
| 4251 | }
|
---|
| 4252 |
|
---|
[856098] | 4253 | struct BoundaryLineSetCompare {
|
---|
| 4254 | bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) {
|
---|
| 4255 | int lowerNra = -1;
|
---|
| 4256 | int lowerNrb = -1;
|
---|
| 4257 |
|
---|
| 4258 | if (a->endpoints[0] < a->endpoints[1])
|
---|
| 4259 | lowerNra = 0;
|
---|
| 4260 | else
|
---|
| 4261 | lowerNra = 1;
|
---|
| 4262 |
|
---|
| 4263 | if (b->endpoints[0] < b->endpoints[1])
|
---|
| 4264 | lowerNrb = 0;
|
---|
| 4265 | else
|
---|
| 4266 | lowerNrb = 1;
|
---|
| 4267 |
|
---|
| 4268 | if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
|
---|
| 4269 | return true;
|
---|
| 4270 | else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
|
---|
| 4271 | return false;
|
---|
| 4272 | else { // both lower-numbered endpoints are the same ...
|
---|
| 4273 | if (a->endpoints[(lowerNra+1)%2] < b->endpoints[(lowerNrb+1)%2])
|
---|
| 4274 | return true;
|
---|
| 4275 | else if (a->endpoints[(lowerNra+1)%2] > b->endpoints[(lowerNrb+1)%2])
|
---|
| 4276 | return false;
|
---|
| 4277 | }
|
---|
| 4278 | return false;
|
---|
| 4279 | };
|
---|
| 4280 | };
|
---|
| 4281 |
|
---|
| 4282 | #define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
|
---|
| 4283 |
|
---|
[7c14ec] | 4284 | /**
|
---|
[57066a] | 4285 | * Finds all degenerated lines within the tesselation structure.
|
---|
[7c14ec] | 4286 | *
|
---|
[57066a] | 4287 | * @return map of keys of degenerated line pairs, each line occurs twice
|
---|
[7c14ec] | 4288 | * in the list, once as key and once as value
|
---|
| 4289 | */
|
---|
[c15ca2] | 4290 | IndexToIndex * Tesselation::FindAllDegeneratedLines()
|
---|
[7c14ec] | 4291 | {
|
---|
[f67b6e] | 4292 | Info FunctionInfo(__func__);
|
---|
[856098] | 4293 | UniqueLines AllLines;
|
---|
[c15ca2] | 4294 | IndexToIndex * DegeneratedLines = new IndexToIndex;
|
---|
[7c14ec] | 4295 |
|
---|
| 4296 | // sanity check
|
---|
| 4297 | if (LinesOnBoundary.empty()) {
|
---|
[f67b6e] | 4298 | eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.";
|
---|
[57066a] | 4299 | return DegeneratedLines;
|
---|
[7c14ec] | 4300 | }
|
---|
| 4301 |
|
---|
[57066a] | 4302 | LineMap::iterator LineRunner1;
|
---|
[856098] | 4303 | pair< UniqueLines::iterator, bool> tester;
|
---|
[7c14ec] | 4304 | for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
|
---|
[856098] | 4305 | tester = AllLines.insert( LineRunner1->second );
|
---|
| 4306 | if (!tester.second) { // found degenerated line
|
---|
| 4307 | DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr) );
|
---|
| 4308 | DegeneratedLines->insert ( pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr) );
|
---|
[57066a] | 4309 | }
|
---|
| 4310 | }
|
---|
| 4311 |
|
---|
| 4312 | AllLines.clear();
|
---|
| 4313 |
|
---|
[f67b6e] | 4314 | Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
|
---|
[c15ca2] | 4315 | IndexToIndex::iterator it;
|
---|
[856098] | 4316 | for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
|
---|
| 4317 | const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
|
---|
| 4318 | const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
|
---|
| 4319 | if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
|
---|
| 4320 | Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl;
|
---|
| 4321 | else
|
---|
| 4322 | eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl;
|
---|
| 4323 | }
|
---|
[57066a] | 4324 |
|
---|
| 4325 | return DegeneratedLines;
|
---|
| 4326 | }
|
---|
| 4327 |
|
---|
| 4328 | /**
|
---|
| 4329 | * Finds all degenerated triangles within the tesselation structure.
|
---|
| 4330 | *
|
---|
| 4331 | * @return map of keys of degenerated triangle pairs, each triangle occurs twice
|
---|
| 4332 | * in the list, once as key and once as value
|
---|
| 4333 | */
|
---|
[c15ca2] | 4334 | IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
|
---|
[57066a] | 4335 | {
|
---|
[f67b6e] | 4336 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4337 | IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
|
---|
| 4338 | IndexToIndex * DegeneratedTriangles = new IndexToIndex;
|
---|
[57066a] | 4339 |
|
---|
| 4340 | TriangleMap::iterator TriangleRunner1, TriangleRunner2;
|
---|
| 4341 | LineMap::iterator Liner;
|
---|
| 4342 | class BoundaryLineSet *line1 = NULL, *line2 = NULL;
|
---|
| 4343 |
|
---|
[c15ca2] | 4344 | for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
|
---|
[57066a] | 4345 | // run over both lines' triangles
|
---|
| 4346 | Liner = LinesOnBoundary.find(LineRunner->first);
|
---|
| 4347 | if (Liner != LinesOnBoundary.end())
|
---|
| 4348 | line1 = Liner->second;
|
---|
| 4349 | Liner = LinesOnBoundary.find(LineRunner->second);
|
---|
| 4350 | if (Liner != LinesOnBoundary.end())
|
---|
| 4351 | line2 = Liner->second;
|
---|
| 4352 | for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
|
---|
| 4353 | for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
|
---|
| 4354 | if ((TriangleRunner1->second != TriangleRunner2->second)
|
---|
| 4355 | && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
|
---|
| 4356 | DegeneratedTriangles->insert( pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr) );
|
---|
| 4357 | DegeneratedTriangles->insert( pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr) );
|
---|
[7c14ec] | 4358 | }
|
---|
| 4359 | }
|
---|
| 4360 | }
|
---|
| 4361 | }
|
---|
[57066a] | 4362 | delete(DegeneratedLines);
|
---|
[7c14ec] | 4363 |
|
---|
[f67b6e] | 4364 | Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
|
---|
[c15ca2] | 4365 | IndexToIndex::iterator it;
|
---|
[57066a] | 4366 | for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
|
---|
[f67b6e] | 4367 | Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
|
---|
[7c14ec] | 4368 |
|
---|
| 4369 | return DegeneratedTriangles;
|
---|
| 4370 | }
|
---|
| 4371 |
|
---|
| 4372 | /**
|
---|
| 4373 | * Purges degenerated triangles from the tesselation structure if they are not
|
---|
| 4374 | * necessary to keep a single point within the structure.
|
---|
| 4375 | */
|
---|
| 4376 | void Tesselation::RemoveDegeneratedTriangles()
|
---|
| 4377 | {
|
---|
[f67b6e] | 4378 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4379 | IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[57066a] | 4380 | TriangleMap::iterator finder;
|
---|
| 4381 | BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
|
---|
| 4382 | int count = 0;
|
---|
[7c14ec] | 4383 |
|
---|
[c15ca2] | 4384 | for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
|
---|
[57066a] | 4385 | TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
|
---|
[7c14ec] | 4386 | ) {
|
---|
[57066a] | 4387 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
|
---|
| 4388 | if (finder != TrianglesOnBoundary.end())
|
---|
| 4389 | triangle = finder->second;
|
---|
| 4390 | else
|
---|
| 4391 | break;
|
---|
| 4392 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->second);
|
---|
| 4393 | if (finder != TrianglesOnBoundary.end())
|
---|
| 4394 | partnerTriangle = finder->second;
|
---|
| 4395 | else
|
---|
| 4396 | break;
|
---|
[7c14ec] | 4397 |
|
---|
| 4398 | bool trianglesShareLine = false;
|
---|
| 4399 | for (int i = 0; i < 3; ++i)
|
---|
| 4400 | for (int j = 0; j < 3; ++j)
|
---|
| 4401 | trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
|
---|
| 4402 |
|
---|
| 4403 | if (trianglesShareLine
|
---|
| 4404 | && (triangle->endpoints[1]->LinesCount > 2)
|
---|
| 4405 | && (triangle->endpoints[2]->LinesCount > 2)
|
---|
| 4406 | && (triangle->endpoints[0]->LinesCount > 2)
|
---|
| 4407 | ) {
|
---|
[57066a] | 4408 | // check whether we have to fix lines
|
---|
| 4409 | BoundaryTriangleSet *Othertriangle = NULL;
|
---|
| 4410 | BoundaryTriangleSet *OtherpartnerTriangle = NULL;
|
---|
| 4411 | TriangleMap::iterator TriangleRunner;
|
---|
| 4412 | for (int i = 0; i < 3; ++i)
|
---|
| 4413 | for (int j = 0; j < 3; ++j)
|
---|
| 4414 | if (triangle->lines[i] != partnerTriangle->lines[j]) {
|
---|
| 4415 | // get the other two triangles
|
---|
| 4416 | for (TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 4417 | if (TriangleRunner->second != triangle) {
|
---|
| 4418 | Othertriangle = TriangleRunner->second;
|
---|
| 4419 | }
|
---|
| 4420 | for (TriangleRunner = partnerTriangle->lines[i]->triangles.begin(); TriangleRunner != partnerTriangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 4421 | if (TriangleRunner->second != partnerTriangle) {
|
---|
| 4422 | OtherpartnerTriangle = TriangleRunner->second;
|
---|
| 4423 | }
|
---|
| 4424 | /// interchanges their lines so that triangle->lines[i] == partnerTriangle->lines[j]
|
---|
| 4425 | // the line of triangle receives the degenerated ones
|
---|
| 4426 | triangle->lines[i]->triangles.erase(Othertriangle->Nr);
|
---|
| 4427 | triangle->lines[i]->triangles.insert( TrianglePair( partnerTriangle->Nr, partnerTriangle) );
|
---|
| 4428 | for (int k=0;k<3;k++)
|
---|
| 4429 | if (triangle->lines[i] == Othertriangle->lines[k]) {
|
---|
| 4430 | Othertriangle->lines[k] = partnerTriangle->lines[j];
|
---|
| 4431 | break;
|
---|
| 4432 | }
|
---|
| 4433 | // the line of partnerTriangle receives the non-degenerated ones
|
---|
| 4434 | partnerTriangle->lines[j]->triangles.erase( partnerTriangle->Nr);
|
---|
| 4435 | partnerTriangle->lines[j]->triangles.insert( TrianglePair( Othertriangle->Nr, Othertriangle) );
|
---|
| 4436 | partnerTriangle->lines[j] = triangle->lines[i];
|
---|
| 4437 | }
|
---|
| 4438 |
|
---|
| 4439 | // erase the pair
|
---|
| 4440 | count += (int) DegeneratedTriangles->erase(triangle->Nr);
|
---|
[f67b6e] | 4441 | Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
|
---|
[7c14ec] | 4442 | RemoveTesselationTriangle(triangle);
|
---|
[57066a] | 4443 | count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
|
---|
[f67b6e] | 4444 | Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
|
---|
[7c14ec] | 4445 | RemoveTesselationTriangle(partnerTriangle);
|
---|
| 4446 | } else {
|
---|
[f67b6e] | 4447 | Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
|
---|
[7c14ec] | 4448 | << " and its partner " << *partnerTriangle << " because it is essential for at"
|
---|
| 4449 | << " least one of the endpoints to be kept in the tesselation structure." << endl;
|
---|
| 4450 | }
|
---|
| 4451 | }
|
---|
[57066a] | 4452 | delete(DegeneratedTriangles);
|
---|
[6a7f78c] | 4453 | if (count > 0)
|
---|
| 4454 | LastTriangle = NULL;
|
---|
[57066a] | 4455 |
|
---|
[f67b6e] | 4456 | Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
|
---|
[7c14ec] | 4457 | }
|
---|
| 4458 |
|
---|
[57066a] | 4459 | /** Adds an outside Tesselpoint to the envelope via (two) degenerated triangles.
|
---|
| 4460 | * We look for the closest point on the boundary, we look through its connected boundary lines and
|
---|
| 4461 | * seek the one with the minimum angle between its center point and the new point and this base line.
|
---|
| 4462 | * We open up the line by adding a degenerated triangle, whose other side closes the base line again.
|
---|
| 4463 | * \param *out output stream for debugging
|
---|
| 4464 | * \param *point point to add
|
---|
| 4465 | * \param *LC Linked Cell structure to find nearest point
|
---|
[ab1932] | 4466 | */
|
---|
[e138de] | 4467 | void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
|
---|
[ab1932] | 4468 | {
|
---|
[f67b6e] | 4469 | Info FunctionInfo(__func__);
|
---|
[57066a] | 4470 | // find nearest boundary point
|
---|
| 4471 | class TesselPoint *BackupPoint = NULL;
|
---|
[71b20e] | 4472 | class TesselPoint *NearestPoint = FindClosestTesselPoint(point->node, BackupPoint, LC);
|
---|
[57066a] | 4473 | class BoundaryPointSet *NearestBoundaryPoint = NULL;
|
---|
| 4474 | PointMap::iterator PointRunner;
|
---|
| 4475 |
|
---|
| 4476 | if (NearestPoint == point)
|
---|
| 4477 | NearestPoint = BackupPoint;
|
---|
| 4478 | PointRunner = PointsOnBoundary.find(NearestPoint->nr);
|
---|
| 4479 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 4480 | NearestBoundaryPoint = PointRunner->second;
|
---|
| 4481 | } else {
|
---|
[717e0c] | 4482 | eLog() << Verbose(1) << "I cannot find the boundary point." << endl;
|
---|
[57066a] | 4483 | return;
|
---|
| 4484 | }
|
---|
[f67b6e] | 4485 | Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
|
---|
[57066a] | 4486 |
|
---|
| 4487 | // go through its lines and find the best one to split
|
---|
| 4488 | Vector CenterToPoint;
|
---|
| 4489 | Vector BaseLine;
|
---|
| 4490 | double angle, BestAngle = 0.;
|
---|
| 4491 | class BoundaryLineSet *BestLine = NULL;
|
---|
| 4492 | for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
|
---|
| 4493 | BaseLine.CopyVector(Runner->second->endpoints[0]->node->node);
|
---|
| 4494 | BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node);
|
---|
| 4495 | CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node);
|
---|
| 4496 | CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node);
|
---|
| 4497 | CenterToPoint.Scale(0.5);
|
---|
| 4498 | CenterToPoint.SubtractVector(point->node);
|
---|
| 4499 | angle = CenterToPoint.Angle(&BaseLine);
|
---|
| 4500 | if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
|
---|
| 4501 | BestAngle = angle;
|
---|
| 4502 | BestLine = Runner->second;
|
---|
| 4503 | }
|
---|
[ab1932] | 4504 | }
|
---|
| 4505 |
|
---|
[57066a] | 4506 | // remove one triangle from the chosen line
|
---|
| 4507 | class BoundaryTriangleSet *TempTriangle = (BestLine->triangles.begin())->second;
|
---|
| 4508 | BestLine->triangles.erase(TempTriangle->Nr);
|
---|
| 4509 | int nr = -1;
|
---|
| 4510 | for (int i=0;i<3; i++) {
|
---|
| 4511 | if (TempTriangle->lines[i] == BestLine) {
|
---|
| 4512 | nr = i;
|
---|
| 4513 | break;
|
---|
| 4514 | }
|
---|
| 4515 | }
|
---|
[ab1932] | 4516 |
|
---|
[57066a] | 4517 | // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
|
---|
[f67b6e] | 4518 | Log() << Verbose(2) << "Adding new triangle points."<< endl;
|
---|
[57066a] | 4519 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 4520 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 4521 | AddTesselationPoint(point, 2);
|
---|
[f67b6e] | 4522 | Log() << Verbose(2) << "Adding new triangle lines."<< endl;
|
---|
[57066a] | 4523 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 4524 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
| 4525 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
| 4526 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 4527 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
| 4528 | BTS->NormalVector.Scale(-1.);
|
---|
[f67b6e] | 4529 | Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
|
---|
[57066a] | 4530 | AddTesselationTriangle();
|
---|
| 4531 |
|
---|
| 4532 | // create other side of this triangle and close both new sides of the first created triangle
|
---|
[f67b6e] | 4533 | Log() << Verbose(2) << "Adding new triangle points."<< endl;
|
---|
[57066a] | 4534 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 4535 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 4536 | AddTesselationPoint(point, 2);
|
---|
[f67b6e] | 4537 | Log() << Verbose(2) << "Adding new triangle lines."<< endl;
|
---|
[57066a] | 4538 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 4539 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
| 4540 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
| 4541 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 4542 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
[f67b6e] | 4543 | Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
|
---|
[57066a] | 4544 | AddTesselationTriangle();
|
---|
| 4545 |
|
---|
| 4546 | // add removed triangle to the last open line of the second triangle
|
---|
| 4547 | for (int i=0;i<3;i++) { // look for the same line as BestLine (only it's its degenerated companion)
|
---|
| 4548 | if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
|
---|
| 4549 | if (BestLine == BTS->lines[i]){
|
---|
[f67b6e] | 4550 | eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl;
|
---|
| 4551 | performCriticalExit();
|
---|
[57066a] | 4552 | }
|
---|
| 4553 | BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle) );
|
---|
| 4554 | TempTriangle->lines[nr] = BTS->lines[i];
|
---|
| 4555 | break;
|
---|
| 4556 | }
|
---|
| 4557 | }
|
---|
| 4558 | };
|
---|
| 4559 |
|
---|
| 4560 | /** Writes the envelope to file.
|
---|
| 4561 | * \param *out otuput stream for debugging
|
---|
| 4562 | * \param *filename basename of output file
|
---|
| 4563 | * \param *cloud PointCloud structure with all nodes
|
---|
| 4564 | */
|
---|
[e138de] | 4565 | void Tesselation::Output(const char *filename, const PointCloud * const cloud)
|
---|
[57066a] | 4566 | {
|
---|
[f67b6e] | 4567 | Info FunctionInfo(__func__);
|
---|
[57066a] | 4568 | ofstream *tempstream = NULL;
|
---|
| 4569 | string NameofTempFile;
|
---|
| 4570 | char NumberName[255];
|
---|
| 4571 |
|
---|
| 4572 | if (LastTriangle != NULL) {
|
---|
| 4573 | sprintf(NumberName, "-%04d-%s_%s_%s", (int)TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);
|
---|
| 4574 | if (DoTecplotOutput) {
|
---|
| 4575 | string NameofTempFile(filename);
|
---|
| 4576 | NameofTempFile.append(NumberName);
|
---|
| 4577 | for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 4578 | NameofTempFile.erase(npos, 1);
|
---|
| 4579 | NameofTempFile.append(TecplotSuffix);
|
---|
[f67b6e] | 4580 | Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
|
---|
[57066a] | 4581 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 4582 | WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
|
---|
[57066a] | 4583 | tempstream->close();
|
---|
| 4584 | tempstream->flush();
|
---|
| 4585 | delete(tempstream);
|
---|
| 4586 | }
|
---|
| 4587 |
|
---|
| 4588 | if (DoRaster3DOutput) {
|
---|
| 4589 | string NameofTempFile(filename);
|
---|
| 4590 | NameofTempFile.append(NumberName);
|
---|
| 4591 | for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 4592 | NameofTempFile.erase(npos, 1);
|
---|
| 4593 | NameofTempFile.append(Raster3DSuffix);
|
---|
[f67b6e] | 4594 | Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
|
---|
[57066a] | 4595 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 4596 | WriteRaster3dFile(tempstream, this, cloud);
|
---|
| 4597 | IncludeSphereinRaster3D(tempstream, this, cloud);
|
---|
[57066a] | 4598 | tempstream->close();
|
---|
| 4599 | tempstream->flush();
|
---|
| 4600 | delete(tempstream);
|
---|
| 4601 | }
|
---|
| 4602 | }
|
---|
| 4603 | if (DoTecplotOutput || DoRaster3DOutput)
|
---|
| 4604 | TriangleFilesWritten++;
|
---|
| 4605 | };
|
---|
[262bae] | 4606 |
|
---|
[856098] | 4607 | struct BoundaryPolygonSetCompare {
|
---|
| 4608 | bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const {
|
---|
| 4609 | if (s1->endpoints.size() < s2->endpoints.size())
|
---|
| 4610 | return true;
|
---|
| 4611 | else if (s1->endpoints.size() > s2->endpoints.size())
|
---|
| 4612 | return false;
|
---|
| 4613 | else { // equality of number of endpoints
|
---|
| 4614 | PointSet::const_iterator Walker1 = s1->endpoints.begin();
|
---|
| 4615 | PointSet::const_iterator Walker2 = s2->endpoints.begin();
|
---|
| 4616 | while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
|
---|
| 4617 | if ((*Walker1)->Nr < (*Walker2)->Nr)
|
---|
| 4618 | return true;
|
---|
| 4619 | else if ((*Walker1)->Nr > (*Walker2)->Nr)
|
---|
| 4620 | return false;
|
---|
| 4621 | Walker1++;
|
---|
| 4622 | Walker2++;
|
---|
| 4623 | }
|
---|
| 4624 | return false;
|
---|
| 4625 | }
|
---|
| 4626 | }
|
---|
| 4627 | };
|
---|
| 4628 |
|
---|
| 4629 | #define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
|
---|
| 4630 |
|
---|
[262bae] | 4631 | /** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
|
---|
| 4632 | * \return number of polygons found
|
---|
| 4633 | */
|
---|
| 4634 | int Tesselation::CorrectAllDegeneratedPolygons()
|
---|
| 4635 | {
|
---|
| 4636 | Info FunctionInfo(__func__);
|
---|
| 4637 |
|
---|
[fad93c] | 4638 | /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
|
---|
[c15ca2] | 4639 | IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[fad93c] | 4640 | set < BoundaryPointSet *> EndpointCandidateList;
|
---|
| 4641 | pair < set < BoundaryPointSet *>::iterator, bool > InsertionTester;
|
---|
| 4642 | pair < map < int, Vector *>::iterator, bool > TriangleInsertionTester;
|
---|
| 4643 | for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
|
---|
| 4644 | Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl;
|
---|
| 4645 | map < int, Vector *> TriangleVectors;
|
---|
| 4646 | // gather all NormalVectors
|
---|
| 4647 | Log() << Verbose(1) << "Gathering triangles ..." << endl;
|
---|
| 4648 | for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
|
---|
| 4649 | for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
[b998c3] | 4650 | if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
|
---|
| 4651 | TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)) );
|
---|
| 4652 | if (TriangleInsertionTester.second)
|
---|
| 4653 | Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;
|
---|
| 4654 | } else {
|
---|
| 4655 | Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl;
|
---|
| 4656 | }
|
---|
[fad93c] | 4657 | }
|
---|
| 4658 | // check whether there are two that are parallel
|
---|
| 4659 | Log() << Verbose(1) << "Finding two parallel triangles ..." << endl;
|
---|
| 4660 | for (map < int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
|
---|
| 4661 | for (map < int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
|
---|
| 4662 | if (VectorWalker != VectorRunner) { // skip equals
|
---|
| 4663 | const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
|
---|
| 4664 | Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl;
|
---|
| 4665 | if (fabs(SCP + 1.) < ParallelEpsilon) {
|
---|
| 4666 | InsertionTester = EndpointCandidateList.insert((Runner->second));
|
---|
| 4667 | if (InsertionTester.second)
|
---|
| 4668 | Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl;
|
---|
| 4669 | // and break out of both loops
|
---|
| 4670 | VectorWalker = TriangleVectors.end();
|
---|
| 4671 | VectorRunner = TriangleVectors.end();
|
---|
| 4672 | break;
|
---|
| 4673 | }
|
---|
| 4674 | }
|
---|
| 4675 | }
|
---|
[856098] | 4676 |
|
---|
[fad93c] | 4677 | /// 3. Find connected endpoint candidates and put them into a polygon
|
---|
| 4678 | UniquePolygonSet ListofDegeneratedPolygons;
|
---|
| 4679 | BoundaryPointSet *Walker = NULL;
|
---|
| 4680 | BoundaryPointSet *OtherWalker = NULL;
|
---|
| 4681 | BoundaryPolygonSet *Current = NULL;
|
---|
| 4682 | stack <BoundaryPointSet*> ToCheckConnecteds;
|
---|
| 4683 | while (!EndpointCandidateList.empty()) {
|
---|
| 4684 | Walker = *(EndpointCandidateList.begin());
|
---|
| 4685 | if (Current == NULL) { // create a new polygon with current candidate
|
---|
| 4686 | Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl;
|
---|
| 4687 | Current = new BoundaryPolygonSet;
|
---|
| 4688 | Current->endpoints.insert(Walker);
|
---|
| 4689 | EndpointCandidateList.erase(Walker);
|
---|
| 4690 | ToCheckConnecteds.push(Walker);
|
---|
[856098] | 4691 | }
|
---|
[262bae] | 4692 |
|
---|
[fad93c] | 4693 | // go through to-check stack
|
---|
| 4694 | while (!ToCheckConnecteds.empty()) {
|
---|
| 4695 | Walker = ToCheckConnecteds.top(); // fetch ...
|
---|
| 4696 | ToCheckConnecteds.pop(); // ... and remove
|
---|
| 4697 | for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
|
---|
| 4698 | OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
|
---|
| 4699 | Log() << Verbose(1) << "Checking " << *OtherWalker << endl;
|
---|
| 4700 | set < BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
|
---|
| 4701 | if (Finder != EndpointCandidateList.end()) { // found a connected partner
|
---|
| 4702 | Log() << Verbose(1) << " Adding to polygon." << endl;
|
---|
| 4703 | Current->endpoints.insert(OtherWalker);
|
---|
| 4704 | EndpointCandidateList.erase(Finder); // remove from candidates
|
---|
| 4705 | ToCheckConnecteds.push(OtherWalker); // but check its partners too
|
---|
[856098] | 4706 | } else {
|
---|
[fad93c] | 4707 | Log() << Verbose(1) << " is not connected to " << *Walker << endl;
|
---|
[856098] | 4708 | }
|
---|
| 4709 | }
|
---|
| 4710 | }
|
---|
[262bae] | 4711 |
|
---|
[fad93c] | 4712 | Log() << Verbose(0) << "Final polygon is " << *Current << endl;
|
---|
| 4713 | ListofDegeneratedPolygons.insert(Current);
|
---|
| 4714 | Current = NULL;
|
---|
[262bae] | 4715 | }
|
---|
| 4716 |
|
---|
[fad93c] | 4717 | const int counter = ListofDegeneratedPolygons.size();
|
---|
[262bae] | 4718 |
|
---|
[fad93c] | 4719 | Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl;
|
---|
| 4720 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
|
---|
[856098] | 4721 | Log() << Verbose(0) << " " << **PolygonRunner << endl;
|
---|
| 4722 |
|
---|
[262bae] | 4723 | /// 4. Go through all these degenerated polygons
|
---|
[fad93c] | 4724 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
|
---|
[856098] | 4725 | stack <int> TriangleNrs;
|
---|
| 4726 | Vector NormalVector;
|
---|
[262bae] | 4727 | /// 4a. Gather all triangles of this polygon
|
---|
[856098] | 4728 | TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
|
---|
[262bae] | 4729 |
|
---|
[125b3c] | 4730 | // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do.
|
---|
[b998c3] | 4731 | if (T->size() == 2) {
|
---|
| 4732 | Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl;
|
---|
| 4733 | delete(T);
|
---|
| 4734 | continue;
|
---|
| 4735 | }
|
---|
| 4736 |
|
---|
[125b3c] | 4737 | // check whether number is even
|
---|
| 4738 | // If this case occurs, we have to think about it!
|
---|
| 4739 | // The Problem is probably due to two degenerated polygons being connected by a bridging, non-degenerated polygon, as somehow one node has
|
---|
| 4740 | // connections to either polygon ...
|
---|
| 4741 | if (T->size() % 2 != 0) {
|
---|
| 4742 | eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl;
|
---|
| 4743 | performCriticalExit();
|
---|
| 4744 | }
|
---|
| 4745 |
|
---|
[856098] | 4746 | TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
|
---|
[262bae] | 4747 | /// 4a. Get NormalVector for one side (this is "front")
|
---|
[856098] | 4748 | NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
|
---|
| 4749 | Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl;
|
---|
| 4750 | TriangleWalker++;
|
---|
| 4751 | TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
|
---|
[262bae] | 4752 | /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back")
|
---|
[856098] | 4753 | BoundaryTriangleSet *triangle = NULL;
|
---|
| 4754 | while (TriangleSprinter != T->end()) {
|
---|
| 4755 | TriangleWalker = TriangleSprinter;
|
---|
| 4756 | triangle = *TriangleWalker;
|
---|
| 4757 | TriangleSprinter++;
|
---|
| 4758 | Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl;
|
---|
| 4759 | if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
|
---|
| 4760 | Log() << Verbose(1) << " Removing ... " << endl;
|
---|
| 4761 | TriangleNrs.push(triangle->Nr);
|
---|
[262bae] | 4762 | T->erase(TriangleWalker);
|
---|
[856098] | 4763 | RemoveTesselationTriangle(triangle);
|
---|
| 4764 | } else
|
---|
| 4765 | Log() << Verbose(1) << " Keeping ... " << endl;
|
---|
[262bae] | 4766 | }
|
---|
| 4767 | /// 4c. Copy all "front" triangles but with inverse NormalVector
|
---|
| 4768 | TriangleWalker = T->begin();
|
---|
[856098] | 4769 | while (TriangleWalker != T->end()) { // go through all front triangles
|
---|
[fad93c] | 4770 | Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl;
|
---|
[856098] | 4771 | for (int i = 0; i < 3; i++)
|
---|
| 4772 | AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
|
---|
| 4773 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 4774 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
| 4775 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
[fad93c] | 4776 | if (TriangleNrs.empty())
|
---|
| 4777 | eLog() << Verbose(0) << "No more free triangle numbers!" << endl;
|
---|
[856098] | 4778 | BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
|
---|
| 4779 | AddTesselationTriangle(); // ... and add
|
---|
| 4780 | TriangleNrs.pop();
|
---|
| 4781 | BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
|
---|
| 4782 | BTS->NormalVector.Scale(-1.);
|
---|
[262bae] | 4783 | TriangleWalker++;
|
---|
| 4784 | }
|
---|
[856098] | 4785 | if (!TriangleNrs.empty()) {
|
---|
| 4786 | eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl;
|
---|
| 4787 | }
|
---|
[262bae] | 4788 | delete(T); // remove the triangleset
|
---|
| 4789 | }
|
---|
| 4790 |
|
---|
[c15ca2] | 4791 | IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[856098] | 4792 | Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;
|
---|
[c15ca2] | 4793 | IndexToIndex::iterator it;
|
---|
[856098] | 4794 | for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
|
---|
| 4795 | Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;
|
---|
[fad93c] | 4796 | delete(SimplyDegeneratedTriangles);
|
---|
[856098] | 4797 |
|
---|
[262bae] | 4798 | /// 5. exit
|
---|
[856098] | 4799 | UniquePolygonSet::iterator PolygonRunner;
|
---|
[fad93c] | 4800 | while (!ListofDegeneratedPolygons.empty()) {
|
---|
| 4801 | PolygonRunner = ListofDegeneratedPolygons.begin();
|
---|
[262bae] | 4802 | delete(*PolygonRunner);
|
---|
[fad93c] | 4803 | ListofDegeneratedPolygons.erase(PolygonRunner);
|
---|
[262bae] | 4804 | }
|
---|
| 4805 |
|
---|
| 4806 | return counter;
|
---|
| 4807 | };
|
---|