PluginFunctions.cc 31.8 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
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 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
42
43
44
45
46
47
48
49
50
51
52




//=============================================================================
//
//  Plugin Functions
//
//=============================================================================

#include <OpenFlipper/common/Types.hh>
53
#include <QGLWidget>
Jan Möbius's avatar
 
Jan Möbius committed
54
55

#include "PluginFunctions.hh"
Jan Möbius's avatar
   
Jan Möbius committed
56
#include "PluginFunctionsCore.hh"
Jan Möbius's avatar
 
Jan Möbius committed
57
58
59
60
61
62
63

namespace PluginFunctions {

 /** \brief DONT USE DIRECTLY!!
  *
  * This Pointer will be used to access the data trees root in the plugin. Never use it directly as
 *  the internal Structure will change. Use the Access functions instead */
Jan Möbius's avatar
Jan Möbius committed
64
static BaseObject* objectRoot_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
65
66
67
68
69

/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is internally used to acces the examiner widget in the main apllication
 */
Jan Möbius's avatar
   
Jan Möbius committed
70
static std::vector< glViewer* > examiner_widgets_;
Jan Möbius's avatar
Jan Möbius committed
71

Dirk Wilden's avatar
Dirk Wilden committed
72
73
74
75
76
77
/** \brief DONT USE DIRECTLY!!
 *
 * This vector is used internally to access properties of all viewers
 */
static std::vector< Viewer::ViewerProperties* > viewerProperties_;

Jan Möbius's avatar
Jan Möbius committed
78
/// TODO : Remove this variable and implement multiView correctly here
Jan Möbius's avatar
   
Jan Möbius committed
79
static glViewer*  examiner_widget_;
Jan Möbius's avatar
Jan Möbius committed
80

Jan Möbius's avatar
Docu    
Jan Möbius committed
81
/// Contains the currently active examiner
Jan Möbius's avatar
Jan Möbius committed
82
static unsigned int activeExaminer_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
83
84
85

/** \brief DONT USE DIRECTLY!!
 *
Jan Möbius's avatar
Jan Möbius committed
86
87
 * The pointer to the beginning of the scenegraph nodes ( only the nodes belonging to objects )
 * Between the actual root node ( sceneGraphRootNode_ ) and this node global nodes could be added
Jan Möbius's avatar
 
Jan Möbius committed
88
89
 * This pointer is internally used to access the scenegraphs root node
 */
Jan Möbius's avatar
Jan Möbius committed
90
91
92
93
94
95
static SeparatorNode* dataRootNode_ = 0;

/** This node is used to add nodes between the root node of the scenegraph and the objects separator node.
* It is directly below the sceneGraphRootNode_
*/
static SeparatorNode* dataSeparatorNode_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
96

Jan Möbius's avatar
Docu    
Jan Möbius committed
97
98
/** \brief Scenegraph root node
 */
Jan Möbius's avatar
Jan Möbius committed
99
static SeparatorNode* sceneGraphRootNode_ = 0;
Dirk Wilden's avatar
Dirk Wilden committed
100

Jan Möbius's avatar
Docu    
Jan Möbius committed
101
102
103
/** \brief a dummy properties object returned as a reference if the real object does not exist
 *
 */
Jan Möbius's avatar
   
Jan Möbius committed
104
105
static Viewer::ViewerProperties dummyProperties;

106
107
108
109
110
111
112

/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is used internally
 */
static ViewObjectMarker* defaultMarker_ = 0;

113
114
115
116
117
118
/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is used internally
 */
static QGLWidget* shareGLWidget_ = 0;

119
120
121
122
/** This is a unique id for the running OpenFlipper instance. Use it to identify yourself on the network
*/
static int viewerId_ = 0;

123
124
125
126
127
128
/// Number of currently open objects
static int objectCounter_ = 0;

/// Number of current target objects
static int targetCounter_ = 0;

Jan Möbius's avatar
 
Jan Möbius committed
129
130
131
132
void setDataRoot( BaseObject* _root ) {
   objectRoot_ = _root;
}

133
134
135
136
int viewers( ) {
  return examiner_widgets_.size();
}

137
138
139
140
int viewerId() {
  return viewerId_;
}

141
142
void setViewers( std::vector< glViewer* > _viewerWidgets ) {
   PluginFunctions::examiner_widgets_ = _viewerWidgets;
Jan Möbius's avatar
Jan Möbius committed
143
   PluginFunctions::examiner_widget_ =  examiner_widgets_[0];
144
145
146
147
148

   // Generate a (hopefully) unique viewer id
   QTime time = QTime::currentTime();
   qsrand( time.hour() * 10 + time.minute() * 100 + time.second() * 1000 + time.msec() * 10000  );
   viewerId_ = qrand();
Jan Möbius's avatar
Jan Möbius committed
149
150
}

Dirk Wilden's avatar
Dirk Wilden committed
151
152
153
154
void setViewerProperties( std::vector< Viewer::ViewerProperties* > _viewerProperties ) {
   PluginFunctions::viewerProperties_ = _viewerProperties;
}

155
void setActiveExaminer( const unsigned int _id ) {
Jan Möbius's avatar
Jan Möbius committed
156
  activeExaminer_ = _id;
Jan Möbius's avatar
 
Jan Möbius committed
157
158
}

159
160
161
162
163
164
165
166
167
glViewer* viewer(int  _viewerId ) {
   if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
     std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
     return examiner_widgets_[activeExaminer()];
   }

