SplatCloudObjectSelectionPlugin.hh 13.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*===========================================================================*\
 *                                                                           *
 *                              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$                   *
 *                                                                           *
\*===========================================================================*/

Jan Möbius's avatar
   
Jan Möbius committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//================================================================
//
//  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
{
80
81
82
83
84
85
86
87
88
  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    )
Jan Möbius's avatar
   
Jan Möbius committed
89
90

public:
91
92
  /// Default constructor
  SplatCloudObjectSelectionPlugin() : vertexType_( 0 ), allSupportedTypes_( 0 ) { }
Jan Möbius's avatar
   
Jan Möbius committed
93

94
  friend class SelectVolumeAction;
Jan Möbius's avatar
   
Jan Möbius committed
95
96
97

signals:

98
99
100
101
102
  //-- 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 );
Jan Möbius's avatar
   
Jan Möbius committed
103

104
105
  //-- Backup Interface --
  void createBackup( int _objectId, QString _name, UpdateType _type = UPDATE_ALL );
Jan Möbius's avatar
   
Jan Möbius committed
106

107
108
109
  //-- Logging Interface --
  void log(                QString _message );
  void log( Logtype _type, QString _message );
Jan Möbius's avatar
   
Jan Möbius committed
110

111
112
113
114
115
  //-- 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 );
Jan Möbius's avatar
   
Jan Möbius committed
116

117
118
119
120
  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 );
Jan Möbius's avatar
   
Jan Möbius committed
121

122
123
124
  void getActiveDataTypes( SelectionInterface::TypeList &_types );
  void getActivePrimitiveType( SelectionInterface::PrimitiveType &_type );
  void targetObjectsOnly( bool &_targetsOnly );
Jan Möbius's avatar
   
Jan Möbius committed
125

126
  void registerKeyShortcut( int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier );
Jan Möbius's avatar
   
Jan Möbius committed
127

128
129
  //-- LoadSave Interface --
  void deleteObject( int _objectId );
Jan Möbius's avatar
   
Jan Möbius committed
130

131
132
  //-- Script Interface --
  void scriptInfo( QString _functionName );
Jan Möbius's avatar
   
Jan Möbius committed
133
134
135

public slots:

136
137
  //-- Selection Interface --
  void loadSelection( int _objectId, const QString &_filename );
Jan Möbius's avatar
   
Jan Möbius committed
138
139
140

private slots:

141
142
143
  //-- INI Interface --
  void loadIniFile( INIFile &_ini, int _objectId );
  void saveIniFile( INIFile &_ini, int _objectId );
Jan Möbius's avatar
   
Jan Möbius committed
144

145
146
147
148
  //-- Base Interface --
  void initializePlugin();
  void pluginsInitialized();
  void noguiSupported() { };
Jan Möbius's avatar
   
Jan Möbius committed
149

150
151
  //-- Selection Interface --
  void slotSelectionOperation( QString _operation );
Jan Möbius's avatar
   
Jan Möbius committed
152

153
154
155
156
  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 );
Jan Möbius's avatar
   
Jan Möbius committed
157

158
159
  void slotLoadSelection( const INIFile &_file );
  void slotSaveSelection(       INIFile &_file );
Jan Möbius's avatar
   
Jan Möbius committed
160

161
  void slotKeyShortcutEvent( int _key, Qt::KeyboardModifiers _modifiers );
Jan Möbius's avatar
   
Jan Möbius committed
162
163
164

public:

165
166
167
  //-- Base Interface --
  QString name()        { return QString( tr("SplatCloud Object Selection"                 ) ); }
  QString description() { return QString( tr("Allows to select parts of SplatCloud Objects") ); }
Jan Möbius's avatar
   
Jan Möbius committed
168

169
170
171
172
  //===========================================================================
  /** @name Private methods
  * @{ */
  //===========================================================================
Jan Möbius's avatar
   
Jan Möbius committed
173
174
private:

175
176
  /// Set descriptions for local public slots
  void updateSlotDescriptions();
Jan Möbius's avatar
   
