MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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:
49 enum Direction {
50 NONE = 0,
51 LEFT = 1,
52 TOP = 2,
53 RIGHT = 4,
54 BOTTOM = 8
55 };
56
57 typedef std::vector<Vector2> vecPoint2D;
58 typedef vecPoint2D::iterator vecPoint2DIter;
59
60 friend class CSOMarchingSquares;
61
66
67public:
69 void reset();
72 void set(int topLeftVoxel[2], float values[4], float isoValue, char cellConfig = 0);
75 bool isAmbiguous() const;
77 inline bool isIsoCell() const
78 {
79 return isIsoCell(_cellConfig);
80 }
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 case LEFT:
112 return RIGHT;
113 case TOP:
114 return BOTTOM;
115 case RIGHT:
116 return LEFT;
117 case BOTTOM:
118 return TOP;
119 default:
120 return NONE;
121 }
122 }
123
126 {
127 return ((_cellConfig != rkCell._cellConfig) || (_topLeftVoxel[0] != rkCell._topLeftVoxel[0]) ||
128 (_topLeftVoxel[1] != rkCell._topLeftVoxel[1]));
129 }
130
131private:
132 bool _isCorner() const;
133
138 int _getDirectionOppositeOfEdge() const;
139
141 std::array<float, 2> _voxelsInDirection(int direction) const;
142
148 static float interpolate(float valueA, float valueB, float interpolationValue);
149
150protected:
153 unsigned char _cellConfig;
155 int _topLeftVoxel[2];
162 float _values[4];
170};
171
173
174inline bool CSOMarchingSquaresCell::isAmbiguous() const
175{
176 return (_cellConfig == 5) || (_cellConfig == 10);
177}
178
180
181inline bool CSOMarchingSquaresCell::isIsoCell(char cellConfig)
182{
183 return (cellConfig != 0) && (cellConfig != 15);
184}
185
187
#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)
Sets the top left position in voxel coordinates topLeftVoxel, the values of the four corners,...
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 operator!=(CSOMarchingSquaresCell &rkCell)
The inequality operator takes the cell configuration and the cell position into account.
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.