]> Creatis software - creaVtk.git/commitdiff
2178 creaVtk Bug New High Error in creaVtkFromVtk4DToItk4 box output.
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Fri, 29 Nov 2013 16:36:52 +0000 (17:36 +0100)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Fri, 29 Nov 2013 16:36:52 +0000 (17:36 +0100)
bbtk_creaVtk_PKG/CMakeLists.txt
bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkFromVtk4DToItk4D.h
lib/creaVtk/CMakeLists.txt
lib/creaVtk/creaVtkFromVtk4DToItk4D.cpp
lib/creaVtk/creaVtkFromVtk4DToItk4D.h

index 31e2d705ba89e72625e67ada1fdb69460824926c..69a55c4e9088de718cb31418ac6f8035c77ccb15 100644 (file)
@@ -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)
index 4a79770af6c49d674d9a12b197d409e644969255..52ddeab5c97c9a0a10f8f0f2bcc313c1fa720f2a 100644 (file)
@@ -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<vtkImageData*> prs;
+printf("EED FromVtk4DToItk4D::Process 1\n ");
+//EED          creaVtkFromVtk4DToItk4D<vtkImageData*> 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)
index 7ff303cec6c097d7550a63df0beadbeb6687d7c6..772a837575e9ff0572272525492b8eb0faff09ac 100644 (file)
@@ -6,9 +6,11 @@
 #include "bbcreaVtk_EXPORT.h"
 #include "bbtkAtomicBlackBox.h"
 #include "iostream"
+
 #include "vtkImageData.h"
 #include <vector>
-#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<vtkImageData*> );
-       //Bug. Image type doesn't work.
-  //BBTK_DECLARE_OUTPUT(Out,std::vector<itk::Image< unsigned char > >);
+  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<vtkImageData*>,"");
-//BBTK_OUTPUT(FromVtk4DToItk4D,Out,"Itk image 4D",std::vector<itk::Image< unsigned char > >,"");
+ 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<vtkImageData*>,"");
+
+ BBTK_OUTPUT(FromVtk4DToItk4D,Out,"Itk image 4D", Image4DType::Pointer ,"");
+
 BBTK_END_DESCRIBE_BLACK_BOX(FromVtk4DToItk4D);
 
 }
index 3aa6bd68a5c7d8680d578215d155d6741991c584..93560c511892dba7b9196eab29e1db0bc56500ed 100644 (file)
@@ -88,7 +88,7 @@ IF ( BUILD_${LIBRARY_NAME} )
   #    ${WXWIDGETS_LIBRARIES}
   #    ${KWWidgets_LIBRARIES}
       ${VTK_LIBRARIES}
-  #    ${ITK_LIBRARIES}
+      ${ITK_LIBRARIES}
   #    ${GDCM_LIBRARIES}
   #    ${BOOST_LIBRARIES}
 
index a54c7d15816d4933eca2d10d045afc69eb457d09..369bcbb1a5835ec82a96e4435e22dd80d0878682 100644 (file)
 */
 
 #include "creaVtkFromVtk4DToItk4D.h"
-#include "itkImage.h"
-#include "itkImageLinearConstIteratorWithIndex.h"
-#include "itkImageRegionConstIterator.h"
+//#include "itkImage.h"
+
+//#include <itkImageRegionConstIteratorWithIndex.h>
+
+
+//#include "itkImageRegionConstIterator.h"
 #include "itkImageRegionIterator.h"
-#include "itkImageFileReader.h"
+// #include "itkImageFileReader.h"
 #include <vector>
 
-template <class TImage>
-creaVtkFromVtk4DToItk4D<TImage>::creaVtkFromVtk4DToItk4D()
+//template <class TImage>
+//creaVtkFromVtk4DToItk4D<TImage>::creaVtkFromVtk4DToItk4D()
+creaVtkFromVtk4DToItk4D::creaVtkFromVtk4DToItk4D()
 {
 }
 
