Commit 50538b83 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] Optional Input for selective coloring to the TriangleMesh vertices

parent a55f2602
......@@ -4,5 +4,6 @@ FILE( GLOB COMMON_DATASTRUCTURES_SRC "*.cpp" "*.h" )
IF( OW_COMPILE_TESTS )
CXXTEST_ADD_TESTS_FROM_LIST( "${COMMON_DATASTRUCTURES_SRC}"
"common" # no libs for linking required
"WColoredVertices.cpp" # is just an container, no logic to test
)
ENDIF( OW_COMPILE_TESTS )
//---------------------------------------------------------------------------
//
// 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 <map>
#include <boost/shared_ptr.hpp>
#include "WColoredVertices.h"
// init _static_ member variable and provide a linker reference to it
boost::shared_ptr< WPrototyped > WColoredVertices::m_prototype = boost::shared_ptr< WPrototyped >();
boost::shared_ptr< WPrototyped > WColoredVertices::getPrototype()
{
if ( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WColoredVertices() );
}
return m_prototype;
}
WColoredVertices::WColoredVertices()
{
}
WColoredVertices::WColoredVertices( const std::map< size_t, WColor >& data )
: m_data( data )
{
}
WColoredVertices::~WColoredVertices()
{
}
//---------------------------------------------------------------------------
//
// 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 WCOLOREDVERTICES_H
#define WCOLOREDVERTICES_H
#include <map>
#include <string>
#include "../WTransferable.h"
#include "../WColor.h"
/**
* Represents a std::map where for each vertex ID a color is stored.
*/
class WColoredVertices : public WTransferable
{
public:
/**
* Default constructor.
*/
WColoredVertices();
/**
* Initialize this with the given map.
*
* \param data The map
*/
explicit WColoredVertices( const std::map< size_t, WColor >& data );
/**
* Cleans up this instance.
*/
virtual ~WColoredVertices();
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual const std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual const std::string getDescription() const;
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static boost::shared_ptr< WPrototyped > getPrototype();
/**
* Reference to the data.
*
* \return Reference to the map of ids and colors.
*/
const std::map< size_t, WColor >& getData() const;
/**
* Replace (copies) the internal data with the given one.
*
* \param data The ID-Color map
*/
void setData( const std::map< size_t, WColor >& data );
protected:
static boost::shared_ptr< WPrototyped > m_prototype; //!< The prototype as singleton.
private:
std::map< size_t, WColor > m_data; //!< stores the vertex ids and colors
};
inline const std::string WColoredVertices::getName() const
{
return "WColoredVertices";
}
inline const std::string WColoredVertices::getDescription() const
{
return "Represents a std::map where for each vertex ID a color is stored.";
}
inline const std::map< size_t, WColor >& WColoredVertices::getData() const
{
return m_data;
}
inline void WColoredVertices::setData( const std::map< size_t, WColor >& data )
{
m_data = data;
}
#endif // WCOLOREDVERTICES_H
......@@ -23,14 +23,15 @@
//---------------------------------------------------------------------------
#include <string>
#include <map>
#include <osg/LightModel>
#include "../../kernel/WKernel.h"
#include "../../common/datastructures/WTriangleMesh.h"
#include "WMTriangleMeshRenderer.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "../../kernel/WKernel.h"
#include "trianglemeshrenderer.xpm"
#include "WMTriangleMeshRenderer.h"
WMTriangleMeshRenderer::WMTriangleMeshRenderer():
WModule(),
......@@ -68,11 +69,17 @@ const std::string WMTriangleMeshRenderer::getDescription() const
void WMTriangleMeshRenderer::connectors()
{
m_input = boost::shared_ptr< WModuleInputData < WTriangleMesh > >(
new WModuleInputData< WTriangleMesh >( shared_from_this(), "in", "The mesh to display" )
m_meshInput = boost::shared_ptr< WModuleInputData < WTriangleMesh > >(
new WModuleInputData< WTriangleMesh >( shared_from_this(), "mesh", "The mesh to display" )
);
addConnector( m_input );
addConnector( m_meshInput );
m_colorMapInput = boost::shared_ptr< WModuleInputData < WColoredVertices > >(
new WModuleInputData< WColoredVertices >( shared_from_this(), "colorMap", "The special colors" )
);
addConnector( m_colorMapInput );
// call WModules initialization
WModule::connectors();
......@@ -87,7 +94,8 @@ void WMTriangleMeshRenderer::moduleMain()
{
// let the main loop awake if the data changes or the properties changed.
m_moduleState.setResetable( true, true );
m_moduleState.add( m_input->getDataChangedCondition() );
m_moduleState.add( m_meshInput->getDataChangedCondition() );
m_moduleState.add( m_colorMapInput->getDataChangedCondition() );
// signal ready state
ready();
......@@ -107,7 +115,7 @@ void WMTriangleMeshRenderer::moduleMain()
break;
}
// invalid data
boost::shared_ptr< WTriangleMesh > mesh = m_input->getData();
boost::shared_ptr< WTriangleMesh > mesh = m_meshInput->getData();
if ( !mesh )
{
debugLog() << "Invalid Data. Disabling.";
......@@ -163,18 +171,35 @@ void WMTriangleMeshRenderer::renderMesh( boost::shared_ptr< WTriangleMesh > mesh
// ------------------------------------------------
// colors
osg::Vec4Array* colors = new osg::Vec4Array;
osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
boost::shared_ptr< WColoredVertices > colorMap = m_colorMapInput->getData();
if( !colorMap )
{
colors->push_back( osg::Vec4( .9f, .9f, 0.9f, 1.0f ) );
surfaceGeometry->setColorArray( colors );
surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
}
else
{
for( size_t i = 0; i < mesh->getNumVertices(); ++i )
{
colors->push_back( osg::Vec4( .9f, .9f, 0.9f, 1.0f ) );
}
for( std::map< size_t, WColor >::const_iterator vc = colorMap->getData().begin(); vc != colorMap->getData().end(); ++vc )
{
colors->at( vc->first ) = wge::osgColor( vc->second );
}
colors->push_back( osg::Vec4( .9f, .9f, 0.9f, 1.0f ) );
surfaceGeometry->setColorArray( colors );
surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
surfaceGeometry->setColorArray( colors );
surfaceGeometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
}
osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel();
lightModel->setTwoSided( true );
state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
m_moduleNode->insert( m_surfaceGeode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_moduleNode );
}
......
......@@ -29,6 +29,7 @@
#include <osg/Geode>
#include "../../common/datastructures/WColoredVertices.h"
#include "../../graphicsEngine/WGEGroupNode.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
......@@ -113,7 +114,8 @@ private:
/**
* An input connector used to get mehses from other modules. The connection management between connectors must not be handled by the module.
*/
boost::shared_ptr< WModuleInputData< WTriangleMesh > > m_input;
boost::shared_ptr< WModuleInputData< WTriangleMesh > > m_meshInput;
boost::shared_ptr< WModuleInputData< WColoredVertices > > m_colorMapInput; //!< for each vertex ID in that container a special color is given.
osg::ref_ptr< WGEGroupNode > m_moduleNode; //!< Pointer to the modules group node.
......
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