SplatCloudRenderingControlPlugin.cc 31.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
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
80
81
82
83
84
85
//================================================================
//
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2011 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: 12588 $                                                       *
*   $LastChangedBy: moebius $                                                *
*   $Date: 2011-10-13 12:41:04 +0200 (Do, 13 Okt 2011) $                     *
*                                                                            *
\*===========================================================================*/


//================================================================
//
//  CLASS SplatCloudRenderingControlPlugin - IMPLEMENTATION
//
//================================================================


//== INCLUDES ====================================================


#include "SplatCloudRenderingControlPlugin.hh"

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>

#include <ObjectTypes/SplatCloud/SplatCloud.hh>

#include <OpenFlipper/common/GlobalOptions.hh>


//== IMPLEMENTATION ==============================================


void SplatCloudRenderingControlPlugin::initializePlugin()
{
	// --------------------------------
	// -------- create toolbox --------
	// --------------------------------

	// ---- options ----

	// pointsizeScale
	toolboxPointsizeScale_ = new QDoubleSpinBox();
	toolboxPointsizeScale_->setRange( 0.0, 100.0 );
	toolboxPointsizeScale_->setDecimals( 4 );
	toolboxPointsizeScale_->setSingleStep( 0.1 );
	toolboxPointsizeScale_->setValue( 1.0 );

	// pointsizeScale layout
	QHBoxLayout *toolboxPointsizeScaleLayout = new QHBoxLayout();
	toolboxPointsizeScaleLayout->addWidget( new QLabel( "Pointsize Scale:" ) );
Jan Möbius's avatar
Jan Möbius committed
86
	toolboxPointsizeScaleLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
87
88
	toolboxPointsizeScaleLayout->addWidget( toolboxPointsizeScale_           );

89
90
91
92
93
94
	// buttons
	QPushButton *toolboxEnableBackfaceCullingButton  = new QPushButton( "Enable Backface Culling"  );
	QPushButton *toolboxDisableBackfaceCullingButton = new QPushButton( "Disable Backface Culling" );
	QPushButton *toolboxReloadShadersButton          = new QPushButton( "Reload Shaders"           );
	QPushButton *toolboxRebuildVBOsButton            = new QPushButton( "Rebuild VBOs"             );

Jan Möbius's avatar
Jan Möbius committed
95
96
97
98
99
100
101
	// buttons layout
	QGridLayout *toolboxButtonsLayout = new QGridLayout();
	toolboxButtonsLayout->setSpacing( 6 );
	toolboxButtonsLayout->addWidget( toolboxEnableBackfaceCullingButton,  0, 0 );
	toolboxButtonsLayout->addWidget( toolboxDisableBackfaceCullingButton, 0, 1 );
	toolboxButtonsLayout->addWidget( toolboxReloadShadersButton,          1, 0 );
	toolboxButtonsLayout->addWidget( toolboxRebuildVBOsButton,            1, 1 );
102
103
104

	// options layout
	QVBoxLayout *toolboxOptionsLayout = new QVBoxLayout();
Jan Möbius's avatar
Jan Möbius committed
105
	toolboxOptionsLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
106
	toolboxOptionsLayout->addItem  ( toolboxPointsizeScaleLayout );
Jan Möbius's avatar
Jan Möbius committed
107
108
	toolboxOptionsLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
	toolboxOptionsLayout->addItem  ( toolboxButtonsLayout        );
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

	// ---- defaults ----

	// defaultNormal
	toolboxDefaultNormalX_ = new QDoubleSpinBox();
	toolboxDefaultNormalY_ = new QDoubleSpinBox();
	toolboxDefaultNormalZ_ = new QDoubleSpinBox();
	toolboxDefaultNormalX_->setRange( -1.0, 1.0 );
	toolboxDefaultNormalY_->setRange( -1.0, 1.0 );
	toolboxDefaultNormalZ_->setRange( -1.0, 1.0 );
	toolboxDefaultNormalX_->setDecimals( 2 );
	toolboxDefaultNormalY_->setDecimals( 2 );
	toolboxDefaultNormalZ_->setDecimals( 2 );
	toolboxDefaultNormalX_->setSingleStep( 0.1 );
	toolboxDefaultNormalY_->setSingleStep( 0.1 );
	toolboxDefaultNormalZ_->setSingleStep( 0.1 );
	toolboxDefaultNormalX_->setValue( 0.0 );
	toolboxDefaultNormalY_->setValue( 0.0 );
	toolboxDefaultNormalZ_->setValue( 1.0 );

	// defaultNormal layout
	QHBoxLayout *toolboxDefaultNormalLayout = new QHBoxLayout();
	toolboxDefaultNormalLayout->addWidget( new QLabel( "Default Normal:" ) );
Jan Möbius's avatar
Jan Möbius committed
132
	toolboxDefaultNormalLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
133
	toolboxDefaultNormalLayout->addWidget( toolboxDefaultNormalX_          );
Jan Möbius's avatar
Jan Möbius committed
134
	toolboxDefaultNormalLayout->addItem  ( new QSpacerItem( 6, 6 )         );
135
	toolboxDefaultNormalLayout->addWidget( toolboxDefaultNormalY_          );
Jan Möbius's avatar
Jan Möbius committed
136
	toolboxDefaultNormalLayout->addItem  ( new QSpacerItem( 6, 6 )         );
137
138
139
140
141
142
143
144
145
146
147
148
	toolboxDefaultNormalLayout->addWidget( toolboxDefaultNormalZ_          );

	// defaultPointsize
	toolboxDefaultPointsize_ = new QDoubleSpinBox();
	toolboxDefaultPointsize_->setRange( 0.0, 1000.0 );
	toolboxDefaultPointsize_->setDecimals( 4 );
	toolboxDefaultPointsize_->setSingleStep( 0.001 );
	toolboxDefaultPointsize_->setValue( 0.01 );

	// defaultPointsize layout
	QHBoxLayout *toolboxDefaultPointsizeLayout = new QHBoxLayout();
	toolboxDefaultPointsizeLayout->addWidget( new QLabel( "Default Pointsize:" ) );
Jan Möbius's avatar
Jan Möbius committed
149
	toolboxDefaultPointsizeLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
	toolboxDefaultPointsizeLayout->addWidget( toolboxDefaultPointsize_           );

	// defaultColor
	toolboxDefaultColorR_ = new QSpinBox();
	toolboxDefaultColorG_ = new QSpinBox();
	toolboxDefaultColorB_ = new QSpinBox();
	toolboxDefaultColorR_->setRange( 0, 255 );
	toolboxDefaultColorG_->setRange( 0, 255 );
	toolboxDefaultColorB_->setRange( 0, 255 );
	toolboxDefaultColorR_->setSingleStep( 1 );
	toolboxDefaultColorG_->setSingleStep( 1 );
	toolboxDefaultColorB_->setSingleStep( 1 );
	toolboxDefaultColorR_->setValue( 255 );
	toolboxDefaultColorG_->setValue( 255 );
	toolboxDefaultColorB_->setValue( 255 );

	// defaultColor layout
	QHBoxLayout *toolboxDefaultColorLayout = new QHBoxLayout();
	toolboxDefaultColorLayout->addWidget( new QLabel( "Default Color:" ) );
Jan Möbius's avatar
Jan Möbius committed
169
	toolboxDefaultColorLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
170
	toolboxDefaultColorLayout->addWidget( toolboxDefaultColorR_          );
Jan Möbius's avatar
Jan Möbius committed
171
	toolboxDefaultColorLayout->addItem  ( new QSpacerItem( 6, 6 )        );
172
	toolboxDefaultColorLayout->addWidget( toolboxDefaultColorG_          );
Jan Möbius's avatar
Jan Möbius committed
173
	toolboxDefaultColorLayout->addItem  ( new QSpacerItem( 6, 6 )        );
174
175
176
177
178
179
180
181
182
183
	toolboxDefaultColorLayout->addWidget( toolboxDefaultColorB_          );

	// applyDefaults button
	QPushButton *toolboxApplyDefaultsButton = new QPushButton( "Apply Defaults" );

	// defaults layout
	QVBoxLayout *toolboxDefaultsLayout = new QVBoxLayout();
	toolboxDefaultsLayout->addItem  ( toolboxDefaultNormalLayout    );
	toolboxDefaultsLayout->addItem  ( toolboxDefaultPointsizeLayout );
	toolboxDefaultsLayout->addItem  ( toolboxDefaultColorLayout     );
Jan Möbius's avatar
Jan Möbius committed
184
	toolboxDefaultsLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
	toolboxDefaultsLayout->addWidget( toolboxApplyDefaultsButton    );

	// ----

	// options widget
	QWidget *toolboxOptionsWidget = new QWidget();
	toolboxOptionsWidget->setLayout( toolboxOptionsLayout );

	// defaults widget
	QWidget *toolboxDefaultsWidget = new QWidget();
	toolboxDefaultsWidget->setLayout( toolboxDefaultsLayout );

	// tab widget
	QTabWidget *toolboxTabWidget = new QTabWidget();
	toolboxTabWidget->addTab( toolboxOptionsWidget,  "Options"  );
	toolboxTabWidget->addTab( toolboxDefaultsWidget, "Defaults" );

	// toolbox layout
	QVBoxLayout *toolboxLayout = new QVBoxLayout();
	toolboxLayout->addWidget( toolboxTabWidget );

	// toolbox
	QWidget *toolbox = new QWidget();
	toolbox->setLayout( toolboxLayout );

	// ----

	// connect events to slots
213
214
215
216
217
218
	connect( toolboxPointsizeScale_,              SIGNAL( valueChanged(double) ), this, SLOT( slotToolboxPointsizeScaleValueChanged()          ) );
	connect( toolboxEnableBackfaceCullingButton,  SIGNAL( clicked()            ), this, SLOT( slotToolboxEnableBackfaceCullingButtonClicked()  ) );
	connect( toolboxDisableBackfaceCullingButton, SIGNAL( clicked()            ), this, SLOT( slotToolboxDisableBackfaceCullingButtonClicked() ) );
	connect( toolboxReloadShadersButton,          SIGNAL( clicked()            ), this, SLOT( slotToolboxReloadShadersButtonClicked()          ) );
	connect( toolboxRebuildVBOsButton,            SIGNAL( clicked()            ), this, SLOT( slotToolboxRebuildVBOsButtonClicked()            ) );
	connect( toolboxApplyDefaultsButton,          SIGNAL( clicked()            ), this, SLOT( slotToolboxApplyDefaultsButtonClicked()          ) );
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278

	// emit signal to add the new toolbox
	toolBoxIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"SplatCloudType.png");
	emit addToolbox( tr("SplatCloud Rendering Control") , toolbox , toolBoxIcon_);

	// -------------------------------------
	// -------- create context menu --------
	// -------------------------------------

	// scale action
	menuScaleAction_ = new QAction( tr("Pointsize Scale..."), this );

	// culling action
	menuCullingAction_ = new QAction( tr("Backface Culling"), this );
	menuCullingAction_->setCheckable( true );

	// defaults action
	menuDefaultsAction_ = new QAction( tr("Defaults..."), this );

	// reloadShaders action
	menuReloadShadersAction_ = new QAction( tr("Reload Shaders"), this );

	// rebuildVBO action
	menuRebuildVBOAction_ = new QAction( tr("Rebuild VBO"), this );

	// menu
	QMenu *menu = new QMenu( "SplatCloud Rendering Control" );
	menu->addAction( menuScaleAction_         );
	menu->addAction( menuCullingAction_       );
	menu->addSeparator();
	menu->addAction( menuDefaultsAction_      );
	menu->addSeparator();
	menu->addAction( menuReloadShadersAction_ );
	menu->addAction( menuRebuildVBOAction_    );

	// ----

	// connect events to slots
	connect( menuScaleAction_,         SIGNAL( triggered() ), this, SLOT( slotMenuScaleActionTriggered()         ) );
	connect( menuCullingAction_,       SIGNAL( triggered() ), this, SLOT( slotMenuCullingActionTriggered()       ) );
	connect( menuDefaultsAction_,      SIGNAL( triggered() ), this, SLOT( slotMenuDefaultsActionTriggered()      ) );
	connect( menuReloadShadersAction_, SIGNAL( triggered() ), this, SLOT( slotMenuReloadShadersActionTriggered() ) );
	connect( menuRebuildVBOAction_,    SIGNAL( triggered() ), this, SLOT( slotMenuRebuildVBOActionTriggered()    ) );

	// emit signal to add the new contest menu
	emit addContextMenuItem( menu->menuAction(), DATA_SPLATCLOUD, CONTEXTOBJECTMENU );

	// -------------------------------------
	// -------- create scale widget --------
	// -------------------------------------

	// pointsizeScale
	scaleWidgetPointsizeScale_ = new QDoubleSpinBox();
	scaleWidgetPointsizeScale_->setRange( 0.0, 100.0 );
	scaleWidgetPointsizeScale_->setDecimals( 4 );
	scaleWidgetPointsizeScale_->setSingleStep( 0.1 );

	// pointsizeScale layout
	QHBoxLayout *scaleWidgetPointsizeScaleLayout = new QHBoxLayout();
	scaleWidgetPointsizeScaleLayout->addWidget( new QLabel( "Pointsize Scale:" ) );
