MeVisLabToolboxReference
MeVisLab/Standard/Sources/ML/MLCSO/CSOTools/CSOMarchingSquaresCell.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00009 //----------------------------------------------------------------------------------
00010 
00011 #ifndef __MSCell_H
00012 #define __MSCell_H
00013 
00014 #include "MLCSOIncludes.h"
00015 
00016 
00017 ML_START_NAMESPACE
00018 
00019 class CSOMarchingSquares;
00020 
00022 
00023 // A cell consists of four voxel values, thus there are 16 possible configurations
00024 // describing which voxel value is greater or lower than the isovalue.
00025 // The cell configuration is saved as a bit set such that Bit 0 is set if the upper left
00026 // corner is above the isovalue. See below for the mapping of nth bit to voxel position:
00027 //
00028 //   1--------2         2^0     2^1
00029 //   |        |
00030 //   |        |
00031 //   |        |
00032 //   |        |
00033 //   8--------4         2^3     2^2
00034 
00036 
00038 class MLCSO_EXPORT CSOMarchingSquaresCell
00039 {
00040 
00041 public:
00042 
00044   enum Direction {
00045     NONE   = 0, 
00046     LEFT   = 1, 
00047     TOP    = 2, 
00048     RIGHT  = 4, 
00049     BOTTOM = 8  
00050   };
00051 
00052   typedef std::vector<Vector2>    vecPoint2D;     
00053   typedef vecPoint2D::iterator vecPoint2DIter; 
00054 
00055   friend class CSOMarchingSquares; 
00056 
00058   CSOMarchingSquaresCell();
00060   ~CSOMarchingSquaresCell();
00061 
00062 public:
00063 
00065   void reset();
00068   void set(int topLeftVoxel[2], float values[4], float isoValue);
00071   bool isAmbiguous() const;
00073   bool isIsoCell() const;
00079   int  getToDirection(int fromDir) const;
00086   bool addPoints(bool bIinterpolate, int fromDir, vecPoint2D& points, float xyOffset);
00087 
00089   bool operator != (CSOMarchingSquaresCell& rkCell) {
00090     return ((_cellConfig != rkCell._cellConfig) ||
00091       (_topLeftVoxel[0] != rkCell._topLeftVoxel[0]) ||
00092       (_topLeftVoxel[1] != rkCell._topLeftVoxel[1]));
00093   }
00094 
00095 protected:
00096 
00099   unsigned char _cellConfig;
00101   int          _topLeftVoxel[2];
00108   float        _values[4];
00110   float        _isoValue;
00113   bool         _isBorder;
00114 };
00115 
00117 
00118 inline bool CSOMarchingSquaresCell::isAmbiguous() const 
00119 { 
00120   return (_cellConfig == 5) || (_cellConfig == 10); 
00121 }
00122 
00124 
00125 inline bool CSOMarchingSquaresCell::isIsoCell() const
00126 {
00127   return (_cellConfig != 0) && (_cellConfig != 15);
00128 }
00129 
00131 
00132 
00133 ML_END_NAMESPACE
00134 
00135 
00136 #endif // __MSCell_H
00137