Jan Möbius committed
177

178
179
  /// Set color for selection
  void setColorForSelection( const int _objectId, const PrimitiveType _primitiveType );
Jan Möbius's avatar
   
Jan Möbius committed
180

181
  /** @} */
Jan Möbius's avatar
   
Jan Möbius committed
182

183
184
185
186
  //===========================================================================
  /** @name Private slots
  * @{ */
  //===========================================================================
Jan Möbius's avatar
   
Jan Möbius committed
187
188
private slots:

189
  /** @} */
Jan Möbius's avatar
   
Jan Möbius committed
190
191
192

public slots:

193
  QString version() { return QString( "1.0" ); }
Jan Möbius's avatar
   
Jan Möbius committed
194

195
196
197
198
199
200
201
  // Is vertex type active? (for use in plugins that need SplatCloud selection)
  bool vertexTypeActive()
  {
    SelectionInterface::PrimitiveType t;
    emit getActivePrimitiveType( t );
    return (t & vertexType_) > 0;
  }
Jan Möbius's avatar
   
Jan Möbius committed
202

203
204
205
206
  //===========================================================================
  /** @name Scriptable slots
  * @{ */
  //===========================================================================
Jan Möbius's avatar
   
Jan Möbius committed
207
208
public slots:

209
210
211
  //==========================================
  // VERTEX OPERATIONS
  //==========================================
Jan Möbius's avatar
   
Jan Möbius committed
212

213
214
215
216
217
218
219
220
  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
Jan Möbius's avatar
   
Jan Möbius committed
221

222
  //===========================================================================
Jan Möbius's avatar
   
Jan Möbius committed
223

224
  void lassoSelect( QRegion &_region, PrimitiveType _primitiveType, bool _deselection ); //!< Lasso selection tool
Jan Möbius's avatar
   
Jan Möbius committed
225

226
  /** @} */
Jan Möbius's avatar
   
Jan Möbius committed
227

228
229
230
231
  //===========================================================================
  /** @name Template Functions
  * @{ */
  //===========================================================================
Jan Möbius's avatar
   
Jan Möbius committed
232
233
234

private:

235
236
237
238
239
  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
Jan Möbius's avatar
   
Jan Möbius committed
240

241
  /** @} */
Jan Möbius's avatar
   
Jan Möbius committed
242

243
244
245
246
  //===========================================================================
  /** @name Member variables
  * @{ */
  //===========================================================================
Jan Möbius's avatar
   
Jan Möbius committed
247
248
249

private:

250
251
252
253
254
  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
Jan Möbius's avatar
   
Jan Möbius committed
255

256
  /** @} */
Jan Möbius's avatar
   
Jan Möbius committed
257
258
259
260
261
262
263
264
};


/// Traverse the scenegraph and call the selection function for all SplatCloud nodes
class SelectVolumeAction
{
public:

265
  SelectVolumeAction( QRegion &_region, SplatCloudObjectSelectionPlugin *_plugin, unsigned int _type, bool _deselection, ACG::GLState &_state ) : 
266
267
268
269
270
271
    state_      ( _state       ),
    region_     ( _region      ),
    plugin_     ( _plugin      ),
    type_       ( _type        ),
    deselection_( _deselection )
  { }
Jan Möbius's avatar
   
Jan Möbius committed
272

273
274
  void enter( BaseNode * /*_node*/ ) { }
  void leave( BaseNode * /*_node*/ ) { }
Jan Möbius's avatar
   
Jan Möbius committed
275

276
  bool operator()( BaseNode *_node );
Jan Möbius's avatar
   
Jan Möbius committed
277
278

private:
279
280
281
282
283
  ACG::GLState                    &state_;
  QRegion                         &region_;
  SplatCloudObjectSelectionPlugin *plugin_;
  unsigned int                    type_;
  bool                            deselection_;
Jan Möbius's avatar
   
Jan Möbius committed
284
285
286
287
288
289
290
};


//================================================================


#endif // SPLATCLOUDOBJECTSELECTIONPLUGIN_HH