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

[CHANGE] Fixing feature regression in interpolate, now supporting a bool...

[CHANGE] Fixing feature regression in interpolate, now supporting a bool indicates the success again
parent b5f0d220
...@@ -102,7 +102,7 @@ boost::shared_ptr< WPrototyped > WDataSetScalar::getPrototype() ...@@ -102,7 +102,7 @@ boost::shared_ptr< WPrototyped > WDataSetScalar::getPrototype()
return m_prototype; return m_prototype;
} }
double WDataSetScalar::interpolate( wmath::WPosition pos ) double WDataSetScalar::interpolate( const wmath::WPosition& pos, bool* success )
{ {
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid ); boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
...@@ -112,16 +112,23 @@ double WDataSetScalar::interpolate( wmath::WPosition pos ) ...@@ -112,16 +112,23 @@ double WDataSetScalar::interpolate( wmath::WPosition pos )
throw WException( std::string( "This data set has a grid whose type is not yet supported for interpolation." ) ); throw WException( std::string( "This data set has a grid whose type is not yet supported for interpolation." ) );
} }
// TODO(wiebel): change this to eassert. // TODO(wiebel): change this to eassert.
if( grid->getTransformationMatrix() != wmath::WMatrix<double>( 4, 4 ).makeIdentity() ) // if( grid->getTransformationMatrix() != wmath::WMatrix<double>( 4, 4 ).makeIdentity() )
{ // {
throw WException( std::string( "Only feasible for untranslated grid so far." ) ); // throw WException( std::string( "Only feasible for untranslated grid so far." ) );
} // }
// TODO(wiebel): change this to eassert. // TODO(wiebel): change this to eassert.
if( !( m_valueSet->order() == 0 && m_valueSet->dimension() == 1 ) ) if( !( m_valueSet->order() == 0 && m_valueSet->dimension() == 1 ) )
{ {
throw WException( std::string( "Only implemented for scalar values so far." ) ); throw WException( std::string( "Only implemented for scalar values so far." ) );
} }
*success = grid->encloses( pos );
if( !*success )
{
return 0;
}
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) ); std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] ); wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] );
...@@ -153,5 +160,7 @@ double WDataSetScalar::interpolate( wmath::WPosition pos ) ...@@ -153,5 +160,7 @@ double WDataSetScalar::interpolate( wmath::WPosition pos )
{ {
result += h[i] * getValueAt( vertexIds[i] ); result += h[i] * getValueAt( vertexIds[i] );
} }
*success = true;
return result; return result;
} }
...@@ -80,14 +80,16 @@ public: ...@@ -80,14 +80,16 @@ public:
double getMin() const; double getMin() const;
/** /**
* Interpolate the value fo the valueset at the given position * Interpolate the value fo the valueset at the given position.
* If interpolation fails, the success parameter will be false
* and the value returned zero.
* *
* \param pos The position for wich we would like to get a value. * \param pos The position for wich we would like to get a value.
* \param success indicates whether the interpolation was successful
* *
* \return Scalar value for that given position * \return Scalar value for that given position
*/ */
double interpolate( wmath::WPosition pos ); double interpolate( const wmath::WPosition& pos, bool* success );
/** /**
* Returns a prototype instantiated with the true type of the deriving class. * Returns a prototype instantiated with the true type of the deriving class.
......
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