Commit 9c00ad01 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[MERGE]

parents bbb9d7e6 248742bb
......@@ -91,7 +91,6 @@ namespace
boost::shared_ptr< const WGridRegular3D > grid = boost::shared_dynamic_cast< const WGridRegular3D >( i_grid );
WAssert( grid, "This data set has a grid whose type is not yet supported for interpolation." );
WAssert( grid->isNotRotated(), "Only feasible for grids that are only translated or scaled so far." );
WAssert( ( i_valueSet->order() == 1 && i_valueSet->dimension() == 3 ),
"Only implemented for 3D Vectors so far." );
boost::array< double, 8 > h;
......@@ -108,11 +107,11 @@ namespace
*vertexIds = grid->getCellVertexIds( cellId );
WPosition localPos = pos - grid->getPosition( ( *vertexIds )[0] );
WPosition localPos = grid->getTransform().positionToGridSpace( pos - grid->getPosition( ( *vertexIds )[0] ) );
double lambdaX = localPos[0] / grid->getOffsetX();
double lambdaY = localPos[1] / grid->getOffsetY();
double lambdaZ = localPos[2] / grid->getOffsetZ();
double lambdaX = localPos[0];
double lambdaY = localPos[1];
double lambdaZ = localPos[2];
// lZ lY
// | /
......
......@@ -26,6 +26,7 @@
#define WDATASETVECTOR_TEST_H
#include <vector>
#include <cmath>
#include <boost/array.hpp>
......@@ -53,57 +54,39 @@ public:
*/
void testInterpolate( void )
{
boost::shared_ptr< WGrid > grid = boost::shared_ptr< WGrid >( new WGridRegular3D( 5, 3, 3 ) );
boost::shared_ptr< std::vector< double > > data = boost::shared_ptr< std::vector< double > >( new std::vector< double >( grid->size() * 3 ) );
boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 2, 2, 2 ) );
boost::array< WPosition, 8 > d = { { WPosition( 0, 1, 2 ), WPosition( 3, 4, 5 ), WPosition( 6, 7, 8 ), // NOLINT braces
WPosition( 9,10,11 ), WPosition( 12,13,14 ), WPosition( 15,16,17 ), WPosition( 18,19,20 ), WPosition( 21,22,23 ) } }; // NOLINT braces
boost::shared_ptr< std::vector< double > > data( new std::vector< double > );
for( size_t i = 0; i < grid->size() * 3; ++i )
{
( *data )[i] = i;
data->push_back( i );
}
double almost1 = 1 - wlimits::DBL_EPS;
boost::array< WPosition, 8 > gridPos = { { WPosition( 0, 0, 0 ), WPosition( almost1, 0, 0 ), WPosition( 0, almost1, 0 ), // NOLINT braces
WPosition( almost1, almost1, 0 ), WPosition( 0, 0, almost1 ), WPosition( almost1, 0, almost1 ),
WPosition( 0, almost1, almost1 ), WPosition( almost1, almost1, almost1 ) } }; // NOLINT braces
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
WDataSetVector ds( valueSet, grid );
bool success = false;
for( size_t i = 0; i < 8; ++i )
{
if( !delta( ds.interpolate( gridPos[i], &success ), d[i], 1e-9 ) )
{
std::stringstream ss;
ss << "i:" << i << " gridPos(i):" << gridPos[i] << " d(i):" << d[i] << " interpol:" << ds.interpolate( gridPos[i], &success ) << "\n";
TS_FAIL( ss.str() );
}
TS_ASSERT( success );
}
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[0], ( *data )[0] );
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[1], ( *data )[1] );
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[2], ( *data )[2] );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[0], ( *data )[3], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[1], ( *data )[4], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[2], ( *data )[5], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[0], ( *data )[15], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[1], ( *data )[16], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[2], ( *data )[17], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[0], ( *data )[18], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[1], ( *data )[19], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[2], ( *data )[20], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[0], ( *data )[45], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[1], ( *data )[46], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[2], ( *data )[47], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[0], ( *data )[48], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[1], ( *data )[49], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[2], ( *data )[50], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[0], ( *data )[60], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[1], ( *data )[61], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[2], ( *data )[62], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[0], ( *data )[63], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[1], ( *data )[64], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[2], ( *data )[65], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[0], 29.4, 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[1], 30.4, 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[2], 31.4, 1e-9 );
TS_ASSERT( delta( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success ), WPosition( 9.3, 10.3, 11.3 ), 1e-9 ) );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[0], 31.5, 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[1], 32.5, 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[2], 33.5, 1e-9 );
TS_ASSERT( delta( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), WPosition( 10.5, 11.5, 12.5 ), 1e-9 ) );
TS_ASSERT( success );
}
......@@ -159,22 +142,15 @@ public:
bool success = false;
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0.0, 0.0, 0.0 ), &success ), d[0] );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[0], d[7][0], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[1], d[7][1], 1e-9 );
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[2], d[7][2], 1e-9 );
TS_ASSERT( delta( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success ), d[7], 1e-9 ) );
TS_ASSERT( success );
WPosition expected( 0.75, 0.0, 0.0 );
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), expected );
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), WPosition( 0.75, 0.0, 0.0 ) );
TS_ASSERT( success );
TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( WPosition( 0.0, 0.0, 0.0 ), &success ), d[0] );
TS_ASSERT( success );
expected = WPosition( -1.0, 0.0, 0.0 );
TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[0], expected[0], 1e-9 );
TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[1], expected[1], 1e-9 );
TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[2], expected[2], 1e-9 );
TS_ASSERT( delta( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success ), WPosition( -1.0, 0.0, 0.0 ), 1e-9 ) );
TS_ASSERT( success );
expected = WPosition( -1.0, 0.0, 0.0 );
TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), expected );
TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), WPosition( -1.0, 0.0, 0.0 ) );
TS_ASSERT( success );
}
......@@ -196,6 +172,89 @@ public:
ds.interpolate( WPosition( 2.0, 3.0, 4.0 ), &success );
TS_ASSERT( !success );
}
/**
* When the grid for this dataset was rotated the interpolation should still work.
*/
void testRotatedGridInterpolate( void )
{
// rotation around z with 45 degrees
WMatrix< double > mat( 4, 4 );
mat.makeIdentity();
mat( 0, 0 ) = 1.0 / sqrt( 2.0 );
mat( 0, 1 ) = 1.0 / sqrt( 2.0 );
mat( 1, 0 ) = -1.0 / sqrt( 2.0 );
mat( 1, 1 ) = 1.0 / sqrt( 2.0 );
WGridTransformOrtho v( mat );
boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 2, 2, 2, v ) );
boost::shared_ptr< std::vector< double > > data( new std::vector< double > );
boost::array< WPosition, 8 > d = { { WPosition( -1, 0, 0 ), // NOLINT braces
WPosition( 1, 0, 0 ),
WPosition( 1, 0, 0 ),
WPosition( 1, 0, 0 ),
WPosition( 1, 0, 0 ),
WPosition( 1, 0, 0 ),
WPosition( 1, 0, 0 ),
WPosition( 1, 0, 0 ) } }; // NOLINT braces
for( size_t i = 0; i < grid->size(); ++i )
{
data->push_back( d[i][0] );
data->push_back( d[i][1] );
data->push_back( d[i][2] );
}
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
WDataSetVector ds( valueSet, grid );
bool success = false;
WPosition pos = grid->getTransform().positionToWorldSpace( WPosition( 0.0, 0.0, 0.0 ) );
TS_ASSERT_EQUALS( ds.interpolate( pos, &success ), d[0] );
TS_ASSERT( success );
pos = grid->getTransform().positionToWorldSpace( WPosition( 0.9999, 0.9999, 0.9999 ) );
TS_ASSERT( delta( ds.interpolate( pos, &success ), d[7], 1e-9 ) );
TS_ASSERT( success );
pos = grid->getTransform().positionToWorldSpace( WPosition( 0.5, 0.5, 0.5 ) );
TS_ASSERT_EQUALS( ds.interpolate( pos, &success ), WPosition( 0.75, 0.0, 0.0 ) );
TS_ASSERT( success );
pos = grid->getTransform().positionToWorldSpace( WPosition( 0.0, 0.0, 0.0 ) );
TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( pos, &success ), d[0] );
TS_ASSERT( success );
pos = grid->getTransform().positionToWorldSpace( WPosition( 0.9999, 0.9999, 0.9999 ) );
TS_ASSERT( delta( ds.eigenVectorInterpolate( pos, &success ), WPosition( -1.0, 0.0, 0.0 ), 1e-9 ) );
TS_ASSERT( success );
pos = grid->getTransform().positionToWorldSpace( WPosition( 0.5, 0.5, 0.5 ) );
TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( pos, &success ), WPosition( -1.0, 0.0, 0.0 ) );
TS_ASSERT( success );
}
private:
/**
* Computes if both vectors are almost similar and their components do not differ from a certain given delta.
*
* \param lhs First vector
* \param rhs Second vector
* \param d The given delta
*
* \return True if and only if all components differing at most by the given delta.
*/
bool delta( WVector3d lhs, WVector3d rhs, double d )
{
bool result = true;
for( int i = 0; result && ( i < 3 ); ++i )
{
result = result && ( std::abs( lhs[i] - rhs[i] ) <= d );
if( !result )
{
std::cout.precision( 10 );
std::cout.setf( std::ios::fixed, std::ios::floatfield );
std::cout << "delta failed! => lhs:" << lhs << " rhs:" << rhs << " failed: abs(lhs[" << i << "] - rhs["
<< i << "])=" << std::abs( lhs[i] - rhs[i] ) << ", but should be: " << d << "\n";
}
}
return result;
}
};
#endif // WDATASETVECTOR_TEST_H
......@@ -188,8 +188,6 @@ BUILD_SYSTEM_COMPILER()
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# OpenWalnut specific options
# other options
OPTION( OW_HANDLE_SHADERS "This ensures that shaders are available in build directory after build." ON )
# sorry, linking not available properly on windows, Cygwin supports this but we do not want special rules for thousands of environments.
# ==> keep it clean
......
......@@ -195,32 +195,41 @@ ENDFUNCTION( SETUP_TESTS )
# break the install targets
# _Component the name of the install component
FUNCTION( SETUP_SHADERS _Shaders _TargetDir _Component )
# only if we are allowed to
IF( OW_HANDLE_SHADERS )
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E make_directory ${_TargetDir} )
# should we copy or link them?
SET( ShaderOperation "copy_if_different" )
IF ( OW_LINK_SHADERS ) # link
SET( ShaderOperation "create_symlink" )
ENDIF( OW_LINK_SHADERS )
# now do the operation for each shader into build dir
FOREACH( fname ${_Shaders} )
# We need the plain filename (create_symlink needs it)
STRING( REGEX REPLACE "^.*/" "" StrippedFileName "${fname}" )
# let cmake do it
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E ${ShaderOperation} ${fname} "${PROJECT_BINARY_DIR}/${_TargetDir}/${StrippedFileName}" )
ENDFOREACH( fname )
# now add install targets for each shader. All paths are relative to the current source dir.
FOREACH( fname ${_Shaders} )
INSTALL( FILES ${fname} DESTINATION ${_TargetDir}
COMPONENT ${_Component}
)
ENDFOREACH( fname )
ENDIF( OW_HANDLE_SHADERS )
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E make_directory ${_TargetDir} )
# should we copy or link them?
SET( ShaderOperation "copy_if_different" )
IF ( OW_LINK_SHADERS ) # link
SET( ShaderOperation "create_symlink" )
ENDIF( OW_LINK_SHADERS )
# now do the operation for each shader into build dir
FOREACH( fname ${_Shaders} )
# We need the plain filename (create_symlink needs it)
STRING( REGEX REPLACE "^.*/" "" StrippedFileName "${fname}" )
# construct final filename
SET( targetFile "${PROJECT_BINARY_DIR}/${_TargetDir}/${StrippedFileName}" )
# if the file already exists as non-symlink and we use the "create_symlink" command, we first need to remove the files
IF( NOT IS_SYMLINK ${targetFile} AND OW_LINK_SHADERS )
# before creating the symlink, remove the old files or cmake will not create the symlinks (as intended)
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E remove -f ${targetFile} )
ELSEIF( IS_SYMLINK ${targetFile} AND NOT OW_LINK_SHADERS )
# also handle the inverse case. The files exist as symlinks but copies should be used. Remove symlinks!
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E remove -f ${targetFile} )
ENDIF()
# let cmake do it
EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E ${ShaderOperation} ${fname} ${targetFile} )
ENDFOREACH( fname )
# now add install targets for each shader. All paths are relative to the current source dir.
FOREACH( fname ${_Shaders} )
INSTALL( FILES ${fname} DESTINATION ${_TargetDir}
COMPONENT ${_Component}
)
ENDFOREACH( fname )
ENDFUNCTION( SETUP_SHADERS )
# Sets up the stylecheck mechanism. Use this to add your codes to the stylecheck mechanism.
......
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