// clitk
#include "clitkImageToImageGenericFilterBase.h"
+#include "clitkExceptionObject.h"
// itk
#include <itkImage.h>
m_FilterName = n;
m_FailOnImageTypeError = true;
m_ReadOnDisk = true;
+ m_WriteOnDisk = true;
// m_LastError = "";
// StopOnErrorOn();
SetFilterBase(NULL);
void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<std::string> & 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);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+void clitk::ImageToImageGenericFilterBase::EnableWriteOnDisk(bool b)
+{
+ m_WriteOnDisk = b;
+}
+//--------------------------------------------------------------------
+
+
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename)
{
std::vector<std::string> 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);
}
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & 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);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
-void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string & filename)
+void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string filename)
{
m_OutputFilenames.push_back(filename);
}
{
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);
}
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector<vvImage::Pointer> 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);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::ImageTypeError()
{
- 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);
+ 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);
}
//--------------------------------------------------------------------
template<class ImageType>
void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output)
{
- if (m_OutputFilenames.size()) {
+ if (m_WriteOnDisk && m_OutputFilenames.size()) {
clitk::writeImage<ImageType>(output, m_OutputFilenames.front(), m_IOVerbose);
m_OutputFilenames.pop_front();
}
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
void GetInputImageDimensionAndPixelType(unsigned int& dim, std::string& pixeltype,
void AddInputFilename(const std::string & filename);
void SetInputFilenames(const std::vector<std::string> & filenames);
void EnableReadOnDisk(bool b);
+ void EnableWriteOnDisk(bool b);
void SetOutputFilename(const std::string & filename);
- void AddOutputFilename(const std::string & filename);
+ void AddOutputFilename(const std::string filename);
void SetOutputFilenames(const std::vector<std::string> & filenames);
std::string GetOutputFilename();
void SetIOVerbose(bool b);
FilterBase * GetFilterBase() { return m_FilterBase; }
// Indicate that the filter must stop as soon as possible (if threaded)
- // void MustStop();
void DeleteLastOutputImage();
- // itkSetMacro(StopOnError, bool);
- // itkGetConstMacro(StopOnError, bool);
- // itkBooleanMacro(StopOnError);
protected:
bool m_ReadOnDisk;
+ bool m_WriteOnDisk;
/// Call this function to dispatch an output towards the correct sink
template<class ImageType>
void SetNextOutput(typename ImageType::Pointer output);
std::vector<std::string> m_InputFilenames;
std::list<std::string> m_OutputFilenames;
-
+
bool m_IOVerbose;
unsigned int m_Dim;
std::string m_PixelTypeName;