OpenStructure
data_viewer_panel_base.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 /*
22  Authors: Ansgar Philippsen, Johan Hebert, Andreas Schenk
23 */
24 
25 #ifndef DATA_VIEWER_PANEL_BASE_HH_
26 #define DATA_VIEWER_PANEL_BASE_HH_
27 
28 #include <map>
29 
30 #ifndef Q_MOC_RUN
31 
32 #include <boost/shared_ptr.hpp>
33 #include <ost/base.hh>
34 #include <ost/img/extent.hh>
35 #include <ost/img/data_observer.hh>
38 
39 #include <ost/gui/module_config.hh>
41 
43 
44 #endif
45 
46 #include <QWidget>
47 #include <QCursor>
48 #include <QMenu>
49 #include <QPen>
50 #include <QBrush>
51 #include <QRubberBand>
52 
53 namespace ost { namespace img { namespace gui {
54 
55 
56 class DLLEXPORT_OST_GUI DataViewerPanelBase: public QWidget,
57  public DataObserver
58 {
59  Q_OBJECT;
60 
61 public:
62  DataViewerPanelBase(const ImageHandle& data,QWidget* parent);
64 
65  virtual void SetData(const ImageHandle& d);
66 
68  // event handling
69  virtual void paintEvent(QPaintEvent* event);
70  virtual void resizeEvent(QResizeEvent* event);
71  virtual void wheelEvent (QWheelEvent* event);
72  virtual void mousePressEvent(QMouseEvent* event);
73  virtual void mouseReleaseEvent(QMouseEvent* event);
74  virtual void mouseMoveEvent(QMouseEvent* event);
75  virtual void keyPressEvent(QKeyEvent * event);
76 
77 
79  // observer interface
80  virtual void ObserverUpdate();
81  virtual void ObserverUpdate(const Extent& e);
82  virtual void ObserverUpdate(const Point& p);
83  virtual void ObserverRelease();
84 
86  // other methods
87 
89  void UpdateView(bool update_raster_image=true);
90  void UpdateView(const QRect& rect,bool update_raster_image=true);
91 
94 
96  void Renormalize();
97 
98 
100 
104 
106  void SetSelection(const Extent& extent);
107 
109  Point WinToPoint(int mx, int my) const;
110  Point WinToPoint(const QPoint& p) const;
111 
113  geom::Vec2 WinToFracPoint(const QPoint& p) const;
114  geom::Vec2 WinToFracPoint(int mx, int my) const;
115  geom::Vec2 WinToFracPointCenter(const QPoint& p) const;
116  geom::Vec2 WinToFracPointCenter(int mx, int my) const;
117 
119  QPoint PointToWin(const Point& p) const;
121  QPoint FracPointToWin(const geom::Vec2& p) const;
123  QPoint FracPointToWinCenter(const geom::Vec2& p) const;
124 
126  bool IsWithin(const QPoint& p) const;
127 
130 
132  void SetZoomScale(Real zoom);
133 
136 
139 
140 
142  void SetDefaultCursor(const QCursor& c);
143  void SetDefaultCursor(int id);
144 
146  void SetCursor(const QCursor& c);
147  void SetCursor(int id);
148 
150  void SetDisplayPixelValues(bool show);
151  bool GetDisplayPixelValues(){return display_pixel_values_;};
152 
154  void Recenter();
155 
156 
158  // other methods
161  RasterImage::Mode GetColorMode(){return cmode_;};
162 
168 
169  geom::Vec2 GetMousePosition(){return mouseposition_;};
170  void MoveTo(const geom::Vec2& p);
173  void ShowClickedPosition(bool show);
175  bool HasSelection();
177  Real GetDataMin() const;
178  Real GetDataMax() const;
179  bool GetInvert() const;
180  void SetInvert(bool invert);
181  Real GetGamma() const;
182  void SetGamma(Real gamma);
183  void SetViewerMin(Real min);
185  void SetViewerMax(Real max);
187  void UpdateNormalizer(Real min, Real max, Real gamma, bool invert);
188  int GetSlab();
189  void SetSlab(int slab);
190  void SetSelectionMode(int mode);
192  void SetAntialiasing(bool f);
193  bool GetAntialiasing() const;
195  void SetOffset(const geom::Vec2& offset);
196 
197 
198 
199 signals:
200  void clicked(const geom::Vec3& mousepos);
201  void zoomed(int zoomlevel);
202  void selected(const Extent& selection);
203  void deselected();
204  void slabChanged(int slab);
205  void released(void);
206 
207 protected:
208  QMenu* popupmenu_;
209 
210 protected slots:
211  // slots for popup menu
213  void normalize();
214  void center();
218  void zoom_plus();
219  void zoom_minus();
220  void zoom_reset();
221  void slab_plus();
222  void slab_minus();
223  void slab_start();
224  void slab_end();
225  void slab_center();
229 
230 
231 private:
232  Real data_min_;
233  Real data_max_;
234  Point data_min_pos_;
235  Point data_max_pos_;
236  ViewerNormalizerPtr normalizer_;
237  QImage* image_;
238  QPixmap* pixmap_;
239  QRubberBand* rubberband_;
240  QPoint lastmouse_;
241  int zoom_level_;
242  bool update_raster_image_;
243  Real offset_x_, offset_y_;
244 
245  geom::Vec3 clicked_position_;
246  bool show_clicked_position_;
247 
248  Real zoom_scale_;
249  Real i_zoom_scale_;
250  int slab_;
251 
252  QCursor cursor_;
253  bool display_pixel_values_;
254  geom::Vec2 mouseposition_;
255 
256  int last_x_,last_y_;
257  int right_press_x_,right_press_y_;
258  Extent selection_;
259  int selection_mode_;
260 
261  RasterImage::Mode cmode_;
262  std::map<int, QCursor> cursors_;
263 
264  bool use_update_extent_;
265  Extent update_extent_;
266  bool fast_low_mag_;
267  bool fast_high_mag_;
268 
269  bool antialiasing_;
270  Point drag_start_;
271  QAction* phase_toggle_action_;
272  QAction* invert_toggle_action_;
273  QAction* show_click_pos_toggle_action_;
274  QAction* fast_low_mag_toggle_action_;
275  QAction* fast_high_mag_toggle_action_;
276  QAction* display_pixel_toggle_action_;
277  QAction* antialiasing_toggle_action_;
278 
279 
280  void move(int dx, int dy);
281  void slab(int dz);
282  void zoom(int d);
283  void extract_ri();
284 
285  void draw_extent(QPainter& p);
286  void draw_pixel_values(QPainter& p);
287  void update_min_max();
288  void update_rubberband_from_selection_();
289 };
290 
291 }}} //ns
292 
293 #endif
294 
Three dimensional vector class, using Real precision.
Definition: vec3.hh:48
Abstract base class of data observer.
Defines lower and upper valid indices.
Definition: extent.hh:60
Manage shared instances of images.
class encapsulating 1D to 3D point
Definition: point.hh:47
QPoint PointToWin(const Point &p) const
convert image point to window coordinates
QPoint FracPointToWinCenter(const geom::Vec2 &p) const
convert fractional image point to window coordinates (center of point)
QPoint FracPointToWin(const geom::Vec2 &p) const
convert fractional image point to window coordinates (top left corner of point)
Real GetZoomScale() const
retrieve the zoomscale
void SetCursor(const QCursor &c)
set cursor
Point WinToPoint(const QPoint &p) const
virtual void mouseReleaseEvent(QMouseEvent *event)
ImageHandle Extract(const Extent &e)
virtual void paintEvent(QPaintEvent *event)
geom::Vec2 WinToFracPointCenter(int mx, int my) const
Extent GetSelection() const
return currently active selection
virtual void mousePressEvent(QMouseEvent *event)
virtual void ObserverUpdate()
called upon data change, noop by default
virtual void SetData(const ImageHandle &d)
virtual void mouseMoveEvent(QMouseEvent *event)
geom::Vec2 WinToFracPoint(int mx, int my) const
void SetDefaultCursor(const QCursor &c)
set default cursor
void UpdateView(bool update_raster_image=true)
update view
bool IsWithin(const QPoint &p) const
checks if given point is visible in current panel
void Renormalize()
do a renormalization with the current normalizer
void Recenter()
re-center with spatial origin in the middle of the window
virtual void keyPressEvent(QKeyEvent *event)
void UpdateView(const QRect &rect, bool update_raster_image=true)
void SetColorMode(RasterImage::Mode m)
set coloring mode to either greyscale or phasecolor
void selected(const Extent &selection)
void SetZoomScale(Real zoom)
set the zoomscale
virtual void ObserverUpdate(const Extent &e)
special update, calls ObserverUpdate() by default
virtual void ObserverUpdate(const Point &p)
special update, calls ObserverUpdate() by default
void UpdateNormalizer(Real min, Real max, Real gamma, bool invert)
void SetDisplayPixelValues(bool show)
set display pixelvalues
void SetOffset(const geom::Vec2 &offset)
geom::Vec3 GetPixelSampling()
retrieve the pixel sampling of the image
Point WinToPoint(int mx, int my) const
convert window coordinates to image point
virtual void ObserverRelease()
Called if data is released from memory.
DataViewerPanelBase(const ImageHandle &data, QWidget *parent)
virtual void resizeEvent(QResizeEvent *event)
Extent GetExtent()
retrieve the extent of the image
ViewerNormalizerPtr GetNormalizer() const
retrieve ptr to internal normalizer
void MoveTo(const geom::Vec2 &p)
void SetFastLowMagnificationDrawing(bool flag)
set/get fast drawing modes for low and high magnification
void clicked(const geom::Vec3 &mousepos)
void SetFastHighMagnificationDrawing(bool flag)
virtual void wheelEvent(QWheelEvent *event)
geom::Vec2 WinToFracPointCenter(const QPoint &p) const
geom::Vec2 WinToFracPoint(const QPoint &p) const
convert window coordinates to fractional image point
void SetSelection(const Extent &extent)
set currently active selection
#define DLLEXPORT_OST_GUI
float Real
Definition: base.hh:44
boost::shared_ptr< ViewerNormalizer > ViewerNormalizerPtr
Definition: base.dox:1