Jan Möbius's avatar
Jan Möbius committed
279
	scaleWidgetPointsizeScaleLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
	scaleWidgetPointsizeScaleLayout->addWidget( scaleWidgetPointsizeScale_       );

	// widget layout
	QVBoxLayout *scaleWidgetLayout = new QVBoxLayout();
	scaleWidgetLayout->addItem( scaleWidgetPointsizeScaleLayout );

	// widget
	scaleWidget_ = new QWidget();
	scaleWidget_->setWindowTitle( "Pointsize Scale" );
	scaleWidget_->setLayout( scaleWidgetLayout );

	// ----

	// connect events to slots
	connect( scaleWidgetPointsizeScale_, SIGNAL( valueChanged(double) ), this, SLOT( slotScaleWidgetPointsizeScaleValueChanged() ) );

	// ----------------------------------------
	// -------- create defaults widget --------
	// ----------------------------------------

	// defaultNormal
	defaultsWidgetDefaultNormalX_ = new QDoubleSpinBox();
	defaultsWidgetDefaultNormalY_ = new QDoubleSpinBox();
	defaultsWidgetDefaultNormalZ_ = new QDoubleSpinBox();
	defaultsWidgetDefaultNormalX_->setRange( -1.0, 1.0 );
	defaultsWidgetDefaultNormalY_->setRange( -1.0, 1.0 );
	defaultsWidgetDefaultNormalZ_->setRange( -1.0, 1.0 );
	defaultsWidgetDefaultNormalX_->setDecimals( 2 );
	defaultsWidgetDefaultNormalY_->setDecimals( 2 );
	defaultsWidgetDefaultNormalZ_->setDecimals( 2 );
	defaultsWidgetDefaultNormalX_->setSingleStep( 0.1 );
	defaultsWidgetDefaultNormalY_->setSingleStep( 0.1 );
	defaultsWidgetDefaultNormalZ_->setSingleStep( 0.1 );

	// defaultNormal layout
	QHBoxLayout *defaultsWidgetDefaultNormalLayout = new QHBoxLayout();
	defaultsWidgetDefaultNormalLayout->addWidget( new QLabel( "Default Normal:" ) );
