From 98948f2103a598cb1dd64de7f8d86b3ffd8d389b Mon Sep 17 00:00:00 2001 From: trillos Date: Wed, 2 Dec 2009 13:15:16 +0000 Subject: [PATCH] Added new classes to the lib --- lib/PlanesOperations.cxx | 83 ++++++++++++++++++++++++ lib/PlanesOperations.h | 25 ++++++++ lib/Transformer3D1Point.cxx | 123 ++++++++++++++++++++++++++++++++++++ lib/Transformer3D1Point.h | 37 +++++++++++ 4 files changed, 268 insertions(+) create mode 100644 lib/PlanesOperations.cxx create mode 100644 lib/PlanesOperations.h create mode 100644 lib/Transformer3D1Point.cxx create mode 100644 lib/Transformer3D1Point.h diff --git a/lib/PlanesOperations.cxx b/lib/PlanesOperations.cxx new file mode 100644 index 0000000..ede6494 --- /dev/null +++ b/lib/PlanesOperations.cxx @@ -0,0 +1,83 @@ + +#include "PlanesOperations.h" + +/******************************************************************************************** +** Start of data viewmanagerData +*********************************************************************************************/ + +PlanesOperations::PlanesOperations() +{ +} + + +PlanesOperations::~PlanesOperations() +{ + +} + + +double* PlanesOperations::getCrossProduct(double* vect0,double* vect1) +{ + double* vectCross; + vectCross = new double[3]; + vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]); + vectCross[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0])); + vectCross[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]); + + return vectCross; +} + +double PlanesOperations::getDotProduct(double* vect0,double* vect1) +{ + double vectDot; + vectDot = vect0[0]*vect1[0] + vect0[1]*vect1[1] + vect0[2]*vect1[2]; + + return vectDot; +} +/** +** Returns the magnitud of the given vector +**/ +double PlanesOperations::getMagnitud(double* vect) +{ + double mag; + + mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2)); + + return mag; +} +/** +** returns the unitary vector of the given vector +** u = 1/|vect| . vect +**/ +double* PlanesOperations::getNormal(double* vect) +{ + + double* vectnorm; + double mag = getMagnitud(vect); + + vectnorm = new double[3]; + + if(mag!=0){ + vectnorm[0] = vect[0]/mag; + vectnorm[1] = vect[1]/mag; + vectnorm[2] = vect[2]/mag; + }else{ + vectnorm[0] = 0; + vectnorm[1] = 0; + vectnorm[2] = 0; + } + return vectnorm; +} + +double* PlanesOperations::makeVector(double podouble0[3], double podouble1[3]) +{ + double *vect; + vect = new double[3]; + + vect[0]= podouble1[0]-podouble0[0]; + vect[1]= podouble1[1]-podouble0[1]; + vect[2]= podouble1[2]-podouble0[2]; + + return vect; +} + diff --git a/lib/PlanesOperations.h b/lib/PlanesOperations.h new file mode 100644 index 0000000..3e37dd9 --- /dev/null +++ b/lib/PlanesOperations.h @@ -0,0 +1,25 @@ +#ifndef PlanesOperations_H_ +#define PlanesOperations_H_ + +#include + +#include + +class PlanesOperations { + +public: + PlanesOperations(); + ~PlanesOperations(); + + + + double* getCrossProduct(double* vect0,double* vect1); + double getDotProduct(double* vect0,double* vect1); + double getPodoubleProduct(double* vect0,double* vect1); + double* getNormal(double* vect); + double getMagnitud(double* vect); + double* makeVector(double podouble0[3], double podouble1[3]); + +}; + +#endif /*PlanesOperations_H_*/ diff --git a/lib/Transformer3D1Point.cxx b/lib/Transformer3D1Point.cxx new file mode 100644 index 0000000..de97c9a --- /dev/null +++ b/lib/Transformer3D1Point.cxx @@ -0,0 +1,123 @@ + +#include "Transformer3D1Point.h" +/* + CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0. +*/ +Transformer3D1Point::Transformer3D1Point() +{ + std::vector empty (3,0); + _centerPoint=empty; + //If the transform already exists, we delete it before we create a new transform + //and set the matrix with the identity matrix + _transform= vtkTransform::New(); + _matrix = vtkMatrix4x4::New(); + _matrix->Identity(); + _transform->SetMatrix(_matrix); +} + +/* + DESTRUCTOR +*/ +Transformer3D1Point::~Transformer3D1Point() +{ + //We delete the existing transform + if (_transform != NULL ) { _transform->Delete(); } + if (_matrix != NULL ) { _matrix->Delete(); } +} + +/* + SETS A NEW TRANSFORM +*/ +void Transformer3D1Point::SetTransform(vtkTransform *transform) +{ + _transform=transform; +} + +/* + SETS CENTER POINT +*/ +void Transformer3D1Point::SetCenterPoint(std::vector point) +{ + _centerPoint=point; +} + +/* + SETS THE ANGLE IN X +*/ +void Transformer3D1Point::SetAngleX(double angle) +{ + _angleX=angle; +} + +/* + SETS THE ANGLE IN Y +*/ +void Transformer3D1Point::SetAngleY(double angle) +{ + _angleY=angle; +} + +/* + SETS THE ANGLE IN Z +*/ +void Transformer3D1Point::SetAngleZ(double angle) +{ + _angleZ=angle; +} + +/* + SETS THE X SCALE +*/ +void Transformer3D1Point::SetScaleX(double scaleX) +{ + _scaleX=scaleX/100.0; +} + +/* + SETS THE Y SCALE +*/ +void Transformer3D1Point::SetScaleY(double scaleY) +{ + _scaleY=scaleY/100.0; +} + +/* + SETS THE Y SCALE + */ +void Transformer3D1Point::SetScaleZ(double scaleZ) +{ + _scaleZ=scaleZ/100.0; +} + +/* + GETS THE RESULTANT TRANSFORM +*/ +vtkTransform *Transformer3D1Point::GetResult() +{ + return _transform; +} + +/* + MAKES THE TRANSFORMATIONS +*/ +void Transformer3D1Point::Run() +{ + //Clears any old transformations in the pipeline + _transform->Identity(); + + //Make all transformations in post multiply mode + _transform->PostMultiply(); + + //Centers the image before applying the transformation + _transform->Translate(-_centerPoint[0], -_centerPoint[1], -_centerPoint[2]); + + + _transform->RotateWXYZ(_angleY, 0, 1, 0); + _transform->RotateWXYZ(_angleX, 1, 0, 0); + _transform->RotateWXYZ(_angleZ, 0, 0, 1); + _transform->Scale(_scaleX, _scaleY,_scaleZ); + + //Returns the inverse of the transformation (NTU: Have no idea why we have to do this for the image to appear properly) + _transform->Inverse(); + _transform->Update(); +} \ No newline at end of file diff --git a/lib/Transformer3D1Point.h b/lib/Transformer3D1Point.h new file mode 100644 index 0000000..9d6e1f0 --- /dev/null +++ b/lib/Transformer3D1Point.h @@ -0,0 +1,37 @@ + +#ifndef Transformer3DV1_h +#define Transformer3DV1_h + +#include "vtkTransform.h" +#include "vtkMatrix4x4.h" +#include + +class Transformer3D1Point{ +public: + Transformer3D1Point(); + ~Transformer3D1Point(); + void SetTransform(vtkTransform *transform); + void SetCenterPoint(std::vector point); + void SetAngleX(double angle); + void SetAngleY(double angle); + void SetAngleZ(double angle); + void SetScaleX(double scaleX); + void SetScaleY(double scaleY); + void SetScaleZ(double scaleZ); + void Run(); + + vtkTransform *GetResult(); +private: + std::vector _centerPoint; + double _angleX; + double _angleY; + double _angleZ; + double _scaleX; + double _scaleY; + double _scaleZ; + + vtkTransform *_transform; + vtkMatrix4x4 *_matrix; +}; + +#endif -- 2.47.1