]> Creatis software - creaImageIO.git/commitdiff
*** empty log message ***
authorFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Wed, 4 May 2011 15:17:04 +0000 (15:17 +0000)
committerFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Wed, 4 May 2011 15:17:04 +0000 (15:17 +0000)
appli/TestWxSimpleView/itkVTKImageToImageFilter.h [new file with mode: 0644]
appli/TestWxSimpleView/itkVTKImageToImageFilter.txx [new file with mode: 0644]
appli/TestWxSimpleView/main.cxx
src/creaImageIOWxISimpleDlg.hpp

diff --git a/appli/TestWxSimpleView/itkVTKImageToImageFilter.h b/appli/TestWxSimpleView/itkVTKImageToImageFilter.h
new file mode 100644 (file)
index 0000000..39e9b56
--- /dev/null
@@ -0,0 +1,107 @@
+/*=========================================================================
+
+  Program:   Insight Segmentation & Registration Toolkit
+  Module:    $RCSfile: itkVTKImageToImageFilter.h,v $
+  Language:  C++
+  Date:      $Date: 2011/05/04 15:17:04 $
+  Version:   $Revision: 1.1 $
+
+  Copyright (c) 2002 Insight Consortium. All rights reserved.
+  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
+
+     This software is distributed WITHOUT ANY WARRANTY; without even 
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+#ifndef __itkVTKImageToImageFilter_h
+#define __itkVTKImageToImageFilter_h
+
+#include "itkVTKImageImport.h"
+#include "vtkImageExport.h"
+#include "vtkImageData.h"
+
+#ifndef vtkFloatingPointType
+#define vtkFloatingPointType float
+#endif
+
+namespace itk
+{
+  
+/** \class VTKImageToImageFilter
+ * \brief Converts a VTK image into an ITK image and plugs a 
+ *  vtk data pipeline to an ITK datapipeline.   
+ *
+ *  This class puts together an itkVTKImageImporter and a vtkImageExporter.
+ *  It takes care of the details related to the connection of ITK and VTK
+ *  pipelines. The User will perceive this filter as an adaptor to which
+ *  a vtkImage can be plugged as input and an itk::Image is produced as 
+ *  output.
+ * 
+ * \ingroup   ImageFilters     
+ */
+template <class TOutputImage >
+class ITK_EXPORT VTKImageToImageFilter : public ProcessObject
+{
+public:
+  /** Standard class typedefs. */
+  typedef VTKImageToImageFilter       Self;
+  typedef ProcessObject             Superclass;
+  typedef SmartPointer<Self>        Pointer;
+  typedef SmartPointer<const Self>  ConstPointer;
+
+  /** Method for creation through the object factory. */
+  itkNewMacro(Self);
+  
+  /** Run-time type information (and related methods). */
+  itkTypeMacro(VTKImageToImageFilter, ProcessObject);
+
+  /** Some typedefs. */
+  typedef TOutputImage OutputImageType;
+  typedef typename    OutputImageType::ConstPointer    OutputImagePointer;
+  typedef VTKImageImport< OutputImageType >   ImporterFilterType; 
+  typedef typename ImporterFilterType::Pointer         ImporterFilterPointer;
+  /** Get the output in the form of a vtkImage. 
+      This call is delegated to the internal vtkImageImporter filter  */
+  const OutputImageType *  GetOutput() const;
+
+  /** Set the input in the form of a vtkImageData */
+  void SetInput( vtkImageData * );
+
+  /** Return the internal VTK image exporter filter.
+      This is intended to facilitate users the access 
+      to methods in the exporter */
+  vtkImageExport * GetExporter() const;
+
+  /** Return the internal ITK image importer filter.
+      This is intended to facilitate users the access 
+      to methods in the importer */
+  ImporterFilterType * GetImporter() const;
+  
+  /** This call delegate the update to the importer */
+  void Update();
+  
+protected:
+  VTKImageToImageFilter(); 
+  virtual ~VTKImageToImageFilter(); 
+
+private:
+  VTKImageToImageFilter(const Self&); //purposely not implemented
+  void operator=(const Self&); //purposely not implemented
+
+  ImporterFilterPointer       m_Importer;
+  vtkImageExport            * m_Exporter;
+
+};
+
+} // end namespace itk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "itkVTKImageToImageFilter.txx"
+#endif
+
+#endif
+
+
+
diff --git a/appli/TestWxSimpleView/itkVTKImageToImageFilter.txx b/appli/TestWxSimpleView/itkVTKImageToImageFilter.txx
new file mode 100644 (file)
index 0000000..d74ee83
--- /dev/null
@@ -0,0 +1,144 @@
+/*=========================================================================
+
+  Program:   Insight Segmentation & Registration Toolkit
+  Module:    $RCSfile: itkVTKImageToImageFilter.txx,v $
+  Language:  C++
+  Date:      $Date: 2011/05/04 15:17:04 $
+  Version:   $Revision: 1.1 $
+
+  Copyright (c) 2002 Insight Consortium. All rights reserved.
+  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
+
+     This software is distributed WITHOUT ANY WARRANTY; without even 
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+#ifndef _itkVTKImageToImageFilter_txx
+#define _itkVTKImageToImageFilter_txx
+
+#include "itkVTKImageToImageFilter.h"
+
+namespace itk
+{
+
+
+
+/**
+ * Constructor
+ */
+template <class TOutputImage>
+VTKImageToImageFilter<TOutputImage>
+::VTKImageToImageFilter()
+{
+
+  m_Exporter = vtkImageExport::New();
+
+  m_Importer = ImporterFilterType::New();
+
+  m_Importer->SetUpdateInformationCallback( m_Exporter->GetUpdateInformationCallback());
+  m_Importer->SetPipelineModifiedCallback( m_Exporter->GetPipelineModifiedCallback());
+  m_Importer->SetWholeExtentCallback( m_Exporter->GetWholeExtentCallback());
+  m_Importer->SetSpacingCallback( m_Exporter->GetSpacingCallback());
+  m_Importer->SetOriginCallback( m_Exporter->GetOriginCallback());
+  m_Importer->SetScalarTypeCallback( m_Exporter->GetScalarTypeCallback());
+  m_Importer->SetNumberOfComponentsCallback( m_Exporter->GetNumberOfComponentsCallback());
+  m_Importer->SetPropagateUpdateExtentCallback( m_Exporter->GetPropagateUpdateExtentCallback());
+  m_Importer->SetUpdateDataCallback( m_Exporter->GetUpdateDataCallback());
+  m_Importer->SetDataExtentCallback( m_Exporter->GetDataExtentCallback());
+  m_Importer->SetBufferPointerCallback( m_Exporter->GetBufferPointerCallback());
+  m_Importer->SetCallbackUserData( m_Exporter->GetCallbackUserData());
+
+}
+
+
+
+
+/**
+ * Destructor
+ */
+template <class TOutputImage>
+VTKImageToImageFilter<TOutputImage>
+::~VTKImageToImageFilter()
+{
+  if( m_Exporter )
+    {
+    m_Exporter->Delete();
+    m_Exporter = 0;
+    }
+}
+
+
+
+/**
+ * Set a vtkImageData as input 
+ */
+template <class TOutputImage>
+void
+VTKImageToImageFilter<TOutputImage>
+::SetInput( vtkImageData * inputImage )
+{
+  m_Exporter->SetInput( inputImage );
+}
+
+
+
+/**
+ * Get an itk::Image as output
+ */
+template <class TOutputImage>
+const typename VTKImageToImageFilter<TOutputImage>::OutputImageType *
+VTKImageToImageFilter<TOutputImage>
+::GetOutput() const
+{
+  return m_Importer->GetOutput();
+}
+
+
+
+
+/**
+ * Get the exporter filter
+ */
+template <class TOutputImage>
+vtkImageExport *
+VTKImageToImageFilter<TOutputImage>
+::GetExporter() const
+{
+  return m_Exporter;
+}
+
+
+
+/**
+ * Get the importer filter
+ */
+template <class TOutputImage>
+typename VTKImageToImageFilter<TOutputImage>::ImporterFilterType *
+VTKImageToImageFilter<TOutputImage>
+::GetImporter() const
+{
+  return m_Importer;
+}
+
+
+
+
+/**
+ * Delegate the Update to the importer
+ */
+template <class TOutputImage>
+void
+VTKImageToImageFilter<TOutputImage>
+::Update()
+{
+  m_Importer->Update();
+}
+
+
+
+
+} // end namespace itk
+
+#endif
+
index d8d5c172005f2af5b673ae7cf433b7b94ff513d0..60898b99ee1b52dc21d188c50b18820c02b59836 100644 (file)
@@ -29,6 +29,7 @@ bool myApp::OnInit( )
    wxInitAllImageHandlers();
    std::vector <vtkImageData*> vtktest;
    std::vector<std::string> exts;
