Commit 16916fa0 authored by Alexander Wiebel's avatar Alexander Wiebel

[ADD #182] WScalarDataSet provides maximum and mimimum now

parent 0d9de569
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include "../common/WAssert.h"
#include "../common/WLimits.h"
#include "WDataSetSingle.h"
#include "WDataSetScalar.h"
......@@ -36,8 +37,46 @@ 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." );
double max = wlimits::MIN_DOUBLE;
double min = wlimits::MAX_DOUBLE;
for( size_t i = 0; i < newValueSet->size(); ++i )
{
double tmp = newValueSet->getScalarDouble( i );
max = max < tmp ? tmp : max;
min = min > tmp ? tmp : min;
}
m_maximum = max;
m_minimum = min;
}
WDataSetScalar::WDataSetScalar( boost::shared_ptr< WValueSetBase > newValueSet,
boost::shared_ptr< WGrid > newGrid,
double max,
double min )
: WDataSetSingle( newValueSet, newGrid )
{
WAssert( newValueSet, "No value set given." );
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." );
WAssert( max >= min, "max must be at least as large as min." );
m_maximum = max;
m_minimum = min;
}
WDataSetScalar::~WDataSetScalar()
{
}
double WDataSetScalar::getMax() const
{
return m_maximum;
}
double WDataSetScalar::getMin() const
{
return m_minimum;
}
......@@ -37,6 +37,7 @@ public:
/**
* Constructs an instance out of an appropriate value set and a grid.
* Computes the maximum an minimum values stored as member variables.
*
* \param newValueSet the scalar value set to use
* \param newGrid the grid which maps world space to the value set
......@@ -44,13 +45,39 @@ public:
WDataSetScalar( boost::shared_ptr< WValueSetBase > newValueSet,
boost::shared_ptr< WGrid > newGrid );
/**
* Constructs an instance out of an appropriate value set and a grid.
* Computes the maximum an minimum values stored as member variables.
*
* \param newValueSet the scalar value set to use
* \param newGrid the grid which maps world space to the value set
* \param min a priori known smallest scalar value in newValueSet
* \param max a priori known largest scalar value in newValueSet
*/
WDataSetScalar( boost::shared_ptr< WValueSetBase > newValueSet,
boost::shared_ptr< WGrid > newGrid,
double min,
double max );
/**
* Destroys this DataSet instance
*/
virtual ~WDataSetScalar();
/**
* Returns the largest of the scalars stored in the data set
*/
double getMax() const;
/**
* Returns the smallest of the scalars stored in the data set
*/
double getMin() const;
protected:
private:
double m_maximum; //!< Largest scalar of data set.
double m_minimum; //!< Smallest scalar of data set.
};
#endif // WDATASETSCALAR_H
......@@ -98,6 +98,15 @@ public:
return m_data[i];
}
/**
* \param i id of the scalar to retrieve
* \return The i-th scalar stored in this value set. There are rawSize() such scalars.
*/
virtual double getScalarDouble( size_t i ) const
{
return static_cast< double >( m_data[i] );
}
/**
* Sometimes we need raw access to the data array, for e.g. OpenGL.
*/
......
......@@ -60,6 +60,12 @@ public:
*/
virtual size_t rawSize() const = 0;
/**
* \param i id of the scalar to retrieve
* \return The i-th scalar stored in this value set. There are rawSize() such scalars.
*/
virtual double getScalarDouble( size_t i ) const = 0;
/**
* \return Dimension of the values in this ValueSet
*/
......
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