Commit 82084199 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[MERGE]

parents 0593a98a db844a13
......@@ -84,14 +84,16 @@ double WDataSetScalar::interpolate( const wmath::WPosition& pos, bool* success )
WAssert( ( m_valueSet->order() == 0 && m_valueSet->dimension() == 1 ),
"Only implemented for scalar values so far." );
*success = grid->encloses( pos );
bool isInside = true;
size_t cellId = grid->getCellId( pos, &isInside );
if( !*success )
if( !isInside )
{
return 0;
*success = false;
return 0.0;
}
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
std::vector< size_t > vertexIds = grid->getCellVertexIds( cellId );
wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] );
......
......@@ -69,13 +69,17 @@ wmath::WSymmetricSphericalHarmonic WDataSetSphericalHarmonics::interpolate( cons
*success = grid->encloses( pos );
if( !*success )
bool isInside = true;
size_t cellId = grid->getCellId( pos, &isInside );
if( !isInside )
{
*success = false;
return wmath::WSymmetricSphericalHarmonic();
}
// ids of vertices for interpolation
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
std::vector< size_t > vertexIds = grid->getCellVertexIds( cellId );
wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] );
......@@ -128,3 +132,8 @@ const std::string WDataSetSphericalHarmonics::getDescription() const
{
return "Contains factors for spherical harmonics.";
}
bool WDataSetSphericalHarmonics::isTexture() const
{
return false;
}
......@@ -102,6 +102,13 @@ public:
*/
virtual const std::string getDescription() const;
/**
* Determines whether this dataset can be used as a texture.
*
* \return true if usable as texture.
*/
virtual bool isTexture() const;
protected:
/**
......
......@@ -72,14 +72,15 @@ wmath::WVector3D WDataSetVector::interpolate( const wmath::WPosition& pos, bool
WAssert( ( m_valueSet->order() == 1 && m_valueSet->dimension() == 3 ),
"Only implemented for 3D Vectors so far." );
*success = grid->encloses( pos );
bool isInside = true;
size_t cellId = grid->getCellId( pos, &isInside );
if( !*success )
if( !isInside )
{
return wmath::WVector3D( 0, 0, 0 );
*success = false;
return wmath::WVector3D();
}
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
std::vector< size_t > vertexIds = grid->getCellVertexIds( cellId );
wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] );
......
......@@ -441,15 +441,17 @@ bool WGridRegular3D::isNotRotatedOrSheared() const
return onlyTranslatedOrScaled;
}
size_t WGridRegular3D::getCellId( const wmath::WPosition& pos ) const
size_t WGridRegular3D::getCellId( const wmath::WPosition& pos, bool* success ) const
{
WAssert( isNotRotatedOrSheared(), "Only feasible for grids that are only translated or scaled so far." );
wmath::WPosition posRelativeToOrigin = pos - m_origin;
size_t xCellId = floor( posRelativeToOrigin[0] / m_offsetX );
size_t yCellId = floor( posRelativeToOrigin[1] / m_offsetY );
size_t zCellId = floor( posRelativeToOrigin[2] / m_offsetZ );
double xCellId = floor( posRelativeToOrigin[0] / m_offsetX );
double yCellId = floor( posRelativeToOrigin[1] / m_offsetY );
double zCellId = floor( posRelativeToOrigin[2] / m_offsetZ );
*success = xCellId >= 0 && yCellId >=0 && zCellId >= 0 && xCellId < m_nbPosX - 1 && yCellId < m_nbPosY -1 && zCellId < m_nbPosZ -1;
return xCellId + yCellId * ( m_nbPosX - 1 ) + zCellId * ( m_nbPosX - 1 ) * ( m_nbPosY - 1 );
}
......
......@@ -41,6 +41,8 @@
* A grid that has parallelepiped cells which all have the same proportion. I.e.
* the samples along a single axis are equidistant. The distance of samples may
* vary between axes.
*
* \warning Positions on the upper bounddaries in x, y and z are considered outside the grid.
* \ingroup dataHandler
*/
class WGridRegular3D : public WGrid
......@@ -339,8 +341,9 @@ public:
* Computes the id of the cell containing the position pos.
*
* \param pos The position selecting the cell.
* \param success True if the position pos is inside the grid.
*/
size_t getCellId( const wmath::WPosition& pos ) const;
size_t getCellId( const wmath::WPosition& pos, bool* success ) const;
/**
* Computes the ids of the vertices of a cell given by its id.
......
......@@ -511,8 +511,51 @@ public:
void testGetCellId( void )
{
WGridRegular3D g( 5, 3, 3, 0, 0, 0, 1, 1, 1 );
size_t cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 0.78 ) );
bool isInside = true;
// Test some value
size_t cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 0.78 ), &isInside );
TS_ASSERT_EQUALS( cellId, 7 );
TS_ASSERT_EQUALS( isInside, true );
// Test bounds for X direction
cellId = g.getCellId( wmath::WPosition( 4.0, 1.75, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
cellId = g.getCellId( wmath::WPosition( 4.0 - wlimits::FLT_EPS, 1.75, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 0.0, 1.75, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 0.0 - wlimits::FLT_EPS, 1.75, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
// Test bounds for Y direction
cellId = g.getCellId( wmath::WPosition( 3.3, 2.0, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
cellId = g.getCellId( wmath::WPosition( 3.3, 2.0 - wlimits::FLT_EPS, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 3.3, 0.0, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 3.3, 0.0 - wlimits::FLT_EPS, 0.3 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
// Test bounds for Z direction
cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 2.0 ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 2.0 - wlimits::FLT_EPS ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 0.0 ), &isInside );
TS_ASSERT_EQUALS( isInside, true );
cellId = g.getCellId( wmath::WPosition( 3.3, 1.75, 0.0 - wlimits::FLT_EPS ), &isInside );
TS_ASSERT_EQUALS( isInside, false );
}
/**
......
......@@ -69,3 +69,12 @@ bool WROI::isModified()
return tmp;
}
void WROI::hide()
{
setNodeMask( 0x0 );
}
void WROI::unhide()
{
setNodeMask( 0xFFFFFFFF );
}
......@@ -84,6 +84,16 @@ public:
*/
void setActive( bool active );
/**
* hides the roi in the scene
*/
void hide();
/**
* unhides the roi in the scene
*/
void unhide();
/**
* Getter for modified flag
*/
......
......@@ -62,14 +62,14 @@ public:
wmath::WPosition getMaxPos() const;
/**
* setter
* \param color
* Setter for standard color
* \param color The new color.
*/
void setColor( osg::Vec4 color );
/**
* setter
* \param color
* Setter for color in negated state
* \param color The new color.
*/
void setNotColor( osg::Vec4 color );
......
//---------------------------------------------------------------------------
//
// 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 <string>
#include <utility>
#include <osg/LightModel>
#include "WROISphere.h"
#include "WGraphicsEngine.h"
#include "WGEUtils.h"
size_t WROISphere::maxSphereId = 0;
WROISphere::WROISphere( wmath::WPosition position, float radius ) :
WROI(),
sphereId( maxSphereId++ ),
m_position( position ),
m_originalPosition( position ),
m_radius( radius ),
m_lockX( false ),
m_lockY( false ),
m_lockZ( false ),
m_pickNormal( wmath::WVector3D() ),
m_oldPixelPosition( std::make_pair( 0, 0 ) ),
m_color( osg::Vec4( 0.f, 1.f, 1.f, 0.4f ) ),
m_notColor( osg::Vec4( 1.0f, 0.0f, 0.0f, 0.4f ) )
{
boost::shared_ptr< WGraphicsEngine > ge = WGraphicsEngine::getGraphicsEngine();
assert( ge );
boost::shared_ptr< WGEViewer > viewer = ge->getViewerByName( "main" );
assert( viewer );
m_viewer = viewer;
m_pickHandler = m_viewer->getPickHandler();
m_pickHandler->getPickSignal()->connect( boost::bind( &WROISphere::registerRedrawRequest, this, _1 ) );
redrawSphere();
//**********************************************************
m_isModified = true;
m_isNot = false;
assert( WGraphicsEngine::getGraphicsEngine() );
WGraphicsEngine::getGraphicsEngine()->getScene()->addChild( this );
setUserData( this );
setUpdateCallback( osg::ref_ptr<ROISphereNodeCallback>( new ROISphereNodeCallback ) );
}
void WROISphere::redrawSphere()
{
removeDrawables( 0 );
osg::ShapeDrawable* shape = new osg::ShapeDrawable( new osg::Sphere( osg::Vec3( m_position[0], m_position[1], m_position[2] ), m_radius ) );
std::stringstream ss;
ss << "ROISphere" << sphereId;
setName( ss.str() );
shape->setName( ss.str() );
addDrawable( shape );
}
WROISphere::~WROISphere()
{
// std::cout << "destructor called" << std::endl;
// std::cout << "ref count geode: " << m_geode->referenceCount() << std::endl;
//
// WGraphicsEngine::getGraphicsEngine()->getScene()->remove( m_geode );
}
wmath::WPosition WROISphere::getPosition() const
{
return m_position;
}
void WROISphere::setPosition( wmath::WPosition position )
{
m_position = position;
m_originalPosition = position;
m_isModified = true;
}
void WROISphere::registerRedrawRequest( WPickInfo pickInfo )
{
m_pickInfo = pickInfo;
}
void WROISphere::updateGFX()
{
std::stringstream ss;
ss << "ROISphere" << sphereId << "";
if ( m_pickInfo.getName() == ss.str() )
{
std::pair< float, float > newPixelPos( m_pickInfo.getPickPixelPosition() );
if ( m_isPicked )
{
osg::Vec3 in( newPixelPos.first, newPixelPos.second, 0.0 );
osg::Vec3 world = wge::unprojectFromScreen( in, m_viewer->getCamera() );
wmath::WPosition newPixelWorldPos( world[0], world[1], world[2] );
wmath::WPosition oldPixelWorldPos;
if( m_oldPixelPosition.first == 0 && m_oldPixelPosition.second == 0 )
{
oldPixelWorldPos = newPixelWorldPos;
}
else
{
osg::Vec3 in( m_oldPixelPosition.first, m_oldPixelPosition.second, 0.0 );
osg::Vec3 world = wge::unprojectFromScreen( in, m_viewer->getCamera() );
oldPixelWorldPos = wmath::WPosition( world[0], world[1], world[2] );
}
wmath::WVector3D moveVec = newPixelWorldPos - oldPixelWorldPos;
osg::ref_ptr<osg::Vec3Array> vertices = osg::ref_ptr<osg::Vec3Array>( new osg::Vec3Array );
// move sphere
if( m_pickInfo.getModifierKey() == WPickInfo::NONE )
{
moveSphere( moveVec );
}
}
m_oldPixelPosition = newPixelPos;
m_isModified = true;
m_isPicked = true;
m_signalIsModified();
}
if ( m_isPicked && m_pickInfo.getName() == "unpick" )
{
// Perform all actions necessary for finishing a pick
m_pickNormal = wmath::WVector3D();
m_isPicked = false;
}
if ( isModified() )
{
redrawSphere();
}
}
void WROISphere::moveSphere( wmath::WVector3D offset )
{
m_position += offset;
if ( m_lockX )
{
m_position[0] = m_originalPosition[0];
}
if ( m_lockY )
{
m_position[1] = m_originalPosition[1];
}
if ( m_lockZ )
{
m_position[2] = m_originalPosition[2];
}
}
void WROISphere::setLockX( bool value )
{
m_lockX = value;
}
void WROISphere::setLockY( bool value )
{
m_lockY = value;
}
void WROISphere::setLockZ( bool value )
{
m_lockZ = value;
}
void WROISphere::setColor( osg::Vec4 color )
{
m_color = color;
}
void WROISphere::setNotColor( osg::Vec4 color )
{
m_notColor = color;
}
//---------------------------------------------------------------------------
//
// 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 WROISPHERE_H
#define WROISPHERE_H
#include <string>
#include <utility>
#include <boost/thread.hpp>
#include "../common/math/WPosition.h"
#include "WPickHandler.h"
#include "WGEViewer.h"
#include "WROI.h"
/**
* A sphere representing a region of interest.
*/
class WROISphere : public WROI
{
public:
/**
* Yields sphere with desired center point and radius
* \param position position of the center of the sphere
* \param radius radius of the sphere
*/
WROISphere( wmath::WPosition position, float radius = 5.0 );
/**
* standard destructor
*/
virtual ~WROISphere();
/**
* getter
* \return position
*/
wmath::WPosition getPosition() const;
/**
* setter
* \param position
*/
void setPosition( wmath::WPosition position );
/**
* Setter for standard color
* \param color The new color.
*/
void setColor( osg::Vec4 color );
/**
* Setter for color in negated state
* \param color The new color.
*/
void setNotColor( osg::Vec4 color );
/**
* removes the old drawable from the osg geode and adds a new one at the current position and size
*/
void redrawSphere();
/**
* sets the flag that allows or disallows movement along the x axis
*
* \param value the flag
*/
void setLockX( bool value = true );
/**
* sets the flag that allows or disallows movement along the y axis
*
* \param value the flag
*/
void setLockY( bool value = true );
/**
* sets the flag that allows or disallows movement along the z axis
*
* \param value the flag
*/
void setLockZ( bool value = true );
/**
* move the sphere with a given offset
*
* \param offset the distance to move
*/
void moveSphere( wmath::WVector3D offset );
protected:
private:
static size_t maxSphereId; //!< Current maximum boxId over all spheres.
size_t sphereId; //!< Id of the current sphere.
wmath::WPosition m_position; //!< The position of the sphere
wmath::WPosition m_originalPosition; //!< The position of the sphere when created, used for locking
float m_radius; //!< The radius of the sphere
bool m_lockX; //!< if true disallows changing of the X component of the position
bool m_lockY; //!< if true disallows changing of the Y component of the position
bool m_lockZ; //!< if true disallows changing of the Z component of the position
bool m_isPicked; //!< Indicates whether the box is currently picked or not.
wmath::WPosition m_pickedPosition; //!< Caches the old picked position to a allow for comparison
wmath::WVector3D m_pickNormal; //!< Store the normal that occured when the pick action was started.
std::pair< float, float > m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison
WPickInfo m_pickInfo; //!< Stores the pick information for potential redraw
boost::shared_ptr< WGEViewer > m_viewer; //!< makes viewer available all over this class.
osg::Vec4 m_color; //!< the color of the box
osg::Vec4 m_notColor; //!< the color of the box when negated
/**
* note that there was a pick
* \param pickInfo info from pick
*/
void registerRedrawRequest( WPickInfo pickInfo );
/**
* updates the graphics
*/
virtual void updateGFX();
/**
* Node callback to handle updates properly
*/
class ROISphereNodeCallback : public osg::NodeCallback
{
public: // NOLINT
/**
* operator ()
*
* \param node the osg node
* \param nv the node visitor
*/
virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
{
osg::ref_ptr< WROISphere > module = static_cast< WROISphere* > ( node->getUserData() );
if ( module )
{
module->updateGFX();
}
traverse( node, nv );
}
};
};
#endif // WROISPHERE_H
......@@ -26,28 +26,9 @@ void directionalLight( in int i, in vec3 normal, in float shininess,
ambient += gl_LightSource[