~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/DATASTRUCTURES/ConvexHull2D.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework 
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Stephan Aiche$
 
25
// $Authors: Marc Sturm, Chris Bielow $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#ifndef OPENMS_DATASTRUCTURES_CONVEXHULL2D_H
 
29
#define OPENMS_DATASTRUCTURES_CONVEXHULL2D_H
 
30
 
 
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>
 
36
 
 
37
#include <vector>
 
38
 
 
39
 
 
40
 
 
41
namespace OpenMS
 
42
{
 
43
        /**     
 
44
                @brief A 2-dimensional hull representation in [counter]clockwise direction - depending on axis labelling.
 
45
 
 
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,
 
49
                and will always work.
 
50
                
 
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.)
 
60
 
 
61
                The outer hullpoints can be queried by getHullPoints().
 
62
 
 
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.
 
65
                
 
66
                @ingroup Datastructures
 
67
        */
 
68
        class OPENMS_DLLAPI ConvexHull2D
 
69
        {
 
70
                public:
 
71
                        typedef DPosition<2> PointType;
 
72
                        typedef std::vector< PointType > PointArrayType;
 
73
                        typedef PointArrayType::size_type SizeType;
 
74
                        typedef PointArrayType::const_iterator PointArrayTypeConstIterator;
 
75
 
 
76
                        typedef Map<PointType::CoordinateType, DBoundingBox<1> > HullPointType;
 
77
 
 
78
                        /// default constructor
 
79
                        ConvexHull2D();
 
80
                        
 
81
                        /// assignment operator
 
82
                        ConvexHull2D& operator=(const ConvexHull2D& rhs);
 
83
 
 
84
                        /// equality operator
 
85
                        bool operator==(const ConvexHull2D& rhs) const;
 
86
                        
 
87
                        /// removes all points
 
88
                        void clear();
 
89
 
 
90
                        /// accessor for the outer points
 
91
                        const PointArrayType& getHullPoints() const;
 
92
 
 
93
                        /// accessor for the outer(!) points (no checking is performed if this is actually a convex hull)
 
94
                        void setHullPoints(const PointArrayType& points);
 
95
                        
 
96
                        /// returns the bounding box of the feature hull points
 
97
                        DBoundingBox<2> getBoundingBox() const;
 
98
                        
 
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);
 
102
 
 
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);
 
106
 
 
107
      /**
 
108
        @brief Allows to reduce the disk/memory footprint of a hull
 
109
 
 
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.
 
112
        
 
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
 
115
        to the convex hull.
 
116
 
 
117
        @returns Number of removed scans
 
118
      **/
 
119
      Size compress();
 
120
 
 
121
                        /**
 
122
                                @brief Expand a convex hull to its bounding box.
 
123
                
 
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.
 
128
                        **/
 
129
                        void expandToBoundingBox();
 
130
                
 
131
                        
 
132
      /** 
 
133
                                @brief returns if the @p point lies in the feature hull
 
134
                        
 
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.
 
138
 
 
139
                                @throws Exception::NotImplemented if only hull points (outer_points_), but no internal structure (map_points_) is given
 
140
                        **/
 
141
                        bool encloses(const PointType& point) const;
 
142
                        
 
143
                protected:
 
144
                        /// internal structure maintaining the hull and enabling queries to encloses()
 
145
                        HullPointType map_points_;
 
146
 
 
147
                        /// just the list of points of the outer hull (derived from map_points_ or given by user)
 
148
                        mutable PointArrayType outer_points_;
 
149
 
 
150
        };
 
151
} // namespace OPENMS
 
152
 
 
153
#endif // OPENMS_DATASTRUCTURES_DCONVEXHULL_H