Ignore:
Timestamp:
Apr 7, 2010, 3:45:38 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
0f55b2
Parents:
770138
Message:

Made data internal data-structure of vector class private

  • Replaced occurences of access to internals with operator
  • moved Vector-class into LinAlg-Module
  • Reworked Vector to allow clean modularization
  • Added Plane class to describe arbitrary planes in 3d space
File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/tesselation.cpp

    r770138 r71910a  
    1515#include "tesselationhelpers.hpp"
    1616#include "vector.hpp"
     17#include "vector_ops.hpp"
    1718#include "verbose.hpp"
     19#include "Plane.hpp"
     20#include "Exceptions/LinearDependenceException.hpp"
    1821
    1922class molecule;
     
    258261      helper[i].CopyVector(node->node->node);
    259262      helper[i].SubtractVector(&BaseLineCenter);
    260       helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
     263      helper[i].MakeNormalTo(BaseLine);  // we want to compare the triangle's heights' angles!
    261264      //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    262265      i++;
     
    402405        Info FunctionInfo(__func__);
    403406  // get normal vector
    404   NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     407  NormalVector = Plane(*(endpoints[0]->node->node),
     408                       *(endpoints[1]->node->node),
     409                       *(endpoints[2]->node->node)).getNormal();
    405410
    406411  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
     
    428433  Vector helper;
    429434
    430   if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
     435  try {
     436    *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x);
     437  }
     438  catch (LinearDependenceException &excp) {
     439    Log() << Verbose(1) << excp;
    431440    eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
    432441    return false;
     
    450459  int i=0;
    451460  do {
    452     if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) {
     461    try {
     462      CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node),
     463                                                    *(endpoints[(i+1)%3]->node->node),
     464                                                    *(endpoints[(i+2)%3]->node->node),
     465                                                    *Intersection);
    453466      helper.CopyVector(endpoints[(i+1)%3]->node->node);
    454467      helper.SubtractVector(endpoints[i%3]->node->node);
     
    462475      }
    463476      i++;
    464     } else
     477    } catch (LinearDependenceException &excp){
    465478      break;
     479    }
    466480  } while (i<3);
    467481  if (i==3) {
     
    492506  Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl;
    493507  GetCenter(&Direction);
    494   if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
     508  try {
     509    *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction);
     510  }
     511  catch (LinearDependenceException &excp) {
    495512    ClosestPoint->CopyVector(x);
    496513  }
     
    518535    Direction.SubtractVector(endpoints[i%3]->node->node);
    519536    // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
    520     CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node);
     537
     538    CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
     539
    521540    CrossDirection[i].CopyVector(&CrossPoint[i]);
    522541    CrossDirection[i].SubtractVector(&InPlane);
     
    731750  int counter=0;
    732751  for (; Runner[2] != endpoints.end(); ) {
    733     TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
     752    TemporaryNormal = Plane(*((*Runner[0])->node->node),
     753                            *((*Runner[1])->node->node),
     754                            *((*Runner[2])->node->node)).getNormal();
    734755    for (int i=0;i<3;i++) // increase each of them
    735756      Runner[i]++;
     
    12201241      // 2. next, we have to check whether all points reside on only one side of the triangle
    12211242      // 3. construct plane vector
    1222       PlaneVector.MakeNormalVector(A->second->node->node,
    1223           baseline->second.first->second->node->node,
    1224           baseline->second.second->second->node->node);
     1243      PlaneVector = Plane(*(A->second->node->node),
     1244                          *(baseline->second.first->second->node->node),
     1245                          *(baseline->second.second->second->node->node)).getNormal();
    12251246      Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl;
    12261247      // 4. loop over all points
     
    13911412        // vector in propagation direction (out of triangle)
    13921413        // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
    1393         PropagationVector.MakeNormalVector(&BaseLine, &NormalVector);
     1414        PropagationVector = Plane(BaseLine, NormalVector,0).getNormal();
    13941415        TempVector.CopyVector(&CenterVector);
    13951416        TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
     
    14481469            // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
    14491470            flag = true;
    1450             VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node);
     1471            VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node),
     1472                                        *(baseline->second->endpoints[1]->node->node),
     1473                                        *(target->second->node->node)).getNormal();
    14511474            TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
    14521475            TempVector.AddVector(baseline->second->endpoints[1]->node->node);
     
    20632086        if (List != NULL) {
    20642087          for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
    2065             if ((*Runner)->node->x[i] > maxCoordinate[i]) {
     2088            if ((*Runner)->node->at(i) > maxCoordinate[i]) {
    20662089              Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
    2067               maxCoordinate[i] = (*Runner)->node->x[i];
     2090              maxCoordinate[i] = (*Runner)->node->at(i);
    20682091              MaxPoint[i] = (*Runner);
    20692092            }
     
    20832106  for (int k=0;k<NDIM;k++) {
    20842107    NormalVector.Zero();
    2085     NormalVector.x[k] = 1.;
     2108    NormalVector[k] = 1.;
    20862109    BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
    20872110    Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;
     
    21172140
    21182141    // look in one direction of baseline for initial candidate
    2119     SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector);  // whether we look "left" first or "right" first is not important ...
     2142    SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal();  // whether we look "left" first or "right" first is not important ...
    21202143
    21212144    // adding point 1 and point 2 and add the line between them
     
    23362359
    23372360    // construct SearchDirection and an "outward pointer"
    2338     SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
     2361    SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal();
    23392362    helper.CopyVector(&CircleCenter);
    23402363    helper.SubtractVector(ThirdNode->node);
     
    29793002                  Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl;
    29803003
    2981                   if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node)
    2982                   && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)
    2983                   ) {
     3004                  try {
     3005                    NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node),
     3006                                              *(CandidateLine.BaseLine->endpoints[1]->node->node),
     3007                                              *(Candidate->node)).getNormal();
     3008
     3009                    if(!fabs(NewNormalVector.NormSquared()) > HULLEPSILON)
     3010                      throw LinearDependenceException(__FILE__,__LINE__);
     3011
    29843012                    Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
    29853013                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
     
    30433071                      Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
    30443072                    }
    3045                   } else {
     3073                  }
     3074                  catch (LinearDependenceException &excp){
     3075                    Log() << Verbose(1) << excp;
    30463076                    Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
    30473077                  }
     
    35653595  Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
    35663596  if (AngleZero.NormSquared() > MYEPSILON)
    3567     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3597    OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
    35683598  else
    3569     OrthogonalVector.MakeNormalVector(&PlaneNormal);
     3599    OrthogonalVector.MakeNormalTo(PlaneNormal);
    35703600  Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
    35713601
     
    36333663  int counter = 0;
    36343664  while (TesselC != SetOfNeighbours->end()) {
    3635     helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
     3665    helper = Plane(*((*TesselA)->node),
     3666                   *((*TesselB)->node),
     3667                   *((*TesselC)->node)).getNormal();
    36363668    Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl;
    36373669    counter++;
     
    36703702  Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
    36713703  if (AngleZero.NormSquared() > MYEPSILON)
    3672     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3704    OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
    36733705  else
    3674     OrthogonalVector.MakeNormalVector(&PlaneNormal);
     3706    OrthogonalVector.MakeNormalTo(PlaneNormal);
    36753707  Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
    36763708
     
    40024034          OrthogonalVector.CopyVector((*MiddleNode)->node);
    40034035          OrthogonalVector.SubtractVector(&OldPoint);
    4004           OrthogonalVector.MakeNormalVector(&Reference);
     4036          OrthogonalVector.MakeNormalTo(Reference);
    40054037          angle = GetAngle(Point, Reference, OrthogonalVector);
    40064038          //if (angle < M_PI)  // no wrong-sided triangles, please?
Note: See TracChangeset for help on using the changeset viewer.