MeVisLab Toolbox Reference
ml::CSOMarchingSquares Class Reference

This class implements the Marching Squares algorithm to find isolines on 2D image slices. More...

#include <CSOMarchingSquares.h>

Classes

struct  FillCSOParameters
 

Public Member Functions

 CSOMarchingSquares ()
 Constructor. More...
 
 ~CSOMarchingSquares ()
 Destructor. More...
 
void reset ()
 Resets the state of the object. More...
 
void setInterpolation (bool use)
 Specifies whether the algorithm should interpolate the contour bi-linearly. More...
 
void setImage (float *image, int imgSizeX, int imgSizeY)
 Sets the 2D image to track/find contours on. More...
 
void setFunction (CSOFunction *implicitFunction, const Matrix4 &voxelToWorldMatrix, int startX, int startY, int imgSizeX, int imgSizeY, int voxelZPosition)
 Sets a 3D interpolation function, an image size and voxel size and a fixed z-offset. More...
 
void findIsoLine (int startPosX, int startPosY, float isoValue, bool takeShortestPath, CSOMarchingSquaresCell::vecPoint2D &positions)
 Looks for an isoline on the image. More...
 
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 vectors. More...
 
bool fillCSO (FillCSOParameters &parameters)
 Fills the given CSO with seed points according to the given list of points. More...
 

Protected Member Functions

void _findStartPosition (int &startX, int &startY)
 Searches for a starting position such that startX/startY make up the top-left voxel position of a cell which is intersected by the isoline. More...
 
bool _findNearestIsoCell (int voxelPosX, int voxelPosY, CSOMarchingSquaresCell &cell)
 Searches for the first cell that is an iso cell starting from [voxelPosX, voxelPosY]. Returns true if a cell was found, i.e. cell is valid. More...
 
bool _findNearestIsoCell (int voxelPos[2], CSOMarchingSquaresCell &cell)
 Searches for the first cell that is an iso cell starting from [voxelPos[0], voxelPos[1]]. Returns true if a cell was found, i.e. cell is valid. More...
 
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. More...
 
void _createCell (int topLeftVoxel[2], CSOMarchingSquaresCell &cell)
 Create a new cell at position topLeftVoxel[2]. More...
 
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. More...
 
void _createCell (int topLeftVoxel[2], CSOMarchingSquaresCell &cell, float values[4], char cellConfig)
 Create a new cell at position topLeftVoxel[2]. More...
 
int _walkToCell (const CSOMarchingSquaresCell &fromCell, int fromDir, CSOMarchingSquaresCell &toCell)
 Create a cell toCell from the cell fromCell coming from fromDir. More...
 
int _getPossibleEnterDirection (const CSOMarchingSquaresCell &cell) const
 
unsigned int _getKey (const CSOMarchingSquaresCell &cell) const
 Returns the key for a cell. E.g. for hashtables. More...
 
unsigned int _getKey (int x, int y) const
 Returns the key for a position for hashtables. More...
 
float _getValueAt (int x, int y)
 Returns the value of the image or function at the given position. More...
 
bool _isInImage (int x, int y) const
 Returns whether the x,y coordinates are within the image. More...
 

Protected Attributes

float * _image
 Pointer to input image. More...
 
int _imageSizeX
 The x extent of the input image. More...
 
int _imageSizeY
 The y extent of the input image. More...
 
int _startX
 Starting voxel x (function). More...
 
int _startY
 Starting voxel y (function). More...
 
float _isoValue
 The iso value to find the iso line for. More...
 
CSOFunction_function
 An implicit function. More...
 
int _voxelZPosition
 The z-position of the voxels. More...
 
Matrix4 _voxelToWorldMatrix
 The voxelToWorld matrix. More...
 
bool _bInterpolatePoints
 Should the contour be interpolated bi-linearly? More...
 
boost::unordered_map< int, double > _existingValues
 A map holding all computed image/function values. More...
 

Detailed Description

This class implements the Marching Squares algorithm to find isolines on 2D image slices.

One can either find an iso line starting from a start point or find all contours on that slice.

Definition at line 38 of file CSOMarchingSquares.h.

