19 #ifndef __itkMaskedImageToImageFilter_hxx 20 #define __itkMaskedImageToImageFilter_hxx 23 #include "itkStdStreamLogOutput.h" 24 #include "itkProgressReporter.h" 30 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
35 this->SetNumberOfRequiredInputs(1);
46 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
51 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
57 itk::ReadImage<MaskImageType>(file, mask);
58 this->SetMaskImage(mask);
61 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
69 utlGlobalException((!itk::VerifyImageInformation<InputImageType, MaskImageType>(input, m_MaskImage,
true)),
"wrong mask information");
73 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
74 typename LightObject::Pointer
78 typename LightObject::Pointer loPtr = Superclass::InternalClone();
83 itkExceptionMacro(<<
"downcast to type " << this->GetNameOfClass()<<
" failed.");
85 rval->m_MaskImage = m_MaskImage;
86 rval->m_Logger = m_Logger;
87 rval->m_LoggerVector = m_LoggerVector;
88 rval->m_ThreadID = m_ThreadID;
89 rval->m_LogLevel = m_LogLevel;
90 rval->SetNumberOfThreads(this->GetNumberOfThreads());
91 rval->SetDebug(this->GetDebug());
95 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
100 utlException(!(this->GetDebug() && this->GetNumberOfThreads()>1),
"create m_LoggerVector only when m_Debug is true and multiple threads are used");
103 itk::StdStreamLogOutput::Pointer coutput = itk::StdStreamLogOutput::New();
104 coutput->SetStream(std::cout);
105 m_Logger = itk::ThreadLogger::New();
106 m_Logger->SetPriorityLevel(itk::LoggerBase::DEBUG);
107 m_Logger->SetLevelForFlushing(itk::LoggerBase::MUSTFLUSH);
108 m_Logger->AddLogOutput(coutput);
111 int numberofThreads = this->GetNumberOfThreads();
113 for (
int ii = 0; ii < numberofThreads; ++ii)
114 (*m_LoggerVector)[ii] = m_Logger;
117 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
120 ::WriteLogger(
const std::string& str,
const LoggerBase::PriorityLevelType level)
const 122 if (m_ThreadID>=0 && this->GetDebug() && this->GetNumberOfThreads()>1)
124 utlSAException(this->m_LoggerVector->size()!=this->GetNumberOfThreads())
125 (this->m_LoggerVector->size())(this->GetNumberOfThreads()).msg(
"need to set m_LoggerVector");
126 (*this->m_LoggerVector)[m_ThreadID]->Write(level, str);
127 (*this->m_LoggerVector)[m_ThreadID]->Flush();
130 std::cout << str << std::flush;
133 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
138 if (m_ThreadID>=0 && this->GetDebug() && this->GetNumberOfThreads()>1)
140 std::ostringstream msg;
141 msg <<
"<Thread " << m_ThreadID <<
"> : ";
148 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
156 template<
class TInputImage,
class TOutputImage,
class TMaskImage >
161 Superclass::PrintSelf(os, indent);
163 os << indent <<
"MaskImage = " << m_MaskImage << std::endl << std::flush;
TInputImage InputImageType
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
virtual void VerifyMaskInformation() const
helper functions specifically used in dmritool
std::vector< LoggerPointer > LoggerVectorType
SmartPointer< Self > Pointer
virtual void SetMaskImage(MaskImageType *_arg)
bool IsImageEmpty(const SmartPointer< ImageType > &image)
#define utlException(cond, expout)
InputImageType::Pointer InputImagePointer
ImageToImageFilter< TInputImage, TOutputImage > Superclass
void WriteLogger(const std::string &str, const LoggerBase::PriorityLevelType level=LoggerBase::DEBUG) const
void CreateLoggerVector()
MaskImageType::Pointer MaskImagePointer
#define utlGlobalException(cond, expout)
virtual ~MaskedImageToImageFilter()
ImageToImageFilter with mask and threaded logger support.
#define utlSAException(expr)
LightObject::Pointer InternalClone() const ITK_OVERRIDE
utl_shared_ptr< LoggerVectorType > LoggerVectorPointer
static void InitializeThreadedLibraries(const int numThreads)
std::string ThreadIDToString() const
virtual void InitializeThreadedLibraries()
MaskedImageToImageFilter()