Developer Documentation
PluginFunctions.hh
Go to the documentation of this file.
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 // Standard Functions
45 //
46 //=============================================================================
47 
53 #pragma once
54 
55 
56 #include <QPair>
57 #include <QFileDialog>
58 
60 #include <OpenFlipper/common/OFGLWidget.hh>
61 
63 #include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
64 
65 //== FORWARDDECLARATIONS ======================================================
66 class ViewObjectMarker;
67 
70 namespace PluginFunctions {
71 
72 //=======================================
73 // Get Source/Target objects
76 //=======================================
77 
84 bool getPickedObject(const size_t _node_idx , BaseObjectData*& _object);
85 
88 //=======================================
89 // Get Objects by their identifier
92 //=======================================
93 
100 bool getSourceIdentifiers( std::vector<int>& _identifiers );
101 
107 DLLEXPORT
108 bool getTargetIdentifiers( std::vector<int>& _identifiers );
109 
115 DLLEXPORT
116 bool getAllObjectIdentifiers( std::vector<int>& _identifiers );
117 
123 DLLEXPORT
124 bool getAllMeshes( std::vector<int>& _identifiers );
125 
136 DLLEXPORT
137 bool getObject( const int _identifier , BaseObject*& _object );
138 
142 DLLEXPORT
143 bool getObject( const int _identifier , BaseObjectData*& _object );
144 
147 DLLEXPORT
148 int getObjectId( const QString& _name );
149 
155 DLLEXPORT
156 bool objectExists( const int _identifier );
157 
159 DLLEXPORT
160 int objectCount();
161 
163 DLLEXPORT
164 int targetCount();
165 
167 DLLEXPORT
168 int sourceCount();
169 
171 DLLEXPORT
172 int visibleCount();
173 
176 //=======================================
177 // Get/set status of examiner
180 //=======================================
181 
182 
184 DLLEXPORT
185 int viewers( );
186 
194 DLLEXPORT
196 
202 DLLEXPORT
203 bool examinerLightHandling();
204 
206 DLLEXPORT
207 void setActiveExaminer( const unsigned int _id );
208 
210 DLLEXPORT
211 unsigned int activeExaminer();
212 
214 DLLEXPORT
215 QString getEncodedExaminerView();
216 
218 DLLEXPORT
219 QString getEncodedExaminerView(int _viewerId);
220 
222 DLLEXPORT
223 void setEncodedExaminerView( QString _view );
224 
226 DLLEXPORT
227 void setEncodedExaminerView(int _viewerId , QString _view );
228 
232 DLLEXPORT
233 void setSceneCenter(const ACG::Vec3d& _center, int _viewer );
234 
240 DLLEXPORT
241 bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr );
242 
247 DLLEXPORT
248 bool scenegraphPick( const unsigned int _examiner ,ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr );
249 
256 DLLEXPORT
257 bool scenegraphPick( const unsigned int _examiner ,ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, BaseObjectData*& _object, size_t &_targetIdx, const bool _refine ,ACG::Vec3d *_hitPointPtr );
258 
265 DLLEXPORT
266 bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, BaseObjectData*& _object, size_t &_targetIdx, const bool _refine, ACG::Vec3d *_hitPointPtr );
267 
268 
273 DLLEXPORT
275  const QRegion& _region,
276  QList<QPair<size_t, size_t> >& _list,
277  QVector<float>* _depths = 0,
278  QVector<ACG::Vec3d>* _points = 0);
279 
283 DLLEXPORT
284 bool scenegraphRegionPick( const unsigned int _examiner,
285  ACG::SceneGraph::PickTarget _pickTarget,
286  const QRegion& _region,
287  QList<QPair<size_t, size_t> >& _list,
288  QVector<float>* _depths = 0,
289  QVector<ACG::Vec3d>* _points = 0);
290 
295 DLLEXPORT
297 
299 DLLEXPORT
300 const std::string pickMode ();
301 
303 DLLEXPORT
304 void pickMode ( const std::string& _mode);
305 
307 DLLEXPORT
308 void getCurrentViewImage(QImage& _image);
309 
318 DLLEXPORT
320 
326 DLLEXPORT
328 
334 DLLEXPORT
336 
342 DLLEXPORT
344 
353 DLLEXPORT
355 
357 DLLEXPORT
358 void actionMode ( Viewer::ActionMode _mode);
359 
361 DLLEXPORT
363 
365 DLLEXPORT
366 void shareGLWidget(OFGLWidget* _widget);
367 
369 DLLEXPORT
370 OFGLWidget* shareGLWidget();
371 
376 DLLEXPORT
377 void allowRotation(bool _mode);
378 
382 DLLEXPORT
383 QPoint mapToGlobal( const QPoint _point );
384 
388 DLLEXPORT
389 QPoint mapToLocal( const QPoint _point );
390 
395 DLLEXPORT
396 void setViewObjectMarker (ViewObjectMarker *_marker);
397 
402 DLLEXPORT
404 
407 DLLEXPORT
408 QStringList collectObjectComments(bool visibleOnly, bool targetedOnly);
409 
412 DLLEXPORT
413 QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly);
414 
416 DLLEXPORT
418 
422 //=======================================
423 // Iterators for object Access
426 //=======================================
427 
428 typedef QStringList IteratorRestriction;
429 
430 const QStringList ALL_OBJECTS;
431 const QStringList TARGET_OBJECTS ("target");
432 const QStringList SOURCE_OBJECTS ("source");
433 
442 
443  public :
444 
447 
450 
452  typedef value_type& reference;
453 
455  typedef value_type* pointer;
456 
464  ObjectIterator(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
465 
467  ObjectIterator(BaseObjectData* pos, IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
468 
470  operator value_handle() { return pos_; };
471 
473  bool operator==( const ObjectIterator& _rhs) const;
474 
476  bool operator!=( const ObjectIterator& _rhs) const;
477 
479  ObjectIterator& operator=( const ObjectIterator& _rhs);
480 
482  pointer operator->();
483 
485  ObjectIterator& operator++();
486 
488  ObjectIterator& operator--();
489 
491  BaseObjectData* operator*();
492 
494  BaseObjectData* index() { return pos_; };
495 
496  private :
499 
502 
504  IteratorRestriction restriction_;
505 
509  inline void proceedToNextBaseObjectData(BaseObject*& _object);
510 };
511 
512 
517 class DLLEXPORT ObjectReferenceIterator : public std::iterator<std::forward_iterator_tag, BaseObjectData>
518 {
519 public:
520  explicit ObjectReferenceIterator(IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
521  it_(_restriction, _dataType)
522  {
523  }
524 
525  explicit ObjectReferenceIterator(BaseObjectData* _pos, IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
526  it_(_pos, _restriction, _dataType)
527  {
528  }
529 
531  it_(_rhs.it_)
532  {
533  }
534 
535  ObjectReferenceIterator& operator=(const ObjectReferenceIterator& _rhs)
536  {
537  if (this != &_rhs) {
538  it_ = _rhs.it_;
539  }
540  return *this;
541  }
542 
543  ObjectReferenceIterator& operator++() {
544  ++it_;
545  return *this;
546  }
547 
548  ObjectReferenceIterator operator++(int) {
549  ObjectReferenceIterator copy(*this);
550  operator++();
551  return copy;
552  }
553 
554  bool operator==(const ObjectReferenceIterator& _rhs) const {
555  return it_ == _rhs.it_;
556  }
557 
558  bool operator!=(const ObjectReferenceIterator& _rhs) const {
559  return it_ != _rhs.it_;
560  }
561 
562  BaseObjectData& operator*() {
563  return **it_;
564  }
565 
566  BaseObjectData* operator->() {
567  return *it_;
568  }
569 
570 private:
571  ObjectIterator it_;
572 };
573 
574 
584 public:
585  explicit ObjectRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
586  restriction_(_restriction),
587  dataType_(_dataType)
588  {
589  }
590 
591  ObjectIterator begin() const {
592  return ObjectIterator(restriction_, dataType_);
593  }
594 
595  ObjectIterator end() const {
596  return ObjectIterator(0);
597  }
598 
599 private:
600  IteratorRestriction restriction_;
601  DataType dataType_;
602 };
603 
604 
614 public:
615  explicit ObjectReferenceRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
616  restriction_(_restriction),
617  dataType_(_dataType)
618  {
619  }
620 
621  ObjectReferenceIterator begin() const {
622  return ObjectReferenceIterator(restriction_, dataType_);
623  }
624 
625  ObjectReferenceIterator end() const {
626  return ObjectReferenceIterator(0);
627  }
628 
629 private:
630  IteratorRestriction restriction_;
631  DataType dataType_;
632 };
633 
634 
647 DLLEXPORT
648 ObjectReferenceRange objectReferences(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL);
649 
650 
664 DLLEXPORT
665 ObjectRange objects(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL);
666 
667 
676 
677  public :
678 
681 
684 
686  typedef value_type& reference;
687 
689  typedef value_type* pointer;
690 
698  BaseObjectIterator(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
699 
701  BaseObjectIterator(BaseObject* pos, IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
702 
704  operator value_handle() { return pos_; };
705 
707  bool operator==( const BaseObjectIterator& _rhs);
708 
710  bool operator!=( const BaseObjectIterator& _rhs);
711 
713  BaseObjectIterator& operator=( const BaseObjectIterator& _rhs);
714 
716  pointer operator->();
717 
719  BaseObjectIterator& operator++();
720 
722  BaseObjectIterator& operator--();
723 
725  BaseObject* operator*();
726 
728  BaseObject* index() { return pos_; };
729 
730  private :
732  BaseObject* pos_;
733 
736 
738  IteratorRestriction restriction_;
739 
740 };
741 
742 // /// Return Iterator to Mesh End
743 // MeshIterator meshes_end();
744 
746 DLLEXPORT
748 
750 DLLEXPORT
752 
755 //=======================================
756 // Dont Use functions below!!!
759 //=======================================
760 
762 DLLEXPORT
763 void setDataRoot( BaseObject* _root );
764 
767 //=======================================
770 //=======================================
771 
777 DLLEXPORT
779 
788 DLLEXPORT
789 int viewerId();
790 
792 DLLEXPORT
794 
814 DLLEXPORT
815 QString getOpenFileName(const QString &configProperty,
816  QWidget * parent = 0, const QString & caption = QString(),
817  const QString & defaultDir = QString(), const QString & filter = QString(),
818  QString * selectedFilter = 0, QFileDialog::Options options = 0);
838 DLLEXPORT
839 QString getSaveFileName(const QString &configProperty,
840  QWidget * parent = 0, const QString & caption = QString(),
841  const QString & defaultDir = QString(), const QString & filter = QString(),
842  QString * selectedFilter = 0, QFileDialog::Options options = 0,
843  const QString & defaultSuffix = QString() );
844 
845 } /* namespace PluginFunctions */
846 
ViewObjectMarker * defaultViewObjectMarker()
Get the default ViewObjectMarker.
void allowRotation(bool _mode, int _viewer)
void addGlobalNode(ACG::SceneGraph::BaseNode *_node)
Add a global node.
void shareGLWidget(OFGLWidget *_widget)
Sets the main QGLWidget for gl data sharing.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
int getObjectId(const QString &_name)
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
int sourceCount()
Get the number of source objects.
bool getAllObjectIdentifiers(std::vector< int > &_identifiers)
Get identifiers of all objects.
QStringList collectObjectComments(bool visibleOnly, bool targetedOnly)
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly)
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
value_type * pointer
basic pointer type
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
bool getTargetIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a target object.
bool objectExists(const int _identifier)
Check if an object with this identifier exists.
BaseObjectData * value_handle
handle type (just an int)
IteratorRestriction restriction_
Restriction of the iterator.
BaseObjectData value_type
type of the Objects the iterator works on
const QStringList TARGET_OBJECTS("target")
Iterable object range.
QStringList IteratorRestriction
Iterable object range.
QPoint mapToGlobal(const QPoint _point)
Map coordinates of GL Widget to global coordinates.
int viewers()
Get the number of viewers.
const QStringList ALL_OBJECTS
Iterable object range.
void setActiveExaminer(const unsigned int _id)
Set the active id of the examiner which got the last mouse events.
int viewerId()
Return unique viewer id.
bool getSourceIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a source object.
void addObjectRenderingNode(ACG::SceneGraph::BaseNode *_node)
Add scenegraph node modifing object rendering.
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
ActionMode
Enum listing action modes of the viewers.
void getCurrentViewImage(QImage &_image)
Returns a QImage of the current View.
Helper class that wraps an ObjectIterator to return a reference instead of a pointer.
BaseObject * pos_
current position of the iterator
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
BaseObject *& objectRoot()
Get the root of the object structure.
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
void disableExaminerLightHandling()
Disable the core light handling.
Range adapter for ObjectIterator.
DataType dataType_
returned data types of the iterator
void setEncodedExaminerView(QString _view)
Set the encoded view for the active examiner.
bool scenegraphRegionPick(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< size_t, size_t > > &_list, QVector< float > *_depths, QVector< ACG::Vec3d > *_points)
ObjectReferenceRange objectReferences(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
value_type * pointer
basic pointer type
BaseObjectData * pos_
current position of the iterator
BaseObjectData * baseObjectData(BaseObject *_object)
Cast an BaseObject to a BaseObjectData if possible.
QString getEncodedExaminerView()
Get the encoded view for the active examiner.
void addGlobalStatusNode(ACG::SceneGraph::BaseNode *_node)
Adds a global status node.
void setSceneCenter(const ACG::Vec3d &_center, int _viewer)
bool getAllMeshes(std::vector< int > &_identifiers)
Get identifiers of all meshes.
DataType dataType_
returned data types of the iterator
IteratorRestriction restriction_
Restriction of the iterator.
Predefined datatypes.
Definition: DataTypes.hh:83
int visibleCount()
Get the number of visible objects.
value_type & reference
reference type
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void setDataRoot(BaseObject *_root)
void setViewObjectMarker(ViewObjectMarker *_marker)
QString getOpenFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QPoint mapToLocal(const QPoint _point)
Map global coordinates to GL Widget local coordinates.
Viewer::ActionMode actionMode()
Get the current Action mode.
BaseObject * value_handle
handle type (just an int)
int objectCount()
Get the number of available objects.
Range adapter for ObjectIterator.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
int targetCount()
Get the number of target objects.
BaseObject value_type
type of the Objects the iterator works on
value_type & reference
reference type
#define DLLEXPORT
QString getSaveFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options, const QString &defaultSuffix)
void traverse(ACG::SceneGraph::MouseEventAction &_action)
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
bool examinerLightHandling()
returns if internal light handling is active.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
const std::string pickMode()
Get the current Picking mode.
Core Data Iterator used to iterate over all objects (Including groups)