cmtkGroupwiseRegistrationFunctionalXformTemplate_SplineWarp.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 1768 $
00026 //
00027 //  $LastChangedDate: 2010-05-27 15:16:01 -0700 (Thu, 27 May 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkGroupwiseRegistrationFunctionalXformTemplate_SplineWarp_h_included_
00034 #define __cmtkGroupwiseRegistrationFunctionalXformTemplate_SplineWarp_h_included_
00035 
00036 #include <Base/cmtkSplineWarpXform.h>
00037 
00038 namespace
00039 cmtk
00040 {
00041 
00049 template<>
00050 class GroupwiseRegistrationFunctionalXformTemplate<SplineWarpXform> : 
00052   public GroupwiseRegistrationFunctionalXformTemplateBase<SplineWarpXform>
00053 {
00054 public:
00056   typedef GroupwiseRegistrationFunctionalXformTemplateBase<SplineWarpXform> Superclass;
00057   
00059   typedef GroupwiseRegistrationFunctionalXformTemplate<SplineWarpXform> Self;
00060 
00062   typedef SmartPointer<Self> SmartPtr;
00063 
00065   GroupwiseRegistrationFunctionalXformTemplate();
00066 
00068   virtual ~GroupwiseRegistrationFunctionalXformTemplate() {};
00069 
00071   virtual void InitializeXformsFromAffine( const Types::Coordinate gridSpacing, 
00072                                            std::vector<AffineXform::SmartPtr> initialAffineXformsVector, 
00073                                            const bool exactSpacing = true 
00074     );
00075   
00078   virtual void InitializeXforms( const Types::Coordinate gridSpacing, 
00079                                  const bool exactSpacing = true  
00080     )
00081   {
00082     this->InitializeXformsFromAffine( gridSpacing, this->m_InitialAffineXformsVector, exactSpacing );
00083   }
00084   
00086   virtual void RefineTransformationGrids();
00087 
00089   void SetForceZeroSumNoAffine( const bool noaffine = true )
00090   {
00091     this->m_ForceZeroSumNoAffine = noaffine;
00092   }
00093 
00095   void SetPartialGradientMode( const bool partialGradientMode = false, const float partialGradientThreshold = 0.0 )
00096   {
00097     this->m_PartialGradientMode = partialGradientMode;
00098     this->m_PartialGradientThreshold = partialGradientThreshold;
00099   }
00100 
00102   void SetDeactivateUninformativeMode( const bool dum = true )
00103   {
00104     this->m_DeactivateUninformativeMode = dum;
00105   }
00106 
00110   virtual void SetActiveXformsFromTo( const size_t from, const size_t to )
00111   {
00112     this->Superclass::SetActiveXformsFromTo( from, to );
00113     this->UpdateParamStepArray();
00114   }
00115 
00117   virtual void SetTemplateGrid( UniformVolume::SmartPtr& templateGrid, const int downsample = 1, const bool useTemplateData = false );
00118     
00119 protected:
00121   size_t m_MaximumNumberOfPixelsVOI;
00122   
00124   size_t m_MaximumNumberOfPixelsPerLineVOI;
00125 
00127   virtual void UpdateVolumesOfInfluence();
00128 
00130   virtual void UpdateActiveControlPoints() = 0;
00131   
00142   virtual void InterpolateImage( const size_t idx, byte* const destination );
00143 
00151   virtual void ForceZeroSumGradient( CoordinateVector& g ) const;
00152 
00158   bool Wiggle();
00159 
00160 protected:
00162   bool m_ForceZeroSumNoAffine;
00163 
00165   bool m_WarpFastMode;
00166 
00168   float m_JacobianConstraintWeight;
00169 
00171   float m_BendingEnergyWeight;
00172 
00177   bool m_PartialGradientMode;
00178 
00180   std::vector<AffineXform::SmartPtr> m_InitialAffineXformsVector;
00181 
00183   std::vector<AffineXform::SmartPtr> m_InitialRotationsVector;
00184 
00186   std::vector<Types::Coordinate> m_ParamStepArray;
00187 
00189   virtual bool UpdateParamStepArray();
00190 
00192   std::vector<DataGrid::RegionType> m_VolumeOfInfluenceArray;
00193 
00195   Types::Coordinate m_PartialGradientThreshold;
00196 
00198   bool m_DeactivateUninformativeMode;
00199 
00201   std::vector<bool> m_ActiveControlPointFlags;
00202 
00204   size_t m_NumberOfActiveControlPoints;
00205 
00206 private:
00208   class InterpolateImageThreadParameters : 
00210     public ThreadParameters<Self>
00211   {
00212   public:
00214     size_t m_Idx;
00215 
00217     byte* m_Destination;
00218   };
00219 
00221   static void InterpolateImageThread( void* args, const size_t taskIdx, const size_t taskCnt, const size_t, const size_t );
00222 
00223   friend ClassStream& operator<<( ClassStream& stream, const GroupwiseRegistrationFunctionalXformTemplate<SplineWarpXform>& func );
00224   friend ClassStream& operator>>( ClassStream& stream, GroupwiseRegistrationFunctionalXformTemplate<SplineWarpXform>& func );
00225 };
00226 
00227 ClassStream& operator<<( ClassStream& stream, const GroupwiseRegistrationFunctionalXformTemplate<SplineWarpXform>& func );
00228 ClassStream& operator>>( ClassStream& stream, GroupwiseRegistrationFunctionalXformTemplate<SplineWarpXform>& func );
00229 
00230 } // namespace cmtk
00231 
00232 #endif // #ifndef __cmtkGroupwiseRegistrationFunctionalXformTemplate_SplineWarp_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines