MeVisLab Toolbox Reference
CSOMarchingSquares.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"
21#include "CSOFunction.h"
22
23#include <ThirdPartyWarningsDisable.h>
24#include <boost/unordered_map.hpp>
25#include <ThirdPartyWarningsRestore.h>
26
27#include <queue>
28#include <set>
29#include <array>
30
32
33
35
39{
40public:
41
46
47
48public:
49
51 void reset();
53 void setInterpolation(bool use);
55 void setImage(float* image, int imgSizeX, int imgSizeY);
59 void setFunction(CSOFunction* implicitFunction, const Matrix4& voxelToWorldMatrix, int startX, int startY, int imgSizeX, int imgSizeY, int voxelZPosition);
60
66 void findAllIsoLines(float isoValue, bool takeShortestPath, std::vector<CSOMarchingSquaresCell::vecPoint2D>& vecPositions);
67
81
84
85protected:
86
88 void _findStartPosition(int& startX, int& startY);
95 void _trackIsoCell(CSOMarchingSquaresCell startCell, const int initialFromDir, CSOMarchingSquaresCell::vecPoint2D& positions, std::vector<std::array<unsigned char, 2>>* cellsVisitedDirections = nullptr);
99 void _createCell(int topLeftVoxel[2], std::set<unsigned int>& cellsVisited, std::queue<CSOMarchingSquaresCell>& cellFront);
101 void _createCell(int topLeftVoxel[2], CSOMarchingSquaresCell& cell, float values[4], char cellConfig);
107 int _getPossibleEnterDirection(const CSOMarchingSquaresCell& cell) const;
109 unsigned int _getKey(const CSOMarchingSquaresCell& cell) const;
111 unsigned int _getKey(int x, int y) const;
112
114 float _getValueAt(int x, int y);
115
117 bool _isInImage(int x, int y) const;
118
119protected:
120
122 float* _image;
127
132
141
144
146 boost::unordered_map <int, double> _existingValues;
147};
148
150
151inline void CSOMarchingSquares::setImage(float* image, int imgSizeX, int imgSizeY)
152{
153 _image = image;
154 _imageSizeX = imgSizeX;
155 _imageSizeY = imgSizeY;
156 _startX = 0;
157 _startY = 0;
158
159 _function = nullptr;
160 _voxelZPosition = 0;
161}
162
164
165inline void CSOMarchingSquares::setFunction(CSOFunction* implicitFunction,
166 const Matrix4& voxelToWorldMatrix,
167 int startX, int startY,
168 int imgSizeX, int imgSizeY,
169 int voxelZPosition)
170{
171 _image = nullptr;
172
173 _imageSizeX = imgSizeX;
174 _imageSizeY = imgSizeY;
175
176 _startX = startX;
177 _startY = startY;
178
179 _function = implicitFunction;
180 _voxelToWorldMatrix = voxelToWorldMatrix;
181
182 _voxelZPosition = voxelZPosition;
183}
184
186
187inline void CSOMarchingSquares::setInterpolation(bool useInterpolation)
188{
189 _bInterpolatePoints = useInterpolation;
190}
191
193
194inline unsigned int CSOMarchingSquares::_getKey(const CSOMarchingSquaresCell& cell) const
195{
196 return _getKey(cell._topLeftVoxel[0], cell._topLeftVoxel[1]);
197}
198
200
201inline unsigned int CSOMarchingSquares::_getKey(int x, int y) const
202{
203 return 1 + x-_startX + ((1 + y-_startY) * (_imageSizeX+_startX+1));
204}
205
207
208inline int CSOMarchingSquares::_getPossibleEnterDirection(const CSOMarchingSquaresCell& cell) const
209{
210 int fromDir = cell.getToDirection(1);
211 if (0 == fromDir) {
212 fromDir = cell.getToDirection(2);
213 if (0 == fromDir) {
214 fromDir = cell.getToDirection(4);
215 if (0 == fromDir) {
216 fromDir = cell.getToDirection(8);
217 }
218 }
219 }
220 return fromDir;
221}
222
224
#define MLCSO_EXPORT
Defines export symbols for classes, so they can be used in other DLLs.
Definition MLCSOSystem.h:23
Base class for distance functions for application in the marching cubes algorithm.
Definition CSOFunction.h:29
std::vector< Vector2 > vecPoint2D
Defines a 2D point vector.
This class implements the Marching Squares algorithm to find isolines on 2D image slices.
Matrix4 _voxelToWorldMatrix
The voxelToWorld matrix.
float * _image
Pointer to input image.
int _imageSizeX
The x extent of the input image.
int _startY
Starting voxel y (function).
int _voxelZPosition
The z-position of the voxels.
boost::unordered_map< int, double > _existingValues
A map holding all computed image/function values.
bool _findNearestIsoCell(int voxelPos[2], CSOMarchingSquaresCell &cell)
Searches for the first cell that is an iso cell starting from [voxelPos[0], voxelPos[1]]....
float _getValueAt(int x, int y)
Returns the value of the image or function at the given position.
void _createCell(int topLeftVoxel[2], CSOMarchingSquaresCell &cell)
Create a new cell at position topLeftVoxel[2].
int _imageSizeY
The y extent of the input image.
void _findStartPosition(int &startX, int &startY)
Searches for a starting position such that startX/startY make up the top-left voxel position of a cel...
bool fillCSO(FillCSOParameters &parameters)
Fills the given CSO with seed points according to the given list of points.
void reset()
Resets the state of the object.
CSOMarchingSquares()
Constructor.
void _createCell(int topLeftVoxel[2], CSOMarchingSquaresCell &cell, float values[4], char cellConfig)
Create a new cell at position topLeftVoxel[2].
void findIsoLine(int startPosX, int startPosY, float isoValue, bool takeShortestPath, CSOMarchingSquaresCell::vecPoint2D &positions)
Looks for an isoline on the image.
bool _isInImage(int x, int y) const
Returns whether the x,y coordinates are within the image.
void _createCell(int topLeftVoxel[2], std::set< unsigned int > &cellsVisited, std::queue< CSOMarchingSquaresCell > &cellFront)
Create a new cell at position topLeftVoxel[2], keeps track whether this cell has already been created...
~CSOMarchingSquares()
Destructor.
int _walkToCell(const CSOMarchingSquaresCell &fromCell, int fromDir, CSOMarchingSquaresCell &toCell)
Create a cell toCell from the cell fromCell coming from fromDir.
CSOFunction * _function
An implicit function.
void _trackIsoCell(CSOMarchingSquaresCell startCell, const int initialFromDir, CSOMarchingSquaresCell::vecPoint2D &positions, std::vector< std::array< unsigned char, 2 > > *cellsVisitedDirections=nullptr)
Tracks the isoline starting from the startCell.
int _startX
Starting voxel x (function).
bool _bInterpolatePoints
Should the contour be interpolated bi-linearly?
float _isoValue
The iso value to find the iso line for.
void findAllIsoLines(float isoValue, bool takeShortestPath, std::vector< CSOMarchingSquaresCell::vecPoint2D > &vecPositions)
Finds all contours on the image with isovalue isovalue. Returns them in a vector of 2D position vecto...
bool _findNearestIsoCell(int voxelPosX, int voxelPosY, CSOMarchingSquaresCell &cell)
Searches for the first cell that is an iso cell starting from [voxelPosX, voxelPosY]....
The CSO represents a contour segmentation object.
Definition CSO.h:44
Class which represents an image, which manages properties of an image and image data which is located...
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
CSOSmoothingModes
Enumeration of smoothing modes.
Definition CSODefines.h:166
CSOMarchingSquaresCell::vecPoint2D positions