]> Creatis software - clitk.git/commitdiff
- cosmetic
authordsarrut <dsarrut>
Mon, 19 Apr 2010 07:18:44 +0000 (07:18 +0000)
committerdsarrut <dsarrut>
Mon, 19 Apr 2010 07:18:44 +0000 (07:18 +0000)
filters/clitkMedianImageGenericFilter.txx
vv/vvImageReader.cxx
vv/vvImageReader.txx

index 81ef36eacf8c82284ea0b35b42b371bed477a845..696124c95749dfb5c97197718909a566524eacaa 100644 (file)
@@ -39,8 +39,6 @@ namespace clitk
     ADD_IMAGE_TYPE(Dim, float);
     ADD_IMAGE_TYPE(Dim, double);
     ADD_IMAGE_TYPE(Dim, unsigned short); 
-
-
   }
   //--------------------------------------------------------------------
   
@@ -49,8 +47,7 @@ namespace clitk
   template<class args_info_type>
   void MedianImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
     mArgsInfo=a;
-    SetIOVerbose(mArgsInfo.verbose_flag);
-  
+    SetIOVerbose(mArgsInfo.verbose_flag);  
 
     if (mArgsInfo.input_given) {
       SetInputFilename(mArgsInfo.input_arg);
@@ -59,10 +56,10 @@ namespace clitk
       SetOutputFilename(mArgsInfo.output_arg);
     }
 
-
   }
   //--------------------------------------------------------------------
 
+
   //--------------------------------------------------------------------
   // Update with the number of dimensions and the pixeltype
   //--------------------------------------------------------------------
@@ -71,56 +68,42 @@ namespace clitk
   void 
   MedianImageGenericFilter<args_info_type>::UpdateWithInputImageType()
   {
-     // Reading input
+    // Reading input
     typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
-// Typedef
-  typedef typename InputImageType::PixelType PixelType;
+    // Typedef
+    typedef typename InputImageType::PixelType PixelType;
 
-
-
- // typedef itk::Image<PixelType,InputImageType::ImageDimension> OutputImageType;
+    // typedef itk::Image<PixelType,InputImageType::ImageDimension> OutputImageType;
 
- // Main filter
-   
-     typedef itk::Image<uchar, InputImageType::ImageDimension> OutputImageType;
-     typename InputImageType::SizeType indexRadius;
+    // Main filter   
+    typedef itk::Image<PixelType, InputImageType::ImageDimension> OutputImageType;
+    class  InputImageType::SizeType indexRadius;
 
     // Filter
-    typedef itk::MedianImageFilter<InputImageType, OutputImageType> MedianImageFilterType;
-
+    typedef itk::MedianImageFilter<InputImageType, OutputImageType> MedianImageFilterType; 
     typename MedianImageFilterType::Pointer thresholdFilter=MedianImageFilterType::New();
     thresholdFilter->SetInput(input);
 
-
-indexRadius[0]=mArgsInfo.radius_arg[0];
-indexRadius[1]=mArgsInfo.radius_arg[1];
-indexRadius[2]=mArgsInfo.radius_arg[2];
-
-
-
+    indexRadius[0]=mArgsInfo.radius_arg[0];
+    indexRadius[1]=mArgsInfo.radius_arg[1];
+    indexRadius[2]=mArgsInfo.radius_arg[2];
   
-// indexRadius[0] = 1; 
- // indexRadius[1] = 1;
+    // indexRadius[0] = 1; 
   // indexRadius[1] = 1;
 
-thresholdFilter->SetRadius( indexRadius );
-  
+    thresholdFilter->SetRadius( indexRadius );  
 
     typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
- thresholdFilter->Update();
   thresholdFilter->Update();
      
-     // Write/Save results
-    this->template SetNextOutput<OutputImageType>(outputImage);
-
-   
-    }
+    // Write/Save results
+    this->template SetNextOutput<OutputImageType>(outputImage);   
+  }
   
   //--------------------------------------------------------------------
 
 }//end clitk
 
-
  
 #endif //#define clitkMedianImageGenericFilter_txx
 
index fde48ce89e5a7e99d462e833b30b5618472dee79..7cc0e569856b160276385b1f7c81d7e9ecba03ec 100644 (file)
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
-#ifndef vvImageReader_CXX
-#define vvImageReader_CXX
+  ======================================================================-====*/
+#ifndef VVIMAGEREADER_CXX
+#define VVIMAGEREADER_CXX
+
 #include <QApplication>
 #include <itkImageFileReader.h>
 #include "vvImageReader.h"
 #include "vvImageReader.txx"
 
