OpenMS
Loading...
Searching...
No Matches
MSImagingGeometry.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Timo Sachsenberg, Patrick Boschmann $
7// --------------------------------------------------------------------------
8
9#pragma once
10
14
15#include <limits>
16#include <unordered_map>
17#include <vector>
18
19namespace OpenMS
20{
32class OPENMS_DLLAPI MSImagingGeometry final
33{
34public:
36 struct Pixel
37 {
38 UInt x = 0;
39 UInt y = 0;
40 Size spectrum_index = 0;
41 };
42
48 void setDimensions(UInt width, UInt height);
49
52 UInt getWidth() const;
53
56 UInt getHeight() const;
57
64 void setPixelSize(double x, double y, const std::string& unit = "micrometer");
65
68 double getPixelSizeX() const;
69
72 double getPixelSizeY() const;
73
76 const std::string& getPixelSizeUnit() const;
77
87 void addPixel(UInt x, UInt y, Size spectrum_index);
88
95 bool hasPixel(UInt x, UInt y) const;
96
105
108 const std::vector<Pixel>& getPixels() const;
109
113
115 void clear();
116
118 static constexpr Size NO_REGION = std::numeric_limits<Size>::max();
119
131 void addRegion(const MSImagingRegion& region);
132
139
142
145 const std::vector<MSImagingRegion>& getRegions() const;
146
154
158
166 Size regionOf(UInt x, UInt y) const;
167
174 std::vector<Size> getRegionPixels(Size id) const;
175
182 std::vector<Size> getRegionSpectrumIndices(Size id) const;
183
184 private:
185 UInt width_ = 0;
186 UInt height_ = 0;
187 double pixel_size_x_ = 1.0;
188 double pixel_size_y_ = 1.0;
189 std::string pixel_size_unit_ = "micrometer";
190 std::vector<Pixel> pixels_;
191 std::unordered_map<UInt64, Size> lookup_;
192
193 static UInt64 packKey_(UInt x, UInt y);
194 std::vector<MSImagingRegion> regions_;
195 std::unordered_map<Size, Size> region_id_to_index_;
196};
197
198} // namespace OpenMS
Pixel grid metadata and (x, y) -> spectrum_index lookup for MSI data.
Definition MSImagingGeometry.h:33
Size getNumberOfPixels() const
Total number of pixels with a bound spectrum.
const std::vector< MSImagingRegion > & getRegions() const
All regions in insertion order.
void clearRegions()
Removes all regions; acquired pixels are left untouched.
double getPixelSizeY() const
Physical pixel size along y.
static UInt64 packKey_(UInt x, UInt y)
bool hasPixel(UInt x, UInt y) const
Tests pixel presence at (x, y).
const std::vector< Pixel > & getPixels() const
Pixels in insertion order.
UInt getWidth() const
Image width.
const MSImagingRegion & getRegion(Size id) const
Returns the region with the given id.
std::vector< Size > getRegionSpectrumIndices(Size id) const
Spectrum indices of the acquired pixels belonging to a region.
void addPixel(UInt x, UInt y, Size spectrum_index)
Adds a pixel at (x, y) bound to spectrum_index.
Size getSpectrumIndex(UInt x, UInt y) const
Looks up the spectrum index at (x, y).
std::vector< Size > getRegionPixels(Size id) const
Acquired pixels belonging to a region, as indices into getPixels().
std::vector< Pixel > pixels_
Definition MSImagingGeometry.h:190
void setPixelSize(double x, double y, const std::string &unit="micrometer")
Records the physical pixel size and its unit.
void addRegion(const MSImagingRegion &region)
Adds a region to the geometry as a decoupled overlay.
std::unordered_map< Size, Size > region_id_to_index_
Definition MSImagingGeometry.h:195
Size regionOf(UInt x, UInt y) const
Returns the id of the region owning the acquired pixel at (x, y).
void setDimensions(UInt width, UInt height)
Sets the image dimensions.
std::unordered_map< UInt64, Size > lookup_
Definition MSImagingGeometry.h:191
UInt getHeight() const
Image height.
void clear()
Resets all state (dimensions, pixel size, pixels, lookup, regions).
const std::string & getPixelSizeUnit() const
Unit for the pixel size.
double getPixelSizeX() const
Physical pixel size along x.
void removeRegion(Size id)
Removes the region with the given id.
std::vector< MSImagingRegion > regions_
Definition MSImagingGeometry.h:194
Size getNumberOfRegions() const
Number of regions in the overlay.
A pixel in the imaging grid, linked to one spectrum in the experiment.
Definition MSImagingGeometry.h:37
A spatial region within an MSI dataset, in global pixel coordinates.
Definition MSImagingRegion.h:30
uint64_t UInt64
Unsigned integer type (64bit)
Definition Types.h:47
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19