DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkFunctorFromStringImageFilter.h
Go to the documentation of this file.
1 
13 #ifndef itkFunctorFromStringImageFilter_h
14 #define itkFunctorFromStringImageFilter_h
15 
17 #include "utlExprtk.h"
18 #include "utlITKMacro.h"
19 #include "utlFunctors.h"
20 
21 namespace itk
22 {
35 template< typename TInputImage, typename TOutputImage, class TMaskImage=Image<double,3> >
37  :public FunctorBaseVectorImageFilter< TInputImage, TOutputImage, utl::Functor::VectorMultiVariableFunctionWrapper<>, TMaskImage >
38 {
39 public:
43  typedef SmartPointer< Self > Pointer;
44  typedef SmartPointer< const Self > ConstPointer;
45 
47  itkNewMacro(Self);
48 
51 
54 
55  typedef TInputImage InputImageType;
56  typedef typename InputImageType::Pointer InputImagePointer;
57  typedef typename InputImageType::ConstPointer InputImageConstPointer;
58  typedef typename InputImageType::IndexType InputImageIndexType;
59  typedef typename InputImageType::SizeType InputImageSizeType;
60  typedef typename InputImageType::SpacingType InputImageSpacingType;
61  typedef typename InputImageType::PixelType InputImagePixelType;
62  typedef typename InputImageType::RegionType InputImageRegionType;
63 
64  typedef TOutputImage OutputImageType;
65  typedef typename OutputImageType::Pointer OutputImagePointer;
66  typedef typename OutputImageType::IndexType OutputImageIndexType;
67  typedef typename OutputImageType::SizeType OutputImageSizeType;
68  typedef typename OutputImageType::SpacingType OutputImageSpacingType;
69  typedef typename OutputImageType::PixelType OutputImagePixelType;
70  typedef typename OutputImageType::RegionType OutputImageRegionType;
71 
73 
74  itkSetGetMacro(Expression, std::string);
75 
76 protected:
79 
80  void BeforeThreadedGenerateData () ITK_OVERRIDE;
81 
83  virtual void PropagateRequestedRegion(DataObject *output) ITK_OVERRIDE
84  {
85  }
86 
87  virtual void GenerateOutputInformation() ITK_OVERRIDE;
88 
89  void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
90  ThreadIdType threadId) ITK_OVERRIDE;
91 
92 protected:
93 
94  std::string m_Expression;
95 
96 private:
98  void operator=(const Self &) ITK_DELETE_FUNCTION;
99 
100 };
101 
102 
107 template <class ImageType, class ImageOutType, class MaskImageType=Image<double,4> >
108 void
109 FunctorFromStringOPImage(const std::vector<itk::SmartPointer<ImageType> >& images, itk::SmartPointer<ImageOutType>& outImage, const std::string& funcStr, const itk::SmartPointer<MaskImageType>& mask=nullptr, int numberOfThreads=-1)
110 {
112  typename FunctorImageFilterType::Pointer filter = FunctorImageFilterType::New();
113 
114  if (!itk::IsImageEmpty(mask))
115  filter->SetMaskImage(mask);
116  for ( int i = 0; i < images.size(); ++i )
117  {
118  filter->SetInput(i, images[i]);
119  }
120  filter->SetExpression(funcStr);
121  filter->SetDebug(utl::IsLogDebug());
122  filter->SetLogLevel(utl::LogLevel);
123  if (numberOfThreads>0)
124  filter->SetNumberOfThreads(numberOfThreads);
125 
126  filter->Update();
127 
128  outImage = filter->GetOutput();
129 }
130 
131 
132 } // end namespace itk
133 
134 #if !defined(ITK_MANUAL_INSTANTIATION) && !defined(__itkFunctorFromStringImageFilter_hxx)
136 #endif
137 
138 #endif
utl::Functor::VectorMultiVariableFunctionWrapper FunctorType
Implements vector-valued generic operation on one image.
FunctorBaseVectorImageFilter< TInputImage, TOutputImage, utl::Functor::VectorMultiVariableFunctionWrapper<>, TMaskImage > Superclass
bool IsImageEmpty(const SmartPointer< ImageType > &image)
Definition: utlITK.h:435
Created "04-05-2017.
Implements vector-valued generic operation on images with the same size.
STL namespace.
#define ITK_DELETE_FUNCTION
Definition: utlITKMacro.h:49
InputImageType::ConstPointer InputImageConstPointer
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
bool IsLogDebug(const int level=utl::LogLevel)
Definition: utlCoreMacro.h:213
virtual void PropagateRequestedRegion(DataObject *output) ITK_OVERRIDE
functors in utl
OutputImageType::SpacingType OutputImageSpacingType
static int LogLevel
Definition: utlCoreMacro.h:203
#define itkSetGetMacro(name, type)
Definition: utlITKMacro.h:134
void FunctorFromStringOPImage(const std::vector< itk::SmartPointer< ImageType > > &images, itk::SmartPointer< ImageOutType > &outImage, const std::string &funcStr, const itk::SmartPointer< MaskImageType > &mask=nullptr, int numberOfThreads=-1)