From b6cfdecc2f880a7015d8f5a73174a0361cfe7924 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Mon, 19 Apr 2010 07:18:44 +0000 Subject: [PATCH] - cosmetic --- filters/clitkMedianImageGenericFilter.txx | 57 ++--- vv/vvImageReader.cxx | 124 ++++++----- vv/vvImageReader.txx | 242 ++++++++++++---------- 3 files changed, 219 insertions(+), 204 deletions(-) diff --git a/filters/clitkMedianImageGenericFilter.txx b/filters/clitkMedianImageGenericFilter.txx index 81ef36e..696124c 100644 --- a/filters/clitkMedianImageGenericFilter.txx +++ b/filters/clitkMedianImageGenericFilter.txx @@ -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 void MedianImageGenericFilter::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::UpdateWithInputImageType() { - // Reading input + // Reading input typename InputImageType::Pointer input = this->template GetInput(0); -// Typedef - typedef typename InputImageType::PixelType PixelType; + // Typedef + typedef typename InputImageType::PixelType PixelType; - - - - // typedef itk::Image OutputImageType; + // typedef itk::Image OutputImageType; - // Main filter - - typedef itk::Image OutputImageType; - typename InputImageType::SizeType indexRadius; + // Main filter + typedef itk::Image OutputImageType; + class InputImageType::SizeType indexRadius; // Filter - typedef itk::MedianImageFilter MedianImageFilterType; - - + typedef itk::MedianImageFilter 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(outputImage); - - - } + // Write/Save results + this->template SetNextOutput(outputImage); + } //-------------------------------------------------------------------- }//end clitk - #endif //#define clitkMedianImageGenericFilter_txx diff --git a/vv/vvImageReader.cxx b/vv/vvImageReader.cxx index fde48ce..7cc0e56 100644 --- a/vv/vvImageReader.cxx +++ b/vv/vvImageReader.cxx @@ -14,96 +14,108 @@ - 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 #include #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 & filenames) { - mInputFilenames = filenames; + mInputFilenames = filenames; } -//==================================================================== +//------------------------------------------------------------------------------ #endif diff --git a/vv/vvImageReader.txx b/vv/vvImageReader.txx index a22c5b7..cfa389a 100644 --- a/vv/vvImageReader.txx +++ b/vv/vvImageReader.txx @@ -14,140 +14,160 @@ - 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 + ======================================================================-====*/ +#ifndef VVIMAGEREADER_TXX +#define VVIMAGEREADER_TXX + +#include #include #include - #include "clitkCommon.h" #include "itkImageToVTKImageFilter.h" #include "vvFromITK.h" #include "vvConstants.h" +//---------------------------------------------------------------------------- template -void vvImageReader::UpdateWithDim(std::string InputPixelType) -{ - if (mType == VECTORFIELD) - UpdateWithDimAndInputPixelType,VImageDimension>(); - else if (InputPixelType == "short") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "unsigned_short") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "char") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "unsigned_char") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "int") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "double") - UpdateWithDimAndInputPixelType(); - else if (InputPixelType == "float") - UpdateWithDimAndInputPixelType(); - else - std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl; +void vvImageReader::UpdateWithDim(std::string InputPixelType) { + if (mType == VECTORFIELD) + UpdateWithDimAndInputPixelType,VImageDimension>(); + else if (InputPixelType == "short") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "unsigned_short") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "char") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "unsigned_char") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "int") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "double") + UpdateWithDimAndInputPixelType(); + else if (InputPixelType == "float") + UpdateWithDimAndInputPixelType(); + else + std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl; } -//==================================================================== +//---------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- template -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 ReaderType; - typename ReaderType::Pointer reader = ReaderType::New(); - typedef itk::ImageToVTKImageFilter ConnectorType; - typename ConnectorType::Pointer connector = ConnectorType::New(); - connector->SetInput(reader->GetOutput()); - mImage=vvImage::New(); - for (std::vector::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++) + typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType; + typedef itk::ImageFileReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + typedef itk::ImageToVTKImageFilter ConnectorType; + typename ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(reader->GetOutput()); + mImage=vvImage::New(); + for (std::vector::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 ReaderType; - typename ReaderType::Pointer reader = ReaderType::New(); - for (std::vector::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(reader->GetOutput(),true); - else - mImage=vvImageFromITK(reader->GetOutput()); + typedef itk::Image< InputPixelType, VImageDimension > InputImageType; + typedef itk::ImageSeriesReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + for (std::vector::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 GetOutput()->GetImageDimension(); i++) { + // DD(reader->GetOutput()->GetSpacing()[i]); + // } + + if (mType == IMAGEWITHTIME) + mImage=vvImageFromITK(reader->GetOutput(),true); + else + mImage=vvImageFromITK(reader->GetOutput()); } - else + else { - typedef itk::Image< InputPixelType, VImageDimension > InputImageType; - typedef itk::ImageFileReader 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(reader->GetOutput(),true); - else - mImage=vvImageFromITK(reader->GetOutput()); + typedef itk::Image< InputPixelType, VImageDimension > InputImageType; + typedef itk::ImageFileReader 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 GetOutput()->GetImageDimension(); i++) { + // DD(reader->GetOutput()->GetSpacing()[i]); + // DD(reader->GetOutput()->GetOrigin()[i]); + // } + + + if (mType == IMAGEWITHTIME) + mImage=vvImageFromITK(reader->GetOutput(),true); + else + mImage=vvImageFromITK(reader->GetOutput()); } } } -//==================================================================== +//---------------------------------------------------------------------------- #endif /* end #define vvImageReader_TXX */ -- 2.47.1