ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkCompositeTransform.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 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 :
88  public MultiTransform<TParametersValueType, NDimensions, NDimensions>
89 {
90 public:
91  ITK_DISALLOW_COPY_AND_ASSIGN(CompositeTransform);
92 
98 
100  itkTypeMacro( CompositeTransform, Transform );
101 
103  itkNewMacro( Self );
104 
106  using TransformType = typename Superclass::TransformType;
107  using TransformTypePointer = typename Superclass::TransformTypePointer;
108 
110  using InverseTransformBasePointer = typename Superclass::InverseTransformBasePointer;
111 
113  using ScalarType = typename Superclass::ScalarType;
114 
116  using FixedParametersType = typename Superclass::FixedParametersType;
117  using FixedParametersValueType = typename Superclass::FixedParametersValueType;
118  using ParametersType = typename Superclass::ParametersType;
119  using ParametersValueType = typename Superclass::ParametersValueType;
120 
122  using DerivativeType = typename Superclass::DerivativeType;
123 
125  using JacobianType = typename Superclass::JacobianType;
126  using JacobianPositionType = typename Superclass::JacobianPositionType;
127  using InverseJacobianPositionType = typename Superclass::InverseJacobianPositionType;
128 
130  using TransformCategoryType = typename Superclass::TransformCategoryType;
131 
133  using InputPointType = typename Superclass::InputPointType;
134  using OutputPointType = typename Superclass::OutputPointType;
135 
137  using InputVectorType = typename Superclass::InputVectorType;
138  using OutputVectorType = typename Superclass::OutputVectorType;
139 
141  using InputCovariantVectorType = typename Superclass::InputCovariantVectorType;
142  using OutputCovariantVectorType = typename Superclass::OutputCovariantVectorType;
143 
145  using InputVnlVectorType = typename Superclass::InputVnlVectorType;
146  using OutputVnlVectorType = typename Superclass::OutputVnlVectorType;
147 
149  using InputVectorPixelType = typename Superclass::InputVectorPixelType;
150  using OutputVectorPixelType = typename Superclass::OutputVectorPixelType;
151 
153  using InputDiffusionTensor3DType = typename Superclass::InputDiffusionTensor3DType;
154  using OutputDiffusionTensor3DType = typename Superclass::OutputDiffusionTensor3DType;
155 
157  using InputSymmetricSecondRankTensorType = typename Superclass::InputSymmetricSecondRankTensorType;
158  using OutputSymmetricSecondRankTensorType = typename Superclass::OutputSymmetricSecondRankTensorType;
159 
161  using TransformQueueType = typename Superclass::TransformQueueType;
162 
164  using NumberOfParametersType = typename Superclass::NumberOfParametersType;
165 
167  using TransformsToOptimizeFlagsType = std::deque<bool>;
168 
170  static constexpr unsigned int InputDimension = NDimensions;
171  static constexpr unsigned int OutputDimension = NDimensions;
172 
175  virtual void SetNthTransformToOptimize( SizeValueType i, bool state )
176  {
177  this->m_TransformsToOptimizeFlags.at(i) = state;
178  this->Modified();
179  }
180 
182  {
183  this->SetNthTransformToOptimize( i, true );
184  }
185 
187  {
188  this->SetNthTransformToOptimize( i, false );
189  }
190 
191  virtual void SetAllTransformsToOptimize( bool state )
192  {
193  this->m_TransformsToOptimizeFlags.assign(
194  this->m_TransformsToOptimizeFlags.size(), state );
195  this->Modified();
196  }
197 
199  {
200  this->SetAllTransformsToOptimize( true );
201  }
202 
204  {
205  this->SetAllTransformsToOptimize( false );
206  }
207 
208  /* With AddTransform() as the only way to add a transform, we
209  * can have this method to easily allow user to optimize only
210  * the transform added most recenlty. */
212  {
213  this->SetAllTransformsToOptimize( false );
214  this->SetNthTransformToOptimizeOn( this->GetNumberOfTransforms() - 1 );
215  }
216 
217  /* Get whether the Nth transform is set to be optimzied */
218  /* NOTE: ambiguous function name here - are we getting if the Nth transform
219  is set to be optimized, or the Nth of the transforms that are set to be
220  optimized? */
221  virtual bool GetNthTransformToOptimize( SizeValueType i ) const
222  {
223  return this->m_TransformsToOptimizeFlags.at(i);
224  }
225 
228  {
229  return this->m_TransformsToOptimizeFlags;
230  }
231 
232  void ClearTransformQueue() override
233  {
234  Superclass::ClearTransformQueue();
235  this->m_TransformsToOptimizeFlags.clear();
236  }
237 
243  bool GetInverse( Self *inverse ) const;
244 
245  InverseTransformBasePointer GetInverseTransform() const override;
246 
261  OutputPointType TransformPoint( const InputPointType & inputPoint ) const override;
262 
264  using Superclass::TransformVector;
265  OutputVectorType TransformVector(const InputVectorType &) const override;
266 
267  OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector) const override;
268 
269  OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector ) const override;
270 
271  OutputVectorType TransformVector(const InputVectorType & inputVector,
272  const InputPointType & inputPoint ) const override;
273 
274  OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector,
275  const InputPointType & inputPoint ) const override;
276 
277  OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector,
278  const InputPointType & inputPoint ) const override;
279 
281  using Superclass::TransformCovariantVector;
282  OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const override;
283 
284  OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const override;
285 
286  OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & inputVector,
287  const InputPointType & inputPoint ) const override;
288 
289  OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType & inputVector,
290  const InputPointType & inputPoint ) const override;
291 
293  using Superclass::TransformDiffusionTensor3D;
294  OutputDiffusionTensor3DType TransformDiffusionTensor3D(
295  const InputDiffusionTensor3DType & inputTensor) const override;
296 
297  OutputVectorPixelType TransformDiffusionTensor3D(
298  const InputVectorPixelType & inputTensor) const override;
299 
300  OutputDiffusionTensor3DType TransformDiffusionTensor3D(
301  const InputDiffusionTensor3DType & inputTensor,
302  const InputPointType & inputPoint ) const override;
303 
304  OutputVectorPixelType TransformDiffusionTensor3D(
305  const InputVectorPixelType & inputTensor,
306  const InputPointType & inputPoint ) const override;
307 
309  using Superclass::TransformSymmetricSecondRankTensor;
310  OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
311  const InputSymmetricSecondRankTensorType & inputTensor) const override;
312 
313  OutputVectorPixelType TransformSymmetricSecondRankTensor(
314  const InputVectorPixelType & inputTensor) const override;
315 
316  OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
317  const InputSymmetricSecondRankTensorType & inputTensor,
318  const InputPointType & inputPoint ) const override;
319 
320  OutputVectorPixelType TransformSymmetricSecondRankTensor(
321  const InputVectorPixelType & inputTensor,
322  const InputPointType & inputPoint ) const override;
323 
328  TransformCategoryType GetTransformCategory() const override;
329 
340  const ParametersType & GetParameters() const override;
341 
342  /* SetParameters only for transforms that are set to be optimized
343  * See GetParameters() for parameter ordering. */
344  void SetParameters(const ParametersType & p) override;
345 
346  /* GetFixedParameters only for transforms that are set to be optimized
347  * See GetParameters() for parameter ordering. */
348  const FixedParametersType & GetFixedParameters() const override;
349 
350  /* SetFixedParameters only for transforms that are set to be optimized.
351  * See GetParameters() for parameter ordering. */
352  void SetFixedParameters(const FixedParametersType & fixedParameters) override;
353 
354  /* Get total number of parameters for transforms that are set to be
355  * optimized */
356  NumberOfParametersType GetNumberOfParameters() const override;
357 
358  /* Get total number of local parameters for transforms that are set
359  * to be optimized */
360  NumberOfParametersType GetNumberOfLocalParameters() const override;
361 
362  /* Get total number of fixed parameters for transforms that are set
363  * to be optimized */
364  NumberOfParametersType GetNumberOfFixedParameters() const override;
365 
368  void UpdateTransformParameters( const DerivativeType & update, ScalarType factor = 1.0 ) override;
369 
373  virtual void FlattenTransformQueue();
374 
379  void ComputeJacobianWithRespectToParameters(const InputPointType & p, JacobianType & j) const override;
380 
389  void ComputeJacobianWithRespectToParametersCachedTemporaries( const InputPointType & p,
390  JacobianType & outJacobian,
391  JacobianType & cacheJacobian ) const override;
393 
394 protected:
396  ~CompositeTransform() override = default;
397  void PrintSelf( std::ostream& os, Indent indent ) const override;
398 
400  typename LightObject::Pointer InternalClone() const override;
401 
403  {
404  Superclass::PushFrontTransform( t );
405  /* Add element to list of flags, and set true by default */
406  this->m_TransformsToOptimizeFlags.push_front( true );
407  }
408 
410  {
411  Superclass::PushBackTransform( t );
412  /* Add element to list of flags, and set true by default */
413  this->m_TransformsToOptimizeFlags.push_back( true );
414  }
415 
416  void PopFrontTransform() override
417  {
418  Superclass::PopFrontTransform();
419  this->m_TransformsToOptimizeFlags.pop_front();
420  }
421 
422  void PopBackTransform() override
423  {
424  Superclass::PopBackTransform();
425  this->m_TransformsToOptimizeFlags.pop_back();
426  }
427 
429  TransformQueueType & GetTransformsToOptimizeQueue() const;
430 
433 
434 private:
436 
437 };
438 
439 } // end namespace itk
440 
441 #ifndef ITK_MANUAL_INSTANTIATION
442 #include "itkCompositeTransform.hxx"
443 #endif
444 
445 #endif // itkCompositeTransform_h
virtual void SetAllTransformsToOptimizeOff()
typename Superclass::InverseTransformBasePointer InverseTransformBasePointer
typename Superclass::TransformType TransformType
Light weight base class for most itk classes.
std::deque< bool > TransformsToOptimizeFlagsType
typename Superclass::FixedParametersType FixedParametersType
typename Superclass::InputSymmetricSecondRankTensorType InputSymmetricSecondRankTensorType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
virtual void SetAllTransformsToOptimize(bool state)
typename Superclass::ParametersType ParametersType
ModifiedTimeType m_PreviousTransformsToOptimizeUpdateTime
TransformsToOptimizeFlagsType m_TransformsToOptimizeFlags
typename Superclass::NumberOfParametersType NumberOfParametersType
virtual void SetNthTransformToOptimize(SizeValueType i, bool state)
typename Superclass::DerivativeType DerivativeType
virtual void SetNthTransformToOptimizeOff(SizeValueType i)
typename Superclass::FixedParametersValueType FixedParametersValueType
typename Superclass::ParametersValueType ParametersValueType
typename Superclass::JacobianPositionType JacobianPositionType
void PushFrontTransform(TransformTypePointer t) override
typename Superclass::OutputCovariantVectorType OutputCovariantVectorType
virtual void SetOnlyMostRecentTransformToOptimizeOn()
typename Superclass::InputVnlVectorType InputVnlVectorType
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
virtual bool GetNthTransformToOptimize(SizeValueType i) const
typename Superclass::InputVectorType InputVectorType
typename Superclass::TransformTypePointer TransformTypePointer
TransformQueueType m_TransformsToOptimizeQueue
This class contains a list of transforms and concatenates them by composition.
typename Superclass::OutputDiffusionTensor3DType OutputDiffusionTensor3DType
virtual const TransformsToOptimizeFlagsType & GetTransformsToOptimizeFlags() const
typename Superclass::OutputVectorPixelType OutputVectorPixelType
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:104
typename Superclass::ScalarType ScalarType
typename Superclass::OutputSymmetricSecondRankTensorType OutputSymmetricSecondRankTensorType
This abstract class contains a list of transforms and provides basic methods.
typename Superclass::OutputVectorType OutputVectorType
typename Superclass::InputDiffusionTensor3DType InputDiffusionTensor3DType
typename Superclass::InverseJacobianPositionType InverseJacobianPositionType
typename Superclass::InputCovariantVectorType InputCovariantVectorType
virtual void SetAllTransformsToOptimizeOn()
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename Superclass::InputVectorPixelType InputVectorPixelType
typename Superclass::OutputPointType OutputPointType
virtual void SetNthTransformToOptimizeOn(SizeValueType i)
typename Superclass::JacobianType JacobianType
typename Superclass::TransformQueueType TransformQueueType
typename Superclass::OutputVnlVectorType OutputVnlVectorType
void PushBackTransform(TransformTypePointer t) override
typename Superclass::InputPointType InputPointType