[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"
|
---|
[57066a] | 11 | #include "linkedcell.hpp"
|
---|
[e138de] | 12 | #include "log.hpp"
|
---|
[357fba] | 13 | #include "tesselation.hpp"
|
---|
[57066a] | 14 | #include "tesselationhelpers.hpp"
|
---|
| 15 | #include "vector.hpp"
|
---|
[f66195] | 16 | #include "verbose.hpp"
|
---|
[57066a] | 17 |
|
---|
| 18 | class molecule;
|
---|
[357fba] | 19 |
|
---|
| 20 | // ======================================== Points on Boundary =================================
|
---|
| 21 |
|
---|
[16d866] | 22 | /** Constructor of BoundaryPointSet.
|
---|
| 23 | */
|
---|
[357fba] | 24 | BoundaryPointSet::BoundaryPointSet()
|
---|
| 25 | {
|
---|
| 26 | LinesCount = 0;
|
---|
| 27 | Nr = -1;
|
---|
[1d9b7aa] | 28 | value = 0.;
|
---|
[16d866] | 29 | };
|
---|
[357fba] | 30 |
|
---|
[16d866] | 31 | /** Constructor of BoundaryPointSet with Tesselpoint.
|
---|
| 32 | * \param *Walker TesselPoint this boundary point represents
|
---|
| 33 | */
|
---|
[776b64] | 34 | BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker)
|
---|
[357fba] | 35 | {
|
---|
| 36 | node = Walker;
|
---|
| 37 | LinesCount = 0;
|
---|
| 38 | Nr = Walker->nr;
|
---|
[1d9b7aa] | 39 | value = 0.;
|
---|
[16d866] | 40 | };
|
---|
[357fba] | 41 |
|
---|
[16d866] | 42 | /** Destructor of BoundaryPointSet.
|
---|
| 43 | * Sets node to NULL to avoid removing the original, represented TesselPoint.
|
---|
| 44 | * \note When removing point from a class Tesselation, use RemoveTesselationPoint()
|
---|
| 45 | */
|
---|
[357fba] | 46 | BoundaryPointSet::~BoundaryPointSet()
|
---|
| 47 | {
|
---|
[e138de] | 48 | //Log() << Verbose(5) << "Erasing point nr. " << Nr << "." << endl;
|
---|
[357fba] | 49 | if (!lines.empty())
|
---|
[717e0c] | 50 | eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl;
|
---|
[357fba] | 51 | node = NULL;
|
---|
[16d866] | 52 | };
|
---|
[357fba] | 53 |
|
---|
[16d866] | 54 | /** Add a line to the LineMap of this point.
|
---|
| 55 | * \param *line line to add
|
---|
| 56 | */
|
---|
[357fba] | 57 | void BoundaryPointSet::AddLine(class BoundaryLineSet *line)
|
---|
| 58 | {
|
---|
[e138de] | 59 | Log() << Verbose(6) << "Adding " << *this << " to line " << *line << "."
|
---|
[357fba] | 60 | << endl;
|
---|
| 61 | if (line->endpoints[0] == this)
|
---|
| 62 | {
|
---|
| 63 | lines.insert(LinePair(line->endpoints[1]->Nr, line));
|
---|
| 64 | }
|
---|
| 65 | else
|
---|
| 66 | {
|
---|
| 67 | lines.insert(LinePair(line->endpoints[0]->Nr, line));
|
---|
| 68 | }
|
---|
| 69 | LinesCount++;
|
---|
[16d866] | 70 | };
|
---|
[357fba] | 71 |
|
---|
[16d866] | 72 | /** output operator for BoundaryPointSet.
|
---|
| 73 | * \param &ost output stream
|
---|
| 74 | * \param &a boundary point
|
---|
| 75 | */
|
---|
[776b64] | 76 | ostream & operator <<(ostream &ost, const BoundaryPointSet &a)
|
---|
[357fba] | 77 | {
|
---|
[57066a] | 78 | ost << "[" << a.Nr << "|" << a.node->Name << " at " << *a.node->node << "]";
|
---|
[357fba] | 79 | return ost;
|
---|
| 80 | }
|
---|
| 81 | ;
|
---|
| 82 |
|
---|
| 83 | // ======================================== Lines on Boundary =================================
|
---|
| 84 |
|
---|
[16d866] | 85 | /** Constructor of BoundaryLineSet.
|
---|
| 86 | */
|
---|
[357fba] | 87 | BoundaryLineSet::BoundaryLineSet()
|
---|
| 88 | {
|
---|
| 89 | for (int i = 0; i < 2; i++)
|
---|
| 90 | endpoints[i] = NULL;
|
---|
| 91 | Nr = -1;
|
---|
[16d866] | 92 | };
|
---|
[357fba] | 93 |
|
---|
[16d866] | 94 | /** Constructor of BoundaryLineSet with two endpoints.
|
---|
| 95 | * Adds line automatically to each endpoints' LineMap
|
---|
| 96 | * \param *Point[2] array of two boundary points
|
---|
| 97 | * \param number number of the list
|
---|
| 98 | */
|
---|
[776b64] | 99 | BoundaryLineSet::BoundaryLineSet(class BoundaryPointSet *Point[2], const int number)
|
---|
[357fba] | 100 | {
|
---|
| 101 | // set number
|
---|
| 102 | Nr = number;
|
---|
| 103 | // set endpoints in ascending order
|
---|
| 104 | SetEndpointsOrdered(endpoints, Point[0], Point[1]);
|
---|
| 105 | // add this line to the hash maps of both endpoints
|
---|
| 106 | Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
|
---|
| 107 | Point[1]->AddLine(this); //
|
---|
| 108 | // clear triangles list
|
---|
[e138de] | 109 | Log() << Verbose(5) << "New Line with endpoints " << *this << "." << endl;
|
---|
[16d866] | 110 | };
|
---|
[357fba] | 111 |
|
---|
[16d866] | 112 | /** Destructor for BoundaryLineSet.
|
---|
| 113 | * Removes itself from each endpoints' LineMap, calling RemoveTrianglePoint() when point not connected anymore.
|
---|
| 114 | * \note When removing lines from a class Tesselation, use RemoveTesselationLine()
|
---|
| 115 | */
|
---|
[357fba] | 116 | BoundaryLineSet::~BoundaryLineSet()
|
---|
| 117 | {
|
---|
| 118 | int Numbers[2];
|
---|
[16d866] | 119 |
|
---|
| 120 | // get other endpoint number of finding copies of same line
|
---|
| 121 | if (endpoints[1] != NULL)
|
---|
| 122 | Numbers[0] = endpoints[1]->Nr;
|
---|
| 123 | else
|
---|
| 124 | Numbers[0] = -1;
|
---|
| 125 | if (endpoints[0] != NULL)
|
---|
| 126 | Numbers[1] = endpoints[0]->Nr;
|
---|
| 127 | else
|
---|
| 128 | Numbers[1] = -1;
|
---|
| 129 |
|
---|
[357fba] | 130 | for (int i = 0; i < 2; i++) {
|
---|
[16d866] | 131 | if (endpoints[i] != NULL) {
|
---|
| 132 | 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
|
---|
| 133 | pair<LineMap::iterator, LineMap::iterator> erasor = endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 134 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 135 | if ((*Runner).second == this) {
|
---|
[e138de] | 136 | //Log() << Verbose(5) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[16d866] | 137 | endpoints[i]->lines.erase(Runner);
|
---|
| 138 | break;
|
---|
| 139 | }
|
---|
| 140 | } else { // there's just a single line left
|
---|
[57066a] | 141 | if (endpoints[i]->lines.erase(Nr)) {
|
---|
[e138de] | 142 | //Log() << Verbose(5) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[57066a] | 143 | }
|
---|
[357fba] | 144 | }
|
---|
[16d866] | 145 | if (endpoints[i]->lines.empty()) {
|
---|
[e138de] | 146 | //Log() << Verbose(5) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
|
---|
[16d866] | 147 | if (endpoints[i] != NULL) {
|
---|
| 148 | delete(endpoints[i]);
|
---|
| 149 | endpoints[i] = NULL;
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
[357fba] | 153 | }
|
---|
| 154 | if (!triangles.empty())
|
---|
[717e0c] | 155 | eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl;
|
---|
[16d866] | 156 | };
|
---|
[357fba] | 157 |
|
---|
[16d866] | 158 | /** Add triangle to TriangleMap of this boundary line.
|
---|
| 159 | * \param *triangle to add
|
---|
| 160 | */
|
---|
| 161 | void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
|
---|
[357fba] | 162 | {
|
---|
[e138de] | 163 | Log() << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
|
---|
[357fba] | 164 | triangles.insert(TrianglePair(triangle->Nr, triangle));
|
---|
[16d866] | 165 | };
|
---|
[357fba] | 166 |
|
---|
| 167 | /** Checks whether we have a common endpoint with given \a *line.
|
---|
| 168 | * \param *line other line to test
|
---|
| 169 | * \return true - common endpoint present, false - not connected
|
---|
| 170 | */
|
---|
| 171 | bool BoundaryLineSet::IsConnectedTo(class BoundaryLineSet *line)
|
---|
| 172 | {
|
---|
| 173 | if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
|
---|
| 174 | return true;
|
---|
| 175 | else
|
---|
| 176 | return false;
|
---|
| 177 | };
|
---|
| 178 |
|
---|
| 179 | /** Checks whether the adjacent triangles of a baseline are convex or not.
|
---|
[57066a] | 180 | * We sum the two angles of each height vector with respect to the center of the baseline.
|
---|
[357fba] | 181 | * If greater/equal M_PI than we are convex.
|
---|
| 182 | * \param *out output stream for debugging
|
---|
| 183 | * \return true - triangles are convex, false - concave or less than two triangles connected
|
---|
| 184 | */
|
---|
[e138de] | 185 | bool BoundaryLineSet::CheckConvexityCriterion()
|
---|
[357fba] | 186 | {
|
---|
[5c7bf8] | 187 | Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
|
---|
[357fba] | 188 | // get the two triangles
|
---|
[5c7bf8] | 189 | if (triangles.size() != 2) {
|
---|
[717e0c] | 190 | eLog() << Verbose(1) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
|
---|
[1d9b7aa] | 191 | return true;
|
---|
[357fba] | 192 | }
|
---|
[5c7bf8] | 193 | // check normal vectors
|
---|
[357fba] | 194 | // have a normal vector on the base line pointing outwards
|
---|
[e138de] | 195 | //Log() << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
|
---|
[62bb91] | 196 | BaseLineCenter.CopyVector(endpoints[0]->node->node);
|
---|
| 197 | BaseLineCenter.AddVector(endpoints[1]->node->node);
|
---|
| 198 | BaseLineCenter.Scale(1./2.);
|
---|
| 199 | BaseLine.CopyVector(endpoints[0]->node->node);
|
---|
| 200 | BaseLine.SubtractVector(endpoints[1]->node->node);
|
---|
[e138de] | 201 | //Log() << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
|
---|
[357fba] | 202 |
|
---|
[62bb91] | 203 | BaseLineNormal.Zero();
|
---|
[5c7bf8] | 204 | NormalCheck.Zero();
|
---|
| 205 | double sign = -1.;
|
---|
[62bb91] | 206 | int i=0;
|
---|
| 207 | class BoundaryPointSet *node = NULL;
|
---|
| 208 | for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
|
---|
[e138de] | 209 | //Log() << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
|
---|
[5c7bf8] | 210 | NormalCheck.AddVector(&runner->second->NormalVector);
|
---|
| 211 | NormalCheck.Scale(sign);
|
---|
| 212 | sign = -sign;
|
---|
[57066a] | 213 | if (runner->second->NormalVector.NormSquared() > MYEPSILON)
|
---|
| 214 | BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first
|
---|
| 215 | else {
|
---|
[e138de] | 216 | Log() << Verbose(1) << "CRITICAL: Triangle " << *runner->second << " has zero normal vector!" << endl;
|
---|
[57066a] | 217 | exit(255);
|
---|
| 218 | }
|
---|
[62bb91] | 219 | node = runner->second->GetThirdEndpoint(this);
|
---|
| 220 | if (node != NULL) {
|
---|
[e138de] | 221 | //Log() << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
|
---|
[62bb91] | 222 | helper[i].CopyVector(node->node->node);
|
---|
| 223 | helper[i].SubtractVector(&BaseLineCenter);
|
---|
| 224 | helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles!
|
---|
[e138de] | 225 | //Log() << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
|
---|
[62bb91] | 226 | i++;
|
---|
| 227 | } else {
|
---|
[717e0c] | 228 | //eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;
|
---|
[62bb91] | 229 | return true;
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
[e138de] | 232 | //Log() << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
|
---|
[5c7bf8] | 233 | if (NormalCheck.NormSquared() < MYEPSILON) {
|
---|
[e138de] | 234 | Log() << Verbose(3) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
|
---|
[5c7bf8] | 235 | return true;
|
---|
[62bb91] | 236 | }
|
---|
[57066a] | 237 | BaseLineNormal.Scale(-1.);
|
---|
[f1cccd] | 238 | double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
|
---|
[1d9b7aa] | 239 | if ((angle - M_PI) > -MYEPSILON) {
|
---|
[e138de] | 240 | Log() << Verbose(3) << "ACCEPT: Angle is greater than pi: convex." << endl;
|
---|
[357fba] | 241 | return true;
|
---|
[1d9b7aa] | 242 | } else {
|
---|
[e138de] | 243 | Log() << Verbose(3) << "REJECT: Angle is less than pi: concave." << endl;
|
---|
[357fba] | 244 | return false;
|
---|
[1d9b7aa] | 245 | }
|
---|
[357fba] | 246 | }
|
---|
| 247 |
|
---|
| 248 | /** Checks whether point is any of the two endpoints this line contains.
|
---|
| 249 | * \param *point point to test
|
---|
| 250 | * \return true - point is of the line, false - is not
|
---|
| 251 | */
|
---|
| 252 | bool BoundaryLineSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
|
---|
| 253 | {
|
---|
| 254 | for(int i=0;i<2;i++)
|
---|
| 255 | if (point == endpoints[i])
|
---|
| 256 | return true;
|
---|
| 257 | return false;
|
---|
| 258 | };
|
---|
| 259 |
|
---|
[62bb91] | 260 | /** Returns other endpoint of the line.
|
---|
| 261 | * \param *point other endpoint
|
---|
| 262 | * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise
|
---|
| 263 | */
|
---|
[08ef35] | 264 | class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(class BoundaryPointSet *point)
|
---|
[62bb91] | 265 | {
|
---|
| 266 | if (endpoints[0] == point)
|
---|
| 267 | return endpoints[1];
|
---|
| 268 | else if (endpoints[1] == point)
|
---|
| 269 | return endpoints[0];
|
---|
| 270 | else
|
---|
| 271 | return NULL;
|
---|
| 272 | };
|
---|
| 273 |
|
---|
[16d866] | 274 | /** output operator for BoundaryLineSet.
|
---|
| 275 | * \param &ost output stream
|
---|
| 276 | * \param &a boundary line
|
---|
| 277 | */
|
---|
[776b64] | 278 | ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
|
---|
[357fba] | 279 | {
|
---|
[57066a] | 280 | 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] | 281 | return ost;
|
---|
[16d866] | 282 | };
|
---|
[357fba] | 283 |
|
---|
| 284 | // ======================================== Triangles on Boundary =================================
|
---|
| 285 |
|
---|
[16d866] | 286 | /** Constructor for BoundaryTriangleSet.
|
---|
| 287 | */
|
---|
[357fba] | 288 | BoundaryTriangleSet::BoundaryTriangleSet()
|
---|
| 289 | {
|
---|
| 290 | for (int i = 0; i < 3; i++)
|
---|
| 291 | {
|
---|
| 292 | endpoints[i] = NULL;
|
---|
| 293 | lines[i] = NULL;
|
---|
| 294 | }
|
---|
| 295 | Nr = -1;
|
---|
[16d866] | 296 | };
|
---|
[357fba] | 297 |
|
---|
[16d866] | 298 | /** Constructor for BoundaryTriangleSet with three lines.
|
---|
| 299 | * \param *line[3] lines that make up the triangle
|
---|
| 300 | * \param number number of triangle
|
---|
| 301 | */
|
---|
[357fba] | 302 | BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number)
|
---|
| 303 | {
|
---|
| 304 | // set number
|
---|
| 305 | Nr = number;
|
---|
| 306 | // set lines
|
---|
[e138de] | 307 | Log() << Verbose(5) << "New triangle " << Nr << ":" << endl;
|
---|
[357fba] | 308 | for (int i = 0; i < 3; i++)
|
---|
| 309 | {
|
---|
| 310 | lines[i] = line[i];
|
---|
| 311 | lines[i]->AddTriangle(this);
|
---|
| 312 | }
|
---|
| 313 | // get ascending order of endpoints
|
---|
| 314 | map<int, class BoundaryPointSet *> OrderMap;
|
---|
| 315 | for (int i = 0; i < 3; i++)
|
---|
| 316 | // for all three lines
|
---|
| 317 | for (int j = 0; j < 2; j++)
|
---|
| 318 | { // for both endpoints
|
---|
| 319 | OrderMap.insert(pair<int, class BoundaryPointSet *> (
|
---|
| 320 | line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
|
---|
| 321 | // and we don't care whether insertion fails
|
---|
| 322 | }
|
---|
| 323 | // set endpoints
|
---|
| 324 | int Counter = 0;
|
---|
[e138de] | 325 | Log() << Verbose(6) << " with end points ";
|
---|
[357fba] | 326 | for (map<int, class BoundaryPointSet *>::iterator runner = OrderMap.begin(); runner
|
---|
| 327 | != OrderMap.end(); runner++)
|
---|
| 328 | {
|
---|
| 329 | endpoints[Counter] = runner->second;
|
---|
[e138de] | 330 | Log() << Verbose(0) << " " << *endpoints[Counter];
|
---|
[357fba] | 331 | Counter++;
|
---|
| 332 | }
|
---|
| 333 | if (Counter < 3)
|
---|
| 334 | {
|
---|
[e359a8] | 335 | eLog() << Verbose(0) << "ERROR! We have a triangle with only two distinct endpoints!" << endl;
|
---|
| 336 | performCriticalExit();
|
---|
[357fba] | 337 | }
|
---|
[e138de] | 338 | Log() << Verbose(0) << "." << endl;
|
---|
[16d866] | 339 | };
|
---|
[357fba] | 340 |
|
---|
[16d866] | 341 | /** Destructor of BoundaryTriangleSet.
|
---|
| 342 | * Removes itself from each of its lines' LineMap and removes them if necessary.
|
---|
| 343 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 344 | */
|
---|
[357fba] | 345 | BoundaryTriangleSet::~BoundaryTriangleSet()
|
---|
| 346 | {
|
---|
| 347 | for (int i = 0; i < 3; i++) {
|
---|
[16d866] | 348 | if (lines[i] != NULL) {
|
---|
[57066a] | 349 | if (lines[i]->triangles.erase(Nr)) {
|
---|
[e138de] | 350 | //Log() << Verbose(5) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
|
---|
[57066a] | 351 | }
|
---|
[16d866] | 352 | if (lines[i]->triangles.empty()) {
|
---|
[e138de] | 353 | //Log() << Verbose(5) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
|
---|
[16d866] | 354 | delete (lines[i]);
|
---|
| 355 | lines[i] = NULL;
|
---|
| 356 | }
|
---|
| 357 | }
|
---|
[357fba] | 358 | }
|
---|
[e138de] | 359 | //Log() << Verbose(5) << "Erasing triangle Nr." << Nr << " itself." << endl;
|
---|
[16d866] | 360 | };
|
---|
[357fba] | 361 |
|
---|
| 362 | /** Calculates the normal vector for this triangle.
|
---|
| 363 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 364 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 365 | */
|
---|
| 366 | void BoundaryTriangleSet::GetNormalVector(Vector &OtherVector)
|
---|
| 367 | {
|
---|
| 368 | // get normal vector
|
---|
| 369 | NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
|
---|
| 370 |
|
---|
| 371 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
[658efb] | 372 | if (NormalVector.ScalarProduct(&OtherVector) > 0.)
|
---|
[357fba] | 373 | NormalVector.Scale(-1.);
|
---|
| 374 | };
|
---|
| 375 |
|
---|
| 376 | /** Finds the point on the triangle \a *BTS the line defined by \a *MolCenter and \a *x crosses through.
|
---|
| 377 | * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
|
---|
| 378 | * This we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
[7dea7c] | 379 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 380 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 381 | * the first two basepoints) or not.
|
---|
[357fba] | 382 | * \param *out output stream for debugging
|
---|
| 383 | * \param *MolCenter offset vector of line
|
---|
| 384 | * \param *x second endpoint of line, minus \a *MolCenter is directional vector of line
|
---|
| 385 | * \param *Intersection intersection on plane on return
|
---|
| 386 | * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
|
---|
| 387 | */
|
---|
[e138de] | 388 | bool BoundaryTriangleSet::GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection)
|
---|
[357fba] | 389 | {
|
---|
| 390 | Vector CrossPoint;
|
---|
| 391 | Vector helper;
|
---|
| 392 |
|
---|
[e138de] | 393 | if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
|
---|
| 394 | Log() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
|
---|
[357fba] | 395 | return false;
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | // Calculate cross point between one baseline and the line from the third endpoint to intersection
|
---|
[5c7bf8] | 399 | int i=0;
|
---|
[357fba] | 400 | do {
|
---|
[e138de] | 401 | if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) {
|
---|
[5c7bf8] | 402 | helper.CopyVector(endpoints[(i+1)%3]->node->node);
|
---|
| 403 | helper.SubtractVector(endpoints[i%3]->node->node);
|
---|
| 404 | } else
|
---|
| 405 | i++;
|
---|
| 406 | if (i>2)
|
---|
[357fba] | 407 | break;
|
---|
| 408 | } while (CrossPoint.NormSquared() < MYEPSILON);
|
---|
[5c7bf8] | 409 | if (i==3) {
|
---|
[717e0c] | 410 | eLog() << Verbose(1) << "Could not find any cross points, something's utterly wrong here!" << endl;
|
---|
[357fba] | 411 | exit(255);
|
---|
| 412 | }
|
---|
[7dea7c] | 413 | CrossPoint.SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
[357fba] | 414 |
|
---|
| 415 | // check whether intersection is inside or not by comparing length of intersection and length of cross point
|
---|
[7dea7c] | 416 | if ((CrossPoint.NormSquared() - helper.NormSquared()) < MYEPSILON) { // inside
|
---|
[357fba] | 417 | return true;
|
---|
| 418 | } else { // outside!
|
---|
| 419 | Intersection->Zero();
|
---|
| 420 | return false;
|
---|
| 421 | }
|
---|
| 422 | };
|
---|
| 423 |
|
---|
| 424 | /** Checks whether lines is any of the three boundary lines this triangle contains.
|
---|
| 425 | * \param *line line to test
|
---|
| 426 | * \return true - line is of the triangle, false - is not
|
---|
| 427 | */
|
---|
| 428 | bool BoundaryTriangleSet::ContainsBoundaryLine(class BoundaryLineSet *line)
|
---|
| 429 | {
|
---|
| 430 | for(int i=0;i<3;i++)
|
---|
| 431 | if (line == lines[i])
|
---|
| 432 | return true;
|
---|
| 433 | return false;
|
---|
| 434 | };
|
---|
| 435 |
|
---|
| 436 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 437 | * \param *point point to test
|
---|
| 438 | * \return true - point is of the triangle, false - is not
|
---|
| 439 | */
|
---|
| 440 | bool BoundaryTriangleSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
|
---|
| 441 | {
|
---|
| 442 | for(int i=0;i<3;i++)
|
---|
| 443 | if (point == endpoints[i])
|
---|
| 444 | return true;
|
---|
| 445 | return false;
|
---|
| 446 | };
|
---|
| 447 |
|
---|
[7dea7c] | 448 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 449 | * \param *point TesselPoint to test
|
---|
| 450 | * \return true - point is of the triangle, false - is not
|
---|
| 451 | */
|
---|
| 452 | bool BoundaryTriangleSet::ContainsBoundaryPoint(class TesselPoint *point)
|
---|
| 453 | {
|
---|
| 454 | for(int i=0;i<3;i++)
|
---|
| 455 | if (point == endpoints[i]->node)
|
---|
| 456 | return true;
|
---|
| 457 | return false;
|
---|
| 458 | };
|
---|
| 459 |
|
---|
[357fba] | 460 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 461 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 462 | * \return true - is the very triangle, false - is not
|
---|
| 463 | */
|
---|
| 464 | bool BoundaryTriangleSet::IsPresentTupel(class BoundaryPointSet *Points[3])
|
---|
| 465 | {
|
---|
| 466 | return (((endpoints[0] == Points[0])
|
---|
| 467 | || (endpoints[0] == Points[1])
|
---|
| 468 | || (endpoints[0] == Points[2])
|
---|
| 469 | ) && (
|
---|
| 470 | (endpoints[1] == Points[0])
|
---|
| 471 | || (endpoints[1] == Points[1])
|
---|
| 472 | || (endpoints[1] == Points[2])
|
---|
| 473 | ) && (
|
---|
| 474 | (endpoints[2] == Points[0])
|
---|
| 475 | || (endpoints[2] == Points[1])
|
---|
| 476 | || (endpoints[2] == Points[2])
|
---|
[62bb91] | 477 |
|
---|
[357fba] | 478 | ));
|
---|
| 479 | };
|
---|
| 480 |
|
---|
[57066a] | 481 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 482 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 483 | * \return true - is the very triangle, false - is not
|
---|
| 484 | */
|
---|
| 485 | bool BoundaryTriangleSet::IsPresentTupel(class BoundaryTriangleSet *T)
|
---|
| 486 | {
|
---|
| 487 | return (((endpoints[0] == T->endpoints[0])
|
---|
| 488 | || (endpoints[0] == T->endpoints[1])
|
---|
| 489 | || (endpoints[0] == T->endpoints[2])
|
---|
| 490 | ) && (
|
---|
| 491 | (endpoints[1] == T->endpoints[0])
|
---|
| 492 | || (endpoints[1] == T->endpoints[1])
|
---|
| 493 | || (endpoints[1] == T->endpoints[2])
|
---|
| 494 | ) && (
|
---|
| 495 | (endpoints[2] == T->endpoints[0])
|
---|
| 496 | || (endpoints[2] == T->endpoints[1])
|
---|
| 497 | || (endpoints[2] == T->endpoints[2])
|
---|
| 498 |
|
---|
| 499 | ));
|
---|
| 500 | };
|
---|
| 501 |
|
---|
[62bb91] | 502 | /** Returns the endpoint which is not contained in the given \a *line.
|
---|
| 503 | * \param *line baseline defining two endpoints
|
---|
| 504 | * \return pointer third endpoint or NULL if line does not belong to triangle.
|
---|
| 505 | */
|
---|
| 506 | class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(class BoundaryLineSet *line)
|
---|
| 507 | {
|
---|
| 508 | // sanity check
|
---|
| 509 | if (!ContainsBoundaryLine(line))
|
---|
| 510 | return NULL;
|
---|
| 511 | for(int i=0;i<3;i++)
|
---|
| 512 | if (!line->ContainsBoundaryPoint(endpoints[i]))
|
---|
| 513 | return endpoints[i];
|
---|
| 514 | // actually, that' impossible :)
|
---|
| 515 | return NULL;
|
---|
| 516 | };
|
---|
| 517 |
|
---|
| 518 | /** Calculates the center point of the triangle.
|
---|
| 519 | * Is third of the sum of all endpoints.
|
---|
| 520 | * \param *center central point on return.
|
---|
| 521 | */
|
---|
| 522 | void BoundaryTriangleSet::GetCenter(Vector *center)
|
---|
| 523 | {
|
---|
| 524 | center->Zero();
|
---|
| 525 | for(int i=0;i<3;i++)
|
---|
| 526 | center->AddVector(endpoints[i]->node->node);
|
---|
| 527 | center->Scale(1./3.);
|
---|
| 528 | }
|
---|
| 529 |
|
---|
[16d866] | 530 | /** output operator for BoundaryTriangleSet.
|
---|
| 531 | * \param &ost output stream
|
---|
| 532 | * \param &a boundary triangle
|
---|
| 533 | */
|
---|
[776b64] | 534 | ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
|
---|
[357fba] | 535 | {
|
---|
[57066a] | 536 | ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
|
---|
| 537 | << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
|
---|
[357fba] | 538 | return ost;
|
---|
[16d866] | 539 | };
|
---|
[357fba] | 540 |
|
---|
| 541 | // =========================================================== class TESSELPOINT ===========================================
|
---|
| 542 |
|
---|
| 543 | /** Constructor of class TesselPoint.
|
---|
| 544 | */
|
---|
| 545 | TesselPoint::TesselPoint()
|
---|
| 546 | {
|
---|
| 547 | node = NULL;
|
---|
| 548 | nr = -1;
|
---|
| 549 | Name = NULL;
|
---|
| 550 | };
|
---|
| 551 |
|
---|
| 552 | /** Destructor for class TesselPoint.
|
---|
| 553 | */
|
---|
| 554 | TesselPoint::~TesselPoint()
|
---|
| 555 | {
|
---|
| 556 | };
|
---|
| 557 |
|
---|
| 558 | /** Prints LCNode to screen.
|
---|
| 559 | */
|
---|
| 560 | ostream & operator << (ostream &ost, const TesselPoint &a)
|
---|
| 561 | {
|
---|
[57066a] | 562 | ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]";
|
---|
[357fba] | 563 | return ost;
|
---|
| 564 | };
|
---|
| 565 |
|
---|
[5c7bf8] | 566 | /** Prints LCNode to screen.
|
---|
| 567 | */
|
---|
| 568 | ostream & TesselPoint::operator << (ostream &ost)
|
---|
| 569 | {
|
---|
| 570 | ost << "[" << (Name) << "|" << this << "]";
|
---|
| 571 | return ost;
|
---|
| 572 | };
|
---|
| 573 |
|
---|
[357fba] | 574 |
|
---|
| 575 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 576 |
|
---|
| 577 | /** Constructor of class PointCloud.
|
---|
| 578 | */
|
---|
| 579 | PointCloud::PointCloud()
|
---|
| 580 | {
|
---|
| 581 |
|
---|
| 582 | };
|
---|
| 583 |
|
---|
| 584 | /** Destructor for class PointCloud.
|
---|
| 585 | */
|
---|
| 586 | PointCloud::~PointCloud()
|
---|
| 587 | {
|
---|
| 588 |
|
---|
| 589 | };
|
---|
| 590 |
|
---|
| 591 | // ============================ CandidateForTesselation =============================
|
---|
| 592 |
|
---|
| 593 | /** Constructor of class CandidateForTesselation.
|
---|
| 594 | */
|
---|
| 595 | CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) {
|
---|
| 596 | point = candidate;
|
---|
| 597 | BaseLine = line;
|
---|
| 598 | OptCenter.CopyVector(&OptCandidateCenter);
|
---|
| 599 | OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
|
---|
| 600 | };
|
---|
| 601 |
|
---|
| 602 | /** Destructor for class CandidateForTesselation.
|
---|
| 603 | */
|
---|
| 604 | CandidateForTesselation::~CandidateForTesselation() {
|
---|
| 605 | point = NULL;
|
---|
| 606 | BaseLine = NULL;
|
---|
| 607 | };
|
---|
| 608 |
|
---|
| 609 | // =========================================================== class TESSELATION ===========================================
|
---|
| 610 |
|
---|
| 611 | /** Constructor of class Tesselation.
|
---|
| 612 | */
|
---|
| 613 | Tesselation::Tesselation()
|
---|
| 614 | {
|
---|
| 615 | PointsOnBoundaryCount = 0;
|
---|
| 616 | LinesOnBoundaryCount = 0;
|
---|
| 617 | TrianglesOnBoundaryCount = 0;
|
---|
[5c7bf8] | 618 | InternalPointer = PointsOnBoundary.begin();
|
---|
[57066a] | 619 | LastTriangle = NULL;
|
---|
| 620 | TriangleFilesWritten = 0;
|
---|
[357fba] | 621 | }
|
---|
| 622 | ;
|
---|
| 623 |
|
---|
| 624 | /** Destructor of class Tesselation.
|
---|
| 625 | * We have to free all points, lines and triangles.
|
---|
| 626 | */
|
---|
| 627 | Tesselation::~Tesselation()
|
---|
| 628 | {
|
---|
[e138de] | 629 | Log() << Verbose(1) << "Free'ing TesselStruct ... " << endl;
|
---|
[357fba] | 630 | for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
|
---|
| 631 | if (runner->second != NULL) {
|
---|
| 632 | delete (runner->second);
|
---|
| 633 | runner->second = NULL;
|
---|
| 634 | } else
|
---|
[717e0c] | 635 | eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl;
|
---|
[357fba] | 636 | }
|
---|
[e138de] | 637 | Log() << Verbose(1) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
|
---|
[357fba] | 638 | }
|
---|
| 639 | ;
|
---|
| 640 |
|
---|
[5c7bf8] | 641 | /** PointCloud implementation of GetCenter
|
---|
| 642 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 643 | */
|
---|
[776b64] | 644 | Vector * Tesselation::GetCenter(ofstream *out) const
|
---|
[5c7bf8] | 645 | {
|
---|
| 646 | Vector *Center = new Vector(0.,0.,0.);
|
---|
| 647 | int num=0;
|
---|
| 648 | for (GoToFirst(); (!IsEnd()); GoToNext()) {
|
---|
| 649 | Center->AddVector(GetPoint()->node);
|
---|
| 650 | num++;
|
---|
| 651 | }
|
---|
| 652 | Center->Scale(1./num);
|
---|
| 653 | return Center;
|
---|
| 654 | };
|
---|
| 655 |
|
---|
| 656 | /** PointCloud implementation of GoPoint
|
---|
| 657 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 658 | */
|
---|
[776b64] | 659 | TesselPoint * Tesselation::GetPoint() const
|
---|
[5c7bf8] | 660 | {
|
---|
| 661 | return (InternalPointer->second->node);
|
---|
| 662 | };
|
---|
| 663 |
|
---|
| 664 | /** PointCloud implementation of GetTerminalPoint.
|
---|
| 665 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 666 | */
|
---|
[776b64] | 667 | TesselPoint * Tesselation::GetTerminalPoint() const
|
---|
[5c7bf8] | 668 | {
|
---|
[776b64] | 669 | PointMap::const_iterator Runner = PointsOnBoundary.end();
|
---|
[5c7bf8] | 670 | Runner--;
|
---|
| 671 | return (Runner->second->node);
|
---|
| 672 | };
|
---|
| 673 |
|
---|
| 674 | /** PointCloud implementation of GoToNext.
|
---|
| 675 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 676 | */
|
---|
[776b64] | 677 | void Tesselation::GoToNext() const
|
---|
[5c7bf8] | 678 | {
|
---|
| 679 | if (InternalPointer != PointsOnBoundary.end())
|
---|
| 680 | InternalPointer++;
|
---|
| 681 | };
|
---|
| 682 |
|
---|
| 683 | /** PointCloud implementation of GoToPrevious.
|
---|
| 684 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 685 | */
|
---|
[776b64] | 686 | void Tesselation::GoToPrevious() const
|
---|
[5c7bf8] | 687 | {
|
---|
| 688 | if (InternalPointer != PointsOnBoundary.begin())
|
---|
| 689 | InternalPointer--;
|
---|
| 690 | };
|
---|
| 691 |
|
---|
| 692 | /** PointCloud implementation of GoToFirst.
|
---|
| 693 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 694 | */
|
---|
[776b64] | 695 | void Tesselation::GoToFirst() const
|
---|
[5c7bf8] | 696 | {
|
---|
| 697 | InternalPointer = PointsOnBoundary.begin();
|
---|
| 698 | };
|
---|
| 699 |
|
---|
| 700 | /** PointCloud implementation of GoToLast.
|
---|
| 701 | * Uses PointsOnBoundary and STL stuff.
|
---|
[776b64] | 702 | */
|
---|
| 703 | void Tesselation::GoToLast() const
|
---|
[5c7bf8] | 704 | {
|
---|
| 705 | InternalPointer = PointsOnBoundary.end();
|
---|
| 706 | InternalPointer--;
|
---|
| 707 | };
|
---|
| 708 |
|
---|
| 709 | /** PointCloud implementation of IsEmpty.
|
---|
| 710 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 711 | */
|
---|
[776b64] | 712 | bool Tesselation::IsEmpty() const
|
---|
[5c7bf8] | 713 | {
|
---|
| 714 | return (PointsOnBoundary.empty());
|
---|
| 715 | };
|
---|
| 716 |
|
---|
| 717 | /** PointCloud implementation of IsLast.
|
---|
| 718 | * Uses PointsOnBoundary and STL stuff.
|
---|
| 719 | */
|
---|
[776b64] | 720 | bool Tesselation::IsEnd() const
|
---|
[5c7bf8] | 721 | {
|
---|
| 722 | return (InternalPointer == PointsOnBoundary.end());
|
---|
| 723 | };
|
---|
| 724 |
|
---|
| 725 |
|
---|
[357fba] | 726 | /** Gueses first starting triangle of the convex envelope.
|
---|
| 727 | * We guess the starting triangle by taking the smallest distance between two points and looking for a fitting third.
|
---|
| 728 | * \param *out output stream for debugging
|
---|
| 729 | * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
|
---|
| 730 | */
|
---|
| 731 | void
|
---|
[e138de] | 732 | Tesselation::GuessStartingTriangle()
|
---|
[357fba] | 733 | {
|
---|
| 734 | // 4b. create a starting triangle
|
---|
| 735 | // 4b1. create all distances
|
---|
| 736 | DistanceMultiMap DistanceMMap;
|
---|
| 737 | double distance, tmp;
|
---|
| 738 | Vector PlaneVector, TrialVector;
|
---|
| 739 | PointMap::iterator A, B, C; // three nodes of the first triangle
|
---|
| 740 | A = PointsOnBoundary.begin(); // the first may be chosen arbitrarily
|
---|
| 741 |
|
---|
| 742 | // with A chosen, take each pair B,C and sort
|
---|
| 743 | if (A != PointsOnBoundary.end())
|
---|
| 744 | {
|
---|
| 745 | B = A;
|
---|
| 746 | B++;
|
---|
| 747 | for (; B != PointsOnBoundary.end(); B++)
|
---|
| 748 | {
|
---|
| 749 | C = B;
|
---|
| 750 | C++;
|
---|
| 751 | for (; C != PointsOnBoundary.end(); C++)
|
---|
| 752 | {
|
---|
| 753 | tmp = A->second->node->node->DistanceSquared(B->second->node->node);
|
---|
| 754 | distance = tmp * tmp;
|
---|
| 755 | tmp = A->second->node->node->DistanceSquared(C->second->node->node);
|
---|
| 756 | distance += tmp * tmp;
|
---|
| 757 | tmp = B->second->node->node->DistanceSquared(C->second->node->node);
|
---|
| 758 | distance += tmp * tmp;
|
---|
| 759 | DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
|
---|
| 760 | }
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
| 763 | // // listing distances
|
---|
[e138de] | 764 | // Log() << Verbose(1) << "Listing DistanceMMap:";
|
---|
[357fba] | 765 | // for(DistanceMultiMap::iterator runner = DistanceMMap.begin(); runner != DistanceMMap.end(); runner++) {
|
---|
[e138de] | 766 | // Log() << Verbose(0) << " " << runner->first << "(" << *runner->second.first->second << ", " << *runner->second.second->second << ")";
|
---|
[357fba] | 767 | // }
|
---|
[e138de] | 768 | // Log() << Verbose(0) << endl;
|
---|
[357fba] | 769 | // 4b2. pick three baselines forming a triangle
|
---|
| 770 | // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 771 | DistanceMultiMap::iterator baseline = DistanceMMap.begin();
|
---|
| 772 | for (; baseline != DistanceMMap.end(); baseline++)
|
---|
| 773 | {
|
---|
| 774 | // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 775 | // 2. next, we have to check whether all points reside on only one side of the triangle
|
---|
| 776 | // 3. construct plane vector
|
---|
| 777 | PlaneVector.MakeNormalVector(A->second->node->node,
|
---|
| 778 | baseline->second.first->second->node->node,
|
---|
| 779 | baseline->second.second->second->node->node);
|
---|
[e138de] | 780 | Log() << Verbose(2) << "Plane vector of candidate triangle is ";
|
---|
| 781 | PlaneVector.Output();
|
---|
| 782 | Log() << Verbose(0) << endl;
|
---|
[357fba] | 783 | // 4. loop over all points
|
---|
| 784 | double sign = 0.;
|
---|
| 785 | PointMap::iterator checker = PointsOnBoundary.begin();
|
---|
| 786 | for (; checker != PointsOnBoundary.end(); checker++)
|
---|
| 787 | {
|
---|
| 788 | // (neglecting A,B,C)
|
---|
| 789 | if ((checker == A) || (checker == baseline->second.first) || (checker
|
---|
| 790 | == baseline->second.second))
|
---|
| 791 | continue;
|
---|
| 792 | // 4a. project onto plane vector
|
---|
| 793 | TrialVector.CopyVector(checker->second->node->node);
|
---|
| 794 | TrialVector.SubtractVector(A->second->node->node);
|
---|
[658efb] | 795 | distance = TrialVector.ScalarProduct(&PlaneVector);
|
---|
[357fba] | 796 | if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
|
---|
| 797 | continue;
|
---|
[e138de] | 798 | Log() << Verbose(3) << "Projection of " << checker->second->node->Name
|
---|
[357fba] | 799 | << " yields distance of " << distance << "." << endl;
|
---|
| 800 | tmp = distance / fabs(distance);
|
---|
| 801 | // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
|
---|
| 802 | if ((sign != 0) && (tmp != sign))
|
---|
| 803 | {
|
---|
| 804 | // 4c. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
[e138de] | 805 | Log() << Verbose(2) << "Current candidates: "
|
---|
[357fba] | 806 | << A->second->node->Name << ","
|
---|
| 807 | << baseline->second.first->second->node->Name << ","
|
---|
| 808 | << baseline->second.second->second->node->Name << " leaves "
|
---|
| 809 | << checker->second->node->Name << " outside the convex hull."
|
---|
| 810 | << endl;
|
---|
| 811 | break;
|
---|
| 812 | }
|
---|
| 813 | else
|
---|
| 814 | { // note the sign for later
|
---|
[e138de] | 815 | Log() << Verbose(2) << "Current candidates: "
|
---|
[357fba] | 816 | << A->second->node->Name << ","
|
---|
| 817 | << baseline->second.first->second->node->Name << ","
|
---|
| 818 | << baseline->second.second->second->node->Name << " leave "
|
---|
| 819 | << checker->second->node->Name << " inside the convex hull."
|
---|
| 820 | << endl;
|
---|
| 821 | sign = tmp;
|
---|
| 822 | }
|
---|
| 823 | // 4d. Check whether the point is inside the triangle (check distance to each node
|
---|
| 824 | tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
|
---|
| 825 | int innerpoint = 0;
|
---|
| 826 | if ((tmp < A->second->node->node->DistanceSquared(
|
---|
| 827 | baseline->second.first->second->node->node)) && (tmp
|
---|
| 828 | < A->second->node->node->DistanceSquared(
|
---|
| 829 | baseline->second.second->second->node->node)))
|
---|
| 830 | innerpoint++;
|
---|
| 831 | tmp = checker->second->node->node->DistanceSquared(
|
---|
| 832 | baseline->second.first->second->node->node);
|
---|
| 833 | if ((tmp < baseline->second.first->second->node->node->DistanceSquared(
|
---|
| 834 | A->second->node->node)) && (tmp
|
---|
| 835 | < baseline->second.first->second->node->node->DistanceSquared(
|
---|
| 836 | baseline->second.second->second->node->node)))
|
---|
| 837 | innerpoint++;
|
---|
| 838 | tmp = checker->second->node->node->DistanceSquared(
|
---|
| 839 | baseline->second.second->second->node->node);
|
---|
| 840 | if ((tmp < baseline->second.second->second->node->node->DistanceSquared(
|
---|
| 841 | baseline->second.first->second->node->node)) && (tmp
|
---|
| 842 | < baseline->second.second->second->node->node->DistanceSquared(
|
---|
| 843 | A->second->node->node)))
|
---|
| 844 | innerpoint++;
|
---|
| 845 | // 4e. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
| 846 | if (innerpoint == 3)
|
---|
| 847 | break;
|
---|
| 848 | }
|
---|
| 849 | // 5. come this far, all on same side? Then break 1. loop and construct triangle
|
---|
| 850 | if (checker == PointsOnBoundary.end())
|
---|
| 851 | {
|
---|
[e138de] | 852 | Log() << Verbose(0) << "Looks like we have a candidate!" << endl;
|
---|
[357fba] | 853 | break;
|
---|
| 854 | }
|
---|
| 855 | }
|
---|
| 856 | if (baseline != DistanceMMap.end())
|
---|
| 857 | {
|
---|
| 858 | BPS[0] = baseline->second.first->second;
|
---|
| 859 | BPS[1] = baseline->second.second->second;
|
---|
| 860 | BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 861 | BPS[0] = A->second;
|
---|
| 862 | BPS[1] = baseline->second.second->second;
|
---|
| 863 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 864 | BPS[0] = baseline->second.first->second;
|
---|
| 865 | BPS[1] = A->second;
|
---|
| 866 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 867 |
|
---|
| 868 | // 4b3. insert created triangle
|
---|
| 869 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 870 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 871 | TrianglesOnBoundaryCount++;
|
---|
| 872 | for (int i = 0; i < NDIM; i++)
|
---|
| 873 | {
|
---|
| 874 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
|
---|
| 875 | LinesOnBoundaryCount++;
|
---|
| 876 | }
|
---|
| 877 |
|
---|
[e138de] | 878 | Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl;
|
---|
[357fba] | 879 | }
|
---|
| 880 | else
|
---|
| 881 | {
|
---|
[e138de] | 882 | Log() << Verbose(1) << "No starting triangle found." << endl;
|
---|
[357fba] | 883 | exit(255);
|
---|
| 884 | }
|
---|
| 885 | }
|
---|
| 886 | ;
|
---|
| 887 |
|
---|
| 888 | /** Tesselates the convex envelope of a cluster from a single starting triangle.
|
---|
| 889 | * The starting triangle is made out of three baselines. Each line in the final tesselated cluster may belong to at most
|
---|
| 890 | * 2 triangles. Hence, we go through all current lines:
|
---|
| 891 | * -# if the lines contains to only one triangle
|
---|
| 892 | * -# We search all points in the boundary
|
---|
| 893 | * -# if the triangle is in forward direction of the baseline (at most 90 degrees angle between vector orthogonal to
|
---|
| 894 | * baseline in triangle plane pointing out of the triangle and normal vector of new triangle)
|
---|
| 895 | * -# if the triangle with the baseline and the current point has the smallest of angles (comparison between normal vectors)
|
---|
| 896 | * -# then we have a new triangle, whose baselines we again add (or increase their TriangleCount)
|
---|
| 897 | * \param *out output stream for debugging
|
---|
| 898 | * \param *configuration for IsAngstroem
|
---|
| 899 | * \param *cloud cluster of points
|
---|
| 900 | */
|
---|
[e138de] | 901 | void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
|
---|
[357fba] | 902 | {
|
---|
| 903 | bool flag;
|
---|
| 904 | PointMap::iterator winner;
|
---|
| 905 | class BoundaryPointSet *peak = NULL;
|
---|
| 906 | double SmallestAngle, TempAngle;
|
---|
| 907 | Vector NormalVector, VirtualNormalVector, CenterVector, TempVector, helper, PropagationVector, *Center = NULL;
|
---|
| 908 | LineMap::iterator LineChecker[2];
|
---|
| 909 |
|
---|
[e138de] | 910 | Center = cloud->GetCenter();
|
---|
[357fba] | 911 | // create a first tesselation with the given BoundaryPoints
|
---|
| 912 | do {
|
---|
| 913 | flag = false;
|
---|
| 914 | for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++)
|
---|
[5c7bf8] | 915 | if (baseline->second->triangles.size() == 1) {
|
---|
[357fba] | 916 | // 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)
|
---|
| 917 | SmallestAngle = M_PI;
|
---|
| 918 |
|
---|
| 919 | // get peak point with respect to this base line's only triangle
|
---|
| 920 | BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
|
---|
[e138de] | 921 | Log() << Verbose(2) << "Current baseline is between " << *(baseline->second) << "." << endl;
|
---|
[357fba] | 922 | for (int i = 0; i < 3; i++)
|
---|
| 923 | if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
|
---|
| 924 | peak = BTS->endpoints[i];
|
---|
[e138de] | 925 | Log() << Verbose(3) << " and has peak " << *peak << "." << endl;
|
---|
[357fba] | 926 |
|
---|
| 927 | // prepare some auxiliary vectors
|
---|
| 928 | Vector BaseLineCenter, BaseLine;
|
---|
| 929 | BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node);
|
---|
| 930 | BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node);
|
---|
| 931 | BaseLineCenter.Scale(1. / 2.); // points now to center of base line
|
---|
| 932 | BaseLine.CopyVector(baseline->second->endpoints[0]->node->node);
|
---|
| 933 | BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node);
|
---|
| 934 |
|
---|
| 935 | // offset to center of triangle
|
---|
| 936 | CenterVector.Zero();
|
---|
| 937 | for (int i = 0; i < 3; i++)
|
---|
| 938 | CenterVector.AddVector(BTS->endpoints[i]->node->node);
|
---|
| 939 | CenterVector.Scale(1. / 3.);
|
---|
[e138de] | 940 | Log() << Verbose(4) << "CenterVector of base triangle is " << CenterVector << endl;
|
---|
[357fba] | 941 |
|
---|
| 942 | // normal vector of triangle
|
---|
| 943 | NormalVector.CopyVector(Center);
|
---|
| 944 | NormalVector.SubtractVector(&CenterVector);
|
---|
| 945 | BTS->GetNormalVector(NormalVector);
|
---|
| 946 | NormalVector.CopyVector(&BTS->NormalVector);
|
---|
[e138de] | 947 | Log() << Verbose(4) << "NormalVector of base triangle is " << NormalVector << endl;
|
---|
[357fba] | 948 |
|
---|
| 949 | // vector in propagation direction (out of triangle)
|
---|
| 950 | // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
|
---|
| 951 | PropagationVector.MakeNormalVector(&BaseLine, &NormalVector);
|
---|
| 952 | TempVector.CopyVector(&CenterVector);
|
---|
| 953 | TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
|
---|
[e138de] | 954 | //Log() << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
|
---|
[658efb] | 955 | if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
|
---|
[357fba] | 956 | PropagationVector.Scale(-1.);
|
---|
[e138de] | 957 | Log() << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl;
|
---|
[357fba] | 958 | winner = PointsOnBoundary.end();
|
---|
| 959 |
|
---|
| 960 | // loop over all points and calculate angle between normal vector of new and present triangle
|
---|
| 961 | for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
|
---|
| 962 | if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
|
---|
[e138de] | 963 | Log() << Verbose(3) << "Target point is " << *(target->second) << ":" << endl;
|
---|
[357fba] | 964 |
|
---|
| 965 | // first check direction, so that triangles don't intersect
|
---|
| 966 | VirtualNormalVector.CopyVector(target->second->node->node);
|
---|
| 967 | VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target
|
---|
| 968 | VirtualNormalVector.ProjectOntoPlane(&NormalVector);
|
---|
| 969 | TempAngle = VirtualNormalVector.Angle(&PropagationVector);
|
---|
[e138de] | 970 | Log() << Verbose(4) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
|
---|
[357fba] | 971 | if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees)
|
---|
[e138de] | 972 | Log() << Verbose(4) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
|
---|
[357fba] | 973 | continue;
|
---|
| 974 | } else
|
---|
[e138de] | 975 | Log() << Verbose(4) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
|
---|
[357fba] | 976 |
|
---|
| 977 | // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
|
---|
| 978 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(target->first);
|
---|
| 979 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
|
---|
[5c7bf8] | 980 | if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
|
---|
[e138de] | 981 | Log() << Verbose(4) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl;
|
---|
[357fba] | 982 | continue;
|
---|
| 983 | }
|
---|
[5c7bf8] | 984 | if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
|
---|
[e138de] | 985 | Log() << Verbose(4) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl;
|
---|
[357fba] | 986 | continue;
|
---|
| 987 | }
|
---|
| 988 |
|
---|
| 989 | // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
|
---|
| 990 | 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] | 991 | Log() << Verbose(4) << "Current target is peak!" << endl;
|
---|
[357fba] | 992 | continue;
|
---|
| 993 | }
|
---|
| 994 |
|
---|
| 995 | // check for linear dependence
|
---|
| 996 | TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
|
---|
| 997 | TempVector.SubtractVector(target->second->node->node);
|
---|
| 998 | helper.CopyVector(baseline->second->endpoints[1]->node->node);
|
---|
| 999 | helper.SubtractVector(target->second->node->node);
|
---|
| 1000 | helper.ProjectOntoPlane(&TempVector);
|
---|
| 1001 | if (fabs(helper.NormSquared()) < MYEPSILON) {
|
---|
[e138de] | 1002 | Log() << Verbose(4) << "Chosen set of vectors is linear dependent." << endl;
|
---|
[357fba] | 1003 | continue;
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
|
---|
| 1007 | flag = true;
|
---|
| 1008 | VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node);
|
---|
| 1009 | TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
|
---|
| 1010 | TempVector.AddVector(baseline->second->endpoints[1]->node->node);
|
---|
| 1011 | TempVector.AddVector(target->second->node->node);
|
---|
| 1012 | TempVector.Scale(1./3.);
|
---|
| 1013 | TempVector.SubtractVector(Center);
|
---|
| 1014 | // make it always point outward
|
---|
[658efb] | 1015 | if (VirtualNormalVector.ScalarProduct(&TempVector) < 0)
|
---|
[357fba] | 1016 | VirtualNormalVector.Scale(-1.);
|
---|
| 1017 | // calculate angle
|
---|
| 1018 | TempAngle = NormalVector.Angle(&VirtualNormalVector);
|
---|
[e138de] | 1019 | Log() << Verbose(4) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
|
---|
[357fba] | 1020 | if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
|
---|
| 1021 | SmallestAngle = TempAngle;
|
---|
| 1022 | winner = target;
|
---|
[e138de] | 1023 | Log() << Verbose(4) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
|
---|
[357fba] | 1024 | } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
|
---|
| 1025 | // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
|
---|
| 1026 | helper.CopyVector(target->second->node->node);
|
---|
| 1027 | helper.SubtractVector(&BaseLineCenter);
|
---|
| 1028 | helper.ProjectOntoPlane(&BaseLine);
|
---|
| 1029 | // ...the one with the smaller angle is the better candidate
|
---|
| 1030 | TempVector.CopyVector(target->second->node->node);
|
---|
| 1031 | TempVector.SubtractVector(&BaseLineCenter);
|
---|
| 1032 | TempVector.ProjectOntoPlane(&VirtualNormalVector);
|
---|
| 1033 | TempAngle = TempVector.Angle(&helper);
|
---|
| 1034 | TempVector.CopyVector(winner->second->node->node);
|
---|
| 1035 | TempVector.SubtractVector(&BaseLineCenter);
|
---|
| 1036 | TempVector.ProjectOntoPlane(&VirtualNormalVector);
|
---|
| 1037 | if (TempAngle < TempVector.Angle(&helper)) {
|
---|
| 1038 | TempAngle = NormalVector.Angle(&VirtualNormalVector);
|
---|
| 1039 | SmallestAngle = TempAngle;
|
---|
| 1040 | winner = target;
|
---|
[e138de] | 1041 | Log() << Verbose(4) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
|
---|
[357fba] | 1042 | } else
|
---|
[e138de] | 1043 | Log() << Verbose(4) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
|
---|
[357fba] | 1044 | } else
|
---|
[e138de] | 1045 | Log() << Verbose(4) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
|
---|
[357fba] | 1046 | }
|
---|
| 1047 | } // end of loop over all boundary points
|
---|
| 1048 |
|
---|
| 1049 | // 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
|
---|
| 1050 | if (winner != PointsOnBoundary.end()) {
|
---|
[e138de] | 1051 | Log() << Verbose(2) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
|
---|
[357fba] | 1052 | // create the lins of not yet present
|
---|
| 1053 | BLS[0] = baseline->second;
|
---|
| 1054 | // 5c. add lines to the line set if those were new (not yet part of a triangle), delete lines that belong to two triangles)
|
---|
| 1055 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(winner->first);
|
---|
| 1056 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(winner->first);
|
---|
| 1057 | if (LineChecker[0] == baseline->second->endpoints[0]->lines.end()) { // create
|
---|
| 1058 | BPS[0] = baseline->second->endpoints[0];
|
---|
| 1059 | BPS[1] = winner->second;
|
---|
| 1060 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1061 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[1]));
|
---|
| 1062 | LinesOnBoundaryCount++;
|
---|
| 1063 | } else
|
---|
| 1064 | BLS[1] = LineChecker[0]->second;
|
---|
| 1065 | if (LineChecker[1] == baseline->second->endpoints[1]->lines.end()) { // create
|
---|
| 1066 | BPS[0] = baseline->second->endpoints[1];
|
---|
| 1067 | BPS[1] = winner->second;
|
---|
| 1068 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1069 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[2]));
|
---|
| 1070 | LinesOnBoundaryCount++;
|
---|
| 1071 | } else
|
---|
| 1072 | BLS[2] = LineChecker[1]->second;
|
---|
| 1073 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[62bb91] | 1074 | BTS->GetCenter(&helper);
|
---|
| 1075 | helper.SubtractVector(Center);
|
---|
| 1076 | helper.Scale(-1);
|
---|
| 1077 | BTS->GetNormalVector(helper);
|
---|
[357fba] | 1078 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1079 | TrianglesOnBoundaryCount++;
|
---|
| 1080 | } else {
|
---|
[e138de] | 1081 | Log() << Verbose(1) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
|
---|
[357fba] | 1082 | }
|
---|
| 1083 |
|
---|
| 1084 | // 5d. If the set of lines is not yet empty, go to 5. and continue
|
---|
| 1085 | } else
|
---|
[e138de] | 1086 | Log() << Verbose(2) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
|
---|
[357fba] | 1087 | } while (flag);
|
---|
| 1088 |
|
---|
| 1089 | // exit
|
---|
| 1090 | delete(Center);
|
---|
| 1091 | };
|
---|
| 1092 |
|
---|
[62bb91] | 1093 | /** Inserts all points outside of the tesselated surface into it by adding new triangles.
|
---|
[357fba] | 1094 | * \param *out output stream for debugging
|
---|
| 1095 | * \param *cloud cluster of points
|
---|
[62bb91] | 1096 | * \param *LC LinkedCell structure to find nearest point quickly
|
---|
[357fba] | 1097 | * \return true - all straddling points insert, false - something went wrong
|
---|
| 1098 | */
|
---|
[e138de] | 1099 | bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
|
---|
[357fba] | 1100 | {
|
---|
[5c7bf8] | 1101 | Vector Intersection, Normal;
|
---|
[357fba] | 1102 | TesselPoint *Walker = NULL;
|
---|
[e138de] | 1103 | Vector *Center = cloud->GetCenter();
|
---|
[62bb91] | 1104 | list<BoundaryTriangleSet*> *triangles = NULL;
|
---|
[7dea7c] | 1105 | bool AddFlag = false;
|
---|
| 1106 | LinkedCell *BoundaryPoints = NULL;
|
---|
[62bb91] | 1107 |
|
---|
[e138de] | 1108 | Log() << Verbose(1) << "Begin of InsertStraddlingPoints" << endl;
|
---|
[357fba] | 1109 |
|
---|
| 1110 | cloud->GoToFirst();
|
---|
[7dea7c] | 1111 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
[1999d8] | 1112 | while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
|
---|
[7dea7c] | 1113 | if (AddFlag) {
|
---|
| 1114 | delete(BoundaryPoints);
|
---|
| 1115 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
| 1116 | AddFlag = false;
|
---|
| 1117 | }
|
---|
[357fba] | 1118 | Walker = cloud->GetPoint();
|
---|
[e138de] | 1119 | Log() << Verbose(2) << "Current point is " << *Walker << "." << endl;
|
---|
[357fba] | 1120 | // get the next triangle
|
---|
[e138de] | 1121 | triangles = FindClosestTrianglesToPoint(Walker->node, BoundaryPoints);
|
---|
[7dea7c] | 1122 | BTS = triangles->front();
|
---|
| 1123 | if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
|
---|
[e138de] | 1124 | Log() << Verbose(2) << "No triangles found, probably a tesselation point itself." << endl;
|
---|
[62bb91] | 1125 | cloud->GoToNext();
|
---|
| 1126 | continue;
|
---|
| 1127 | } else {
|
---|
[357fba] | 1128 | }
|
---|
[e138de] | 1129 | Log() << Verbose(2) << "Closest triangle is " << *BTS << "." << endl;
|
---|
[357fba] | 1130 | // get the intersection point
|
---|
[e138de] | 1131 | if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
|
---|
| 1132 | Log() << Verbose(2) << "We have an intersection at " << Intersection << "." << endl;
|
---|
[357fba] | 1133 | // we have the intersection, check whether in- or outside of boundary
|
---|
| 1134 | if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
|
---|
| 1135 | // inside, next!
|
---|
[e138de] | 1136 | Log() << Verbose(2) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
|
---|
[357fba] | 1137 | } else {
|
---|
| 1138 | // outside!
|
---|
[e138de] | 1139 | Log() << Verbose(2) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
|
---|
[357fba] | 1140 | class BoundaryLineSet *OldLines[3], *NewLines[3];
|
---|
| 1141 | class BoundaryPointSet *OldPoints[3], *NewPoint;
|
---|
| 1142 | // store the three old lines and old points
|
---|
| 1143 | for (int i=0;i<3;i++) {
|
---|
| 1144 | OldLines[i] = BTS->lines[i];
|
---|
| 1145 | OldPoints[i] = BTS->endpoints[i];
|
---|
| 1146 | }
|
---|
[5c7bf8] | 1147 | Normal.CopyVector(&BTS->NormalVector);
|
---|
[357fba] | 1148 | // add Walker to boundary points
|
---|
[e138de] | 1149 | Log() << Verbose(2) << "Adding " << *Walker << " to BoundaryPoints." << endl;
|
---|
[7dea7c] | 1150 | AddFlag = true;
|
---|
[16d866] | 1151 | if (AddBoundaryPoint(Walker,0))
|
---|
[357fba] | 1152 | NewPoint = BPS[0];
|
---|
| 1153 | else
|
---|
| 1154 | continue;
|
---|
| 1155 | // remove triangle
|
---|
[e138de] | 1156 | Log() << Verbose(2) << "Erasing triangle " << *BTS << "." << endl;
|
---|
[357fba] | 1157 | TrianglesOnBoundary.erase(BTS->Nr);
|
---|
[5c7bf8] | 1158 | delete(BTS);
|
---|
[357fba] | 1159 | // create three new boundary lines
|
---|
| 1160 | for (int i=0;i<3;i++) {
|
---|
| 1161 | BPS[0] = NewPoint;
|
---|
| 1162 | BPS[1] = OldPoints[i];
|
---|
| 1163 | NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
[e138de] | 1164 | Log() << Verbose(3) << "Creating new line " << *NewLines[i] << "." << endl;
|
---|
[357fba] | 1165 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
|
---|
| 1166 | LinesOnBoundaryCount++;
|
---|
| 1167 | }
|
---|
| 1168 | // create three new triangle with new point
|
---|
| 1169 | for (int i=0;i<3;i++) { // find all baselines
|
---|
| 1170 | BLS[0] = OldLines[i];
|
---|
| 1171 | int n = 1;
|
---|
| 1172 | for (int j=0;j<3;j++) {
|
---|
| 1173 | if (NewLines[j]->IsConnectedTo(BLS[0])) {
|
---|
| 1174 | if (n>2) {
|
---|
[717e0c] | 1175 | Log() << Verbose(1) << BLS[0] << " connects to all of the new lines?!" << endl;
|
---|
[357fba] | 1176 | return false;
|
---|
| 1177 | } else
|
---|
| 1178 | BLS[n++] = NewLines[j];
|
---|
| 1179 | }
|
---|
| 1180 | }
|
---|
| 1181 | // create the triangle
|
---|
| 1182 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[5c7bf8] | 1183 | Normal.Scale(-1.);
|
---|
| 1184 | BTS->GetNormalVector(Normal);
|
---|
| 1185 | Normal.Scale(-1.);
|
---|
[e138de] | 1186 | Log() << Verbose(2) << "Created new triangle " << *BTS << "." << endl;
|
---|
[357fba] | 1187 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1188 | TrianglesOnBoundaryCount++;
|
---|
| 1189 | }
|
---|
| 1190 | }
|
---|
| 1191 | } else { // something is wrong with FindClosestTriangleToPoint!
|
---|
[717e0c] | 1192 | eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl;
|
---|
[357fba] | 1193 | return false;
|
---|
| 1194 | }
|
---|
| 1195 | cloud->GoToNext();
|
---|
| 1196 | }
|
---|
| 1197 |
|
---|
| 1198 | // exit
|
---|
| 1199 | delete(Center);
|
---|
[e138de] | 1200 | Log() << Verbose(1) << "End of InsertStraddlingPoints" << endl;
|
---|
[357fba] | 1201 | return true;
|
---|
| 1202 | };
|
---|
| 1203 |
|
---|
[16d866] | 1204 | /** Adds a point to the tesselation::PointsOnBoundary list.
|
---|
[62bb91] | 1205 | * \param *Walker point to add
|
---|
[08ef35] | 1206 | * \param n TesselStruct::BPS index to put pointer into
|
---|
| 1207 | * \return true - new point was added, false - point already present
|
---|
[357fba] | 1208 | */
|
---|
[776b64] | 1209 | bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
|
---|
[357fba] | 1210 | {
|
---|
| 1211 | PointTestPair InsertUnique;
|
---|
[08ef35] | 1212 | BPS[n] = new class BoundaryPointSet(Walker);
|
---|
| 1213 | InsertUnique = PointsOnBoundary.insert(PointPair(Walker->nr, BPS[n]));
|
---|
| 1214 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
[357fba] | 1215 | PointsOnBoundaryCount++;
|
---|
[08ef35] | 1216 | return true;
|
---|
| 1217 | } else {
|
---|
| 1218 | delete(BPS[n]);
|
---|
| 1219 | BPS[n] = InsertUnique.first->second;
|
---|
| 1220 | return false;
|
---|
[357fba] | 1221 | }
|
---|
| 1222 | }
|
---|
| 1223 | ;
|
---|
| 1224 |
|
---|
| 1225 | /** Adds point to Tesselation::PointsOnBoundary if not yet present.
|
---|
| 1226 | * Tesselation::TPS is set to either this new BoundaryPointSet or to the existing one of not unique.
|
---|
| 1227 | * @param Candidate point to add
|
---|
| 1228 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1229 | */
|
---|
[776b64] | 1230 | void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
|
---|
[357fba] | 1231 | {
|
---|
| 1232 | PointTestPair InsertUnique;
|
---|
| 1233 | TPS[n] = new class BoundaryPointSet(Candidate);
|
---|
| 1234 | InsertUnique = PointsOnBoundary.insert(PointPair(Candidate->nr, TPS[n]));
|
---|
| 1235 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
| 1236 | PointsOnBoundaryCount++;
|
---|
| 1237 | } else {
|
---|
| 1238 | delete TPS[n];
|
---|
[e138de] | 1239 | Log() << Verbose(4) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
|
---|
[357fba] | 1240 | TPS[n] = (InsertUnique.first)->second;
|
---|
| 1241 | }
|
---|
| 1242 | }
|
---|
| 1243 | ;
|
---|
| 1244 |
|
---|
[f1ef60a] | 1245 | /** Sets point to a present Tesselation::PointsOnBoundary.
|
---|
| 1246 | * Tesselation::TPS is set to the existing one or NULL if not found.
|
---|
| 1247 | * @param Candidate point to set to
|
---|
| 1248 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1249 | */
|
---|
| 1250 | void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
|
---|
| 1251 | {
|
---|
| 1252 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
|
---|
| 1253 | if (FindPoint != PointsOnBoundary.end())
|
---|
| 1254 | TPS[n] = FindPoint->second;
|
---|
| 1255 | else
|
---|
| 1256 | TPS[n] = NULL;
|
---|
| 1257 | };
|
---|
| 1258 |
|
---|
[357fba] | 1259 | /** Function tries to add line from current Points in BPS to BoundaryLineSet.
|
---|
| 1260 | * If successful it raises the line count and inserts the new line into the BLS,
|
---|
| 1261 | * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
|
---|
| 1262 | * @param *a first endpoint
|
---|
| 1263 | * @param *b second endpoint
|
---|
| 1264 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1265 | */
|
---|
[776b64] | 1266 | void Tesselation::AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) {
|
---|
[357fba] | 1267 | bool insertNewLine = true;
|
---|
| 1268 |
|
---|
| 1269 | if (a->lines.find(b->node->nr) != a->lines.end()) {
|
---|
[065e82] | 1270 | LineMap::iterator FindLine = a->lines.find(b->node->nr);
|
---|
[357fba] | 1271 | pair<LineMap::iterator,LineMap::iterator> FindPair;
|
---|
| 1272 | FindPair = a->lines.equal_range(b->node->nr);
|
---|
[e138de] | 1273 | Log() << Verbose(5) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
|
---|
[357fba] | 1274 |
|
---|
[065e82] | 1275 | for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
|
---|
[357fba] | 1276 | // If there is a line with less than two attached triangles, we don't need a new line.
|
---|
[5c7bf8] | 1277 | if (FindLine->second->triangles.size() < 2) {
|
---|
[357fba] | 1278 | insertNewLine = false;
|
---|
[e138de] | 1279 | Log() << Verbose(4) << "Using existing line " << *FindLine->second << endl;
|
---|
[357fba] | 1280 |
|
---|
| 1281 | BPS[0] = FindLine->second->endpoints[0];
|
---|
| 1282 | BPS[1] = FindLine->second->endpoints[1];
|
---|
| 1283 | BLS[n] = FindLine->second;
|
---|
| 1284 |
|
---|
| 1285 | break;
|
---|
| 1286 | }
|
---|
| 1287 | }
|
---|
| 1288 | }
|
---|
| 1289 |
|
---|
| 1290 | if (insertNewLine) {
|
---|
[16d866] | 1291 | AlwaysAddTesselationTriangleLine(a, b, n);
|
---|
[357fba] | 1292 | }
|
---|
| 1293 | }
|
---|
| 1294 | ;
|
---|
| 1295 |
|
---|
| 1296 | /**
|
---|
| 1297 | * Adds lines from each of the current points in the BPS to BoundaryLineSet.
|
---|
| 1298 | * Raises the line count and inserts the new line into the BLS.
|
---|
| 1299 | *
|
---|
| 1300 | * @param *a first endpoint
|
---|
| 1301 | * @param *b second endpoint
|
---|
| 1302 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1303 | */
|
---|
[776b64] | 1304 | void Tesselation::AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
|
---|
[357fba] | 1305 | {
|
---|
[e138de] | 1306 | Log() << Verbose(4) << "Adding line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
|
---|
[357fba] | 1307 | BPS[0] = a;
|
---|
| 1308 | BPS[1] = b;
|
---|
| 1309 | BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
|
---|
| 1310 | // add line to global map
|
---|
| 1311 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
|
---|
| 1312 | // increase counter
|
---|
| 1313 | LinesOnBoundaryCount++;
|
---|
| 1314 | };
|
---|
| 1315 |
|
---|
[7dea7c] | 1316 | /** Function adds triangle to global list.
|
---|
| 1317 | * Furthermore, the triangle receives the next free id and id counter \a TrianglesOnBoundaryCount is increased.
|
---|
[357fba] | 1318 | */
|
---|
[16d866] | 1319 | void Tesselation::AddTesselationTriangle()
|
---|
[357fba] | 1320 | {
|
---|
[e138de] | 1321 | Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
|
---|
[357fba] | 1322 |
|
---|
| 1323 | // add triangle to global map
|
---|
| 1324 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1325 | TrianglesOnBoundaryCount++;
|
---|
| 1326 |
|
---|
[57066a] | 1327 | // set as last new triangle
|
---|
| 1328 | LastTriangle = BTS;
|
---|
| 1329 |
|
---|
[357fba] | 1330 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
[16d866] | 1331 | };
|
---|
| 1332 |
|
---|
[7dea7c] | 1333 | /** Function adds triangle to global list.
|
---|
| 1334 | * Furthermore, the triangle number is set to \a nr.
|
---|
| 1335 | * \param nr triangle number
|
---|
| 1336 | */
|
---|
[776b64] | 1337 | void Tesselation::AddTesselationTriangle(const int nr)
|
---|
[7dea7c] | 1338 | {
|
---|
[e138de] | 1339 | Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
|
---|
[7dea7c] | 1340 |
|
---|
| 1341 | // add triangle to global map
|
---|
| 1342 | TrianglesOnBoundary.insert(TrianglePair(nr, BTS));
|
---|
| 1343 |
|
---|
| 1344 | // set as last new triangle
|
---|
| 1345 | LastTriangle = BTS;
|
---|
| 1346 |
|
---|
| 1347 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
| 1348 | };
|
---|
| 1349 |
|
---|
[16d866] | 1350 | /** Removes a triangle from the tesselation.
|
---|
| 1351 | * Removes itself from the TriangleMap's of its lines, calls for them RemoveTriangleLine() if they are no more connected.
|
---|
| 1352 | * Removes itself from memory.
|
---|
| 1353 | * \param *triangle to remove
|
---|
| 1354 | */
|
---|
| 1355 | void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
|
---|
| 1356 | {
|
---|
| 1357 | if (triangle == NULL)
|
---|
| 1358 | return;
|
---|
| 1359 | for (int i = 0; i < 3; i++) {
|
---|
| 1360 | if (triangle->lines[i] != NULL) {
|
---|
[e138de] | 1361 | Log() << Verbose(5) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
|
---|
[16d866] | 1362 | triangle->lines[i]->triangles.erase(triangle->Nr);
|
---|
| 1363 | if (triangle->lines[i]->triangles.empty()) {
|
---|
[e138de] | 1364 | Log() << Verbose(5) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
|
---|
[16d866] | 1365 | RemoveTesselationLine(triangle->lines[i]);
|
---|
[065e82] | 1366 | } else {
|
---|
[e138de] | 1367 | Log() << Verbose(5) << *triangle->lines[i] << " is still attached to another triangle: ";
|
---|
[065e82] | 1368 | for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
|
---|
[e138de] | 1369 | Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
|
---|
| 1370 | Log() << Verbose(0) << endl;
|
---|
[065e82] | 1371 | // for (int j=0;j<2;j++) {
|
---|
[e138de] | 1372 | // Log() << Verbose(5) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
|
---|
[065e82] | 1373 | // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
|
---|
[e138de] | 1374 | // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
|
---|
| 1375 | // Log() << Verbose(0) << endl;
|
---|
[065e82] | 1376 | // }
|
---|
| 1377 | }
|
---|
| 1378 | triangle->lines[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 1379 | } else
|
---|
[717e0c] | 1380 | eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl;
|
---|
[16d866] | 1381 | }
|
---|
| 1382 |
|
---|
| 1383 | if (TrianglesOnBoundary.erase(triangle->Nr))
|
---|
[e138de] | 1384 | Log() << Verbose(5) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
|
---|
[16d866] | 1385 | delete(triangle);
|
---|
| 1386 | };
|
---|
| 1387 |
|
---|
| 1388 | /** Removes a line from the tesselation.
|
---|
| 1389 | * Removes itself from each endpoints' LineMap, then removes itself from global LinesOnBoundary list and free's the line.
|
---|
| 1390 | * \param *line line to remove
|
---|
| 1391 | */
|
---|
| 1392 | void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
|
---|
| 1393 | {
|
---|
| 1394 | int Numbers[2];
|
---|
| 1395 |
|
---|
| 1396 | if (line == NULL)
|
---|
| 1397 | return;
|
---|
[065e82] | 1398 | // get other endpoint number for finding copies of same line
|
---|
[16d866] | 1399 | if (line->endpoints[1] != NULL)
|
---|
| 1400 | Numbers[0] = line->endpoints[1]->Nr;
|
---|
| 1401 | else
|
---|
| 1402 | Numbers[0] = -1;
|
---|
| 1403 | if (line->endpoints[0] != NULL)
|
---|
| 1404 | Numbers[1] = line->endpoints[0]->Nr;
|
---|
| 1405 | else
|
---|
| 1406 | Numbers[1] = -1;
|
---|
| 1407 |
|
---|
| 1408 | for (int i = 0; i < 2; i++) {
|
---|
| 1409 | if (line->endpoints[i] != NULL) {
|
---|
| 1410 | 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
|
---|
| 1411 | pair<LineMap::iterator, LineMap::iterator> erasor = line->endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 1412 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 1413 | if ((*Runner).second == line) {
|
---|
[e138de] | 1414 | Log() << Verbose(5) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
|
---|
[16d866] | 1415 | line->endpoints[i]->lines.erase(Runner);
|
---|
| 1416 | break;
|
---|
| 1417 | }
|
---|
| 1418 | } else { // there's just a single line left
|
---|
| 1419 | if (line->endpoints[i]->lines.erase(line->Nr))
|
---|
[e138de] | 1420 | Log() << Verbose(5) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
|
---|
[16d866] | 1421 | }
|
---|
| 1422 | if (line->endpoints[i]->lines.empty()) {
|
---|
[e138de] | 1423 | Log() << Verbose(5) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
|
---|
[16d866] | 1424 | RemoveTesselationPoint(line->endpoints[i]);
|
---|
[065e82] | 1425 | } else {
|
---|
[e138de] | 1426 | Log() << Verbose(5) << *line->endpoints[i] << " has still lines it's attached to: ";
|
---|
[065e82] | 1427 | for(LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
|
---|
[e138de] | 1428 | Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
|
---|
| 1429 | Log() << Verbose(0) << endl;
|
---|
[065e82] | 1430 | }
|
---|
| 1431 | line->endpoints[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 1432 | } else
|
---|
[717e0c] | 1433 | eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl;
|
---|
[16d866] | 1434 | }
|
---|
| 1435 | if (!line->triangles.empty())
|
---|
[717e0c] | 1436 | eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl;
|
---|
[16d866] | 1437 |
|
---|
| 1438 | if (LinesOnBoundary.erase(line->Nr))
|
---|
[e138de] | 1439 | Log() << Verbose(5) << "Removing line Nr. " << line->Nr << "." << endl;
|
---|
[16d866] | 1440 | delete(line);
|
---|
| 1441 | };
|
---|
| 1442 |
|
---|
| 1443 | /** Removes a point from the tesselation.
|
---|
| 1444 | * Checks whether there are still lines connected, removes from global PointsOnBoundary list, then free's the point.
|
---|
| 1445 | * \note If a point should be removed, while keep the tesselated surface intact (i.e. closed), use RemovePointFromTesselatedSurface()
|
---|
| 1446 | * \param *point point to remove
|
---|
| 1447 | */
|
---|
| 1448 | void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
|
---|
| 1449 | {
|
---|
| 1450 | if (point == NULL)
|
---|
| 1451 | return;
|
---|
| 1452 | if (PointsOnBoundary.erase(point->Nr))
|
---|
[e138de] | 1453 | Log() << Verbose(5) << "Removing point Nr. " << point->Nr << "." << endl;
|
---|
[16d866] | 1454 | delete(point);
|
---|
| 1455 | };
|
---|
[357fba] | 1456 |
|
---|
[62bb91] | 1457 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
[357fba] | 1458 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 1459 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 1460 | * returned.
|
---|
| 1461 | * \param *out output stream for debugging
|
---|
| 1462 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 1463 | * \return integer 0 if no triangle exists, 1 if one triangle exists, 2 if two
|
---|
| 1464 | * triangles exist which is the maximum for three points
|
---|
| 1465 | */
|
---|
[f1ef60a] | 1466 | int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
|
---|
| 1467 | {
|
---|
[357fba] | 1468 | int adjacentTriangleCount = 0;
|
---|
| 1469 | class BoundaryPointSet *Points[3];
|
---|
| 1470 |
|
---|
[e138de] | 1471 | Log() << Verbose(2) << "Begin of CheckPresenceOfTriangle" << endl;
|
---|
[357fba] | 1472 | // builds a triangle point set (Points) of the end points
|
---|
| 1473 | for (int i = 0; i < 3; i++) {
|
---|
[f1ef60a] | 1474 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
[357fba] | 1475 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 1476 | Points[i] = FindPoint->second;
|
---|
| 1477 | } else {
|
---|
| 1478 | Points[i] = NULL;
|
---|
| 1479 | }
|
---|
| 1480 | }
|
---|
| 1481 |
|
---|
| 1482 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 1483 | for (int i = 0; i < 3; i++) {
|
---|
| 1484 | if (Points[i] != NULL) {
|
---|
| 1485 | for (int j = i; j < 3; j++) {
|
---|
| 1486 | if (Points[j] != NULL) {
|
---|
[f1ef60a] | 1487 | LineMap::const_iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
[357fba] | 1488 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 1489 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
[e138de] | 1490 | Log() << Verbose(3) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
|
---|
[f1ef60a] | 1491 | for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
[357fba] | 1492 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 1493 | adjacentTriangleCount++;
|
---|
| 1494 | }
|
---|
| 1495 | }
|
---|
[e138de] | 1496 | Log() << Verbose(3) << "end." << endl;
|
---|
[357fba] | 1497 | }
|
---|
| 1498 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[e138de] | 1499 | //Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 1500 | //return adjacentTriangleCount;
|
---|
[357fba] | 1501 | }
|
---|
| 1502 | }
|
---|
| 1503 | }
|
---|
| 1504 | }
|
---|
| 1505 |
|
---|
[e138de] | 1506 | Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
| 1507 | Log() << Verbose(2) << "End of CheckPresenceOfTriangle" << endl;
|
---|
[357fba] | 1508 | return adjacentTriangleCount;
|
---|
| 1509 | };
|
---|
| 1510 |
|
---|
[065e82] | 1511 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
| 1512 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 1513 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 1514 | * returned.
|
---|
| 1515 | * \param *out output stream for debugging
|
---|
| 1516 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 1517 | * \return NULL - none found or pointer to triangle
|
---|
| 1518 | */
|
---|
[e138de] | 1519 | class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
|
---|
[065e82] | 1520 | {
|
---|
| 1521 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 1522 | class BoundaryPointSet *Points[3];
|
---|
| 1523 |
|
---|
| 1524 | // builds a triangle point set (Points) of the end points
|
---|
| 1525 | for (int i = 0; i < 3; i++) {
|
---|
| 1526 | PointMap::iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
| 1527 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 1528 | Points[i] = FindPoint->second;
|
---|
| 1529 | } else {
|
---|
| 1530 | Points[i] = NULL;
|
---|
| 1531 | }
|
---|
| 1532 | }
|
---|
| 1533 |
|
---|
| 1534 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 1535 | for (int i = 0; i < 3; i++) {
|
---|
| 1536 | if (Points[i] != NULL) {
|
---|
| 1537 | for (int j = i; j < 3; j++) {
|
---|
| 1538 | if (Points[j] != NULL) {
|
---|
| 1539 | LineMap::iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
| 1540 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 1541 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
| 1542 | for (TriangleMap::iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
| 1543 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 1544 | if ((triangle == NULL) || (triangle->Nr > FindTriangle->second->Nr))
|
---|
| 1545 | triangle = FindTriangle->second;
|
---|
| 1546 | }
|
---|
| 1547 | }
|
---|
| 1548 | }
|
---|
| 1549 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[e138de] | 1550 | //Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 1551 | //return adjacentTriangleCount;
|
---|
| 1552 | }
|
---|
| 1553 | }
|
---|
| 1554 | }
|
---|
| 1555 | }
|
---|
| 1556 |
|
---|
| 1557 | return triangle;
|
---|
| 1558 | };
|
---|
| 1559 |
|
---|
[357fba] | 1560 |
|
---|
[f1cccd] | 1561 | /** Finds the starting triangle for FindNonConvexBorder().
|
---|
| 1562 | * Looks at the outermost point per axis, then FindSecondPointForTesselation()
|
---|
| 1563 | * for the second and FindNextSuitablePointViaAngleOfSphere() for the third
|
---|
[357fba] | 1564 | * point are called.
|
---|
| 1565 | * \param *out output stream for debugging
|
---|
| 1566 | * \param RADIUS radius of virtual rolling sphere
|
---|
| 1567 | * \param *LC LinkedCell structure with neighbouring TesselPoint's
|
---|
| 1568 | */
|
---|
[e138de] | 1569 | void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 1570 | {
|
---|
[e138de] | 1571 | Log() << Verbose(1) << "Begin of FindStartingTriangle\n";
|
---|
[357fba] | 1572 | int i = 0;
|
---|
| 1573 | TesselPoint* FirstPoint = NULL;
|
---|
| 1574 | TesselPoint* SecondPoint = NULL;
|
---|
[62bb91] | 1575 | TesselPoint* MaxPoint[NDIM];
|
---|
[f1cccd] | 1576 | double maxCoordinate[NDIM];
|
---|
[357fba] | 1577 | Vector Oben;
|
---|
| 1578 | Vector helper;
|
---|
| 1579 | Vector Chord;
|
---|
| 1580 | Vector SearchDirection;
|
---|
| 1581 |
|
---|
| 1582 | Oben.Zero();
|
---|
| 1583 |
|
---|
| 1584 | for (i = 0; i < 3; i++) {
|
---|
[62bb91] | 1585 | MaxPoint[i] = NULL;
|
---|
[f1cccd] | 1586 | maxCoordinate[i] = -1;
|
---|
[357fba] | 1587 | }
|
---|
| 1588 |
|
---|
[62bb91] | 1589 | // 1. searching topmost point with respect to each axis
|
---|
[357fba] | 1590 | for (int i=0;i<NDIM;i++) { // each axis
|
---|
| 1591 | LC->n[i] = LC->N[i]-1; // current axis is topmost cell
|
---|
| 1592 | for (LC->n[(i+1)%NDIM]=0;LC->n[(i+1)%NDIM]<LC->N[(i+1)%NDIM];LC->n[(i+1)%NDIM]++)
|
---|
| 1593 | for (LC->n[(i+2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {
|
---|
[776b64] | 1594 | const LinkedNodes *List = LC->GetCurrentCell();
|
---|
[e138de] | 1595 | //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 1596 | if (List != NULL) {
|
---|
[776b64] | 1597 | for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
|
---|
[f1cccd] | 1598 | if ((*Runner)->node->x[i] > maxCoordinate[i]) {
|
---|
[e138de] | 1599 | Log() << Verbose(2) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
|
---|
[f1cccd] | 1600 | maxCoordinate[i] = (*Runner)->node->x[i];
|
---|
[62bb91] | 1601 | MaxPoint[i] = (*Runner);
|
---|
[357fba] | 1602 | }
|
---|
| 1603 | }
|
---|
| 1604 | } else {
|
---|
[717e0c] | 1605 | eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
|
---|
[357fba] | 1606 | }
|
---|
| 1607 | }
|
---|
| 1608 | }
|
---|
| 1609 |
|
---|
[e138de] | 1610 | Log() << Verbose(2) << "Found maximum coordinates: ";
|
---|
[357fba] | 1611 | for (int i=0;i<NDIM;i++)
|
---|
[e138de] | 1612 | Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t";
|
---|
| 1613 | Log() << Verbose(0) << endl;
|
---|
[357fba] | 1614 |
|
---|
| 1615 | BTS = NULL;
|
---|
[f1cccd] | 1616 | CandidateList *OptCandidates = new CandidateList();
|
---|
[357fba] | 1617 | for (int k=0;k<NDIM;k++) {
|
---|
[57066a] | 1618 | Oben.Zero();
|
---|
[357fba] | 1619 | Oben.x[k] = 1.;
|
---|
[62bb91] | 1620 | FirstPoint = MaxPoint[k];
|
---|
[e138de] | 1621 | Log() << Verbose(1) << "Coordinates of start node at " << *FirstPoint->node << "." << endl;
|
---|
[357fba] | 1622 |
|
---|
| 1623 | double ShortestAngle;
|
---|
[f1cccd] | 1624 | TesselPoint* OptCandidate = NULL;
|
---|
[357fba] | 1625 | 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.
|
---|
| 1626 |
|
---|
[57066a] | 1627 | FindSecondPointForTesselation(FirstPoint, Oben, OptCandidate, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
|
---|
[f1cccd] | 1628 | SecondPoint = OptCandidate;
|
---|
[357fba] | 1629 | if (SecondPoint == NULL) // have we found a second point?
|
---|
| 1630 | continue;
|
---|
| 1631 |
|
---|
| 1632 | helper.CopyVector(FirstPoint->node);
|
---|
| 1633 | helper.SubtractVector(SecondPoint->node);
|
---|
| 1634 | helper.Normalize();
|
---|
| 1635 | Oben.ProjectOntoPlane(&helper);
|
---|
| 1636 | Oben.Normalize();
|
---|
| 1637 | helper.VectorProduct(&Oben);
|
---|
| 1638 | ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
|
---|
| 1639 |
|
---|
| 1640 | Chord.CopyVector(FirstPoint->node); // bring into calling function
|
---|
| 1641 | Chord.SubtractVector(SecondPoint->node);
|
---|
| 1642 | double radius = Chord.ScalarProduct(&Chord);
|
---|
| 1643 | double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
|
---|
| 1644 | helper.CopyVector(&Oben);
|
---|
| 1645 | helper.Scale(CircleRadius);
|
---|
| 1646 | // Now, oben and helper are two orthonormalized vectors in the plane defined by Chord (not normalized)
|
---|
| 1647 |
|
---|
| 1648 | // look in one direction of baseline for initial candidate
|
---|
| 1649 | SearchDirection.MakeNormalVector(&Chord, &Oben); // whether we look "left" first or "right" first is not important ...
|
---|
| 1650 |
|
---|
[5c7bf8] | 1651 | // adding point 1 and point 2 and add the line between them
|
---|
[e138de] | 1652 | Log() << Verbose(1) << "Coordinates of start node at " << *FirstPoint->node << "." << endl;
|
---|
[16d866] | 1653 | AddTesselationPoint(FirstPoint, 0);
|
---|
[e138de] | 1654 | Log() << Verbose(1) << "Found second point is at " << *SecondPoint->node << ".\n";
|
---|
[16d866] | 1655 | AddTesselationPoint(SecondPoint, 1);
|
---|
| 1656 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
[357fba] | 1657 |
|
---|
[e138de] | 1658 | //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << helper << ".\n";
|
---|
[776b64] | 1659 | FindThirdPointForTesselation(Oben, SearchDirection, helper, BLS[0], NULL, *&OptCandidates, &ShortestAngle, RADIUS, LC);
|
---|
[e138de] | 1660 | Log() << Verbose(1) << "List of third Points is ";
|
---|
[f1cccd] | 1661 | for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
[e138de] | 1662 | Log() << Verbose(0) << " " << *(*it)->point;
|
---|
[357fba] | 1663 | }
|
---|
[e138de] | 1664 | Log() << Verbose(0) << endl;
|
---|
[357fba] | 1665 |
|
---|
[f1cccd] | 1666 | for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
[357fba] | 1667 | // add third triangle point
|
---|
[16d866] | 1668 | AddTesselationPoint((*it)->point, 2);
|
---|
[357fba] | 1669 | // add the second and third line
|
---|
[16d866] | 1670 | AddTesselationLine(TPS[1], TPS[2], 1);
|
---|
| 1671 | AddTesselationLine(TPS[0], TPS[2], 2);
|
---|
[357fba] | 1672 | // ... and triangles to the Maps of the Tesselation class
|
---|
| 1673 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[16d866] | 1674 | AddTesselationTriangle();
|
---|
[357fba] | 1675 | // ... and calculate its normal vector (with correct orientation)
|
---|
| 1676 | (*it)->OptCenter.Scale(-1.);
|
---|
[e138de] | 1677 | Log() << Verbose(2) << "Anti-Oben is currently " << (*it)->OptCenter << "." << endl;
|
---|
[357fba] | 1678 | BTS->GetNormalVector((*it)->OptCenter); // vector to compare with should point inwards
|
---|
[e138de] | 1679 | Log() << Verbose(0) << "==> Found starting triangle consists of " << *FirstPoint << ", " << *SecondPoint << " and "
|
---|
[357fba] | 1680 | << *(*it)->point << " with normal vector " << BTS->NormalVector << ".\n";
|
---|
| 1681 |
|
---|
| 1682 | // if we do not reach the end with the next step of iteration, we need to setup a new first line
|
---|
[f1cccd] | 1683 | if (it != OptCandidates->end()--) {
|
---|
[357fba] | 1684 | FirstPoint = (*it)->BaseLine->endpoints[0]->node;
|
---|
| 1685 | SecondPoint = (*it)->point;
|
---|
| 1686 | // adding point 1 and point 2 and the line between them
|
---|
[16d866] | 1687 | AddTesselationPoint(FirstPoint, 0);
|
---|
| 1688 | AddTesselationPoint(SecondPoint, 1);
|
---|
| 1689 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
[357fba] | 1690 | }
|
---|
[e138de] | 1691 | Log() << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl;
|
---|
[357fba] | 1692 | }
|
---|
| 1693 | if (BTS != NULL) // we have created one starting triangle
|
---|
| 1694 | break;
|
---|
| 1695 | else {
|
---|
| 1696 | // remove all candidates from the list and then the list itself
|
---|
| 1697 | class CandidateForTesselation *remover = NULL;
|
---|
[f1cccd] | 1698 | for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
[357fba] | 1699 | remover = *it;
|
---|
| 1700 | delete(remover);
|
---|
| 1701 | }
|
---|
[f1cccd] | 1702 | OptCandidates->clear();
|
---|
[357fba] | 1703 | }
|
---|
| 1704 | }
|
---|
| 1705 |
|
---|
| 1706 | // remove all candidates from the list and then the list itself
|
---|
| 1707 | class CandidateForTesselation *remover = NULL;
|
---|
[f1cccd] | 1708 | for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
[357fba] | 1709 | remover = *it;
|
---|
| 1710 | delete(remover);
|
---|
| 1711 | }
|
---|
[f1cccd] | 1712 | delete(OptCandidates);
|
---|
[e138de] | 1713 | Log() << Verbose(1) << "End of FindStartingTriangle\n";
|
---|
[357fba] | 1714 | };
|
---|
| 1715 |
|
---|
[f1ef60a] | 1716 | /** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
|
---|
| 1717 | * This is supposed to prevent early closing of the tesselation.
|
---|
| 1718 | * \param *BaseRay baseline, i.e. not \a *OptCandidate
|
---|
| 1719 | * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
|
---|
| 1720 | * \param ShortestAngle path length on this circle band for the current \a *ThirdNode
|
---|
| 1721 | * \param RADIUS radius of sphere
|
---|
| 1722 | * \param *LC LinkedCell structure
|
---|
| 1723 | * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
|
---|
| 1724 | */
|
---|
| 1725 | bool Tesselation::HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const ThirdNode, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const
|
---|
| 1726 | {
|
---|
| 1727 | bool result = false;
|
---|
| 1728 | Vector CircleCenter;
|
---|
| 1729 | Vector CirclePlaneNormal;
|
---|
| 1730 | Vector OldSphereCenter;
|
---|
| 1731 | Vector SearchDirection;
|
---|
| 1732 | Vector helper;
|
---|
| 1733 | TesselPoint *OtherOptCandidate = NULL;
|
---|
| 1734 | double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
|
---|
| 1735 | double radius, CircleRadius;
|
---|
| 1736 | BoundaryLineSet *Line = NULL;
|
---|
| 1737 | BoundaryTriangleSet *T = NULL;
|
---|
| 1738 |
|
---|
| 1739 | Log() << Verbose(1) << "Begin of HasOtherBaselineBetterCandidate" << endl;
|
---|
| 1740 |
|
---|
| 1741 | // check both other lines
|
---|
| 1742 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
|
---|
| 1743 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 1744 | for (int i=0;i<2;i++) {
|
---|
| 1745 | LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
|
---|
| 1746 | if (FindLine != (FindPoint->second)->lines.end()) {
|
---|
| 1747 | Line = FindLine->second;
|
---|
| 1748 | Log() << Verbose(1) << "Found line " << *Line << "." << endl;
|
---|
| 1749 | if (Line->triangles.size() == 1) {
|
---|
| 1750 | T = Line->triangles.begin()->second;
|
---|
| 1751 | // construct center of circle
|
---|
| 1752 | CircleCenter.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 1753 | CircleCenter.AddVector(Line->endpoints[1]->node->node);
|
---|
| 1754 | CircleCenter.Scale(0.5);
|
---|
| 1755 |
|
---|
| 1756 | // construct normal vector of circle
|
---|
| 1757 | CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 1758 | CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
|
---|
| 1759 |
|
---|
| 1760 | // calculate squared radius of circle
|
---|
| 1761 | radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
|
---|
| 1762 | if (radius/4. < RADIUS*RADIUS) {
|
---|
| 1763 | CircleRadius = RADIUS*RADIUS - radius/4.;
|
---|
| 1764 | CirclePlaneNormal.Normalize();
|
---|
| 1765 | //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
| 1766 |
|
---|
| 1767 | // construct old center
|
---|
| 1768 | GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
|
---|
| 1769 | helper.CopyVector(&T->NormalVector); // normal vector ensures that this is correct center of the two possible ones
|
---|
| 1770 | radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
|
---|
| 1771 | helper.Scale(sqrt(RADIUS*RADIUS - radius));
|
---|
| 1772 | OldSphereCenter.AddVector(&helper);
|
---|
| 1773 | OldSphereCenter.SubtractVector(&CircleCenter);
|
---|
| 1774 | //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
|
---|
| 1775 |
|
---|
| 1776 | // construct SearchDirection
|
---|
| 1777 | SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
|
---|
| 1778 | helper.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 1779 | helper.SubtractVector(ThirdNode->node);
|
---|
| 1780 | if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
| 1781 | SearchDirection.Scale(-1.);
|
---|
| 1782 | SearchDirection.ProjectOntoPlane(&OldSphereCenter);
|
---|
| 1783 | SearchDirection.Normalize();
|
---|
| 1784 | Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
| 1785 | if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
|
---|
| 1786 | // rotated the wrong way!
|
---|
[717e0c] | 1787 | eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
|
---|
[f1ef60a] | 1788 | }
|
---|
| 1789 |
|
---|
| 1790 | // add third point
|
---|
| 1791 | CandidateList *OptCandidates = new CandidateList();
|
---|
| 1792 | FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, Line, ThirdNode, OptCandidates, &OtherShortestAngle, RADIUS, LC);
|
---|
| 1793 | for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
| 1794 | if (((*it)->point == BaseRay->endpoints[0]->node) || ((*it)->point == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
|
---|
| 1795 | continue;
|
---|
| 1796 | Log() << Verbose(1) << " Third point candidate is " << *(*it)->point
|
---|
| 1797 | << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
|
---|
| 1798 | Log() << Verbose(1) << " Baseline is " << *BaseRay << endl;
|
---|
| 1799 |
|
---|
| 1800 | // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
|
---|
| 1801 | TesselPoint *PointCandidates[3];
|
---|
| 1802 | PointCandidates[0] = (*it)->point;
|
---|
| 1803 | PointCandidates[1] = BaseRay->endpoints[0]->node;
|
---|
| 1804 | PointCandidates[2] = BaseRay->endpoints[1]->node;
|
---|
| 1805 | bool check=false;
|
---|
| 1806 | int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
|
---|
| 1807 | // If there is no triangle, add it regularly.
|
---|
| 1808 | if (existentTrianglesCount == 0) {
|
---|
| 1809 | SetTesselationPoint((*it)->point, 0);
|
---|
| 1810 | SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 1811 | SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 1812 |
|
---|
| 1813 | if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
|
---|
| 1814 | OtherOptCandidate = (*it)->point;
|
---|
| 1815 | check = true;
|
---|
| 1816 | }
|
---|
| 1817 | } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
|
---|
| 1818 | SetTesselationPoint((*it)->point, 0);
|
---|
| 1819 | SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 1820 | SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 1821 |
|
---|
| 1822 | // 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)
|
---|
| 1823 | // i.e. at least one of the three lines must be present with TriangleCount <= 1
|
---|
| 1824 | if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
|
---|
| 1825 | OtherOptCandidate = (*it)->point;
|
---|
| 1826 | check = true;
|
---|
| 1827 | }
|
---|
| 1828 | }
|
---|
| 1829 |
|
---|
| 1830 | if (check) {
|
---|
| 1831 | if (ShortestAngle > OtherShortestAngle) {
|
---|
| 1832 | Log() << Verbose(1) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
|
---|
| 1833 | result = true;
|
---|
| 1834 | break;
|
---|
| 1835 | }
|
---|
| 1836 | }
|
---|
| 1837 | }
|
---|
| 1838 | delete(OptCandidates);
|
---|
| 1839 | if (result)
|
---|
| 1840 | break;
|
---|
| 1841 | } else {
|
---|
| 1842 | Log() << Verbose(1) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
|
---|
| 1843 | }
|
---|
| 1844 | } else {
|
---|
| 1845 | eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;
|
---|
| 1846 | }
|
---|
| 1847 | } else {
|
---|
| 1848 | Log() << Verbose(2) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
|
---|
| 1849 | }
|
---|
| 1850 | }
|
---|
| 1851 | } else {
|
---|
| 1852 | eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;
|
---|
| 1853 | }
|
---|
| 1854 |
|
---|
| 1855 | Log() << Verbose(1) << "End of HasOtherBaselineBetterCandidate" << endl;
|
---|
| 1856 |
|
---|
| 1857 | return result;
|
---|
| 1858 | };
|
---|
[357fba] | 1859 |
|
---|
| 1860 | /** This function finds a triangle to a line, adjacent to an existing one.
|
---|
| 1861 | * @param out output stream for debugging
|
---|
| 1862 | * @param Line current baseline to search from
|
---|
| 1863 | * @param T current triangle which \a Line is edge of
|
---|
| 1864 | * @param RADIUS radius of the rolling ball
|
---|
| 1865 | * @param N number of found triangles
|
---|
[62bb91] | 1866 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 1867 | */
|
---|
[e138de] | 1868 | bool Tesselation::FindNextSuitableTriangle(BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 1869 | {
|
---|
[e138de] | 1870 | Log() << Verbose(0) << "Begin of FindNextSuitableTriangle\n";
|
---|
[357fba] | 1871 | bool result = true;
|
---|
[f1cccd] | 1872 | CandidateList *OptCandidates = new CandidateList();
|
---|
[357fba] | 1873 |
|
---|
| 1874 | Vector CircleCenter;
|
---|
| 1875 | Vector CirclePlaneNormal;
|
---|
| 1876 | Vector OldSphereCenter;
|
---|
| 1877 | Vector SearchDirection;
|
---|
| 1878 | Vector helper;
|
---|
| 1879 | TesselPoint *ThirdNode = NULL;
|
---|
| 1880 | LineMap::iterator testline;
|
---|
| 1881 | double ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
|
---|
| 1882 | double radius, CircleRadius;
|
---|
| 1883 |
|
---|
[e138de] | 1884 | Log() << Verbose(1) << "Current baseline is " << Line << " of triangle " << T << "." << endl;
|
---|
[357fba] | 1885 | for (int i=0;i<3;i++)
|
---|
| 1886 | if ((T.endpoints[i]->node != Line.endpoints[0]->node) && (T.endpoints[i]->node != Line.endpoints[1]->node))
|
---|
| 1887 | ThirdNode = T.endpoints[i]->node;
|
---|
| 1888 |
|
---|
| 1889 | // construct center of circle
|
---|
| 1890 | CircleCenter.CopyVector(Line.endpoints[0]->node->node);
|
---|
| 1891 | CircleCenter.AddVector(Line.endpoints[1]->node->node);
|
---|
| 1892 | CircleCenter.Scale(0.5);
|
---|
| 1893 |
|
---|
| 1894 | // construct normal vector of circle
|
---|
| 1895 | CirclePlaneNormal.CopyVector(Line.endpoints[0]->node->node);
|
---|
| 1896 | CirclePlaneNormal.SubtractVector(Line.endpoints[1]->node->node);
|
---|
| 1897 |
|
---|
| 1898 | // calculate squared radius of circle
|
---|
| 1899 | radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
|
---|
| 1900 | if (radius/4. < RADIUS*RADIUS) {
|
---|
| 1901 | CircleRadius = RADIUS*RADIUS - radius/4.;
|
---|
| 1902 | CirclePlaneNormal.Normalize();
|
---|
[e138de] | 1903 | //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
[357fba] | 1904 |
|
---|
| 1905 | // construct old center
|
---|
[c0f6c6] | 1906 | GetCenterofCircumcircle(&OldSphereCenter, *T.endpoints[0]->node->node, *T.endpoints[1]->node->node, *T.endpoints[2]->node->node);
|
---|
[357fba] | 1907 | helper.CopyVector(&T.NormalVector); // normal vector ensures that this is correct center of the two possible ones
|
---|
| 1908 | radius = Line.endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
|
---|
| 1909 | helper.Scale(sqrt(RADIUS*RADIUS - radius));
|
---|
| 1910 | OldSphereCenter.AddVector(&helper);
|
---|
| 1911 | OldSphereCenter.SubtractVector(&CircleCenter);
|
---|
[e138de] | 1912 | //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
|
---|
[357fba] | 1913 |
|
---|
| 1914 | // construct SearchDirection
|
---|
| 1915 | SearchDirection.MakeNormalVector(&T.NormalVector, &CirclePlaneNormal);
|
---|
| 1916 | helper.CopyVector(Line.endpoints[0]->node->node);
|
---|
| 1917 | helper.SubtractVector(ThirdNode->node);
|
---|
| 1918 | if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
| 1919 | SearchDirection.Scale(-1.);
|
---|
| 1920 | SearchDirection.ProjectOntoPlane(&OldSphereCenter);
|
---|
| 1921 | SearchDirection.Normalize();
|
---|
[e138de] | 1922 | Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
[357fba] | 1923 | if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
|
---|
| 1924 | // rotated the wrong way!
|
---|
[717e0c] | 1925 | eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
|
---|
[357fba] | 1926 | }
|
---|
| 1927 |
|
---|
| 1928 | // add third point
|
---|
[776b64] | 1929 | FindThirdPointForTesselation(T.NormalVector, SearchDirection, OldSphereCenter, &Line, ThirdNode, OptCandidates, &ShortestAngle, RADIUS, LC);
|
---|
[357fba] | 1930 |
|
---|
| 1931 | } else {
|
---|
[e138de] | 1932 | Log() << Verbose(1) << "Circumcircle for base line " << Line << " and base triangle " << T << " is too big!" << endl;
|
---|
[357fba] | 1933 | }
|
---|
| 1934 |
|
---|
[f1cccd] | 1935 | if (OptCandidates->begin() == OptCandidates->end()) {
|
---|
[717e0c] | 1936 | eLog() << Verbose(2) << "Could not find a suitable candidate." << endl;
|
---|
[357fba] | 1937 | return false;
|
---|
| 1938 | }
|
---|
[e138de] | 1939 | Log() << Verbose(1) << "Third Points are ";
|
---|
[f1cccd] | 1940 | for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
[f1ef60a] | 1941 | Log() << Verbose(1) << " " << *(*it)->point << endl;
|
---|
[357fba] | 1942 | }
|
---|
| 1943 |
|
---|
| 1944 | BoundaryLineSet *BaseRay = &Line;
|
---|
[f1cccd] | 1945 | for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
[e138de] | 1946 | Log() << Verbose(1) << " Third point candidate is " << *(*it)->point
|
---|
[357fba] | 1947 | << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
|
---|
[e138de] | 1948 | Log() << Verbose(1) << " Baseline is " << *BaseRay << endl;
|
---|
[357fba] | 1949 |
|
---|
| 1950 | // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
|
---|
[62bb91] | 1951 | TesselPoint *PointCandidates[3];
|
---|
| 1952 | PointCandidates[0] = (*it)->point;
|
---|
| 1953 | PointCandidates[1] = BaseRay->endpoints[0]->node;
|
---|
| 1954 | PointCandidates[2] = BaseRay->endpoints[1]->node;
|
---|
[e138de] | 1955 | int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
|
---|
[357fba] | 1956 |
|
---|
| 1957 | BTS = NULL;
|
---|
[f1ef60a] | 1958 | // check for present edges and whether we reach better candidates from them
|
---|
[6a7f78c] | 1959 | //if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) {
|
---|
| 1960 | if (0) {
|
---|
[f1ef60a] | 1961 | result = false;
|
---|
| 1962 | break;
|
---|
| 1963 | } else {
|
---|
| 1964 | // If there is no triangle, add it regularly.
|
---|
| 1965 | if (existentTrianglesCount == 0) {
|
---|
[16d866] | 1966 | AddTesselationPoint((*it)->point, 0);
|
---|
| 1967 | AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 1968 | AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
[357fba] | 1969 |
|
---|
[f1ef60a] | 1970 | if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
|
---|
[16d866] | 1971 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 1972 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
| 1973 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
[357fba] | 1974 |
|
---|
| 1975 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[f1ef60a] | 1976 | AddTesselationTriangle();
|
---|
| 1977 | (*it)->OptCenter.Scale(-1.);
|
---|
| 1978 | BTS->GetNormalVector((*it)->OptCenter);
|
---|
| 1979 | (*it)->OptCenter.Scale(-1.);
|
---|
| 1980 |
|
---|
| 1981 | Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector
|
---|
| 1982 | << " for this triangle ... " << endl;
|
---|
| 1983 | //Log() << Verbose(1) << "We have "<< TrianglesOnBoundaryCount << " for line " << *BaseRay << "." << endl;
|
---|
[357fba] | 1984 | } else {
|
---|
[717e0c] | 1985 | eLog() << Verbose(2) << "This triangle consisting of ";
|
---|
[e138de] | 1986 | Log() << Verbose(0) << *(*it)->point << ", ";
|
---|
| 1987 | Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
|
---|
| 1988 | Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
|
---|
| 1989 | Log() << Verbose(0) << "exists and is not added, as it does not seem helpful!" << endl;
|
---|
[357fba] | 1990 | result = false;
|
---|
| 1991 | }
|
---|
[f1ef60a] | 1992 | } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
|
---|
| 1993 | AddTesselationPoint((*it)->point, 0);
|
---|
| 1994 | AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 1995 | AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 1996 |
|
---|
| 1997 | // 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)
|
---|
| 1998 | // i.e. at least one of the three lines must be present with TriangleCount <= 1
|
---|
| 1999 | if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
|
---|
| 2000 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 2001 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
| 2002 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
| 2003 |
|
---|
| 2004 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2005 | AddTesselationTriangle(); // add to global map
|
---|
| 2006 |
|
---|
| 2007 | (*it)->OtherOptCenter.Scale(-1.);
|
---|
| 2008 | BTS->GetNormalVector((*it)->OtherOptCenter);
|
---|
| 2009 | (*it)->OtherOptCenter.Scale(-1.);
|
---|
| 2010 |
|
---|
[717e0c] | 2011 | eLog() << Verbose(2) << "--> WARNING: Special new triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " for this triangle ... " << endl;
|
---|
[f1ef60a] | 2012 | Log() << Verbose(1) << "We have "<< BaseRay->triangles.size() << " for line " << BaseRay << "." << endl;
|
---|
| 2013 | } else {
|
---|
[717e0c] | 2014 | eLog() << Verbose(2) << "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;
|
---|
[f1ef60a] | 2015 | result = false;
|
---|
| 2016 | }
|
---|
| 2017 | } else {
|
---|
| 2018 | Log() << Verbose(1) << "This triangle consisting of ";
|
---|
| 2019 | Log() << Verbose(0) << *(*it)->point << ", ";
|
---|
| 2020 | Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
|
---|
| 2021 | Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
|
---|
| 2022 | Log() << Verbose(0) << "is invalid!" << endl;
|
---|
| 2023 | result = false;
|
---|
| 2024 | }
|
---|
[357fba] | 2025 | }
|
---|
| 2026 |
|
---|
| 2027 | // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
|
---|
| 2028 | BaseRay = BLS[0];
|
---|
[57066a] | 2029 | if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
|
---|
[717e0c] | 2030 | eLog() << Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl;
|
---|
[57066a] | 2031 | exit(255);
|
---|
| 2032 | }
|
---|
| 2033 |
|
---|
[357fba] | 2034 | }
|
---|
| 2035 |
|
---|
| 2036 | // remove all candidates from the list and then the list itself
|
---|
| 2037 | class CandidateForTesselation *remover = NULL;
|
---|
[f1cccd] | 2038 | for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
|
---|
[357fba] | 2039 | remover = *it;
|
---|
| 2040 | delete(remover);
|
---|
| 2041 | }
|
---|
[f1cccd] | 2042 | delete(OptCandidates);
|
---|
[e138de] | 2043 | Log() << Verbose(0) << "End of FindNextSuitableTriangle\n";
|
---|
[357fba] | 2044 | return result;
|
---|
| 2045 | };
|
---|
| 2046 |
|
---|
[16d866] | 2047 | /** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
|
---|
| 2048 | * We look whether the closest point on \a *Base with respect to the other baseline is outside
|
---|
| 2049 | * of the segment formed by both endpoints (concave) or not (convex).
|
---|
| 2050 | * \param *out output stream for debugging
|
---|
| 2051 | * \param *Base line to be flipped
|
---|
[57066a] | 2052 | * \return NULL - convex, otherwise endpoint that makes it concave
|
---|
[16d866] | 2053 | */
|
---|
[e138de] | 2054 | class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
|
---|
[16d866] | 2055 | {
|
---|
| 2056 | class BoundaryPointSet *Spot = NULL;
|
---|
| 2057 | class BoundaryLineSet *OtherBase;
|
---|
[0077b5] | 2058 | Vector *ClosestPoint;
|
---|
[16d866] | 2059 |
|
---|
| 2060 | int m=0;
|
---|
| 2061 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2062 | for (int j=0;j<3;j++) // all of their endpoints and baselines
|
---|
| 2063 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2064 | BPS[m++] = runner->second->endpoints[j];
|
---|
| 2065 | OtherBase = new class BoundaryLineSet(BPS,-1);
|
---|
| 2066 |
|
---|
[e138de] | 2067 | Log() << Verbose(3) << "INFO: Current base line is " << *Base << "." << endl;
|
---|
| 2068 | Log() << Verbose(3) << "INFO: Other base line is " << *OtherBase << "." << endl;
|
---|
[16d866] | 2069 |
|
---|
| 2070 | // get the closest point on each line to the other line
|
---|
[e138de] | 2071 | ClosestPoint = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
[16d866] | 2072 |
|
---|
| 2073 | // delete the temporary other base line
|
---|
| 2074 | delete(OtherBase);
|
---|
| 2075 |
|
---|
| 2076 | // get the distance vector from Base line to OtherBase line
|
---|
[0077b5] | 2077 | Vector DistanceToIntersection[2], BaseLine;
|
---|
| 2078 | double distance[2];
|
---|
[16d866] | 2079 | BaseLine.CopyVector(Base->endpoints[1]->node->node);
|
---|
| 2080 | BaseLine.SubtractVector(Base->endpoints[0]->node->node);
|
---|
[0077b5] | 2081 | for (int i=0;i<2;i++) {
|
---|
| 2082 | DistanceToIntersection[i].CopyVector(ClosestPoint);
|
---|
| 2083 | DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
|
---|
| 2084 | distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
|
---|
[16d866] | 2085 | }
|
---|
[1d9b7aa] | 2086 | delete(ClosestPoint);
|
---|
| 2087 | if ((distance[0] * distance[1]) > 0) { // have same sign?
|
---|
[e138de] | 2088 | Log() << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl;
|
---|
[0077b5] | 2089 | if (distance[0] < distance[1]) {
|
---|
| 2090 | Spot = Base->endpoints[0];
|
---|
| 2091 | } else {
|
---|
| 2092 | Spot = Base->endpoints[1];
|
---|
| 2093 | }
|
---|
[16d866] | 2094 | return Spot;
|
---|
[0077b5] | 2095 | } else { // different sign, i.e. we are in between
|
---|
[e138de] | 2096 | Log() << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
|
---|
[16d866] | 2097 | return NULL;
|
---|
| 2098 | }
|
---|
| 2099 |
|
---|
| 2100 | };
|
---|
| 2101 |
|
---|
[776b64] | 2102 | void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
|
---|
[0077b5] | 2103 | {
|
---|
| 2104 | // print all lines
|
---|
[e138de] | 2105 | Log() << Verbose(1) << "Printing all boundary points for debugging:" << endl;
|
---|
[776b64] | 2106 | for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
|
---|
[e138de] | 2107 | Log() << Verbose(2) << *(PointRunner->second) << endl;
|
---|
[0077b5] | 2108 | };
|
---|
| 2109 |
|
---|
[776b64] | 2110 | void Tesselation::PrintAllBoundaryLines(ofstream *out) const
|
---|
[0077b5] | 2111 | {
|
---|
| 2112 | // print all lines
|
---|
[e138de] | 2113 | Log() << Verbose(1) << "Printing all boundary lines for debugging:" << endl;
|
---|
[776b64] | 2114 | for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
|
---|
[e138de] | 2115 | Log() << Verbose(2) << *(LineRunner->second) << endl;
|
---|
[0077b5] | 2116 | };
|
---|
| 2117 |
|
---|
[776b64] | 2118 | void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
|
---|
[0077b5] | 2119 | {
|
---|
| 2120 | // print all triangles
|
---|
[e138de] | 2121 | Log() << Verbose(1) << "Printing all boundary triangles for debugging:" << endl;
|
---|
[776b64] | 2122 | for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
|
---|
[e138de] | 2123 | Log() << Verbose(2) << *(TriangleRunner->second) << endl;
|
---|
[0077b5] | 2124 | };
|
---|
[357fba] | 2125 |
|
---|
[16d866] | 2126 | /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
|
---|
[357fba] | 2127 | * \param *out output stream for debugging
|
---|
[16d866] | 2128 | * \param *Base line to be flipped
|
---|
[57066a] | 2129 | * \return volume change due to flipping (0 - then no flipped occured)
|
---|
[357fba] | 2130 | */
|
---|
[e138de] | 2131 | double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
|
---|
[357fba] | 2132 | {
|
---|
[16d866] | 2133 | class BoundaryLineSet *OtherBase;
|
---|
| 2134 | Vector *ClosestPoint[2];
|
---|
[57066a] | 2135 | double volume;
|
---|
[16d866] | 2136 |
|
---|
| 2137 | int m=0;
|
---|
| 2138 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2139 | for (int j=0;j<3;j++) // all of their endpoints and baselines
|
---|
| 2140 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2141 | BPS[m++] = runner->second->endpoints[j];
|
---|
| 2142 | OtherBase = new class BoundaryLineSet(BPS,-1);
|
---|
[62bb91] | 2143 |
|
---|
[e138de] | 2144 | Log() << Verbose(3) << "INFO: Current base line is " << *Base << "." << endl;
|
---|
| 2145 | Log() << Verbose(3) << "INFO: Other base line is " << *OtherBase << "." << endl;
|
---|
[62bb91] | 2146 |
|
---|
[16d866] | 2147 | // get the closest point on each line to the other line
|
---|
[e138de] | 2148 | ClosestPoint[0] = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
| 2149 | ClosestPoint[1] = GetClosestPointBetweenLine(OtherBase, Base);
|
---|
[16d866] | 2150 |
|
---|
| 2151 | // get the distance vector from Base line to OtherBase line
|
---|
| 2152 | Vector Distance;
|
---|
| 2153 | Distance.CopyVector(ClosestPoint[1]);
|
---|
| 2154 | Distance.SubtractVector(ClosestPoint[0]);
|
---|
| 2155 |
|
---|
[57066a] | 2156 | // calculate volume
|
---|
[c0f6c6] | 2157 | volume = CalculateVolumeofGeneralTetraeder(*Base->endpoints[1]->node->node, *OtherBase->endpoints[0]->node->node, *OtherBase->endpoints[1]->node->node, *Base->endpoints[0]->node->node);
|
---|
[57066a] | 2158 |
|
---|
[0077b5] | 2159 | // delete the temporary other base line and the closest points
|
---|
| 2160 | delete(ClosestPoint[0]);
|
---|
| 2161 | delete(ClosestPoint[1]);
|
---|
[16d866] | 2162 | delete(OtherBase);
|
---|
| 2163 |
|
---|
| 2164 | if (Distance.NormSquared() < MYEPSILON) { // check for intersection
|
---|
[e138de] | 2165 | Log() << Verbose(3) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
|
---|
[16d866] | 2166 | return false;
|
---|
| 2167 | } else { // check for sign against BaseLineNormal
|
---|
| 2168 | Vector BaseLineNormal;
|
---|
[5c7bf8] | 2169 | BaseLineNormal.Zero();
|
---|
| 2170 | if (Base->triangles.size() < 2) {
|
---|
[717e0c] | 2171 | eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;
|
---|
[57066a] | 2172 | return 0.;
|
---|
[5c7bf8] | 2173 | }
|
---|
| 2174 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[e138de] | 2175 | Log() << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
|
---|
[5c7bf8] | 2176 | BaseLineNormal.AddVector(&(runner->second->NormalVector));
|
---|
| 2177 | }
|
---|
[0077b5] | 2178 | BaseLineNormal.Scale(1./2.);
|
---|
[357fba] | 2179 |
|
---|
[16d866] | 2180 | if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
|
---|
[e138de] | 2181 | Log() << Verbose(2) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;
|
---|
[57066a] | 2182 | // calculate volume summand as a general tetraeder
|
---|
| 2183 | return volume;
|
---|
[16d866] | 2184 | } else { // Base higher than OtherBase -> do nothing
|
---|
[e138de] | 2185 | Log() << Verbose(2) << "REJECT: Base line is higher: Nothing to do." << endl;
|
---|
[57066a] | 2186 | return 0.;
|
---|
[16d866] | 2187 | }
|
---|
| 2188 | }
|
---|
| 2189 | };
|
---|
[357fba] | 2190 |
|
---|
[16d866] | 2191 | /** For a given baseline and its two connected triangles, flips the baseline.
|
---|
| 2192 | * I.e. we create the new baseline between the other two endpoints of these four
|
---|
| 2193 | * endpoints and reconstruct the two triangles accordingly.
|
---|
| 2194 | * \param *out output stream for debugging
|
---|
| 2195 | * \param *Base line to be flipped
|
---|
[57066a] | 2196 | * \return pointer to allocated new baseline - flipping successful, NULL - something went awry
|
---|
[16d866] | 2197 | */
|
---|
[e138de] | 2198 | class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
|
---|
[16d866] | 2199 | {
|
---|
| 2200 | class BoundaryLineSet *OldLines[4], *NewLine;
|
---|
| 2201 | class BoundaryPointSet *OldPoints[2];
|
---|
| 2202 | Vector BaseLineNormal;
|
---|
| 2203 | int OldTriangleNrs[2], OldBaseLineNr;
|
---|
| 2204 | int i,m;
|
---|
| 2205 |
|
---|
[e138de] | 2206 | Log() << Verbose(1) << "Begin of FlipBaseline" << endl;
|
---|
[16d866] | 2207 |
|
---|
| 2208 | // calculate NormalVector for later use
|
---|
| 2209 | BaseLineNormal.Zero();
|
---|
| 2210 | if (Base->triangles.size() < 2) {
|
---|
[717e0c] | 2211 | eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;
|
---|
[57066a] | 2212 | return NULL;
|
---|
[16d866] | 2213 | }
|
---|
| 2214 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[e138de] | 2215 | Log() << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
|
---|
[16d866] | 2216 | BaseLineNormal.AddVector(&(runner->second->NormalVector));
|
---|
| 2217 | }
|
---|
| 2218 | BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
|
---|
| 2219 |
|
---|
| 2220 | // get the two triangles
|
---|
| 2221 | // gather four endpoints and four lines
|
---|
| 2222 | for (int j=0;j<4;j++)
|
---|
| 2223 | OldLines[j] = NULL;
|
---|
| 2224 | for (int j=0;j<2;j++)
|
---|
| 2225 | OldPoints[j] = NULL;
|
---|
| 2226 | i=0;
|
---|
| 2227 | m=0;
|
---|
[e138de] | 2228 | Log() << Verbose(3) << "The four old lines are: ";
|
---|
[16d866] | 2229 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2230 | for (int j=0;j<3;j++) // all of their endpoints and baselines
|
---|
| 2231 | if (runner->second->lines[j] != Base) { // pick not the central baseline
|
---|
| 2232 | OldLines[i++] = runner->second->lines[j];
|
---|
[e138de] | 2233 | Log() << Verbose(0) << *runner->second->lines[j] << "\t";
|
---|
[357fba] | 2234 | }
|
---|
[e138de] | 2235 | Log() << Verbose(0) << endl;
|
---|
| 2236 | Log() << Verbose(3) << "The two old points are: ";
|
---|
[16d866] | 2237 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2238 | for (int j=0;j<3;j++) // all of their endpoints and baselines
|
---|
| 2239 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
|
---|
| 2240 | OldPoints[m++] = runner->second->endpoints[j];
|
---|
[e138de] | 2241 | Log() << Verbose(0) << *runner->second->endpoints[j] << "\t";
|
---|
[16d866] | 2242 | }
|
---|
[e138de] | 2243 | Log() << Verbose(0) << endl;
|
---|
[16d866] | 2244 |
|
---|
| 2245 | // check whether everything is in place to create new lines and triangles
|
---|
| 2246 | if (i<4) {
|
---|
[717e0c] | 2247 | eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;
|
---|
[57066a] | 2248 | return NULL;
|
---|
[16d866] | 2249 | }
|
---|
| 2250 | for (int j=0;j<4;j++)
|
---|
| 2251 | if (OldLines[j] == NULL) {
|
---|
[717e0c] | 2252 | eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;
|
---|
[57066a] | 2253 | return NULL;
|
---|
[16d866] | 2254 | }
|
---|
| 2255 | for (int j=0;j<2;j++)
|
---|
| 2256 | if (OldPoints[j] == NULL) {
|
---|
[717e0c] | 2257 | eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl;
|
---|
[57066a] | 2258 | return NULL;
|
---|
[357fba] | 2259 | }
|
---|
[16d866] | 2260 |
|
---|
| 2261 | // remove triangles and baseline removes itself
|
---|
[e138de] | 2262 | Log() << Verbose(3) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
|
---|
[16d866] | 2263 | OldBaseLineNr = Base->Nr;
|
---|
| 2264 | m=0;
|
---|
| 2265 | for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[e138de] | 2266 | Log() << Verbose(3) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
|
---|
[16d866] | 2267 | OldTriangleNrs[m++] = runner->second->Nr;
|
---|
| 2268 | RemoveTesselationTriangle(runner->second);
|
---|
| 2269 | }
|
---|
| 2270 |
|
---|
| 2271 | // construct new baseline (with same number as old one)
|
---|
| 2272 | BPS[0] = OldPoints[0];
|
---|
| 2273 | BPS[1] = OldPoints[1];
|
---|
| 2274 | NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
|
---|
| 2275 | LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
|
---|
[e138de] | 2276 | Log() << Verbose(3) << "INFO: Created new baseline " << *NewLine << "." << endl;
|
---|
[16d866] | 2277 |
|
---|
| 2278 | // construct new triangles with flipped baseline
|
---|
| 2279 | i=-1;
|
---|
| 2280 | if (OldLines[0]->IsConnectedTo(OldLines[2]))
|
---|
| 2281 | i=2;
|
---|
| 2282 | if (OldLines[0]->IsConnectedTo(OldLines[3]))
|
---|
| 2283 | i=3;
|
---|
| 2284 | if (i!=-1) {
|
---|
| 2285 | BLS[0] = OldLines[0];
|
---|
| 2286 | BLS[1] = OldLines[i];
|
---|
| 2287 | BLS[2] = NewLine;
|
---|
| 2288 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[0]);
|
---|
| 2289 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 2290 | AddTesselationTriangle(OldTriangleNrs[0]);
|
---|
[e138de] | 2291 | Log() << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
|
---|
[16d866] | 2292 |
|
---|
| 2293 | BLS[0] = (i==2 ? OldLines[3] : OldLines[2]);
|
---|
| 2294 | BLS[1] = OldLines[1];
|
---|
| 2295 | BLS[2] = NewLine;
|
---|
| 2296 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[1]);
|
---|
| 2297 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 2298 | AddTesselationTriangle(OldTriangleNrs[1]);
|
---|
[e138de] | 2299 | Log() << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
|
---|
[16d866] | 2300 | } else {
|
---|
[e138de] | 2301 | Log() << Verbose(1) << "The four old lines do not connect, something's utterly wrong here!" << endl;
|
---|
[57066a] | 2302 | return NULL;
|
---|
[357fba] | 2303 | }
|
---|
[16d866] | 2304 |
|
---|
[e138de] | 2305 | Log() << Verbose(1) << "End of FlipBaseline" << endl;
|
---|
[57066a] | 2306 | return NewLine;
|
---|
[357fba] | 2307 | };
|
---|
| 2308 |
|
---|
[16d866] | 2309 |
|
---|
[357fba] | 2310 | /** Finds the second point of starting triangle.
|
---|
| 2311 | * \param *a first node
|
---|
| 2312 | * \param Oben vector indicating the outside
|
---|
[f1cccd] | 2313 | * \param OptCandidate reference to recommended candidate on return
|
---|
[357fba] | 2314 | * \param Storage[3] array storing angles and other candidate information
|
---|
| 2315 | * \param RADIUS radius of virtual sphere
|
---|
[62bb91] | 2316 | * \param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 2317 | */
|
---|
[776b64] | 2318 | void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2319 | {
|
---|
[e138de] | 2320 | Log() << Verbose(2) << "Begin of FindSecondPointForTesselation" << endl;
|
---|
[357fba] | 2321 | Vector AngleCheck;
|
---|
[57066a] | 2322 | class TesselPoint* Candidate = NULL;
|
---|
[776b64] | 2323 | double norm = -1.;
|
---|
| 2324 | double angle = 0.;
|
---|
| 2325 | int N[NDIM];
|
---|
| 2326 | int Nlower[NDIM];
|
---|
| 2327 | int Nupper[NDIM];
|
---|
[357fba] | 2328 |
|
---|
[62bb91] | 2329 | if (LC->SetIndexToNode(a)) { // get cell for the starting point
|
---|
[357fba] | 2330 | for(int i=0;i<NDIM;i++) // store indices of this cell
|
---|
| 2331 | N[i] = LC->n[i];
|
---|
| 2332 | } else {
|
---|
[717e0c] | 2333 | eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl;
|
---|
[357fba] | 2334 | return;
|
---|
| 2335 | }
|
---|
[62bb91] | 2336 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[357fba] | 2337 | for (int i=0;i<NDIM;i++) {
|
---|
| 2338 | Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
|
---|
| 2339 | Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
|
---|
| 2340 | }
|
---|
[f1ef60a] | 2341 | Log() << Verbose(3) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :"
|
---|
| 2342 | << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl;
|
---|
[357fba] | 2343 |
|
---|
| 2344 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 2345 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 2346 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[776b64] | 2347 | const LinkedNodes *List = LC->GetCurrentCell();
|
---|
[e138de] | 2348 | //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2349 | if (List != NULL) {
|
---|
[776b64] | 2350 | for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 2351 | Candidate = (*Runner);
|
---|
| 2352 | // check if we only have one unique point yet ...
|
---|
| 2353 | if (a != Candidate) {
|
---|
| 2354 | // Calculate center of the circle with radius RADIUS through points a and Candidate
|
---|
[f1cccd] | 2355 | Vector OrthogonalizedOben, aCandidate, Center;
|
---|
[357fba] | 2356 | double distance, scaleFactor;
|
---|
| 2357 |
|
---|
| 2358 | OrthogonalizedOben.CopyVector(&Oben);
|
---|
[f1cccd] | 2359 | aCandidate.CopyVector(a->node);
|
---|
| 2360 | aCandidate.SubtractVector(Candidate->node);
|
---|
| 2361 | OrthogonalizedOben.ProjectOntoPlane(&aCandidate);
|
---|
[357fba] | 2362 | OrthogonalizedOben.Normalize();
|
---|
[f1cccd] | 2363 | distance = 0.5 * aCandidate.Norm();
|
---|
[357fba] | 2364 | scaleFactor = sqrt(((RADIUS * RADIUS) - (distance * distance)));
|
---|
| 2365 | OrthogonalizedOben.Scale(scaleFactor);
|
---|
| 2366 |
|
---|
| 2367 | Center.CopyVector(Candidate->node);
|
---|
| 2368 | Center.AddVector(a->node);
|
---|
| 2369 | Center.Scale(0.5);
|
---|
| 2370 | Center.AddVector(&OrthogonalizedOben);
|
---|
| 2371 |
|
---|
| 2372 | AngleCheck.CopyVector(&Center);
|
---|
| 2373 | AngleCheck.SubtractVector(a->node);
|
---|
[f1cccd] | 2374 | norm = aCandidate.Norm();
|
---|
[357fba] | 2375 | // second point shall have smallest angle with respect to Oben vector
|
---|
| 2376 | if (norm < RADIUS*2.) {
|
---|
| 2377 | angle = AngleCheck.Angle(&Oben);
|
---|
| 2378 | if (angle < Storage[0]) {
|
---|
[e138de] | 2379 | //Log() << Verbose(3) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
|
---|
| 2380 | Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
|
---|
[f1cccd] | 2381 | OptCandidate = Candidate;
|
---|
[357fba] | 2382 | Storage[0] = angle;
|
---|
[e138de] | 2383 | //Log() << Verbose(3) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
|
---|
[357fba] | 2384 | } else {
|
---|
[e138de] | 2385 | //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
|
---|
[357fba] | 2386 | }
|
---|
| 2387 | } else {
|
---|
[e138de] | 2388 | //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
|
---|
[357fba] | 2389 | }
|
---|
| 2390 | } else {
|
---|
[e138de] | 2391 | //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
|
---|
[357fba] | 2392 | }
|
---|
| 2393 | }
|
---|
| 2394 | } else {
|
---|
[e138de] | 2395 | Log() << Verbose(3) << "Linked cell list is empty." << endl;
|
---|
[357fba] | 2396 | }
|
---|
| 2397 | }
|
---|
[e138de] | 2398 | Log() << Verbose(2) << "End of FindSecondPointForTesselation" << endl;
|
---|
[357fba] | 2399 | };
|
---|
| 2400 |
|
---|
| 2401 |
|
---|
| 2402 | /** This recursive function finds a third point, to form a triangle with two given ones.
|
---|
| 2403 | * Note that this function is for the starting triangle.
|
---|
| 2404 | * The idea is as follows: A sphere with fixed radius is (almost) uniquely defined in space by three points
|
---|
| 2405 | * that sit on its boundary. Hence, when two points are given and we look for the (next) third point, then
|
---|
| 2406 | * the center of the sphere is still fixed up to a single parameter. The band of possible values
|
---|
| 2407 | * describes a circle in 3D-space. The old center of the sphere for the current base triangle gives
|
---|
| 2408 | * us the "null" on this circle, the new center of the candidate point will be some way along this
|
---|
| 2409 | * circle. The shorter the way the better is the candidate. Note that the direction is clearly given
|
---|
| 2410 | * by the normal vector of the base triangle that always points outwards by construction.
|
---|
| 2411 | * Hence, we construct a Center of this circle which sits right in the middle of the current base line.
|
---|
| 2412 | * We construct the normal vector that defines the plane this circle lies in, it is just in the
|
---|
| 2413 | * direction of the baseline. And finally, we need the radius of the circle, which is given by the rest
|
---|
| 2414 | * with respect to the length of the baseline and the sphere's fixed \a RADIUS.
|
---|
| 2415 | * Note that there is one difficulty: The circumcircle is uniquely defined, but for the circumsphere's center
|
---|
| 2416 | * there are two possibilities which becomes clear from the construction as seen below. Hence, we must check
|
---|
| 2417 | * both.
|
---|
| 2418 | * Note also that the acos() function is not unique on [0, 2.*M_PI). Hence, we need an additional check
|
---|
| 2419 | * to decide for one of the two possible angles. Therefore we need a SearchDirection and to make this check
|
---|
| 2420 | * sensible we need OldSphereCenter to be orthogonal to it. Either we construct SearchDirection orthogonal
|
---|
| 2421 | * right away, or -- what we do here -- we rotate the relative sphere centers such that this orthogonality
|
---|
| 2422 | * holds. Then, the normalized projection onto the SearchDirection is either +1 or -1 and thus states whether
|
---|
| 2423 | * the angle is uniquely in either (0,M_PI] or [M_PI, 2.*M_PI).
|
---|
[f1cccd] | 2424 | * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa FindStartingTriangle())
|
---|
[357fba] | 2425 | * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
|
---|
| 2426 | * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
|
---|
| 2427 | * @param BaseLine BoundaryLineSet with the current base line
|
---|
[62bb91] | 2428 | * @param ThirdNode third point to avoid in search
|
---|
[357fba] | 2429 | * @param candidates list of equally good candidates to return
|
---|
[f1cccd] | 2430 | * @param ShortestAngle the current path length on this circle band for the current OptCandidate
|
---|
[357fba] | 2431 | * @param RADIUS radius of sphere
|
---|
[62bb91] | 2432 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 2433 | */
|
---|
[f1ef60a] | 2434 | void Tesselation::FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, class BoundaryLineSet *BaseLine, const class TesselPoint * const ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC) const
|
---|
[357fba] | 2435 | {
|
---|
| 2436 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
| 2437 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 2438 | Vector SphereCenter;
|
---|
| 2439 | Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
|
---|
| 2440 | Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
|
---|
| 2441 | Vector NewNormalVector; // normal vector of the Candidate's triangle
|
---|
| 2442 | Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
|
---|
| 2443 | double CircleRadius; // radius of this circle
|
---|
| 2444 | double radius;
|
---|
| 2445 | double alpha, Otheralpha; // angles (i.e. parameter for the circle).
|
---|
| 2446 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
| 2447 | TesselPoint *Candidate = NULL;
|
---|
| 2448 | CandidateForTesselation *optCandidate = NULL;
|
---|
| 2449 |
|
---|
[e138de] | 2450 | Log() << Verbose(1) << "Begin of FindThirdPointForTesselation" << endl;
|
---|
[357fba] | 2451 |
|
---|
[e138de] | 2452 | Log() << Verbose(2) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
|
---|
[357fba] | 2453 |
|
---|
| 2454 | // construct center of circle
|
---|
| 2455 | CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node);
|
---|
| 2456 | CircleCenter.AddVector(BaseLine->endpoints[1]->node->node);
|
---|
| 2457 | CircleCenter.Scale(0.5);
|
---|
| 2458 |
|
---|
| 2459 | // construct normal vector of circle
|
---|
| 2460 | CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node);
|
---|
| 2461 | CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
|
---|
| 2462 |
|
---|
[ab1932] | 2463 | // calculate squared radius TesselPoint *ThirdNode,f circle
|
---|
[357fba] | 2464 | radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
|
---|
| 2465 | if (radius/4. < RADIUS*RADIUS) {
|
---|
| 2466 | CircleRadius = RADIUS*RADIUS - radius/4.;
|
---|
| 2467 | CirclePlaneNormal.Normalize();
|
---|
[e138de] | 2468 | //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
[357fba] | 2469 |
|
---|
| 2470 | // test whether old center is on the band's plane
|
---|
| 2471 | if (fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
|
---|
[717e0c] | 2472 | eLog() << Verbose(1) << "Something's very wrong here: OldSphereCenter is not on the band's plane as desired by " << fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
|
---|
[357fba] | 2473 | OldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
|
---|
| 2474 | }
|
---|
| 2475 | radius = OldSphereCenter.ScalarProduct(&OldSphereCenter);
|
---|
| 2476 | if (fabs(radius - CircleRadius) < HULLEPSILON) {
|
---|
[e138de] | 2477 | //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
|
---|
[357fba] | 2478 |
|
---|
| 2479 | // check SearchDirection
|
---|
[e138de] | 2480 | //Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
[357fba] | 2481 | if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
|
---|
[717e0c] | 2482 | eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl;
|
---|
[357fba] | 2483 | }
|
---|
| 2484 |
|
---|
[62bb91] | 2485 | // get cell for the starting point
|
---|
[357fba] | 2486 | if (LC->SetIndexToVector(&CircleCenter)) {
|
---|
| 2487 | for(int i=0;i<NDIM;i++) // store indices of this cell
|
---|
| 2488 | N[i] = LC->n[i];
|
---|
[e138de] | 2489 | //Log() << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2490 | } else {
|
---|
[717e0c] | 2491 | eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl;
|
---|
[357fba] | 2492 | return;
|
---|
| 2493 | }
|
---|
[62bb91] | 2494 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[e138de] | 2495 | //Log() << Verbose(2) << "LC Intervals:";
|
---|
[357fba] | 2496 | for (int i=0;i<NDIM;i++) {
|
---|
| 2497 | Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
|
---|
| 2498 | Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
|
---|
[e138de] | 2499 | //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
|
---|
[357fba] | 2500 | }
|
---|
[e138de] | 2501 | //Log() << Verbose(0) << endl;
|
---|
[357fba] | 2502 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 2503 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 2504 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[776b64] | 2505 | const LinkedNodes *List = LC->GetCurrentCell();
|
---|
[e138de] | 2506 | //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2507 | if (List != NULL) {
|
---|
[776b64] | 2508 | for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 2509 | Candidate = (*Runner);
|
---|
| 2510 |
|
---|
| 2511 | // check for three unique points
|
---|
[e138de] | 2512 | //Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " at " << Candidate->node << "." << endl;
|
---|
[357fba] | 2513 | if ((Candidate != BaseLine->endpoints[0]->node) && (Candidate != BaseLine->endpoints[1]->node) ){
|
---|
| 2514 |
|
---|
| 2515 | // construct both new centers
|
---|
[c0f6c6] | 2516 | GetCenterofCircumcircle(&NewSphereCenter, *BaseLine->endpoints[0]->node->node, *BaseLine->endpoints[1]->node->node, *Candidate->node);
|
---|
[357fba] | 2517 | OtherNewSphereCenter.CopyVector(&NewSphereCenter);
|
---|
| 2518 |
|
---|
| 2519 | if ((NewNormalVector.MakeNormalVector(BaseLine->endpoints[0]->node->node, BaseLine->endpoints[1]->node->node, Candidate->node))
|
---|
| 2520 | && (fabs(NewNormalVector.ScalarProduct(&NewNormalVector)) > HULLEPSILON)
|
---|
| 2521 | ) {
|
---|
| 2522 | helper.CopyVector(&NewNormalVector);
|
---|
[e138de] | 2523 | //Log() << Verbose(2) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
|
---|
[357fba] | 2524 | radius = BaseLine->endpoints[0]->node->node->DistanceSquared(&NewSphereCenter);
|
---|
| 2525 | if (radius < RADIUS*RADIUS) {
|
---|
| 2526 | helper.Scale(sqrt(RADIUS*RADIUS - radius));
|
---|
[e138de] | 2527 | //Log() << Verbose(2) << "INFO: Distance of NewCircleCenter to NewSphereCenter is " << helper.Norm() << " with sphere radius " << RADIUS << "." << endl;
|
---|
[357fba] | 2528 | NewSphereCenter.AddVector(&helper);
|
---|
| 2529 | NewSphereCenter.SubtractVector(&CircleCenter);
|
---|
[e138de] | 2530 | //Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
|
---|
[357fba] | 2531 |
|
---|
| 2532 | // OtherNewSphereCenter is created by the same vector just in the other direction
|
---|
| 2533 | helper.Scale(-1.);
|
---|
| 2534 | OtherNewSphereCenter.AddVector(&helper);
|
---|
| 2535 | OtherNewSphereCenter.SubtractVector(&CircleCenter);
|
---|
[e138de] | 2536 | //Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
|
---|
[357fba] | 2537 |
|
---|
| 2538 | alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
| 2539 | Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
| 2540 | alpha = min(alpha, Otheralpha);
|
---|
| 2541 | // if there is a better candidate, drop the current list and add the new candidate
|
---|
| 2542 | // otherwise ignore the new candidate and keep the list
|
---|
| 2543 | if (*ShortestAngle > (alpha - HULLEPSILON)) {
|
---|
| 2544 | optCandidate = new CandidateForTesselation(Candidate, BaseLine, OptCandidateCenter, OtherOptCandidateCenter);
|
---|
| 2545 | if (fabs(alpha - Otheralpha) > MYEPSILON) {
|
---|
| 2546 | optCandidate->OptCenter.CopyVector(&NewSphereCenter);
|
---|
| 2547 | optCandidate->OtherOptCenter.CopyVector(&OtherNewSphereCenter);
|
---|
| 2548 | } else {
|
---|
| 2549 | optCandidate->OptCenter.CopyVector(&OtherNewSphereCenter);
|
---|
| 2550 | optCandidate->OtherOptCenter.CopyVector(&NewSphereCenter);
|
---|
| 2551 | }
|
---|
| 2552 | // if there is an equal candidate, add it to the list without clearing the list
|
---|
| 2553 | if ((*ShortestAngle - HULLEPSILON) < alpha) {
|
---|
| 2554 | candidates->push_back(optCandidate);
|
---|
[e138de] | 2555 | Log() << Verbose(2) << "ACCEPT: We have found an equally good candidate: " << *(optCandidate->point) << " with "
|
---|
[357fba] | 2556 | << alpha << " and circumsphere's center at " << optCandidate->OptCenter << "." << endl;
|
---|
| 2557 | } else {
|
---|
| 2558 | // remove all candidates from the list and then the list itself
|
---|
| 2559 | class CandidateForTesselation *remover = NULL;
|
---|
| 2560 | for (CandidateList::iterator it = candidates->begin(); it != candidates->end(); ++it) {
|
---|
| 2561 | remover = *it;
|
---|
| 2562 | delete(remover);
|
---|
| 2563 | }
|
---|
| 2564 | candidates->clear();
|
---|
| 2565 | candidates->push_back(optCandidate);
|
---|
[e138de] | 2566 | Log() << Verbose(2) << "ACCEPT: We have found a better candidate: " << *(optCandidate->point) << " with "
|
---|
[357fba] | 2567 | << alpha << " and circumsphere's center at " << optCandidate->OptCenter << "." << endl;
|
---|
| 2568 | }
|
---|
| 2569 | *ShortestAngle = alpha;
|
---|
[e138de] | 2570 | //Log() << Verbose(2) << "INFO: There are " << candidates->size() << " candidates in the list now." << endl;
|
---|
[357fba] | 2571 | } else {
|
---|
| 2572 | if ((optCandidate != NULL) && (optCandidate->point != NULL)) {
|
---|
[e138de] | 2573 | //Log() << Verbose(2) << "REJECT: Old candidate " << *(optCandidate->point) << " with " << *ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
|
---|
[357fba] | 2574 | } else {
|
---|
[e138de] | 2575 | //Log() << Verbose(2) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
|
---|
[357fba] | 2576 | }
|
---|
| 2577 | }
|
---|
| 2578 |
|
---|
| 2579 | } else {
|
---|
[e138de] | 2580 | //Log() << Verbose(2) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
|
---|
[357fba] | 2581 | }
|
---|
| 2582 | } else {
|
---|
[e138de] | 2583 | //Log() << Verbose(2) << "REJECT: Three points from " << *BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
|
---|
[357fba] | 2584 | }
|
---|
| 2585 | } else {
|
---|
| 2586 | if (ThirdNode != NULL) {
|
---|
[e138de] | 2587 | //Log() << Verbose(2) << "REJECT: Base triangle " << *BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
|
---|
[357fba] | 2588 | } else {
|
---|
[e138de] | 2589 | //Log() << Verbose(2) << "REJECT: Base triangle " << *BaseLine << " contains Candidate " << *Candidate << "." << endl;
|
---|
[357fba] | 2590 | }
|
---|
| 2591 | }
|
---|
| 2592 | }
|
---|
| 2593 | }
|
---|
| 2594 | }
|
---|
| 2595 | } else {
|
---|
[717e0c] | 2596 | eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;
|
---|
[357fba] | 2597 | }
|
---|
| 2598 | } else {
|
---|
| 2599 | if (ThirdNode != NULL)
|
---|
[e138de] | 2600 | Log() << Verbose(2) << "Circumcircle for base line " << *BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
|
---|
[357fba] | 2601 | else
|
---|
[e138de] | 2602 | Log() << Verbose(2) << "Circumcircle for base line " << *BaseLine << " is too big!" << endl;
|
---|
[357fba] | 2603 | }
|
---|
| 2604 |
|
---|
[e138de] | 2605 | //Log() << Verbose(2) << "INFO: Sorting candidate list ..." << endl;
|
---|
[357fba] | 2606 | if (candidates->size() > 1) {
|
---|
| 2607 | candidates->unique();
|
---|
[f1cccd] | 2608 | candidates->sort(SortCandidates);
|
---|
[357fba] | 2609 | }
|
---|
| 2610 |
|
---|
[e138de] | 2611 | Log() << Verbose(1) << "End of FindThirdPointForTesselation" << endl;
|
---|
[357fba] | 2612 | };
|
---|
| 2613 |
|
---|
| 2614 | /** Finds the endpoint two lines are sharing.
|
---|
| 2615 | * \param *line1 first line
|
---|
| 2616 | * \param *line2 second line
|
---|
| 2617 | * \return point which is shared or NULL if none
|
---|
| 2618 | */
|
---|
[776b64] | 2619 | class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
|
---|
[357fba] | 2620 | {
|
---|
[776b64] | 2621 | const BoundaryLineSet * lines[2] = { line1, line2 };
|
---|
[357fba] | 2622 | class BoundaryPointSet *node = NULL;
|
---|
| 2623 | map<int, class BoundaryPointSet *> OrderMap;
|
---|
| 2624 | pair<map<int, class BoundaryPointSet *>::iterator, bool> OrderTest;
|
---|
| 2625 | for (int i = 0; i < 2; i++)
|
---|
| 2626 | // for both lines
|
---|
| 2627 | for (int j = 0; j < 2; j++)
|
---|
| 2628 | { // for both endpoints
|
---|
| 2629 | OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (
|
---|
| 2630 | lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
|
---|
| 2631 | if (!OrderTest.second)
|
---|
| 2632 | { // if insertion fails, we have common endpoint
|
---|
| 2633 | node = OrderTest.first->second;
|
---|
[e138de] | 2634 | Log() << Verbose(5) << "Common endpoint of lines " << *line1
|
---|
[357fba] | 2635 | << " and " << *line2 << " is: " << *node << "." << endl;
|
---|
| 2636 | j = 2;
|
---|
| 2637 | i = 2;
|
---|
| 2638 | break;
|
---|
| 2639 | }
|
---|
| 2640 | }
|
---|
| 2641 | return node;
|
---|
| 2642 | };
|
---|
| 2643 |
|
---|
[62bb91] | 2644 | /** Finds the triangle that is closest to a given Vector \a *x.
|
---|
| 2645 | * \param *out output stream for debugging
|
---|
| 2646 | * \param *x Vector to look from
|
---|
| 2647 | * \return list of BoundaryTriangleSet of nearest triangles or NULL in degenerate case.
|
---|
| 2648 | */
|
---|
[e138de] | 2649 | list<BoundaryTriangleSet*> * Tesselation::FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 2650 | {
|
---|
[5c7bf8] | 2651 | TesselPoint *trianglePoints[3];
|
---|
| 2652 | TesselPoint *SecondPoint = NULL;
|
---|
[57066a] | 2653 | list<BoundaryTriangleSet*> *triangles = NULL;
|
---|
[62bb91] | 2654 |
|
---|
| 2655 | if (LinesOnBoundary.empty()) {
|
---|
[e138de] | 2656 | Log() << Verbose(0) << "Error: There is no tesselation structure to compare the point with, please create one first.";
|
---|
[62bb91] | 2657 | return NULL;
|
---|
| 2658 | }
|
---|
[e138de] | 2659 | Log() << Verbose(1) << "Finding closest Tesselpoint to " << *x << " ... " << endl;
|
---|
[f1cccd] | 2660 | trianglePoints[0] = FindClosestPoint(x, SecondPoint, LC);
|
---|
[5c7bf8] | 2661 |
|
---|
[62bb91] | 2662 | // check whether closest point is "too close" :), then it's inside
|
---|
[5c7bf8] | 2663 | if (trianglePoints[0] == NULL) {
|
---|
[e138de] | 2664 | Log() << Verbose(2) << "Is the only point, no one else is closeby." << endl;
|
---|
[5c7bf8] | 2665 | return NULL;
|
---|
| 2666 | }
|
---|
[62bb91] | 2667 | if (trianglePoints[0]->node->DistanceSquared(x) < MYEPSILON) {
|
---|
[e138de] | 2668 | Log() << Verbose(3) << "Point is right on a tesselation point, no nearest triangle." << endl;
|
---|
[776b64] | 2669 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(trianglePoints[0]->nr);
|
---|
[57066a] | 2670 | triangles = new list<BoundaryTriangleSet*>;
|
---|
| 2671 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 2672 | for(LineMap::iterator LineRunner = PointRunner->second->lines.begin(); LineRunner != PointRunner->second->lines.end(); LineRunner++)
|
---|
| 2673 | for(TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
|
---|
| 2674 | triangles->push_back(TriangleRunner->second);
|
---|
| 2675 | triangles->sort();
|
---|
| 2676 | triangles->unique();
|
---|
| 2677 | } else {
|
---|
| 2678 | PointRunner = PointsOnBoundary.find(SecondPoint->nr);
|
---|
| 2679 | trianglePoints[0] = SecondPoint;
|
---|
| 2680 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 2681 | for(LineMap::iterator LineRunner = PointRunner->second->lines.begin(); LineRunner != PointRunner->second->lines.end(); LineRunner++)
|
---|
| 2682 | for(TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
|
---|
| 2683 | triangles->push_back(TriangleRunner->second);
|
---|
| 2684 | triangles->sort();
|
---|
| 2685 | triangles->unique();
|
---|
| 2686 | } else {
|
---|
[717e0c] | 2687 | eLog() << Verbose(1) << "I cannot find a boundary point to the tessel point " << *trianglePoints[0] << "." << endl;
|
---|
[57066a] | 2688 | return NULL;
|
---|
| 2689 | }
|
---|
| 2690 | }
|
---|
| 2691 | } else {
|
---|
[e138de] | 2692 | list<TesselPoint*> *connectedClosestPoints = GetCircleOfConnectedPoints(trianglePoints[0], x);
|
---|
[99593f] | 2693 | if (connectedClosestPoints != NULL) {
|
---|
| 2694 | trianglePoints[1] = connectedClosestPoints->front();
|
---|
| 2695 | trianglePoints[2] = connectedClosestPoints->back();
|
---|
| 2696 | for (int i=0;i<3;i++) {
|
---|
| 2697 | if (trianglePoints[i] == NULL) {
|
---|
[717e0c] | 2698 | eLog() << Verbose(1) << "IsInnerPoint encounters serious error, point " << i << " not found." << endl;
|
---|
[99593f] | 2699 | }
|
---|
[e138de] | 2700 | //Log() << Verbose(2) << "List of triangle points:" << endl;
|
---|
| 2701 | //Log() << Verbose(3) << *trianglePoints[i] << endl;
|
---|
[57066a] | 2702 | }
|
---|
[62bb91] | 2703 |
|
---|
[99593f] | 2704 | triangles = FindTriangles(trianglePoints);
|
---|
[e138de] | 2705 | Log() << Verbose(2) << "List of possible triangles:" << endl;
|
---|
[99593f] | 2706 | for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
|
---|
[e138de] | 2707 | Log() << Verbose(3) << **Runner << endl;
|
---|
[62bb91] | 2708 |
|
---|
[99593f] | 2709 | delete(connectedClosestPoints);
|
---|
| 2710 | } else {
|
---|
| 2711 | triangles = NULL;
|
---|
[e138de] | 2712 | Log() << Verbose(1) << "There is no circle of connected points!" << endl;
|
---|
[99593f] | 2713 | }
|
---|
[57066a] | 2714 | }
|
---|
[5c7bf8] | 2715 |
|
---|
[99593f] | 2716 | if ((triangles == NULL) || (triangles->empty())) {
|
---|
[717e0c] | 2717 | eLog() << Verbose(1) << "There is no nearest triangle. Please check the tesselation structure.";
|
---|
[57066a] | 2718 | delete(triangles);
|
---|
[62bb91] | 2719 | return NULL;
|
---|
| 2720 | } else
|
---|
| 2721 | return triangles;
|
---|
| 2722 | };
|
---|
| 2723 |
|
---|
| 2724 | /** Finds closest triangle to a point.
|
---|
| 2725 | * This basically just takes care of the degenerate case, which is not handled in FindClosestTrianglesToPoint().
|
---|
| 2726 | * \param *out output stream for debugging
|
---|
| 2727 | * \param *x Vector to look from
|
---|
| 2728 | * \return list of BoundaryTriangleSet of nearest triangles or NULL.
|
---|
| 2729 | */
|
---|
[e138de] | 2730 | class BoundaryTriangleSet * Tesselation::FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 2731 | {
|
---|
| 2732 | class BoundaryTriangleSet *result = NULL;
|
---|
[e138de] | 2733 | list<BoundaryTriangleSet*> *triangles = FindClosestTrianglesToPoint(x, LC);
|
---|
[57066a] | 2734 | Vector Center;
|
---|
[62bb91] | 2735 |
|
---|
| 2736 | if (triangles == NULL)
|
---|
| 2737 | return NULL;
|
---|
| 2738 |
|
---|
[57066a] | 2739 | if (triangles->size() == 1) { // there is no degenerate case
|
---|
[62bb91] | 2740 | result = triangles->front();
|
---|
[e138de] | 2741 | Log() << Verbose(2) << "Normal Vector of this triangle is " << result->NormalVector << "." << endl;
|
---|
[57066a] | 2742 | } else {
|
---|
| 2743 | result = triangles->front();
|
---|
| 2744 | result->GetCenter(&Center);
|
---|
| 2745 | Center.SubtractVector(x);
|
---|
[e138de] | 2746 | Log() << Verbose(2) << "Normal Vector of this front side is " << result->NormalVector << "." << endl;
|
---|
[57066a] | 2747 | if (Center.ScalarProduct(&result->NormalVector) < 0) {
|
---|
| 2748 | result = triangles->back();
|
---|
[e138de] | 2749 | Log() << Verbose(2) << "Normal Vector of this back side is " << result->NormalVector << "." << endl;
|
---|
[57066a] | 2750 | if (Center.ScalarProduct(&result->NormalVector) < 0) {
|
---|
[717e0c] | 2751 | eLog() << Verbose(1) << "Front and back side yield NormalVector in wrong direction!" << endl;
|
---|
[57066a] | 2752 | }
|
---|
| 2753 | }
|
---|
| 2754 | }
|
---|
[62bb91] | 2755 | delete(triangles);
|
---|
| 2756 | return result;
|
---|
| 2757 | };
|
---|
| 2758 |
|
---|
| 2759 | /** Checks whether the provided Vector is within the tesselation structure.
|
---|
| 2760 | *
|
---|
| 2761 | * @param point of which to check the position
|
---|
| 2762 | * @param *LC LinkedCell structure
|
---|
| 2763 | *
|
---|
| 2764 | * @return true if the point is inside the tesselation structure, false otherwise
|
---|
| 2765 | */
|
---|
[e138de] | 2766 | bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
|
---|
[62bb91] | 2767 | {
|
---|
[e138de] | 2768 | class BoundaryTriangleSet *result = FindClosestTriangleToPoint(&Point, LC);
|
---|
[57066a] | 2769 | Vector Center;
|
---|
| 2770 |
|
---|
| 2771 | if (result == NULL) {// is boundary point or only point in point cloud?
|
---|
[e138de] | 2772 | Log() << Verbose(1) << Point << " is the only point in vicinity." << endl;
|
---|
[57066a] | 2773 | return false;
|
---|
| 2774 | }
|
---|
| 2775 |
|
---|
| 2776 | result->GetCenter(&Center);
|
---|
[e138de] | 2777 | Log() << Verbose(3) << "INFO: Central point of the triangle is " << Center << "." << endl;
|
---|
[57066a] | 2778 | Center.SubtractVector(&Point);
|
---|
[e138de] | 2779 | Log() << Verbose(3) << "INFO: Vector from center to point to test is " << Center << "." << endl;
|
---|
[57066a] | 2780 | if (Center.ScalarProduct(&result->NormalVector) > -MYEPSILON) {
|
---|
[e138de] | 2781 | Log() << Verbose(1) << Point << " is an inner point." << endl;
|
---|
[62bb91] | 2782 | return true;
|
---|
[57066a] | 2783 | } else {
|
---|
[e138de] | 2784 | Log() << Verbose(1) << Point << " is NOT an inner point." << endl;
|
---|
[62bb91] | 2785 | return false;
|
---|
[57066a] | 2786 | }
|
---|
[62bb91] | 2787 | }
|
---|
| 2788 |
|
---|
| 2789 | /** Checks whether the provided TesselPoint is within the tesselation structure.
|
---|
| 2790 | *
|
---|
| 2791 | * @param *Point of which to check the position
|
---|
| 2792 | * @param *LC Linked Cell structure
|
---|
| 2793 | *
|
---|
| 2794 | * @return true if the point is inside the tesselation structure, false otherwise
|
---|
| 2795 | */
|
---|
[e138de] | 2796 | bool Tesselation::IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const
|
---|
[62bb91] | 2797 | {
|
---|
[e138de] | 2798 | return IsInnerPoint(*(Point->node), LC);
|
---|
[62bb91] | 2799 | }
|
---|
| 2800 |
|
---|
| 2801 | /** Gets all points connected to the provided point by triangulation lines.
|
---|
| 2802 | *
|
---|
| 2803 | * @param *Point of which get all connected points
|
---|
| 2804 | *
|
---|
[065e82] | 2805 | * @return set of the all points linked to the provided one
|
---|
[62bb91] | 2806 | */
|
---|
[e138de] | 2807 | set<TesselPoint*> * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
|
---|
[62bb91] | 2808 | {
|
---|
[065e82] | 2809 | set<TesselPoint*> *connectedPoints = new set<TesselPoint*>;
|
---|
[5c7bf8] | 2810 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
[62bb91] | 2811 | TesselPoint* current;
|
---|
| 2812 | bool takePoint = false;
|
---|
| 2813 |
|
---|
[e138de] | 2814 | Log() << Verbose(3) << "Begin of GetAllConnectedPoints" << endl;
|
---|
[a2028e] | 2815 |
|
---|
[5c7bf8] | 2816 | // find the respective boundary point
|
---|
[776b64] | 2817 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[5c7bf8] | 2818 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 2819 | ReferencePoint = PointRunner->second;
|
---|
| 2820 | } else {
|
---|
[e138de] | 2821 | Log() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
|
---|
[5c7bf8] | 2822 | ReferencePoint = NULL;
|
---|
| 2823 | }
|
---|
[62bb91] | 2824 |
|
---|
[065e82] | 2825 | // little trick so that we look just through lines connect to the BoundaryPoint
|
---|
[5c7bf8] | 2826 | // OR fall-back to look through all lines if there is no such BoundaryPoint
|
---|
[776b64] | 2827 | const LineMap *Lines;;
|
---|
[5c7bf8] | 2828 | if (ReferencePoint != NULL)
|
---|
| 2829 | Lines = &(ReferencePoint->lines);
|
---|
[776b64] | 2830 | else
|
---|
| 2831 | Lines = &LinesOnBoundary;
|
---|
| 2832 | LineMap::const_iterator findLines = Lines->begin();
|
---|
[5c7bf8] | 2833 | while (findLines != Lines->end()) {
|
---|
[065e82] | 2834 | takePoint = false;
|
---|
| 2835 |
|
---|
| 2836 | if (findLines->second->endpoints[0]->Nr == Point->nr) {
|
---|
| 2837 | takePoint = true;
|
---|
| 2838 | current = findLines->second->endpoints[1]->node;
|
---|
| 2839 | } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
|
---|
| 2840 | takePoint = true;
|
---|
| 2841 | current = findLines->second->endpoints[0]->node;
|
---|
| 2842 | }
|
---|
| 2843 |
|
---|
| 2844 | if (takePoint) {
|
---|
[e138de] | 2845 | Log() << Verbose(5) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
|
---|
[065e82] | 2846 | connectedPoints->insert(current);
|
---|
| 2847 | }
|
---|
[62bb91] | 2848 |
|
---|
[065e82] | 2849 | findLines++;
|
---|
[62bb91] | 2850 | }
|
---|
| 2851 |
|
---|
[16d866] | 2852 | if (connectedPoints->size() == 0) { // if have not found any points
|
---|
[717e0c] | 2853 | eLog() << Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl;
|
---|
[16d866] | 2854 | return NULL;
|
---|
| 2855 | }
|
---|
[065e82] | 2856 |
|
---|
[e138de] | 2857 | Log() << Verbose(3) << "End of GetAllConnectedPoints" << endl;
|
---|
[16d866] | 2858 | return connectedPoints;
|
---|
[065e82] | 2859 | };
|
---|
[16d866] | 2860 |
|
---|
[065e82] | 2861 |
|
---|
| 2862 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
[16d866] | 2863 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 2864 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 2865 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 2866 | * triangle we are looking for.
|
---|
| 2867 | *
|
---|
| 2868 | * @param *out output stream for debugging
|
---|
| 2869 | * @param *Point of which get all connected points
|
---|
[065e82] | 2870 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 2871 | * @return list of the all points linked to the provided one
|
---|
[16d866] | 2872 | */
|
---|
[e138de] | 2873 | list<TesselPoint*> * Tesselation::GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[16d866] | 2874 | {
|
---|
| 2875 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[e138de] | 2876 | set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(Point);
|
---|
[065e82] | 2877 | list<TesselPoint*> *connectedCircle = new list<TesselPoint*>;
|
---|
| 2878 | Vector center;
|
---|
| 2879 | Vector PlaneNormal;
|
---|
| 2880 | Vector AngleZero;
|
---|
| 2881 | Vector OrthogonalVector;
|
---|
| 2882 | Vector helper;
|
---|
[62bb91] | 2883 |
|
---|
[99593f] | 2884 | if (connectedPoints == NULL) {
|
---|
[e138de] | 2885 | Log() << Verbose(2) << "Could not find any connected points!" << endl;
|
---|
[99593f] | 2886 | delete(connectedCircle);
|
---|
| 2887 | return NULL;
|
---|
| 2888 | }
|
---|
[e138de] | 2889 | Log() << Verbose(2) << "Begin of GetCircleOfConnectedPoints" << endl;
|
---|
[a2028e] | 2890 |
|
---|
[16d866] | 2891 | // calculate central point
|
---|
[776b64] | 2892 | for (set<TesselPoint*>::const_iterator TesselRunner = connectedPoints->begin(); TesselRunner != connectedPoints->end(); TesselRunner++)
|
---|
[16d866] | 2893 | center.AddVector((*TesselRunner)->node);
|
---|
[e138de] | 2894 | //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
|
---|
[16d866] | 2895 | // << "; scale factor " << 1.0/connectedPoints.size();
|
---|
| 2896 | center.Scale(1.0/connectedPoints->size());
|
---|
[e138de] | 2897 | Log() << Verbose(4) << "INFO: Calculated center of all circle points is " << center << "." << endl;
|
---|
[5c7bf8] | 2898 |
|
---|
| 2899 | // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
|
---|
| 2900 | PlaneNormal.CopyVector(Point->node);
|
---|
| 2901 | PlaneNormal.SubtractVector(¢er);
|
---|
| 2902 | PlaneNormal.Normalize();
|
---|
[e138de] | 2903 | Log() << Verbose(4) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
|
---|
[62bb91] | 2904 |
|
---|
| 2905 | // construct one orthogonal vector
|
---|
[a2028e] | 2906 | if (Reference != NULL) {
|
---|
[065e82] | 2907 | AngleZero.CopyVector(Reference);
|
---|
[a2028e] | 2908 | AngleZero.SubtractVector(Point->node);
|
---|
| 2909 | AngleZero.ProjectOntoPlane(&PlaneNormal);
|
---|
| 2910 | }
|
---|
| 2911 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
|
---|
[e138de] | 2912 | Log() << Verbose(4) << "Using alternatively " << *(*connectedPoints->begin())->node << " as angle 0 referencer." << endl;
|
---|
[065e82] | 2913 | AngleZero.CopyVector((*connectedPoints->begin())->node);
|
---|
[a2028e] | 2914 | AngleZero.SubtractVector(Point->node);
|
---|
| 2915 | AngleZero.ProjectOntoPlane(&PlaneNormal);
|
---|
| 2916 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
[e138de] | 2917 | eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
|
---|
[a2028e] | 2918 | performCriticalExit();
|
---|
| 2919 | }
|
---|
| 2920 | }
|
---|
[e138de] | 2921 | Log() << Verbose(4) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
|
---|
[a2028e] | 2922 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
| 2923 | OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
|
---|
| 2924 | else
|
---|
| 2925 | OrthogonalVector.MakeNormalVector(&PlaneNormal);
|
---|
[e138de] | 2926 | Log() << Verbose(4) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
|
---|
[16d866] | 2927 |
|
---|
[5c7bf8] | 2928 | // go through all connected points and calculate angle
|
---|
[065e82] | 2929 | for (set<TesselPoint*>::iterator listRunner = connectedPoints->begin(); listRunner != connectedPoints->end(); listRunner++) {
|
---|
[5c7bf8] | 2930 | helper.CopyVector((*listRunner)->node);
|
---|
| 2931 | helper.SubtractVector(Point->node);
|
---|
| 2932 | helper.ProjectOntoPlane(&PlaneNormal);
|
---|
[f1cccd] | 2933 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
[e138de] | 2934 | Log() << Verbose(3) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
|
---|
[62bb91] | 2935 | anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
|
---|
| 2936 | }
|
---|
| 2937 |
|
---|
[065e82] | 2938 | for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
| 2939 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 2940 | }
|
---|
[62bb91] | 2941 |
|
---|
[065e82] | 2942 | delete(connectedPoints);
|
---|
[a2028e] | 2943 |
|
---|
[e138de] | 2944 | Log() << Verbose(2) << "End of GetCircleOfConnectedPoints" << endl;
|
---|
[a2028e] | 2945 |
|
---|
[065e82] | 2946 | return connectedCircle;
|
---|
| 2947 | }
|
---|
[62bb91] | 2948 |
|
---|
[065e82] | 2949 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path.
|
---|
| 2950 | *
|
---|
| 2951 | * @param *out output stream for debugging
|
---|
| 2952 | * @param *Point of which get all connected points
|
---|
| 2953 | * @return list of the all points linked to the provided one
|
---|
| 2954 | */
|
---|
[e138de] | 2955 | list<list<TesselPoint*> *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 2956 | {
|
---|
| 2957 | map<double, TesselPoint*> anglesOfPoints;
|
---|
| 2958 | list<list<TesselPoint*> *> *ListOfPaths = new list<list<TesselPoint*> *>;
|
---|
| 2959 | list<TesselPoint*> *connectedPath = NULL;
|
---|
| 2960 | Vector center;
|
---|
| 2961 | Vector PlaneNormal;
|
---|
| 2962 | Vector AngleZero;
|
---|
| 2963 | Vector OrthogonalVector;
|
---|
| 2964 | Vector helper;
|
---|
| 2965 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
| 2966 | class BoundaryPointSet *CurrentPoint = NULL;
|
---|
| 2967 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 2968 | class BoundaryLineSet *CurrentLine = NULL;
|
---|
| 2969 | class BoundaryLineSet *StartLine = NULL;
|
---|
| 2970 |
|
---|
| 2971 | // find the respective boundary point
|
---|
[776b64] | 2972 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[065e82] | 2973 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 2974 | ReferencePoint = PointRunner->second;
|
---|
| 2975 | } else {
|
---|
[717e0c] | 2976 | eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
|
---|
[065e82] | 2977 | return NULL;
|
---|
| 2978 | }
|
---|
| 2979 |
|
---|
[57066a] | 2980 | map <class BoundaryLineSet *, bool> TouchedLine;
|
---|
| 2981 | map <class BoundaryTriangleSet *, bool> TouchedTriangle;
|
---|
| 2982 | map <class BoundaryLineSet *, bool>::iterator LineRunner;
|
---|
| 2983 | map <class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
|
---|
| 2984 | for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
|
---|
| 2985 | TouchedLine.insert( pair <class BoundaryLineSet *, bool>(Runner->second, false) );
|
---|
| 2986 | for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
|
---|
| 2987 | TouchedTriangle.insert( pair <class BoundaryTriangleSet *, bool>(Sprinter->second, false) );
|
---|
| 2988 | }
|
---|
[065e82] | 2989 | if (!ReferencePoint->lines.empty()) {
|
---|
| 2990 | for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) {
|
---|
[57066a] | 2991 | LineRunner = TouchedLine.find(runner->second);
|
---|
| 2992 | if (LineRunner == TouchedLine.end()) {
|
---|
[717e0c] | 2993 | eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl;
|
---|
[57066a] | 2994 | } else if (!LineRunner->second) {
|
---|
| 2995 | LineRunner->second = true;
|
---|
[065e82] | 2996 | connectedPath = new list<TesselPoint*>;
|
---|
| 2997 | triangle = NULL;
|
---|
| 2998 | CurrentLine = runner->second;
|
---|
| 2999 | StartLine = CurrentLine;
|
---|
| 3000 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
[e138de] | 3001 | Log() << Verbose(3)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
|
---|
[065e82] | 3002 | do {
|
---|
| 3003 | // push current one
|
---|
[e138de] | 3004 | Log() << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
|
---|
[065e82] | 3005 | connectedPath->push_back(CurrentPoint->node);
|
---|
| 3006 |
|
---|
| 3007 | // find next triangle
|
---|
[57066a] | 3008 | for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
|
---|
[e138de] | 3009 | Log() << Verbose(3) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
|
---|
[57066a] | 3010 | if ((Runner->second != triangle)) { // look for first triangle not equal to old one
|
---|
| 3011 | triangle = Runner->second;
|
---|
| 3012 | TriangleRunner = TouchedTriangle.find(triangle);
|
---|
| 3013 | if (TriangleRunner != TouchedTriangle.end()) {
|
---|
| 3014 | if (!TriangleRunner->second) {
|
---|
| 3015 | TriangleRunner->second = true;
|
---|
[e138de] | 3016 | Log() << Verbose(3) << "INFO: Connecting triangle is " << *triangle << "." << endl;
|
---|
[57066a] | 3017 | break;
|
---|
| 3018 | } else {
|
---|
[e138de] | 3019 | Log() << Verbose(3) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
|
---|
[57066a] | 3020 | triangle = NULL;
|
---|
| 3021 | }
|
---|
| 3022 | } else {
|
---|
[717e0c] | 3023 | eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl;
|
---|
[57066a] | 3024 | triangle = NULL;
|
---|
| 3025 | }
|
---|
[065e82] | 3026 | }
|
---|
| 3027 | }
|
---|
[57066a] | 3028 | if (triangle == NULL)
|
---|
| 3029 | break;
|
---|
[065e82] | 3030 | // find next line
|
---|
| 3031 | for (int i=0;i<3;i++) {
|
---|
| 3032 | if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
|
---|
| 3033 | CurrentLine = triangle->lines[i];
|
---|
[e138de] | 3034 | Log() << Verbose(3) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
|
---|
[065e82] | 3035 | break;
|
---|
| 3036 | }
|
---|
| 3037 | }
|
---|
[57066a] | 3038 | LineRunner = TouchedLine.find(CurrentLine);
|
---|
| 3039 | if (LineRunner == TouchedLine.end())
|
---|
[717e0c] | 3040 | eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl;
|
---|
[065e82] | 3041 | else
|
---|
[57066a] | 3042 | LineRunner->second = true;
|
---|
[065e82] | 3043 | // find next point
|
---|
| 3044 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
| 3045 |
|
---|
| 3046 | } while (CurrentLine != StartLine);
|
---|
| 3047 | // last point is missing, as it's on start line
|
---|
[e138de] | 3048 | Log() << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
|
---|
[57066a] | 3049 | if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
|
---|
| 3050 | connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
|
---|
[065e82] | 3051 |
|
---|
| 3052 | ListOfPaths->push_back(connectedPath);
|
---|
| 3053 | } else {
|
---|
[e138de] | 3054 | Log() << Verbose(3) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
|
---|
[065e82] | 3055 | }
|
---|
| 3056 | }
|
---|
| 3057 | } else {
|
---|
[717e0c] | 3058 | eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl;
|
---|
[065e82] | 3059 | }
|
---|
| 3060 |
|
---|
| 3061 | return ListOfPaths;
|
---|
[62bb91] | 3062 | }
|
---|
| 3063 |
|
---|
[065e82] | 3064 | /** Gets all closed paths on the circle of points connected to the provided point by triangulation lines, if this very point is removed.
|
---|
| 3065 | * From GetPathsOfConnectedPoints() extracts all single loops of intracrossing paths in the list of closed paths.
|
---|
| 3066 | * @param *out output stream for debugging
|
---|
| 3067 | * @param *Point of which get all connected points
|
---|
| 3068 | * @return list of the closed paths
|
---|
| 3069 | */
|
---|
[e138de] | 3070 | list<list<TesselPoint*> *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 3071 | {
|
---|
[e138de] | 3072 | list<list<TesselPoint*> *> *ListofPaths = GetPathsOfConnectedPoints(Point);
|
---|
[065e82] | 3073 | list<list<TesselPoint*> *> *ListofClosedPaths = new list<list<TesselPoint*> *>;
|
---|
| 3074 | list<TesselPoint*> *connectedPath = NULL;
|
---|
| 3075 | list<TesselPoint*> *newPath = NULL;
|
---|
| 3076 | int count = 0;
|
---|
| 3077 |
|
---|
| 3078 |
|
---|
| 3079 | list<TesselPoint*>::iterator CircleRunner;
|
---|
| 3080 | list<TesselPoint*>::iterator CircleStart;
|
---|
| 3081 |
|
---|
| 3082 | for(list<list<TesselPoint*> *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
|
---|
| 3083 | connectedPath = *ListRunner;
|
---|
| 3084 |
|
---|
[e138de] | 3085 | Log() << Verbose(2) << "INFO: Current path is " << connectedPath << "." << endl;
|
---|
[065e82] | 3086 |
|
---|
| 3087 | // go through list, look for reappearance of starting Point and count
|
---|
| 3088 | CircleStart = connectedPath->begin();
|
---|
| 3089 |
|
---|
| 3090 | // go through list, look for reappearance of starting Point and create list
|
---|
| 3091 | list<TesselPoint*>::iterator Marker = CircleStart;
|
---|
| 3092 | for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
|
---|
| 3093 | if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
|
---|
| 3094 | // we have a closed circle from Marker to new Marker
|
---|
[e138de] | 3095 | Log() << Verbose(3) << count+1 << ". closed path consists of: ";
|
---|
[065e82] | 3096 | newPath = new list<TesselPoint*>;
|
---|
| 3097 | list<TesselPoint*>::iterator CircleSprinter = Marker;
|
---|
| 3098 | for (; CircleSprinter != CircleRunner; CircleSprinter++) {
|
---|
| 3099 | newPath->push_back(*CircleSprinter);
|
---|
[e138de] | 3100 | Log() << Verbose(0) << (**CircleSprinter) << " <-> ";
|
---|
[065e82] | 3101 | }
|
---|
[e138de] | 3102 | Log() << Verbose(0) << ".." << endl;
|
---|
[065e82] | 3103 | count++;
|
---|
| 3104 | Marker = CircleRunner;
|
---|
| 3105 |
|
---|
| 3106 | // add to list
|
---|
| 3107 | ListofClosedPaths->push_back(newPath);
|
---|
| 3108 | }
|
---|
| 3109 | }
|
---|
| 3110 | }
|
---|
[e138de] | 3111 | Log() << Verbose(3) << "INFO: " << count << " closed additional path(s) have been created." << endl;
|
---|
[065e82] | 3112 |
|
---|
| 3113 | // delete list of paths
|
---|
| 3114 | while (!ListofPaths->empty()) {
|
---|
| 3115 | connectedPath = *(ListofPaths->begin());
|
---|
| 3116 | ListofPaths->remove(connectedPath);
|
---|
| 3117 | delete(connectedPath);
|
---|
| 3118 | }
|
---|
| 3119 | delete(ListofPaths);
|
---|
| 3120 |
|
---|
| 3121 | // exit
|
---|
| 3122 | return ListofClosedPaths;
|
---|
| 3123 | };
|
---|
| 3124 |
|
---|
| 3125 |
|
---|
| 3126 | /** Gets all belonging triangles for a given BoundaryPointSet.
|
---|
| 3127 | * \param *out output stream for debugging
|
---|
| 3128 | * \param *Point BoundaryPoint
|
---|
| 3129 | * \return pointer to allocated list of triangles
|
---|
| 3130 | */
|
---|
[e138de] | 3131 | set<BoundaryTriangleSet*> *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
|
---|
[065e82] | 3132 | {
|
---|
| 3133 | set<BoundaryTriangleSet*> *connectedTriangles = new set<BoundaryTriangleSet*>;
|
---|
| 3134 |
|
---|
| 3135 | if (Point == NULL) {
|
---|
[717e0c] | 3136 | eLog() << Verbose(1) << "Point given is NULL." << endl;
|
---|
[065e82] | 3137 | } else {
|
---|
| 3138 | // go through its lines and insert all triangles
|
---|
[776b64] | 3139 | for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
|
---|
[065e82] | 3140 | for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
| 3141 | connectedTriangles->insert(TriangleRunner->second);
|
---|
| 3142 | }
|
---|
| 3143 | }
|
---|
| 3144 |
|
---|
| 3145 | return connectedTriangles;
|
---|
| 3146 | };
|
---|
| 3147 |
|
---|
| 3148 |
|
---|
[16d866] | 3149 | /** Removes a boundary point from the envelope while keeping it closed.
|
---|
[57066a] | 3150 | * We remove the old triangles connected to the point and re-create new triangles to close the surface following this ansatz:
|
---|
| 3151 | * -# a closed path(s) of boundary points surrounding the point to be removed is constructed
|
---|
| 3152 | * -# on each closed path, we pick three adjacent points, create a triangle with them and subtract the middle point from the path
|
---|
| 3153 | * -# we advance two points (i.e. the next triangle will start at the ending point of the last triangle) and continue as before
|
---|
| 3154 | * -# the surface is closed, when the path is empty
|
---|
| 3155 | * Thereby, we (hopefully) make sure that the removed points remains beneath the surface (this is checked via IsInnerPoint eventually).
|
---|
[16d866] | 3156 | * \param *out output stream for debugging
|
---|
| 3157 | * \param *point point to be removed
|
---|
| 3158 | * \return volume added to the volume inside the tesselated surface by the removal
|
---|
| 3159 | */
|
---|
[e138de] | 3160 | double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) {
|
---|
[16d866] | 3161 | class BoundaryLineSet *line = NULL;
|
---|
| 3162 | class BoundaryTriangleSet *triangle = NULL;
|
---|
[57066a] | 3163 | Vector OldPoint, NormalVector;
|
---|
[16d866] | 3164 | double volume = 0;
|
---|
| 3165 | int count = 0;
|
---|
| 3166 |
|
---|
[1d9b7aa] | 3167 | if (point == NULL) {
|
---|
[717e0c] | 3168 | eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl;
|
---|
[1d9b7aa] | 3169 | return 0.;
|
---|
| 3170 | } else
|
---|
[e138de] | 3171 | Log() << Verbose(2) << "Removing point " << *point << " from tesselated boundary ..." << endl;
|
---|
[1d9b7aa] | 3172 |
|
---|
[16d866] | 3173 | // copy old location for the volume
|
---|
| 3174 | OldPoint.CopyVector(point->node->node);
|
---|
| 3175 |
|
---|
| 3176 | // get list of connected points
|
---|
| 3177 | if (point->lines.empty()) {
|
---|
[717e0c] | 3178 | eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl;
|
---|
[16d866] | 3179 | return 0.;
|
---|
| 3180 | }
|
---|
| 3181 |
|
---|
[e138de] | 3182 | list<list<TesselPoint*> *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
|
---|
[065e82] | 3183 | list<TesselPoint*> *connectedPath = NULL;
|
---|
| 3184 |
|
---|
| 3185 | // gather all triangles
|
---|
[16d866] | 3186 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
|
---|
| 3187 | count+=LineRunner->second->triangles.size();
|
---|
[065e82] | 3188 | map<class BoundaryTriangleSet *, int> Candidates;
|
---|
[57066a] | 3189 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
|
---|
[16d866] | 3190 | line = LineRunner->second;
|
---|
| 3191 | for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
|
---|
| 3192 | triangle = TriangleRunner->second;
|
---|
[065e82] | 3193 | Candidates.insert( pair<class BoundaryTriangleSet *, int> (triangle, triangle->Nr) );
|
---|
[16d866] | 3194 | }
|
---|
| 3195 | }
|
---|
| 3196 |
|
---|
[065e82] | 3197 | // remove all triangles
|
---|
| 3198 | count=0;
|
---|
[57066a] | 3199 | NormalVector.Zero();
|
---|
[065e82] | 3200 | for (map<class BoundaryTriangleSet *, int>::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
|
---|
[e138de] | 3201 | Log() << Verbose(3) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
|
---|
[57066a] | 3202 | NormalVector.SubtractVector(&Runner->first->NormalVector); // has to point inward
|
---|
[065e82] | 3203 | RemoveTesselationTriangle(Runner->first);
|
---|
| 3204 | count++;
|
---|
| 3205 | }
|
---|
[e138de] | 3206 | Log() << Verbose(1) << count << " triangles were removed." << endl;
|
---|
[065e82] | 3207 |
|
---|
| 3208 | list<list<TesselPoint*> *>::iterator ListAdvance = ListOfClosedPaths->begin();
|
---|
| 3209 | list<list<TesselPoint*> *>::iterator ListRunner = ListAdvance;
|
---|
| 3210 | map<class BoundaryTriangleSet *, int>::iterator NumberRunner = Candidates.begin();
|
---|
[57066a] | 3211 | list<TesselPoint*>::iterator StartNode, MiddleNode, EndNode;
|
---|
| 3212 | double angle;
|
---|
| 3213 | double smallestangle;
|
---|
| 3214 | Vector Point, Reference, OrthogonalVector;
|
---|
[065e82] | 3215 | if (count > 2) { // less than three triangles, then nothing will be created
|
---|
| 3216 | class TesselPoint *TriangleCandidates[3];
|
---|
| 3217 | count = 0;
|
---|
| 3218 | for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
|
---|
| 3219 | if (ListAdvance != ListOfClosedPaths->end())
|
---|
| 3220 | ListAdvance++;
|
---|
| 3221 |
|
---|
| 3222 | connectedPath = *ListRunner;
|
---|
| 3223 |
|
---|
| 3224 | // re-create all triangles by going through connected points list
|
---|
[57066a] | 3225 | list<class BoundaryLineSet *> NewLines;
|
---|
| 3226 | for (;!connectedPath->empty();) {
|
---|
| 3227 | // search middle node with widest angle to next neighbours
|
---|
| 3228 | EndNode = connectedPath->end();
|
---|
| 3229 | smallestangle = 0.;
|
---|
| 3230 | for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
|
---|
[e138de] | 3231 | Log() << Verbose(3) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
|
---|
[57066a] | 3232 | // construct vectors to next and previous neighbour
|
---|
| 3233 | StartNode = MiddleNode;
|
---|
| 3234 | if (StartNode == connectedPath->begin())
|
---|
| 3235 | StartNode = connectedPath->end();
|
---|
| 3236 | StartNode--;
|
---|
[e138de] | 3237 | //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl;
|
---|
[57066a] | 3238 | Point.CopyVector((*StartNode)->node);
|
---|
| 3239 | Point.SubtractVector((*MiddleNode)->node);
|
---|
| 3240 | StartNode = MiddleNode;
|
---|
| 3241 | StartNode++;
|
---|
| 3242 | if (StartNode == connectedPath->end())
|
---|
| 3243 | StartNode = connectedPath->begin();
|
---|
[e138de] | 3244 | //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl;
|
---|
[57066a] | 3245 | Reference.CopyVector((*StartNode)->node);
|
---|
| 3246 | Reference.SubtractVector((*MiddleNode)->node);
|
---|
| 3247 | OrthogonalVector.CopyVector((*MiddleNode)->node);
|
---|
| 3248 | OrthogonalVector.SubtractVector(&OldPoint);
|
---|
| 3249 | OrthogonalVector.MakeNormalVector(&Reference);
|
---|
| 3250 | angle = GetAngle(Point, Reference, OrthogonalVector);
|
---|
| 3251 | //if (angle < M_PI) // no wrong-sided triangles, please?
|
---|
| 3252 | if(fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
|
---|
| 3253 | smallestangle = angle;
|
---|
| 3254 | EndNode = MiddleNode;
|
---|
| 3255 | }
|
---|
| 3256 | }
|
---|
| 3257 | MiddleNode = EndNode;
|
---|
| 3258 | if (MiddleNode == connectedPath->end()) {
|
---|
[e138de] | 3259 | Log() << Verbose(1) << "CRITICAL: Could not find a smallest angle!" << endl;
|
---|
[57066a] | 3260 | exit(255);
|
---|
| 3261 | }
|
---|
| 3262 | StartNode = MiddleNode;
|
---|
| 3263 | if (StartNode == connectedPath->begin())
|
---|
| 3264 | StartNode = connectedPath->end();
|
---|
| 3265 | StartNode--;
|
---|
| 3266 | EndNode++;
|
---|
| 3267 | if (EndNode == connectedPath->end())
|
---|
| 3268 | EndNode = connectedPath->begin();
|
---|
[e138de] | 3269 | Log() << Verbose(4) << "INFO: StartNode is " << **StartNode << "." << endl;
|
---|
| 3270 | Log() << Verbose(4) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
|
---|
| 3271 | Log() << Verbose(4) << "INFO: EndNode is " << **EndNode << "." << endl;
|
---|
| 3272 | Log() << Verbose(3) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;
|
---|
[57066a] | 3273 | TriangleCandidates[0] = *StartNode;
|
---|
| 3274 | TriangleCandidates[1] = *MiddleNode;
|
---|
| 3275 | TriangleCandidates[2] = *EndNode;
|
---|
[e138de] | 3276 | triangle = GetPresentTriangle(TriangleCandidates);
|
---|
[57066a] | 3277 | if (triangle != NULL) {
|
---|
[717e0c] | 3278 | eLog() << Verbose(2) << "New triangle already present, skipping!" << endl;
|
---|
[57066a] | 3279 | StartNode++;
|
---|
| 3280 | MiddleNode++;
|
---|
| 3281 | EndNode++;
|
---|
| 3282 | if (StartNode == connectedPath->end())
|
---|
| 3283 | StartNode = connectedPath->begin();
|
---|
| 3284 | if (MiddleNode == connectedPath->end())
|
---|
| 3285 | MiddleNode = connectedPath->begin();
|
---|
| 3286 | if (EndNode == connectedPath->end())
|
---|
| 3287 | EndNode = connectedPath->begin();
|
---|
| 3288 | continue;
|
---|
| 3289 | }
|
---|
[e138de] | 3290 | Log() << Verbose(5) << "Adding new triangle points."<< endl;
|
---|
[57066a] | 3291 | AddTesselationPoint(*StartNode, 0);
|
---|
| 3292 | AddTesselationPoint(*MiddleNode, 1);
|
---|
| 3293 | AddTesselationPoint(*EndNode, 2);
|
---|
[e138de] | 3294 | Log() << Verbose(5) << "Adding new triangle lines."<< endl;
|
---|
[065e82] | 3295 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 3296 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
[57066a] | 3297 | NewLines.push_back(BLS[1]);
|
---|
[065e82] | 3298 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
| 3299 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[57066a] | 3300 | BTS->GetNormalVector(NormalVector);
|
---|
[065e82] | 3301 | AddTesselationTriangle();
|
---|
| 3302 | // calculate volume summand as a general tetraeder
|
---|
[c0f6c6] | 3303 | volume += CalculateVolumeofGeneralTetraeder(*TPS[0]->node->node, *TPS[1]->node->node, *TPS[2]->node->node, OldPoint);
|
---|
[065e82] | 3304 | // advance number
|
---|
| 3305 | count++;
|
---|
[57066a] | 3306 |
|
---|
| 3307 | // prepare nodes for next triangle
|
---|
| 3308 | StartNode = EndNode;
|
---|
[e138de] | 3309 | Log() << Verbose(4) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
|
---|
[57066a] | 3310 | connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
|
---|
| 3311 | if (connectedPath->size() == 2) { // we are done
|
---|
| 3312 | connectedPath->remove(*StartNode); // remove the start node
|
---|
| 3313 | connectedPath->remove(*EndNode); // remove the end node
|
---|
| 3314 | break;
|
---|
| 3315 | } else if (connectedPath->size() < 2) { // something's gone wrong!
|
---|
[e138de] | 3316 | Log() << Verbose(1) << "CRITICAL: There are only two endpoints left!" << endl;
|
---|
[57066a] | 3317 | exit(255);
|
---|
| 3318 | } else {
|
---|
| 3319 | MiddleNode = StartNode;
|
---|
| 3320 | MiddleNode++;
|
---|
| 3321 | if (MiddleNode == connectedPath->end())
|
---|
| 3322 | MiddleNode = connectedPath->begin();
|
---|
| 3323 | EndNode = MiddleNode;
|
---|
| 3324 | EndNode++;
|
---|
| 3325 | if (EndNode == connectedPath->end())
|
---|
| 3326 | EndNode = connectedPath->begin();
|
---|
| 3327 | }
|
---|
[065e82] | 3328 | }
|
---|
[57066a] | 3329 | // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
|
---|
| 3330 | if (NewLines.size() > 1) {
|
---|
| 3331 | list<class BoundaryLineSet *>::iterator Candidate;
|
---|
| 3332 | class BoundaryLineSet *OtherBase = NULL;
|
---|
| 3333 | double tmp, maxgain;
|
---|
| 3334 | do {
|
---|
| 3335 | maxgain = 0;
|
---|
| 3336 | for(list<class BoundaryLineSet *>::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
|
---|
[e138de] | 3337 | tmp = PickFarthestofTwoBaselines(*Runner);
|
---|
[57066a] | 3338 | if (maxgain < tmp) {
|
---|
| 3339 | maxgain = tmp;
|
---|
| 3340 | Candidate = Runner;
|
---|
| 3341 | }
|
---|
| 3342 | }
|
---|
| 3343 | if (maxgain != 0) {
|
---|
| 3344 | volume += maxgain;
|
---|
[e138de] | 3345 | Log() << Verbose(3) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
|
---|
| 3346 | OtherBase = FlipBaseline(*Candidate);
|
---|
[57066a] | 3347 | NewLines.erase(Candidate);
|
---|
| 3348 | NewLines.push_back(OtherBase);
|
---|
| 3349 | }
|
---|
| 3350 | } while (maxgain != 0.);
|
---|
| 3351 | }
|
---|
| 3352 |
|
---|
[065e82] | 3353 | ListOfClosedPaths->remove(connectedPath);
|
---|
| 3354 | delete(connectedPath);
|
---|
[16d866] | 3355 | }
|
---|
[e138de] | 3356 | Log() << Verbose(1) << count << " triangles were created." << endl;
|
---|
[065e82] | 3357 | } else {
|
---|
| 3358 | while (!ListOfClosedPaths->empty()) {
|
---|
| 3359 | ListRunner = ListOfClosedPaths->begin();
|
---|
| 3360 | connectedPath = *ListRunner;
|
---|
| 3361 | ListOfClosedPaths->remove(connectedPath);
|
---|
| 3362 | delete(connectedPath);
|
---|
| 3363 | }
|
---|
[e138de] | 3364 | Log() << Verbose(1) << "No need to create any triangles." << endl;
|
---|
[16d866] | 3365 | }
|
---|
[065e82] | 3366 | delete(ListOfClosedPaths);
|
---|
[16d866] | 3367 |
|
---|
[e138de] | 3368 | Log() << Verbose(1) << "Removed volume is " << volume << "." << endl;
|
---|
[357fba] | 3369 |
|
---|
[57066a] | 3370 | return volume;
|
---|
[357fba] | 3371 | };
|
---|
[ab1932] | 3372 |
|
---|
[5c7bf8] | 3373 |
|
---|
[ab1932] | 3374 |
|
---|
| 3375 | /**
|
---|
[62bb91] | 3376 | * Finds triangles belonging to the three provided points.
|
---|
[ab1932] | 3377 | *
|
---|
[62bb91] | 3378 | * @param *Points[3] list, is expected to contain three points
|
---|
[ab1932] | 3379 | *
|
---|
[62bb91] | 3380 | * @return triangles which belong to the provided points, will be empty if there are none,
|
---|
[ab1932] | 3381 | * will usually be one, in case of degeneration, there will be two
|
---|
| 3382 | */
|
---|
[776b64] | 3383 | list<BoundaryTriangleSet*> *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
|
---|
[ab1932] | 3384 | {
|
---|
| 3385 | list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;
|
---|
[776b64] | 3386 | LineMap::const_iterator FindLine;
|
---|
| 3387 | TriangleMap::const_iterator FindTriangle;
|
---|
[ab1932] | 3388 | class BoundaryPointSet *TrianglePoints[3];
|
---|
| 3389 |
|
---|
| 3390 | for (int i = 0; i < 3; i++) {
|
---|
[776b64] | 3391 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
|
---|
[ab1932] | 3392 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 3393 | TrianglePoints[i] = FindPoint->second;
|
---|
| 3394 | } else {
|
---|
| 3395 | TrianglePoints[i] = NULL;
|
---|
| 3396 | }
|
---|
| 3397 | }
|
---|
| 3398 |
|
---|
| 3399 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 3400 | for (int i = 0; i < 3; i++) {
|
---|
| 3401 | if (TrianglePoints[i] != NULL) {
|
---|
[a2028e] | 3402 | for (int j = i+1; j < 3; j++) {
|
---|
[ab1932] | 3403 | if (TrianglePoints[j] != NULL) {
|
---|
[a2028e] | 3404 | for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
|
---|
| 3405 | (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
|
---|
| 3406 | FindLine++) {
|
---|
| 3407 | for (FindTriangle = FindLine->second->triangles.begin();
|
---|
| 3408 | FindTriangle != FindLine->second->triangles.end();
|
---|
| 3409 | FindTriangle++) {
|
---|
| 3410 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 3411 | result->push_back(FindTriangle->second);
|
---|
[ab1932] | 3412 | }
|
---|
| 3413 | }
|
---|
| 3414 | }
|
---|
[a2028e] | 3415 | // Is it sufficient to consider one of the triangle lines for this.
|
---|
| 3416 | return result;
|
---|
[ab1932] | 3417 | }
|
---|
| 3418 | }
|
---|
| 3419 | }
|
---|
| 3420 | }
|
---|
| 3421 |
|
---|
| 3422 | return result;
|
---|
| 3423 | }
|
---|
| 3424 |
|
---|
[7c14ec] | 3425 | /**
|
---|
[57066a] | 3426 | * Finds all degenerated lines within the tesselation structure.
|
---|
[7c14ec] | 3427 | *
|
---|
[57066a] | 3428 | * @return map of keys of degenerated line pairs, each line occurs twice
|
---|
[7c14ec] | 3429 | * in the list, once as key and once as value
|
---|
| 3430 | */
|
---|
[57066a] | 3431 | map<int, int> * Tesselation::FindAllDegeneratedLines()
|
---|
[7c14ec] | 3432 | {
|
---|
[57066a] | 3433 | map<int, class BoundaryLineSet *> AllLines;
|
---|
| 3434 | map<int, int> * DegeneratedLines = new map<int, int>;
|
---|
[7c14ec] | 3435 |
|
---|
| 3436 | // sanity check
|
---|
| 3437 | if (LinesOnBoundary.empty()) {
|
---|
[e138de] | 3438 | Log() << Verbose(1) << "Warning: FindAllDegeneratedTriangles() was called without any tesselation structure.";
|
---|
[57066a] | 3439 | return DegeneratedLines;
|
---|
[7c14ec] | 3440 | }
|
---|
| 3441 |
|
---|
[57066a] | 3442 | LineMap::iterator LineRunner1;
|
---|
| 3443 | pair<LineMap::iterator, bool> tester;
|
---|
[7c14ec] | 3444 | for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
|
---|
[57066a] | 3445 | tester = AllLines.insert( pair<int,BoundaryLineSet *> (LineRunner1->second->endpoints[0]->Nr, LineRunner1->second) );
|
---|
| 3446 | if ((!tester.second) && (tester.first->second->endpoints[1]->Nr == LineRunner1->second->endpoints[1]->Nr)) { // found degenerated line
|
---|
| 3447 | DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, tester.first->second->Nr) );
|
---|
| 3448 | DegeneratedLines->insert ( pair<int, int> (tester.first->second->Nr, LineRunner1->second->Nr) );
|
---|
| 3449 | }
|
---|
| 3450 | }
|
---|
| 3451 |
|
---|
| 3452 | AllLines.clear();
|
---|
| 3453 |
|
---|
[e138de] | 3454 | Log() << Verbose(1) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
|
---|
[57066a] | 3455 | map<int,int>::iterator it;
|
---|
| 3456 | for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++)
|
---|
[e138de] | 3457 | Log() << Verbose(2) << (*it).first << " => " << (*it).second << endl;
|
---|
[57066a] | 3458 |
|
---|
| 3459 | return DegeneratedLines;
|
---|
| 3460 | }
|
---|
| 3461 |
|
---|
| 3462 | /**
|
---|
| 3463 | * Finds all degenerated triangles within the tesselation structure.
|
---|
| 3464 | *
|
---|
| 3465 | * @return map of keys of degenerated triangle pairs, each triangle occurs twice
|
---|
| 3466 | * in the list, once as key and once as value
|
---|
| 3467 | */
|
---|
| 3468 | map<int, int> * Tesselation::FindAllDegeneratedTriangles()
|
---|
| 3469 | {
|
---|
| 3470 | map<int, int> * DegeneratedLines = FindAllDegeneratedLines();
|
---|
| 3471 | map<int, int> * DegeneratedTriangles = new map<int, int>;
|
---|
| 3472 |
|
---|
| 3473 | TriangleMap::iterator TriangleRunner1, TriangleRunner2;
|
---|
| 3474 | LineMap::iterator Liner;
|
---|
| 3475 | class BoundaryLineSet *line1 = NULL, *line2 = NULL;
|
---|
| 3476 |
|
---|
| 3477 | for (map<int, int>::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
|
---|
| 3478 | // run over both lines' triangles
|
---|
| 3479 | Liner = LinesOnBoundary.find(LineRunner->first);
|
---|
| 3480 | if (Liner != LinesOnBoundary.end())
|
---|
| 3481 | line1 = Liner->second;
|
---|
| 3482 | Liner = LinesOnBoundary.find(LineRunner->second);
|
---|
| 3483 | if (Liner != LinesOnBoundary.end())
|
---|
| 3484 | line2 = Liner->second;
|
---|
| 3485 | for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
|
---|
| 3486 | for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
|
---|
| 3487 | if ((TriangleRunner1->second != TriangleRunner2->second)
|
---|
| 3488 | && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
|
---|
| 3489 | DegeneratedTriangles->insert( pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr) );
|
---|
| 3490 | DegeneratedTriangles->insert( pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr) );
|
---|
[7c14ec] | 3491 | }
|
---|
| 3492 | }
|
---|
| 3493 | }
|
---|
| 3494 | }
|
---|
[57066a] | 3495 | delete(DegeneratedLines);
|
---|
[7c14ec] | 3496 |
|
---|
[e138de] | 3497 | Log() << Verbose(1) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
|
---|
[7c14ec] | 3498 | map<int,int>::iterator it;
|
---|
[57066a] | 3499 | for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
|
---|
[e138de] | 3500 | Log() << Verbose(2) << (*it).first << " => " << (*it).second << endl;
|
---|
[7c14ec] | 3501 |
|
---|
| 3502 | return DegeneratedTriangles;
|
---|
| 3503 | }
|
---|
| 3504 |
|
---|
| 3505 | /**
|
---|
| 3506 | * Purges degenerated triangles from the tesselation structure if they are not
|
---|
| 3507 | * necessary to keep a single point within the structure.
|
---|
| 3508 | */
|
---|
| 3509 | void Tesselation::RemoveDegeneratedTriangles()
|
---|
| 3510 | {
|
---|
[57066a] | 3511 | map<int, int> * DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
| 3512 | TriangleMap::iterator finder;
|
---|
| 3513 | BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
|
---|
| 3514 | int count = 0;
|
---|
[7c14ec] | 3515 |
|
---|
[e138de] | 3516 | Log() << Verbose(1) << "Begin of RemoveDegeneratedTriangles" << endl;
|
---|
[7dea7c] | 3517 |
|
---|
[57066a] | 3518 | for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
|
---|
| 3519 | TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
|
---|
[7c14ec] | 3520 | ) {
|
---|
[57066a] | 3521 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
|
---|
| 3522 | if (finder != TrianglesOnBoundary.end())
|
---|
| 3523 | triangle = finder->second;
|
---|
| 3524 | else
|
---|
| 3525 | break;
|
---|
| 3526 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->second);
|
---|
| 3527 | if (finder != TrianglesOnBoundary.end())
|
---|
| 3528 | partnerTriangle = finder->second;
|
---|
| 3529 | else
|
---|
| 3530 | break;
|
---|
[7c14ec] | 3531 |
|
---|
| 3532 | bool trianglesShareLine = false;
|
---|
| 3533 | for (int i = 0; i < 3; ++i)
|
---|
| 3534 | for (int j = 0; j < 3; ++j)
|
---|
| 3535 | trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
|
---|
| 3536 |
|
---|
| 3537 | if (trianglesShareLine
|
---|
| 3538 | && (triangle->endpoints[1]->LinesCount > 2)
|
---|
| 3539 | && (triangle->endpoints[2]->LinesCount > 2)
|
---|
| 3540 | && (triangle->endpoints[0]->LinesCount > 2)
|
---|
| 3541 | ) {
|
---|
[57066a] | 3542 | // check whether we have to fix lines
|
---|
| 3543 | BoundaryTriangleSet *Othertriangle = NULL;
|
---|
| 3544 | BoundaryTriangleSet *OtherpartnerTriangle = NULL;
|
---|
| 3545 | TriangleMap::iterator TriangleRunner;
|
---|
| 3546 | for (int i = 0; i < 3; ++i)
|
---|
| 3547 | for (int j = 0; j < 3; ++j)
|
---|
| 3548 | if (triangle->lines[i] != partnerTriangle->lines[j]) {
|
---|
| 3549 | // get the other two triangles
|
---|
| 3550 | for (TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 3551 | if (TriangleRunner->second != triangle) {
|
---|
| 3552 | Othertriangle = TriangleRunner->second;
|
---|
| 3553 | }
|
---|
| 3554 | for (TriangleRunner = partnerTriangle->lines[i]->triangles.begin(); TriangleRunner != partnerTriangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 3555 | if (TriangleRunner->second != partnerTriangle) {
|
---|
| 3556 | OtherpartnerTriangle = TriangleRunner->second;
|
---|
| 3557 | }
|
---|
| 3558 | /// interchanges their lines so that triangle->lines[i] == partnerTriangle->lines[j]
|
---|
| 3559 | // the line of triangle receives the degenerated ones
|
---|
| 3560 | triangle->lines[i]->triangles.erase(Othertriangle->Nr);
|
---|
| 3561 | triangle->lines[i]->triangles.insert( TrianglePair( partnerTriangle->Nr, partnerTriangle) );
|
---|
| 3562 | for (int k=0;k<3;k++)
|
---|
| 3563 | if (triangle->lines[i] == Othertriangle->lines[k]) {
|
---|
| 3564 | Othertriangle->lines[k] = partnerTriangle->lines[j];
|
---|
| 3565 | break;
|
---|
| 3566 | }
|
---|
| 3567 | // the line of partnerTriangle receives the non-degenerated ones
|
---|
| 3568 | partnerTriangle->lines[j]->triangles.erase( partnerTriangle->Nr);
|
---|
| 3569 | partnerTriangle->lines[j]->triangles.insert( TrianglePair( Othertriangle->Nr, Othertriangle) );
|
---|
| 3570 | partnerTriangle->lines[j] = triangle->lines[i];
|
---|
| 3571 | }
|
---|
| 3572 |
|
---|
| 3573 | // erase the pair
|
---|
| 3574 | count += (int) DegeneratedTriangles->erase(triangle->Nr);
|
---|
[e138de] | 3575 | Log() << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
|
---|
[7c14ec] | 3576 | RemoveTesselationTriangle(triangle);
|
---|
[57066a] | 3577 | count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
|
---|
[e138de] | 3578 | Log() << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
|
---|
[7c14ec] | 3579 | RemoveTesselationTriangle(partnerTriangle);
|
---|
| 3580 | } else {
|
---|
[e138de] | 3581 | Log() << Verbose(1) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
|
---|
[7c14ec] | 3582 | << " and its partner " << *partnerTriangle << " because it is essential for at"
|
---|
| 3583 | << " least one of the endpoints to be kept in the tesselation structure." << endl;
|
---|
| 3584 | }
|
---|
| 3585 | }
|
---|
[57066a] | 3586 | delete(DegeneratedTriangles);
|
---|
[6a7f78c] | 3587 | if (count > 0)
|
---|
| 3588 | LastTriangle = NULL;
|
---|
[57066a] | 3589 |
|
---|
[e138de] | 3590 | Log() << Verbose(1) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
|
---|
| 3591 | Log() << Verbose(1) << "End of RemoveDegeneratedTriangles" << endl;
|
---|
[7c14ec] | 3592 | }
|
---|
| 3593 |
|
---|
[57066a] | 3594 | /** Adds an outside Tesselpoint to the envelope via (two) degenerated triangles.
|
---|
| 3595 | * We look for the closest point on the boundary, we look through its connected boundary lines and
|
---|
| 3596 | * seek the one with the minimum angle between its center point and the new point and this base line.
|
---|
| 3597 | * We open up the line by adding a degenerated triangle, whose other side closes the base line again.
|
---|
| 3598 | * \param *out output stream for debugging
|
---|
| 3599 | * \param *point point to add
|
---|
| 3600 | * \param *LC Linked Cell structure to find nearest point
|
---|
[ab1932] | 3601 | */
|
---|
[e138de] | 3602 | void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
|
---|
[ab1932] | 3603 | {
|
---|
[e138de] | 3604 | Log() << Verbose(2) << "Begin of AddBoundaryPointByDegeneratedTriangle" << endl;
|
---|
[ab1932] | 3605 |
|
---|
[57066a] | 3606 | // find nearest boundary point
|
---|
| 3607 | class TesselPoint *BackupPoint = NULL;
|
---|
| 3608 | class TesselPoint *NearestPoint = FindClosestPoint(point->node, BackupPoint, LC);
|
---|
| 3609 | class BoundaryPointSet *NearestBoundaryPoint = NULL;
|
---|
| 3610 | PointMap::iterator PointRunner;
|
---|
| 3611 |
|
---|
| 3612 | if (NearestPoint == point)
|
---|
| 3613 | NearestPoint = BackupPoint;
|
---|
| 3614 | PointRunner = PointsOnBoundary.find(NearestPoint->nr);
|
---|
| 3615 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 3616 | NearestBoundaryPoint = PointRunner->second;
|
---|
| 3617 | } else {
|
---|
[717e0c] | 3618 | eLog() << Verbose(1) << "I cannot find the boundary point." << endl;
|
---|
[57066a] | 3619 | return;
|
---|
| 3620 | }
|
---|
[e138de] | 3621 | Log() << Verbose(2) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
|
---|
[57066a] | 3622 |
|
---|
| 3623 | // go through its lines and find the best one to split
|
---|
| 3624 | Vector CenterToPoint;
|
---|
| 3625 | Vector BaseLine;
|
---|
| 3626 | double angle, BestAngle = 0.;
|
---|
| 3627 | class BoundaryLineSet *BestLine = NULL;
|
---|
| 3628 | for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
|
---|
| 3629 | BaseLine.CopyVector(Runner->second->endpoints[0]->node->node);
|
---|
| 3630 | BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node);
|
---|
| 3631 | CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node);
|
---|
| 3632 | CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node);
|
---|
| 3633 | CenterToPoint.Scale(0.5);
|
---|
| 3634 | CenterToPoint.SubtractVector(point->node);
|
---|
| 3635 | angle = CenterToPoint.Angle(&BaseLine);
|
---|
| 3636 | if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
|
---|
| 3637 | BestAngle = angle;
|
---|
| 3638 | BestLine = Runner->second;
|
---|
| 3639 | }
|
---|
[ab1932] | 3640 | }
|
---|
| 3641 |
|
---|
[57066a] | 3642 | // remove one triangle from the chosen line
|
---|
| 3643 | class BoundaryTriangleSet *TempTriangle = (BestLine->triangles.begin())->second;
|
---|
| 3644 | BestLine->triangles.erase(TempTriangle->Nr);
|
---|
| 3645 | int nr = -1;
|
---|
| 3646 | for (int i=0;i<3; i++) {
|
---|
| 3647 | if (TempTriangle->lines[i] == BestLine) {
|
---|
| 3648 | nr = i;
|
---|
| 3649 | break;
|
---|
| 3650 | }
|
---|
| 3651 | }
|
---|
[ab1932] | 3652 |
|
---|
[57066a] | 3653 | // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
|
---|
[e138de] | 3654 | Log() << Verbose(5) << "Adding new triangle points."<< endl;
|
---|
[57066a] | 3655 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 3656 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 3657 | AddTesselationPoint(point, 2);
|
---|
[e138de] | 3658 | Log() << Verbose(5) << "Adding new triangle lines."<< endl;
|
---|
[57066a] | 3659 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 3660 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
| 3661 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
| 3662 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 3663 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
| 3664 | BTS->NormalVector.Scale(-1.);
|
---|
[e138de] | 3665 | Log() << Verbose(3) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
|
---|
[57066a] | 3666 | AddTesselationTriangle();
|
---|
| 3667 |
|
---|
| 3668 | // create other side of this triangle and close both new sides of the first created triangle
|
---|
[e138de] | 3669 | Log() << Verbose(5) << "Adding new triangle points."<< endl;
|
---|
[57066a] | 3670 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 3671 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 3672 | AddTesselationPoint(point, 2);
|
---|
[e138de] | 3673 | Log() << Verbose(5) << "Adding new triangle lines."<< endl;
|
---|
[57066a] | 3674 | AddTesselationLine(TPS[0], TPS[1], 0);
|
---|
| 3675 | AddTesselationLine(TPS[0], TPS[2], 1);
|
---|
| 3676 | AddTesselationLine(TPS[1], TPS[2], 2);
|
---|
| 3677 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 3678 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
[e138de] | 3679 | Log() << Verbose(3) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
|
---|
[57066a] | 3680 | AddTesselationTriangle();
|
---|
| 3681 |
|
---|
| 3682 | // add removed triangle to the last open line of the second triangle
|
---|
| 3683 | for (int i=0;i<3;i++) { // look for the same line as BestLine (only it's its degenerated companion)
|
---|
| 3684 | if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
|
---|
| 3685 | if (BestLine == BTS->lines[i]){
|
---|
[e138de] | 3686 | Log() << Verbose(1) << "CRITICAL: BestLine is same as found line, something's wrong here!" << endl;
|
---|
[57066a] | 3687 | exit(255);
|
---|
| 3688 | }
|
---|
| 3689 | BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle) );
|
---|
| 3690 | TempTriangle->lines[nr] = BTS->lines[i];
|
---|
| 3691 | break;
|
---|
| 3692 | }
|
---|
| 3693 | }
|
---|
[ab1932] | 3694 |
|
---|
[57066a] | 3695 | // exit
|
---|
[e138de] | 3696 | Log() << Verbose(2) << "End of AddBoundaryPointByDegeneratedTriangle" << endl;
|
---|
[57066a] | 3697 | };
|
---|
| 3698 |
|
---|
| 3699 | /** Writes the envelope to file.
|
---|
| 3700 | * \param *out otuput stream for debugging
|
---|
| 3701 | * \param *filename basename of output file
|
---|
| 3702 | * \param *cloud PointCloud structure with all nodes
|
---|
| 3703 | */
|
---|
[e138de] | 3704 | void Tesselation::Output(const char *filename, const PointCloud * const cloud)
|
---|
[57066a] | 3705 | {
|
---|
| 3706 | ofstream *tempstream = NULL;
|
---|
| 3707 | string NameofTempFile;
|
---|
| 3708 | char NumberName[255];
|
---|
| 3709 |
|
---|
| 3710 | if (LastTriangle != NULL) {
|
---|
| 3711 | sprintf(NumberName, "-%04d-%s_%s_%s", (int)TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);
|
---|
| 3712 | if (DoTecplotOutput) {
|
---|
| 3713 | string NameofTempFile(filename);
|
---|
| 3714 | NameofTempFile.append(NumberName);
|
---|
| 3715 | for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 3716 | NameofTempFile.erase(npos, 1);
|
---|
| 3717 | NameofTempFile.append(TecplotSuffix);
|
---|
[e138de] | 3718 | Log() << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
|
---|
[57066a] | 3719 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 3720 | WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
|
---|
[57066a] | 3721 | tempstream->close();
|
---|
| 3722 | tempstream->flush();
|
---|
| 3723 | delete(tempstream);
|
---|
| 3724 | }
|
---|
| 3725 |
|
---|
| 3726 | if (DoRaster3DOutput) {
|
---|
| 3727 | string NameofTempFile(filename);
|
---|
| 3728 | NameofTempFile.append(NumberName);
|
---|
| 3729 | for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 3730 | NameofTempFile.erase(npos, 1);
|
---|
| 3731 | NameofTempFile.append(Raster3DSuffix);
|
---|
[e138de] | 3732 | Log() << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
|
---|
[57066a] | 3733 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 3734 | WriteRaster3dFile(tempstream, this, cloud);
|
---|
| 3735 | IncludeSphereinRaster3D(tempstream, this, cloud);
|
---|
[57066a] | 3736 | tempstream->close();
|
---|
| 3737 | tempstream->flush();
|
---|
| 3738 | delete(tempstream);
|
---|
| 3739 | }
|
---|
| 3740 | }
|
---|
| 3741 | if (DoTecplotOutput || DoRaster3DOutput)
|
---|
| 3742 | TriangleFilesWritten++;
|
---|
| 3743 | };
|
---|