Commit a7ef1a85 authored by Dirk Albrecht's avatar Dirk Albrecht

[ADD] TubeGeometry

parent bbb9c5eb
//---------------------------------------------------------------------------
//
// 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 <vector>
#include "../../../dataHandler/WDataSetFibers.h"
#include "../../../kernel/WKernel.h"
#include "WTubeGeometry.h"
WTubeGeometry::WTubeGeometry() : osg::Geometry()
{
}
// I can't say much about the methods below, but OSG seems to expect
// that we implement them.
WTubeGeometry::WTubeGeometry( const WTubeGeometry& /*pg*/, const osg::CopyOp& /*copyop*/ ):
osg::Geometry()
{
}
osg::Object* WTubeGeometry::cloneType() const
{
return new WTubeGeometry();
}
osg::Object* WTubeGeometry::clone( const osg::CopyOp& copyop ) const
{
return new WTubeGeometry( *this, copyop );
}
void WTubeGeometry::setDataset( boost::shared_ptr< const WDataSetFibers > dataset )
{
m_dataset = dataset;
}
void WTubeGeometry::setStartIndices( boost::shared_ptr< std::vector< size_t > > startIndices )
{
m_startIndices = startIndices;
}
void WTubeGeometry::setViewPortUniform( osg::ref_ptr<osg::Uniform> uniformViewportHeight, osg::ref_ptr<osg::Uniform> uniformViewportWidth )
{
m_uniformViewportHeight = uniformViewportHeight;
m_uniformViewportWidth = uniformViewportWidth;
}
void WTubeGeometry::drawImplementation( osg::RenderInfo& renderInfo ) const
{
if ( _internalOptimizedGeometry.valid() )
{
_internalOptimizedGeometry->drawImplementation( renderInfo );
return;
}
osg::State& state = *renderInfo.getState();
bool checkForGLErrors = state.getCheckForGLErrors() == osg::State::ONCE_PER_ATTRIBUTE;
if (checkForGLErrors) state.checkGLErrors( "start of Geometry::drawImplementation()" );
bool useFastPath = areFastPathsUsed();
useFastPath = false;
bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
bool handleVertexAttributes = !_vertexAttribList.empty();
osg::ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
arrayDispatchers.reset();
arrayDispatchers.setUseVertexAttribAlias(useFastPath && state.getUseVertexAttributeAliasing());
arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath);
arrayDispatchers.activateNormalArray(_normalData.binding, _normalData.array.get(), _normalData.indices.get());
arrayDispatchers.activateColorArray(_colorData.binding, _colorData.array.get(), _colorData.indices.get());
arrayDispatchers.activateSecondaryColorArray(_secondaryColorData.binding, _secondaryColorData.array.get(), _secondaryColorData.indices.get());
arrayDispatchers.activateFogCoordArray(_fogCoordData.binding, _fogCoordData.array.get(), _fogCoordData.indices.get());
if (handleVertexAttributes)
{
for(unsigned int unit=0;unit<_vertexAttribList.size();++unit)
{
arrayDispatchers.activateVertexAttribArray(_vertexAttribList[unit].binding,
unit, _vertexAttribList[unit].array.get(), _vertexAttribList[unit].indices.get());
}
}
state.disableAllVertexArrays();
// dispatch any attributes that are bound overall
arrayDispatchers.dispatch(BIND_OVERALL,0);
state.lazyDisablingOfVertexAttributes();
// set up arrays
state.setVertexPointer( _vertexData.array.get() );
state.setNormalPointer( _normalData.array.get() );
state.setColorPointer( _colorData.array.get() );
for( unsigned int unit = 0; unit < _texCoordList.size(); ++unit )
{
const osg::Array* array = _texCoordList[unit].array.get();
if ( array ) state.setTexCoordPointer( unit, array );
}
for( unsigned int index = 0; index < _vertexAttribList.size(); ++index )
{
const osg::Array* array = _vertexAttribList[index].array.get();
const AttributeBinding ab = _vertexAttribList[index].binding;
if( ab == BIND_PER_VERTEX && array )
{
state.setVertexAttribPointer( index, array, _vertexAttribList[index].normalize );
}
}
state.applyDisablingOfVertexAttributes();
bool bindPerPrimitiveSetActive = arrayDispatchers.active(BIND_PER_PRIMITIVE_SET);
bool bindPerPrimitiveActive = arrayDispatchers.active(BIND_PER_PRIMITIVE);
unsigned int primitiveNum = 0;
if ( checkForGLErrors ) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup.");
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// draw the primitives themselves.
//
GLenum mode = _primitives[0].get()->getMode();
switch( mode )
{
case( GL_POINTS ):
{
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_VERTEX_PROGRAM_POINT_SIZE );
glEnable( GL_ALPHA_TEST );
glEnable( GL_POINT_SPRITE );
glAlphaFunc( GL_NOTEQUAL, 0.0 );
glTexEnvi( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
m_uniformViewportHeight->set( static_cast<int>( ( *renderInfo.getCurrentCamera()->getViewport() ).height() ) );
m_uniformViewportWidth->set( static_cast<int>( ( *renderInfo.getCurrentCamera()->getViewport() ).width() ) );
break;
}
case( GL_QUAD_STRIP ):
{
glDisable( GL_VERTEX_PROGRAM_POINT_SIZE );
glDisable( GL_POINT_SPRITE );
glEnable( GL_ALPHA_TEST );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glAlphaFunc( GL_NOTEQUAL, 0.0 );
break;
}
}
glEnable( GL_DEPTH_TEST );
glDisable( GL_LIGHTING );
glDisable( GL_BLEND );
boost::shared_ptr< std::vector< bool > > active = WKernel::getRunningKernel()->getRoiManager()->getBitField();
boost::shared_ptr< std::vector< size_t > > pointsPerLine = m_dataset->getLineLengths();
if ( useFastPath )
{
for( unsigned int primitiveSetNum = 0; primitiveSetNum != _primitives.size(); ++primitiveSetNum )
{
// dispatch any attributes that are bound per primitive
//if (bindPerPrimitiveSetActive) arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET, primitiveSetNum);
const osg::PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get();
primitiveset->draw( state, true );
}
}
else
{
for ( size_t i = 0; i < active->size(); ++i )
{
if( (*active)[i] )
{
switch( mode )
{
case( GL_POINTS ):
{
state.glDrawArraysInstanced( mode, m_startIndices->at( i ), ( *pointsPerLine )[i], 1);
break;
}
case( GL_QUAD_STRIP ):
{
state.glDrawArraysInstanced( mode, m_startIndices->at( i ), 2 * ( *pointsPerLine )[i], 1);
break;
}
}
}
}
}
// unbind the VBO's if any are used.
state.unbindVertexBufferObject();
state.unbindElementBufferObject();
state.disableVertexPointer();
state.disableColorPointer();
state.disableNormalPointer();
state.disableVertexAttribPointer( 0 );
}
//---------------------------------------------------------------------------
//
// 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 WTUBEGEOMETRY_H
#define WTUBEGEOMETRY_H
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>
#include <osg/Drawable>
#include <osg/ShapeDrawable>
#include <osg/Group>
#include <osg/Geometry>
#include "../../../graphicsEngine/WShader.h"
#include "../../WExportKernel.h"
class WDataSetFibers;
/**
* Module for drawing fibers
*
* \ingroup modules
*/
class OWKERNEL_EXPORT WTubeGeometry : public osg::Geometry
{
public:
WTubeGeometry();
/**
* I can't say much about the methods below, but OSG seems to expect
* that we implement them.
*
* \param pg
* \param copyop
*/
WTubeGeometry( const WTubeGeometry& pg, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY );
/**
* no clue why it's here and wehat it does
*/
virtual osg::Object* cloneType() const;
/**
* clones it
*
* \param copyop
*/
virtual osg::Object* clone( const osg::CopyOp& copyop ) const;
/** Draw Geometry directly ignoring an OpenGL display list which could be attached.
* This is the internal draw method which does the drawing itself,
* and is the method to override when deriving from Geometry for user-drawn objects.
* \param renderInfo
*/
virtual void drawImplementation( osg::RenderInfo& renderInfo ) const;
/**
* sets the uniforms to inform the shader about the viewport size
*
* \param uniformViewportHeight
* \param uniformViewportWidth
*/
void setViewPortUniform( osg::ref_ptr<osg::Uniform> uniformViewportHeight, osg::ref_ptr<osg::Uniform> uniformViewportWidth );
/**
* sets the dataset pointer which provides access to the necessary array
*
* \param dataset
*/
void setDataset( boost::shared_ptr< const WDataSetFibers > dataset );
boost::shared_ptr< const WDataSetFibers > m_dataset; //!< stores pointer to dataset
boost::shared_ptr< std::vector< size_t > > m_startIndices; //!< stores pointer to start indices
/**
* sets the start indices pointer for the start indices of the fibers
*
* \param startIndices
*/
void setStartIndices( boost::shared_ptr< std::vector< size_t > > startIndices );
osg::ref_ptr<osg::Uniform> m_uniformViewportHeight; //!< uniform to inform shader of viewport height
osg::ref_ptr<osg::Uniform> m_uniformViewportWidth; //!< uniform to inform shader of viewport width
};
#endif // WTUBEGEOMETRY_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