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