Commit e9c7d9e4 authored by Franziska Jacob's avatar Franziska Jacob
Browse files

Trilinear Interpolation

parent e50fa48b
[Dolphin]
ShowPreview=true
Timestamp=2012,4,23,20,0,34
Timestamp=2012,5,4,23,31,16
Version=2
[Settings]
......
[Dolphin]
Timestamp=2012,4,24,1,31,55
Timestamp=2012,5,4,23,30,37
Version=2
ViewMode=2
......@@ -53,6 +53,7 @@
// This line is needed by the module loader to actually find your module. You need to add this to your module too. Do NOT add a ";" here.
// W_LOADABLE_MODULE( WMTransferCalc )
// TODO
WMTransferCalc::WMTransferCalc():
WModule()
......@@ -187,7 +188,7 @@ void WMTransferCalc::moduleMain()
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Getting Data and Setting Properties
// Getting Data and setting Properties
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
unsigned int x_scale = grid->getNbCoordsX();
......@@ -203,9 +204,6 @@ void WMTransferCalc::moduleMain()
m_yPos->setMin( 0 );
m_yPos->setMax( y_scale );
m_yPos->setRecommendedValue( 0.5 * y_scale );
// size_t s = dataSet->getValueSet()->rawSize();
// debugLog() << "Raw size of ValueSet: " << s ;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Calculating Ray
......@@ -228,6 +226,7 @@ void WMTransferCalc::moduleMain()
// step length
double interval = 1;
// start position
double distance = 0;
// progress
......@@ -242,7 +241,8 @@ void WMTransferCalc::moduleMain()
debugLog() << "Point: " << current;
// do not calculate anything for vectors outside of the data grid
if( current[0] > x_scale - 0.5 || current[1] > y_scale - 0.5 || current[2] > z_scale - 0.5 )
//if( current[0] > x_scale - 0.5 || current[1] > y_scale - 0.5 || current[2] > z_scale - 0.5 )
if( ! grid->encloses( current ) )
{
calc = false;
break;
......@@ -252,7 +252,7 @@ void WMTransferCalc::moduleMain()
newGeode->addDrawable( new osg::ShapeDrawable( new osg::Sphere( current, 0.5f ) ) );
double val = dataSet->getValueSet()->getScalarDouble( grid->getVoxelNum( current ) );
double val = interpolate( current, grid );
debugLog() << "Value: " << val;
}
......@@ -269,6 +269,211 @@ void WMTransferCalc::moduleMain()
}
}
double WMTransferCalc::interpolate( WVector3d position, boost::shared_ptr<WGridRegular3D> grid )
{
double vox_x = static_cast< double >( grid->getXVoxelCoord( position ) );
double vox_y = static_cast< double >( grid->getYVoxelCoord( position ) );
double vox_z = static_cast< double >( grid->getZVoxelCoord( position ) );
WVector3d voxel_center( vox_x, vox_y, vox_z );
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Calculating all relevant neighbours for the interpolation
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// vector with all 8 neighbours
std::vector< WVector3d > neighbours (8);
// vector with min values of the scales of the "neighbour cube"
// { min_x, min_y, min_z }
std::vector< double > min_val (3);
// positive x direction
if( position[0] >= voxel_center[0] )
{
// positive y direction
if( position[1] >= voxel_center[1] )
{
// positive z direction
if( position[2] >= voxel_center[2] )
{
// Quadrant I
neighbours[0] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2] );
neighbours[1] = WVector3d( voxel_center[0]+1, voxel_center[1], voxel_center[2] );
neighbours[2] = WVector3d( voxel_center[0], voxel_center[1]+1, voxel_center[2] );
neighbours[3] = WVector3d( voxel_center[0]+1, voxel_center[1]+1, voxel_center[2] );
neighbours[4] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2]+1 );
neighbours[5] = WVector3d( voxel_center[0]+1, voxel_center[1], voxel_center[2]+1 );
neighbours[6] = WVector3d( voxel_center[0], voxel_center[1]+1, voxel_center[2]+1 );
neighbours[7] = WVector3d( voxel_center[0]+1, voxel_center[1]+1, voxel_center[2]+1 );
min_val[0] = voxel_center[0];
min_val[1] = voxel_center[1];
min_val[2] = voxel_center[2];
}
else // negative z direction
{
// Quadrant V
neighbours[0] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2]-1 );
neighbours[1] = WVector3d( voxel_center[0]+1, voxel_center[1], voxel_center[2]-1 );
neighbours[2] = WVector3d( voxel_center[0], voxel_center[1]+1, voxel_center[2]-1 );
neighbours[3] = WVector3d( voxel_center[0]+1, voxel_center[1]+1, voxel_center[2]-1 );
neighbours[4] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2] );
neighbours[5] = WVector3d( voxel_center[0]+1, voxel_center[1], voxel_center[2] );
neighbours[6] = WVector3d( voxel_center[0], voxel_center[1]+1, voxel_center[2] );
neighbours[7] = WVector3d( voxel_center[0]+1, voxel_center[1]+1, voxel_center[2] );
min_val[0] = voxel_center[0];
min_val[1] = voxel_center[1];
min_val[2] = voxel_center[2]-1;
}
}
else // negative y direction
{
// positive z direction
if( position[2] >= voxel_center[2] )
{
// Quadrant IV
neighbours[0] = WVector3d( voxel_center[0], voxel_center[1]-1, voxel_center[2] );
neighbours[1] = WVector3d( voxel_center[0]+1, voxel_center[1]-1, voxel_center[2] );
neighbours[2] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2] );
neighbours[3] = WVector3d( voxel_center[0]+1, voxel_center[1], voxel_center[2] );
neighbours[4] = WVector3d( voxel_center[0], voxel_center[1]-1, voxel_center[2]+1 );
neighbours[5] = WVector3d( voxel_center[0]+1, voxel_center[1]-1, voxel_center[2]+1 );
neighbours[6] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2]+1 );
neighbours[7] = WVector3d( voxel_center[0]+1, voxel_center[1], voxel_center[2]+1 );
min_val[0] = voxel_center[0];
min_val[1] = voxel_center[1]-1;
min_val[2] = voxel_center[2];
}
else // negative z direction
{
// Quadrant VIII
neighbours[0] = WVector3d( voxel_center[0], voxel_center[1]-1, voxel_center[2]-1 );
neighbours[1] = WVector3d( voxel_center[0]+1, voxel_center[1]-1, voxel_center[2]-1 );
neighbours[2] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2]-1 );
neighbours[3] = WVector3d( voxel_center[0]+1, voxel_center[1], voxel_center[2]-1 );
neighbours[4] = WVector3d( voxel_center[0], voxel_center[1]-1, voxel_center[2] );
neighbours[5] = WVector3d( voxel_center[0]+1, voxel_center[1]-1, voxel_center[2] );
neighbours[6] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2] );
neighbours[7] = WVector3d( voxel_center[0]+1, voxel_center[1], voxel_center[2] );
min_val[0] = voxel_center[0];
min_val[1] = voxel_center[1]-1;
min_val[2] = voxel_center[2]-1;
}
}
}
else // negative x direction
{
// positive y direction
if( position[1] >= voxel_center[1] )
{
// positive z direction
if( position[2] >= voxel_center[2] )
{
// Quadrant II
neighbours[0] = WVector3d( voxel_center[0]-1, voxel_center[1], voxel_center[2] );
neighbours[1] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2] );
neighbours[2] = WVector3d( voxel_center[0]-1, voxel_center[1]+1, voxel_center[2] );
neighbours[3] = WVector3d( voxel_center[0], voxel_center[1]+1, voxel_center[2] );
neighbours[4] = WVector3d( voxel_center[0]-1, voxel_center[1], voxel_center[2]+1 );
neighbours[5] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2]+1 );
neighbours[6] = WVector3d( voxel_center[0]-1, voxel_center[1]+1, voxel_center[2]+1 );
neighbours[7] = WVector3d( voxel_center[0], voxel_center[1]+1, voxel_center[2]+1 );
min_val[0] = voxel_center[0]-1;
min_val[1] = voxel_center[1];
min_val[2] = voxel_center[2];
}
else // negative z direction
{
// Quadrant VI
neighbours[0] = WVector3d( voxel_center[0]-1, voxel_center[1], voxel_center[2]-1 );
neighbours[1] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2]-1 );
neighbours[2] = WVector3d( voxel_center[0]-1, voxel_center[1]+1, voxel_center[2]-1 );
neighbours[3] = WVector3d( voxel_center[0], voxel_center[1]+1, voxel_center[2]-1 );
neighbours[4] = WVector3d( voxel_center[0]-1, voxel_center[1], voxel_center[2] );
neighbours[5] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2] );
neighbours[6] = WVector3d( voxel_center[0]-1, voxel_center[1]+1, voxel_center[2] );
neighbours[7] = WVector3d( voxel_center[0], voxel_center[1]+1, voxel_center[2] );
min_val[0] = voxel_center[0]-1;
min_val[1] = voxel_center[1];
min_val[2] = voxel_center[2]-1;
}
}
else // negative y direction
{
// positive z direction
if( position[2] >= voxel_center[2] )
{
// Quadrant III
neighbours[0] = WVector3d( voxel_center[0]-1, voxel_center[1]-1, voxel_center[2] );
neighbours[1] = WVector3d( voxel_center[0], voxel_center[1]-1, voxel_center[2] );
neighbours[2] = WVector3d( voxel_center[0]-1, voxel_center[1], voxel_center[2] );
neighbours[3] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2] );
neighbours[4] = WVector3d( voxel_center[0]-1, voxel_center[1]-1, voxel_center[2]+1 );
neighbours[5] = WVector3d( voxel_center[0], voxel_center[1]-1, voxel_center[2]+1 );
neighbours[6] = WVector3d( voxel_center[0]-1, voxel_center[1], voxel_center[2]+1 );
neighbours[7] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2]+1 );
min_val[0] = voxel_center[0]-1;
min_val[1] = voxel_center[1]-1;
min_val[2] = voxel_center[2];
}
else // negative z direction
{
// Quadrant VII
neighbours[0] = WVector3d( voxel_center[0]-1, voxel_center[1]-1, voxel_center[2]-1 );
neighbours[1] = WVector3d( voxel_center[0], voxel_center[1]-1, voxel_center[2]-1 );
neighbours[2] = WVector3d( voxel_center[0]-1, voxel_center[1], voxel_center[2]-1 );
neighbours[3] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2]-1 );
neighbours[4] = WVector3d( voxel_center[0]-1, voxel_center[1]-1, voxel_center[2] );
neighbours[5] = WVector3d( voxel_center[0], voxel_center[1]-1, voxel_center[2] );
neighbours[6] = WVector3d( voxel_center[0]-1, voxel_center[1], voxel_center[2] );
neighbours[7] = WVector3d( voxel_center[0], voxel_center[1], voxel_center[2] );
min_val[0] = voxel_center[0]-1;
min_val[1] = voxel_center[1]-1;
min_val[2] = voxel_center[2]-1;
}
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Interpolate
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
std::vector< double > values (8);
// check, if all neighbours are inside the grid
boost::shared_ptr< WDataSetScalar > dataSet = m_inputData->getData();
for( unsigned int i = 0; i < neighbours.size(); i++)
{
if( ! grid->encloses( neighbours[i] ) )
{
values[i] = 0;
}
else
{
values[i] = dataSet->getValueSet()->getScalarDouble( grid->getVoxelNum( neighbours[i] ) );
}
}
double x_dif = position[0] - min_val[0];
double y_dif = position[1] - min_val[1];
double z_dif = position[2] - min_val[2];
double c_00 = values[0]*( 1-x_dif ) + values[1]*x_dif;
double c_10 = values[2]*( 1-x_dif ) + values[3]*x_dif;
double c_01 = values[4]*( 1-x_dif ) + values[5]*x_dif;
double c_11 = values[6]*( 1-x_dif ) + values[7]*x_dif;
double c_0 = c_00*( 1-y_dif ) + c_10*y_dif;
double c_1 = c_01*( 1-y_dif ) + c_11*y_dif;
return c_0*( 1-z_dif ) + c_1*z_dif;
}
void WMTransferCalc::SafeUpdateCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
{
// One note about m_aColor: As you might have notices, changing one of the properties, which recreate the OSG node, causes the material to be
......
......@@ -124,6 +124,13 @@ protected:
private:
/**
* Trilinear interpolation within the grid for a given position
*
* \return interpolated value
*/
virtual double interpolate( WVector3d position, boost::shared_ptr<WGridRegular3D> grid );
/**
* An input connector used to get datasets from other modules.
*/
......
......@@ -24,6 +24,8 @@
#include "WRay.h"
WRay::WRay() {}
WRay::WRay( WVector3d st, WVector3d dir ) :
m_start( st ),
m_direction( dir )
......@@ -32,9 +34,7 @@ WRay::WRay( WVector3d st, WVector3d dir ) :
m_direction *= ( 1/n );
}
WRay::~WRay()
{
}
WRay::~WRay() {}
WVector3d WRay::getSpot( double t )
{
......
......@@ -34,6 +34,12 @@
class WRay
{
public:
/**
* Standard Constructor
*/
WRay();
/**
* constructor -
* normalizes direction
......@@ -46,7 +52,7 @@ public:
/**
* destructor
*/
~WRay();
virtual ~WRay();
/**
* Calculates a spot on the ray with given parameter t
......@@ -56,7 +62,7 @@ public:
*
* \return vector
*/
WVector3d getSpot( double t );
virtual WVector3d getSpot( double t );
protected:
private:
......
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