MIRA
Visualization2DView.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_VISUALIZATION2DVIEW_H_
48 #define _MIRA_VISUALIZATION2DVIEW_H_
49 
51 #include <serialization/adapters/Qt/QColor>
52 
55 
56 #include <QGraphicsView>
57 #include <QMessageBox>
58 
59 namespace mira {
60 
62 
68 {
70  ("Name", "2D")
71  ("Description", "2D view for channel data")
72  ("Category" , "Visualization")
73  ("Visualization", "mira::Visualization2D"))
74 
75 public:
77 
78  virtual ~Visualization2DView()
79  {
80  // we must make sure that we destroy our tools and visualizations
81  // before we destroy ourself to give them the chance to cleanup
82  // (during cleanup they may need a fully operational Visualization2DView)
84  destroyTools();
85  }
86 
87 public:
88 
89  template <typename Reflector>
90  void reflect(Reflector& r)
91  {
93  r.property("BackgroundColor", mBackgroundColor, setter<QColor>(&Visualization2DView::setBackgroundColor, this), "The color", QColor(Qt::white));
94  r.property("Camera", mCameraSettings, "Camera view", Camera());
95 
96  r.property("SaveContentMinPictureSize", mSaveContentMinPictureSize,
97  "Minimum width or height of the image saved by rendering the viewport at an appropriate resolution.", 2048);
98  }
99 
100 public: // implementation of VisualizationView
101 
102  virtual void addVisualization(Visualization* vis);
103  virtual void moveUpVisualization(Visualization* vis);
104  virtual void moveDownVisualization(Visualization* vis);
105 
106  virtual void addTool(VisualizationTool* tool);
107 
108  virtual const Class& supportedVisualizationClass() const;
109  virtual const Class& supportedVisualizationToolClass() const;
110 
111 protected:
112 
113  virtual void update(Duration dt);
114 
115 protected:
116 
117  virtual QWidget* createVisualizationPart();
118  virtual void resetView();
119  virtual void saveContentToFile();
120 
121 public: // implementation of IVisualization2DSite
122 
123  virtual QGraphicsScene* getSceneManager();
124 
125  virtual QGraphicsView* getViewManager();
126 
127  virtual const std::string& getFixedFrame() const {
128  return mFixedFrame.getID();
129  }
130 
131  virtual const std::string& getCameraFrame() const {
132  return mCameraFrame.getID();
133  }
134 
135  virtual const Camera& getCamera() const;
136  virtual void setCamera(const Camera& camera);
137 
138  virtual float getToolBaseZValue() const;
139 
140 private:
141 
142  void setBackgroundColor(const QColor& color);
143  void updateCamera();
144 
145 private:
146 
147  class UI;
148  UI* ui;
149 
150 private:
151  friend class UI;
152 
153  void setupVisualizations();
154  void setupTools();
155 
156 private:
157  void populateDefaultVisualizations();
158  void createDefaultVisualization(const std::string& className, const std::string& displayName);
159 
160 private:
161 
162  QGraphicsScene* mScene;
163  QColor mBackgroundColor;
164  Camera mCameraSettings;
165 
166  uint mSaveContentMinPictureSize;
167 };
168 
170 
171 class Visualization2DView::UI : public QGraphicsView
172 {
173  Q_OBJECT
174 public:
175 
176  UI(Visualization2DView* parent);
177 
178  virtual ~UI()
179  {
180  }
181 
182  void setCenter(const QPointF& centerPoint);
183  QPointF getCenter() const { return mCurrentCenterPoint; }
184 
186 
187 protected:
188 
189  virtual void dragEnterEvent(QDragEnterEvent *event);
190 
191  virtual void dropEvent(QDropEvent *event);
192 
193  // we need to overwrite this to prevent the QGraphicsView from disturbing our drag n drop
194  virtual void dragMoveEvent(QDragMoveEvent* event);
195  virtual void mousePressEvent(QMouseEvent* event);
196  virtual void mouseMoveEvent(QMouseEvent* event);
197  virtual void mouseReleaseEvent(QMouseEvent* event);
198  virtual void wheelEvent (QWheelEvent* event);
199 
200 protected:
202 
203 private:
204  QPointF mCurrentCenterPoint;
205 };
206 
208 
209 }
210 
211 #endif
virtual void saveContentToFile()
virtual void addTool(VisualizationTool *tool)
Adds an existing tool to this view.
virtual void wheelEvent(QWheelEvent *event)
virtual void moveDownVisualization(Visualization *vis)
Change order of visualizations in the view, move the specified visualization down.
Definition: Visualization2D.h:73
Definition: VisualizationTool.h:59
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Abstract base class for all derived visualizations, namely Visualization3D and Visualization2D.
Definition: Visualization.h:90
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
Class object which supports some kind of class reflection.
Definition: Class.h:97
virtual float getToolBaseZValue() const
Obtains the Z value all tools should adhere to to ensure that they will always be above regular visua...
virtual const std::string & getFixedFrame() const
Definition: Visualization2DView.h:127
TransformProperty mFixedFrame
Definition: VisualizationView.h:366
void reflect(Reflector &r)
Definition: Visualization2DView.h:90
2D view of a scene that may contain different visualization objects which show the actual content of ...
Definition: Visualization2DView.h:67
Provides MIRA_CLASS_SERIALIZATION macro and includes the major headers of the serialization framework...
virtual void setCamera(const Camera &camera)
Sets the current camera settings (position, orientation, etc.) of the views own camera.
Definition: Visualization2DView.h:171
Abstract base class for 2D, 3D, text and plot visualization views (namely Visualization2DView and Vis...
Definition: VisualizationView.h:338
virtual const Camera & getCamera() const
Obtains the current camera settings (position, orientation, etc.) of the views own camera...
#define MIRA_META_OBJECT(classIdentifier, MetaInfo)
Use this MACRO instead of MIRA_OBJECT if you like to add meta information to your class...
Definition: FactoryMacros.h:204
Use this class to represent time durations.
Definition: Time.h:106
virtual void update(Duration dt)
Is called by this class within the update timer event to update the view.
virtual const std::string & getCameraFrame() const
Definition: Visualization2DView.h:131
virtual void addVisualization(Visualization *vis)
Adds an existing visualization to this view.
virtual void dragMoveEvent(QDragMoveEvent *event)
TransformProperty mCameraFrame
Definition: VisualizationView.h:367
virtual const Class & supportedVisualizationToolClass() const
Derived visualization views may return the base class of their supported tools.
Definition: Visualization2D.h:64
virtual ~UI()
Definition: Visualization2DView.h:178
UI(Visualization2DView *parent)
virtual QGraphicsView * getViewManager()
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void moveUpVisualization(Visualization *vis)
Change order of visualizations in the view, move the specified visualization up.
virtual void dragEnterEvent(QDragEnterEvent *event)
const std::string & getID() const
Returns the frame ID of this property.
Definition: TransformProperty.h:95
virtual void mousePressEvent(QMouseEvent *event)
Declaration of Visualization2D and related classes.
virtual QWidget * createVisualizationPart()
virtual QGraphicsScene * getSceneManager()
Visualization2DView * vis
Definition: Visualization2DView.h:201
QPointF getCenter() const
Definition: Visualization2DView.h:183
virtual const Class & supportedVisualizationClass() const
Derived visualization views must return the base class of their supported visualizations.
Declaration of VisualizationView and VisualizationViewTransformable.
virtual void dropEvent(QDropEvent *event)
friend class UI
Definition: Visualization2DView.h:151
virtual void mouseMoveEvent(QMouseEvent *event)
virtual void resetView()
void setCenter(const QPointF &centerPoint)