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

[ADD #251] very trivial slice sampling implemented

parent 486dace2
......@@ -131,13 +131,33 @@ inline double WVector3D::dotProduct( const WVector3D& factor2 ) const
inline bool WVector3D::operator<( const wmath::WVector3D& rhs ) const
{
if( ( ( (*this)[0] < rhs[0] ) && ( std::abs( (*this)[0] - rhs[0] ) > wlimits::FLT_EPS ) ) || // using FLT_EPS to make it more robust
( ( (*this)[1] < rhs[1] ) && ( std::abs( (*this)[1] - rhs[1] ) > wlimits::FLT_EPS ) ) ||
( ( (*this)[2] < rhs[2] ) && ( std::abs( (*this)[2] - rhs[2] ) > wlimits::FLT_EPS ) ) )
if( (*this)[0] < rhs[0] )
{
return true;
}
return false;
if( (*this)[0] > rhs[0] )
{
return false;
}
else
{
if( (*this)[1] < rhs[1] )
{
return true;
}
if( (*this)[1] > rhs[1] )
{
return false;
}
else
{
if( (*this)[2] < rhs[2] )
{
return true;
}
return false;
}
}
}
} // End of namespace
#endif // WVECTOR3D_H
......@@ -224,8 +224,7 @@ public:
}
/**
* Upto the precision of wlimits::FLT_EPS the operator< should be stable. If the difference
* of two vectors is below FLT_EPS we consider them generously as nearly equal!
* A vector a is small than a vector b if a is small than b in lexicographical order.
*/
void testOperatorLessOnNumericalStability( void )
{
......@@ -235,8 +234,6 @@ public:
b[2] = 1;
TS_ASSERT( a < b );
a += WVector3D( 0, 0, 1 - wlimits::FLT_EPS );
TS_ASSERT( !( a < b ) );
a -= WVector3D( 0, 0, wlimits::DBL_EPS );
TS_ASSERT( a < b );
}
};
......
......@@ -36,7 +36,7 @@ WPlane::WPlane( const wmath::WVector3D& normal, const wmath::WPosition& pos )
: m_normal( normal ),
m_pos( pos )
{
m_first = normal.crossProduct( wmath::WVector3D( 1, 1, 1 ) );
m_first = normal.crossProduct( wmath::WVector3D( 1, 0, 0 ) );
m_first.normalize();
m_second = normal.crossProduct( m_first );
m_second.normalize();
......@@ -59,6 +59,28 @@ void WPlane::resetPosition( wmath::WPosition newPos )
}
boost::shared_ptr< std::set< wmath::WPosition > > WPlane::samplePoints( double stepWidth, size_t numX, size_t numY ) const
{
// idea: start from m_pos in m_first direction until boundary reached, increment in m_second direction from m_pos and start again
boost::shared_ptr< std::set< wmath::WPosition > > result( new std::set< wmath::WPosition >() );
// the plane has two directions m_first and m_second
const wmath::WVector3D ycrement = stepWidth * m_second;
const wmath::WVector3D xcrement = stepWidth * m_first;
result->insert( m_pos );
for( size_t i = 0; i < numY; ++i )
{
for( size_t j = 0; j < numX; ++j )
{
result->insert( m_pos - i * ycrement - j * xcrement );
result->insert( m_pos + i * ycrement - j * xcrement );
result->insert( m_pos - i * ycrement + j * xcrement );
result->insert( m_pos + i * ycrement + j * xcrement );
}
}
return result;
}
boost::shared_ptr< std::set< wmath::WPosition > > WPlane::samplePoints( const WGridRegular3D& grid, double stepWidth )
{
// idea: start from m_pos in m_first direction until boundary reached, increment in m_second direction from m_pos and start again
......@@ -71,6 +93,7 @@ boost::shared_ptr< std::set< wmath::WPosition > > WPlane::samplePoints( const WG
wmath::WPosition y_offset_down = m_pos;
wmath::WPosition x_offset_right = m_pos;
wmath::WPosition x_offset_left = m_pos;
// TODO(math): assert( grid.encloses( m_pos ) );
while( grid.encloses( y_offset_up ) || grid.encloses( y_offset_down ) )
{
if( grid.encloses( y_offset_up ) ) // walk up
......
......@@ -76,10 +76,21 @@ public:
* \param grid
* \param stepWidth
*
* \return Vector of positions on the plane
* \return Set of positions on the plane
*/
boost::shared_ptr< std::set< wmath::WPosition > > samplePoints( const WGridRegular3D& grid, double stepWidth );
/**
* Computes a fixed number of sample points on that plane.
*
* \param stepWidth
* \param numX
* \param numY
*
* \return Set of positions on the plane
*/
boost::shared_ptr< std::set< wmath::WPosition > > samplePoints( double stepWidth, size_t numX, size_t numY ) const;
protected:
wmath::WVector3D m_normal; //!< Direction of the plane
wmath::WPosition m_pos; //!< Position of the plane specifying the center
......
......@@ -25,8 +25,11 @@
#ifndef WPLANE_TEST_H
#define WPLANE_TEST_H
#include <set>
#include <cxxtest/TestSuite.h>
#include "../../../common/math/test/WPositionTraits.h"
#include "../WPlane.h"
/**
......@@ -35,14 +38,46 @@
class WPlaneTest : public CxxTest::TestSuite
{
public:
// /**
// * Simple sampling test
// */
// void testSamplePointsFromCenter( void )
// {
// WPlane p( wmath::WVector3D( 0, 0, 1 ), wmath::WPosition( 1.5, 1.5, 1. ) );
// WGridRegular3D grid( 2, 2, 2, 1., 1., 1. );
// boost::shared_ptr< std::set< wmath::WPosition > > expected( new std::set< wmath::WPosition > );
// expected->insert( wmath::WPosition( 1, 1, 1 ) );
// expected->insert( wmath::WPosition( 1.5, 1, 1 ) );
// expected->insert( wmath::WPosition( 2, 1, 1 ) );
// expected->insert( wmath::WPosition( 1, 1.5, 1 ) );
// expected->insert( wmath::WPosition( 1.5, 1.5, 1 ) );
// expected->insert( wmath::WPosition( 2, 1.5, 1 ) );
// expected->insert( wmath::WPosition( 1, 2, 1 ) );
// expected->insert( wmath::WPosition( 1.5, 2, 1 ) );
// expected->insert( wmath::WPosition( 2, 2, 1 ) );
// using string_utils::operator<<;
// TS_ASSERT_EQUALS( *expected, *p.samplePoints( grid, 0.5 ) );
// }
/**
* TODO(math): Document this!
* A predefined number of sampling points with step width from the center position.
*/
void testSamplePointsFromCenter( void )
void testFixedSampling( void )
{
WPlane p( wmath::WVector3D( 0, 0, 1 ), wmath::WPosition( 1, 1, 1 ) );
// boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( ) );
}
WPlane p( wmath::WVector3D( 0, 0, 1 ), wmath::WPosition( 1.5, 1.5, 1. ) );
boost::shared_ptr< std::set< wmath::WPosition > > expected( new std::set< wmath::WPosition > );
expected->insert( wmath::WPosition( 1, 1, 1 ) );
expected->insert( wmath::WPosition( 1, 1.5, 1 ) );
expected->insert( wmath::WPosition( 1, 2, 1 ) );
expected->insert( wmath::WPosition( 1.5, 1, 1 ) );
expected->insert( wmath::WPosition( 2, 1, 1 ) );
expected->insert( wmath::WPosition( 1.5, 1.5, 1 ) );
expected->insert( wmath::WPosition( 2, 1.5, 1 ) );
expected->insert( wmath::WPosition( 1, 1.5, 1 ) );
expected->insert( wmath::WPosition( 1.5, 2, 1 ) );
expected->insert( wmath::WPosition( 2, 2, 1 ) );
TS_ASSERT_EQUALS( *expected, *p.samplePoints( 0.5, 2, 2 ) );
}
};
#endif // WPLANE_TEST_H
......@@ -519,6 +519,9 @@ public:
TS_ASSERT_THROWS_ANYTHING( g1.getCellId( wmath::WPosition( 3.3, 1.75, 0.78 ) ) );
}
/**
* If a point is inside of the boundary of a grid encloses should return true, otherwise false.
*/
void testEnclosesQuery( void )
{
WGridRegular3D g( 2, 2, 2, 1., 1., 1. );
......
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