   return( examiner_widgets_[_viewerId] );
}

168
169
170
171
unsigned int activeExaminer( ) {
  return activeExaminer_;
}

172
173
174
175
176
177
QString getEncodedExaminerView() {
  return getEncodedExaminerView(activeExaminer());
}

/// Get the encoded view for the given
QString getEncodedExaminerView(int _viewerId) {
Mike Kremer's avatar
Mike Kremer committed
178

179
  QString view;
Mike Kremer's avatar
Mike Kremer committed
180

181
182
183
184
  if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
     std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
     examiner_widgets_[activeExaminer()]->encodeView ( view );
     return view;
Mike Kremer's avatar
Mike Kremer committed
185
186
  }

187
188
  examiner_widgets_[_viewerId]->encodeView ( view );
  return view;
Mike Kremer's avatar
Mike Kremer committed
189

190
191
192
193
194
195
196
}

void setEncodedExaminerView( QString _view ) {
  setEncodedExaminerView( activeExaminer() , _view );
}

void setEncodedExaminerView(int _viewerId , QString _view ) {
Mike Kremer's avatar
Mike Kremer committed
197

198
199
200
  if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
     std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
     examiner_widgets_[activeExaminer()]->decodeView ( _view );
Mike Kremer's avatar
Mike Kremer committed
201
202
  }

203
  examiner_widgets_[_viewerId]->decodeView ( _view );
Mike Kremer's avatar
Mike Kremer committed
204
205
}

Jan Möbius's avatar
Jan Möbius committed
206
207
208
void setDataSeparatorNodes( SeparatorNode* _dataSeparatorNode ) {
  
  // The function should only be called once by the core. 
209

Jan Möbius's avatar
Jan Möbius committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
  // Set the separatorNode
  PluginFunctions::dataSeparatorNode_ = _dataSeparatorNode;

  
  if ( PluginFunctions::dataSeparatorNode_->nChildren() != 1 ){
    std::cerr << "Only one child allowed for dataSeparatorNode on initialization!" << std::endl;
    std::cerr << "The Core has initialized the scenegraph in a strange way!" << std::endl;
    ACG::SceneGraph::BaseNode* child = *(PluginFunctions::dataSeparatorNode_->childrenBegin());
  }
  
  // Set the root node for the data objects
  // which has to be a child of the dataSeparatorNode_
  PluginFunctions::dataRootNode_ = dynamic_cast<ACG::SceneGraph::SeparatorNode*> (*(PluginFunctions::dataSeparatorNode_->childrenBegin()) );
  
Jan Möbius's avatar
 
Jan Möbius committed
224
225
}

Jan Möbius's avatar
   
Jan Möbius committed
226
void setSceneGraphRootNode( SeparatorNode* _root_node ) {
Jan Möbius's avatar
Jan Möbius committed
227
   PluginFunctions::sceneGraphRootNode_ = _root_node;
Dirk Wilden's avatar
Dirk Wilden committed
228
229
}

