1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Stephan Aiche$
25
// $Authors: Marc Sturm, Chris Bielow $
26
// --------------------------------------------------------------------------
28
#ifndef OPENMS_DATASTRUCTURES_CONVEXHULL2D_H
29
#define OPENMS_DATASTRUCTURES_CONVEXHULL2D_H
31
#include <OpenMS/config.h>
32
#include <OpenMS/CONCEPT/Types.h>
33
#include <OpenMS/DATASTRUCTURES/DBoundingBox.h>
34
#include <OpenMS/DATASTRUCTURES/DRange.h>
35
#include <OpenMS/DATASTRUCTURES/Map.h>
44
@brief A 2-dimensional hull representation in [counter]clockwise direction - depending on axis labelling.
46
The current implementation does not guarantee to produce convex hulls.
47
It can still store 'old' convex hulls from featureXML without problems, but does not support the enclose() query in this case,
48
and you will get an exception. As an alternative, you can use my_hull.getBoundingBox().encloses(), which yields similar results,
51
If you are creating new hull from peaks (eg during FeatureFinding), the generated hulls of a feature are defined as
52
a range in m/z dimension for each RT scan (thus might be non-convex). This has the advantage that one can clearly see
53
where points range within each scan (although missing points within this range are still not shown).
54
When hulls are created like this, the encloses() function is supported, and works as expected, i.e.
55
for the shape defined by this hull (view it in TOPPView) it answers whether the point is inside the shape.
56
However, once you store the hull in featureXML and load it again, the encloses() function is not supported any longer, because
57
the old convex hulls did not save min&max for each scan.
58
(to support encloses() at least for the new hulls, one would need to check if there exists a min&max value for each scan
59
--> then the query would be valid and the inner representation can be filled. Old featureXML's are not supported in any case.)
61
The outer hullpoints can be queried by getHullPoints().
63
@improvement For chromatograms we could postprocess the input and remove points in intermediate RT scans,
64
which are currently reported but make the number of points rather large.
66
@ingroup Datastructures
68
class OPENMS_DLLAPI ConvexHull2D
71
typedef DPosition<2> PointType;
72
typedef std::vector< PointType > PointArrayType;
73
typedef PointArrayType::size_type SizeType;
74
typedef PointArrayType::const_iterator PointArrayTypeConstIterator;
76
typedef Map<PointType::CoordinateType, DBoundingBox<1> > HullPointType;
78
/// default constructor
81
/// assignment operator
82
ConvexHull2D& operator=(const ConvexHull2D& rhs);
85
bool operator==(const ConvexHull2D& rhs) const;
87
/// removes all points
90
/// accessor for the outer points
91
const PointArrayType& getHullPoints() const;
93
/// accessor for the outer(!) points (no checking is performed if this is actually a convex hull)
94
void setHullPoints(const PointArrayType& points);
96
/// returns the bounding box of the feature hull points
97
DBoundingBox<2> getBoundingBox() const;
99
/// adds a point to the hull if it is not already contained. Returns if the point was added.
100
/// this will trigger recomputation of the outer hull points (thus points set with setHullPoints() will be lost)
101
bool addPoint(const PointType& point);
103
/// adds points to the hull if it is not already contained.
104
/// this will trigger recomputation of the outer hull points (thus points set with setHullPoints() will be lost)
105
void addPoints(const PointArrayType& points);
108
@brief Allows to reduce the disk/memory footprint of a hull
110
Removes points from the hull which lie on a straight line and do not contribute to
111
the hulls shape. Should be called before saving to disk.
113
Example: Consider a series of 3 scans with the same dimension in m/z. After calling
114
compress, the points from the second scan will be removed, since they do not contribute
117
@returns Number of removed scans
122
@brief Expand a convex hull to its bounding box.
124
This reduces the size of a convex hull to four points, its
125
bounding box, thus reducing size when storing the information.
126
Note that this leads to an enclosed area that can be significantly
127
larger than the original convex hull.
129
void expandToBoundingBox();
133
@brief returns if the @p point lies in the feature hull
135
This function is only supported if the hull is created using addPoint() or addPoints(),
136
but not then suing setHullPoints().
137
If you require the latter functionality, then augment this function.
139
@throws Exception::NotImplemented if only hull points (outer_points_), but no internal structure (map_points_) is given
141
bool encloses(const PointType& point) const;
144
/// internal structure maintaining the hull and enabling queries to encloses()
145
HullPointType map_points_;
147
/// just the list of points of the outer hull (derived from map_points_ or given by user)
148
mutable PointArrayType outer_points_;
151
} // namespace OPENMS
153
#endif // OPENMS_DATASTRUCTURES_DCONVEXHULL_H