From: Eduardo DAVILA Date: Fri, 29 Nov 2013 16:36:52 +0000 (+0100) Subject: 2178 creaVtk Bug New High Error in creaVtkFromVtk4DToItk4 box output. X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=7c3081ccca0482d832635a20482f2391e9a360b8;p=creaVtk.git 2178 creaVtk Bug New High Error in creaVtkFromVtk4DToItk4 box output. --- diff --git a/bbtk_creaVtk_PKG/CMakeLists.txt b/bbtk_creaVtk_PKG/CMakeLists.txt index 31e2d70..69a55c4 100644 --- a/bbtk_creaVtk_PKG/CMakeLists.txt +++ b/bbtk_creaVtk_PKG/CMakeLists.txt @@ -63,7 +63,7 @@ SET(USE_BOOST ON) #=========================================================================== # UNCOMMENT EACH LIBRARY NEEDED (WILL BE FOUND AND USED AUTOMATICALLY) SET(${BBTK_PACKAGE_NAME}_USE_VTK ON) -# SET(${BBTK_PACKAGE_NAME}_USE_ITK ON) + SET(${BBTK_PACKAGE_NAME}_USE_ITK ON) # SET(${BBTK_PACKAGE_NAME}_USE_GDCM ON) # SET(${BBTK_PACKAGE_NAME}_USE_GDCM_VTK ON) # SET(${BBTK_PACKAGE_NAME}_USE_GSMIS ON) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.cxx index 4a79770..52ddeab 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.cxx @@ -1,11 +1,12 @@ -//===== + //===== // 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 "bbcreaVtkFromVtk4DToItk4D.h" #include "bbcreaVtkPackage.h" -#include "creaVtkFromVtk4DToItk4D.h" + #include "vtkImageData.h" #include "itkImage.h" + namespace bbcreaVtk { @@ -16,10 +17,15 @@ BBTK_BLACK_BOX_IMPLEMENTATION(FromVtk4DToItk4D,bbtk::AtomicBlackBox); //===== void FromVtk4DToItk4D::Process() { - creaVtkFromVtk4DToItk4D prs; +printf("EED FromVtk4DToItk4D::Process 1\n "); +//EED creaVtkFromVtk4DToItk4D prs; + creaVtkFromVtk4DToItk4D prs; +printf("EED FromVtk4DToItk4D::Process 2\n "); prs.SetImage4Dvtk(bbGetInputIn()); - //Bug. Cant declare output image in .h - //bbSetOutputOut(prs.Process()); +printf("EED FromVtk4DToItk4D::Process 3\n "); + //CT Bug. Cant declare output image in .h + prs.Process(); +//EED bbSetOutputOut( ); } //===== // 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) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.h b/bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.h index 7ff303c..772a837 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.h @@ -6,9 +6,11 @@ #include "bbcreaVtk_EXPORT.h" #include "bbtkAtomicBlackBox.h" #include "iostream" + #include "vtkImageData.h" #include -#include "itkImage.h" +//#include "itkImage.h" +#include "creaVtkFromVtk4DToItk4D.h" namespace bbcreaVtk { @@ -18,22 +20,23 @@ class bbcreaVtk_EXPORT FromVtk4DToItk4D public bbtk::AtomicBlackBox { BBTK_BLACK_BOX_INTERFACE(FromVtk4DToItk4D,bbtk::AtomicBlackBox); - BBTK_DECLARE_INPUT(In,std::vector ); - //Bug. Image type doesn't work. - //BBTK_DECLARE_OUTPUT(Out,std::vector >); + BBTK_DECLARE_OUTPUT(Out, Image4DType::Pointer ); BBTK_PROCESS(Process); void Process(); }; BBTK_BEGIN_DESCRIBE_BLACK_BOX(FromVtk4DToItk4D,bbtk::AtomicBlackBox); -BBTK_NAME("FromVtk4DToItk4D"); -BBTK_AUTHOR("Carlos Torres"); -BBTK_DESCRIPTION("carlos.torres@creatis.insa-lyon.fr -"); -BBTK_CATEGORY("empty"); -BBTK_INPUT(FromVtk4DToItk4D,In,"Vtk image 4D",std::vector,""); -//BBTK_OUTPUT(FromVtk4DToItk4D,Out,"Itk image 4D",std::vector >,""); + BBTK_NAME("FromVtk4DToItk4D"); + BBTK_AUTHOR("Carlos Torres"); + BBTK_DESCRIPTION("carlos.torres@creatis.insa-lyon.fr -"); + BBTK_CATEGORY("empty"); + + BBTK_INPUT(FromVtk4DToItk4D,In,"Vtk image 4D",std::vector,""); + + BBTK_OUTPUT(FromVtk4DToItk4D,Out,"Itk image 4D", Image4DType::Pointer ,""); + BBTK_END_DESCRIBE_BLACK_BOX(FromVtk4DToItk4D); } diff --git a/lib/creaVtk/CMakeLists.txt b/lib/creaVtk/CMakeLists.txt index 3aa6bd6..93560c5 100644 --- a/lib/creaVtk/CMakeLists.txt +++ b/lib/creaVtk/CMakeLists.txt @@ -88,7 +88,7 @@ IF ( BUILD_${LIBRARY_NAME} ) # ${WXWIDGETS_LIBRARIES} # ${KWWidgets_LIBRARIES} ${VTK_LIBRARIES} - # ${ITK_LIBRARIES} + ${ITK_LIBRARIES} # ${GDCM_LIBRARIES} # ${BOOST_LIBRARIES} diff --git a/lib/creaVtk/creaVtkFromVtk4DToItk4D.cpp b/lib/creaVtk/creaVtkFromVtk4DToItk4D.cpp index a54c7d1..369bcbb 100644 --- a/lib/creaVtk/creaVtkFromVtk4DToItk4D.cpp +++ b/lib/creaVtk/creaVtkFromVtk4DToItk4D.cpp @@ -26,37 +26,51 @@ */ #include "creaVtkFromVtk4DToItk4D.h" -#include "itkImage.h" -#include "itkImageLinearConstIteratorWithIndex.h" -#include "itkImageRegionConstIterator.h" +//#include "itkImage.h" + +//#include + + +//#include "itkImageRegionConstIterator.h" #include "itkImageRegionIterator.h" -#include "itkImageFileReader.h" +// #include "itkImageFileReader.h" #include -template -creaVtkFromVtk4DToItk4D::creaVtkFromVtk4DToItk4D() +//template +//creaVtkFromVtk4DToItk4D::creaVtkFromVtk4DToItk4D() +creaVtkFromVtk4DToItk4D::creaVtkFromVtk4DToItk4D() { } -template -creaVtkFromVtk4DToItk4D::~creaVtkFromVtk4DToItk4D() +//EED template +//EED creaVtkFromVtk4DToItk4D::~creaVtkFromVtk4DToItk4D() +creaVtkFromVtk4DToItk4D::~creaVtkFromVtk4DToItk4D() { } -template -void creaVtkFromVtk4DToItk4D::SetImage4D(TImage *image) +//EED template +//EED void creaVtkFromVtk4DToItk4D::SetImage4D(TImage *image) +//EED { +//EED _image4D = image; +//EED } + + +Image4DType::Pointer creaVtkFromVtk4DToItk4D::GetResult() { - _image4D = image; + return _image4D; } -template -void creaVtkFromVtk4DToItk4D::SetImage4Dvtk(std::vector image) + +//EED template +//EED void creaVtkFromVtk4DToItk4D::SetImage4Dvtk( std::vector image) +void creaVtkFromVtk4DToItk4D::SetImage4Dvtk( std::vector image) { - image4Dvtk = image; + _image4Dvtk = image; } -template -std::vector > creaVtkFromVtk4DToItk4D::Process() +//EED template +//EED std::vector > creaVtkFromVtk4DToItk4D::Process() +void creaVtkFromVtk4DToItk4D::Process() { /* int dir; @@ -90,7 +104,10 @@ std::vector > creaVtkFromVtk4DToItk4D::Proc } } */ - const unsigned int Dimension = 4; + + +/* EED2 + const unsigned int Dimension = 4; typedef unsigned char PixelType; typedef itk::Image< PixelType, Dimension > ImageType; typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType; @@ -117,6 +134,7 @@ std::vector > creaVtkFromVtk4DToItk4D::Proc outputStart[3] = 0; outputRegion.SetSize( size ); outputRegion.SetIndex( outputStart ); +*/ /* ReaderType::Pointer reader = ReaderType::New(); @@ -139,35 +157,109 @@ std::vector > creaVtkFromVtk4DToItk4D::Proc << reader->GetOutput()->GetRequestedRegion() << std::endl; return -1; }*/ + + + +/* EED std::vector outputImage4D; - for(int k = 0 ; k < image4Dvtk.size() ; k++){ + for(int k = 0 ; k < _image4Dvtk.size() ; k++) + { ImageType::Pointer outputImage = ImageType::New(); outputImage->SetRegions( outputRegion ); - const ImageType::SpacingType& spacing = image4Dvtk[k]->GetSpacing(); - const ImageType::PointType& inputOrigin = image4Dvtk[k]->GetOrigin(); + const ImageType::SpacingType& spacing = _image4Dvtk[k]->GetSpacing(); + const ImageType::PointType& inputOrigin = _image4Dvtk[k]->GetOrigin(); double outputOrigin[ Dimension ]; for(unsigned int i=0; i< Dimension; i++) - { + { outputOrigin[i] = inputOrigin[i] + spacing[i] * inputStart[i]; - } + } // for outputImage->SetSpacing( spacing ); outputImage->SetOrigin( outputOrigin ); outputImage->Allocate(); - ConstIteratorType inputIt( image4Dvtk[k], inputRegion ); + ConstIteratorType inputIt( _image4Dvtk[k], inputRegion ); IteratorType outputIt( outputImage, outputRegion ); inputIt.GoToBegin(); outputIt.GoToBegin(); while( !outputIt.IsAtEnd() ) - { + { outputIt.Set( inputIt.Get() ); ++inputIt; ++outputIt; - } - outputImage4D[k]=outputImage; + } // while +//EED outputImage4D[k]=outputImage; + } // for k +//EED return outputImage4D; + +*/ + + + +// http://www.itk.org/pipermail/insight-users/2003-December/005796.html +// http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/InvertIntensityImageFilter + + + int ext[6]; + int dimX, dimY, dimZ; + long int sizeimage; + unsigned int k, i; + + _image4Dvtk[0]->GetWholeExtent(ext); + dimX = ext[1]-ext[0]+1; + dimY = ext[3]-ext[2]+1; + dimZ = ext[5]-ext[4]+1; + sizeimage = dimX*dimY*dimZ; + + + + typedef itk::ImageRegionIterator< Image4DType > Iterator4D; +// typedef itk::ImageRegionConstIterator< Image4DType > Iterator4D; +// typedef itk::ImageRegionConstIteratorWithIndex< Image4DType > Iterator4D; + + + _image4D = Image4DType::New(); + + Image4DType::RegionType region; + Image4DType::IndexType start; + start[0] = 0; + start[1] = 0; + start[2] = 0; + start[3] = 0; + + Image4DType::SizeType size; + unsigned int NumRows = dimX; + unsigned int NumCols = dimY; + unsigned int NumSlices = dimZ; + unsigned int NumVolumes = _image4Dvtk.size(); + size[0] = NumRows; + size[1] = NumCols; + size[2] = NumSlices; + size[3] = NumVolumes; + + region.SetSize(size); + region.SetIndex(start); + + _image4D->SetRegions(region); + _image4D->Allocate(); + + +// Iterator4D it4( image4D, image4D->GetBufferedRegion() ); + Iterator4D it4( _image4D, _image4D->GetLargestPossibleRegion() ); + it4.GoToBegin(); + for(k = 0 ; k < _image4Dvtk.size() ; k++) + { + unsigned short * ptrVtkImage; + ptrVtkImage = (unsigned short *)_image4Dvtk[k]->GetScalarPointer(); + for (i=0; i< sizeimage;i++) + { + it4.Set( *ptrVtkImage ); +// *it4 = *ptrVtkImage; +// unsigned short q= it4.Get(); + ++it4; + ptrVtkImage++; + } } - return outputImage4D; } //--------------------------------------------- //Method template diff --git a/lib/creaVtk/creaVtkFromVtk4DToItk4D.h b/lib/creaVtk/creaVtkFromVtk4DToItk4D.h index 3518f47..3cc462e 100644 --- a/lib/creaVtk/creaVtkFromVtk4DToItk4D.h +++ b/lib/creaVtk/creaVtkFromVtk4DToItk4D.h @@ -29,23 +29,38 @@ #define _CREAVTKFROMVTK4DTOITK4D_H_ #include "vtkImageData.h" #include + #include "itkImage.h" -template + +//EED template + +typedef unsigned short PixelType; +typedef itk::Image< PixelType, 4 > Image4DType; + class creaVtkFromVtk4DToItk4D { public : creaVtkFromVtk4DToItk4D(); ~creaVtkFromVtk4DToItk4D(); - void SetImage4D(TImage *image); - void SetImage4Dvtk(std::vector image); - std::vector > Process(); +//EED void SetImage4D(TImage *image); + + void SetImage4Dvtk(std::vector image); +//EED std::vector > Process(); + void Process(); + Image4DType::Pointer GetResult(); + protected: private: - TImage* _image4D; - std::vector image4Dvtk; + +//EED TImage* _image4D; +//EED2 itk::Image _image4D; + + Image4DType::Pointer _image4D; + std::vector _image4Dvtk; }; + //-end of _CREAVTKFROMVTK4DTOITK4D_H_------------------------------------------------------ #endif