Jan Möbius's avatar
   
Jan Möbius committed
230
bool getPickedObject(const unsigned int _node_idx , BaseObjectData*& _object) {
Jan Möbius's avatar
   
Jan Möbius committed
231
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
232
233
234
235
236
237
238
239
240
    if ( o_it->picked( _node_idx ) ) {
      _object = *o_it;
      return true;
    }
  }
  return false;
}


Jan Möbius's avatar
   
Jan Möbius committed
241
bool getSourceIdentifiers( std::vector<int>& _identifiers  ) {
Jan Möbius's avatar
 
Jan Möbius committed
242
243
  _identifiers.clear();

Jan Möbius's avatar
   
Jan Möbius committed
244
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
245
246
247
248
249
250
    if ( o_it->source() )
      _identifiers.push_back ( o_it->id() );
  }
  return (_identifiers.size() >0 );
}

Jan Möbius's avatar
   
Jan Möbius committed
251
bool getTargetIdentifiers( std::vector<int>& _identifiers  ) {
Jan Möbius's avatar
 
Jan Möbius committed
252
253
  _identifiers.clear();

Jan Möbius's avatar
   
Jan Möbius committed
254
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
255
256
257
258
259
260
261
262
263
264
    if ( o_it->target() )
      _identifiers.push_back ( o_it->id() );
  }
  return (_identifiers.size() >0 );
}

// ===============================================================================
// Get objects
// ===============================================================================

Jan Möbius's avatar
   
Jan Möbius committed
265
bool getObject(  const int _identifier , BaseObject*& _object ) {
266

Jan Möbius's avatar
 
Jan Möbius committed
267
268
  if ( _identifier == -1 )
    return false;
269

Jan Möbius's avatar
 
Jan Möbius committed
270
271
272
273
  _object = objectRoot_->childExists( _identifier );
  return ( _object != 0 );
}

Jan Möbius's avatar
   
Jan Möbius committed
274
bool getObject(  const int _identifier , BaseObjectData*& _object ) {
275

Jan Möbius's avatar
 
Jan Möbius committed
276
277
  if ( _identifier == -1 )
    return false;
278

Jan Möbius's avatar
 
Jan Möbius committed
279
280
281
282
283
  BaseObject* object = objectRoot_->childExists( _identifier );
  _object = dynamic_cast< BaseObjectData* >(object);
  return ( _object != 0 );
}

284
285
286
287
288
289
290
291
int getObjectId( const QString _name ) {

	if(_name.isEmpty()) return -1;

	BaseObject* object = objectRoot_->childExists( _name );
	return object->id();
}

Jan Möbius's avatar
 
Jan Möbius committed
292
293
294
// ===============================================================================
// ===============================================================================

295
bool object_exists(  const int _identifier ) {
296

Jan Möbius's avatar
 
Jan Möbius committed
297
298
  if ( _identifier == -1 )
    return false;
299

Jan Möbius's avatar
 
Jan Möbius committed
300
301
302
303
304
305
  BaseObject* object = objectRoot_->childExists( _identifier );
  return ( object != 0 );
}

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

Jan Möbius's avatar
   
Jan Möbius committed
306
bool getAllMeshes( std::vector<int>& _identifiers  ) {
Jan Möbius's avatar
 
Jan Möbius committed
307
308
309
310

  _identifiers.clear();

  // find changed manipulator
311
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,typeId("TriangleMesh")) ;
Jan Möbius's avatar
   
Jan Möbius committed
312
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
313
314
315
316
317
318
319
320
321
322
323
324
    _identifiers.push_back( o_it->id() );
  }

  return (_identifiers.size() > 0);
}

bool get_all_object_identifiers( std::vector<int>& _identifiers  ) {

  _identifiers.clear();

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
Jan Möbius's avatar
   
Jan Möbius committed
325
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
326
327
328
329
330
331
332
    _identifiers.push_back( o_it->id() );
  }

  return (_identifiers.size() > 0);
}

