ITK  4.13.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:
96 
98  itkTypeMacro( CompositeTransform, Transform );
99 
101  itkNewMacro( Self );
102 
104  typedef typename Superclass::TransformType TransformType;
105  typedef typename Superclass::TransformTypePointer TransformTypePointer;
106 
108  typedef typename Superclass::InverseTransformBasePointer InverseTransformBasePointer;
109 
111  typedef typename Superclass::ScalarType ScalarType;
112 
114  typedef typename Superclass::FixedParametersType FixedParametersType;
115  typedef typename Superclass::FixedParametersValueType FixedParametersValueType;
116  typedef typename Superclass::ParametersType ParametersType;
117  typedef typename Superclass::ParametersValueType ParametersValueType;
118 
120  typedef typename Superclass::DerivativeType DerivativeType;
121 
123  typedef typename Superclass::JacobianType JacobianType;
124 
126  typedef typename Superclass::TransformCategoryType TransformCategoryType;
127 
129  typedef typename Superclass::InputPointType InputPointType;
130  typedef typename Superclass::OutputPointType OutputPointType;
131 
133  typedef typename Superclass::InputVectorType InputVectorType;
134  typedef typename Superclass::OutputVectorType OutputVectorType;
135 
137  typedef typename Superclass::InputCovariantVectorType InputCovariantVectorType;
138  typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType;
139 
141  typedef typename Superclass::InputVnlVectorType InputVnlVectorType;
142  typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
143 
145  typedef typename Superclass::InputVectorPixelType InputVectorPixelType;
146  typedef typename Superclass::OutputVectorPixelType OutputVectorPixelType;
147 
149  typedef typename Superclass::InputDiffusionTensor3DType InputDiffusionTensor3DType;
150  typedef typename Superclass::OutputDiffusionTensor3DType OutputDiffusionTensor3DType;
151 
153  typedef typename Superclass::InputSymmetricSecondRankTensorType InputSymmetricSecondRankTensorType;
154  typedef typename Superclass::OutputSymmetricSecondRankTensorType OutputSymmetricSecondRankTensorType;
155 
157  typedef typename Superclass::TransformQueueType TransformQueueType;
158 
160  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
161 
163  typedef std::deque<bool> TransformsToOptimizeFlagsType;
164 
166  itkStaticConstMacro( InputDimension, unsigned int, NDimensions );
167  itkStaticConstMacro( OutputDimension, unsigned int, NDimensions );
169 
172  virtual void SetNthTransformToOptimize( SizeValueType i, bool state )
173  {
174  this->m_TransformsToOptimizeFlags.at(i) = state;
175  this->Modified();
176  }
177 
179  {
180  this->SetNthTransformToOptimize( i, true );
181  }
182 
184  {
185  this->SetNthTransformToOptimize( i, false );
186  }
187 
188  virtual void SetAllTransformsToOptimize( bool state )
189  {
190  this->m_TransformsToOptimizeFlags.assign(
191  this->m_TransformsToOptimizeFlags.size(), state );
192  this->Modified();
193  }
194 
196  {
197  this->SetAllTransformsToOptimize( true );
198  }
199 
201  {
202  this->SetAllTransformsToOptimize( false );
203  }
204 
205  /* With AddTransform() as the only way to add a transform, we
206  * can have this method to easily allow user to optimize only
207  * the transform added most recenlty. */
209  {
210  this->SetAllTransformsToOptimize( false );
211  this->SetNthTransformToOptimizeOn( this->GetNumberOfTransforms() - 1 );
212  }
213 
214  /* Get whether the Nth transform is set to be optimzied */
215  /* NOTE: ambiguous function name here - are we getting if the Nth transform
216  is set to be optimized, or the Nth of the transforms that are set to be
217  optimized? */
218  virtual bool GetNthTransformToOptimize( SizeValueType i ) const
219  {
220  return this->m_TransformsToOptimizeFlags.at(i);
221  }
222 
225  {
226  return this->m_TransformsToOptimizeFlags;
227  }
228 
229  virtual void ClearTransformQueue() ITK_OVERRIDE
230  {
231  Superclass::ClearTransformQueue();
232  this->m_TransformsToOptimizeFlags.clear();
233  }
234 
240  bool GetInverse( Self *inverse ) const;
241 
242  virtual InverseTransformBasePointer GetInverseTransform() const ITK_OVERRIDE;
243 
258  virtual OutputPointType TransformPoint( const InputPointType & inputPoint ) const ITK_OVERRIDE;
259 
261  using Superclass::TransformVector;
262  virtual OutputVectorType TransformVector(const InputVectorType &) const ITK_OVERRIDE;
263 
264  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector) const ITK_OVERRIDE;
265 
266  virtual OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector ) const ITK_OVERRIDE;
267 
268  virtual OutputVectorType TransformVector(const InputVectorType & inputVector,
269  const InputPointType & inputPoint ) const ITK_OVERRIDE;
270 
271  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector,
272  const InputPointType & inputPoint ) const ITK_OVERRIDE;
273 
274  virtual OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector,
275  const InputPointType & inputPoint ) const ITK_OVERRIDE;
276 
278  using Superclass::TransformCovariantVector;
279  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const ITK_OVERRIDE;
280 
281  virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const ITK_OVERRIDE;
282 
283  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & inputVector,
284  const InputPointType & inputPoint ) const ITK_OVERRIDE;
285 
286  virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType & inputVector,
287  const InputPointType & inputPoint ) const ITK_OVERRIDE;
288 
290  using Superclass::TransformDiffusionTensor3D;
291  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
292  const InputDiffusionTensor3DType & inputTensor) const ITK_OVERRIDE;
293 
294  virtual OutputVectorPixelType TransformDiffusionTensor3D(
295  const InputVectorPixelType & inputTensor) const ITK_OVERRIDE;
296 
297  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
298  const InputDiffusionTensor3DType & inputTensor,
299  const InputPointType & inputPoint ) const ITK_OVERRIDE;
300 
301  virtual OutputVectorPixelType TransformDiffusionTensor3D(
302  const InputVectorPixelType & inputTensor,
303  const InputPointType & inputPoint ) const ITK_OVERRIDE;
304 
306  using Superclass::TransformSymmetricSecondRankTensor;
307  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
308  const InputSymmetricSecondRankTensorType & inputTensor) const ITK_OVERRIDE;
309 
310  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
311  const InputVectorPixelType & inputTensor) const ITK_OVERRIDE;
312 
313  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
314  const InputSymmetricSecondRankTensorType & inputTensor,
315  const InputPointType & inputPoint ) const ITK_OVERRIDE;
316 
317  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
318  const InputVectorPixelType & inputTensor,
319  const InputPointType & inputPoint ) const ITK_OVERRIDE;
320 
325  virtual TransformCategoryType GetTransformCategory() const ITK_OVERRIDE;
326 
337  virtual const ParametersType & GetParameters() const ITK_OVERRIDE;
338 
339  /* SetParameters only for transforms that are set to be optimized
340  * See GetParameters() for parameter ordering. */
341  virtual void SetParameters(const ParametersType & p) ITK_OVERRIDE;
342 
343  /* GetFixedParameters only for transforms that are set to be optimized
344  * See GetParameters() for parameter ordering. */
345  virtual const FixedParametersType & GetFixedParameters() const ITK_OVERRIDE;
346 
347  /* SetFixedParameters only for transforms that are set to be optimized.
348  * See GetParameters() for parameter ordering. */
349  virtual void SetFixedParameters(const FixedParametersType & fixedParameters) ITK_OVERRIDE;
350 
351  /* Get total number of parameters for transforms that are set to be
352  * optimized */
353  virtual NumberOfParametersType GetNumberOfParameters(void) const ITK_OVERRIDE;
354 
355  /* Get total number of local parameters for transforms that are set
356  * to be optimized */
357  virtual NumberOfParametersType GetNumberOfLocalParameters(void) const ITK_OVERRIDE;
358 
359  /* Get total number of fixed parameters for transforms that are set
360  * to be optimized */
361  virtual NumberOfParametersType GetNumberOfFixedParameters(void) const ITK_OVERRIDE;
362 
365  virtual void UpdateTransformParameters( const DerivativeType & update, ScalarType factor = 1.0 ) ITK_OVERRIDE;
366 
370  virtual void FlattenTransformQueue();
371 
376  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & p, JacobianType & j) const ITK_OVERRIDE;
377 
387  virtual void ComputeJacobianWithRespectToParametersCachedTemporaries( const InputPointType & p, JacobianType & outJacobian, JacobianType & jacobianWithRespectToPosition ) const ITK_OVERRIDE;
389 
390 protected:
392  virtual ~CompositeTransform() ITK_OVERRIDE;
393  virtual void PrintSelf( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
394 
396  virtual typename LightObject::Pointer InternalClone() const ITK_OVERRIDE;
397 
398  virtual void PushFrontTransform( TransformTypePointer t ) ITK_OVERRIDE
399  {
400  Superclass::PushFrontTransform( t );
401  /* Add element to list of flags, and set true by default */
402  this->m_TransformsToOptimizeFlags.push_front( true );
403  }
404 
405  virtual void PushBackTransform( TransformTypePointer t ) ITK_OVERRIDE
406  {
407  Superclass::PushBackTransform( t );
408  /* Add element to list of flags, and set true by default */
409  this->m_TransformsToOptimizeFlags.push_back( true );
410  }
411 
412  virtual void PopFrontTransform() ITK_OVERRIDE
413  {
414  Superclass::PopFrontTransform();
415  this->m_TransformsToOptimizeFlags.pop_front();
416  }
417 
418  virtual void PopBackTransform() ITK_OVERRIDE
419  {
420  Superclass::PopBackTransform();
421  this->m_TransformsToOptimizeFlags.pop_back();
422  }
423 
425  TransformQueueType & GetTransformsToOptimizeQueue() const;
426 
429 
430 private:
431  ITK_DISALLOW_COPY_AND_ASSIGN(CompositeTransform);
432 
434 
435 };
436 
437 } // end namespace itk
438 
439 #ifndef ITK_MANUAL_INSTANTIATION
440 #include "itkCompositeTransform.hxx"
441 #endif
442 
443 #endif // itkCompositeTransform_h
virtual void SetAllTransformsToOptimizeOff()
Superclass::InputVectorPixelType InputVectorPixelType
Superclass::ScalarType ScalarType
Superclass::InputDiffusionTensor3DType InputDiffusionTensor3DType
Light weight base class for most itk classes.
Superclass::ParametersValueType ParametersValueType
Superclass::ParametersType ParametersType
virtual void SetAllTransformsToOptimize(bool state)
ModifiedTimeType m_PreviousTransformsToOptimizeUpdateTime
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:164
Superclass::OutputDiffusionTensor3DType OutputDiffusionTensor3DType
TransformsToOptimizeFlagsType m_TransformsToOptimizeFlags
virtual void SetNthTransformToOptimize(SizeValueType i, bool state)
SmartPointer< const Self > ConstPointer
Superclass::OutputVectorType OutputVectorType
Superclass::InputVnlVectorType InputVnlVectorType
virtual void PushBackTransform(TransformTypePointer t) override
virtual void SetNthTransformToOptimizeOff(SizeValueType i)
SmartPointer< Self > Pointer
Superclass::FixedParametersValueType FixedParametersValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:143
Superclass::TransformQueueType TransformQueueType
Superclass::InverseTransformBasePointer InverseTransformBasePointer
Superclass::OutputPointType OutputPointType
virtual void SetOnlyMostRecentTransformToOptimizeOn()
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
Superclass::NumberOfParametersType NumberOfParametersType
virtual bool GetNthTransformToOptimize(SizeValueType i) const
Superclass::JacobianType JacobianType
Superclass::InputSymmetricSecondRankTensorType InputSymmetricSecondRankTensorType
TransformQueueType m_TransformsToOptimizeQueue
This class contains a list of transforms and concatenates them by composition.
virtual void ClearTransformQueue() override
virtual const TransformsToOptimizeFlagsType & GetTransformsToOptimizeFlags() const
Superclass::DerivativeType DerivativeType
Superclass::TransformTypePointer TransformTypePointer
Superclass::OutputVectorPixelType OutputVectorPixelType
This abstract class contains a list of transforms and provides basic methods.
Superclass::OutputCovariantVectorType OutputCovariantVectorType
Superclass::TransformCategoryType TransformCategoryType
Superclass::OutputVnlVectorType OutputVnlVectorType
Superclass::OutputSymmetricSecondRankTensorType OutputSymmetricSecondRankTensorType
Superclass::FixedParametersType FixedParametersType
Superclass::InputVectorType InputVectorType
virtual void SetAllTransformsToOptimizeOn()
Superclass::TransformType TransformType
virtual void PopFrontTransform() override
Control indentation during Print() invocation.
Definition: itkIndent.h:49
std::deque< bool > TransformsToOptimizeFlagsType
virtual void PopBackTransform() override
virtual void SetNthTransformToOptimizeOn(SizeValueType i)
Superclass::InputPointType InputPointType
MultiTransform< TParametersValueType, NDimensions, NDimensions > Superclass
Superclass::InputCovariantVectorType InputCovariantVectorType