Changeset 1f591b for molecuilder/src/tesselationhelpers.cpp
- Timestamp:
- Apr 13, 2010, 1:22:42 PM (16 years ago)
- Children:
- e7ea64
- Parents:
- 0f55b2
- File:
-
- 1 edited
-
molecuilder/src/tesselationhelpers.cpp (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/tesselationhelpers.cpp
r0f55b2 r1f591b 88 88 center->at(2) = 0.5 * m14/ m11; 89 89 90 if (fabs(a.Distance( center) - RADIUS) > MYEPSILON)91 eLog() << Verbose(1) << "The given center is further way by " << fabs(a.Distance( center) - RADIUS) << " from a than RADIUS." << endl;90 if (fabs(a.Distance(*center) - RADIUS) > MYEPSILON) 91 eLog() << Verbose(1) << "The given center is further way by " << fabs(a.Distance(*center) - RADIUS) << " from a than RADIUS." << endl; 92 92 93 93 gsl_matrix_free(A); … … 121 121 Vector OtherCenter; 122 122 Center->Zero(); 123 helper.CopyVector(&a); 124 helper.Scale(sin(2.*alpha)); 125 Center->AddVector(&helper); 126 helper.CopyVector(&b); 127 helper.Scale(sin(2.*beta)); 128 Center->AddVector(&helper); 129 helper.CopyVector(&c); 130 helper.Scale(sin(2.*gamma)); 131 Center->AddVector(&helper); 123 helper = sin(2.*alpha) * a; 124 (*Center) += helper; 125 helper = sin(2.*beta) * b; 126 (*Center) += helper; 127 helper = sin(2.*gamma) * c; 128 (*Center) += helper; 132 129 //*Center = a * sin(2.*alpha) + b * sin(2.*beta) + c * sin(2.*gamma) ; 133 130 Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma))); 134 NewUmkreismittelpunkt->CopyVector(Center);131 (*NewUmkreismittelpunkt) = (*Center); 135 132 Log() << Verbose(1) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n"; 136 133 // Here we calculated center of circumscribing circle, using barycentric coordinates 137 134 Log() << Verbose(1) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n"; 138 135 139 TempNormal.CopyVector(&a); 140 TempNormal.SubtractVector(&b); 141 helper.CopyVector(&a); 142 helper.SubtractVector(&c); 143 TempNormal.VectorProduct(&helper); 136 TempNormal = a - b; 137 helper = a - c; 138 TempNormal.VectorProduct(helper); 144 139 if (fabs(HalfplaneIndicator) < MYEPSILON) 145 140 { 146 if ((TempNormal.ScalarProduct( AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(AlternativeDirection) >0 && AlternativeIndicator <0))141 if ((TempNormal.ScalarProduct(*AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(*AlternativeDirection) >0 && AlternativeIndicator <0)) 147 142 { 148 TempNormal .Scale(-1);143 TempNormal *= -1; 149 144 } 150 145 } 151 146 else 152 147 { 153 if (((TempNormal.ScalarProduct( Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(Direction)>0) && (HalfplaneIndicator<0)))148 if (((TempNormal.ScalarProduct(*Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(*Direction)>0) && (HalfplaneIndicator<0))) 154 149 { 155 TempNormal .Scale(-1);150 TempNormal *= -1; 156 151 } 157 152 } … … 163 158 Log() << Verbose(1) << "Shift vector to sphere of circumference is " << TempNormal << ".\n"; 164 159 165 Center->AddVector(&TempNormal);160 (*Center) += TempNormal; 166 161 Log() << Verbose(1) << "Center of sphere of circumference is " << *Center << ".\n"; 167 162 GetSphere(&OtherCenter, a, b, c, RADIUS); … … 181 176 Vector helper; 182 177 double alpha, beta, gamma; 183 Vector SideA, SideB, SideC; 184 SideA.CopyVector(b); 185 SideA.SubtractVector(&c); 186 SideB.CopyVector(c); 187 SideB.SubtractVector(&a); 188 SideC.CopyVector(a); 189 SideC.SubtractVector(&b); 190 alpha = M_PI - SideB.Angle(&SideC); 191 beta = M_PI - SideC.Angle(&SideA); 192 gamma = M_PI - SideA.Angle(&SideB); 178 Vector SideA = b - c; 179 Vector SideB = c - a; 180 Vector SideC = a - b; 181 alpha = M_PI - SideB.Angle(SideC); 182 beta = M_PI - SideC.Angle(SideA); 183 gamma = M_PI - SideA.Angle(SideB); 193 184 //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl; 194 185 if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) { … … 197 188 198 189 Center->Zero(); 199 helper.CopyVector(a); 200 helper.Scale(sin(2.*alpha)); 201 Center->AddVector(&helper); 202 helper.CopyVector(b); 203 helper.Scale(sin(2.*beta)); 204 Center->AddVector(&helper); 205 helper.CopyVector(c); 206 helper.Scale(sin(2.*gamma)); 207 Center->AddVector(&helper); 190 helper = sin(2.*alpha) * a; 191 (*Center) += helper; 192 helper = sin(2.*beta) * b; 193 (*Center) += helper; 194 helper = sin(2.*gamma) * c; 195 (*Center) += helper; 208 196 Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma))); 209 197 }; … … 227 215 Vector helper; 228 216 double radius, alpha; 229 Vector RelativeOldSphereCenter; 230 Vector RelativeNewSphereCenter; 231 232 RelativeOldSphereCenter.CopyVector(&OldSphereCenter); 233 RelativeOldSphereCenter.SubtractVector(&CircleCenter); 234 RelativeNewSphereCenter.CopyVector(&NewSphereCenter); 235 RelativeNewSphereCenter.SubtractVector(&CircleCenter); 236 helper.CopyVector(&RelativeNewSphereCenter); 217 218 Vector RelativeOldSphereCenter = OldSphereCenter - CircleCenter; 219 Vector RelativeNewSphereCenter = NewSphereCenter - CircleCenter; 220 helper = RelativeNewSphereCenter; 237 221 // test whether new center is on the parameter circle's plane 238 if (fabs(helper.ScalarProduct( &CirclePlaneNormal)) > HULLEPSILON) {239 eLog() << Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct( &CirclePlaneNormal)) << "!" << endl;240 helper.ProjectOntoPlane( &CirclePlaneNormal);222 if (fabs(helper.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) { 223 eLog() << Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct(CirclePlaneNormal)) << "!" << endl; 224 helper.ProjectOntoPlane(CirclePlaneNormal); 241 225 } 242 226 radius = helper.NormSquared(); … … 244 228 if (fabs(radius - CircleRadius) > HULLEPSILON) 245 229 eLog() << Verbose(1) << "The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl; 246 alpha = helper.Angle( &RelativeOldSphereCenter);230 alpha = helper.Angle(RelativeOldSphereCenter); 247 231 // make the angle unique by checking the halfplanes/search direction 248 if (helper.ScalarProduct( &SearchDirection) < -HULLEPSILON) // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals232 if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON) // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals 249 233 alpha = 2.*M_PI - alpha; 250 234 Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << RelativeOldSphereCenter << " and resulting angle is " << alpha << "." << endl; 251 radius = helper.Distance( &RelativeOldSphereCenter);252 helper.ProjectOntoPlane( &NormalVector);235 radius = helper.Distance(RelativeOldSphereCenter); 236 helper.ProjectOntoPlane(NormalVector); 253 237 // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles 254 238 if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) { … … 280 264 struct Intersection *I = (struct Intersection *)params; 281 265 Vector intersection; 282 Vector SideA,SideB,HeightA, HeightB;283 266 for (int i=0;i<NDIM;i++) 284 267 intersection[i] = gsl_vector_get(x, i); 285 268 286 SideA.CopyVector(&(I->x1)); 287 SideA.SubtractVector(&I->x2); 288 HeightA.CopyVector(&intersection); 289 HeightA.SubtractVector(&I->x1); 290 HeightA.ProjectOntoPlane(&SideA); 291 292 SideB.CopyVector(&I->x3); 293 SideB.SubtractVector(&I->x4); 294 HeightB.CopyVector(&intersection); 295 HeightB.SubtractVector(&I->x3); 296 HeightB.ProjectOntoPlane(&SideB); 297 298 retval = HeightA.ScalarProduct(&HeightA) + HeightB.ScalarProduct(&HeightB); 269 Vector SideA = I->x1 -I->x2 ; 270 Vector HeightA = intersection - I->x1; 271 HeightA.ProjectOntoPlane(SideA); 272 273 Vector SideB = I->x3 - I->x4; 274 Vector HeightB = intersection - I->x3; 275 HeightB.ProjectOntoPlane(SideB); 276 277 retval = HeightA.ScalarProduct(HeightA) + HeightB.ScalarProduct(HeightB); 299 278 //Log() << Verbose(1) << "MinIntersectDistance called, result: " << retval << endl; 300 279 … … 321 300 322 301 struct Intersection par; 323 par.x1 .CopyVector(&point1);324 par.x2 .CopyVector(&point2);325 par.x3 .CopyVector(&point3);326 par.x4 .CopyVector(&point4);302 par.x1 = point1; 303 par.x2 = point2; 304 par.x3 = point3; 305 par.x4 = point4; 327 306 328 307 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; … … 370 349 371 350 // check whether intersection is in between or not 372 Vector intersection , SideA, SideB, HeightA, HeightB;351 Vector intersection; 373 352 double t1, t2; 374 353 for (int i = 0; i < NDIM; i++) { … … 376 355 } 377 356 378 SideA.CopyVector(&par.x2); 379 SideA.SubtractVector(&par.x1); 380 HeightA.CopyVector(&intersection); 381 HeightA.SubtractVector(&par.x1); 382 383 t1 = HeightA.ScalarProduct(&SideA)/SideA.ScalarProduct(&SideA); 384 385 SideB.CopyVector(&par.x4); 386 SideB.SubtractVector(&par.x3); 387 HeightB.CopyVector(&intersection); 388 HeightB.SubtractVector(&par.x3); 389 390 t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB); 357 Vector SideA = par.x2 - par.x1; 358 Vector HeightA = intersection - par.x1; 359 360 t1 = HeightA.ScalarProduct(SideA)/SideA.ScalarProduct(SideA); 361 362 Vector SideB = par.x4 - par.x3; 363 Vector HeightB = intersection - par.x3; 364 365 t2 = HeightB.ScalarProduct(SideB)/SideB.ScalarProduct(SideB); 391 366 392 367 Log() << Verbose(1) << "Intersection " << intersection << " is at " … … 428 403 if (point.IsZero()) 429 404 return M_PI; 430 double phi = point.Angle( &reference);431 if (OrthogonalVector.ScalarProduct( &point) > 0) {405 double phi = point.Angle(reference); 406 if (OrthogonalVector.ScalarProduct(point) > 0) { 432 407 phi = 2.*M_PI - phi; 433 408 } … … 456 431 TetraederVector[2].CopyVector(c); 457 432 for (int j=0;j<3;j++) 458 TetraederVector[j].SubtractVector( &d);459 Point.CopyVector( &TetraederVector[0]);460 Point.VectorProduct( &TetraederVector[1]);461 volume = 1./6. * fabs(Point.ScalarProduct( &TetraederVector[2]));433 TetraederVector[j].SubtractVector(d); 434 Point.CopyVector(TetraederVector[0]); 435 Point.VectorProduct(TetraederVector[1]); 436 volume = 1./6. * fabs(Point.ScalarProduct(TetraederVector[2])); 462 437 return volume; 463 438 }; … … 583 558 if (List != NULL) { 584 559 for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 585 helper.CopyVector(Point); 586 helper.SubtractVector((*Runner)->node); 587 double currentNorm = helper. Norm(); 560 helper = (*Point) - (*(*Runner)->node); 561 double currentNorm = helper.Norm(); 588 562 if (currentNorm < distance) { 589 563 // remember second point … … 638 612 if (List != NULL) { 639 613 for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 640 helper.CopyVector(Point); 641 helper.SubtractVector((*Runner)->node); 614 helper = (*Point) - (*(*Runner)->node); 642 615 double currentNorm = helper.NormSquared(); 643 616 if (currentNorm < distance) { … … 678 651 Info FunctionInfo(__func__); 679 652 // construct the plane of the two baselines (i.e. take both their directional vectors) 680 Vector Normal; 681 Vector Baseline, OtherBaseline; 682 Baseline.CopyVector(Base->endpoints[1]->node->node); 683 Baseline.SubtractVector(Base->endpoints[0]->node->node); 684 OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node); 685 OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node); 686 Normal.CopyVector(&Baseline); 687 Normal.VectorProduct(&OtherBaseline); 653 Vector Baseline = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node); 654 Vector OtherBaseline = (*OtherBase->endpoints[1]->node->node) - (*OtherBase->endpoints[0]->node->node); 655 Vector Normal = Baseline; 656 Normal.VectorProduct(OtherBaseline); 688 657 Normal.Normalize(); 689 658 Log() << Verbose(1) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl; 690 659 691 660 // project one offset point of OtherBase onto this plane (and add plane offset vector) 692 Vector NewOffset; 693 NewOffset.CopyVector(OtherBase->endpoints[0]->node->node); 694 NewOffset.SubtractVector(Base->endpoints[0]->node->node); 695 NewOffset.ProjectOntoPlane(&Normal); 696 NewOffset.AddVector(Base->endpoints[0]->node->node); 697 Vector NewDirection; 698 NewDirection.CopyVector(&NewOffset); 699 NewDirection.AddVector(&OtherBaseline); 661 Vector NewOffset = (*OtherBase->endpoints[0]->node->node) - (*Base->endpoints[0]->node->node); 662 NewOffset.ProjectOntoPlane(Normal); 663 NewOffset += (*Base->endpoints[0]->node->node); 664 Vector NewDirection = NewOffset + OtherBaseline; 700 665 701 666 // calculate the intersection between this projected baseline and Base … … 704 669 *(Base->endpoints[1]->node->node), 705 670 NewOffset, NewDirection); 706 Normal.CopyVector(Intersection); 707 Normal.SubtractVector(Base->endpoints[0]->node->node); 708 Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl; 671 Normal = (*Intersection) - (*Base->endpoints[0]->node->node); 672 Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(Baseline)/Baseline.NormSquared()) << "." << endl; 709 673 710 674 return Intersection; … … 724 688 return -1; 725 689 } 726 distance = x->DistanceToPlane( &triangle->NormalVector,triangle->endpoints[0]->node->node);690 distance = x->DistanceToPlane(triangle->NormalVector, *triangle->endpoints[0]->node->node); 727 691 return distance; 728 692 }; … … 787 751 Vector *center = cloud->GetCenter(); 788 752 // make the circumsphere's center absolute again 789 helper.CopyVector(Tess->LastTriangle->endpoints[0]->node->node); 790 helper.AddVector(Tess->LastTriangle->endpoints[1]->node->node); 791 helper.AddVector(Tess->LastTriangle->endpoints[2]->node->node); 792 helper.Scale(1./3.); 793 helper.SubtractVector(center); 753 Vector helper = (1./3.) * ((*Tess->LastTriangle->endpoints[0]->node->node) + 754 (*Tess->LastTriangle->endpoints[1]->node->node) + 755 (*Tess->LastTriangle->endpoints[2]->node->node)); 756 helper -= (*center); 794 757 // and add to file plus translucency object 795 758 *rasterfile << "# current virtual sphere\n";
Note:
See TracChangeset
for help on using the changeset viewer.
