Commit f79d06cf authored by cornimueller's avatar cornimueller
Browse files

[FIX] Fixed crashing of the EEG view module when trying to display values at invalid time positions

parent fa3d3d9d
......@@ -123,7 +123,7 @@ boost::shared_ptr< WEEGValueMatrix > WPagerEEGLibeep::getValues( std::size_t seg
{
std::ostringstream stream;
stream << "Could not read sample number " << start + length - 1 << " of file " << m_fileName
<< ", it has only " << m_nbSamples << " samples";
<< ", it only has " << m_nbSamples << " samples";
throw WOutOfBounds( stream.str() );
}
......
......@@ -68,12 +68,17 @@ void WLineStripCallback::update( osg::NodeVisitor* /*nv*/, osg::Drawable* drawab
osg::Geometry* geometry = static_cast< osg::Geometry* >( drawable );
if( geometry )
{
const std::size_t startSample = timePos * m_samplingRate;
const std::size_t endSample = std::ceil( ( timePos + timeRange ) * m_samplingRate ) + 1;
const std::size_t currentStartSample = m_currentTimePos * m_samplingRate;
const std::size_t nbSamples = m_segment->getNumberOfSamples();
const std::size_t startSample = clampToRange( timePos * m_samplingRate, 0u, nbSamples - 1u );
const std::size_t endSample = clampToRange( std::ceil( ( timePos + timeRange ) * m_samplingRate ) + 1.0,
startSample,
nbSamples );
const std::size_t currentStartSample = clampToRange( m_currentTimePos * m_samplingRate, 0u, nbSamples - 1u );
const std::size_t currentEndSample = ( 0.0 <= m_currentTimeRange ) ?
std::ceil( ( m_currentTimePos + m_currentTimeRange ) * m_samplingRate ) + 1 :
currentStartSample;
clampToRange( std::ceil( ( m_currentTimePos + m_currentTimeRange ) * m_samplingRate ) + 1.0,
currentStartSample,
nbSamples ) :
currentStartSample;
osg::Vec3Array* vertices = new osg::Vec3Array();
vertices->reserve( endSample - startSample );
......@@ -125,3 +130,18 @@ void WLineStripCallback::update( osg::NodeVisitor* /*nv*/, osg::Drawable* drawab
m_currentTimeRange = timeRange;
}
}
std::size_t WLineStripCallback::clampToRange( double value, std::size_t min, std::size_t max ) const
{
std::size_t out = ( value > 0.0 ) ? value : 0u;
if( out < min )
{
out = min;
}
else if( max < out )
{
out = max;
}
return out;
}
......@@ -106,6 +106,17 @@ private:
* sampling rate used by the recording
*/
double m_samplingRate;
/**
* Convert the given double value to std::size_t and clamp it into the given
* range
*
* \param value value to convert
* \param min minimum of the valid range
* \param max maximum of the valid range
* \return converted value
*/
std::size_t clampToRange( double value, std::size_t min, std::size_t max ) const;
};
#endif // WLINESTRIPCALLBACK_H
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