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

Using class Ray or ray casting

parent 21d18287
......@@ -37,11 +37,14 @@
#include <osg/Geode>
#include <osg/Material>
#include <osg/StateAttribute>
#include <osg/Vec3>
#include "core/kernel/WKernel.h"
#include "core/common/WColor.h"
#include "core/common/WPathHelper.h"
#include "core/common/WPropertyHelper.h"
#include "core/common/math/WMatrix.h"
#include "core/common/math/linearAlgebra/WLinearAlgebra.h"
#include "core/graphicsEngine/WGEUtils.h"
#include "core/graphicsEngine/WGERequirement.h"
......@@ -183,6 +186,10 @@ void WMTransferCalc::moduleMain()
continue;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Getting Data and Setting Properties
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
unsigned int x_scale = grid->getNbCoordsX();
unsigned int y_scale = grid->getNbCoordsY();
unsigned int z_scale = grid->getNbCoordsZ();
......@@ -196,27 +203,58 @@ 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 ;
// (x,y) position for the ray
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Calculating Ray
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
unsigned int x = m_xPos->get( true );
unsigned int y = m_yPos->get( true );
// start point and direction of the ray
double x = m_xPos->get( true );
double y = m_yPos->get( true );
double z = 0;
// size_t s = dataSet->getValueSet()->rawSize();
// debugLog() << "Raw size of ValueSet: " << s ;
WVector3d start( x, y, z );
debugLog() << "Start: " << start;
WVector3d dir( 0, 0, 1 );
debugLog() << "Direction: " << dir;
boost::shared_ptr< WProgress > prog = boost::shared_ptr< WProgress >( new WProgress( "Reading one scale of data.", z_scale ) );
// ray object
// ray = start + t * direction
WRay ray ( start, dir );
// step length
double interval = 1;
double distance = 0;
// progress
boost::shared_ptr< WProgress > prog = boost::shared_ptr< WProgress >( new WProgress( "Casting ray." ) );
m_progress->addSubProgress( prog );
for( unsigned int z = 0; z < z_scale; z++ )
bool calc = true;
while( calc )
{
++*prog;
WVector3d current = ray.getSpot( distance );
distance += interval;
debugLog() << "Point: " << current;
newGeode->addDrawable( new osg::ShapeDrawable( new osg::Sphere( osg::Vec3(x,y,z), 0.5f ) ) );
double val = dataSet->getValueSet()->getScalarDouble( grid->getVoxelNum(x,y,z) );
// 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 )
{
calc = false;
break;
}
debugLog() << "Value: " << val;
// static_cast< osg::Vec3 >( ~ )
newGeode->addDrawable( new osg::ShapeDrawable( new osg::Sphere( current, 0.5f ) ) );
double val = dataSet->getValueSet()->getScalarDouble( grid->getVoxelNum( current ) );
debugLog() << "Value: " << val;
}
m_rootNode->remove( m_geode );
......@@ -226,6 +264,7 @@ void WMTransferCalc::moduleMain()
m_rootNode->insert( m_geode );
prog->finish();
m_progress->removeSubProgress( prog );
}
}
}
......
......@@ -41,8 +41,11 @@
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/graphicsEngine/WGEManagedGroupNode.h"
#include "core/dataHandler/WDataSetScalar.h"
#include "core/common/math/linearAlgebra/WLinearAlgebra.h"
#include "core/common/math/WMatrix.h"
#include "WRay.h"
/**
* --
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WRay.h"
WRay::WRay( WVector3d st, WVector3d dir ) :
m_start( st ),
m_direction( dir )
{
double n = sqrt( dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2] );
m_direction *= ( 1/n );
}
WRay::~WRay()
{
}
WVector3d WRay::getSpot( double t )
{
return m_start + m_direction * t;
}
\ No newline at end of file
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WRAY_H
#define WRAY_H
#include "core/common/math/WMatrix.h"
#include "core/common/math/linearAlgebra/WLinearAlgebra.h"
/**
* class to implement a simple ray
*/
class WRay
{
public:
/**
* constructor -
* normalizes direction
*
* \param st start vector
* \param dir direction of the ray
*/
WRay( WVector3d st, WVector3d dir );
/**
* destructor
*/
~WRay();
/**
* Calculates a spot on the ray with given parameter t
* ray = start + t * direction
*
* \param t the distance to the start of the ray
*
* \return vector
*/
WVector3d getSpot( double t );
protected:
private:
/**
* origin of the ray
*/
WVector3d m_start;
/**
* direction of the ray
*/
WVector3d m_direction;
};
#endif // WRAY_H
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