Constructor & Destructor Documentation

◆ CSOMarchingSquares()

ml::CSOMarchingSquares::CSOMarchingSquares ( )

Constructor.

◆ ~CSOMarchingSquares()

ml::CSOMarchingSquares::~CSOMarchingSquares ( )

Destructor.

Member Function Documentation

◆ _createCell() [1/3]

void ml::CSOMarchingSquares::_createCell ( int  topLeftVoxel[2],
CSOMarchingSquaresCell cell 
)
protected

Create a new cell at position topLeftVoxel[2].

◆ _createCell() [2/3]

void ml::CSOMarchingSquares::_createCell ( int  topLeftVoxel[2],
CSOMarchingSquaresCell cell,
float  values[4],
char  cellConfig 
)
protected

Create a new cell at position topLeftVoxel[2].

◆ _createCell() [3/3]

void ml::CSOMarchingSquares::_createCell ( int  topLeftVoxel[2],
std::set< unsigned int > &  cellsVisited,
std::queue< CSOMarchingSquaresCell > &  cellFront 
)
protected

Create a new cell at position topLeftVoxel[2], keeps track whether this cell has already been created.

◆ _findNearestIsoCell() [1/2]

bool ml::CSOMarchingSquares::_findNearestIsoCell ( int  voxelPos[2],
CSOMarchingSquaresCell cell 
)
protected

Searches for the first cell that is an iso cell starting from [voxelPos[0], voxelPos[1]]. Returns true if a cell was found, i.e. cell is valid.

◆ _findNearestIsoCell() [2/2]

bool ml::CSOMarchingSquares::_findNearestIsoCell ( int  voxelPosX,
int  voxelPosY,
CSOMarchingSquaresCell cell 
)
protected

Searches for the first cell that is an iso cell starting from [voxelPosX, voxelPosY]. Returns true if a cell was found, i.e. cell is valid.

◆ _findStartPosition()

void ml::CSOMarchingSquares::_findStartPosition ( int &  startX,
int &  startY 
)
protected

Searches for a starting position such that startX/startY make up the top-left voxel position of a cell which is intersected by the isoline.

◆ _getKey() [1/2]

unsigned int ml::CSOMarchingSquares::_getKey ( const CSOMarchingSquaresCell cell) const
inlineprotected

Returns the key for a cell. E.g. for hashtables.

Definition at line 194 of file CSOMarchingSquares.h.

References ml::CSOMarchingSquaresCell::_topLeftVoxel.

◆ _getKey() [2/2]

unsigned int ml::CSOMarchingSquares::_getKey ( int  x,
int  y 
) const
inlineprotected

Returns the key for a position for hashtables.

Definition at line 201 of file CSOMarchingSquares.h.

◆ _getPossibleEnterDirection()

int ml::CSOMarchingSquares::_getPossibleEnterDirection ( const CSOMarchingSquaresCell cell) const
inlineprotected
Returns
A start direction from which one can enter the created cell.

Definition at line 208 of file CSOMarchingSquares.h.

References ml::CSOMarchingSquaresCell::getToDirection().

◆ _getValueAt()

float ml::CSOMarchingSquares::_getValueAt ( int  x,
int  y 
)
protected

Returns the value of the image or function at the given position.

◆ _isInImage()

bool ml::CSOMarchingSquares::_isInImage ( int  x,
int  y 
) const
protected

Returns whether the x,y coordinates are within the image.

◆ _trackIsoCell()

void ml::CSOMarchingSquares::_trackIsoCell ( CSOMarchingSquaresCell  startCell,
const int  initialFromDir,
CSOMarchingSquaresCell::vecPoint2D positions,
std::vector< std::array< unsigned char, 2 >> *  cellsVisitedDirections = nullptr 
)
protected

Tracks the isoline starting from the startCell.

If this is not an iso-cell (i.e. the isoline intersects this cell) it just returns. One can optionally pass a map where to save all visited cells.

◆ _walkToCell()

int ml::CSOMarchingSquares::_walkToCell ( const CSOMarchingSquaresCell fromCell,
int  fromDir,
CSOMarchingSquaresCell toCell 
)
protected

