PluginFunctions.cc 21.8 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16
17
18
19
//  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.
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




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

#include <OpenFlipper/common/Types.hh>

#include "PluginFunctions.hh"
Jan Möbius's avatar
   
Jan Möbius committed
44
#include "PluginFunctionsCore.hh"
Jan Möbius's avatar
 
Jan Möbius committed
45
46
47
48
49
50
51
52
53
54
55
56
57

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 */
static BaseObject* objectRoot_;

/** \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
58
static std::vector< glViewer* > examiner_widgets_;
Jan Möbius's avatar
Jan Möbius committed
59

Dirk Wilden's avatar
Dirk Wilden committed
60
61
62
63
64
65
/** \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
66
/// TODO : Remove this variable and implement multiView correctly here
Jan Möbius's avatar
   
Jan Möbius committed
67
static glViewer*  examiner_widget_;
Jan Möbius's avatar
Jan Möbius committed
68
69

static unsigned int activeExaminer_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
70
71
72
73
74
75
76

/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is internally used to access the scenegraphs root node
 */
static SeparatorNode* root_node_;

Dirk Wilden's avatar
Dirk Wilden committed
77
78
static SeparatorNode* sceneGraph_root_node_;

Jan Möbius's avatar
   
Jan Möbius committed
79
80
static Viewer::ViewerProperties dummyProperties;

Jan Möbius's avatar
 
Jan Möbius committed
81
82
83
84
void setDataRoot( BaseObject* _root ) {
   objectRoot_ = _root;
}

85
86
87
88
int viewers( ) {
  return examiner_widgets_.size();
}

89
90
void setViewers( std::vector< glViewer* > _viewerWidgets ) {
   PluginFunctions::examiner_widgets_ = _viewerWidgets;
Jan Möbius's avatar
Jan Möbius committed
91
92
93
   PluginFunctions::examiner_widget_ =  examiner_widgets_[0];
}

Dirk Wilden's avatar
Dirk Wilden committed
94
95
96
97
void setViewerProperties( std::vector< Viewer::ViewerProperties* > _viewerProperties ) {
   PluginFunctions::viewerProperties_ = _viewerProperties;
}

98
void setActiveExaminer( const unsigned int _id ) {
Jan Möbius's avatar
Jan Möbius committed
99
  activeExaminer_ = _id;
Jan Möbius's avatar
 
Jan Möbius committed
100
101
}

102
103
104
105
106
107
108
109
110
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] );
}

111
112
113
114
unsigned int activeExaminer( ) {
  return activeExaminer_;
}

Jan Möbius's avatar
   
Jan Möbius committed
115
void setRootNode( SeparatorNode* _root_node ) {
Jan Möbius's avatar
 
Jan Möbius committed
116
117
118
   PluginFunctions::root_node_ = _root_node;
}

Jan Möbius's avatar
   
Jan Möbius committed
119
void setSceneGraphRootNode( SeparatorNode* _root_node ) {
Dirk Wilden's avatar
Dirk Wilden committed
120
121
122
   PluginFunctions::sceneGraph_root_node_ = _root_node;
}

Jan Möbius's avatar
   
Jan Möbius committed
123
bool getPickedObject(const unsigned int _node_idx , BaseObjectData*& _object) {
Jan Möbius's avatar
   
Jan Möbius committed
124
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
125
126
127
128
129
130
131
132
133
    if ( o_it->picked( _node_idx ) ) {
      _object = *o_it;
      return true;
    }
  }
  return false;
}


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

Jan Möbius's avatar
   
Jan Möbius committed
137
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
138
139
140
141
142
143
    if ( o_it->source() )
      _identifiers.push_back ( o_it->id() );
  }
  return (_identifiers.size() >0 );
}

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

Jan Möbius's avatar
   
Jan Möbius committed
147
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
148
149
150
151
152
153
154
155
156
157
    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
