Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkFEMImageMetricLoad.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit (ITK) 00004 Module: $RCSfile: itkFEMImageMetricLoad.h,v $ Language: C++ 00005 Date: $Date: 2003/08/07 18:56:56 $ 00006 Version: $Revision: 1.23 $ 00007 00008 Copyright (c) 2001 Insight Consortium 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 00017 * Redistributions in binary form must reproduce the above copyright notice, 00018 this list of conditions and the following disclaimer in the documentation 00019 and/or other materials provided with the distribution. 00020 00021 * The name of the Insight Consortium, nor the names of any consortium members, 00022 nor of any contributors, may be used to endorse or promote products derived 00023 from this software without specific prior written permission. 00024 00025 * Modified source versions must be plainly marked as such, and must not be 00026 misrepresented as being the original software. 00027 00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' 00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 00039 =========================================================================*/ 00040 #ifndef _itkFEMImageMetricLoad_h_ 00041 #define _itkFEMImageMetricLoad_h_ 00042 00043 #include "itkFEMLoadElementBase.h" 00044 00045 #include "itkImage.h" 00046 #include "itkTranslationTransform.h" 00047 00048 #include "itkImageRegionIteratorWithIndex.h" 00049 #include "itkNeighborhoodIterator.h" 00050 #include "itkNeighborhoodIterator.h" 00051 #include "itkNeighborhoodInnerProduct.h" 00052 #include "itkDerivativeOperator.h" 00053 #include "itkForwardDifferenceOperator.h" 00054 #include "itkLinearInterpolateImageFunction.h" 00055 #include "vnl/vnl_math.h" 00056 00057 #include <itkMutualInformationImageToImageMetric.h> 00058 #include <itkMattesMutualInformationImageToImageMetric.h> 00059 #include <itkMeanSquaresImageToImageMetric.h> 00060 #include <itkNormalizedCorrelationImageToImageMetric.h> 00061 //#include <itkMeanReciprocalSquareDifferenceImageToImageMetric.h> 00062 00063 00064 namespace itk 00065 { 00066 namespace fem 00067 { 00068 00092 template<class TMoving,class TFixed> 00093 class ImageMetricLoad : public LoadElement 00094 { 00095 FEM_CLASS(ImageMetricLoad,LoadElement) 00096 public: 00097 00098 // Necessary typedefs for dealing with images BEGIN 00099 typedef typename LoadElement::Float Float; 00100 00101 typedef TMoving MovingType; 00102 typedef typename MovingType::ConstPointer MovingConstPointer; 00103 typedef MovingType* MovingPointer; 00104 typedef TFixed FixedType; 00105 typedef FixedType* FixedPointer; 00106 typedef typename FixedType::ConstPointer FixedConstPointer; 00107 00109 itkStaticConstMacro(ImageDimension, unsigned int, 00110 MovingType::ImageDimension); 00111 00112 typedef ImageRegionIteratorWithIndex<MovingType> RefRegionIteratorType; 00113 typedef ImageRegionIteratorWithIndex<FixedType> TarRegionIteratorType; 00114 00115 00116 typedef NeighborhoodIterator<MovingType> 00117 MovingNeighborhoodIteratorType; 00118 typedef typename MovingNeighborhoodIteratorType::IndexType 00119 MovingNeighborhoodIndexType; 00120 typedef typename MovingNeighborhoodIteratorType::RadiusType 00121 MovingRadiusType; 00122 typedef NeighborhoodIterator<FixedType> 00123 FixedNeighborhoodIteratorType; 00124 typedef typename FixedNeighborhoodIteratorType::IndexType 00125 FixedNeighborhoodIndexType; 00126 typedef typename FixedNeighborhoodIteratorType::RadiusType 00127 FixedRadiusType; 00128 00129 00130 // IMAGE DATA 00131 typedef typename MovingType::PixelType RefPixelType; 00132 typedef typename FixedType::PixelType TarPixelType; 00133 typedef Float PixelType; 00134 typedef Float ComputationType; 00135 typedef Image< RefPixelType, itkGetStaticConstMacro(ImageDimension) > RefImageType; 00136 typedef Image< TarPixelType, itkGetStaticConstMacro(ImageDimension) > TarImageType; 00137 typedef Image< PixelType, itkGetStaticConstMacro(ImageDimension) > ImageType; 00138 typedef vnl_vector<Float> VectorType; 00139 00140 // Necessary typedefs for dealing with images END 00141 00142 //------------------------------------------------------------ 00143 // Set up the metrics 00144 //------------------------------------------------------------ 00145 typedef double CoordinateRepresentationType; 00146 typedef Transform< CoordinateRepresentationType,itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > TransformBaseType; 00147 typedef TranslationTransform<CoordinateRepresentationType, itkGetStaticConstMacro(ImageDimension) > DefaultTransformType; 00148 00150 typedef ImageToImageMetric<FixedType,MovingType > MetricBaseType; 00151 typedef typename MetricBaseType::Pointer MetricBaseTypePointer; 00152 00153 typedef MutualInformationImageToImageMetric< MovingType, FixedType > MutualInformationMetricType; 00154 00155 typedef MeanSquaresImageToImageMetric< MovingType, FixedType > MeanSquaresMetricType; 00156 00157 typedef NormalizedCorrelationImageToImageMetric< MovingType, FixedType > NormalizedCorrelationMetricType; 00158 00159 // typedef MeanReciprocalSquareDifferenceImageToImageMetric< ReferenceType, TargetType > MeanReciprocalSquaresMetricType; 00160 00161 // typedef MutualInformationMetricType DefaultMetricType; 00162 // typedef NormalizedCorrelationMetricType DefaultMetricType; 00163 // typedef MeanReciprocalSquaresMetricType DefaultMetricType; 00164 typedef MeanSquaresMetricType DefaultMetricType; 00165 typedef typename DefaultTransformType::ParametersType ParametersType; 00166 typedef typename DefaultTransformType::JacobianType JacobianType; 00167 00168 00169 //------------------------------------------------------------ 00170 // Set up an Interpolator 00171 //------------------------------------------------------------ 00172 typedef LinearInterpolateImageFunction< MovingType, double > InterpolatorType; 00173 00175 typedef float RealType; 00176 typedef CovariantVector<RealType, 00177 itkGetStaticConstMacro(ImageDimension)> GradientPixelType; 00178 typedef Image<GradientPixelType, 00179 itkGetStaticConstMacro(ImageDimension)> GradientImageType; 00180 typedef SmartPointer<GradientImageType> GradientImagePointer; 00181 typedef GradientRecursiveGaussianImageFilter< ImageType, 00182 GradientImageType > 00183 GradientImageFilterType; 00184 // typedef typename GradientImageFilterType::Pointer GradientImageFilterPointer; 00185 00186 00187 // FUNCTIONS 00188 00190 void SetMetric(MetricBaseTypePointer MP) { m_Metric=MP; }; 00191 00193 void SetMovingImage(MovingType* R) 00194 { 00195 m_RefImage = R; 00196 m_RefSize=m_RefImage->GetLargestPossibleRegion().GetSize(); 00197 }; 00198 00199 void SetMetricMovingImage(MovingType* R) 00200 { 00201 m_Metric->SetMovingImage( R ); 00202 m_RefSize=R->GetLargestPossibleRegion().GetSize(); 00203 }; 00204 00206 void SetFixedImage(FixedType* T) 00207 { 00208 m_TarImage=T; 00209 m_TarSize=T->GetLargestPossibleRegion().GetSize(); 00210 }; 00211 void SetMetricFixedImage(FixedType* T) 00212 { 00213 m_Metric->SetFixedImage( T ) ; 00214 m_TarSize=T->GetLargestPossibleRegion().GetSize(); 00215 }; 00216 00217 00218 MovingPointer GetMovingImage() { return m_RefImage; }; 00219 FixedPointer GetFixedImage() { return m_TarImage; }; 00220 00222 void SetMetricRadius(MovingRadiusType T) {m_MetricRadius = T; }; 00224 MovingRadiusType GetMetricRadius() { return m_MetricRadius; }; 00225 00230 void SetNumberOfIntegrationPoints(unsigned int i){ m_NumberOfIntegrationPoints=i;} 00231 unsigned int GetNumberOfIntegrationPoints(){ return m_NumberOfIntegrationPoints;} 00232 00236 void SetSign(Float s) {m_Sign=s;} 00237 00239 void SetTemp(Float s) {m_Temp=s;} 00240 00241 00243 void SetGamma(Float s) {m_Gamma=s;} 00244 00245 void SetSolution(Solution::ConstPointer ptr) { m_Solution=ptr; } 00246 Solution::ConstPointer GetSolution() { return m_Solution; } 00247 00251 Float GetMetric (VectorType InVec); 00252 VectorType GetPolynomialFitToMetric(VectorType PositionInElement, VectorType SolutionAtPosition); 00253 00254 VectorType MetricFiniteDiff(VectorType PositionInElement, VectorType SolutionAtPosition); 00255 00256 // FIXME - WE ASSUME THE 2ND VECTOR (INDEX 1) HAS THE INFORMATION WE WANT 00257 Float GetSolution(unsigned int i,unsigned int which=0) 00258 { 00259 return m_Solution->GetSolutionValue(i,which); 00260 } 00261 00262 // define the copy constructor 00263 // ImageMetricLoad(const ImageMetricLoad& LMS); 00264 00265 void InitializeMetric(void); 00266 ImageMetricLoad(); // cannot be private until we always use smart pointers 00267 Float EvaluateMetricGivenSolution ( Element::ArrayType* el, Float step=1.0); 00268 00272 VectorType Fe1(VectorType); 00273 VectorType Fe(VectorType,VectorType); 00274 00275 static Baseclass* NewImageMetricLoad(void) 00276 { return new ImageMetricLoad; } 00277 00278 00280 //void InitializeGradientImage(); 00281 void SetMetricGradientImage(GradientImageType* g) { m_MetricGradientImage=g;} 00282 GradientImageType* GetMetricGradientImage() { return m_MetricGradientImage;} 00283 00284 00285 void PrintCurrentEnergy(){ std:: cout << " energy " << m_Energy << std::endl;} 00286 double GetCurrentEnergy() { return m_Energy; } 00287 void SetCurrentEnergy( double e ) { m_Energy=e; } 00288 00289 protected: 00290 00291 00292 private: 00293 GradientImageType* m_MetricGradientImage; 00294 MovingPointer m_RefImage; 00295 FixedPointer m_TarImage; 00296 MovingRadiusType m_MetricRadius; 00297 typename MovingType::SizeType m_RefSize; 00298 typename FixedType::SizeType m_TarSize; 00299 unsigned int m_NumberOfIntegrationPoints; 00300 unsigned int m_SolutionIndex; 00301 unsigned int m_SolutionIndex2; 00302 Float m_Sign; 00303 Float m_Temp; 00304 Float m_Gamma; 00305 00306 typename Solution::ConstPointer m_Solution; 00307 MetricBaseTypePointer m_Metric; 00308 typename TransformBaseType::Pointer m_Transform; 00309 typename InterpolatorType::Pointer m_Interpolator; 00310 00311 mutable double m_Energy; 00312 private: 00315 static const int DummyCLID; 00316 00317 }; 00318 00319 00320 00321 00322 }} // end namespace fem/itk 00323 00324 #ifndef ITK_MANUAL_INSTANTIATION 00325 #include "itkFEMImageMetricLoad.txx" 00326 #endif 00327 00328 #endif

Generated at Sat Mar 31 02:18:28 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000