-
-//====================================================================
+//------------------------------------------------------------------------------
 vvImageReader::vvImageReader()
 {
-    mImage = NULL;
-    mInputFilenames.resize(0);
-    mLastError = "";
-    mType = UNDEFINEDIMAGETYPE;
+  mImage = NULL;
+  mInputFilenames.resize(0);
+  mLastError = "";
+  mType = UNDEFINEDIMAGETYPE;
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 vvImageReader::~vvImageReader() { }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvImageReader::Update()
 {
-    Update(mType);
+  Update(mType);
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 void vvImageReader::Update(LoadedImageType type)
 {
-    itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(mInputFilenames[0].c_str(), itk::ImageIOFactory::ReadMode);
-    if (!reader) {
-        mLastError="Unable to read file.";
-    }
-    else {
-        reader->SetFileName(mInputFilenames[0]);
-        reader->ReadImageInformation();
-        if (mInputFilenames.size() > 1)
-            Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),type);
-        else
-            Update(reader->GetNumberOfDimensions(),reader->GetComponentTypeAsString(reader->GetComponentType()),type);
-    }
+  itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(mInputFilenames[0].c_str(), itk::ImageIOFactory::ReadMode);
+  if (!reader) {
+    mLastError="Unable to read file.";
+  }
+  else {
+    reader->SetFileName(mInputFilenames[0]);
+    reader->ReadImageInformation();
+    if (mInputFilenames.size() > 1)
+      Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),type);
+    else
+      Update(reader->GetNumberOfDimensions(),reader->GetComponentTypeAsString(reader->GetComponentType()),type);
+  }
 }
+//------------------------------------------------------------------------------
 
-//====================================================================
+
+//------------------------------------------------------------------------------
 void vvImageReader::Update(int dim,std::string inputPixelType, LoadedImageType type) {
-    //CALL_FOR_ALL_DIMS(dim,UpdateWithDim,inputPixelType);
-    mType = type;
-    mDim = dim;
-    mInputPixelType=inputPixelType;
-    this->start(); //Start heavy read operation in a separate thread
-    while (this->isRunning())
+  //CALL_FOR_ALL_DIMS(dim,UpdateWithDim,inputPixelType);
+  mType = type;
+  mDim = dim;
+  mInputPixelType=inputPixelType;
+  this->start(); //Start heavy read operation in a separate thread
+  while (this->isRunning())
     {
-        qApp->processEvents();
-        this->wait(50);
+      qApp->processEvents();
+      this->wait(50);
     }
 }
+//------------------------------------------------------------------------------
+
 
+//------------------------------------------------------------------------------
 void vvImageReader::run()
 {
-    switch(mDim)
-    {
-        case 2:
-            UpdateWithDim<2>(mInputPixelType);
-            break;;
-        case 3:
-            UpdateWithDim<3>(mInputPixelType);
-            break;;
-        case 4:
-            UpdateWithDim<4>(mInputPixelType);
-            break;;
-        default:
-            std::cerr << "dimension unknown in Update ! " << std::endl;
-    }
+  switch(mDim)     {
+  case 2:
+    UpdateWithDim<2>(mInputPixelType);
+    break;;
+  case 3:
+    UpdateWithDim<3>(mInputPixelType);
+    break;;
+  case 4:
+    UpdateWithDim<4>(mInputPixelType);
+    break;;
+  default:
+    std::cerr << "dimension unknown in Update ! " << std::endl;
+  }
 }
-//====================================================================
+//------------------------------------------------------------------------------
+
 
-//====================================================================
-/*void vvImageReader::Extract(int dim, std::string inputPixelType, int slice) {
-  CALL_FOR_ALL_DIMS(dim, ExtractWithDim, inputPixelType, slice);
-}*/
-//====================================================================
+//------------------------------------------------------------------------------
 void vvImageReader::SetInputFilename(const std::string & filename)
 {
-    mInputFilenames.resize(0);
-    mInputFilenames.push_back(filename);
+  mInputFilenames.resize(0);
+  mInputFilenames.push_back(filename);
 }
+//------------------------------------------------------------------------------
+
 
-//====================================================================
+//------------------------------------------------------------------------------
 void vvImageReader::SetInputFilenames(const std::vector<std::string> & filenames) {
-    mInputFilenames = filenames;
+  mInputFilenames = filenames;
 }
-//====================================================================
+//------------------------------------------------------------------------------
 
 #endif
 
index a22c5b73f46ee9495f77c941c5d07b1ce1834d2c..cfa389a7154e5cf803469d6b9da39030536b3949 100644 (file)
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
-#ifndef vvImageReader_TXX
-#define vvImageReader_TXX
-#include<string>
+  ======================================================================-====*/
 
