Commit a9bf2594 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] Texture generation for 2D Histograms

parent 6fc26f74
......@@ -24,6 +24,8 @@
#include <utility>
#include <osg/Texture2D>
#include "WAssert.h"
#include "WHistogram2D.h"
#include "WLimits.h"
......@@ -118,3 +120,35 @@ void WHistogram2D::insert( double x, double y )
insert( values );
}
osg::ref_ptr< osg::Texture2D > WHistogram2D::getTexture()
{
osg::ref_ptr< osg::Image > image = new osg::Image();
size_t imageWidth = m_buckets[0];
size_t imageHeight = m_buckets[1];
//get max bin for scaling
size_t maxCount = 0;
for( int j = 0; j < imageHeight; j++)
{
for (int i = 0; i < imageWidth; i++)
{
if(m_bins(i, j) > maxCount)
{
maxCount = m_bins(i, j);
}
}
}
// allocate the image data, size x 1 x 1 with 4 rgba floats - equivalent to a Vec4!
image->allocateImage( imageWidth, imageHeight, 1, GL_RED, GL_FLOAT );
image->setInternalTextureFormat( GL_RED );
float* data = reinterpret_cast< float* >( image->data() );
for( int j = 0; j < imageHeight; j++)
{
for (int i = 0; i < imageWidth; i++)
{
data[i + j * imageWidth] = (float)m_bins(i, j) / (float)maxCount;
}
}
return new osg::Texture2D( image );
}
......@@ -31,6 +31,8 @@
#include <Eigen/Core>
#include <osg/Texture2D>
#include "WHistogramND.h"
/**
......@@ -40,6 +42,12 @@
class WHistogram2D : public WHistogramND< 2 > // NOLINT
{
public:
/**
* Convenience type for a shared_ptr on this type.
*/
typedef boost::shared_ptr< WHistogram2D > SPtr;
/**
* Creates a two dimensional histogram field, bounded by the given limits, containing the demanded number of buckets in each dimension.
*
......@@ -117,6 +125,13 @@ public:
*/
void insert( double x, double y );
/**
* Copy-convert this into an OSG texture.
*
* \return osg::Texture2D representing this histogram.
*/
osg::ref_ptr< osg::Texture2D > getTexture();
protected:
private:
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment