ITK  5.2.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  * 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 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 NDimensions = 3>
87 class ITK_TEMPLATE_EXPORT CompositeTransform : public MultiTransform<TParametersValueType, NDimensions, NDimensions>
88 {
89 public:
90  ITK_DISALLOW_COPY_AND_MOVE(CompositeTransform);
91 
97 
99  itkTypeMacro(CompositeTransform, Transform);
100 
102  itkNewMacro(Self);
103 
105  using TransformType = typename Superclass::TransformType;
106  using TransformTypePointer = typename Superclass::TransformTypePointer;
107 
109  using InverseTransformBasePointer = typename Superclass::InverseTransformBasePointer;
110 
112  using ScalarType = typename Superclass::ScalarType;
113 
115  using FixedParametersType = typename Superclass::FixedParametersType;
116  using FixedParametersValueType = typename Superclass::FixedParametersValueType;
117  using ParametersType = typename Superclass::ParametersType;
118  using ParametersValueType = typename Superclass::ParametersValueType;
119 
121  using DerivativeType = typename Superclass::DerivativeType;
122 
124  using JacobianType = typename Superclass::JacobianType;
125  using JacobianPositionType = typename Superclass::JacobianPositionType;
126  using InverseJacobianPositionType = typename Superclass::InverseJacobianPositionType;
127 
129  using TransformCategoryEnum = typename Superclass::TransformCategoryEnum;
130 
132  using InputPointType = typename Superclass::InputPointType;
133  using OutputPointType = typename Superclass::OutputPointType;
134 
136  using InputVectorType = typename Superclass::InputVectorType;
137  using OutputVectorType = typename Superclass::OutputVectorType;
138 
140  using InputCovariantVectorType = typename Superclass::InputCovariantVectorType;
141  using OutputCovariantVectorType = typename Superclass::OutputCovariantVectorType;
142 
144  using InputVnlVectorType = typename Superclass::InputVnlVectorType;
145  using OutputVnlVectorType = typename Superclass::OutputVnlVectorType;
146 
148  using InputVectorPixelType = typename Superclass::InputVectorPixelType;
149  using OutputVectorPixelType = typename Superclass::OutputVectorPixelType;
150 
152  using InputDiffusionTensor3DType = typename Superclass::InputDiffusionTensor3DType;
153  using OutputDiffusionTensor3DType = typename Superclass::OutputDiffusionTensor3DType;
154 
156  using InputSymmetricSecondRankTensorType = typename Superclass::InputSymmetricSecondRankTensorType;
157  using OutputSymmetricSecondRankTensorType = typename Superclass::OutputSymmetricSecondRankTensorType;
158 
160  using TransformQueueType = typename Superclass::TransformQueueType;
161 
163  using NumberOfParametersType = typename Superclass::NumberOfParametersType;
164 
166  using TransformsToOptimizeFlagsType = std::deque<bool>;
167 
169  static constexpr unsigned int InputDimension = NDimensions;
170  static constexpr unsigned int OutputDimension = NDimensions;
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 recenlty. */
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 & p) 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 & fixedParameters) 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 & j) const override;
408 
417  void
418  ComputeJacobianWithRespectToParametersCachedTemporaries(const InputPointType & p,
419  JacobianType & outJacobian,
420  JacobianType & cacheJacobian) const override;
422 
423 protected:
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  TransformQueueType &
465  GetTransformsToOptimizeQueue() const;
466 
469 
470 private:
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::ClearTransformQueue
void ClearTransformQueue() override
Definition: itkCompositeTransform.h:240
itk::CompositeTransform
This class contains a list of transforms and concatenates them by composition.
Definition: itkCompositeTransform.h:87
itk::CompositeTransform::OutputSymmetricSecondRankTensorType
typename Superclass::OutputSymmetricSecondRankTensorType OutputSymmetricSecondRankTensorType
Definition: itkCompositeTransform.h:157
itk::CompositeTransform::FixedParametersType
typename Superclass::FixedParametersType FixedParametersType
Definition: itkCompositeTransform.h:115
itk::CompositeTransform::InputDiffusionTensor3DType
typename Superclass::InputDiffusionTensor3DType InputDiffusionTensor3DType
Definition: itkCompositeTransform.h:152
itk::CompositeTransform::FixedParametersValueType
typename Superclass::FixedParametersValueType FixedParametersValueType
Definition: itkCompositeTransform.h:116
itk::ModifiedTimeType
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:102
itk::CompositeTransform::TransformTypePointer
typename Superclass::TransformTypePointer TransformTypePointer
Definition: itkCompositeTransform.h:106
itk::CompositeTransform::PopFrontTransform
void PopFrontTransform() override
Definition: itkCompositeTransform.h:450
itk::CompositeTransform::JacobianType
typename Superclass::JacobianType JacobianType
Definition: itkCompositeTransform.h:124
itk::CompositeTransform::GetTransformsToOptimizeFlags
virtual const TransformsToOptimizeFlagsType & GetTransformsToOptimizeFlags() const
Definition: itkCompositeTransform.h:234
itk::CompositeTransform::InputCovariantVectorType
typename Superclass::InputCovariantVectorType InputCovariantVectorType
Definition: itkCompositeTransform.h:140
itk::CompositeTransform::InputVnlVectorType
typename Superclass::InputVnlVectorType InputVnlVectorType
Definition: itkCompositeTransform.h:144
itk::CompositeTransform::SetAllTransformsToOptimizeOff
virtual void SetAllTransformsToOptimizeOff()
Definition: itkCompositeTransform.h:207
itk::CompositeTransform::SetNthTransformToOptimizeOn
virtual void SetNthTransformToOptimizeOn(SizeValueType i)
Definition: itkCompositeTransform.h:182
itk::CompositeTransform::m_TransformsToOptimizeQueue
TransformQueueType m_TransformsToOptimizeQueue
Definition: itkCompositeTransform.h:467
itk::CompositeTransform::SetNthTransformToOptimize
virtual void SetNthTransformToOptimize(SizeValueType i, bool state)
Definition: itkCompositeTransform.h:175
itk::CompositeTransform::OutputCovariantVectorType
typename Superclass::OutputCovariantVectorType OutputCovariantVectorType
Definition: itkCompositeTransform.h:141
itk::CompositeTransform::TransformsToOptimizeFlagsType
std::deque< bool > TransformsToOptimizeFlagsType
Definition: itkCompositeTransform.h:166
itk::CompositeTransform::OutputPointType
typename Superclass::OutputPointType OutputPointType
Definition: itkCompositeTransform.h:133
itk::CompositeTransform::ParametersType
typename Superclass::ParametersType ParametersType
Definition: itkCompositeTransform.h:117
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::CompositeTransform::PopBackTransform
void PopBackTransform() override
Definition: itkCompositeTransform.h:457
itk::CompositeTransform::SetOnlyMostRecentTransformToOptimizeOn
virtual void SetOnlyMostRecentTransformToOptimizeOn()
Definition: itkCompositeTransform.h:216
itk::MultiTransform
This abstract class contains a list of transforms and provides basic methods.
Definition: itkMultiTransform.h:65
itk::CompositeTransform::InputSymmetricSecondRankTensorType
typename Superclass::InputSymmetricSecondRankTensorType InputSymmetricSecondRankTensorType
Definition: itkCompositeTransform.h:156
itk::CompositeTransform::DerivativeType
typename Superclass::DerivativeType DerivativeType
Definition: itkCompositeTransform.h:121
itk::CompositeTransform::OutputVectorPixelType
typename Superclass::OutputVectorPixelType OutputVectorPixelType
Definition: itkCompositeTransform.h:149
itk::CompositeTransform::InputPointType
typename Superclass::InputPointType InputPointType
Definition: itkCompositeTransform.h:132
itk::CompositeTransform::TransformQueueType
typename Superclass::TransformQueueType TransformQueueType
Definition: itkCompositeTransform.h:160
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::CompositeTransform::NumberOfParametersType
typename Superclass::NumberOfParametersType NumberOfParametersType
Definition: itkCompositeTransform.h:163
itk::CompositeTransform::PushBackTransform
void PushBackTransform(TransformTypePointer t) override
Definition: itkCompositeTransform.h:442
itk::CompositeTransform::InputVectorPixelType
typename Superclass::InputVectorPixelType InputVectorPixelType
Definition: itkCompositeTransform.h:148
itk::CompositeTransform::OutputDiffusionTensor3DType
typename Superclass::OutputDiffusionTensor3DType OutputDiffusionTensor3DType
Definition: itkCompositeTransform.h:153
itk::CompositeTransform::ScalarType
typename Superclass::ScalarType ScalarType
Definition: itkCompositeTransform.h:112
itk::CompositeTransform::m_PreviousTransformsToOptimizeUpdateTime
ModifiedTimeType m_PreviousTransformsToOptimizeUpdateTime
Definition: itkCompositeTransform.h:471
itk::CompositeTransform::OutputVnlVectorType
typename Superclass::OutputVnlVectorType OutputVnlVectorType
Definition: itkCompositeTransform.h:145
itk::CompositeTransform::SetAllTransformsToOptimize
virtual void SetAllTransformsToOptimize(bool state)
Definition: itkCompositeTransform.h:194
itk::CompositeTransform::InputVectorType
typename Superclass::InputVectorType InputVectorType
Definition: itkCompositeTransform.h:136
itk::CompositeTransform::GetNthTransformToOptimize
virtual bool GetNthTransformToOptimize(SizeValueType i) const
Definition: itkCompositeTransform.h:227
itk::CompositeTransform::PushFrontTransform
void PushFrontTransform(TransformTypePointer t) override
Definition: itkCompositeTransform.h:434
itk::CompositeTransform::JacobianPositionType
typename Superclass::JacobianPositionType JacobianPositionType
Definition: itkCompositeTransform.h:125
itk::CompositeTransform::OutputVectorType
typename Superclass::OutputVectorType OutputVectorType
Definition: itkCompositeTransform.h:137
itk::CompositeTransform::ParametersValueType
typename Superclass::ParametersValueType ParametersValueType
Definition: itkCompositeTransform.h:118
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::CompositeTransform::TransformType
typename Superclass::TransformType TransformType
Definition: itkCompositeTransform.h:105
itk::CompositeTransform::m_TransformsToOptimizeFlags
TransformsToOptimizeFlagsType m_TransformsToOptimizeFlags
Definition: itkCompositeTransform.h:468
itk::CompositeTransform::TransformCategoryEnum
typename Superclass::TransformCategoryEnum TransformCategoryEnum
Definition: itkCompositeTransform.h:129
itk::CompositeTransform::SetNthTransformToOptimizeOff
virtual void SetNthTransformToOptimizeOff(SizeValueType i)
Definition: itkCompositeTransform.h:188
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
itk::CompositeTransform::SetAllTransformsToOptimizeOn
virtual void SetAllTransformsToOptimizeOn()
Definition: itkCompositeTransform.h:201
itk::CompositeTransform::InverseTransformBasePointer
typename Superclass::InverseTransformBasePointer InverseTransformBasePointer
Definition: itkCompositeTransform.h:109
itk::CompositeTransform::InverseJacobianPositionType
typename Superclass::InverseJacobianPositionType InverseJacobianPositionType
Definition: itkCompositeTransform.h:126
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83