[51695c] | 1 | #include "molecules.hpp"
|
---|
| 2 | #include "boundary.hpp"
|
---|
| 3 |
|
---|
| 4 |
|
---|
[03648b] | 5 | void Find_next_suitable_point(atom a, atom b, atom Candidate, int n, Vector *d1, Vector *d2, double *Storage, const double RADIUS, molecule mol)
|
---|
[51695c] | 6 | {
|
---|
| 7 | /* d2 ist der Normalenvektor auf dem Dreieck,
|
---|
| 8 | * d1 ist der Vektor, der normal auf der Kante und d2 steht.
|
---|
| 9 | */
|
---|
[1ffa21] | 10 | Vector dif_a;
|
---|
| 11 | Vector dif_b;
|
---|
| 12 | Vector Chord;
|
---|
| 13 | Vector AngleCheck;
|
---|
[51695c] | 14 | atom *Walker;
|
---|
| 15 |
|
---|
[1ffa21] | 16 | dif_a.CopyVector(&a.x);
|
---|
| 17 | dif_a.SubtractVector(&Candidate.x);
|
---|
| 18 | dif_b.CopyVector(&b.x);
|
---|
| 19 | dif_b.SubtractVector(&Candidate.x);
|
---|
| 20 | Chord.CopyVector(&a.x);
|
---|
| 21 | Chord.SubtractVector(&b.x);
|
---|
| 22 | AngleCheck.CopyVector(&dif_a);
|
---|
| 23 | AngleCheck.ProjectOntoPlane(&Chord);
|
---|
[51695c] | 24 |
|
---|
| 25 | //Storage eintrag fuer aktuelles Atom
|
---|
[1ffa21] | 26 | 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
|
---|
[51695c] | 27 | {
|
---|
| 28 |
|
---|
| 29 | if (dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1))>Storage[1]) //This will give absolute preference to those in "right-hand" quadrants
|
---|
| 30 | {
|
---|
| 31 | Storage[0]=(double)Candidate.nr;
|
---|
| 32 | Storage[1]=1;
|
---|
| 33 | Storage[2]=AngleCheck.Angle(d2);
|
---|
| 34 | }
|
---|
| 35 | else
|
---|
| 36 | {
|
---|
| 37 | if ((dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1)) == Storage[1] && Storage[1]>0 && Storage[2]< AngleCheck.Angle(d2)) or \
|
---|
| 38 | (dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1)) == Storage[1] && Storage[1]<0 && Storage[2]> AngleCheck.Angle(d2)))
|
---|
| 39 | //Depending on quadrant we prefer higher or lower atom with respect to Triangle normal first.
|
---|
| 40 | {
|
---|
| 41 | Storage[0]=(double)Candidate.nr;
|
---|
[1ffa21] | 42 | Storage[1]=dif_a.ScalarProduct(d1)/fabs(dif_a.ScalarProduct(d1));
|
---|
[51695c] | 43 | Storage[2]=AngleCheck.Angle(d2);
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | if (n<5)
|
---|
| 49 | {
|
---|
[1ffa21] | 50 | for(int i=0; i<mol.NumberOfBondsPerAtom[Candidate.nr];i++)
|
---|
[51695c] | 51 | {
|
---|
[1ffa21] | 52 | while (Candidate.nr != (mol.ListOfBondsPerAtom[Candidate.nr][i]->leftatom->nr ==Candidate.nr ? mol.ListOfBondsPerAtom[Candidate.nr][i]->leftatom->nr : mol.ListOfBondsPerAtom[Candidate.nr][i]->rightatom->nr))
|
---|
[51695c] | 53 | {
|
---|
[1ffa21] | 54 | Walker = Walker->next;
|
---|
[51695c] | 55 | }
|
---|
| 56 |
|
---|
[1ffa21] | 57 | Find_next_suitable_point(a, b, *Walker, n+1, d1, d2, Storage, RADIUS, mol);
|
---|
[51695c] | 58 | }
|
---|
| 59 | }
|
---|
[1ffa21] | 60 | };
|
---|
[51695c] | 61 |
|
---|
| 62 |
|
---|
[1ffa21] | 63 | void Tesselation::Find_next_suitable_triangle(molecule *mol, BoundaryLineSet Line, BoundaryTriangleSet T, const double& RADIUS)
|
---|
[51695c] | 64 | {
|
---|
[1ffa21] | 65 | Vector CenterOfLine = Line.endpoints[0]->node->x;
|
---|
[51695c] | 66 | Vector direction1;
|
---|
| 67 | Vector direction2;
|
---|
| 68 | Vector helper;
|
---|
[1ffa21] | 69 | atom* Walker;
|
---|
[51695c] | 70 |
|
---|
[1ffa21] | 71 | double Storage[3];
|
---|
| 72 | Storage[0]=-1.; // Id must be positive, we see should nothing be done
|
---|
| 73 | Storage[1]=-1.; // This direction is either +1 or -1 one, so any result will take precedence over initial values
|
---|
| 74 | Storage[2]=-10.; // This is also lower then any value produced by an eligible atom, which are all positive
|
---|
[51695c] | 75 |
|
---|
| 76 |
|
---|
[1ffa21] | 77 | helper.CopyVector(&(Line.endpoints[0]->node->x));
|
---|
[51695c] | 78 | for (int i =0; i<3; i++)
|
---|
| 79 | {
|
---|
[1ffa21] | 80 | if (T.endpoints[i]->node->nr != Line.endpoints[0]->node->nr && T.endpoints[i]->node->nr!=Line.endpoints[1]->node->nr)
|
---|
[51695c] | 81 | {
|
---|
[1ffa21] | 82 | helper.SubtractVector(&T.endpoints[i]->node->x);
|
---|
[51695c] | 83 | break;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 |
|
---|
[1ffa21] | 88 | direction1.CopyVector(&Line.endpoints[0]->node->x);
|
---|
| 89 | direction1.SubtractVector(&Line.endpoints[1]->node->x);
|
---|
| 90 | direction1.VectorProduct(T.NormalVector);
|
---|
[51695c] | 91 |
|
---|
[1ffa21] | 92 | if (direction1.ScalarProduct(&helper)>0)
|
---|
[51695c] | 93 | {
|
---|
| 94 | direction1.Scale(-1);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[1ffa21] | 97 | Find_next_suitable_point(*Line.endpoints[0]->node, *Line.endpoints[1]->node, *Line.endpoints[0]->node, 0, &direction1, T.NormalVector, Storage, RADIUS, *mol);
|
---|
[51695c] | 98 |
|
---|
| 99 | // Konstruiere nun neues Dreieck am Ende der Liste der Dreiecke
|
---|
| 100 | // Next Triangle is Line, atom with number in Storage[0]
|
---|
[03648b] | 101 |
|
---|
[1ffa21] | 102 | Walker= mol->start;
|
---|
| 103 | while (Walker->nr != (int)Storage[0])
|
---|
[03648b] | 104 | {
|
---|
| 105 | Walker = Walker->next;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | AddPoint(Walker);
|
---|
| 109 |
|
---|
[1ffa21] | 110 | BPS[0] = new class BoundaryPointSet(Walker);
|
---|
| 111 | BPS[1] = new class BoundaryPointSet(Line.endpoints[0]->node);
|
---|
[03648b] | 112 | BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
---|
[1ffa21] | 113 | BPS[0] = new class BoundaryPointSet(Walker);
|
---|
| 114 | BPS[1] = new class BoundaryPointSet(Line.endpoints[1]->node);
|
---|
[03648b] | 115 | BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
---|
[1ffa21] | 116 | BLS[2] = new class BoundaryLineSet(Line);
|
---|
[03648b] | 117 |
|
---|
| 118 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 119 | TrianglesOnBoundary.insert( TrianglePair(TrianglesOnBoundaryCount, BTS) );
|
---|
| 120 | TrianglesOnBoundaryCount++;
|
---|
| 121 |
|
---|
| 122 | for(int i=0;i<NDIM;i++) // sind Linien bereits vorhanden ???
|
---|
| 123 | {
|
---|
[1ffa21] | 124 | if (LinesOnBoundary.find(BTS->lines[i]) == LinesOnBoundary.end)
|
---|
[03648b] | 125 | {
|
---|
| 126 | LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BTS->lines[i]) );
|
---|
| 127 | LinesOnBoundaryCount++;
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
[1ffa21] | 130 | BTS->GetNormalVector(*BTS->NormalVector);
|
---|
[03648b] | 131 |
|
---|
[1ffa21] | 132 | if( (BTS->NormalVector->ScalarProduct(T.NormalVector)<0 && Storage[1]>0) || \
|
---|
| 133 | (BTS->NormalVector->ScalarProduct(T.NormalVector)>0 && Storage[1]<0))
|
---|
[03648b] | 134 | {
|
---|
[1ffa21] | 135 | BTS->NormalVector->Scale(-1);
|
---|
[03648b] | 136 | }
|
---|
[51695c] | 137 |
|
---|
[1ffa21] | 138 | };
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | void Find_second_point_for_Tesselation(atom a, atom Candidate, int n, Vector Oben, double* Storage, molecule mol)
|
---|
| 142 | {
|
---|
| 143 | int i;
|
---|
| 144 | Vector *AngleCheck;
|
---|
| 145 | atom* Walker;
|
---|
| 146 |
|
---|
| 147 | AngleCheck->CopyVector(&Candidate.x);
|
---|
| 148 | AngleCheck->SubtractVector(&a.x);
|
---|
| 149 | if (AngleCheck->ScalarProduct(&Oben) < Storage[1])
|
---|
| 150 | {
|
---|
| 151 | Storage[0]=(double)(Candidate.nr);
|
---|
| 152 | Storage[1]=AngleCheck->ScalarProduct(&Oben);
|
---|
| 153 | };
|
---|
| 154 |
|
---|
| 155 | if (n<5)
|
---|
| 156 | {
|
---|
| 157 | for (i = 0; i< mol.NumberOfBondsPerAtom[Candidate.nr]; i++)
|
---|
| 158 | {
|
---|
| 159 | Walker = mol.start;
|
---|
| 160 | while (Candidate.nr != (mol.ListOfBondsPerAtom[Candidate.nr][i]->leftatom->nr ==Candidate.nr ? mol.ListOfBondsPerAtom[Candidate.nr][i]->leftatom->nr : mol.ListOfBondsPerAtom[Candidate.nr][i]->rightatom->nr))
|
---|
| 161 | {
|
---|
| 162 | Walker = Walker->next;
|
---|
| 163 | };
|
---|
| 164 |
|
---|
| 165 | Find_second_point_for_Tesselation(a, *Walker, n+1, Oben, Storage, mol);
|
---|
| 166 | };
|
---|
| 167 | };
|
---|
| 168 |
|
---|
[51695c] | 169 |
|
---|
[1ffa21] | 170 | };
|
---|
[51695c] | 171 |
|
---|
[1ffa21] | 172 |
|
---|
| 173 | void Tesselation::Find_starting_triangle(molecule mol, const double RADIUS)
|
---|
[51695c] | 174 | {
|
---|
[1ffa21] | 175 | int i=0;
|
---|
[51695c] | 176 | atom Walker;
|
---|
| 177 | atom Walker2;
|
---|
[03648b] | 178 | atom Walker3;
|
---|
[51695c] | 179 | int max_index[3];
|
---|
| 180 | double max_coordinate[3];
|
---|
| 181 | Vector Oben;
|
---|
| 182 | Vector helper;
|
---|
| 183 |
|
---|
[1ffa21] | 184 | Oben.Zero();
|
---|
[51695c] | 185 |
|
---|
| 186 |
|
---|
[1ffa21] | 187 | for(i =0; i<3; i++)
|
---|
[51695c] | 188 | {
|
---|
| 189 | max_index[i] =-1;
|
---|
| 190 | max_coordinate[i] =-1;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[1ffa21] | 193 | Walker = *mol.start;
|
---|
| 194 | while (Walker.next != NULL)
|
---|
[51695c] | 195 | {
|
---|
| 196 | for (i=0; i<3; i++)
|
---|
| 197 | {
|
---|
[1ffa21] | 198 | if (Walker.x.x[i]>max_coordinate[i])
|
---|
[51695c] | 199 | {
|
---|
[1ffa21] | 200 | max_coordinate[i]=Walker.x.x[i];
|
---|
[51695c] | 201 | max_index[i]=Walker.nr;
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | //Koennen dies fuer alle Richtungen, legen hier erstmal Richtung auf k=0
|
---|
| 207 | const int k=0;
|
---|
| 208 |
|
---|
| 209 | Oben.x[k]=1;
|
---|
[1ffa21] | 210 | Walker = *mol.start;
|
---|
[51695c] | 211 | while (Walker.nr != max_index[k])
|
---|
| 212 | {
|
---|
[1ffa21] | 213 | Walker = *Walker.next;
|
---|
[51695c] | 214 | }
|
---|
| 215 |
|
---|
[1ffa21] | 216 | double Storage[3];
|
---|
| 217 | Storage[0]=-1.; // Id must be positive, we see should nothing be done
|
---|
| 218 | Storage[1]=-2.; // 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.
|
---|
| 219 | Storage[2]=-10.; // This will be an angle looking for the third point.
|
---|
[51695c] | 220 |
|
---|
| 221 |
|
---|
[1ffa21] | 222 | for (i=0; i< mol.NumberOfBondsPerAtom[Walker.nr]; i++)
|
---|
[51695c] | 223 | {
|
---|
[1ffa21] | 224 | Walker2 = *mol.start;
|
---|
| 225 | while (Walker2.nr != (mol.ListOfBondsPerAtom[Walker.nr][i]->leftatom->nr == Walker.nr ? mol.ListOfBondsPerAtom[Walker.nr][i]->rightatom->nr : mol.ListOfBondsPerAtom[Walker.nr][i]->leftatom->nr) )
|
---|
[51695c] | 226 | {
|
---|
[1ffa21] | 227 | Walker2 = *Walker2.next;
|
---|
[51695c] | 228 | }
|
---|
| 229 |
|
---|
[1ffa21] | 230 | Find_second_point_for_Tesselation(Walker, Walker2, 0, Oben, Storage, mol);
|
---|
[51695c] | 231 | }
|
---|
| 232 |
|
---|
[1ffa21] | 233 | Walker2 = *mol.start;
|
---|
[51695c] | 234 |
|
---|
| 235 | while (Walker2.nr != int(Storage[0]))
|
---|
| 236 | {
|
---|
[1ffa21] | 237 | Walker = *Walker.next;
|
---|
[51695c] | 238 | }
|
---|
| 239 |
|
---|
[1ffa21] | 240 | helper.CopyVector(&Walker.x);
|
---|
| 241 | helper.SubtractVector(&Walker2.x);
|
---|
| 242 | Oben.ProjectOntoPlane(&helper);
|
---|
| 243 | helper.VectorProduct(&Oben);
|
---|
[51695c] | 244 |
|
---|
[1ffa21] | 245 | Find_next_suitable_point(Walker, Walker2, *(mol.ListOfBondsPerAtom[Walker.nr][i]->leftatom->nr == Walker.nr ? mol.ListOfBondsPerAtom[Walker.nr][i]->rightatom : mol.ListOfBondsPerAtom[Walker.nr][i]->leftatom), 0, &helper, &Oben, Storage, RADIUS, mol);
|
---|
| 246 | Walker3 = *mol.start;
|
---|
[03648b] | 247 | while (Walker3.nr != int(Storage[0]))
|
---|
| 248 | {
|
---|
[1ffa21] | 249 | Walker3 = *Walker3.next;
|
---|
[03648b] | 250 | }
|
---|
[51695c] | 251 |
|
---|
| 252 | //Starting Triangle is Walker, Walker2, index Storage[0]
|
---|
| 253 |
|
---|
[1ffa21] | 254 | AddPoint(&Walker);
|
---|
| 255 | AddPoint(&Walker2);
|
---|
| 256 | AddPoint(&Walker3);
|
---|
[03648b] | 257 |
|
---|
[1ffa21] | 258 | BPS[0] = new class BoundaryPointSet(&Walker);
|
---|
| 259 | BPS[1] = new class BoundaryPointSet(&Walker2);
|
---|
[03648b] | 260 | BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
---|
[1ffa21] | 261 | BPS[0] = new class BoundaryPointSet(&Walker);
|
---|
| 262 | BPS[1] = new class BoundaryPointSet(&Walker3);
|
---|
[03648b] | 263 | BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
---|
[1ffa21] | 264 | BPS[0] = new class BoundaryPointSet(&Walker);
|
---|
| 265 | BPS[1] = new class BoundaryPointSet(&Walker2);
|
---|
[03648b] | 266 | BLS[2] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
|
---|
| 267 |
|
---|
| 268 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
|
---|
| 269 | TrianglesOnBoundary.insert( TrianglePair(TrianglesOnBoundaryCount, BTS) );
|
---|
| 270 | TrianglesOnBoundaryCount++;
|
---|
| 271 |
|
---|
| 272 | for(int i=0;i<NDIM;i++)
|
---|
| 273 | {
|
---|
| 274 | LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BTS->lines[i]) );
|
---|
| 275 | LinesOnBoundaryCount++;
|
---|
[1ffa21] | 276 | };
|
---|
[03648b] | 277 |
|
---|
[1ffa21] | 278 | BTS->GetNormalVector(*BTS->NormalVector);
|
---|
[51695c] | 279 |
|
---|
[1ffa21] | 280 | if( BTS->NormalVector->ScalarProduct(&Oben)<0)
|
---|
| 281 | {
|
---|
| 282 | BTS->NormalVector->Scale(-1);
|
---|
| 283 | }
|
---|
| 284 | };
|
---|
[51695c] | 285 |
|
---|
| 286 |
|
---|
[1ffa21] | 287 | void Find_non_convex_border(Tesselation* Tess, molecule mol)
|
---|
| 288 | {
|
---|
| 289 | const double RADIUS =6;
|
---|
| 290 | Tess->Find_starting_triangle(mol, RADIUS);
|
---|
[03648b] | 291 |
|
---|
[1ffa21] | 292 | for (LineMap::iterator baseline = Tess->LinesOnBoundary.begin(); baseline != Tess->LinesOnBoundary.end(); baseline++)
|
---|
[03648b] | 293 | if (baseline->second->TrianglesCount == 1)
|
---|
| 294 | {
|
---|
[1ffa21] | 295 | Tess->Find_next_suitable_triangle(&mol, baseline->second, baseline->second->triangles.begin()->second, RADIUS); //the line is there, so there is a triangle, but only one.
|
---|
[03648b] | 296 |
|
---|
| 297 | }
|
---|
| 298 | else
|
---|
| 299 | {
|
---|
| 300 | printf("There is a line with %d triangles adjacent", baseline->second->TrianglesCount);
|
---|
| 301 | }
|
---|
[1ffa21] | 302 | };
|
---|