158
bool getObject(  const int _identifier , BaseObject*& _object ) {
159

Jan Möbius's avatar
 
Jan Möbius committed
160
161
  if ( _identifier == -1 )
    return false;
162

Jan Möbius's avatar
 
Jan Möbius committed
163
164
165
166
  _object = objectRoot_->childExists( _identifier );
  return ( _object != 0 );
}

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

Jan Möbius's avatar
 
Jan Möbius committed
169
170
  if ( _identifier == -1 )
    return false;
171

Jan Möbius's avatar
 
Jan Möbius committed
172
173
174
175
176
177
178
179
  BaseObject* object = objectRoot_->childExists( _identifier );
  _object = dynamic_cast< BaseObjectData* >(object);
  return ( _object != 0 );
}

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

180
int copyObject( const int _id ) {
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  if ( _id == -1 )
    return -1;

  // get the node
  BaseObject* object = objectRoot_->childExists(_id);

  if ( !object ) {
    std::cerr << "Error while copying object ... not found" << std::endl;
    return -1;
  }

  // remove the whole subtree below this item
  BaseObject* copy = object->copy();

  if ( copy == 0 ) {
    std::cerr << "Unable to create a copy of the object." << std::endl;
  }

  // Integrate into object tree
  copy->setParent( object->parent() );
  if ( object->parent() )
    object->parent()->appendChild(copy);
  else
    std::cerr << "Unable to add copy to object list" << std::endl;

  return copy->id();
}
Jan Möbius's avatar
 
Jan Möbius committed
208

209
bool object_exists(  const int _identifier ) {
210

Jan Möbius's avatar
 
Jan Möbius committed
211
212
  if ( _identifier == -1 )
    return false;
213

Jan Möbius's avatar
 
Jan Möbius committed
214
215
216
217
218
219
  BaseObject* object = objectRoot_->childExists( _identifier );
  return ( object != 0 );
}

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

Jan Möbius's avatar
   
Jan Möbius committed
220
bool getAllMeshes( std::vector<int>& _identifiers  ) {
Jan Möbius's avatar
 
Jan Möbius committed
221
222
223
224
225

  _identifiers.clear();

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ;
Jan Möbius's avatar
   
Jan Möbius committed
226
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
227
228
229
230
231
232
233
234
235
236
237
238
    _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
239
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
240
241
242
243
244
245
246
    _identifiers.push_back( o_it->id() );
  }

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

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

251
QPoint mapToGlobal(const QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
252
  return examiner_widgets_[activeExaminer_]->glMapToGlobal(_point);
Jan Möbius's avatar
 
Jan Möbius committed
253
254
}

255
QPoint mapToLocal( const QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
256
  return examiner_widgets_[activeExaminer_]->glMapFromGlobal(_point);
Jan Möbius's avatar
 
Jan Möbius committed
257
258
}

259
260
void setDrawMode( const unsigned int _mode , int _viewer) {

Jan Möbius's avatar
Jan Möbius committed
261
  if ( _viewer == ACTIVE_VIEWER )
262
263
    viewerProperties(activeExaminer()).drawMode(_mode);
  else if ( _viewer == ALL_VIEWERS )
Jan Möbius's avatar
Jan Möbius committed
264
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
265
      viewerProperties(i).drawMode(_mode);
Jan Möbius's avatar
Jan Möbius committed
266
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
267
    viewerProperties(_viewer).drawMode(_mode);
268
269
270
  else
    std::cerr << "Requested illegal viewer for setting DrawMode!!" << std::endl;

Jan Möbius's avatar
 
Jan Möbius committed
271
272
273
274
275
276
277
}

/** Get the current draw Mode of the examiner widget.\n
 *
 * The DrawModes are defined at ACG/Scenegraph/DrawModes.hh \n
 * They can be combined.
 */
278
279
unsigned int drawMode( int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
280
    return viewerProperties(activeExaminer()).drawMode();
281
282
283
  } 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() )
284
    return viewerProperties(_viewer).drawMode();
285
286
  else
    std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
287

288
  return viewerProperties(activeExaminer()).drawMode();
289
290
}

Jan Möbius's avatar
   
Jan Möbius committed
291
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
292
293
294
295

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

Jan Möbius's avatar
   
Jan Möbius committed
296
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
297
298
299
300
301
302

  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
303
304
}

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
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
325
326
327

//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse( ACG::SceneGraph::MouseEventAction  &_action ) {
328
   ACG::SceneGraph::traverse(sceneGraph_root_node_,
329
                             _action,viewerProperties().glState() );
Jan Möbius's avatar
 
Jan Möbius committed
330
331
}

Jan Möbius's avatar
Jan Möbius committed
332
//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
333
void traverse( const unsigned int _examiner, ACG::SceneGraph::MouseEventAction  &_action ) {
Jan Möbius's avatar
Jan Möbius committed
334
335
336
337
338
339

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

340
  ACG::SceneGraph::traverse(sceneGraph_root_node_, _action,viewerProperties(_examiner).glState() );
Jan Möbius's avatar
Jan Möbius committed
341
342
343
}


344
const std::string pickMode () {
345
  // No seperate draw modes available all should have the same so take first
346
  return viewerProperties().pickMode();
Jan Möbius's avatar
 
Jan Möbius committed
347
348
349
}

void pickMode ( std::string _mode) {
350
  viewerProperties().pickMode(_mode);
Jan Möbius's avatar
Jan Möbius committed
351
352
}

353
354
Viewer::ActionMode actionMode() {
   return viewerProperties().actionMode();
Jan Möbius's avatar
 
Jan Möbius committed
355
356
}

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

359
  viewerProperties().actionMode(_mode);
Jan Möbius's avatar
 
Jan Möbius committed
360
361
362
363
364
365
}

void getCurrentViewImage(QImage& _image) {
  examiner_widget_->copyToImage( _image );
}

Jan Möbius's avatar
   
Jan Möbius committed
366
Viewer::ViewerProperties& viewerProperties(int _id) {
Dirk Wilden's avatar
Dirk Wilden committed
367
  if ( _id >= (int)viewerProperties_.size() ) {
Jan Möbius's avatar
   
Jan Möbius committed
368
369
370
371
372
373
374
    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
375
  return ( *viewerProperties_[_id] );
Jan Möbius's avatar
   
Jan Möbius committed
376

Jan Möbius's avatar
 
Jan Möbius committed
377
378
}

Jan Möbius's avatar
Jan Möbius committed
379
380
381
382
383
384
385
386
387
388
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
389
390
}

Jan Möbius's avatar
Jan Möbius committed
391
392
393
394
395
396
397
398
399
400
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
401
402
403
404
405
406
}

void allowRotation(bool _mode) {
  examiner_widget_->allowRotation(_mode);
}

407
408
409
410
void setMainGLContext() {
  examiner_widget_->makeCurrent();
}

411
412
413
414
415
416
417
418
419
420
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
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
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;
  examiner_widgets_[activeExaminer_];
}

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
447
448
}

Jan Möbius's avatar
Jan Möbius committed
449
450
451
452
453
454
455
456
457
458
459
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;

  return examiner_widgets_[activeExaminer_]->scene_center();
Jan Möbius's avatar
 
Jan Möbius committed
460
461
462
}

double sceneRadius() {
463
   return examiner_widgets_[activeExaminer_]->scene_radius();
Jan Möbius's avatar
 
Jan Möbius committed
464
465
}

466
467
468
469
470
471
472
473
474
475
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
476
477
}

478
void rotate(const ACG::Vec3d&  _axis,
479
            const double       _angle,
480
481
            const ACG::Vec3d&  _center,
            int                _viewer )
Jan Möbius's avatar
 
Jan Möbius committed
482
{
483
484
485
486
487
488
489
490
491
  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
492
493
}

494
495
496
497
498
499
500
501
502
503
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
504
505
}

