Commit 1e22bb46 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[FIX #347] now getCellId return whether the cell was found in the grid or

not. Upper bounds do not belong to the grid. Finally adapted all dependent
stuff to the new interface.
parent a6163926
......@@ -84,14 +84,16 @@ double WDataSetScalar::interpolate( const wmath::WPosition& pos, bool* success )
WAssert( ( m_valueSet->order() == 0 && m_valueSet->dimension() == 1 ),
"Only implemented for scalar values so far." );
*success = grid->encloses( pos );
bool isInside = true;
size_t cellId = grid->getCellId( pos, &isInside );
if( !*success )
if( !isInside )
{
return 0;
*success = false;
return 0.0;
}
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
std::vector< size_t > vertexIds = grid->getCellVertexIds( cellId );
wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] );
......
......@@ -69,13 +69,17 @@ wmath::WSymmetricSphericalHarmonic WDataSetSphericalHarmonics::interpolate( cons
*success = grid->encloses( pos );
if( !*success )
bool isInside = true;
size_t cellId = grid->getCellId( pos, &isInside );
if( !isInside )
{
*success = false;
return wmath::WSymmetricSphericalHarmonic();
}
// ids of vertices for interpolation
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
std::vector< size_t > vertexIds = grid->getCellVertexIds( cellId );
wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] );
......
......@@ -72,14 +72,15 @@ wmath::WVector3D WDataSetVector::interpolate( const wmath::WPosition& pos, bool
WAssert( ( m_valueSet->order() == 1 && m_valueSet->dimension() == 3 ),
"Only implemented for 3D Vectors so far." );
*success = grid->encloses( pos );
bool isInside = true;
size_t cellId = grid->getCellId( pos, &isInside );
if( !*success )
if( !isInside )
{
return wmath::WVector3D( 0, 0, 0 );
*success = false;
return wmath::WVector3D();
}
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
std::vector< size_t > vertexIds = grid->getCellVertexIds( cellId );
wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] );
......
......@@ -441,15 +441,17 @@ bool WGridRegular3D::isNotRotatedOrSheared() const
return onlyTranslatedOrScaled;
}
size_t WGridRegular3D::getCellId( const wmath::WPosition& pos ) const
size_t WGridRegular3D::getCellId( const wmath::WPosition& pos, bool* success ) const
{
WAssert( isNotRotatedOrSheared(), "Only feasible for grids that are only translated or scaled so far." );
wmath::WPosition posRelativeToOrigin = pos - m_origin;
size_t xCellId = floor( posRelativeToOrigin[0] / m_offsetX );
size_t yCellId = floor( posRelativeToOrigin[1] / m_offsetY );
size_t zCellId = floor( posRelativeToOrigin[2] / m_offsetZ );
double xCellId = floor( posRelativeToOrigin[0] / m_offsetX );
double yCellId = floor( posRelativeToOrigin[1] / m_offsetY );
double zCellId = floor( posRelativeToOrigin[2] / m_offsetZ );
*success = xCellId >= 0 && yCellId >=0 && zCellId >= 0 && xCellId < m_nbPosX - 1 && yCellId < m_nbPosY -1 && zCellId < m_nbPosZ -1;
return xCellId + yCellId * ( m_nbPosX - 1 ) + zCellId * ( m_nbPosX - 1 ) * ( m_nbPosY - 1 );
}
......
......@@ -41,6 +41,8 @@
* A grid that has parallelepiped cells which all have the same proportion. I.e.
* the samples along a single axis are equidistant. The distance of samples may
* vary between axes.
*
* \warning Positions on the upper bounddaries in x, y and z are considered outside the grid.
* \ingroup dataHandler
*/
class WGridRegular3D : public WGrid
......@@ -339,8 +341,9 @@ public:
* Computes the id of the cell containing the position pos.
*
* \param pos The position selecting the cell.
* \param success True if the position pos is inside the grid.
*/
size_t getCellId( const wmath::WPosition& pos ) const;
size_t getCellId( const wmath::WPosition& pos, bool* success ) const;
/**
* Computes the ids of the vertices of a cell given by its id.
......
......@@ -511,8 +511,51 @@ public:
void testGetCellId( void )
{
WGridRegular3D g( 5, 3, 3, 0, 0, 0, 1, 1, 1 );
size_t cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 0.78 ) );
bool isInside = true;
// Test some value
size_t cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 0.78 ), &isInside );
TS_ASSERT_EQUALS( cellId, 7 );
TS_ASSERT_EQUALS( isInside, true );
// Test bounds for X direction
cellId = g.getCellId( wmath::WPosition( 4.0, 1.75, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
cellId = g.getCellId( wmath::WPosition( 4.0 - wlimits::FLT_EPS, 1.75, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 0.0, 1.75, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 0.0 - wlimits::FLT_EPS, 1.75, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
// Test bounds for Y direction
cellId = g.getCellId( wmath::WPosition( 3.3, 2.0, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
cellId = g.getCellId( wmath::WPosition( 3.3, 2.0 - wlimits::FLT_EPS, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 3.3, 0.0, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 3.3, 0.0 - wlimits::FLT_EPS, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
// Test bounds for Z direction
cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 2.0 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 2.0 - wlimits::FLT_EPS ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 0.0 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 0.0 - wlimits::FLT_EPS ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
}
/**
......
......@@ -50,7 +50,8 @@ FTensor TensorField::getInterpolatedVector(float x, float y, float z)
"Only implemented for 3D Vectors so far." );
wmath::WPosition pos( x, y, z );
WAssert( grid->encloses( pos ), "Grid does not enclose position to interpolate" );
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
bool isInside = true; // TODO(all): check for isInside here. How will we handle it?
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos, &isInside ) );
float xMult = x - (int)x;
float yMult = y - (int)y;
......
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