void setBackColor( OpenMesh::Vec4f _color) {
333
  for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
334
    PluginFunctions::viewerProperties(i).backgroundColor(_color);
Jan Möbius's avatar
 
Jan Möbius committed
335
336
}

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
void setFixedView(int _mode, int _viewer ) {

  if ( (_viewer != ACTIVE_VIEWER ) && ( ( _viewer < 0 ) || _viewer >= (int)examiner_widgets_.size()) ){
    std::cerr << "Unable to set fixed view. Wrong viewer id (" << _viewer << ")" << std::endl;
    return;
  }

  switch ( _mode ){
    case VIEW_TOP : //TOP
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, -1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
      PluginFunctions::allowRotation(false, _viewer);
      break;
    case VIEW_BOTTOM : //BOTTOM
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
      PluginFunctions::allowRotation(false, _viewer);
      break;
    case VIEW_LEFT : //LEFT
      PluginFunctions::viewingDirection( ACG::Vec3d(1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
      PluginFunctions::allowRotation(false, _viewer);
      break;
    case VIEW_RIGHT : //RIGHT
      PluginFunctions::viewingDirection( ACG::Vec3d(-1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
      PluginFunctions::allowRotation(false, _viewer);
      break;
    case VIEW_FRONT : //FRONT
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 0.0, -1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
      PluginFunctions::allowRotation(false, _viewer);
      break;
    case VIEW_BACK : //BACK
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 0.0, 1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
      PluginFunctions::allowRotation(false, _viewer);
      break;
    default : //Free View
      PluginFunctions::allowRotation(true, _viewer);
      break;
  }

  if ( _viewer == ACTIVE_VIEWER )
    viewerProperties(activeExaminer()).currentViewingDirection( _mode );
  else
    viewerProperties( _viewer ).currentViewingDirection( _mode );
}

380
QPoint mapToGlobal(const QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
381
  return examiner_widgets_[activeExaminer_]->glMapToGlobal(_point);
Jan Möbius's avatar
 
Jan Möbius committed
382
383
}

384
QPoint mapToLocal( const QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
385
  return examiner_widgets_[activeExaminer_]->glMapFromGlobal(_point);
Jan Möbius's avatar
 
Jan Möbius committed
386
387
}

388
389
void setDrawMode( const unsigned int _mode , int _viewer) {

Jan Möbius's avatar
Jan Möbius committed
390
  if ( _viewer == ACTIVE_VIEWER )
391
392
    viewerProperties(activeExaminer()).drawMode(_mode);
  else if ( _viewer == ALL_VIEWERS )
Jan Möbius's avatar
Jan Möbius committed
393
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
394
      viewerProperties(i).drawMode(_mode);
Jan Möbius's avatar
Jan Möbius committed
395
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
396
    viewerProperties(_viewer).drawMode(_mode);
397
398
399
  else
    std::cerr << "Requested illegal viewer for setting DrawMode!!" << std::endl;

Jan Möbius's avatar
 
Jan Möbius committed
400
401
402
403
404
405
406
}

/** Get the current draw Mode of the examiner widget.\n
 *
 * The DrawModes are defined at ACG/Scenegraph/DrawModes.hh \n
 * They can be combined.
 */
407
408
unsigned int drawMode( int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
409
    return viewerProperties(activeExaminer()).drawMode();
410
411
412
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get viewing direction!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
413
    return viewerProperties(_viewer).drawMode();
414
415
  else
    std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
416

417
  return viewerProperties(activeExaminer()).drawMode();
418
419
}

Jan Möbius's avatar
   
Jan Möbius committed
420
bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {
Jan Möbius's avatar
Jan Möbius committed
421
422
423
424

   return examiner_widgets_[activeExaminer_]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
}

Jan Möbius's avatar
   
Jan Möbius committed
425
bool scenegraphPick( const unsigned int _examiner, ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {
Jan Möbius's avatar
Jan Möbius committed
426
427
428
429
430
431

  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return false;
  }
  return examiner_widgets_[_examiner]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
Jan Möbius's avatar
 
Jan Möbius committed
432
433
}

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
bool scenegraphRegionPick( ACG::SceneGraph::PickTarget                _pickTarget,
                           const QRegion&                             _region,
                           QList<QPair<unsigned int, unsigned int> >& _list)
{
  return examiner_widgets_[activeExaminer_]->pick_region( _pickTarget, _region, _list);
}

bool scenegraphRegionPick( const unsigned int                         _examiner,
                           ACG::SceneGraph::PickTarget                _pickTarget,
                           const QRegion&                             _region,
                           QList<QPair<unsigned int, unsigned int> >& _list)
{
  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return false;
  }
  return examiner_widgets_[_examiner]->pick_region( _pickTarget, _region, _list);
}


Jan Möbius's avatar
 
Jan Möbius committed
454
455
456

//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse( ACG::SceneGraph::MouseEventAction  &_action ) {
457
458
459
  // Single pass action, as the mouse action will only update the graph.
  // If its changed, it will be set to dirty and an automatic redraw is triggered.
  ACG::SceneGraph::traverse(sceneGraphRootNode_, _action,viewerProperties().glState() );
Jan Möbius's avatar
 
Jan Möbius committed
460
461
}

Jan Möbius's avatar
Jan Möbius committed
462
//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
463
void traverse( const unsigned int _examiner, ACG::SceneGraph::MouseEventAction  &_action ) {
Jan Möbius's avatar
Jan Möbius committed
464
465
466
467
468
469

  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return;
  }

470
471
  // Single pass action, as the mouse action will only update the graph.
  // If its changed, it will be set to dirty and an automatic redraw is triggered.
Jan Möbius's avatar
Jan Möbius committed
472
  ACG::SceneGraph::traverse(sceneGraphRootNode_, _action,viewerProperties(_examiner).glState() );
Jan Möbius's avatar
Jan Möbius committed
473
474
475
}


476
const std::string pickMode () {
477
  // No seperate draw modes available all should have the same so take first
478
  return viewerProperties().pickMode();
Jan Möbius's avatar
 
Jan Möbius committed
479
480
481
}

void pickMode ( std::string _mode) {
482
483
  // switch to default marker
  setViewObjectMarker (defaultViewObjectMarker ());
484
  viewerProperties().pickMode(_mode);
Jan Möbius's avatar
Jan Möbius committed
485
486
}

487
488
Viewer::ActionMode actionMode() {
   return viewerProperties().actionMode();
Jan Möbius's avatar
 
Jan Möbius committed
489
490
}

Jan Möbius's avatar
   
Jan Möbius committed
491
492
void actionMode ( Viewer::ActionMode _mode) {

493
  viewerProperties().actionMode(_mode);
Jan Möbius's avatar
 
Jan Möbius committed
494
495
}

496
497
498
499
500
501
502
503
504
505
void shareGLWidget (QGLWidget *_widget)
{
  shareGLWidget_ = _widget;
}

QGLWidget *shareGLWidget ()
{
  return shareGLWidget_;
}

Jan Möbius's avatar
 
Jan Möbius committed
506
void getCurrentViewImage(QImage& _image) {
507
  viewer( activeExaminer() )->snapshot( _image, true );
Jan Möbius's avatar
 
Jan Möbius committed
508
509
}

Jan Möbius's avatar
   
Jan Möbius committed
510
Viewer::ViewerProperties& viewerProperties(int _id) {
Dirk Wilden's avatar
Dirk Wilden committed
511
  if ( _id >= (int)viewerProperties_.size() ) {
Jan Möbius's avatar
   
Jan Möbius committed
512
513
514
515
516
517
518
    std::cerr << " Error, requested properties for non-existing Viewer!" << std::endl;
    return dummyProperties;
  }

  if ( _id == -1 )
    _id = activeExaminer_;

Dirk Wilden's avatar
Dirk Wilden committed
519
  return ( *viewerProperties_[_id] );
Jan Möbius's avatar
   
Jan Möbius committed
520

Jan Möbius's avatar
 
Jan Möbius committed
521
522
}

Jan Möbius's avatar
Jan Möbius committed
523
524
525
526
527
528
529
530
531
532
void perspectiveProjection( int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->perspectiveProjection();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->perspectiveProjection();
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->perspectiveProjection();
  else
    std::cerr << "Requested illegal viewer for perspectiveProjection()!!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
533
534
}

Jan Möbius's avatar
Jan Möbius committed
535
536
537
538
539
540
541
542
543
544
void orthographicProjection( int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->orthographicProjection();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->orthographicProjection();
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->orthographicProjection();
  else
    std::cerr << "Requested illegal viewer for orthographicProjection()!!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
545
546
}

547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
void allowRotation(bool _mode, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->allowRotation(_mode);
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->allowRotation(_mode);
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->allowRotation(_mode);
  else
    std::cerr << "Requested illegal viewer for allowRotation!!" << std::endl;
}

bool allowRotation( int _viewer ) {

  if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return examiner_widgets_[_viewer]->allowRotation();
  else {

    std::cerr << "Requested illegal viewer for isRotationAllowed!!" << std::endl;
    return false;
  }
Jan Möbius's avatar
 
Jan Möbius committed
568
569
}

570
571
572
573
void setMainGLContext() {
  examiner_widget_->makeCurrent();
}

574
575
576
577
578
579
580
581
582
583
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up , int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->viewingDirection(_dir,_up);
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->viewingDirection(_dir,_up);
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->viewingDirection(_dir,_up);
  else
    std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
584
585
}

