OpenMS
Loading...
Searching...
No Matches
ClusteringGrid.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: Lars Nilse $
6// $Authors: Lars Nilse $
7// --------------------------------------------------------------------------
8#pragma once
9
12
16
17#include <list>
18#include <unordered_map>
19#include <vector>
20
21namespace OpenMS
22{
29class OPENMS_DLLAPI ClusteringGrid
30{
31 public:
35 typedef std::pair<int,int> CellIndex;
36
41
49 ClusteringGrid(const std::vector<double> &grid_spacing_x, const std::vector<double> &grid_spacing_y);
50
54 std::vector<double> getGridSpacingX() const;
55
59 std::vector<double> getGridSpacingY() const;
60
67 void addCluster(const CellIndex &cell_index, const int &cluster_index);
68
76 void removeCluster(const CellIndex &cell_index, const int &cluster_index);
77
82
90 const std::list<int>& getClusters(const CellIndex &cell_index) const;
91
98 CellIndex getIndex(const Point &position) const;
99
109 bool isNonEmptyCell(const CellIndex &cell_index) const;
110
116 int getCellCount() const;
117
118 private:
122 const std::vector<double> grid_spacing_x_;
123 const std::vector<double> grid_spacing_y_;
124
128 std::pair <double,double> range_x_;
129 std::pair <double,double> range_y_;
130
135 {
136 size_t operator()(const CellIndex& cell_index) const noexcept;
137 };
138
142 std::unordered_map<CellIndex, std::list<int>, CellIndexHash> cells_;
143
144};
145
146}
147
data structure to store 2D data to be clustered e.g. (m/z, retention time) coordinates from multiplex...
Definition ClusteringGrid.h:30
const std::vector< double > grid_spacing_y_
Definition ClusteringGrid.h:123
CellIndex getIndex(const Point &position) const
returns grid cell index (i,j) for the positions (x,y)
void removeCluster(const CellIndex &cell_index, const int &cluster_index)
removes a cluster from this grid cell and removes the cell if no other cluster left
int getCellCount() const
returns number of grid cells occupied by one or more clusters
const std::list< int > & getClusters(const CellIndex &cell_index) const
returns clusters in this grid cell
const std::vector< double > grid_spacing_x_
spacing of the grid in x and y direction
Definition ClusteringGrid.h:122
std::vector< double > getGridSpacingY() const
returns grid spacing in y direction
std::pair< int, int > CellIndex
Definition ClusteringGrid.h:35
std::unordered_map< CellIndex, std::list< int >, CellIndexHash > cells_
grid cell index mapped to a list of clusters in it (only cells with clusters)
Definition ClusteringGrid.h:142
void removeAllClusters()
removes all clusters from this grid (and hence all cells)
ClusteringGrid(const std::vector< double > &grid_spacing_x, const std::vector< double > &grid_spacing_y)
constructor taking two vectors
bool isNonEmptyCell(const CellIndex &cell_index) const
checks if there are clusters at this cell index
void addCluster(const CellIndex &cell_index, const int &cluster_index)
adds a cluster to this grid cell
std::pair< double, double > range_x_
[min, max] of the grid in x and y direction
Definition ClusteringGrid.h:128
std::pair< double, double > range_y_
Definition ClusteringGrid.h:129
DPosition< 2 > Point
Definition ClusteringGrid.h:40
std::vector< double > getGridSpacingX() const
returns grid spacing in x direction
Representation of a coordinate in D-dimensional space.
Definition DPosition.h:32
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
hash of a cell index
Definition ClusteringGrid.h:135
size_t operator()(const CellIndex &cell_index) const noexcept