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

Pixel grid metadata and (x, y) -> spectrum_index lookup for MSI data. More...

#include <OpenMS/IMAGING/MSImagingGeometry.h>

Collaboration diagram for MSImagingGeometry:
[legend]

Classes

struct  Pixel
 A pixel in the imaging grid, linked to one spectrum in the experiment. More...
 

Public Member Functions

void setDimensions (UInt width, UInt height)
 Sets the image dimensions.
 
UInt getWidth () const
 Image width.
 
UInt getHeight () const
 Image height.
 
void setPixelSize (double x, double y, const std::string &unit="micrometer")
 Records the physical pixel size and its unit.
 
double getPixelSizeX () const
 Physical pixel size along x.
 
double getPixelSizeY () const
 Physical pixel size along y.
 
const std::string & getPixelSizeUnit () const
 Unit for the pixel size.
 
void addPixel (UInt x, UInt y, Size spectrum_index)
 Adds a pixel at (x, y) bound to spectrum_index.
 
bool hasPixel (UInt x, UInt y) const
 Tests pixel presence at (x, y).
 
Size getSpectrumIndex (UInt x, UInt y) const
 Looks up the spectrum index at (x, y).
 
const std::vector< Pixel > & getPixels () const
 Pixels in insertion order.
 
Size getNumberOfPixels () const
 Total number of pixels with a bound spectrum.
 
void clear ()
 Resets all state (dimensions, pixel size, pixels, lookup, regions).
 
void addRegion (const MSImagingRegion &region)
 Adds a region to the geometry as a decoupled overlay.
 
void removeRegion (Size id)
 Removes the region with the given id.
 
void clearRegions ()
 Removes all regions; acquired pixels are left untouched.
 
const std::vector< MSImagingRegion > & getRegions () const
 All regions in insertion order.
 
const MSImagingRegiongetRegion (Size id) const
 Returns the region with the given id.
 
Size getNumberOfRegions () const
 Number of regions in the overlay.
 
Size regionOf (UInt x, UInt y) const
 Returns the id of the region owning the acquired pixel at (x, y).
 
std::vector< SizegetRegionPixels (Size id) const
 Acquired pixels belonging to a region, as indices into getPixels().
 
std::vector< SizegetRegionSpectrumIndices (Size id) const
 Spectrum indices of the acquired pixels belonging to a region.
 

Static Public Attributes

static constexpr Size NO_REGION = std::numeric_limits<Size>::max()
 Sentinel returned by regionOf() when a coordinate belongs to no region.
 

Static Private Member Functions

static UInt64 packKey_ (UInt x, UInt y)
 

Private Attributes

UInt width_ = 0
 
UInt height_ = 0
 
double pixel_size_x_ = 1.0
 
double pixel_size_y_ = 1.0
 
std::string pixel_size_unit_ = "micrometer"
 
std::vector< Pixelpixels_
 
std::unordered_map< UInt64, Sizelookup_
 
std::vector< MSImagingRegionregions_
 
std::unordered_map< Size, Sizeregion_id_to_index_
 

Detailed Description

Pixel grid metadata and (x, y) -> spectrum_index lookup for MSI data.

Coordinates are zero-based. imzML files are one-based; the Phase 2 loader (ImzMLFile) is responsible for normalizing those to zero-based coordinates before populating this geometry.

3D MSI is intentionally not modeled here. Serial-section experiments should be handled as a collection of MSImagingExperiment objects (one per section).


Class Documentation

◆ OpenMS::MSImagingGeometry::Pixel

struct OpenMS::MSImagingGeometry::Pixel

A pixel in the imaging grid, linked to one spectrum in the experiment.

Collaboration diagram for MSImagingGeometry::Pixel:
[legend]
Class Members
Size spectrum_index = 0 Index into the bound MSExperiment.
UInt x = 0 Column index (zero-based).
UInt y = 0 Row index (zero-based).

Member Function Documentation

◆ addPixel()

void addPixel ( UInt  x,
UInt  y,
Size  spectrum_index 
)

Adds a pixel at (x, y) bound to spectrum_index.

Parameters
[in]xColumn index (zero-based).
[in]yRow index (zero-based).
[in]spectrum_indexIndex into the bound MSExperiment.
Exceptions
Exception::InvalidValueon duplicate coordinates, or if dimensions have been set and (x, y) is outside [0, width) x [0, height).

◆ addRegion()

void addRegion ( const MSImagingRegion region)

Adds a region to the geometry as a decoupled overlay.

Membership of acquired pixels in the region is derived on demand via MSImagingRegion::contains(); no per-pixel region state is stored.

Parameters
[in]regionRegion footprint to add (copied in).
Exceptions
Exception::InvalidValueif the id equals NO_REGION, the id is already present, or the footprint geometrically overlaps an existing region.

◆ clear()

void clear ( )