+   vtkImageData* im = vtkImageData::New();
   if(ITK_DIM_TO_TEST == 3)
    {
    
@@ -42,8 +43,11 @@ bool myApp::OnInit( )
           std::vector <ImageType::Pointer> test = x.getImagesSelected();
           // convert 3D itk to 3D vtk
           x.split3Din3Dvtk();
-           // get vtkImageData* vector
-       vtktest = x.getVtkImagesSelected();
+          vtktest = x.getVtkImagesSelected();
+         if(vtktest.size() >0)
+         {
+               crea::VtkBasicSlicer(vtktest.front());
+         }
   }
   else if (ITK_DIM_TO_TEST == 4)
   {
@@ -53,17 +57,19 @@ bool myApp::OnInit( )
          // get itkImage vector
          std::vector <ImageType::Pointer> test = x.getImagesSelected();
          // convert 4D itk to 3D vtk  with a directory to create tempory vtk files.
-      x.split4Din3Dvtk("d:/temp");
+      x.split4Din3Dvtk("d:/temp2");
          // get vtkImageData* vector
          vtktest = x.getVtkImagesSelected();
+         if(vtktest.size() >0)
+         {
+               crea::VtkBasicSlicer(vtktest.front());
+         }
        }
+   
   else{}
 
  
-  if(vtktest.size() >0)
-   {
-       crea::VtkBasicSlicer(vtktest.front());
-   }
+  
    return false;
 }
 
