ITK  6.0.0
Insight Toolkit
itkCompositeTransform.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 itkCompositeTransform_h
19 #define itkCompositeTransform_h
20 
21 #include "itkMultiTransform.h"
22 
23 #include <deque>
24 
25 namespace itk
26 {
27 
86 template <typename TParametersValueType = double, unsigned int VDimension = 3>
87 class ITK_TEMPLATE_EXPORT CompositeTransform : public MultiTransform<TParametersValueType, VDimension, VDimension>
88 {
89 public:
90  ITK_DISALLOW_COPY_AND_MOVE(CompositeTransform);
91 
97 
99  itkOverrideGetNameOfClassMacro(CompositeTransform);
100 
102  itkNewMacro(Self);
103 
106  using typename Superclass::TransformTypePointer;
107 
110 
112  using typename Superclass::ScalarType;
113 
115  using typename Superclass::FixedParametersType;
116  using typename Superclass::FixedParametersValueType;
117  using typename Superclass::ParametersType;
118  using typename Superclass::ParametersValueType;
119 
121  using typename Superclass::DerivativeType;
122 
124  using typename Superclass::JacobianType;
125  using typename Superclass::JacobianPositionType;
127 
129  using typename Superclass::TransformCategoryEnum;
130 
132  using typename Superclass::InputPointType;
133  using typename Superclass::OutputPointType;
134 
136  using typename Superclass::InputVectorType;
137  using typename Superclass::OutputVectorType;
138 
142 
144  using typename Superclass::InputVnlVectorType;
145  using typename Superclass::OutputVnlVectorType;
146 
148  using typename Superclass::InputVectorPixelType;
149  using typename Superclass::OutputVectorPixelType;
150 
154 
158 
160  using typename Superclass::TransformQueueType;
161 
163  using typename Superclass::NumberOfParametersType;
164 
166  using TransformsToOptimizeFlagsType = std::deque<bool>;
167 
169  static constexpr unsigned int InputDimension = VDimension;
170  static constexpr unsigned int OutputDimension = VDimension;
171 
174  virtual void
176  {
177  this->m_TransformsToOptimizeFlags.at(i) = state;
178  this->Modified();
179  }
180 
181  virtual void
183  {
184  this->SetNthTransformToOptimize(i, true);
185  }
186 
187  virtual void
189  {
190  this->SetNthTransformToOptimize(i, false);
191  }
192 
193  virtual void
195  {
196  this->m_TransformsToOptimizeFlags.assign(this->m_TransformsToOptimizeFlags.size(), state);
197  this->Modified();
198  }
199 
200  virtual void
202  {
203  this->SetAllTransformsToOptimize(true);
204  }
205 
206  virtual void
208  {
209  this->SetAllTransformsToOptimize(false);
210  }
211 
212  /* With AddTransform() as the only way to add a transform, we
213  * can have this method to easily allow user to optimize only
214  * the transform added most recently. */
215  virtual void
217  {
218  this->SetAllTransformsToOptimize(false);
219  this->SetNthTransformToOptimizeOn(this->GetNumberOfTransforms() - 1);
220  }
221 
222  /* Get whether the Nth transform is set to be optimizied */
223  /* NOTE: ambiguous function name here - are we getting if the Nth transform
224  is set to be optimized, or the Nth of the transforms that are set to be
225  optimized? */
226  virtual bool
228  {
229  return this->m_TransformsToOptimizeFlags.at(i);
230  }
231 
233  virtual const TransformsToOptimizeFlagsType &
235  {
236  return this->m_TransformsToOptimizeFlags;
237  }
238 
239  void
241  {
242  Superclass::ClearTransformQueue();
243  this->m_TransformsToOptimizeFlags.clear();
244  }
245 
251  bool
252  GetInverse(Self * inverse) const;
253 
254  InverseTransformBasePointer
255  GetInverseTransform() const override;
256 
271  OutputPointType
272  TransformPoint(const InputPointType & inputPoint) const override;
273 
275  using Superclass::TransformVector;
276  OutputVectorType
277  TransformVector(const InputVectorType &) const override;
278 
279  OutputVnlVectorType
280  TransformVector(const InputVnlVectorType & inputVector) const override;
281 
282  OutputVectorPixelType
283  TransformVector(const InputVectorPixelType & inputVector) const override;
284 
285  OutputVectorType
286  TransformVector(const InputVectorType & inputVector, const InputPointType & inputPoint) const override;
287 
288  OutputVnlVectorType
289  TransformVector(const InputVnlVectorType & inputVector, const InputPointType & inputPoint) const override;
290 
291  OutputVectorPixelType
292  TransformVector(const InputVectorPixelType & inputVector, const InputPointType & inputPoint) const override;
293 
295  using Superclass::TransformCovariantVector;
296  OutputCovariantVectorType
297  TransformCovariantVector(const InputCovariantVectorType &) const override;
298 
299  OutputVectorPixelType
300  TransformCovariantVector(const InputVectorPixelType &) const override;
301 
302  OutputCovariantVectorType
303  TransformCovariantVector(const InputCovariantVectorType & inputVector,
304  const InputPointType & inputPoint) const override;
305 
306  OutputVectorPixelType
307  TransformCovariantVector(const InputVectorPixelType & inputVector, const InputPointType & inputPoint) const override;
308 
310  using Superclass::TransformDiffusionTensor3D;
311  OutputDiffusionTensor3DType
312  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & inputTensor) const override;
313 
314  OutputVectorPixelType
315  TransformDiffusionTensor3D(const InputVectorPixelType & inputTensor) const override;
316 
317  OutputDiffusionTensor3DType
318  TransformDiffusionTensor3D(const InputDiffusionTensor3DType & inputTensor,
319  const InputPointType & inputPoint) const override;
320 
321  OutputVectorPixelType
322  TransformDiffusionTensor3D(const InputVectorPixelType & inputTensor,
323  const InputPointType & inputPoint) const override;
324 
326  using Superclass::TransformSymmetricSecondRankTensor;
327  OutputSymmetricSecondRankTensorType
328  TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType & inputTensor) const override;
329 
330  OutputVectorPixelType
331  TransformSymmetricSecondRankTensor(const InputVectorPixelType & inputTensor) const override;
332 
333  OutputSymmetricSecondRankTensorType
334  TransformSymmetricSecondRankTensor(const InputSymmetricSecondRankTensorType & inputTensor,
335  const InputPointType & inputPoint) const override;
336 
337  OutputVectorPixelType
338  TransformSymmetricSecondRankTensor(const InputVectorPixelType & inputTensor,
339  const InputPointType & inputPoint) const override;
340 
345  TransformCategoryEnum
346  GetTransformCategory() const override;
347 
358  const ParametersType &
359  GetParameters() const override;
360 
361  /* SetParameters only for transforms that are set to be optimized
362  * See GetParameters() for parameter ordering. */
363  void
364  SetParameters(const ParametersType & inputParameters) override;
365 
366  /* GetFixedParameters only for transforms that are set to be optimized
367  * See GetParameters() for parameter ordering. */
368  const FixedParametersType &
369  GetFixedParameters() const override;
370 
371  /* SetFixedParameters only for transforms that are set to be optimized.
372  * See GetParameters() for parameter ordering. */
373  void
374  SetFixedParameters(const FixedParametersType & inputParameters) override;
375 
376  /* Get total number of parameters for transforms that are set to be
377  * optimized */
378  NumberOfParametersType
379  GetNumberOfParameters() const override;
380 
381  /* Get total number of local parameters for transforms that are set
382  * to be optimized */
383  NumberOfParametersType
384  GetNumberOfLocalParameters() const override;
385 
386  /* Get total number of fixed parameters for transforms that are set
387  * to be optimized */
388  NumberOfParametersType
389  GetNumberOfFixedParameters() const override;
390 
393  void
394  UpdateTransformParameters(const DerivativeType & update, ScalarType factor = 1.0) override;
395 
399  virtual void
400  FlattenTransformQueue();
401 
406  void
407  ComputeJacobianWithRespectToParameters(const InputPointType & p, JacobianType & outJacobian) const override;
408 
417  void
418  ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType & p,
419  JacobianType & outJacobian,
420  JacobianType & cacheJacobian) const override;
423 protected:
424  CompositeTransform() = default;
425  ~CompositeTransform() override = default;
426  void
427  PrintSelf(std::ostream & os, Indent indent) const override;
428 
430  typename LightObject::Pointer
431  InternalClone() const override;
432 
433  void
435  {
436  Superclass::PushFrontTransform(t);
437  /* Add element to list of flags, and set true by default */
438  this->m_TransformsToOptimizeFlags.push_front(true);
439  }
440 
441  void
443  {
444  Superclass::PushBackTransform(t);
445  /* Add element to list of flags, and set true by default */
446  this->m_TransformsToOptimizeFlags.push_back(true);
447  }
448 
449  void
450  PopFrontTransform() override
451  {
452  Superclass::PopFrontTransform();
453  this->m_TransformsToOptimizeFlags.pop_front();
454  }
455 
456  void
457  PopBackTransform() override
458  {
459  Superclass::PopBackTransform();
460  this->m_TransformsToOptimizeFlags.pop_back();
461  }
462 
464  const TransformQueueType &
465  GetTransformsToOptimizeQueue() const;
466 
467  mutable TransformQueueType m_TransformsToOptimizeQueue{};
468  TransformsToOptimizeFlagsType m_TransformsToOptimizeFlags{};
469 
470 private:
471  mutable ModifiedTimeType m_PreviousTransformsToOptimizeUpdateTime{};
472 };
473 
474 } // end namespace itk
475 
476 #ifndef ITK_MANUAL_INSTANTIATION
477 # include "itkCompositeTransform.hxx"
478 #endif
479 
480 #endif // itkCompositeTransform_h
itkMultiTransform.h
itk::CompositeTransform
This class contains a list of transforms and concatenates them by composition.
Definition: itkCompositeTransform.h:87
itk::ModifiedTimeType
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:105
itk::Transform< TParametersValueType, VDimension, VSubDimensions >::OutputVnlVectorType
vnl_vector_fixed< TParametersValueType, VOutputDimension > OutputVnlVectorType
Definition: itkTransform.h:157
itk::CompositeTransform::SetNthTransformToOptimizeOn
virtual void SetNthTransformToOptimizeOn(SizeValueType i)
Definition: itkCompositeTransform.h:182
itk::Transform< TParametersValueType, VDimension, VSubDimensions >::InverseTransformBasePointer
typename InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkTransform.h:167
itk::CompositeTransform::GetNthTransformToOptimize
virtual bool GetNthTransformToOptimize(SizeValueType i) const
Definition: itkCompositeTransform.h:227
itk::CompositeTransform::PopBackTransform
void PopBackTransform() override
Definition: itkCompositeTransform.h:457
itk::CompositeTransform::SetAllTransformsToOptimizeOn
virtual void SetAllTransformsToOptimizeOn()
Definition: itkCompositeTransform.h:201
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::CompositeTransform::PushBackTransform
void PushBackTransform(TransformTypePointer t) override
Definition: itkCompositeTransform.h:442
itk::DiffusionTensor3D
Represent a diffusion tensor as used in DTI images.
Definition: itkDiffusionTensor3D.h:79
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::CompositeTransform::SetOnlyMostRecentTransformToOptimizeOn
virtual void SetOnlyMostRecentTransformToOptimizeOn()
Definition: itkCompositeTransform.h:216
itk::CompositeTransform::PopFrontTransform
void PopFrontTransform() override
Definition: itkCompositeTransform.h:450
itk::MultiTransform
This abstract class contains a list of transforms and provides basic methods.
Definition: itkMultiTransform.h:63
itk::SymmetricSecondRankTensor
Represent a symmetric tensor of second rank.
Definition: itkSymmetricSecondRankTensor.h:75
itk::CompositeTransform::GetTransformsToOptimizeFlags
virtual const TransformsToOptimizeFlagsType & GetTransformsToOptimizeFlags() const
Definition: itkCompositeTransform.h:234
itk::MultiTransform< TParametersValueType, VDimension, VDimension >::TransformTypePointer
typename TransformType::Pointer TransformTypePointer
Definition: itkMultiTransform.h:79
itk::CompositeTransform::ClearTransformQueue
void ClearTransformQueue() override
Definition: itkCompositeTransform.h:240
itk::MultiTransform< TParametersValueType, VDimension, VDimension >::TransformQueueType
std::deque< TransformTypePointer > TransformQueueType
Definition: itkMultiTransform.h:140
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::CompositeTransform::TransformType
typename Superclass::TransformType TransformType
Definition: itkCompositeTransform.h:105
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::Transform< TParametersValueType, VDimension, VSubDimensions >::JacobianPositionType
vnl_matrix_fixed< ParametersValueType, VOutputDimension, VInputDimension > JacobianPositionType
Definition: itkTransform.h:131
itk::CompositeTransform::SetNthTransformToOptimize
virtual void SetNthTransformToOptimize(SizeValueType i, bool state)
Definition: itkCompositeTransform.h:175
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::MultiTransform< TParametersValueType, VDimension, VDimension >::ScalarType
ParametersValueType ScalarType
Definition: itkMultiTransform.h:88
itk::Transform< TParametersValueType, VDimension, VSubDimensions >::InverseJacobianPositionType
vnl_matrix_fixed< ParametersValueType, VInputDimension, VOutputDimension > InverseJacobianPositionType
Definition: itkTransform.h:132
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::CompositeTransform::SetAllTransformsToOptimize
virtual void SetAllTransformsToOptimize(bool state)
Definition: itkCompositeTransform.h:194
itk::Array2D
Array2D class representing a 2D array.
Definition: itkArray2D.h:42
itk::CompositeTransform::TransformsToOptimizeFlagsType
std::deque< bool > TransformsToOptimizeFlagsType
Definition: itkCompositeTransform.h:166
itk::CompositeTransform::PushFrontTransform
void PushFrontTransform(TransformTypePointer t) override
Definition: itkCompositeTransform.h:434
itk::CompositeTransform::SetAllTransformsToOptimizeOff
virtual void SetAllTransformsToOptimizeOff()
Definition: itkCompositeTransform.h:207
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::CompositeTransform::SetNthTransformToOptimizeOff
virtual void SetNthTransformToOptimizeOff(SizeValueType i)
Definition: itkCompositeTransform.h:188
itk::Transform< TParametersValueType, VDimension, VSubDimensions >::InputVnlVectorType
vnl_vector_fixed< TParametersValueType, VInputDimension > InputVnlVectorType
Definition: itkTransform.h:156