]> Creatis software - creaRigidRegistration.git/commitdiff
Added new classes to the lib
authortrillos <trillos>
Wed, 2 Dec 2009 13:15:16 +0000 (13:15 +0000)
committertrillos <trillos>
Wed, 2 Dec 2009 13:15:16 +0000 (13:15 +0000)
lib/PlanesOperations.cxx [new file with mode: 0644]
lib/PlanesOperations.h [new file with mode: 0644]
lib/Transformer3D1Point.cxx [new file with mode: 0644]
lib/Transformer3D1Point.h [new file with mode: 0644]

diff --git a/lib/PlanesOperations.cxx b/lib/PlanesOperations.cxx
new file mode 100644 (file)
index 0000000..ede6494
--- /dev/null
@@ -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 (file)
index 0000000..3e37dd9
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef PlanesOperations_H_
+#define PlanesOperations_H_
+
+#include <math.h>
+
+#include <iostream>
+
+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 (file)
index 0000000..de97c9a
--- /dev/null
@@ -0,0 +1,123 @@
+
+#include "Transformer3D1Point.h"
+/*
+       CONSTRUCTOR: Initializes the two points with empty vectors, the angle in 0.
+*/
+Transformer3D1Point::Transformer3D1Point() 
+{
+       std::vector<int> 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<int> 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 (file)
index 0000000..9d6e1f0
--- /dev/null
@@ -0,0 +1,37 @@
+
+#ifndef Transformer3DV1_h
+#define Transformer3DV1_h
+
+#include "vtkTransform.h"
+#include "vtkMatrix4x4.h"
+#include <vector>
+
+class Transformer3D1Point{
+public: 
+       Transformer3D1Point();
+    ~Transformer3D1Point();
+       void SetTransform(vtkTransform *transform);
+       void SetCenterPoint(std::vector<int> 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<int> _centerPoint;
+       double _angleX;
+       double _angleY;
+       double _angleZ;
+       double _scaleX;
+       double _scaleY;
+       double _scaleZ;
+       
+       vtkTransform *_transform;
+       vtkMatrix4x4 *_matrix;
+};
+
+#endif