index e310a0736c7fe581568e3582964c7c5135bba59c..b2d813d6ddb83a5db0d0a0265e209280c73073d3 100644 (file)
@@ -3,14 +3,20 @@
 #include "creaImageIOWxGimmickReaderDialog.h"
 #include <itkAnalyzeImageIO.h>
 #include <itkImageFileReader.h>
+#include <itkImageSeriesReader.h>
 #include <itkImage.h>
 #include <itkImageSeriesWriter.h>
+#include <itkGDCMImageIO.h>
+#include <itkDICOMSeriesFileNames.h>
 #include <itkNumericSeriesFileNames.h>
-#include "itkImageToVTKImageFilter.h"
+#include <itkVectorImage.h>
+//#include "itkImageToVTKImageFilter.h"
+#include <itkOrientedImage.h>
 #include <vtkImageReader2.h>
 #include <boost/filesystem/path.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/utility.hpp>
+#include <creaVtkBasicSlicer.h>
 
 namespace creaImageIO
 {
@@ -74,7 +80,7 @@ namespace creaImageIO
           Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxISimpleDlg::OnReadGimmick ); 
 
           /// \TODO  Button to select Bruker directory
-       
+               m_dicom = true;
        Layout(); 
        
        }
@@ -178,24 +184,21 @@ namespace creaImageIO
                 dlg.ShowModal();
                 if (dlg.GetReturnCode() == wxID_OK)
             {
-       //              infoimage=_T("DICOM: ???_EED_???");
-//EED 07JUIN2010                       dlg.GetSelectedImages(m_results,3);
-                       std::vector<creaImageIO::OutStrGimmick> out;
-                       std::vector<std::string> attr;
-//                             attr.push_back("D0028_0010");
-//                             attr.push_back("D0008_0023");
-//                             attr.push_back("D0008_1070");
-                               dlg.stopReading();
-                               dlg.getSelected(out, attr,true,"");
-//                             crea::VtkBasicSlicer(out.front().img);
-                       //m_results.clear();
-                       int size=out.size();
-                       int ii;
-                       //for (ii=0;ii<size;ii++)
-                       //{
-                               //m_results.push_back(out[ii].img);
-                       //}
-
+                       std::vector<std::string> out;
+                       dlg.stopReading();
+                       dlg.GetSelectedFiles(out);
+                       if(m_dicom)
+                       {
+                               readDicomImg( out);
+                       }
+                       else
+                       {
+                               std::vector<std::string>::iterator ii = out.begin();
+                               for (;ii != out.end();ii++)
+                               {
+                                       readImg( (*ii).c_str() );
+                               }
+                       }
                        dlg.OnExit();
                 }
                 SetReturnCode( dlg.GetReturnCode() );
@@ -256,26 +259,58 @@ namespace creaImageIO
 
 
 
