ITK  6.0.0
Insight Toolkit
itkBSplineControlPointImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 itkBSplineControlPointImageFilter_h
19 #define itkBSplineControlPointImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
24 #include "itkFixedArray.h"
25 #include "itkPointSet.h"
26 #include "itkVariableSizeMatrix.h"
27 #include "itkVector.h"
28 #include "itkVectorContainer.h"
29 
30 #include "vnl/vnl_matrix.h"
31 #include "vnl/vnl_vector.h"
32 
33 namespace itk
34 {
35 
58 template <typename TInputImage, typename TOutputImage = TInputImage>
59 class ITK_TEMPLATE_EXPORT BSplineControlPointImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
60 {
61 public:
62  ITK_DISALLOW_COPY_AND_MOVE(BSplineControlPointImageFilter);
63 
68 
70  itkNewMacro(Self);
71 
73  itkOverrideGetNameOfClassMacro(BSplineControlPointImageFilter);
74 
76  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
77 
78  using ControlPointLatticeType = TInputImage;
79  using OutputImageType = TOutputImage;
80 
82  using PixelType = typename OutputImageType::PixelType;
87 
88  using SpacingType = typename OutputImageType::SpacingType;
92 
94  using RealType = float;
97 
100 
107 
114 
119  void
120  SetSplineOrder(unsigned int);
121 
126  void SetSplineOrder(ArrayType);
127 
131  itkGetConstReferenceMacro(SplineOrder, ArrayType);
132 
149  itkSetMacro(CloseDimension, ArrayType);
150  itkGetConstReferenceMacro(CloseDimension, ArrayType);
156  itkSetMacro(Spacing, SpacingType);
157  itkGetConstMacro(Spacing, SpacingType);
163  itkSetMacro(Origin, OriginType);
164  itkGetConstMacro(Origin, OriginType);
170  itkSetMacro(Size, SizeType);
171  itkGetConstMacro(Size, SizeType);
188  itkSetMacro(Direction, DirectionType);
189 
193  itkGetConstMacro(Direction, DirectionType);
194 
202  typename ControlPointLatticeType::Pointer RefineControlPointLattice(ArrayType);
203 
204 protected:
206  ~BSplineControlPointImageFilter() override = default;
207  void
208  PrintSelf(std::ostream & os, Indent indent) const override;
209 
211  void
212  DynamicThreadedGenerateData(const OutputImageRegionType &) override;
213 
214 
215 private:
220  void
221  BeforeThreadedGenerateData() override;
222 
227  unsigned int
228  SplitRequestedRegion(unsigned int, unsigned int, OutputImageRegionType &) override;
229 
234  void
235  CollapsePhiLattice(PointDataImageType *, PointDataImageType *, const RealType, const unsigned int);
236 
240  void SetNumberOfLevels(ArrayType);
241 
243  SizeType m_Size{};
244  SpacingType m_Spacing{};
245  OriginType m_Origin{};
246  DirectionType m_Direction{};
247 
248  bool m_DoMultilevel{ false };
249  unsigned int m_MaximumNumberOfLevels{ 1 };
250  ArrayType m_NumberOfControlPoints{};
251  ArrayType m_CloseDimension{};
252  ArrayType m_SplineOrder{};
253  ArrayType m_NumberOfLevels{};
254 
255  vnl_matrix<RealType> m_RefinedLatticeCoefficients[ImageDimension]{};
256 
257  typename KernelType::Pointer m_Kernel[ImageDimension]{};
258  typename KernelOrder0Type::Pointer m_KernelOrder0{};
259  typename KernelOrder1Type::Pointer m_KernelOrder1{};
260  typename KernelOrder2Type::Pointer m_KernelOrder2{};
261  typename KernelOrder3Type::Pointer m_KernelOrder3{};
262 
263  RealType m_BSplineEpsilon{ static_cast<RealType>(1e-3) };
264 
265  inline typename RealImageType::IndexType
266  NumberToIndex(unsigned int number, typename RealImageType::SizeType size)
267  {
268  typename RealImageType::IndexType k;
269  k[0] = 1;
270 
271  for (unsigned int i = 1; i < ImageDimension; ++i)
272  {
273  k[i] = size[ImageDimension - i - 1] * k[i - 1];
274  }
275  typename RealImageType::IndexType index;
276  for (unsigned int i = 0; i < ImageDimension; ++i)
277  {
278  index[ImageDimension - i - 1] = static_cast<unsigned int>(number / k[ImageDimension - i - 1]);
279  number %= k[ImageDimension - i - 1];
280  }
281  return index;
282  }
283 };
284 
285 } // end namespace itk
286 
287 #ifndef ITK_MANUAL_INSTANTIATION
288 # include "itkBSplineControlPointImageFilter.hxx"
289 #endif
290 
291 #endif
itk::BSplineControlPointImageFilter::RealImagePointer
typename RealImageType::Pointer RealImagePointer
Definition: itkBSplineControlPointImageFilter.h:96
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::BSplineKernelFunction
BSpline kernel used for density estimation and nonparametric regression.
Definition: itkBSplineKernelFunction.h:43
itk::Index< VImageDimension >
itk::GTest::TypedefsAndConstructors::Dimension2::DirectionType
ImageBaseType::DirectionType DirectionType
Definition: itkGTestTypedefsAndConstructors.h:52
itk::PointSet
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:81
itkVariableSizeMatrix.h
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::BSplineControlPointImageFilter::ControlPointLatticeType
TInputImage ControlPointLatticeType
Definition: itkBSplineControlPointImageFilter.h:78
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::BSplineControlPointImageFilter::RegionType
typename OutputImageType::RegionType RegionType
Definition: itkBSplineControlPointImageFilter.h:83
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::BSplineControlPointImageFilter::PointType
typename OutputImageType::PointType PointType
Definition: itkBSplineControlPointImageFilter.h:85
itk::BSplineControlPointImageFilter::PixelType
typename OutputImageType::PixelType PixelType
Definition: itkBSplineControlPointImageFilter.h:82
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::BSplineControlPointImageFilter::OriginType
typename OutputImageType::PointType OriginType
Definition: itkBSplineControlPointImageFilter.h:89
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::BSplineControlPointImageFilter::NumberToIndex
RealImageType::IndexType NumberToIndex(unsigned int number, typename RealImageType::SizeType size)
Definition: itkBSplineControlPointImageFilter.h:266
itk::PointSet::PixelType
typename MeshTraits::PixelType PixelType
Definition: itkPointSet.h:100
itkFixedArray.h
itk::BSplineControlPointImageFilter::PointDataContainerType
typename PointSetType::PointDataContainer PointDataContainerType
Definition: itkBSplineControlPointImageFilter.h:104
itkImageToImageFilter.h
itk::FixedArray< unsigned int, Self::ImageDimension >
itk::BSplineControlPointImageFilter::SpacingType
typename OutputImageType::SpacingType SpacingType
Definition: itkBSplineControlPointImageFilter.h:88
itk::BSplineControlPointImageFilter::PointDataImagePointer
typename PointDataImageType::Pointer PointDataImagePointer
Definition: itkBSplineControlPointImageFilter.h:106
itk::BSplineControlPointImageFilter::IndexType
typename OutputImageType::IndexType IndexType
Definition: itkBSplineControlPointImageFilter.h:84
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itkVectorContainer.h
itkCoxDeBoorBSplineKernelFunction.h
itkBSplineKernelFunction.h
itk::BSplineControlPointImageFilter::PointDataType
typename PointSetType::PixelType PointDataType
Definition: itkBSplineControlPointImageFilter.h:103
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itkVector.h
itk::PointSet::PointDataContainer
typename MeshTraits::PointDataContainer PointDataContainer
Definition: itkPointSet.h:105
itk::Math::e
static constexpr double e
Definition: itkMath.h:56
itk::BSplineControlPointImageFilter::SizeType
typename OutputImageType::SizeType SizeType
Definition: itkBSplineControlPointImageFilter.h:90
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itkPointSet.h
itk::CoxDeBoorBSplineKernelFunction
BSpline kernel used for density estimation and nonparametric regression.
Definition: itkCoxDeBoorBSplineKernelFunction.h:57
itk::BSplineControlPointImageFilter::RealType
float RealType
Definition: itkBSplineControlPointImageFilter.h:94
itk::BSplineControlPointImageFilter::DirectionType
typename OutputImageType::DirectionType DirectionType
Definition: itkBSplineControlPointImageFilter.h:91
itk::BSplineControlPointImageFilter
Process a given a B-spline grid of control points.
Definition: itkBSplineControlPointImageFilter.h:59
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90