586
587
588
589
590
591
592
593
594
595
const ACG::Vec3d trackBallCenter(const ACG::Vec3d& _center, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return examiner_widgets_[activeExaminer_]->trackBallCenter();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      return examiner_widgets_[i]->trackBallCenter(  );
    else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
      return examiner_widgets_[_viewer]->trackBallCenter(  );
    else
      std::cerr << "Requested illegal viewer for setTrackBallCenter!!" << std::endl;
Jan Möbius's avatar
Jan Möbius committed
596
597

  return examiner_widgets_[activeExaminer_]->trackBallCenter();
598
599
600
601
602
603
604
605
606
607
608
609
610
611
}

void setTrackBallCenter(const ACG::Vec3d& _center, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->setTrackBallCenter( _center );
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->setTrackBallCenter( _center );
    else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
      examiner_widgets_[_viewer]->setTrackBallCenter( _center );
    else
      std::cerr << "Requested illegal viewer for setTrackBallCenter!!" << std::endl;
}

612
613
614
615
616
617
618
619
620
621
void setScenePos(const ACG::Vec3d& _center,const double _radius, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->setScenePos( _center, _radius );
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->setScenePos( _center, _radius );
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->setScenePos( _center, _radius );
  else
    std::cerr << "Requested illegal viewer for setScenePos!!" << std::endl;
622
623
}

