Commit 7b646da1 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD #764] Function for linear texture for 2D histogram

parent f1c0587c
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <utility>
#include <cmath>
#include <algorithm>
#include <vector>
......@@ -218,7 +219,39 @@ unsigned char* WHistogram2D::getRawTexture()
{
for( size_t j = 0; j < imageHeight; ++j )
{
// logarithmic bin count. To get linear scale, remove the log()/log()
// FIXME: use 8-bit grayscale instead of RGBA
// ( outcome is rotated when using QImage::Format::Indexed8, thats why we use RGBA here )
data[ 4 * i * imageWidth + 4 * j + 0 ] = static_cast< unsigned char >( 255. * m_bins( i, j ) / maxCount );
data[ 4 * i * imageWidth + 4 * j + 1 ] = static_cast< unsigned char >( 255. * m_bins( i, j ) / maxCount );
data[ 4 * i * imageWidth + 4 * j + 2 ] = static_cast< unsigned char >( 255. * m_bins( i, j ) / maxCount );
data[ 4 * i * imageWidth + 4 * j + 3 ] = static_cast< unsigned char >( 255. );
}
}
return data;
}
unsigned char* WHistogram2D::getRawTextureLog()
{
size_t imageWidth = m_buckets[ 0 ];
size_t imageHeight = m_buckets[ 1 ];
double maxCount = 0;
for( size_t j = 0; j < imageHeight; ++j ) // get max bin for scaling
{
for( size_t i = 0; i < imageWidth; ++i )
{
if( m_bins( i, j ) > maxCount )
{
maxCount = static_cast< double >( m_bins( i, j ) );
}
}
}
unsigned char * data = new unsigned char[ imageWidth * imageHeight * 4 ]();
for( size_t i = 0; i < imageWidth; ++i )
{
for( size_t j = 0; j < imageHeight; ++j )
{
// FIXME: use 8-bit grayscale instead of RGBA
// ( outcome is rotated when using QImage::Format::Indexed8, thats why we use RGBA here )
data[ 4 * i * imageWidth + 4 * j + 0 ] = static_cast< unsigned char >( 255. * log( m_bins( i, j ) ) / log( maxCount ) );
......@@ -230,6 +263,7 @@ unsigned char* WHistogram2D::getRawTexture()
return data;
}
/**
* Unnamed namespace for helper functions keeping the code DRY as possible.
*/
......@@ -278,4 +312,3 @@ WGETexture2D::RPtr WHistogram2D::getSphereTexture()
return WGETexture2D::RPtr( new WGETexture2D( image ) );
}
......@@ -155,6 +155,13 @@ public:
*/
unsigned char* getRawTexture();
/**
* Copy-convert and logarithmize this into a raw texture as set of RGBA samples.
*
* \return \c return raw texture of the log-version of the histogram
*/
unsigned char* getRawTextureLog();
/**
* Copy-convert this into a spherical texture. \e Spherical means hereby, that buckets representing areas near the poles have scaled counters.
*
......
......@@ -33,7 +33,6 @@
WTransferFunction2DBackground::WTransferFunction2DBackground( QWidget * /*parent*/ ) : BaseClass()
{
//this->setFlag( ItemIsMovable );
setOpacity( 1.0 );
setZValue( -1 );
......@@ -44,7 +43,6 @@ void WTransferFunction2DBackground::setMyPixmap( const QPixmap& newpixmap )
{
if( newpixmap.width() > 0 && newpixmap.height() > 0 )
{
// std::cout << "SET MY PIXMAP" << std::endl;
QTransform m( scene()->sceneRect().width()/( double )newpixmap.width(), 0, 0,
0, scene()->sceneRect().height()/( double )newpixmap.height(), 0,
0, 0, 1 );
......
......@@ -80,7 +80,7 @@ void WTransferFunction2DGUIWidget::setMyBackground()
{
if( background && hist != nullptr )
{
unsigned char * data = hist->getRawTexture();
unsigned char * data = hist->getRawTextureLog();
size_t imageWidth = hist->getBucketsX();
size_t imageHeight = hist->getBucketsY();
......
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