MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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#include <CSOBase/CSODefines.h>
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
33class CSO;
34
36
40{
41public:
46
47
48public:
50 void reset();
52 void setInterpolation(bool use);
54 void setImage(float* image, int imgSizeX, int imgSizeY);
58 void setFunction(CSOFunction* implicitFunction, const Matrix4& voxelToWorldMatrix, int startX, int startY,
59 int imgSizeX, int imgSizeY, int voxelZPosition);
60
68 std::vector<CSOMarchingSquaresCell::vecPoint2D>& vecPositions);
69
83
86
87protected:
90 void _findStartPosition(int& startX, int& startY);
101 std::vector<std::array<unsigned char, 2>>* cellsVisitedDirections = nullptr);
105 void _createCell(int topLeftVoxel[2], std::set<unsigned int>& cellsVisited,
106 std::queue<CSOMarchingSquaresCell>& cellFront);
108 void _createCell(int topLeftVoxel[2], CSOMarchingSquaresCell& cell, float values[4], char cellConfig);
114 int _getPossibleEnterDirection(const CSOMarchingSquaresCell& cell) const;
116 unsigned int _getKey(const CSOMarchingSquaresCell& cell) const;
118 unsigned int _getKey(int x, int y) const;
119
121 float _getValueAt(int x, int y);
122
124 bool _isInImage(int x, int y) const;
125
126protected:
128 float* _image;
133
138
147
150
152 boost::unordered_map<int, double> _existingValues;
153};
154
156
157inline void CSOMarchingSquares::setImage(float* image, int imgSizeX, int imgSizeY)
158{
159 _image = image;
160 _imageSizeX = imgSizeX;
161 _imageSizeY = imgSizeY;
162 _startX = 0;
163 _startY = 0;
164
165 _function = nullptr;
166 _voxelZPosition = 0;
167}
168
170
171inline void CSOMarchingSquares::setFunction(CSOFunction* implicitFunction, const Matrix4& voxelToWorldMatrix,
172 int startX, int startY, int imgSizeX, int imgSizeY, int voxelZPosition)
173{
174 _image = nullptr;
175
176 _imageSizeX = imgSizeX;
177 _imageSizeY = imgSizeY;
178
179 _startX = startX;
180 _startY = startY;
181
182 _function = implicitFunction;
183 _voxelToWorldMatrix = voxelToWorldMatrix;
184
185 _voxelZPosition = voxelZPosition;
186}
187
189
190inline void CSOMarchingSquares::setInterpolation(bool useInterpolation)
191{
192 _bInterpolatePoints = useInterpolation;
193}
194
196
197inline unsigned int CSOMarchingSquares::_getKey(const CSOMarchingSquaresCell& cell) const
198{
199 return _getKey(cell._topLeftVoxel[0], cell._topLeftVoxel[1]);
200}
201
203
204inline unsigned int CSOMarchingSquares::_getKey(int x, int y) const
205{
206 return 1 + x - _startX + ((1 + y - _startY) * (_imageSizeX + _startX + 1));
207}
208
210
211inline int CSOMarchingSquares::_getPossibleEnterDirection(const CSOMarchingSquaresCell& cell) const
212{
213 int fromDir = cell.getToDirection(1);
214 if (0 == fromDir) {
215 fromDir = cell.getToDirection(2);
216 if (0 == fromDir) {
217 fromDir = cell.getToDirection(4);
218 if (0 == fromDir) {
219 fromDir = cell.getToDirection(8);
220 }
221 }
222 }
223 return fromDir;
224}
225
227
#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 voxel-to-world 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)
Creates 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)
Creates 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)
Creates a new cell at position topLeftVoxel[2], and keeps track whether this cell has already been cr...
~CSOMarchingSquares()
Destructor.
int _walkToCell(const CSOMarchingSquaresCell &fromCell, int fromDir, CSOMarchingSquaresCell &toCell)
Creates 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 isovalue to find the isoline 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
The class PagedImage, representing a fragmented image that manages properties and data of an image lo...
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
CSOSmoothingModes
Enumeration of smoothing modes.
Definition CSODefines.h:158
CSOMarchingSquaresCell::vecPoint2D positions