MeVisLabToolboxReference
FMEwork/Release/Sources/Shared/DTICalculator/IDTICalculator.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00013 //----------------------------------------------------------------------------------
00014 
00015 #ifndef __IDTICalculator__H_
00016 #define __IDTICalculator__H_
00017 
00018 #include "mlMacros.h"
00019 
00020 
00021 #include <MLMiscMath.h>
00022 
00023 
00024 
00025 // DLL export macro definition
00026 #ifdef DTICCALCULATOR_EXPORTS
00027   // Use the MLCSOLISTWRAPPERS_EXPORT macro to export classes and functions
00028   #define DTICCALCULATOR_EXPORT ML_LIBRARY_EXPORT_ATTRIBUTE
00029 #else
00030   // If included by external modules, exported symbols are declared as import symbols
00031   #define DTICCALCULATOR_EXPORT ML_LIBRARY_IMPORT_ATTRIBUTE
00032 #endif
00033 
00034 const double DIFFUSION_CONST = 1000.0;
00035 
00036 
00038 class ML_UNIX_ONLY_EXPORT(DTICCALCULATOR_EXPORT) IDTICalculator
00039 {
00040 
00041 public:
00042 
00043     virtual ~IDTICalculator(){};
00044 
00045     typedef MLMISCMATH_NAMESPACE::Math_Error_Type Error_Type;
00046 
00048     enum ErrorCodes{
00049         noErr                    = MLMISCMATH_NAMESPACE::noErr,
00050 
00051         matrixInvertErr          = MLMISCMATH_NAMESPACE::matrixInvertErr,
00052         matrixDiagErr            = MLMISCMATH_NAMESPACE::matrixDiagErr,
00053         negEVErr                 = MLMISCMATH_NAMESPACE::negEVErr,
00054     };
00055 
00056 
00057     virtual MLuint32 getDimension() const=0;
00058 
00064     virtual Error_Type setGradients(const double **aGradients, const MLuint32 lNrOfGradients)=0;
00065 
00066     virtual double getTensorError(const double *pLNNorm, const MLuint32 lNrOfGradients)=0;
00067 
00068     virtual MLuint32 getNrOfGradients() const=0;
00069 
00074     template<typename DATATYPE>
00075     static void calcLNNorm(double *pLNNorm, const DATATYPE* const *pInPtr, const MLuint32 lNrDWImages,
00076                            const double *bValueArray = NULL, const int bValue=1000)
00077     {
00078         const double ln_2 = 0.69314718055994530941723212145818;
00079         DATATYPE s0 = *(pInPtr[0]);
00080 
00081         for (MLuint32 i=1;i<lNrDWImages;i++)
00082         {
00083             DATATYPE si = *(pInPtr[i]);
00084 
00085             if ( si >= s0 )
00086             {
00087                 pLNNorm[i-1] = 0.0;
00088             }
00089             else if (s0 != 0 && si == 0)
00090             {
00091                 pLNNorm[i-1] = ((sizeof(MLuint16)<<3)+1)*ln_2; // different data types should always lead to same results, thus, MLuint16 is used for all of them!
00092             }
00093             else
00094             {
00095                 if (bValueArray==NULL)
00096                 {
00097                     pLNNorm[i-1]  = log(static_cast<double>(si)/static_cast<double>(s0))*(-DIFFUSION_CONST/static_cast<double>(bValue));
00098                 }
00099                 else
00100                 {
00101                    // note si and s0 are exchanged
00102                     pLNNorm[i-1]  = log(static_cast<double>(si)/static_cast<double>(s0))*(-DIFFUSION_CONST/bValueArray[i-1]);
00103                 }
00104             }
00105         }
00106 
00107     }
00108 
00109 
00111     virtual const double* calcDiffusionTensor(const double *pLNNorm) = 0;
00112 
00114     virtual Error_Type eigenAnaly()                                  = 0;
00116     virtual Error_Type eigenAnaly(double regularizationParam)        = 0;
00117 
00119     virtual const double* getEigenvalues()                     const = 0;
00120 
00123     virtual const double* getEigenvectors()                    const = 0;
00124 
00125 
00128     static double normalizeDiffusionStrength(double dDiffStrength,
00129                                              double dDiffusionNorm,
00130                                              double dDiffThreshold)
00131     {
00132         if ( dDiffusionNorm > 0.0)
00133         {
00134             dDiffStrength /= (dDiffusionNorm);
00135             if (dDiffStrength > 1.0)
00136             {
00137                 dDiffStrength = 1.0;
00138             }
00139             else if (dDiffStrength < dDiffThreshold)
00140             {
00141                  dDiffStrength = 0.0;
00142             }
00143         }
00144         else
00145         {
00146             dDiffStrength = 1.0;
00147         }
00148         return dDiffStrength;
00149     }
00150 
00151 
00152 
00154     virtual void DeleteDTICalculator ()=0;
00155 
00156 };
00157 
00158 
00159 class QuantificationFunction;
00161 
00163 #ifdef __cplusplus
00164 extern "C" {
00165 #endif
00166 
00167     ML_UNIX_ONLY_EXPORT(DTICCALCULATOR_EXPORT) IDTICalculator* NewDTICalculator(MLuint32 dim);
00168 
00169     //QuantificationFunction* NewQuantificationFunction(IDTICalculator::Diffiusion_Mode eMode);
00170 
00171 
00172 #ifdef __cplusplus
00173 }
00174 #endif
00175 
00176 #endif // __IDTICalculator__H_