vtkImageEMAtlasSegmenter.h

Go to the documentation of this file.
00001 /*=auto=========================================================================
00002 
00003   Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
00004 
00005   See Doc/copyright/copyright.txt
00006   or http://www.slicer.org/copyright/copyright.txt for details.
00007 
00008   Program:   3D Slicer
00009   Module:    $RCSfile: vtkImageEMAtlasSegmenter.h,v $
00010   Date:      $Date: 2006/12/08 23:28:24 $
00011   Version:   $Revision: 1.1 $
00012 
00013 =========================================================================auto=*/
00014 // .NAME vtkImageEMAtlasSegmenter
00015 // Since 22-Apr-02 vtkImageEMAtlas3DSegmenter is called vtkImageEMAtlasSegmenter - Kilian
00016 // EMAtlas =  using EM Algorithm with Private Tissue Class Probability
00017 #ifndef __vtkImageEMAtlasSegmenter_h
00018 #define __vtkImageEMAtlasSegmenter_h 
00019   
00020 #include "vtkImageEMGeneral.h" 
00021 #include "vtkEMSegment.h"
00022 #include "vtkImageData.h"
00023 #include "vtkImageEMAtlasSuperClass.h"
00024 
00025 // ---------------------------------------------------
00026 
00027 //BTX  
00028 // Needed to parallelise the algorithm
00029 typedef struct {
00030   int           id ;
00031   float         **w_m_input;
00032   unsigned char *MapVector;
00033   float         *cY_M; 
00034   int           imgX;
00035   int           imgY; 
00036   int           imgXY;
00037   int           StartVoxel;
00038   int           EndVoxel;
00039   int           NumClasses;
00040   int           NumTotalTypeCLASS;
00041   int*          NumChildClasses;
00042   int           NumInputImages;
00043   double        Alpha;
00044   double        ***MrfParams;
00045   void          ** ProbDataPtr;
00046   int           *ProbDataIncY; 
00047   int           *ProbDataIncZ; 
00048   float         *ProbDataWeight;
00049   float         *ProbDataMinusWeight;
00050   int           ProbDataType;
00051   double        **LogMu;
00052   double        ***InvLogCov;
00053   double        *InvSqrtDetLogCov;
00054   double        *TissueProbability;
00055   int           *VirtualNumInputImages;
00056   float         **w_m_output;
00057 } EMAtlas_MF_Approximation_Work_Private;
00058 
00059 //ETX 
00060 class VTK_EMSEGMENT_EXPORT vtkImageEMAtlasSegmenter : public vtkImageEMGeneral
00061 {
00062   public:
00063   // -----------------------------------------------------
00064   // Genral Functions for the filter
00065   // -----------------------------------------------------
00066   static vtkImageEMAtlasSegmenter *New();
00067   vtkTypeMacro(vtkImageEMAtlasSegmenter,vtkObject);
00068   void PrintSelf(ostream& os, vtkIndent indent);
00069   // -----------------------------------------------------
00070   // Setting Algorithm 
00071   // -----------------------------------------------------
00072   vtkSetMacro(NumIter, int);
00073   vtkGetMacro(NumIter, int);
00074 
00075   vtkSetMacro(NumRegIter, int);
00076   vtkGetMacro(NumRegIter, int);
00077 
00078   vtkSetMacro(Alpha, double);
00079   vtkGetMacro(Alpha, double);
00080 
00081   vtkSetMacro(SmoothingWidth, int);
00082   vtkGetMacro(SmoothingWidth, int);
00083 
00084   vtkSetMacro(SmoothingSigma, int);
00085   vtkGetMacro(SmoothingSigma, int);
00086 
00087   void SetNumberOfTrainingSamples(int Number) {this->NumberOfTrainingSamples = Number;}
00088   vtkGetMacro(NumberOfTrainingSamples, int);
00089 
00090   int* GetSegmentationBoundaryMin();
00091   int* GetSegmentationBoundaryMax();
00092 
00093   int* GetExtent(){return this->Extent;}
00094 
00095   // -----------------------------------------------------
00096   // Print functions 
00097   // -----------------------------------------------------
00098   vtkGetStringMacro(PrintDir);
00099   vtkSetStringMacro(PrintDir);
00100 
00101   // Description:
00102   // Number of input images for the segmentation - Has to be defined before defining any class specific setting 
00103   // Otherwise they get deleted
00104   // Be carefull: this is just the number of images not attlases, 
00105   // e.g. I have 5 tissue classes and 3 Inputs (T1, T2, SPGR) -> NumInputImages = 3
00106   void SetNumInputImages(int number);
00107   int GetNumInputImages() {return this->NumInputImages;} 
00108 
00109   void SetImageInput(int index, vtkImageData *image) {this->SetInput(index,image);}
00110 
00111   vtkGetMacro(ImageProd, int); 
00112 
00113   // Desciption:
00114   // Dimension of work area => SegmentationBoundaryMax[i] - SegmentationBoundaryMin[i] + 1 
00115   int GetDimensionX();
00116   int GetDimensionY();
00117   int GetDimensionZ();
00118 
00119   // -----------------------------------------------------
00120   // EM-MF Function 
00121   // -----------------------------------------------------  
00122   // Description:
00123   // Defines the Label map of a given image
00124   static void DetermineLabelMap(short *LabelMap, int NumTotalTypeCLASS, int* NumChildClasses, vtkImageEMAtlasSuperClass* head,  short* ROI,int ImageMax, float **w_m);
00125 
00126   // Desciption:
00127   // Special function for parallelise MF part -> Creating Threads 
00128   int MF_Approx_Workpile(float **w_m_input,unsigned char* MapVector, float *cY_M, int imgXY,double ***InvLogCov,
00129                          double *InvSqrtDetLogCov, int NumTotalTypeCLASS, int* NumChildClasses, int NumClasses, void** ProbDataPtr, 
00130                          int* ProbDataIncY, int* ProbDataIncZ, float* ProbDataWeight, float *ProbDataMinusWeight, double** LogMu, 
00131                          double* TissueProbability, int *VirtualNumInputImages, vtkImageEMAtlasSuperClass* head, float **_m_output);
00132 
00133   // Description:
00134   // Print out intermediate result of the algorithm in a  file
00135   // The file is called  this->PrintIntermediateDir/EM*.m
00136   void PrintIntermediateResultsToFile(int iter, float **w_m, short *ROI, unsigned char* OutputVector, int NumTotalTypeCLASS, int* NumChildClasses, 
00137                       vtkImageEMAtlasSuperClass* actSupCl, char* LevelName, void **ClassList, classType *ClassListType, int* LabelList, FILE** QualityFile);
00138 
00139   // -----------------------------------------------------
00140   // Intensity Correction 
00141   // -----------------------------------------------------
00142 
00143   //BTX
00144   vtkImageEMAtlasSuperClass* GetActiveSuperClass() {return this->activeSuperClass;}
00145   vtkImageEMAtlasSuperClass* GetHeadClass() {return this->HeadClass;}
00146   //ETX
00147   int HierarchicalSegmentation(vtkImageEMAtlasSuperClass* head, float** InputVector,short *ROI, short *OutputVector, EMTriVolume & iv_m, EMVolume *r_m, char* LevelName);
00148 
00149   //Kilian rewrite it 
00150   void PrintSuperClass () {
00151     printf("Current: %f Prob: %f Label: %d Parent: %f \n", activeSuperClass, activeSuperClass->GetTissueProbability(), activeSuperClass->GetLabel(), activeSuperClass->GetParentClass());
00152   } 
00153 
00154   // Desciption:
00155   // Head Class is the inital class under which all subclasses are attached  
00156   void SetHeadClass(vtkImageEMAtlasSuperClass *InitHead) {
00157     InitHead->Update(); 
00158     if (InitHead->GetErrorFlag()) {
00159       // This is done before this->Update() so we cannot use Error Message Report;
00160       vtkErrorMacro(<<"Cannot set HeadClass because the class given has its ErrorFlag activated !");
00161       return;
00162     }
00163     this->HeadClass   = InitHead;
00164     this->activeClass = (void*) InitHead;
00165     this->activeClassType  = SUPERCLASS;
00166   }
00167 
00168   // =============================
00169   // For Message Protocol
00170   char* GetErrorMessages() {return this->ErrorMessage.GetMessages(); }
00171   int GetErrorFlag() {return  this->ErrorMessage.GetFlag();}
00172   void ResetErrorMessage() {this->ErrorMessage.ResetParameters();}
00173   // So we can also enter streams for functions outside vtk
00174   ProtocolMessages* GetErrorMessagePtr(){return &this->ErrorMessage;}
00175 
00176   char* GetWarningMessages() {return this->WarningMessage.GetMessages(); }
00177   int GetWarningFlag() {return  this->WarningMessage.GetFlag();}
00178   void ResetWarningMessage() {this->WarningMessage.ResetParameters();}
00179   ProtocolMessages* GetWarningMessagePtr(){return &this->WarningMessage;}
00180 protected:
00181   vtkImageEMAtlasSegmenter();
00182   vtkImageEMAtlasSegmenter(const vtkImageEMAtlasSegmenter&) {};
00183   ~vtkImageEMAtlasSegmenter(); 
00184   void DeleteVariables();
00185 
00186   void operator=(const vtkImageEMAtlasSegmenter&) {};
00187   void ExecuteData(vtkDataObject *);   
00188 
00189   //BTX
00190   // Description:
00191   // Checks all intput image if they have coresponding dimensions 
00192 // #if EM_VTK_OLD_SETTINGS
00193 //   int CheckInputImage(vtkImageData * inData,int DataTypeOrig, float DataSpacingOrig[3], int num);
00194 // #else 
00195   int CheckInputImage(vtkImageData * inData,int DataTypeOrig, vtkFloatingPointType DataSpacingOrig[3], int num);
00196 // #endif
00197   // Description:
00198   // Resets the error flag and messages 
00199   void ResetMessageSettings();  
00200 
00201   int NumIter;         // Number of EM-iterations
00202   int NumRegIter;      // Number of iteration in E- Step to regularize weights 
00203   double Alpha;        // alpha - Paramter 0<= alpaha <= 1
00204 
00205   int SmoothingWidth;  // Width for Gausian to regularize weights   
00206   int SmoothingSigma;  // Sigma paramter for regularizing Gaussian
00207 
00208   int NumInputImages;               // Number of input images  
00209  
00210   // These are defined in vtkEMImagePrivateSegment
00211   char* PrintDir;        // In which directory should the results be printed  
00212 
00213   // New Variables for Local Version 
00214   int ImageProd;                   // Size of Image = DimensionX*DimensionY*DimensionZ
00215 
00216   int Extent[6];                  // Extent of images - needed for several inputs 
00217 
00218   int NumberOfTrainingSamples;    // Number of Training Samples Probability Image has been summed up over !  
00219 
00220   vtkImageEMAtlasSuperClass *activeSuperClass;   // Currently Active Super Class -> Important for interface with TCL
00221   classType    activeClassType;
00222 
00223   vtkImageEMAtlasSuperClass *HeadClass;          // Initial Class
00224 
00225   void *activeClass;               // Currently Active Class -> Important for interface with TCL
00226 
00227   ProtocolMessages ErrorMessage;    // Lists all the error messges -> allows them to be displayed in tcl too 
00228   ProtocolMessages WarningMessage;  // Lists all the warning messges -> allows them to be displayed in tcl too 
00229   //ETX
00230 };
00231 #endif
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1