Commit 1fa0699b authored by Tobias Neeb's avatar Tobias Neeb
Browse files

Merge branch 'main' into '736-triangular-tf-widget'

[MERGE 736]

See merge request openwalnut/openwalnut!11
parents 758439d4 3513d8a8
......@@ -11,9 +11,7 @@
<td style="padding:10px; background:#ddd;">
<h3>Version Information</h3>
This is %OW_VERSION%. You can check out the
<a href="http://redmine.openwalnut.org/projects/openwalnut/wiki/ReleaseNotes">Release Notes</a> and the
<a href="http://redmine.openwalnut.org/versions/2">Changelog</a> for detailled information on fixed bugs, new features and other
improvements.
<a href="https://bsvgit.informatik.uni-leipzig.de/openwalnut/openwalnut/-/wikis/ReleaseNotes">Release Notes</a> for detailed information on fixed bugs, new features and other improvements.
</td>
</tr>
<tr>
......@@ -29,17 +27,13 @@
<br>
We provide
<ul>
<li> <a href="http://redmine.openwalnut.org/projects/openwalnut/wiki/FirstSteps">a first steps tutorial</a>,
<li> <a href="https://bsvgit.informatik.uni-leipzig.de/openwalnut/openwalnut/-/wikis/FirstSteps">a first steps tutorial</a>,
<li> a user documentation,
<li> programming tutorials,
<li> and the latest information on OpenWalnut.
</ul>
Do you have problems using OpenWalnut? Do not hesitate to ask:
<ul>
<li><a href="mailto:openwalnut@lists.informatik.uni-leipzig.de">Mailing list</a>
<li>IRC Chat on irc.freenode.net, channel #ow
</ul>
Found a bug? Do you have ideas for improvements? Please <a href="http://redmine.openwalnut.org/projects/openwalnut/wiki/Contribute">report</a> these issues! We can improve OpenWalnut only with your help and ideas.
Do you have problems using OpenWalnut? Do not hesitate to ask: <a href="mailto:openwalnut@lists.informatik.uni-leipzig.de">Mailing list</a>.
Found a bug? Do you have ideas for improvements? Please <a href="https://bsvgit.informatik.uni-leipzig.de/openwalnut/openwalnut/-/wikis/contribute">report</a> these issues! We can improve OpenWalnut only with your help and ideas.
<br><br>
<i>Thank you for using OpenWalnut!</i>
</td>
......
......@@ -163,6 +163,10 @@ void WGEColormapping::applyInst( NodeList nodes, WMatrix4d preTransform, osg::re
info->m_rebind = true;
info->m_texUnitStart = startTexUnit;
info->m_preTransform = preTransform;
// If the node is already in the map it needs to be erased first as insert does not overwrite and thus not rebind the texture.
// instead of this it may be better for modules to remove their nodes => less memory consumption
m_nodeInfo.erase( *i );
m_nodeInfo.insert( std::make_pair( *i, info ) );
( *i )->addUpdateCallback( new WGEFunctorCallback< osg::Node >( boost::bind( &WGEColormapping::callback, this, boost::placeholders::_1 ) ) );
......
......@@ -48,6 +48,7 @@
#include "WGraphicsEngine.h"
#include "WMouseLocationHandler.h"
#include "WPickHandler.h"
#include "WPickHandler3D.h"
#include "core/common/WConditionOneShot.h"
#include "core/common/WLogger.h"
#include "core/common/WThreadedRunner.h"
......@@ -93,6 +94,7 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
{
case( WGECamera::ORTHOGRAPHIC ):
m_pickHandler = new WPickHandler( name );
m_pickHandler3D = new WPickHandler3D();
m_View->addEventHandler( m_pickHandler );
if( name != std::string( "Main View" ) )
break;
......@@ -268,6 +270,11 @@ osg::ref_ptr< WPickHandler > WGEViewer::getPickHandler()
return m_pickHandler;
}
osg::ref_ptr< WPickHandler3D > WGEViewer::getPickHandler3D()
{
return m_pickHandler3D;
}
osg::ref_ptr< WMouseLocationHandler > WGEViewer::getMouseLocationHandler()
{
return m_mouseLocationHandler;
......
......@@ -54,6 +54,7 @@
class WGEGroupNode;
#include "WGEScreenCapture.h"
class WPickHandler;
class WPickHandler3D;
class WMouseLocationHandler;
#include "animation/WGEAnimationManipulator.h"
......@@ -217,6 +218,14 @@ public:
*/
osg::ref_ptr< WPickHandler > getPickHandler();
/**
* Getter for the 3D pick handler
* This is for the virtual reality handling
*
* \return the pick handler
*/
osg::ref_ptr< WPickHandler3D > getPickHandler3D();
/**
* Getter for the mouse loection handler
*
......@@ -353,6 +362,11 @@ protected:
*/
osg::ref_ptr<WPickHandler> m_pickHandler;
/**
* Pointer to the 3D pick handler of the viewer.
*/
osg::ref_ptr<WPickHandler3D> m_pickHandler3D;
/**
* Pointer to the mouse location handler of the viewer.
*/
......
//---------------------------------------------------------------------------
//
// 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 "WPickHandler3D.h"
const std::string WPickHandler3D::unpickString = "unpick";
WPickHandler3D::WPickHandler3D() :
m_hitResultLeft( WPickInfo3D() ),
m_hitResultRight( WPickInfo3D() ),
m_startPickLeft( WPickInfo3D() ),
m_startPickRight( WPickInfo3D() )
{
}
void WPickHandler3D::unpickLeft()
{
if( m_hitResultLeft != WPickInfo3D() )
{
m_hitResultLeft = WPickInfo3D( WPickHandler3D::unpickString );
m_startPickLeft = WPickInfo3D();
}
m_pickSignal( std::make_pair( getHitResultLeft(), getHitResultRight() ) );
}
void WPickHandler3D::unpickRight()
{
if( m_hitResultRight != WPickInfo3D() )
{
m_hitResultRight = WPickInfo3D( WPickHandler3D::unpickString );
m_startPickRight = WPickInfo3D();
}
m_pickSignal( std::make_pair( getHitResultLeft(), getHitResultRight() ) );
}
std::string extractSuitableName( osgUtil::RayIntersector::Intersections::iterator hitr )
{
if( !hitr->nodePath.empty() && !( hitr->nodePath.back()->getName().empty() ) )
{
return hitr->nodePath.back()->getName();
}
else if( hitr->drawable.valid() )
{
return hitr->drawable->className();
}
assert( 0 && "This should not happen. Tell \"wiebel\" if it does." );
return ""; // This line will not be reached.
}
WPickInfo3D createPickInfo( osg::Camera* camera, WPickInfo3D startPick, osg::Vec3 position, osg::Quat rotation, int buttons )
{
osg::Vec3 dir = rotation * osg::Vec3( 0.0, 1.0, 0.0 );
osg::Vec3 pos = position;
if( buttons == WPickInfo3D::NONE )
{
return WPickInfo3D( "nothing", position, rotation, buttons );
}
osgUtil::RayIntersector::Intersections intersections;
osg::ref_ptr< osgUtil::RayIntersector > picker = new osgUtil::RayIntersector( pos, dir );
osgUtil::IntersectionVisitor iv( picker.get() );
camera->accept( iv );
bool intersectionsExist = picker->containsIntersections();
WPickInfo3D pickInfo;
WPickInfo3D fullPathpickInfo;
bool startPickIsStillInList = false;
osgUtil::RayIntersector::Intersections::iterator hitr;
if( intersectionsExist )
{
intersections = picker->getIntersections();
hitr = intersections.begin();
while( hitr != intersections.end() )
{
std::string nodeName = extractSuitableName( hitr );
fullPathpickInfo.appendToPickPath( nodeName );
++hitr;
}
assert( intersections.size() );
hitr = intersections.begin();
while( hitr != intersections.end() )
{
std::string nodeName = extractSuitableName( hitr );
WAssert( nodeName.size() > 2, "Geode name too short for picking." );
// now we skip everything that starts with an underscores or vr
if( nodeName[0] == '_' || ( nodeName[0] == 'v' && nodeName[1] == 'r' ) )
{
++hitr;
}
else
{
break;
}
}
if( hitr == intersections.end() )
{
if( startPick.empty() )
{
return WPickInfo3D( "nothing", position, rotation, buttons );
}
}
if( !startPick.empty() && startPick.getName() != WPickHandler3D::unpickString )
{
while( ( hitr != intersections.end() ) && !startPickIsStillInList )
{
WPickInfo3D pickInfoTmp( extractSuitableName( hitr ) );
startPickIsStillInList |= ( pickInfoTmp.getName() == startPick.getName() );
if( !startPickIsStillInList )
{
++hitr;
}
}
}
}
else
{
if( startPick.empty() )
{
return WPickInfo3D( "nothing", position, rotation, buttons );
}
}
if( startPickIsStillInList || ( intersectionsExist && ( startPick.getName() == WPickHandler3D::unpickString || startPick.empty() ) ) )
{
WPosition pickPos;
pickPos[0] = hitr->getWorldIntersectPoint()[0];
pickPos[1] = hitr->getWorldIntersectPoint()[1];
pickPos[2] = hitr->getWorldIntersectPoint()[2];
WVector3d pickNormal;
const osgUtil::RayIntersector::Intersection::IndexList& vil = hitr->indexList;
osg::ref_ptr< osg::Geometry > geo = dynamic_cast< osg::Geometry* >( hitr->drawable.get() );
if( geo )
{
float* normals = ( float* ) geo->getNormalArray()->getDataPointer();
int vertexIdx = vil[0];
pickNormal[0] = normals[vertexIdx * 3];
pickNormal[1] = normals[vertexIdx * 3 + 1];
pickNormal[2] = normals[vertexIdx * 3 + 2];
}
pickInfo = WPickInfo3D( extractSuitableName( hitr ), position, rotation, buttons, pickPos, pickNormal );
}
if( !startPickIsStillInList && !startPick.empty() && startPick.getName() != WPickHandler3D::unpickString )
{
pickInfo = WPickInfo3D( startPick.getName(), position, rotation, buttons,
startPick.getPickPosition(), startPick.getPickNormal(), startPick.getPickPath() );
}
pickInfo.setPickPath( fullPathpickInfo.getPickPath() );
return pickInfo;
}
WPickInfo3D WPickHandler3D::getHitResultLeft()
{
return m_hitResultLeft;
}
WPickInfo3D WPickHandler3D::getHitResultRight()
{
return m_hitResultRight;
}
boost::signals2::signal< void( std::pair< WPickInfo3D, WPickInfo3D > ) >* WPickHandler3D::getPickSignal()
{
return &m_pickSignal;
}
void WPickHandler3D::pick( osg::Camera* camera,
osg::Vec3 leftPosition,
osg::Vec3 rightPosition,
osg::Quat leftRotation,
osg::Quat rightRotation,
int leftButtons,
int rightButtons )
{
WPickInfo3D oldLeft = m_hitResultLeft;
WPickInfo3D oldRight = m_hitResultRight;
m_hitResultLeft = createPickInfo( camera, m_startPickLeft, leftPosition, leftRotation, leftButtons );
if( m_startPickLeft.empty() )
{
m_startPickLeft = m_hitResultLeft;
}
m_hitResultRight = createPickInfo( camera, m_startPickRight, rightPosition, rightRotation, rightButtons );
if( m_startPickRight.empty() )
{
m_startPickRight = m_hitResultRight;
}
if( oldLeft.getButtons() != WPickInfo3D::NONE && leftButtons == WPickInfo3D::NONE )
{
unpickLeft();
}
if( oldRight.getButtons() != WPickInfo3D::NONE && rightButtons == WPickInfo3D::NONE )
{
unpickRight();
}
m_pickSignal( std::make_pair( getHitResultLeft(), getHitResultRight() ) );
}
//---------------------------------------------------------------------------
//
// 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 WPICKHANDLER3D_H
#define WPICKHANDLER3D_H
#include <string>
#include <utility>
#include <boost/signals2/signal.hpp>
#include <osgUtil/RayIntersector>
#include <osgViewer/View>
#include "WPickInfo3D.h"
/**
* Class to handle events with a pick in 3D.
*
* The handler ignores any geometry whose name starts with an underscore ("_").
*/
class WPickHandler3D : public osg::Referenced
{
public:
/**
* Constructor that initalizes members with sensible defaults.
*/
WPickHandler3D();
/**
* Call this when picking in 3D.
* \param camera The camera that the pick was done through.
* \param leftPosition The position of the left controller.
* \param rightPosition The position of the right controller.
* \param leftRotation The rotation of the left controller.
* \param rightRotation The rotation of the right controller.
* \param leftButtons The pressed buttons on the left controller.
* \param rightButtons The pressed buttons on the right controller.
*/
void pick( osg::Camera* camera,
osg::Vec3 leftPosition,
osg::Vec3 rightPosition,
osg::Quat leftRotation,
osg::Quat rightRotation,
int leftButtons,
int rightButtons );
/**
* Send a pick signal with the unpickString for the left controller
*/
void unpickLeft();
/**
* Send a pick signal with the unpickString for the right controller
*/
void unpickRight();
/**
* Gives information about the picked object on the left controller.
*
* \return info object for this hit
*/
WPickInfo3D getHitResultLeft();
/**
* Gives information about the picked object on the right controller.
*
* \return info object for this hit
*/
WPickInfo3D getHitResultRight();
/**
* \return the m_pickSignal to for registering to it.
*/
boost::signals2::signal< void( std::pair< WPickInfo3D, WPickInfo3D > ) >* getPickSignal();
static const std::string unpickString; //!< The string indicating picking has stopped.
private:
boost::signals2::signal< void( std::pair< WPickInfo3D, WPickInfo3D > ) > m_pickSignal; //!< Register to this signal to receive pick events.
WPickInfo3D m_hitResultLeft; //!< The info for the left hit.
WPickInfo3D m_hitResultRight; //!< The info for the right hit.
WPickInfo3D m_startPickLeft; //!< Where the left side was picked first.
WPickInfo3D m_startPickRight; //!< Where the right side was picked first.
};
#endif // WPICKHANDLER3D_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 "WPickInfo3D.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 WPICKINFO3D_H
#define WPICKINFO3D_H
#include <string>
#include <osg/Vec3>
#include <osg/Quat>
#include "../common/math/linearAlgebra/WVectorFixed.h"
#include "../common/math/linearAlgebra/WPosition.h"
/**
* Encapsulates the data for the 3D pick.
*/
class WPickInfo3D
{
public:
/**
* Different button types
*/
typedef enum
{
NONE = 0x0,
TRIGGER = 0x1,
GRIP = 0x2
}
WVRButton;
/**
* Creates an object with the needed information.
* \param name The name of the picked object.
* \param position The position of the controller.
* \param rotation The rotation of the controller.
* \param buttons The controller buttons.
* \param pickPosition The position of the pick.
* \param pickNormal The normal of the picked surface.
* \param pickPath The path of the pick.
*/
inline WPickInfo3D( std::string name,
osg::Vec3 position = osg::Vec3(),
osg::Quat rotation = osg::Quat(),
int buttons = WVRButton::NONE,
WPosition pickPosition = WPosition(),
WVector3d pickNormal = WVector3d(),
std::string pickPath = "" );
/**
* Creates an empty object.
*/
inline WPickInfo3D();
/**
* Get name of picked object.
*
* \return object name
*/
inline std::string getName() const;
/**
* Get name of all picked objects in ray.
*
* \return Names
*/
inline std::string getPickPath() const;
/**
* Gets the position of the controller.
*
* \return The position
*/
inline osg::Vec3 getPosition() const;
/**
* Gets the rotation of the controller.
*
* \return The rotation
*/
inline osg::Quat getRotation() const;
/**
* Gets the pressed buttons
*
* \return The buttons
*/
inline int getButtons() const;
/**
* Get position where object was hit.
*
* \return the pick position
*/
inline WPosition getPickPosition() const;
/**
* Get normal at position where object was hit.
*
* \return pick normal
*/
inline WVector3d getPickNormal() const;