Commit b4bec1d0 authored by André Reichenbach's avatar André Reichenbach
Browse files

changed WMDatasetManipulator to a more general implementation, still needs osg manipulators added

parent 8e612e85
......@@ -27,29 +27,30 @@
#include <string>
#include <osg/Geode>
#include "core/graphicsEngine/WROISphere.h"
#include "core/dataHandler/WDataSet.h"
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
#include "core/common/WStrategyHelper.h"
#include "core/common/WObjectNDIP.h"
/**
* Module allowing manipulation of the dataset properties via manipulators in the 3D scene.
* Module allowing manipulation of the dataset scaling, orientation and position.
*
* \ingroup modules
*/
class WMDatasetManipulator: public WModule
class WMDatasetManipulator : public WModule
{
public:
/**
*
* Constructor.
*/
WMDatasetManipulator();
/**
*
* Destructor.
*/
virtual ~WMDatasetManipulator();
......@@ -95,181 +96,44 @@ protected:
*/
virtual void properties();
private:
/**
* initializes the manipulator and other settings
*/
void init();
/**
* Removes the knobs and cleans up.
*/
void shutdown();
/**
* reacts to movements of the manipulator knobs
*/
void manipulatorMoved();
/**
* reacts to movements of the manipulator knobs
*/
void manipulatorRotMoved();
/**
* function move manipulators to new positions when they are affected by other operations, like translate
* or rotate
*/
void adjustManipulatorPositions();
/**
* locks the manipulators depending on resize or rotation mode
* Init the matrix to be applied from the transformations stored in the current dataset.
*/
void setManipulatorMode();
void initMatrix();
/**
* sets the manipulator positions unsing the bounding box
*/
void setManipulatorsFromBoundingBox();
/**
* Notify the module of an update of the transform.
* Transform the data using the provided transformation matrix.
*
* \param mat The Transform to apply.
*
* \return The new and transformed dataset.
*/
void notifyChanged();
boost::shared_ptr< WDataSet > transformData( WMatrixFixed< double, 4, 4 > const& mat );
/**
* A condition used to notify about changes in several properties.
*/
//! A condition for property updates.
boost::shared_ptr< WCondition > m_propCondition;
/**
* True if the manipulator spheres should be shown
*/
WPropBool m_showManipulators;
/**
* Toggles between resize and rotation mode
*/
WPropBool m_rotationMode;
boost::shared_ptr< boost::function< void() > > m_changeRotRoiSignal; //!< Signal that can be used to update the rotation manipulator
boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the translation manipulator
osg::ref_ptr<WROISphere> m_knobCenter; //!< stores pointer to the center manipulator
osg::ref_ptr<WROISphere> m_knobx1; //!< stores pointer to manipulator 1
osg::ref_ptr<WROISphere> m_knobx2; //!< stores pointer to manipulator 2
osg::ref_ptr<WROISphere> m_knoby1; //!< stores pointer to manipulator 1
osg::ref_ptr<WROISphere> m_knoby2; //!< stores pointer to manipulator 2
osg::ref_ptr<WROISphere> m_knobz1; //!< stores pointer to manipulator 1
osg::ref_ptr<WROISphere> m_knobz2; //!< stores pointer to manipulator 2
WPosition m_posCenter; //!< stores the old position of the manipulator
WPosition m_posx1; //!< stores the old position of the manipulator
WPosition m_posx2; //!< stores the old position of the manipulator
WPosition m_posy1; //!< stores the old position of the manipulator
WPosition m_posy2; //!< stores the old position of the manipulator
WPosition m_posz1; //!< stores the old position of the manipulator
WPosition m_posz2; //!< stores the old position of the manipulator
//! A trigger to reset the current transformation to the initial one.
WPropTrigger m_resetTrigger;
WPosition m_posCenterOrig; //!< stores the old position of the manipulator
WPosition m_posx1Orig; //!< stores the old position of the manipulator
WPosition m_posx2Orig; //!< stores the old position of the manipulator
WPosition m_posy1Orig; //!< stores the old position of the manipulator
WPosition m_posy2Orig; //!< stores the old position of the manipulator
WPosition m_posz1Orig; //!< stores the old position of the manipulator
WPosition m_posz2Orig; //!< stores the old position of the manipulator
//! A trigger to add the transformation from the currently active strategy to the current transformation.
WPropTrigger m_applyTrigger;
osg::ref_ptr<WROISphere> m_knobRotCenter; //!< stores pointer to the center manipulator
osg::ref_ptr<WROISphere> m_knobRot; //!< stores pointer to manipulator 1
WPosition m_posRotCenter; //!< stores the old position of the manipulator
WPosition m_posRot; //!< stores the old position of the manipulator
WPosition m_posRotCenterOrig; //!< stores the old position of the manipulator
WPosition m_posRotOrig; //!< stores the old position of the manipulator
/**
* An input connector that accepts order 1 datasets.
*/
boost::shared_ptr< WModuleInputData< WDataSetSingle > > m_input;
/**
* An output connector for the output scalar dsataset.
*/
boost::shared_ptr< WModuleOutputData< WDataSetSingle > > m_output;
/**
* This is a pointer to the dataset the module is currently working on.
*/
boost::shared_ptr< WDataSetSingle > m_dataSet;
/**
* stores a pointer to the grid we use;
*/
boost::shared_ptr< WGridRegular3D > m_grid;
/**
* grouping the texture manipulation properties
*/
WPropGroup m_groupTexManip;
/**
* translation of the texture
*/
WPropInt m_translationX;
/**
* translation of the texture
*/
WPropInt m_translationY;
/**
* translation of the texture
*/
WPropInt m_translationZ;
/**
* voxel size in x direction
*/
WPropDouble m_stretchX;
/**
* voxel size in y direction
*/
WPropDouble m_stretchY;
/**
* voxel size in z direction
*/
WPropDouble m_stretchZ;
/**
* rotation around the x axis
*/
WPropInt m_rotationX;
/**
* rotation around the y axis
*/
WPropInt m_rotationY;
/**
* rotation around the z axis
*/
WPropInt m_rotationZ;
//! The current data.
boost::shared_ptr< WDataSet > m_data;
//! The grid's transformation.
boost::shared_ptr< WGridTransformOrtho > m_transform;
//! The current transformation.
WMatrixFixed< double, 4, 4 > m_currentMat;
//! Whether the output connector should be updated.
bool m_updated;
//! An input connector that accepts any dataset.
boost::shared_ptr< WModuleInputData< WDataSet > > m_input;
//! A condition that gets notified when any changes were made to the transformation.
boost::shared_ptr< WCondition > m_transformChangedCondition;
//! An output connector for the transformed dataset.
boost::shared_ptr< WModuleOutputData< WDataSet > > m_output;
//! A mutex for changes to members of this module.
boost::mutex m_updateMutex;
//! The strategy to use for dataset transformation manipulation.
WStrategyHelper< WObjectNDIP< WManipulatorInterface > > m_strategy;
};
#endif // WMDATASETMANIPULATOR_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 "WManipulatorInterface.h"
WManipulatorInterface::~WManipulatorInterface()
{
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 WMANIPULATORINTERFACE_H
#define WMANIPULATORINTERFACE_H
#include "core/common/math/linearAlgebra/WMatrixFixed.h"
/**
* An interface for dataset transformation manipulators.
*/
class WManipulatorInterface
{
public:
/**
* Destructor.
*/
virtual ~WManipulatorInterface();
/**
* Get the transformation matrix from this manipulator.
*
* \return The current transform.
*/
virtual WMatrixFixed< double, 4, 4 > getTransformationMatrix() const = 0;
/**
* Check if the transform has changed, for example because of a change to properties.
*
* \return true, iff the transformation has changed.
*/
virtual bool transformationChanged() const = 0;
/**
* Reset the transform.
*/
virtual void reset() = 0;
};
#endif // WMANIPULATORINTERFACE_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 <Eigen/Dense>
#include "core/common/math/WMath.h"
#include "WManipulatorRotation.h"
WManipulatorRotation::WManipulatorRotation()
: WObjectNDIP< WManipulatorInterface >( "Rotation", "Rotates the dataset." )
{
m_axis = m_properties->addProperty( "Rotation axis", "Axis to rotate around in world coordinates.", WPosition( 0.0, 0.0, 1.0 ) );
m_angle = m_properties->addProperty( "Rotation angle", "The angle to rotate.", 0.0 );
m_angle->setMin( 0.0 );
m_angle->setMax( 2.0 * piDouble );
}
WManipulatorRotation::~WManipulatorRotation()
{
}
WMatrixFixed< double, 4, 4 > WManipulatorRotation::getTransformationMatrix() const
{
WPosition w = m_axis->get( true );
Eigen::Vector3d v( w[ 0 ], w[ 1 ], w[ 2 ] );
Eigen::AngleAxisd aa( m_angle->get( true ), v );
WMatrixFixed< double, 4, 4 > mat = WMatrixFixed< double, 4, 4 >::identity();
for( std::size_t i = 0; i < 3; ++i )
{
for( std::size_t j = 0; j < 3; ++j )
{
mat( i, j ) = aa.toRotationMatrix()( i, j );
}
}
return mat;
}
bool WManipulatorRotation::transformationChanged() const
{
return m_angle->changed() || m_axis->changed();
}
void WManipulatorRotation::reset()
{
m_angle->set( 0.0, false );
m_axis->set( WPosition( 0.0, 0.0, 1.0 ), false );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 WMANIPULATORROTATION_H
#define WMANIPULATORROTATION_H
#include "core/common/WObjectNDIP.h"
#include "WManipulatorInterface.h"
/**
* A manipulator for rotating a dataset around an axis in the world coordinate system.
*/
class WManipulatorRotation : public WObjectNDIP< WManipulatorInterface >
{
public:
/**
* Constructor.
*/
WManipulatorRotation();
/**
* Destructor.
*/
virtual ~WManipulatorRotation();
/**
* Get the transformation matrix from this manipulator.
*
* \return The current transform.
*/
virtual WMatrixFixed< double, 4, 4 > getTransformationMatrix() const;
/**
* Check if the transform has changed, for example because of a change to properties.
*
* \return true, iff the transformation has changed.
*/
virtual bool transformationChanged() const;
/**
* Reset the transform.
*/
virtual void reset();
private:
//! The axis to rotate around in world coordinates.
WPropPosition m_axis;
//! The angle to rotate.
WPropDouble m_angle;
};
#endif // WMANIPULATORROTATION_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 "WManipulatorScaling.h"
WManipulatorScaling::WManipulatorScaling()
: WObjectNDIP< WManipulatorInterface >( "Scaling", "Scales the dataset." )
{
m_scaling = m_properties->addProperty( "Scale", "Scale of the data.", WPosition( 1.0, 1.0, 1.0 ) );
}
WManipulatorScaling::~WManipulatorScaling()
{
}
WMatrixFixed< double, 4, 4 > WManipulatorScaling::getTransformationMatrix() const
{
WMatrixFixed< double, 4, 4 > m = WMatrixFixed< double, 4, 4 >::identity();
WPosition s = m_scaling->get( true );
m( 0, 0 ) = s[ 0 ];
m( 1, 1 ) = s[ 1 ];
m( 2, 2 ) = s[ 2 ];
return m;
}
bool WManipulatorScaling::transformationChanged() const
{
return m_scaling->changed();
}
void WManipulatorScaling::reset()
{
m_scaling->set( WPosition( 1.0, 1.0, 1.0 ) );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 WMANIPULATORSCALING_H
#define WMANIPULATORSCALING_H
#include "core/common/WObjectNDIP.h"
#include "WManipulatorInterface.h"
/**
* A manipulator to scale datasets in world coords.
*/
class WManipulatorScaling : public WObjectNDIP< WManipulatorInterface >
{
public:
/**
* Constructor.
*/
WManipulatorScaling();
/**
* Destructor.
*/
virtual ~WManipulatorScaling();
/**
* Get the transformation matrix from this manipulator.
*
* \return The current transform.
*/
virtual WMatrixFixed< double, 4, 4 > getTransformationMatrix() const;
/**
* Check if the transform has changed, for example because of a change to properties.
*
* \return true, iff the transformation has changed.
*/
virtual bool transformationChanged() const;