| 1 | #include "molecules.hpp"
|
|---|
| 2 | #include "boundary.hpp"
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | // ======================================== Points on Boundary =================================
|
|---|
| 8 |
|
|---|
| 9 | BoundaryPointSet::BoundaryPointSet()
|
|---|
| 10 | {
|
|---|
| 11 | LinesCount = 0;
|
|---|
| 12 | Nr = -1;
|
|---|
| 13 | };
|
|---|
| 14 |
|
|---|
| 15 | BoundaryPointSet::BoundaryPointSet(atom *Walker)
|
|---|
| 16 | {
|
|---|
| 17 | node = Walker;
|
|---|
| 18 | LinesCount = 0;
|
|---|
| 19 | Nr = Walker->nr;
|
|---|
| 20 | };
|
|---|
| 21 |
|
|---|
| 22 | BoundaryPointSet::~BoundaryPointSet()
|
|---|
| 23 | {
|
|---|
| 24 | cout << Verbose(5) << "Erasing point nr. " << Nr << "." << endl;
|
|---|
| 25 | node = NULL;
|
|---|
| 26 | };
|
|---|
| 27 |
|
|---|
| 28 | void BoundaryPointSet::AddLine(class BoundaryLineSet *line)
|
|---|
| 29 | {
|
|---|
| 30 | cout << Verbose(6) << "Adding line " << *line << " to " << *this << "." << endl;
|
|---|
| 31 | if (line->endpoints[0] == this) {
|
|---|
| 32 | lines.insert ( LinePair( line->endpoints[1]->Nr, line) );
|
|---|
| 33 | } else {
|
|---|
| 34 | lines.insert ( LinePair( line->endpoints[0]->Nr, line) );
|
|---|
| 35 | }
|
|---|
| 36 | LinesCount++;
|
|---|
| 37 | };
|
|---|
| 38 |
|
|---|
| 39 | ostream & operator << (ostream &ost, BoundaryPointSet &a)
|
|---|
| 40 | {
|
|---|
| 41 | ost << "[" << a.Nr << "|" << a.node->Name << "]";
|
|---|
| 42 | return ost;
|
|---|
| 43 | };
|
|---|
| 44 |
|
|---|
| 45 | // ======================================== Lines on Boundary =================================
|
|---|
| 46 |
|
|---|
| 47 | BoundaryLineSet::BoundaryLineSet()
|
|---|
| 48 | {
|
|---|
| 49 | for (int i=0;i<2;i++)
|
|---|
| 50 | endpoints[i] = NULL;
|
|---|
| 51 | TrianglesCount = 0;
|
|---|
| 52 | Nr = -1;
|
|---|
| 53 | };
|
|---|
| 54 |
|
|---|
| 55 | BoundaryLineSet::BoundaryLineSet(class BoundaryPointSet *Point[2], int number)
|
|---|
| 56 | {
|
|---|
| 57 | // set number
|
|---|
| 58 | Nr = number;
|
|---|
| 59 | // set endpoints in ascending order
|
|---|
| 60 | SetEndpointsOrdered(endpoints, Point[0], Point[1]);
|
|---|
| 61 | // add this line to the hash maps of both endpoints
|
|---|
| 62 | Point[0]->AddLine(this);
|
|---|
| 63 | Point[1]->AddLine(this);
|
|---|
| 64 | // clear triangles list
|
|---|
| 65 | TrianglesCount = 0;
|
|---|
| 66 | cout << Verbose(5) << "New Line with endpoints " << *this << "." << endl;
|
|---|
| 67 | };
|
|---|
| 68 |
|
|---|
| 69 | BoundaryLineSet::~BoundaryLineSet()
|
|---|
| 70 | {
|
|---|
| 71 | for (int i=0;i<2;i++) {
|
|---|
| 72 | cout << Verbose(5) << "Erasing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
|
|---|
| 73 | endpoints[i]->lines.erase(Nr);
|
|---|
| 74 | LineMap::iterator tester = endpoints[i]->lines.begin();
|
|---|
| 75 | tester++;
|
|---|
| 76 | if (tester == endpoints[i]->lines.end()) {
|
|---|
| 77 | cout << Verbose(5) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
|
|---|
| 78 | delete(endpoints[i]);
|
|---|
| 79 | } else
|
|---|
| 80 | cout << Verbose(5) << *endpoints[i] << " has still lines it's attached to." << endl;
|
|---|
| 81 | }
|
|---|
| 82 | };
|
|---|
| 83 |
|
|---|
| 84 | void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
|
|---|
| 85 | {
|
|---|
| 86 | cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
|
|---|
| 87 | triangles.insert ( TrianglePair( TrianglesCount, triangle) );
|
|---|
| 88 | TrianglesCount++;
|
|---|
| 89 | };
|
|---|
| 90 |
|
|---|
| 91 | ostream & operator << (ostream &ost, BoundaryLineSet &a)
|
|---|
| 92 | {
|
|---|
| 93 | ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "]";
|
|---|
| 94 | return ost;
|
|---|
| 95 | };
|
|---|
| 96 |
|
|---|
| 97 | // ======================================== Triangles on Boundary =================================
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | BoundaryTriangleSet::BoundaryTriangleSet()
|
|---|
| 101 | {
|
|---|
| 102 | for (int i=0;i<3;i++) {
|
|---|
| 103 | endpoints[i] = NULL;
|
|---|
| 104 | lines[i] = NULL;
|
|---|
| 105 | }
|
|---|
| 106 | Nr = -1;
|
|---|
| 107 | };
|
|---|
| 108 |
|
|---|
| 109 | BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number)
|
|---|
| 110 | {
|
|---|
| 111 | // set number
|
|---|
| 112 | Nr = number;
|
|---|
| 113 | // set lines
|
|---|
| 114 | cout << Verbose(5) << "New triangle " << Nr << ":" << endl;
|
|---|
| 115 | for (int i=0;i<3;i++) {
|
|---|
| 116 | lines[i] = line[i];
|
|---|
| 117 | lines[i]->AddTriangle(this);
|
|---|
| 118 | }
|
|---|
| 119 | // get ascending order of endpoints
|
|---|
| 120 | map <int, class BoundaryPointSet * > OrderMap;
|
|---|
| 121 | for(int i=0;i<3;i++) // for all three lines
|
|---|
| 122 | for (int j=0;j<2;j++) { // for both endpoints
|
|---|
| 123 | OrderMap.insert ( pair <int, class BoundaryPointSet * >( line[i]->endpoints[j]->Nr, line[i]->endpoints[j]) );
|
|---|
| 124 | // and we don't care whether insertion fails
|
|---|
| 125 | }
|
|---|
| 126 | // set endpoints
|
|---|
| 127 | int Counter = 0;
|
|---|
| 128 | cout << Verbose(6) << " with end points ";
|
|---|
| 129 | for (map <int, class BoundaryPointSet * >::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
|
|---|
| 130 | endpoints[Counter] = runner->second;
|
|---|
| 131 | cout << " " << *endpoints[Counter];
|
|---|
| 132 | Counter++;
|
|---|
| 133 | }
|
|---|
| 134 | if (Counter < 3) {
|
|---|
| 135 | cerr << "ERROR! We have a triangle with only two distinct endpoints!" << endl;
|
|---|
| 136 | //exit(1);
|
|---|
| 137 | }
|
|---|
| 138 | cout << "." << endl;
|
|---|
| 139 | };
|
|---|
| 140 |
|
|---|
| 141 | BoundaryTriangleSet::~BoundaryTriangleSet()
|
|---|
| 142 | {
|
|---|
| 143 | for (int i=0;i<3;i++) {
|
|---|
| 144 | cout << Verbose(5) << "Erasing triangle Nr." << Nr << endl;
|
|---|
| 145 | lines[i]->triangles.erase(Nr);
|
|---|
| 146 | TriangleMap::iterator tester = lines[i]->triangles.begin();
|
|---|
| 147 | tester++;
|
|---|
| 148 | if (tester == lines[i]->triangles.end()) {
|
|---|
| 149 | cout << Verbose(5) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
|
|---|
| 150 | delete(lines[i]);
|
|---|
| 151 | } else
|
|---|
| 152 | cout << Verbose(5) << *lines[i] << " is still attached to a triangle." << endl;
|
|---|
| 153 | }
|
|---|
| 154 | };
|
|---|
| 155 |
|
|---|
| 156 | void BoundaryTriangleSet::GetNormalVector(Vector &NormalVector)
|
|---|
| 157 | {
|
|---|
| 158 | // get normal vector
|
|---|
| 159 | NormalVector.MakeNormalVector(&endpoints[0]->node->x, &endpoints[1]->node->x, &endpoints[2]->node->x);
|
|---|
| 160 |
|
|---|
| 161 | // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
|
|---|
| 162 | if (endpoints[0]->node->x.Projection(&NormalVector) > 0)
|
|---|
| 163 | NormalVector.Scale(-1.);
|
|---|
| 164 | };
|
|---|
| 165 |
|
|---|
| 166 | ostream & operator << (ostream &ost, BoundaryTriangleSet &a)
|
|---|
| 167 | {
|
|---|
| 168 | ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]";
|
|---|
| 169 | return ost;
|
|---|
| 170 | };
|
|---|
| 171 |
|
|---|
| 172 | // ========================================== F U N C T I O N S =================================
|
|---|
| 173 |
|
|---|
| 174 | /** Finds the endpoint two lines are sharing.
|
|---|
| 175 | * \param *line1 first line
|
|---|
| 176 | * \param *line2 second line
|
|---|
| 177 | * \return point which is shared or NULL if none
|
|---|
| 178 | */
|
|---|
| 179 | class BoundaryPointSet * GetCommonEndpoint(class BoundaryLineSet * line1, class BoundaryLineSet * line2)
|
|---|
| 180 | {
|
|---|
| 181 | class BoundaryLineSet * lines[2] = {line1, line2};
|
|---|
| 182 | class BoundaryPointSet *node = NULL;
|
|---|
| 183 | map <int, class BoundaryPointSet * > OrderMap;
|
|---|
| 184 | pair < map <int, class BoundaryPointSet * >::iterator, bool > OrderTest;
|
|---|
| 185 | for(int i=0;i<2;i++) // for both lines
|
|---|
| 186 | for (int j=0;j<2;j++) { // for both endpoints
|
|---|
| 187 | OrderTest = OrderMap.insert ( pair <int, class BoundaryPointSet * >( lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]) );
|
|---|
| 188 | if (!OrderTest.second) { // if insertion fails, we have common endpoint
|
|---|
| 189 | node = OrderTest.first->second;
|
|---|
| 190 | cout << Verbose(5) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl;
|
|---|
| 191 | j=2;
|
|---|
| 192 | i=2;
|
|---|
| 193 | break;
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 | return node;
|
|---|
| 197 | };
|
|---|
| 198 |
|
|---|
| 199 | /** Determines the boundary points of a cluster.
|
|---|
| 200 | * Does a projection per axis onto the orthogonal plane, transforms into spherical coordinates, sorts them by the angle
|
|---|
| 201 | * and looks at triples: if the middle has less a distance than the allowed maximum height of the triangle formed by the plane's
|
|---|
| 202 | * center and first and last point in the triple, it is thrown out.
|
|---|
| 203 | * \param *out output stream for debugging
|
|---|
| 204 | * \param *mol molecule structure representing the cluster
|
|---|
| 205 | */
|
|---|
| 206 | Boundaries * GetBoundaryPoints(ofstream *out, molecule *mol)
|
|---|
| 207 | {
|
|---|
| 208 | atom *Walker = NULL;
|
|---|
| 209 | PointMap PointsOnBoundary;
|
|---|
| 210 | LineMap LinesOnBoundary;
|
|---|
| 211 | TriangleMap TrianglesOnBoundary;
|
|---|
| 212 |
|
|---|
| 213 | *out << Verbose(1) << "Finding all boundary points." << endl;
|
|---|
| 214 | Boundaries *BoundaryPoints = new Boundaries [NDIM]; // first is alpha, second is (r, nr)
|
|---|
| 215 | BoundariesTestPair BoundaryTestPair;
|
|---|
| 216 | Vector AxisVector, AngleReferenceVector, AngleReferenceNormalVector;
|
|---|
| 217 | double radius, angle;
|
|---|
| 218 | // 3a. Go through every axis
|
|---|
| 219 | for (int axis=0; axis<NDIM; axis++) {
|
|---|
| 220 | AxisVector.Zero();
|
|---|
| 221 | AngleReferenceVector.Zero();
|
|---|
| 222 | AngleReferenceNormalVector.Zero();
|
|---|
| 223 | AxisVector.x[axis] = 1.;
|
|---|
| 224 | AngleReferenceVector.x[(axis+1)%NDIM] = 1.;
|
|---|
| 225 | AngleReferenceNormalVector.x[(axis+2)%NDIM] = 1.;
|
|---|
| 226 | // *out << Verbose(1) << "Axisvector is ";
|
|---|
| 227 | // AxisVector.Output(out);
|
|---|
| 228 | // *out << " and AngleReferenceVector is ";
|
|---|
| 229 | // AngleReferenceVector.Output(out);
|
|---|
| 230 | // *out << "." << endl;
|
|---|
| 231 | // *out << " and AngleReferenceNormalVector is ";
|
|---|
| 232 | // AngleReferenceNormalVector.Output(out);
|
|---|
| 233 | // *out << "." << endl;
|
|---|
| 234 | // 3b. construct set of all points, transformed into cylindrical system and with left and right neighbours
|
|---|
| 235 | Walker = mol->start;
|
|---|
| 236 | while (Walker->next != mol->end) {
|
|---|
| 237 | Walker = Walker->next;
|
|---|
| 238 | Vector ProjectedVector;
|
|---|
| 239 | ProjectedVector.CopyVector(&Walker->x);
|
|---|
| 240 | ProjectedVector.ProjectOntoPlane(&AxisVector);
|
|---|
| 241 | // correct for negative side
|
|---|
| 242 | //if (Projection(y) < 0)
|
|---|
| 243 | //angle = 2.*M_PI - angle;
|
|---|
| 244 | radius = ProjectedVector.Norm();
|
|---|
| 245 | if (fabs(radius) > MYEPSILON)
|
|---|
| 246 | angle = ProjectedVector.Angle(&AngleReferenceVector);
|
|---|
| 247 | else
|
|---|
| 248 | angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues
|
|---|
| 249 |
|
|---|
| 250 | //*out << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
|
|---|
| 251 | if (ProjectedVector.Projection(&AngleReferenceNormalVector) > 0) {
|
|---|
| 252 | angle = 2.*M_PI - angle;
|
|---|
| 253 | }
|
|---|
| 254 | //*out << Verbose(2) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): ";
|
|---|
| 255 | //ProjectedVector.Output(out);
|
|---|
| 256 | //*out << endl;
|
|---|
| 257 | BoundaryTestPair = BoundaryPoints[axis].insert( BoundariesPair (angle, DistancePair (radius, Walker) ) );
|
|---|
| 258 | if (BoundaryTestPair.second) { // successfully inserted
|
|---|
| 259 | } else { // same point exists, check first r, then distance of original vectors to center of gravity
|
|---|
| 260 | *out << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl;
|
|---|
| 261 | *out << Verbose(2) << "Present vector: ";
|
|---|
| 262 | BoundaryTestPair.first->second.second->x.Output(out);
|
|---|
| 263 | *out << endl;
|
|---|
| 264 | *out << Verbose(2) << "New vector: ";
|
|---|
| 265 | Walker->x.Output(out);
|
|---|
| 266 | *out << endl;
|
|---|
| 267 | double tmp = ProjectedVector.Norm();
|
|---|
| 268 | if (tmp > BoundaryTestPair.first->second.first) {
|
|---|
| 269 | BoundaryTestPair.first->second.first = tmp;
|
|---|
| 270 | BoundaryTestPair.first->second.second = Walker;
|
|---|
| 271 | *out << Verbose(2) << "Keeping new vector." << endl;
|
|---|
| 272 | } else if (tmp == BoundaryTestPair.first->second.first) {
|
|---|
| 273 | if (BoundaryTestPair.first->second.second->x.ScalarProduct(&BoundaryTestPair.first->second.second->x) < Walker->x.ScalarProduct(&Walker->x)) { // Norm() does a sqrt, which makes it a lot slower
|
|---|
| 274 | BoundaryTestPair.first->second.second = Walker;
|
|---|
| 275 | *out << Verbose(2) << "Keeping new vector." << endl;
|
|---|
| 276 | } else {
|
|---|
| 277 | *out << Verbose(2) << "Keeping present vector." << endl;
|
|---|
| 278 | }
|
|---|
| 279 | } else {
|
|---|
| 280 | *out << Verbose(2) << "Keeping present vector." << endl;
|
|---|
| 281 | }
|
|---|
| 282 | }
|
|---|
| 283 | }
|
|---|
| 284 | // printing all inserted for debugging
|
|---|
| 285 | // {
|
|---|
| 286 | // *out << Verbose(2) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
|
|---|
| 287 | // int i=0;
|
|---|
| 288 | // for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
|
|---|
| 289 | // if (runner != BoundaryPoints[axis].begin())
|
|---|
| 290 | // *out << ", " << i << ": " << *runner->second.second;
|
|---|
| 291 | // else
|
|---|
| 292 | // *out << i << ": " << *runner->second.second;
|
|---|
| 293 | // i++;
|
|---|
| 294 | // }
|
|---|
| 295 | // *out << endl;
|
|---|
| 296 | // }
|
|---|
| 297 | // 3c. throw out points whose distance is less than the mean of left and right neighbours
|
|---|
| 298 | bool flag = false;
|
|---|
| 299 | do { // do as long as we still throw one out per round
|
|---|
| 300 | *out << Verbose(1) << "Looking for candidates to kick out by convex condition ... " << endl;
|
|---|
| 301 | flag = false;
|
|---|
| 302 | Boundaries::iterator left = BoundaryPoints[axis].end();
|
|---|
| 303 | Boundaries::iterator right = BoundaryPoints[axis].end();
|
|---|
| 304 | for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
|
|---|
| 305 | // set neighbours correctly
|
|---|
| 306 | if (runner == BoundaryPoints[axis].begin()) {
|
|---|
| 307 | left = BoundaryPoints[axis].end();
|
|---|
| 308 | } else {
|
|---|
| 309 | left = runner;
|
|---|
| 310 | }
|
|---|
| 311 | left--;
|
|---|
| 312 | right = runner;
|
|---|
| 313 | right++;
|
|---|
| 314 | if (right == BoundaryPoints[axis].end()) {
|
|---|
| 315 | right = BoundaryPoints[axis].begin();
|
|---|
| 316 | }
|
|---|
| 317 | // check distance
|
|---|
| 318 |
|
|---|
| 319 | // construct the vector of each side of the triangle on the projected plane (defined by normal vector AxisVector)
|
|---|
| 320 | {
|
|---|
| 321 | Vector SideA, SideB, SideC, SideH;
|
|---|
| 322 | SideA.CopyVector(&left->second.second->x);
|
|---|
| 323 | SideA.ProjectOntoPlane(&AxisVector);
|
|---|
| 324 | // *out << "SideA: ";
|
|---|
| 325 | // SideA.Output(out);
|
|---|
| 326 | // *out << endl;
|
|---|
| 327 |
|
|---|
| 328 | SideB.CopyVector(&right->second.second->x);
|
|---|
| 329 | SideB.ProjectOntoPlane(&AxisVector);
|
|---|
| 330 | // *out << "SideB: ";
|
|---|
| 331 | // SideB.Output(out);
|
|---|
| 332 | // *out << endl;
|
|---|
| 333 |
|
|---|
| 334 | SideC.CopyVector(&left->second.second->x);
|
|---|
| 335 | SideC.SubtractVector(&right->second.second->x);
|
|---|
| 336 | SideC.ProjectOntoPlane(&AxisVector);
|
|---|
| 337 | // *out << "SideC: ";
|
|---|
| 338 | // SideC.Output(out);
|
|---|
| 339 | // *out << endl;
|
|---|
| 340 |
|
|---|
| 341 | SideH.CopyVector(&runner->second.second->x);
|
|---|
| 342 | SideH.ProjectOntoPlane(&AxisVector);
|
|---|
| 343 | // *out << "SideH: ";
|
|---|
| 344 | // SideH.Output(out);
|
|---|
| 345 | // *out << endl;
|
|---|
| 346 |
|
|---|
| 347 | // calculate each length
|
|---|
| 348 | double a = SideA.Norm();
|
|---|
| 349 | //double b = SideB.Norm();
|
|---|
| 350 | //double c = SideC.Norm();
|
|---|
| 351 | double h = SideH.Norm();
|
|---|
| 352 | // calculate the angles
|
|---|
| 353 | double alpha = SideA.Angle(&SideH);
|
|---|
| 354 | double beta = SideA.Angle(&SideC);
|
|---|
| 355 | double gamma = SideB.Angle(&SideH);
|
|---|
| 356 | double delta = SideC.Angle(&SideH);
|
|---|
| 357 | double MinDistance = a * sin(beta)/(sin(delta)) * (((alpha < M_PI/2.) || (gamma < M_PI/2.)) ? 1. : -1.);
|
|---|
| 358 | // *out << Verbose(2) << " I calculated: a = " << a << ", h = " << h << ", beta(" << left->second.second->Name << "," << left->second.second->Name << "-" << right->second.second->Name << ") = " << beta << ", delta(" << left->second.second->Name << "," << runner->second.second->Name << ") = " << delta << ", Min = " << MinDistance << "." << endl;
|
|---|
| 359 | //*out << Verbose(1) << "Checking CoG distance of runner " << *runner->second.second << " " << h << " against triangle's side length spanned by (" << *left->second.second << "," << *right->second.second << ") of " << MinDistance << "." << endl;
|
|---|
| 360 | if ((fabs(h/fabs(h) - MinDistance/fabs(MinDistance)) < MYEPSILON) && (h < MinDistance)) {
|
|---|
| 361 | // throw out point
|
|---|
| 362 | //*out << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl;
|
|---|
| 363 | BoundaryPoints[axis].erase(runner);
|
|---|
| 364 | flag = true;
|
|---|
| 365 | }
|
|---|
| 366 | }
|
|---|
| 367 | }
|
|---|
| 368 | } while (flag);
|
|---|
| 369 | }
|
|---|
| 370 | return BoundaryPoints;
|
|---|
| 371 | };
|
|---|
| 372 |
|
|---|
| 373 | /** Determines greatest diameters of a cluster defined by its convex envelope.
|
|---|
| 374 | * Looks at lines parallel to one axis and where they intersect on the projected planes
|
|---|
| 375 | * \param *out output stream for debugging
|
|---|
| 376 | * \param *BoundaryPoints NDIM set of boundary points defining the convex envelope on each projected plane
|
|---|
| 377 | * \param *mol molecule structure representing the cluster
|
|---|
| 378 | * \param IsAngstroem whether we have angstroem or atomic units
|
|---|
| 379 | * \return NDIM array of the diameters
|
|---|
| 380 | */
|
|---|
| 381 | double * GetDiametersOfCluster(ofstream *out, Boundaries *BoundaryPtr, molecule *mol, bool IsAngstroem)
|
|---|
| 382 | {
|
|---|
| 383 | // get points on boundary of NULL was given as parameter
|
|---|
| 384 | bool BoundaryFreeFlag = false;
|
|---|
| 385 | Boundaries *BoundaryPoints = BoundaryPtr;
|
|---|
| 386 | if (BoundaryPoints == NULL) {
|
|---|
| 387 | BoundaryFreeFlag = true;
|
|---|
| 388 | BoundaryPoints = GetBoundaryPoints(out, mol);
|
|---|
| 389 | } else {
|
|---|
| 390 | *out << Verbose(1) << "Using given boundary points set." << endl;
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | // determine biggest "diameter" of cluster for each axis
|
|---|
| 394 | Boundaries::iterator Neighbour, OtherNeighbour;
|
|---|
| 395 | double *GreatestDiameter = new double[NDIM];
|
|---|
| 396 | for(int i=0;i<NDIM;i++)
|
|---|
| 397 | GreatestDiameter[i] = 0.;
|
|---|
| 398 | double OldComponent, tmp, w1, w2;
|
|---|
| 399 | Vector DistanceVector, OtherVector;
|
|---|
| 400 | int component, Othercomponent;
|
|---|
| 401 | for(int axis=0;axis<NDIM;axis++) { // regard each projected plane
|
|---|
| 402 | //*out << Verbose(1) << "Current axis is " << axis << "." << endl;
|
|---|
| 403 | for (int j=0;j<2;j++) { // and for both axis on the current plane
|
|---|
| 404 | component = (axis+j+1)%NDIM;
|
|---|
| 405 | Othercomponent = (axis+1+((j+1) & 1))%NDIM;
|
|---|
| 406 | //*out << Verbose(1) << "Current component is " << component << ", Othercomponent is " << Othercomponent << "." << endl;
|
|---|
| 407 | for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
|
|---|
| 408 | //*out << Verbose(2) << "Current runner is " << *(runner->second.second) << "." << endl;
|
|---|
| 409 | // seek for the neighbours pair where the Othercomponent sign flips
|
|---|
| 410 | Neighbour = runner;
|
|---|
| 411 | Neighbour++;
|
|---|
| 412 | if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around
|
|---|
| 413 | Neighbour = BoundaryPoints[axis].begin();
|
|---|
| 414 | DistanceVector.CopyVector(&runner->second.second->x);
|
|---|
| 415 | DistanceVector.SubtractVector(&Neighbour->second.second->x);
|
|---|
| 416 | do { // seek for neighbour pair where it flips
|
|---|
| 417 | OldComponent = DistanceVector.x[Othercomponent];
|
|---|
| 418 | Neighbour++;
|
|---|
| 419 | if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around
|
|---|
| 420 | Neighbour = BoundaryPoints[axis].begin();
|
|---|
| 421 | DistanceVector.CopyVector(&runner->second.second->x);
|
|---|
| 422 | DistanceVector.SubtractVector(&Neighbour->second.second->x);
|
|---|
| 423 | //*out << Verbose(3) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl;
|
|---|
| 424 | } while ((runner != Neighbour) && ( fabs( OldComponent/fabs(OldComponent) - DistanceVector.x[Othercomponent]/fabs(DistanceVector.x[Othercomponent]) ) < MYEPSILON)); // as long as sign does not flip
|
|---|
| 425 | if (runner != Neighbour) {
|
|---|
| 426 | OtherNeighbour = Neighbour;
|
|---|
| 427 | if (OtherNeighbour == BoundaryPoints[axis].begin()) // make it wrap around
|
|---|
| 428 | OtherNeighbour = BoundaryPoints[axis].end();
|
|---|
| 429 | OtherNeighbour--;
|
|---|
| 430 | //*out << Verbose(2) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl;
|
|---|
| 431 | // now we have found the pair: Neighbour and OtherNeighbour
|
|---|
| 432 | OtherVector.CopyVector(&runner->second.second->x);
|
|---|
| 433 | OtherVector.SubtractVector(&OtherNeighbour->second.second->x);
|
|---|
| 434 | //*out << Verbose(2) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl;
|
|---|
| 435 | //*out << Verbose(2) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl;
|
|---|
| 436 | // do linear interpolation between points (is exact) to extract exact intersection between Neighbour and OtherNeighbour
|
|---|
| 437 | w1 = fabs(OtherVector.x[Othercomponent]);
|
|---|
| 438 | w2 = fabs(DistanceVector.x[Othercomponent]);
|
|---|
| 439 | tmp = fabs((w1*DistanceVector.x[component] + w2*OtherVector.x[component])/(w1+w2));
|
|---|
| 440 | // mark if it has greater diameter
|
|---|
| 441 | //*out << Verbose(2) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl;
|
|---|
| 442 | GreatestDiameter[component] = (GreatestDiameter[component] > tmp) ? GreatestDiameter[component] : tmp;
|
|---|
| 443 | } //else
|
|---|
| 444 | //*out << Verbose(2) << "Saw no sign flip, probably top or bottom node." << endl;
|
|---|
| 445 | }
|
|---|
| 446 | }
|
|---|
| 447 | }
|
|---|
| 448 | *out << Verbose(0) << "RESULT: The biggest diameters are " << GreatestDiameter[0] << " and " << GreatestDiameter[1] << " and " << GreatestDiameter[2] << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "." << endl;
|
|---|
| 449 |
|
|---|
| 450 | // free reference lists
|
|---|
| 451 | if (BoundaryFreeFlag)
|
|---|
| 452 | delete[](BoundaryPoints);
|
|---|
| 453 |
|
|---|
| 454 | return GreatestDiameter;
|
|---|
| 455 | };
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 | /*
|
|---|
| 459 | * This function creates the tecplot file, displaying the tesselation of the hull.
|
|---|
| 460 | * \param *out output stream for debugging
|
|---|
| 461 | * \param *tecplot output stream for tecplot data
|
|---|
| 462 | */
|
|---|
| 463 | void write_tecplot_file(ofstream *out, ofstream *tecplot, class Tesselation *TesselStruct, class molecule *mol)
|
|---|
| 464 | {
|
|---|
| 465 | // 8. Store triangles in tecplot file
|
|---|
| 466 | if (tecplot != NULL) {
|
|---|
| 467 | *tecplot << "TITLE = \"3D CONVEX SHELL\"" << endl;
|
|---|
| 468 | *tecplot << "VARIABLES = \"X\" \"Y\" \"Z\"" << endl;
|
|---|
| 469 | *tecplot << "ZONE T=\"TRIANGLES\", N=" << TesselStruct->PointsOnBoundaryCount << ", E=" << TesselStruct->TrianglesOnBoundaryCount << ", DATAPACKING=POINT, ZONETYPE=FETRIANGLE" << endl;
|
|---|
| 470 | int *LookupList = new int[mol->AtomCount];
|
|---|
| 471 | for (int i=0;i<mol->AtomCount;i++)
|
|---|
| 472 | LookupList[i] = -1;
|
|---|
| 473 |
|
|---|
| 474 | // print atom coordinates
|
|---|
| 475 | *out << Verbose(2) << "The following triangles were created:";
|
|---|
| 476 | int Counter = 1;
|
|---|
| 477 | atom *Walker = NULL;
|
|---|
| 478 | for (PointMap::iterator target = TesselStruct->PointsOnBoundary.begin(); target != TesselStruct->PointsOnBoundary.end(); target++) {
|
|---|
| 479 | Walker = target->second->node;
|
|---|
| 480 | LookupList[Walker->nr] = Counter++;
|
|---|
| 481 | *tecplot << Walker->x.x[0] << " " << Walker->x.x[1] << " " << Walker->x.x[2] << " " << endl;
|
|---|
| 482 | }
|
|---|
| 483 | *tecplot << endl;
|
|---|
| 484 | // print connectivity
|
|---|
| 485 | for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++) {
|
|---|
| 486 | *out << " " << runner->second->endpoints[0]->node->Name << "<->" << runner->second->endpoints[1]->node->Name << "<->" << runner->second->endpoints[2]->node->Name;
|
|---|
| 487 | *tecplot << LookupList[runner->second->endpoints[0]->node->nr] << " " << LookupList[runner->second->endpoints[1]->node->nr] << " " << LookupList[runner->second->endpoints[2]->node->nr] << endl;
|
|---|
| 488 | }
|
|---|
| 489 | delete[](LookupList);
|
|---|
| 490 | *out << endl;
|
|---|
| 491 | }
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | /** Determines the volume of a cluster.
|
|---|
| 495 | * Determines first the convex envelope, then tesselates it and calculates its volume.
|
|---|
| 496 | * \param *out output stream for debugging
|
|---|
| 497 | * \param *tecplot output stream for tecplot data
|
|---|
| 498 | * \param *configuration needed for path to store convex envelope file
|
|---|
| 499 | * \param *BoundaryPoints NDIM set of boundary points on the projected plane per axis, on return if desired
|
|---|
| 500 | * \param *mol molecule structure representing the cluster
|
|---|
| 501 | * \return determined volume of the cluster in cubed config:GetIsAngstroem()
|
|---|
| 502 | */
|
|---|
| 503 | double VolumeOfConvexEnvelope(ofstream *out, ofstream *tecplot, config *configuration, Boundaries *BoundaryPtr, molecule *mol)
|
|---|
| 504 | {
|
|---|
| 505 | bool IsAngstroem = configuration->GetIsAngstroem();
|
|---|
| 506 | atom *Walker = NULL;
|
|---|
| 507 | struct Tesselation *TesselStruct = new Tesselation;
|
|---|
| 508 | bool BoundaryFreeFlag = false;
|
|---|
| 509 | Boundaries *BoundaryPoints = BoundaryPtr;
|
|---|
| 510 | double volume = 0.;
|
|---|
| 511 | double PyramidVolume = 0.;
|
|---|
| 512 | double G,h;
|
|---|
| 513 | Vector x,y;
|
|---|
| 514 | double a,b,c;
|
|---|
| 515 |
|
|---|
| 516 | Find_non_convex_border(out, tecplot, *TesselStruct, mol);
|
|---|
| 517 | /*
|
|---|
| 518 | // 1. calculate center of gravity
|
|---|
| 519 | *out << endl;
|
|---|
| 520 | Vector *CenterOfGravity = mol->DetermineCenterOfGravity(out);
|
|---|
| 521 |
|
|---|
| 522 | // 2. translate all points into CoG
|
|---|
| 523 | *out << Verbose(1) << "Translating system to Center of Gravity." << endl;
|
|---|
| 524 | Walker = mol->start;
|
|---|
| 525 | while (Walker->next != mol->end) {
|
|---|
| 526 | Walker = Walker->next;
|
|---|
| 527 | Walker->x.Translate(CenterOfGravity);
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | // 3. Find all points on the boundary
|
|---|
| 531 | if (BoundaryPoints == NULL) {
|
|---|
| 532 | BoundaryFreeFlag = true;
|
|---|
| 533 | BoundaryPoints = GetBoundaryPoints(out, mol);
|
|---|
| 534 | } else {
|
|---|
| 535 | *out << Verbose(1) << "Using given boundary points set." << endl;
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | // 4. fill the boundary point list
|
|---|
| 539 | for (int axis=0;axis<NDIM;axis++)
|
|---|
| 540 | for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
|
|---|
| 541 | TesselStruct->AddPoint(runner->second.second);
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | *out << Verbose(2) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl;
|
|---|
| 545 | // now we have the whole set of edge points in the BoundaryList
|
|---|
| 546 |
|
|---|
| 547 | // listing for debugging
|
|---|
| 548 | // *out << Verbose(1) << "Listing PointsOnBoundary:";
|
|---|
| 549 | // for(PointMap::iterator runner = PointsOnBoundary.begin(); runner != PointsOnBoundary.end(); runner++) {
|
|---|
| 550 | // *out << " " << *runner->second;
|
|---|
| 551 | // }
|
|---|
| 552 | // *out << endl;
|
|---|
| 553 |
|
|---|
| 554 | // 5a. guess starting triangle
|
|---|
| 555 | TesselStruct->GuessStartingTriangle(out);
|
|---|
| 556 |
|
|---|
| 557 | // 5b. go through all lines, that are not yet part of two triangles (only of one so far)
|
|---|
| 558 | TesselStruct->TesselateOnBoundary(out, configuration, mol);
|
|---|
| 559 |
|
|---|
| 560 | *out << Verbose(2) << "I created " << TesselStruct->TrianglesOnBoundaryCount << " triangles with " << TesselStruct->LinesOnBoundaryCount << " lines and " << TesselStruct->PointsOnBoundaryCount << " points." << endl;
|
|---|
| 561 | */
|
|---|
| 562 |
|
|---|
| 563 |
|
|---|
| 564 | // 6a. Every triangle forms a pyramid with the center of gravity as its peak, sum up the volumes
|
|---|
| 565 | *out << Verbose(1) << "Calculating the volume of the pyramids formed out of triangles and center of gravity." << endl;
|
|---|
| 566 | for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++) { // go through every triangle, calculate volume of its pyramid with CoG as peak
|
|---|
| 567 | x.CopyVector(&runner->second->endpoints[0]->node->x);
|
|---|
| 568 | x.SubtractVector(&runner->second->endpoints[1]->node->x);
|
|---|
| 569 | y.CopyVector(&runner->second->endpoints[0]->node->x);
|
|---|
| 570 | y.SubtractVector(&runner->second->endpoints[2]->node->x);
|
|---|
| 571 | a = sqrt(runner->second->endpoints[0]->node->x.Distance(&runner->second->endpoints[1]->node->x));
|
|---|
| 572 | b = sqrt(runner->second->endpoints[0]->node->x.Distance(&runner->second->endpoints[2]->node->x));
|
|---|
| 573 | c = sqrt(runner->second->endpoints[2]->node->x.Distance(&runner->second->endpoints[1]->node->x));
|
|---|
| 574 | G = sqrt( ( (a*a+b*b+c*c)*(a*a+b*b+c*c) - 2*(a*a*a*a + b*b*b*b + c*c*c*c) )/16.); // area of tesselated triangle
|
|---|
| 575 | x.MakeNormalVector(&runner->second->endpoints[0]->node->x, &runner->second->endpoints[1]->node->x, &runner->second->endpoints[2]->node->x);
|
|---|
| 576 | x.Scale(runner->second->endpoints[1]->node->x.Projection(&x));
|
|---|
| 577 | h = x.Norm(); // distance of CoG to triangle
|
|---|
| 578 | PyramidVolume = (1./3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
|
|---|
| 579 | *out << Verbose(2) << "Area of triangle is " << G << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^2, height is " << h << " and the volume is " << PyramidVolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
|
|---|
| 580 | volume += PyramidVolume;
|
|---|
| 581 | }
|
|---|
| 582 | *out << Verbose(0) << "RESULT: The summed volume is " << setprecision(10) << volume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
|
|---|
| 583 |
|
|---|
| 584 | /*
|
|---|
| 585 | // 7. translate all points back from CoG
|
|---|
| 586 | *out << Verbose(1) << "Translating system back from Center of Gravity." << endl;
|
|---|
| 587 | CenterOfGravity->Scale(-1);
|
|---|
| 588 | Walker = mol->start;
|
|---|
| 589 | while (Walker->next != mol->end) {
|
|---|
| 590 | Walker = Walker->next;
|
|---|
| 591 | Walker->x.Translate(CenterOfGravity);
|
|---|
| 592 | }
|
|---|
| 593 | */
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 | write_tecplot_file(out, tecplot, TesselStruct, mol);
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 | // free reference lists
|
|---|
| 602 | if (BoundaryFreeFlag)
|
|---|
| 603 | delete[](BoundaryPoints);
|
|---|
| 604 |
|
|---|
| 605 | return volume;
|
|---|
| 606 | };
|
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 | /** Creates multiples of the by \a *mol given cluster and suspends them in water with a given final density.
|
|---|
| 610 | * We get cluster volume by VolumeOfConvexEnvelope() and its diameters by GetDiametersOfCluster()
|
|---|
| 611 | * \param *out output stream for debugging
|
|---|
| 612 | * \param *configuration needed for path to store convex envelope file
|
|---|
| 613 | * \param *mol molecule structure representing the cluster
|
|---|
| 614 | * \param ClusterVolume guesstimated cluster volume, if equal 0 we used VolumeOfConvexEnvelope() instead.
|
|---|
| 615 | * \param celldensity desired average density in final cell
|
|---|
| 616 | */
|
|---|
| 617 | void PrepareClustersinWater(ofstream *out, config *configuration, molecule *mol, double ClusterVolume, double celldensity)
|
|---|
| 618 | {
|
|---|
| 619 | // transform to PAS
|
|---|
| 620 | mol->PrincipalAxisSystem(out, true);
|
|---|
| 621 |
|
|---|
| 622 | // some preparations beforehand
|
|---|
| 623 | bool IsAngstroem = configuration->GetIsAngstroem();
|
|---|
| 624 | Boundaries *BoundaryPoints = GetBoundaryPoints(out, mol);
|
|---|
| 625 | double clustervolume;
|
|---|
| 626 | if (ClusterVolume == 0)
|
|---|
| 627 | clustervolume = VolumeOfConvexEnvelope(out, NULL, configuration, BoundaryPoints, mol);
|
|---|
| 628 | else
|
|---|
| 629 | clustervolume = ClusterVolume;
|
|---|
| 630 | double *GreatestDiameter = GetDiametersOfCluster(out, BoundaryPoints, mol, IsAngstroem);
|
|---|
| 631 | Vector BoxLengths;
|
|---|
| 632 | int repetition[NDIM] = {1, 1, 1};
|
|---|
| 633 | int TotalNoClusters = 1;
|
|---|
| 634 | for (int i=0;i<NDIM;i++)
|
|---|
| 635 | TotalNoClusters *= repetition[i];
|
|---|
| 636 |
|
|---|
| 637 | // sum up the atomic masses
|
|---|
| 638 | double totalmass = 0.;
|
|---|
| 639 | atom *Walker = mol->start;
|
|---|
| 640 | while (Walker->next != mol->end) {
|
|---|
| 641 | Walker = Walker->next;
|
|---|
| 642 | totalmass += Walker->type->mass;
|
|---|
| 643 | }
|
|---|
| 644 | *out << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl;
|
|---|
| 645 |
|
|---|
| 646 | *out << Verbose(0) << "RESULT: The average density is " << setprecision(10) << totalmass/clustervolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
|
|---|
| 647 |
|
|---|
| 648 | // solve cubic polynomial
|
|---|
| 649 | *out << Verbose(1) << "Solving equidistant suspension in water problem ..." << endl;
|
|---|
| 650 | double cellvolume;
|
|---|
| 651 | if (IsAngstroem)
|
|---|
| 652 | cellvolume = (TotalNoClusters*totalmass/SOLVENTDENSITY_A - (totalmass/clustervolume))/(celldensity-1);
|
|---|
| 653 | else
|
|---|
| 654 | cellvolume = (TotalNoClusters*totalmass/SOLVENTDENSITY_a0 - (totalmass/clustervolume))/(celldensity-1);
|
|---|
| 655 | *out << Verbose(1) << "Cellvolume needed for a density of " << celldensity << " g/cm^3 is " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
|
|---|
| 656 |
|
|---|
| 657 | double minimumvolume = TotalNoClusters*(GreatestDiameter[0]*GreatestDiameter[1]*GreatestDiameter[2]);
|
|---|
| 658 | *out << Verbose(1) << "Minimum volume of the convex envelope contained in a rectangular box is " << minimumvolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
|
|---|
| 659 | if (minimumvolume > cellvolume) {
|
|---|
| 660 | cerr << Verbose(0) << "ERROR: the containing box already has a greater volume than the envisaged cell volume!" << endl;
|
|---|
| 661 | cout << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl;
|
|---|
| 662 | for(int i=0;i<NDIM;i++)
|
|---|
| 663 | BoxLengths.x[i] = GreatestDiameter[i];
|
|---|
| 664 | mol->CenterEdge(out, &BoxLengths);
|
|---|
| 665 | } else {
|
|---|
| 666 | BoxLengths.x[0] = (repetition[0]*GreatestDiameter[0] + repetition[1]*GreatestDiameter[1] + repetition[2]*GreatestDiameter[2]);
|
|---|
| 667 | BoxLengths.x[1] = (repetition[0]*repetition[1]*GreatestDiameter[0]*GreatestDiameter[1]
|
|---|
| 668 | + repetition[0]*repetition[2]*GreatestDiameter[0]*GreatestDiameter[2]
|
|---|
| 669 | + repetition[1]*repetition[2]*GreatestDiameter[1]*GreatestDiameter[2]);
|
|---|
| 670 | BoxLengths.x[2] = minimumvolume - cellvolume;
|
|---|
| 671 | double x0 = 0.,x1 = 0.,x2 = 0.;
|
|---|
| 672 | if (gsl_poly_solve_cubic(BoxLengths.x[0],BoxLengths.x[1],BoxLengths.x[2],&x0,&x1,&x2) == 1) // either 1 or 3 on return
|
|---|
| 673 | *out << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl;
|
|---|
| 674 | else {
|
|---|
| 675 | *out << Verbose(0) << "RESULT: The resulting spacings are: " << x0 << " and " << x1 << " and " << x2 << " ." << endl;
|
|---|
| 676 | x0 = x2; // sorted in ascending order
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | cellvolume = 1;
|
|---|
| 680 | for(int i=0;i<NDIM;i++) {
|
|---|
| 681 | BoxLengths.x[i] = repetition[i] * (x0 + GreatestDiameter[i]);
|
|---|
| 682 | cellvolume *= BoxLengths.x[i];
|
|---|
| 683 | }
|
|---|
| 684 |
|
|---|
| 685 | // set new box dimensions
|
|---|
| 686 | *out << Verbose(0) << "Translating to box with these boundaries." << endl;
|
|---|
| 687 | mol->CenterInBox((ofstream *)&cout, &BoxLengths);
|
|---|
| 688 | }
|
|---|
| 689 | // update Box of atoms by boundary
|
|---|
| 690 | mol->SetBoxDimension(&BoxLengths);
|
|---|
| 691 | *out << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths.x[0] << " and " << BoxLengths.x[1] << " and " << BoxLengths.x[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
|
|---|
| 692 | };
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 | // =========================================================== class TESSELATION ===========================================
|
|---|
| 696 |
|
|---|
| 697 | /** Constructor of class Tesselation.
|
|---|
| 698 | */
|
|---|
| 699 | Tesselation::Tesselation()
|
|---|
| 700 | {
|
|---|
| 701 | PointsOnBoundaryCount = 0;
|
|---|
| 702 | LinesOnBoundaryCount = 0;
|
|---|
| 703 | TrianglesOnBoundaryCount = 0;
|
|---|
| 704 | };
|
|---|
| 705 |
|
|---|
| 706 | /** Constructor of class Tesselation.
|
|---|
| 707 | * We have to free all points, lines and triangles.
|
|---|
| 708 | */
|
|---|
| 709 | Tesselation::~Tesselation()
|
|---|
| 710 | {
|
|---|
| 711 | cout << Verbose(1) << "Free'ing TesselStruct ... " << endl;
|
|---|
| 712 | for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
|
|---|
| 713 | delete(runner->second);
|
|---|
| 714 | }
|
|---|
| 715 | };
|
|---|
| 716 |
|
|---|
| 717 | /** Gueses first starting triangle of the convex envelope.
|
|---|
| 718 | * We guess the starting triangle by taking the smallest distance between two points and looking for a fitting third.
|
|---|
| 719 | * \param *out output stream for debugging
|
|---|
| 720 | * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
|
|---|
| 721 | */
|
|---|
| 722 | void Tesselation::GuessStartingTriangle(ofstream *out)
|
|---|
| 723 | {
|
|---|
| 724 | // 4b. create a starting triangle
|
|---|
| 725 | // 4b1. create all distances
|
|---|
| 726 | DistanceMultiMap DistanceMMap;
|
|---|
| 727 | double distance, tmp;
|
|---|
| 728 | Vector PlaneVector, TrialVector;
|
|---|
| 729 | PointMap::iterator A, B, C; // three nodes of the first triangle
|
|---|
| 730 | A = PointsOnBoundary.begin(); // the first may be chosen arbitrarily
|
|---|
| 731 |
|
|---|
| 732 | // with A chosen, take each pair B,C and sort
|
|---|
| 733 | if (A != PointsOnBoundary.end()) {
|
|---|
| 734 | B = A;
|
|---|
| 735 | B++;
|
|---|
| 736 | for (; B != PointsOnBoundary.end(); B++) {
|
|---|
| 737 | C = B;
|
|---|
| 738 | C++;
|
|---|
| 739 | for (; C != PointsOnBoundary.end(); C++) {
|
|---|
| 740 | tmp = A->second->node->x.Distance(&B->second->node->x);
|
|---|
| 741 | distance = tmp*tmp;
|
|---|
| 742 | tmp = A->second->node->x.Distance(&C->second->node->x);
|
|---|
| 743 | distance += tmp*tmp;
|
|---|
| 744 | tmp = B->second->node->x.Distance(&C->second->node->x);
|
|---|
| 745 | distance += tmp*tmp;
|
|---|
| 746 | DistanceMMap.insert( DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator>(B,C) ) );
|
|---|
| 747 | }
|
|---|
| 748 | }
|
|---|
| 749 | }
|
|---|
| 750 | // // listing distances
|
|---|
| 751 | // *out << Verbose(1) << "Listing DistanceMMap:";
|
|---|
| 752 | // for(DistanceMultiMap::iterator runner = DistanceMMap.begin(); runner != DistanceMMap.end(); runner++) {
|
|---|
| 753 | // *out << " " << runner->first << "(" << *runner->second.first->second << ", " << *runner->second.second->second << ")";
|
|---|
| 754 | // }
|
|---|
| 755 | // *out << endl;
|
|---|
| 756 |
|
|---|
| 757 | // 4b2. pick three baselines forming a triangle
|
|---|
| 758 | // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
|---|
| 759 | DistanceMultiMap::iterator baseline = DistanceMMap.begin();
|
|---|
| 760 | for (; baseline != DistanceMMap.end(); baseline++) {
|
|---|
| 761 | // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
|
|---|
| 762 | // 2. next, we have to check whether all points reside on only one side of the triangle
|
|---|
| 763 | // 3. construct plane vector
|
|---|
| 764 | PlaneVector.MakeNormalVector(&A->second->node->x, &baseline->second.first->second->node->x, &baseline->second.second->second->node->x);
|
|---|
| 765 | *out << Verbose(2) << "Plane vector of candidate triangle is ";
|
|---|
| 766 | PlaneVector.Output(out);
|
|---|
| 767 | *out << endl;
|
|---|
| 768 | // 4. loop over all points
|
|---|
| 769 | double sign = 0.;
|
|---|
| 770 | PointMap::iterator checker = PointsOnBoundary.begin();
|
|---|
| 771 | for (; checker != PointsOnBoundary.end(); checker++) {
|
|---|
| 772 | // (neglecting A,B,C)
|
|---|
| 773 | if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
|
|---|
| 774 | continue;
|
|---|
| 775 | // 4a. project onto plane vector
|
|---|
| 776 | TrialVector.CopyVector(&checker->second->node->x);
|
|---|
| 777 | TrialVector.SubtractVector(&A->second->node->x);
|
|---|
| 778 | distance = TrialVector.Projection(&PlaneVector);
|
|---|
| 779 | if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
|
|---|
| 780 | continue;
|
|---|
| 781 | *out << Verbose(3) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl;
|
|---|
| 782 | tmp = distance/fabs(distance);
|
|---|
| 783 | // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
|
|---|
| 784 | if ((sign != 0) && (tmp != sign)) {
|
|---|
| 785 | // 4c. If so, break 4. loop and continue with next candidate in 1. loop
|
|---|
| 786 | *out << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leave " << checker->second->node->Name << " outside the convex hull." << endl;
|
|---|
| 787 | break;
|
|---|
| 788 | } else { // note the sign for later
|
|---|
| 789 | *out << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leave " << checker->second->node->Name << " inside the convex hull." << endl;
|
|---|
| 790 | sign = tmp;
|
|---|
| 791 | }
|
|---|
| 792 | // 4d. Check whether the point is inside the triangle (check distance to each node
|
|---|
| 793 | tmp = checker->second->node->x.Distance(&A->second->node->x);
|
|---|
| 794 | int innerpoint = 0;
|
|---|
| 795 | if ((tmp < A->second->node->x.Distance(&baseline->second.first->second->node->x))
|
|---|
| 796 | && (tmp < A->second->node->x.Distance(&baseline->second.second->second->node->x)))
|
|---|
| 797 | innerpoint++;
|
|---|
| 798 | tmp = checker->second->node->x.Distance(&baseline->second.first->second->node->x);
|
|---|
| 799 | if ((tmp < baseline->second.first->second->node->x.Distance(&A->second->node->x))
|
|---|
| 800 | && (tmp < baseline->second.first->second->node->x.Distance(&baseline->second.second->second->node->x)))
|
|---|
| 801 | innerpoint++;
|
|---|
| 802 | tmp = checker->second->node->x.Distance(&baseline->second.second->second->node->x);
|
|---|
| 803 | if ((tmp < baseline->second.second->second->node->x.Distance(&baseline->second.first->second->node->x))
|
|---|
| 804 | && (tmp < baseline->second.second->second->node->x.Distance(&A->second->node->x)))
|
|---|
| 805 | innerpoint++;
|
|---|
| 806 | // 4e. If so, break 4. loop and continue with next candidate in 1. loop
|
|---|
| 807 | if (innerpoint == 3)
|
|---|
| 808 | break;
|
|---|
| 809 | }
|
|---|
| 810 | // 5. come this far, all on same side? Then break 1. loop and construct triangle
|
|---|
| 811 | if (checker == PointsOnBoundary.end()) {
|
|---|
| 812 | *out << "Looks like we have a candidate!" << endl;
|
|---|
| 813 | break;
|
|---|
| 814 | }
|
|---|
| 815 | }
|
|---|
| 816 | if (baseline != DistanceMMap.end()) {
|
|---|
| 817 | BPS[0] = baseline->second.first->second;
|
|---|
| 818 | BPS[1] = baseline->second.second->second;
|
|---|
| 819 | BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 820 | BPS[0] = A->second;
|
|---|
| 821 | BPS[1] = baseline->second.second->second;
|
|---|
| 822 | BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 823 | BPS[0] = baseline->second.first->second;
|
|---|
| 824 | BPS[1] = A->second;
|
|---|
| 825 | BLS[2] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 826 |
|
|---|
| 827 | // 4b3. insert created triangle
|
|---|
| 828 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
|---|
| 829 | TrianglesOnBoundary.insert( TrianglePair(TrianglesOnBoundaryCount, BTS) );
|
|---|
| 830 | TrianglesOnBoundaryCount++;
|
|---|
| 831 | for(int i=0;i<NDIM;i++) {
|
|---|
| 832 | LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BTS->lines[i]) );
|
|---|
| 833 | LinesOnBoundaryCount++;
|
|---|
| 834 | }
|
|---|
| 835 |
|
|---|
| 836 | *out << Verbose(1) << "Starting triangle is " << *BTS << "." << endl;
|
|---|
| 837 | } else {
|
|---|
| 838 | *out << Verbose(1) << "No starting triangle found." << endl;
|
|---|
| 839 | exit(255);
|
|---|
| 840 | }
|
|---|
| 841 | };
|
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 | /** Tesselates the convex envelope of a cluster from a single starting triangle.
|
|---|
| 845 | * The starting triangle is made out of three baselines. Each line in the final tesselated cluster may belong to at most
|
|---|
| 846 | * 2 triangles. Hence, we go through all current lines:
|
|---|
| 847 | * -# if the lines contains to only one triangle
|
|---|
| 848 | * -# We search all points in the boundary
|
|---|
| 849 | * -# if the triangle with the baseline and the current point has the smallest of angles (comparison between normal vectors
|
|---|
| 850 | * -# if the triangle is in forward direction of the baseline (at most 90 degrees angle between vector orthogonal to
|
|---|
| 851 | * baseline in triangle plane pointing out of the triangle and normal vector of new triangle)
|
|---|
| 852 | * -# then we have a new triangle, whose baselines we again add (or increase their TriangleCount)
|
|---|
| 853 | * \param *out output stream for debugging
|
|---|
| 854 | * \param *configuration for IsAngstroem
|
|---|
| 855 | * \param *mol the cluster as a molecule structure
|
|---|
| 856 | */
|
|---|
| 857 | void Tesselation::TesselateOnBoundary(ofstream *out, config *configuration, molecule *mol)
|
|---|
| 858 | {
|
|---|
| 859 | bool flag;
|
|---|
| 860 | PointMap::iterator winner;
|
|---|
| 861 | class BoundaryPointSet *peak = NULL;
|
|---|
| 862 | double SmallestAngle, TempAngle;
|
|---|
| 863 | Vector NormalVector, VirtualNormalVector, CenterVector, TempVector, PropagationVector;
|
|---|
| 864 | LineMap::iterator LineChecker[2];
|
|---|
| 865 | do {
|
|---|
| 866 | flag = false;
|
|---|
| 867 | for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++)
|
|---|
| 868 | if (baseline->second->TrianglesCount == 1) {
|
|---|
| 869 | *out << Verbose(2) << "Current baseline is between " << *(baseline->second) << "." << endl;
|
|---|
| 870 | // 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)
|
|---|
| 871 | SmallestAngle = M_PI;
|
|---|
| 872 | BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
|
|---|
| 873 | // get peak point with respect to this base line's only triangle
|
|---|
| 874 | for(int i=0;i<3;i++)
|
|---|
| 875 | if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
|
|---|
| 876 | peak = BTS->endpoints[i];
|
|---|
| 877 | *out << Verbose(3) << " and has peak " << *peak << "." << endl;
|
|---|
| 878 | // normal vector of triangle
|
|---|
| 879 | BTS->GetNormalVector(NormalVector);
|
|---|
| 880 | *out << Verbose(4) << "NormalVector of base triangle is ";
|
|---|
| 881 | NormalVector.Output(out);
|
|---|
| 882 | *out << endl;
|
|---|
| 883 | // offset to center of triangle
|
|---|
| 884 | CenterVector.Zero();
|
|---|
| 885 | for(int i=0;i<3;i++)
|
|---|
| 886 | CenterVector.AddVector(&BTS->endpoints[i]->node->x);
|
|---|
| 887 | CenterVector.Scale(1./3.);
|
|---|
| 888 | *out << Verbose(4) << "CenterVector of base triangle is ";
|
|---|
| 889 | CenterVector.Output(out);
|
|---|
| 890 | *out << endl;
|
|---|
| 891 | // vector in propagation direction (out of triangle)
|
|---|
| 892 | // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
|
|---|
| 893 | TempVector.CopyVector(&baseline->second->endpoints[0]->node->x);
|
|---|
| 894 | TempVector.SubtractVector(&baseline->second->endpoints[1]->node->x);
|
|---|
| 895 | PropagationVector.MakeNormalVector(&TempVector, &NormalVector);
|
|---|
| 896 | TempVector.CopyVector(&CenterVector);
|
|---|
| 897 | TempVector.SubtractVector(&baseline->second->endpoints[0]->node->x); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
|
|---|
| 898 | //*out << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
|
|---|
| 899 | if (PropagationVector.Projection(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
|
|---|
| 900 | PropagationVector.Scale(-1.);
|
|---|
| 901 | *out << Verbose(4) << "PropagationVector of base triangle is ";
|
|---|
| 902 | PropagationVector.Output(out);
|
|---|
| 903 | *out << endl;
|
|---|
| 904 | winner = PointsOnBoundary.end();
|
|---|
| 905 | for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++)
|
|---|
| 906 | if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
|
|---|
| 907 | *out << Verbose(3) << "Target point is " << *(target->second) << ":";
|
|---|
| 908 | bool continueflag = true;
|
|---|
| 909 |
|
|---|
| 910 | VirtualNormalVector.CopyVector(&baseline->second->endpoints[0]->node->x);
|
|---|
| 911 | VirtualNormalVector.AddVector(&baseline->second->endpoints[0]->node->x);
|
|---|
| 912 | VirtualNormalVector.Scale(-1./2.); // points now to center of base line
|
|---|
| 913 | VirtualNormalVector.AddVector(&target->second->node->x); // points from center of base line to target
|
|---|
| 914 | TempAngle = VirtualNormalVector.Angle(&PropagationVector);
|
|---|
| 915 | continueflag = continueflag && (TempAngle < (M_PI/2.)); // no bends bigger than Pi/2 (90 degrees)
|
|---|
| 916 | if (!continueflag) {
|
|---|
| 917 | *out << Verbose(4) << "Angle between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
|
|---|
| 918 | continue;
|
|---|
| 919 | } else
|
|---|
| 920 | *out << Verbose(4) << "Angle between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
|
|---|
| 921 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(target->first);
|
|---|
| 922 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
|
|---|
| 923 | // if (LineChecker[0] != baseline->second->endpoints[0]->lines.end())
|
|---|
| 924 | // *out << Verbose(4) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->TrianglesCount << " triangles." << endl;
|
|---|
| 925 | // else
|
|---|
| 926 | // *out << Verbose(4) << *(baseline->second->endpoints[0]) << " has no line to " << *(target->second) << " as endpoint." << endl;
|
|---|
| 927 | // if (LineChecker[1] != baseline->second->endpoints[1]->lines.end())
|
|---|
| 928 | // *out << Verbose(4) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->TrianglesCount << " triangles." << endl;
|
|---|
| 929 | // else
|
|---|
| 930 | // *out << Verbose(4) << *(baseline->second->endpoints[1]) << " has no line to " << *(target->second) << " as endpoint." << endl;
|
|---|
| 931 | // check first endpoint (if any connecting line goes to target or at least not more than 1)
|
|---|
| 932 | continueflag = continueflag && (( (LineChecker[0] == baseline->second->endpoints[0]->lines.end()) || (LineChecker[0]->second->TrianglesCount == 1)));
|
|---|
| 933 | if (!continueflag) {
|
|---|
| 934 | *out << Verbose(4) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->TrianglesCount << " triangles." << endl;
|
|---|
| 935 | continue;
|
|---|
| 936 | }
|
|---|
| 937 | // check second endpoint (if any connecting line goes to target or at least not more than 1)
|
|---|
| 938 | continueflag = continueflag && (( (LineChecker[1] == baseline->second->endpoints[1]->lines.end()) || (LineChecker[1]->second->TrianglesCount == 1)));
|
|---|
| 939 | if (!continueflag) {
|
|---|
| 940 | *out << Verbose(4) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->TrianglesCount << " triangles." << endl;
|
|---|
| 941 | continue;
|
|---|
| 942 | }
|
|---|
| 943 | // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
|
|---|
| 944 | continueflag = continueflag && (!(
|
|---|
| 945 | ((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[1] != baseline->second->endpoints[1]->lines.end())
|
|---|
| 946 | && (GetCommonEndpoint(LineChecker[0]->second, LineChecker[1]->second) == peak))
|
|---|
| 947 | ));
|
|---|
| 948 | if (!continueflag) {
|
|---|
| 949 | *out << Verbose(4) << "Current target is peak!" << endl;
|
|---|
| 950 | continue;
|
|---|
| 951 | }
|
|---|
| 952 | // in case NOT both were found
|
|---|
| 953 | if (continueflag) { // create virtually this triangle, get its normal vector, calculate angle
|
|---|
| 954 | flag = true;
|
|---|
| 955 | VirtualNormalVector.MakeNormalVector(&baseline->second->endpoints[0]->node->x, &baseline->second->endpoints[1]->node->x, &target->second->node->x);
|
|---|
| 956 | // make it always point inward
|
|---|
| 957 | if (baseline->second->endpoints[0]->node->x.Projection(&VirtualNormalVector) > 0)
|
|---|
| 958 | VirtualNormalVector.Scale(-1.);
|
|---|
| 959 | // calculate angle
|
|---|
| 960 | TempAngle = NormalVector.Angle(&VirtualNormalVector);
|
|---|
| 961 | *out << Verbose(4) << "NormalVector is ";
|
|---|
| 962 | VirtualNormalVector.Output(out);
|
|---|
| 963 | *out << " and the angle is " << TempAngle << "." << endl;
|
|---|
| 964 | if (SmallestAngle > TempAngle) { // set to new possible winner
|
|---|
| 965 | SmallestAngle = TempAngle;
|
|---|
| 966 | winner = target;
|
|---|
| 967 | }
|
|---|
| 968 | }
|
|---|
| 969 | }
|
|---|
| 970 | // 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
|
|---|
| 971 | if (winner != PointsOnBoundary.end()) {
|
|---|
| 972 | *out << Verbose(2) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
|
|---|
| 973 | // create the lins of not yet present
|
|---|
| 974 | BLS[0] = baseline->second;
|
|---|
| 975 | // 5c. add lines to the line set if those were new (not yet part of a triangle), delete lines that belong to two triangles)
|
|---|
| 976 | LineChecker[0] = baseline->second->endpoints[0]->lines.find(winner->first);
|
|---|
| 977 | LineChecker[1] = baseline->second->endpoints[1]->lines.find(winner->first);
|
|---|
| 978 | if (LineChecker[0] == baseline->second->endpoints[0]->lines.end()) { // create
|
|---|
| 979 | BPS[0] = baseline->second->endpoints[0];
|
|---|
| 980 | BPS[1] = winner->second;
|
|---|
| 981 | BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 982 | LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BLS[1]) );
|
|---|
| 983 | LinesOnBoundaryCount++;
|
|---|
| 984 | } else
|
|---|
| 985 | BLS[1] = LineChecker[0]->second;
|
|---|
| 986 | if (LineChecker[1] == baseline->second->endpoints[1]->lines.end()) { // create
|
|---|
| 987 | BPS[0] = baseline->second->endpoints[1];
|
|---|
| 988 | BPS[1] = winner->second;
|
|---|
| 989 | BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
|
|---|
| 990 | LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BLS[2]) );
|
|---|
| 991 | LinesOnBoundaryCount++;
|
|---|
| 992 | } else
|
|---|
| 993 | BLS[2] = LineChecker[1]->second;
|
|---|
| 994 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
|---|
| 995 | TrianglesOnBoundary.insert( TrianglePair(TrianglesOnBoundaryCount, BTS) );
|
|---|
| 996 | TrianglesOnBoundaryCount++;
|
|---|
| 997 | } else {
|
|---|
| 998 | *out << Verbose(1) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | // 5d. If the set of lines is not yet empty, go to 5. and continue
|
|---|
| 1002 | } else
|
|---|
| 1003 | *out << Verbose(2) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->TrianglesCount << "." << endl;
|
|---|
| 1004 | } while (flag);
|
|---|
| 1005 |
|
|---|
| 1006 | };
|
|---|
| 1007 |
|
|---|
| 1008 | /** Adds an atom to the tesselation::PointsOnBoundary list.
|
|---|
| 1009 | * \param *Walker atom to add
|
|---|
| 1010 | */
|
|---|
| 1011 | void Tesselation::AddPoint(atom *Walker)
|
|---|
| 1012 | {
|
|---|
| 1013 | PointTestPair InsertUnique;
|
|---|
| 1014 | BPS[0] = new class BoundaryPointSet(Walker);
|
|---|
| 1015 | InsertUnique = PointsOnBoundary.insert( PointPair(Walker->nr, BPS[0]) );
|
|---|
| 1016 | if (InsertUnique.second) // if new point was not present before, increase counter
|
|---|
| 1017 | PointsOnBoundaryCount++;
|
|---|
| 1018 | };
|
|---|
| 1019 |
|
|---|
| 1020 |
|
|---|
| 1021 |
|
|---|
| 1022 |
|
|---|
| 1023 |
|
|---|
| 1024 |
|
|---|
| 1025 | //====================================================================================================================
|
|---|
| 1026 | //
|
|---|
| 1027 | // ab hier habe ich das verzapft.
|
|---|
| 1028 | //
|
|---|
| 1029 | //====================================================================================================================
|
|---|
| 1030 |
|
|---|
| 1031 | /*!
|
|---|
| 1032 | * This recursive function finds a third point, to form a triangle with two given ones.
|
|---|
| 1033 | * Two atoms are fixed, a candidate is supplied, additionally two vectors for direction distinction, a Storage area to \
|
|---|
| 1034 | * supply results to the calling function, the radius of the sphere which the triangle shall support and the molecule \
|
|---|
| 1035 | * upon which we operate.
|
|---|
| 1036 | * If the candidate is more fitting to support the sphere than the already stored atom is, then we write its id, its general \
|
|---|
| 1037 | * direction and angle into Storage.
|
|---|
| 1038 | * We the determine the recursive level we have reached and if this is not on the threshold yet, call this function again, \
|
|---|
| 1039 | * with all neighbours of the candidate.
|
|---|
| 1040 | */
|
|---|
| 1041 | void Find_next_suitable_point(atom* a, atom* b, atom* Candidate, int n, Vector *Chord, Vector *d1, Vector *d2, atom*& Opt_Candidate, double *Storage, const double RADIUS, molecule* mol, bool problem)
|
|---|
| 1042 | {
|
|---|
| 1043 | /* d2 is normal vector on the triangle
|
|---|
| 1044 | * d1 is normal on the triangle line, from which we come, as well as on d2.
|
|---|
| 1045 | */
|
|---|
| 1046 | Vector dif_a; //Vector from a to candidate
|
|---|
| 1047 | Vector dif_b; //Vector from b to candidate
|
|---|
| 1048 | Vector AngleCheck; // Projection of a difference vector on plane orthogonal on triangle side.
|
|---|
| 1049 | atom *Walker; // variable atom point
|
|---|
| 1050 |
|
|---|
| 1051 | dif_a.CopyVector(&(a->x));
|
|---|
| 1052 | dif_a.SubtractVector(&(Candidate->x));
|
|---|
| 1053 | dif_b.CopyVector(&(b->x));
|
|---|
| 1054 | dif_b.SubtractVector(&(Candidate->x));
|
|---|
| 1055 | AngleCheck.CopyVector(&dif_a);
|
|---|
| 1056 | AngleCheck.ProjectOntoPlane(Chord);
|
|---|
| 1057 |
|
|---|
| 1058 | if (problem)
|
|---|
| 1059 | {
|
|---|
| 1060 | cout << "Atom number" << Candidate->nr << endl;
|
|---|
| 1061 | Candidate->x.Output((ofstream *)&cout);
|
|---|
| 1062 | cout << "number of bonds " << mol->NumberOfBondsPerAtom[Candidate->nr] << endl;
|
|---|
| 1063 | }
|
|---|
| 1064 |
|
|---|
| 1065 | if (a != Candidate and b != Candidate)
|
|---|
| 1066 | {
|
|---|
| 1067 |
|
|---|
| 1068 | if (Chord->Norm()/(2*sin(dif_a.Angle(&dif_b)))<RADIUS) //Using Formula for relation of chord length with inner angle to find of Ball will touch atom
|
|---|
| 1069 | {
|
|---|
| 1070 | if (dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1))>Storage[0]) //This will give absolute preference to those in "right-hand" quadrants
|
|---|
| 1071 | {
|
|---|
| 1072 | Opt_Candidate = Candidate;
|
|---|
| 1073 | Storage[0]=dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1));
|
|---|
| 1074 | Storage[1]=AngleCheck.Angle(d2);
|
|---|
| 1075 | }
|
|---|
| 1076 | else
|
|---|
| 1077 | {
|
|---|
| 1078 | if ((dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1)) == Storage[0] && Storage[0]>0 && Storage[1]< AngleCheck.Angle(d2)) or \
|
|---|
| 1079 | (dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1)) == Storage[0] && Storage[0]<0 && Storage[1]> AngleCheck.Angle(d2)))
|
|---|
| 1080 | //Depending on quadrant we prefer higher or lower atom with respect to Triangle normal first.
|
|---|
| 1081 | {
|
|---|
| 1082 | Opt_Candidate = Candidate;
|
|---|
| 1083 | Storage[0]=dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1));
|
|---|
| 1084 | Storage[1]=AngleCheck.Angle(d2);
|
|---|
| 1085 | }
|
|---|
| 1086 | else
|
|---|
| 1087 | {
|
|---|
| 1088 | if (problem)
|
|---|
| 1089 | cout << "Loses to better candidate" << endl;
|
|---|
| 1090 | }
|
|---|
| 1091 | }
|
|---|
| 1092 | }
|
|---|
| 1093 | else
|
|---|
| 1094 | {
|
|---|
| 1095 | if (problem)
|
|---|
| 1096 | cout << "erfuellt Dreiecksbedingung fuer sehne nicht" <<endl;
|
|---|
| 1097 | }
|
|---|
| 1098 | }
|
|---|
| 1099 | else
|
|---|
| 1100 | {
|
|---|
| 1101 | if (problem)
|
|---|
| 1102 | cout << "identisch mit Ursprungslinie" << endl;
|
|---|
| 1103 | }
|
|---|
| 1104 |
|
|---|
| 1105 | if (n<5) // Five is the recursion level threshold.
|
|---|
| 1106 | {
|
|---|
| 1107 | for(int i=0; i<mol->NumberOfBondsPerAtom[Candidate->nr];i++) // go through all bond
|
|---|
| 1108 | {
|
|---|
| 1109 | Walker = mol->ListOfBondsPerAtom[Candidate->nr][i]->GetOtherAtom(Candidate);
|
|---|
| 1110 |
|
|---|
| 1111 | Find_next_suitable_point(a, b, Walker, n+1, Chord, d1, d2, Opt_Candidate, Storage, RADIUS, mol, problem); //call function again
|
|---|
| 1112 | }
|
|---|
| 1113 | }
|
|---|
| 1114 | };
|
|---|
| 1115 |
|
|---|
| 1116 | /*!
|
|---|
| 1117 | * this function fins a triangle to a line, adjacent to an existing one.
|
|---|
| 1118 | */
|
|---|
| 1119 | void Tesselation::Find_next_suitable_triangle(ofstream *out, ofstream *tecplot, molecule* mol, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS)
|
|---|
| 1120 | {
|
|---|
| 1121 | cout << Verbose(1) << "Looking for next suitable triangle \n";
|
|---|
| 1122 | Vector direction1;
|
|---|
| 1123 | Vector helper;
|
|---|
| 1124 | Vector Chord;
|
|---|
| 1125 | atom* Walker;
|
|---|
| 1126 |
|
|---|
| 1127 | double Storage[2];
|
|---|
| 1128 | Storage[0]=-2.; // This direction is either +1 or -1 one, so any result will take precedence over initial values
|
|---|
| 1129 | Storage[1]=9999999.; // This is also lower then any value produced by an eligible atom, which are all positive
|
|---|
| 1130 | atom* Opt_Candidate = NULL;
|
|---|
| 1131 |
|
|---|
| 1132 |
|
|---|
| 1133 | cout << Verbose(1) << "Constructing helpful vectors ... " << endl;
|
|---|
| 1134 | helper.CopyVector(&(Line.endpoints[0]->node->x));
|
|---|
| 1135 | for (int i =0; i<3; i++)
|
|---|
| 1136 | {
|
|---|
| 1137 | if (T.endpoints[i]->node->nr != Line.endpoints[0]->node->nr && T.endpoints[i]->node->nr!=Line.endpoints[1]->node->nr)
|
|---|
| 1138 | {
|
|---|
| 1139 | helper.SubtractVector(&T.endpoints[i]->node->x);
|
|---|
| 1140 | break;
|
|---|
| 1141 | }
|
|---|
| 1142 | }
|
|---|
| 1143 |
|
|---|
| 1144 |
|
|---|
| 1145 | direction1.CopyVector(&Line.endpoints[0]->node->x);
|
|---|
| 1146 | direction1.SubtractVector(&Line.endpoints[1]->node->x);
|
|---|
| 1147 | direction1.VectorProduct(&(T.NormalVector));
|
|---|
| 1148 |
|
|---|
| 1149 | if (direction1.ScalarProduct(&helper)>0)
|
|---|
| 1150 | {
|
|---|
| 1151 | direction1.Scale(-1);
|
|---|
| 1152 | }
|
|---|
| 1153 |
|
|---|
| 1154 | Chord.CopyVector(&(Line.endpoints[0]->node->x)); // bring into calling function
|
|---|
| 1155 | Chord.SubtractVector(&(Line.endpoints[1]->node->x));
|
|---|
| 1156 |
|
|---|
| 1157 | cout << Verbose(1) << "Looking for third point candidates for triangle ... " << endl;
|
|---|
| 1158 | Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1, &(T.NormalVector), Opt_Candidate, Storage, RADIUS, mol,0);
|
|---|
| 1159 |
|
|---|
| 1160 | if (Opt_Candidate==NULL)
|
|---|
| 1161 | {
|
|---|
| 1162 | cout << Verbose(1) << "No new Atom found, triangle construction will crash" << endl;
|
|---|
| 1163 | write_tecplot_file(out, tecplot, this, mol);
|
|---|
| 1164 | tecplot->flush();
|
|---|
| 1165 | Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1, &(T.NormalVector), Opt_Candidate, Storage, RADIUS, mol, 1);
|
|---|
| 1166 |
|
|---|
| 1167 | }
|
|---|
| 1168 | // Konstruiere nun neues Dreieck am Ende der Liste der Dreiecke
|
|---|
| 1169 |
|
|---|
| 1170 | cout << Verbose(1) << "Adding exactly one Walker for reasons completely unknown to me ... " << endl;
|
|---|
| 1171 | cout << " Optimal candidate is " << *Opt_Candidate << endl;
|
|---|
| 1172 | AddPoint(Opt_Candidate);
|
|---|
| 1173 | cout << " Optimal candidate is " << *Opt_Candidate << endl;
|
|---|
| 1174 |
|
|---|
| 1175 | BPS[0] = new class BoundaryPointSet(Opt_Candidate);
|
|---|
| 1176 | cout << " Optimal candidate is " << *Opt_Candidate << endl;
|
|---|
| 1177 | BPS[1] = new class BoundaryPointSet(Line.endpoints[0]->node);
|
|---|
| 1178 | cout << " Optimal candidate is " << *Opt_Candidate << endl;
|
|---|
| 1179 | BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 1180 | cout << " Optimal candidate is " << *Opt_Candidate << endl;
|
|---|
| 1181 | BPS[0] = new class BoundaryPointSet(Opt_Candidate);
|
|---|
| 1182 | cout << " Optimal candidate is " << *Opt_Candidate << endl;
|
|---|
| 1183 | BPS[1] = new class BoundaryPointSet(Line.endpoints[1]->node);
|
|---|
| 1184 | BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 1185 | BLS[2] = new class BoundaryLineSet(Line);
|
|---|
| 1186 |
|
|---|
| 1187 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
|---|
| 1188 | TrianglesOnBoundary.insert( TrianglePair(TrianglesOnBoundaryCount, BTS) );
|
|---|
| 1189 | TrianglesOnBoundaryCount++;
|
|---|
| 1190 |
|
|---|
| 1191 | cout << Verbose(1) << "Checking for already present lines ... " << endl;
|
|---|
| 1192 | for(int i=0;i<NDIM;i++) // sind Linien bereits vorhanden ???
|
|---|
| 1193 | {
|
|---|
| 1194 |
|
|---|
| 1195 |
|
|---|
| 1196 | if ( (LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BTS->lines[i]))).second);
|
|---|
| 1197 | {
|
|---|
| 1198 | LinesOnBoundaryCount++;
|
|---|
| 1199 | }
|
|---|
| 1200 | }
|
|---|
| 1201 | cout << Verbose(1) << "Constructing normal vector for this triangle ... " << endl;
|
|---|
| 1202 |
|
|---|
| 1203 | BTS->GetNormalVector(BTS->NormalVector);
|
|---|
| 1204 |
|
|---|
| 1205 | if ((BTS->NormalVector.ScalarProduct(&(T.NormalVector))<0 && Storage[0]>0) ||
|
|---|
| 1206 | ((BTS->NormalVector.ScalarProduct(&(T.NormalVector))>0 && Storage[0]<0)) )
|
|---|
| 1207 | {
|
|---|
| 1208 | BTS->NormalVector.Scale(-1);
|
|---|
| 1209 | };
|
|---|
| 1210 |
|
|---|
| 1211 | };
|
|---|
| 1212 |
|
|---|
| 1213 |
|
|---|
| 1214 | void Find_second_point_for_Tesselation(atom* a, atom* Candidate, int n, Vector Oben, atom*& Opt_Candidate, double Storage[2], molecule* mol, double RADIUS)
|
|---|
| 1215 | {
|
|---|
| 1216 | cout << Verbose(1) << "Looking for second point of starting triangle, recursive level "<< n <<endl;;
|
|---|
| 1217 | int i;
|
|---|
| 1218 | Vector AngleCheck;
|
|---|
| 1219 | atom* Walker;
|
|---|
| 1220 |
|
|---|
| 1221 | AngleCheck.CopyVector(&(Candidate->x));
|
|---|
| 1222 | AngleCheck.SubtractVector(&(a->x));
|
|---|
| 1223 | if (AngleCheck.Norm() < RADIUS and AngleCheck.Angle(&Oben) < Storage[0])
|
|---|
| 1224 | {
|
|---|
| 1225 | //cout << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
|
|---|
| 1226 | Opt_Candidate=Candidate;
|
|---|
| 1227 | Storage[0]=AngleCheck.Angle(&Oben);
|
|---|
| 1228 | //cout << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[1]);
|
|---|
| 1229 | };
|
|---|
| 1230 | if (n<5)
|
|---|
| 1231 | {
|
|---|
| 1232 | for (i = 0; i< mol->NumberOfBondsPerAtom[Candidate->nr]; i++)
|
|---|
| 1233 | {
|
|---|
| 1234 | Walker = mol->ListOfBondsPerAtom[Candidate->nr][i]->GetOtherAtom(Candidate);
|
|---|
| 1235 | Find_second_point_for_Tesselation(a, Walker, n+1, Oben, Opt_Candidate, Storage, mol, RADIUS);
|
|---|
| 1236 | };
|
|---|
| 1237 | };
|
|---|
| 1238 |
|
|---|
| 1239 |
|
|---|
| 1240 | };
|
|---|
| 1241 |
|
|---|
| 1242 |
|
|---|
| 1243 | void Tesselation::Find_starting_triangle(molecule* mol, const double RADIUS)
|
|---|
| 1244 | {
|
|---|
| 1245 | cout << Verbose(1) << "Looking for starting triangle \n";
|
|---|
| 1246 | int i=0;
|
|---|
| 1247 | atom* Walker;
|
|---|
| 1248 | atom* Walker2;
|
|---|
| 1249 | atom* Walker3;
|
|---|
| 1250 | int max_index[3];
|
|---|
| 1251 | double max_coordinate[3];
|
|---|
| 1252 | Vector Oben;
|
|---|
| 1253 | Vector helper;
|
|---|
| 1254 | Vector Chord;
|
|---|
| 1255 |
|
|---|
| 1256 | Oben.Zero();
|
|---|
| 1257 |
|
|---|
| 1258 |
|
|---|
| 1259 | for(i =0; i<3; i++)
|
|---|
| 1260 | {
|
|---|
| 1261 | max_index[i] =-1;
|
|---|
| 1262 | max_coordinate[i] =-1;
|
|---|
| 1263 | }
|
|---|
| 1264 | cout << Verbose(1) << "Molecule mol is there and has " << mol->AtomCount << " Atoms \n";
|
|---|
| 1265 | Walker = mol->start;
|
|---|
| 1266 | while (Walker->next != mol->end)
|
|---|
| 1267 | {
|
|---|
| 1268 | Walker = Walker->next;
|
|---|
| 1269 | for (i=0; i<3; i++)
|
|---|
| 1270 | {
|
|---|
| 1271 | if (Walker->x.x[i] > max_coordinate[i])
|
|---|
| 1272 | {
|
|---|
| 1273 | max_coordinate[i]=Walker->x.x[i];
|
|---|
| 1274 | max_index[i]=Walker->nr;
|
|---|
| 1275 | }
|
|---|
| 1276 | }
|
|---|
| 1277 | }
|
|---|
| 1278 |
|
|---|
| 1279 | cout << Verbose(1) << "Found starting atom \n";
|
|---|
| 1280 | //Koennen dies fuer alle Richtungen, legen hier erstmal Richtung auf k=0
|
|---|
| 1281 | const int k=2;
|
|---|
| 1282 |
|
|---|
| 1283 | Oben.x[k]=1.;
|
|---|
| 1284 | Walker = mol->start;
|
|---|
| 1285 | Walker = Walker->next;
|
|---|
| 1286 | while (Walker->nr != max_index[k])
|
|---|
| 1287 | {
|
|---|
| 1288 | Walker = Walker->next;
|
|---|
| 1289 | }
|
|---|
| 1290 | cout << Verbose(1) << "Number of start atom: " << Walker->nr << endl;
|
|---|
| 1291 | double Storage[2];
|
|---|
| 1292 | atom* Opt_Candidate = NULL;
|
|---|
| 1293 | Storage[0]=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.
|
|---|
| 1294 | Storage[1]=999999.; // This will be an angle looking for the third point.
|
|---|
| 1295 | cout << Verbose(1) << "Number of Bonds: " << mol->NumberOfBondsPerAtom[Walker->nr] << endl;
|
|---|
| 1296 |
|
|---|
| 1297 | for (i=1; i< (mol->NumberOfBondsPerAtom[Walker->nr]); i++)
|
|---|
| 1298 | {
|
|---|
| 1299 | Walker2 = mol->ListOfBondsPerAtom[Walker->nr][i]->GetOtherAtom(Walker);
|
|---|
| 1300 | Find_second_point_for_Tesselation(Walker, Walker2, 0, Oben, Opt_Candidate, Storage, mol, RADIUS);
|
|---|
| 1301 | }
|
|---|
| 1302 |
|
|---|
| 1303 | Walker2 = Opt_Candidate;
|
|---|
| 1304 | Opt_Candidate=NULL;
|
|---|
| 1305 | helper.CopyVector(&(Walker->x));
|
|---|
| 1306 | helper.SubtractVector(&(Walker2->x));
|
|---|
| 1307 | Oben.ProjectOntoPlane(&helper);
|
|---|
| 1308 | helper.VectorProduct(&Oben);
|
|---|
| 1309 | Storage[0]=-2.; // This will indicate the quadrant.
|
|---|
| 1310 | Storage[1]= 9999999.; // This will be an angle looking for the third point.
|
|---|
| 1311 |
|
|---|
| 1312 | Chord.CopyVector(&(Walker->x)); // bring into calling function
|
|---|
| 1313 | Chord.SubtractVector(&(Walker2->x));
|
|---|
| 1314 |
|
|---|
| 1315 | cout << Verbose(1) << "Looking for third point candidates \n";
|
|---|
| 1316 | Find_next_suitable_point(Walker, Walker2, mol->ListOfBondsPerAtom[Walker->nr][0]->GetOtherAtom(Walker), 0, &Chord, &helper, &Oben, Opt_Candidate, Storage, RADIUS, mol, 0);
|
|---|
| 1317 |
|
|---|
| 1318 |
|
|---|
| 1319 | //Starting Triangle is Walker, Walker2, Opt_Candidate
|
|---|
| 1320 |
|
|---|
| 1321 | AddPoint(Walker);
|
|---|
| 1322 | AddPoint(Walker2);
|
|---|
| 1323 | AddPoint(Opt_Candidate);
|
|---|
| 1324 |
|
|---|
| 1325 | cout << Verbose(1) << "The found starting triangle consists of " << *Walker << ", " << *Walker2 << " and " << *Opt_Candidate << "." << endl;
|
|---|
| 1326 |
|
|---|
| 1327 | BPS[0] = new class BoundaryPointSet(Walker);
|
|---|
| 1328 | BPS[1] = new class BoundaryPointSet(Walker2);
|
|---|
| 1329 | BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 1330 | BPS[0] = new class BoundaryPointSet(Walker);
|
|---|
| 1331 | BPS[1] = new class BoundaryPointSet(Opt_Candidate);
|
|---|
| 1332 | BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 1333 | BPS[0] = new class BoundaryPointSet(Walker);
|
|---|
| 1334 | BPS[1] = new class BoundaryPointSet(Walker2);
|
|---|
| 1335 | BLS[2] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
|---|
| 1336 |
|
|---|
| 1337 | Tesselation::BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
|---|
| 1338 | TrianglesOnBoundary.insert( TrianglePair(TrianglesOnBoundaryCount, BTS) );
|
|---|
| 1339 | TrianglesOnBoundaryCount++;
|
|---|
| 1340 |
|
|---|
| 1341 | for(int i=0;i<NDIM;i++)
|
|---|
| 1342 | {
|
|---|
| 1343 | LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BTS->lines[i]) );
|
|---|
| 1344 | LinesOnBoundaryCount++;
|
|---|
| 1345 | };
|
|---|
| 1346 |
|
|---|
| 1347 | BTS->GetNormalVector(BTS->NormalVector);
|
|---|
| 1348 |
|
|---|
| 1349 | if( BTS->NormalVector.ScalarProduct(&Oben)<0)
|
|---|
| 1350 | {
|
|---|
| 1351 | BTS->NormalVector.Scale(-1);
|
|---|
| 1352 | }
|
|---|
| 1353 | };
|
|---|
| 1354 |
|
|---|
| 1355 |
|
|---|
| 1356 | void Find_non_convex_border(ofstream *out, ofstream *tecplot, Tesselation Tess, molecule* mol)
|
|---|
| 1357 | {
|
|---|
| 1358 | cout << Verbose(1) << "Entering finding of non convex hull. " << endl;
|
|---|
| 1359 | cout << flush;
|
|---|
| 1360 | const double RADIUS =6;
|
|---|
| 1361 | LineMap::iterator baseline;
|
|---|
| 1362 | Tess.Find_starting_triangle(mol, RADIUS);
|
|---|
| 1363 |
|
|---|
| 1364 | baseline = Tess.LinesOnBoundary.begin();
|
|---|
| 1365 | while (baseline != Tess.LinesOnBoundary.end()) {
|
|---|
| 1366 | if (baseline->second->TrianglesCount == 1)
|
|---|
| 1367 | {
|
|---|
| 1368 | cout << Verbose(1) << "Begin of Tesselation ... " << endl;
|
|---|
| 1369 | Tess.Find_next_suitable_triangle(out, tecplot, mol, *(baseline->second), *(baseline->second->triangles.begin()->second), RADIUS); //the line is there, so there is a triangle, but only one.
|
|---|
| 1370 | cout << Verbose(1) << "End of Tesselation ... " << endl;
|
|---|
| 1371 | }
|
|---|
| 1372 | else
|
|---|
| 1373 | {
|
|---|
| 1374 | cout << Verbose(1) << "There is a line with " << baseline->second->TrianglesCount << " triangles adjacent";
|
|---|
| 1375 | }
|
|---|
| 1376 | baseline++;
|
|---|
| 1377 | }
|
|---|
| 1378 |
|
|---|
| 1379 | };
|
|---|