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

[ADD #157] finished porting the distance metrics

parent 63041d66
......@@ -25,6 +25,8 @@
#ifndef WLIMITS_H
#define WLIMITS_H
#include <limits>
/**
* Project wide limits for different quantitities.
*/
......@@ -56,6 +58,11 @@ namespace wlimits
* Maximum samplimg frequency of a recording.
*/
const unsigned int MAX_RECORDING_SAMPLING_FREQUENCY = 20000;
/**
* Maximum double value
*/
const double MAX_DOUBLE = std::numeric_limits< double >::max();
}
#endif // WLIMITS_H
......@@ -36,7 +36,7 @@
#include "WModule.h"
#include "../modules/data/WDataModule.hpp"
#include "../modules/navigationSlices/WNavigationSliceModule.h"
#include "../modules/FiberDisplay/WFiberDisplay.h"
#include "../modules/fiberDisplay/WFiberDisplay.h"
#include "../common/WException.h"
#include "../graphicsEngine/WGraphicsEngine.h"
......
......@@ -23,10 +23,11 @@
//---------------------------------------------------------------------------
#include <algorithm>
#include <vector>
#include <utility>
#include <vector>
#include "WFiber.h"
#include "../common/WLimits.h"
namespace wmath
{
......@@ -65,8 +66,7 @@ namespace wmath
qr = qr / qsize;
for( size_t j = 0; j < rsize; ++j )
{
// TODO(math): MAX_FANTOM_DOUBLE correct this
minSoFar = 9999999999999999999.9; // _FANTOM_DOUBLE;
minSoFar = wlimits::MAX_DOUBLE;
for( size_t i = 0; i < qsize; ++i )
{
if( m[i][j] < minSoFar )
......@@ -82,5 +82,16 @@ namespace wmath
rq = rq / rsize;
return std::make_pair( qr, rq );
}
}
double WFiber::dSt( const WFiber& other, const double thresholdSquare ) const
{
std::pair< double, double > result = dXt_optimized( other, thresholdSquare );
return std::min( result.first, result.second );
}
double WFiber::dLt( const WFiber& other, const double thresholdSquare ) const
{
std::pair< double, double > result = dXt_optimized( other, thresholdSquare );
return std::max( result.first, result.second );
}
}
......@@ -47,8 +47,17 @@ public:
explicit WFiber( const std::vector< WPosition > &points );
/**
* TODO(math): document this method in more detail
* Optimized version which computes dt measure from qr and rq at once.
* Optimized version which computes dt measure from fibers Q and R.
* Since this is not symmetric it computes both: dt(Q,R) and dt(R,Q) at
* once. dt(Q,R) computes the mean euclidian distance of the closest
* points. See Paper from Zhang: doi.ieeecomputersociety.org/10.1109/TVCG.2008.52
*
* \param other The other fiber R
* \param thresholdSquare The threshold, where distances below will be
* ignored for dt() computation. Note that this parameter is given
* as square, since the distanceSquare is much faster to compute then
* just the distance.
* \return Both dt(Q,R) and dt(R,Q).
*/
std::pair< double, double > dXt_optimized( const WFiber &other,
const double thresholdSquare ) const;
......
......@@ -82,6 +82,31 @@ public:
WFiber fib2( lineData2 );
TS_ASSERT_EQUALS( fib1, fib2 );
}
/**
* The dt(Q,R) measure (mean closest point distance) is not symmetric.
* distances below a certain threshold will be omitted.
*/
void testDTMeasure( void )
{
double threshold = 1.0;
using wmath::WPosition;
std::vector< WPosition > lineData1;
lineData1.push_back( WPosition( 0, 1, 0 ) );
lineData1.push_back( WPosition( 0, 0, 0 ) );
std::vector< WPosition > lineData2;
lineData2.push_back( WPosition( 1, 1, 0 ) );
lineData2.push_back( WPosition( 2, 2, 0 ) );
using wmath::WFiber;
WFiber fib1( lineData1 );
WFiber fib2( lineData2 );
double dt = fib1.dXt_optimized( fib2, threshold ).first;
double expected = std::sqrt( 2.0 ) / 2.0;
TS_ASSERT_EQUALS( dt, expected );
dt = fib1.dXt_optimized( fib2, threshold ).second;
expected = std::sqrt( 5.0 ) / 2.0;
TS_ASSERT_EQUALS( dt, expected );
}
};
#endif // WFIBER_TEST_H
ADD_SUBDIRECTORY( FiberDisplay )
ADD_SUBDIRECTORY( FiberCulling )
ADD_SUBDIRECTORY( fiberDisplay )
ADD_SUBDIRECTORY( fiberCulling )
......@@ -122,18 +122,19 @@ void WFiberCulling::cullOutFibers( boost::shared_ptr< WDataSetFibers > fibers )
{
continue;
}
// const wmath::WFiber& r = (*fibers)[j];
// double dst = q.dSt( r, proximity_t_Square );
//
// if( dst < m_dSt_culling_t ) { // cullout small fibs nearby long fibs
// if( q.posSize() < r.posSize() ) {
// unusedFibers[i] = true;
// break;
// }
// else {
// unusedFibers[j] = true;
// }
// }
const wmath::WFiber& r = (*fibers)[j];
double dst = q.dSt( r, proximity_t_Square );
if( dst < m_dSt_culling_t ) // cullout small fibs nearby long fibs
{
if( q.size() < r.size() ) {
unusedFibers[i] = true;
break;
}
else {
unusedFibers[j] = true;
}
}
}
}
......
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