EMLocalShapeCostFunction.h

Go to the documentation of this file.
00001 /*=auto=========================================================================
00002 
00003 (c) Copyright 2001 Massachusetts Institute of Technology 
00004 
00005 Permission is hereby granted, without payment, to copy, modify, display 
00006 and distribute this software and its documentation, if any, for any purpose, 
00007 provided that the above copyright notice and the following three paragraphs 
00008 appear on all copies of this software.  Use of this software constitutes 
00009 acceptance of these terms and conditions.
00010 
00011 IN NO EVENT SHALL MIT BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, 
00012 INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE 
00013 AND ITS DOCUMENTATION, EVEN IF MIT HAS BEEN ADVISED OF THE POSSIBILITY OF 
00014 SUCH DAMAGE.
00015 
00016 MIT SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, 
00017 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR 
00018 A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00019 
00020 THE SOFTWARE IS PROVIDED "AS IS."  MIT HAS NO OBLIGATION TO PROVIDE 
00021 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
00022 
00023 =========================================================================auto=*/
00024 
00025 #ifndef _EMLOCALSHAPECOSTFUNCTION_H_INCLUDED
00026 #define _EMLOCALSHAPECOSTFUNCTION_H_INCLUDED 1
00027 
00028 #include "vtkEMSegment.h"
00029 #include "EMLocalInterface.h" 
00030 #include "vtkMultiThreader.h"
00031 
00032 typedef struct {
00033   float Result;
00034   int VoxelStart[3];
00035   int DataJump;
00036   int *PCAMeanShapeJump;
00037   int **PCAEigenVectorsJump;
00038   int *ProbDataJump;
00039   // Job specifc number of Voxels in Image Space (not considering boundaries); 
00040   int NumberOfVoxels;
00041 } EMLocalShapeCostFunction_MultiThreadedParameters;
00042 
00043 typedef struct {
00044   const double *PCAPara;
00045   float *SpatialCostFunction;
00046 
00047   float GaussianPenalty;
00048   float ImagePenalty;
00049 
00050 } EMLocalShapeCostFunction_IterationSpecificVariables;
00051 
00052 class VTK_EMSEGMENT_EXPORT EMLocalShapeCostFunction { 
00053 public:
00054   // ------------------------
00055   // Core Functions
00056   // ------------------------
00057 
00058   // Call this function before starting optimization 
00059   void InitializeCostFunction(int PCAMaxX, int PCAMinX, int PCAMaxY, int PCAMinY, int PCAMaxZ, int PCAMinZ, int BoundaryMinX, int BoundaryMinY, 
00060                   int BoundaryMinZ, int Boundary_LengthX, int Boundary_LengthY, float** w_m, unsigned char* PCA_ROI, void  **initProbDataPtr, 
00061                   float** initPCAMeanShapePtr, int* initPCAMeanShapeIncY, int *initPCAMeanShapeIncZ, float*** initPCAEigenVectorsPtr, 
00062                   int **initPCAEigenVectorsIncY, int** initPCAEigenVectorsIncZ);
00063 
00064 
00065   // This calculates the metric defined by KL Divergence.
00066   // Call this function by optimization method 
00067   float ComputeCostFunction(const double *initPCAPara) const;
00068 
00069 
00070   // Initialize values
00071   EMLocalShapeCostFunction(EMLocal_Hierarchical_Class_Parameters* initEMHierarchyParameters, int  *initPCANumberOfEigenModes, int DisableMultiThreading);
00072   ~EMLocalShapeCostFunction();
00073 
00074   // ------------------------
00075   // Set/Get  Function
00076   // ------------------------
00077 
00078   void InitRegSpecPara(int RegistrationType, int LengthX, int LengthY, int LengthZ);
00079 
00080   int GetROI_MinZ(){return this->ROI_MinZ;}
00081   int GetROI_MinY(){return this->ROI_MinY;}
00082   int GetROI_MinX(){return this->ROI_MinX;}
00083   int GetROI_MaxZ(){return this->ROI_MaxZ;}
00084   int GetROI_MaxY(){return this->ROI_MaxY;}
00085   int GetROI_MaxX(){return this->ROI_MaxX;}
00086 
00087   int GetROI_LengthX(){return this->ROI_LengthX;}
00088   int GetROI_LengthY(){return this->ROI_LengthY;}
00089   int GetROI_LengthZ(){return this->ROI_LengthZ;}
00090 
00091   unsigned char* GetROI() {return this->ROI;}
00092   void ROI_Unassign() { this->ROI = NULL;}
00093 
00094   int  GetROIIncY() {return this->ROIIncY;}
00095   int  GetROIIncZ() {return this->ROIIncZ;}
00096 
00097   // Got rid of it bc I have my own instance of NumTotalTypeCLASS (NumberOfTotalTypeCLASS)
00098   int    GetNumberOfTotalTypeCLASS()   {return this->NumberOfTotalTypeCLASS;}
00099 
00100   int    GetNumClasses()          {return this->EMHierarchyParameters->NumClasses; } 
00101   int*   GetNumChildClasses()     {return this->EMHierarchyParameters->NumChildClasses; } 
00102 
00103   // They are differently defined from this->EMHierarchyParameter
00104   int    GetProbDataType()        {return this->EMHierarchyParameters->ProbDataType;}
00105   int*   GetProbDataIncY()        {return this->ProbDataIncY;}
00106   int*   GetProbDataIncZ()        {return this->ProbDataIncZ;}
00107   void   SetProbDataPtr(void* init, int i)  {this->ProbDataPtr[i] = init;}
00108   void** GetProbDataPtr()         {return this->ProbDataPtr;}
00109   
00110   float* GetProbDataMinusWeight() {return this->EMHierarchyParameters->ProbDataMinusWeight;}
00111   float* GetProbDataWeight ()     {return this->EMHierarchyParameters->ProbDataWeight;}
00112 
00113   int*   GetImage_Length() { return this->Image_Length;}
00114   const double* GetPCAPara() { return this->ParaDepVar->PCAPara;}
00115   int    GetNumOfThreads() { return this->NumOfThreads;} 
00116   EMLocalShapeCostFunction_MultiThreadedParameters* GetMultiThreadedParameters() {return this->MultiThreadedParameters;}
00117   int    GetRegistrationType(){return this->RegistrationType;}
00118   char*  GetIncludeSpatialPriorForNormalization() { return this->IncludeSpatialPriorForNormalization;}
00119   void   SetROIExactVoxelCount(int* init) {this->ROIExactVoxelCount = init;} 
00120 
00121   void   SetNumberOfVoxelsInImage(int init) {this->NumberOfVoxelsInImage = init;}
00122   void   SpatialCostFunctionOn(); 
00123   float* GetSpatialCostFunction(){return this->ParaDepVar->SpatialCostFunction;} 
00124   void   SpatialCostFunctionOff();
00125 
00126   int    GetPCANumberOfEigenModes(int index) {return this->PCANumberOfEigenModes[index];}
00127   int    *GetPCANumberOfEigenModes() {return this->PCANumberOfEigenModes;}
00128  
00129   int    GetPCATotalNumOfShapeParameters() {return this->PCATotalNumOfShapeParameters;}
00130 
00131   float  GetGaussianPenalty() {return this->ParaDepVar->GaussianPenalty;}
00132   float  GetImagePenalty() {return this->ParaDepVar->ImagePenalty;}
00133 
00134   float  GetImage_MidX() { return this->Image_MidX; } 
00135   float  GetImage_MidY() { return this->Image_MidY; } 
00136   float  GetImage_MidZ() { return this->Image_MidZ; } 
00137 
00138   float* Getweights(int index) {return this->weights[index];}
00139   int    GetweightsIncY() {return this->weightsIncY;}
00140   int    GetweightsIncZ() {return this->weightsIncZ;}
00141 
00142   float* GetPCAEigenVectorsPtr(int id, int index) {return this->PCAEigenVectorsPtr[id][index];}
00143   int    **GetPCAEigenVectorsIncY() {return this->PCAEigenVectorsIncY;}
00144   int    **GetPCAEigenVectorsIncZ() {return this->PCAEigenVectorsIncZ;}
00145 
00146 
00147   float* GetPCAMeanShapePtr(int index) {return this->PCAMeanShapePtr[index];}
00148   int*   GetPCAMeanShapeIncY() {return this->PCAMeanShapeIncY;}
00149   int*   GetPCAMeanShapeIncZ() {return this->PCAMeanShapeIncZ;}
00150 
00151   int    GetDataJump() {return this->DataJump;}
00152   int    GetDataIncY() {return this->DataIncY;}
00153   int    GetDataIncZ() {return this->DataIncZ;}
00154 
00155   // ------------------------
00156   // Utility Functions
00157   // ------------------------
00158   double Transfere_DistanceMap_Into_SpatialPrior(double distance, float variance, float boundary, float Min, float Max);
00159   void TransferePCAShapeParametersIntoArray(float** PCAShapeParameters,float* PCAParameters);
00160   void TransfereArrayIntoPCAShapeParameters(float* PCAParameters, float** PCAShapeParameters);
00161 
00162   // ------------------------
00163   // Public Variables
00164   // ------------------------
00165 
00166   // Variables set by vtkImageEMLocalSegment
00167   int   NumberOfTrainingSamples;
00168   int   PCAShapeModelType;  
00169   int    PCATotalNumOfShapeParameters;
00170   float  PCASpatialPriorVariance;
00171 
00172   // Variables defined by vtkImageEMLocalSuperClass
00173   float  **PCAInverseEigenValues;
00174   // You can say if each class has their own shape parameters defined or not
00175   float  *PCALogisticSlope;
00176   float  *PCALogisticBoundary;
00177   float  *PCALogisticMin;
00178   float  *PCALogisticMax;
00179 
00180   // Interface to registration model 
00181   float  **ClassToAtlasRotationMatrix;
00182   float  **ClassToAtlasTranslationVector; 
00183 
00184 private:
00185   void   DefinePCADataPtr(int inPCAMinX, int inPCAMinY, int inPCAMinZ, int inBoundaryMaxX, int inBoundaryMaxY, int inDataIncY,  int inDataIncZ, int &outJump, int &outDataIncY,  int &outDataIncZ);
00186 
00187   EMLocal_Hierarchical_Class_Parameters *EMHierarchyParameters;
00188   EMLocalShapeCostFunction_MultiThreadedParameters *MultiThreadedParameters;
00189   int NumOfThreads;
00190   vtkMultiThreader *Threader; 
00191 
00192   int ROI_MaxZ;
00193   int ROI_MaxY; 
00194   int ROI_MaxX; 
00195 
00196   int ROI_MinZ; 
00197   int ROI_MinY;
00198   int ROI_MinX;  
00199  
00200   int ROI_LengthX;
00201   int ROI_LengthY;
00202   int ROI_LengthZ;
00203 
00204   // These are neeeded bc of registration - set by function
00205   float Image_MidX; 
00206   float Image_MidY;
00207   float Image_MidZ;
00208   int RegistrationType;
00209   int Image_Length[3];
00210 
00211   void **ProbDataPtr;
00212   int  *ProbDataIncY;
00213   int  *ProbDataIncZ;
00214 
00215   float  **PCAMeanShapePtr;
00216   int    *PCAMeanShapeIncY;
00217   int    *PCAMeanShapeIncZ;
00218 
00219   float ***PCAEigenVectorsPtr;
00220   int    **PCAEigenVectorsIncY;
00221   int    **PCAEigenVectorsIncZ;
00222 
00223   int    *PCANumberOfEigenModes;
00224 
00225   unsigned char* ROI;
00226   int ROIIncY;
00227   int ROIIncZ;
00228   int *ROIExactVoxelCount;
00229  
00230   float** weights;
00231   int weightsIncY;
00232   int weightsIncZ;
00233 
00234   char *IncludeSpatialPriorForNormalization;
00235 
00236   //Needed own instance of this variable bc EMHierarchyParameter could be deleted 
00237   // before this class is deleted 
00238   int NumberOfTotalTypeCLASS;
00239 
00240   int DataJump;
00241   int DataIncY;
00242   int DataIncZ;
00243 
00244   // Needed for Print function
00245   int NumberOfVoxelsInImage;
00246 
00247   // Needed for ITK 
00248   EMLocalShapeCostFunction_IterationSpecificVariables *ParaDepVar;
00249 
00250 
00251 };
00252 #endif
00253 

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1