Jan Möbius's avatar
Jan Möbius committed
317
	defaultsWidgetDefaultNormalLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
318
	defaultsWidgetDefaultNormalLayout->addWidget( defaultsWidgetDefaultNormalX_   );
Jan Möbius's avatar
Jan Möbius committed
319
	defaultsWidgetDefaultNormalLayout->addItem  ( new QSpacerItem( 6, 6 )         );
320
	defaultsWidgetDefaultNormalLayout->addWidget( defaultsWidgetDefaultNormalY_   );
Jan Möbius's avatar
Jan Möbius committed
321
	defaultsWidgetDefaultNormalLayout->addItem  ( new QSpacerItem( 6, 6 )         );
322
323
324
325
326
327
328
329
330
331
332
	defaultsWidgetDefaultNormalLayout->addWidget( defaultsWidgetDefaultNormalZ_   );

	// defaultPointsize
	defaultsWidgetDefaultPointsize_ = new QDoubleSpinBox();
	defaultsWidgetDefaultPointsize_->setRange( 0.0, 1000.0 );
	defaultsWidgetDefaultPointsize_->setDecimals( 4 );
	defaultsWidgetDefaultPointsize_->setSingleStep( 0.001 );

	// defaultPointsize layout
	QHBoxLayout *defaultsWidgetDefaultPointsizeLayout = new QHBoxLayout();
	defaultsWidgetDefaultPointsizeLayout->addWidget( new QLabel( "Default Pointsize:" ) );