-template <class TImage>
-creaVtkFromVtk4DToItk4D<TImage>::~creaVtkFromVtk4DToItk4D()
+//EED template <class TImage>
+//EED creaVtkFromVtk4DToItk4D<TImage>::~creaVtkFromVtk4DToItk4D()
+creaVtkFromVtk4DToItk4D::~creaVtkFromVtk4DToItk4D()
 {
 }
 
-template <class TImage>
-void creaVtkFromVtk4DToItk4D<TImage>::SetImage4D(TImage *image)
+//EED template <class TImage>
+//EED void creaVtkFromVtk4DToItk4D<TImage>::SetImage4D(TImage *image)
+//EED {
+//EED   _image4D = image;
+//EED }
+
+
+Image4DType::Pointer creaVtkFromVtk4DToItk4D::GetResult()
 {
-   _image4D = image;
+   return _image4D;
 }
 
-template <class TImage>
-void creaVtkFromVtk4DToItk4D<TImage>::SetImage4Dvtk(std::vector<vtkImageData*> image)
+
+//EED template <class TImage>
+//EED void creaVtkFromVtk4DToItk4D<TImage>::SetImage4Dvtk( std::vector<vtkImageData*> image)
+void creaVtkFromVtk4DToItk4D::SetImage4Dvtk( std::vector<vtkImageData*> image)
 {
-       image4Dvtk = image;
+       _image4Dvtk = image;
 }
 
-template <class TImage>
-std::vector<itk::Image< unsigned char > >  creaVtkFromVtk4DToItk4D<TImage>::Process()
+//EED template <class TImage>
+//EED std::vector<itk::Image< unsigned char > >  creaVtkFromVtk4DToItk4D<TImage>::Process()
+void creaVtkFromVtk4DToItk4D::Process()
 {
        /*      
        int dir;        
@@ -90,7 +104,10 @@ std::vector<itk::Image< unsigned char > >  creaVtkFromVtk4DToItk4D<TImage>::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<itk::Image< unsigned char > >  creaVtkFromVtk4DToItk4D<TImage>::Proc
   outputStart[3] = 0;
   outputRegion.SetSize( size );
   outputRegion.SetIndex( outputStart );
+*/
 
        /*
   ReaderType::Pointer reader = ReaderType::New();
@@ -139,35 +157,109 @@ std::vector<itk::Image< unsigned char > >  creaVtkFromVtk4DToItk4D<TImage>::Proc
               << reader->GetOutput()->GetRequestedRegion() << std::endl;
     return -1;
     }*/
+
+
+
+/* EED
        std::vector<ImageType::Pointer> 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
index 3518f470bd937ba56b30da7a65b9832f406d2f1d..3cc462e8a62f8713cbb9a6ebd32fc7351ede2a25 100644 (file)
 #define _CREAVTKFROMVTK4DTOITK4D_H_
 #include "vtkImageData.h"
 #include <vector>
+
 #include "itkImage.h"
-template <class TImage>
+
+//EED template <class TImage>
+
+typedef unsigned short PixelType; 
+typedef itk::Image< PixelType, 4 >  Image4DType;
+
 class creaVtkFromVtk4DToItk4D
 {
 public :
   creaVtkFromVtk4DToItk4D();
   ~creaVtkFromVtk4DToItk4D();
-       void SetImage4D(TImage *image);
-       void SetImage4Dvtk(std::vector<vtkImageData*> image);
-       std::vector<itk::Image<unsigned char> > Process();
 
+//EED  void SetImage4D(TImage *image);
+
+       void SetImage4Dvtk(std::vector<vtkImageData*> image);
+//EED  std::vector<itk::Image<unsigned char> > Process();
+       void Process();
+       Image4DType::Pointer GetResult();
 protected:
                
 private:
-       TImage* _image4D;
-       std::vector<vtkImageData*>  image4Dvtk;
+
+//EED  TImage* _image4D;
+//EED2 itk::Image<unsigned char> _image4D;
+
+     Image4DType::Pointer      _image4D; 
+     std::vector<vtkImageData*> _image4Dvtk;
 };
 
+
 //-end of _CREAVTKFROMVTK4DTOITK4D_H_------------------------------------------------------
 #endif