SplatCloudRenderingControlPlugin.cc 34.3 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
//================================================================
//
/*===========================================================================*\
*                                                                            *
*                              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 --------
	// --------------------------------

74
	// ---- options tab ----
75

76
	// pointsize scale
77 78 79 80 81
	toolboxPointsizeScale_ = new QDoubleSpinBox();
	toolboxPointsizeScale_->setRange( 0.0, 100.0 );
	toolboxPointsizeScale_->setDecimals( 4 );
	toolboxPointsizeScale_->setSingleStep( 0.1 );
	toolboxPointsizeScale_->setValue( 1.0 );
82
	toolboxPointsizeScale_->setToolTip( "The scaling factor of the pointsizes used during the rendering of objects" );
83

84
	// pointsize scale layout
85
	QHBoxLayout *toolboxPointsizeScaleLayout = new QHBoxLayout();
86 87 88
	toolboxPointsizeScaleLayout->setSpacing( 6 );
	toolboxPointsizeScaleLayout->addWidget( new QLabel( "Pointsize Scaling Factor:" ) );
	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"             );
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
	toolboxEnableBackfaceCullingButton->setToolTip ( "Enable the culling of backfaces"       );
	toolboxDisableBackfaceCullingButton->setToolTip( "Disable the culling of backfaces"      );
	toolboxReloadShadersButton->setToolTip         ( "Reload all shader files"           );
	toolboxRebuildVBOsButton->setToolTip           ( "Rebuild all vertex-buffer-objects" );

	// buttonsA layout
	QHBoxLayout *toolboxButtonsALayout = new QHBoxLayout();
	toolboxButtonsALayout->setSpacing( 6 );
	toolboxButtonsALayout->addWidget( toolboxEnableBackfaceCullingButton  );
	toolboxButtonsALayout->addWidget( toolboxDisableBackfaceCullingButton );

	// separator frame
	QFrame *toolboxSeparatorFrame = new QFrame();
	toolboxSeparatorFrame->setFrameShape( QFrame::HLine );
	toolboxSeparatorFrame->setFrameShadow( QFrame::Sunken );

	// buttonsB layout
	QHBoxLayout *toolboxButtonsBLayout = new QHBoxLayout();
	toolboxButtonsBLayout->setSpacing( 6 );
	toolboxButtonsBLayout->addWidget( toolboxReloadShadersButton );
	toolboxButtonsBLayout->addWidget( toolboxRebuildVBOsButton   );
116 117 118

	// options layout
	QVBoxLayout *toolboxOptionsLayout = new QVBoxLayout();
119
	toolboxOptionsLayout->setSpacing( 6 );
120
	toolboxOptionsLayout->addItem  ( toolboxPointsizeScaleLayout );
121 122 123 124 125 126 127 128
	toolboxOptionsLayout->addItem  ( toolboxButtonsALayout       );
	toolboxOptionsLayout->addWidget( toolboxSeparatorFrame       );
	toolboxOptionsLayout->addItem  ( toolboxButtonsBLayout       );

	// options widget
	QWidget *toolboxOptionsWidget = new QWidget();
	toolboxOptionsWidget->setLayout( toolboxOptionsLayout );
	toolboxOptionsWidget->setToolTip( "Rendering options" );
129

130
	// ---- defaults tab ----
131

132
	// default normal
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
	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 );
148 149 150
	toolboxDefaultNormalX_->setToolTip( "The default x-component of the normal used when an object has no normals" );
	toolboxDefaultNormalY_->setToolTip( "The default y-component of the normal used when an object has no normals" );
	toolboxDefaultNormalZ_->setToolTip( "The default z-component of the normal used when an object has no normals" );
151

152
	// default pointsize
153 154 155 156 157
	toolboxDefaultPointsize_ = new QDoubleSpinBox();
	toolboxDefaultPointsize_->setRange( 0.0, 1000.0 );
	toolboxDefaultPointsize_->setDecimals( 4 );
	toolboxDefaultPointsize_->setSingleStep( 0.001 );
	toolboxDefaultPointsize_->setValue( 0.01 );
158
	toolboxDefaultPointsize_->setToolTip( "The default pointsize used when an object has no pointsizes" );
159

160
	// default color
161 162 163 164 165 166 167 168 169 170 171 172
	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 );
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
	toolboxDefaultColorR_->setToolTip( "The default red-component of the color used when an object has no colors"   );
	toolboxDefaultColorG_->setToolTip( "The default green-component of the color used when an object has no colors" );
	toolboxDefaultColorB_->setToolTip( "The default blue-component of the color used when an object has no colors"  );

	// default normal layout
	QHBoxLayout *toolboxDefaultNormalLayout = new QHBoxLayout();
	toolboxDefaultNormalLayout->setSpacing( 6 );
	toolboxDefaultNormalLayout->addWidget( toolboxDefaultNormalX_ );
	toolboxDefaultNormalLayout->addWidget( toolboxDefaultNormalY_ );
	toolboxDefaultNormalLayout->addWidget( toolboxDefaultNormalZ_ );

	// default pointsize layout
	QHBoxLayout *toolboxDefaultPointsizeLayout = new QHBoxLayout();
	toolboxDefaultPointsizeLayout->setSpacing( 6 );
	toolboxDefaultPointsizeLayout->addWidget( toolboxDefaultPointsize_ );
188

189
	// default color layout
190
	QHBoxLayout *toolboxDefaultColorLayout = new QHBoxLayout();
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
	toolboxDefaultColorLayout->setSpacing( 6 );
	toolboxDefaultColorLayout->addWidget( toolboxDefaultColorR_ );
	toolboxDefaultColorLayout->addWidget( toolboxDefaultColorG_ );
	toolboxDefaultColorLayout->addWidget( toolboxDefaultColorB_ );

	// default options layout
	QGridLayout *toolboxDefaultOptionsLayout = new QGridLayout();
	toolboxDefaultOptionsLayout->setSpacing( 6 );
	toolboxDefaultOptionsLayout->addWidget( new QLabel( "Default Normal:"    ), 0, 0 );
	toolboxDefaultOptionsLayout->addWidget( new QLabel( "Default Pointsize:" ), 1, 0 );
	toolboxDefaultOptionsLayout->addWidget( new QLabel( "Default Color:"     ), 2, 0 );
	toolboxDefaultOptionsLayout->addItem  ( toolboxDefaultNormalLayout,         0, 1 );
	toolboxDefaultOptionsLayout->addItem  ( toolboxDefaultPointsizeLayout,      1, 1 );
	toolboxDefaultOptionsLayout->addItem  ( toolboxDefaultColorLayout,          2, 1 );

	// apply defaults button
207
	QPushButton *toolboxApplyDefaultsButton = new QPushButton( "Apply Defaults" );
208
	toolboxApplyDefaultsButton->setToolTip( "Apply the changes made" );
209 210 211

	// defaults layout
	QVBoxLayout *toolboxDefaultsLayout = new QVBoxLayout();
212 213 214
	toolboxDefaultsLayout->setSpacing( 6 );
	toolboxDefaultsLayout->addItem  ( toolboxDefaultOptionsLayout );
	toolboxDefaultsLayout->addWidget( toolboxApplyDefaultsButton  );
215 216 217 218

	// defaults widget
	QWidget *toolboxDefaultsWidget = new QWidget();
	toolboxDefaultsWidget->setLayout( toolboxDefaultsLayout );
219 220 221
	toolboxDefaultsWidget->setToolTip( "Default values" );

	// ----
222 223 224 225 226 227 228 229

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

	// toolbox layout
	QVBoxLayout *toolboxLayout = new QVBoxLayout();
230
	toolboxLayout->setSpacing( 6 );
231 232 233 234 235 236
	toolboxLayout->addWidget( toolboxTabWidget );

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

237 238 239
	// toolbox icon
	QIcon *toolboxIcon = new QIcon( OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "SplatCloudType.png" );

240 241 242
	// ----

	// connect events to slots
243 244 245 246 247 248
	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()          ) );
249 250

	// emit signal to add the new toolbox
251
	emit addToolbox( tr("SplatCloud Rendering Control") , toolbox , toolboxIcon );
252 253 254 255 256

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

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
	// actions
	contextScaleAction_         = new QAction( tr( "Pointsize Scaling Factor..."), this );
	contextCullingAction_       = new QAction( tr( "Backface Culling"           ), this );
	contextDefaultsAction_      = new QAction( tr( "Defaults..."                ), this );
	contextReloadShadersAction_ = new QAction( tr( "Reload Shaders"             ), this );
	contextRebuildVBOAction_    = new QAction( tr( "Rebuild VBO"                ), this );
	contextCullingAction_->setCheckable( true );

	// context menu
	QMenu *contextMenu = new QMenu( "SplatCloud Rendering Control" );
	contextMenu->addAction( contextScaleAction_         );
	contextMenu->addAction( contextCullingAction_       );
	contextMenu->addSeparator();
	contextMenu->addAction( contextDefaultsAction_      );
	contextMenu->addSeparator();
	contextMenu->addAction( contextReloadShadersAction_ );
	contextMenu->addAction( contextRebuildVBOAction_    );
274 275 276 277

	// ----

	// connect events to slots
278 279 280 281 282
	connect( contextScaleAction_,         SIGNAL( triggered() ), this, SLOT( slotContextScaleActionTriggered()         ) );
	connect( contextCullingAction_,       SIGNAL( triggered() ), this, SLOT( slotContextCullingActionTriggered()       ) );
	connect( contextDefaultsAction_,      SIGNAL( triggered() ), this, SLOT( slotContextDefaultsActionTriggered()      ) );
	connect( contextReloadShadersAction_, SIGNAL( triggered() ), this, SLOT( slotContextReloadShadersActionTriggered() ) );
	connect( contextRebuildVBOAction_,    SIGNAL( triggered() ), this, SLOT( slotContextRebuildVBOActionTriggered()    ) );
283

284 285
	// emit signal to add the new context menu
	emit addContextMenuItem( contextMenu->menuAction(), DATA_SPLATCLOUD, CONTEXTOBJECTMENU );
286 287 288 289 290

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

291
	// pointsize scale
292 293 294 295
	scaleWidgetPointsizeScale_ = new QDoubleSpinBox();
	scaleWidgetPointsizeScale_->setRange( 0.0, 100.0 );
	scaleWidgetPointsizeScale_->setDecimals( 4 );
	scaleWidgetPointsizeScale_->setSingleStep( 0.1 );
296
	scaleWidgetPointsizeScale_->setToolTip( "The scaling factor of the pointsizes used during the rendering of the picked object" );
297

298
	// pointsize scale layout
299
	QHBoxLayout *scaleWidgetPointsizeScaleLayout = new QHBoxLayout();
300 301 302
	scaleWidgetPointsizeScaleLayout->setSpacing( 6 );
	scaleWidgetPointsizeScaleLayout->addWidget( new QLabel( "Pointsize Scaling Factor:" ) );
	scaleWidgetPointsizeScaleLayout->addWidget( scaleWidgetPointsizeScale_                );
303 304 305

	// widget layout
	QVBoxLayout *scaleWidgetLayout = new QVBoxLayout();
306
	scaleWidgetLayout->setSpacing( 6 );
307 308 309 310
	scaleWidgetLayout->addItem( scaleWidgetPointsizeScaleLayout );

	// widget
	scaleWidget_ = new QWidget();
311
	scaleWidget_->setWindowTitle( "Pointsize Scaling Factor" );
312 313 314 315 316 317 318 319 320 321 322
	scaleWidget_->setLayout( scaleWidgetLayout );

	// ----

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

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

323
	// default normal
324 325 326 327 328 329 330 331 332 333 334 335
	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 );
336 337 338
	defaultsWidgetDefaultNormalX_->setToolTip( "The default x-component of the normal used when the picked object has no normals" );
	defaultsWidgetDefaultNormalY_->setToolTip( "The default y-component of the normal used when the picked object has no normals" );
	defaultsWidgetDefaultNormalZ_->setToolTip( "The default z-component of the normal used when the picked object has no normals" );
339

340
	// default pointsize
341 342 343 344
	defaultsWidgetDefaultPointsize_ = new QDoubleSpinBox();
	defaultsWidgetDefaultPointsize_->setRange( 0.0, 1000.0 );
	defaultsWidgetDefaultPointsize_->setDecimals( 4 );
	defaultsWidgetDefaultPointsize_->setSingleStep( 0.001 );
345
	defaultsWidgetDefaultPointsize_->setToolTip( "The default pointsize used when the picked object has no pointsizes" );
346

347
	// default color
348 349 350 351 352 353 354 355 356
	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 );
357 358 359
	defaultsWidgetDefaultColorR_->setToolTip( "The default red-component of the color used when the picked object has no colors"   );
	defaultsWidgetDefaultColorG_->setToolTip( "The default green-component of the color used when the picked object has no colors" );
	defaultsWidgetDefaultColorB_->setToolTip( "The default blue-component of the color used when the picked object has no colors"  );
360

361 362 363 364 365 366 367 368 369 370 371 372 373
	// default normal layout
	QHBoxLayout *defaultsWidgetDefaultNormalLayout = new QHBoxLayout();
	defaultsWidgetDefaultNormalLayout->setSpacing( 6 );
	defaultsWidgetDefaultNormalLayout->addWidget( defaultsWidgetDefaultNormalX_ );
	defaultsWidgetDefaultNormalLayout->addWidget( defaultsWidgetDefaultNormalY_ );
	defaultsWidgetDefaultNormalLayout->addWidget( defaultsWidgetDefaultNormalZ_ );

	// default pointsize layout
	QHBoxLayout *defaultsWidgetDefaultPointsizeLayout = new QHBoxLayout();
	defaultsWidgetDefaultPointsizeLayout->setSpacing( 6 );
	defaultsWidgetDefaultPointsizeLayout->addWidget( defaultsWidgetDefaultPointsize_ );

	// default color layout
374
	QHBoxLayout *defaultsWidgetDefaultColorLayout = new QHBoxLayout();
375 376 377 378 379 380 381 382 383 384 385 386 387 388
	defaultsWidgetDefaultColorLayout->setSpacing( 6 );
	defaultsWidgetDefaultColorLayout->addWidget( defaultsWidgetDefaultColorR_ );
	defaultsWidgetDefaultColorLayout->addWidget( defaultsWidgetDefaultColorG_ );
	defaultsWidgetDefaultColorLayout->addWidget( defaultsWidgetDefaultColorB_ );

	// default options layout
	QGridLayout *defaultsWidgetDefaultOptionsLayout = new QGridLayout();
	defaultsWidgetDefaultOptionsLayout->setSpacing( 6 );
	defaultsWidgetDefaultOptionsLayout->addWidget( new QLabel( "Default Normal:"    ),   0, 0 );
	defaultsWidgetDefaultOptionsLayout->addWidget( new QLabel( "Default Pointsize:" ),   1, 0 );
	defaultsWidgetDefaultOptionsLayout->addWidget( new QLabel( "Default Color:"     ),   2, 0 );
	defaultsWidgetDefaultOptionsLayout->addItem  ( defaultsWidgetDefaultNormalLayout,    0, 1 );
	defaultsWidgetDefaultOptionsLayout->addItem  ( defaultsWidgetDefaultPointsizeLayout, 1, 1 );
	defaultsWidgetDefaultOptionsLayout->addItem  ( defaultsWidgetDefaultColorLayout,     2, 1 );
389 390 391 392

	// cancel and apply buttons
	QPushButton *defaultsWidgetCancelButton = new QPushButton( "Cancel" );
	QPushButton *defaultsWidgetApplyButton  = new QPushButton( "Apply"  );
393 394
	defaultsWidgetCancelButton->setToolTip( "Return without applying any changes" );
	defaultsWidgetApplyButton->setToolTip ( "Apply the changes made and return" );
395 396 397

	// buttons layout
	QHBoxLayout *defaultsWidgetButtonsLayout = new QHBoxLayout();
398
	defaultsWidgetButtonsLayout->setSpacing( 6 );
399 400 401 402 403
	defaultsWidgetButtonsLayout->addWidget( defaultsWidgetCancelButton );
	defaultsWidgetButtonsLayout->addWidget( defaultsWidgetApplyButton  );

	// widget layout
	QVBoxLayout *defaultsWidgetLayout = new QVBoxLayout();
404 405 406
	defaultsWidgetLayout->setSpacing( 6 );
	defaultsWidgetLayout->addItem( defaultsWidgetDefaultOptionsLayout );
	defaultsWidgetLayout->addItem( defaultsWidgetButtonsLayout        );
407 408 409 410 411 412 413 414 415 416 417

	// 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()  ) );
Jan Möbius's avatar
Jan Möbius committed
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448

	// ----------------------------------
	// -------- create view mode --------
	// ----------------------------------

	// toolboxes
	QStringList viewModeToolboxes;
	viewModeToolboxes += "Data Control";
	viewModeToolboxes += "SplatCloud Estimator";
	viewModeToolboxes += "SplatCloud Rendering Control";

	// toolbars
	QStringList viewModeToolbars;
	viewModeToolbars += "Main Toolbar";
	viewModeToolbars += "Viewer Toolbar";
	viewModeToolbars += "Color Toolbar";
	viewModeToolbars += "Viewing Directions";

	// context menus
	QStringList viewModeContextMenus;
	viewModeContextMenus += "DataControl->Material Properties";
	viewModeContextMenus += "DataControl->Object";
	viewModeContextMenus += "SplatCloudEstimatorPlugin->SplatCloud Estimator";
	viewModeContextMenus += "SplatCloudRenderingControlPlugin->SplatCloud Rendering Control";
	viewModeContextMenus += "ViewControl->Visualization";

	// emit signals to add new viewmode
	emit defineViewModeToolboxes   ( "SplatCloud", viewModeToolboxes    );
	emit defineViewModeToolbars    ( "SplatCloud", viewModeToolbars     );
	emit defineViewModeContextMenus( "SplatCloud", viewModeContextMenus );
	emit defineViewModeIcon        ( "SplatCloud", "SplatCloudType.png" );
449 450 451 452 453 454 455 456 457 458 459
}


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


void SplatCloudRenderingControlPlugin::slotUpdateContextMenu( int _objectId )
{
	// get object by id
	if( _objectId == -1 )
		return;
460
	//
461 462 463 464 465 466 467
	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
468 469 470
	// if object is a SplatCloud...
	if( splatCloud )
	{
471 472
		// update context menu value
		contextCullingAction_->setChecked( splatCloud->isBackfaceCullingEnabled() );
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
	}
}


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


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 );
	}
}


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


504
void SplatCloudRenderingControlPlugin::slotToolboxEnableBackfaceCullingButtonClicked()
505
{
506 507 508 509 510 511 512 513 514 515 516 517 518 519
	// 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 );
	}
}
520

521 522 523 524 525 526

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


void SplatCloudRenderingControlPlugin::slotToolboxDisableBackfaceCullingButtonClicked()
{
527 528 529 530 531 532 533 534
	// 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
535
		splatCloud->enableBackfaceCulling( false );
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551

		// 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
552
		// get scenegraph splatcloud-object
553 554
		SplatCloudObject *splatCloud = PluginFunctions::splatCloudObject( *objIter );

Jan Möbius's avatar
Jan Möbius committed
555
		// apply update (reload standard and picking shaders and re-set uniforms)
556
		splatCloud->reloadShaders();
Jan Möbius's avatar
Jan Möbius committed
557 558
		splatCloud->setPointsizeScale    ( splatCloud->pointsizeScale()           );
		splatCloud->enableBackfaceCulling( splatCloud->isBackfaceCullingEnabled() );
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577

		// 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
578 579
		// apply update (make vertex-buffer-object invalid so it will be rebuilt the next time the node is drawn (or picked))
		splatCloudNode->invalidateVBO();
580

Jan Möbius's avatar
Jan Möbius committed
581 582
		// emit signal that object has to be updated
		emit updatedObject( objIter->id(), UPDATE_ALL );
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
	}
}


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


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
599 600 601 602 603 604 605 606 607 608 609
		// 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 );
610 611 612 613 614 615 616
	}
}


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


617
void SplatCloudRenderingControlPlugin::slotContextScaleActionTriggered()
618
{
619 620
	// get picked object by id
	int objectId = contextScaleAction_->data().toInt();
621 622
	if( objectId == -1 )
		return;
623
	//
624 625 626 627 628 629 630
	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
631 632 633 634 635
	// if object is a SplatCloud...
	if( splatCloud )
	{
		// update scale-widget option value
		scaleWidgetPointsizeScale_->setValue( splatCloud->pointsizeScale() );
636

Jan Möbius's avatar
Jan Möbius committed
637
		// move scale-widget to position of context menu entry
638
		scaleWidget_->move( contextScaleAction_->associatedWidgets()[0]->mapToGlobal( QPoint() ) );
639

Jan Möbius's avatar
Jan Möbius committed
640 641 642
		// show scale-widget
		scaleWidget_->show();
	}
643 644 645 646 647 648 649 650
}


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


void SplatCloudRenderingControlPlugin::slotScaleWidgetPointsizeScaleValueChanged()
{
651 652
	// get picked object by id
	int objectId = contextScaleAction_->data().toInt();
653 654
	if( objectId == -1 )
		return;
655
	//
656 657 658 659 660 661 662
	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
663 664 665 666 667 668 669 670
	// if object is a SplatCloud...
	if( splatCloud )
	{
		// get scale-widget option value
		float scale = (float) scaleWidgetPointsizeScale_->value();

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

Jan Möbius's avatar
Jan Möbius committed
672 673 674
		// emit signal that object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
	}
675 676 677 678 679 680
}


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


681
void SplatCloudRenderingControlPlugin::slotContextCullingActionTriggered()
682
{
683 684
	// get picked object by id
	int objectId = contextCullingAction_->data().toInt();
685 686
	if( objectId == -1 )
		return;
687
	//
688 689 690 691 692 693 694
	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
695 696 697
	// if object is a SplatCloud...
	if( splatCloud )
	{
698 699
		// get context menu option value
		bool enable = contextCullingAction_->isChecked();
Jan Möbius's avatar
Jan Möbius committed
700 701 702

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

Jan Möbius's avatar
Jan Möbius committed
704 705 706
		// emit signal that the object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
	}
707 708 709 710 711 712
}


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


713
void SplatCloudRenderingControlPlugin::slotContextReloadShadersActionTriggered()
714
{
715 716
	// get picked object by id
	int objectId = contextReloadShadersAction_->data().toInt();
717 718
	if( objectId == -1 )
		return;
719
	//
720 721 722 723 724 725 726
	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
727 728 729 730 731 732 733
	// 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() );
734

Jan Möbius's avatar
Jan Möbius committed
735 736 737
		// emit signal that object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
	}
738 739 740 741 742 743
}


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


744
void SplatCloudRenderingControlPlugin::slotContextRebuildVBOActionTriggered()
745
{
746 747
	// get picked object by id
	int objectId = contextRebuildVBOAction_->data().toInt();
748 749
	if( objectId == -1 )
		return;
750
	//
751 752 753 754 755 756 757
	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
758 759 760 761 762
	// 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();
763

Jan Möbius's avatar
Jan Möbius committed
764 765
		// emit signal that object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
766 767 768 769 770 771 772
	}
}


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


773
void SplatCloudRenderingControlPlugin::slotContextDefaultsActionTriggered()
774
{
775 776
	// get picked object by id
	int objectId = contextDefaultsAction_->data().toInt();
777 778
	if( objectId == -1 )
		return;
779
	//
780 781 782 783 784 785 786
	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
787 788 789 790 791 792 793 794 795 796 797 798 799
	// 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
800
		defaultsWidget_->move( contextDefaultsAction_->associatedWidgets()[0]->mapToGlobal( QPoint() ) );
Jan Möbius's avatar
Jan Möbius committed
801 802 803

		// show defaults widget
		defaultsWidget_->show();
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
	}
}


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


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


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


void SplatCloudRenderingControlPlugin::slotDefaultsWidgetApplyButtonClicked()
{
823 824
	// close widget
	defaultsWidget_->close();
825

826 827
	// get picked object by id
	int objectId = contextDefaultsAction_->data().toInt();
828 829
	if( objectId == -1 )
		return;
830
	//
831 832 833 834 835 836 837
	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
838 839 840 841 842 843 844 845 846 847 848
	// 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() ) );
849

Jan Möbius's avatar
Jan Möbius committed
850 851
		// emit signal that the object has to be updated
		emit updatedObject( object->id(), UPDATE_ALL );
852 853 854 855 856 857 858 859
	}
}


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


Q_EXPORT_PLUGIN2( splatcloudrenderingcontrolplugin, SplatCloudRenderingControlPlugin );