624
625
626
627
628
629
630
631
632
633
void setScenePos(const ACG::Vec3d& _center, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->setScenePos( _center, examiner_widgets_[activeExaminer_]->scene_radius() );
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->setScenePos( _center, examiner_widgets_[i]->scene_radius() );
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->setScenePos( _center, examiner_widgets_[_viewer]->scene_radius() );
  else
    std::cerr << "Requested illegal viewer for setScenePos!!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
634
635
}

636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
void setSceneCenter(const ACG::Vec3d& _center, int _viewer) {

	if (_viewer == ACTIVE_VIEWER) {

		examiner_widgets_[activeExaminer_]->setSceneCenter(_center);
	} else if (_viewer == ALL_VIEWERS) {

		for (uint i = 0; i < examiner_widgets_.size(); ++i) {

			examiner_widgets_[i]->setSceneCenter(_center);
		}
	} else if ((_viewer >= 0) && _viewer < (int) examiner_widgets_.size()) {

		examiner_widgets_[_viewer]->setSceneCenter(_center);
	} else {
		std::cerr << "Requested illegal viewer for setSceneCenter!!"
				<< std::endl;
	}
}

const ACG::Vec3d& sceneCenter(int _viewer) {

	if (_viewer == ACTIVE_VIEWER) {
		return examiner_widgets_[activeExaminer_]->scene_center();
	} else if (_viewer == ALL_VIEWERS)
		std::cerr << "Please select viewer to get viewing direction!"
				<< std::endl;
	else if ((_viewer >= 0) && _viewer < (int) examiner_widgets_.size())
		return examiner_widgets_[_viewer]->scene_center();
	else
		std::cerr << "Requested illegal viewer for sceneCenter!!" << std::endl;
Jan Möbius's avatar
Jan Möbius committed
667

668
	return examiner_widgets_[activeExaminer_]->scene_center();
Jan Möbius's avatar
 
Jan Möbius committed
669
670
671
}

double sceneRadius() {
672
   return examiner_widgets_[activeExaminer_]->scene_radius();
Jan Möbius's avatar
 
Jan Möbius committed
673
674
}

675
676
677
678
679
680
681
682
683
double sceneRadius( int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return examiner_widgets_[activeExaminer_]->scene_radius();
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Illegal request for scene radius. Please select one viewer!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return examiner_widgets_[_viewer]->scene_radius();
  else
    std::cerr << "Requested illegal viewer for translate!!" << std::endl;
Mike Kremer's avatar
Mike Kremer committed
684

685
686
687
  return -1;
}

688
689
690
691
692
693
694
695
696
697
void translate( const ACG::Vec3d &_vector , int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->translate(_vector);
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->translate(_vector);
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->translate(_vector);
  else
    std::cerr << "Requested illegal viewer for translate!!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
698
699
}

700
void rotate(const ACG::Vec3d&  _axis,
701
            const double       _angle,
702
703
            const ACG::Vec3d&  _center,
            int                _viewer )
Jan Möbius's avatar
 
Jan Möbius committed
704
{
705
706
707
708
709
710
711
712
713
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->rotate(_axis,_angle,_center);
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->rotate(_axis,_angle,_center);
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->rotate(_axis,_angle,_center);
  else
    std::cerr << "Requested illegal viewer for rotate!!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
714
715
}

716
717
718
719
720
721
722
723
724
725
void viewHome(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->home();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->home();
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->home();
  else
    std::cerr << "Requested illegal viewer for viewHome!!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
726
727
}

728
729
730
731
732
733
734
735
736
737
void viewAll(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->viewAll();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->viewAll();
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->viewAll();
  else
    std::cerr << "Requested illegal viewer for viewAll!!" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
738
739
}

740
741
742
743
744
745
746
747
748
749
ACG::Vec3d viewingDirection(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return viewerProperties(activeExaminer_).glState().viewing_direction();
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get viewing direction!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return viewerProperties(_viewer).glState().viewing_direction();
  else
    std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;

750
  return viewerProperties().glState().viewing_direction();
Jan Möbius's avatar
 
Jan Möbius committed
751
752
}

753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
bool isProjectionOrthographic( int _viewer ) {

  if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() ){

    if ( examiner_widgets_[_viewer]->projectionMode() == 0) //ORTHOGRAPHIC_PROJECTION
      return true;
    else
      return false;

  } else
    std::cerr << "Requested illegal viewer for isProjectionOrthographic!!" << std::endl;

  return false;
}

768
769
770
771
772
773
774
775
776
777
ACG::Vec3d eyePos(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return viewerProperties(activeExaminer_).glState().eye();
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get eyePos!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return viewerProperties(_viewer).glState().eye();
  else
    std::cerr << "Requested illegal viewer for eyePos!!" << std::endl;

778
  return viewerProperties().glState().eye();
Jan Möbius's avatar
 
Jan Möbius committed
779
780
}

781
782
783
784
785
786
787
788
789
790
ACG::Vec3d upVector(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return viewerProperties(activeExaminer_).glState().up();
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get up vector!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return viewerProperties(_viewer).glState().up();
  else
    std::cerr << "Requested illegal viewer for up vector!!" << std::endl;

791
  return viewerProperties().glState().up();
Jan Möbius's avatar
 
Jan Möbius committed
792
793
}

794
795
void setViewObjectMarker(ViewObjectMarker * _marker)
{
Jan Möbius's avatar
Jan Möbius committed
796
797
  for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
    PluginFunctions::viewerProperties(i).objectMarker(_marker);
798
799
800
801
802
803
804
805
806
807
808
809
810
}

void setDefaultViewObjectMarker(ViewObjectMarker * _marker)
{
  defaultMarker_ = _marker;
}

ViewObjectMarker * defaultViewObjectMarker()
{
  return defaultMarker_;
}


Dirk Wilden's avatar
Dirk Wilden committed
811
ACG::SceneGraph::BaseNode* getSceneGraphRootNode() {
Jan Möbius's avatar
Jan Möbius committed
812
   return PluginFunctions::sceneGraphRootNode_;
Dirk Wilden's avatar
Dirk Wilden committed
813
814
}

Jan Möbius's avatar
 
