27 #include <core/common/math/WMath.h>
28 #include <core/graphicsEngine/WGETexture.h>
30 #include "WHistogram2D.h"
37 TArray min = {{ minX, minY }};
38 TArray max = {{ maxX, maxY }};
39 SizeArray buckets = {{ bucketsX, bucketsY }};
40 reset( min, max, buckets );
42 m_intervalWidth[0] = std::abs( maxX - minX ) /
static_cast< double >( bucketsX );
43 m_intervalWidth[1] = std::abs( maxY - minY ) /
static_cast< double >( bucketsY );
44 m_bins = BinType::Zero( bucketsX, bucketsY );
59 return m_bins( index[0], index[1] );
75 boost::array< std::pair< double, double >, 2 > result;
77 for(
size_t i = 0; i < 2; ++i )
88 if( values[0] >
m_max[0] || values[0] <
m_min[0] || values[1] >
m_max[1] || values[1] <
m_min[1] )
90 wlog::warn(
"WHistogram2D" ) << std::scientific << std::setprecision( 16 ) <<
"Inserted value out of bounds, thread: ("
91 << values[0] <<
"," << values[1] <<
") whereas min,max are: dim0: (" <<
m_min[0] <<
"," <<
m_max[0] <<
") "
92 <<
"dim1:(" <<
m_min[1] <<
"," <<
m_max[1] <<
")";
98 for(
size_t i = 0; i < 2; ++i )
114 m_bins( coord[0], coord[1] )++;
119 TArray values = {{ x, y }};
125 osg::ref_ptr< osg::Image > image =
new osg::Image();
130 for(
size_t j = 0; j < imageHeight; ++j )
132 for(
size_t i = 0; i < imageWidth; ++i )
134 if(
m_bins( i, j ) > maxCount )
136 maxCount =
static_cast< float >(
m_bins( i, j ) );
141 image->allocateImage( imageWidth, imageHeight, 1, GL_RED, GL_FLOAT );
142 image->setInternalTextureFormat( GL_RED );
143 float* data =
reinterpret_cast< float*
>( image->data() );
145 for(
size_t j = 0; j < imageHeight; ++j )
147 for(
size_t i = 0; i < imageWidth; ++i )
149 data[i + j * imageWidth] =
static_cast< float >(
m_bins( i, j ) ) / maxCount;
161 double calcAreaScale(
const double bucket,
const size_t j )
163 double theta = pi() - ( j * bucket + ( bucket / 2.0 ) );
164 return 1.0 / sin( theta );
170 osg::ref_ptr< osg::Image > image =
new osg::Image();
173 double maxCount = 0.0;
174 const double bucket = pi() /
static_cast< double >( imageHeight );
175 double areaScale = 0.0;
177 for(
size_t j = 0; j < imageHeight; ++j )
179 areaScale = calcAreaScale( bucket, j );
180 for(
size_t i = 0; i < imageWidth; ++i )
182 if( areaScale *
m_bins( i, j ) > maxCount )
184 maxCount = areaScale *
static_cast< double >(
m_bins( i, j ) );
189 image->allocateImage( imageWidth, imageHeight, 1, GL_RED, GL_FLOAT );
190 image->setInternalTextureFormat( GL_RED );
191 float* data =
reinterpret_cast< float*
>( image->data() );
193 for(
size_t j = 0; j < imageHeight; ++j )
195 areaScale = calcAreaScale( bucket, j );
196 for(
size_t i = 0; i < imageWidth; ++i )
198 data[i + j * imageWidth] = areaScale *
static_cast< double >(
m_bins( i, j ) ) / maxCount;
This calls serves a simple purpose: have a texture and its scaling information together which allows ...
osg::ref_ptr< WGETexture< TextureType > > RPtr
Convenience type for OSG reference pointer on WGETextures.
Uniform two dimensional histogram for double values.
virtual size_t operator()(SizeArray index) const
Get the count of the specified bucket.
BinType m_bins
Storing the bucket counts, how often a value occurs.
~WHistogram2D()
Cleans up!
WGETexture2D::RPtr getTexture()
Copy-convert this into a texture.
TArray m_intervalWidth
For each dimension this stores the uniform interval width.
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...
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.
void reset(TArray min, TArray max, SizeArray buckets)
Initializes all members.
SizeArray m_buckets
The number of buckets.
boost::array< double, N > TArray
Shorthand for N-dimensional values of type T.
TArray m_min
The smallest value in each dimension.
TArray m_max
The biggest value in each dimension.
boost::array< size_t, N > SizeArray
Shorthand for N-dimensional indices, counter, etc.
const double DBL_EPS
Smallest double such: 1.0 + DBL_EPS == 1.0 is still true.
WStreamedLogger warn(const std::string &source)
Logging a warning message.