ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkDiffusionTensor3DReconstructionImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkDiffusionTensor3DReconstructionImageFilter_h
19 #define itkDiffusionTensor3DReconstructionImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 #include "itkSpatialObject.h"
23 #include "itkDiffusionTensor3D.h"
24 #include "vnl/vnl_matrix.h"
25 #include "vnl/vnl_vector_fixed.h"
26 #include "vnl/vnl_matrix_fixed.h"
27 #include "vnl/algo/vnl_svd.h"
28 #include "itkVectorContainer.h"
29 #include "itkVectorImage.h"
30 
31 namespace itk
32 {
122 template< typename TReferenceImagePixelType,
123  typename TGradientImagePixelType = TReferenceImagePixelType,
124  typename TTensorPixelType = double,
125  typename TMaskImageType = Image<unsigned char, 3> >
127  public ImageToImageFilter< Image< TReferenceImagePixelType, 3 >,
128  Image< DiffusionTensor3D< TTensorPixelType >, 3 > >
129 {
130 public:
131 
137 
139  itkNewMacro(Self);
140 
144 
145  using ReferencePixelType = TReferenceImagePixelType;
146 
147  using GradientPixelType = TGradientImagePixelType;
148 
150 
153  using ReferenceImageType = typename Superclass::InputImageType;
154 
156 
158 
159  using OutputImageRegionType = typename Superclass::OutputImageRegionType;
160 
163 
169 
172 
174  using MaskImageType = TMaskImageType;
175 
177  using TensorBasisMatrixType = vnl_matrix_fixed< double, 6, 6 >;
178 
179  using CoefficientMatrixType = vnl_matrix< double >;
180 
182  using GradientDirectionType = vnl_vector_fixed< double, 3 >;
183 
185  using GradientDirectionContainerType = VectorContainer< unsigned int,
187 
189  void AddGradientImage(const GradientDirectionType &, const GradientImageType *image);
190  const GradientImageType *GetGradientImage(unsigned index) const;
192 
199  void SetGradientImage(GradientDirectionContainerType *,
200  const GradientImagesType *image);
201 
203  void SetReferenceImage(ReferenceImageType *referenceImage)
204  {
205  if ( m_GradientImageTypeEnumeration == GradientIsInASingleImage )
206  {
207  itkExceptionMacro(<< "Cannot call both methods:"
208  << "AddGradientImage and SetGradientImage. Please call only one of them.");
209  }
210 
211  this->ProcessObject::SetNthInput(0, referenceImage);
212 
213  m_GradientImageTypeEnumeration = GradientIsInManyImages;
214  }
215 
218  { return ( static_cast< ReferenceImageType * >( this->ProcessObject::GetInput(0) ) ); }
219 
221  virtual GradientDirectionType GetGradientDirection(unsigned int idx) const
222  {
223  if ( idx >= m_NumberOfGradientDirections )
224  {
225  itkExceptionMacro(<< "Gradient direction " << idx << "does not exist");
226  }
227  return m_GradientDirectionContainer->ElementAt(idx + 1);
228  }
230 
232  void SetMaskImage(MaskImageType *maskImage);
233 
235  void SetMaskSpatialObject(MaskSpatialObjectType *maskSpatialObject);
236 
237 
241  itkSetMacro(Threshold, ReferencePixelType);
242  itkGetConstMacro(Threshold, ReferencePixelType);
244 
251  itkSetMacro(BValue, TTensorPixelType);
252 #ifdef GetBValue
253 #undef GetBValue
254 #endif
255  itkGetConstReferenceMacro(BValue, TTensorPixelType);
257 
258 #ifdef ITK_USE_CONCEPT_CHECKING
259  // Begin concept checking
260  itkConceptMacro( ReferenceEqualityComparableCheck,
262  itkConceptMacro( TensorEqualityComparableCheck,
264  itkConceptMacro( GradientConvertibleToDoubleCheck,
266  itkConceptMacro( DoubleConvertibleToTensorCheck,
268  itkConceptMacro( GradientReferenceAdditiveOperatorsCheck,
269  ( Concept::AdditiveOperators< GradientPixelType, GradientPixelType,
270  ReferencePixelType > ) );
271  itkConceptMacro( GradientReferenceAdditiveAndAssignOperatorsCheck,
272  ( Concept::AdditiveAndAssignOperators< GradientPixelType,
273  ReferencePixelType > ) );
274 
275  itkConceptMacro( ReferenceOStreamWritableCheck,
277  itkConceptMacro( TensorOStreamWritableCheck,
279  // End concept checking
280 #endif
281 
282 protected:
284  ~DiffusionTensor3DReconstructionImageFilter() override = default;
285  void PrintSelf(std::ostream & os, Indent indent) const override;
286 
287  void ComputeTensorBasis();
288 
289  void BeforeThreadedGenerateData() override;
290 
291  void DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
292 
293  void VerifyPreconditions() ITKv5_CONST override;
294 
297  typedef enum {
298  GradientIsInASingleImage = 1,
300  Else
301  } GradientImageTypeEnumeration;
302 
303 private:
304 
305  /* Tensor basis coeffs */
307 
309 
312 
315 
318 
321 
323  TTensorPixelType m_BValue;
324 
327 
330 };
331 }
332 
333 #ifndef ITK_MANUAL_INSTANTIATION
334 #include "itkDiffusionTensor3DReconstructionImageFilter.hxx"
335 #endif
336 
337 #endif
Light weight base class for most itk classes.
virtual GradientDirectionType GetGradientDirection(unsigned int idx) const
Templated n-dimensional vector image class.
Implementation of the composite pattern.
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
This class takes as input one or more reference image (acquired in the absence of diffusion sensitizi...
Base class for filters that take an image as input and produce an image as output.
Define a front-end to the STL &quot;vector&quot; container that conforms to the IndexedContainerInterface.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
#define itkConceptMacro(name, concept)
Represent a diffusion tensor as used in DTI images.
Templated n-dimensional image class.
Definition: itkImage.h:75