Create a cell toCell from the cell fromCell coming from fromDir.

So this method first looks for the direction leaving the fromCell coming from the direction fromDir.

Returns
The direction from which one enters the toCell

◆ fillCSO()

bool ml::CSOMarchingSquares::fillCSO ( FillCSOParameters parameters)

Fills the given CSO with seed points according to the given list of points.

◆ findAllIsoLines()

void ml::CSOMarchingSquares::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 vectors.

◆ findIsoLine()

void ml::CSOMarchingSquares::findIsoLine ( int  startPosX,
int  startPosY,
float  isoValue,
bool  takeShortestPath,
CSOMarchingSquaresCell::vecPoint2D positions 
)

Looks for an isoline on the image.

It starts searching for a starting cell using the startPos parameters and then tracks this cell. All contour points are pushed back to the positions vector.

◆ reset()

void ml::CSOMarchingSquares::reset ( )

Resets the state of the object.

◆ setFunction()

void ml::CSOMarchingSquares::setFunction ( CSOFunction implicitFunction,
const Matrix4 voxelToWorldMatrix,
int  startX,
int  startY,
int  imgSizeX,
int  imgSizeY,
int  voxelZPosition 
)
inline

Sets a 3D interpolation function, an image size and voxel size and a fixed z-offset.

NOTE that this approach supports an axial scanning of the function only at the moment; if this class should scan in sagittal or coronal direction as well, some extra flag needs to be provided.

Definition at line 165 of file CSOMarchingSquares.h.

◆ setImage()

void ml::CSOMarchingSquares::setImage ( float *  image,
int  imgSizeX,
int  imgSizeY 
)
inline

Sets the 2D image to track/find contours on.

Definition at line 151 of file CSOMarchingSquares.h.

◆ setInterpolation()

void ml::CSOMarchingSquares::setInterpolation ( bool  use)
inline

Specifies whether the algorithm should interpolate the contour bi-linearly.

Definition at line 187 of file CSOMarchingSquares.h.

Member Data Documentation

◆ _bInterpolatePoints

bool ml::CSOMarchingSquares::_bInterpolatePoints
protected

Should the contour be interpolated bi-linearly?

Definition at line 143 of file CSOMarchingSquares.h.

◆ _existingValues

boost::unordered_map<int, double> ml::CSOMarchingSquares::_existingValues
protected

A map holding all computed image/function values.

Definition at line 146 of file CSOMarchingSquares.h.

◆ _function

CSOFunction* ml::CSOMarchingSquares::_function
protected

An implicit function.

Definition at line 136 of file CSOMarchingSquares.h.

◆ _image

float* ml::CSOMarchingSquares::_image
protected

Pointer to input image.

Definition at line 122 of file CSOMarchingSquares.h.

◆ _imageSizeX

int ml::CSOMarchingSquares::_imageSizeX
protected

The x extent of the input image.

Definition at line 124 of file CSOMarchingSquares.h.

◆ _imageSizeY

int ml::CSOMarchingSquares::_imageSizeY
protected

The y extent of the input image.

Definition at line 126 of file CSOMarchingSquares.h.

◆ _isoValue

float ml::CSOMarchingSquares::_isoValue
protected

The iso value to find the iso line for.

Definition at line 134 of file CSOMarchingSquares.h.

◆ _startX

int ml::CSOMarchingSquares::_startX
protected

Starting voxel x (function).

Definition at line 129 of file CSOMarchingSquares.h.

◆ _startY

int ml::CSOMarchingSquares::_startY
protected

Starting voxel y (function).

Definition at line 131 of file CSOMarchingSquares.h.

◆ _voxelToWorldMatrix

Matrix4 ml::CSOMarchingSquares::_voxelToWorldMatrix
protected

The voxelToWorld matrix.

Definition at line 140 of file CSOMarchingSquares.h.

◆ _voxelZPosition

int ml::CSOMarchingSquares::_voxelZPosition
protected

The z-position of the voxels.

Definition at line 138 of file CSOMarchingSquares.h.


The documentation for this class was generated from the following file: