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