OpenMS
Loading...
Searching...
No Matches
MSImagingRegion Class Referencefinal

A spatial region within an MSI dataset, in global pixel coordinates. More...

#include <OpenMS/IMAGING/MSImagingRegion.h>

Collaboration diagram for MSImagingRegion:
[legend]

Public Types

enum class  Shape { Rectangle , Mask }
 Discriminates how a region's footprint is represented. More...
 

Public Member Functions

const std::string & getName () const
 Region name.
 
bool contains (UInt x, UInt y) const
 Tests whether the global coordinate (x, y) is inside the region.
 
bool intersects (const MSImagingRegion &other) const
 Tests whether this region's footprint geometrically overlaps other.
 
Shape getShape () const
 Region shape (Rectangle or Mask).
 
Size getId () const
 Region identifier.
 
UInt getMinX () const
 Leftmost column of the global bounding box (inclusive).
 
UInt getMinY () const
 Top row of the global bounding box (inclusive).
 
UInt getMaxX () const
 Rightmost column of the global bounding box (inclusive).
 
UInt getMaxY () const
 Bottom row of the global bounding box (inclusive).
 
UInt getBBoxWidth () const
 Bounding box width in pixels (max_x - min_x + 1).
 
UInt getBBoxHeight () const
 Bounding box height in pixels (max_y - min_y + 1).
 
const std::vector< bool > & getMask () const
 Bbox-local row-major bitmask; empty for a Rectangle.
 
Size area () const
 Number of pixels inside the region.
 

Static Public Member Functions

static MSImagingRegion rectangle (Size id, const std::string &name, UInt min_x, UInt min_y, UInt max_x, UInt max_y)
 Creates a rectangular region spanning the inclusive bounding box.
 
static MSImagingRegion fromMask (Size id, const std::string &name, UInt origin_x, UInt origin_y, UInt width, UInt height, std::vector< bool > mask)
 Creates a masked region from a row-major bitmask over a bounding box.
 

Private Attributes

Size id_ {0}
 
Shape shape_ = Shape::Rectangle
 
std::string name_
 
std::vector< bool > mask_
 
UInt min_x_ {0}
 
UInt min_y_ {0}
 
UInt max_x_ {0}
 
UInt max_y_ {0}
 

Detailed Description

A spatial region within an MSI dataset, in global pixel coordinates.

A region is a pure-geometry footprint, either an axis-aligned rectangular bounding box (Shape::Rectangle) or a per-pixel bitmask within a bounding box (Shape::Mask). It knows nothing about acquired pixels or spectra and is reusable as a bare footprint (e.g. a microscopy annotation). Construct via the rectangle() / fromMask() factories. Coordinates are zero-based and bounding boxes are inclusive on both ends.

Member Enumeration Documentation

◆ Shape

enum class Shape
strong

Discriminates how a region's footprint is represented.

Enumerator
Rectangle 

grid aligned bounding box (every cell inside the bbox is part of the region)

Mask 

per pixel bitmask inside the bounding box

Member Function Documentation

◆ area()

Size area ( ) const

Number of pixels inside the region.

Returns
Bounding-box area for a Rectangle, set-bit count (popcount) for a Mask.

◆ contains()

bool contains ( UInt  x,
UInt  y 
) const

Tests whether the global coordinate (x, y) is inside the region.

Parameters
[in]xColumn index (zero-based).
[in]yRow index (zero-based).
Returns
true if (x, y) lies within the footprint (bbox for a Rectangle, a set bit for a Mask).

◆ fromMask()

static MSImagingRegion fromMask ( Size  id,
const std::string &  name,
UInt  origin_x,
UInt  origin_y,
UInt  width,
UInt  height,
std::vector< bool >  mask 
)
static

Creates a masked region from a row-major bitmask over a bounding box.

The global bounding box is [origin_x, origin_x + width - 1] x [origin_y, origin_y + height - 1]; mask is stored bbox-local.

Parameters
[in]idRegion identifier.
[in]nameHuman-readable region name.
[in]origin_xLeftmost column of the bounding box (zero-based).
[in]origin_yTop row of the bounding box (zero-based).
[in]widthBounding box width in pixels.
[in]heightBounding box height in pixels.
[in]maskRow-major bitmask (true = inside), size == width * height.
Returns
A region with Shape::Mask.
Exceptions
Exception::InvalidValueif width or height is 0, if mask.size() != width * height, or if mask is all-false.

◆ getBBoxHeight()

UInt getBBoxHeight ( ) const

Bounding box height in pixels (max_y - min_y + 1).

Returns
Bounding box height.

◆ getBBoxWidth()

UInt getBBoxWidth ( ) const

Bounding box width in pixels (max_x - min_x + 1).

Returns
Bounding box width.

◆ getId()

Size getId ( ) const

Region identifier.

Returns
The stored id.

◆ getMask()

const std::vector< bool > & getMask ( ) const

Bbox-local row-major bitmask; empty for a Rectangle.

Returns
Reference to the mask (branch on getShape() before use).

◆ getMaxX()

UInt getMaxX ( ) const

Rightmost column of the global bounding box (inclusive).

Returns
max x.

◆ getMaxY()

UInt getMaxY ( ) const

Bottom row of the global bounding box (inclusive).

Returns
max y.

◆ getMinX()

UInt getMinX ( ) const

Leftmost column of the global bounding box (inclusive).

Returns
min x.

◆ getMinY()

UInt getMinY ( ) const

Top row of the global bounding box (inclusive).

Returns
min y.

◆ getName()

const std::string & getName ( ) const

Region name.

Returns
Reference to the stored name.

◆ getShape()

Shape getShape ( ) const

Region shape (Rectangle or Mask).

Returns
The shape discriminator.

◆ intersects()

bool intersects ( const MSImagingRegion other) const

Tests whether this region's footprint geometrically overlaps other.

Symmetric and independent of any acquired pixels: returns true iff some global coordinate lies inside both footprints.

Parameters
[in]otherThe other region.
Returns
true if the footprints share at least one coordinate.

◆ rectangle()

static MSImagingRegion rectangle ( Size  id,
const std::string &  name,
UInt  min_x,
UInt  min_y,
UInt  max_x,
UInt  max_y 
)
static

Creates a rectangular region spanning the inclusive bounding box.

Parameters
[in]idRegion identifier.
[in]nameHuman-readable region name.
[in]min_xLeftmost column (inclusive, zero-based).
[in]min_yTop row (inclusive, zero-based).
[in]max_xRightmost column (inclusive, zero-based).
[in]max_yBottom row (inclusive, zero-based).
Returns
A region with Shape::Rectangle.
Exceptions
Exception::InvalidValueif max_x < min_x or max_y < min_y.

Member Data Documentation

◆ id_

Size id_ {0}
private

◆ mask_

std::vector<bool> mask_
private

◆ max_x_

UInt max_x_ {0}
private

◆ max_y_

UInt max_y_ {0}
private

◆ min_x_

UInt min_x_ {0}
private

◆ min_y_

UInt min_y_ {0}
private

◆ name_

std::string name_
private

◆ shape_

Shape shape_ = Shape::Rectangle
private