OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2011 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);
63  virtual ~DataViewerPanelBase();
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 
93  ViewerNormalizerPtr GetNormalizer() const;
94 
96  void Renormalize();
97 
98 
100 
103  Extent GetSelection() const;
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 
129  Real GetZoomScale() const;
130 
132  void SetZoomScale(Real zoom);
133 
135  Extent GetExtent();
136 
138  geom::Vec3 GetPixelSampling();
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
160  void SetColorMode(RasterImage::Mode m);
161  RasterImage::Mode GetColorMode(){return cmode_;};
162 
164  void SetFastLowMagnificationDrawing(bool flag);
165  bool GetFastLowMagnificationDrawing();
166  void SetFastHighMagnificationDrawing(bool flag);
167  bool GetFastHighMagnificationDrawing();
168 
169  geom::Vec2 GetMousePosition(){return mouseposition_;};
170  void MoveTo(const geom::Vec2& p);
171  ImageHandle Extract(const Extent& e);
172  void HideClickedPosition();
173  void ShowClickedPosition(bool show);
174  bool ClickedPositionIsVisible();
175  bool HasSelection();
176  geom::Vec3 GetClickedPosition();
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);
184  Real GetViewerMin() const;
185  void SetViewerMax(Real max);
186  Real GetViewerMax() const;
187  void UpdateNormalizer(Real min, Real max, Real gamma, bool invert);
188  int GetSlab();
189  void SetSlab(int slab);
190  void SetSelectionMode(int mode);
191  int GetSelectionMode();
192  void SetAntialiasing(bool f);
193  bool GetAntialiasing() const;
194  geom::Vec2 GetOffset() 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
212  void toggle_phase_color();
213  void normalize();
214  void center();
215  void toggle_invert();
216  void toggle_display_pixels();
217  void toggle_show_click_pos();
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();
226  void toggle_fast_low_mag();
227  void toggle_fast_high_mag();
228  void toggle_antialiasing();
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 
float Real
Definition: base.hh:44
boost::shared_ptr< ViewerNormalizer > ViewerNormalizerPtr
#define DLLEXPORT_OST_GUI
T Extract(const info::InfoGroup &g, const String &n)
Convenience function to extract a value from an item.
Definition: info_item.hh:128
Mode
coloring mode
Definition: raster_image.hh:64
Defines lower and upper valid indices.
Definition: extent.hh:60
Three dimensional vector class, using Real precision.
Definition: vec3.hh:42
Abstract base class of data observer.
Manage shared instances of images.
class encapsulating 1D to 3D point
Definition: point.hh:43