ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkRegistrationParameterScalesEstimator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkRegistrationParameterScalesEstimator_h
00019 #define __itkRegistrationParameterScalesEstimator_h
00020 
00021 #include "itkTransform.h"
00022 #include "itkMatrixOffsetTransformBase.h"
00023 #include "itkTranslationTransform.h"
00024 #include "itkIdentityTransform.h"
00025 #include "itkRigid3DPerspectiveTransform.h"
00026 
00027 #include "itkOptimizerParameterScalesEstimator.h"
00028 #include "itkImageRandomConstIteratorWithIndex.h"
00029 #include "itkImageRegionConstIteratorWithIndex.h"
00030 
00031 namespace itk
00032 {
00033 
00048 template < class TMetric >
00049 class ITK_EXPORT RegistrationParameterScalesEstimator : public OptimizerParameterScalesEstimator
00050 {
00051 public:
00053   typedef RegistrationParameterScalesEstimator  Self;
00054   typedef OptimizerParameterScalesEstimator     Superclass;
00055   typedef SmartPointer<Self>                    Pointer;
00056   typedef SmartPointer<const Self>              ConstPointer;
00057 
00059   itkTypeMacro( RegistrationParameterScalesEstimator, OptimizerParameterScalesEstimator );
00060 
00062   typedef typename Superclass::ScalesType           ScalesType;
00063 
00065   typedef typename Superclass::ParametersType       ParametersType;
00066 
00068   typedef typename Superclass::FloatType            FloatType;
00069 
00070   typedef TMetric                                   MetricType;
00071   typedef typename MetricType::ConstPointer         MetricConstPointer;
00072 
00074   typedef typename MetricType::FixedTransformType   FixedTransformType;
00075   typedef typename FixedTransformType::ConstPointer FixedTransformConstPointer;
00076 
00077   typedef typename MetricType::MovingTransformType  MovingTransformType;
00078   typedef typename MovingTransformType::ConstPointer
00079                                                     MovingTransformConstPointer;
00080 
00082   typedef typename TMetric::FixedImageType          FixedImageType;
00083   typedef typename TMetric::MovingImageType         MovingImageType;
00084   typedef typename TMetric::VirtualImageType        VirtualImageType;
00085 
00086   typedef typename FixedImageType::ConstPointer     FixedImageConstPointer;
00087   typedef typename MovingImageType::ConstPointer    MovingImageConstPointer;
00088   typedef typename VirtualImageType::ConstPointer   VirtualImageConstPointer;
00089 
00090   /* Image dimension accessors */
00091   itkStaticConstMacro(FixedImageDimension, SizeValueType,
00092       ::itk::GetImageDimension<FixedImageType>::ImageDimension);
00093   itkStaticConstMacro(MovingImageDimension, SizeValueType,
00094       ::itk::GetImageDimension<MovingImageType>::ImageDimension);
00095   itkStaticConstMacro(VirtualImageDimension, SizeValueType,
00096       ::itk::GetImageDimension<VirtualImageType>::ImageDimension);
00097 
00098   typedef typename VirtualImageType::RegionType     VirtualRegionType;
00099   typedef typename VirtualImageType::SizeType       VirtualSizeType;
00100   typedef typename VirtualImageType::PointType      VirtualPointType;
00101   typedef typename VirtualImageType::IndexType      VirtualIndexType;
00102 
00103   typedef typename FixedImageType::PointType        FixedPointType;
00104   typedef typename FixedImageType::IndexType        FixedIndexType;
00105   typedef typename FixedImageType::PointValueType   FixedPointValueType;
00106   typedef typename itk::ContinuousIndex< FixedPointValueType,
00107           FixedImageType::ImageDimension >          FixedContinuousIndexType;
00108 
00109   typedef typename MovingImageType::PointType       MovingPointType;
00110   typedef typename MovingImageType::IndexType       MovingIndexType;
00111   typedef typename MovingImageType::PointValueType  MovingPointValueType;
00112   typedef typename itk::ContinuousIndex< MovingPointValueType,
00113           MovingImageType::ImageDimension >         MovingContinuousIndexType;
00114 
00116   typedef enum { FullDomainSampling, CornerSampling, RandomSampling,
00117                  CentralRegionSampling }
00118           SamplingStrategyType;
00119 
00120   typedef std::vector<VirtualPointType>             ImageSampleContainerType;
00121 
00123   typedef typename TMetric::JacobianType            JacobianType;
00124 
00128   itkSetObjectMacro(Metric, MetricType);
00129 
00134   itkSetMacro(TransformForward, bool);
00135   itkGetConstMacro(TransformForward, bool);
00137 
00139   itkSetMacro(CentralRegionRadius, IndexValueType);
00140 
00142   virtual void EstimateScales(ScalesType &scales) = 0;
00143 
00145   virtual FloatType EstimateStepScale(const ParametersType &step) = 0;
00146 
00148   virtual void EstimateLocalStepScales(const ParametersType &step,
00149     ScalesType &localStepScales) = 0;
00150 
00152   virtual FloatType EstimateMaximumStepSize();
00153 
00155   virtual void SetScalesSamplingStrategy();
00156 
00158   virtual void SetStepScaleSamplingStrategy();
00159 
00160 protected:
00161   RegistrationParameterScalesEstimator();
00162   ~RegistrationParameterScalesEstimator(){};
00163 
00164   virtual void PrintSelf(std::ostream &os, Indent indent) const;
00165 
00167   bool CheckAndSetInputs();
00168 
00170   itkSetMacro(NumberOfRandomSamples, SizeValueType);
00171 
00173   itkSetMacro(SamplingStrategy, SamplingStrategyType);
00174 
00179   bool CheckGeneralAffineTransform();
00180 
00186   template< class TTransform > bool CheckGeneralAffineTransformTemplated();
00187 
00189   template< class TTargetPointType > void TransformPoint(
00190                               const VirtualPointType &point,
00191                               TTargetPointType &mappedPoint);
00192 
00194   template< class TContinuousIndexType > void TransformPointToContinuousIndex(
00195                               const VirtualPointType &point,
00196                               TContinuousIndexType &mappedIndex);
00197 
00199   void ComputeSquaredJacobianNorms(
00200                               const VirtualPointType  & p,
00201                               ParametersType & squareNorms);
00202 
00204   bool HasLocalSupport();
00205 
00207   SizeValueType GetNumberOfLocalParameters();
00208 
00210   void UpdateTransformParameters(const ParametersType &deltaParameters);
00211 
00213   virtual void SampleImageDomain();
00214 
00216   void SampleImageDomainFully();
00217 
00219   void SampleImageDomainWithCorners();
00220 
00222   void SampleImageDomainRandomly();
00223 
00225   void SampleImageDomainWithCentralRegion();
00226 
00228   void SampleImageDomainWithRegion(VirtualRegionType region);
00229 
00231   VirtualIndexType GetVirtualImageCentralIndex();
00232 
00234   VirtualRegionType GetVirtualImageCentralRegion();
00235 
00237   const TransformBase *GetTransform();
00238 
00240   SizeValueType GetImageDimension();
00241 
00243   itkGetConstObjectMacro(FixedImage,  FixedImageType);
00244 
00246   itkGetConstObjectMacro(MovingImage, MovingImageType);
00247 
00249   itkGetConstObjectMacro(VirtualImage, VirtualImageType);
00250 
00252   itkGetConstObjectMacro(FixedTransform,  FixedTransformType);
00253 
00255   itkGetConstObjectMacro(MovingTransform, MovingTransformType);
00256 
00257   // the metric object
00258   MetricConstPointer            m_Metric;
00259 
00260   // the image samples in the virtual image domain
00261   ImageSampleContainerType      m_ImageSamples;
00262 
00264   mutable TimeStamp             m_SamplingTime;
00265 
00266   // the number of image samples in the virtual image domain
00267   SizeValueType                 m_NumberOfRandomSamples;
00268 
00269   // the radius of the central region for sampling
00270   IndexValueType                m_CentralRegionRadius;
00271 
00272   // the threadhold to decide if the number of random samples uses logarithm
00273   static const SizeValueType    SizeOfSmallDomain = 1000;
00274 
00275 private:
00276   RegistrationParameterScalesEstimator(const Self&); //purposely not implemented
00277   void operator=(const Self&); //purposely not implemented
00278 
00279   // the transform objects
00280   FixedTransformConstPointer         m_FixedTransform;
00281   MovingTransformConstPointer        m_MovingTransform;
00282 
00283   // the fixed images
00284   FixedImageConstPointer             m_FixedImage;
00285   // the moving images
00286   MovingImageConstPointer            m_MovingImage;
00287   // the virtual image for symmetric registration
00288   VirtualImageConstPointer           m_VirtualImage;
00289 
00294   bool m_TransformForward;
00295 
00296   // sampling stategy
00297   SamplingStrategyType          m_SamplingStrategy;
00298 
00299 }; //class RegistrationParameterScalesEstimator
00300 
00301 
00302 }  // namespace itk
00303 
00304 
00305 #ifndef ITK_MANUAL_INSTANTIATION
00306 #include "itkRegistrationParameterScalesEstimator.hxx"
00307 #endif
00308 
00309 #endif /* __itkRegistrationParameterScalesEstimator_h */
00310