Commit 8c078e55 authored by Alexander Wiebel's avatar Alexander Wiebel

[CHANGE] the ROI boxes are now available throuh WROIBox and are only use by

WMPrototypeBoxManipulation for testing. This will be droppen when the boxes
are working in WFioberDisplay
parent 93e2bf36
//---------------------------------------------------------------------------
//
// 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 "WROI.h"
#include "WPickHandler.h"
WROI::~WROI()
{
}
//---------------------------------------------------------------------------
//
// 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 WROI_H
#define WROI_H
#include <string>
#include <osg/Geode>
#include "../common/WColor.h"
class WPickHandler;
/**
* Superclass for different ROI (region of interest) types.
*/
class WROI
{
public:
/**
* Need virtual destructor because of virtual function.
*/
virtual ~WROI();
protected:
osg::ref_ptr< WPickHandler > m_pickHandler; //!< A pointer to the pick handler used to get gui events for moving the box.
osg::Geode* m_geode; //!< The graphical representation of the ROI.
private:
bool m_isNot; //!< Indivated whether the region of interest is inside the WROI (false) oroutside (true).
bool m_isModified; //!< Indicates whether a changed ROI has already taken effect. Means: if true, still some updates needed.
WColor m_color; //!< The selected onject (Fibers, region on surface, ...) will have this color if m_useColor.
bool m_useColor; //!< Indicated whether m_color should be used for display.
/**
* updates the graphics
* \param text text info from pick
*/
virtual void updateGFX( std::string text ) = 0;
};
#endif // WROI_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 <string>
#include <osg/LineWidth>
#include <osg/LightModel>
#include "WROIBox.h"
#include "../kernel/WKernel.h"
size_t WROIBox::maxBoxId = 0;
void buildFacesFromPoints( osg::DrawElementsUInt* surfaceElements )
{
surfaceElements->push_back( 0 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 0 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 0 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 2 );
}
void buildLinesFromPoints( osg::DrawElementsUInt* surfaceElements )
{
surfaceElements->push_back( 0 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 0 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 0 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 5 );
}
void setVertices( osg::Vec3Array* vertices, wmath::WPosition minPos, wmath::WPosition maxPos )
{
vertices->push_back( osg::Vec3( minPos[0], minPos[1], minPos[2] ) );
vertices->push_back( osg::Vec3( minPos[0], minPos[1], maxPos[2] ) );
vertices->push_back( osg::Vec3( minPos[0], maxPos[1], minPos[2] ) );
vertices->push_back( osg::Vec3( minPos[0], maxPos[1], maxPos[2] ) );
vertices->push_back( osg::Vec3( maxPos[0], minPos[1], minPos[2] ) );
vertices->push_back( osg::Vec3( maxPos[0], minPos[1], maxPos[2] ) );
vertices->push_back( osg::Vec3( maxPos[0], maxPos[1], minPos[2] ) );
vertices->push_back( osg::Vec3( maxPos[0], maxPos[1], maxPos[2] ) );
}
WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
WROI(),
boxId( maxBoxId++ )
{
m_minPos = minPos;
m_maxPos = maxPos;
// connect updateGFX with picking
boost::shared_ptr< WGEViewer > viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" );
assert( viewer );
m_pickHandler = viewer->getPickHandler();
m_pickHandler->getPickSignal()->connect( boost::bind( &WROIBox::updateGFX, this, _1 ) );
osg::Geometry* surfaceGeometry = new osg::Geometry();
m_geode = new osg::Geode;
std::stringstream ss;
ss << "ROIBox" << boxId;
m_geode->setName( ss.str() );
std::cout << "..." << m_geode->getName() << std::endl;
osg::Vec3Array* vertices = new osg::Vec3Array;
setVertices( vertices, minPos, maxPos );
surfaceGeometry->setVertexArray( vertices );
osg::DrawElementsUInt* surfaceElements;
surfaceElements = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
buildFacesFromPoints( surfaceElements );
osg::DrawElementsUInt* lineElements;
lineElements = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
buildLinesFromPoints( lineElements );
surfaceGeometry->addPrimitiveSet( surfaceElements );
surfaceGeometry->addPrimitiveSet( lineElements );
m_geode->addDrawable( surfaceGeometry );
osg::StateSet* state = m_geode->getOrCreateStateSet();
state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
osg::LineWidth* linewidth = new osg::LineWidth();
linewidth->setWidth( 2.f );
state->setAttributeAndModes( linewidth, osg::StateAttribute::ON );
// ------------------------------------------------
// colors
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back( osg::Vec4( .0f, .0f, 1.f, 0.5f ) );
surfaceGeometry->setColorArray( colors );
surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
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 );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_geode );
}
WROIBox::WROIBox()
{
}
wmath::WPosition WROIBox::getMinPos() const
{
return m_minPos;
}
wmath::WPosition WROIBox::getMaxPos() const
{
return m_maxPos;
}
void WROIBox::updateGFX( std::string text )
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
std::stringstream ss;
ss << "\"ROIBox" << boxId << "\"";
std::cout << text << std::endl;
if( text.find( "Object ") != std::string::npos
&& text.find( ss.str() ) != std::string::npos )
{
wmath::WPosition newPos( m_pickHandler->getHitPosition() );
if( m_isPicked )
{
wmath::WVector3D moveVec = m_pickedPosition - newPos;
osg::Vec3Array* vertices = new osg::Vec3Array;
m_minPos -= moveVec;
m_maxPos -= moveVec;
setVertices( vertices, m_minPos, m_maxPos );
((osg::Geometry*)(m_geode->getDrawable( 0 )))->setVertexArray( vertices );
}
else
{
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back( osg::Vec4( 1.f, .0f, .0f, 0.5f ) );
((osg::Geometry*)(m_geode->getDrawable( 0 )))->setColorArray( colors );
}
m_pickedPosition = newPos;
m_isPicked = true;
}
if( m_isPicked && text.find( "unpick" ) != std::string::npos )
{
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back( osg::Vec4( 0.f, 0.f, 1.f, 0.5f ) );
((osg::Geometry*)(m_geode->getDrawable( 0 )))->setColorArray( colors );
m_isPicked = false;
}
slock.unlock();
}
//---------------------------------------------------------------------------
//
// 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 WROIBOX_H
#define WROIBOX_H
#include <string>
#include <boost/thread.hpp>
#include "../math/WPosition.h"
#include "WPickHandler.h"
#include "WROI.h"
/**
* A box representing a region of interest.
*/
class WROIBox : public WROI
{
public:
/**
* Yields box with desired extremal points minPos and maxPos
*/
WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos );
/**
* Yields minimal box with both extremal points minPos and maxPos at the origin.
*/
WROIBox();
/**
* Get the corner of the box that has minimal x, y and z values
*/
wmath::WPosition getMinPos() const;
/**
* Get the corner of the box that has maximal x, y and z values
*/
wmath::WPosition getMaxPos() const;
protected:
private:
static size_t maxBoxId; //!< Current macimum boxId over all boxes.
size_t boxId; //!< Id of the current box.
wmath::WPosition m_minPos; //!< The minimum position of the box
wmath::WPosition m_maxPos; //!< The maximum position of the box
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 cmoparison
boost::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node
/**
* updates the graphics
* \param text text info from pick
*/
virtual void updateGFX( std::string text );
};
#endif // WROIBOX_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/>.
//
//---------------------------------------------------------------------------
#ifndef WROIBOX_TEST_H
#define WROIBOX_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WROIBox.h"
/**
* TODO(wiebel): Document this!
*/
class WROIBoxTest : public CxxTest::TestSuite
{
public:
/**
* TODO(wiebel): Document this!
*/
void testSomething( void )
{
}
};
#endif // WROIBOX_TEST_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/>.
//
//---------------------------------------------------------------------------
#ifndef WROI_TEST_H
#define WROI_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WROI.h"
/**
* TODO(wiebel): Document this!
*/
class WROITest : public CxxTest::TestSuite
{
public:
/**
* TODO(wiebel): Document this!
*/
void testSomething( void )
{
}
};
#endif // WROI_TEST_H
......@@ -41,20 +41,17 @@
#include <osg/PolygonMode>
#include <osg/LightModel>
#include <osg/LineWidth>
#include <osgDB/WriteFile>
#include "../../utils/WStringUtils.h"
#include "../../math/WVector3D.h"
#include "../../math/WPosition.h"
#include "../../kernel/WKernel.h"
#include "../../graphicsEngine/WShader.h"
#include "../../graphicsEngine/WROIBox.h"
#include "../data/WMData.h"
WMPrototypeBoxManipulation::WMPrototypeBoxManipulation():
WModule(),
m_isPicked( false )
WModule()
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
......@@ -86,22 +83,15 @@ void WMPrototypeBoxManipulation::moduleMain()
{
// use the m_input "data changed" flag
m_moduleState.add( m_input->getDataChangedCondition() );
WKernel::getRunningKernel()->getGui()->getPickSignal()->connect( boost::bind( &WMPrototypeBoxManipulation::updateGFX, this, _1 ) );
// connect updateGFX with picking
boost::shared_ptr< WGEViewer > viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" );
assert( viewer );
m_pickHandler = viewer->getPickHandler();
m_pickHandler->getPickSignal()->connect( boost::bind( &WMPrototypeBoxManipulation::updateGFX, this, _1 ) );
// signal ready state
ready();
m_ROI = boost::shared_ptr< WROIBox >( new WROIBox( wmath::WPosition(), wmath::WPosition( 30., 30., 30 ) ) );
// loop until the module container requests the module to quit
while ( !m_shutdownFlag() )
{
draw( wmath::WPosition( 30, 30, 30 ), wmath::WPosition( 70, 70, 70 ) );
// this waits for m_moduleState to fire. By default, this is only the m_shutdownFlag condition.
// NOTE: you can add your own conditions to m_moduleState using m_moduleState.add( ... )
m_moduleState.wait();
......@@ -132,14 +122,6 @@ void WMPrototypeBoxManipulation::slotPropertyChanged( std::string propertyName )
{
if( propertyName == "active" )
{
if ( m_properties->getValue<bool>( propertyName ) )
{
m_geode->setNodeMask( 0xFFFFFFFF );
}
else
{
m_geode->setNodeMask( 0x0 );
}
}
else
{
......@@ -147,165 +129,3 @@ void WMPrototypeBoxManipulation::slotPropertyChanged( std::string propertyName )
assert( 0 && "This property name is not supported by this function yet." );
}
}
void buildFacesFromPoints( osg::DrawElementsUInt* surfaceElements )
{
surfaceElements->push_back( 0 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 0 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 0 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 2 );
}
void buildLinesFromPoints( osg::DrawElementsUInt* surfaceElements )
{
surfaceElements->push_back( 0 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 0 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 5 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 2 );
surfaceElements->push_back( 6 );
surfaceElements->push_back( 7 );
surfaceElements->push_back( 3 );
surfaceElements->push_back( 4 );
surfaceElements->push_back( 0 );
surfaceElements->push_back( 1 );
surfaceElements->push_back( 5 );
}
void setVertices( osg::Vec3Array* vertices, wmath::WPosition minPos, wmath::WPosition maxPos )
{
vertices->push_back( osg::Vec3( minPos[0], minPos[1], minPos[2] ) );
vertices->push_back( osg::Vec3( minPos[0], minPos[1], maxPos[2] ) );
vertices->push_back( osg::Vec3( minPos[0], maxPos[1], minPos[2] ) );
vertices->push_back( osg::Vec3( minPos[0], maxPos[1], maxPos[2] ) );
vertices->push_back( osg::Vec3( maxPos[0], minPos[1], minPos[2] ) );
vertices->push_back( osg::Vec3( maxPos[0], minPos[1], maxPos[2] ) );
vertices->push_back( osg::Vec3( maxPos[0], maxPos[1], minPos[2] )