Commit 57a122a8 authored by Jan Möbius's avatar Jan Möbius

Added the plugin collection for selection



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15691 383ad7c9-94d9-4d36-a494-682f7c89f535
parents
include (plugin)
openflipper_plugin (INSTALLDATA Icons)
This diff is collapsed.
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper 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 with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper 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 LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//================================================================
//
// CLASS SplatCloudObjectSelectionPlugin
//
//================================================================
#ifndef SPLATCLOUDOBJECTSELECTIONPLUGIN_HH
#define SPLATCLOUDOBJECTSELECTIONPLUGIN_HH
//== INCLUDES ====================================================
#include <QObject>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/SelectionInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/INIInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/INIFile/INIFile.hh>
#include <ObjectTypes/SplatCloud/SplatCloud.hh>
//== CLASS DEFINITION ============================================
class SplatCloudObjectSelectionPlugin : public QObject, BaseInterface, BackupInterface, LoggingInterface, SelectionInterface, LoadSaveInterface, INIInterface, KeyInterface, ScriptInterface
{
Q_OBJECT
Q_INTERFACES( BaseInterface )
Q_INTERFACES( BackupInterface )
Q_INTERFACES( LoggingInterface )
Q_INTERFACES( SelectionInterface )
Q_INTERFACES( LoadSaveInterface )
Q_INTERFACES( INIInterface )
Q_INTERFACES( KeyInterface )
Q_INTERFACES( ScriptInterface )
public:
/// Default constructor
SplatCloudObjectSelectionPlugin() : vertexType_( 0 ), allSupportedTypes_( 0 ) { }
friend class SelectVolumeAction;
signals:
//-- Base Interface --
void updateView();
void updatedObject( int _objectId, const UpdateType& _type );
void nodeVisibilityChanged( int _objectId );
void setSlotDescription( QString _slotName, QString _slotDescription, QStringList _parameters, QStringList _descriptions );
//-- Backup Interface --
void createBackup( int _objectId, QString _name, UpdateType _type = UPDATE_ALL );
//-- Logging Interface --
void log( QString _message );
void log( Logtype _type, QString _message );
//-- Selection Interface --
void addSelectionEnvironment( QString _modeName, QString _description, QIcon _icon, QString &_handleName );
void registerType( QString _handleName, DataType _type );
void addPrimitiveType( QString _handleName, QString _name, QIcon _icon, SelectionInterface::PrimitiveType &_typeHandle );
void addSelectionOperations( QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u );
void showToggleSelectionMode ( QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes );
void showSphereSelectionMode ( QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes );
void showLassoSelectionMode ( QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes );
void showVolumeLassoSelectionMode( QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes );
void getActiveDataTypes( SelectionInterface::TypeList &_types );
void getActivePrimitiveType( SelectionInterface::PrimitiveType &_type );
void targetObjectsOnly( bool &_targetsOnly );
void registerKeyShortcut( int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier );
//-- LoadSave Interface --
void deleteObject( int _objectId );
//-- Script Interface --
void scriptInfo( QString _functionName );
public slots:
//-- Selection Interface --
void loadSelection( int _objectId, const QString &_filename );
private slots:
//-- INI Interface --
void loadIniFile( INIFile &_ini, int _objectId );
void saveIniFile( INIFile &_ini, int _objectId );
//-- Base Interface --
void initializePlugin();
void pluginsInitialized();
void noguiSupported() { };
//-- Selection Interface --
void slotSelectionOperation( QString _operation );
void slotToggleSelection ( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect );
void slotSphereSelection ( QMouseEvent *_event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect );
void slotLassoSelection ( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect );
void slotVolumeLassoSelection( QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect );
void slotLoadSelection( const INIFile &_file );
void slotSaveSelection( INIFile &_file );
void slotKeyShortcutEvent( int _key, Qt::KeyboardModifiers _modifiers );
public:
//-- Base Interface --
QString name() { return QString( tr("SplatCloud Object Selection" ) ); }
QString description() { return QString( tr("Allows to select parts of SplatCloud Objects") ); }
//===========================================================================
/** @name Private methods
* @{ */
//===========================================================================
private:
/// Set descriptions for local public slots
void updateSlotDescriptions();
/// Set color for selection
void setColorForSelection( const int _objectId, const PrimitiveType _primitiveType );
/** @} */
//===========================================================================
/** @name Private slots
* @{ */
//===========================================================================
private slots:
/** @} */
public slots:
QString version() { return QString( "1.0" ); }
// Is vertex type active? (for use in plugins that need SplatCloud selection)
bool vertexTypeActive()
{
SelectionInterface::PrimitiveType t;
emit getActivePrimitiveType( t );
return (t & vertexType_) > 0;
}
//===========================================================================
/** @name Scriptable slots
* @{ */
//===========================================================================
public slots:
//==========================================
// VERTEX OPERATIONS
//==========================================
void selectVertices ( int _objectId, IdList _vertexList ); //!< Select given vertices
void unselectVertices ( int _objectId, IdList _vertexList ); //!< Unselect given vertices
void selectAllVertices ( int _objectId ); //!< Select all vertices
void clearVertexSelection ( int _objectId ); //!< Unselect all vertices
void invertVertexSelection ( int _objectId ); //!< Invert the current vertex selection
IdList getVertexSelection ( int _objectId ); //!< Return a list of all selected vertices
void deleteVertexSelection ( int _objectId ); //!< Delete vertices that are currently selected
void colorizeVertexSelection( int _objectId, int _r, int _g, int _b, int _a ); //!< Colorize the vertex selection
//===========================================================================
void lassoSelect( QRegion &_region, PrimitiveType _primitiveType, bool _deselection ); //!< Lasso selection tool
/** @} */
//===========================================================================
/** @name Template Functions
* @{ */
//===========================================================================
private:
bool splatCloudDeleteSelection ( SplatCloud *_splatCloud, PrimitiveType _primitiveType ); //!< Delete all selected elements of a SplatCloud
void splatCloudToggleSelection ( SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, PrimitiveType _primitiveType ); //!< Toggle SplatCloud selection
void splatCloudSphereSelection ( SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, double _radius, PrimitiveType _primitiveTypes, bool _deselection ); //!< Use the event to paint selection with a sphere
bool splatCloudVolumeSelection ( SplatCloud *_splatCloud, ACG::GLState &_state, QRegion *_region, PrimitiveType _primitiveTypes, bool _deselection ); //!< Surface volume selection tool
void splatCloudColorizeSelection ( SplatCloud *_splatCloud, PrimitiveType _primitiveTypes, int _r, int _g, int _b, int _a ); //!< Colorize the selection
/** @} */
//===========================================================================
/** @name Member variables
* @{ */
//===========================================================================
private:
QString environmentHandle_; //!< Handle to selection environment
SelectionInterface::PrimitiveType vertexType_; //!< Primitive type handle
SelectionInterface::PrimitiveType allSupportedTypes_; //!< Primitive type handle
QPolygon lasso_2Dpoints_; //!< Used for lasso selection tool
QVector<QPoint> volumeLassoPoints_; //!< Used for volume lasso tool
/** @} */
};
/// Traverse the scenegraph and call the selection function for all SplatCloud nodes
class SelectVolumeAction
{
public:
SelectVolumeAction( QRegion &_region, SplatCloudObjectSelectionPlugin *_plugin, unsigned int _type, bool _deselection, ACG::GLState &_state ) :
state_ ( _state ),
region_ ( _region ),
plugin_ ( _plugin ),
type_ ( _type ),
deselection_( _deselection )
{ }
void enter( BaseNode * /*_node*/ ) { }
void leave( BaseNode * /*_node*/ ) { }
bool operator()( BaseNode *_node );
private:
ACG::GLState &state_;
QRegion &region_;
SplatCloudObjectSelectionPlugin *plugin_;
unsigned int type_;
bool deselection_;
};
//================================================================
#endif // SPLATCLOUDOBJECTSELECTIONPLUGIN_HH
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper 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 with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper 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 LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//================================================================
//
// CLASS SplatCloudObjectSelectionPlugin - IMPLEMENTATION (continued)
//
//================================================================
//== INCLUDES ====================================================
#include "SplatCloudObjectSelectionPlugin.hh"
#include "SplatCloudSelection.hh"
#include <set>
//== IMPLEMENTATION ==============================================
/** \brief Delete all selected elements of a SplatCloud
*
* @param _splatCloud a SplatCloud
* @param _primitiveType bitmask of active primitive types
* @return returns true if the SplatCloud was changed (i.e there was something selected that was deleted)
*/
bool SplatCloudObjectSelectionPlugin::splatCloudDeleteSelection( SplatCloud *_splatCloud, PrimitiveType _primitiveType )
{
if( (_primitiveType & vertexType_) == 0 )
return false; // done
if( _splatCloud == 0 )
return false; // error
unsigned int numDeleted = _splatCloud->eraseSplatsByIndex( SplatCloudSelection::getVertexSelection( _splatCloud ) );
return (numDeleted != 0);
}
//----------------------------------------------------------------
/** \brief Toggle the selection state of SplatCloud primitives
*
* @param _splatCloud a SplatCloud
* @param _index index of vertex that was picked
* @param _hit_point point that was picked
* @param _primitiveType primitive types to be selected
*/
void SplatCloudObjectSelectionPlugin::splatCloudToggleSelection( SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, PrimitiveType _primitiveType )
{
if( (_primitiveType & vertexType_) == 0 )
return; // done
if( _splatCloud == 0 )
return; // error
if( /*(_index < 0) ||*/ (_index >= _splatCloud->numSplats()) )
return; // error
if( !_splatCloud->hasSelections() )
{
if( !_splatCloud->requestSelections() )
return; // error
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = false;
}
_splatCloud->selections( _index ) = !_splatCloud->selections( _index );
if( _splatCloud->selections( _index ) )
emit scriptInfo( "selectVertices(ObjectId , [" + QString::number( _index ) + "])" );
else
emit scriptInfo( "unselectVertices(ObjectId , [" + QString::number( _index ) + "])" );
}
//----------------------------------------------------------------
/** \brief paint selection with a sphere
*
* @param _splatCloud a SplatCloud
* @param _index index of vertex that was picked
* @param _hit_point point that was picked
* @param _radius selection sphere radius
* @param _primitiveType primitive types to be selected
* @param _deselection true, if entities should be deselected
*/
void SplatCloudObjectSelectionPlugin::splatCloudSphereSelection( SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, double _radius, PrimitiveType _primitiveType, bool _deselection )
{
if( (_primitiveType & vertexType_) == 0 )
return; // done
if( _splatCloud == 0 )
return; // error
if( /*(_index < 0) ||*/ (_index >= _splatCloud->numSplats()) )
return; // error
if( !_splatCloud->hasPositions() )
return; // error
if( !_splatCloud->hasSelections() )
{
if( _deselection )
return; // done
if( !_splatCloud->requestSelections() )
return; // error
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = false;
}
if( _radius < 0.0 )
return; // done
double sqrRadius = _radius * _radius;
SplatCloud::Selection selection = !_deselection;
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
const SplatCloud::Position &pos = _splatCloud->positions( i );
double dx = pos[0] - _hit_point[0];
double dy = pos[1] - _hit_point[1];
double dz = pos[2] - _hit_point[2];
double sqrDist = dx*dx + dy*dy + dz*dz;
if( sqrDist <= sqrRadius )
_splatCloud->selections( i ) = selection;
}
}
//----------------------------------------------------------------
/** \brief Select all primitves that are projected to the given region
*
* @param _splatCloud a SplatCloud
* @param _state current gl state
* @param _region region
* @param _primitiveType primitive types to be selected
* @param _deselection true, if entities should be deselected
* @return true, if something was selected
*/
bool SplatCloudObjectSelectionPlugin::splatCloudVolumeSelection( SplatCloud *_splatCloud, ACG::GLState &_state, QRegion *_region, PrimitiveType _primitiveType, bool _deselection )
{
if( (_primitiveType & vertexType_) == 0 )
return false; // done
if( _splatCloud == 0 )
return false; // error
if( !_splatCloud->hasPositions() )
return false; // error
bool modify = true;
if( !_splatCloud->hasSelections() )
{
if( _deselection )
{
modify = false;
}
else
{
if( !_splatCloud->requestSelections() )
return false; // error
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = false;
}
}
bool rv = false;
SplatCloud::Selection selection = !_deselection;
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
const SplatCloud::Position &pos = _splatCloud->positions( i );
ACG::Vec3d proj = _state.project( ACG::Vec3d( pos[0], pos[1], pos[2] ) );
if( _region->contains( QPoint( (int) proj[0], _state.context_height() - (int) proj[1] ) ) )
{
if( modify )
_splatCloud->selections( i ) = selection;
rv = true;
}
}
return rv;
}
//----------------------------------------------------------------
/** \brief Colorize a selection
*
* @param _splatCloud a SplatCloud
* @param _primitiveTypes selection types
* @param _r red rgba color-component
* @param _g green rgba color-component
* @param _b blue rgba color-component
* @param _a blue rgba color-component
*/
void SplatCloudObjectSelectionPlugin::splatCloudColorizeSelection( SplatCloud *_splatCloud, PrimitiveType _primitiveTypes, int _r, int _g, int _b, int _a )
{
if( (_primitiveTypes & vertexType_) == 0 )
return; // done
if( _splatCloud == 0 )
return; // error
if( !_splatCloud->hasColors() )
{
if( !_splatCloud->requestColors() )
return; // error
SplatCloud::Color black( 0, 0, 0 );
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->colors( i ) = black;
}
if( !_splatCloud->hasSelections() )
return; // done
unsigned char r = (_r < 0) ? 0 : (_r > 255) ? 255 : (unsigned char) _r;
unsigned char g = (_g < 0) ? 0 : (_g > 255) ? 255 : (unsigned char) _g;
unsigned char b = (_b < 0) ? 0 : (_b > 255) ? 255 : (unsigned char) _b;
SplatCloud::Color color( r, g, b ); // drop alpha
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections( i ) )
_splatCloud->colors( i ) = color;
}
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper 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 with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper 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 LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *