From: dsarrut Date: Fri, 22 Oct 2010 07:19:27 +0000 (+0000) Subject: make explicit write/read on disk X-Git-Tag: v1.2.0~331 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=7ee1221182f8b142a3f91a61bf13f1bc0c3852cd;p=clitk.git make explicit write/read on disk --- diff --git a/common/clitkImageToImageGenericFilterBase.cxx b/common/clitkImageToImageGenericFilterBase.cxx index 70dcba6..ee9dcf8 100644 --- a/common/clitkImageToImageGenericFilterBase.cxx +++ b/common/clitkImageToImageGenericFilterBase.cxx @@ -18,6 +18,7 @@ // clitk #include "clitkImageToImageGenericFilterBase.h" +#include "clitkExceptionObject.h" // itk #include @@ -34,6 +35,7 @@ clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string m_FilterName = n; m_FailOnImageTypeError = true; m_ReadOnDisk = true; + m_WriteOnDisk = true; // m_LastError = ""; // StopOnErrorOn(); SetFilterBase(NULL); @@ -45,6 +47,11 @@ clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector & 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); } //-------------------------------------------------------------------- @@ -57,12 +64,25 @@ void clitk::ImageToImageGenericFilterBase::EnableReadOnDisk(bool b) //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void clitk::ImageToImageGenericFilterBase::EnableWriteOnDisk(bool b) +{ + m_WriteOnDisk = b; +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename) { 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); } //-------------------------------------------------------------------- @@ -71,6 +91,11 @@ void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & 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); } //-------------------------------------------------------------------- @@ -85,7 +110,7 @@ void clitk::ImageToImageGenericFilterBase::SetOutputFilename(const std::string & //-------------------------------------------------------------------- -void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string & filename) +void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string filename) { m_OutputFilenames.push_back(filename); } @@ -156,6 +181,11 @@ void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer inp { 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); } //-------------------------------------------------------------------- @@ -172,6 +202,11 @@ void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer inp void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector 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); } //-------------------------------------------------------------------- @@ -188,12 +223,14 @@ void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes() //-------------------------------------------------------------------- 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); } //-------------------------------------------------------------------- @@ -281,7 +318,7 @@ DEF_SetNextOutput_And_GetInput(double, 4); template void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output) { - if (m_OutputFilenames.size()) { + if (m_WriteOnDisk && m_OutputFilenames.size()) { clitk::writeImage(output, m_OutputFilenames.front(), m_IOVerbose); m_OutputFilenames.pop_front(); } diff --git a/common/clitkImageToImageGenericFilterBase.h b/common/clitkImageToImageGenericFilterBase.h index 280dd65..2cd6e70 100644 --- a/common/clitkImageToImageGenericFilterBase.h +++ b/common/clitkImageToImageGenericFilterBase.h @@ -52,11 +52,6 @@ namespace clitk { 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, @@ -66,8 +61,9 @@ namespace clitk { void AddInputFilename(const std::string & filename); void SetInputFilenames(const std::vector & 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 & filenames); std::string GetOutputFilename(); void SetIOVerbose(bool b); @@ -93,14 +89,11 @@ namespace clitk { 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 void SetNextOutput(typename ImageType::Pointer output); @@ -111,7 +104,7 @@ namespace clitk { std::vector m_InputFilenames; std::list m_OutputFilenames; - + bool m_IOVerbose; unsigned int m_Dim; std::string m_PixelTypeName;