]> Creatis software - creaVtk.git/commitdiff
2209 creaVtk Feature New Normal Correction of Heart Angles Box 2013-12-13 16:50
authorctorres <carlos.torres@creatis.insa-lyon.fr>
Fri, 13 Dec 2013 15:51:02 +0000 (16:51 +0100)
committerctorres <carlos.torres@creatis.insa-lyon.fr>
Fri, 13 Dec 2013 15:51:02 +0000 (16:51 +0100)
bbtk_creaVtk_PKG/src/bbcreaVtkHeartAngles.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkHeartAngles.h
lib/creaVtk/creaVtkHeartAngles.cpp
lib/creaVtk/creaVtkHeartAngles.h

index c8ddd49a4f72fce8567c1337bf2e08e1457f1eaa..fc496d08768fb74c82d5611f1dc9da366ecbf8e3 100644 (file)
@@ -15,10 +15,27 @@ BBTK_BLACK_BOX_IMPLEMENTATION(HeartAngles,bbtk::AtomicBlackBox);
 //===== 
 void HeartAngles::Process()
 {
+       std::cout << "CFT HeartAngles::Process() Start"<<std::endl;
        creaVtkHeartAngles ha;
-       ha.calculateImages (bbGetInputImage(), bbGetInputPx(), bbGetInputPy(), bbGetInputPz(), bbGetInputVx(), bbGetInputVy(), bbGetInputVz(), bbGetInputNx(), bbGetInputNy(), bbGetInputNz(), bbGetInputp2x(), bbGetInputp2y(), bbGetInputp2z());
+       
+       //ha.calculateImages (bbGetInputImage(), bbGetInputPlanePoint()[0], bbGetInputPlanePoint()[1], bbGetInputPlanePoint()[2], bbGetInputVector()[0], bbGetInputVector()[1], bbGetInputVector()[2], bbGetInputNormal()[0], bbGetInputNormal()[1], bbGetInputNormal()[2], bbGetInputPoint2()[0], bbGetInputPoint2()[1], bbGetInputPoint2()[2]);
+//     bbSetOutputAlphaImage(ha.getAlphaImage());
+       double p2x = bbGetInputNormal()[0]+ bbGetInputPlanePoint()[0];
+       double p2y = bbGetInputNormal()[1]+ bbGetInputPlanePoint()[1];
+       double p2z = bbGetInputNormal()[2]+ bbGetInputPlanePoint()[2];
+
+       double Nx = bbGetInputNormal()[0];
+       double Ny = bbGetInputNormal()[1];
+       double Nz = bbGetInputNormal()[2];
+
+       double Px = bbGetInputPlanePoint()[0];
+       double Py = bbGetInputPlanePoint()[1];
+       double Pz = bbGetInputPlanePoint()[2];
+
+       ha.calculateImages (bbGetInputImage(), Px, Py, Pz, Nx, Ny, Nz, p2x, p2y, p2z);
        bbSetOutputAlphaImage(ha.getAlphaImage());
        bbSetOutputBetaImage(ha.getBetaImage());
+       std::cout << "CFT HeartAngles::Process() End"<<std::endl;
 }
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
index 10a80f8a1b51879e0bf271c6bf6ab6dfb8959de1..287d88fbffcc8580c0502e4b5c8f0ad7228bab89 100644 (file)
@@ -7,6 +7,7 @@
 #include "bbtkAtomicBlackBox.h"
 #include "iostream"
 #include "vtkImageData.h"
