ITK  4.2.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 "itkTransform.h"
22 
23 #include <deque>
24 
25 namespace itk
26 {
27 
100 template
101 <class TScalar = double, unsigned int NDimensions = 3>
102 class ITK_EXPORT CompositeTransform :
103  public Transform<TScalar, NDimensions, NDimensions>
104 {
105 public:
111 
113  itkTypeMacro( CompositeTransform, Transform );
114 
116  itkNewMacro( Self );
117 
119  typedef Superclass TransformType;
121 
123  typedef typename Superclass::InverseTransformBasePointer
125 
127  typedef typename Superclass::ScalarType ScalarType;
128 
130  typedef typename Superclass::ParametersType ParametersType;
131  typedef typename Superclass::ParametersValueType ParametersValueType;
132 
134  typedef typename Superclass::DerivativeType DerivativeType;
135 
137  typedef typename Superclass::JacobianType JacobianType;
138 
140  typedef typename Superclass::InputPointType InputPointType;
141  typedef typename Superclass::OutputPointType OutputPointType;
142 
144  typedef typename Superclass::InputVectorType InputVectorType;
145  typedef typename Superclass::OutputVectorType OutputVectorType;
146 
148  typedef typename Superclass::InputCovariantVectorType
150  typedef typename Superclass::OutputCovariantVectorType
152 
154  typedef typename Superclass::InputVnlVectorType InputVnlVectorType;
155  typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
156 
158  typedef typename Superclass::InputVectorPixelType InputVectorPixelType;
159  typedef typename Superclass::OutputVectorPixelType OutputVectorPixelType;
160 
162  typedef typename Superclass::InputDiffusionTensor3DType InputDiffusionTensor3DType;
163  typedef typename Superclass::OutputDiffusionTensor3DType OutputDiffusionTensor3DType;
164 
166  typedef typename Superclass::InputSymmetricSecondRankTensorType
168  typedef typename Superclass::OutputSymmetricSecondRankTensorType
170 
172  typedef std::deque<TransformTypePointer> TransformQueueType;
173 
175  typedef std::deque<bool> TransformsToOptimizeFlagsType;
176 
179 
181  itkStaticConstMacro( InputDimension, unsigned int, NDimensions );
182  itkStaticConstMacro( OutputDimension, unsigned int, NDimensions );
184 
190  void AddTransform( TransformType *t )
191  {
192  this->PushBackTransform( t ); /* Also adds to TransformsToOptimize list */
193  }
194 
195  void RemoveTransform()
196  {
197  this->PopBackTransform(); /* Also removes to TransformsToOptimize list */
198  }
199 
201  const
202  TransformTypePointer GetFrontTransform()
203  {
204  return this->m_TransformQueue.front();
205  }
206 
207  const
208  TransformTypePointer GetBackTransform()
209  {
210  return this->m_TransformQueue.back();
211  }
212 
213  const
214  TransformTypePointer GetNthTransform( size_t n ) const
215  {
216  return this->m_TransformQueue[n];
217  }
218 
221  void SetNthTransformToOptimize( size_t i, bool state )
222  {
223  this->m_TransformsToOptimizeFlags.at(i) = state;
224  this->Modified();
225  }
226 
227  void SetNthTransformToOptimizeOn( size_t i )
228  {
229  this->SetNthTransformToOptimize( i, true );
230  }
231 
232  void SetNthTransformToOptimizeOff( size_t i )
233  {
234  this->SetNthTransformToOptimize( i, false );
235  }
236 
237  void SetAllTransformsToOptimize( bool state )
238  {
239  this->m_TransformsToOptimizeFlags.assign(
240  this->m_TransformsToOptimizeFlags.size(), state );
241  this->Modified();
242  }
243 
244  void SetAllTransformsToOptimizeOn()
245  {
246  this->SetAllTransformsToOptimize( true );
247  }
248 
249  void SetAllTransformsToOptimizeOff()
250  {
251  this->SetAllTransformsToOptimize( false );
252  }
253 
254  /* With AddTransform() as the only way to add a transform, we
255  * can have this method to easily allow user to optimize only
256  * the transform added most recenlty. */
257  void SetOnlyMostRecentTransformToOptimizeOn()
258  {
259  this->SetAllTransformsToOptimize( false );
260  this->SetNthTransformToOptimizeOn( this->GetNumberOfTransforms() - 1 );
261  }
262 
263  /* Get whether the Nth transform is set to be optimzied */
264  /* NOTE: ambiguous function name here - are we getting if the Nth transform
265  is set to be optimized, or the Nth of the transforms that are set to be
266  optimized? */
267  bool GetNthTransformToOptimize( size_t i ) const
268  {
269  return this->m_TransformsToOptimizeFlags.at(i);
270  }
271 
273  const TransformQueueType & GetTransformQueue() const
274  {
275  return this->m_TransformQueue;
276  }
277 
279  const TransformsToOptimizeFlagsType & GetTransformsToOptimizeFlags() const
280  {
281  return this->m_TransformsToOptimizeFlags;
282  }
283 
285  bool IsTransformQueueEmpty()
286  {
287  return this->m_TransformQueue.empty();
288  }
289 
290  size_t GetNumberOfTransforms() const
291  {
292  return this->m_TransformQueue.size();
293  }
294 
295  void ClearTransformQueue()
296  {
297  this->m_TransformQueue.clear();
298  this->m_TransformsToOptimizeFlags.clear();
299  this->Modified();
300  }
301 
303  bool GetInverse( Self *inverse ) const;
304 
305  virtual InverseTransformBasePointer GetInverseTransform() const;
306 
321  virtual OutputPointType TransformPoint( const InputPointType & inputPoint ) const;
322 
323  /* Note: why was the 'isInsideTransformRegion' flag used below?
324  {
325  bool isInside = true;
326 
327  return this->TransformPoint( inputPoint, isInside );
328  }
329  virtual OutputPointType TransformPoint( const InputPointType& thisPoint,
330  bool &isInsideTransformRegion ) const;
331  */
333  using Superclass::TransformVector;
334  virtual OutputVectorType TransformVector(const InputVectorType &) const;
335 
336  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector) const;
337 
338  virtual OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector ) const;
339 
340  virtual OutputVectorType TransformVector(const InputVectorType & inputVector,
341  const InputPointType & inputPoint ) const;
342 
343  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector,
344  const InputPointType & inputPoint ) const;
345 
346  virtual OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector,
347  const InputPointType & inputPoint ) const;
348 
350  using Superclass::TransformCovariantVector;
351  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const;
352 
353  virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const;
354 
355  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & inputVector,
356  const InputPointType & inputPoint ) const;
357 
358  virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType & inputVector,
359  const InputPointType & inputPoint ) const;
360 
362  using Superclass::TransformDiffusionTensor3D;
363  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
364  const InputDiffusionTensor3DType & inputTensor) const;
365 
366  virtual OutputVectorPixelType TransformDiffusionTensor3D(
367  const InputVectorPixelType & inputTensor) const;
368 
369  virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
370  const InputDiffusionTensor3DType & inputTensor,
371  const InputPointType & inputPoint ) const;
372 
373  virtual OutputVectorPixelType TransformDiffusionTensor3D(
374  const InputVectorPixelType & inputTensor,
375  const InputPointType & inputPoint ) const;
376 
378  using Superclass::TransformSymmetricSecondRankTensor;
379  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
380  const InputSymmetricSecondRankTensorType & inputTensor) const;
381 
382  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
383  const InputVectorPixelType & inputTensor) const;
384 
385  virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
386  const InputSymmetricSecondRankTensorType & inputTensor,
387  const InputPointType & inputPoint ) const;
388 
389  virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
390  const InputVectorPixelType & inputTensor,
391  const InputPointType & inputPoint ) const;
392 
393  virtual bool IsLinear() const;
394 
400  virtual const ParametersType & GetParameters(void) const;
401 
402  /* SetParameters only for transforms that are set to be optimized */
403  virtual void SetParameters(const ParametersType & p);
404 
405  /* GetFixedParameters only for transforms that are set to be optimized */
406  virtual const ParametersType & GetFixedParameters(void) const;
407 
408  /* SetFixedParameters only for transforms that are set to be optimized */
409  virtual void SetFixedParameters(const ParametersType & fixedParameters);
410 
411  /* Get total number of parameters for transforms that are set to be
412  * optimized */
413  virtual NumberOfParametersType GetNumberOfParameters(void) const;
414 
415  /* Get total number of local parameters for transforms that are set
416  * to be optimized */
417  virtual NumberOfParametersType GetNumberOfLocalParameters(void) const;
418 
419  /* Get total number of fixed parameters for transforms that are set
420  * to be optimized */
421  virtual NumberOfParametersType GetNumberOfFixedParameters(void) const;
422 
423  /* Prepare the transform for use, e.g. in registration framework.
424  * Must be called before registration to optimize parameter storage
425  * for more efficient operation, particularly with high-dimensionality
426  * sub-transforms. */
427  // virtual void PrepareForUse(void);
428 
437  virtual void UpdateTransformParameters( const DerivativeType & update, ScalarType factor = 1.0 );
438 
442  virtual void FlattenTransformQueue();
443 
444 
450  virtual bool HasLocalSupport() const;
451 
456  virtual void ComputeJacobianWithRespectToParameters(const InputPointType & p, JacobianType & j) const;
457 
458  virtual void ComputeJacobianWithRespectToPosition(const InputPointType &,
459  JacobianType &) const
460  {
461  itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented "
462  "for " << this->GetNameOfClass() );
463  }
464 
465 protected:
467  virtual ~CompositeTransform();
468  void PrintSelf( std::ostream& os, Indent indent ) const;
469 
471  virtual typename LightObject::Pointer InternalClone() const;
472 
473  void PushFrontTransform( TransformTypePointer t )
474  {
475  this->m_TransformQueue.push_front( t );
476  /* Add element to list of flags, and set true by default */
477  this->m_TransformsToOptimizeFlags.push_front( true );
478  this->Modified();
479  }
480 
481  void PushBackTransform( TransformTypePointer t )
482  {
483  this->m_TransformQueue.push_back( t );
484  /* Add element to list of flags, and set true by default */
485  this->m_TransformsToOptimizeFlags.push_back( true );
486  this->Modified();
487  }
488 
489  void PopFrontTransform()
490  {
491  this->m_TransformQueue.pop_front();
492  this->m_TransformsToOptimizeFlags.pop_front();
493  this->Modified();
494  }
495 
496  void PopBackTransform()
497  {
498  this->m_TransformQueue.pop_back();
499  this->m_TransformsToOptimizeFlags.pop_back();
500  this->Modified();
501  }
502 
508  // void UnifyParameterMemory(void);
509 
512 
515 
517  TransformQueueType & GetTransformsToOptimizeQueue() const;
518 
521 private:
522  CompositeTransform( const Self & ); // purposely not implemented
523  void operator=( const Self & ); // purposely not implemented
524 
526  mutable unsigned long m_LocalParametersUpdateTime;
527 
528 };
529 
530 } // end namespace itk
531 
532 #if ITK_TEMPLATE_EXPLICIT
533 #include "Templates/itkCompositeTransform+-.h"
534 #endif
535 
536 #if ITK_TEMPLATE_TXX
537 #include "itkCompositeTransform.hxx"
538 #endif
539 
540 #endif // __itkCompositeTransform_h
541