+         template <typename TImage> 
+         void WxISimpleDlg<TImage>::readDicomImg(const std::vector<std::string> &i_names)
+         {
+                 typedef itk::GDCMImageIO GDCMType;
+                 typedef itk::DICOMSeriesFileNames dicnames;
+                 GDCMType::Pointer gdcmIO = GDCMType::New(); 
+                 dicnames::Pointer generator = dicnames::New();
+//               generator->SetInput(i_names);
+                       typedef itk::ImageSeriesReader<TImage> ReaderType; 
+                   typename ReaderType::Pointer reader = ReaderType::New(); 
+                       reader->SetImageIO(gdcmIO);
+                       reader->SetFileNames(i_names);
+               //      reader->SetFileName( i_name ); 
+                       try 
+                       { 
+                               reader->Update(); 
+                       } 
+                       catch( itk::ExceptionObject & err ) 
+                       { 
+                       //      std::cout << "Caught an exception reading" << i_name << ": " << std::endl; 
+                               std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl; 
+                               throw err; 
+                       } 
+                       catch(...) 
+                       { 
+                               //std::cout << "Error while reading image " << i_name << std::endl; 
+                               throw; 
+                       } 
+                       m_Iresults.push_back(reader->GetOutput()); 
+    
+         }
+
+
+
+
          template <typename TImage> 
          void WxISimpleDlg<TImage>::split3Din3Dvtk()
          {
-                
-                int ii;
                  if ((m_Iresults).size() != 0)
                  {
-
-                         typename TImage::Pointer image = m_Iresults[0];
-                         image->GetImageDimension();
-                         typedef itk::ImageToVTKImageFilter< TImage > ConnectorType;
-                         ConnectorType::Pointer connector = ConnectorType::New();
-                         for(unsigned int i = 0 ;i < m_Iresults.size(); i++)
-                                  {
-                                               connector->SetInput(m_Iresults[i]);
-                                               connector->Update();
-                                               vtkImageData *im = vtkImageData::New();
-                                               im->ShallowCopy(connector->GetOutput());
-                                               m_Vresults.push_back(im);
-                                  }
+                         typedef itk::ImageToVTKImageFilter<  TImage > ConnectorType;
+                         ConnectorType::Pointer          connector = ConnectorType::New();
+             for(unsigned int i = 0 ;i < m_Iresults.size(); i++)
+                     {
+                                       connector->SetInput(m_Iresults[i]);
+                                       connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
+                                       connector->Update();
+                                       vtkImageData *im = vtkImageData::New();
+                                       im->ShallowCopy(connector->GetOutput());
+                                       im->Update();
+                                       m_Vresults.push_back(im);
+                    }
                  }
          }
 
@@ -289,15 +324,20 @@ namespace creaImageIO
                            typename TImage::Pointer image = m_Iresults[0];
                        
                                 // Size and dims for Input Image
-                               typedef itk::Size<4> iSize;
-                               typedef const itk::Size<4>::SizeValueType iSizeVal;
+                               typedef itk::Size<4> iSize; // TO REMOVE
+                               typedef const itk::Size<4>::SizeValueType iSizeVal; // TO REMOVE
                                iSize size = image->GetLargestPossibleRegion().GetSize();
                                iSizeVal *dims_size  = size.GetSize();
 
                                 // Output Type
-                                typedef itk::Image<short,3> ImageOutputType;  
+                                typedef itk::Image<unsigned char,3> ImageOutputType;  
                             typedef itk::ImageSeriesWriter<TImage, ImageOutputType >  SeriesWriterType;
                  
+                               /* typedef itk::VectorImage<short, 3> VectorImageType;
+                                VectorImageType::Pointer vect = VectorImageType::New();
+                                vect.*/
+
+
                                 SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
                                 seriesWriter->SetInput( image);
                        
@@ -305,22 +345,25 @@ namespace creaImageIO
                                 typedef itk::NumericSeriesFileNames NamesGeneratorType;
                                 NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
                                 namesGenerator->SetStartIndex(0);
-                                namesGenerator->SetEndIndex(dims_size[3]-1);
+                                namesGenerator->SetEndIndex(dims_size[3]-1); // TO CHANGE
                                 namesGenerator->SetIncrementIndex(1);
                                 std::string format = i_dir;
                             format += "/image%03d.vtk";
                                 namesGenerator->SetSeriesFormat( format.c_str() );
-      
-                                seriesWriter->SetFileNames( namesGenerator->GetFileNames() );
+                                const std::vector<std::string> names = namesGenerator->GetFileNames();
+                                seriesWriter->SetFileNames( names );
                        
                                 try
                                {
                                        seriesWriter->Update();
-                                       vtkImageReader2 *vReader =vtkImageReader2::New();
-                                       for(unsigned int i = 0 ;i < dims_size[3]; i++)
+                                       vtkImageReader2 *vReader = vtkImageReader2::New();
+                                       vReader->SetFilePrefix(".vtk");
+                                       std::vector<std::string>::const_iterator it = names.begin();
+                                       for( ;it !=  names.end(); ++it)
                                        {
-                                               vReader->SetFileName(namesGenerator->GetFileNames()[i].c_str());
+                                               vReader->SetFileName((*it).c_str());
                                                vReader->Update();
+                                               crea::VtkBasicSlicer(vReader->GetOutput());
                                                m_Vresults.push_back(vReader->GetOutput());
                                        }
                                }