+#include <vector>
 namespace bbcreaVtk
 {
 
@@ -18,18 +19,10 @@ class bbcreaVtk_EXPORT HeartAngles
 
 //vtkImageData* image, double Px, double Py, double Pz, double Vx, double Vy, double Vz, double Nx, double Ny, double Nz, double p2x, double p2y, double p2z
   BBTK_DECLARE_INPUT(Image, vtkImageData*);
-  BBTK_DECLARE_INPUT(Px,double);
-  BBTK_DECLARE_INPUT(Py,double);
-  BBTK_DECLARE_INPUT(Pz,double);
-  BBTK_DECLARE_INPUT(Vx,double);
-  BBTK_DECLARE_INPUT(Vy,double);
-  BBTK_DECLARE_INPUT(Vz,double);
-  BBTK_DECLARE_INPUT(Nx,double);
-  BBTK_DECLARE_INPUT(Ny,double);
-  BBTK_DECLARE_INPUT(Nz,double);
-  BBTK_DECLARE_INPUT(p2x,double);
-  BBTK_DECLARE_INPUT(p2y,double);
-  BBTK_DECLARE_INPUT(p2z,double);
+  BBTK_DECLARE_INPUT(PlanePoint,std::vector<double>);
+  BBTK_DECLARE_INPUT(Vector,std::vector<double>);
+  BBTK_DECLARE_INPUT(Normal,std::vector<double>);
+  BBTK_DECLARE_INPUT(Point2,std::vector<double>);
   BBTK_DECLARE_OUTPUT(AlphaImage, vtkImageData*);
   BBTK_DECLARE_OUTPUT(BetaImage, vtkImageData*);
   BBTK_PROCESS(Process);
@@ -45,18 +38,10 @@ BBTK_AUTHOR("carlos torres");
 BBTK_DESCRIPTION("No Description.");
 BBTK_CATEGORY("empty");
 BBTK_INPUT(HeartAngles,Image,"Image",vtkImageData*,"");
-BBTK_INPUT(HeartAngles,Px,"Punto en el plano componente X",double,"");
-BBTK_INPUT(HeartAngles,Py,"Punto en el plano componente Y",double,"");
-BBTK_INPUT(HeartAngles,Pz,"Punto en el plano componente Z",double,"");
-BBTK_INPUT(HeartAngles,Vx,"Vector componente X",double,"");
-BBTK_INPUT(HeartAngles,Vy,"Vector componente Y",double,"");
-BBTK_INPUT(HeartAngles,Vz,"Vector componente Z",double,"");
-BBTK_INPUT(HeartAngles,Nx,"Normal componente X",double,"");
-BBTK_INPUT(HeartAngles,Ny,"Normal componente Y",double,"");
-BBTK_INPUT(HeartAngles,Nz,"Normal componente Z",double,"");
-BBTK_INPUT(HeartAngles,p2x,"Punto P2 componente X",double,"");
-BBTK_INPUT(HeartAngles,p2y,"Punto P2 componente Y",double,"");
-BBTK_INPUT(HeartAngles,p2z,"Punto P2 componente Z",double,"");
+BBTK_INPUT(HeartAngles,PlanePoint,"Punto en el plano componente X",std::vector<double>,"");
+BBTK_INPUT(HeartAngles,Vector,"Vector componente X",std::vector<double>,"");
+BBTK_INPUT(HeartAngles,Normal,"Normal componente X",std::vector<double>,"");
+BBTK_INPUT(HeartAngles,Point2,"Punto P2 componente X",std::vector<double>,"");
 BBTK_OUTPUT(HeartAngles,AlphaImage,"Alpha Image",vtkImageData*,"");
 BBTK_OUTPUT(HeartAngles,BetaImage,"Beta Image",vtkImageData*,"");
 BBTK_END_DESCRIBE_BLACK_BOX(HeartAngles);
index cceaa643963d809df8312c2a1a8e1cc48986a0de..c70472e7df1760e919205b5c30e117d424fd4d1d 100644 (file)
 #include "creaVtkHeartAngles.h"
 #include <math.h>
 #include <iostream>
+#include "vtkDoubleArray.h"
+#include "vtkStructuredPoints.h"
+#include "vtkPointData.h"
+#include "vtkDataArray.h"
 
 creaVtkHeartAngles::creaVtkHeartAngles()
 {
@@ -63,7 +67,7 @@ double creaVtkHeartAngles::alpha (double P0a, double P0b,double P0c, double vx,
        double al = alpha - ent;
        double min = al * 60;
        //std::cout << "minutos: " << min << std::endl;
-       std::cout << "Grados: "<< ent <<" minutos: " << floor(min) << std::endl;
+       //std::cout << "Alpha grados: "<< ent <<" minutos: " << floor(min) << " cos: " << cosAlpha << std::endl;
        return alpha;
 }
 
@@ -83,34 +87,24 @@ double creaVtkHeartAngles::beta (double P0a, double P0b,double P0c, double P3x,
        double al = beta - ent;
        double min = al * 60;
        //std::cout << "minutos: " << min << std::endl;
-       std::cout << "Grados: "<< ent <<" minutos: " << floor(min) << std::endl;
+       //std::cout << "Beta grados: "<< ent <<" minutos: " << floor(min) << " cos: " << cosBeta << std::endl;
        return beta;
 }
 
-double * creaVtkHeartAngles::vectorProjection (double plX, double plY, double plZ, double nX, double nY, double nZ, double vX, double vY, double vZ)
+double * creaVtkHeartAngles::vectorProjection (double nX, double nY, double nZ, double vX, double vY, double vZ)
 {
-       //punto del plano
-       double plx=plX, ply=plY, plz=plZ;
+       
        //normalPlano
        double nx=nX, ny=nY, nz=nZ;
        //vector V
        double vx=vX, vy=vY, vz=vZ;
 
-       //distancia del punto al plano
-       double dist;
        //vector proyectado     
-       double vpx, vpy, vpz;
        double proj [3];
        
-       dist = ply - vy;
-       //std::cout << dist << std
-       vpx = vx - (dist * nx);
-       vpy = vy - (dist * ny);
-       vpz = vz - (dist * nz);
-       
-       proj[0]=vpx;
-       proj[1]=vpy;
-       proj[2]=vpz;
+       proj[0]= vX - (nX*vX);
+       proj[1]= vY - (nY*vY);
+       proj[2]= vZ - (nZ*vZ);
 
        return proj;
 }
@@ -171,9 +165,11 @@ double *creaVtkHeartAngles::intersectionPlaneLine(double plx1, double ply1, doub
        return puntoCorte;
 }
 
-void creaVtkHeartAngles::calculateImages (vtkImageData* image, double Px, double Py, double Pz, double Vx, double Vy, double Vz, double Nx, double Ny, double Nz, double p2x, double p2y, double p2z)
+void creaVtkHeartAngles::calculateImages (vtkImageData* image, double Px, double Py, double Pz, double Nx, double Ny, double Nz, double p2x, double p2y, double p2z)
 {
-       alphaImage = image;
+std::cout << "CFT creaVtkHeartAngles::calculateImages Start"<<std::endl;
+        
+       alphaImage = vtkImageData::New();
   alphaImage->SetExtent( image->GetExtent() );
   alphaImage->SetOrigin( image->GetOrigin() );
   alphaImage->SetSpacing( image->GetSpacing() );
@@ -181,8 +177,18 @@ void creaVtkHeartAngles::calculateImages (vtkImageData* image, double Px, double
   alphaImage->SetNumberOfScalarComponents( image->GetNumberOfScalarComponents() );
   alphaImage->AllocateScalars();
 
-       betaImage = image;
+       int ext[6];
+       image->GetWholeExtent(ext);
+       int dim[3];
+  dim[0]=ext[1]-ext[0]+1;
+  dim[1]=ext[3]-ext[2]+1;
+  dim[2]=ext[5]-ext[4]+1;
+
+       std::cout<<"dim0 "<<dim[0]<<" dim1 "<<dim[1]<<" dim2 "<<dim[2]<<std::endl;
+
+       betaImage = vtkImageData::New();
   betaImage->SetExtent( image->GetExtent() );
+  betaImage->SetWholeExtent( image->GetWholeExtent() );
   betaImage->SetOrigin( image->GetOrigin() );
   betaImage->SetSpacing( image->GetSpacing() );
   betaImage->SetScalarTypeToUnsignedChar();
@@ -194,21 +200,39 @@ void creaVtkHeartAngles::calculateImages (vtkImageData* image, double Px, double
        double a;
        double b;
 
-       for( int i = 0 ; i < image->GetExtent()[1] ; i++ )
+       int numberOfPoints = dim[0]*dim[1]*dim[2];
+
+       vtkDoubleArray *array;
+  array = (vtkDoubleArray*) image->GetPointData()->GetVectors();
+       //for(int i = 0 ; i < 8600 ; i++) {
+       //              std::cout<<" arreglo #"<< i << " "<< array->GetValue(i)<<" tuple3 "<< array->GetTuple3(i)[0]<<"  "<< array->GetTuple3(i)[1]<<"  "<<array->GetTuple3(i)[2]<< std::endl;
+       //}
+
+       int i, j, k;
+       int numTuple=0;
+
+
+       for( i = 0 ; i < dim[0] ; i++ )
   {
-    for( int j = 0 ; j < image->GetExtent()[3] ; j++ )
+    for( j = 0 ; j < dim[1] ; j++ )
        {
-                       for( int k = 0 ; k < image->GetExtent()[5] ; k++ )
+                       for( k = 0 ; k < dim[2] ; k++ )
                {
-                       unsigned char* pPix = (unsigned char *)image->GetScalarPointer( i , j , k );
-                       int p1 = pPix[0];
-                       int p2 = pPix[1];
-                       int p3 = pPix[2];
-                       
+                       //unsigned char* pPix = (unsigned char *)image->GetScalarPointer( i , j , k );
+
+                       double p1 = array->GetTuple3(numTuple)[0];
+                       double p2 = array->GetTuple3(numTuple)[1];
+                       double p3 = array->GetTuple3(numTuple)[2];
+                       numTuple++;
+               
+                       //std::cout << " p1: " << p1 << " p2: " << p2 <<" p3: " << p3 << std::endl;
+                       //std::cout << " Px: " << Px << " Py: " << Py <<" Pz: " << Pz << std::endl;
+                       //std::cout << " p2x: " << p2x << " p2y: " << p2y <<" p2z: " << p2z << std::endl;
+
                        double* vecProj;
-                       vecProj = vectorProjection (Px, Py, Pz,
-                                                                                                                                       Nx, Ny, Nz, 
+                       vecProj = vectorProjection (Nx, Ny, Nz, 
                                                                                                                                        p1, p2, p3);
+                       //std::cout << " vecProj[0]: " << vecProj[0] << " vecProj[1]: " << vecProj[1] <<" vecProj[2]: " << vecProj[2] << std::endl;                     
                        a = alpha (Px, Py, Pz, 
                                                           p1, p2, p3, 
                                                           vecProj[0], vecProj[1], vecProj[2]);
@@ -216,14 +240,17 @@ void creaVtkHeartAngles::calculateImages (vtkImageData* image, double Px, double
                        b = beta  (Px, Py, Pz, 
                                                           p2x, p2y, p2z, 
                                                           vecProj[0], vecProj[1], vecProj[2]);
-                       
+                       //std::cout << " a: " << a << " b: " << b << std::endl;
                        unsigned char *zPtr1 = (unsigned char *) alphaImage->GetScalarPointer( i , j , k );
-                       *zPtr1 = a;
+                       *zPtr1 = (unsigned char)a;
                        unsigned char *zPtr2 = (unsigned char *) betaImage->GetScalarPointer( i , j , k );
-                       *zPtr2 = b; 
-                       }
-       } 
-  }
+                       *zPtr2 = (unsigned char)b; 
+                       } //for k
+       } // for j
+  } // for i
+
+
+std::cout << "CFT creaVtkHeartAngles::calculateImages End"<<std::endl;
 }
 
 
index 433008e521c36349cf8330332898b9c0f4cabaf2..a610d391e6b661e07c9900766e0a1d17305d68ec 100644 (file)
@@ -41,12 +41,12 @@ public :
        double alpha (double P0a, double P0b,double P0c, double vx, double vy, double vz, double vxp, double vyp, double vzp);
        //Parametros: Punto P0, Punto P2, Punto P4 (proyection de V)
        double beta (double P0a, double P0b,double P0c, double P2x, double P2y, double P2z, double P4x, double P4y, double P4z);
-       //Parametros: punto del plano, normalPlano, vector V.
-       double * vectorProjection (double plx, double ply, double plz, double nx, double ny, double nz, double vx, double vy, double vz);
+       //Parametros: normalPlano, vector V.
+       double * vectorProjection (double nx, double ny, double nz, double vx, double vy, double vz);
        //Parametros: Tres puntos del plano, dos puntos de la recta.
        double *intersectionPlaneLine(double plx1, double ply1, double plz1, double plx2, double ply2, double plz2, double plx3, double ply3, double plz3, double px1, double py1, double pz1,double px2, double py2, double pz2);
-       //Parametros: Imagen 3D, Punto en el plano, Vector, Normal, p2.
-       void calculateImages (vtkImageData* image, double Px, double Py, double Pz, double Vx, double Vy, double Vz, double Nx, double Ny, double Nz, double p2x, double p2y, double p2z);
+       //Parametros: Imagen 3D, Punto en el plano, Normal, p2.
+       void calculateImages (vtkImageData* image, double Px, double Py, double Pz, double Nx, double Ny, double Nz, double p2x, double p2y, double p2z);
                
 protected: