MeVisLab Toolbox Reference
CSOMarchingSquaresCell.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13
15
16#pragma once
17
18
19#include "MLCSOIncludes.h"
20
21#include <array>
22
24
25class CSOMarchingSquares;
26
28
29// A cell consists of four voxel values, thus there are 16 possible configurations
30// describing which voxel value is greater or lower than the isovalue.
31// The cell configuration is saved as a bit set such that Bit 0 is set if the upper left
32// corner is above the isovalue. See below for the mapping of nth bit to voxel position:
33//
34// 1--------2 2^0 2^1
35// | |
36// | |
37// | |
38// | |
39// 8--------4 2^3 2^2
40
42
45{
46
47public:
48
51 {
52 NONE = 0,
53 LEFT = 1,
54 TOP = 2,
55 RIGHT = 4,
56 BOTTOM = 8
57 };
58
59 typedef std::vector<Vector2> vecPoint2D;
60 typedef vecPoint2D::iterator vecPoint2DIter;
61
62 friend class CSOMarchingSquares;
63
68
69public:
70
72 void reset();
75 void set(int topLeftVoxel[2], float values[4], float isoValue, char cellConfig = 0);
78 bool isAmbiguous() const;
80 inline bool isIsoCell() const { return isIsoCell(_cellConfig); }
82 static inline bool isIsoCell(char cellConfig);
83
89 int getToDirection(int fromDir) const;
96 bool addPoints(bool bIinterpolate, int fromDir, vecPoint2D& points, float xyOffset);
97
99 static inline char calculateCellConfig(float isoValue, float values[4])
100 {
101 char config = (static_cast<unsigned char>(values[0] >= isoValue) << 0) |
102 (static_cast<unsigned char>(values[1] >= isoValue) << 1) |
103 (static_cast<unsigned char>(values[2] >= isoValue) << 2) |
104 (static_cast<unsigned char>(values[3] >= isoValue) << 3);
105 return config;
106 }
107
109 {
110 switch (fromDir)
111 {
112 case LEFT:
113 return RIGHT;
114 case TOP:
115 return BOTTOM;
116 case RIGHT:
117 return LEFT;
118 case BOTTOM:
119 return TOP;
120 default:
121 return NONE;
122 }
123 }
124
126 bool operator != (CSOMarchingSquaresCell& rkCell)
127 {
128 return ((_cellConfig != rkCell._cellConfig) ||
129 (_topLeftVoxel[0] != rkCell._topLeftVoxel[0]) ||
130 (_topLeftVoxel[1] != rkCell._topLeftVoxel[1]));
131 }
132
133private:
134
135 bool _isCorner() const;
136
141 int _getDirectionOppositeOfEdge() const;
142
144 std::array<float, 2> _voxelsInDirection(int direction) const;
145
151 static float interpolate(float valueA, float valueB, float interpolationValue);
152
153protected:
154
157 unsigned char _cellConfig;
159 int _topLeftVoxel[2];
166 float _values[4];
174};
175
177
178inline bool CSOMarchingSquaresCell::isAmbiguous() const
179{
180 return (_cellConfig == 5) || (_cellConfig == 10);
181}
182
184
185inline bool CSOMarchingSquaresCell::isIsoCell(char cellConfig)
186{
187 return (cellConfig != 0) && (cellConfig != 15);
188}
189
191
#define MLCSO_EXPORT
Defines export symbols for classes, so they can be used in other DLLs.
Definition MLCSOSystem.h:23
void set(int topLeftVoxel[2], float values[4], float isoValue, char cellConfig=0)
Set the top left position in voxel coordinates topLeftVoxel, the values of the 4 corners and the isoV...
void reset()
Resets the state of the cell (i.e. no values are set)
int getToDirection(int fromDir) const
Returns the direction for this cell to go to coming from fromDir.
bool addPoints(bool bIinterpolate, int fromDir, vecPoint2D &points, float xyOffset)
Adds points the points vector according to the cell configuration.
CSOMarchingSquaresCell()
Constructor.
float _isoValue
The isovalue to check the values against.
static int oppositeDirection(int fromDir)
unsigned char _cellConfig
The cell configuration is saved as a bit set such that Bit 0 is set if the upper left corner is above...
static char calculateCellConfig(float isoValue, float values[4])
Calculates the cell config.
vecPoint2D::iterator vecPoint2DIter
Defines an iterator to iterate through a 2D point vector.
Direction
Enumeration of directions (next to compute).
bool _isBorderLeft
Flags to indicate that some voxels of this cell are outside the image.
std::vector< Vector2 > vecPoint2D
Defines a 2D point vector.
bool isIsoCell() const
Returns true if this cell is intersected by the isoline.
~CSOMarchingSquaresCell()
Destructor.
This class implements the Marching Squares algorithm to find isolines on 2D image slices.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.