From: ctorres Date: Mon, 17 Feb 2014 16:27:21 +0000 (+0100) Subject: 2307 creaVtk Support New Normal Erase of heart angles lib and box 2014-02-17 17:27 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=284957390f0b4381c970cbcd7b9dd16db9a92ad0;p=creaVtk.git 2307 creaVtk Support New Normal Erase of heart angles lib and box 2014-02-17 17:27 --- diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkHeartAngles.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkHeartAngles.cxx deleted file mode 100644 index fc496d0..0000000 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkHeartAngles.cxx +++ /dev/null @@ -1,75 +0,0 @@ -//===== -// 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) -//===== -#include "bbcreaVtkHeartAngles.h" -#include "bbcreaVtkPackage.h" -#include "creaVtkHeartAngles.h" - -namespace bbcreaVtk -{ - -BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,HeartAngles) -BBTK_BLACK_BOX_IMPLEMENTATION(HeartAngles,bbtk::AtomicBlackBox); -//===== -// 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) -//===== -void HeartAngles::Process() -{ - std::cout << "CFT HeartAngles::Process() Start"< -namespace bbcreaVtk -{ - -class bbcreaVtk_EXPORT HeartAngles - : - public bbtk::AtomicBlackBox -{ - BBTK_BLACK_BOX_INTERFACE(HeartAngles,bbtk::AtomicBlackBox); - -//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(PlanePoint,std::vector); - BBTK_DECLARE_INPUT(Vector,std::vector); - BBTK_DECLARE_INPUT(Normal,std::vector); - BBTK_DECLARE_INPUT(Point2,std::vector); - BBTK_DECLARE_OUTPUT(AlphaImage, vtkImageData*); - BBTK_DECLARE_OUTPUT(BetaImage, vtkImageData*); - BBTK_PROCESS(Process); - void Process(); -//===== -// 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) -//===== -}; - -BBTK_BEGIN_DESCRIBE_BLACK_BOX(HeartAngles,bbtk::AtomicBlackBox); -BBTK_NAME("HeartAngles"); -BBTK_AUTHOR("carlos torres"); -BBTK_DESCRIPTION("No Description."); -BBTK_CATEGORY("empty"); -BBTK_INPUT(HeartAngles,Image,"Image",vtkImageData*,""); -BBTK_INPUT(HeartAngles,PlanePoint,"Punto en el plano componente X",std::vector,""); -BBTK_INPUT(HeartAngles,Vector,"Vector componente X",std::vector,""); -BBTK_INPUT(HeartAngles,Normal,"Normal componente X",std::vector,""); -BBTK_INPUT(HeartAngles,Point2,"Punto P2 componente X",std::vector,""); -BBTK_OUTPUT(HeartAngles,AlphaImage,"Alpha Image",vtkImageData*,""); -BBTK_OUTPUT(HeartAngles,BetaImage,"Beta Image",vtkImageData*,""); -BBTK_END_DESCRIBE_BLACK_BOX(HeartAngles); -//===== -// 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) -//===== -} -// EO namespace bbcreaVtk - -#endif // __bbcreaVtkHeartAngles_h_INCLUDED__ - diff --git a/lib/creaVtk/creaVtkHeartAngles.cpp b/lib/creaVtk/creaVtkHeartAngles.cpp deleted file mode 100644 index bb74fb9..0000000 --- a/lib/creaVtk/creaVtkHeartAngles.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* -# --------------------------------------------------------------------- -# -# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image -# pour la Sante) -# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton -# Previous Authors : Laurent Guigues, Jean-Pierre Roux -# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil -# -# This software is governed by the CeCILL-B license under French law and -# abiding by the rules of distribution of free software. You can use, -# modify and/ or redistribute the software under the terms of the CeCILL-B -# license as circulated by CEA, CNRS and INRIA at the following URL -# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -# or in the file LICENSE.txt. -# -# As a counterpart to the access to the source code and rights to copy, -# modify and redistribute granted by the license, users are provided only -# with a limited warranty and the software's author, the holder of the -# economic rights, and the successive licensors have only limited -# liability. -# -# The fact that you are presently reading this means that you have had -# knowledge of the CeCILL-B license and that you accept its terms. -# ------------------------------------------------------------------------ -*/ - -#include "creaVtkHeartAngles.h" -#include -#include -#include "vtkDoubleArray.h" -#include "vtkStructuredPoints.h" -#include "vtkPointData.h" -#include "vtkDataArray.h" - -creaVtkHeartAngles::creaVtkHeartAngles() -{ -} - -creaVtkHeartAngles::~creaVtkHeartAngles() -{ -} - -vtkImageData* creaVtkHeartAngles::getAlphaImage () -{ - return alphaImage; -} - -vtkImageData* creaVtkHeartAngles::getBetaImage () -{ - return betaImage; -}; - -double creaVtkHeartAngles::alpha (double P0a, double P0b,double P0c, double vx, double vy, double vz, double vxp, double vyp, double vzp) -{ - double a=P0a,b=P0b,c=P0c; - double x=vx,y=vy,z=vz; - double xp=vxp,yp=vyp,zp=vzp; - double alpha; - - //Calcular el ángulo que forman las rectas, sabiendo sus vectores directores. - //double cosAlpha = ( ( (x-a)*(xp-a) )+( (y-b)*(yp-b) )+( (z-c)*(zp-c) ) )/sqrt((( (pow(x,2.0)-pow(a,2.0)) + (pow(y,2.0)-pow(b,2.0)) + (pow(z,2.0)-pow(c,2.0)) )*( (pow(xp,2.0)-pow(a,2.0)) + (pow(yp,2.0)-pow(b,2.0)) + (pow(zp,2.0)-pow(c,2.0)) ) )); - double cosAlpha = ( ( x*xp )+( y*yp )+( z*zp ) )/(sqrt( pow(x,2.0) + pow(y,2.0) + pow(z,2.0) )*sqrt ( pow(xp,2.0) + pow(yp,2.0) + pow(zp,2.0) ) ); - - alpha = (180 * acos(fabs(cosAlpha)))/M_PI; - /*if((alpha<=90)&&(alpha>=0)){ - std::cout << " " << a << " " << b <<" " << c <<" " << x <<" " << y <<" " << z <<" " << xp <<" " << yp <<" " << zp; - std::cout << " cosAlpha: " << cosAlpha; - std::cout << " acos(fabs(cosalpha)) " << acos(fabs(cosAlpha)); - std::cout << " Angulo Alpha: " << alpha << std::endl ; }*/ - double ent = floor(alpha); - double al = alpha - ent; - double min = al * 60; - //std::cout << "minutos: " << min << std::endl; - //std::cout << "Alpha grados: "<< ent <<" minutos: " << floor(min) << " cos: " << cosAlpha << std::endl; - return alpha; -} - -double creaVtkHeartAngles::beta (double P0a, double P0b,double P0c, double P3x, double P3y, double P3z, double P4x, double P4y, double P4z) -{ - double a=P0a,b=P0b,c=P0c; - double x=P3x,y=P3y,z=P3z; - double xp=P4x,yp=P4y,zp=P4z; - double beta; - - //Calcular el ángulo que forman las rectas, sabiendo sus vectores directores. - //double cosBeta = ( ( (x-a)*(xp-a) )+( (y-b)*(yp-b) )+( (z-c)*(zp-c) ) )/sqrt((( (pow(x,2.0)-pow(a,2.0)) + (pow(y,2.0)-pow(b,2.0)) + (pow(z,2.0)-pow(c,2.0)) )*( (pow(xp,2.0)-pow(a,2.0)) + (pow(yp,2.0)-pow(b,2.0)) + (pow(zp,2.0)-pow(c,2.0)) ) )); - double cosBeta = ( ( x*xp )+( y*yp )+( z*zp ) )/(sqrt( pow(x,2.0) + pow(y,2.0) + pow(z,2.0) )*sqrt ( pow(xp,2.0) + pow(yp,2.0) + pow(zp,2.0) ) ); - beta = (180 * acos(fabs(cosBeta)))/M_PI; - //std::cout << "Angulo Beta: " << beta << std::endl; - double ent = floor(beta); - double al = beta - ent; - double min = al * 60; - //std::cout << "minutos: " << min << std::endl; - //std::cout << "Beta grados: "<< ent <<" minutos: " << floor(min) << " cos: " << cosBeta << std::endl; - return beta; -} - -double * creaVtkHeartAngles::vectorProjection (double nX, double nY, double nZ, double vX, double vY, double vZ) -{ - - //normalPlano - double nx=nX, ny=nY, nz=nZ; - //vector V - double vx=vX, vy=vY, vz=vZ; - - //vector proyectado - double proj [3]; - - proj[0]= vX - (nX*vX); - proj[1]= vY - (nY*vY); - proj[2]= vZ - (nZ*vZ); - - return proj; -} - -double *creaVtkHeartAngles::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) -{ - double puntoCorte[3]; - - double Plx1 = plx1, Ply1 = ply1, Plz1 = plz1, Plx2 = plx2, Ply2 = ply2, Plz2 = plz2, Plx3 = plx3, Ply3 = ply3, Plz3 = plz3; - double Px1 = px1, Py1 = py1, Pz1 = pz1, Px2 = px2, Py2 = py2, Pz2 = pz2; - - //Calculo del plano - - double aX = ((Ply2-Ply1)*(Plz3-Plz1)-(Ply3-Ply1)*(Plz2-Plz1)); - double a = (Plx1)*((Ply2-Ply1)*(Plz3-Plz1)-(Ply3-Ply1)*(Plz2-Plz1)); - - double bX = ((Plx2-Plx1)*(Plz3-Plz1)-(Plx3-Plx1)*(Plz2-Plz1)); - double b = (Ply1)*((Plx2-Plx1)*(Plz3-Plz1)-(Plx3-Plx1)*(Plz2-Plz1)); - - double cX = ((Plx2-Plx1)*(Ply3-Ply1)-(Plx3-Plx1)*(Ply2-Ply1)); - double c = (Plz1)*((Plx2-Plx1)*(Ply3-Ply1)-(Plx3-Plx1)*(Ply2-Ply1)); - - double r = a + b + c; - std::cout << "ecuacion: " << aX << "," << a << "," << bX << "," << b << "," << cX << "," << c << std::endl; - std::cout << "r: " << r << std::endl; - - //Calculo del vector director - - double vdirx = Px2 - Px1; - double vdiry = Py2 - Py1; - double vdirz = Pz2 - Pz1; - - std::cout << "vdirx: " << vdirx << " vdiry: " << vdiry << " vdirz: " << vdirz << std::endl; - - //Se igualan las formulas del plano y la recta - //x=Px1+vdirx, y=Py1+vdiry, z=Pz1+vdirz - - double eRes = aX*Px1 + bX*Py1 + cX*Pz1; - double eResT = aX*vdirx + bX*vdiry + cX*vdirz; - std::cout << "eRes: " << eRes << " eResT: " << eResT << std::endl; - //Calculo del punto solucion - if(eResT == 0){ - std::cout << "Soluciones infinitas... " << std::endl; - } - else { - double t = (((-1)*eRes)-r)/eResT; - - double Px = Px1 + (t * vdirx); - double Py = Py1 + (t * vdiry); - double Pz = Pz1 + (t * vdirz); - - std::cout << "px: " << Px << " py: " << Py << " pz: " << Pz << std::endl; - - puntoCorte[0] = Px; - puntoCorte[1] = Py; - puntoCorte[2] = Pz; - } - return puntoCorte; -} - -void creaVtkHeartAngles::calculateImages (vtkImageData* image, double Px, double Py, double Pz, double Nx, double Ny, double Nz, double p2x, double p2y, double p2z) -{ -std::cout << "CFT creaVtkHeartAngles::calculateImages Start"<SetExtent( image->GetExtent() ); - alphaImage->SetOrigin( image->GetOrigin() ); - alphaImage->SetSpacing( image->GetSpacing() ); - alphaImage->SetScalarTypeToUnsignedChar(); - alphaImage->SetNumberOfScalarComponents( image->GetNumberOfScalarComponents() ); - alphaImage->AllocateScalars(); - - 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 "<SetExtent( image->GetExtent() ); - betaImage->SetWholeExtent( image->GetWholeExtent() ); - betaImage->SetOrigin( image->GetOrigin() ); - betaImage->SetSpacing( image->GetSpacing() ); - betaImage->SetScalarTypeToUnsignedChar(); - betaImage->SetNumberOfScalarComponents( image->GetNumberOfScalarComponents() ); - betaImage->AllocateScalars(); - - unsigned char* pPix; - pPix = (unsigned char*)image->GetScalarPointer(); - double a; - double b; - - 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]<<" "<GetTuple3(i)[2]<< std::endl; - //} - - int i, j, k; - int numTuple=0; - - - for( k = 0 ; k < dim[2] ; k++ ) - { - for( j = 0 ; j < dim[1] ; j++ ) - { - for( i = 0 ; i < dim[0] ; i++ ) - { - //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 (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]); - - b = beta (Px, Py, Pz, - p2x, p2y, p2z, - vecProj[0], vecProj[1], vecProj[2]); - - //if(a>=90&&a<=360) { std::cout << " numTuple: " << numTuple << " a: " << a << " b: " << b << std::endl; } - if(p1==0&&p2==0&&p3==0){ - unsigned char *zPtr1 = (unsigned char *) alphaImage->GetScalarPointer( i , j , k ); - *zPtr1 = (unsigned char)0; - unsigned char *zPtr2 = (unsigned char *) betaImage->GetScalarPointer( i , j , k ); - *zPtr2 = (unsigned char)0; - }else{ - unsigned char *zPtr1 = (unsigned char *) alphaImage->GetScalarPointer( i , j , k ); - *zPtr1 = (unsigned char)a; - unsigned char *zPtr2 = (unsigned char *) betaImage->GetScalarPointer( i , j , k ); - *zPtr2 = (unsigned char)b; - } - } //for i - } // for j - } // for k - -std::cout << "CFT creaVtkHeartAngles::calculateImages End"<