--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ ======================================================================-====*/
+
+// clitk
+#include "clitkFilterBase.h"
+
+//--------------------------------------------------------------------
+clitk::FilterBase::FilterBase()
+{
+ SetVerboseOption(false);
+ SetCurrentStepNumber(0);
+ SetCurrentStepBaseId("");
+ StopOnErrorOn();
+ ResetLastError();
+ VerboseWarningOffOn(); // OffOn, it's cool not ?
+ SetWarning("");
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void clitk::FilterBase::ResetLastError()
+{
+ m_LastError = "";
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void clitk::FilterBase::SetLastError(std::string e)
+{
+ m_LastError = e;
+ if (GetStopOnError()) {
+ std::cerr << GetLastError() << std::endl;
+ exit(0);
+ }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void clitk::FilterBase::SetWarning(std::string e)
+{
+ m_Warning = e;
+ if (!GetVerboseWarningOff()) {
+ std::cout << GetWarning() << std::endl;
+ }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void clitk::FilterBase::StartNewStep(std::string s)
+{
+ m_CurrentStepNumber++;
+ if (GetCurrentStepBaseId() != "") {
+ std::ostringstream oss;
+ oss << GetCurrentStepBaseId() << "." << m_CurrentStepNumber;
+ SetCurrentStepId(oss.str());
+ }
+ else {
+ std::ostringstream oss;
+ oss << m_CurrentStepNumber;
+ SetCurrentStepId(oss.str());
+ }
+
+ if (m_VerboseStep) {
+ std::cout << "Step " << GetCurrentStepId() << " -- " << s << std::endl;
+ }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void clitk::FilterBase::StopCurrentStep()
+{
+
+}
+//--------------------------------------------------------------------
+
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ ======================================================================-====*/
+
+#ifndef CLITKFILTERBASE_H
+#define CLITKFILTERBASE_H
+
+// clitk
+#include "clitkCommon.h"
+#include "clitkFilterMacros.txx"
+#include "clitkLabelizeParameters.h"
+
+// itk
+#include "itkObject.h"
+
+namespace clitk {
+
+ //--------------------------------------------------------------------
+ /*
+ Convenient class to manage options from GGO gengetopt) to filter
+ */
+ //--------------------------------------------------------------------
+ class FilterBase {
+
+ public:
+ // Standard class typedefs
+ typedef FilterBase Self;
+
+ // Run-time type information (and related methods)
+ itkTypeMacro(FilterBase, Object);
+
+ // Needed by itkSetMacro (cannot inherit from itkObject because of
+ // multiple inheritance)
+ virtual void Modified() {}
+ virtual bool GetDebug() const { return false; }
+
+ // To put in class that inherit from FilterBase
+#define FILTERBASE_INIT \
+ virtual void Modified() { Superclass::Modified(); } \
+ virtual bool GetDebug() const { return Superclass::GetDebug(); }
+
+ // Verbose options management
+ itkSetMacro(VerboseOption, bool);
+ itkGetConstMacro(VerboseOption, bool);
+ itkBooleanMacro(VerboseOption);
+ GGO_DefineOption_Flag(verboseOption, SetVerboseOption);
+
+ // Steps management
+ itkSetMacro(VerboseStep, bool);
+ itkGetConstMacro(VerboseStep, bool);
+ itkBooleanMacro(VerboseStep);
+ GGO_DefineOption_Flag(verboseStep, SetVerboseStep);
+
+ itkSetMacro(WriteStep, bool);
+ itkGetConstMacro(WriteStep, bool);
+ itkBooleanMacro(WriteStep);
+ GGO_DefineOption_Flag(writeStep, SetWriteStep);
+
+ itkSetMacro(CurrentStepNumber, int);
+ itkGetConstMacro(CurrentStepNumber, int);
+ itkSetMacro(CurrentStepId, std::string);
+ itkGetConstMacro(CurrentStepId, std::string);
+ itkSetMacro(CurrentStepBaseId, std::string);
+ itkGetConstMacro(CurrentStepBaseId, std::string);
+
+ // Convenient function for verbose option
+ template<class OptionType>
+ void VerboseOption(std::string name, OptionType value);
+ template<class OptionType>
+ void VerboseOption(std::string name, int nb, OptionType value);
+ template<class OptionType>
+ void VerboseOptionV(std::string name, int nb, OptionType * value);
+
+ // Error
+ void SetLastError(std::string e);
+ void ResetLastError();
+ itkGetConstMacro(LastError, std::string);
+ bool HasError() { return (GetLastError() != ""); }
+ itkSetMacro(StopOnError, bool);
+ itkGetConstMacro(StopOnError, bool);
+ itkBooleanMacro(StopOnError);
+
+ void SetWarning(std::string e);
+ itkGetConstMacro(Warning, std::string);
+ itkSetMacro(VerboseWarningOff, bool);
+ itkGetConstMacro(VerboseWarningOff, bool);
+ itkBooleanMacro(VerboseWarningOff);
+ GGO_DefineOption_Flag(verboseWarningOff, SetVerboseWarningOff);
+
+ protected:
+ FilterBase();
+ virtual ~FilterBase() {}
+ void StartNewStep(std::string s);
+ template<class TInternalImageType>
+ void StopCurrentStep(typename TInternalImageType::Pointer p);
+ void StopCurrentStep();
+
+ bool m_VerboseOption;
+ bool m_VerboseStep;
+ bool m_WriteStep;
+ int m_CurrentStepNumber;
+ std::string m_CurrentStepId;
+ std::string m_CurrentStepBaseId;
+ std::string m_LastError;
+ bool m_StopOnError;
+ std::string m_Warning;
+ bool m_VerboseWarningOff;
+
+ private:
+ FilterBase(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
+
+ }; // end class
+ //--------------------------------------------------------------------
+
+} // end namespace clitk
+//--------------------------------------------------------------------
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkFilterBase.txx"
+#endif
+
+#endif // CLITKFILTERBASE_H
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ ======================================================================-====*/
+
+#include "clitkImageCommon.h"
+
+//--------------------------------------------------------------------
+template<class OptionType>
+void clitk::FilterBase::VerboseOption(std::string name, OptionType value)
+{
+ if (!this->GetVerboseOption()) return;
+ std::cout << "Set option '" << name << "' = " << value << std::endl;
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class OptionType>
+void clitk::FilterBase::VerboseOption(std::string name, int nb, OptionType value)
+{
+ if (!this->GetVerboseOption()) return;
+ if (nb==0) std::cout << "Set option '" << name << "' not given" << std::endl;
+ else {
+ std::cout << "Set option '" << name << "' = " << value << std::endl;
+ }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class OptionType>
+void clitk::FilterBase::VerboseOptionV(std::string name, int nb, OptionType * value)
+{
+ if (!this->GetVerboseOption()) return;
+ if (nb==0) std::cout << "Set option '" << name << "' not given" << std::endl;
+ else {
+ std::cout << "Set option '" << name << "'[" << nb << "] ";
+ for(int i=0; i<nb; i++) std::cout << value[i] << " ";
+ std::cout << std::endl;
+ }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class TInternalImageType>
+void clitk::FilterBase::StopCurrentStep(typename TInternalImageType::Pointer p)
+{
+ if (m_WriteStep) {
+ std::ostringstream name;
+ name << "step-" << GetCurrentStepId() << ".mhd";
+ clitk::writeImage<TInternalImageType>(p, name.str());
+ }
+}
+//--------------------------------------------------------------------
+
+
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ ======================================================================-====*/
+
+#define GGO_DefineOption_Vector(OPTION, FUNC, TYPE, NB, BOOL) \
+ template<class ArgsInfoType> \
+ void FUNC##_GGO(ArgsInfoType & mArgsInfo) { \
+ if (mArgsInfo.OPTION##_given == NB) { \
+ TYPE aaa; \
+ for(unsigned int i=0; i<NB; i++) { \
+ aaa[i] = mArgsInfo.OPTION##_arg[i]; \
+ } \
+ VerboseOption(#FUNC, mArgsInfo.OPTION##_given, mArgsInfo.OPTION##_arg); \
+ FUNC(aaa); \
+ } \
+ else { \
+ if (BOOL && mArgsInfo.OPTION##_given != 0) { \
+ std::cerr << "Sorry, you give only " << mArgsInfo.OPTION##_given << " while " \
+ << NB << " values a required for option '" << #OPTION << "'" << std::endl; \
+ exit(0); \
+ } \
+ } \
+ }
+
+#define GGO_DefineOption_Multiple(OPTION, FUNC, TYPE) \
+ template<class ArgsInfoType> \
+ void FUNC##_GGO(ArgsInfoType & mArgsInfo) { \
+ VerboseOption(#OPTION, mArgsInfo.OPTION##_given, mArgsInfo.OPTION##_arg); \
+ for(unsigned int i=0; i<mArgsInfo.OPTION##_given; i++) { \
+ FUNC(mArgsInfo.OPTION##_arg[i]); \
+ } \
+ }
+
+#define GGO_DefineOption(OPTION, FUNC, TYPE) \
+ template<class ArgsInfoType> \
+ void FUNC##_GGO(ArgsInfoType & mArgsInfo) { \
+ VerboseOption(#OPTION, mArgsInfo.OPTION##_arg); \
+ FUNC(static_cast<TYPE>(mArgsInfo.OPTION##_arg)); \
+ }
+
+#define GGO_DefineOption_Flag(OPTION, FUNC) \
+ template<class ArgsInfoType> \
+ void FUNC##_GGO(ArgsInfoType & mArgsInfo) { \
+ VerboseOption(#OPTION, mArgsInfo.OPTION##_flag); \
+ FUNC(mArgsInfo.OPTION##_flag); \
+ }
+
+#define GGO_DefineOption_WithTest(OPTION, FUNC, TYPE, TEST) \
+ template<class ArgsInfoType> \
+ void FUNC##_GGO(ArgsInfoType & mArgsInfo) { \
+ VerboseOption(#OPTION, mArgsInfo.OPTION##_given, mArgsInfo.OPTION##_arg); \
+ if (mArgsInfo.OPTION##_given) { \
+ VerboseOption(#OPTION, mArgsInfo.OPTION##_arg); \
+ FUNC(static_cast<TYPE>(mArgsInfo.OPTION##_arg)); \
+ TEST##On(); \
+ } \
+ else TEST##Off(); \
+ }
+
+#define GGO_DefineOption_LabelParam(OPTION, FUNC, TYPE) \
+ template<class ArgsInfoType> \
+ void FUNC##_GGO(ArgsInfoType & mArgsInfo) { \
+ TYPE * param = new TYPE; \
+ param->SetFirstKeep(mArgsInfo.firstKeep##OPTION##_arg); \
+ for(unsigned int i=0; i<mArgsInfo.remove##OPTION##_given; i++) \
+ param->AddLabelToRemove(mArgsInfo.remove##OPTION##_arg[i]); \
+ if (mArgsInfo.lastKeep##OPTION##_given) { \
+ param->SetLastKeep(mArgsInfo.lastKeep##OPTION##_arg); \
+ param->UseLastKeepOn(); \
+ } \
+ else param->UseLastKeepOff(); \
+ VerboseOption("firstKeep"#OPTION, mArgsInfo.firstKeep##OPTION##_arg); \
+ VerboseOption("lastKeep"#OPTION, mArgsInfo.lastKeep##OPTION##_given, mArgsInfo.lastKeep##OPTION##_arg ); \
+ VerboseOptionV("remove"#OPTION, mArgsInfo.remove##OPTION##_given, mArgsInfo.remove##OPTION##_arg); \
+ FUNC(param); \
+ }
+