X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkImageToImageGenericFilterBase.cxx;h=c538ac0d196a3773508918f110b093785a8be7e8;hb=d55f025b18f68066a52b8f33c2dc6481e82c2580;hp=bf68c9c28c9ebddc4541210d43bf1d0f0072eab7;hpb=1e034c70105f0926939acaaa27ddb46e904ae8bf;p=clitk.git diff --git a/common/clitkImageToImageGenericFilterBase.cxx b/common/clitkImageToImageGenericFilterBase.cxx index bf68c9c..c538ac0 100644 --- a/common/clitkImageToImageGenericFilterBase.cxx +++ b/common/clitkImageToImageGenericFilterBase.cxx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,8 +14,13 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ +===========================================================================**/ + +// clitk #include "clitkImageToImageGenericFilterBase.h" +#include "clitkExceptionObject.h" + +// itk #include //-------------------------------------------------------------------- @@ -25,11 +30,16 @@ clitk::ImageToImageGenericFilterBase::~ImageToImageGenericFilterBase() {} //-------------------------------------------------------------------- clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string n) - :mIOVerbose(false) + :m_IOVerbose(false) { - mFilterName = n; - mFailOnImageTypeError = true; - mReadOnDisk = true; + m_FilterName = n; + m_FailOnImageTypeError = true; + m_ReadOnDisk = true; + m_WriteOnDisk = true; + m_WriteCompression = false; + // m_LastError = ""; + // StopOnErrorOn(); + SetFilterBase(NULL); } //-------------------------------------------------------------------- @@ -37,7 +47,12 @@ clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector & filenames) { - mInputFilenames=filenames; + m_InputFilenames = filenames; + // in this case, assume by default that we DO want to write/read on + // disk (rather a command line tool, but not a vvTool. Can be + // changed with EnableReadOnDisk and EnableWriteOnDisk) + EnableReadOnDisk(true); + EnableWriteOnDisk(true); } //-------------------------------------------------------------------- @@ -45,7 +60,23 @@ void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector f; f.push_back(filename); SetInputFilenames(f); + // in this case, assume by default that we DO want to write/read on + // disk (rather a command line tool, but not a vvTool. Can be + // changed with EnableReadOnDisk and EnableWriteOnDisk) + EnableReadOnDisk(true); + EnableWriteOnDisk(true); } //-------------------------------------------------------------------- @@ -63,7 +99,12 @@ void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & filename) { - mInputFilenames.push_back(filename); + m_InputFilenames.push_back(filename); + // in this case, assume by default that we DO want to write/read on + // disk (rather a command line tool, but not a vvTool. Can be + // changed with EnableReadOnDisk and EnableWriteOnDisk) + EnableReadOnDisk(true); + EnableWriteOnDisk(true); } //-------------------------------------------------------------------- @@ -71,16 +112,16 @@ void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetOutputFilename(const std::string & filename) { - mOutputFilenames.clear(); - mOutputFilenames.push_back(filename); + m_OutputFilenames.clear(); + m_OutputFilenames.push_back(filename); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string & filename) +void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string filename) { - mOutputFilenames.push_back(filename); + m_OutputFilenames.push_back(filename); } //-------------------------------------------------------------------- @@ -88,8 +129,8 @@ void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string & //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector & filenames) { - mOutputFilenames.clear(); - std::copy(filenames.begin(),filenames.end(),mOutputFilenames.begin()); + m_OutputFilenames.clear(); + std::copy(filenames.begin(),filenames.end(),m_OutputFilenames.begin()); } //-------------------------------------------------------------------- @@ -97,8 +138,8 @@ void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector< //-------------------------------------------------------------------- std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename() { - assert(mOutputFilenames.size() == 1); - return mOutputFilenames.front(); + assert(m_OutputFilenames.size() == 1); + return m_OutputFilenames.front(); } //-------------------------------------------------------------------- @@ -107,21 +148,23 @@ std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename() void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(unsigned int& dim, \ std::string& pixeltype,unsigned int& components) { - if (mReadOnDisk && mInputFilenames.size()) { + if (m_ReadOnDisk && m_InputFilenames.size()) { int comp_temp,dim_temp; //clitkCommonImage takes ints - ReadImageDimensionAndPixelType(mInputFilenames[0], dim_temp, pixeltype,comp_temp); + ReadImageDimensionAndPixelType(m_InputFilenames[0], dim_temp, pixeltype,comp_temp); components=comp_temp; dim=dim_temp; } else { - if (mInputVVImages.size()) { - pixeltype=mInputVVImages[0]->GetScalarTypeAsString(); - dim=mInputVVImages[0]->GetNumberOfDimensions(); - components=mInputVVImages[0]->GetNumberOfScalarComponents(); - } else + if (m_InputVVImages.size()) { + pixeltype = m_InputVVImages[0]->GetScalarTypeAsITKString(); + dim = m_InputVVImages[0]->GetNumberOfDimensions(); + components = m_InputVVImages[0]->GetNumberOfScalarComponents(); + } else { + clitkExceptionMacro("No input given in this ImageToImageGenericFilter."); assert(false); //No input image, shouldn't happen + } } - if (mIOVerbose) { - std::cout << "Input is " << mDim << "D " << mPixelTypeName << "." << std::endl; + if (m_IOVerbose) { + std::cout << "Input is " << m_Dim << "D " << m_PixelTypeName << "." << std::endl; } } //-------------------------------------------------------------------- @@ -130,8 +173,8 @@ void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(un //-------------------------------------------------------------------- vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage () { - assert(mOutputVVImages.size()); - return mOutputVVImages[0]; + assert(m_OutputVVImages.size()); + return m_OutputVVImages[0]; } //-------------------------------------------------------------------- @@ -139,7 +182,7 @@ vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage () //-------------------------------------------------------------------- std::vector clitk::ImageToImageGenericFilterBase::GetOutputVVImages() { - return mOutputVVImages; + return m_OutputVVImages; } //-------------------------------------------------------------------- @@ -147,8 +190,13 @@ std::vector clitk::ImageToImageGenericFilterBase::GetOutputVVI //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer input) { - mInputVVImages.clear(); - mInputVVImages.push_back(input); + m_InputVVImages.clear(); + m_InputVVImages.push_back(input); + // in this case, assume by default that we do not want to write/read + // on disk (not a command line tool, but rather a vvTool. Can be + // changed with EnableReadOnDisk and EnableWriteOnDisk) + EnableReadOnDisk(false); + EnableWriteOnDisk(false); } //-------------------------------------------------------------------- @@ -156,7 +204,7 @@ void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer inp //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer input) { - mInputVVImages.push_back(input); + m_InputVVImages.push_back(input); } //-------------------------------------------------------------------- @@ -164,7 +212,12 @@ void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer inp //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector input) { - mInputVVImages=input; + m_InputVVImages=input; + // in this case, assume by default that we do not want to write/read + // on disk (not a command line tool, but rather a vvTool. Can be + // changed with EnableReadOnDisk and EnableWriteOnDisk) + EnableReadOnDisk(false); + EnableWriteOnDisk(false); } //-------------------------------------------------------------------- @@ -181,12 +234,14 @@ void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes() //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::ImageTypeError() { - std::cerr << "**Error** The filter <" << mFilterName << "> is not available for " - << mDim << "D images with pixel=" - << mPixelTypeName << " and " - << mNbOfComponents << " component." << std::endl; - std::cerr << GetAvailableImageTypes(); - exit(0); + std::ostringstream os; + os << "**Error** The filter <" << m_FilterName << "> is not available for " + << m_Dim << "D images with pixel=" + << m_PixelTypeName << " and " + << m_NbOfComponents << " component." << std::endl; + os << GetAvailableImageTypes(); + clitkExceptionMacro(os.str()); + // exit(0); } //-------------------------------------------------------------------- @@ -203,7 +258,7 @@ void clitk::ImageToImageGenericFilterBase::SetImageTypeError() //-------------------------------------------------------------------- const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName() { - return mFilterName; + return m_FilterName; } //-------------------------------------------------------------------- @@ -211,7 +266,7 @@ const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName() //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n) { - mFilterName = n; + m_FilterName = n; } //-------------------------------------------------------------------- @@ -219,7 +274,7 @@ void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n) //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b) { - mIOVerbose = b; + m_IOVerbose = b; } //-------------------------------------------------------------------- @@ -229,11 +284,11 @@ void clitk::ImageToImageGenericFilterBase::SetNextOutput::Pointer clitk::ImageToImageGenericFilterBase::GetInput >(unsigned int n); -#define DEF_SetNextOutput_And_GetInput_WithCompo(Compo, Dim) \ +#define DEF_SetNextOutput_And_GetInput_WithCompo(PixelType, Compo, Dim) \ template \ - void clitk::ImageToImageGenericFilterBase::SetNextOutput, Dim> >(itk::Image,Dim>::Pointer output); \ + void clitk::ImageToImageGenericFilterBase::SetNextOutput, Dim> >(itk::Image,Dim>::Pointer output); \ template \ - itk::Image, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput, Dim> >(unsigned int n); + itk::Image, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput, Dim> >(unsigned int n); DEF_SetNextOutput_And_GetInput(char, 2); DEF_SetNextOutput_And_GetInput(unsigned char, 2); @@ -251,15 +306,77 @@ DEF_SetNextOutput_And_GetInput(int, 3); DEF_SetNextOutput_And_GetInput(float, 3); DEF_SetNextOutput_And_GetInput(double, 3); -DEF_SetNextOutput_And_GetInput_WithCompo(2, 2); -DEF_SetNextOutput_And_GetInput_WithCompo(2, 3); -DEF_SetNextOutput_And_GetInput_WithCompo(2, 4); -DEF_SetNextOutput_And_GetInput_WithCompo(3, 2); -DEF_SetNextOutput_And_GetInput_WithCompo(3, 3); -DEF_SetNextOutput_And_GetInput_WithCompo(3, 4); -DEF_SetNextOutput_And_GetInput_WithCompo(4, 2); -DEF_SetNextOutput_And_GetInput_WithCompo(4, 3); -DEF_SetNextOutput_And_GetInput_WithCompo(4, 4); +/* +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 2, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 2, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 2, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 3, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 3, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 3, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 4, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 4, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned char, 4, 4); + +DEF_SetNextOutput_And_GetInput_WithCompo(char, 2, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(char, 2, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(char, 2, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(char, 3, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(char, 3, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(char, 3, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(char, 4, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(char, 4, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(char, 4, 4); + +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 2, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 2, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 2, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 3, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 3, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 3, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 4, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 4, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(unsigned short, 4, 4); + +DEF_SetNextOutput_And_GetInput_WithCompo(short, 2, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(short, 2, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(short, 2, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(short, 3, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(short, 3, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(short, 3, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(short, 4, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(short, 4, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(short, 4, 4); + +DEF_SetNextOutput_And_GetInput_WithCompo(int, 2, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(int, 2, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(int, 2, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(int, 3, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(int, 3, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(int, 3, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(int, 4, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(int, 4, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(int, 4, 4); +*/ + +DEF_SetNextOutput_And_GetInput_WithCompo(float, 2, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(float, 2, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(float, 2, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(float, 3, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(float, 3, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(float, 3, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(float, 4, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(float, 4, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(float, 4, 4); + +DEF_SetNextOutput_And_GetInput_WithCompo(double, 2, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(double, 2, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(double, 2, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(double, 3, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(double, 3, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(double, 3, 4); +DEF_SetNextOutput_And_GetInput_WithCompo(double, 4, 2); +DEF_SetNextOutput_And_GetInput_WithCompo(double, 4, 3); +DEF_SetNextOutput_And_GetInput_WithCompo(double, 4, 4); DEF_SetNextOutput_And_GetInput(char, 4); DEF_SetNextOutput_And_GetInput(unsigned char, 4); @@ -274,12 +391,12 @@ DEF_SetNextOutput_And_GetInput(double, 4); template void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output) { - if (mOutputFilenames.size()) { - clitk::writeImage(output, mOutputFilenames.front(), mIOVerbose); - mOutputFilenames.pop_front(); + if (m_WriteOnDisk && m_OutputFilenames.size()) { + clitk::writeImage(output, m_OutputFilenames.front(), m_IOVerbose, m_WriteCompression); + m_OutputFilenames.pop_front(); } - if (mInputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output - mOutputVVImages.push_back(vvImageFromITK(output)); + if (m_InputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output + m_OutputVVImages.push_back(vvImageFromITK(output)); } //-------------------------------------------------------------------- @@ -288,18 +405,40 @@ void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Poi template typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n) { - if (mReadOnDisk && mInputFilenames.size() > n) { - return clitk::readImage(mInputFilenames[n], mIOVerbose); + if (m_ReadOnDisk && m_InputFilenames.size() > n) { + return clitk::readImage(m_InputFilenames[n], m_IOVerbose); } else { - if (mInputVVImages.size() > n) - return typename ImageType::Pointer(const_cast(vvImageToITK(mInputVVImages[n]).GetPointer())); + if (m_InputVVImages.size() > n) + return typename ImageType::Pointer(const_cast(vvImageToITK(m_InputVVImages[n]).GetPointer())); else { assert(false); //No input, this shouldn't happen - return typename ImageType::Pointer(NULL); + return typename ImageType::Pointer((ImageType*)ITK_NULLPTR); } } } //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +// void clitk::ImageToImageGenericFilterBase::MustStop() +// { +// if (m_FilterBase != NULL) { +// m_FilterBase->SetMustStop(true); +// } +// } +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::ImageToImageGenericFilterBase::DeleteLastOutputImage() +{ + if (m_OutputVVImages.size()>1) { + m_OutputVVImages.pop_back(); + } +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +