Commit fd425ae9 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - added plane based clipping feature to fiber display simple. It is...

[ADD] - added plane based clipping feature to fiber display simple. It is shader based and, therefore, fast.
parent 1e1ea3fe
......@@ -75,8 +75,7 @@ void WPropertyDoubleWidget::update()
}
else
{
wlog::warn( "PropertyWidget( " + m_doubleProperty->getName() + " )" ) << "The property has no minimum constraint. " <<
"You should define it to avoid unexpected behaviour. Using default (" << m_min << ").";
m_slider.hide();
}
// get the max constraint
......@@ -88,8 +87,7 @@ void WPropertyDoubleWidget::update()
}
else
{
wlog::warn( "PropertyWidget( " + m_doubleProperty->getName() + " )" ) << "The property has no maximum constraint. " <<
"You should define it to avoid unexpected behaviour. Using default (" << m_max << ").";
m_slider.hide();
}
// setup the slider
......
......@@ -30,6 +30,7 @@
#include "../../common/WPropertyObserver.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../graphicsEngine/WShader.h"
#include "WMFiberDisplaySimple.h"
#include "WMFiberDisplaySimple.xpm"
......@@ -85,12 +86,26 @@ void WMFiberDisplaySimple::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
m_clipPlaneGroup = m_properties->addPropertyGroup( "Clipping", "Clip the fiber data basing on an arbitrary plane." );
m_clipPlaneEnabled = m_clipPlaneGroup->addProperty( "Enabled", "If set, clipping of fibers is done using an arbitrary plane and plane distance.",
false, m_propCondition );
m_clipPlanePoint = m_clipPlaneGroup->addProperty( "Plane point", "An point on the plane.", wmath::WPosition( 0.0, 0.0, 0.0 ) );
m_clipPlaneVector = m_clipPlaneGroup->addProperty( "Plane normal", "The normal of the plane.", wmath::WPosition( 1.0, 0.0, 0.0 ) );
m_clipPlaneDistance= m_clipPlaneGroup->addProperty( "Clip distance", "The distance from the plane where fibers get clipped.", 10.0 );
m_clipPlaneDistance->removeConstraint( m_clipPlaneDistance->getMax() ); // there simply is no max.
// call WModule's initialization
WModule::properties();
}
void WMFiberDisplaySimple::moduleMain()
{
// initialize clipping shader
m_shader = osg::ref_ptr< WShader > ( new WShader( "WMFiberDisplaySimple", m_localPath ) );
m_clipPlanePointUniform = new WGEPropertyUniform< WPropPosition >( "u_planePoint", m_clipPlanePoint );
m_clipPlaneVectorUniform = new WGEPropertyUniform< WPropPosition >( "u_planeVector", m_clipPlaneVector );
m_clipPlaneDistanceUniform = new WGEPropertyUniform< WPropDouble >( "u_distance", m_clipPlaneDistance );
// get notified about data changes
m_moduleState.setResetable( true, true );
m_moduleState.add( m_fiberInput->getDataChangedCondition() );
......@@ -124,7 +139,8 @@ void WMFiberDisplaySimple::moduleMain()
boost::shared_ptr< WDataSetFibers > fibers = m_fiberInput->getData();
bool dataValid = ( fibers );
bool dataPropertiesUpdated = propObserver->updated();
if ( !( dataValid && ( dataPropertiesUpdated || dataUpdated ) ) )
bool propertiesUpdated = m_clipPlaneEnabled->changed();
if ( !( dataValid && ( propertiesUpdated || dataPropertiesUpdated || dataUpdated ) ) )
{
continue;
}
......@@ -224,6 +240,15 @@ void WMFiberDisplaySimple::moduleMain()
// disable light for this geode as lines can't be lit properly
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
// Apply the shader. This is for clipping.
if ( m_clipPlaneEnabled->get( true ) )
{
state->addUniform( m_clipPlanePointUniform );
state->addUniform( m_clipPlaneVectorUniform );
state->addUniform( m_clipPlaneDistanceUniform );
m_shader->apply( geode );
}
// add geode to module node
m_rootNode->clear();
m_rootNode->insert( geode );
......
......@@ -29,6 +29,7 @@
#include "../../dataHandler/WDataSetScalar.h"
#include "../../graphicsEngine/WGEManagedGroupNode.h"
#include "../../graphicsEngine/WShader.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "../../kernel/WModuleOutputData.h"
......@@ -115,6 +116,51 @@ private:
* The properties of the fiber dataset.
*/
WProperties::SharedPtr m_fibProps;
/**
* The shader used for clipping of fibers using an arbitrary plane.
*/
osg::ref_ptr< WShader > m_shader;
/**
* A property group for all the clipping related props.
*/
WPropGroup m_clipPlaneGroup;
/**
* Property for en-/disable clipping.
*/
WPropBool m_clipPlaneEnabled;
/**
* Point on the plane. Defines the plane.
*/
WPropPosition m_clipPlanePoint;
/**
* Vector of the plane. Defines the plane.
*/
WPropPosition m_clipPlaneVector;
/**
* Distance from plane. Used as threshold.
*/
WPropDouble m_clipPlaneDistance;
/**
* Uniform for plane point.
*/
osg::ref_ptr< WGEPropertyUniform< WPropPosition > > m_clipPlanePointUniform;
/**
* Uniform for plane vector.
*/
osg::ref_ptr< WGEPropertyUniform< WPropPosition > > m_clipPlaneVectorUniform;
/**
* Uniform for plane distance.
*/
osg::ref_ptr< WGEPropertyUniform< WPropDouble > > m_clipPlaneDistanceUniform;
};
#endif // WMFIBERDISPLAYSIMPLE_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/>.
//
//---------------------------------------------------------------------------
#version 120
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
/**
* The distance to the plane
*/
varying float dist;
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
/**
* The max distance allowed
*/
uniform float u_distance = 1.0;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////
/**
* Main entry point of the fragment shader.
*/
void main()
{
// discard fragment if too far from plane
if ( abs( dist ) >= u_distance )
{
discard;
}
gl_FragColor = gl_Color;
gl_FragDepth = gl_FragCoord.z;
}
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#version 120
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
/**
* The distance to the plane
*/
varying float dist;
/////////////////////////////////////////////////////////////////////////////
// Uniforms
/////////////////////////////////////////////////////////////////////////////
/**
* A point on the plane.
*/
uniform vec3 u_planePoint;
/**
* The normal vector of the plane
*/
uniform vec3 u_planeVector;
/////////////////////////////////////////////////////////////////////////////
// Attributes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////
/**
* Main entry point of the vertex shader.
*/
void main()
{
// define the plane
vec3 n = normalize( u_planeVector );
float d = dot( u_planePoint, n );
dist = dot( gl_Vertex.xyz, n ) - d;
// Simply project the vertex
gl_Position = ftransform();
gl_FrontColor = gl_Color;
}
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