OpenWalnut  1.4.0
WHistogram2D.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WHISTOGRAM2D_H
26 #define WHISTOGRAM2D_H
27 
28 #include <utility>
29 
30 #ifndef Q_MOC_RUN
31 #include <boost/array.hpp>
32 #endif
33 
34 #include <Eigen/Core>
35 
36 #include <core/graphicsEngine/WGETexture.h>
37 
38 #include "WHistogramND.h"
39 
40 /**
41  * Uniform two dimensional histogram for double values. The terms bin and bucket are interchangeable. For the first dimensional part often the
42  * analouge X-dimension is used and for the second, Y-dimension.
43  */
44 class WHistogram2D : public WHistogramND< 2 > // NOLINT
45 {
46 public:
47  /**
48  * Convenience type for a shared_ptr on this type.
49  */
50  typedef boost::shared_ptr< WHistogram2D > SPtr;
51 
52  /**
53  * Creates a two dimensional histogram field, bounded by the given limits, containing the demanded number of buckets in each dimension.
54  *
55  * \param minX Minimal bound for X-values.
56  * \param maxX Maximal bound for X-values.
57  * \param minY Minimal bound for Y-values.
58  * \param maxY Maximal bound for Y-values.
59  * \param bucketsX Number of buckets in X direction.
60  * \param bucketsY Number of buckets in Y direction.
61  */
62  WHistogram2D( double minX, double maxX, double minY, double maxY, size_t bucketsX, size_t bucketsY );
63 
64  /**
65  * Cleans up!
66  */
67  ~WHistogram2D();
68 
69  /**
70  * Copy constructor, performing a deep copy.
71  *
72  * \param other The other instance to copy from.
73  */
74  WHistogram2D( const WHistogram2D& other );
75 
76  /**
77  * Get the count of the specified bucket.
78  *
79  * \param index in each dimension
80  *
81  * \return elements in the bucket.
82  */
83  virtual size_t operator()( SizeArray index ) const;
84 
85  /**
86  * Convenience function to easier access the buckets for 2D.
87  *
88  * \param i X-index
89  * \param j Y-index
90  *
91  * \return elements in the bucket.
92  */
93  virtual size_t operator()( size_t i, size_t j ) const;
94 
95  /**
96  * Return the measure of one specific bucket. For one dimensional Histograms this is the width of the bucket, for two
97  * dimensions this is the area, for three dims this is the volume, etc.
98  *
99  * \param index the measure for this bucket is queried.
100  *
101  * \return the size of a bucket.
102  */
103  virtual double getBucketSize( SizeArray index ) const;
104 
105  /**
106  * Returns the actual (right-open) interval in each dimension associated with the given index.
107  *
108  * \param index for this bucket the intervals will be returned
109  *
110  * \return the right-open interval in each dimension.
111  */
112  virtual boost::array< std::pair< double, double >, 2 > getIntervalForIndex( SizeArray index ) const;
113 
114  /**
115  * Given a value the corresponding bucket is determined and incremented by one.
116  *
117  * \param values The value to count into specific bucket.
118  */
119  void insert( TArray values );
120 
121  /**
122  * Shorthand to overloaded insert function where each dimension can be overhanded separately.
123  * \see insert()
124  * \param x value for the first dimension.
125  * \param y value for the second dimension.
126  */
127  void insert( double x, double y );
128 
129  /**
130  * Copy-convert this into a texture.
131  *
132  * \return \c osg::ref_ptr to the two-dimensional texture.
133  */
135 
136  /**
137  * Copy-convert this into a spherical texture. \e Spherical means hereby, that buckets representing areas near the poles have scaled counters.
138  *
139  * \return \c osg::ref_ptr to the two-dimensional spherical texture.
140  */
142 
143 protected:
144 private:
145  /**
146  * Shorthand for data structure storing bucket information. In 2D this is a matrix.
147  */
148  typedef Eigen::Matrix< size_t, Eigen::Dynamic, Eigen::Dynamic > BinType;
149 
150  /**
151  * Storing the bucket counts, how often a value occurs.
152  */
153  BinType m_bins;
154 
155  /**
156  * For each dimension this stores the uniform interval width.
157  */
159 };
160 
161 #endif // WHISTOGRAM2D_H
This template should handly arbitrary N-dimensional histograms.
Definition: WHistogramND.h:44
WHistogram2D(double minX, double maxX, double minY, double maxY, size_t bucketsX, size_t bucketsY)
Creates a two dimensional histogram field, bounded by the given limits, containing the demanded numbe...
Uniform two dimensional histogram for double values.
Definition: WHistogram2D.h:44
WGETexture2D::RPtr getTexture()
Copy-convert this into a texture.
virtual boost::array< std::pair< double, double >, 2 > getIntervalForIndex(SizeArray index) const
Returns the actual (right-open) interval in each dimension associated with the given index...
BinType m_bins
Storing the bucket counts, how often a value occurs.
Definition: WHistogram2D.h:153
WGETexture2D::RPtr getSphereTexture()
Copy-convert this into a spherical texture.
virtual double getBucketSize(SizeArray index) const
Return the measure of one specific bucket.
Eigen::Matrix< size_t, Eigen::Dynamic, Eigen::Dynamic > BinType
Shorthand for data structure storing bucket information.
Definition: WHistogram2D.h:148
~WHistogram2D()
Cleans up!
osg::ref_ptr< WGETexture< TextureType > > RPtr
Convenience type for OSG reference pointer on WGETextures.
Definition: WGETexture.h:61
boost::shared_ptr< WHistogram2D > SPtr
Convenience type for a shared_ptr on this type.
Definition: WHistogram2D.h:50
boost::array< double, N > TArray
Shorthand for N-dimensional values of type T.
Definition: WHistogramND.h:55
void insert(TArray values)
Given a value the corresponding bucket is determined and incremented by one.
boost::array< size_t, N > SizeArray
Shorthand for N-dimensional indices, counter, etc.
Definition: WHistogramND.h:50
TArray m_intervalWidth
For each dimension this stores the uniform interval width.
Definition: WHistogram2D.h:158
virtual size_t operator()(SizeArray index) const
Get the count of the specified bucket.