[357fba] | 1 | /*
|
---|
| 2 | * tesselation.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 3, 2009
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[f66195] | 10 | #include <fstream>
|
---|
| 11 |
|
---|
[a2028e] | 12 | #include "helpers.hpp"
|
---|
[f67b6e] | 13 | #include "info.hpp"
|
---|
[57066a] | 14 | #include "linkedcell.hpp"
|
---|
[e138de] | 15 | #include "log.hpp"
|
---|
[357fba] | 16 | #include "tesselation.hpp"
|
---|
[57066a] | 17 | #include "tesselationhelpers.hpp"
|
---|
[8db598] | 18 | #include "triangleintersectionlist.hpp"
|
---|
[57066a] | 19 | #include "vector.hpp"
|
---|
[643e76] | 20 | #include "Line.hpp"
|
---|
[0a4f7f] | 21 | #include "vector_ops.hpp"
|
---|
[f66195] | 22 | #include "verbose.hpp"
|
---|
[0a4f7f] | 23 | #include "Plane.hpp"
|
---|
| 24 | #include "Exceptions/LinearDependenceException.hpp"
|
---|
[d4c9ae] | 25 | #include "Helpers/Assert.hpp"
|
---|
[57066a] | 26 |
|
---|
| 27 | class molecule;
|
---|
[357fba] | 28 |
|
---|
| 29 | // ======================================== Points on Boundary =================================
|
---|
| 30 |
|
---|
[16d866] | 31 | /** Constructor of BoundaryPointSet.
|
---|
| 32 | */
|
---|
[1e168b] | 33 | BoundaryPointSet::BoundaryPointSet() :
|
---|
[6613ec] | 34 | LinesCount(0), value(0.), Nr(-1)
|
---|
[357fba] | 35 | {
|
---|
[6613ec] | 36 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 37 | DoLog(1) && (Log() << Verbose(1) << "Adding noname." << endl);
|
---|
[6613ec] | 38 | }
|
---|
| 39 | ;
|
---|
[357fba] | 40 |
|
---|
[16d866] | 41 | /** Constructor of BoundaryPointSet with Tesselpoint.
|
---|
| 42 | * \param *Walker TesselPoint this boundary point represents
|
---|
| 43 | */
|
---|
[9473f6] | 44 | BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) :
|
---|
[6613ec] | 45 | LinesCount(0), node(Walker), value(0.), Nr(Walker->nr)
|
---|
[357fba] | 46 | {
|
---|
[6613ec] | 47 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 48 | DoLog(1) && (Log() << Verbose(1) << "Adding Node " << *Walker << endl);
|
---|
[6613ec] | 49 | }
|
---|
| 50 | ;
|
---|
[357fba] | 51 |
|
---|
[16d866] | 52 | /** Destructor of BoundaryPointSet.
|
---|
| 53 | * Sets node to NULL to avoid removing the original, represented TesselPoint.
|
---|
| 54 | * \note When removing point from a class Tesselation, use RemoveTesselationPoint()
|
---|
| 55 | */
|
---|
[357fba] | 56 | BoundaryPointSet::~BoundaryPointSet()
|
---|
| 57 | {
|
---|
[6613ec] | 58 | Info FunctionInfo(__func__);
|
---|
[f67b6e] | 59 | //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
|
---|
[357fba] | 60 | if (!lines.empty())
|
---|
[6613ec] | 61 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);
|
---|
[357fba] | 62 | node = NULL;
|
---|
[6613ec] | 63 | }
|
---|
| 64 | ;
|
---|
[357fba] | 65 |
|
---|
[16d866] | 66 | /** Add a line to the LineMap of this point.
|
---|
| 67 | * \param *line line to add
|
---|
| 68 | */
|
---|
[9473f6] | 69 | void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
|
---|
[357fba] | 70 | {
|
---|
[6613ec] | 71 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 72 | DoLog(1) && (Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl);
|
---|
[6613ec] | 73 | if (line->endpoints[0] == this) {
|
---|
| 74 | lines.insert(LinePair(line->endpoints[1]->Nr, line));
|
---|
| 75 | } else {
|
---|
| 76 | lines.insert(LinePair(line->endpoints[0]->Nr, line));
|
---|
| 77 | }
|
---|
[357fba] | 78 | LinesCount++;
|
---|
[6613ec] | 79 | }
|
---|
| 80 | ;
|
---|
[357fba] | 81 |
|
---|
[16d866] | 82 | /** output operator for BoundaryPointSet.
|
---|
| 83 | * \param &ost output stream
|
---|
| 84 | * \param &a boundary point
|
---|
| 85 | */
|
---|
[776b64] | 86 | ostream & operator <<(ostream &ost, const BoundaryPointSet &a)
|
---|
[357fba] | 87 | {
|
---|
[68f03d] | 88 | ost << "[" << a.Nr << "|" << a.node->getName() << " at " << *a.node->node << "]";
|
---|
[357fba] | 89 | return ost;
|
---|
| 90 | }
|
---|
| 91 | ;
|
---|
| 92 |
|
---|
| 93 | // ======================================== Lines on Boundary =================================
|
---|
| 94 |
|
---|
[16d866] | 95 | /** Constructor of BoundaryLineSet.
|
---|
| 96 | */
|
---|
[1e168b] | 97 | BoundaryLineSet::BoundaryLineSet() :
|
---|
[6613ec] | 98 | Nr(-1)
|
---|
[357fba] | 99 | {
|
---|
[6613ec] | 100 | Info FunctionInfo(__func__);
|
---|
[357fba] | 101 | for (int i = 0; i < 2; i++)
|
---|
| 102 | endpoints[i] = NULL;
|
---|
[6613ec] | 103 | }
|
---|
| 104 | ;
|
---|
[357fba] | 105 |
|
---|
[16d866] | 106 | /** Constructor of BoundaryLineSet with two endpoints.
|
---|
| 107 | * Adds line automatically to each endpoints' LineMap
|
---|
| 108 | * \param *Point[2] array of two boundary points
|
---|
| 109 | * \param number number of the list
|
---|
| 110 | */
|
---|
[9473f6] | 111 | BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
|
---|
[357fba] | 112 | {
|
---|
[6613ec] | 113 | Info FunctionInfo(__func__);
|
---|
[357fba] | 114 | // set number
|
---|
| 115 | Nr = number;
|
---|
| 116 | // set endpoints in ascending order
|
---|
| 117 | SetEndpointsOrdered(endpoints, Point[0], Point[1]);
|
---|
| 118 | // add this line to the hash maps of both endpoints
|
---|
| 119 | Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
|
---|
| 120 | Point[1]->AddLine(this); //
|
---|
[1e168b] | 121 | // set skipped to false
|
---|
| 122 | skipped = false;
|
---|
[357fba] | 123 | // clear triangles list
|
---|
[a67d19] | 124 | DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
|
---|
[6613ec] | 125 | }
|
---|
| 126 | ;
|
---|
[357fba] | 127 |
|
---|
[9473f6] | 128 | /** Constructor of BoundaryLineSet with two endpoints.
|
---|
| 129 | * Adds line automatically to each endpoints' LineMap
|
---|
| 130 | * \param *Point1 first boundary point
|
---|
| 131 | * \param *Point2 second boundary point
|
---|
| 132 | * \param number number of the list
|
---|
| 133 | */
|
---|
| 134 | BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number)
|
---|
| 135 | {
|
---|
| 136 | Info FunctionInfo(__func__);
|
---|
| 137 | // set number
|
---|
| 138 | Nr = number;
|
---|
| 139 | // set endpoints in ascending order
|
---|
| 140 | SetEndpointsOrdered(endpoints, Point1, Point2);
|
---|
| 141 | // add this line to the hash maps of both endpoints
|
---|
| 142 | Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
|
---|
| 143 | Point2->AddLine(this); //
|
---|
| 144 | // set skipped to false
|
---|
| 145 | skipped = false;
|
---|
| 146 | // clear triangles list
|
---|
[a67d19] | 147 | DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
|
---|
[6613ec] | 148 | }
|
---|
| 149 | ;
|
---|
[9473f6] | 150 |
|
---|
[16d866] | 151 | /** Destructor for BoundaryLineSet.
|
---|
| 152 | * Removes itself from each endpoints' LineMap, calling RemoveTrianglePoint() when point not connected anymore.
|
---|
| 153 | * \note When removing lines from a class Tesselation, use RemoveTesselationLine()
|
---|
| 154 | */
|
---|
[357fba] | 155 | BoundaryLineSet::~BoundaryLineSet()
|
---|
| 156 | {
|
---|
[6613ec] | 157 | Info FunctionInfo(__func__);
|
---|
[357fba] | 158 | int Numbers[2];
|
---|
[16d866] | 159 |
|
---|
| 160 | // get other endpoint number of finding copies of same line
|
---|
| 161 | if (endpoints[1] != NULL)
|
---|
| 162 | Numbers[0] = endpoints[1]->Nr;
|
---|
| 163 | else
|
---|
| 164 | Numbers[0] = -1;
|
---|
| 165 | if (endpoints[0] != NULL)
|
---|
| 166 | Numbers[1] = endpoints[0]->Nr;
|
---|
| 167 | else
|
---|
| 168 | Numbers[1] = -1;
|
---|
| 169 |
|
---|
[357fba] | 170 | for (int i = 0; i < 2; i++) {
|
---|
[16d866] | 171 | if (endpoints[i] != NULL) {
|
---|
| 172 | 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
|
---|
| 173 | pair<LineMap::iterator, LineMap::iterator> erasor = endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 174 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 175 | if ((*Runner).second == this) {
|
---|
[f67b6e] | 176 | //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[16d866] | 177 | endpoints[i]->lines.erase(Runner);
|
---|
| 178 | break;
|
---|
| 179 | }
|
---|
| 180 | } else { // there's just a single line left
|
---|
[57066a] | 181 | if (endpoints[i]->lines.erase(Nr)) {
|
---|
[f67b6e] | 182 | //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
---|
[57066a] | 183 | }
|
---|
[357fba] | 184 | }
|
---|
[16d866] | 185 | if (endpoints[i]->lines.empty()) {
|
---|
[f67b6e] | 186 | //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
|
---|
[16d866] | 187 | if (endpoints[i] != NULL) {
|
---|
[6613ec] | 188 | delete (endpoints[i]);
|
---|
[16d866] | 189 | endpoints[i] = NULL;
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 | }
|
---|
[357fba] | 193 | }
|
---|
| 194 | if (!triangles.empty())
|
---|
[6613ec] | 195 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
|
---|
| 196 | }
|
---|
| 197 | ;
|
---|
[357fba] | 198 |
|
---|
[16d866] | 199 | /** Add triangle to TriangleMap of this boundary line.
|
---|
| 200 | * \param *triangle to add
|
---|
| 201 | */
|
---|
[9473f6] | 202 | void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
|
---|
[357fba] | 203 | {
|
---|
[6613ec] | 204 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 205 | DoLog(0) && (Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl);
|
---|
[357fba] | 206 | triangles.insert(TrianglePair(triangle->Nr, triangle));
|
---|
[6613ec] | 207 | }
|
---|
| 208 | ;
|
---|
[357fba] | 209 |
|
---|
| 210 | /** Checks whether we have a common endpoint with given \a *line.
|
---|
| 211 | * \param *line other line to test
|
---|
| 212 | * \return true - common endpoint present, false - not connected
|
---|
| 213 | */
|
---|
[9473f6] | 214 | bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
|
---|
[357fba] | 215 | {
|
---|
[6613ec] | 216 | Info FunctionInfo(__func__);
|
---|
[357fba] | 217 | if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
|
---|
| 218 | return true;
|
---|
| 219 | else
|
---|
| 220 | return false;
|
---|
[6613ec] | 221 | }
|
---|
| 222 | ;
|
---|
[357fba] | 223 |
|
---|
| 224 | /** Checks whether the adjacent triangles of a baseline are convex or not.
|
---|
[57066a] | 225 | * We sum the two angles of each height vector with respect to the center of the baseline.
|
---|
[357fba] | 226 | * If greater/equal M_PI than we are convex.
|
---|
| 227 | * \param *out output stream for debugging
|
---|
| 228 | * \return true - triangles are convex, false - concave or less than two triangles connected
|
---|
| 229 | */
|
---|
[9473f6] | 230 | bool BoundaryLineSet::CheckConvexityCriterion() const
|
---|
[b32dbb] | 231 | {
|
---|
| 232 | Info FunctionInfo(__func__);
|
---|
| 233 | double angle = CalculateConvexity();
|
---|
| 234 | if (angle > -MYEPSILON) {
|
---|
| 235 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
|
---|
| 236 | return true;
|
---|
| 237 | } else {
|
---|
| 238 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
|
---|
| 239 | return false;
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 |
|
---|
| 244 | /** Calculates the angle between two triangles with respect to their normal vector.
|
---|
| 245 | * We sum the two angles of each height vector with respect to the center of the baseline.
|
---|
| 246 | * \return angle > 0 then convex, if < 0 then concave
|
---|
| 247 | */
|
---|
| 248 | double BoundaryLineSet::CalculateConvexity() const
|
---|
[357fba] | 249 | {
|
---|
[6613ec] | 250 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 251 | Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
|
---|
[357fba] | 252 | // get the two triangles
|
---|
[5c7bf8] | 253 | if (triangles.size() != 2) {
|
---|
[6613ec] | 254 | DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
|
---|
[1d9b7aa] | 255 | return true;
|
---|
[357fba] | 256 | }
|
---|
[5c7bf8] | 257 | // check normal vectors
|
---|
[357fba] | 258 | // have a normal vector on the base line pointing outwards
|
---|
[f67b6e] | 259 | //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
|
---|
[273382] | 260 | BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node));
|
---|
| 261 | BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node);
|
---|
[8cbb97] | 262 |
|
---|
[f67b6e] | 263 | //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
|
---|
[357fba] | 264 |
|
---|
[62bb91] | 265 | BaseLineNormal.Zero();
|
---|
[5c7bf8] | 266 | NormalCheck.Zero();
|
---|
| 267 | double sign = -1.;
|
---|
[6613ec] | 268 | int i = 0;
|
---|
[62bb91] | 269 | class BoundaryPointSet *node = NULL;
|
---|
[6613ec] | 270 | for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
|
---|
[f67b6e] | 271 | //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
|
---|
[273382] | 272 | NormalCheck += runner->second->NormalVector;
|
---|
| 273 | NormalCheck *= sign;
|
---|
[5c7bf8] | 274 | sign = -sign;
|
---|
[57066a] | 275 | if (runner->second->NormalVector.NormSquared() > MYEPSILON)
|
---|
[273382] | 276 | BaseLineNormal = runner->second->NormalVector; // yes, copy second on top of first
|
---|
[57066a] | 277 | else {
|
---|
[6613ec] | 278 | DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
|
---|
[57066a] | 279 | }
|
---|
[62bb91] | 280 | node = runner->second->GetThirdEndpoint(this);
|
---|
| 281 | if (node != NULL) {
|
---|
[f67b6e] | 282 | //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
|
---|
[273382] | 283 | helper[i] = (*node->node->node) - BaseLineCenter;
|
---|
[0a4f7f] | 284 | helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles!
|
---|
[f67b6e] | 285 | //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
|
---|
[62bb91] | 286 | i++;
|
---|
| 287 | } else {
|
---|
[6613ec] | 288 | DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
|
---|
[62bb91] | 289 | return true;
|
---|
| 290 | }
|
---|
| 291 | }
|
---|
[f67b6e] | 292 | //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
|
---|
[5c7bf8] | 293 | if (NormalCheck.NormSquared() < MYEPSILON) {
|
---|
[a67d19] | 294 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl);
|
---|
[5c7bf8] | 295 | return true;
|
---|
[62bb91] | 296 | }
|
---|
[57066a] | 297 | BaseLineNormal.Scale(-1.);
|
---|
[f1cccd] | 298 | double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
|
---|
[b32dbb] | 299 | return (angle - M_PI);
|
---|
[357fba] | 300 | }
|
---|
| 301 |
|
---|
| 302 | /** Checks whether point is any of the two endpoints this line contains.
|
---|
| 303 | * \param *point point to test
|
---|
| 304 | * \return true - point is of the line, false - is not
|
---|
| 305 | */
|
---|
[9473f6] | 306 | bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
[357fba] | 307 | {
|
---|
[6613ec] | 308 | Info FunctionInfo(__func__);
|
---|
| 309 | for (int i = 0; i < 2; i++)
|
---|
[357fba] | 310 | if (point == endpoints[i])
|
---|
| 311 | return true;
|
---|
| 312 | return false;
|
---|
[6613ec] | 313 | }
|
---|
| 314 | ;
|
---|
[357fba] | 315 |
|
---|
[62bb91] | 316 | /** Returns other endpoint of the line.
|
---|
| 317 | * \param *point other endpoint
|
---|
[b32dbb] | 318 | * \return NULL - if endpoint not contained in BoundaryLineSet::lines, or pointer to BoundaryPointSet otherwise
|
---|
[62bb91] | 319 | */
|
---|
[9473f6] | 320 | class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
|
---|
[62bb91] | 321 | {
|
---|
[6613ec] | 322 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 323 | if (endpoints[0] == point)
|
---|
| 324 | return endpoints[1];
|
---|
| 325 | else if (endpoints[1] == point)
|
---|
| 326 | return endpoints[0];
|
---|
| 327 | else
|
---|
| 328 | return NULL;
|
---|
[6613ec] | 329 | }
|
---|
| 330 | ;
|
---|
[62bb91] | 331 |
|
---|
[b32dbb] | 332 | /** Returns other triangle of the line.
|
---|
| 333 | * \param *point other endpoint
|
---|
| 334 | * \return NULL - if triangle not contained in BoundaryLineSet::triangles, or pointer to BoundaryTriangleSet otherwise
|
---|
| 335 | */
|
---|
| 336 | class BoundaryTriangleSet *BoundaryLineSet::GetOtherTriangle(const BoundaryTriangleSet * const triangle) const
|
---|
| 337 | {
|
---|
| 338 | Info FunctionInfo(__func__);
|
---|
| 339 | if (triangles.size() == 2) {
|
---|
| 340 | for (TriangleMap::const_iterator TriangleRunner = triangles.begin(); TriangleRunner != triangles.end(); ++TriangleRunner)
|
---|
| 341 | if (TriangleRunner->second != triangle)
|
---|
| 342 | return TriangleRunner->second;
|
---|
| 343 | }
|
---|
| 344 | return NULL;
|
---|
| 345 | }
|
---|
| 346 | ;
|
---|
| 347 |
|
---|
[16d866] | 348 | /** output operator for BoundaryLineSet.
|
---|
| 349 | * \param &ost output stream
|
---|
| 350 | * \param &a boundary line
|
---|
| 351 | */
|
---|
[6613ec] | 352 | ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
|
---|
[357fba] | 353 | {
|
---|
[68f03d] | 354 | ost << "[" << a.Nr << "|" << a.endpoints[0]->node->getName() << " at " << *a.endpoints[0]->node->node << "," << a.endpoints[1]->node->getName() << " at " << *a.endpoints[1]->node->node << "]";
|
---|
[357fba] | 355 | return ost;
|
---|
[6613ec] | 356 | }
|
---|
| 357 | ;
|
---|
[357fba] | 358 |
|
---|
| 359 | // ======================================== Triangles on Boundary =================================
|
---|
| 360 |
|
---|
[16d866] | 361 | /** Constructor for BoundaryTriangleSet.
|
---|
| 362 | */
|
---|
[1e168b] | 363 | BoundaryTriangleSet::BoundaryTriangleSet() :
|
---|
| 364 | Nr(-1)
|
---|
[357fba] | 365 | {
|
---|
[6613ec] | 366 | Info FunctionInfo(__func__);
|
---|
| 367 | for (int i = 0; i < 3; i++) {
|
---|
| 368 | endpoints[i] = NULL;
|
---|
| 369 | lines[i] = NULL;
|
---|
| 370 | }
|
---|
| 371 | }
|
---|
| 372 | ;
|
---|
[357fba] | 373 |
|
---|
[16d866] | 374 | /** Constructor for BoundaryTriangleSet with three lines.
|
---|
| 375 | * \param *line[3] lines that make up the triangle
|
---|
| 376 | * \param number number of triangle
|
---|
| 377 | */
|
---|
[9473f6] | 378 | BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
|
---|
[1e168b] | 379 | Nr(number)
|
---|
[357fba] | 380 | {
|
---|
[6613ec] | 381 | Info FunctionInfo(__func__);
|
---|
[357fba] | 382 | // set number
|
---|
| 383 | // set lines
|
---|
[f67b6e] | 384 | for (int i = 0; i < 3; i++) {
|
---|
| 385 | lines[i] = line[i];
|
---|
| 386 | lines[i]->AddTriangle(this);
|
---|
| 387 | }
|
---|
[357fba] | 388 | // get ascending order of endpoints
|
---|
[f67b6e] | 389 | PointMap OrderMap;
|
---|
[a7b761b] | 390 | for (int i = 0; i < 3; i++) {
|
---|
[357fba] | 391 | // for all three lines
|
---|
[f67b6e] | 392 | for (int j = 0; j < 2; j++) { // for both endpoints
|
---|
[6613ec] | 393 | OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
|
---|
[f67b6e] | 394 | // and we don't care whether insertion fails
|
---|
| 395 | }
|
---|
[a7b761b] | 396 | }
|
---|
[357fba] | 397 | // set endpoints
|
---|
| 398 | int Counter = 0;
|
---|
[a67d19] | 399 | DoLog(0) && (Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl);
|
---|
[f67b6e] | 400 | for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
|
---|
| 401 | endpoints[Counter] = runner->second;
|
---|
[a67d19] | 402 | DoLog(0) && (Log() << Verbose(0) << " " << *endpoints[Counter] << endl);
|
---|
[f67b6e] | 403 | Counter++;
|
---|
| 404 | }
|
---|
[8d2772] | 405 | ASSERT(Counter >= 3,"We have a triangle with only two distinct endpoints!");
|
---|
[16d866] | 406 | };
|
---|
[357fba] | 407 |
|
---|
| 408 |
|
---|
[16d866] | 409 | /** Destructor of BoundaryTriangleSet.
|
---|
| 410 | * Removes itself from each of its lines' LineMap and removes them if necessary.
|
---|
| 411 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 412 | */
|
---|
[357fba] | 413 | BoundaryTriangleSet::~BoundaryTriangleSet()
|
---|
| 414 | {
|
---|
[6613ec] | 415 | Info FunctionInfo(__func__);
|
---|
[357fba] | 416 | for (int i = 0; i < 3; i++) {
|
---|
[16d866] | 417 | if (lines[i] != NULL) {
|
---|
[57066a] | 418 | if (lines[i]->triangles.erase(Nr)) {
|
---|
[f67b6e] | 419 | //Log() << Verbose(0) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
|
---|
[57066a] | 420 | }
|
---|
[16d866] | 421 | if (lines[i]->triangles.empty()) {
|
---|
[6613ec] | 422 | //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
|
---|
| 423 | delete (lines[i]);
|
---|
| 424 | lines[i] = NULL;
|
---|
[16d866] | 425 | }
|
---|
| 426 | }
|
---|
[357fba] | 427 | }
|
---|
[f67b6e] | 428 | //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
|
---|
[6613ec] | 429 | }
|
---|
| 430 | ;
|
---|
[357fba] | 431 |
|
---|
| 432 | /** Calculates the normal vector for this triangle.
|
---|
| 433 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 434 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 435 | */
|
---|
[9473f6] | 436 | void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
|
---|
[357fba] | 437 | {
|
---|
[6613ec] | 438 | Info FunctionInfo(__func__);
|
---|
[357fba] | 439 | // get normal vector
|
---|
[0a4f7f] | 440 | NormalVector = Plane(*(endpoints[0]->node->node),
|
---|
| 441 | *(endpoints[1]->node->node),
|
---|
| 442 | *(endpoints[2]->node->node)).getNormal();
|
---|
[357fba] | 443 |
|
---|
| 444 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
[273382] | 445 | if (NormalVector.ScalarProduct(OtherVector) > 0.)
|
---|
[357fba] | 446 | NormalVector.Scale(-1.);
|
---|
[a67d19] | 447 | DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl);
|
---|
[6613ec] | 448 | }
|
---|
| 449 | ;
|
---|
[357fba] | 450 |
|
---|
[97498a] | 451 | /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
|
---|
[357fba] | 452 | * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
|
---|
[9473f6] | 453 | * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
[7dea7c] | 454 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 455 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 456 | * the first two basepoints) or not.
|
---|
[357fba] | 457 | * \param *out output stream for debugging
|
---|
| 458 | * \param *MolCenter offset vector of line
|
---|
| 459 | * \param *x second endpoint of line, minus \a *MolCenter is directional vector of line
|
---|
| 460 | * \param *Intersection intersection on plane on return
|
---|
| 461 | * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
|
---|
| 462 | */
|
---|
[8cbb97] | 463 |
|
---|
[9473f6] | 464 | bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
|
---|
[357fba] | 465 | {
|
---|
[fee69b] | 466 | Info FunctionInfo(__func__);
|
---|
[357fba] | 467 | Vector CrossPoint;
|
---|
| 468 | Vector helper;
|
---|
| 469 |
|
---|
[0a4f7f] | 470 | try {
|
---|
[27ac00] | 471 | Line centerLine = makeLineThrough(*MolCenter, *x);
|
---|
| 472 | *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(centerLine);
|
---|
[357fba] | 473 |
|
---|
[215df0] | 474 | DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl);
|
---|
| 475 | DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl);
|
---|
| 476 | DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
|
---|
[97498a] | 477 |
|
---|
[215df0] | 478 | if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) {
|
---|
| 479 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
|
---|
| 480 | return true;
|
---|
| 481 | } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) {
|
---|
| 482 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
|
---|
| 483 | return true;
|
---|
| 484 | } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) {
|
---|
| 485 | DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
|
---|
| 486 | return true;
|
---|
| 487 | }
|
---|
| 488 | // Calculate cross point between one baseline and the line from the third endpoint to intersection
|
---|
| 489 | int i = 0;
|
---|
| 490 | do {
|
---|
[643e76] | 491 | Line line1 = makeLineThrough(*(endpoints[i%3]->node->node),*(endpoints[(i+1)%3]->node->node));
|
---|
| 492 | Line line2 = makeLineThrough(*(endpoints[(i+2)%3]->node->node),*Intersection);
|
---|
| 493 | CrossPoint = line1.getIntersection(line2);
|
---|
[273382] | 494 | helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
|
---|
| 495 | CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
| 496 | const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared();
|
---|
[a67d19] | 497 | DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl);
|
---|
[fee69b] | 498 | if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
|
---|
[a67d19] | 499 | DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
|
---|
[215df0] | 500 | return false;
|
---|
[fee69b] | 501 | }
|
---|
[5c7bf8] | 502 | i++;
|
---|
[215df0] | 503 | } while (i < 3);
|
---|
[a67d19] | 504 | DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl);
|
---|
[357fba] | 505 | return true;
|
---|
[215df0] | 506 | }
|
---|
| 507 | catch (MathException &excp) {
|
---|
| 508 | Log() << Verbose(1) << excp;
|
---|
| 509 | DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
|
---|
[357fba] | 510 | return false;
|
---|
| 511 | }
|
---|
[6613ec] | 512 | }
|
---|
| 513 | ;
|
---|
[357fba] | 514 |
|
---|
[8db598] | 515 | /** Finds the point on the triangle to the point \a *x.
|
---|
| 516 | * We call Vector::GetIntersectionWithPlane() with \a * and the center of the triangle to receive an intersection point.
|
---|
| 517 | * Then we check the in-plane part (the part projected down onto plane). We check whether it crosses one of the
|
---|
| 518 | * boundary lines. If it does, we return this intersection as closest point, otherwise the projected point down.
|
---|
[9473f6] | 519 | * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
|
---|
| 520 | * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
|
---|
| 521 | * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
|
---|
| 522 | * the first two basepoints) or not.
|
---|
| 523 | * \param *x point
|
---|
| 524 | * \param *ClosestPoint desired closest point inside triangle to \a *x, is absolute vector
|
---|
| 525 | * \return Distance squared between \a *x and closest point inside triangle
|
---|
| 526 | */
|
---|
| 527 | double BoundaryTriangleSet::GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const
|
---|
| 528 | {
|
---|
| 529 | Info FunctionInfo(__func__);
|
---|
| 530 | Vector Direction;
|
---|
| 531 |
|
---|
| 532 | // 1. get intersection with plane
|
---|
[a67d19] | 533 | DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl);
|
---|
[9473f6] | 534 | GetCenter(&Direction);
|
---|
[0a4f7f] | 535 | try {
|
---|
[27ac00] | 536 | Line l = makeLineThrough(*x, Direction);
|
---|
| 537 | *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(l);
|
---|
[0a4f7f] | 538 | }
|
---|
[27ac00] | 539 | catch (MathException &excp) {
|
---|
[273382] | 540 | (*ClosestPoint) = (*x);
|
---|
[9473f6] | 541 | }
|
---|
| 542 |
|
---|
| 543 | // 2. Calculate in plane part of line (x, intersection)
|
---|
[273382] | 544 | Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point
|
---|
| 545 | InPlane.ProjectOntoPlane(NormalVector);
|
---|
| 546 | InPlane += *ClosestPoint;
|
---|
[9473f6] | 547 |
|
---|
[a67d19] | 548 | DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl);
|
---|
| 549 | DoLog(2) && (Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl);
|
---|
| 550 | DoLog(2) && (Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl);
|
---|
[9473f6] | 551 |
|
---|
| 552 | // Calculate cross point between one baseline and the desired point such that distance is shortest
|
---|
| 553 | double ShortestDistance = -1.;
|
---|
| 554 | bool InsideFlag = false;
|
---|
| 555 | Vector CrossDirection[3];
|
---|
| 556 | Vector CrossPoint[3];
|
---|
| 557 | Vector helper;
|
---|
[6613ec] | 558 | for (int i = 0; i < 3; i++) {
|
---|
[9473f6] | 559 | // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
|
---|
[273382] | 560 | Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
|
---|
[9473f6] | 561 | // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
|
---|
[27ac00] | 562 | Line l = makeLineThrough(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
|
---|
| 563 | CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(l);
|
---|
[273382] | 564 | CrossDirection[i] = CrossPoint[i] - InPlane;
|
---|
| 565 | CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector
|
---|
| 566 | const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared();
|
---|
[a67d19] | 567 | DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl);
|
---|
[9473f6] | 568 | if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
|
---|
[8cbb97] | 569 | CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again
|
---|
[a67d19] | 570 | DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl);
|
---|
[273382] | 571 | const double distance = CrossPoint[i].DistanceSquared(*x);
|
---|
[9473f6] | 572 | if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
|
---|
| 573 | ShortestDistance = distance;
|
---|
[273382] | 574 | (*ClosestPoint) = CrossPoint[i];
|
---|
[9473f6] | 575 | }
|
---|
| 576 | } else
|
---|
| 577 | CrossPoint[i].Zero();
|
---|
| 578 | }
|
---|
| 579 | InsideFlag = true;
|
---|
[6613ec] | 580 | for (int i = 0; i < 3; i++) {
|
---|
[8cbb97] | 581 | const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 1) % 3]);
|
---|
| 582 | const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 2) % 3]);
|
---|
| 583 |
|
---|
[6613ec] | 584 | if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
|
---|
[9473f6] | 585 | InsideFlag = false;
|
---|
| 586 | }
|
---|
| 587 | if (InsideFlag) {
|
---|
[273382] | 588 | (*ClosestPoint) = InPlane;
|
---|
| 589 | ShortestDistance = InPlane.DistanceSquared(*x);
|
---|
[6613ec] | 590 | } else { // also check endnodes
|
---|
| 591 | for (int i = 0; i < 3; i++) {
|
---|
[273382] | 592 | const double distance = x->DistanceSquared(*endpoints[i]->node->node);
|
---|
[9473f6] | 593 | if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
|
---|
| 594 | ShortestDistance = distance;
|
---|
[273382] | 595 | (*ClosestPoint) = (*endpoints[i]->node->node);
|
---|
[9473f6] | 596 | }
|
---|
| 597 | }
|
---|
| 598 | }
|
---|
[a67d19] | 599 | DoLog(1) && (Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl);
|
---|
[9473f6] | 600 | return ShortestDistance;
|
---|
[6613ec] | 601 | }
|
---|
| 602 | ;
|
---|
[9473f6] | 603 |
|
---|
[357fba] | 604 | /** Checks whether lines is any of the three boundary lines this triangle contains.
|
---|
| 605 | * \param *line line to test
|
---|
| 606 | * \return true - line is of the triangle, false - is not
|
---|
| 607 | */
|
---|
[9473f6] | 608 | bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
|
---|
[357fba] | 609 | {
|
---|
[6613ec] | 610 | Info FunctionInfo(__func__);
|
---|
| 611 | for (int i = 0; i < 3; i++)
|
---|
[357fba] | 612 | if (line == lines[i])
|
---|
| 613 | return true;
|
---|
| 614 | return false;
|
---|
[6613ec] | 615 | }
|
---|
| 616 | ;
|
---|
[357fba] | 617 |
|
---|
| 618 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 619 | * \param *point point to test
|
---|
| 620 | * \return true - point is of the triangle, false - is not
|
---|
| 621 | */
|
---|
[9473f6] | 622 | bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
[357fba] | 623 | {
|
---|
[6613ec] | 624 | Info FunctionInfo(__func__);
|
---|
| 625 | for (int i = 0; i < 3; i++)
|
---|
[357fba] | 626 | if (point == endpoints[i])
|
---|
| 627 | return true;
|
---|
| 628 | return false;
|
---|
[6613ec] | 629 | }
|
---|
| 630 | ;
|
---|
[357fba] | 631 |
|
---|
[7dea7c] | 632 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 633 | * \param *point TesselPoint to test
|
---|
| 634 | * \return true - point is of the triangle, false - is not
|
---|
| 635 | */
|
---|
[9473f6] | 636 | bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
|
---|
[7dea7c] | 637 | {
|
---|
[6613ec] | 638 | Info FunctionInfo(__func__);
|
---|
| 639 | for (int i = 0; i < 3; i++)
|
---|
[7dea7c] | 640 | if (point == endpoints[i]->node)
|
---|
| 641 | return true;
|
---|
| 642 | return false;
|
---|
[6613ec] | 643 | }
|
---|
| 644 | ;
|
---|
[7dea7c] | 645 |
|
---|
[357fba] | 646 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 647 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 648 | * \return true - is the very triangle, false - is not
|
---|
| 649 | */
|
---|
[9473f6] | 650 | bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
|
---|
[357fba] | 651 | {
|
---|
[6613ec] | 652 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 653 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl);
|
---|
[6613ec] | 654 | return (((endpoints[0] == Points[0]) || (endpoints[0] == Points[1]) || (endpoints[0] == Points[2])) && ((endpoints[1] == Points[0]) || (endpoints[1] == Points[1]) || (endpoints[1] == Points[2])) && ((endpoints[2] == Points[0]) || (endpoints[2] == Points[1]) || (endpoints[2] == Points[2])
|
---|
| 655 |
|
---|
| 656 | ));
|
---|
| 657 | }
|
---|
| 658 | ;
|
---|
[357fba] | 659 |
|
---|
[57066a] | 660 | /** Checks whether three given \a *Points coincide with triangle's endpoints.
|
---|
| 661 | * \param *Points[3] pointer to BoundaryPointSet
|
---|
| 662 | * \return true - is the very triangle, false - is not
|
---|
| 663 | */
|
---|
[9473f6] | 664 | bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
|
---|
[57066a] | 665 | {
|
---|
[6613ec] | 666 | Info FunctionInfo(__func__);
|
---|
| 667 | return (((endpoints[0] == T->endpoints[0]) || (endpoints[0] == T->endpoints[1]) || (endpoints[0] == T->endpoints[2])) && ((endpoints[1] == T->endpoints[0]) || (endpoints[1] == T->endpoints[1]) || (endpoints[1] == T->endpoints[2])) && ((endpoints[2] == T->endpoints[0]) || (endpoints[2] == T->endpoints[1]) || (endpoints[2] == T->endpoints[2])
|
---|
| 668 |
|
---|
| 669 | ));
|
---|
| 670 | }
|
---|
| 671 | ;
|
---|
[57066a] | 672 |
|
---|
[62bb91] | 673 | /** Returns the endpoint which is not contained in the given \a *line.
|
---|
| 674 | * \param *line baseline defining two endpoints
|
---|
| 675 | * \return pointer third endpoint or NULL if line does not belong to triangle.
|
---|
| 676 | */
|
---|
[9473f6] | 677 | class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
|
---|
[62bb91] | 678 | {
|
---|
[6613ec] | 679 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 680 | // sanity check
|
---|
| 681 | if (!ContainsBoundaryLine(line))
|
---|
| 682 | return NULL;
|
---|
[6613ec] | 683 | for (int i = 0; i < 3; i++)
|
---|
[62bb91] | 684 | if (!line->ContainsBoundaryPoint(endpoints[i]))
|
---|
| 685 | return endpoints[i];
|
---|
| 686 | // actually, that' impossible :)
|
---|
| 687 | return NULL;
|
---|
[6613ec] | 688 | }
|
---|
| 689 | ;
|
---|
[62bb91] | 690 |
|
---|
[b32dbb] | 691 | /** Returns the baseline which does not contain the given boundary point \a *point.
|
---|
| 692 | * \param *point endpoint which is neither endpoint of the desired line
|
---|
| 693 | * \return pointer to desired third baseline
|
---|
| 694 | */
|
---|
| 695 | class BoundaryLineSet *BoundaryTriangleSet::GetThirdLine(const BoundaryPointSet * const point) const
|
---|
| 696 | {
|
---|
| 697 | Info FunctionInfo(__func__);
|
---|
| 698 | // sanity check
|
---|
| 699 | if (!ContainsBoundaryPoint(point))
|
---|
| 700 | return NULL;
|
---|
| 701 | for (int i = 0; i < 3; i++)
|
---|
| 702 | if (!lines[i]->ContainsBoundaryPoint(point))
|
---|
| 703 | return lines[i];
|
---|
| 704 | // actually, that' impossible :)
|
---|
| 705 | return NULL;
|
---|
| 706 | }
|
---|
| 707 | ;
|
---|
| 708 |
|
---|
[62bb91] | 709 | /** Calculates the center point of the triangle.
|
---|
| 710 | * Is third of the sum of all endpoints.
|
---|
| 711 | * \param *center central point on return.
|
---|
| 712 | */
|
---|
[9473f6] | 713 | void BoundaryTriangleSet::GetCenter(Vector * const center) const
|
---|
[62bb91] | 714 | {
|
---|
[6613ec] | 715 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 716 | center->Zero();
|
---|
[6613ec] | 717 | for (int i = 0; i < 3; i++)
|
---|
[273382] | 718 | (*center) += (*endpoints[i]->node->node);
|
---|
[6613ec] | 719 | center->Scale(1. / 3.);
|
---|
[a67d19] | 720 | DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl);
|
---|
[62bb91] | 721 | }
|
---|
| 722 |
|
---|
[d4c9ae] | 723 | /**
|
---|
| 724 | * gets the Plane defined by the three triangle Basepoints
|
---|
| 725 | */
|
---|
| 726 | Plane BoundaryTriangleSet::getPlane() const{
|
---|
| 727 | ASSERT(endpoints[0] && endpoints[1] && endpoints[2], "Triangle not fully defined");
|
---|
| 728 |
|
---|
| 729 | return Plane(*endpoints[0]->node->node,
|
---|
| 730 | *endpoints[1]->node->node,
|
---|
| 731 | *endpoints[2]->node->node);
|
---|
| 732 | }
|
---|
| 733 |
|
---|
[8f215d] | 734 | Vector BoundaryTriangleSet::getEndpoint(int i) const{
|
---|
| 735 | ASSERT(i>=0 && i<3,"Index of Endpoint out of Range");
|
---|
| 736 |
|
---|
| 737 | return *endpoints[i]->node->node;
|
---|
| 738 | }
|
---|
| 739 |
|
---|
| 740 | string BoundaryTriangleSet::getEndpointName(int i) const{
|
---|
| 741 | ASSERT(i>=0 && i<3,"Index of Endpoint out of Range");
|
---|
| 742 |
|
---|
| 743 | return endpoints[i]->node->getName();
|
---|
| 744 | }
|
---|
| 745 |
|
---|
[16d866] | 746 | /** output operator for BoundaryTriangleSet.
|
---|
| 747 | * \param &ost output stream
|
---|
| 748 | * \param &a boundary triangle
|
---|
| 749 | */
|
---|
[776b64] | 750 | ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
|
---|
[357fba] | 751 | {
|
---|
[8f215d] | 752 | ost << "[" << a.Nr << "|" << a.getEndpointName(0) << "," << a.getEndpointName(1) << "," << a.getEndpointName(2) << "]";
|
---|
[6613ec] | 753 | // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
|
---|
| 754 | // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
|
---|
[357fba] | 755 | return ost;
|
---|
[6613ec] | 756 | }
|
---|
| 757 | ;
|
---|
[357fba] | 758 |
|
---|
[262bae] | 759 | // ======================================== Polygons on Boundary =================================
|
---|
| 760 |
|
---|
| 761 | /** Constructor for BoundaryPolygonSet.
|
---|
| 762 | */
|
---|
| 763 | BoundaryPolygonSet::BoundaryPolygonSet() :
|
---|
| 764 | Nr(-1)
|
---|
| 765 | {
|
---|
| 766 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 767 | }
|
---|
| 768 | ;
|
---|
[262bae] | 769 |
|
---|
| 770 | /** Destructor of BoundaryPolygonSet.
|
---|
| 771 | * Just clears endpoints.
|
---|
| 772 | * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
|
---|
| 773 | */
|
---|
| 774 | BoundaryPolygonSet::~BoundaryPolygonSet()
|
---|
| 775 | {
|
---|
| 776 | Info FunctionInfo(__func__);
|
---|
| 777 | endpoints.clear();
|
---|
[a67d19] | 778 | DoLog(1) && (Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl);
|
---|
[6613ec] | 779 | }
|
---|
| 780 | ;
|
---|
[262bae] | 781 |
|
---|
| 782 | /** Calculates the normal vector for this triangle.
|
---|
| 783 | * Is made unique by comparison with \a OtherVector to point in the other direction.
|
---|
| 784 | * \param &OtherVector direction vector to make normal vector unique.
|
---|
| 785 | * \return allocated vector in normal direction
|
---|
| 786 | */
|
---|
| 787 | Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
|
---|
| 788 | {
|
---|
| 789 | Info FunctionInfo(__func__);
|
---|
| 790 | // get normal vector
|
---|
| 791 | Vector TemporaryNormal;
|
---|
| 792 | Vector *TotalNormal = new Vector;
|
---|
| 793 | PointSet::const_iterator Runner[3];
|
---|
[6613ec] | 794 | for (int i = 0; i < 3; i++) {
|
---|
[262bae] | 795 | Runner[i] = endpoints.begin();
|
---|
[6613ec] | 796 | for (int j = 0; j < i; j++) { // go as much further
|
---|
[262bae] | 797 | Runner[i]++;
|
---|
| 798 | if (Runner[i] == endpoints.end()) {
|
---|
[6613ec] | 799 | DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
|
---|
[262bae] | 800 | performCriticalExit();
|
---|
| 801 | }
|
---|
| 802 | }
|
---|
| 803 | }
|
---|
| 804 | TotalNormal->Zero();
|
---|
[6613ec] | 805 | int counter = 0;
|
---|
| 806 | for (; Runner[2] != endpoints.end();) {
|
---|
[0a4f7f] | 807 | TemporaryNormal = Plane(*((*Runner[0])->node->node),
|
---|
| 808 | *((*Runner[1])->node->node),
|
---|
| 809 | *((*Runner[2])->node->node)).getNormal();
|
---|
[6613ec] | 810 | for (int i = 0; i < 3; i++) // increase each of them
|
---|
[262bae] | 811 | Runner[i]++;
|
---|
[273382] | 812 | (*TotalNormal) += TemporaryNormal;
|
---|
[262bae] | 813 | }
|
---|
[6613ec] | 814 | TotalNormal->Scale(1. / (double) counter);
|
---|
[262bae] | 815 |
|
---|
| 816 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
---|
[273382] | 817 | if (TotalNormal->ScalarProduct(OtherVector) > 0.)
|
---|
[262bae] | 818 | TotalNormal->Scale(-1.);
|
---|
[a67d19] | 819 | DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
|
---|
[262bae] | 820 |
|
---|
| 821 | return TotalNormal;
|
---|
[6613ec] | 822 | }
|
---|
| 823 | ;
|
---|
[262bae] | 824 |
|
---|
| 825 | /** Calculates the center point of the triangle.
|
---|
| 826 | * Is third of the sum of all endpoints.
|
---|
| 827 | * \param *center central point on return.
|
---|
| 828 | */
|
---|
| 829 | void BoundaryPolygonSet::GetCenter(Vector * const center) const
|
---|
| 830 | {
|
---|
| 831 | Info FunctionInfo(__func__);
|
---|
| 832 | center->Zero();
|
---|
| 833 | int counter = 0;
|
---|
| 834 | for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[273382] | 835 | (*center) += (*(*Runner)->node->node);
|
---|
[262bae] | 836 | counter++;
|
---|
| 837 | }
|
---|
[6613ec] | 838 | center->Scale(1. / (double) counter);
|
---|
[a67d19] | 839 | DoLog(1) && (Log() << Verbose(1) << "Center is at " << *center << "." << endl);
|
---|
[262bae] | 840 | }
|
---|
| 841 |
|
---|
| 842 | /** Checks whether the polygons contains all three endpoints of the triangle.
|
---|
| 843 | * \param *triangle triangle to test
|
---|
| 844 | * \return true - triangle is contained polygon, false - is not
|
---|
| 845 | */
|
---|
| 846 | bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
|
---|
| 847 | {
|
---|
| 848 | Info FunctionInfo(__func__);
|
---|
| 849 | return ContainsPresentTupel(triangle->endpoints, 3);
|
---|
[6613ec] | 850 | }
|
---|
| 851 | ;
|
---|
[262bae] | 852 |
|
---|
| 853 | /** Checks whether the polygons contains both endpoints of the line.
|
---|
| 854 | * \param *line line to test
|
---|
| 855 | * \return true - line is of the triangle, false - is not
|
---|
| 856 | */
|
---|
| 857 | bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
|
---|
| 858 | {
|
---|
[856098] | 859 | Info FunctionInfo(__func__);
|
---|
[262bae] | 860 | return ContainsPresentTupel(line->endpoints, 2);
|
---|
[6613ec] | 861 | }
|
---|
| 862 | ;
|
---|
[262bae] | 863 |
|
---|
| 864 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 865 | * \param *point point to test
|
---|
| 866 | * \return true - point is of the triangle, false - is not
|
---|
| 867 | */
|
---|
| 868 | bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
|
---|
| 869 | {
|
---|
| 870 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 871 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[a67d19] | 872 | DoLog(0) && (Log() << Verbose(0) << "Checking against " << **Runner << endl);
|
---|
[856098] | 873 | if (point == (*Runner)) {
|
---|
[a67d19] | 874 | DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
|
---|
[262bae] | 875 | return true;
|
---|
[856098] | 876 | }
|
---|
| 877 | }
|
---|
[a67d19] | 878 | DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
|
---|
[262bae] | 879 | return false;
|
---|
[6613ec] | 880 | }
|
---|
| 881 | ;
|
---|
[262bae] | 882 |
|
---|
| 883 | /** Checks whether point is any of the three endpoints this triangle contains.
|
---|
| 884 | * \param *point TesselPoint to test
|
---|
| 885 | * \return true - point is of the triangle, false - is not
|
---|
| 886 | */
|
---|
| 887 | bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
|
---|
| 888 | {
|
---|
| 889 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 890 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
|
---|
[856098] | 891 | if (point == (*Runner)->node) {
|
---|
[a67d19] | 892 | DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
|
---|
[262bae] | 893 | return true;
|
---|
[856098] | 894 | }
|
---|
[a67d19] | 895 | DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
|
---|
[262bae] | 896 | return false;
|
---|
[6613ec] | 897 | }
|
---|
| 898 | ;
|
---|
[262bae] | 899 |
|
---|
| 900 | /** Checks whether given array of \a *Points coincide with polygons's endpoints.
|
---|
| 901 | * \param **Points pointer to an array of BoundaryPointSet
|
---|
| 902 | * \param dim dimension of array
|
---|
| 903 | * \return true - set of points is contained in polygon, false - is not
|
---|
| 904 | */
|
---|
| 905 | bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
|
---|
| 906 | {
|
---|
[856098] | 907 | Info FunctionInfo(__func__);
|
---|
[262bae] | 908 | int counter = 0;
|
---|
[a67d19] | 909 | DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
|
---|
[6613ec] | 910 | for (int i = 0; i < dim; i++) {
|
---|
[a67d19] | 911 | DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl);
|
---|
[856098] | 912 | if (ContainsBoundaryPoint(Points[i])) {
|
---|
[262bae] | 913 | counter++;
|
---|
[856098] | 914 | }
|
---|
| 915 | }
|
---|
[262bae] | 916 |
|
---|
| 917 | if (counter == dim)
|
---|
| 918 | return true;
|
---|
| 919 | else
|
---|
| 920 | return false;
|
---|
[6613ec] | 921 | }
|
---|
| 922 | ;
|
---|
[262bae] | 923 |
|
---|
| 924 | /** Checks whether given PointList coincide with polygons's endpoints.
|
---|
| 925 | * \param &endpoints PointList
|
---|
| 926 | * \return true - set of points is contained in polygon, false - is not
|
---|
| 927 | */
|
---|
| 928 | bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
|
---|
| 929 | {
|
---|
[856098] | 930 | Info FunctionInfo(__func__);
|
---|
[262bae] | 931 | size_t counter = 0;
|
---|
[a67d19] | 932 | DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
|
---|
[6613ec] | 933 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
|
---|
[a67d19] | 934 | DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << **Runner << endl);
|
---|
[262bae] | 935 | if (ContainsBoundaryPoint(*Runner))
|
---|
| 936 | counter++;
|
---|
| 937 | }
|
---|
| 938 |
|
---|
| 939 | if (counter == endpoints.size())
|
---|
| 940 | return true;
|
---|
| 941 | else
|
---|
| 942 | return false;
|
---|
[6613ec] | 943 | }
|
---|
| 944 | ;
|
---|
[262bae] | 945 |
|
---|
| 946 | /** Checks whether given set of \a *Points coincide with polygons's endpoints.
|
---|
| 947 | * \param *P pointer to BoundaryPolygonSet
|
---|
| 948 | * \return true - is the very triangle, false - is not
|
---|
| 949 | */
|
---|
| 950 | bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
|
---|
| 951 | {
|
---|
[6613ec] | 952 | return ContainsPresentTupel((const PointSet) P->endpoints);
|
---|
| 953 | }
|
---|
| 954 | ;
|
---|
[262bae] | 955 |
|
---|
| 956 | /** Gathers all the endpoints' triangles in a unique set.
|
---|
| 957 | * \return set of all triangles
|
---|
| 958 | */
|
---|
[856098] | 959 | TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
|
---|
[262bae] | 960 | {
|
---|
| 961 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 962 | pair<TriangleSet::iterator, bool> Tester;
|
---|
[262bae] | 963 | TriangleSet *triangles = new TriangleSet;
|
---|
| 964 |
|
---|
[6613ec] | 965 | for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
|
---|
| 966 | for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
|
---|
| 967 | for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
|
---|
[856098] | 968 | //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
|
---|
| 969 | if (ContainsBoundaryTriangle(Sprinter->second)) {
|
---|
| 970 | Tester = triangles->insert(Sprinter->second);
|
---|
| 971 | if (Tester.second)
|
---|
[a67d19] | 972 | DoLog(0) && (Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl);
|
---|
[856098] | 973 | }
|
---|
| 974 | }
|
---|
[262bae] | 975 |
|
---|
[a67d19] | 976 | DoLog(1) && (Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl);
|
---|
[262bae] | 977 | return triangles;
|
---|
[6613ec] | 978 | }
|
---|
| 979 | ;
|
---|
[262bae] | 980 |
|
---|
| 981 | /** Fills the endpoints of this polygon from the triangles attached to \a *line.
|
---|
| 982 | * \param *line lines with triangles attached
|
---|
[856098] | 983 | * \return true - polygon contains endpoints, false - line was NULL
|
---|
[262bae] | 984 | */
|
---|
| 985 | bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
|
---|
| 986 | {
|
---|
[856098] | 987 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 988 | pair<PointSet::iterator, bool> Tester;
|
---|
[856098] | 989 | if (line == NULL)
|
---|
| 990 | return false;
|
---|
[a67d19] | 991 | DoLog(1) && (Log() << Verbose(1) << "Filling polygon from line " << *line << endl);
|
---|
[6613ec] | 992 | for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
|
---|
| 993 | for (int i = 0; i < 3; i++) {
|
---|
[856098] | 994 | Tester = endpoints.insert((Runner->second)->endpoints[i]);
|
---|
| 995 | if (Tester.second)
|
---|
[a67d19] | 996 | DoLog(1) && (Log() << Verbose(1) << " Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl);
|
---|
[856098] | 997 | }
|
---|
[262bae] | 998 | }
|
---|
| 999 |
|
---|
[856098] | 1000 | return true;
|
---|
[6613ec] | 1001 | }
|
---|
| 1002 | ;
|
---|
[262bae] | 1003 |
|
---|
| 1004 | /** output operator for BoundaryPolygonSet.
|
---|
| 1005 | * \param &ost output stream
|
---|
| 1006 | * \param &a boundary polygon
|
---|
| 1007 | */
|
---|
| 1008 | ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
|
---|
| 1009 | {
|
---|
| 1010 | ost << "[" << a.Nr << "|";
|
---|
[6613ec] | 1011 | for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
|
---|
[68f03d] | 1012 | ost << (*Runner)->node->getName();
|
---|
[6613ec] | 1013 | Runner++;
|
---|
| 1014 | if (Runner != a.endpoints.end())
|
---|
| 1015 | ost << ",";
|
---|
[262bae] | 1016 | }
|
---|
[6613ec] | 1017 | ost << "]";
|
---|
[262bae] | 1018 | return ost;
|
---|
[6613ec] | 1019 | }
|
---|
| 1020 | ;
|
---|
[262bae] | 1021 |
|
---|
[357fba] | 1022 | // =========================================================== class TESSELPOINT ===========================================
|
---|
| 1023 |
|
---|
| 1024 | /** Constructor of class TesselPoint.
|
---|
| 1025 | */
|
---|
| 1026 | TesselPoint::TesselPoint()
|
---|
| 1027 | {
|
---|
[244a84] | 1028 | //Info FunctionInfo(__func__);
|
---|
[357fba] | 1029 | node = NULL;
|
---|
| 1030 | nr = -1;
|
---|
[6613ec] | 1031 | }
|
---|
| 1032 | ;
|
---|
[357fba] | 1033 |
|
---|
| 1034 | /** Destructor for class TesselPoint.
|
---|
| 1035 | */
|
---|
| 1036 | TesselPoint::~TesselPoint()
|
---|
| 1037 | {
|
---|
[244a84] | 1038 | //Info FunctionInfo(__func__);
|
---|
[6613ec] | 1039 | }
|
---|
| 1040 | ;
|
---|
[357fba] | 1041 |
|
---|
| 1042 | /** Prints LCNode to screen.
|
---|
| 1043 | */
|
---|
[6613ec] | 1044 | ostream & operator <<(ostream &ost, const TesselPoint &a)
|
---|
[357fba] | 1045 | {
|
---|
[68f03d] | 1046 | ost << "[" << a.getName() << "|" << *a.node << "]";
|
---|
[357fba] | 1047 | return ost;
|
---|
[6613ec] | 1048 | }
|
---|
| 1049 | ;
|
---|
[357fba] | 1050 |
|
---|
[5c7bf8] | 1051 | /** Prints LCNode to screen.
|
---|
| 1052 | */
|
---|
[6613ec] | 1053 | ostream & TesselPoint::operator <<(ostream &ost)
|
---|
[5c7bf8] | 1054 | {
|
---|
[6613ec] | 1055 | Info FunctionInfo(__func__);
|
---|
[27bd2f] | 1056 | ost << "[" << (nr) << "|" << this << "]";
|
---|
[5c7bf8] | 1057 | return ost;
|
---|
[6613ec] | 1058 | }
|
---|
| 1059 | ;
|
---|
[357fba] | 1060 |
|
---|
| 1061 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 1062 |
|
---|
| 1063 | /** Constructor of class PointCloud.
|
---|
| 1064 | */
|
---|
| 1065 | PointCloud::PointCloud()
|
---|
| 1066 | {
|
---|
[6613ec] | 1067 | //Info FunctionInfo(__func__);
|
---|
| 1068 | }
|
---|
| 1069 | ;
|
---|
[357fba] | 1070 |
|
---|
| 1071 | /** Destructor for class PointCloud.
|
---|
| 1072 | */
|
---|
| 1073 | PointCloud::~PointCloud()
|
---|
| 1074 | {
|
---|
[6613ec] | 1075 | //Info FunctionInfo(__func__);
|
---|
| 1076 | }
|
---|
| 1077 | ;
|
---|
[357fba] | 1078 |
|
---|
| 1079 | // ============================ CandidateForTesselation =============================
|
---|
| 1080 |
|
---|
| 1081 | /** Constructor of class CandidateForTesselation.
|
---|
| 1082 | */
|
---|
[6613ec] | 1083 | CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
|
---|
| 1084 | BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
|
---|
[1e168b] | 1085 | {
|
---|
[6613ec] | 1086 | Info FunctionInfo(__func__);
|
---|
| 1087 | }
|
---|
| 1088 | ;
|
---|
[1e168b] | 1089 |
|
---|
| 1090 | /** Constructor of class CandidateForTesselation.
|
---|
| 1091 | */
|
---|
[6613ec] | 1092 | CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
|
---|
| 1093 | BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
|
---|
[1e168b] | 1094 | {
|
---|
[f67b6e] | 1095 | Info FunctionInfo(__func__);
|
---|
[273382] | 1096 | OptCenter = OptCandidateCenter;
|
---|
| 1097 | OtherOptCenter = OtherOptCandidateCenter;
|
---|
[357fba] | 1098 | };
|
---|
| 1099 |
|
---|
| 1100 |
|
---|
| 1101 | /** Destructor for class CandidateForTesselation.
|
---|
| 1102 | */
|
---|
[6613ec] | 1103 | CandidateForTesselation::~CandidateForTesselation()
|
---|
| 1104 | {
|
---|
| 1105 | }
|
---|
| 1106 | ;
|
---|
[357fba] | 1107 |
|
---|
[734816] | 1108 | /** Checks validity of a given sphere of a candidate line.
|
---|
| 1109 | * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside.
|
---|
| 1110 | * \param RADIUS radius of sphere
|
---|
| 1111 | * \param *LC LinkedCell structure with other atoms
|
---|
| 1112 | * \return true - sphere is valid, false - sphere contains other points
|
---|
| 1113 | */
|
---|
| 1114 | bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
|
---|
| 1115 | {
|
---|
[09898c] | 1116 | Info FunctionInfo(__func__);
|
---|
| 1117 |
|
---|
[6613ec] | 1118 | const double radiusSquared = RADIUS * RADIUS;
|
---|
[734816] | 1119 | list<const Vector *> VectorList;
|
---|
| 1120 | VectorList.push_back(&OptCenter);
|
---|
[09898c] | 1121 | //VectorList.push_back(&OtherOptCenter); // don't check the other (wrong) center
|
---|
[734816] | 1122 |
|
---|
[09898c] | 1123 | if (!pointlist.empty())
|
---|
[6613ec] | 1124 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
|
---|
[09898c] | 1125 | else
|
---|
| 1126 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
|
---|
[734816] | 1127 | // check baseline for OptCenter and OtherOptCenter being on sphere's surface
|
---|
| 1128 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
[6613ec] | 1129 | for (int i = 0; i < 2; i++) {
|
---|
[8cbb97] | 1130 | const double distance = fabs((*VRunner)->DistanceSquared(*BaseLine->endpoints[i]->node->node) - radiusSquared);
|
---|
[f07f86d] | 1131 | if (distance > HULLEPSILON) {
|
---|
[6613ec] | 1132 | DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
|
---|
[734816] | 1133 | return false;
|
---|
| 1134 | }
|
---|
[f07f86d] | 1135 | }
|
---|
[734816] | 1136 | }
|
---|
| 1137 |
|
---|
| 1138 | // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
|
---|
[6613ec] | 1139 | for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
|
---|
[734816] | 1140 | const TesselPoint *Walker = *Runner;
|
---|
| 1141 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
[8cbb97] | 1142 | const double distance = fabs((*VRunner)->DistanceSquared(*Walker->node) - radiusSquared);
|
---|
[f07f86d] | 1143 | if (distance > HULLEPSILON) {
|
---|
[6613ec] | 1144 | DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
|
---|
[734816] | 1145 | return false;
|
---|
[6613ec] | 1146 | } else {
|
---|
[a67d19] | 1147 | DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl);
|
---|
[734816] | 1148 | }
|
---|
| 1149 | }
|
---|
| 1150 | }
|
---|
| 1151 |
|
---|
[09898c] | 1152 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
|
---|
[734816] | 1153 | bool flag = true;
|
---|
| 1154 | for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
|
---|
| 1155 | // get all points inside the sphere
|
---|
| 1156 | TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
|
---|
[6613ec] | 1157 |
|
---|
[b32dbb] | 1158 | DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << (*VRunner) << ":" << endl);
|
---|
[6613ec] | 1159 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[b32dbb] | 1160 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(*(*VRunner)) << "." << endl);
|
---|
[6613ec] | 1161 |
|
---|
[734816] | 1162 | // remove baseline's endpoints and candidates
|
---|
[6613ec] | 1163 | for (int i = 0; i < 2; i++) {
|
---|
[a67d19] | 1164 | DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl);
|
---|
[734816] | 1165 | ListofPoints->remove(BaseLine->endpoints[i]->node);
|
---|
[6613ec] | 1166 | }
|
---|
| 1167 | for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
|
---|
[a67d19] | 1168 | DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl);
|
---|
[734816] | 1169 | ListofPoints->remove(*Runner);
|
---|
[6613ec] | 1170 | }
|
---|
[734816] | 1171 | if (!ListofPoints->empty()) {
|
---|
[6613ec] | 1172 | DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
|
---|
[734816] | 1173 | flag = false;
|
---|
[09898c] | 1174 | DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
|
---|
| 1175 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[b32dbb] | 1176 | DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << " at distance " << setprecision(13) << (*Runner)->node->distance(*(*VRunner)) << setprecision(6) << "." << endl);
|
---|
| 1177 |
|
---|
| 1178 | // check with animate_sphere.tcl VMD script
|
---|
| 1179 | if (ThirdPoint != NULL) {
|
---|
| 1180 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
|
---|
| 1181 | } else {
|
---|
| 1182 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: ... missing third point ..." << endl);
|
---|
| 1183 | DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
|
---|
| 1184 | }
|
---|
[734816] | 1185 | }
|
---|
[6613ec] | 1186 | delete (ListofPoints);
|
---|
[09898c] | 1187 |
|
---|
[734816] | 1188 | }
|
---|
| 1189 | return flag;
|
---|
[6613ec] | 1190 | }
|
---|
| 1191 | ;
|
---|
[357fba] | 1192 |
|
---|
[1e168b] | 1193 | /** output operator for CandidateForTesselation.
|
---|
| 1194 | * \param &ost output stream
|
---|
| 1195 | * \param &a boundary line
|
---|
| 1196 | */
|
---|
[6613ec] | 1197 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
|
---|
[1e168b] | 1198 | {
|
---|
[68f03d] | 1199 | ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->getName() << "," << a.BaseLine->endpoints[1]->node->getName() << "] with ";
|
---|
[f67b6e] | 1200 | if (a.pointlist.empty())
|
---|
[1e168b] | 1201 | ost << "no candidate.";
|
---|
[f67b6e] | 1202 | else {
|
---|
| 1203 | ost << "candidate";
|
---|
| 1204 | if (a.pointlist.size() != 1)
|
---|
| 1205 | ost << "s ";
|
---|
| 1206 | else
|
---|
| 1207 | ost << " ";
|
---|
| 1208 | for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
|
---|
| 1209 | ost << *(*Runner) << " ";
|
---|
[6613ec] | 1210 | ost << " at angle " << (a.ShortestAngle) << ".";
|
---|
[f67b6e] | 1211 | }
|
---|
[1e168b] | 1212 |
|
---|
| 1213 | return ost;
|
---|
[6613ec] | 1214 | }
|
---|
| 1215 | ;
|
---|
[1e168b] | 1216 |
|
---|
[357fba] | 1217 | // =========================================================== class TESSELATION ===========================================
|
---|
| 1218 |
|
---|
| 1219 | /** Constructor of class Tesselation.
|
---|
| 1220 | */
|
---|
[1e168b] | 1221 | Tesselation::Tesselation() :
|
---|
[6613ec] | 1222 | PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin())
|
---|
[357fba] | 1223 | {
|
---|
[6613ec] | 1224 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1225 | }
|
---|
| 1226 | ;
|
---|
| 1227 |
|
---|
| 1228 | /** Destructor of class Tesselation.
|
---|
| 1229 | * We have to free all points, lines and triangles.
|
---|
| 1230 | */
|
---|
| 1231 | Tesselation::~Tesselation()
|
---|
| 1232 | {
|
---|
[6613ec] | 1233 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1234 | DoLog(0) && (Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl);
|
---|
[357fba] | 1235 | for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
|
---|
| 1236 | if (runner->second != NULL) {
|
---|
| 1237 | delete (runner->second);
|
---|
| 1238 | runner->second = NULL;
|
---|
| 1239 | } else
|
---|
[6613ec] | 1240 | DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);
|
---|
[357fba] | 1241 | }
|
---|
[a67d19] | 1242 | DoLog(0) && (Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl);
|
---|
[357fba] | 1243 | }
|
---|
| 1244 | ;
|
---|
| 1245 |
|
---|
[5c7bf8] | 1246 | /** PointCloud implementation of GetCenter
|
---|
| 1247 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1248 | */
|
---|
[776b64] | 1249 | Vector * Tesselation::GetCenter(ofstream *out) const
|
---|
[5c7bf8] | 1250 | {
|
---|
[6613ec] | 1251 | Info FunctionInfo(__func__);
|
---|
| 1252 | Vector *Center = new Vector(0., 0., 0.);
|
---|
| 1253 | int num = 0;
|
---|
[5c7bf8] | 1254 | for (GoToFirst(); (!IsEnd()); GoToNext()) {
|
---|
[273382] | 1255 | (*Center) += (*GetPoint()->node);
|
---|
[5c7bf8] | 1256 | num++;
|
---|
| 1257 | }
|
---|
[6613ec] | 1258 | Center->Scale(1. / num);
|
---|
[5c7bf8] | 1259 | return Center;
|
---|
[6613ec] | 1260 | }
|
---|
| 1261 | ;
|
---|
[5c7bf8] | 1262 |
|
---|
| 1263 | /** PointCloud implementation of GoPoint
|
---|
| 1264 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1265 | */
|
---|
[776b64] | 1266 | TesselPoint * Tesselation::GetPoint() const
|
---|
[5c7bf8] | 1267 | {
|
---|
[6613ec] | 1268 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1269 | return (InternalPointer->second->node);
|
---|
[6613ec] | 1270 | }
|
---|
| 1271 | ;
|
---|
[5c7bf8] | 1272 |
|
---|
| 1273 | /** PointCloud implementation of GoToNext.
|
---|
| 1274 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1275 | */
|
---|
[776b64] | 1276 | void Tesselation::GoToNext() const
|
---|
[5c7bf8] | 1277 | {
|
---|
[6613ec] | 1278 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1279 | if (InternalPointer != PointsOnBoundary.end())
|
---|
| 1280 | InternalPointer++;
|
---|
[6613ec] | 1281 | }
|
---|
| 1282 | ;
|
---|
[5c7bf8] | 1283 |
|
---|
| 1284 | /** PointCloud implementation of GoToFirst.
|
---|
| 1285 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1286 | */
|
---|
[776b64] | 1287 | void Tesselation::GoToFirst() const
|
---|
[5c7bf8] | 1288 | {
|
---|
[6613ec] | 1289 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1290 | InternalPointer = PointsOnBoundary.begin();
|
---|
[6613ec] | 1291 | }
|
---|
| 1292 | ;
|
---|
[5c7bf8] | 1293 |
|
---|
| 1294 | /** PointCloud implementation of IsEmpty.
|
---|
| 1295 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1296 | */
|
---|
[776b64] | 1297 | bool Tesselation::IsEmpty() const
|
---|
[5c7bf8] | 1298 | {
|
---|
[6613ec] | 1299 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1300 | return (PointsOnBoundary.empty());
|
---|
[6613ec] | 1301 | }
|
---|
| 1302 | ;
|
---|
[5c7bf8] | 1303 |
|
---|
| 1304 | /** PointCloud implementation of IsLast.
|
---|
| 1305 | * Uses PointsOnBoundary and STL stuff.
|
---|
[6613ec] | 1306 | */
|
---|
[776b64] | 1307 | bool Tesselation::IsEnd() const
|
---|
[5c7bf8] | 1308 | {
|
---|
[6613ec] | 1309 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1310 | return (InternalPointer == PointsOnBoundary.end());
|
---|
[6613ec] | 1311 | }
|
---|
| 1312 | ;
|
---|
[5c7bf8] | 1313 |
|
---|
[357fba] | 1314 | /** Gueses first starting triangle of the convex envelope.
|
---|
| 1315 | * We guess the starting triangle by taking the smallest distance between two points and looking for a fitting third.
|
---|
| 1316 | * \param *out output stream for debugging
|
---|
| 1317 | * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
|
---|
| 1318 | */
|
---|
[244a84] | 1319 | void Tesselation::GuessStartingTriangle()
|
---|
[357fba] | 1320 | {
|
---|
[6613ec] | 1321 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1322 | // 4b. create a starting triangle
|
---|
| 1323 | // 4b1. create all distances
|
---|
| 1324 | DistanceMultiMap DistanceMMap;
|
---|
| 1325 | double distance, tmp;
|
---|
| 1326 | Vector PlaneVector, TrialVector;
|
---|
| 1327 | PointMap::iterator A, B, C; // three nodes of the first triangle
|
---|
| 1328 | A = PointsOnBoundary.begin(); // the first may be chosen arbitrarily
|
---|
| 1329 |
|
---|
| 1330 | // with A chosen, take each pair B,C and sort
|
---|
[6613ec] | 1331 | if (A != PointsOnBoundary.end()) {
|
---|
| 1332 | B = A;
|
---|
| 1333 | B++;
|
---|
| 1334 | for (; B != PointsOnBoundary.end(); B++) {
|
---|
| 1335 | C = B;
|
---|
| 1336 | C++;
|
---|
| 1337 | for (; C != PointsOnBoundary.end(); C++) {
|
---|
[8cbb97] | 1338 | tmp = A->second->node->node->DistanceSquared(*B->second->node->node);
|
---|
[6613ec] | 1339 | distance = tmp * tmp;
|
---|
[8cbb97] | 1340 | tmp = A->second->node->node->DistanceSquared(*C->second->node->node);
|
---|
[6613ec] | 1341 | distance += tmp * tmp;
|
---|
[8cbb97] | 1342 | tmp = B->second->node->node->DistanceSquared(*C->second->node->node);
|
---|
[6613ec] | 1343 | distance += tmp * tmp;
|
---|
| 1344 | DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
|
---|
| 1345 | }
|
---|
[357fba] | 1346 | }
|
---|
[6613ec] | 1347 | }
|
---|
[357fba] | 1348 | // // listing distances
|
---|
[e138de] | 1349 | // Log() << Verbose(1) << "Listing DistanceMMap:";
|
---|
[357fba] | 1350 | // for(DistanceMultiMap::iterator runner = DistanceMMap.begin(); runner != DistanceMMap.end(); runner++) {
|
---|
[e138de] | 1351 | // Log() << Verbose(0) << " " << runner->first << "(" << *runner->second.first->second << ", " << *runner->second.second->second << ")";
|
---|
[357fba] | 1352 | // }
|
---|
[e138de] | 1353 | // Log() << Verbose(0) << endl;
|
---|
[357fba] | 1354 | // 4b2. pick three baselines forming a triangle
|
---|
| 1355 | // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 1356 | DistanceMultiMap::iterator baseline = DistanceMMap.begin();
|
---|
[6613ec] | 1357 | for (; baseline != DistanceMMap.end(); baseline++) {
|
---|
| 1358 | // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
---|
| 1359 | // 2. next, we have to check whether all points reside on only one side of the triangle
|
---|
| 1360 | // 3. construct plane vector
|
---|
[8cbb97] | 1361 | PlaneVector = Plane(*A->second->node->node,
|
---|
| 1362 | *baseline->second.first->second->node->node,
|
---|
| 1363 | *baseline->second.second->second->node->node).getNormal();
|
---|
[a67d19] | 1364 | DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl);
|
---|
[6613ec] | 1365 | // 4. loop over all points
|
---|
| 1366 | double sign = 0.;
|
---|
| 1367 | PointMap::iterator checker = PointsOnBoundary.begin();
|
---|
| 1368 | for (; checker != PointsOnBoundary.end(); checker++) {
|
---|
| 1369 | // (neglecting A,B,C)
|
---|
| 1370 | if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
|
---|
| 1371 | continue;
|
---|
| 1372 | // 4a. project onto plane vector
|
---|
[8cbb97] | 1373 | TrialVector = (*checker->second->node->node);
|
---|
| 1374 | TrialVector.SubtractVector(*A->second->node->node);
|
---|
| 1375 | distance = TrialVector.ScalarProduct(PlaneVector);
|
---|
[6613ec] | 1376 | if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
|
---|
| 1377 | continue;
|
---|
[68f03d] | 1378 | DoLog(2) && (Log() << Verbose(2) << "Projection of " << checker->second->node->getName() << " yields distance of " << distance << "." << endl);
|
---|
[6613ec] | 1379 | tmp = distance / fabs(distance);
|
---|
| 1380 | // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
|
---|
| 1381 | if ((sign != 0) && (tmp != sign)) {
|
---|
| 1382 | // 4c. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
[68f03d] | 1383 | DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->getName() << "," << baseline->second.first->second->node->getName() << "," << baseline->second.second->second->node->getName() << " leaves " << checker->second->node->getName() << " outside the convex hull." << endl);
|
---|
[6613ec] | 1384 | break;
|
---|
| 1385 | } else { // note the sign for later
|
---|
[68f03d] | 1386 | DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->getName() << "," << baseline->second.first->second->node->getName() << "," << baseline->second.second->second->node->getName() << " leave " << checker->second->node->getName() << " inside the convex hull." << endl);
|
---|
[6613ec] | 1387 | sign = tmp;
|
---|
| 1388 | }
|
---|
| 1389 | // 4d. Check whether the point is inside the triangle (check distance to each node
|
---|
[8cbb97] | 1390 | tmp = checker->second->node->node->DistanceSquared(*A->second->node->node);
|
---|
[6613ec] | 1391 | int innerpoint = 0;
|
---|
[8cbb97] | 1392 | if ((tmp < A->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(*baseline->second.second->second->node->node)))
|
---|
[6613ec] | 1393 | innerpoint++;
|
---|
[8cbb97] | 1394 | tmp = checker->second->node->node->DistanceSquared(*baseline->second.first->second->node->node);
|
---|
| 1395 | if ((tmp < baseline->second.first->second->node->node->DistanceSquared(*A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(*baseline->second.second->second->node->node)))
|
---|
[6613ec] | 1396 | innerpoint++;
|
---|
[8cbb97] | 1397 | tmp = checker->second->node->node->DistanceSquared(*baseline->second.second->second->node->node);
|
---|
| 1398 | if ((tmp < baseline->second.second->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(*A->second->node->node)))
|
---|
[6613ec] | 1399 | innerpoint++;
|
---|
| 1400 | // 4e. If so, break 4. loop and continue with next candidate in 1. loop
|
---|
| 1401 | if (innerpoint == 3)
|
---|
| 1402 | break;
|
---|
[357fba] | 1403 | }
|
---|
[6613ec] | 1404 | // 5. come this far, all on same side? Then break 1. loop and construct triangle
|
---|
| 1405 | if (checker == PointsOnBoundary.end()) {
|
---|
[a67d19] | 1406 | DoLog(2) && (Log() << Verbose(2) << "Looks like we have a candidate!" << endl);
|
---|
[6613ec] | 1407 | break;
|
---|
[357fba] | 1408 | }
|
---|
[6613ec] | 1409 | }
|
---|
| 1410 | if (baseline != DistanceMMap.end()) {
|
---|
| 1411 | BPS[0] = baseline->second.first->second;
|
---|
| 1412 | BPS[1] = baseline->second.second->second;
|
---|
| 1413 | BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1414 | BPS[0] = A->second;
|
---|
| 1415 | BPS[1] = baseline->second.second->second;
|
---|
| 1416 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1417 | BPS[0] = baseline->second.first->second;
|
---|
| 1418 | BPS[1] = A->second;
|
---|
| 1419 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1420 |
|
---|
| 1421 | // 4b3. insert created triangle
|
---|
| 1422 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 1423 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1424 | TrianglesOnBoundaryCount++;
|
---|
| 1425 | for (int i = 0; i < NDIM; i++) {
|
---|
| 1426 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
|
---|
| 1427 | LinesOnBoundaryCount++;
|
---|
[357fba] | 1428 | }
|
---|
[6613ec] | 1429 |
|
---|
[a67d19] | 1430 | DoLog(1) && (Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl);
|
---|
[6613ec] | 1431 | } else {
|
---|
| 1432 | DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl);
|
---|
| 1433 | }
|
---|
[357fba] | 1434 | }
|
---|
| 1435 | ;
|
---|
| 1436 |
|
---|
| 1437 | /** Tesselates the convex envelope of a cluster from a single starting triangle.
|
---|
| 1438 | * The starting triangle is made out of three baselines. Each line in the final tesselated cluster may belong to at most
|
---|
| 1439 | * 2 triangles. Hence, we go through all current lines:
|
---|
| 1440 | * -# if the lines contains to only one triangle
|
---|
| 1441 | * -# We search all points in the boundary
|
---|
| 1442 | * -# if the triangle is in forward direction of the baseline (at most 90 degrees angle between vector orthogonal to
|
---|
| 1443 | * baseline in triangle plane pointing out of the triangle and normal vector of new triangle)
|
---|
| 1444 | * -# if the triangle with the baseline and the current point has the smallest of angles (comparison between normal vectors)
|
---|
| 1445 | * -# then we have a new triangle, whose baselines we again add (or increase their TriangleCount)
|
---|
| 1446 | * \param *out output stream for debugging
|
---|
| 1447 | * \param *configuration for IsAngstroem
|
---|
| 1448 | * \param *cloud cluster of points
|
---|
| 1449 | */
|
---|
[e138de] | 1450 | void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
|
---|
[357fba] | 1451 | {
|
---|
[6613ec] | 1452 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1453 | bool flag;
|
---|
| 1454 | PointMap::iterator winner;
|
---|
| 1455 | class BoundaryPointSet *peak = NULL;
|
---|
| 1456 | double SmallestAngle, TempAngle;
|
---|
| 1457 | Vector NormalVector, VirtualNormalVector, CenterVector, TempVector, helper, PropagationVector, *Center = NULL;
|
---|
| 1458 | LineMap::iterator LineChecker[2];
|
---|
| 1459 |
|
---|
[e138de] | 1460 | Center = cloud->GetCenter();
|
---|
[357fba] | 1461 | // create a first tesselation with the given BoundaryPoints
|
---|
| 1462 | do {
|
---|
| 1463 | flag = false;
|
---|
| 1464 | for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++)
|
---|
[5c7bf8] | 1465 | if (baseline->second->triangles.size() == 1) {
|
---|
[357fba] | 1466 | // 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)
|
---|
| 1467 | SmallestAngle = M_PI;
|
---|
| 1468 |
|
---|
| 1469 | // get peak point with respect to this base line's only triangle
|
---|
| 1470 | BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
|
---|
[a67d19] | 1471 | DoLog(0) && (Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl);
|
---|
[357fba] | 1472 | for (int i = 0; i < 3; i++)
|
---|
| 1473 | if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
|
---|
| 1474 | peak = BTS->endpoints[i];
|
---|
[a67d19] | 1475 | DoLog(1) && (Log() << Verbose(1) << " and has peak " << *peak << "." << endl);
|
---|
[357fba] | 1476 |
|
---|
| 1477 | // prepare some auxiliary vectors
|
---|
| 1478 | Vector BaseLineCenter, BaseLine;
|
---|
[273382] | 1479 | BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) +
|
---|
| 1480 | (*baseline->second->endpoints[1]->node->node));
|
---|
| 1481 | BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node);
|
---|
[357fba] | 1482 |
|
---|
| 1483 | // offset to center of triangle
|
---|
| 1484 | CenterVector.Zero();
|
---|
| 1485 | for (int i = 0; i < 3; i++)
|
---|
[8f215d] | 1486 | CenterVector += BTS->getEndpoint(i);
|
---|
[357fba] | 1487 | CenterVector.Scale(1. / 3.);
|
---|
[a67d19] | 1488 | DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
|
---|
[357fba] | 1489 |
|
---|
| 1490 | // normal vector of triangle
|
---|
[273382] | 1491 | NormalVector = (*Center) - CenterVector;
|
---|
[357fba] | 1492 | BTS->GetNormalVector(NormalVector);
|
---|
[273382] | 1493 | NormalVector = BTS->NormalVector;
|
---|
[a67d19] | 1494 | DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl);
|
---|
[357fba] | 1495 |
|
---|
| 1496 | // vector in propagation direction (out of triangle)
|
---|
| 1497 | // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
|
---|
[0a4f7f] | 1498 | PropagationVector = Plane(BaseLine, NormalVector,0).getNormal();
|
---|
[273382] | 1499 | TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
|
---|
[f67b6e] | 1500 | //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
|
---|
[273382] | 1501 | if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline
|
---|
[357fba] | 1502 | PropagationVector.Scale(-1.);
|
---|
[a67d19] | 1503 | DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl);
|
---|
[357fba] | 1504 | winner = PointsOnBoundary.end();
|
---|
| 1505 |
|
---|
| 1506 | // loop over all points and calculate angle between normal vector of new and present triangle
|
---|
| 1507 | for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
|
---|
| 1508 | if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
|
---|
[a67d19] | 1509 | DoLog(1) && (Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl);
|
---|
[357fba] | 1510 |
|
---|
| 1511 | // first check direction, so that triangles don't intersect
|
---|
[273382] | 1512 | VirtualNormalVector = (*target->second->node->node) - BaseLineCenter;
|
---|
[8cbb97] | 1513 | VirtualNormalVector.ProjectOntoPlane(NormalVector);
|
---|
[273382] | 1514 | TempAngle = VirtualNormalVector.Angle(PropagationVector);
|
---|
[a67d19] | 1515 | DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl);
|
---|
[6613ec] | 1516 | if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
|
---|
[a67d19] | 1517 | DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl);
|
---|
[357fba] | 1518 | continue;
|
---|
| 1519 | } else
|
---|
[a67d19] | 1520 | DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl);
|
---|
[357fba] | 1521 |
|
---|
| 1522 | // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
|
---|
| 1523 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(target->first);
|
---|
| 1524 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
|
---|
[5c7bf8] | 1525 | if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
|
---|
[a67d19] | 1526 | DoLog(2) && (Log() << Verbose(2) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl);
|
---|
[357fba] | 1527 | continue;
|
---|
| 1528 | }
|
---|
[5c7bf8] | 1529 | if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
|
---|
[a67d19] | 1530 | DoLog(2) && (Log() << Verbose(2) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl);
|
---|
[357fba] | 1531 | continue;
|
---|
| 1532 | }
|
---|
| 1533 |
|
---|
| 1534 | // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
|
---|
| 1535 | if ((((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (GetCommonEndpoint(LineChecker[0]->second, LineChecker[1]->second) == peak)))) {
|
---|
[a67d19] | 1536 | DoLog(4) && (Log() << Verbose(4) << "Current target is peak!" << endl);
|
---|
[357fba] | 1537 | continue;
|
---|
| 1538 | }
|
---|
| 1539 |
|
---|
| 1540 | // check for linear dependence
|
---|
[273382] | 1541 | TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node);
|
---|
| 1542 | helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node);
|
---|
| 1543 | helper.ProjectOntoPlane(TempVector);
|
---|
[357fba] | 1544 | if (fabs(helper.NormSquared()) < MYEPSILON) {
|
---|
[a67d19] | 1545 | DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl);
|
---|
[357fba] | 1546 | continue;
|
---|
| 1547 | }
|
---|
| 1548 |
|
---|
| 1549 | // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
|
---|
| 1550 | flag = true;
|
---|
[0a4f7f] | 1551 | VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node),
|
---|
| 1552 | *(baseline->second->endpoints[1]->node->node),
|
---|
| 1553 | *(target->second->node->node)).getNormal();
|
---|
[273382] | 1554 | TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) +
|
---|
| 1555 | (*baseline->second->endpoints[1]->node->node) +
|
---|
| 1556 | (*target->second->node->node));
|
---|
| 1557 | TempVector -= (*Center);
|
---|
[357fba] | 1558 | // make it always point outward
|
---|
[273382] | 1559 | if (VirtualNormalVector.ScalarProduct(TempVector) < 0)
|
---|
[357fba] | 1560 | VirtualNormalVector.Scale(-1.);
|
---|
| 1561 | // calculate angle
|
---|
[273382] | 1562 | TempAngle = NormalVector.Angle(VirtualNormalVector);
|
---|
[a67d19] | 1563 | DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl);
|
---|
[357fba] | 1564 | if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
|
---|
| 1565 | SmallestAngle = TempAngle;
|
---|
| 1566 | winner = target;
|
---|
[a67d19] | 1567 | DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
|
---|
[357fba] | 1568 | } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
|
---|
| 1569 | // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
|
---|
[273382] | 1570 | helper = (*target->second->node->node) - BaseLineCenter;
|
---|
| 1571 | helper.ProjectOntoPlane(BaseLine);
|
---|
[357fba] | 1572 | // ...the one with the smaller angle is the better candidate
|
---|
[273382] | 1573 | TempVector = (*target->second->node->node) - BaseLineCenter;
|
---|
| 1574 | TempVector.ProjectOntoPlane(VirtualNormalVector);
|
---|
| 1575 | TempAngle = TempVector.Angle(helper);
|
---|
| 1576 | TempVector = (*winner->second->node->node) - BaseLineCenter;
|
---|
| 1577 | TempVector.ProjectOntoPlane(VirtualNormalVector);
|
---|
| 1578 | if (TempAngle < TempVector.Angle(helper)) {
|
---|
| 1579 | TempAngle = NormalVector.Angle(VirtualNormalVector);
|
---|
[357fba] | 1580 | SmallestAngle = TempAngle;
|
---|
| 1581 | winner = target;
|
---|
[a67d19] | 1582 | DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl);
|
---|
[357fba] | 1583 | } else
|
---|
[a67d19] | 1584 | DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl);
|
---|
[357fba] | 1585 | } else
|
---|
[a67d19] | 1586 | DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
|
---|
[357fba] | 1587 | }
|
---|
| 1588 | } // end of loop over all boundary points
|
---|
| 1589 |
|
---|
| 1590 | // 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
|
---|
| 1591 | if (winner != PointsOnBoundary.end()) {
|
---|
[a67d19] | 1592 | DoLog(0) && (Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl);
|
---|
[357fba] | 1593 | // create the lins of not yet present
|
---|
| 1594 | BLS[0] = baseline->second;
|
---|
| 1595 | // 5c. add lines to the line set if those were new (not yet part of a triangle), delete lines that belong to two triangles)
|
---|
| 1596 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(winner->first);
|
---|
| 1597 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(winner->first);
|
---|
| 1598 | if (LineChecker[0] == baseline->second->endpoints[0]->lines.end()) { // create
|
---|
| 1599 | BPS[0] = baseline->second->endpoints[0];
|
---|
| 1600 | BPS[1] = winner->second;
|
---|
| 1601 | BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1602 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[1]));
|
---|
| 1603 | LinesOnBoundaryCount++;
|
---|
| 1604 | } else
|
---|
| 1605 | BLS[1] = LineChecker[0]->second;
|
---|
| 1606 | if (LineChecker[1] == baseline->second->endpoints[1]->lines.end()) { // create
|
---|
| 1607 | BPS[0] = baseline->second->endpoints[1];
|
---|
| 1608 | BPS[1] = winner->second;
|
---|
| 1609 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
| 1610 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[2]));
|
---|
| 1611 | LinesOnBoundaryCount++;
|
---|
| 1612 | } else
|
---|
| 1613 | BLS[2] = LineChecker[1]->second;
|
---|
| 1614 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[62bb91] | 1615 | BTS->GetCenter(&helper);
|
---|
[273382] | 1616 | helper -= (*Center);
|
---|
| 1617 | helper *= -1;
|
---|
[62bb91] | 1618 | BTS->GetNormalVector(helper);
|
---|
[357fba] | 1619 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1620 | TrianglesOnBoundaryCount++;
|
---|
| 1621 | } else {
|
---|
[6613ec] | 1622 | DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);
|
---|
[357fba] | 1623 | }
|
---|
| 1624 |
|
---|
| 1625 | // 5d. If the set of lines is not yet empty, go to 5. and continue
|
---|
| 1626 | } else
|
---|
[a67d19] | 1627 | DoLog(0) && (Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl);
|
---|
[357fba] | 1628 | } while (flag);
|
---|
| 1629 |
|
---|
| 1630 | // exit
|
---|
[6613ec] | 1631 | delete (Center);
|
---|
| 1632 | }
|
---|
| 1633 | ;
|
---|
[357fba] | 1634 |
|
---|
[62bb91] | 1635 | /** Inserts all points outside of the tesselated surface into it by adding new triangles.
|
---|
[357fba] | 1636 | * \param *out output stream for debugging
|
---|
| 1637 | * \param *cloud cluster of points
|
---|
[62bb91] | 1638 | * \param *LC LinkedCell structure to find nearest point quickly
|
---|
[357fba] | 1639 | * \return true - all straddling points insert, false - something went wrong
|
---|
| 1640 | */
|
---|
[e138de] | 1641 | bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
|
---|
[357fba] | 1642 | {
|
---|
[6613ec] | 1643 | Info FunctionInfo(__func__);
|
---|
[5c7bf8] | 1644 | Vector Intersection, Normal;
|
---|
[357fba] | 1645 | TesselPoint *Walker = NULL;
|
---|
[e138de] | 1646 | Vector *Center = cloud->GetCenter();
|
---|
[c15ca2] | 1647 | TriangleList *triangles = NULL;
|
---|
[7dea7c] | 1648 | bool AddFlag = false;
|
---|
| 1649 | LinkedCell *BoundaryPoints = NULL;
|
---|
[62bb91] | 1650 |
|
---|
[357fba] | 1651 | cloud->GoToFirst();
|
---|
[7dea7c] | 1652 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
[6613ec] | 1653 | while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
|
---|
[7dea7c] | 1654 | if (AddFlag) {
|
---|
[6613ec] | 1655 | delete (BoundaryPoints);
|
---|
[7dea7c] | 1656 | BoundaryPoints = new LinkedCell(this, 5.);
|
---|
| 1657 | AddFlag = false;
|
---|
| 1658 | }
|
---|
[357fba] | 1659 | Walker = cloud->GetPoint();
|
---|
[a67d19] | 1660 | DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Walker << "." << endl);
|
---|
[357fba] | 1661 | // get the next triangle
|
---|
[c15ca2] | 1662 | triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
|
---|
[7dea7c] | 1663 | BTS = triangles->front();
|
---|
| 1664 | if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
|
---|
[a67d19] | 1665 | DoLog(0) && (Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl);
|
---|
[62bb91] | 1666 | cloud->GoToNext();
|
---|
| 1667 | continue;
|
---|
| 1668 | } else {
|
---|
[357fba] | 1669 | }
|
---|
[a67d19] | 1670 | DoLog(0) && (Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl);
|
---|
[357fba] | 1671 | // get the intersection point
|
---|
[e138de] | 1672 | if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
|
---|
[a67d19] | 1673 | DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl);
|
---|
[357fba] | 1674 | // we have the intersection, check whether in- or outside of boundary
|
---|
[273382] | 1675 | if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) {
|
---|
[357fba] | 1676 | // inside, next!
|
---|
[a67d19] | 1677 | DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1678 | } else {
|
---|
| 1679 | // outside!
|
---|
[a67d19] | 1680 | DoLog(0) && (Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1681 | class BoundaryLineSet *OldLines[3], *NewLines[3];
|
---|
| 1682 | class BoundaryPointSet *OldPoints[3], *NewPoint;
|
---|
| 1683 | // store the three old lines and old points
|
---|
[6613ec] | 1684 | for (int i = 0; i < 3; i++) {
|
---|
[357fba] | 1685 | OldLines[i] = BTS->lines[i];
|
---|
| 1686 | OldPoints[i] = BTS->endpoints[i];
|
---|
| 1687 | }
|
---|
[273382] | 1688 | Normal = BTS->NormalVector;
|
---|
[357fba] | 1689 | // add Walker to boundary points
|
---|
[a67d19] | 1690 | DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl);
|
---|
[7dea7c] | 1691 | AddFlag = true;
|
---|
[6613ec] | 1692 | if (AddBoundaryPoint(Walker, 0))
|
---|
[357fba] | 1693 | NewPoint = BPS[0];
|
---|
| 1694 | else
|
---|
| 1695 | continue;
|
---|
| 1696 | // remove triangle
|
---|
[a67d19] | 1697 | DoLog(0) && (Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1698 | TrianglesOnBoundary.erase(BTS->Nr);
|
---|
[6613ec] | 1699 | delete (BTS);
|
---|
[357fba] | 1700 | // create three new boundary lines
|
---|
[6613ec] | 1701 | for (int i = 0; i < 3; i++) {
|
---|
[357fba] | 1702 | BPS[0] = NewPoint;
|
---|
| 1703 | BPS[1] = OldPoints[i];
|
---|
| 1704 | NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
---|
[a67d19] | 1705 | DoLog(1) && (Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl);
|
---|
[357fba] | 1706 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
|
---|
| 1707 | LinesOnBoundaryCount++;
|
---|
| 1708 | }
|
---|
| 1709 | // create three new triangle with new point
|
---|
[6613ec] | 1710 | for (int i = 0; i < 3; i++) { // find all baselines
|
---|
[357fba] | 1711 | BLS[0] = OldLines[i];
|
---|
| 1712 | int n = 1;
|
---|
[6613ec] | 1713 | for (int j = 0; j < 3; j++) {
|
---|
[357fba] | 1714 | if (NewLines[j]->IsConnectedTo(BLS[0])) {
|
---|
[6613ec] | 1715 | if (n > 2) {
|
---|
| 1716 | DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);
|
---|
[357fba] | 1717 | return false;
|
---|
| 1718 | } else
|
---|
| 1719 | BLS[n++] = NewLines[j];
|
---|
| 1720 | }
|
---|
| 1721 | }
|
---|
| 1722 | // create the triangle
|
---|
| 1723 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[5c7bf8] | 1724 | Normal.Scale(-1.);
|
---|
| 1725 | BTS->GetNormalVector(Normal);
|
---|
| 1726 | Normal.Scale(-1.);
|
---|
[a67d19] | 1727 | DoLog(0) && (Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl);
|
---|
[357fba] | 1728 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1729 | TrianglesOnBoundaryCount++;
|
---|
| 1730 | }
|
---|
| 1731 | }
|
---|
| 1732 | } else { // something is wrong with FindClosestTriangleToPoint!
|
---|
[6613ec] | 1733 | DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl);
|
---|
[357fba] | 1734 | return false;
|
---|
| 1735 | }
|
---|
| 1736 | cloud->GoToNext();
|
---|
| 1737 | }
|
---|
| 1738 |
|
---|
| 1739 | // exit
|
---|
[6613ec] | 1740 | delete (Center);
|
---|
[357fba] | 1741 | return true;
|
---|
[6613ec] | 1742 | }
|
---|
| 1743 | ;
|
---|
[357fba] | 1744 |
|
---|
[16d866] | 1745 | /** Adds a point to the tesselation::PointsOnBoundary list.
|
---|
[62bb91] | 1746 | * \param *Walker point to add
|
---|
[08ef35] | 1747 | * \param n TesselStruct::BPS index to put pointer into
|
---|
| 1748 | * \return true - new point was added, false - point already present
|
---|
[357fba] | 1749 | */
|
---|
[776b64] | 1750 | bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
|
---|
[357fba] | 1751 | {
|
---|
[6613ec] | 1752 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1753 | PointTestPair InsertUnique;
|
---|
[08ef35] | 1754 | BPS[n] = new class BoundaryPointSet(Walker);
|
---|
| 1755 | InsertUnique = PointsOnBoundary.insert(PointPair(Walker->nr, BPS[n]));
|
---|
| 1756 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
[357fba] | 1757 | PointsOnBoundaryCount++;
|
---|
[08ef35] | 1758 | return true;
|
---|
| 1759 | } else {
|
---|
[6613ec] | 1760 | delete (BPS[n]);
|
---|
[08ef35] | 1761 | BPS[n] = InsertUnique.first->second;
|
---|
| 1762 | return false;
|
---|
[357fba] | 1763 | }
|
---|
| 1764 | }
|
---|
| 1765 | ;
|
---|
| 1766 |
|
---|
| 1767 | /** Adds point to Tesselation::PointsOnBoundary if not yet present.
|
---|
| 1768 | * Tesselation::TPS is set to either this new BoundaryPointSet or to the existing one of not unique.
|
---|
| 1769 | * @param Candidate point to add
|
---|
| 1770 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1771 | */
|
---|
[776b64] | 1772 | void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
|
---|
[357fba] | 1773 | {
|
---|
[6613ec] | 1774 | Info FunctionInfo(__func__);
|
---|
[357fba] | 1775 | PointTestPair InsertUnique;
|
---|
| 1776 | TPS[n] = new class BoundaryPointSet(Candidate);
|
---|
| 1777 | InsertUnique = PointsOnBoundary.insert(PointPair(Candidate->nr, TPS[n]));
|
---|
| 1778 | if (InsertUnique.second) { // if new point was not present before, increase counter
|
---|
| 1779 | PointsOnBoundaryCount++;
|
---|
| 1780 | } else {
|
---|
| 1781 | delete TPS[n];
|
---|
[a67d19] | 1782 | DoLog(0) && (Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl);
|
---|
[357fba] | 1783 | TPS[n] = (InsertUnique.first)->second;
|
---|
| 1784 | }
|
---|
| 1785 | }
|
---|
| 1786 | ;
|
---|
| 1787 |
|
---|
[f1ef60a] | 1788 | /** Sets point to a present Tesselation::PointsOnBoundary.
|
---|
| 1789 | * Tesselation::TPS is set to the existing one or NULL if not found.
|
---|
| 1790 | * @param Candidate point to set to
|
---|
| 1791 | * @param n index for this point in Tesselation::TPS array
|
---|
| 1792 | */
|
---|
| 1793 | void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
|
---|
| 1794 | {
|
---|
[6613ec] | 1795 | Info FunctionInfo(__func__);
|
---|
[f1ef60a] | 1796 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
|
---|
| 1797 | if (FindPoint != PointsOnBoundary.end())
|
---|
| 1798 | TPS[n] = FindPoint->second;
|
---|
| 1799 | else
|
---|
| 1800 | TPS[n] = NULL;
|
---|
[6613ec] | 1801 | }
|
---|
| 1802 | ;
|
---|
[f1ef60a] | 1803 |
|
---|
[357fba] | 1804 | /** Function tries to add line from current Points in BPS to BoundaryLineSet.
|
---|
| 1805 | * If successful it raises the line count and inserts the new line into the BLS,
|
---|
| 1806 | * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
|
---|
[f07f86d] | 1807 | * @param *OptCenter desired OptCenter if there are more than one candidate line
|
---|
[d5fea7] | 1808 | * @param *candidate third point of the triangle to be, for checking between multiple open line candidates
|
---|
[357fba] | 1809 | * @param *a first endpoint
|
---|
| 1810 | * @param *b second endpoint
|
---|
| 1811 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1812 | */
|
---|
[6613ec] | 1813 | void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
|
---|
| 1814 | {
|
---|
[357fba] | 1815 | bool insertNewLine = true;
|
---|
[b998c3] | 1816 | LineMap::iterator FindLine = a->lines.find(b->node->nr);
|
---|
[d5fea7] | 1817 | BoundaryLineSet *WinningLine = NULL;
|
---|
[b998c3] | 1818 | if (FindLine != a->lines.end()) {
|
---|
[a67d19] | 1819 | DoLog(1) && (Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl);
|
---|
[b998c3] | 1820 |
|
---|
[6613ec] | 1821 | pair<LineMap::iterator, LineMap::iterator> FindPair;
|
---|
[357fba] | 1822 | FindPair = a->lines.equal_range(b->node->nr);
|
---|
| 1823 |
|
---|
[6613ec] | 1824 | for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) {
|
---|
[a67d19] | 1825 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
|
---|
[357fba] | 1826 | // If there is a line with less than two attached triangles, we don't need a new line.
|
---|
[d5fea7] | 1827 | if (FindLine->second->triangles.size() == 1) {
|
---|
| 1828 | CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
|
---|
[f07f86d] | 1829 | if (!Finder->second->pointlist.empty())
|
---|
[a67d19] | 1830 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
|
---|
[f07f86d] | 1831 | else
|
---|
[a67d19] | 1832 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl);
|
---|
[f07f86d] | 1833 | // get open line
|
---|
[6613ec] | 1834 | for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
|
---|
[8cbb97] | 1835 | if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
|
---|
[b0a5f1] | 1836 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl);
|
---|
[6613ec] | 1837 | insertNewLine = false;
|
---|
| 1838 | WinningLine = FindLine->second;
|
---|
| 1839 | break;
|
---|
[b0a5f1] | 1840 | } else {
|
---|
| 1841 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *(*CandidateChecker) << "'s center " << Finder->second->OptCenter << " does not match desired on " << *OptCenter << "." << endl);
|
---|
[6613ec] | 1842 | }
|
---|
[856098] | 1843 | }
|
---|
[357fba] | 1844 | }
|
---|
| 1845 | }
|
---|
| 1846 | }
|
---|
| 1847 |
|
---|
| 1848 | if (insertNewLine) {
|
---|
[474961] | 1849 | AddNewTesselationTriangleLine(a, b, n);
|
---|
[d5fea7] | 1850 | } else {
|
---|
| 1851 | AddExistingTesselationTriangleLine(WinningLine, n);
|
---|
[357fba] | 1852 | }
|
---|
| 1853 | }
|
---|
| 1854 | ;
|
---|
| 1855 |
|
---|
| 1856 | /**
|
---|
| 1857 | * Adds lines from each of the current points in the BPS to BoundaryLineSet.
|
---|
| 1858 | * Raises the line count and inserts the new line into the BLS.
|
---|
| 1859 | *
|
---|
| 1860 | * @param *a first endpoint
|
---|
| 1861 | * @param *b second endpoint
|
---|
| 1862 | * @param n index of Tesselation::BLS giving the line with both endpoints
|
---|
| 1863 | */
|
---|
[474961] | 1864 | void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
|
---|
[357fba] | 1865 | {
|
---|
[6613ec] | 1866 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1867 | DoLog(0) && (Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl);
|
---|
[357fba] | 1868 | BPS[0] = a;
|
---|
| 1869 | BPS[1] = b;
|
---|
[6613ec] | 1870 | BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
|
---|
[357fba] | 1871 | // add line to global map
|
---|
| 1872 | LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
|
---|
| 1873 | // increase counter
|
---|
| 1874 | LinesOnBoundaryCount++;
|
---|
[1e168b] | 1875 | // also add to open lines
|
---|
| 1876 | CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
|
---|
[6613ec] | 1877 | OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
|
---|
| 1878 | }
|
---|
| 1879 | ;
|
---|
[357fba] | 1880 |
|
---|
[474961] | 1881 | /** Uses an existing line for a new triangle.
|
---|
| 1882 | * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines.
|
---|
| 1883 | * \param *FindLine the line to add
|
---|
| 1884 | * \param n index of the line to set in Tesselation::BLS
|
---|
| 1885 | */
|
---|
| 1886 | void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n)
|
---|
| 1887 | {
|
---|
| 1888 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1889 | DoLog(0) && (Log() << Verbose(0) << "Using existing line " << *Line << endl);
|
---|
[474961] | 1890 |
|
---|
| 1891 | // set endpoints and line
|
---|
| 1892 | BPS[0] = Line->endpoints[0];
|
---|
| 1893 | BPS[1] = Line->endpoints[1];
|
---|
| 1894 | BLS[n] = Line;
|
---|
| 1895 | // remove existing line from OpenLines
|
---|
| 1896 | CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
|
---|
| 1897 | if (CandidateLine != OpenLines.end()) {
|
---|
[a67d19] | 1898 | DoLog(1) && (Log() << Verbose(1) << " Removing line from OpenLines." << endl);
|
---|
[6613ec] | 1899 | delete (CandidateLine->second);
|
---|
[474961] | 1900 | OpenLines.erase(CandidateLine);
|
---|
| 1901 | } else {
|
---|
[6613ec] | 1902 | DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
|
---|
[474961] | 1903 | }
|
---|
[6613ec] | 1904 | }
|
---|
| 1905 | ;
|
---|
[357fba] | 1906 |
|
---|
[7dea7c] | 1907 | /** Function adds triangle to global list.
|
---|
| 1908 | * Furthermore, the triangle receives the next free id and id counter \a TrianglesOnBoundaryCount is increased.
|
---|
[357fba] | 1909 | */
|
---|
[16d866] | 1910 | void Tesselation::AddTesselationTriangle()
|
---|
[357fba] | 1911 | {
|
---|
[6613ec] | 1912 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1913 | DoLog(1) && (Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl);
|
---|
[357fba] | 1914 |
|
---|
| 1915 | // add triangle to global map
|
---|
| 1916 | TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
|
---|
| 1917 | TrianglesOnBoundaryCount++;
|
---|
| 1918 |
|
---|
[57066a] | 1919 | // set as last new triangle
|
---|
| 1920 | LastTriangle = BTS;
|
---|
| 1921 |
|
---|
[357fba] | 1922 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
[6613ec] | 1923 | }
|
---|
| 1924 | ;
|
---|
[16d866] | 1925 |
|
---|
[7dea7c] | 1926 | /** Function adds triangle to global list.
|
---|
| 1927 | * Furthermore, the triangle number is set to \a nr.
|
---|
| 1928 | * \param nr triangle number
|
---|
| 1929 | */
|
---|
[776b64] | 1930 | void Tesselation::AddTesselationTriangle(const int nr)
|
---|
[7dea7c] | 1931 | {
|
---|
[6613ec] | 1932 | Info FunctionInfo(__func__);
|
---|
[a67d19] | 1933 | DoLog(0) && (Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl);
|
---|
[7dea7c] | 1934 |
|
---|
| 1935 | // add triangle to global map
|
---|
| 1936 | TrianglesOnBoundary.insert(TrianglePair(nr, BTS));
|
---|
| 1937 |
|
---|
| 1938 | // set as last new triangle
|
---|
| 1939 | LastTriangle = BTS;
|
---|
| 1940 |
|
---|
| 1941 | // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
|
---|
[6613ec] | 1942 | }
|
---|
| 1943 | ;
|
---|
[7dea7c] | 1944 |
|
---|
[16d866] | 1945 | /** Removes a triangle from the tesselation.
|
---|
| 1946 | * Removes itself from the TriangleMap's of its lines, calls for them RemoveTriangleLine() if they are no more connected.
|
---|
| 1947 | * Removes itself from memory.
|
---|
| 1948 | * \param *triangle to remove
|
---|
| 1949 | */
|
---|
| 1950 | void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
|
---|
| 1951 | {
|
---|
[6613ec] | 1952 | Info FunctionInfo(__func__);
|
---|
[16d866] | 1953 | if (triangle == NULL)
|
---|
| 1954 | return;
|
---|
| 1955 | for (int i = 0; i < 3; i++) {
|
---|
| 1956 | if (triangle->lines[i] != NULL) {
|
---|
[a67d19] | 1957 | DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl);
|
---|
[16d866] | 1958 | triangle->lines[i]->triangles.erase(triangle->Nr);
|
---|
| 1959 | if (triangle->lines[i]->triangles.empty()) {
|
---|
[a67d19] | 1960 | DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl);
|
---|
[6613ec] | 1961 | RemoveTesselationLine(triangle->lines[i]);
|
---|
[065e82] | 1962 | } else {
|
---|
[accebe] | 1963 | DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: " << endl);
|
---|
[6613ec] | 1964 | OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
|
---|
| 1965 | for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
|
---|
[accebe] | 1966 | DoLog(0) && (Log() << Verbose(0) << "\t[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t");
|
---|
[a67d19] | 1967 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[6613ec] | 1968 | // for (int j=0;j<2;j++) {
|
---|
| 1969 | // Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
|
---|
| 1970 | // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
|
---|
| 1971 | // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
|
---|
| 1972 | // Log() << Verbose(0) << endl;
|
---|
| 1973 | // }
|
---|
[065e82] | 1974 | }
|
---|
[6613ec] | 1975 | triangle->lines[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 1976 | } else
|
---|
[6613ec] | 1977 | DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl);
|
---|
[16d866] | 1978 | }
|
---|
| 1979 |
|
---|
| 1980 | if (TrianglesOnBoundary.erase(triangle->Nr))
|
---|
[a67d19] | 1981 | DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl);
|
---|
[6613ec] | 1982 | delete (triangle);
|
---|
| 1983 | }
|
---|
| 1984 | ;
|
---|
[16d866] | 1985 |
|
---|
| 1986 | /** Removes a line from the tesselation.
|
---|
| 1987 | * Removes itself from each endpoints' LineMap, then removes itself from global LinesOnBoundary list and free's the line.
|
---|
| 1988 | * \param *line line to remove
|
---|
| 1989 | */
|
---|
| 1990 | void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
|
---|
| 1991 | {
|
---|
[6613ec] | 1992 | Info FunctionInfo(__func__);
|
---|
[16d866] | 1993 | int Numbers[2];
|
---|
| 1994 |
|
---|
| 1995 | if (line == NULL)
|
---|
| 1996 | return;
|
---|
[065e82] | 1997 | // get other endpoint number for finding copies of same line
|
---|
[16d866] | 1998 | if (line->endpoints[1] != NULL)
|
---|
| 1999 | Numbers[0] = line->endpoints[1]->Nr;
|
---|
| 2000 | else
|
---|
| 2001 | Numbers[0] = -1;
|
---|
| 2002 | if (line->endpoints[0] != NULL)
|
---|
| 2003 | Numbers[1] = line->endpoints[0]->Nr;
|
---|
| 2004 | else
|
---|
| 2005 | Numbers[1] = -1;
|
---|
| 2006 |
|
---|
| 2007 | for (int i = 0; i < 2; i++) {
|
---|
| 2008 | if (line->endpoints[i] != NULL) {
|
---|
| 2009 | 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
|
---|
| 2010 | pair<LineMap::iterator, LineMap::iterator> erasor = line->endpoints[i]->lines.equal_range(Numbers[i]);
|
---|
| 2011 | for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
|
---|
| 2012 | if ((*Runner).second == line) {
|
---|
[a67d19] | 2013 | DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
|
---|
[16d866] | 2014 | line->endpoints[i]->lines.erase(Runner);
|
---|
| 2015 | break;
|
---|
| 2016 | }
|
---|
| 2017 | } else { // there's just a single line left
|
---|
| 2018 | if (line->endpoints[i]->lines.erase(line->Nr))
|
---|
[a67d19] | 2019 | DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
|
---|
[16d866] | 2020 | }
|
---|
| 2021 | if (line->endpoints[i]->lines.empty()) {
|
---|
[a67d19] | 2022 | DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl);
|
---|
[16d866] | 2023 | RemoveTesselationPoint(line->endpoints[i]);
|
---|
[065e82] | 2024 | } else {
|
---|
[a67d19] | 2025 | DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ");
|
---|
[6613ec] | 2026 | for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
|
---|
[a67d19] | 2027 | DoLog(0) && (Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t");
|
---|
| 2028 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[065e82] | 2029 | }
|
---|
[6613ec] | 2030 | line->endpoints[i] = NULL; // free'd or not: disconnect
|
---|
[16d866] | 2031 | } else
|
---|
[6613ec] | 2032 | DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);
|
---|
[16d866] | 2033 | }
|
---|
| 2034 | if (!line->triangles.empty())
|
---|
[6613ec] | 2035 | DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);
|
---|
[16d866] | 2036 |
|
---|
| 2037 | if (LinesOnBoundary.erase(line->Nr))
|
---|
[a67d19] | 2038 | DoLog(0) && (Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl);
|
---|
[6613ec] | 2039 | delete (line);
|
---|
| 2040 | }
|
---|
| 2041 | ;
|
---|
[16d866] | 2042 |
|
---|
| 2043 | /** Removes a point from the tesselation.
|
---|
| 2044 | * Checks whether there are still lines connected, removes from global PointsOnBoundary list, then free's the point.
|
---|
| 2045 | * \note If a point should be removed, while keep the tesselated surface intact (i.e. closed), use RemovePointFromTesselatedSurface()
|
---|
| 2046 | * \param *point point to remove
|
---|
| 2047 | */
|
---|
| 2048 | void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
|
---|
| 2049 | {
|
---|
[6613ec] | 2050 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2051 | if (point == NULL)
|
---|
| 2052 | return;
|
---|
| 2053 | if (PointsOnBoundary.erase(point->Nr))
|
---|
[a67d19] | 2054 | DoLog(0) && (Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl);
|
---|
[6613ec] | 2055 | delete (point);
|
---|
| 2056 | }
|
---|
| 2057 | ;
|
---|
[f07f86d] | 2058 |
|
---|
| 2059 | /** Checks validity of a given sphere of a candidate line.
|
---|
| 2060 | * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
|
---|
[6613ec] | 2061 | * We check CandidateForTesselation::OtherOptCenter
|
---|
| 2062 | * \param &CandidateLine contains other degenerated candidates which we have to subtract as well
|
---|
[f07f86d] | 2063 | * \param RADIUS radius of sphere
|
---|
| 2064 | * \param *LC LinkedCell structure with other atoms
|
---|
| 2065 | * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
|
---|
| 2066 | */
|
---|
[6613ec] | 2067 | bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const
|
---|
[f07f86d] | 2068 | {
|
---|
| 2069 | Info FunctionInfo(__func__);
|
---|
| 2070 |
|
---|
| 2071 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
|
---|
| 2072 | bool flag = true;
|
---|
| 2073 |
|
---|
[8cbb97] | 2074 | DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30" << endl);
|
---|
[f07f86d] | 2075 | // get all points inside the sphere
|
---|
[6613ec] | 2076 | TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
|
---|
[f07f86d] | 2077 |
|
---|
[a67d19] | 2078 | DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
|
---|
[f07f86d] | 2079 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[1513a74] | 2080 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(CandidateLine.OtherOptCenter) << "." << endl);
|
---|
[f07f86d] | 2081 |
|
---|
| 2082 | // remove triangles's endpoints
|
---|
[6613ec] | 2083 | for (int i = 0; i < 2; i++)
|
---|
| 2084 | ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node);
|
---|
| 2085 |
|
---|
| 2086 | // remove other candidates
|
---|
| 2087 | for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner)
|
---|
| 2088 | ListofPoints->remove(*Runner);
|
---|
[f07f86d] | 2089 |
|
---|
| 2090 | // check for other points
|
---|
| 2091 | if (!ListofPoints->empty()) {
|
---|
[a67d19] | 2092 | DoLog(1) && (Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
|
---|
[f07f86d] | 2093 | flag = false;
|
---|
[a67d19] | 2094 | DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
|
---|
[f07f86d] | 2095 | for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
|
---|
[1513a74] | 2096 | DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(CandidateLine.OtherOptCenter) << "." << endl);
|
---|
[f07f86d] | 2097 | }
|
---|
[6613ec] | 2098 | delete (ListofPoints);
|
---|
[f07f86d] | 2099 |
|
---|
| 2100 | return flag;
|
---|
[6613ec] | 2101 | }
|
---|
| 2102 | ;
|
---|
[357fba] | 2103 |
|
---|
[62bb91] | 2104 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
[357fba] | 2105 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 2106 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 2107 | * returned.
|
---|
| 2108 | * \param *out output stream for debugging
|
---|
| 2109 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 2110 | * \return integer 0 if no triangle exists, 1 if one triangle exists, 2 if two
|
---|
| 2111 | * triangles exist which is the maximum for three points
|
---|
| 2112 | */
|
---|
[f1ef60a] | 2113 | int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
|
---|
| 2114 | {
|
---|
[6613ec] | 2115 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2116 | int adjacentTriangleCount = 0;
|
---|
| 2117 | class BoundaryPointSet *Points[3];
|
---|
| 2118 |
|
---|
| 2119 | // builds a triangle point set (Points) of the end points
|
---|
| 2120 | for (int i = 0; i < 3; i++) {
|
---|
[f1ef60a] | 2121 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
[357fba] | 2122 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2123 | Points[i] = FindPoint->second;
|
---|
| 2124 | } else {
|
---|
| 2125 | Points[i] = NULL;
|
---|
| 2126 | }
|
---|
| 2127 | }
|
---|
| 2128 |
|
---|
| 2129 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 2130 | for (int i = 0; i < 3; i++) {
|
---|
| 2131 | if (Points[i] != NULL) {
|
---|
| 2132 | for (int j = i; j < 3; j++) {
|
---|
| 2133 | if (Points[j] != NULL) {
|
---|
[f1ef60a] | 2134 | LineMap::const_iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
[357fba] | 2135 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 2136 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
[a67d19] | 2137 | DoLog(1) && (Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl);
|
---|
[f1ef60a] | 2138 | for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
[357fba] | 2139 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 2140 | adjacentTriangleCount++;
|
---|
| 2141 | }
|
---|
| 2142 | }
|
---|
[a67d19] | 2143 | DoLog(1) && (Log() << Verbose(1) << "end." << endl);
|
---|
[357fba] | 2144 | }
|
---|
| 2145 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[f67b6e] | 2146 | //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 2147 | //return adjacentTriangleCount;
|
---|
[357fba] | 2148 | }
|
---|
| 2149 | }
|
---|
| 2150 | }
|
---|
| 2151 | }
|
---|
| 2152 |
|
---|
[a67d19] | 2153 | DoLog(0) && (Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl);
|
---|
[357fba] | 2154 | return adjacentTriangleCount;
|
---|
[6613ec] | 2155 | }
|
---|
| 2156 | ;
|
---|
[357fba] | 2157 |
|
---|
[065e82] | 2158 | /** Checks whether the triangle consisting of the three points is already present.
|
---|
| 2159 | * Searches for the points in Tesselation::PointsOnBoundary and checks their
|
---|
| 2160 | * lines. If any of the three edges already has two triangles attached, false is
|
---|
| 2161 | * returned.
|
---|
| 2162 | * \param *out output stream for debugging
|
---|
| 2163 | * \param *Candidates endpoints of the triangle candidate
|
---|
| 2164 | * \return NULL - none found or pointer to triangle
|
---|
| 2165 | */
|
---|
[e138de] | 2166 | class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
|
---|
[065e82] | 2167 | {
|
---|
[6613ec] | 2168 | Info FunctionInfo(__func__);
|
---|
[065e82] | 2169 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 2170 | class BoundaryPointSet *Points[3];
|
---|
| 2171 |
|
---|
| 2172 | // builds a triangle point set (Points) of the end points
|
---|
| 2173 | for (int i = 0; i < 3; i++) {
|
---|
| 2174 | PointMap::iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
|
---|
| 2175 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2176 | Points[i] = FindPoint->second;
|
---|
| 2177 | } else {
|
---|
| 2178 | Points[i] = NULL;
|
---|
| 2179 | }
|
---|
| 2180 | }
|
---|
| 2181 |
|
---|
| 2182 | // checks lines between the points in the Points for their adjacent triangles
|
---|
| 2183 | for (int i = 0; i < 3; i++) {
|
---|
| 2184 | if (Points[i] != NULL) {
|
---|
| 2185 | for (int j = i; j < 3; j++) {
|
---|
| 2186 | if (Points[j] != NULL) {
|
---|
| 2187 | LineMap::iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
|
---|
| 2188 | for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
|
---|
| 2189 | TriangleMap *triangles = &FindLine->second->triangles;
|
---|
| 2190 | for (TriangleMap::iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
|
---|
| 2191 | if (FindTriangle->second->IsPresentTupel(Points)) {
|
---|
| 2192 | if ((triangle == NULL) || (triangle->Nr > FindTriangle->second->Nr))
|
---|
| 2193 | triangle = FindTriangle->second;
|
---|
| 2194 | }
|
---|
| 2195 | }
|
---|
| 2196 | }
|
---|
| 2197 | // Only one of the triangle lines must be considered for the triangle count.
|
---|
[f67b6e] | 2198 | //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
|
---|
[065e82] | 2199 | //return adjacentTriangleCount;
|
---|
| 2200 | }
|
---|
| 2201 | }
|
---|
| 2202 | }
|
---|
| 2203 | }
|
---|
| 2204 |
|
---|
| 2205 | return triangle;
|
---|
[6613ec] | 2206 | }
|
---|
| 2207 | ;
|
---|
[357fba] | 2208 |
|
---|
[f1cccd] | 2209 | /** Finds the starting triangle for FindNonConvexBorder().
|
---|
| 2210 | * Looks at the outermost point per axis, then FindSecondPointForTesselation()
|
---|
| 2211 | * for the second and FindNextSuitablePointViaAngleOfSphere() for the third
|
---|
[357fba] | 2212 | * point are called.
|
---|
| 2213 | * \param *out output stream for debugging
|
---|
| 2214 | * \param RADIUS radius of virtual rolling sphere
|
---|
| 2215 | * \param *LC LinkedCell structure with neighbouring TesselPoint's
|
---|
[ce70970] | 2216 | * \return true - a starting triangle has been created, false - no valid triple of points found
|
---|
[357fba] | 2217 | */
|
---|
[ce70970] | 2218 | bool Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2219 | {
|
---|
[6613ec] | 2220 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2221 | int i = 0;
|
---|
[62bb91] | 2222 | TesselPoint* MaxPoint[NDIM];
|
---|
[7273fc] | 2223 | TesselPoint* Temporary;
|
---|
[f1cccd] | 2224 | double maxCoordinate[NDIM];
|
---|
[f07f86d] | 2225 | BoundaryLineSet *BaseLine = NULL;
|
---|
[357fba] | 2226 | Vector helper;
|
---|
| 2227 | Vector Chord;
|
---|
| 2228 | Vector SearchDirection;
|
---|
[6613ec] | 2229 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
[b998c3] | 2230 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 2231 | Vector SphereCenter;
|
---|
| 2232 | Vector NormalVector;
|
---|
[357fba] | 2233 |
|
---|
[b998c3] | 2234 | NormalVector.Zero();
|
---|
[357fba] | 2235 |
|
---|
| 2236 | for (i = 0; i < 3; i++) {
|
---|
[62bb91] | 2237 | MaxPoint[i] = NULL;
|
---|
[f1cccd] | 2238 | maxCoordinate[i] = -1;
|
---|
[357fba] | 2239 | }
|
---|
| 2240 |
|
---|
[62bb91] | 2241 | // 1. searching topmost point with respect to each axis
|
---|
[6613ec] | 2242 | for (int i = 0; i < NDIM; i++) { // each axis
|
---|
| 2243 | LC->n[i] = LC->N[i] - 1; // current axis is topmost cell
|
---|
| 2244 | for (LC->n[(i + 1) % NDIM] = 0; LC->n[(i + 1) % NDIM] < LC->N[(i + 1) % NDIM]; LC->n[(i + 1) % NDIM]++)
|
---|
| 2245 | for (LC->n[(i + 2) % NDIM] = 0; LC->n[(i + 2) % NDIM] < LC->N[(i + 2) % NDIM]; LC->n[(i + 2) % NDIM]++) {
|
---|
[734816] | 2246 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 2247 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 2248 | if (List != NULL) {
|
---|
[6613ec] | 2249 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[0a4f7f] | 2250 | if ((*Runner)->node->at(i) > maxCoordinate[i]) {
|
---|
[a67d19] | 2251 | DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl);
|
---|
[0a4f7f] | 2252 | maxCoordinate[i] = (*Runner)->node->at(i);
|
---|
[62bb91] | 2253 | MaxPoint[i] = (*Runner);
|
---|
[357fba] | 2254 | }
|
---|
| 2255 | }
|
---|
| 2256 | } else {
|
---|
[6613ec] | 2257 | DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
|
---|
[357fba] | 2258 | }
|
---|
| 2259 | }
|
---|
| 2260 | }
|
---|
| 2261 |
|
---|
[a67d19] | 2262 | DoLog(1) && (Log() << Verbose(1) << "Found maximum coordinates: ");
|
---|
[6613ec] | 2263 | for (int i = 0; i < NDIM; i++)
|
---|
[a67d19] | 2264 | DoLog(0) && (Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t");
|
---|
| 2265 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[357fba] | 2266 |
|
---|
| 2267 | BTS = NULL;
|
---|
[6613ec] | 2268 | for (int k = 0; k < NDIM; k++) {
|
---|
[b998c3] | 2269 | NormalVector.Zero();
|
---|
[0a4f7f] | 2270 | NormalVector[k] = 1.;
|
---|
[f07f86d] | 2271 | BaseLine = new BoundaryLineSet();
|
---|
| 2272 | BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
|
---|
[a67d19] | 2273 | DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
|
---|
[357fba] | 2274 |
|
---|
| 2275 | double ShortestAngle;
|
---|
| 2276 | 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.
|
---|
| 2277 |
|
---|
[cfe56d] | 2278 | Temporary = NULL;
|
---|
[f07f86d] | 2279 | FindSecondPointForTesselation(BaseLine->endpoints[0]->node, NormalVector, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
|
---|
[711ac2] | 2280 | if (Temporary == NULL) {
|
---|
| 2281 | // have we found a second point?
|
---|
| 2282 | delete BaseLine;
|
---|
[357fba] | 2283 | continue;
|
---|
[711ac2] | 2284 | }
|
---|
[f07f86d] | 2285 | BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
|
---|
[357fba] | 2286 |
|
---|
[b998c3] | 2287 | // construct center of circle
|
---|
[8cbb97] | 2288 | CircleCenter = 0.5 * ((*BaseLine->endpoints[0]->node->node) + (*BaseLine->endpoints[1]->node->node));
|
---|
[b998c3] | 2289 |
|
---|
| 2290 | // construct normal vector of circle
|
---|
[8cbb97] | 2291 | CirclePlaneNormal = (*BaseLine->endpoints[0]->node->node) - (*BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2292 |
|
---|
[b998c3] | 2293 | double radius = CirclePlaneNormal.NormSquared();
|
---|
[6613ec] | 2294 | double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
|
---|
[b998c3] | 2295 |
|
---|
[273382] | 2296 | NormalVector.ProjectOntoPlane(CirclePlaneNormal);
|
---|
[b998c3] | 2297 | NormalVector.Normalize();
|
---|
[6613ec] | 2298 | ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
|
---|
[b998c3] | 2299 |
|
---|
[273382] | 2300 | SphereCenter = (CircleRadius * NormalVector) + CircleCenter;
|
---|
[b998c3] | 2301 | // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
|
---|
[357fba] | 2302 |
|
---|
| 2303 | // look in one direction of baseline for initial candidate
|
---|
[0a4f7f] | 2304 | SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ...
|
---|
[357fba] | 2305 |
|
---|
[5c7bf8] | 2306 | // adding point 1 and point 2 and add the line between them
|
---|
[a67d19] | 2307 | DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
|
---|
| 2308 | DoLog(0) && (Log() << Verbose(0) << "Found second point is at " << *BaseLine->endpoints[1]->node << ".\n");
|
---|
[357fba] | 2309 |
|
---|
[f67b6e] | 2310 | //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
|
---|
[f07f86d] | 2311 | CandidateForTesselation OptCandidates(BaseLine);
|
---|
[b998c3] | 2312 | FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
|
---|
[a67d19] | 2313 | DoLog(0) && (Log() << Verbose(0) << "List of third Points is:" << endl);
|
---|
[f67b6e] | 2314 | for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
|
---|
[a67d19] | 2315 | DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
|
---|
[357fba] | 2316 | }
|
---|
[f07f86d] | 2317 | if (!OptCandidates.pointlist.empty()) {
|
---|
| 2318 | BTS = NULL;
|
---|
| 2319 | AddCandidatePolygon(OptCandidates, RADIUS, LC);
|
---|
| 2320 | } else {
|
---|
| 2321 | delete BaseLine;
|
---|
| 2322 | continue;
|
---|
[357fba] | 2323 | }
|
---|
| 2324 |
|
---|
[711ac2] | 2325 | if (BTS != NULL) { // we have created one starting triangle
|
---|
| 2326 | delete BaseLine;
|
---|
[357fba] | 2327 | break;
|
---|
[711ac2] | 2328 | } else {
|
---|
[357fba] | 2329 | // remove all candidates from the list and then the list itself
|
---|
[7273fc] | 2330 | OptCandidates.pointlist.clear();
|
---|
[357fba] | 2331 | }
|
---|
[f07f86d] | 2332 | delete BaseLine;
|
---|
[357fba] | 2333 | }
|
---|
[ce70970] | 2334 |
|
---|
| 2335 | return (BTS != NULL);
|
---|
[6613ec] | 2336 | }
|
---|
| 2337 | ;
|
---|
[357fba] | 2338 |
|
---|
[f1ef60a] | 2339 | /** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
|
---|
| 2340 | * This is supposed to prevent early closing of the tesselation.
|
---|
[f67b6e] | 2341 | * \param CandidateLine CandidateForTesselation with baseline and shortestangle , i.e. not \a *OptCandidate
|
---|
[f1ef60a] | 2342 | * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
|
---|
| 2343 | * \param RADIUS radius of sphere
|
---|
| 2344 | * \param *LC LinkedCell structure
|
---|
| 2345 | * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
|
---|
| 2346 | */
|
---|
[f67b6e] | 2347 | //bool Tesselation::HasOtherBaselineBetterCandidate(CandidateForTesselation &CandidateLine, const TesselPoint * const ThirdNode, double RADIUS, const LinkedCell * const LC) const
|
---|
| 2348 | //{
|
---|
| 2349 | // Info FunctionInfo(__func__);
|
---|
| 2350 | // bool result = false;
|
---|
| 2351 | // Vector CircleCenter;
|
---|
| 2352 | // Vector CirclePlaneNormal;
|
---|
| 2353 | // Vector OldSphereCenter;
|
---|
| 2354 | // Vector SearchDirection;
|
---|
| 2355 | // Vector helper;
|
---|
| 2356 | // TesselPoint *OtherOptCandidate = NULL;
|
---|
| 2357 | // double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
|
---|
| 2358 | // double radius, CircleRadius;
|
---|
| 2359 | // BoundaryLineSet *Line = NULL;
|
---|
| 2360 | // BoundaryTriangleSet *T = NULL;
|
---|
| 2361 | //
|
---|
| 2362 | // // check both other lines
|
---|
| 2363 | // PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
|
---|
| 2364 | // if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 2365 | // for (int i=0;i<2;i++) {
|
---|
| 2366 | // LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
|
---|
| 2367 | // if (FindLine != (FindPoint->second)->lines.end()) {
|
---|
| 2368 | // Line = FindLine->second;
|
---|
| 2369 | // Log() << Verbose(0) << "Found line " << *Line << "." << endl;
|
---|
| 2370 | // if (Line->triangles.size() == 1) {
|
---|
| 2371 | // T = Line->triangles.begin()->second;
|
---|
| 2372 | // // construct center of circle
|
---|
| 2373 | // CircleCenter.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2374 | // CircleCenter.AddVector(Line->endpoints[1]->node->node);
|
---|
| 2375 | // CircleCenter.Scale(0.5);
|
---|
| 2376 | //
|
---|
| 2377 | // // construct normal vector of circle
|
---|
| 2378 | // CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2379 | // CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
|
---|
| 2380 | //
|
---|
| 2381 | // // calculate squared radius of circle
|
---|
| 2382 | // radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
|
---|
| 2383 | // if (radius/4. < RADIUS*RADIUS) {
|
---|
| 2384 | // CircleRadius = RADIUS*RADIUS - radius/4.;
|
---|
| 2385 | // CirclePlaneNormal.Normalize();
|
---|
| 2386 | // //Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
|
---|
| 2387 | //
|
---|
| 2388 | // // construct old center
|
---|
| 2389 | // GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
|
---|
| 2390 | // helper.CopyVector(&T->NormalVector); // normal vector ensures that this is correct center of the two possible ones
|
---|
| 2391 | // radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
|
---|
| 2392 | // helper.Scale(sqrt(RADIUS*RADIUS - radius));
|
---|
| 2393 | // OldSphereCenter.AddVector(&helper);
|
---|
| 2394 | // OldSphereCenter.SubtractVector(&CircleCenter);
|
---|
| 2395 | // //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
|
---|
| 2396 | //
|
---|
| 2397 | // // construct SearchDirection
|
---|
| 2398 | // SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
|
---|
| 2399 | // helper.CopyVector(Line->endpoints[0]->node->node);
|
---|
| 2400 | // helper.SubtractVector(ThirdNode->node);
|
---|
| 2401 | // if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
| 2402 | // SearchDirection.Scale(-1.);
|
---|
| 2403 | // SearchDirection.ProjectOntoPlane(&OldSphereCenter);
|
---|
| 2404 | // SearchDirection.Normalize();
|
---|
| 2405 | // Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
|
---|
| 2406 | // if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
|
---|
| 2407 | // // rotated the wrong way!
|
---|
[58ed4a] | 2408 | // DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
|
---|
[f67b6e] | 2409 | // }
|
---|
| 2410 | //
|
---|
| 2411 | // // add third point
|
---|
| 2412 | // FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, OptCandidates, ThirdNode, RADIUS, LC);
|
---|
| 2413 | // for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); ++it) {
|
---|
| 2414 | // if (((*it) == BaseRay->endpoints[0]->node) || ((*it) == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
|
---|
| 2415 | // continue;
|
---|
| 2416 | // Log() << Verbose(0) << " Third point candidate is " << (*it)
|
---|
| 2417 | // << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
|
---|
| 2418 | // Log() << Verbose(0) << " Baseline is " << *BaseRay << endl;
|
---|
| 2419 | //
|
---|
| 2420 | // // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
|
---|
| 2421 | // TesselPoint *PointCandidates[3];
|
---|
| 2422 | // PointCandidates[0] = (*it);
|
---|
| 2423 | // PointCandidates[1] = BaseRay->endpoints[0]->node;
|
---|
| 2424 | // PointCandidates[2] = BaseRay->endpoints[1]->node;
|
---|
| 2425 | // bool check=false;
|
---|
| 2426 | // int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
|
---|
| 2427 | // // If there is no triangle, add it regularly.
|
---|
| 2428 | // if (existentTrianglesCount == 0) {
|
---|
| 2429 | // SetTesselationPoint((*it), 0);
|
---|
| 2430 | // SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2431 | // SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2432 | //
|
---|
| 2433 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
|
---|
| 2434 | // OtherOptCandidate = (*it);
|
---|
| 2435 | // check = true;
|
---|
| 2436 | // }
|
---|
| 2437 | // } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
|
---|
| 2438 | // SetTesselationPoint((*it), 0);
|
---|
| 2439 | // SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
|
---|
| 2440 | // SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
|
---|
| 2441 | //
|
---|
| 2442 | // // 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)
|
---|
| 2443 | // // i.e. at least one of the three lines must be present with TriangleCount <= 1
|
---|
| 2444 | // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
|
---|
| 2445 | // OtherOptCandidate = (*it);
|
---|
| 2446 | // check = true;
|
---|
| 2447 | // }
|
---|
| 2448 | // }
|
---|
| 2449 | //
|
---|
| 2450 | // if (check) {
|
---|
| 2451 | // if (ShortestAngle > OtherShortestAngle) {
|
---|
| 2452 | // Log() << Verbose(0) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
|
---|
| 2453 | // result = true;
|
---|
| 2454 | // break;
|
---|
| 2455 | // }
|
---|
| 2456 | // }
|
---|
| 2457 | // }
|
---|
| 2458 | // delete(OptCandidates);
|
---|
| 2459 | // if (result)
|
---|
| 2460 | // break;
|
---|
| 2461 | // } else {
|
---|
| 2462 | // Log() << Verbose(0) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
|
---|
| 2463 | // }
|
---|
| 2464 | // } else {
|
---|
[58ed4a] | 2465 | // DoeLog(2) && (eLog()<< Verbose(2) << "Baseline is connected to two triangles already?" << endl);
|
---|
[f67b6e] | 2466 | // }
|
---|
| 2467 | // } else {
|
---|
| 2468 | // Log() << Verbose(1) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
|
---|
| 2469 | // }
|
---|
| 2470 | // }
|
---|
| 2471 | // } else {
|
---|
[58ed4a] | 2472 | // DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl);
|
---|
[f67b6e] | 2473 | // }
|
---|
| 2474 | //
|
---|
| 2475 | // return result;
|
---|
| 2476 | //};
|
---|
[357fba] | 2477 |
|
---|
| 2478 | /** This function finds a triangle to a line, adjacent to an existing one.
|
---|
| 2479 | * @param out output stream for debugging
|
---|
[1e168b] | 2480 | * @param CandidateLine current cadndiate baseline to search from
|
---|
[357fba] | 2481 | * @param T current triangle which \a Line is edge of
|
---|
| 2482 | * @param RADIUS radius of the rolling ball
|
---|
| 2483 | * @param N number of found triangles
|
---|
[62bb91] | 2484 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 2485 | */
|
---|
[f07f86d] | 2486 | bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 2487 | {
|
---|
[6613ec] | 2488 | Info FunctionInfo(__func__);
|
---|
[357fba] | 2489 | Vector CircleCenter;
|
---|
| 2490 | Vector CirclePlaneNormal;
|
---|
[b998c3] | 2491 | Vector RelativeSphereCenter;
|
---|
[357fba] | 2492 | Vector SearchDirection;
|
---|
| 2493 | Vector helper;
|
---|
[09898c] | 2494 | BoundaryPointSet *ThirdPoint = NULL;
|
---|
[357fba] | 2495 | LineMap::iterator testline;
|
---|
| 2496 | double radius, CircleRadius;
|
---|
| 2497 |
|
---|
[6613ec] | 2498 | for (int i = 0; i < 3; i++)
|
---|
[09898c] | 2499 | if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
|
---|
| 2500 | ThirdPoint = T.endpoints[i];
|
---|
[b998c3] | 2501 | break;
|
---|
| 2502 | }
|
---|
[a67d19] | 2503 | DoLog(0) && (Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << "." << endl);
|
---|
[09898c] | 2504 |
|
---|
| 2505 | CandidateLine.T = &T;
|
---|
[357fba] | 2506 |
|
---|
| 2507 | // construct center of circle
|
---|
[273382] | 2508 | CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
|
---|
| 2509 | (*CandidateLine.BaseLine->endpoints[1]->node->node));
|
---|
[357fba] | 2510 |
|
---|
| 2511 | // construct normal vector of circle
|
---|
[273382] | 2512 | CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
|
---|
| 2513 | (*CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 2514 |
|
---|
| 2515 | // calculate squared radius of circle
|
---|
[273382] | 2516 | radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal);
|
---|
[6613ec] | 2517 | if (radius / 4. < RADIUS * RADIUS) {
|
---|
[b998c3] | 2518 | // construct relative sphere center with now known CircleCenter
|
---|
[273382] | 2519 | RelativeSphereCenter = T.SphereCenter - CircleCenter;
|
---|
[b998c3] | 2520 |
|
---|
[6613ec] | 2521 | CircleRadius = RADIUS * RADIUS - radius / 4.;
|
---|
[357fba] | 2522 | CirclePlaneNormal.Normalize();
|
---|
[a67d19] | 2523 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
[357fba] | 2524 |
|
---|
[a67d19] | 2525 | DoLog(1) && (Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl);
|
---|
[b998c3] | 2526 |
|
---|
| 2527 | // construct SearchDirection and an "outward pointer"
|
---|
[0a4f7f] | 2528 | SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal();
|
---|
[8cbb97] | 2529 | helper = CircleCenter - (*ThirdPoint->node->node);
|
---|
[273382] | 2530 | if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
|
---|
[357fba] | 2531 | SearchDirection.Scale(-1.);
|
---|
[a67d19] | 2532 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
[273382] | 2533 | if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) {
|
---|
[357fba] | 2534 | // rotated the wrong way!
|
---|
[6613ec] | 2535 | DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
|
---|
[357fba] | 2536 | }
|
---|
| 2537 |
|
---|
| 2538 | // add third point
|
---|
[09898c] | 2539 | FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC);
|
---|
[357fba] | 2540 |
|
---|
| 2541 | } else {
|
---|
[a67d19] | 2542 | DoLog(0) && (Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl);
|
---|
[357fba] | 2543 | }
|
---|
| 2544 |
|
---|
[f67b6e] | 2545 | if (CandidateLine.pointlist.empty()) {
|
---|
[6613ec] | 2546 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl);
|
---|
[357fba] | 2547 | return false;
|
---|
| 2548 | }
|
---|
[a67d19] | 2549 | DoLog(0) && (Log() << Verbose(0) << "Third Points are: " << endl);
|
---|
[f67b6e] | 2550 | for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
|
---|
[a67d19] | 2551 | DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
|
---|
[357fba] | 2552 | }
|
---|
| 2553 |
|
---|
[f67b6e] | 2554 | return true;
|
---|
[6613ec] | 2555 | }
|
---|
| 2556 | ;
|
---|
[f67b6e] | 2557 |
|
---|
[6613ec] | 2558 | /** Walks through Tesselation::OpenLines() and finds candidates for newly created ones.
|
---|
| 2559 | * \param *&LCList atoms in LinkedCell list
|
---|
| 2560 | * \param RADIUS radius of the virtual sphere
|
---|
| 2561 | * \return true - for all open lines without candidates so far, a candidate has been found,
|
---|
| 2562 | * false - at least one open line without candidate still
|
---|
| 2563 | */
|
---|
| 2564 | bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList)
|
---|
| 2565 | {
|
---|
| 2566 | bool TesselationFailFlag = true;
|
---|
| 2567 | CandidateForTesselation *baseline = NULL;
|
---|
| 2568 | BoundaryTriangleSet *T = NULL;
|
---|
| 2569 |
|
---|
| 2570 | for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
|
---|
| 2571 | baseline = Runner->second;
|
---|
| 2572 | if (baseline->pointlist.empty()) {
|
---|
[6d574a] | 2573 | ASSERT((baseline->BaseLine->triangles.size() == 1),"Open line without exactly one attached triangle");
|
---|
[6613ec] | 2574 | T = (((baseline->BaseLine->triangles.begin()))->second);
|
---|
[a67d19] | 2575 | DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl);
|
---|
[6613ec] | 2576 | TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
|
---|
| 2577 | }
|
---|
| 2578 | }
|
---|
| 2579 | return TesselationFailFlag;
|
---|
| 2580 | }
|
---|
| 2581 | ;
|
---|
[357fba] | 2582 |
|
---|
[1e168b] | 2583 | /** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
|
---|
[f67b6e] | 2584 | * \param CandidateLine triangle to add
|
---|
[474961] | 2585 | * \param RADIUS Radius of sphere
|
---|
| 2586 | * \param *LC LinkedCell structure
|
---|
| 2587 | * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in
|
---|
| 2588 | * AddTesselationLine() in AddCandidateTriangle()
|
---|
[1e168b] | 2589 | */
|
---|
[474961] | 2590 | void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC)
|
---|
[1e168b] | 2591 | {
|
---|
[ebb50e] | 2592 | Info FunctionInfo(__func__);
|
---|
[1e168b] | 2593 | Vector Center;
|
---|
[27bd2f] | 2594 | TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
|
---|
[09898c] | 2595 | TesselPointList::iterator Runner;
|
---|
| 2596 | TesselPointList::iterator Sprinter;
|
---|
[27bd2f] | 2597 |
|
---|
| 2598 | // fill the set of neighbours
|
---|
[c15ca2] | 2599 | TesselPointSet SetOfNeighbours;
|
---|
[8d2772] | 2600 |
|
---|
[27bd2f] | 2601 | SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
|
---|
| 2602 | for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
|
---|
| 2603 | SetOfNeighbours.insert(*Runner);
|
---|
[c15ca2] | 2604 | TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[27bd2f] | 2605 |
|
---|
[a67d19] | 2606 | DoLog(0) && (Log() << Verbose(0) << "List of Candidates for Turning Point " << *TurningPoint << ":" << endl);
|
---|
[c15ca2] | 2607 | for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
|
---|
[a67d19] | 2608 | DoLog(0) && (Log() << Verbose(0) << " " << **TesselRunner << endl);
|
---|
[09898c] | 2609 |
|
---|
| 2610 | // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
|
---|
| 2611 | Runner = connectedClosestPoints->begin();
|
---|
| 2612 | Sprinter = Runner;
|
---|
[27bd2f] | 2613 | Sprinter++;
|
---|
[6613ec] | 2614 | while (Sprinter != connectedClosestPoints->end()) {
|
---|
[a67d19] | 2615 | DoLog(0) && (Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl);
|
---|
[f67b6e] | 2616 |
|
---|
[f07f86d] | 2617 | AddTesselationPoint(TurningPoint, 0);
|
---|
| 2618 | AddTesselationPoint(*Runner, 1);
|
---|
| 2619 | AddTesselationPoint(*Sprinter, 2);
|
---|
[1e168b] | 2620 |
|
---|
[6613ec] | 2621 | AddCandidateTriangle(CandidateLine, Opt);
|
---|
[1e168b] | 2622 |
|
---|
[27bd2f] | 2623 | Runner = Sprinter;
|
---|
| 2624 | Sprinter++;
|
---|
[6613ec] | 2625 | if (Sprinter != connectedClosestPoints->end()) {
|
---|
| 2626 | // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
|
---|
[f04f11] | 2627 | FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); // Assume BTS contains last triangle
|
---|
[a67d19] | 2628 | DoLog(0) && (Log() << Verbose(0) << " There are still more triangles to add." << endl);
|
---|
[6613ec] | 2629 | }
|
---|
| 2630 | // pick candidates for other open lines as well
|
---|
| 2631 | FindCandidatesforOpenLines(RADIUS, LC);
|
---|
| 2632 |
|
---|
[f07f86d] | 2633 | // check whether we add a degenerate or a normal triangle
|
---|
[6613ec] | 2634 | if (CheckDegeneracy(CandidateLine, RADIUS, LC)) {
|
---|
[f07f86d] | 2635 | // add normal and degenerate triangles
|
---|
[a67d19] | 2636 | DoLog(1) && (Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl);
|
---|
[6613ec] | 2637 | AddCandidateTriangle(CandidateLine, OtherOpt);
|
---|
| 2638 |
|
---|
| 2639 | if (Sprinter != connectedClosestPoints->end()) {
|
---|
| 2640 | // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
|
---|
| 2641 | FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter);
|
---|
| 2642 | }
|
---|
| 2643 | // pick candidates for other open lines as well
|
---|
| 2644 | FindCandidatesforOpenLines(RADIUS, LC);
|
---|
[474961] | 2645 | }
|
---|
[6613ec] | 2646 | }
|
---|
| 2647 | delete (connectedClosestPoints);
|
---|
| 2648 | };
|
---|
[474961] | 2649 |
|
---|
[6613ec] | 2650 | /** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate.
|
---|
| 2651 | * \param *Sprinter next candidate to which internal open lines are set
|
---|
| 2652 | * \param *OptCenter OptCenter for this candidate
|
---|
| 2653 | */
|
---|
| 2654 | void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter)
|
---|
| 2655 | {
|
---|
| 2656 | Info FunctionInfo(__func__);
|
---|
| 2657 |
|
---|
| 2658 | pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr);
|
---|
| 2659 | for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
|
---|
[a67d19] | 2660 | DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
|
---|
[6613ec] | 2661 | // If there is a line with less than two attached triangles, we don't need a new line.
|
---|
| 2662 | if (FindLine->second->triangles.size() == 1) {
|
---|
| 2663 | CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
|
---|
| 2664 | if (!Finder->second->pointlist.empty())
|
---|
[a67d19] | 2665 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
|
---|
[6613ec] | 2666 | else {
|
---|
[a67d19] | 2667 | DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl);
|
---|
[f04f11] | 2668 | Finder->second->T = BTS; // is last triangle
|
---|
[6613ec] | 2669 | Finder->second->pointlist.push_back(Sprinter);
|
---|
| 2670 | Finder->second->ShortestAngle = 0.;
|
---|
[8cbb97] | 2671 | Finder->second->OptCenter = *OptCenter;
|
---|
[6613ec] | 2672 | }
|
---|
| 2673 | }
|
---|
[f67b6e] | 2674 | }
|
---|
[1e168b] | 2675 | };
|
---|
| 2676 |
|
---|
[f07f86d] | 2677 | /** If a given \a *triangle is degenerated, this adds both sides.
|
---|
[474961] | 2678 | * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction.
|
---|
[f07f86d] | 2679 | * Note that endpoints are stored in Tesselation::TPS
|
---|
| 2680 | * \param CandidateLine CanddiateForTesselation structure for the desired BoundaryLine
|
---|
[474961] | 2681 | * \param RADIUS radius of sphere
|
---|
| 2682 | * \param *LC pointer to LinkedCell structure
|
---|
| 2683 | */
|
---|
[711ac2] | 2684 | void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
|
---|
[474961] | 2685 | {
|
---|
| 2686 | Info FunctionInfo(__func__);
|
---|
[f07f86d] | 2687 | Vector Center;
|
---|
| 2688 | CandidateMap::const_iterator CandidateCheck = OpenLines.end();
|
---|
[711ac2] | 2689 | BoundaryTriangleSet *triangle = NULL;
|
---|
[f07f86d] | 2690 |
|
---|
[711ac2] | 2691 | /// 1. Create or pick the lines for the first triangle
|
---|
[a67d19] | 2692 | DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl);
|
---|
[6613ec] | 2693 | for (int i = 0; i < 3; i++) {
|
---|
[711ac2] | 2694 | BLS[i] = NULL;
|
---|
[a67d19] | 2695 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[6613ec] | 2696 | AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
|
---|
[474961] | 2697 | }
|
---|
[f07f86d] | 2698 |
|
---|
[711ac2] | 2699 | /// 2. create the first triangle and NormalVector and so on
|
---|
[a67d19] | 2700 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl);
|
---|
[f07f86d] | 2701 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2702 | AddTesselationTriangle();
|
---|
[711ac2] | 2703 |
|
---|
[f07f86d] | 2704 | // create normal vector
|
---|
| 2705 | BTS->GetCenter(&Center);
|
---|
[8cbb97] | 2706 | Center -= CandidateLine.OptCenter;
|
---|
| 2707 | BTS->SphereCenter = CandidateLine.OptCenter;
|
---|
[f07f86d] | 2708 | BTS->GetNormalVector(Center);
|
---|
| 2709 | // give some verbose output about the whole procedure
|
---|
| 2710 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2711 | DoLog(0) && (Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
|
---|
[f07f86d] | 2712 | else
|
---|
[a67d19] | 2713 | DoLog(0) && (Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[f07f86d] | 2714 | triangle = BTS;
|
---|
| 2715 |
|
---|
[711ac2] | 2716 | /// 3. Gather candidates for each new line
|
---|
[a67d19] | 2717 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl);
|
---|
[6613ec] | 2718 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2719 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[f07f86d] | 2720 | CandidateCheck = OpenLines.find(BLS[i]);
|
---|
| 2721 | if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
|
---|
| 2722 | if (CandidateCheck->second->T == NULL)
|
---|
| 2723 | CandidateCheck->second->T = triangle;
|
---|
| 2724 | FindNextSuitableTriangle(*(CandidateCheck->second), *CandidateCheck->second->T, RADIUS, LC);
|
---|
[474961] | 2725 | }
|
---|
[f07f86d] | 2726 | }
|
---|
[d5fea7] | 2727 |
|
---|
[711ac2] | 2728 | /// 4. Create or pick the lines for the second triangle
|
---|
[a67d19] | 2729 | DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl);
|
---|
[6613ec] | 2730 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2731 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[6613ec] | 2732 | AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
|
---|
[474961] | 2733 | }
|
---|
[f07f86d] | 2734 |
|
---|
[711ac2] | 2735 | /// 5. create the second triangle and NormalVector and so on
|
---|
[a67d19] | 2736 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl);
|
---|
[f07f86d] | 2737 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2738 | AddTesselationTriangle();
|
---|
[711ac2] | 2739 |
|
---|
[8cbb97] | 2740 | BTS->SphereCenter = CandidateLine.OtherOptCenter;
|
---|
[f07f86d] | 2741 | // create normal vector in other direction
|
---|
[8cbb97] | 2742 | BTS->GetNormalVector(triangle->NormalVector);
|
---|
[f07f86d] | 2743 | BTS->NormalVector.Scale(-1.);
|
---|
| 2744 | // give some verbose output about the whole procedure
|
---|
| 2745 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2746 | DoLog(0) && (Log() << Verbose(0) << "--> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
|
---|
[f07f86d] | 2747 | else
|
---|
[a67d19] | 2748 | DoLog(0) && (Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[f07f86d] | 2749 |
|
---|
[711ac2] | 2750 | /// 6. Adding triangle to new lines
|
---|
[a67d19] | 2751 | DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl);
|
---|
[6613ec] | 2752 | for (int i = 0; i < 3; i++) {
|
---|
[a67d19] | 2753 | DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
|
---|
[711ac2] | 2754 | CandidateCheck = OpenLines.find(BLS[i]);
|
---|
| 2755 | if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
|
---|
| 2756 | if (CandidateCheck->second->T == NULL)
|
---|
| 2757 | CandidateCheck->second->T = BTS;
|
---|
| 2758 | }
|
---|
| 2759 | }
|
---|
[6613ec] | 2760 | }
|
---|
| 2761 | ;
|
---|
[474961] | 2762 |
|
---|
| 2763 | /** Adds a triangle to the Tesselation structure from three given TesselPoint's.
|
---|
[f07f86d] | 2764 | * Note that endpoints are in Tesselation::TPS.
|
---|
| 2765 | * \param CandidateLine CandidateForTesselation structure contains other information
|
---|
[6613ec] | 2766 | * \param type which opt center to add (i.e. which side) and thus which NormalVector to take
|
---|
[474961] | 2767 | */
|
---|
[6613ec] | 2768 | void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type)
|
---|
[474961] | 2769 | {
|
---|
| 2770 | Info FunctionInfo(__func__);
|
---|
[f07f86d] | 2771 | Vector Center;
|
---|
[6613ec] | 2772 | Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter;
|
---|
[474961] | 2773 |
|
---|
| 2774 | // add the lines
|
---|
[6613ec] | 2775 | AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0);
|
---|
| 2776 | AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1);
|
---|
| 2777 | AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2);
|
---|
[474961] | 2778 |
|
---|
| 2779 | // add the triangles
|
---|
| 2780 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 2781 | AddTesselationTriangle();
|
---|
[f07f86d] | 2782 |
|
---|
| 2783 | // create normal vector
|
---|
| 2784 | BTS->GetCenter(&Center);
|
---|
[8cbb97] | 2785 | Center.SubtractVector(*OptCenter);
|
---|
| 2786 | BTS->SphereCenter = *OptCenter;
|
---|
[f07f86d] | 2787 | BTS->GetNormalVector(Center);
|
---|
| 2788 |
|
---|
| 2789 | // give some verbose output about the whole procedure
|
---|
| 2790 | if (CandidateLine.T != NULL)
|
---|
[a67d19] | 2791 | DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
|
---|
[f07f86d] | 2792 | else
|
---|
[a67d19] | 2793 | DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
|
---|
[6613ec] | 2794 | }
|
---|
| 2795 | ;
|
---|
[474961] | 2796 |
|
---|
[16d866] | 2797 | /** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
|
---|
| 2798 | * We look whether the closest point on \a *Base with respect to the other baseline is outside
|
---|
| 2799 | * of the segment formed by both endpoints (concave) or not (convex).
|
---|
| 2800 | * \param *out output stream for debugging
|
---|
| 2801 | * \param *Base line to be flipped
|
---|
[57066a] | 2802 | * \return NULL - convex, otherwise endpoint that makes it concave
|
---|
[16d866] | 2803 | */
|
---|
[e138de] | 2804 | class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
|
---|
[16d866] | 2805 | {
|
---|
[6613ec] | 2806 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2807 | class BoundaryPointSet *Spot = NULL;
|
---|
| 2808 | class BoundaryLineSet *OtherBase;
|
---|
[0077b5] | 2809 | Vector *ClosestPoint;
|
---|
[16d866] | 2810 |
|
---|
[6613ec] | 2811 | int m = 0;
|
---|
| 2812 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2813 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2814 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2815 | BPS[m++] = runner->second->endpoints[j];
|
---|
[6613ec] | 2816 | OtherBase = new class BoundaryLineSet(BPS, -1);
|
---|
[16d866] | 2817 |
|
---|
[a67d19] | 2818 | DoLog(1) && (Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl);
|
---|
| 2819 | DoLog(1) && (Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl);
|
---|
[16d866] | 2820 |
|
---|
| 2821 | // get the closest point on each line to the other line
|
---|
[e138de] | 2822 | ClosestPoint = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
[16d866] | 2823 |
|
---|
| 2824 | // delete the temporary other base line
|
---|
[6613ec] | 2825 | delete (OtherBase);
|
---|
[16d866] | 2826 |
|
---|
| 2827 | // get the distance vector from Base line to OtherBase line
|
---|
[0077b5] | 2828 | Vector DistanceToIntersection[2], BaseLine;
|
---|
| 2829 | double distance[2];
|
---|
[273382] | 2830 | BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node);
|
---|
[6613ec] | 2831 | for (int i = 0; i < 2; i++) {
|
---|
[273382] | 2832 | DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node);
|
---|
| 2833 | distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]);
|
---|
[16d866] | 2834 | }
|
---|
[6613ec] | 2835 | delete (ClosestPoint);
|
---|
| 2836 | if ((distance[0] * distance[1]) > 0) { // have same sign?
|
---|
[a67d19] | 2837 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl);
|
---|
[0077b5] | 2838 | if (distance[0] < distance[1]) {
|
---|
| 2839 | Spot = Base->endpoints[0];
|
---|
| 2840 | } else {
|
---|
| 2841 | Spot = Base->endpoints[1];
|
---|
| 2842 | }
|
---|
[16d866] | 2843 | return Spot;
|
---|
[6613ec] | 2844 | } else { // different sign, i.e. we are in between
|
---|
[a67d19] | 2845 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl);
|
---|
[16d866] | 2846 | return NULL;
|
---|
| 2847 | }
|
---|
| 2848 |
|
---|
[6613ec] | 2849 | }
|
---|
| 2850 | ;
|
---|
[16d866] | 2851 |
|
---|
[776b64] | 2852 | void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
|
---|
[0077b5] | 2853 | {
|
---|
[6613ec] | 2854 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2855 | // print all lines
|
---|
[a67d19] | 2856 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl);
|
---|
[6613ec] | 2857 | for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)
|
---|
[a67d19] | 2858 | DoLog(0) && (Log() << Verbose(0) << *(PointRunner->second) << endl);
|
---|
[6613ec] | 2859 | }
|
---|
| 2860 | ;
|
---|
[0077b5] | 2861 |
|
---|
[776b64] | 2862 | void Tesselation::PrintAllBoundaryLines(ofstream *out) const
|
---|
[0077b5] | 2863 | {
|
---|
[6613ec] | 2864 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2865 | // print all lines
|
---|
[a67d19] | 2866 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl);
|
---|
[776b64] | 2867 | for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
|
---|
[a67d19] | 2868 | DoLog(0) && (Log() << Verbose(0) << *(LineRunner->second) << endl);
|
---|
[6613ec] | 2869 | }
|
---|
| 2870 | ;
|
---|
[0077b5] | 2871 |
|
---|
[776b64] | 2872 | void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
|
---|
[0077b5] | 2873 | {
|
---|
[6613ec] | 2874 | Info FunctionInfo(__func__);
|
---|
[0077b5] | 2875 | // print all triangles
|
---|
[a67d19] | 2876 | DoLog(0) && (Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl);
|
---|
[776b64] | 2877 | for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
|
---|
[a67d19] | 2878 | DoLog(0) && (Log() << Verbose(0) << *(TriangleRunner->second) << endl);
|
---|
[6613ec] | 2879 | }
|
---|
| 2880 | ;
|
---|
[357fba] | 2881 |
|
---|
[16d866] | 2882 | /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
|
---|
[357fba] | 2883 | * \param *out output stream for debugging
|
---|
[16d866] | 2884 | * \param *Base line to be flipped
|
---|
[57066a] | 2885 | * \return volume change due to flipping (0 - then no flipped occured)
|
---|
[357fba] | 2886 | */
|
---|
[e138de] | 2887 | double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
|
---|
[357fba] | 2888 | {
|
---|
[6613ec] | 2889 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2890 | class BoundaryLineSet *OtherBase;
|
---|
| 2891 | Vector *ClosestPoint[2];
|
---|
[57066a] | 2892 | double volume;
|
---|
[16d866] | 2893 |
|
---|
[6613ec] | 2894 | int m = 0;
|
---|
| 2895 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2896 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2897 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
|
---|
| 2898 | BPS[m++] = runner->second->endpoints[j];
|
---|
[6613ec] | 2899 | OtherBase = new class BoundaryLineSet(BPS, -1);
|
---|
[62bb91] | 2900 |
|
---|
[a67d19] | 2901 | DoLog(0) && (Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl);
|
---|
| 2902 | DoLog(0) && (Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl);
|
---|
[62bb91] | 2903 |
|
---|
[16d866] | 2904 | // get the closest point on each line to the other line
|
---|
[e138de] | 2905 | ClosestPoint[0] = GetClosestPointBetweenLine(Base, OtherBase);
|
---|
| 2906 | ClosestPoint[1] = GetClosestPointBetweenLine(OtherBase, Base);
|
---|
[16d866] | 2907 |
|
---|
| 2908 | // get the distance vector from Base line to OtherBase line
|
---|
[273382] | 2909 | Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]);
|
---|
[16d866] | 2910 |
|
---|
[57066a] | 2911 | // calculate volume
|
---|
[c0f6c6] | 2912 | volume = CalculateVolumeofGeneralTetraeder(*Base->endpoints[1]->node->node, *OtherBase->endpoints[0]->node->node, *OtherBase->endpoints[1]->node->node, *Base->endpoints[0]->node->node);
|
---|
[57066a] | 2913 |
|
---|
[0077b5] | 2914 | // delete the temporary other base line and the closest points
|
---|
[6613ec] | 2915 | delete (ClosestPoint[0]);
|
---|
| 2916 | delete (ClosestPoint[1]);
|
---|
| 2917 | delete (OtherBase);
|
---|
[16d866] | 2918 |
|
---|
| 2919 | if (Distance.NormSquared() < MYEPSILON) { // check for intersection
|
---|
[a67d19] | 2920 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl);
|
---|
[16d866] | 2921 | return false;
|
---|
| 2922 | } else { // check for sign against BaseLineNormal
|
---|
| 2923 | Vector BaseLineNormal;
|
---|
[5c7bf8] | 2924 | BaseLineNormal.Zero();
|
---|
| 2925 | if (Base->triangles.size() < 2) {
|
---|
[6613ec] | 2926 | DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
|
---|
[57066a] | 2927 | return 0.;
|
---|
[5c7bf8] | 2928 | }
|
---|
| 2929 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[8cbb97] | 2930 | DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
|
---|
[273382] | 2931 | BaseLineNormal += (runner->second->NormalVector);
|
---|
[5c7bf8] | 2932 | }
|
---|
[6613ec] | 2933 | BaseLineNormal.Scale(1. / 2.);
|
---|
[357fba] | 2934 |
|
---|
[273382] | 2935 | if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
|
---|
[a67d19] | 2936 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl);
|
---|
[57066a] | 2937 | // calculate volume summand as a general tetraeder
|
---|
| 2938 | return volume;
|
---|
[6613ec] | 2939 | } else { // Base higher than OtherBase -> do nothing
|
---|
[a67d19] | 2940 | DoLog(0) && (Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl);
|
---|
[57066a] | 2941 | return 0.;
|
---|
[16d866] | 2942 | }
|
---|
| 2943 | }
|
---|
[6613ec] | 2944 | }
|
---|
| 2945 | ;
|
---|
[357fba] | 2946 |
|
---|
[16d866] | 2947 | /** For a given baseline and its two connected triangles, flips the baseline.
|
---|
| 2948 | * I.e. we create the new baseline between the other two endpoints of these four
|
---|
| 2949 | * endpoints and reconstruct the two triangles accordingly.
|
---|
| 2950 | * \param *out output stream for debugging
|
---|
| 2951 | * \param *Base line to be flipped
|
---|
[57066a] | 2952 | * \return pointer to allocated new baseline - flipping successful, NULL - something went awry
|
---|
[16d866] | 2953 | */
|
---|
[e138de] | 2954 | class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
|
---|
[16d866] | 2955 | {
|
---|
[6613ec] | 2956 | Info FunctionInfo(__func__);
|
---|
[16d866] | 2957 | class BoundaryLineSet *OldLines[4], *NewLine;
|
---|
| 2958 | class BoundaryPointSet *OldPoints[2];
|
---|
| 2959 | Vector BaseLineNormal;
|
---|
| 2960 | int OldTriangleNrs[2], OldBaseLineNr;
|
---|
[6613ec] | 2961 | int i, m;
|
---|
[16d866] | 2962 |
|
---|
| 2963 | // calculate NormalVector for later use
|
---|
| 2964 | BaseLineNormal.Zero();
|
---|
| 2965 | if (Base->triangles.size() < 2) {
|
---|
[6613ec] | 2966 | DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
|
---|
[57066a] | 2967 | return NULL;
|
---|
[16d866] | 2968 | }
|
---|
| 2969 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
|
---|
[a67d19] | 2970 | DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
|
---|
[273382] | 2971 | BaseLineNormal += (runner->second->NormalVector);
|
---|
[16d866] | 2972 | }
|
---|
[6613ec] | 2973 | BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
|
---|
[16d866] | 2974 |
|
---|
| 2975 | // get the two triangles
|
---|
| 2976 | // gather four endpoints and four lines
|
---|
[6613ec] | 2977 | for (int j = 0; j < 4; j++)
|
---|
[16d866] | 2978 | OldLines[j] = NULL;
|
---|
[6613ec] | 2979 | for (int j = 0; j < 2; j++)
|
---|
[16d866] | 2980 | OldPoints[j] = NULL;
|
---|
[6613ec] | 2981 | i = 0;
|
---|
| 2982 | m = 0;
|
---|
[a67d19] | 2983 | DoLog(0) && (Log() << Verbose(0) << "The four old lines are: ");
|
---|
[6613ec] | 2984 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2985 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2986 | if (runner->second->lines[j] != Base) { // pick not the central baseline
|
---|
| 2987 | OldLines[i++] = runner->second->lines[j];
|
---|
[a67d19] | 2988 | DoLog(0) && (Log() << Verbose(0) << *runner->second->lines[j] << "\t");
|
---|
[357fba] | 2989 | }
|
---|
[a67d19] | 2990 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
| 2991 | DoLog(0) && (Log() << Verbose(0) << "The two old points are: ");
|
---|
[6613ec] | 2992 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
|
---|
| 2993 | for (int j = 0; j < 3; j++) // all of their endpoints and baselines
|
---|
[16d866] | 2994 | if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
|
---|
| 2995 | OldPoints[m++] = runner->second->endpoints[j];
|
---|
[a67d19] | 2996 | DoLog(0) && (Log() << Verbose(0) << *runner->second->endpoints[j] << "\t");
|
---|
[16d866] | 2997 | }
|
---|
[a67d19] | 2998 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[16d866] | 2999 |
|
---|
| 3000 | // check whether everything is in place to create new lines and triangles
|
---|
[6613ec] | 3001 | if (i < 4) {
|
---|
| 3002 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
|
---|
[57066a] | 3003 | return NULL;
|
---|
[16d866] | 3004 | }
|
---|
[6613ec] | 3005 | for (int j = 0; j < 4; j++)
|
---|
[16d866] | 3006 | if (OldLines[j] == NULL) {
|
---|
[6613ec] | 3007 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
|
---|
[57066a] | 3008 | return NULL;
|
---|
[16d866] | 3009 | }
|
---|
[6613ec] | 3010 | for (int j = 0; j < 2; j++)
|
---|
[16d866] | 3011 | if (OldPoints[j] == NULL) {
|
---|
[6613ec] | 3012 | DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl);
|
---|
[57066a] | 3013 | return NULL;
|
---|
[357fba] | 3014 | }
|
---|
[16d866] | 3015 |
|
---|
| 3016 | // remove triangles and baseline removes itself
|
---|
[a67d19] | 3017 | DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl);
|
---|
[16d866] | 3018 | OldBaseLineNr = Base->Nr;
|
---|
[6613ec] | 3019 | m = 0;
|
---|
[accebe] | 3020 | // first obtain all triangle to delete ... (otherwise we pull the carpet (Base) from under the for-loop's feet)
|
---|
| 3021 | list <BoundaryTriangleSet *> TrianglesOfBase;
|
---|
| 3022 | for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); ++runner)
|
---|
| 3023 | TrianglesOfBase.push_back(runner->second);
|
---|
| 3024 | // .. then delete each triangle (which deletes the line as well)
|
---|
| 3025 | for (list <BoundaryTriangleSet *>::iterator runner = TrianglesOfBase.begin(); !TrianglesOfBase.empty(); runner = TrianglesOfBase.begin()) {
|
---|
| 3026 | DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting triangle " << *(*runner) << "." << endl);
|
---|
| 3027 | OldTriangleNrs[m++] = (*runner)->Nr;
|
---|
| 3028 | RemoveTesselationTriangle((*runner));
|
---|
| 3029 | TrianglesOfBase.erase(runner);
|
---|
[16d866] | 3030 | }
|
---|
| 3031 |
|
---|
| 3032 | // construct new baseline (with same number as old one)
|
---|
| 3033 | BPS[0] = OldPoints[0];
|
---|
| 3034 | BPS[1] = OldPoints[1];
|
---|
| 3035 | NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
|
---|
| 3036 | LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
|
---|
[a67d19] | 3037 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl);
|
---|
[16d866] | 3038 |
|
---|
| 3039 | // construct new triangles with flipped baseline
|
---|
[6613ec] | 3040 | i = -1;
|
---|
[16d866] | 3041 | if (OldLines[0]->IsConnectedTo(OldLines[2]))
|
---|
[6613ec] | 3042 | i = 2;
|
---|
[16d866] | 3043 | if (OldLines[0]->IsConnectedTo(OldLines[3]))
|
---|
[6613ec] | 3044 | i = 3;
|
---|
| 3045 | if (i != -1) {
|
---|
[16d866] | 3046 | BLS[0] = OldLines[0];
|
---|
| 3047 | BLS[1] = OldLines[i];
|
---|
| 3048 | BLS[2] = NewLine;
|
---|
| 3049 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[0]);
|
---|
| 3050 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 3051 | AddTesselationTriangle(OldTriangleNrs[0]);
|
---|
[a67d19] | 3052 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
|
---|
[16d866] | 3053 |
|
---|
[6613ec] | 3054 | BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]);
|
---|
[16d866] | 3055 | BLS[1] = OldLines[1];
|
---|
| 3056 | BLS[2] = NewLine;
|
---|
| 3057 | BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[1]);
|
---|
| 3058 | BTS->GetNormalVector(BaseLineNormal);
|
---|
[7dea7c] | 3059 | AddTesselationTriangle(OldTriangleNrs[1]);
|
---|
[a67d19] | 3060 | DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
|
---|
[16d866] | 3061 | } else {
|
---|
[6613ec] | 3062 | DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);
|
---|
[57066a] | 3063 | return NULL;
|
---|
[357fba] | 3064 | }
|
---|
[16d866] | 3065 |
|
---|
[57066a] | 3066 | return NewLine;
|
---|
[6613ec] | 3067 | }
|
---|
| 3068 | ;
|
---|
[16d866] | 3069 |
|
---|
[357fba] | 3070 | /** Finds the second point of starting triangle.
|
---|
| 3071 | * \param *a first node
|
---|
| 3072 | * \param Oben vector indicating the outside
|
---|
[f1cccd] | 3073 | * \param OptCandidate reference to recommended candidate on return
|
---|
[357fba] | 3074 | * \param Storage[3] array storing angles and other candidate information
|
---|
| 3075 | * \param RADIUS radius of virtual sphere
|
---|
[62bb91] | 3076 | * \param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 3077 | */
|
---|
[776b64] | 3078 | void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
|
---|
[357fba] | 3079 | {
|
---|
[6613ec] | 3080 | Info FunctionInfo(__func__);
|
---|
[357fba] | 3081 | Vector AngleCheck;
|
---|
[57066a] | 3082 | class TesselPoint* Candidate = NULL;
|
---|
[776b64] | 3083 | double norm = -1.;
|
---|
| 3084 | double angle = 0.;
|
---|
| 3085 | int N[NDIM];
|
---|
| 3086 | int Nlower[NDIM];
|
---|
| 3087 | int Nupper[NDIM];
|
---|
[357fba] | 3088 |
|
---|
[6613ec] | 3089 | if (LC->SetIndexToNode(a)) { // get cell for the starting point
|
---|
| 3090 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
[357fba] | 3091 | N[i] = LC->n[i];
|
---|
| 3092 | } else {
|
---|
[6613ec] | 3093 | DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);
|
---|
[357fba] | 3094 | return;
|
---|
| 3095 | }
|
---|
[62bb91] | 3096 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[6613ec] | 3097 | for (int i = 0; i < NDIM; i++) {
|
---|
| 3098 | Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
|
---|
| 3099 | Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
|
---|
[357fba] | 3100 | }
|
---|
[a67d19] | 3101 | DoLog(0) && (Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :" << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl);
|
---|
[357fba] | 3102 |
|
---|
| 3103 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3104 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3105 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3106 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 3107 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3108 | if (List != NULL) {
|
---|
[734816] | 3109 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 3110 | Candidate = (*Runner);
|
---|
| 3111 | // check if we only have one unique point yet ...
|
---|
| 3112 | if (a != Candidate) {
|
---|
| 3113 | // Calculate center of the circle with radius RADIUS through points a and Candidate
|
---|
[f1cccd] | 3114 | Vector OrthogonalizedOben, aCandidate, Center;
|
---|
[357fba] | 3115 | double distance, scaleFactor;
|
---|
| 3116 |
|
---|
[273382] | 3117 | OrthogonalizedOben = Oben;
|
---|
| 3118 | aCandidate = (*a->node) - (*Candidate->node);
|
---|
| 3119 | OrthogonalizedOben.ProjectOntoPlane(aCandidate);
|
---|
[357fba] | 3120 | OrthogonalizedOben.Normalize();
|
---|
[f1cccd] | 3121 | distance = 0.5 * aCandidate.Norm();
|
---|
[357fba] | 3122 | scaleFactor = sqrt(((RADIUS * RADIUS) - (distance * distance)));
|
---|
| 3123 | OrthogonalizedOben.Scale(scaleFactor);
|
---|
| 3124 |
|
---|
[273382] | 3125 | Center = 0.5 * ((*Candidate->node) + (*a->node));
|
---|
| 3126 | Center += OrthogonalizedOben;
|
---|
[357fba] | 3127 |
|
---|
[273382] | 3128 | AngleCheck = Center - (*a->node);
|
---|
[f1cccd] | 3129 | norm = aCandidate.Norm();
|
---|
[357fba] | 3130 | // second point shall have smallest angle with respect to Oben vector
|
---|
[6613ec] | 3131 | if (norm < RADIUS * 2.) {
|
---|
[273382] | 3132 | angle = AngleCheck.Angle(Oben);
|
---|
[357fba] | 3133 | if (angle < Storage[0]) {
|
---|
[f67b6e] | 3134 | //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
|
---|
[a67d19] | 3135 | DoLog(1) && (Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n");
|
---|
[f1cccd] | 3136 | OptCandidate = Candidate;
|
---|
[357fba] | 3137 | Storage[0] = angle;
|
---|
[f67b6e] | 3138 | //Log() << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
|
---|
[357fba] | 3139 | } else {
|
---|
[f67b6e] | 3140 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
|
---|
[357fba] | 3141 | }
|
---|
| 3142 | } else {
|
---|
[f67b6e] | 3143 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
|
---|
[357fba] | 3144 | }
|
---|
| 3145 | } else {
|
---|
[f67b6e] | 3146 | //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
|
---|
[357fba] | 3147 | }
|
---|
| 3148 | }
|
---|
| 3149 | } else {
|
---|
[a67d19] | 3150 | DoLog(0) && (Log() << Verbose(0) << "Linked cell list is empty." << endl);
|
---|
[357fba] | 3151 | }
|
---|
| 3152 | }
|
---|
[6613ec] | 3153 | }
|
---|
| 3154 | ;
|
---|
[357fba] | 3155 |
|
---|
| 3156 | /** This recursive function finds a third point, to form a triangle with two given ones.
|
---|
| 3157 | * Note that this function is for the starting triangle.
|
---|
| 3158 | * The idea is as follows: A sphere with fixed radius is (almost) uniquely defined in space by three points
|
---|
| 3159 | * that sit on its boundary. Hence, when two points are given and we look for the (next) third point, then
|
---|
| 3160 | * the center of the sphere is still fixed up to a single parameter. The band of possible values
|
---|
| 3161 | * describes a circle in 3D-space. The old center of the sphere for the current base triangle gives
|
---|
| 3162 | * us the "null" on this circle, the new center of the candidate point will be some way along this
|
---|
| 3163 | * circle. The shorter the way the better is the candidate. Note that the direction is clearly given
|
---|
| 3164 | * by the normal vector of the base triangle that always points outwards by construction.
|
---|
| 3165 | * Hence, we construct a Center of this circle which sits right in the middle of the current base line.
|
---|
| 3166 | * We construct the normal vector that defines the plane this circle lies in, it is just in the
|
---|
| 3167 | * direction of the baseline. And finally, we need the radius of the circle, which is given by the rest
|
---|
| 3168 | * with respect to the length of the baseline and the sphere's fixed \a RADIUS.
|
---|
| 3169 | * Note that there is one difficulty: The circumcircle is uniquely defined, but for the circumsphere's center
|
---|
| 3170 | * there are two possibilities which becomes clear from the construction as seen below. Hence, we must check
|
---|
| 3171 | * both.
|
---|
| 3172 | * Note also that the acos() function is not unique on [0, 2.*M_PI). Hence, we need an additional check
|
---|
| 3173 | * to decide for one of the two possible angles. Therefore we need a SearchDirection and to make this check
|
---|
| 3174 | * sensible we need OldSphereCenter to be orthogonal to it. Either we construct SearchDirection orthogonal
|
---|
| 3175 | * right away, or -- what we do here -- we rotate the relative sphere centers such that this orthogonality
|
---|
| 3176 | * holds. Then, the normalized projection onto the SearchDirection is either +1 or -1 and thus states whether
|
---|
| 3177 | * the angle is uniquely in either (0,M_PI] or [M_PI, 2.*M_PI).
|
---|
[f1cccd] | 3178 | * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa FindStartingTriangle())
|
---|
[357fba] | 3179 | * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
|
---|
| 3180 | * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
|
---|
[f67b6e] | 3181 | * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
|
---|
[09898c] | 3182 | * @param ThirdPoint third point to avoid in search
|
---|
[357fba] | 3183 | * @param RADIUS radius of sphere
|
---|
[62bb91] | 3184 | * @param *LC LinkedCell structure with neighbouring points
|
---|
[357fba] | 3185 | */
|
---|
[6613ec] | 3186 | void Tesselation::FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdPoint, const double RADIUS, const LinkedCell *LC) const
|
---|
[357fba] | 3187 | {
|
---|
[6613ec] | 3188 | Info FunctionInfo(__func__);
|
---|
| 3189 | Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
|
---|
[357fba] | 3190 | Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
|
---|
| 3191 | Vector SphereCenter;
|
---|
[6613ec] | 3192 | Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
|
---|
| 3193 | Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
|
---|
| 3194 | Vector NewNormalVector; // normal vector of the Candidate's triangle
|
---|
[357fba] | 3195 | Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
|
---|
[b998c3] | 3196 | Vector RelativeOldSphereCenter;
|
---|
| 3197 | Vector NewPlaneCenter;
|
---|
[357fba] | 3198 | double CircleRadius; // radius of this circle
|
---|
| 3199 | double radius;
|
---|
[b998c3] | 3200 | double otherradius;
|
---|
[357fba] | 3201 | double alpha, Otheralpha; // angles (i.e. parameter for the circle).
|
---|
| 3202 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
| 3203 | TesselPoint *Candidate = NULL;
|
---|
| 3204 |
|
---|
[a67d19] | 3205 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl);
|
---|
[357fba] | 3206 |
|
---|
[09898c] | 3207 | // copy old center
|
---|
[8cbb97] | 3208 | CandidateLine.OldCenter = OldSphereCenter;
|
---|
[09898c] | 3209 | CandidateLine.ThirdPoint = ThirdPoint;
|
---|
| 3210 | CandidateLine.pointlist.clear();
|
---|
[357fba] | 3211 |
|
---|
| 3212 | // construct center of circle
|
---|
[273382] | 3213 | CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
|
---|
| 3214 | (*CandidateLine.BaseLine->endpoints[1]->node->node));
|
---|
[357fba] | 3215 |
|
---|
| 3216 | // construct normal vector of circle
|
---|
[273382] | 3217 | CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
|
---|
| 3218 | (*CandidateLine.BaseLine->endpoints[1]->node->node);
|
---|
[357fba] | 3219 |
|
---|
[273382] | 3220 | RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
|
---|
[b998c3] | 3221 |
|
---|
[09898c] | 3222 | // calculate squared radius TesselPoint *ThirdPoint,f circle
|
---|
[6613ec] | 3223 | radius = CirclePlaneNormal.NormSquared() / 4.;
|
---|
| 3224 | if (radius < RADIUS * RADIUS) {
|
---|
| 3225 | CircleRadius = RADIUS * RADIUS - radius;
|
---|
[357fba] | 3226 | CirclePlaneNormal.Normalize();
|
---|
[a67d19] | 3227 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
[357fba] | 3228 |
|
---|
| 3229 | // test whether old center is on the band's plane
|
---|
[273382] | 3230 | if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
|
---|
[8cbb97] | 3231 | DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!" << endl);
|
---|
[273382] | 3232 | RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal);
|
---|
[357fba] | 3233 | }
|
---|
[b998c3] | 3234 | radius = RelativeOldSphereCenter.NormSquared();
|
---|
[357fba] | 3235 | if (fabs(radius - CircleRadius) < HULLEPSILON) {
|
---|
[a67d19] | 3236 | DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl);
|
---|
[357fba] | 3237 |
|
---|
| 3238 | // check SearchDirection
|
---|
[a67d19] | 3239 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
[8cbb97] | 3240 | if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
|
---|
[6613ec] | 3241 | DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
|
---|
[357fba] | 3242 | }
|
---|
| 3243 |
|
---|
[62bb91] | 3244 | // get cell for the starting point
|
---|
[357fba] | 3245 | if (LC->SetIndexToVector(&CircleCenter)) {
|
---|
[6613ec] | 3246 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
| 3247 | N[i] = LC->n[i];
|
---|
[f67b6e] | 3248 | //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3249 | } else {
|
---|
[6613ec] | 3250 | DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);
|
---|
[357fba] | 3251 | return;
|
---|
| 3252 | }
|
---|
[62bb91] | 3253 | // then go through the current and all neighbouring cells and check the contained points for possible candidates
|
---|
[f67b6e] | 3254 | //Log() << Verbose(1) << "LC Intervals:";
|
---|
[6613ec] | 3255 | for (int i = 0; i < NDIM; i++) {
|
---|
| 3256 | Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
|
---|
| 3257 | Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
|
---|
[e138de] | 3258 | //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
|
---|
[357fba] | 3259 | }
|
---|
[e138de] | 3260 | //Log() << Verbose(0) << endl;
|
---|
[357fba] | 3261 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3262 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3263 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3264 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[f67b6e] | 3265 | //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
|
---|
[357fba] | 3266 | if (List != NULL) {
|
---|
[734816] | 3267 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[357fba] | 3268 | Candidate = (*Runner);
|
---|
| 3269 |
|
---|
| 3270 | // check for three unique points
|
---|
[a67d19] | 3271 | DoLog(2) && (Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl);
|
---|
[6613ec] | 3272 | if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) {
|
---|
[357fba] | 3273 |
|
---|
[b998c3] | 3274 | // find center on the plane
|
---|
| 3275 | GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
|
---|
[a67d19] | 3276 | DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl);
|
---|
[357fba] | 3277 |
|
---|
[0a4f7f] | 3278 | try {
|
---|
| 3279 | NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node),
|
---|
[8cbb97] | 3280 | *(CandidateLine.BaseLine->endpoints[1]->node->node),
|
---|
| 3281 | *(Candidate->node)).getNormal();
|
---|
[a67d19] | 3282 | DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl);
|
---|
[273382] | 3283 | radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter);
|
---|
[a67d19] | 3284 | DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
|
---|
| 3285 | DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
|
---|
| 3286 | DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl);
|
---|
[6613ec] | 3287 | if (radius < RADIUS * RADIUS) {
|
---|
[273382] | 3288 | otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter);
|
---|
[620a3f] | 3289 | if (fabs(radius - otherradius) < HULLEPSILON) {
|
---|
| 3290 | // construct both new centers
|
---|
[8cbb97] | 3291 | NewSphereCenter = NewPlaneCenter;
|
---|
| 3292 | OtherNewSphereCenter= NewPlaneCenter;
|
---|
| 3293 | helper = NewNormalVector;
|
---|
[620a3f] | 3294 | helper.Scale(sqrt(RADIUS * RADIUS - radius));
|
---|
| 3295 | DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl);
|
---|
[8cbb97] | 3296 | NewSphereCenter += helper;
|
---|
[620a3f] | 3297 | DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl);
|
---|
| 3298 | // OtherNewSphereCenter is created by the same vector just in the other direction
|
---|
| 3299 | helper.Scale(-1.);
|
---|
[8cbb97] | 3300 | OtherNewSphereCenter += helper;
|
---|
[620a3f] | 3301 | DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl);
|
---|
| 3302 | alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
| 3303 | Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
|
---|
[b1a6d8] | 3304 | if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
|
---|
[8cbb97] | 3305 | if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter))
|
---|
[b1a6d8] | 3306 | alpha = Otheralpha;
|
---|
| 3307 | } else
|
---|
| 3308 | alpha = min(alpha, Otheralpha);
|
---|
[620a3f] | 3309 | // if there is a better candidate, drop the current list and add the new candidate
|
---|
| 3310 | // otherwise ignore the new candidate and keep the list
|
---|
| 3311 | if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
|
---|
| 3312 | if (fabs(alpha - Otheralpha) > MYEPSILON) {
|
---|
[8cbb97] | 3313 | CandidateLine.OptCenter = NewSphereCenter;
|
---|
| 3314 | CandidateLine.OtherOptCenter = OtherNewSphereCenter;
|
---|
[620a3f] | 3315 | } else {
|
---|
[8cbb97] | 3316 | CandidateLine.OptCenter = OtherNewSphereCenter;
|
---|
| 3317 | CandidateLine.OtherOptCenter = NewSphereCenter;
|
---|
[620a3f] | 3318 | }
|
---|
| 3319 | // if there is an equal candidate, add it to the list without clearing the list
|
---|
| 3320 | if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
|
---|
| 3321 | CandidateLine.pointlist.push_back(Candidate);
|
---|
| 3322 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
|
---|
| 3323 | } else {
|
---|
| 3324 | // remove all candidates from the list and then the list itself
|
---|
| 3325 | CandidateLine.pointlist.clear();
|
---|
| 3326 | CandidateLine.pointlist.push_back(Candidate);
|
---|
| 3327 | DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
|
---|
| 3328 | }
|
---|
| 3329 | CandidateLine.ShortestAngle = alpha;
|
---|
| 3330 | DoLog(0) && (Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl);
|
---|
[357fba] | 3331 | } else {
|
---|
[620a3f] | 3332 | if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
|
---|
| 3333 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl);
|
---|
| 3334 | } else {
|
---|
| 3335 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl);
|
---|
| 3336 | }
|
---|
[357fba] | 3337 | }
|
---|
| 3338 | } else {
|
---|
[b32dbb] | 3339 | DoeLog(0) && (eLog() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
|
---|
[357fba] | 3340 | }
|
---|
| 3341 | } else {
|
---|
[a67d19] | 3342 | DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl);
|
---|
[357fba] | 3343 | }
|
---|
[0a4f7f] | 3344 | }
|
---|
| 3345 | catch (LinearDependenceException &excp){
|
---|
| 3346 | Log() << Verbose(1) << excp;
|
---|
[f67b6e] | 3347 | Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
|
---|
[357fba] | 3348 | }
|
---|
| 3349 | } else {
|
---|
[09898c] | 3350 | if (ThirdPoint != NULL) {
|
---|
[a67d19] | 3351 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << "." << endl);
|
---|
[357fba] | 3352 | } else {
|
---|
[a67d19] | 3353 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl);
|
---|
[357fba] | 3354 | }
|
---|
| 3355 | }
|
---|
| 3356 | }
|
---|
| 3357 | }
|
---|
| 3358 | }
|
---|
| 3359 | } else {
|
---|
[6613ec] | 3360 | DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
|
---|
[357fba] | 3361 | }
|
---|
| 3362 | } else {
|
---|
[09898c] | 3363 | if (ThirdPoint != NULL)
|
---|
[a67d19] | 3364 | DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!" << endl);
|
---|
[357fba] | 3365 | else
|
---|
[a67d19] | 3366 | DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl);
|
---|
[357fba] | 3367 | }
|
---|
| 3368 |
|
---|
[734816] | 3369 | DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl);
|
---|
[f67b6e] | 3370 | if (CandidateLine.pointlist.size() > 1) {
|
---|
| 3371 | CandidateLine.pointlist.unique();
|
---|
| 3372 | CandidateLine.pointlist.sort(); //SortCandidates);
|
---|
[357fba] | 3373 | }
|
---|
[6613ec] | 3374 |
|
---|
| 3375 | if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
|
---|
| 3376 | DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
|
---|
| 3377 | performCriticalExit();
|
---|
| 3378 | }
|
---|
| 3379 | }
|
---|
| 3380 | ;
|
---|
[357fba] | 3381 |
|
---|
| 3382 | /** Finds the endpoint two lines are sharing.
|
---|
| 3383 | * \param *line1 first line
|
---|
| 3384 | * \param *line2 second line
|
---|
| 3385 | * \return point which is shared or NULL if none
|
---|
| 3386 | */
|
---|
[776b64] | 3387 | class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
|
---|
[357fba] | 3388 | {
|
---|
[6613ec] | 3389 | Info FunctionInfo(__func__);
|
---|
[776b64] | 3390 | const BoundaryLineSet * lines[2] = { line1, line2 };
|
---|
[357fba] | 3391 | class BoundaryPointSet *node = NULL;
|
---|
[c15ca2] | 3392 | PointMap OrderMap;
|
---|
| 3393 | PointTestPair OrderTest;
|
---|
[357fba] | 3394 | for (int i = 0; i < 2; i++)
|
---|
| 3395 | // for both lines
|
---|
[6613ec] | 3396 | for (int j = 0; j < 2; j++) { // for both endpoints
|
---|
| 3397 | OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
|
---|
| 3398 | if (!OrderTest.second) { // if insertion fails, we have common endpoint
|
---|
| 3399 | node = OrderTest.first->second;
|
---|
[a67d19] | 3400 | DoLog(1) && (Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl);
|
---|
[6613ec] | 3401 | j = 2;
|
---|
| 3402 | i = 2;
|
---|
| 3403 | break;
|
---|
[357fba] | 3404 | }
|
---|
[6613ec] | 3405 | }
|
---|
[357fba] | 3406 | return node;
|
---|
[6613ec] | 3407 | }
|
---|
| 3408 | ;
|
---|
[357fba] | 3409 |
|
---|
[c15ca2] | 3410 | /** Finds the boundary points that are closest to a given Vector \a *x.
|
---|
[62bb91] | 3411 | * \param *out output stream for debugging
|
---|
| 3412 | * \param *x Vector to look from
|
---|
[c15ca2] | 3413 | * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
|
---|
[62bb91] | 3414 | */
|
---|
[97498a] | 3415 | DistanceToPointMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 3416 | {
|
---|
[c15ca2] | 3417 | Info FunctionInfo(__func__);
|
---|
[71b20e] | 3418 | PointMap::const_iterator FindPoint;
|
---|
| 3419 | int N[NDIM], Nlower[NDIM], Nupper[NDIM];
|
---|
[62bb91] | 3420 |
|
---|
| 3421 | if (LinesOnBoundary.empty()) {
|
---|
[6613ec] | 3422 | DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);
|
---|
[62bb91] | 3423 | return NULL;
|
---|
| 3424 | }
|
---|
[71b20e] | 3425 |
|
---|
| 3426 | // gather all points close to the desired one
|
---|
| 3427 | LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
|
---|
[6613ec] | 3428 | for (int i = 0; i < NDIM; i++) // store indices of this cell
|
---|
[71b20e] | 3429 | N[i] = LC->n[i];
|
---|
[a67d19] | 3430 | DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
|
---|
[97498a] | 3431 | DistanceToPointMap * points = new DistanceToPointMap;
|
---|
[71b20e] | 3432 | LC->GetNeighbourBounds(Nlower, Nupper);
|
---|
| 3433 | //Log() << Verbose(1) << endl;
|
---|
| 3434 | for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
|
---|
| 3435 | for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
|
---|
| 3436 | for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
|
---|
[734816] | 3437 | const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
|
---|
[71b20e] | 3438 | //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
|
---|
| 3439 | if (List != NULL) {
|
---|
[734816] | 3440 | for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
|
---|
[71b20e] | 3441 | FindPoint = PointsOnBoundary.find((*Runner)->nr);
|
---|
[97498a] | 3442 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
[8cbb97] | 3443 | points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second));
|
---|
[a67d19] | 3444 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl);
|
---|
[97498a] | 3445 | }
|
---|
[71b20e] | 3446 | }
|
---|
| 3447 | } else {
|
---|
[6613ec] | 3448 | DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
|
---|
[99593f] | 3449 | }
|
---|
[57066a] | 3450 | }
|
---|
[62bb91] | 3451 |
|
---|
[71b20e] | 3452 | // check whether we found some points
|
---|
[c15ca2] | 3453 | if (points->empty()) {
|
---|
[6613ec] | 3454 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
| 3455 | delete (points);
|
---|
[c15ca2] | 3456 | return NULL;
|
---|
| 3457 | }
|
---|
| 3458 | return points;
|
---|
[6613ec] | 3459 | }
|
---|
| 3460 | ;
|
---|
[c15ca2] | 3461 |
|
---|
| 3462 | /** Finds the boundary line that is closest to a given Vector \a *x.
|
---|
| 3463 | * \param *out output stream for debugging
|
---|
| 3464 | * \param *x Vector to look from
|
---|
| 3465 | * \return closest BoundaryLineSet or NULL in degenerate case.
|
---|
| 3466 | */
|
---|
| 3467 | BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const
|
---|
| 3468 | {
|
---|
| 3469 | Info FunctionInfo(__func__);
|
---|
| 3470 | // get closest points
|
---|
[6613ec] | 3471 | DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
|
---|
[c15ca2] | 3472 | if (points == NULL) {
|
---|
[6613ec] | 3473 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
[71b20e] | 3474 | return NULL;
|
---|
| 3475 | }
|
---|
[62bb91] | 3476 |
|
---|
[71b20e] | 3477 | // for each point, check its lines, remember closest
|
---|
[a67d19] | 3478 | DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl);
|
---|
[71b20e] | 3479 | BoundaryLineSet *ClosestLine = NULL;
|
---|
| 3480 | double MinDistance = -1.;
|
---|
| 3481 | Vector helper;
|
---|
| 3482 | Vector Center;
|
---|
| 3483 | Vector BaseLine;
|
---|
[97498a] | 3484 | for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
|
---|
[c15ca2] | 3485 | for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
|
---|
[71b20e] | 3486 | // calculate closest point on line to desired point
|
---|
[273382] | 3487 | helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) +
|
---|
| 3488 | (*(LineRunner->second)->endpoints[1]->node->node));
|
---|
| 3489 | Center = (*x) - helper;
|
---|
| 3490 | BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
|
---|
| 3491 | (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3492 | Center.ProjectOntoPlane(BaseLine);
|
---|
[71b20e] | 3493 | const double distance = Center.NormSquared();
|
---|
| 3494 | if ((ClosestLine == NULL) || (distance < MinDistance)) {
|
---|
| 3495 | // additionally calculate intersection on line (whether it's on the line section or not)
|
---|
[273382] | 3496 | helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center;
|
---|
| 3497 | const double lengthA = helper.ScalarProduct(BaseLine);
|
---|
| 3498 | helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center;
|
---|
| 3499 | const double lengthB = helper.ScalarProduct(BaseLine);
|
---|
[6613ec] | 3500 | if (lengthB * lengthA < 0) { // if have different sign
|
---|
[71b20e] | 3501 | ClosestLine = LineRunner->second;
|
---|
| 3502 | MinDistance = distance;
|
---|
[a67d19] | 3503 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl);
|
---|
[71b20e] | 3504 | } else {
|
---|
[a67d19] | 3505 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl);
|
---|
[71b20e] | 3506 | }
|
---|
| 3507 | } else {
|
---|
[a67d19] | 3508 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl);
|
---|
[71b20e] | 3509 | }
|
---|
[99593f] | 3510 | }
|
---|
[57066a] | 3511 | }
|
---|
[6613ec] | 3512 | delete (points);
|
---|
[71b20e] | 3513 | // check whether closest line is "too close" :), then it's inside
|
---|
| 3514 | if (ClosestLine == NULL) {
|
---|
[a67d19] | 3515 | DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
|
---|
[62bb91] | 3516 | return NULL;
|
---|
[71b20e] | 3517 | }
|
---|
[c15ca2] | 3518 | return ClosestLine;
|
---|
[6613ec] | 3519 | }
|
---|
| 3520 | ;
|
---|
[c15ca2] | 3521 |
|
---|
| 3522 | /** Finds the triangle that is closest to a given Vector \a *x.
|
---|
| 3523 | * \param *out output stream for debugging
|
---|
| 3524 | * \param *x Vector to look from
|
---|
| 3525 | * \return BoundaryTriangleSet of nearest triangle or NULL.
|
---|
| 3526 | */
|
---|
| 3527 | TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
|
---|
| 3528 | {
|
---|
[6613ec] | 3529 | Info FunctionInfo(__func__);
|
---|
| 3530 | // get closest points
|
---|
| 3531 | DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
|
---|
[c15ca2] | 3532 | if (points == NULL) {
|
---|
[6613ec] | 3533 | DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
|
---|
[c15ca2] | 3534 | return NULL;
|
---|
| 3535 | }
|
---|
| 3536 |
|
---|
| 3537 | // for each point, check its lines, remember closest
|
---|
[a67d19] | 3538 | DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl);
|
---|
[48b47a] | 3539 | LineSet ClosestLines;
|
---|
[97498a] | 3540 | double MinDistance = 1e+16;
|
---|
| 3541 | Vector BaseLineIntersection;
|
---|
[c15ca2] | 3542 | Vector Center;
|
---|
| 3543 | Vector BaseLine;
|
---|
[97498a] | 3544 | Vector BaseLineCenter;
|
---|
| 3545 | for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
|
---|
[c15ca2] | 3546 | for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
|
---|
[97498a] | 3547 |
|
---|
[273382] | 3548 | BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
|
---|
| 3549 | (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
[97498a] | 3550 | const double lengthBase = BaseLine.NormSquared();
|
---|
| 3551 |
|
---|
[273382] | 3552 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node);
|
---|
[97498a] | 3553 | const double lengthEndA = BaseLineIntersection.NormSquared();
|
---|
| 3554 |
|
---|
[273382] | 3555 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
[97498a] | 3556 | const double lengthEndB = BaseLineIntersection.NormSquared();
|
---|
| 3557 |
|
---|
[6613ec] | 3558 | if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
|
---|
[48b47a] | 3559 | const double lengthEnd = Min(lengthEndA, lengthEndB);
|
---|
| 3560 | if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
|
---|
| 3561 | ClosestLines.clear();
|
---|
| 3562 | ClosestLines.insert(LineRunner->second);
|
---|
| 3563 | MinDistance = lengthEnd;
|
---|
[a67d19] | 3564 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl);
|
---|
[6613ec] | 3565 | } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
|
---|
[48b47a] | 3566 | ClosestLines.insert(LineRunner->second);
|
---|
[a67d19] | 3567 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl);
|
---|
[48b47a] | 3568 | } else { // line is worse
|
---|
[a67d19] | 3569 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << "." << endl);
|
---|
[97498a] | 3570 | }
|
---|
| 3571 | } else { // intersection is closer, calculate
|
---|
[c15ca2] | 3572 | // calculate closest point on line to desired point
|
---|
[273382] | 3573 | BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
|
---|
| 3574 | Center = BaseLineIntersection;
|
---|
| 3575 | Center.ProjectOntoPlane(BaseLine);
|
---|
| 3576 | BaseLineIntersection -= Center;
|
---|
[97498a] | 3577 | const double distance = BaseLineIntersection.NormSquared();
|
---|
| 3578 | if (Center.NormSquared() > BaseLine.NormSquared()) {
|
---|
[6613ec] | 3579 | DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);
|
---|
[97498a] | 3580 | }
|
---|
[48b47a] | 3581 | if ((ClosestLines.empty()) || (distance < MinDistance)) {
|
---|
| 3582 | ClosestLines.insert(LineRunner->second);
|
---|
[97498a] | 3583 | MinDistance = distance;
|
---|
[a67d19] | 3584 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl);
|
---|
[c15ca2] | 3585 | } else {
|
---|
[a67d19] | 3586 | DoLog(2) && (Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl);
|
---|
[c15ca2] | 3587 | }
|
---|
| 3588 | }
|
---|
| 3589 | }
|
---|
| 3590 | }
|
---|
[6613ec] | 3591 | delete (points);
|
---|
[c15ca2] | 3592 |
|
---|
| 3593 | // check whether closest line is "too close" :), then it's inside
|
---|
[48b47a] | 3594 | if (ClosestLines.empty()) {
|
---|
[a67d19] | 3595 | DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
|
---|
[c15ca2] | 3596 | return NULL;
|
---|
| 3597 | }
|
---|
| 3598 | TriangleList * candidates = new TriangleList;
|
---|
[48b47a] | 3599 | for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
|
---|
| 3600 | for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
|
---|
[6613ec] | 3601 | candidates->push_back(Runner->second);
|
---|
| 3602 | }
|
---|
[c15ca2] | 3603 | return candidates;
|
---|
[6613ec] | 3604 | }
|
---|
| 3605 | ;
|
---|
[62bb91] | 3606 |
|
---|
| 3607 | /** Finds closest triangle to a point.
|
---|
| 3608 | * This basically just takes care of the degenerate case, which is not handled in FindClosestTrianglesToPoint().
|
---|
| 3609 | * \param *out output stream for debugging
|
---|
| 3610 | * \param *x Vector to look from
|
---|
[8db598] | 3611 | * \param &distance contains found distance on return
|
---|
[62bb91] | 3612 | * \return list of BoundaryTriangleSet of nearest triangles or NULL.
|
---|
| 3613 | */
|
---|
[c15ca2] | 3614 | class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
|
---|
[62bb91] | 3615 | {
|
---|
[6613ec] | 3616 | Info FunctionInfo(__func__);
|
---|
[62bb91] | 3617 | class BoundaryTriangleSet *result = NULL;
|
---|
[c15ca2] | 3618 | TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
|
---|
| 3619 | TriangleList candidates;
|
---|
[57066a] | 3620 | Vector Center;
|
---|
[71b20e] | 3621 | Vector helper;
|
---|
[62bb91] | 3622 |
|
---|
[71b20e] | 3623 | if ((triangles == NULL) || (triangles->empty()))
|
---|
[62bb91] | 3624 | return NULL;
|
---|
| 3625 |
|
---|
[97498a] | 3626 | // go through all and pick the one with the best alignment to x
|
---|
[6613ec] | 3627 | double MinAlignment = 2. * M_PI;
|
---|
[c15ca2] | 3628 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
|
---|
[71b20e] | 3629 | (*Runner)->GetCenter(&Center);
|
---|
[273382] | 3630 | helper = (*x) - Center;
|
---|
| 3631 | const double Alignment = helper.Angle((*Runner)->NormalVector);
|
---|
[97498a] | 3632 | if (Alignment < MinAlignment) {
|
---|
| 3633 | result = *Runner;
|
---|
| 3634 | MinAlignment = Alignment;
|
---|
[a67d19] | 3635 | DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl);
|
---|
[71b20e] | 3636 | } else {
|
---|
[a67d19] | 3637 | DoLog(1) && (Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl);
|
---|
[57066a] | 3638 | }
|
---|
| 3639 | }
|
---|
[6613ec] | 3640 | delete (triangles);
|
---|
[97498a] | 3641 |
|
---|
[62bb91] | 3642 | return result;
|
---|
[6613ec] | 3643 | }
|
---|
| 3644 | ;
|
---|
[62bb91] | 3645 |
|
---|
[9473f6] | 3646 | /** Checks whether the provided Vector is within the Tesselation structure.
|
---|
| 3647 | * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value.
|
---|
| 3648 | * @param point of which to check the position
|
---|
| 3649 | * @param *LC LinkedCell structure
|
---|
| 3650 | *
|
---|
| 3651 | * @return true if the point is inside the Tesselation structure, false otherwise
|
---|
| 3652 | */
|
---|
| 3653 | bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
|
---|
| 3654 | {
|
---|
[8db598] | 3655 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3656 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3657 |
|
---|
| 3658 | return Intersections.IsInside();
|
---|
[9473f6] | 3659 | }
|
---|
[6613ec] | 3660 | ;
|
---|
[9473f6] | 3661 |
|
---|
| 3662 | /** Returns the distance to the surface given by the tesselation.
|
---|
[97498a] | 3663 | * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points
|
---|
[9473f6] | 3664 | * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the
|
---|
| 3665 | * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's
|
---|
| 3666 | * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle().
|
---|
| 3667 | * In the end we additionally find the point on the triangle who was smallest distance to \a Point:
|
---|
| 3668 | * -# Separate distance from point to center in vector in NormalDirection and on the triangle plane.
|
---|
| 3669 | * -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds.
|
---|
| 3670 | * -# If inside, take it to calculate closest distance
|
---|
| 3671 | * -# If not, take intersection with BoundaryLine as distance
|
---|
| 3672 | *
|
---|
| 3673 | * @note distance is squared despite it still contains a sign to determine in-/outside!
|
---|
[62bb91] | 3674 | *
|
---|
| 3675 | * @param point of which to check the position
|
---|
| 3676 | * @param *LC LinkedCell structure
|
---|
| 3677 | *
|
---|
[244a84] | 3678 | * @return >0 if outside, ==0 if on surface, <0 if inside
|
---|
[62bb91] | 3679 | */
|
---|
[244a84] | 3680 | double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
|
---|
[62bb91] | 3681 | {
|
---|
[fcad4b] | 3682 | Info FunctionInfo(__func__);
|
---|
[57066a] | 3683 | Vector Center;
|
---|
[71b20e] | 3684 | Vector helper;
|
---|
[97498a] | 3685 | Vector DistanceToCenter;
|
---|
| 3686 | Vector Intersection;
|
---|
[9473f6] | 3687 | double distance = 0.;
|
---|
[57066a] | 3688 |
|
---|
[244a84] | 3689 | if (triangle == NULL) {// is boundary point or only point in point cloud?
|
---|
[a67d19] | 3690 | DoLog(1) && (Log() << Verbose(1) << "No triangle given!" << endl);
|
---|
[244a84] | 3691 | return -1.;
|
---|
[71b20e] | 3692 | } else {
|
---|
[a67d19] | 3693 | DoLog(1) && (Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl);
|
---|
[57066a] | 3694 | }
|
---|
| 3695 |
|
---|
[244a84] | 3696 | triangle->GetCenter(&Center);
|
---|
[a67d19] | 3697 | DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl);
|
---|
[273382] | 3698 | DistanceToCenter = Center - Point;
|
---|
[a67d19] | 3699 | DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl);
|
---|
[97498a] | 3700 |
|
---|
| 3701 | // check whether we are on boundary
|
---|
[273382] | 3702 | if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) {
|
---|
[97498a] | 3703 | // calculate whether inside of triangle
|
---|
[273382] | 3704 | DistanceToCenter = Point + triangle->NormalVector; // points outside
|
---|
| 3705 | Center = Point - triangle->NormalVector; // points towards MolCenter
|
---|
[a67d19] | 3706 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl);
|
---|
[244a84] | 3707 | if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
|
---|
[a67d19] | 3708 | DoLog(1) && (Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl);
|
---|
[9473f6] | 3709 | return 0.;
|
---|
[97498a] | 3710 | } else {
|
---|
[a67d19] | 3711 | DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl);
|
---|
[97498a] | 3712 | return false;
|
---|
| 3713 | }
|
---|
[57066a] | 3714 | } else {
|
---|
[9473f6] | 3715 | // calculate smallest distance
|
---|
[244a84] | 3716 | distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
|
---|
[a67d19] | 3717 | DoLog(1) && (Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl);
|
---|
[9473f6] | 3718 |
|
---|
| 3719 | // then check direction to boundary
|
---|
[273382] | 3720 | if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) {
|
---|
[a67d19] | 3721 | DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl);
|
---|
[9473f6] | 3722 | return -distance;
|
---|
| 3723 | } else {
|
---|
[a67d19] | 3724 | DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl);
|
---|
[9473f6] | 3725 | return +distance;
|
---|
| 3726 | }
|
---|
[57066a] | 3727 | }
|
---|
[6613ec] | 3728 | }
|
---|
| 3729 | ;
|
---|
[62bb91] | 3730 |
|
---|
[8db598] | 3731 | /** Calculates minimum distance from \a&Point to a tesselated surface.
|
---|
[244a84] | 3732 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
|
---|
| 3733 | * \param &Point point to calculate distance from
|
---|
| 3734 | * \param *LC needed for finding closest points fast
|
---|
| 3735 | * \return distance squared to closest point on surface
|
---|
| 3736 | */
|
---|
[8db598] | 3737 | double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const
|
---|
[244a84] | 3738 | {
|
---|
[8db598] | 3739 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3740 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3741 |
|
---|
| 3742 | return Intersections.GetSmallestDistance();
|
---|
[6613ec] | 3743 | }
|
---|
| 3744 | ;
|
---|
[8db598] | 3745 |
|
---|
| 3746 | /** Calculates minimum distance from \a&Point to a tesselated surface.
|
---|
| 3747 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
|
---|
| 3748 | * \param &Point point to calculate distance from
|
---|
| 3749 | * \param *LC needed for finding closest points fast
|
---|
| 3750 | * \return distance squared to closest point on surface
|
---|
| 3751 | */
|
---|
| 3752 | BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const
|
---|
| 3753 | {
|
---|
| 3754 | Info FunctionInfo(__func__);
|
---|
[6613ec] | 3755 | TriangleIntersectionList Intersections(&Point, this, LC);
|
---|
[8db598] | 3756 |
|
---|
| 3757 | return Intersections.GetClosestTriangle();
|
---|
[6613ec] | 3758 | }
|
---|
| 3759 | ;
|
---|
[244a84] | 3760 |
|
---|
[62bb91] | 3761 | /** Gets all points connected to the provided point by triangulation lines.
|
---|
| 3762 | *
|
---|
| 3763 | * @param *Point of which get all connected points
|
---|
| 3764 | *
|
---|
[065e82] | 3765 | * @return set of the all points linked to the provided one
|
---|
[62bb91] | 3766 | */
|
---|
[c15ca2] | 3767 | TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
|
---|
[62bb91] | 3768 | {
|
---|
[6613ec] | 3769 | Info FunctionInfo(__func__);
|
---|
| 3770 | TesselPointSet *connectedPoints = new TesselPointSet;
|
---|
[5c7bf8] | 3771 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
[62bb91] | 3772 | TesselPoint* current;
|
---|
| 3773 | bool takePoint = false;
|
---|
[5c7bf8] | 3774 | // find the respective boundary point
|
---|
[776b64] | 3775 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[5c7bf8] | 3776 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 3777 | ReferencePoint = PointRunner->second;
|
---|
| 3778 | } else {
|
---|
[6613ec] | 3779 | DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
|
---|
[5c7bf8] | 3780 | ReferencePoint = NULL;
|
---|
| 3781 | }
|
---|
[62bb91] | 3782 |
|
---|
[065e82] | 3783 | // little trick so that we look just through lines connect to the BoundaryPoint
|
---|
[5c7bf8] | 3784 | // OR fall-back to look through all lines if there is no such BoundaryPoint
|
---|
[6613ec] | 3785 | const LineMap *Lines;
|
---|
| 3786 | ;
|
---|
[5c7bf8] | 3787 | if (ReferencePoint != NULL)
|
---|
| 3788 | Lines = &(ReferencePoint->lines);
|
---|
[776b64] | 3789 | else
|
---|
| 3790 | Lines = &LinesOnBoundary;
|
---|
| 3791 | LineMap::const_iterator findLines = Lines->begin();
|
---|
[5c7bf8] | 3792 | while (findLines != Lines->end()) {
|
---|
[6613ec] | 3793 | takePoint = false;
|
---|
| 3794 |
|
---|
| 3795 | if (findLines->second->endpoints[0]->Nr == Point->nr) {
|
---|
| 3796 | takePoint = true;
|
---|
| 3797 | current = findLines->second->endpoints[1]->node;
|
---|
| 3798 | } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
|
---|
| 3799 | takePoint = true;
|
---|
| 3800 | current = findLines->second->endpoints[0]->node;
|
---|
| 3801 | }
|
---|
[065e82] | 3802 |
|
---|
[6613ec] | 3803 | if (takePoint) {
|
---|
[a67d19] | 3804 | DoLog(1) && (Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl);
|
---|
[6613ec] | 3805 | connectedPoints->insert(current);
|
---|
| 3806 | }
|
---|
[62bb91] | 3807 |
|
---|
[6613ec] | 3808 | findLines++;
|
---|
[62bb91] | 3809 | }
|
---|
| 3810 |
|
---|
[71b20e] | 3811 | if (connectedPoints->empty()) { // if have not found any points
|
---|
[6613ec] | 3812 | DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl);
|
---|
[16d866] | 3813 | return NULL;
|
---|
| 3814 | }
|
---|
[065e82] | 3815 |
|
---|
[16d866] | 3816 | return connectedPoints;
|
---|
[6613ec] | 3817 | }
|
---|
| 3818 | ;
|
---|
[065e82] | 3819 |
|
---|
| 3820 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
[16d866] | 3821 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 3822 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 3823 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 3824 | * triangle we are looking for.
|
---|
| 3825 | *
|
---|
| 3826 | * @param *out output stream for debugging
|
---|
[27bd2f] | 3827 | * @param *SetOfNeighbours all points for which the angle should be calculated
|
---|
[16d866] | 3828 | * @param *Point of which get all connected points
|
---|
[065e82] | 3829 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 3830 | * @return list of the all points linked to the provided one
|
---|
[16d866] | 3831 | */
|
---|
[c15ca2] | 3832 | TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[16d866] | 3833 | {
|
---|
[6613ec] | 3834 | Info FunctionInfo(__func__);
|
---|
[16d866] | 3835 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3836 | TesselPointList *connectedCircle = new TesselPointList;
|
---|
[71b20e] | 3837 | Vector PlaneNormal;
|
---|
| 3838 | Vector AngleZero;
|
---|
| 3839 | Vector OrthogonalVector;
|
---|
| 3840 | Vector helper;
|
---|
[6613ec] | 3841 | const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL };
|
---|
[c15ca2] | 3842 | TriangleList *triangles = NULL;
|
---|
[71b20e] | 3843 |
|
---|
| 3844 | if (SetOfNeighbours == NULL) {
|
---|
[6613ec] | 3845 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
|
---|
| 3846 | delete (connectedCircle);
|
---|
[71b20e] | 3847 | return NULL;
|
---|
| 3848 | }
|
---|
| 3849 |
|
---|
| 3850 | // calculate central point
|
---|
| 3851 | triangles = FindTriangles(TrianglePoints);
|
---|
| 3852 | if ((triangles != NULL) && (!triangles->empty())) {
|
---|
[c15ca2] | 3853 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
|
---|
[273382] | 3854 | PlaneNormal += (*Runner)->NormalVector;
|
---|
[71b20e] | 3855 | } else {
|
---|
[6613ec] | 3856 | DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
|
---|
[71b20e] | 3857 | performCriticalExit();
|
---|
| 3858 | }
|
---|
[6613ec] | 3859 | PlaneNormal.Scale(1.0 / triangles->size());
|
---|
[a67d19] | 3860 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl);
|
---|
[71b20e] | 3861 | PlaneNormal.Normalize();
|
---|
| 3862 |
|
---|
| 3863 | // construct one orthogonal vector
|
---|
| 3864 | if (Reference != NULL) {
|
---|
[273382] | 3865 | AngleZero = (*Reference) - (*Point->node);
|
---|
| 3866 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3867 | }
|
---|
[6613ec] | 3868 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
|
---|
[a67d19] | 3869 | DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
|
---|
[273382] | 3870 | AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
|
---|
| 3871 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3872 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
[6613ec] | 3873 | DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
|
---|
[71b20e] | 3874 | performCriticalExit();
|
---|
| 3875 | }
|
---|
| 3876 | }
|
---|
[a67d19] | 3877 | DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
|
---|
[71b20e] | 3878 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
[0a4f7f] | 3879 | OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
|
---|
[71b20e] | 3880 | else
|
---|
[0a4f7f] | 3881 | OrthogonalVector.MakeNormalTo(PlaneNormal);
|
---|
[a67d19] | 3882 | DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
|
---|
[71b20e] | 3883 |
|
---|
| 3884 | // go through all connected points and calculate angle
|
---|
[c15ca2] | 3885 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
|
---|
[273382] | 3886 | helper = (*(*listRunner)->node) - (*Point->node);
|
---|
| 3887 | helper.ProjectOntoPlane(PlaneNormal);
|
---|
[71b20e] | 3888 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
[a67d19] | 3889 | DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl);
|
---|
[6613ec] | 3890 | anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
|
---|
[71b20e] | 3891 | }
|
---|
| 3892 |
|
---|
[6613ec] | 3893 | for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
[71b20e] | 3894 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 3895 | }
|
---|
| 3896 |
|
---|
| 3897 | return connectedCircle;
|
---|
| 3898 | }
|
---|
| 3899 |
|
---|
| 3900 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
|
---|
| 3901 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
|
---|
| 3902 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
|
---|
| 3903 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
|
---|
| 3904 | * triangle we are looking for.
|
---|
| 3905 | *
|
---|
| 3906 | * @param *SetOfNeighbours all points for which the angle should be calculated
|
---|
| 3907 | * @param *Point of which get all connected points
|
---|
| 3908 | * @param *Reference Reference vector for zero angle or NULL for no preference
|
---|
| 3909 | * @return list of the all points linked to the provided one
|
---|
| 3910 | */
|
---|
[c15ca2] | 3911 | TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
|
---|
[71b20e] | 3912 | {
|
---|
| 3913 | Info FunctionInfo(__func__);
|
---|
| 3914 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[c15ca2] | 3915 | TesselPointList *connectedCircle = new TesselPointList;
|
---|
[065e82] | 3916 | Vector center;
|
---|
| 3917 | Vector PlaneNormal;
|
---|
| 3918 | Vector AngleZero;
|
---|
| 3919 | Vector OrthogonalVector;
|
---|
| 3920 | Vector helper;
|
---|
[62bb91] | 3921 |
|
---|
[27bd2f] | 3922 | if (SetOfNeighbours == NULL) {
|
---|
[6613ec] | 3923 | DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
|
---|
| 3924 | delete (connectedCircle);
|
---|
[99593f] | 3925 | return NULL;
|
---|
| 3926 | }
|
---|
[a2028e] | 3927 |
|
---|
[97498a] | 3928 | // check whether there's something to do
|
---|
| 3929 | if (SetOfNeighbours->size() < 3) {
|
---|
| 3930 | for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
|
---|
| 3931 | connectedCircle->push_back(*TesselRunner);
|
---|
| 3932 | return connectedCircle;
|
---|
| 3933 | }
|
---|
| 3934 |
|
---|
[a67d19] | 3935 | DoLog(1) && (Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl);
|
---|
[16d866] | 3936 | // calculate central point
|
---|
[97498a] | 3937 | TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
|
---|
| 3938 | TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
|
---|
| 3939 | TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin();
|
---|
| 3940 | TesselB++;
|
---|
| 3941 | TesselC++;
|
---|
| 3942 | TesselC++;
|
---|
| 3943 | int counter = 0;
|
---|
| 3944 | while (TesselC != SetOfNeighbours->end()) {
|
---|
[0a4f7f] | 3945 | helper = Plane(*((*TesselA)->node),
|
---|
| 3946 | *((*TesselB)->node),
|
---|
| 3947 | *((*TesselC)->node)).getNormal();
|
---|
[a67d19] | 3948 | DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl);
|
---|
[97498a] | 3949 | counter++;
|
---|
| 3950 | TesselA++;
|
---|
| 3951 | TesselB++;
|
---|
| 3952 | TesselC++;
|
---|
[273382] | 3953 | PlaneNormal += helper;
|
---|
[97498a] | 3954 | }
|
---|
| 3955 | //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
|
---|
| 3956 | // << "; scale factor " << counter;
|
---|
[6613ec] | 3957 | PlaneNormal.Scale(1.0 / (double) counter);
|
---|
| 3958 | // Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
|
---|
| 3959 | //
|
---|
| 3960 | // // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
|
---|
| 3961 | // PlaneNormal.CopyVector(Point->node);
|
---|
| 3962 | // PlaneNormal.SubtractVector(¢er);
|
---|
| 3963 | // PlaneNormal.Normalize();
|
---|
[a67d19] | 3964 | DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl);
|
---|
[62bb91] | 3965 |
|
---|
| 3966 | // construct one orthogonal vector
|
---|
[a2028e] | 3967 | if (Reference != NULL) {
|
---|
[273382] | 3968 | AngleZero = (*Reference) - (*Point->node);
|
---|
| 3969 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[a2028e] | 3970 | }
|
---|
| 3971 | if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
|
---|
[a67d19] | 3972 | DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
|
---|
[273382] | 3973 | AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
|
---|
| 3974 | AngleZero.ProjectOntoPlane(PlaneNormal);
|
---|
[a2028e] | 3975 | if (AngleZero.NormSquared() < MYEPSILON) {
|
---|
[6613ec] | 3976 | DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
|
---|
[a2028e] | 3977 | performCriticalExit();
|
---|
| 3978 | }
|
---|
| 3979 | }
|
---|
[a67d19] | 3980 | DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
|
---|
[a2028e] | 3981 | if (AngleZero.NormSquared() > MYEPSILON)
|
---|
[0a4f7f] | 3982 | OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
|
---|
[a2028e] | 3983 | else
|
---|
[0a4f7f] | 3984 | OrthogonalVector.MakeNormalTo(PlaneNormal);
|
---|
[a67d19] | 3985 | DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
|
---|
[16d866] | 3986 |
|
---|
[5c7bf8] | 3987 | // go through all connected points and calculate angle
|
---|
[6613ec] | 3988 | pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
|
---|
[c15ca2] | 3989 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
|
---|
[273382] | 3990 | helper = (*(*listRunner)->node) - (*Point->node);
|
---|
| 3991 | helper.ProjectOntoPlane(PlaneNormal);
|
---|
[f1cccd] | 3992 | double angle = GetAngle(helper, AngleZero, OrthogonalVector);
|
---|
[97498a] | 3993 | if (angle > M_PI) // the correction is of no use here (and not desired)
|
---|
[6613ec] | 3994 | angle = 2. * M_PI - angle;
|
---|
[a67d19] | 3995 | DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl);
|
---|
[6613ec] | 3996 | InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
|
---|
[c15ca2] | 3997 | if (!InserterTest.second) {
|
---|
[6613ec] | 3998 | DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);
|
---|
[c15ca2] | 3999 | performCriticalExit();
|
---|
| 4000 | }
|
---|
[62bb91] | 4001 | }
|
---|
| 4002 |
|
---|
[6613ec] | 4003 | for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
|
---|
[065e82] | 4004 | connectedCircle->push_back(AngleRunner->second);
|
---|
| 4005 | }
|
---|
[62bb91] | 4006 |
|
---|
[065e82] | 4007 | return connectedCircle;
|
---|
| 4008 | }
|
---|
[62bb91] | 4009 |
|
---|
[065e82] | 4010 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path.
|
---|
| 4011 | *
|
---|
| 4012 | * @param *out output stream for debugging
|
---|
| 4013 | * @param *Point of which get all connected points
|
---|
| 4014 | * @return list of the all points linked to the provided one
|
---|
| 4015 | */
|
---|
[244a84] | 4016 | ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 4017 | {
|
---|
[6613ec] | 4018 | Info FunctionInfo(__func__);
|
---|
[065e82] | 4019 | map<double, TesselPoint*> anglesOfPoints;
|
---|
[6613ec] | 4020 | list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ;
|
---|
[c15ca2] | 4021 | TesselPointList *connectedPath = NULL;
|
---|
[065e82] | 4022 | Vector center;
|
---|
| 4023 | Vector PlaneNormal;
|
---|
| 4024 | Vector AngleZero;
|
---|
| 4025 | Vector OrthogonalVector;
|
---|
| 4026 | Vector helper;
|
---|
| 4027 | class BoundaryPointSet *ReferencePoint = NULL;
|
---|
| 4028 | class BoundaryPointSet *CurrentPoint = NULL;
|
---|
| 4029 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 4030 | class BoundaryLineSet *CurrentLine = NULL;
|
---|
| 4031 | class BoundaryLineSet *StartLine = NULL;
|
---|
| 4032 | // find the respective boundary point
|
---|
[776b64] | 4033 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
|
---|
[065e82] | 4034 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 4035 | ReferencePoint = PointRunner->second;
|
---|
| 4036 | } else {
|
---|
[6613ec] | 4037 | DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
|
---|
[065e82] | 4038 | return NULL;
|
---|
| 4039 | }
|
---|
| 4040 |
|
---|
[6613ec] | 4041 | map<class BoundaryLineSet *, bool> TouchedLine;
|
---|
| 4042 | map<class BoundaryTriangleSet *, bool> TouchedTriangle;
|
---|
| 4043 | map<class BoundaryLineSet *, bool>::iterator LineRunner;
|
---|
| 4044 | map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
|
---|
[57066a] | 4045 | for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
|
---|
[6613ec] | 4046 | TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false));
|
---|
[57066a] | 4047 | for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
|
---|
[6613ec] | 4048 | TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false));
|
---|
[57066a] | 4049 | }
|
---|
[065e82] | 4050 | if (!ReferencePoint->lines.empty()) {
|
---|
| 4051 | for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) {
|
---|
[57066a] | 4052 | LineRunner = TouchedLine.find(runner->second);
|
---|
| 4053 | if (LineRunner == TouchedLine.end()) {
|
---|
[6613ec] | 4054 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);
|
---|
[57066a] | 4055 | } else if (!LineRunner->second) {
|
---|
| 4056 | LineRunner->second = true;
|
---|
[c15ca2] | 4057 | connectedPath = new TesselPointList;
|
---|
[065e82] | 4058 | triangle = NULL;
|
---|
| 4059 | CurrentLine = runner->second;
|
---|
| 4060 | StartLine = CurrentLine;
|
---|
| 4061 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
[a67d19] | 4062 | DoLog(1) && (Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl);
|
---|
[065e82] | 4063 | do {
|
---|
| 4064 | // push current one
|
---|
[a67d19] | 4065 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
|
---|
[065e82] | 4066 | connectedPath->push_back(CurrentPoint->node);
|
---|
| 4067 |
|
---|
| 4068 | // find next triangle
|
---|
[57066a] | 4069 | for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
|
---|
[a67d19] | 4070 | DoLog(1) && (Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl);
|
---|
[57066a] | 4071 | if ((Runner->second != triangle)) { // look for first triangle not equal to old one
|
---|
| 4072 | triangle = Runner->second;
|
---|
| 4073 | TriangleRunner = TouchedTriangle.find(triangle);
|
---|
| 4074 | if (TriangleRunner != TouchedTriangle.end()) {
|
---|
| 4075 | if (!TriangleRunner->second) {
|
---|
| 4076 | TriangleRunner->second = true;
|
---|
[a67d19] | 4077 | DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl);
|
---|
[57066a] | 4078 | break;
|
---|
| 4079 | } else {
|
---|
[a67d19] | 4080 | DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl);
|
---|
[57066a] | 4081 | triangle = NULL;
|
---|
| 4082 | }
|
---|
| 4083 | } else {
|
---|
[6613ec] | 4084 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);
|
---|
[57066a] | 4085 | triangle = NULL;
|
---|
| 4086 | }
|
---|
[065e82] | 4087 | }
|
---|
| 4088 | }
|
---|
[57066a] | 4089 | if (triangle == NULL)
|
---|
| 4090 | break;
|
---|
[065e82] | 4091 | // find next line
|
---|
[6613ec] | 4092 | for (int i = 0; i < 3; i++) {
|
---|
[065e82] | 4093 | if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
|
---|
| 4094 | CurrentLine = triangle->lines[i];
|
---|
[a67d19] | 4095 | DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl);
|
---|
[065e82] | 4096 | break;
|
---|
| 4097 | }
|
---|
| 4098 | }
|
---|
[57066a] | 4099 | LineRunner = TouchedLine.find(CurrentLine);
|
---|
| 4100 | if (LineRunner == TouchedLine.end())
|
---|
[6613ec] | 4101 | DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);
|
---|
[065e82] | 4102 | else
|
---|
[57066a] | 4103 | LineRunner->second = true;
|
---|
[065e82] | 4104 | // find next point
|
---|
| 4105 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
|
---|
| 4106 |
|
---|
| 4107 | } while (CurrentLine != StartLine);
|
---|
| 4108 | // last point is missing, as it's on start line
|
---|
[a67d19] | 4109 | DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
|
---|
[57066a] | 4110 | if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
|
---|
| 4111 | connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
|
---|
[065e82] | 4112 |
|
---|
| 4113 | ListOfPaths->push_back(connectedPath);
|
---|
| 4114 | } else {
|
---|
[a67d19] | 4115 | DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl);
|
---|
[065e82] | 4116 | }
|
---|
| 4117 | }
|
---|
| 4118 | } else {
|
---|
[6613ec] | 4119 | DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);
|
---|
[065e82] | 4120 | }
|
---|
| 4121 |
|
---|
| 4122 | return ListOfPaths;
|
---|
[62bb91] | 4123 | }
|
---|
| 4124 |
|
---|
[065e82] | 4125 | /** Gets all closed paths on the circle of points connected to the provided point by triangulation lines, if this very point is removed.
|
---|
| 4126 | * From GetPathsOfConnectedPoints() extracts all single loops of intracrossing paths in the list of closed paths.
|
---|
| 4127 | * @param *out output stream for debugging
|
---|
| 4128 | * @param *Point of which get all connected points
|
---|
| 4129 | * @return list of the closed paths
|
---|
| 4130 | */
|
---|
[244a84] | 4131 | ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
|
---|
[065e82] | 4132 | {
|
---|
[6613ec] | 4133 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4134 | list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
|
---|
[6613ec] | 4135 | list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;
|
---|
[c15ca2] | 4136 | TesselPointList *connectedPath = NULL;
|
---|
| 4137 | TesselPointList *newPath = NULL;
|
---|
[065e82] | 4138 | int count = 0;
|
---|
[c15ca2] | 4139 | TesselPointList::iterator CircleRunner;
|
---|
| 4140 | TesselPointList::iterator CircleStart;
|
---|
[065e82] | 4141 |
|
---|
[6613ec] | 4142 | for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
|
---|
[065e82] | 4143 | connectedPath = *ListRunner;
|
---|
| 4144 |
|
---|
[a67d19] | 4145 | DoLog(1) && (Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl);
|
---|
[065e82] | 4146 |
|
---|
| 4147 | // go through list, look for reappearance of starting Point and count
|
---|
| 4148 | CircleStart = connectedPath->begin();
|
---|
| 4149 | // go through list, look for reappearance of starting Point and create list
|
---|
[c15ca2] | 4150 | TesselPointList::iterator Marker = CircleStart;
|
---|
[065e82] | 4151 | for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
|
---|
| 4152 | if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
|
---|
| 4153 | // we have a closed circle from Marker to new Marker
|
---|
[a67d19] | 4154 | DoLog(1) && (Log() << Verbose(1) << count + 1 << ". closed path consists of: ");
|
---|
[c15ca2] | 4155 | newPath = new TesselPointList;
|
---|
| 4156 | TesselPointList::iterator CircleSprinter = Marker;
|
---|
[065e82] | 4157 | for (; CircleSprinter != CircleRunner; CircleSprinter++) {
|
---|
| 4158 | newPath->push_back(*CircleSprinter);
|
---|
[a67d19] | 4159 | DoLog(0) && (Log() << Verbose(0) << (**CircleSprinter) << " <-> ");
|
---|
[065e82] | 4160 | }
|
---|
[a67d19] | 4161 | DoLog(0) && (Log() << Verbose(0) << ".." << endl);
|
---|
[065e82] | 4162 | count++;
|
---|
| 4163 | Marker = CircleRunner;
|
---|
| 4164 |
|
---|
| 4165 | // add to list
|
---|
| 4166 | ListofClosedPaths->push_back(newPath);
|
---|
| 4167 | }
|
---|
| 4168 | }
|
---|
| 4169 | }
|
---|
[a67d19] | 4170 | DoLog(1) && (Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl);
|
---|
[065e82] | 4171 |
|
---|
| 4172 | // delete list of paths
|
---|
| 4173 | while (!ListofPaths->empty()) {
|
---|
| 4174 | connectedPath = *(ListofPaths->begin());
|
---|
| 4175 | ListofPaths->remove(connectedPath);
|
---|
[6613ec] | 4176 | delete (connectedPath);
|
---|
[065e82] | 4177 | }
|
---|
[6613ec] | 4178 | delete (ListofPaths);
|
---|
[065e82] | 4179 |
|
---|
| 4180 | // exit
|
---|
| 4181 | return ListofClosedPaths;
|
---|
[6613ec] | 4182 | }
|
---|
| 4183 | ;
|
---|
[065e82] | 4184 |
|
---|
| 4185 | /** Gets all belonging triangles for a given BoundaryPointSet.
|
---|
| 4186 | * \param *out output stream for debugging
|
---|
| 4187 | * \param *Point BoundaryPoint
|
---|
| 4188 | * \return pointer to allocated list of triangles
|
---|
| 4189 | */
|
---|
[c15ca2] | 4190 | TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
|
---|
[065e82] | 4191 | {
|
---|
[6613ec] | 4192 | Info FunctionInfo(__func__);
|
---|
| 4193 | TriangleSet *connectedTriangles = new TriangleSet;
|
---|
[065e82] | 4194 |
|
---|
| 4195 | if (Point == NULL) {
|
---|
[6613ec] | 4196 | DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl);
|
---|
[065e82] | 4197 | } else {
|
---|
| 4198 | // go through its lines and insert all triangles
|
---|
[776b64] | 4199 | for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
|
---|
[065e82] | 4200 | for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
[6613ec] | 4201 | connectedTriangles->insert(TriangleRunner->second);
|
---|
| 4202 | }
|
---|
[065e82] | 4203 | }
|
---|
| 4204 |
|
---|
| 4205 | return connectedTriangles;
|
---|
[6613ec] | 4206 | }
|
---|
| 4207 | ;
|
---|
[065e82] | 4208 |
|
---|
[16d866] | 4209 | /** Removes a boundary point from the envelope while keeping it closed.
|
---|
[57066a] | 4210 | * We remove the old triangles connected to the point and re-create new triangles to close the surface following this ansatz:
|
---|
| 4211 | * -# a closed path(s) of boundary points surrounding the point to be removed is constructed
|
---|
| 4212 | * -# on each closed path, we pick three adjacent points, create a triangle with them and subtract the middle point from the path
|
---|
| 4213 | * -# we advance two points (i.e. the next triangle will start at the ending point of the last triangle) and continue as before
|
---|
| 4214 | * -# the surface is closed, when the path is empty
|
---|
| 4215 | * Thereby, we (hopefully) make sure that the removed points remains beneath the surface (this is checked via IsInnerPoint eventually).
|
---|
[16d866] | 4216 | * \param *out output stream for debugging
|
---|
| 4217 | * \param *point point to be removed
|
---|
| 4218 | * \return volume added to the volume inside the tesselated surface by the removal
|
---|
| 4219 | */
|
---|
[6613ec] | 4220 | double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point)
|
---|
| 4221 | {
|
---|
[16d866] | 4222 | class BoundaryLineSet *line = NULL;
|
---|
| 4223 | class BoundaryTriangleSet *triangle = NULL;
|
---|
[57066a] | 4224 | Vector OldPoint, NormalVector;
|
---|
[16d866] | 4225 | double volume = 0;
|
---|
| 4226 | int count = 0;
|
---|
| 4227 |
|
---|
[1d9b7aa] | 4228 | if (point == NULL) {
|
---|
[6613ec] | 4229 | DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);
|
---|
[1d9b7aa] | 4230 | return 0.;
|
---|
| 4231 | } else
|
---|
[a67d19] | 4232 | DoLog(0) && (Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl);
|
---|
[1d9b7aa] | 4233 |
|
---|
[16d866] | 4234 | // copy old location for the volume
|
---|
[273382] | 4235 | OldPoint = (*point->node->node);
|
---|
[16d866] | 4236 |
|
---|
| 4237 | // get list of connected points
|
---|
| 4238 | if (point->lines.empty()) {
|
---|
[6613ec] | 4239 | DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);
|
---|
[16d866] | 4240 | return 0.;
|
---|
| 4241 | }
|
---|
| 4242 |
|
---|
[c15ca2] | 4243 | list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
|
---|
| 4244 | TesselPointList *connectedPath = NULL;
|
---|
[065e82] | 4245 |
|
---|
| 4246 | // gather all triangles
|
---|
[16d866] | 4247 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
|
---|
[6613ec] | 4248 | count += LineRunner->second->triangles.size();
|
---|
[c15ca2] | 4249 | TriangleMap Candidates;
|
---|
[57066a] | 4250 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
|
---|
[16d866] | 4251 | line = LineRunner->second;
|
---|
| 4252 | for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
|
---|
| 4253 | triangle = TriangleRunner->second;
|
---|
[6613ec] | 4254 | Candidates.insert(TrianglePair(triangle->Nr, triangle));
|
---|
[16d866] | 4255 | }
|
---|
| 4256 | }
|
---|
| 4257 |
|
---|
[065e82] | 4258 | // remove all triangles
|
---|
[6613ec] | 4259 | count = 0;
|
---|
[57066a] | 4260 | NormalVector.Zero();
|
---|
[c15ca2] | 4261 | for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
|
---|
[a67d19] | 4262 | DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl);
|
---|
[273382] | 4263 | NormalVector -= Runner->second->NormalVector; // has to point inward
|
---|
[c15ca2] | 4264 | RemoveTesselationTriangle(Runner->second);
|
---|
[065e82] | 4265 | count++;
|
---|
| 4266 | }
|
---|
[a67d19] | 4267 | DoLog(1) && (Log() << Verbose(1) << count << " triangles were removed." << endl);
|
---|
[065e82] | 4268 |
|
---|
[c15ca2] | 4269 | list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
|
---|
| 4270 | list<TesselPointList *>::iterator ListRunner = ListAdvance;
|
---|
| 4271 | TriangleMap::iterator NumberRunner = Candidates.begin();
|
---|
| 4272 | TesselPointList::iterator StartNode, MiddleNode, EndNode;
|
---|
[57066a] | 4273 | double angle;
|
---|
| 4274 | double smallestangle;
|
---|
| 4275 | Vector Point, Reference, OrthogonalVector;
|
---|
[6613ec] | 4276 | if (count > 2) { // less than three triangles, then nothing will be created
|
---|
[065e82] | 4277 | class TesselPoint *TriangleCandidates[3];
|
---|
| 4278 | count = 0;
|
---|
[6613ec] | 4279 | for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
|
---|
[065e82] | 4280 | if (ListAdvance != ListOfClosedPaths->end())
|
---|
| 4281 | ListAdvance++;
|
---|
| 4282 |
|
---|
| 4283 | connectedPath = *ListRunner;
|
---|
| 4284 | // re-create all triangles by going through connected points list
|
---|
[c15ca2] | 4285 | LineList NewLines;
|
---|
[6613ec] | 4286 | for (; !connectedPath->empty();) {
|
---|
[57066a] | 4287 | // search middle node with widest angle to next neighbours
|
---|
| 4288 | EndNode = connectedPath->end();
|
---|
| 4289 | smallestangle = 0.;
|
---|
| 4290 | for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
|
---|
[a67d19] | 4291 | DoLog(1) && (Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
|
---|
[57066a] | 4292 | // construct vectors to next and previous neighbour
|
---|
| 4293 | StartNode = MiddleNode;
|
---|
| 4294 | if (StartNode == connectedPath->begin())
|
---|
| 4295 | StartNode = connectedPath->end();
|
---|
| 4296 | StartNode--;
|
---|
[e138de] | 4297 | //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl;
|
---|
[273382] | 4298 | Point = (*(*StartNode)->node) - (*(*MiddleNode)->node);
|
---|
[57066a] | 4299 | StartNode = MiddleNode;
|
---|
| 4300 | StartNode++;
|
---|
| 4301 | if (StartNode == connectedPath->end())
|
---|
| 4302 | StartNode = connectedPath->begin();
|
---|
[e138de] | 4303 | //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl;
|
---|
[273382] | 4304 | Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node);
|
---|
| 4305 | OrthogonalVector = (*(*MiddleNode)->node) - OldPoint;
|
---|
[0a4f7f] | 4306 | OrthogonalVector.MakeNormalTo(Reference);
|
---|
[57066a] | 4307 | angle = GetAngle(Point, Reference, OrthogonalVector);
|
---|
| 4308 | //if (angle < M_PI) // no wrong-sided triangles, please?
|
---|
[6613ec] | 4309 | if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
|
---|
| 4310 | smallestangle = angle;
|
---|
| 4311 | EndNode = MiddleNode;
|
---|
| 4312 | }
|
---|
[57066a] | 4313 | }
|
---|
| 4314 | MiddleNode = EndNode;
|
---|
| 4315 | if (MiddleNode == connectedPath->end()) {
|
---|
[6613ec] | 4316 | DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);
|
---|
[f67b6e] | 4317 | performCriticalExit();
|
---|
[57066a] | 4318 | }
|
---|
| 4319 | StartNode = MiddleNode;
|
---|
| 4320 | if (StartNode == connectedPath->begin())
|
---|
| 4321 | StartNode = connectedPath->end();
|
---|
| 4322 | StartNode--;
|
---|
| 4323 | EndNode++;
|
---|
| 4324 | if (EndNode == connectedPath->end())
|
---|
| 4325 | EndNode = connectedPath->begin();
|
---|
[a67d19] | 4326 | DoLog(2) && (Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl);
|
---|
| 4327 | DoLog(2) && (Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
|
---|
| 4328 | DoLog(2) && (Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl);
|
---|
[68f03d] | 4329 | DoLog(1) && (Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->getName() << ", " << (*MiddleNode)->getName() << " and " << (*EndNode)->getName() << "." << endl);
|
---|
[57066a] | 4330 | TriangleCandidates[0] = *StartNode;
|
---|
| 4331 | TriangleCandidates[1] = *MiddleNode;
|
---|
| 4332 | TriangleCandidates[2] = *EndNode;
|
---|
[e138de] | 4333 | triangle = GetPresentTriangle(TriangleCandidates);
|
---|
[57066a] | 4334 | if (triangle != NULL) {
|
---|
[6613ec] | 4335 | DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl);
|
---|
[57066a] | 4336 | StartNode++;
|
---|
| 4337 | MiddleNode++;
|
---|
| 4338 | EndNode++;
|
---|
| 4339 | if (StartNode == connectedPath->end())
|
---|
| 4340 | StartNode = connectedPath->begin();
|
---|
| 4341 | if (MiddleNode == connectedPath->end())
|
---|
| 4342 | MiddleNode = connectedPath->begin();
|
---|
| 4343 | if (EndNode == connectedPath->end())
|
---|
| 4344 | EndNode = connectedPath->begin();
|
---|
| 4345 | continue;
|
---|
| 4346 | }
|
---|
[a67d19] | 4347 | DoLog(3) && (Log() << Verbose(3) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4348 | AddTesselationPoint(*StartNode, 0);
|
---|
| 4349 | AddTesselationPoint(*MiddleNode, 1);
|
---|
| 4350 | AddTesselationPoint(*EndNode, 2);
|
---|
[a67d19] | 4351 | DoLog(3) && (Log() << Verbose(3) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4352 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4353 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
[57066a] | 4354 | NewLines.push_back(BLS[1]);
|
---|
[f07f86d] | 4355 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[065e82] | 4356 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
[57066a] | 4357 | BTS->GetNormalVector(NormalVector);
|
---|
[065e82] | 4358 | AddTesselationTriangle();
|
---|
| 4359 | // calculate volume summand as a general tetraeder
|
---|
[c0f6c6] | 4360 | volume += CalculateVolumeofGeneralTetraeder(*TPS[0]->node->node, *TPS[1]->node->node, *TPS[2]->node->node, OldPoint);
|
---|
[065e82] | 4361 | // advance number
|
---|
| 4362 | count++;
|
---|
[57066a] | 4363 |
|
---|
| 4364 | // prepare nodes for next triangle
|
---|
| 4365 | StartNode = EndNode;
|
---|
[a67d19] | 4366 | DoLog(2) && (Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl);
|
---|
[57066a] | 4367 | connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
|
---|
| 4368 | if (connectedPath->size() == 2) { // we are done
|
---|
| 4369 | connectedPath->remove(*StartNode); // remove the start node
|
---|
| 4370 | connectedPath->remove(*EndNode); // remove the end node
|
---|
| 4371 | break;
|
---|
| 4372 | } else if (connectedPath->size() < 2) { // something's gone wrong!
|
---|
[6613ec] | 4373 | DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);
|
---|
[f67b6e] | 4374 | performCriticalExit();
|
---|
[57066a] | 4375 | } else {
|
---|
| 4376 | MiddleNode = StartNode;
|
---|
| 4377 | MiddleNode++;
|
---|
| 4378 | if (MiddleNode == connectedPath->end())
|
---|
| 4379 | MiddleNode = connectedPath->begin();
|
---|
| 4380 | EndNode = MiddleNode;
|
---|
| 4381 | EndNode++;
|
---|
| 4382 | if (EndNode == connectedPath->end())
|
---|
| 4383 | EndNode = connectedPath->begin();
|
---|
| 4384 | }
|
---|
[065e82] | 4385 | }
|
---|
[57066a] | 4386 | // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
|
---|
| 4387 | if (NewLines.size() > 1) {
|
---|
[c15ca2] | 4388 | LineList::iterator Candidate;
|
---|
[57066a] | 4389 | class BoundaryLineSet *OtherBase = NULL;
|
---|
| 4390 | double tmp, maxgain;
|
---|
| 4391 | do {
|
---|
| 4392 | maxgain = 0;
|
---|
[6613ec] | 4393 | for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
|
---|
[e138de] | 4394 | tmp = PickFarthestofTwoBaselines(*Runner);
|
---|
[57066a] | 4395 | if (maxgain < tmp) {
|
---|
| 4396 | maxgain = tmp;
|
---|
| 4397 | Candidate = Runner;
|
---|
| 4398 | }
|
---|
| 4399 | }
|
---|
| 4400 | if (maxgain != 0) {
|
---|
| 4401 | volume += maxgain;
|
---|
[a67d19] | 4402 | DoLog(1) && (Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl);
|
---|
[e138de] | 4403 | OtherBase = FlipBaseline(*Candidate);
|
---|
[57066a] | 4404 | NewLines.erase(Candidate);
|
---|
| 4405 | NewLines.push_back(OtherBase);
|
---|
| 4406 | }
|
---|
| 4407 | } while (maxgain != 0.);
|
---|
| 4408 | }
|
---|
| 4409 |
|
---|
[065e82] | 4410 | ListOfClosedPaths->remove(connectedPath);
|
---|
[6613ec] | 4411 | delete (connectedPath);
|
---|
[16d866] | 4412 | }
|
---|
[a67d19] | 4413 | DoLog(0) && (Log() << Verbose(0) << count << " triangles were created." << endl);
|
---|
[065e82] | 4414 | } else {
|
---|
| 4415 | while (!ListOfClosedPaths->empty()) {
|
---|
| 4416 | ListRunner = ListOfClosedPaths->begin();
|
---|
| 4417 | connectedPath = *ListRunner;
|
---|
| 4418 | ListOfClosedPaths->remove(connectedPath);
|
---|
[6613ec] | 4419 | delete (connectedPath);
|
---|
[065e82] | 4420 | }
|
---|
[a67d19] | 4421 | DoLog(0) && (Log() << Verbose(0) << "No need to create any triangles." << endl);
|
---|
[16d866] | 4422 | }
|
---|
[6613ec] | 4423 | delete (ListOfClosedPaths);
|
---|
[16d866] | 4424 |
|
---|
[a67d19] | 4425 | DoLog(0) && (Log() << Verbose(0) << "Removed volume is " << volume << "." << endl);
|
---|
[357fba] | 4426 |
|
---|
[57066a] | 4427 | return volume;
|
---|
[6613ec] | 4428 | }
|
---|
| 4429 | ;
|
---|
[ab1932] | 4430 |
|
---|
| 4431 | /**
|
---|
[62bb91] | 4432 | * Finds triangles belonging to the three provided points.
|
---|
[ab1932] | 4433 | *
|
---|
[71b20e] | 4434 | * @param *Points[3] list, is expected to contain three points (NULL means wildcard)
|
---|
[ab1932] | 4435 | *
|
---|
[62bb91] | 4436 | * @return triangles which belong to the provided points, will be empty if there are none,
|
---|
[ab1932] | 4437 | * will usually be one, in case of degeneration, there will be two
|
---|
| 4438 | */
|
---|
[c15ca2] | 4439 | TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
|
---|
[ab1932] | 4440 | {
|
---|
[6613ec] | 4441 | Info FunctionInfo(__func__);
|
---|
| 4442 | TriangleList *result = new TriangleList;
|
---|
[776b64] | 4443 | LineMap::const_iterator FindLine;
|
---|
| 4444 | TriangleMap::const_iterator FindTriangle;
|
---|
[ab1932] | 4445 | class BoundaryPointSet *TrianglePoints[3];
|
---|
[71b20e] | 4446 | size_t NoOfWildcards = 0;
|
---|
[ab1932] | 4447 |
|
---|
| 4448 | for (int i = 0; i < 3; i++) {
|
---|
[71b20e] | 4449 | if (Points[i] == NULL) {
|
---|
| 4450 | NoOfWildcards++;
|
---|
[ab1932] | 4451 | TrianglePoints[i] = NULL;
|
---|
[71b20e] | 4452 | } else {
|
---|
| 4453 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
|
---|
| 4454 | if (FindPoint != PointsOnBoundary.end()) {
|
---|
| 4455 | TrianglePoints[i] = FindPoint->second;
|
---|
| 4456 | } else {
|
---|
| 4457 | TrianglePoints[i] = NULL;
|
---|
| 4458 | }
|
---|
[ab1932] | 4459 | }
|
---|
| 4460 | }
|
---|
| 4461 |
|
---|
[71b20e] | 4462 | switch (NoOfWildcards) {
|
---|
| 4463 | case 0: // checks lines between the points in the Points for their adjacent triangles
|
---|
| 4464 | for (int i = 0; i < 3; i++) {
|
---|
| 4465 | if (TrianglePoints[i] != NULL) {
|
---|
[6613ec] | 4466 | for (int j = i + 1; j < 3; j++) {
|
---|
[71b20e] | 4467 | if (TrianglePoints[j] != NULL) {
|
---|
| 4468 | for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
|
---|
[6613ec] | 4469 | (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) {
|
---|
| 4470 | for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
|
---|
[71b20e] | 4471 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 4472 | result->push_back(FindTriangle->second);
|
---|
| 4473 | }
|
---|
| 4474 | }
|
---|
[ab1932] | 4475 | }
|
---|
[71b20e] | 4476 | // Is it sufficient to consider one of the triangle lines for this.
|
---|
| 4477 | return result;
|
---|
[ab1932] | 4478 | }
|
---|
| 4479 | }
|
---|
| 4480 | }
|
---|
| 4481 | }
|
---|
[71b20e] | 4482 | break;
|
---|
| 4483 | case 1: // copy all triangles of the respective line
|
---|
| 4484 | {
|
---|
[6613ec] | 4485 | int i = 0;
|
---|
[71b20e] | 4486 | for (; i < 3; i++)
|
---|
| 4487 | if (TrianglePoints[i] == NULL)
|
---|
| 4488 | break;
|
---|
[6613ec] | 4489 | for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap!
|
---|
| 4490 | (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) {
|
---|
| 4491 | for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
|
---|
[71b20e] | 4492 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
|
---|
| 4493 | result->push_back(FindTriangle->second);
|
---|
| 4494 | }
|
---|
| 4495 | }
|
---|
| 4496 | }
|
---|
| 4497 | break;
|
---|
| 4498 | }
|
---|
| 4499 | case 2: // copy all triangles of the respective point
|
---|
| 4500 | {
|
---|
[6613ec] | 4501 | int i = 0;
|
---|
[71b20e] | 4502 | for (; i < 3; i++)
|
---|
| 4503 | if (TrianglePoints[i] != NULL)
|
---|
| 4504 | break;
|
---|
| 4505 | for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++)
|
---|
| 4506 | for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++)
|
---|
| 4507 | result->push_back(triangle->second);
|
---|
| 4508 | result->sort();
|
---|
| 4509 | result->unique();
|
---|
| 4510 | break;
|
---|
| 4511 | }
|
---|
| 4512 | case 3: // copy all triangles
|
---|
| 4513 | {
|
---|
| 4514 | for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++)
|
---|
| 4515 | result->push_back(triangle->second);
|
---|
| 4516 | break;
|
---|
[ab1932] | 4517 | }
|
---|
[71b20e] | 4518 | default:
|
---|
[6613ec] | 4519 | DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);
|
---|
[71b20e] | 4520 | performCriticalExit();
|
---|
| 4521 | break;
|
---|
[ab1932] | 4522 | }
|
---|
| 4523 |
|
---|
| 4524 | return result;
|
---|
| 4525 | }
|
---|
| 4526 |
|
---|
[6613ec] | 4527 | struct BoundaryLineSetCompare
|
---|
| 4528 | {
|
---|
| 4529 | bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b)
|
---|
| 4530 | {
|
---|
[856098] | 4531 | int lowerNra = -1;
|
---|
| 4532 | int lowerNrb = -1;
|
---|
| 4533 |
|
---|
| 4534 | if (a->endpoints[0] < a->endpoints[1])
|
---|
| 4535 | lowerNra = 0;
|
---|
| 4536 | else
|
---|
| 4537 | lowerNra = 1;
|
---|
| 4538 |
|
---|
| 4539 | if (b->endpoints[0] < b->endpoints[1])
|
---|
| 4540 | lowerNrb = 0;
|
---|
| 4541 | else
|
---|
| 4542 | lowerNrb = 1;
|
---|
| 4543 |
|
---|
| 4544 | if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
|
---|
| 4545 | return true;
|
---|
| 4546 | else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
|
---|
| 4547 | return false;
|
---|
[6613ec] | 4548 | else { // both lower-numbered endpoints are the same ...
|
---|
| 4549 | if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2])
|
---|
| 4550 | return true;
|
---|
| 4551 | else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2])
|
---|
| 4552 | return false;
|
---|
[856098] | 4553 | }
|
---|
| 4554 | return false;
|
---|
[6613ec] | 4555 | }
|
---|
| 4556 | ;
|
---|
[856098] | 4557 | };
|
---|
| 4558 |
|
---|
| 4559 | #define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
|
---|
| 4560 |
|
---|
[7c14ec] | 4561 | /**
|
---|
[57066a] | 4562 | * Finds all degenerated lines within the tesselation structure.
|
---|
[7c14ec] | 4563 | *
|
---|
[57066a] | 4564 | * @return map of keys of degenerated line pairs, each line occurs twice
|
---|
[7c14ec] | 4565 | * in the list, once as key and once as value
|
---|
| 4566 | */
|
---|
[c15ca2] | 4567 | IndexToIndex * Tesselation::FindAllDegeneratedLines()
|
---|
[7c14ec] | 4568 | {
|
---|
[6613ec] | 4569 | Info FunctionInfo(__func__);
|
---|
| 4570 | UniqueLines AllLines;
|
---|
[c15ca2] | 4571 | IndexToIndex * DegeneratedLines = new IndexToIndex;
|
---|
[7c14ec] | 4572 |
|
---|
| 4573 | // sanity check
|
---|
| 4574 | if (LinesOnBoundary.empty()) {
|
---|
[6613ec] | 4575 | DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");
|
---|
[57066a] | 4576 | return DegeneratedLines;
|
---|
[7c14ec] | 4577 | }
|
---|
[57066a] | 4578 | LineMap::iterator LineRunner1;
|
---|
[6613ec] | 4579 | pair<UniqueLines::iterator, bool> tester;
|
---|
[7c14ec] | 4580 | for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
|
---|
[6613ec] | 4581 | tester = AllLines.insert(LineRunner1->second);
|
---|
[856098] | 4582 | if (!tester.second) { // found degenerated line
|
---|
[6613ec] | 4583 | DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));
|
---|
| 4584 | DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));
|
---|
[57066a] | 4585 | }
|
---|
| 4586 | }
|
---|
| 4587 |
|
---|
| 4588 | AllLines.clear();
|
---|
| 4589 |
|
---|
[a67d19] | 4590 | DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl);
|
---|
[c15ca2] | 4591 | IndexToIndex::iterator it;
|
---|
[856098] | 4592 | for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
|
---|
| 4593 | const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
|
---|
| 4594 | const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
|
---|
| 4595 | if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
|
---|
[a67d19] | 4596 | DoLog(0) && (Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl);
|
---|
[856098] | 4597 | else
|
---|
[6613ec] | 4598 | DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);
|
---|
[856098] | 4599 | }
|
---|
[57066a] | 4600 |
|
---|
| 4601 | return DegeneratedLines;
|
---|
| 4602 | }
|
---|
| 4603 |
|
---|
| 4604 | /**
|
---|
| 4605 | * Finds all degenerated triangles within the tesselation structure.
|
---|
| 4606 | *
|
---|
| 4607 | * @return map of keys of degenerated triangle pairs, each triangle occurs twice
|
---|
| 4608 | * in the list, once as key and once as value
|
---|
| 4609 | */
|
---|
[c15ca2] | 4610 | IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
|
---|
[57066a] | 4611 | {
|
---|
[6613ec] | 4612 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4613 | IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
|
---|
| 4614 | IndexToIndex * DegeneratedTriangles = new IndexToIndex;
|
---|
[57066a] | 4615 | TriangleMap::iterator TriangleRunner1, TriangleRunner2;
|
---|
| 4616 | LineMap::iterator Liner;
|
---|
| 4617 | class BoundaryLineSet *line1 = NULL, *line2 = NULL;
|
---|
| 4618 |
|
---|
[c15ca2] | 4619 | for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
|
---|
[57066a] | 4620 | // run over both lines' triangles
|
---|
| 4621 | Liner = LinesOnBoundary.find(LineRunner->first);
|
---|
| 4622 | if (Liner != LinesOnBoundary.end())
|
---|
| 4623 | line1 = Liner->second;
|
---|
| 4624 | Liner = LinesOnBoundary.find(LineRunner->second);
|
---|
| 4625 | if (Liner != LinesOnBoundary.end())
|
---|
| 4626 | line2 = Liner->second;
|
---|
| 4627 | for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
|
---|
| 4628 | for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
|
---|
[6613ec] | 4629 | if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
|
---|
| 4630 | DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr));
|
---|
| 4631 | DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr));
|
---|
[7c14ec] | 4632 | }
|
---|
| 4633 | }
|
---|
| 4634 | }
|
---|
| 4635 | }
|
---|
[6613ec] | 4636 | delete (DegeneratedLines);
|
---|
[7c14ec] | 4637 |
|
---|
[a67d19] | 4638 | DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl);
|
---|
[b32dbb] | 4639 | for (IndexToIndex::iterator it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
|
---|
[a67d19] | 4640 | DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
|
---|
[7c14ec] | 4641 |
|
---|
| 4642 | return DegeneratedTriangles;
|
---|
| 4643 | }
|
---|
| 4644 |
|
---|
| 4645 | /**
|
---|
| 4646 | * Purges degenerated triangles from the tesselation structure if they are not
|
---|
| 4647 | * necessary to keep a single point within the structure.
|
---|
| 4648 | */
|
---|
| 4649 | void Tesselation::RemoveDegeneratedTriangles()
|
---|
| 4650 | {
|
---|
[6613ec] | 4651 | Info FunctionInfo(__func__);
|
---|
[c15ca2] | 4652 | IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[57066a] | 4653 | TriangleMap::iterator finder;
|
---|
| 4654 | BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
|
---|
[6613ec] | 4655 | int count = 0;
|
---|
[7c14ec] | 4656 |
|
---|
[b32dbb] | 4657 | // iterate over all degenerated triangles
|
---|
| 4658 | for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); !DegeneratedTriangles->empty(); TriangleKeyRunner = DegeneratedTriangles->begin()) {
|
---|
| 4659 | DoLog(0) && (Log() << Verbose(0) << "Checking presence of triangles " << TriangleKeyRunner->first << " and " << TriangleKeyRunner->second << "." << endl);
|
---|
| 4660 | // both ways are stored in the map, only use one
|
---|
| 4661 | if (TriangleKeyRunner->first > TriangleKeyRunner->second)
|
---|
| 4662 | continue;
|
---|
| 4663 |
|
---|
| 4664 | // determine from the keys in the map the two _present_ triangles
|
---|
[57066a] | 4665 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
|
---|
| 4666 | if (finder != TrianglesOnBoundary.end())
|
---|
| 4667 | triangle = finder->second;
|
---|
| 4668 | else
|
---|
[b32dbb] | 4669 | continue;
|
---|
[57066a] | 4670 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->second);
|
---|
| 4671 | if (finder != TrianglesOnBoundary.end())
|
---|
| 4672 | partnerTriangle = finder->second;
|
---|
| 4673 | else
|
---|
[b32dbb] | 4674 | continue;
|
---|
[7c14ec] | 4675 |
|
---|
[b32dbb] | 4676 | // determine which lines are shared by the two triangles
|
---|
[7c14ec] | 4677 | bool trianglesShareLine = false;
|
---|
| 4678 | for (int i = 0; i < 3; ++i)
|
---|
| 4679 | for (int j = 0; j < 3; ++j)
|
---|
| 4680 | trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
|
---|
| 4681 |
|
---|
[6613ec] | 4682 | if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) {
|
---|
[57066a] | 4683 | // check whether we have to fix lines
|
---|
| 4684 | BoundaryTriangleSet *Othertriangle = NULL;
|
---|
| 4685 | BoundaryTriangleSet *OtherpartnerTriangle = NULL;
|
---|
| 4686 | TriangleMap::iterator TriangleRunner;
|
---|
| 4687 | for (int i = 0; i < 3; ++i)
|
---|
| 4688 | for (int j = 0; j < 3; ++j)
|
---|
| 4689 | if (triangle->lines[i] != partnerTriangle->lines[j]) {
|
---|
| 4690 | // get the other two triangles
|
---|
| 4691 | for (TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 4692 | if (TriangleRunner->second != triangle) {
|
---|
| 4693 | Othertriangle = TriangleRunner->second;
|
---|
| 4694 | }
|
---|
| 4695 | for (TriangleRunner = partnerTriangle->lines[i]->triangles.begin(); TriangleRunner != partnerTriangle->lines[i]->triangles.end(); ++TriangleRunner)
|
---|
| 4696 | if (TriangleRunner->second != partnerTriangle) {
|
---|
| 4697 | OtherpartnerTriangle = TriangleRunner->second;
|
---|
| 4698 | }
|
---|
| 4699 | /// interchanges their lines so that triangle->lines[i] == partnerTriangle->lines[j]
|
---|
| 4700 | // the line of triangle receives the degenerated ones
|
---|
| 4701 | triangle->lines[i]->triangles.erase(Othertriangle->Nr);
|
---|
[6613ec] | 4702 | triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle));
|
---|
| 4703 | for (int k = 0; k < 3; k++)
|
---|
[57066a] | 4704 | if (triangle->lines[i] == Othertriangle->lines[k]) {
|
---|
| 4705 | Othertriangle->lines[k] = partnerTriangle->lines[j];
|
---|
| 4706 | break;
|
---|
| 4707 | }
|
---|
| 4708 | // the line of partnerTriangle receives the non-degenerated ones
|
---|
[6613ec] | 4709 | partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr);
|
---|
| 4710 | partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle));
|
---|
[57066a] | 4711 | partnerTriangle->lines[j] = triangle->lines[i];
|
---|
| 4712 | }
|
---|
| 4713 |
|
---|
| 4714 | // erase the pair
|
---|
| 4715 | count += (int) DegeneratedTriangles->erase(triangle->Nr);
|
---|
[a67d19] | 4716 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl);
|
---|
[7c14ec] | 4717 | RemoveTesselationTriangle(triangle);
|
---|
[57066a] | 4718 | count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
|
---|
[a67d19] | 4719 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl);
|
---|
[7c14ec] | 4720 | RemoveTesselationTriangle(partnerTriangle);
|
---|
| 4721 | } else {
|
---|
[a67d19] | 4722 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle << " and its partner " << *partnerTriangle << " because it is essential for at" << " least one of the endpoints to be kept in the tesselation structure." << endl);
|
---|
[7c14ec] | 4723 | }
|
---|
| 4724 | }
|
---|
[6613ec] | 4725 | delete (DegeneratedTriangles);
|
---|
[6a7f78c] | 4726 | if (count > 0)
|
---|
| 4727 | LastTriangle = NULL;
|
---|
[57066a] | 4728 |
|
---|
[a67d19] | 4729 | DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl);
|
---|
[7c14ec] | 4730 | }
|
---|
| 4731 |
|
---|
[57066a] | 4732 | /** Adds an outside Tesselpoint to the envelope via (two) degenerated triangles.
|
---|
| 4733 | * We look for the closest point on the boundary, we look through its connected boundary lines and
|
---|
| 4734 | * seek the one with the minimum angle between its center point and the new point and this base line.
|
---|
| 4735 | * We open up the line by adding a degenerated triangle, whose other side closes the base line again.
|
---|
| 4736 | * \param *out output stream for debugging
|
---|
| 4737 | * \param *point point to add
|
---|
| 4738 | * \param *LC Linked Cell structure to find nearest point
|
---|
[ab1932] | 4739 | */
|
---|
[e138de] | 4740 | void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
|
---|
[ab1932] | 4741 | {
|
---|
[6613ec] | 4742 | Info FunctionInfo(__func__);
|
---|
[57066a] | 4743 | // find nearest boundary point
|
---|
| 4744 | class TesselPoint *BackupPoint = NULL;
|
---|
[71b20e] | 4745 | class TesselPoint *NearestPoint = FindClosestTesselPoint(point->node, BackupPoint, LC);
|
---|
[57066a] | 4746 | class BoundaryPointSet *NearestBoundaryPoint = NULL;
|
---|
| 4747 | PointMap::iterator PointRunner;
|
---|
| 4748 |
|
---|
| 4749 | if (NearestPoint == point)
|
---|
| 4750 | NearestPoint = BackupPoint;
|
---|
| 4751 | PointRunner = PointsOnBoundary.find(NearestPoint->nr);
|
---|
| 4752 | if (PointRunner != PointsOnBoundary.end()) {
|
---|
| 4753 | NearestBoundaryPoint = PointRunner->second;
|
---|
| 4754 | } else {
|
---|
[6613ec] | 4755 | DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl);
|
---|
[57066a] | 4756 | return;
|
---|
| 4757 | }
|
---|
[68f03d] | 4758 | DoLog(0) && (Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->getName() << "." << endl);
|
---|
[57066a] | 4759 |
|
---|
| 4760 | // go through its lines and find the best one to split
|
---|
| 4761 | Vector CenterToPoint;
|
---|
| 4762 | Vector BaseLine;
|
---|
| 4763 | double angle, BestAngle = 0.;
|
---|
| 4764 | class BoundaryLineSet *BestLine = NULL;
|
---|
| 4765 | for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
|
---|
[273382] | 4766 | BaseLine = (*Runner->second->endpoints[0]->node->node) -
|
---|
| 4767 | (*Runner->second->endpoints[1]->node->node);
|
---|
| 4768 | CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) +
|
---|
| 4769 | (*Runner->second->endpoints[1]->node->node));
|
---|
| 4770 | CenterToPoint -= (*point->node);
|
---|
| 4771 | angle = CenterToPoint.Angle(BaseLine);
|
---|
[57066a] | 4772 | if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
|
---|
| 4773 | BestAngle = angle;
|
---|
| 4774 | BestLine = Runner->second;
|
---|
| 4775 | }
|
---|
[ab1932] | 4776 | }
|
---|
| 4777 |
|
---|
[57066a] | 4778 | // remove one triangle from the chosen line
|
---|
| 4779 | class BoundaryTriangleSet *TempTriangle = (BestLine->triangles.begin())->second;
|
---|
| 4780 | BestLine->triangles.erase(TempTriangle->Nr);
|
---|
| 4781 | int nr = -1;
|
---|
[6613ec] | 4782 | for (int i = 0; i < 3; i++) {
|
---|
[57066a] | 4783 | if (TempTriangle->lines[i] == BestLine) {
|
---|
| 4784 | nr = i;
|
---|
| 4785 | break;
|
---|
| 4786 | }
|
---|
| 4787 | }
|
---|
[ab1932] | 4788 |
|
---|
[57066a] | 4789 | // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
|
---|
[a67d19] | 4790 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4791 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 4792 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 4793 | AddTesselationPoint(point, 2);
|
---|
[a67d19] | 4794 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4795 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4796 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 4797 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[57066a] | 4798 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 4799 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
| 4800 | BTS->NormalVector.Scale(-1.);
|
---|
[a67d19] | 4801 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl);
|
---|
[57066a] | 4802 | AddTesselationTriangle();
|
---|
| 4803 |
|
---|
| 4804 | // create other side of this triangle and close both new sides of the first created triangle
|
---|
[a67d19] | 4805 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
|
---|
[57066a] | 4806 | AddTesselationPoint((BestLine->endpoints[0]->node), 0);
|
---|
| 4807 | AddTesselationPoint((BestLine->endpoints[1]->node), 1);
|
---|
| 4808 | AddTesselationPoint(point, 2);
|
---|
[a67d19] | 4809 | DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
|
---|
[f07f86d] | 4810 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 4811 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 4812 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[57066a] | 4813 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 4814 | BTS->GetNormalVector(TempTriangle->NormalVector);
|
---|
[a67d19] | 4815 | DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl);
|
---|
[57066a] | 4816 | AddTesselationTriangle();
|
---|
| 4817 |
|
---|
| 4818 | // add removed triangle to the last open line of the second triangle
|
---|
[6613ec] | 4819 | for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion)
|
---|
[57066a] | 4820 | if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
|
---|
[6613ec] | 4821 | if (BestLine == BTS->lines[i]) {
|
---|
| 4822 | DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl);
|
---|
[f67b6e] | 4823 | performCriticalExit();
|
---|
[57066a] | 4824 | }
|
---|
[6613ec] | 4825 | BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));
|
---|
[57066a] | 4826 | TempTriangle->lines[nr] = BTS->lines[i];
|
---|
| 4827 | break;
|
---|
| 4828 | }
|
---|
| 4829 | }
|
---|
[6613ec] | 4830 | }
|
---|
| 4831 | ;
|
---|
[57066a] | 4832 |
|
---|
| 4833 | /** Writes the envelope to file.
|
---|
| 4834 | * \param *out otuput stream for debugging
|
---|
| 4835 | * \param *filename basename of output file
|
---|
| 4836 | * \param *cloud PointCloud structure with all nodes
|
---|
| 4837 | */
|
---|
[e138de] | 4838 | void Tesselation::Output(const char *filename, const PointCloud * const cloud)
|
---|
[57066a] | 4839 | {
|
---|
[6613ec] | 4840 | Info FunctionInfo(__func__);
|
---|
[57066a] | 4841 | ofstream *tempstream = NULL;
|
---|
| 4842 | string NameofTempFile;
|
---|
[68f03d] | 4843 | string NumberName;
|
---|
[57066a] | 4844 |
|
---|
| 4845 | if (LastTriangle != NULL) {
|
---|
[68f03d] | 4846 | stringstream sstr;
|
---|
[8f215d] | 4847 | sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle->getEndpointName(0) << "_" << LastTriangle->getEndpointName(1) << "_" << LastTriangle->getEndpointName(2);
|
---|
[68f03d] | 4848 | NumberName = sstr.str();
|
---|
[57066a] | 4849 | if (DoTecplotOutput) {
|
---|
| 4850 | string NameofTempFile(filename);
|
---|
| 4851 | NameofTempFile.append(NumberName);
|
---|
[6613ec] | 4852 | for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 4853 | NameofTempFile.erase(npos, 1);
|
---|
[57066a] | 4854 | NameofTempFile.append(TecplotSuffix);
|
---|
[a67d19] | 4855 | DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
|
---|
[57066a] | 4856 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 4857 | WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
|
---|
[57066a] | 4858 | tempstream->close();
|
---|
| 4859 | tempstream->flush();
|
---|
[6613ec] | 4860 | delete (tempstream);
|
---|
[57066a] | 4861 | }
|
---|
| 4862 |
|
---|
| 4863 | if (DoRaster3DOutput) {
|
---|
| 4864 | string NameofTempFile(filename);
|
---|
| 4865 | NameofTempFile.append(NumberName);
|
---|
[6613ec] | 4866 | for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
|
---|
| 4867 | NameofTempFile.erase(npos, 1);
|
---|
[57066a] | 4868 | NameofTempFile.append(Raster3DSuffix);
|
---|
[a67d19] | 4869 | DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
|
---|
[57066a] | 4870 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
|
---|
[e138de] | 4871 | WriteRaster3dFile(tempstream, this, cloud);
|
---|
| 4872 | IncludeSphereinRaster3D(tempstream, this, cloud);
|
---|
[57066a] | 4873 | tempstream->close();
|
---|
| 4874 | tempstream->flush();
|
---|
[6613ec] | 4875 | delete (tempstream);
|
---|
[57066a] | 4876 | }
|
---|
| 4877 | }
|
---|
| 4878 | if (DoTecplotOutput || DoRaster3DOutput)
|
---|
| 4879 | TriangleFilesWritten++;
|
---|
[6613ec] | 4880 | }
|
---|
| 4881 | ;
|
---|
[262bae] | 4882 |
|
---|
[6613ec] | 4883 | struct BoundaryPolygonSetCompare
|
---|
| 4884 | {
|
---|
| 4885 | bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const
|
---|
| 4886 | {
|
---|
[856098] | 4887 | if (s1->endpoints.size() < s2->endpoints.size())
|
---|
| 4888 | return true;
|
---|
| 4889 | else if (s1->endpoints.size() > s2->endpoints.size())
|
---|
| 4890 | return false;
|
---|
| 4891 | else { // equality of number of endpoints
|
---|
| 4892 | PointSet::const_iterator Walker1 = s1->endpoints.begin();
|
---|
| 4893 | PointSet::const_iterator Walker2 = s2->endpoints.begin();
|
---|
| 4894 | while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
|
---|
| 4895 | if ((*Walker1)->Nr < (*Walker2)->Nr)
|
---|
| 4896 | return true;
|
---|
| 4897 | else if ((*Walker1)->Nr > (*Walker2)->Nr)
|
---|
| 4898 | return false;
|
---|
| 4899 | Walker1++;
|
---|
| 4900 | Walker2++;
|
---|
| 4901 | }
|
---|
| 4902 | return false;
|
---|
| 4903 | }
|
---|
| 4904 | }
|
---|
| 4905 | };
|
---|
| 4906 |
|
---|
| 4907 | #define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
|
---|
| 4908 |
|
---|
[262bae] | 4909 | /** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
|
---|
| 4910 | * \return number of polygons found
|
---|
| 4911 | */
|
---|
| 4912 | int Tesselation::CorrectAllDegeneratedPolygons()
|
---|
| 4913 | {
|
---|
| 4914 | Info FunctionInfo(__func__);
|
---|
[fad93c] | 4915 | /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
|
---|
[c15ca2] | 4916 | IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[6613ec] | 4917 | set<BoundaryPointSet *> EndpointCandidateList;
|
---|
| 4918 | pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester;
|
---|
| 4919 | pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester;
|
---|
[fad93c] | 4920 | for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
|
---|
[a67d19] | 4921 | DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl);
|
---|
[6613ec] | 4922 | map<int, Vector *> TriangleVectors;
|
---|
[fad93c] | 4923 | // gather all NormalVectors
|
---|
[a67d19] | 4924 | DoLog(1) && (Log() << Verbose(1) << "Gathering triangles ..." << endl);
|
---|
[fad93c] | 4925 | for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
|
---|
| 4926 | for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
|
---|
[b998c3] | 4927 | if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
|
---|
[6613ec] | 4928 | TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));
|
---|
[b998c3] | 4929 | if (TriangleInsertionTester.second)
|
---|
[a67d19] | 4930 | DoLog(1) && (Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl);
|
---|
[b998c3] | 4931 | } else {
|
---|
[a67d19] | 4932 | DoLog(1) && (Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl);
|
---|
[b998c3] | 4933 | }
|
---|
[fad93c] | 4934 | }
|
---|
| 4935 | // check whether there are two that are parallel
|
---|
[a67d19] | 4936 | DoLog(1) && (Log() << Verbose(1) << "Finding two parallel triangles ..." << endl);
|
---|
[6613ec] | 4937 | for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
|
---|
| 4938 | for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
|
---|
[fad93c] | 4939 | if (VectorWalker != VectorRunner) { // skip equals
|
---|
[8cbb97] | 4940 | const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
|
---|
[a67d19] | 4941 | DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl);
|
---|
[fad93c] | 4942 | if (fabs(SCP + 1.) < ParallelEpsilon) {
|
---|
| 4943 | InsertionTester = EndpointCandidateList.insert((Runner->second));
|
---|
| 4944 | if (InsertionTester.second)
|
---|
[a67d19] | 4945 | DoLog(0) && (Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl);
|
---|
[fad93c] | 4946 | // and break out of both loops
|
---|
| 4947 | VectorWalker = TriangleVectors.end();
|
---|
| 4948 | VectorRunner = TriangleVectors.end();
|
---|
| 4949 | break;
|
---|
| 4950 | }
|
---|
| 4951 | }
|
---|
| 4952 | }
|
---|
[9d4c20] | 4953 | delete DegeneratedTriangles;
|
---|
[856098] | 4954 |
|
---|
[fad93c] | 4955 | /// 3. Find connected endpoint candidates and put them into a polygon
|
---|
| 4956 | UniquePolygonSet ListofDegeneratedPolygons;
|
---|
| 4957 | BoundaryPointSet *Walker = NULL;
|
---|
| 4958 | BoundaryPointSet *OtherWalker = NULL;
|
---|
| 4959 | BoundaryPolygonSet *Current = NULL;
|
---|
[6613ec] | 4960 | stack<BoundaryPointSet*> ToCheckConnecteds;
|
---|
[fad93c] | 4961 | while (!EndpointCandidateList.empty()) {
|
---|
| 4962 | Walker = *(EndpointCandidateList.begin());
|
---|
[6613ec] | 4963 | if (Current == NULL) { // create a new polygon with current candidate
|
---|
[a67d19] | 4964 | DoLog(0) && (Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl);
|
---|
[fad93c] | 4965 | Current = new BoundaryPolygonSet;
|
---|
| 4966 | Current->endpoints.insert(Walker);
|
---|
| 4967 | EndpointCandidateList.erase(Walker);
|
---|
| 4968 | ToCheckConnecteds.push(Walker);
|
---|
[856098] | 4969 | }
|
---|
[262bae] | 4970 |
|
---|
[fad93c] | 4971 | // go through to-check stack
|
---|
| 4972 | while (!ToCheckConnecteds.empty()) {
|
---|
| 4973 | Walker = ToCheckConnecteds.top(); // fetch ...
|
---|
| 4974 | ToCheckConnecteds.pop(); // ... and remove
|
---|
| 4975 | for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
|
---|
| 4976 | OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
|
---|
[a67d19] | 4977 | DoLog(1) && (Log() << Verbose(1) << "Checking " << *OtherWalker << endl);
|
---|
[6613ec] | 4978 | set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
|
---|
| 4979 | if (Finder != EndpointCandidateList.end()) { // found a connected partner
|
---|
[a67d19] | 4980 | DoLog(1) && (Log() << Verbose(1) << " Adding to polygon." << endl);
|
---|
[fad93c] | 4981 | Current->endpoints.insert(OtherWalker);
|
---|
[6613ec] | 4982 | EndpointCandidateList.erase(Finder); // remove from candidates
|
---|
| 4983 | ToCheckConnecteds.push(OtherWalker); // but check its partners too
|
---|
[856098] | 4984 | } else {
|
---|
[a67d19] | 4985 | DoLog(1) && (Log() << Verbose(1) << " is not connected to " << *Walker << endl);
|
---|
[856098] | 4986 | }
|
---|
| 4987 | }
|
---|
| 4988 | }
|
---|
[262bae] | 4989 |
|
---|
[a67d19] | 4990 | DoLog(0) && (Log() << Verbose(0) << "Final polygon is " << *Current << endl);
|
---|
[fad93c] | 4991 | ListofDegeneratedPolygons.insert(Current);
|
---|
| 4992 | Current = NULL;
|
---|
[262bae] | 4993 | }
|
---|
| 4994 |
|
---|
[fad93c] | 4995 | const int counter = ListofDegeneratedPolygons.size();
|
---|
[262bae] | 4996 |
|
---|
[a67d19] | 4997 | DoLog(0) && (Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl);
|
---|
[fad93c] | 4998 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
|
---|
[a67d19] | 4999 | DoLog(0) && (Log() << Verbose(0) << " " << **PolygonRunner << endl);
|
---|
[856098] | 5000 |
|
---|
[262bae] | 5001 | /// 4. Go through all these degenerated polygons
|
---|
[fad93c] | 5002 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
|
---|
[6613ec] | 5003 | stack<int> TriangleNrs;
|
---|
[856098] | 5004 | Vector NormalVector;
|
---|
[262bae] | 5005 | /// 4a. Gather all triangles of this polygon
|
---|
[856098] | 5006 | TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
|
---|
[262bae] | 5007 |
|
---|
[125b3c] | 5008 | // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do.
|
---|
[b998c3] | 5009 | if (T->size() == 2) {
|
---|
[a67d19] | 5010 | DoLog(1) && (Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl);
|
---|
[6613ec] | 5011 | delete (T);
|
---|
[b998c3] | 5012 | continue;
|
---|
| 5013 | }
|
---|
| 5014 |
|
---|
[125b3c] | 5015 | // check whether number is even
|
---|
| 5016 | // If this case occurs, we have to think about it!
|
---|
| 5017 | // The Problem is probably due to two degenerated polygons being connected by a bridging, non-degenerated polygon, as somehow one node has
|
---|
| 5018 | // connections to either polygon ...
|
---|
| 5019 | if (T->size() % 2 != 0) {
|
---|
[6613ec] | 5020 | DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);
|
---|
[125b3c] | 5021 | performCriticalExit();
|
---|
| 5022 | }
|
---|
[6613ec] | 5023 | TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
|
---|
[262bae] | 5024 | /// 4a. Get NormalVector for one side (this is "front")
|
---|
[273382] | 5025 | NormalVector = (*TriangleWalker)->NormalVector;
|
---|
[a67d19] | 5026 | DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl);
|
---|
[856098] | 5027 | TriangleWalker++;
|
---|
| 5028 | TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
|
---|
[262bae] | 5029 | /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back")
|
---|
[856098] | 5030 | BoundaryTriangleSet *triangle = NULL;
|
---|
| 5031 | while (TriangleSprinter != T->end()) {
|
---|
| 5032 | TriangleWalker = TriangleSprinter;
|
---|
| 5033 | triangle = *TriangleWalker;
|
---|
| 5034 | TriangleSprinter++;
|
---|
[a67d19] | 5035 | DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl);
|
---|
[273382] | 5036 | if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list
|
---|
[a67d19] | 5037 | DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl);
|
---|
[856098] | 5038 | TriangleNrs.push(triangle->Nr);
|
---|
[262bae] | 5039 | T->erase(TriangleWalker);
|
---|
[856098] | 5040 | RemoveTesselationTriangle(triangle);
|
---|
| 5041 | } else
|
---|
[a67d19] | 5042 | DoLog(1) && (Log() << Verbose(1) << " Keeping ... " << endl);
|
---|
[262bae] | 5043 | }
|
---|
| 5044 | /// 4c. Copy all "front" triangles but with inverse NormalVector
|
---|
| 5045 | TriangleWalker = T->begin();
|
---|
[6613ec] | 5046 | while (TriangleWalker != T->end()) { // go through all front triangles
|
---|
[a67d19] | 5047 | DoLog(1) && (Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl);
|
---|
[856098] | 5048 | for (int i = 0; i < 3; i++)
|
---|
| 5049 | AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
|
---|
[f07f86d] | 5050 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
|
---|
| 5051 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
|
---|
| 5052 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
|
---|
[fad93c] | 5053 | if (TriangleNrs.empty())
|
---|
[6613ec] | 5054 | DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl);
|
---|
[856098] | 5055 | BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
|
---|
| 5056 | AddTesselationTriangle(); // ... and add
|
---|
| 5057 | TriangleNrs.pop();
|
---|
[273382] | 5058 | BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector;
|
---|
[262bae] | 5059 | TriangleWalker++;
|
---|
| 5060 | }
|
---|
[856098] | 5061 | if (!TriangleNrs.empty()) {
|
---|
[6613ec] | 5062 | DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl);
|
---|
[856098] | 5063 | }
|
---|
[6613ec] | 5064 | delete (T); // remove the triangleset
|
---|
[262bae] | 5065 | }
|
---|
[c15ca2] | 5066 | IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
|
---|
[a67d19] | 5067 | DoLog(0) && (Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl);
|
---|
[c15ca2] | 5068 | IndexToIndex::iterator it;
|
---|
[856098] | 5069 | for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
|
---|
[a67d19] | 5070 | DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
|
---|
[6613ec] | 5071 | delete (SimplyDegeneratedTriangles);
|
---|
[262bae] | 5072 | /// 5. exit
|
---|
[856098] | 5073 | UniquePolygonSet::iterator PolygonRunner;
|
---|
[fad93c] | 5074 | while (!ListofDegeneratedPolygons.empty()) {
|
---|
| 5075 | PolygonRunner = ListofDegeneratedPolygons.begin();
|
---|
[6613ec] | 5076 | delete (*PolygonRunner);
|
---|
[fad93c] | 5077 | ListofDegeneratedPolygons.erase(PolygonRunner);
|
---|
[262bae] | 5078 | }
|
---|
| 5079 |
|
---|
| 5080 | return counter;
|
---|
[6613ec] | 5081 | }
|
---|
| 5082 | ;
|
---|