ITK  4.4.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
87 <class TScalar = double, unsigned int NDimensions = 3>
88 class ITK_EXPORT CompositeTransform :
89  public MultiTransform<TScalar, NDimensions>
90 {
91 public:
97 
99  itkTypeMacro( CompositeTransform, Transform );
100 
102  itkNewMacro( Self );
103 
105  typedef typename Superclass::TransformType TransformType;
107 
109  typedef typename Superclass::InverseTransformBasePointer InverseTransformBasePointer;
110 
112  typedef typename Superclass::ScalarType ScalarType;
113 
115  typedef typename Superclass::ParametersType ParametersType;
116  typedef typename Superclass::ParametersValueType ParametersValueType;
117 
119  typedef typename Superclass::DerivativeType DerivativeType;
120 
122  typedef typename Superclass::JacobianType JacobianType;
123 
125  typedef typename Superclass::TransformCategoryType TransformCategoryType;
126 
128  typedef typename Superclass::InputPointType InputPointType;
129  typedef typename Superclass::OutputPointType OutputPointType;
130 
132  typedef typename Superclass::InputVectorType InputVectorType;
133  typedef typename Superclass::OutputVectorType OutputVectorType;
134 
136  typedef typename Superclass::InputCovariantVectorType InputCovariantVectorType;
137  typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType;
138 
140  typedef typename Superclass::InputVnlVectorType InputVnlVectorType;
141  typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
142 
144  typedef typename Superclass::InputVectorPixelType InputVectorPixelType;
145  typedef typename Superclass::OutputVectorPixelType OutputVectorPixelType;
146 
148  typedef typename Superclass::InputDiffusionTensor3DType InputDiffusionTensor3DType;
149  typedef typename Superclass::OutputDiffusionTensor3DType OutputDiffusionTensor3DType;
150 
152  typedef typename Superclass::InputSymmetricSecondRankTensorType InputSymmetricSecondRankTensorType;
153  typedef typename Superclass::OutputSymmetricSecondRankTensorType OutputSymmetricSecondRankTensorType;
154 
156  typedef typename Superclass::TransformQueueType TransformQueueType;
157 
160 
162  typedef std::deque<bool> TransformsToOptimizeFlagsType;
163 
165  itkStaticConstMacro( InputDimension, unsigned int, NDimensions );
166  itkStaticConstMacro( OutputDimension, unsigned int, NDimensions );
168 
171  virtual void SetNthTransformToOptimize( SizeValueType i, bool state )
172  {
173  this->m_TransformsToOptimizeFlags.at(i) = state;
174  this->Modified();
175  }
176 
177  virtual void SetNthTransformToOptimizeOn( SizeValueType i )
178  {
179  this->SetNthTransformToOptimize( i, true );
180  }
181 
182  virtual void SetNthTransformToOptimizeOff( SizeValueType i )
183  {
184  this->SetNthTransformToOptimize( i, false );
185  }
186 
187  virtual void SetAllTransformsToOptimize( bool state )
188  {
189  this->m_TransformsToOptimizeFlags.assign(
190  this->m_TransformsToOptimizeFlags.size(), state );
191  this->Modified();
192  }
193 
194  virtual void SetAllTransformsToOptimizeOn()
195  {
196  this->SetAllTransformsToOptimize( true );
197  }
198 
199  virtual void SetAllTransformsToOptimizeOff()
200  {
201  this->SetAllTransformsToOptimize( false );
202  }
203 
204  /* With AddTransform() as the only way to add a transform, we
205  * can have this method to easily allow user to optimize only
206  * the transform added most recenlty. */
207  virtual void SetOnlyMostRecentTransformToOptimizeOn()
208  {
209  this->SetAllTransformsToOptimize( false );
210  this->SetNthTransformToOptimizeOn( this->GetNumberOfTransforms() - 1 );
211  }
212 
213  /* Get whether the Nth transform is set to be optimzied */
214  /* NOTE: ambiguous function name here - are we getting if the Nth transform
215  is set to be optimized, or the Nth of the transforms that are set to be
216  optimized? */
217  virtual bool GetNthTransformToOptimize( SizeValueType i ) const
218  {
219  return this->m_TransformsToOptimizeFlags.at(i);
220  }
221 
223  virtual const TransformsToOptimizeFlagsType & GetTransformsToOptimizeFlags() const
224  {
225  return this->m_TransformsToOptimizeFlags;
226  }
227 
228  virtual void ClearTransformQueue()
229  {
230  Superclass::ClearTransformQueue();
231  this->m_TransformsToOptimizeFlags.clear();
232  }
233 
239  bool GetInverse( Self *inverse ) const;
240 
241  virtual InverseTransformBasePointer GetInverseTransform() const;
242 
257  virtual OutputPointType TransformPoint( const InputPointType & inputPoint ) const;
258 
260  using Superclass::TransformVector;
261  virtual OutputVectorType TransformVector(const InputVectorType &) const;
262 
263  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector) const;
264 
265  virtual OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector ) const;
266 
267  virtual OutputVectorType TransformVector(const InputVectorType & inputVector,
268  const InputPointType & inputPoint ) const;
269 
270  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector,
271  const InputPointType & inputPoint ) const;
272 
273  virtual OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector,
274  const InputPointType & inputPoint ) const;
275 
277  using Superclass::TransformCovariantVector;
278  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const;
279 
280  virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const;
281 
282  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & inputVector,
283  const InputPointType & inputPoint ) const;
284 
285  virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType & inputVector,
286  const InputPointType & inputPoint ) const;
287 
289  using Superclass::TransformDiffusionTensor3D;
290  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
291  const InputDiffusionTensor3DType & inputTensor) const;
292 
293  virtual OutputVectorPixelType TransformDiffusionTensor3D(
294  const InputVectorPixelType & inputTensor) const;
295 
296  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
297  const InputDiffusionTensor3DType & inputTensor,
298  const InputPointType & inputPoint ) const;
299 
300  virtual OutputVectorPixelType TransformDiffusionTensor3D(
301  const InputVectorPixelType & inputTensor,
302  const InputPointType & inputPoint ) const;
303 
305  using Superclass::TransformSymmetricSecondRankTensor;
306  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
307  const InputSymmetricSecondRankTensorType & inputTensor) const;
308 
309  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
310  const InputVectorPixelType & inputTensor) const;
311 
312  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
313  const InputSymmetricSecondRankTensorType & inputTensor,
314  const InputPointType & inputPoint ) const;
315 
316  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
317  const InputVectorPixelType & inputTensor,
318  const InputPointType & inputPoint ) const;
319 
324  virtual TransformCategoryType GetTransformCategory() const;
325 
336  virtual const ParametersType & GetParameters(void) const;
337 
338  /* SetParameters only for transforms that are set to be optimized
339  * See GetParameters() for parameter ordering. */
340  virtual void SetParameters(const ParametersType & p);
341 
342  /* GetFixedParameters only for transforms that are set to be optimized
343  * See GetParameters() for parameter ordering. */
344  virtual const ParametersType & GetFixedParameters(void) const;
345 
346  /* SetFixedParameters only for transforms that are set to be optimized.
347  * See GetParameters() for parameter ordering. */
348  virtual void SetFixedParameters(const ParametersType & fixedParameters);
349 
350  /* Get total number of parameters for transforms that are set to be
351  * optimized */
352  virtual NumberOfParametersType GetNumberOfParameters(void) const;
353 
354  /* Get total number of local parameters for transforms that are set
355  * to be optimized */
356  virtual NumberOfParametersType GetNumberOfLocalParameters(void) const;
357 
358  /* Get total number of fixed parameters for transforms that are set
359  * to be optimized */
360  virtual NumberOfParametersType GetNumberOfFixedParameters(void) const;
361 
364  virtual void UpdateTransformParameters( const DerivativeType & update, ScalarType factor = 1.0 );
365 
369  virtual void FlattenTransformQueue();
370 
375  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & p, JacobianType & j) const;
376 
377 protected:
379  virtual ~CompositeTransform();
380  void PrintSelf( std::ostream& os, Indent indent ) const;
381 
383  virtual typename LightObject::Pointer InternalClone() const;
384 
385  virtual void PushFrontTransform( TransformTypePointer t )
386  {
387  Superclass::PushFrontTransform( t );
388  /* Add element to list of flags, and set true by default */
389  this->m_TransformsToOptimizeFlags.push_front( true );
390  }
391 
392  virtual void PushBackTransform( TransformTypePointer t )
393  {
394  Superclass::PushBackTransform( t );
395  /* Add element to list of flags, and set true by default */
396  this->m_TransformsToOptimizeFlags.push_back( true );
397  }
398 
399  virtual void PopFrontTransform()
400  {
401  Superclass::PopFrontTransform();
402  this->m_TransformsToOptimizeFlags.pop_front();
403  }
404 
405  virtual void PopBackTransform()
406  {
407  Superclass::PopBackTransform();
408  this->m_TransformsToOptimizeFlags.pop_back();
409  }
410 
412  TransformQueueType & GetTransformsToOptimizeQueue() const;
413 
416 
417 private:
418  CompositeTransform( const Self & ); // purposely not implemented
419  void operator=( const Self & ); // purposely not implemented
420 
422 
423 };
424 
425 } // end namespace itk
426 
427 #ifndef ITK_MANUAL_INSTANTIATION
428 #include "itkCompositeTransform.hxx"
429 #endif
430 
431 #endif // __itkCompositeTransform_h
432