mdsTetraFeatures.h

Go to the documentation of this file.
00001 //==============================================================================
00016 #ifndef MDS_TETRAFEATURES_H
00017 #define MDS_TETRAFEATURES_H
00018 
00019 #include "mdsTetraBase.h"
00020 #include "mdsTetraData.h"
00021 
00022 // MDSTk
00023 #include <MDSTk/Base/mdsGlobalLog.h>
00024 #include <MDSTk/Math/mdsStaticVector.h>
00025 
00026 // VCTL
00027 #include <VectorEntity/mcentity.h>
00028 
00029 // STL
00030 #include <string>
00031 #include <ostream>
00032 
00033 
00034 namespace mds
00035 {
00036 namespace seg
00037 {
00038 
00040 //#define USE_VARIANCE
00041 
00042 // TODO: Predelat do flagu! Podedit z toolkitu!
00043 
00046 #define SUBST_SMALL_TETRAS
00047 
00049 //#define SKIP_EDGE_VOXELS
00050 
00052 //#define SKIP_BOUNDARY_TETRAS
00053 
00054 
00055 //==============================================================================
00056 /*
00057  * Global constants.
00058  */
00059 
00060 namespace TetraFeatures
00061 {
00062 
00064 #ifdef USE_VARIANCE
00065     const int NUM_OF_BASIC_FEATURES     = 2;
00066 #else
00067     const int NUM_OF_BASIC_FEATURES     = 1;
00068 #endif // USE_VARIANCE
00069 
00071 const int NUM_OF_FEATURES               = NUM_OF_BASIC_FEATURES;
00072 
00074 //const int MIN_NUM_OF_VOXELS             = 16;
00075 //const int MIN_NUM_OF_VOXELS             = 4;
00076 const int MIN_NUM_OF_VOXELS             = 1;
00077 
00078 }
00079 
00080 
00081 //==============================================================================
00085 class CTetraFeatures : public CTetraBase, public mds::math::CStaticVector<double, TetraFeatures::NUM_OF_FEATURES>
00086 {
00087 public:
00089     typedef double tFeature;
00090 
00092     typedef mds::math::CStaticVector<double, TetraFeatures::NUM_OF_FEATURES> tVector;
00093 
00095     enum { NUM_OF_FEATURES = TetraFeatures::NUM_OF_FEATURES };
00096 
00098     enum
00099     {
00100         MEAN_VALUE = 0,
00101         VARIANCE,
00102     };
00103 
00105     enum
00106     {
00107         ERROR_NOT_EVALUATED     = 1,
00108         ERROR_CANNOT_EVALUATE   = 2,
00109     };
00110 
00111 public:
00113     CTetraFeatures() : m_iError(ERROR_NOT_EVALUATED), m_iNumOfVoxels(0) {}
00114 
00116     ~CTetraFeatures() {}
00117 
00118 
00120     tFeature& getFeature(mds::tSize i) { return get(i); }
00121     const tFeature& getFeature(tSize i) const { return get(i); }
00122 
00124     void setFeature(tSize i, tFeature Value) { set(i, Value); }
00125 
00126 
00128     int getNumOfVoxels() const { return m_iNumOfVoxels; }
00129 
00131     void setNumOfVoxels(int iValue) { m_iNumOfVoxels = iValue; }
00132 
00133 
00135     bool isError() const { return (m_iError != 0); }
00136 
00138     int getError() const { return m_iError; }
00139 
00141     void setError(int iError) { m_iError = iError; }
00142 
00143 
00145     tFeature& getVoxelMean() { return get(MEAN_VALUE); }
00146     const tFeature& getVoxelMean() const { return get(MEAN_VALUE); }
00147 
00149     void setVoxelMean(tFeature Value) { set(MEAN_VALUE, Value); }
00150 
00151 #ifdef USE_VARIANCE
00152 
00153     tFeature& getVoxelVariance() { return get(VARIANCE); }
00154     const tFeature& getVoxelVariance() const { return get(VARIANCE); }
00155 
00157     void setVoxelVariance(tFeature Value) { set(VARIANCE, Value); }
00158 #else
00159 
00160     tFeature& getVoxelVariance() { return m_VoxelVariance; }
00161     const tFeature& getVoxelVariance() const { return m_VoxelVariance; }
00162 
00164     void setVoxelVariance(tFeature Value) { m_VoxelVariance = Value; }
00165 #endif // USE_VARIANCE
00166 
00167 protected:
00169     int m_iError;
00170 
00172     int m_iNumOfVoxels;
00173 
00174 #ifndef USE_VARIANCE
00175 
00176     tFeature m_VoxelVariance;
00177 #endif // USE_VARIANCE
00178 };
00179 
00180 
00181 //==============================================================================
00185 class CTetraFeaturesExtractor : public CTetraBase
00186 {
00187 public:
00189     typedef CTetraFeatures::tFeature tFeature;
00190 
00192     typedef CTetraFeatures tVector;
00193 
00194 public:
00196     CTetraFeaturesExtractor() { clear(); }
00197 
00199     ~CTetraFeaturesExtractor() {}
00200 
00202     void acumulate(tVolume *pVolume, vctl::MCTetra *pTetrahedron, tScale *pScale);
00203 
00205     void acumulate(const CTetraFeaturesExtractor& Extractor);
00206 
00211     bool evaluate(tVector *pVector, bool bCheckNumOfVoxels = true);
00212 
00214     void clear();
00215 
00216 protected:
00218     double m_dSum, m_dSumSqr;
00219 
00221     int m_iNumOfVoxels;
00222 };
00223 
00224 
00225 //==============================================================================
00229 struct STetrahedronData
00230 {
00232 //    int m_iIndex;
00233 
00235     CTetraFeatures m_Features;
00236 
00238 //    STetrahedronData() : m_iIndex(-1) {}
00239     STetrahedronData() {}
00240 };
00241 
00242 
00243 //==============================================================================
00244 /*
00245  * Global functions.
00246  */
00247 
00250 inline int getTetrahedronRegion(vctl::MCTetra *pTetrahedron)
00251 {
00252 /*    STetrahedronData *pData = (STetrahedronData *)getTetrahedronDataPtr(pTetrahedron);
00253 
00254     return (pData) ? pData->m_iIndex : -1;*/
00255 
00256     return (pTetrahedron) ? pTetrahedron->GetObject() : -1;
00257 }
00258 
00259 
00262 inline void setTetrahedronRegion(vctl::MCTetra *pTetrahedron, int iIndex)
00263 {
00264 /*    STetrahedronData *pData = (STetrahedronData *)getTetrahedronDataPtr(pTetrahedron);
00265 
00266     if( !pData )
00267     {
00268         pData = new STetrahedronData;
00269         setTetrahedronDataPtr(pTetrahedron, pData);
00270     }
00271 
00272     pData->m_iIndex = iIndex;*/
00273 
00274     if( pTetrahedron )
00275     {
00276         pTetrahedron->SetObject(iIndex);
00277     }
00278 }
00279 
00280 
00282 inline CTetraFeatures *getTetrahedronFeatures(vctl::MCTetra *pTetrahedron)
00283 {
00284     STetrahedronData *pData = (STetrahedronData *)getTetrahedronDataPtr(pTetrahedron);
00285 
00286     if( !pData )
00287     {
00288         pData = new STetrahedronData;
00289         setTetrahedronDataPtr(pTetrahedron, pData);
00290     }
00291 
00292     return &(pData->m_Features);
00293 }
00294 
00295 
00296 } // namespace seg
00297 } // namespace mds
00298 
00299 #endif // MDS_TETRAFEATURES_H
00300 

Generated on Thu Mar 11 10:35:44 2010 for MDSTk Extension Libraries by  doxygen 1.4.6-NO