OpenMS
Loading...
Searching...
No Matches
ConvexHull2D.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: Marc Sturm, Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
15#include <OpenMS/OpenMSConfig.h>
16
17#include <functional>
18#include <map>
19#include <vector>
20
21namespace OpenMS
22{
48 class OPENMS_DLLAPI ConvexHull2D
49 {
50public:
52 typedef std::vector<PointType> PointArrayType;
53 typedef PointArrayType::size_type SizeType;
54 typedef PointArrayType::const_iterator PointArrayTypeConstIterator;
55
56 typedef std::map<PointType::CoordinateType, DBoundingBox<1> > HullPointType;
57
60
62 ConvexHull2D(const ConvexHull2D&) = default;
63
66
69
72
74 bool operator==(const ConvexHull2D& rhs) const;
75
77 void clear();
78
81
83 const HullPointType& getMapPoints() const { return map_points_; }
84
86 void setHullPoints(const PointArrayType& points);
87
90
93 bool addPoint(const PointType& point);
94
97 void addPoints(const PointArrayType& points);
98
112
122
123
133 bool encloses(const PointType& point) const;
134
135protected:
138
141
142 };
143} // namespace OpenMS
144
145// Hash function specialization for ConvexHull2D
146namespace std
147{
148 template<>
149 struct hash<OpenMS::ConvexHull2D>
150 {
151 std::size_t operator()(const OpenMS::ConvexHull2D& hull) const noexcept
152 {
153 std::size_t seed = 0;
154
155 // Hash map_points_ (map of RT -> m/z bounding box)
156 // std::map iteration order is deterministic (sorted by key)
157 const auto& map_points = hull.getMapPoints();
158 OpenMS::hash_combine(seed, OpenMS::hash_int(map_points.size()));
159 for (const auto& entry : map_points)
160 {
161 OpenMS::hash_combine(seed, OpenMS::hash_float(entry.first));
162 OpenMS::hash_combine(seed, std::hash<OpenMS::DBoundingBox<1>>{}(entry.second));
163 }
164
165 // Hash outer_points_ (vector of DPosition<2>)
166 const auto& outer_points = hull.getHullPoints();
167 OpenMS::hash_combine(seed, OpenMS::hash_int(outer_points.size()));
168 for (const auto& point : outer_points)
169 {
170 OpenMS::hash_combine(seed, std::hash<OpenMS::DPosition<2>>{}(point));
171 }
172
173 return seed;
174 }
175 };
176} // namespace std
177
Definition ConvexHull2D.h:49
ConvexHull2D()
default constructor
bool operator==(const ConvexHull2D &rhs) const
equality operator
bool addPoint(const PointType &point)
const HullPointType & getMapPoints() const
Accessor for the internal map representation (RT -> m/z bounding box)
Definition ConvexHull2D.h:83
ConvexHull2D & operator=(const ConvexHull2D &rhs)
assignment operator
ConvexHull2D(ConvexHull2D &&)=default
Move constructor.
void setHullPoints(const PointArrayType &points)
accessor for the outer(!) points (no checking is performed if this is actually a convex hull)
DBoundingBox< 2 > getBoundingBox() const
returns the bounding box of the feature hull points
ConvexHull2D & operator=(ConvexHull2D &&) &=default
move assignment operator
PointArrayType::size_type SizeType
Definition ConvexHull2D.h:53
PointArrayType outer_points_
just the list of points of the outer hull (derived from map_points_ or given by user)
Definition ConvexHull2D.h:140
DPosition< 2 > PointType
Definition ConvexHull2D.h:51
PointArrayType::const_iterator PointArrayTypeConstIterator
Definition ConvexHull2D.h:54
const PointArrayType & getHullPoints() const
accessor for the outer points
std::vector< PointType > PointArrayType
Definition ConvexHull2D.h:52
HullPointType map_points_
internal structure maintaining the hull and enabling queries to encloses()
Definition ConvexHull2D.h:137
void clear()
removes all points
Size compress()
Allows to reduce the disk/memory footprint of a hull.
void addPoints(const PointArrayType &points)
bool encloses(const PointType &point) const
returns if the point lies in the feature hull
std::map< PointType::CoordinateType, DBoundingBox< 1 > > HullPointType
Definition ConvexHull2D.h:56
ConvexHull2D(const ConvexHull2D &)=default
Copy constructor.
A D-dimensional bounding box.
Definition DBoundingBox.h:30
Representation of a coordinate in D-dimensional space.
Definition DPosition.h:32
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
std::size_t hash_int(T value) noexcept
Hash for an integer type.
Definition HashUtils.h:107
void hash_combine(std::size_t &seed, std::size_t value) noexcept
Combine a hash value with additional data using golden ratio mixing.
Definition HashUtils.h:87
std::size_t hash_float(T value) noexcept
Hash for a floating point type (float or double).
Definition HashUtils.h:142
STL namespace.
std::size_t operator()(const OpenMS::ConvexHull2D &hull) const noexcept
Definition ConvexHull2D.h:151