+#ifndef VVIMAGEREADER_TXX
+#define VVIMAGEREADER_TXX
+
+#include <string>
 #include <itkImageFileReader.h>
 #include <itkImageSeriesReader.h>
-
 #include "clitkCommon.h"
 #include "itkImageToVTKImageFilter.h"
 #include "vvFromITK.h"
 #include "vvConstants.h"
 
+//----------------------------------------------------------------------------
 template<unsigned int VImageDimension>
-void vvImageReader::UpdateWithDim(std::string InputPixelType)
-{
-    if (mType == VECTORFIELD)
-        UpdateWithDimAndInputPixelType<itk::Vector<float,3>,VImageDimension>();
-    else if (InputPixelType == "short")
-        UpdateWithDimAndInputPixelType<short,VImageDimension>();
-    else if (InputPixelType == "unsigned_short")
-        UpdateWithDimAndInputPixelType<unsigned short,VImageDimension>();
-    else if (InputPixelType == "char")
-        UpdateWithDimAndInputPixelType<char,VImageDimension>();
-    else if (InputPixelType == "unsigned_char")
-        UpdateWithDimAndInputPixelType<unsigned char,VImageDimension>();
-    else if (InputPixelType == "int")
-        UpdateWithDimAndInputPixelType<int,VImageDimension>();
-    else if (InputPixelType == "double")
-        UpdateWithDimAndInputPixelType<double,VImageDimension>();
-    else if (InputPixelType == "float")
-        UpdateWithDimAndInputPixelType<float,VImageDimension>();
-    else
-        std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl;
+void vvImageReader::UpdateWithDim(std::string InputPixelType) {
+  if (mType == VECTORFIELD)
+    UpdateWithDimAndInputPixelType<itk::Vector<float,3>,VImageDimension>();
+  else if (InputPixelType == "short")
+    UpdateWithDimAndInputPixelType<short,VImageDimension>();
+  else if (InputPixelType == "unsigned_short")
+    UpdateWithDimAndInputPixelType<unsigned short,VImageDimension>();
+  else if (InputPixelType == "char")
+    UpdateWithDimAndInputPixelType<char,VImageDimension>();
+  else if (InputPixelType == "unsigned_char")
+    UpdateWithDimAndInputPixelType<unsigned char,VImageDimension>();
+  else if (InputPixelType == "int")
+    UpdateWithDimAndInputPixelType<int,VImageDimension>();
+  else if (InputPixelType == "double")
+    UpdateWithDimAndInputPixelType<double,VImageDimension>();
+  else if (InputPixelType == "float")
+    UpdateWithDimAndInputPixelType<float,VImageDimension>();
+  else
+    std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl;
 }
-//====================================================================
+//----------------------------------------------------------------------------
+
 
+//----------------------------------------------------------------------------
 template<class InputPixelType, unsigned int VImageDimension>
-void vvImageReader::UpdateWithDimAndInputPixelType()
-{
-    if (mType == MERGEDWITHTIME)   // In this case we can load the images
-                                   // one at the time to avoid excessive
-                                   // memory use
+void vvImageReader::UpdateWithDimAndInputPixelType() {
+
+  //  DD(mType);
+
+  if (mType == MERGEDWITHTIME)   // In this case we can load the images
+    // one at the time to avoid excessive
+    // memory use
     {
-        typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType;
-        typedef itk::ImageFileReader<InputImageType> ReaderType;
-        typename ReaderType::Pointer reader = ReaderType::New();
-        typedef itk::ImageToVTKImageFilter <InputImageType> ConnectorType;
-        typename ConnectorType::Pointer connector = ConnectorType::New();
-        connector->SetInput(reader->GetOutput());
-        mImage=vvImage::New();
-        for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
+      typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType;
+      typedef itk::ImageFileReader<InputImageType> ReaderType;
+      typename ReaderType::Pointer reader = ReaderType::New();
+      typedef itk::ImageToVTKImageFilter <InputImageType> ConnectorType;
+      typename ConnectorType::Pointer connector = ConnectorType::New();
+      connector->SetInput(reader->GetOutput());
+      mImage=vvImage::New();
+      for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
         {
-            std::cout << (*i) << std::endl;
-            reader->SetFileName(*i);
-            try {
-                reader->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while reading " << mInputFilenames[0].c_str()
-                    << " " << err << std::endl;
-                std::stringstream error;
-                error << err;
-                mLastError = error.str();
-                return;
-            }
-            try {
-                connector->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while setting vvImage from ITK (MERGEDWITHTIME)"
-                    << " " << err << std::endl;
-            }
-            vtkImageData *image = vtkImageData::New();
-            image->DeepCopy(connector->GetOutput());
-            mImage->AddImage(image);
+          std::cout << (*i) << std::endl;
+          reader->SetFileName(*i);
+          try {
+            reader->Update();
+          }
+          catch ( itk::ExceptionObject & err ) {
+            std::cerr << "Error while reading " << mInputFilenames[0].c_str()
+                      << " " << err << std::endl;
+            std::stringstream error;
+            error << err;
+            mLastError = error.str();
+            return;
+          }
+          try {
+            connector->Update();
+          }
+          catch ( itk::ExceptionObject & err ) {
+            std::cerr << "Error while setting vvImage from ITK (MERGEDWITHTIME)"
+                      << " " << err << std::endl;
+          }
+          vtkImageData *image = vtkImageData::New();
+          image->DeepCopy(connector->GetOutput());
+          mImage->AddImage(image);
         }
     }
-    else
+  else
     {
-        if (mInputFilenames.size() > 1)
+      if (mInputFilenames.size() > 1)
         {
-            typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
-            typedef itk::ImageSeriesReader<InputImageType> ReaderType;
-            typename ReaderType::Pointer reader = ReaderType::New();
-            for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
-                std::cout << (*i) << std::endl;
-            reader->SetFileNames(mInputFilenames);
-            //if (mUseAnObserver) {
-                //reader->AddObserver(itk::ProgressEvent(), mObserver);
-            //}
-            try {
-                reader->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while reading image series:" << err << std::endl;
-                std::stringstream error;
-                error << err;
-                mLastError = error.str();
-                return;
-            }
-            if (mType == IMAGEWITHTIME)
-                mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
-            else
-                mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
+          typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
+          typedef itk::ImageSeriesReader<InputImageType> ReaderType;
+          typename ReaderType::Pointer reader = ReaderType::New();
+          for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
+            std::cout << (*i) << std::endl;
+          reader->SetFileNames(mInputFilenames);
+          //if (mUseAnObserver) {
+          //reader->AddObserver(itk::ProgressEvent(), mObserver);
+          //}
+          try {
+            reader->Update();
+          }
+          catch ( itk::ExceptionObject & err ) {
+            std::cerr << "Error while reading image series:" << err << std::endl;
+            std::stringstream error;
+            error << err;
+            mLastError = error.str();
+            return;
+          }
+
+          // DD(reader->GetOutput()->GetImageDimension());
+          //           DD(reader->GetOutput()->GetNumberOfComponentsPerPixel());
+          //           for(unsigned int i=0; i <reader->GetOutput()->GetImageDimension(); i++) {
+          //             DD(reader->GetOutput()->GetSpacing()[i]);
+          //           }
+
+          if (mType == IMAGEWITHTIME)
+            mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
+          else
+            mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
         }
-        else
+      else
         {
-            typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
-            typedef itk::ImageFileReader<InputImageType> ReaderType;
-            typename ReaderType::Pointer reader = ReaderType::New();
-            reader->SetFileName(mInputFilenames[0]);
-            //if (mUseAnObserver) {
-                //reader->AddObserver(itk::ProgressEvent(), mObserver);
-            //}
-            try {
-                reader->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while reading " << mInputFilenames[0].c_str()
-                    << " " << err << std::endl;
-                std::stringstream error;
-                error << err;
-                mLastError = error.str();
-                return;
-            }
-            if (mType == IMAGEWITHTIME)
-                mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
-            else
-                mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
+          typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
+          typedef itk::ImageFileReader<InputImageType> ReaderType;
+          typename ReaderType::Pointer reader = ReaderType::New();
+          reader->SetFileName(mInputFilenames[0]);
+          //if (mUseAnObserver) {
+          //reader->AddObserver(itk::ProgressEvent(), mObserver);
+          //}
+          try {
+            reader->Update();
+          }
+          catch ( itk::ExceptionObject & err ) {
+            std::cerr << "Error while reading " << mInputFilenames[0].c_str()
+                      << " " << err << std::endl;
+            std::stringstream error;
+            error << err;
+            mLastError = error.str();
+            return;
+          }
+
+          // DD(reader->GetOutput()->GetImageDimension());
+          //           DD(reader->GetOutput()->GetNumberOfComponentsPerPixel());
+          //           for(unsigned int i=0; i <reader->GetOutput()->GetImageDimension(); i++) {
+          //             DD(reader->GetOutput()->GetSpacing()[i]);
+          //             DD(reader->GetOutput()->GetOrigin()[i]);
+          //           }
+
+
+          if (mType == IMAGEWITHTIME)
+            mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
+          else
+            mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
         }
     }
 }
-//====================================================================
+//----------------------------------------------------------------------------
 
 
 #endif /* end #define vvImageReader_TXX */