506
507
508
509
510
511
512
513
514
515
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
516
517
}

518
519
520
521
522
523
524
525
526
527
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;

528
  return viewerProperties().glState().viewing_direction();
Jan Möbius's avatar
 
Jan Möbius committed
529
530
}

531
532
533
534
535
536
537
538
539
540
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;

541
  return viewerProperties().glState().eye();
Jan Möbius's avatar
 
Jan Möbius committed
542
543
}

544
545
546
547
548
549
550
551
552
553
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;

554
  return viewerProperties().glState().up();
Jan Möbius's avatar
 
Jan Möbius committed
555
556
557
}


Dirk Wilden's avatar
Dirk Wilden committed
558
559
560
561
ACG::SceneGraph::BaseNode* getSceneGraphRootNode() {
   return PluginFunctions::sceneGraph_root_node_;
}

Jan Möbius's avatar
 
Jan Möbius committed
562
563
564
565
ACG::SceneGraph::BaseNode* getRootNode() {
   return PluginFunctions::root_node_;
}

Dirk Wilden's avatar
Dirk Wilden committed
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
void addNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::root_node_)
    _node->set_parent( PluginFunctions::root_node_ );
}

void addGlobalNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::sceneGraph_root_node_){
    //set node as new parent for root's children
    while( PluginFunctions::sceneGraph_root_node_->nChildren() > 0 ){
      ACG::SceneGraph::BaseNode* child = *(PluginFunctions::sceneGraph_root_node_->childrenBegin());
      child->set_parent( _node );
    }

    _node->set_parent( PluginFunctions::sceneGraph_root_node_ );
  }
}

Jan Möbius's avatar
   
Jan Möbius committed
583
int objectCount() {
Jan Möbius's avatar
 
Jan Möbius committed
584
585
586
587
588

  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
Jan Möbius's avatar
   
Jan Möbius committed
589
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
590
591
592
593
594
595
596
    ++count;
  }

  return ( count );

}

Jan Möbius's avatar
   
Jan Möbius committed
597
int targetCount() {
Jan Möbius's avatar
 
Jan Möbius committed
598
599
600
601
602

  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ;
Jan Möbius's avatar
   
Jan Möbius committed
603
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
604
605
606
607
608
609
    ++count;
  }

  return ( count );
}

Jan Möbius's avatar
   
Jan Möbius committed
610
int sourceCount() {
Jan Möbius's avatar
 
Jan Möbius committed
611
612
613
614
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS) ;
Jan Möbius's avatar
   
Jan Möbius committed
615
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
616
617
618
619
620
621
    ++count;
  }

  return ( count );
}

Jan Möbius's avatar
   
Jan Möbius committed
622
int visibleCount() {
Jan Möbius's avatar
 
Jan Möbius committed
623
624
625
626
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
Jan Möbius's avatar
   
Jan Möbius committed
627
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
    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
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ;
Jan Möbius's avatar
   
Jan Möbius committed
647
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
648
649
650
651
652
653
    _objects.push_back( *o_it );
  }

}

///   Fly to point and viewing direction (animated).
Jan Möbius's avatar
   
Jan Möbius committed
654
void   flyTo (const ACG::Vec3d &_position, const ACG::Vec3d &_center, double _time) {
655
   examiner_widgets_[activeExaminer_]->flyTo(_position,_center,_time);
Jan Möbius's avatar
 
Jan Möbius committed
656
657
658
659
660
661
662
663
664
665
}


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

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

Jan Möbius's avatar
 
Jan Möbius committed
667
668
669
670
671
672
  return dynamic_cast< BaseObjectData* >(_object);
}

// ===============================================================================
// Get the root of the object structure
// ===============================================================================
Jan Möbius's avatar
Jan Möbius committed
673
BaseObject*& objectRoot() {
Jan Möbius's avatar
 
Jan Möbius committed
674
675
676
677
  return (objectRoot_);
}

}