From: dsarrut Date: Wed, 30 Jun 2010 05:56:19 +0000 (+0000) Subject: set and get macro like itk X-Git-Tag: v1.2.0~602 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=28a696a732734608d0c32608c80c890a164872c4;p=clitk.git set and get macro like itk --- diff --git a/common/clitkImageToImageGenericFilterBase.cxx b/common/clitkImageToImageGenericFilterBase.cxx index bf68c9c..2d1679f 100644 --- a/common/clitkImageToImageGenericFilterBase.cxx +++ b/common/clitkImageToImageGenericFilterBase.cxx @@ -25,11 +25,12 @@ 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_LastError = ""; } //-------------------------------------------------------------------- @@ -37,7 +38,7 @@ clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector & filenames) { - mInputFilenames=filenames; + m_InputFilenames = filenames; } //-------------------------------------------------------------------- @@ -45,7 +46,7 @@ void clitk::ImageToImageGenericFilterBase::SetInputFilenames(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 +98,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 +108,21 @@ 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(); + if (m_InputVVImages.size()) { + pixeltype=m_InputVVImages[0]->GetScalarTypeAsString(); + dim=m_InputVVImages[0]->GetNumberOfDimensions(); + components=m_InputVVImages[0]->GetNumberOfScalarComponents(); } else 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 +131,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 +140,7 @@ vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage () //-------------------------------------------------------------------- std::vector clitk::ImageToImageGenericFilterBase::GetOutputVVImages() { - return mOutputVVImages; + return m_OutputVVImages; } //-------------------------------------------------------------------- @@ -147,8 +148,8 @@ 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); } //-------------------------------------------------------------------- @@ -156,7 +157,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 +165,7 @@ void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer inp //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector input) { - mInputVVImages=input; + m_InputVVImages=input; } //-------------------------------------------------------------------- @@ -181,10 +182,10 @@ 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 << "**Error** The filter <" << m_FilterName << "> is not available for " + << m_Dim << "D images with pixel=" + << m_PixelTypeName << " and " + << m_NbOfComponents << " component." << std::endl; std::cerr << GetAvailableImageTypes(); exit(0); } @@ -203,7 +204,7 @@ void clitk::ImageToImageGenericFilterBase::SetImageTypeError() //-------------------------------------------------------------------- const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName() { - return mFilterName; + return m_FilterName; } //-------------------------------------------------------------------- @@ -211,7 +212,7 @@ const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName() //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n) { - mFilterName = n; + m_FilterName = n; } //-------------------------------------------------------------------- @@ -219,7 +220,7 @@ void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n) //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b) { - mIOVerbose = b; + m_IOVerbose = b; } //-------------------------------------------------------------------- @@ -274,12 +275,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_OutputFilenames.size()) { + clitk::writeImage(output, m_OutputFilenames.front(), m_IOVerbose); + 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,11 +289,11 @@ 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); diff --git a/common/clitkImageToImageGenericFilterBase.h b/common/clitkImageToImageGenericFilterBase.h index 601a752..2d624ba 100644 --- a/common/clitkImageToImageGenericFilterBase.h +++ b/common/clitkImageToImageGenericFilterBase.h @@ -17,14 +17,16 @@ ======================================================================-====*/ #ifndef CLITKIMAGETOIMAGEGENERICFILTERBASE_H #define CLITKIMAGETOIMAGEGENERICFILTERBASE_H + +// clitk #include "clitkCommon.h" #include "clitkImageCommon.h" #include "clitkCommonGenericFilter.h" -// itk include +// itk #include -// vv include +// vv #include "vvImage.h" #include "vvFromITK.h" #include "vvToITK.h" @@ -48,6 +50,11 @@ namespace clitk { // Filters information const std::string & GetFilterName(); void SetFilterName(std::string & n); + + // Error management + itkSetMacro(LastError, std::string); + itkGetConstMacro(LastError, std::string); + bool HasError() { return (GetLastError() != ""); } // Generic IO /// Returns the dimension and pixel type of the *first* input @@ -83,7 +90,7 @@ namespace clitk { virtual bool Update() = 0; protected: - bool mReadOnDisk; + bool m_ReadOnDisk; /// Call this function to dispatch an output towards the correct sink template void SetNextOutput(typename ImageType::Pointer output); @@ -92,21 +99,23 @@ namespace clitk { template typename ImageType::Pointer GetInput(unsigned int n); - std::vector mInputFilenames; - std::list mOutputFilenames; + std::vector m_InputFilenames; + std::list m_OutputFilenames; - bool mIOVerbose; - unsigned int mDim; - std::string mPixelTypeName; - unsigned int mNbOfComponents; - std::string mFilterName; + bool m_IOVerbose; + unsigned int m_Dim; + std::string m_PixelTypeName; + unsigned int m_NbOfComponents; + std::string m_FilterName; - std::vector mInputVVImages; - std::vector mOutputVVImages; + std::vector m_InputVVImages; + std::vector m_OutputVVImages; void ImageTypeError(); void SetImageTypeError(); - bool mFailOnImageTypeError; + bool m_FailOnImageTypeError; + + std::string m_LastError; }; // end class clitk::ImageToImageGenericFilter