Commit ee4c22e9 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - now multiple histograms can be cached in WDataSetSingle once they have been requested.

parent 7e47022c
......@@ -43,9 +43,6 @@ WDataSetScalar::WDataSetScalar( boost::shared_ptr< WValueSetBase > newValueSet,
WAssert( newGrid, "No grid given." );
WAssert( newValueSet->size() == newGrid->size(), "Number of values unequal number of positions in grid." );
WAssert( newValueSet->order() == 0, "The value set does not contain scalars." );
// the histogram gets calculated on demand
m_histogram = boost::shared_ptr< WValueSetHistogram >();
}
WDataSetScalar::WDataSetScalar()
......@@ -138,16 +135,18 @@ double WDataSetScalar::getValueAt( int x, int y, int z ) const
return WDataSetSingle::getValueAt( id );
}
boost::shared_ptr< const WValueSetHistogram > WDataSetScalar::getHistogram()
boost::shared_ptr< const WValueSetHistogram > WDataSetScalar::getHistogram( size_t buckets )
{
if ( m_histogram )
boost::lock_guard<boost::mutex> lock( m_histogramLock );
if ( m_histograms.count( buckets ) != 0 )
{
return m_histogram;
return m_histograms[ buckets ];
}
boost::lock_guard<boost::mutex> lock( m_histogramLock );
m_histogram = boost::shared_ptr< WValueSetHistogram >( new WValueSetHistogram( m_valueSet ) );
// create if not yet existing
m_histograms[ buckets ] = boost::shared_ptr< WValueSetHistogram >( new WValueSetHistogram( m_valueSet, buckets ) );
return m_histogram;
return m_histograms[ buckets ];
}
......@@ -70,11 +70,15 @@ public:
double getMin() const;
/**
* Returns the histogram of this dataset's valueset. If it does not exist yet, it will be created.
* Returns the histogram of this dataset's valueset. If it does not exist yet, it will be created and cached. It does NOT make use of the
* WValueSetHistogram down scaling feature even though the number of buckets might be lower than the default as the down scaling might
* introduce errors. To use down-scaling, grab the default histogram and call WValueSetHistogram( getHistogram(), buckets ) manually.
*
* \param buckets the number of buckets inside the histogram.
*
* \return the histogram.
*/
boost::shared_ptr< const WValueSetHistogram > getHistogram();
boost::shared_ptr< const WValueSetHistogram > getHistogram( size_t buckets = 1000 );
/**
* Interpolate the value fo the valueset at the given position.
......@@ -124,9 +128,9 @@ protected:
private:
/**
* The histogram for later use.
* The histograms for later use. Each histogram for a requested bucket count gets cached.
**/
boost::shared_ptr< WValueSetHistogram > m_histogram;
std::map< size_t, boost::shared_ptr< WValueSetHistogram > > m_histograms;
/**
* The lock used for securely creating m_histogram on demand.
......
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