Jan Möbius's avatar
Jan Möbius committed
333
	defaultsWidgetDefaultPointsizeLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
	defaultsWidgetDefaultPointsizeLayout->addWidget( defaultsWidgetDefaultPointsize_    );

	// defaultColor
	defaultsWidgetDefaultColorR_ = new QSpinBox();
	defaultsWidgetDefaultColorG_ = new QSpinBox();
	defaultsWidgetDefaultColorB_ = new QSpinBox();
	defaultsWidgetDefaultColorR_->setRange( 0, 255 );
	defaultsWidgetDefaultColorG_->setRange( 0, 255 );
	defaultsWidgetDefaultColorB_->setRange( 0, 255 );
	defaultsWidgetDefaultColorR_->setSingleStep( 1 );
	defaultsWidgetDefaultColorG_->setSingleStep( 1 );
	defaultsWidgetDefaultColorB_->setSingleStep( 1 );

	// defaultColor layout
	QHBoxLayout *defaultsWidgetDefaultColorLayout = new QHBoxLayout();
	defaultsWidgetDefaultColorLayout->addWidget( new QLabel( "Default Color:" ) );
Jan Möbius's avatar
Jan Möbius committed
350
	defaultsWidgetDefaultColorLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
351
	defaultsWidgetDefaultColorLayout->addWidget( defaultsWidgetDefaultColorR_   );