Jan Möbius committed
815
ACG::SceneGraph::BaseNode* getRootNode() {
Jan Möbius's avatar
Jan Möbius committed
816
  return PluginFunctions::dataRootNode_;
Jan Möbius's avatar
 
Jan Möbius committed
817
818
}

Jan Möbius's avatar
Jan Möbius committed
819
820
821
void addGlobalNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::sceneGraphRootNode_)
    _node->set_parent( PluginFunctions::sceneGraphRootNode_ );
Dirk Wilden's avatar
Dirk Wilden committed
822
823
824
}


Jan Möbius's avatar
Jan Möbius committed
825
826
827
828
829
830
831
832
833
834
835
void addObjectRenderingNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::sceneGraphRootNode_){
    
    // get the current parent Node 
    ACG::SceneGraph::BaseNode* parent = dataRootNode_->parent();

    // Move the node to the new parent
    _node->set_parent(parent);
    
    // move dataRootNode_ to the new parent
    dataRootNode_->set_parent(_node);
Dirk Wilden's avatar
Dirk Wilden committed
836
  }
Jan Möbius's avatar
Jan Möbius committed
837
  
Dirk Wilden's avatar
Dirk Wilden committed
838
839
}

Jan Möbius's avatar
   
Jan Möbius committed
840
int objectCount() {
841
  return(objectCounter_);
Jan Möbius's avatar
 
Jan Möbius committed
842
843
844
845
}



846
847
int targetCount() {
  return ( targetCounter_ );
Jan Möbius's avatar
 
Jan Möbius committed
848
849
}

Jan Möbius's avatar
   
Jan Möbius committed
850
int sourceCount() {
Jan Möbius's avatar
 
Jan Möbius committed
851
852
853
854
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS) ;
Jan Möbius's avatar
   
Jan Möbius committed
855
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
856
857
858
859
860
861
    ++count;
  }

  return ( count );
}

Jan Möbius's avatar
   
Jan Möbius committed
862
int visibleCount() {
Jan Möbius's avatar
 
Jan Möbius committed
863
864
865
866
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
Jan Möbius's avatar
   
Jan Möbius committed
867
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
    if ( o_it->visible() )
    ++count;
  }

  return ( count );

}


/** Returns a vector containing all currently available objects
 *
 * @param _objects vector of all objects
 */
void get_all_objects( std::vector < BaseObjectData*>& _objects ) {

   _objects.clear();

  // find changed manipulator
886
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_ALL) ;
Jan Möbius's avatar
   
Jan Möbius committed
887
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
888
889
890
891
892
893
    _objects.push_back( *o_it );
  }

}

///   Fly to point and viewing direction (animated).
Jan Möbius's avatar
   
Jan Möbius committed
894
void   flyTo (const ACG::Vec3d &_position, const ACG::Vec3d &_center, double _time) {
895
   examiner_widgets_[activeExaminer_]->flyTo(_position,_center,_time);
Jan Möbius's avatar
 
Jan Möbius committed
896
897
898
899
900
901
902
903
904
905
}


// ===============================================================================
// Getting data from objects and casting between them
// ===============================================================================

BaseObjectData* baseObjectData( BaseObject* _object ){
  if ( _object == 0 )
    return 0;
906

Jan Möbius's avatar
 
Jan Möbius committed
907
908
909
910
911
912
  return dynamic_cast< BaseObjectData* >(_object);
}

// ===============================================================================
// Get the root of the object structure
// ===============================================================================
Jan Möbius's avatar
Jan Möbius committed
913
BaseObject*& objectRoot() {
Jan Möbius's avatar
 
Jan Möbius committed
914
915
916
  return (objectRoot_);
}

917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
void increaseObjectCount() {
  objectCounter_++;
}

// Increase the number of current Object
void decreaseObjectCount() {
  objectCounter_--;
  
  if ( objectCounter_ < 0 )
    std::cerr << "Deleted more objects than created!!!" << std::endl;
}

void increaseTargetCount() {
  targetCounter_++;
}

// Increase the number of current Object
void decreaseTargetCount() {
  targetCounter_--;
  
  if ( targetCounter_ < 0 )
    std::cerr << "target object counter underflow!!!" << std::endl;
}

Jan Möbius's avatar
 
Jan Möbius committed
941
}