Developer Documentation

PluginFunctions.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 //=============================================================================
43 //
44 // Plugin Functions
45 //
46 //=============================================================================
47
48 #include <OpenFlipper/common/Types.hh>
49 #include <OpenFlipper/common/GlobalOptions.hh>
50
51 #include "PluginFunctions.hh"
52 #include "PluginFunctionsCore.hh"
53
54 #include <ACG/Scenegraph/SeparatorNode.hh>
55 #include <ACG/Scenegraph/MaterialNode.hh>
56
57 namespace PluginFunctions {
58
63 static BaseObject* objectRoot_ = 0;
64
69 static std::vector< glViewer* > examiner_widgets_;
70
75 static std::vector< Viewer::ViewerProperties* > viewerProperties_;
76
78 static glViewer* examiner_widget_;
79
81 static unsigned int activeExaminer_ = 0;
82
83 static bool internalLightHandling_ = true;
84
91 static SeparatorNode* dataRootNode_ = 0;
92
96 static SeparatorNode* dataSeparatorNode_ = 0;
97
100 static SeparatorNode* sceneGraphRootNodeGlobal_ = 0;
101
104 static SeparatorNode* sceneGraphRootNode_ = 0;
105
109 static Viewer::ViewerProperties dummyProperties(-1);
110
111
116 static ViewObjectMarker* defaultMarker_ = 0;
117
122 static OFGLWidget* shareGLWidget_ = 0;
123
126 static int viewerId_ = 0;
127
129 static int objectCounter_ = 0;
130
132 static int targetCounter_ = 0;
133
135 static std::map<int, BaseObject*> objectMap_;
136
138 QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > sceneGraphGenerators_;
139
140 void setDataRoot( BaseObject* _root ) {
141 objectRoot_ = _root;
142 }
143
144 int viewers( ) {
145 return examiner_widgets_.size();
146 }
147
148 void disableExaminerLightHandling() {
149 internalLightHandling_ = false;
150 }
151
152 bool examinerLightHandling() {
153 return internalLightHandling_;
154 }
161 static QVector<QPair<QString, QString>> pluginCommandLineOptions_;
162
163 int viewerId() {
164 return viewerId_;
165 }
166
167 void setViewers( const std::vector< glViewer* >& _viewerWidgets ) {
168 PluginFunctions::examiner_widgets_ = _viewerWidgets;
169 PluginFunctions::examiner_widget_ = examiner_widgets_[0];
170
171 // Generate a (hopefully) unique viewer id
172 QTime time = QTime::currentTime();
173 qsrand( time.hour() * 10 + time.minute() * 100 + time.second() * 1000 + time.msec() * 10000 );
174 viewerId_ = qrand();
175 }
176
177 void setViewerProperties( const std::vector< Viewer::ViewerProperties* >& _viewerProperties ) {
178 PluginFunctions::viewerProperties_ = _viewerProperties;
179 }
180
181 void setActiveExaminer( const unsigned int _id ) {
182 activeExaminer_ = _id;
183 }
184
185 glViewer* viewer(int _viewerId ) {
186 if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
187 std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
188 return examiner_widgets_[activeExaminer()];
189 }
190
191 return( examiner_widgets_[_viewerId] );
192 }
193
194 unsigned int activeExaminer( ) {
195 return activeExaminer_;
196 }
197
198 QString getEncodedExaminerView() {
199 return getEncodedExaminerView(activeExaminer());
200 }
201
203 QString getEncodedExaminerView(int _viewerId) {
204
205 QString view;
206
207 if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
208 std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
209 examiner_widgets_[activeExaminer()]->encodeView ( view );
210 return view;
211 }
212
213 examiner_widgets_[_viewerId]->encodeView ( view );
214 return view;
215
216 }
217
218 void setEncodedExaminerView( QString _view ) {
219 setEncodedExaminerView( activeExaminer() , _view );
220 }
221
222 void setEncodedExaminerView(int _viewerId , QString _view ) {
223
224 // Consistency check. If viewer id is wrong, we set the currently active viewer.
225 if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
226 std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
227 examiner_widgets_[activeExaminer()]->decodeView ( _view );
228 return;
229 }
230
231 examiner_widgets_[_viewerId]->decodeView ( _view );
232 }
233
234 void setDataSeparatorNodes( SeparatorNode* _dataSeparatorNode ) {
235
236 // The function should only be called once by the core.
237
238 // Set the separatorNode
239 PluginFunctions::dataSeparatorNode_ = _dataSeparatorNode;
240
241
242 if ( PluginFunctions::dataSeparatorNode_->nChildren() != 1 ){
243 std::cerr << "Only one child allowed for dataSeparatorNode on initialization!" << std::endl;
244 std::cerr << "The Core has initialized the scenegraph in a strange way!" << std::endl;
245 }
246
247 // Set the root node for the data objects
248 // which has to be a child of the dataSeparatorNode_
249 PluginFunctions::dataRootNode_ = dynamic_cast<ACG::SceneGraph::SeparatorNode*> (*(PluginFunctions::dataSeparatorNode_->childrenBegin()) );
250
251 }
252
253 void setSceneGraphRootNode( SeparatorNode* _root_node ) {
254 PluginFunctions::sceneGraphRootNode_ = _root_node;
255 }
256
257 void setSceneGraphRootNodeGlobal( SeparatorNode* _root_node ) {
258 PluginFunctions::sceneGraphRootNodeGlobal_ = _root_node;
259 }
260
261 bool getPickedObject(const size_t _node_idx , BaseObjectData*& _object) {
262 for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
263 if ( o_it->picked( _node_idx ) ) {
264 _object = *o_it;
265 return true;
266 }
267 }
268 return false;
269 }
270
271
272 bool getSourceIdentifiers( std::vector<int>& _identifiers ) {
273 _identifiers.clear();
274
275 for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
276 if ( o_it->source() )
277 _identifiers.push_back ( o_it->id() );
278 }
279 return ( ! _identifiers.empty() );
280 }
281
282 bool getTargetIdentifiers( std::vector<int>& _identifiers ) {
283 _identifiers.clear();
284
285 for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
286 if ( o_it->target() )
287 _identifiers.push_back ( o_it->id() );
288 }
289 return ( !_identifiers.empty() );
290 }
291
292 // ===============================================================================
293 // Get objects
294 // ===============================================================================
295
296 bool getObject( const int _identifier , BaseObject*& _object ) {
297
298 if ( _identifier == -1 )
299 return false;
300
301 // Obsolete:
302 //_object = objectRoot_->childExists( _identifier );
303
304 // Search for specified object in object map:
305 std::map<int, BaseObject*>::iterator it;
306 it = objectMap_.find(_identifier);
307 // Get object
308 _object = (it != objectMap_.end() ? it->second : 0);
309
310 return ( _object != 0 );
311 }
312
313 bool getObject( const int _identifier , BaseObjectData*& _object ) {
314
315 if ( _identifier == -1 )
316 return false;
317
318 // Obsolete: BaseObject* object = objectRoot_->childExists( _identifier );
319
320 // Search for specified object in object map:
321 std::map<int, BaseObject*>::iterator it;
322 it = objectMap_.find(_identifier);
323 // Get object
324 BaseObject* object = (it != objectMap_.end() ? it->second : 0);
325
326 _object = dynamic_cast< BaseObjectData* >(object);
327 return ( _object != 0 );
328 }
329
330 int getObjectId( const QString& _name ) {
331 if(_name.isEmpty()) return -1;
332
333 BaseObject* object = objectRoot_->childExists( _name );
334 return object ? object->id() : -1;
335 }
336
337 // ===============================================================================
338 // ===============================================================================
339
340 bool objectExists( const int _identifier ) {
341
342 if ( _identifier == -1 )
343 return false;
344
345 BaseObject* object = objectRoot_->childExists( _identifier );
346 return ( object != 0 );
347 }
348
349 //===============================================================================
350
351 bool getAllMeshes( std::vector<int>& _identifiers ) {
352
353 _identifiers.clear();
354
355 // find changed manipulator
356 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,typeId("TriangleMesh")) ;
357 o_it != PluginFunctions::objectsEnd(); ++o_it) {
358 _identifiers.push_back( o_it->id() );
359 }
360
361 return (!_identifiers.empty());
362 }
363
364 bool getAllObjectIdentifiers( std::vector<int>& _identifiers ) {
365
366 _identifiers.clear();
367
368 // find changed manipulator
369 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
370 o_it != PluginFunctions::objectsEnd(); ++o_it) {
371 _identifiers.push_back( o_it->id() );
372 }
373
374 return ( !_identifiers.empty() );
375 }
376
377 void setBackColor( OpenMesh::Vec4f _color) {
378 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
379 PluginFunctions::viewerProperties(i).backgroundColor(_color);
380 }
381
382 void setFixedView(int _mode, int _viewer ) {
383
384 if ( (_viewer != ACTIVE_VIEWER ) && ( ( _viewer < 0 ) || _viewer >= (int)examiner_widgets_.size()) ){
385 std::cerr << "Unable to set fixed view. Wrong viewer id (" << _viewer << ")" << std::endl;
386 return;
387 }
388
389 switch ( _mode ){
390 case VIEW_TOP : //TOP
391 PluginFunctions::viewingDirection( ACG::Vec3d(0.0, -1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
392 PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
393 break;
394 case VIEW_BOTTOM : //BOTTOM
395 PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
396 PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
397 break;
398 case VIEW_LEFT : //LEFT
399 PluginFunctions::viewingDirection( ACG::Vec3d(1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
400 PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
401 break;
402 case VIEW_RIGHT : //RIGHT
403 PluginFunctions::viewingDirection( ACG::Vec3d(-1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
404 PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
405 break;
406 case VIEW_FRONT : //FRONT
407 PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 0.0, -1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
408 PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
409 break;
410 case VIEW_BACK : //BACK
411 PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 0.0, 1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
412 PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
413 break;
414 default : //Free View
415 PluginFunctions::allowRotation(true, _viewer);
416 break;
417 }
418
419 if ( _viewer == ACTIVE_VIEWER )
420 viewerProperties(activeExaminer()).currentViewingDirection( _mode );
421 else
422 viewerProperties( _viewer ).currentViewingDirection( _mode );
423 }
424
425 QPoint mapToGlobal(const QPoint _point ) {
426 return examiner_widgets_[activeExaminer_]->glMapToGlobal(_point);
427 }
428
429 QPoint mapToLocal( const QPoint _point ) {
430 return examiner_widgets_[activeExaminer_]->glMapFromGlobal(_point);
431 }
432
433 void setDrawMode( const ACG::SceneGraph::DrawModes::DrawMode& _mode , int _viewer) {
434
435 if ( _viewer == ACTIVE_VIEWER )
436 viewerProperties(activeExaminer()).drawMode(_mode);
437 else if ( _viewer == ALL_VIEWERS )
438 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
439 viewerProperties(i).drawMode(_mode);
440 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
441 viewerProperties(_viewer).drawMode(_mode);
442 else
443 std::cerr << "Requested illegal viewer for setting DrawMode!!" << std::endl;
444
445 }
446
452 ACG::SceneGraph::DrawModes::DrawMode drawMode( int _viewer ) {
453 if ( _viewer == ACTIVE_VIEWER ) {
454 return viewerProperties(activeExaminer()).drawMode();
455 } else if ( _viewer == ALL_VIEWERS )
456 std::cerr << "Please select viewer to get viewing direction!" << std::endl;
457 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
458 return viewerProperties(_viewer).drawMode();
459 else
460 std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
461
462 return viewerProperties(activeExaminer()).drawMode();
463 }
464
465 //get a viewing ray for the active examiner x and y are in widgetspace
466 void viewingRay(int _x, int _y,
467 ACG::Vec3d& _outOrigin, ACG::Vec3d& _outDirection)
468 {
469 viewingRay(_x,_y,_outOrigin,_outDirection,activeExaminer_);
470 }
471
472 //get a viewing ray for the specified examiner x and y are in widgetspace
473 void viewingRay(int _x, int _y,
474 ACG::Vec3d& _outOrigin, ACG::Vec3d& _outDirection, int _viewerIndex)
475 {
476 viewerProperties(_viewerIndex).glState().viewing_ray(_x,_y,_outOrigin,_outDirection);
477 }
478
479 // Pick returning node index
480 bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {
481
482 return examiner_widgets_[activeExaminer_]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
483 }
484
485 // Pick returning node index
486 bool scenegraphPick( const unsigned int _examiner, ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {
487
488 if ( _examiner >= examiner_widgets_.size() ) {
489 std::cerr << "Wrong examiner id" << std::endl;
490 return false;
491 }
492 return examiner_widgets_[_examiner]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
493 }
494
495
496 // Pick returning object and calling refine
497 bool scenegraphPick( const unsigned int _examiner ,
498 ACG::SceneGraph::PickTarget _pickTarget,
499 const QPoint & _mousePos,
500 BaseObjectData*& _object,
501 size_t & _targetIdx,
502 const bool _refine,
503 ACG::Vec3d * _hitPointPtr ) {
504
505 size_t nodeIdx = 0;
506
507 bool ok = scenegraphPick(_examiner,_pickTarget,_mousePos, nodeIdx,_targetIdx,_hitPointPtr);
508
509 // If successfully picked and object is found
510 if ( ok && PluginFunctions::getPickedObject(nodeIdx, _object) ) {
511
512 if ( _refine && (_hitPointPtr != 0) ) {
513
514 // Map to correct coordinates in OpenGL
515 double x = _mousePos.x();
516 double y = examiner_widget_->glHeight() - _mousePos.y();
517
518 ACG::Vec3d mousePoint3d;
519 ACG::Vec3d direction;
520
521 viewingRay(x,y,mousePoint3d,direction);
522
523 *_hitPointPtr = _object->refinePick(_pickTarget,*_hitPointPtr, mousePoint3d , direction , _targetIdx );
524
525 }
526
527 }
528
529 return ok;
530 }
531
532 // Pick returning object and calling refine
533 bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget,
534 const QPoint & _mousePos,
535 BaseObjectData*& _object,
536 size_t & _targetIdx,
537 const bool _refine,
538 ACG::Vec3d * _hitPointPtr ) {
539
540 return scenegraphPick(activeExaminer_,_pickTarget,_mousePos, _object,_targetIdx,_refine,_hitPointPtr );
541
542 }
543
544
545
546
547 bool scenegraphRegionPick( ACG::SceneGraph::PickTarget _pickTarget,
548 const QRegion& _region,
549 QList<QPair<size_t, size_t> >& _list,
550 QVector<float>* _depths,
551 QVector<ACG::Vec3d>* _points)
552 {
553 return examiner_widgets_[activeExaminer_]->pick_region( _pickTarget, _region, _list, _depths, _points);
554 }
555
556 bool scenegraphRegionPick( const unsigned int _examiner,
557 ACG::SceneGraph::PickTarget _pickTarget,
558 const QRegion& _region,
559 QList<QPair<size_t, size_t> >& _list,
560 QVector<float>* _depths,
561 QVector<ACG::Vec3d>* _points)
562 {
563 if ( _examiner >= examiner_widgets_.size() ) {
564 std::cerr << "Wrong examiner id" << std::endl;
565 return false;
566 }
567 return examiner_widgets_[_examiner]->pick_region( _pickTarget, _region, _list, _depths, _points);
568 }
569
570 //Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
571 void traverse( ACG::SceneGraph::MouseEventAction &_action ) {
572 // Single pass action, as the mouse action will only update the graph.
573 // If its changed, it will be set to dirty and an automatic redraw is triggered.
574 ACG::SceneGraph::traverse(sceneGraphRootNode_, _action );
575 }
576
577 const std::string pickMode () {
578 // No seperate draw modes available all should have the same so take first
579 return viewerProperties().pickMode();
580 }
581
582 void pickMode ( const std::string& _mode) {
583 // switch to default marker
584 setViewObjectMarker (defaultViewObjectMarker ());
585 viewerProperties().pickMode(_mode);
586 }
587
588 Viewer::ActionMode actionMode() {
589 return viewerProperties().actionMode();
590 }
591
592 void actionMode ( Viewer::ActionMode _mode) {
593
594 viewerProperties().actionMode(_mode);
595 }
596
597 void shareGLWidget(OFGLWidget *_widget)
598 {
599 shareGLWidget_ = _widget;
600 }
601
602 OFGLWidget *shareGLWidget()
603 {
604 return shareGLWidget_;
605 }
606
607 void getCurrentViewImage(QImage& _image) {
608 viewer( activeExaminer() )->snapshot( _image );
609 }
610
611 Viewer::ViewerProperties& viewerProperties(int _id) {
612 if ( _id >= (int)viewerProperties_.size() ) {
613 std::cerr << " Error, requested properties for non-existing Viewer!" << std::endl;
614 return dummyProperties;
615 }
616
617 if ( _id == -1 )
618 _id = activeExaminer_;
619
620 return ( *viewerProperties_[_id] );
621
622 }
623
624 void perspectiveProjection( int _viewer ) {
625 if ( _viewer == ACTIVE_VIEWER ) {
626 examiner_widgets_[activeExaminer_]->perspectiveProjection();
627 } else if ( _viewer == ALL_VIEWERS )
628 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
629 examiner_widgets_[i]->perspectiveProjection();
630 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
631 examiner_widgets_[_viewer]->perspectiveProjection();
632 else
633 std::cerr << "Requested illegal viewer for perspectiveProjection()!!" << std::endl;
634 }
635
636 void orthographicProjection( int _viewer ) {
637 if ( _viewer == ACTIVE_VIEWER ) {
638 examiner_widgets_[activeExaminer_]->orthographicProjection();
639 } else if ( _viewer == ALL_VIEWERS )
640 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
641 examiner_widgets_[i]->orthographicProjection();
642 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
643 examiner_widgets_[_viewer]->orthographicProjection();
644 else
645 std::cerr << "Requested illegal viewer for orthographicProjection()!!" << std::endl;
646 }
647
648 void setFOVY( double _fovy) {
649
650 // Set FOVY for all viewers
651 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
652 examiner_widgets_[i]->setFOVY(_fovy);
653 }
654
655 void allowRotation(bool _mode, int _viewer ) {
656 if ( _viewer == ACTIVE_VIEWER ) {
657 examiner_widgets_[activeExaminer_]->allowRotation(_mode);
658 } else if ( _viewer == ALL_VIEWERS )
659 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
660 examiner_widgets_[i]->allowRotation(_mode);
661 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
662 examiner_widgets_[_viewer]->allowRotation(_mode);
663 else {
664 std::cerr << "Requested illegal viewer for allowRotation!!" << std::endl;
665 return;
666 }
667
668 if ( _viewer == ACTIVE_VIEWER )
669 viewerProperties(activeExaminer()).rotationLocked( !_mode );
670 else
671 viewerProperties( _viewer ).rotationLocked( !_mode );
672 }
673
674 bool allowRotation( int _viewer ) {
675
676 if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
677 return examiner_widgets_[_viewer]->allowRotation();
678 else {
679
680 std::cerr << "Requested illegal viewer for isRotationAllowed!!" << std::endl;
681 return false;
682 }
683 }
684
685 void setMainGLContext() {
686 examiner_widget_->makeCurrent();
687 }
688
689 void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up , int _viewer ) {
690 if ( _viewer == ACTIVE_VIEWER ) {
691 examiner_widgets_[activeExaminer_]->viewingDirection(_dir,_up);
692 } else if ( _viewer == ALL_VIEWERS )
693 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
694 examiner_widgets_[i]->viewingDirection(_dir,_up);
695 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
696 examiner_widgets_[_viewer]->viewingDirection(_dir,_up);
697 else
698 std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
699 }
700
701 void lookAt(const ACG::Vec3d& _eye, const ACG::Vec3d& _center, const ACG::Vec3d& _up, int _viewer) {
702
703 if ( _viewer == ACTIVE_VIEWER ) {
704 examiner_widgets_[activeExaminer_]->lookAt(_eye,_center, _up);
705 } else if ( _viewer == ALL_VIEWERS )
706 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
707 examiner_widgets_[i]->lookAt(_eye,_center, _up);
708 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
709 examiner_widgets_[_viewer]->lookAt(_eye,_center, _up);
710 else
711 std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
712 }
713
714 const ACG::Vec3d trackBallCenter( int _viewer ) {
715 if ( _viewer == ACTIVE_VIEWER ) {
716 return examiner_widgets_[activeExaminer_]->trackBallCenter();
717 } else if ( _viewer == ALL_VIEWERS )
718 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
719 return examiner_widgets_[i]->trackBallCenter( );
720 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
721 return examiner_widgets_[_viewer]->trackBallCenter( );
722 else
723 std::cerr << "Requested illegal viewer for setTrackBallCenter!!" << std::endl;
724
725 return examiner_widgets_[activeExaminer_]->trackBallCenter();
726 }
727
728 void setTrackBallCenter(const ACG::Vec3d& _center, int _viewer ) {
729 if ( _viewer == ACTIVE_VIEWER ) {
730 examiner_widgets_[activeExaminer_]->setTrackBallCenter( _center );
731 } else if ( _viewer == ALL_VIEWERS )
732 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
733 examiner_widgets_[i]->setTrackBallCenter( _center );
734 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
735 examiner_widgets_[_viewer]->setTrackBallCenter( _center );
736 else
737 std::cerr << "Requested illegal viewer for setTrackBallCenter!!" << std::endl;
738 }
739
740 void setScenePos(const ACG::Vec3d& _center,const double _radius, int _viewer ) {
741 if ( _viewer == ACTIVE_VIEWER ) {
742 examiner_widgets_[activeExaminer_]->setScenePos( _center, _radius );
743 } else if ( _viewer == ALL_VIEWERS )
744 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
745 examiner_widgets_[i]->setScenePos( _center, _radius );
746 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
747 examiner_widgets_[_viewer]->setScenePos( _center, _radius );
748 else
749 std::cerr << "Requested illegal viewer for setScenePos!!" << std::endl;
750 }
751
752 void setScenePos(const ACG::Vec3d& _center, int _viewer ) {
753 if ( _viewer == ACTIVE_VIEWER ) {
754 examiner_widgets_[activeExaminer_]->setScenePos( _center, examiner_widgets_[activeExaminer_]->scene_radius() );
755 } else if ( _viewer == ALL_VIEWERS )
756 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
757 examiner_widgets_[i]->setScenePos( _center, examiner_widgets_[i]->scene_radius() );
758 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
759 examiner_widgets_[_viewer]->setScenePos( _center, examiner_widgets_[_viewer]->scene_radius() );
760 else
761 std::cerr << "Requested illegal viewer for setScenePos!!" << std::endl;
762 }
763
764 void setSceneCenter(const ACG::Vec3d& _center, int _viewer) {
765
766 if (_viewer == ACTIVE_VIEWER) {
767 examiner_widgets_[activeExaminer_]->setSceneCenter(_center);
768 } else if (_viewer == ALL_VIEWERS) {
769
770 for (uint i = 0; i < examiner_widgets_.size(); ++i) {
771 examiner_widgets_[i]->setSceneCenter(_center);
772 }
773 } else if ((_viewer >= 0) && _viewer < (int) examiner_widgets_.size()) {
774 examiner_widgets_[_viewer]->setSceneCenter(_center);
775 } else {
776 std::cerr << "Requested illegal viewer for setSceneCenter!!" << std::endl;
777 }
778 }
779
780 const ACG::Vec3d sceneCenter(int _viewer) {
781
782 if (_viewer == ACTIVE_VIEWER) {
783 return examiner_widgets_[activeExaminer_]->scene_center();
784 } else if (_viewer == ALL_VIEWERS)
785 std::cerr << "Please select viewer to get sceneCenter!" << std::endl;
786 else if ((_viewer >= 0) && _viewer < (int) examiner_widgets_.size())
787 return examiner_widgets_[_viewer]->scene_center();
788 else
789 std::cerr << "Requested illegal viewer for sceneCenter!!" << std::endl;
790
791 return examiner_widgets_[activeExaminer_]->scene_center();
792 }
793
794 double sceneRadius() {
795 return examiner_widgets_[activeExaminer_]->scene_radius();
796 }
797
798 double sceneRadius( int _viewer ) {
799 if ( _viewer == ACTIVE_VIEWER ) {
800 return examiner_widgets_[activeExaminer_]->scene_radius();
801 } else if ( _viewer == ALL_VIEWERS )
802 std::cerr << "Illegal request for scene radius. Please select one viewer!" << std::endl;
803 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
804 return examiner_widgets_[_viewer]->scene_radius();
805 else
806 std::cerr << "Requested illegal viewer for translate!!" << std::endl;
807
808 return -1;
809 }
810
811 void setSceneRadius(double _radius, int _viewer ) {
812 if ( _viewer == ACTIVE_VIEWER ) {
813 examiner_widgets_[activeExaminer_]->setSceneRadius(_radius);
814 } else if ( _viewer == ALL_VIEWERS )
815 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
816 examiner_widgets_[i]->setSceneRadius(_radius);
817 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
818 examiner_widgets_[_viewer]->setSceneRadius(_radius);
819 else
820 std::cerr << "Requested illegal viewer for translate!!" << std::endl;
821 }
822
823 void translate( const ACG::Vec3d &_vector , int _viewer ) {
824 if ( _viewer == ACTIVE_VIEWER ) {
825 examiner_widgets_[activeExaminer_]->translate(_vector);
826 } else if ( _viewer == ALL_VIEWERS )
827 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
828 examiner_widgets_[i]->translate(_vector);
829 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
830 examiner_widgets_[_viewer]->translate(_vector);
831 else
832 std::cerr << "Requested illegal viewer for translate!!" << std::endl;
833 }
834
835 void rotate(const ACG::Vec3d& _axis,
836 const double _angle,
837 const ACG::Vec3d& _center,
838 int _viewer )
839 {
840 if ( _viewer == ACTIVE_VIEWER ) {
841 examiner_widgets_[activeExaminer_]->rotate(_axis,_angle,_center);
842 } else if ( _viewer == ALL_VIEWERS )
843 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
844 examiner_widgets_[i]->rotate(_axis,_angle,_center);
845 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
846 examiner_widgets_[_viewer]->rotate(_axis,_angle,_center);
847 else
848 std::cerr << "Requested illegal viewer for rotate!!" << std::endl;
849 }
850
851 void viewHome(int _viewer) {
852 if ( _viewer == ACTIVE_VIEWER ) {
853 examiner_widgets_[activeExaminer_]->home();
854 } else if ( _viewer == ALL_VIEWERS )
855 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
856 examiner_widgets_[i]->home();
857 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
858 examiner_widgets_[_viewer]->home();
859 else
860 std::cerr << "Requested illegal viewer for viewHome!!" << std::endl;
861 }
862
863 void viewAll(int _viewer) {
864 if ( _viewer == ACTIVE_VIEWER ) {
865 examiner_widgets_[activeExaminer_]->viewAll();
866 } else if ( _viewer == ALL_VIEWERS )
867 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
868 examiner_widgets_[i]->viewAll();
869 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
870 examiner_widgets_[_viewer]->viewAll();
871 else
872 std::cerr << "Requested illegal viewer for viewAll!!" << std::endl;
873 }
874
875 ACG::Vec3d viewingDirection(int _viewer) {
876 if ( _viewer == ACTIVE_VIEWER ) {
877 return viewerProperties(activeExaminer_).glState().viewing_direction();
878 } else if ( _viewer == ALL_VIEWERS )
879 std::cerr << "Please select viewer to get viewing direction!" << std::endl;
880 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
881 return viewerProperties(_viewer).glState().viewing_direction();
882 else
883 std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
884
885 return viewerProperties().glState().viewing_direction();
886 }
887
888 bool isProjectionOrthographic( int _viewer ) {
889
890 if ( _viewer == ACTIVE_VIEWER) {
891 return (examiner_widgets_[activeExaminer_]->projectionMode() == 0);
892 } else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() ){
893 return ( examiner_widgets_[_viewer]->projectionMode() == 0); //ORTHOGRAPHIC_PROJECTION ?
894 } else
895 std::cerr << "Requested illegal viewer for isProjectionOrthographic!!" << std::endl;
896
897 return false;
898 }
899
900 ACG::Vec3d eyePos(int _viewer) {
901 if ( _viewer == ACTIVE_VIEWER ) {
902 return viewerProperties(activeExaminer_).glState().eye();
903 } else if ( _viewer == ALL_VIEWERS )
904 std::cerr << "Please select viewer to get eyePos!" << std::endl;
905 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
906 return viewerProperties(_viewer).glState().eye();
907 else
908 std::cerr << "Requested illegal viewer for eyePos!!" << std::endl;
909
910 return viewerProperties().glState().eye();
911 }
912
913 ACG::Vec3d upVector(int _viewer) {
914 if ( _viewer == ACTIVE_VIEWER ) {
915 return viewerProperties(activeExaminer_).glState().up();
916 } else if ( _viewer == ALL_VIEWERS )
917 std::cerr << "Please select viewer to get up vector!" << std::endl;
918 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
919 return viewerProperties(_viewer).glState().up();
920 else
921 std::cerr << "Requested illegal viewer for up vector!!" << std::endl;
922
923 return viewerProperties().glState().up();
924 }
925
928 DLLEXPORT
929 double fovy(int _viewer) {
930 if ( _viewer == ACTIVE_VIEWER ) {
931 return viewerProperties(activeExaminer_).glState().fovy();
932 } else if ( _viewer == ALL_VIEWERS )
933 std::cerr << "Please select viewer to get fovy!" << std::endl;
934 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
935 return viewerProperties(_viewer).glState().fovy();
936 else
937 std::cerr << "Requested illegal viewer for fovy!!" << std::endl;
938
939 return viewerProperties().glState().fovy();
940 }
941
942 void setViewObjectMarker(ViewObjectMarker * _marker)
943 {
944 for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
945 PluginFunctions::viewerProperties(i).objectMarker(_marker);
946 }
947
948 void setDefaultViewObjectMarker(ViewObjectMarker * _marker)
949 {
950 defaultMarker_ = _marker;
951 }
952
953 ViewObjectMarker * defaultViewObjectMarker()
954 {
955 return defaultMarker_;
956 }
957
958
959 ACG::SceneGraph::BaseNode* getSceneGraphRootNode() {
960 return PluginFunctions::sceneGraphRootNode_;
961 }
962
963 ACG::SceneGraph::BaseNode* getRootNode() {
964 return PluginFunctions::dataRootNode_;
965 }
966
967 void addGlobalStatusNode(ACG::SceneGraph::BaseNode* _node) {
968 if (PluginFunctions::sceneGraphRootNode_){
969
970 // get the current parent Node
971 ACG::SceneGraph::BaseNode* parent = sceneGraphRootNodeGlobal_->parent();
972
973 // Move the node to the new parent
974 _node->set_parent(parent);
975
976 // move sceneGraphRootNodeGlobal_ to the new parent
977 sceneGraphRootNodeGlobal_->set_parent(_node);
978 }
979 }
980
981 void addGlobalNode(ACG::SceneGraph::BaseNode* _node){
982 if (PluginFunctions::sceneGraphRootNode_)
983 _node->set_parent( PluginFunctions::sceneGraphRootNodeGlobal_ );
984 }
985
986
987 void addObjectRenderingNode(ACG::SceneGraph::BaseNode* _node){
988 if (PluginFunctions::sceneGraphRootNode_){
989
990 // get the current parent Node
991 ACG::SceneGraph::BaseNode* parent = dataRootNode_->parent();
992
993 // Move the node to the new parent
994 _node->set_parent(parent);
995
996 // move dataRootNode_ to the new parent
997 dataRootNode_->set_parent(_node);
998 }
999
1000 }
1001
1002 int objectCount() {
1003 return(objectCounter_);
1004 }
1005
1006
1007
1008 int targetCount() {
1009 return ( targetCounter_ );
1010 }
1011
1012 int sourceCount() {
1013 int count = 0;
1014
1015 // find changed manipulator
1016 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS) ;
1017 o_it != PluginFunctions::objectsEnd(); ++o_it) {
1018 ++count;
1019 }
1020
1021 return ( count );
1022 }
1023
1024 int visibleCount() {
1025 int count = 0;
1026
1027 // find changed manipulator
1028 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
1029 o_it != PluginFunctions::objectsEnd(); ++o_it) {
1030 if ( o_it->visible() )
1031 ++count;
1032 }
1033
1034 return ( count );
1035
1036 }
1037
1038
1043 void get_all_objects( std::vector < BaseObjectData*>& _objects ) {
1044
1045 _objects.clear();
1046
1047 // find changed manipulator
1048 for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_ALL) ;
1049 o_it != PluginFunctions::objectsEnd(); ++o_it) {
1050 _objects.push_back( *o_it );
1051 }
1052
1053 }
1054
1055
1057 void flyTo (const ACG::Vec3d &_position, const ACG::Vec3d &_center, double _time) {
1058 examiner_widgets_[activeExaminer_]->flyTo(_position,_center,_time);
1059 }
1060
1061
1063 void flyTo (const ACG::Vec3d &_center, bool _move_back, double _time) {
1064 ACG::Vec3d eye = PluginFunctions::viewerProperties().glState().eye();
1065 ACG::Vec3d t = _center - eye;
1066 ACG::Vec3d e = eye + t * (_move_back ? -0.5f : 0.5f);
1067 examiner_widgets_[activeExaminer_]->flyTo(e, _center, _time);
1068 }
1069
1070
1072 void viewerSnapshot(int _viewer, QImage& _image, int _width, int _height, bool _alpha,
1073 bool _hideCoordsys, int _samples) {
1074
1075 if ( _viewer == ACTIVE_VIEWER ) {
1076 examiner_widgets_[activeExaminer_]->snapshot(_image, _width, _height, _alpha, _hideCoordsys, _samples);
1077 } else if ( _viewer == ALL_VIEWERS )
1078 std::cerr << "Please select viewer to get snapshot!" << std::endl;
1079 else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
1080 examiner_widgets_[_viewer]->snapshot(_image, _width, _height, _alpha, _hideCoordsys, _samples);
1081 else
1082 std::cerr << "Requested illegal viewer for snapshot!!" << std::endl;
1083 }
1084
1085
1086
1087 // ===============================================================================
1088 // Getting data from objects and casting between them
1089 // ===============================================================================
1090
1091 BaseObjectData* baseObjectData( BaseObject* _object ){
1092 if ( _object == 0 )
1093 return 0;
1094
1095 return dynamic_cast< BaseObjectData* >(_object);
1096 }
1097
1098 // ===============================================================================
1099 // Get the root of the object structure
1100 // ===============================================================================
1101 BaseObject*& objectRoot() {
1102 return (objectRoot_);
1103 }
1104
1105 void increaseObjectCount() {
1106 objectCounter_++;
1107 }
1108
1109 // Increase the number of current Object
1110 void decreaseObjectCount() {
1111 objectCounter_--;
1112
1113 if ( objectCounter_ < 0 )
1114 std::cerr << "Deleted more objects than created!!!" << std::endl;
1115 }
1116
1117 void increaseTargetCount() {
1118 targetCounter_++;
1119 }
1120
1121 // Increase the number of current Object
1122 void decreaseTargetCount() {
1123 targetCounter_--;
1124
1125 if ( targetCounter_ < 0 )
1126 std::cerr << "target object counter underflow!!!" << std::endl;
1127 }
1128
1129 // ===============================================================================
1130 // Add an object to the internal object map
1131 // ===============================================================================
1132 void addObjectToMap(int _objectId, BaseObject* _object) {
1133
1134 // Look if object's id already exists in map
1135 std::map<int, BaseObject*>::iterator it;
1136 it = objectMap_.find(_objectId);
1137 // If so return
1138 if(it != objectMap_.end()) return;
1139
1140 // Add new object to map
1141 objectMap_.insert(std::pair<int, BaseObject*>(_objectId, _object));
1142 }
1143
1144 // ===============================================================================
1145 // Remove an object from the internal object map
1146 // ===============================================================================
1147 void removeObjectFromMap(int _objectId) {
1148
1149 // Look if object exists in map
1150 std::map<int, BaseObject*>::iterator it;
1151 it = objectMap_.find(_objectId);
1152
1153 // Erase entry
1154 if(it != objectMap_.end()) objectMap_.erase(it);
1155 }
1156
1157
1158 void addSceneGraphGenerator(ACG::QtWidgets::SceneGraphWidgetGenerator* _generator) {
1159
1160 // Check if we already have a generator for this type.
1161 if ( sceneGraphGenerators_.contains( _generator->handles() ) )
1162 return;
1163
1164 // Store the generator
1165 sceneGraphGenerators_[_generator->handles() ] = _generator;
1166 }
1167
1168
1169 QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > getSceneGraphGeneratorList(){
1170 return sceneGraphGenerators_;
1171 }
1172
1173 QString getOpenFileName(const QString &configProperty,
1174 QWidget * parent, const QString & caption,
1175 const QString & defaultDir, const QString & filter,
1176 QString * selectedFilter, QFileDialog::Options options) {
1177
1178 const QString dir = OpenFlipperSettings().value(configProperty, defaultDir).toString();
1179 const QString result = QFileDialog::getOpenFileName(parent, caption, dir,
1180 filter, selectedFilter, options);
1181 if (result.length())
1182 OpenFlipperSettings().setValue(configProperty, result);
1183 return result;
1184 }
1185
1186 QString getSaveFileName(const QString &configProperty,
1187 QWidget * parent, const QString & caption,
1188 const QString & defaultDir, const QString & filter,
1189 QString * selectedFilter, QFileDialog::Options options,
1190 const QString & defaultSuffix) {
1191
1192 const QString dir = OpenFlipperSettings().value(configProperty, defaultDir).toString();
1193
1194 /*
1195 * We don't use this convenience wrapper any more since it
1196 * prevents us from setting the default suffix.
1197 *
1198 * const QString result = QFileDialog::getSaveFileName(
1199 * parent, caption, dir, filter, selectedFilter, options);
1200 */
1201
1202 QFileDialog dialog(parent, caption, dir, filter);
1203 dialog.setOptions(options);
1204 dialog.setAcceptMode(QFileDialog::AcceptSave);
1205 if (selectedFilter && !selectedFilter->isEmpty())
1206 dialog.selectNameFilter(*selectedFilter);
1207 dialog.setDefaultSuffix(defaultSuffix);
1208 if (dialog.exec() == QDialog::Accepted) {
1209 if (selectedFilter)
1210 *selectedFilter = dialog.selectedNameFilter();
1211 QString result = dialog.selectedFiles().value(0);
1212 OpenFlipperSettings().setValue(configProperty, result);
1213 return result;
1214 }
1215 return QString();
1216 }
1217
1218 QStringList collectObjectComments(bool visibleOnly, bool targetedOnly) {
1219 QStringList result;
1220 for (ObjectIterator o_it(targetedOnly ? TARGET_OBJECTS : ALL_OBJECTS, DATA_ALL) ; o_it != objectsEnd(); ++o_it) {
1221
1222 if (visibleOnly && !o_it->visible()) continue;
1223
1224 result.append(o_it->getAllCommentsFlat());
1225 }
1226 return result;
1227 }
1228
1229 QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly) {
1230 if (!ACG::SceneGraph::Material::support_json_serialization())
1231 return QStringList();
1232
1233 QStringList result;
1234 for (ObjectIterator o_it(targetedOnly ? TARGET_OBJECTS : ALL_OBJECTS, DATA_ALL) ; o_it != objectsEnd(); ++o_it) {
1235
1236 if (visibleOnly && !o_it->visible()) continue;
1237
1238 QString materialStr(QObject::tr("<not available>"));
1239 if (!o_it->materialNode())
1240 materialStr = QObject::tr("<not available: materialNode == null>");
1241 else
1242 materialStr = o_it->materialNode()->material().serializeToJson();
1243
1244 if (!result.empty())
1245 result.last().append(QString::fromUtf8(","));
1246 result.append(QString::fromUtf8("\"%1\": %2").arg(o_it->name()).arg(materialStr));
1247 }
1248 return result;
1249 }
1250
1251 void invalidatePickCaches() {
1252 for(size_t i = 0; i < examiner_widgets_.size(); ++i) {
1253 examiner_widgets_[i]->invalidatePickCache();
1254 }
1255 }
1256
1257 ObjectRange objects(IteratorRestriction _restriction, DataType _dataType) {
1258 return ObjectRange(_restriction, _dataType);
1259 }
1260
1261 ObjectReferenceRange objectReferences(IteratorRestriction _restriction, DataType _dataType) {
1262 return ObjectReferenceRange(_restriction, _dataType);
1263 }
1264
1265 const QVector<QPair<QString, QString> > &pluginCommandLineOptions()
1266 {
1267 return pluginCommandLineOptions_;
1268 }
1269
1270 void setPluginCommandLineOptions(const QVector<QPair<QString, QString> > &_pluginCommandLineOptions)
1271 {
1272 pluginCommandLineOptions_ = _pluginCommandLineOptions;
1273 }
1274
1275 } // End namespace PluginFunctions
PluginFunctions::pluginCommandLineOptions
const QVector< QPair< QString, QString > > & pluginCommandLineOptions()
Get command line plugin settings as key-value pairs.
Definition: PluginFunctions.cc:1265
PluginFunctions::scenegraphPick
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Definition: PluginFunctions.cc:480
ACG::SceneGraph::ACG::SceneGraph::BaseNode::parent
BaseNode * parent()
Get the nodes parent node.
Definition: MeshNode2T_impl.hh:372
ACG::GLState::fovy
double fovy() const
get field of view in y direction
Definition: GLState.cc:868
PluginFunctions::viewHome
void viewHome(int _viewer)
Go to home position.
Definition: PluginFunctions.cc:851
PluginFunctions::shareGLWidget
void shareGLWidget(OFGLWidget *_widget)
Sets the main QGLWidget for gl data sharing.
Definition: PluginFunctions.cc:597
PluginFunctions::fovy
DLLEXPORT double fovy(int _viewer)
Get field of view angle.
Definition: PluginFunctions.cc:929
PluginFunctions::decreaseObjectCount
void decreaseObjectCount()
Increase the number of current Object.
Definition: PluginFunctions.cc:1110
PluginFunctions::setScenePos
void setScenePos(const ACG::Vec3d &_center, const double _radius, int _viewer)
Set the Scene position.
Definition: PluginFunctions.cc:740
PluginFunctions::removeObjectFromMap
void removeObjectFromMap(int _objectId)
Remove object from internal object map.
Definition: PluginFunctions.cc:1147
PluginFunctions::setDataRoot
void setDataRoot(BaseObject *_root)
Definition: PluginFunctions.cc:140
Viewer::ViewerProperties
Definition: ViewerProperties.hh:107
ACG::GLState::viewing_direction
Vec3d viewing_direction() const
get viewing ray
Definition: GLState.hh:848
ACG::SceneGraph::BaseNode::set_parent
void set_parent(BaseNode *_parent)
Set the parent of this node.
PluginFunctions::visibleCount
int visibleCount()
Get the number of visible objects.
Definition: PluginFunctions.cc:1024
ACG::QtWidgets::SceneGraphWidgetGenerator::handles
virtual std::string handles()
return the type this generator handles
Definition: QtSceneGraphWidget.cc:97
PluginFunctions::viewingDirection
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
Definition: PluginFunctions.cc:689
PluginFunctions::decreaseTargetCount
void decreaseTargetCount()
Increase the number of current Object.
Definition: PluginFunctions.cc:1122
ACG::GLState::up
Vec3d up() const
get up-vector w.r.t. camera coordinates
Definition: GLState.cc:906
PluginFunctions::trackBallCenter
const ACG::Vec3d trackBallCenter(int _viewer)
Get the trackball Center.
Definition: PluginFunctions.cc:714
glViewer::makeCurrent
virtual void makeCurrent()
Makes this widget the current widget for OpenGL operations.
Definition: QtBaseViewer.cc:228
PluginFunctions::getRootNode
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
Definition: PluginFunctions.cc:963
Viewer::ActionMode
ActionMode
Enum listing action modes of the viewers.
Definition: ViewerProperties.hh:75
PluginFunctions::getCurrentViewImage
void getCurrentViewImage(QImage &_image)
Returns a QImage of the current View.
Definition: PluginFunctions.cc:607
PluginFunctions::ObjectRange
Range adapter for ObjectIterator.
Definition: PluginFunctions.hh:583
DLLEXPORT
#define DLLEXPORT
Definition: GlobalDefines.hh:95
PluginFunctions::objectCount
int objectCount()
Get the number of available objects.
Definition: PluginFunctions.cc:1002
BaseObject
Definition: BaseObject.hh:82
PluginFunctions::upVector
ACG::Vec3d upVector(int _viewer)
Get the current up vector.
Definition: PluginFunctions.cc:913
glViewer::glHeight
unsigned int glHeight() const
get height of QGLWidget
Definition: QtBaseViewer.cc:1454
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
PluginFunctions::objectRoot
BaseObject *& objectRoot()
Get the root of the object structure.
Definition: PluginFunctions.cc:1101
PluginFunctions::sceneCenter
const ACG::Vec3d sceneCenter(int _viewer)
Get the current scene center.
Definition: PluginFunctions.cc:780
GlobalOptions.hh
PluginFunctions::getObjectId
int getObjectId(const QString &_name)
Definition: PluginFunctions.cc:330
PluginFunctions::getSceneGraphRootNode
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
Definition: PluginFunctions.cc:959
PluginFunctions::scenegraphRegionPick
bool scenegraphRegionPick(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< size_t, size_t > > &_list, QVector< float > *_depths, QVector< ACG::Vec3d > *_points)
Definition: PluginFunctions.cc:547
Viewer::ViewerProperties::drawMode
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
Definition: ViewerProperties.cc:151
Viewer::ViewerProperties::actionMode
Viewer::ActionMode actionMode()
get the action mode
Definition: ViewerProperties.cc:116
OpenMesh::VectorT< float, 4 >
PluginFunctions::drawMode
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
Definition: PluginFunctions.cc:452
PluginFunctions::collectObjectComments
QStringList collectObjectComments(bool visibleOnly, bool targetedOnly)
Definition: PluginFunctions.cc:1218
PluginFunctions::SOURCE_OBJECTS
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
PluginFunctions::setEncodedExaminerView
void setEncodedExaminerView(QString _view)
Set the encoded view for the active examiner.
Definition: PluginFunctions.cc:218
PluginFunctions::sceneGraphGenerators_
QMap< std::string,ACG::QtWidgets::SceneGraphWidgetGenerator *> sceneGraphGenerators_
Map of scenegraph widget generators.
Definition: PluginFunctions.cc:138
PluginFunctions::ALL_OBJECTS
const QStringList ALL_OBJECTS
Iterable object range.
Definition: PluginFunctions.hh:430
PluginFunctions::collectObjectMaterials
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly)
Definition: PluginFunctions.cc:1229
PluginFunctions::activeExaminer
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
Definition: PluginFunctions.cc:194
DataType
Predefined datatypes.
Definition: DataTypes.hh:83
PluginFunctions.hh
PluginFunctions::setFixedView
void setFixedView(int _mode, int _viewer)
Set a fixed View for a viewer.
Definition: PluginFunctions.cc:382
BaseObjectData::refinePick
virtual ACG::Vec3d refinePick(ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start, const ACG::Vec3d _dir, const unsigned int _targetIdx)
Refine picking.
Definition: BaseObjectData.cc:322
PluginFunctions::baseObjectData
BaseObjectData * baseObjectData(BaseObject *_object)
Cast an BaseObject to a BaseObjectData if possible.
Definition: PluginFunctions.cc:1091
PluginFunctions::getAllMeshes
bool getAllMeshes(std::vector< int > &_identifiers)
Get identifiers of all meshes.
Definition: PluginFunctions.cc:351
BaseObject::id
int id() const
Definition: BaseObject.cc:190
BaseObject::childExists
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
Definition: BaseObject.cc:516
PluginFunctions::setDataSeparatorNodes
void setDataSeparatorNodes(SeparatorNode *_dataSeparatorNode)
Set the internal data root node pointers ( DO NOT USE!! )
Definition: PluginFunctions.cc:234
Viewer::ViewerProperties::objectMarker
void objectMarker(ViewObjectMarker *_marker)
set object marker for viewer
Definition: ViewerProperties.cc:330
PluginFunctions::setDefaultViewObjectMarker
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
Definition: PluginFunctions.cc:948
PluginFunctions::objectsEnd
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsIterator.cc:177
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
PluginFunctions::getOpenFileName
QString getOpenFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
Definition: PluginFunctions.cc:1173
Viewer::ViewerProperties::rotationLocked
bool rotationLocked()
Pointer to the glState of the Viewer.
Definition: ViewerProperties.cc:134
PluginFunctions::rotate
void rotate(const ACG::Vec3d &_axis, const double _angle, const ACG::Vec3d &_center, int _viewer)
Rotate Scene around axis.
Definition: PluginFunctions.cc:835
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenBegin
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: MeshNode2T_impl.hh:294
PluginFunctions::setSceneGraphRootNode
void setSceneGraphRootNode(SeparatorNode *_root_node)
Definition: PluginFunctions.cc:253
PluginFunctions::viewers
int viewers()
Get the number of viewers.
Definition: PluginFunctions.cc:144
PluginFunctions::perspectiveProjection
void perspectiveProjection(int _viewer)
Switch to perspective Projection.
Definition: PluginFunctions.cc:624
PluginFunctions::actionMode
Viewer::ActionMode actionMode()
Get the current Action mode.
Definition: PluginFunctions.cc:588
PluginFunctions::setViewObjectMarker
void setViewObjectMarker(ViewObjectMarker *_marker)
Definition: PluginFunctions.cc:942
OpenFlipperQSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: OpenFlipperQSettings.cc:46
PluginFunctions::viewerSnapshot
void viewerSnapshot(int _viewer, QImage &_image, int _width, int _height, bool _alpha, bool _hideCoordsys, int _samples)
Take a snapshot of a viewer.
Definition: PluginFunctions.cc:1072
PluginFunctions::sceneRadius
double sceneRadius()
Returns the current scene radius from the active examiner widget.
Definition: PluginFunctions.cc:794
PluginFunctions::objectExists
bool objectExists(const int _identifier)
Check if an object with this identifier exists.
Definition: PluginFunctions.cc:340
PluginFunctions::ObjectIterator
Core Data Iterator.
Definition: PluginFunctions.hh:441
PluginFunctions::viewerId
int viewerId()
Return unique viewer id.
Definition: PluginFunctions.cc:163
PluginFunctions::mapToLocal
QPoint mapToLocal(const QPoint _point)
Map global coordinates to GL Widget local coordinates.
Definition: PluginFunctions.cc:429
PluginFunctions::eyePos
ACG::Vec3d eyePos(int _viewer)
Get the current viewer position.
Definition: PluginFunctions.cc:900
PluginFunctions::targetCount
int targetCount()
Get the number of target objects.
Definition: PluginFunctions.cc:1008
ACG::SceneGraph::SeparatorNode
Definition: SeparatorNode.hh:78
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
Viewer::ViewerProperties::backgroundColor
ACG::Vec4f backgroundColor()
Get current background color.
Definition: ViewerProperties.cc:215
PluginFunctions::get_all_objects
void get_all_objects(std::vector< BaseObjectData *> &_objects)
Definition: PluginFunctions.cc:1043
PluginFunctions::IteratorRestriction
QStringList IteratorRestriction
Iterable object range.
Definition: PluginFunctions.hh:428
BaseObjectData
Definition: BaseObjectData.hh:102
PluginFunctions::traverse
void traverse(ACG::SceneGraph::MouseEventAction &_action)
Definition: PluginFunctions.cc:571
PluginFunctions::pickMode
const std::string pickMode()
Get the current Picking mode.
Definition: PluginFunctions.cc:577
PluginFunctions::setViewers
void setViewers(const std::vector< glViewer * > &_viewerWidgets)
Set the internal Viewer pointer ( DO NOT USE!! )
Definition: PluginFunctions.cc:167
ACG::SceneGraph::ACG::SceneGraph::BaseNode::set_parent
void set_parent(BaseNode *_parent)
Set the parent of this node.
Definition: BaseNode.cc:146
PluginFunctions::increaseTargetCount
void increaseTargetCount()
Decrease the number of current Object.
Definition: PluginFunctions.cc:1117
PluginFunctions::TARGET_OBJECTS
const QStringList TARGET_OBJECTS("target")
Iterable object range.
PluginFunctions::disableExaminerLightHandling
void disableExaminerLightHandling()
Disable the core light handling.
Definition: PluginFunctions.cc:148
PluginFunctions::setTrackBallCenter
void setTrackBallCenter(const ACG::Vec3d &_center, int _viewer)
Set the trackball Center.
Definition: PluginFunctions.cc:728
ViewObjectMarker
Definition: ViewObjectMarker.hh:82
PluginFunctions::objects
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
Definition: PluginFunctions.cc:1257
PluginFunctions::setActiveExaminer
void setActiveExaminer(const unsigned int _id)
Set the active id of the examiner which got the last mouse events.
Definition: PluginFunctions.cc:181
PluginFunctions::getSourceIdentifiers
bool getSourceIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a source object.
Definition: PluginFunctions.cc:272
PluginFunctions::addObjectRenderingNode
void addObjectRenderingNode(ACG::SceneGraph::BaseNode *_node)
Add scenegraph node modifing object rendering.
Definition: PluginFunctions.cc:987
PluginFunctions::lookAt
void lookAt(const ACG::Vec3d &_eye, const ACG::Vec3d &_center, const ACG::Vec3d &_up, int _viewer)
Set the look at transformation directly.
Definition: PluginFunctions.cc:701
glViewer::snapshot
virtual void snapshot(int _width=0, int _height=0, bool _alpha=false, bool _hideCoordsys=false, int samples=1)
Definition: QtBaseViewer.cc:2384
PluginFunctions::objectReferences
ObjectReferenceRange objectReferences(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
Definition: PluginFunctions.cc:1261
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
PluginFunctions::mapToGlobal
QPoint mapToGlobal(const QPoint _point)
Map coordinates of GL Widget to global coordinates.
Definition: PluginFunctions.cc:425
PluginFunctions::setDrawMode
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
Definition: PluginFunctions.cc:433
ACG::GLState::viewing_ray
void viewing_ray(int _x, int _y, Vec3d &_origin, Vec3d &_direction) const
Definition: GLState.cc:930
PluginFunctions::setBackColor
void setBackColor(OpenMesh::Vec4f _color)
Set the background color of the examiner widget.
Definition: PluginFunctions.cc:377
PluginFunctions::setSceneRadius
void setSceneRadius(double _radius, int _viewer)
Set the background color of the examiner widget.
Definition: PluginFunctions.cc:811
PluginFunctions::addGlobalNode
void addGlobalNode(ACG::SceneGraph::BaseNode *_node)
Add a global node.
Definition: PluginFunctions.cc:981
ACG::SceneGraph::MouseEventAction
Definition: SceneGraph.hh:799
PluginFunctions::defaultViewObjectMarker
ViewObjectMarker * defaultViewObjectMarker()
Get the default ViewObjectMarker.
Definition: PluginFunctions.cc:953
PluginFunctions::addSceneGraphGenerator
void addSceneGraphGenerator(ACG::QtWidgets::SceneGraphWidgetGenerator *_generator)
Add a scenegraph generator ( the handled type will be extracted from the generator) ...
Definition: PluginFunctions.cc:1158
Viewer::ViewerProperties::currentViewingDirection
int currentViewingDirection()
Pointer to the glState of the Viewer.
Definition: ViewerProperties.cc:126
Viewer::ViewerProperties::pickMode
std::string pickMode()
get active pick mode
Definition: ViewerProperties.cc:105
PluginFunctions::viewerProperties
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
Definition: PluginFunctions.cc:611
PluginFunctions::setFOVY
void setFOVY(double _fovy)
Set field of view angle.
Definition: PluginFunctions.cc:648
PluginFunctions::allowRotation
void allowRotation(bool _mode, int _viewer)
Definition: PluginFunctions.cc:655
PluginFunctions::getSaveFileName
QString getSaveFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options, const QString &defaultSuffix)
Definition: PluginFunctions.cc:1186
Types.hh
PluginFunctions
Definition: PluginFunctions.cc:57
PluginFunctions::examinerLightHandling
bool examinerLightHandling()
returns if internal light handling is active.
Definition: PluginFunctions.cc:152
PluginFunctions::translate
void translate(const ACG::Vec3d &_vector, int _viewer)
Translate viewer pos by given vector.
Definition: PluginFunctions.cc:823
OpenFlipperQSettings::setValue
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
Definition: OpenFlipperQSettings.cc:61
glViewer
Definition: QtBaseViewer.hh:126
PluginFunctions::setViewerProperties
void setViewerProperties(const std::vector< Viewer::ViewerProperties * > &_viewerProperties)
Set the internal viewerProperties pointer ( DO NOT USE!! )
Definition: PluginFunctions.cc:177
PluginFunctions::setMainGLContext
void setMainGLContext()
Set current GL Context to main context.
Definition: PluginFunctions.cc:685
OpenFlipperSettings
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
Definition: GlobalOptions.cc:1038
PluginFunctions::ObjectReferenceRange
Range adapter for ObjectIterator.
Definition: PluginFunctions.hh:613
PluginFunctions::sourceCount
int sourceCount()
Get the number of source objects.
Definition: PluginFunctions.cc:1012
PluginFunctions::getAllObjectIdentifiers
bool getAllObjectIdentifiers(std::vector< int > &_identifiers)
Get identifiers of all objects.
Definition: PluginFunctions.cc:364
PluginFunctions::increaseObjectCount
void increaseObjectCount()
Decrease the number of current Object.
Definition: PluginFunctions.cc:1105
PluginFunctions::getEncodedExaminerView
QString getEncodedExaminerView()
Get the encoded view for the active examiner.
Definition: PluginFunctions.cc:198
PluginFunctions::orthographicProjection
void orthographicProjection(int _viewer)
Switch to orthographic Projection.
Definition: PluginFunctions.cc:636
PluginFunctions::addObjectToMap
void addObjectToMap(int _objectId, BaseObject *_object)
Add object to internal object map.
Definition: PluginFunctions.cc:1132
ACG::QtWidgets::SceneGraphWidgetGenerator
Definition: QtSceneGraphWidget.hh:81
PluginFunctions::getPickedObject
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Definition: PluginFunctions.cc:261
PluginFunctions::viewer
glViewer * viewer(int _viewerId)
Get a Viewer.
Definition: PluginFunctions.cc:185
PluginFunctions::getTargetIdentifiers
bool getTargetIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a target object.
Definition: PluginFunctions.cc:282
PluginFunctions::addGlobalStatusNode
void addGlobalStatusNode(ACG::SceneGraph::BaseNode *_node)
Adds a global status node.
Definition: PluginFunctions.cc:967
DATA_ALL
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
PluginFunctions::isProjectionOrthographic
bool isProjectionOrthographic(int _viewer)
Check if the projection is orthographic.
Definition: PluginFunctions.cc:888
ACG::GLState::eye
Vec3d eye() const
get eye point
Definition: GLState.cc:886
PluginFunctions::setSceneCenter
void setSceneCenter(const ACG::Vec3d &_center, int _viewer)
Definition: PluginFunctions.cc:764
ACG::SceneGraph::traverse
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:137
typeId
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
Definition: Types.cc:139
Viewer::ViewerProperties::glState
ACG::GLState & glState()
Get the glState of the Viewer.
Definition: ViewerProperties.cc:318
PluginFunctions::viewAll
void viewAll(int _viewer)
View the whole scene.
Definition: PluginFunctions.cc:863
PluginFunctions::setSceneGraphRootNodeGlobal
void setSceneGraphRootNodeGlobal(SeparatorNode *_root_node)
Definition: PluginFunctions.cc:257
PluginFunctions::viewingRay
void viewingRay(int _x, int _y, ACG::Vec3d &_outOrigin, ACG::Vec3d &_outDirection)
Retrieve a viewing ray from the active examiner that can be used for raycasting.
Definition: PluginFunctions.cc:466
PluginFunctions::flyTo
void flyTo(const ACG::Vec3d &_position, const ACG::Vec3d &_center, double _time)
Fly to point and viewing direction (animated).
Definition: PluginFunctions.cc:1057