freRegionImageMediaController.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freRegionImageMediaController.h,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef __freRegionImageMediaController_h
00023 #define __freRegionImageMediaController_h
00024 
00025 #include "freIntensityImageMediaController.h"
00026 #include "freImageIO.h"
00027 #include "freImageTypes.h"
00028 
00029 #include "itkNearestNeighborInterpolateImageFunction.h"
00030 
00031 namespace FREE
00032 {
00033 
00041         freControllerIDMacro(RegionImageMediaControllerBase, "RegionImageMediaControllerBase");
00042 template <class TInternalPixel, class TExternalPixel, unsigned int VDimension>
00043 class RegionImageMediaControllerBase : public IntensityImageMediaControllerBase< TInternalPixel, TExternalPixel, VDimension >
00044 {
00045 public:  
00046   typedef IntensityImageMediaControllerBase<TInternalPixel, TExternalPixel, VDimension> Superclass;
00047   typedef typename Superclass::ComponentType ComponentType;
00048   typedef typename Superclass::GenericComponentType GenericComponentType;
00049   typedef typename Superclass::GenericComponentPointer GenericComponentPointer;
00050   typedef typename Superclass::GenericMediaPointer GenericMediaPointer;
00051   typedef ComponentType ImageType;
00052 
00053         itkTypeMacro(RegionImageMediaControllerBase, IntensityImageMediaControllerBase);
00054 
00055   RegionImageMediaControllerBase()
00056   {
00057     //Profile settings
00058     this->UpdateControllerID(ControllerID::RegionImageMediaControllerBase);
00059     this->m_Description = "Base class for medias containing region/mask images.";
00060         };
00061 
00062 
00063   virtual ~RegionImageMediaControllerBase() {};
00064 
00065   virtual GenericMediaPointer ComputeActualizedMedia(GenericMediaType* pGenericMedia,
00066                                                      GenericMediaType* pGenericTransformationField) const
00067   {
00068     if (!pGenericMedia) throwCtrlExceptionMacro("","Passed media is NULL.");
00069     if (!pGenericTransformationField) throwCtrlExceptionMacro("","Passed transform field is NULL.");
00070 
00071     typename ImageType::Pointer smpCurrentImage;
00072     try
00073     {
00074       smpCurrentImage = dynamic_cast<ImageType*>(pGenericMedia);
00075     }
00076     catchAllNPassMacro("Error. Media that should be actualized seems not to be of correct type.");
00077     if (smpCurrentImage.IsNull()) throwCtrlExceptionMacro("","Media has wrong type. Cannot be casted.");
00078 
00079     typedef typename ImageTypes<VDimension>::TransformationFieldType TransformationFieldType;
00080     typename TransformationFieldType::Pointer smpTransfromField = static_cast< TransformationFieldType*>(pGenericTransformationField);
00081 
00082     typedef itk::WarpImageFilter< ImageType, ImageType, TransformationFieldType > WarpFilterType;
00083 
00084     typename WarpFilterType::Pointer smpWarpFilter = WarpFilterType::New();
00085 
00086     typedef itk::NearestNeighborInterpolateImageFunction<ImageType, ScalarType> InterpolatorType;
00087 
00088     typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
00089 
00090     smpWarpFilter->SetInput(smpCurrentImage);
00091     smpWarpFilter->SetOutputSpacing(smpCurrentImage->GetSpacing());
00092     smpWarpFilter->SetOutputOrigin(smpCurrentImage->GetOrigin());
00093     smpWarpFilter->SetDeformationField(smpTransfromField);
00094     smpWarpFilter->SetInterpolator(interpolator);
00095     smpCurrentImage = smpWarpFilter->GetOutput();
00096     smpWarpFilter->Update();
00097 
00098     GenericMediaPointer smpResult = smpCurrentImage.GetPointer();
00099 
00100         return smpResult;
00101   };
00102 
00103   virtual GenericMediaPointer ComputeActualizedMediaByFunction(GenericMediaType* pGenericMedia,
00104                                                                GenericMediaType* pGenericTransformationFunction) const
00105   {
00106     if (!pGenericMedia) throwCtrlExceptionMacro("","Passed media is NULL.");
00107     if (!pGenericTransformationFunction) throwCtrlExceptionMacro("","Passed transform function is NULL.");
00108 
00109     typename ImageType::Pointer smpCurrentImage;
00110     try
00111     {
00112       smpCurrentImage = dynamic_cast<ImageType*>(pGenericMedia);
00113     }
00114     catchAllNPassMacro("Error. Media that should be actualized seems not to be of correct type.");
00115     if (smpCurrentImage.IsNull()) throwCtrlExceptionMacro("","Media has wrong type. Cannot be casted.");
00116 
00117     typedef TransformFunctionMedia<ScalarType, VDimension, VDimension> TransformationFunctionType;
00118     typename TransformationFunctionType::Pointer smpTransfromFunction = static_cast< TransformationFunctionType*>(pGenericTransformationFunction);
00119 
00120     typedef itk::ResampleImageFilter< ImageType, ImageType, ScalarType > ResampleFilterType;
00121 
00122     typename ResampleFilterType::Pointer smpResampleFilter = ResampleFilterType::New();
00123 
00124     typedef itk::NearestNeighborInterpolateImageFunction<ImageType, ScalarType> InterpolatorType;
00125 
00126     typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
00127 
00128     smpResampleFilter->SetInput(smpCurrentImage);
00129     smpResampleFilter->SetOutputParametersFromImage(smpCurrentImage);
00130     smpResampleFilter->SetOutputStartIndex(smpCurrentImage->GetLargestPossibleRegion().GetIndex());
00131     smpResampleFilter->SetTransform(smpTransfromFunction->GetTransform());
00132     smpResampleFilter->SetInterpolator(interpolator);
00133     smpCurrentImage = smpResampleFilter->GetOutput();
00134     smpResampleFilter->Update();
00135 
00136     GenericMediaPointer smpResult = smpCurrentImage.GetPointer();
00137 
00138         return smpResult;
00139   };
00140 };
00141 
00147 freControllerIDMacro(RegionImage2DMediaController, "Region Image 2D Media");
00148 class RegionImage2DMediaController : public RegionImageMediaControllerBase< InternalImagePixelType, LoadingPixelType, 2>
00149 {
00150 public:  
00151   typedef RegionImageMediaControllerBase<InternalImagePixelType, LoadingPixelType, 2> Superclass;
00152         typedef Superclass::ComponentType ComponentType;
00153 
00154         itkTypeMacro(RegionImage2DMediaController, RegionImageMediaControllerBase);
00155 
00156   RegionImage2DMediaController();
00157 
00158   virtual ~RegionImage2DMediaController();
00159 };
00160 
00166 freControllerIDMacro(RegionImage3DMediaController, "Region Image 3D Media");
00167 class RegionImage3DMediaController : public RegionImageMediaControllerBase< InternalImagePixelType, LoadingPixelType, 3>
00168 {
00169 public:  
00170   typedef RegionImageMediaControllerBase<InternalImagePixelType, LoadingPixelType, 3> Superclass;
00171         typedef Superclass::ComponentType ComponentType;
00172 
00173         itkTypeMacro(RegionImage3DMediaController, RegionImageMediaControllerBase);
00174 
00175   RegionImage3DMediaController();
00176 
00177   virtual ~RegionImage3DMediaController();
00178 };
00179 
00180 } //end of namespace free
00181 
00182 #endif

Generated at Sat Oct 13 17:12:15 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000