Jan Möbius's avatar
Jan Möbius committed
352
	defaultsWidgetDefaultColorLayout->addItem  ( new QSpacerItem( 6, 6 )        );
353
	defaultsWidgetDefaultColorLayout->addWidget( defaultsWidgetDefaultColorG_   );
Jan Möbius's avatar
Jan Möbius committed
354
	defaultsWidgetDefaultColorLayout->addItem  ( new QSpacerItem( 6, 6 )        );
355
356
357
358
359
360
361
362
363
	defaultsWidgetDefaultColorLayout->addWidget( defaultsWidgetDefaultColorB_   );

	// cancel and apply buttons
	QPushButton *defaultsWidgetCancelButton = new QPushButton( "Cancel" );
	QPushButton *defaultsWidgetApplyButton  = new QPushButton( "Apply"  );

	// buttons layout
	QHBoxLayout *defaultsWidgetButtonsLayout = new QHBoxLayout();
	defaultsWidgetButtonsLayout->addWidget( defaultsWidgetCancelButton );
Jan Möbius's avatar
Jan Möbius committed
364
	defaultsWidgetButtonsLayout->addItem  ( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
365
366
367
368
369
370
371
	defaultsWidgetButtonsLayout->addWidget( defaultsWidgetApplyButton  );

	// widget layout
	QVBoxLayout *defaultsWidgetLayout = new QVBoxLayout();
	defaultsWidgetLayout->addItem( defaultsWidgetDefaultNormalLayout    );
	defaultsWidgetLayout->addItem( defaultsWidgetDefaultPointsizeLayout );
	defaultsWidgetLayout->addItem( defaultsWidgetDefaultColorLayout     );
Jan Möbius's avatar
Jan Möbius committed
372
	defaultsWidgetLayout->addItem( new QSpacerItem( 6, 6, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
	defaultsWidgetLayout->addItem( defaultsWidgetButtonsLayout          );

	// widget
	defaultsWidget_ = new QWidget();
	defaultsWidget_->setWindowTitle( "Defaults" );
	defaultsWidget_->setLayout( defaultsWidgetLayout );

	// ----

	// connect events to slots
	connect( defaultsWidgetCancelButton, SIGNAL( clicked() ), this, SLOT( slotDefaultsWidgetCancelButtonClicked() ) );
	connect( defaultsWidgetApplyButton,  SIGNAL( clicked() ), this, SLOT( slotDefaultsWidgetApplyButtonClicked()  ) );
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotUpdateContextMenu( int _objectId )
{
	// get object by id

	if( _objectId == -1 )
		return;

	BaseObjectData *object;
	if( ! PluginFunctions::getObject( _objectId, object ) )
		return;

	// get splatcloud-object
	SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( object );

Jan Möbius's avatar
Jan Möbius committed
405
406
407
408
409
	// if object is a SplatCloud...
	if( splatCloud )
	{
		// update context-menu value
		menuCullingAction_->setChecked( splatCloud->isBackfaceCullingEnabled() );
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
	}
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotToolboxPointsizeScaleValueChanged()
{
	// get toolbox option value
	float scale = (float) toolboxPointsizeScale_->value();

	// for all splatcloud-objects...
	PluginFunctions::ObjectIterator objIter( PluginFunctions::ALL_OBJECTS, DATA_SPLATCLOUD );
	for( ; objIter != PluginFunctions::objectsEnd(); ++objIter )
	{
		// get splatcloud-object
		SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( *objIter );

		// apply update
		splatCloud->setPointsizeScale( scale );

		// emit signal that the object has to be updated
		emit updatedObject( objIter->id(), UPDATE_ALL );
	}
}


//----------------------------------------------------------------


441
void SplatCloudRenderingControlPlugin::slotToolboxEnableBackfaceCullingButtonClicked()
442
{
443
444
445
446
447
448
449
450
451
452
453
454
455
456
	// for all splatcloud-objects...
	PluginFunctions::ObjectIterator objIter( PluginFunctions::ALL_OBJECTS, DATA_SPLATCLOUD );
	for( ; objIter != PluginFunctions::objectsEnd(); ++objIter )
	{
		// get splatcloud-object
		SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( *objIter );

		// apply update
		splatCloud->enableBackfaceCulling( true );

		// emit signal that the object has to be updated
		emit updatedObject( objIter->id(), UPDATE_ALL );
	}
}
457

458
459
460
461
462
463

//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotToolboxDisableBackfaceCullingButtonClicked()
{
464
465
466
467
468
469
470
471
	// for all splatcloud-objects...
	PluginFunctions::ObjectIterator objIter( PluginFunctions::ALL_OBJECTS, DATA_SPLATCLOUD );
	for( ; objIter != PluginFunctions::objectsEnd(); ++objIter )
	{
		// get splatcloud-object
		SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( *objIter );

		// apply update
472
		splatCloud->enableBackfaceCulling( false );
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488

		// emit signal that the object has to be updated
		emit updatedObject( objIter->id(), UPDATE_ALL );
	}
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotToolboxReloadShadersButtonClicked()
{
	// for all splatcloud-objects...
	PluginFunctions::ObjectIterator objIter( PluginFunctions::ALL_OBJECTS, DATA_SPLATCLOUD );
	for( ; objIter != PluginFunctions::objectsEnd(); ++objIter )
	{
Jan Möbius's avatar
Jan Möbius committed
489
		// get scenegraph splatcloud-object
490
491
		SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( *objIter );

Jan Möbius's avatar
Jan Möbius committed
492
		// apply update (reload standard and picking shaders and re-set uniforms)
493
		splatCloud->reloadShaders();
Jan Möbius's avatar
Jan Möbius committed
494
495
		splatCloud->setPointsizeScale    ( splatCloud->pointsizeScale()           );
		splatCloud->enableBackfaceCulling( splatCloud->isBackfaceCullingEnabled() );
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514

		// emit signal that object has to be updated
		emit updatedObject( objIter->id(), UPDATE_ALL );
	}
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotToolboxRebuildVBOsButtonClicked()
{
	// for all splatcloud-objects...
	PluginFunctions::ObjectIterator objIter( PluginFunctions::ALL_OBJECTS, DATA_SPLATCLOUD );
	for( ; objIter != PluginFunctions::objectsEnd(); ++objIter )
	{
		// get scenegraph splatcloud-node
		SplatCloudNode *splatCloudNode = PluginFunctions::splatCloudNode( *objIter );

Jan Möbius's avatar
Jan Möbius committed
515
516
		// apply update (make vertex-buffer-object invalid so it will be rebuilt the next time the node is drawn (or picked))
		splatCloudNode->invalidateVBO();
517

Jan Möbius's avatar
Jan Möbius committed
518
519
		// emit signal that object has to be updated
		emit updatedObject( objIter->id(), UPDATE_ALL );
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
	}
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotToolboxApplyDefaultsButtonClicked()
{
	// for all splatcloud-objects...
	PluginFunctions::ObjectIterator objIter( PluginFunctions::ALL_OBJECTS, DATA_SPLATCLOUD );
	for( ; objIter != PluginFunctions::objectsEnd(); ++objIter )
	{
		// get scenegraph splatcloud-node
		SplatCloudNode *splatCloudNode = PluginFunctions::splatCloudNode( *objIter );

Jan Möbius's avatar
Jan Möbius committed
536
537
538
539
540
541
542
543
544
545
546
		// apply update (this may trigger the VBO to become invalid so it will be rebuilt)
		splatCloudNode->setDefaultNormal( SplatCloudNode::Normal( toolboxDefaultNormalX_->value(), 
		                                                          toolboxDefaultNormalY_->value(), 
		                                                          toolboxDefaultNormalZ_->value() ) );
		splatCloudNode->setDefaultPointsize( toolboxDefaultPointsize_->value() );
		splatCloudNode->setDefaultColor( SplatCloudNode::Color( toolboxDefaultColorR_->value(), 
		                                                        toolboxDefaultColorG_->value(), 
		                                                        toolboxDefaultColorB_->value() ) );

		// emit signal that object has to be updated
		emit updatedObject( objIter->id(), UPDATE_ALL );
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
	}
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotMenuScaleActionTriggered()
{
	// get picked object

	QVariant contextObject = menuScaleAction_->data();

	int objectId = contextObject.toInt();
	if( objectId == -1 )
		return;

	BaseObjectData *object;
	if( ! PluginFunctions::getObject( objectId, object ) )
		return;

	// get splatcloud-object
	SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( object );

Jan Möbius's avatar
Jan Möbius committed
571
572
573
574
575
	// if object is a SplatCloud...
	if( splatCloud )
	{
		// update scale-widget option value
		scaleWidgetPointsizeScale_->setValue( splatCloud->pointsizeScale() );
576

Jan Möbius's avatar
Jan Möbius committed
577
578
579
		// move scale-widget to position of context menu entry
		QWidget *menuWidget = menuScaleAction_->associatedWidgets()[0];
		scaleWidget_->move( menuWidget->x(), menuWidget->y() );
580

Jan Möbius's avatar
Jan Möbius committed
581
582
583
		// show scale-widget
		scaleWidget_->show();
	}
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotScaleWidgetPointsizeScaleValueChanged()
{
	// get picked object

	QVariant contextObject = menuScaleAction_->data();

	int objectId = contextObject.toInt();
	if( objectId == -1 )
		return;

	BaseObjectData *object;
	if( ! PluginFunctions::getObject( objectId, object ) )
		return;

	// get splatcloud-object
	SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( object );

Jan Möbius's avatar
Jan Möbius committed
607
608
609
610
611
612
613
614
	// if object is a SplatCloud...
	if( splatCloud )
	{
		// get scale-widget option value
		float scale = (float) scaleWidgetPointsizeScale_->value();

		// apply update
		splatCloud->setPointsizeScale( scale );
615

Jan Möbius's avatar
Jan Möbius committed
616
617
618
		// emit signal that object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
	}
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotMenuCullingActionTriggered()
{
	// get picked object

	QVariant contextObject = menuCullingAction_->data();

	int objectId = contextObject.toInt();
	if( objectId == -1 )
		return;

	BaseObjectData *object;
	if( ! PluginFunctions::getObject( objectId, object ) )
		return;

	// get splatcloud-object
	SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( object );

Jan Möbius's avatar
Jan Möbius committed
642
643
644
645
646
647
648
649
	// if object is a SplatCloud...
	if( splatCloud )
	{
		// get context-menu option value
		bool enable = menuCullingAction_->isChecked();

		// apply update
		splatCloud->enableBackfaceCulling( enable );
650

Jan Möbius's avatar
Jan Möbius committed
651
652
653
		// emit signal that the object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
	}
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotMenuReloadShadersActionTriggered()
{
	// get picked object

	QVariant contextObject = menuReloadShadersAction_->data();

	int objectId = contextObject.toInt();
	if( objectId == -1 )
		return;

	BaseObjectData *object;
	if( ! PluginFunctions::getObject( objectId, object ) )
		return;

	// get splatcloud-object
	SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( object );

Jan Möbius's avatar
Jan Möbius committed
677
678
679
680
681
682
683
	// if object is a SplatCloud...
	if( splatCloud )
	{
		// apply update (reload standard and picking shaders and re-set uniforms)
		splatCloud->reloadShaders();
		splatCloud->setPointsizeScale    ( splatCloud->pointsizeScale()           );
		splatCloud->enableBackfaceCulling( splatCloud->isBackfaceCullingEnabled() );
684

Jan Möbius's avatar
Jan Möbius committed
685
686
687
		// emit signal that object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
	}
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotMenuRebuildVBOActionTriggered()
{
	// get picked object

	QVariant contextObject = menuRebuildVBOAction_->data();

	int objectId = contextObject.toInt();
	if( objectId == -1 )
		return;

	BaseObjectData *object;
	if( ! PluginFunctions::getObject( objectId, object ) )
		return;

	// get splatcloud-node
	SplatCloudNode *splatCloudNode = PluginFunctions::splatCloudNode( object );

Jan Möbius's avatar
Jan Möbius committed
711
712
713
714
715
	// if object is a SplatCloud...
	if( splatCloudNode )
	{
		// apply update (make vertex-buffer-object invalid so it will be rebuilt the next time the node is drawn (or picked))
		splatCloudNode->invalidateVBO();
716

Jan Möbius's avatar
Jan Möbius committed
717
718
		// emit signal that object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
	}
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotMenuDefaultsActionTriggered()
{
	// get picked object

	QVariant contextObject = menuDefaultsAction_->data();

	int objectId = contextObject.toInt();
	if( objectId == -1 )
		return;

	BaseObjectData *object;
	if( ! PluginFunctions::getObject( objectId, object ) )
		return;

	// get splatcloud-node
	SplatCloudNode *splatCloudNode = PluginFunctions::splatCloudNode( object );

Jan Möbius's avatar
Jan Möbius committed
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
	// if object is a SplatCloud...
	if( splatCloudNode )
	{
		// update defaults-widget option values
		defaultsWidgetDefaultNormalX_->setValue( splatCloudNode->defaultNormal()[0] );
		defaultsWidgetDefaultNormalY_->setValue( splatCloudNode->defaultNormal()[1] );
		defaultsWidgetDefaultNormalZ_->setValue( splatCloudNode->defaultNormal()[2] );
		defaultsWidgetDefaultPointsize_->setValue( splatCloudNode->defaultPointsize() );
		defaultsWidgetDefaultColorR_->setValue( splatCloudNode->defaultColor()[0] );
		defaultsWidgetDefaultColorG_->setValue( splatCloudNode->defaultColor()[1] );
		defaultsWidgetDefaultColorB_->setValue( splatCloudNode->defaultColor()[2] );

		// move defaults widget to position of context menu entry
		QWidget *menuWidget = menuDefaultsAction_->associatedWidgets()[0];
		defaultsWidget_->move( menuWidget->x(), menuWidget->y() );

		// show defaults widget
		defaultsWidget_->show();
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
	}
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotDefaultsWidgetCancelButtonClicked()
{
	// close widget
	defaultsWidget_->close();
}


//----------------------------------------------------------------


void SplatCloudRenderingControlPlugin::slotDefaultsWidgetApplyButtonClicked()
{
	// get picked object

	QVariant contextObject = menuDefaultsAction_->data();

	int objectId = contextObject.toInt();
	if( objectId == -1 )
		return;

	BaseObjectData *object;
	if( ! PluginFunctions::getObject( objectId, object ) )
		return;

	// get splatcloud-node
	SplatCloudNode *splatCloudNode = PluginFunctions::splatCloudNode( object );

Jan Möbius's avatar
Jan Möbius committed
795
796
797
798
799
800
801
802
803
804
805
	// if object is a SplatCloud...
	if( splatCloudNode )
	{
		// apply update (this may trigger the VBO to become invalid so it will be rebuilt)
		splatCloudNode->setDefaultNormal( SplatCloudNode::Normal( defaultsWidgetDefaultNormalX_->value(), 
		                                                          defaultsWidgetDefaultNormalY_->value(), 
		                                                          defaultsWidgetDefaultNormalZ_->value() ) );
		splatCloudNode->setDefaultPointsize( defaultsWidgetDefaultPointsize_->value() );
		splatCloudNode->setDefaultColor( SplatCloudNode::Color( defaultsWidgetDefaultColorR_->value(), 
		                                                        defaultsWidgetDefaultColorG_->value(), 
		                                                        defaultsWidgetDefaultColorB_->value() ) );
806

Jan Möbius's avatar
Jan Möbius committed
807
808
		// emit signal that the object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
809
810
811
812
813
814
815
816
817
818
819
	}

	// close widget
	defaultsWidget_->close();
}


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


Q_EXPORT_PLUGIN2( splatcloudrenderingcontrolplugin, SplatCloudRenderingControlPlugin );