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 
469  ObjectIterator(const ObjectIterator &) = default;
470 
472  operator value_handle() { return pos_; };
473 
475  bool operator==( const ObjectIterator& _rhs) const;
476 
478  bool operator!=( const ObjectIterator& _rhs) const;
479 
481  ObjectIterator& operator=( const ObjectIterator&) = default;
482 
484  pointer operator->();
485 
487  ObjectIterator& operator++();
488 
490  ObjectIterator& operator--();
491 
493  BaseObjectData* operator*();
494 
496  BaseObjectData* index() { return pos_; };
497 
498  private :
501 
504 
506  IteratorRestriction restriction_;
507 
511  inline void proceedToNextBaseObjectData(BaseObject*& _object);
512 };
513 
514 
519 class DLLEXPORT ObjectReferenceIterator : public std::iterator<std::forward_iterator_tag, BaseObjectData>
520 {
521 public:
522  explicit ObjectReferenceIterator(IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
523  it_(_restriction, _dataType)
524  {
525  }
526 
527  explicit ObjectReferenceIterator(BaseObjectData* _pos, IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
528  it_(_pos, _restriction, _dataType)
529  {
530  }
531 
533  it_(_rhs.it_)
534  {
535  }
536 
537  ObjectReferenceIterator& operator=(const ObjectReferenceIterator& _rhs)
538  {
539  if (this != &_rhs) {
540  it_ = _rhs.it_;
541  }
542  return *this;
543  }
544 
545  ObjectReferenceIterator& operator++() {
546  ++it_;
547  return *this;
548  }
549 
550  ObjectReferenceIterator operator++(int) {
551  ObjectReferenceIterator copy(*this);
552  operator++();
553  return copy;
554  }
555 
556  bool operator==(const ObjectReferenceIterator& _rhs) const {
557  return it_ == _rhs.it_;
558  }
559 
560  bool operator!=(const ObjectReferenceIterator& _rhs) const {
561  return it_ != _rhs.it_;
562  }
563 
564  BaseObjectData& operator*() {
565  return **it_;
566  }
567 
568  BaseObjectData* operator->() {
569  return *it_;
570  }
571 
572 private:
573  ObjectIterator it_;
574 };
575 
576 
586 public:
587  explicit ObjectRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
588  restriction_(_restriction),
589  dataType_(_dataType)
590  {
591  }
592 
593  ObjectIterator begin() const {
594  return ObjectIterator(restriction_, dataType_);
595  }
596 
597  ObjectIterator end() const {
598  return ObjectIterator(0);
599  }
600 
601 private:
602  IteratorRestriction restriction_;
603  DataType dataType_;
604 };
605 
606 
616 public:
617  explicit ObjectReferenceRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
618  restriction_(_restriction),
619  dataType_(_dataType)
620  {
621  }
622 
623  ObjectReferenceIterator begin() const {
624  return ObjectReferenceIterator(restriction_, dataType_);
625  }
626 
627  ObjectReferenceIterator end() const {
628  return ObjectReferenceIterator(0);
629  }
630 
631 private:
632  IteratorRestriction restriction_;
633  DataType dataType_;
634 };
635 
636 
649 DLLEXPORT
650 ObjectReferenceRange objectReferences(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL);
651 
652 
666 DLLEXPORT
667 ObjectRange objects(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL);
668 
669 
678 
679  public :
680 
683 
686 
688  typedef value_type& reference;
689 
691  typedef value_type* pointer;
692 
700  BaseObjectIterator(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
701 
703  BaseObjectIterator(BaseObject* pos, IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
704 
706  operator value_handle() { return pos_; };
707 
709  bool operator==( const BaseObjectIterator& _rhs);
710 
712  bool operator!=( const BaseObjectIterator& _rhs);
713 
715  BaseObjectIterator& operator=( const BaseObjectIterator& _rhs);
716 
718  pointer operator->();
719 
721  BaseObjectIterator& operator++();
722 
724  BaseObjectIterator& operator--();
725 
727  BaseObject* operator*();
728 
730  BaseObject* index() { return pos_; };
731 
732  private :
734  BaseObject* pos_;
735 
738 
740  IteratorRestriction restriction_;
741 
742 };
743 
744 // /// Return Iterator to Mesh End
745 // MeshIterator meshes_end();
746 
748 DLLEXPORT
750 
752 DLLEXPORT
754 
757 //=======================================
758 // Dont Use functions below!!!
761 //=======================================
762 
764 DLLEXPORT
765 void setDataRoot( BaseObject* _root );
766 
769 //=======================================
772 //=======================================
773 
779 DLLEXPORT
781 
790 DLLEXPORT
791 int viewerId();
792 
794 DLLEXPORT
796 
816 DLLEXPORT
817 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
818 QString getOpenFileName(const QString &configProperty,
819  QWidget * parent = nullptr, const QString & caption = QString(),
820  const QString & defaultDir = QString(), const QString & filter = QString(),
821  QString * selectedFilter = nullptr, QFileDialog::Options options = 0);
822 #else
823 QString getOpenFileName(const QString &configProperty,
824  QWidget * parent = nullptr, const QString & caption = QString(),
825  const QString & defaultDir = QString(), const QString & filter = QString(),
826  QString * selectedFilter = nullptr, QFileDialog::Options options = QFileDialog::Options() );
827 #endif
828 
829 
849 DLLEXPORT
850 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
851 QString getSaveFileName(const QString &configProperty,
852  QWidget * parent = nullptr, const QString & caption = QString(),
853  const QString & defaultDir = QString(), const QString & filter = QString(),
854  QString * selectedFilter = nullptr, QFileDialog::Options options = 0,
855  const QString & defaultSuffix = QString() );
856 #else
857 QString getSaveFileName(const QString &configProperty,
858  QWidget * parent = nullptr, const QString & caption = QString(),
859  const QString & defaultDir = QString(), const QString & filter = QString(),
860  QString * selectedFilter = nullptr, QFileDialog::Options options = QFileDialog::Options(),
861  const QString & defaultSuffix = QString() );
862 #endif
863 
864 
865 } /* namespace PluginFunctions */
866 
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
void shareGLWidget(OFGLWidget *_widget)
Sets the main QGLWidget for gl data sharing.
BaseObjectData * value_handle
handle type (just an int)
void setDataRoot(BaseObject *_root)
int visibleCount()
Get the number of visible objects.
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.
Range adapter for ObjectIterator.
#define DLLEXPORT
int objectCount()
Get the number of available objects.
value_type & reference
reference type
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
BaseObject *& objectRoot()
Get the root of the object structure.
value_type * pointer
basic pointer type
int getObjectId(const QString &_name)
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
bool scenegraphRegionPick(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< size_t, size_t > > &_list, QVector< float > *_depths, QVector< ACG::Vec3d > *_points)
QStringList collectObjectComments(bool visibleOnly, bool targetedOnly)
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
void setEncodedExaminerView(QString _view)
Set the encoded view for the active examiner.
const QStringList ALL_OBJECTS
Iterable object range.
Helper class that wraps an ObjectIterator to return a reference instead of a pointer.
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly)
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
Predefined datatypes.
Definition: DataTypes.hh:83
BaseObjectData * baseObjectData(BaseObject *_object)
Cast an BaseObject to a BaseObjectData if possible.
bool getAllMeshes(std::vector< int > &_identifiers)
Get identifiers of all meshes.
BaseObject * value_handle
handle type (just an int)
BaseObjectData * pos_
current position of the iterator
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
value_type * pointer
basic pointer type
QString getOpenFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
IteratorRestriction restriction_
Restriction of the iterator.
int viewers()
Get the number of viewers.
Viewer::ActionMode actionMode()
Get the current Action mode.
void setViewObjectMarker(ViewObjectMarker *_marker)
bool objectExists(const int _identifier)
Check if an object with this identifier exists.
int viewerId()
Return unique viewer id.
QPoint mapToLocal(const QPoint _point)
Map global coordinates to GL Widget local coordinates.
Core Data Iterator used to iterate over all objects (Including groups)
int targetCount()
Get the number of target objects.
IteratorRestriction restriction_
Restriction of the iterator.
QStringList IteratorRestriction
Iterable object range.
void traverse(ACG::SceneGraph::MouseEventAction &_action)
const std::string pickMode()
Get the current Picking mode.
BaseObjectData value_type
type of the Objects the iterator works on
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void disableExaminerLightHandling()
Disable the core light handling.
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
void setActiveExaminer(const unsigned int _id)
Set the active id of the examiner which got the last mouse events.
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.
ObjectReferenceRange objectReferences(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
QPoint mapToGlobal(const QPoint _point)
Map coordinates of GL Widget to global coordinates.
DataType dataType_
returned data types of the iterator
void addGlobalNode(ACG::SceneGraph::BaseNode *_node)
Add a global node.
ViewObjectMarker * defaultViewObjectMarker()
Get the default ViewObjectMarker.
BaseObject * pos_
current position of the iterator
void allowRotation(bool _mode, int _viewer)
QString getSaveFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options, const QString &defaultSuffix)
bool examinerLightHandling()
returns if internal light handling is active.
Range adapter for ObjectIterator.
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
value_type & reference
reference type
int sourceCount()
Get the number of source objects.
bool getAllObjectIdentifiers(std::vector< int > &_identifiers)
Get identifiers of all objects.
QString getEncodedExaminerView()
Get the encoded view for the active examiner.
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.
void addGlobalStatusNode(ACG::SceneGraph::BaseNode *_node)
Adds a global status node.
BaseObject value_type
type of the Objects the iterator works on
DataType dataType_
returned data types of the iterator
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
void setSceneCenter(const ACG::Vec3d &_center, int _viewer)