OpenWalnut  1.5.0dev
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 <memory>
29 #include <utility>
30 
31 #include <Eigen/Core>
32 #include <boost/array.hpp>
33 #include <core/graphicsEngine/WGETexture.h>
34 
35 #include "WHistogramND.h"
36 
37 /**
38  * Uniform two dimensional histogram for double values. The terms bin and bucket are interchangeable. For the first dimensional part often the
39  * analouge X-dimension is used and for the second, Y-dimension.
40  */
41 class WHistogram2D : public WHistogramND< 2 > // NOLINT
42 {
43 public:
44  /**
45  * Convenience type for a shared_ptr on this type.
46  */
47  typedef std::shared_ptr< WHistogram2D > SPtr;
48 
49  /**
50  * Creates a two dimensional histogram field, bounded by the given limits, containing the demanded number of buckets in each dimension.
51  *
52  * \param minX Minimal bound for X-values.
53  * \param maxX Maximal bound for X-values.
54  * \param minY Minimal bound for Y-values.
55  * \param maxY Maximal bound for Y-values.
56  * \param bucketsX Number of buckets in X direction.
57  * \param bucketsY Number of buckets in Y direction.
58  */
59  WHistogram2D( double minX, double maxX, double minY, double maxY, size_t bucketsX, size_t bucketsY );
60 
61  /**
62  * Cleans up!
63  */
64  ~WHistogram2D();
65 
66  /**
67  * Copy constructor, performing a deep copy.
68  *
69  * \param other The other instance to copy from.
70  */
71  WHistogram2D( const WHistogram2D& other );
72 
73  /**
74  * Get the count of the specified bucket.
75  *
76  * \param index in each dimension
77  *
78  * \return elements in the bucket.
79  */
80  virtual size_t operator()( SizeArray index ) const;
81 
82  /**
83  * Convenience function to easier access the buckets for 2D.
84  *
85  * \param i X-index
86  * \param j Y-index
87  *
88  * \return elements in the bucket.
89  */
90  virtual size_t operator()( size_t i, size_t j ) const;
91 
92  /**
93  * Return the measure of one specific bucket. For one dimensional Histograms this is the width of the bucket, for two
94  * dimensions this is the area, for three dims this is the volume, etc.
95  *
96  * \param index the measure for this bucket is queried.
97  *
98  * \return the size of a bucket.
99  */
100  virtual double getBucketSize( SizeArray index ) const;
101 
102  /**
103  * Returns the actual (right-open) interval in each dimension associated with the given index.
104  *
105  * \param index for this bucket the intervals will be returned
106  *
107  * \return the right-open interval in each dimension.
108  */
109  virtual boost::array< std::pair< double, double >, 2 > getIntervalForIndex( SizeArray index ) const;
110 
111  /**
112  * Given a value the corresponding bucket is determined and incremented by one.
113  *
114  * \param values The value to count into specific bucket.
115  */
116  void insert( TArray values );
117 
118  /**
119  * Shorthand to overloaded insert function where each dimension can be overhanded separately.
120  * \see insert()
121  * \param x value for the first dimension.
122  * \param y value for the second dimension.
123  */
124  void insert( double x, double y );
125 
126  /**
127  * Copy-convert this into a texture.
128  *
129  * \return \c osg::ref_ptr to the two-dimensional texture.
130  */
132 
133  /**
134  * Copy-convert this into a spherical texture. \e Spherical means hereby, that buckets representing areas near the poles have scaled counters.
135  *
136  * \return \c osg::ref_ptr to the two-dimensional spherical texture.
137  */
139 
140 protected:
141 private:
142  /**
143  * Shorthand for data structure storing bucket information. In 2D this is a matrix.
144  */
145  typedef Eigen::Matrix< size_t, Eigen::Dynamic, Eigen::Dynamic > BinType;
146 
147  /**
148  * Storing the bucket counts, how often a value occurs.
149  */
151 
152  /**
153  * For each dimension this stores the uniform interval width.
154  */
156 };
157 
158 #endif // WHISTOGRAM2D_H
osg::ref_ptr< WGETexture< TextureType > > RPtr
Convenience type for OSG reference pointer on WGETextures.
Definition: WGETexture.h:58
Uniform two dimensional histogram for double values.
Definition: WHistogram2D.h:42
virtual size_t operator()(SizeArray index) const
Get the count of the specified bucket.
std::shared_ptr< WHistogram2D > SPtr
Convenience type for a shared_ptr on this type.
Definition: WHistogram2D.h:47
BinType m_bins
Storing the bucket counts, how often a value occurs.
Definition: WHistogram2D.h:150
~WHistogram2D()
Cleans up!
WGETexture2D::RPtr getTexture()
Copy-convert this into a texture.
TArray m_intervalWidth
For each dimension this stores the uniform interval width.
Definition: WHistogram2D.h:155
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.
void insert(TArray values)
Given a value the corresponding bucket is determined and incremented by one.
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...
Eigen::Matrix< size_t, Eigen::Dynamic, Eigen::Dynamic > BinType
Shorthand for data structure storing bucket information.
Definition: WHistogram2D.h:145
WGETexture2D::RPtr getSphereTexture()
Copy-convert this into a spherical texture.
virtual double getBucketSize(SizeArray index) const
Return the measure of one specific bucket.
This template should handly arbitrary N-dimensional histograms.
Definition: WHistogramND.h:43
boost::array< double, N > TArray
Shorthand for N-dimensional values of type T.
Definition: WHistogramND.h:53
boost::array< size_t, N > SizeArray
Shorthand for N-dimensional indices, counter, etc.
Definition: WHistogramND.h:48