Ignore:
Timestamp:
Apr 13, 2010, 1:22:42 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
e7ea64
Parents:
0f55b2
Message:

Prepared interface of Vector Class for transition to VectorComposites

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/tesselationhelpers.cpp

    r0f55b2 r1f591b  
    8888  center->at(2) =  0.5 * m14/ m11;
    8989
    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;
    9292
    9393  gsl_matrix_free(A);
     
    121121  Vector OtherCenter;
    122122  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;
    132129  //*Center = a * sin(2.*alpha) + b * sin(2.*beta) + c * sin(2.*gamma) ;
    133130  Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
    134   NewUmkreismittelpunkt->CopyVector(Center);
     131  (*NewUmkreismittelpunkt) = (*Center);
    135132  Log() << Verbose(1) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n";
    136133  // Here we calculated center of circumscribing circle, using barycentric coordinates
    137134  Log() << Verbose(1) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n";
    138135
    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);
    144139  if (fabs(HalfplaneIndicator) < MYEPSILON)
    145140    {
    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))
    147142        {
    148           TempNormal.Scale(-1);
     143          TempNormal *= -1;
    149144        }
    150145    }
    151146  else
    152147    {
    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)))
    154149        {
    155           TempNormal.Scale(-1);
     150          TempNormal *= -1;
    156151        }
    157152    }
     
    163158  Log() << Verbose(1) << "Shift vector to sphere of circumference is " << TempNormal << ".\n";
    164159
    165   Center->AddVector(&TempNormal);
     160  (*Center) += TempNormal;
    166161  Log() << Verbose(1) << "Center of sphere of circumference is " << *Center << ".\n";
    167162  GetSphere(&OtherCenter, a, b, c, RADIUS);
     
    181176  Vector helper;
    182177  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);
    193184  //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;
    194185  if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) {
     
    197188
    198189  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;
    208196  Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
    209197};
     
    227215  Vector helper;
    228216  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;
    237221  // 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);
    241225  }
    242226  radius = helper.NormSquared();
     
    244228  if (fabs(radius - CircleRadius) > HULLEPSILON)
    245229    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);
    247231  // 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 intervals
     232  if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)  // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals
    249233    alpha = 2.*M_PI - alpha;
    250234  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);
    253237  // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles
    254238  if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) {
     
    280264  struct Intersection *I = (struct Intersection *)params;
    281265  Vector intersection;
    282   Vector SideA,SideB,HeightA, HeightB;
    283266  for (int i=0;i<NDIM;i++)
    284267    intersection[i] = gsl_vector_get(x, i);
    285268
    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);
    299278  //Log() << Verbose(1) << "MinIntersectDistance called, result: " << retval << endl;
    300279
     
    321300
    322301  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;
    327306
    328307    const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
     
    370349
    371350    // check whether intersection is in between or not
    372   Vector intersection, SideA, SideB, HeightA, HeightB;
     351  Vector intersection;
    373352  double t1, t2;
    374353  for (int i = 0; i < NDIM; i++) {
     
    376355  }
    377356
    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);
    391366
    392367  Log() << Verbose(1) << "Intersection " << intersection << " is at "
     
    428403  if (point.IsZero())
    429404    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) {
    432407    phi = 2.*M_PI - phi;
    433408  }
     
    456431  TetraederVector[2].CopyVector(c);
    457432  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]));
    462437  return volume;
    463438};
     
    583558        if (List != NULL) {
    584559          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();
    588562            if (currentNorm < distance) {
    589563              // remember second point
     
    638612        if (List != NULL) {
    639613          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);
    642615            double currentNorm = helper.NormSquared();
    643616            if (currentNorm < distance) {
     
    678651        Info FunctionInfo(__func__);
    679652  // 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);
    688657  Normal.Normalize();
    689658  Log() << Verbose(1) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl;
    690659
    691660  // 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;
    700665
    701666  // calculate the intersection between this projected baseline and Base
     
    704669                                                   *(Base->endpoints[1]->node->node),
    705670                                                     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;
    709673
    710674  return Intersection;
     
    724688    return -1;
    725689  }
    726   distance = x->DistanceToPlane(&triangle->NormalVector, triangle->endpoints[0]->node->node);
     690  distance = x->DistanceToPlane(triangle->NormalVector, *triangle->endpoints[0]->node->node);
    727691  return distance;
    728692};
     
    787751    Vector *center = cloud->GetCenter();
    788752    // 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);
    794757    // and add to file plus translucency object
    795758    *rasterfile << "# current virtual sphere\n";
Note: See TracChangeset for help on using the changeset viewer.