Resets all state (dimensions, pixel size, pixels, lookup, regions).

◆ clearRegions()

void clearRegions ( )

Removes all regions; acquired pixels are left untouched.

◆ getHeight()

UInt getHeight ( ) const

Image height.

Returns
Number of rows.

◆ getNumberOfPixels()

Size getNumberOfPixels ( ) const

Total number of pixels with a bound spectrum.

Returns
Size of the pixel list.

◆ getNumberOfRegions()

Size getNumberOfRegions ( ) const

Number of regions in the overlay.

Returns
Size of the region list.

◆ getPixels()

const std::vector< Pixel > & getPixels ( ) const

Pixels in insertion order.

Returns
Reference to the internal pixel list.

◆ getPixelSizeUnit()

const std::string & getPixelSizeUnit ( ) const

Unit for the pixel size.

Returns
Reference to the unit string.

◆ getPixelSizeX()

double getPixelSizeX ( ) const

Physical pixel size along x.

Returns
Stored x pixel size.

◆ getPixelSizeY()

double getPixelSizeY ( ) const

Physical pixel size along y.

Returns
Stored y pixel size.

◆ getRegion()

const MSImagingRegion & getRegion ( Size  id) const

Returns the region with the given id.

Parameters
[in]idRegion id to look up.
Returns
Reference to the stored region.
Exceptions
Exception::ElementNotFoundif no region with that id exists.

◆ getRegionPixels()

std::vector< Size > getRegionPixels ( Size  id) const

Acquired pixels belonging to a region, as indices into getPixels().

Parameters
[in]idRegion id.
Returns
Positions in getPixels() of the member pixels (use to index getPixels()).
Exceptions
Exception::ElementNotFoundif no region with that id exists.

◆ getRegions()

const std::vector< MSImagingRegion > & getRegions ( ) const

All regions in insertion order.

Returns
Reference to the internal region list.

◆ getRegionSpectrumIndices()

std::vector< Size > getRegionSpectrumIndices ( Size  id) const

Spectrum indices of the acquired pixels belonging to a region.

Parameters
[in]idRegion id.
Returns
The spectrum_index values of the member pixels (use to index the bound MSExperiment).
Exceptions
Exception::ElementNotFoundif no region with that id exists.

◆ getSpectrumIndex()

Size getSpectrumIndex ( UInt  x,
UInt  y 
) const

Looks up the spectrum index at (x, y).

Parameters
[in]xColumn index.
[in]yRow index.
Returns
spectrum_index recorded for that pixel.
Exceptions
Exception::ElementNotFoundif no pixel exists at that coordinate.

◆ getWidth()

UInt getWidth ( ) const

Image width.

Returns
Number of columns.

◆ hasPixel()

bool hasPixel ( UInt  x,
UInt  y 
) const

Tests pixel presence at (x, y).

Parameters
[in]xColumn index.
[in]yRow index.
Returns
true if a pixel was inserted at that coordinate.

◆ packKey_()

static UInt64 packKey_ ( UInt  x,
UInt  y 
)
staticprivate

◆ regionOf()

Size regionOf ( UInt  x,
UInt  y 
) const

Returns the id of the region owning the acquired pixel at (x, y).

Parameters
[in]xColumn index.
[in]yRow index.
Returns
The owning region's id, or NO_REGION if (x, y) is not an acquired pixel or belongs to no region.

◆ removeRegion()

void removeRegion ( Size  id)

Removes the region with the given id.

Parameters
[in]idRegion id to remove.
Exceptions
Exception::ElementNotFoundif no region with that id exists.

◆ setDimensions()

void setDimensions ( UInt  width,
UInt  height 
)

Sets the image dimensions.

Parameters
[in]widthNumber of columns.
[in]heightNumber of rows.

◆ setPixelSize()

void setPixelSize ( double  x,
double  y,
const std::string &  unit = "micrometer" 
)

Records the physical pixel size and its unit.

Parameters
[in]xPixel size along x.
[in]yPixel size along y.
[in]unitLength unit (default "micrometer").

Member Data Documentation

◆ height_

UInt height_ = 0
private

◆ lookup_

std::unordered_map<UInt64, Size> lookup_
private

◆ NO_REGION

constexpr Size NO_REGION = std::numeric_limits<Size>::max()
staticconstexpr

Sentinel returned by regionOf() when a coordinate belongs to no region.

◆ pixel_size_unit_

std::string pixel_size_unit_ = "micrometer"
private

◆ pixel_size_x_

double pixel_size_x_ = 1.0
private

◆ pixel_size_y_

double pixel_size_y_ = 1.0
private

◆ pixels_

std::vector<Pixel> pixels_
private

◆ region_id_to_index_

std::unordered_map<Size, Size> region_id_to_index_
private

◆ regions_

std::vector<MSImagingRegion> regions_
private

◆ width_

UInt width_ = 0
private