//--------------------------------------------------------------------
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 = "";
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<std::string> & filenames)
{
- mInputFilenames=filenames;
+ m_InputFilenames = filenames;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::EnableReadOnDisk(bool b)
{
- mReadOnDisk = b;
+ m_ReadOnDisk = b;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & filename)
{
- mInputFilenames.push_back(filename);
+ m_InputFilenames.push_back(filename);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
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)
{
- mOutputFilenames.push_back(filename);
+ m_OutputFilenames.push_back(filename);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector<std::string> & filenames)
{
- mOutputFilenames.clear();
- std::copy(filenames.begin(),filenames.end(),mOutputFilenames.begin());
+ m_OutputFilenames.clear();
+ std::copy(filenames.begin(),filenames.end(),m_OutputFilenames.begin());
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename()
{
- assert(mOutputFilenames.size() == 1);
- return mOutputFilenames.front();
+ assert(m_OutputFilenames.size() == 1);
+ return m_OutputFilenames.front();
}
//--------------------------------------------------------------------
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;
}
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage ()
{
- assert(mOutputVVImages.size());
- return mOutputVVImages[0];
+ assert(m_OutputVVImages.size());
+ return m_OutputVVImages[0];
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
std::vector<vvImage::Pointer> clitk::ImageToImageGenericFilterBase::GetOutputVVImages()
{
- return mOutputVVImages;
+ return m_OutputVVImages;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer input)
{
- mInputVVImages.clear();
- mInputVVImages.push_back(input);
+ m_InputVVImages.clear();
+ m_InputVVImages.push_back(input);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer input)
{
- mInputVVImages.push_back(input);
+ m_InputVVImages.push_back(input);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector<vvImage::Pointer> input)
{
- mInputVVImages=input;
+ m_InputVVImages=input;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
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);
}
//--------------------------------------------------------------------
const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName()
{
- return mFilterName;
+ return m_FilterName;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n)
{
- mFilterName = n;
+ m_FilterName = n;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b)
{
- mIOVerbose = b;
+ m_IOVerbose = b;
}
//--------------------------------------------------------------------
template<class ImageType>
void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output)
{
- if (mOutputFilenames.size()) {
- clitk::writeImage<ImageType>(output, mOutputFilenames.front(), mIOVerbose);
- mOutputFilenames.pop_front();
+ if (m_OutputFilenames.size()) {
+ clitk::writeImage<ImageType>(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<ImageType::ImageDimension,typename ImageType::PixelType>(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<ImageType::ImageDimension,typename ImageType::PixelType>(output));
}
//--------------------------------------------------------------------
template<class ImageType>
typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n)
{
- if (mReadOnDisk && mInputFilenames.size() > n) {
- return clitk::readImage<ImageType>(mInputFilenames[n], mIOVerbose);
+ if (m_ReadOnDisk && m_InputFilenames.size() > n) {
+ return clitk::readImage<ImageType>(m_InputFilenames[n], m_IOVerbose);
} else {
- if (mInputVVImages.size() > n)
- return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(mInputVVImages[n]).GetPointer()));
+ if (m_InputVVImages.size() > n)
+ return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(m_InputVVImages[n]).GetPointer()));
else {
assert(false); //No input, this shouldn't happen
return typename ImageType::Pointer(NULL);
======================================================================-====*/
#ifndef CLITKIMAGETOIMAGEGENERICFILTERBASE_H
#define CLITKIMAGETOIMAGEGENERICFILTERBASE_H
+
+// clitk
#include "clitkCommon.h"
#include "clitkImageCommon.h"
#include "clitkCommonGenericFilter.h"
-// itk include
+// itk
#include <itkImage.h>
-// vv include
+// vv
#include "vvImage.h"
#include "vvFromITK.h"
#include "vvToITK.h"
// 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
virtual bool Update() = 0;
protected:
- bool mReadOnDisk;
+ bool m_ReadOnDisk;
/// Call this function to dispatch an output towards the correct sink
template<class ImageType>
void SetNextOutput(typename ImageType::Pointer output);
template<class ImageType>
typename ImageType::Pointer GetInput(unsigned int n);
- std::vector<std::string> mInputFilenames;
- std::list<std::string> mOutputFilenames;
+ std::vector<std::string> m_InputFilenames;
+ std::list<std::string> 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<vvImage::Pointer> mInputVVImages;
- std::vector<vvImage::Pointer> mOutputVVImages;
+ std::vector<vvImage::Pointer> m_InputVVImages;
+ std::vector<vvImage::Pointer> m_OutputVVImages;
void ImageTypeError();
void SetImageTypeError();
- bool mFailOnImageTypeError;
+ bool m_FailOnImageTypeError;
+
+ std::string m_LastError;
}; // end class clitk::ImageToImageGenericFilter