cmtkVoxelRegistration.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2011 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: 2752 $
00026 //
00027 //  $LastChangedDate: 2011-01-17 11:33:31 -0800 (Mon, 17 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkVoxelRegistration_h_included_
00034 #define __cmtkVoxelRegistration_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkMacros.h>
00039 #include <Base/cmtkTypes.h>
00040 
00041 #include <Base/cmtkXform.h>
00042 #include <Base/cmtkAffineXform.h>
00043 #include <Base/cmtkFunctional.h>
00044 #include <Base/cmtkUniformVolume.h>
00045 #include <Base/cmtkVector.h>
00046 
00047 #include <Registration/cmtkRegistrationCallback.h>
00048 #include <Registration/cmtkOptimizer.h>
00049 #include <Base/cmtkInterpolator.h>
00050 
00051 #include <System/cmtkTimers.h>
00052 #include <System/cmtkCommandLine.h>
00053 #include <IO/cmtkClassStream.h>
00054 
00055 #include <stack>
00056 #include <string.h>
00057 
00058 namespace
00059 cmtk
00060 {
00061 
00064 
00070 class VoxelRegistration 
00071 {
00072 protected:
00074   cmtkGetSetMacro(int,Metric);
00075 
00077   cmtkGetSetMacro(int,Algorithm);
00078 
00080   cmtkGetSetMacro(double,Exploration);
00081 
00083   cmtkGetSetMacro(double,Accuracy);
00084 
00090   double CoarsestResolution;
00091 
00093   cmtkGetSetMacro(bool,UseOriginalData);
00094  
00096   double OptimizerStepFactor;
00097 
00099   bool UseMaxNorm;
00100 
00102   Optimizer::ReturnType m_DeltaFThreshold;
00103 
00105   cmtkGetSetMacro(Types::Coordinate,Sampling);
00106 
00108   cmtkGetSetMacroString(Protocol);
00109 
00111   cmtkGetSetMacro(UniformVolume::SmartPtr,Volume_1);
00112 
00114   cmtkGetSetMacro(UniformVolume::SmartPtr,Volume_2);
00115 
00120   cmtkGetSetMacro(UniformVolume::SmartPtr,ReferenceVolume);
00121 
00126   cmtkGetSetMacro(UniformVolume::SmartPtr,FloatingVolume);
00127 
00129   class ImagePreprocessor
00130   {
00131   public:
00133     const char* m_DataClassString;
00134 
00136     DataClass m_DataClass;
00137     
00139     bool m_PaddingFlag;
00140     
00142     Types::DataItem m_PaddingValue;
00143 
00145     bool m_LowerThresholdActive;
00146 
00148     Types::DataItem m_LowerThresholdValue;
00149   
00151     bool m_UpperThresholdActive;
00152 
00154     Types::DataItem m_UpperThresholdValue;
00155 
00157     bool m_UsePruneHistogramBins;
00158 
00160     unsigned int m_PruneHistogramBins;
00161 
00163     bool m_HistogramEqualization;
00164 
00166     bool m_SobelFilter;
00167 
00169     const char* m_CropIndex;
00170 
00172     const char* m_CropWorld;
00173 
00175     bool m_AutoCropFlag;
00176 
00178     Types::DataItem m_AutoCropLevel;
00179     
00181     ImagePreprocessor( const char* name,  
00182                        const char* key 
00183       );
00184     
00186     void AttachToCommandLine( CommandLine& cl 
00187       ); 
00188     
00190     UniformVolume::SmartPtr GetProcessedImage( const UniformVolume* original );
00191     
00193     void WriteSettings( ClassStream& stream ) const;
00194 
00195   private:
00197     const char* m_Name;
00198 
00200     const char* m_Key;
00201   };
00202 
00204   ImagePreprocessor m_PreprocessorRef;
00205 
00207   ImagePreprocessor m_PreprocessorFlt;
00208   
00210   bool SwitchVolumes;
00211 
00213   cmtkGetSetMacro(RegistrationCallback::SmartPtr,Callback);
00214 
00216   cmtkGetSetMacro(AffineXform::SmartPtr,InitialTransformation);
00217 
00219   cmtkGetSetMacro(bool,InitialXformIsInverse);
00220 
00222   Xform::SmartPtr m_Xform;
00223 
00225   std::stack<Functional::SmartPtr> FunctionalStack;
00226 
00228   Optimizer::SmartPtr m_Optimizer;
00229 
00239   virtual CallbackResult InitRegistration ();
00240 
00247   virtual void OutputResult ( const CoordinateVector* v ) { UNUSED(v); }
00248   
00254   virtual void DoneRegistration ( const CoordinateVector* v = NULL);
00255 
00265   virtual void EnterResolution( CoordinateVector::SmartPtr& v, Functional::SmartPtr& f, const int idx, const int total );
00266 
00276   virtual int DoneResolution( CoordinateVector::SmartPtr&, Functional::SmartPtr&, const int, const int ) { return 1; }
00278 
00279 public:
00281   class ConstructorFailed {};
00282 
00285   VoxelRegistration ();
00286 
00289   virtual ~VoxelRegistration ();
00290 
00297   virtual CallbackResult Register ();
00298 
00301   double GetTotalElapsedTime() const 
00302   {
00303     return cmtk::Timers::GetTimeProcess() - TimeStartRegistration;
00304   }
00305   
00308   double GetLevelElapsedTime() const 
00309   {
00310     return cmtk::Timers::GetTimeProcess() - TimeStartLevel;
00311   }
00312   
00315   double GetTotalElapsedWalltime() const 
00316   {
00317     return cmtk::Timers::GetWalltime() - WalltimeStartRegistration;
00318   }
00319   
00322   double GetLevelElapsedWalltime() const 
00323   {
00324     return cmtk::Timers::GetWalltime() - WalltimeStartLevel;
00325   }
00326   
00329   double GetThreadTotalElapsedTime() const 
00330   {
00331     return cmtk::Timers::GetTimeThread() - ThreadTimeStartRegistration;
00332   }
00333   
00336   double GetThreadLevelElapsedTime() const 
00337   {
00338     return cmtk::Timers::GetTimeThread() - ThreadTimeStartLevel;
00339   }
00340 
00341 private:
00345   double TimeStartRegistration;
00346 
00350   double TimeStartLevel;
00351 
00355   double WalltimeStartRegistration;
00356 
00360   double WalltimeStartLevel;
00361 
00365   double ThreadTimeStartRegistration;
00366 
00370   double ThreadTimeStartLevel;
00371 };
00372 
00374 
00375 } // namespace cmtk
00376 
00377 #endif // #ifndef __cmtkVoxelRegistration_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines