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 #include <boost/shared_ptr.hpp>
30 
31 
32 
33 #include <ost/base.hh>
34 #include <ost/img/extent.hh>
37 
38 #include <ost/gui/module_config.hh>
40 
42 
43 #include <QWidget>
44 #include <QCursor>
45 #include <QMenu>
46 #include <QPen>
47 #include <QBrush>
48 #include <QRubberBand>
49 
50 namespace ost { namespace img { namespace gui {
51 
52 
53 class DLLEXPORT_OST_GUI DataViewerPanelBase: public QWidget,
54  public DataObserver
55 {
56  Q_OBJECT;
57 
58 public:
59  DataViewerPanelBase(const Data& data,QWidget* parent);
60  virtual ~DataViewerPanelBase();
61 
62  virtual void SetData(const Data& d);
63 
65  // event handling
66  virtual void paintEvent(QPaintEvent* event);
67  virtual void resizeEvent(QResizeEvent* event);
68  virtual void wheelEvent (QWheelEvent* event);
69  virtual void mousePressEvent(QMouseEvent* event);
70  virtual void mouseReleaseEvent(QMouseEvent* event);
71  virtual void mouseMoveEvent(QMouseEvent* event);
72  virtual void keyPressEvent(QKeyEvent * event);
73 
74  //void OnMenu(wxCommandEvent& e);
75  //void OnUpdateMenu(wxUpdateUIEvent& e);
76 
78  // observer interface
79  virtual void ObserverUpdate();
80  virtual void ObserverUpdate(const Extent& e);
81  virtual void ObserverUpdate(const Point& p);
82  virtual void ObserverRelease();
83 
85  // other methods
86 
88  void UpdateView(bool update_raster_image=true);
89  void UpdateView(const QRect& rect,bool update_raster_image=true);
90 
92  ViewerNormalizerPtr GetNormalizer() const;
93 
95  void Renormalize();
96 
97 
99 
102  Extent GetSelection() const;
103 
105  void SetSelection(const Extent& extent);
106 
108  Point WinToPoint(int mx, int my) const;
109  Point WinToPoint(const QPoint& p) const;
110 
112  geom::Vec2 WinToFracPoint(const QPoint& p) const;
113  geom::Vec2 WinToFracPoint(int mx, int my) const;
114  geom::Vec2 WinToFracPointCenter(const QPoint& p) const;
115  geom::Vec2 WinToFracPointCenter(int mx, int my) const;
116 
118  QPoint PointToWin(const Point& p) const;
120  QPoint FracPointToWin(const geom::Vec2& p) const;
122  QPoint FracPointToWinCenter(const geom::Vec2& p) const;
123 
125  bool IsWithin(const QPoint& p) const;
126 
128  Real GetZoomScale() const;
129 
131  void SetZoomScale(Real zoom);
132 
134  Extent GetExtent();
135 
137  geom::Vec3 GetPixelSampling();
138 
139 
141  void SetDefaultCursor(const QCursor& c);
142  void SetDefaultCursor(int id);
143 
145  void SetCursor(const QCursor& c);
146  void SetCursor(int id);
147 
149  void SetDisplayPixelValues(bool show);
150  bool GetDisplayPixelValues(){return display_pixel_values_;};
151 
153  void Recenter();
154 
155 
157  // other methods
159  void SetColorMode(RasterImage::Mode m);
160  RasterImage::Mode GetColorMode(){return cmode_;};
161 
163  void SetFastLowMagnificationDrawing(bool flag){fast_low_mag_=flag;UpdateView();}
164  bool GetFastLowMagnificationDrawing(){return fast_low_mag_;}
165  void SetFastHighMagnificationDrawing(bool flag){fast_high_mag_=flag;UpdateView();}
166  bool GetFastHighMagnificationDrawing(){return fast_high_mag_;}
167 
168  geom::Vec2 GetMousePosition(){return mouseposition_;};
169  void MoveTo(const geom::Vec2& p);
170  ImageHandle Extract(const Extent& e);
171  void HideClickedPosition();
172  void ShowClickedPosition(bool show);
173  bool ClickedPositionIsVisible();
174  bool HasSelection();
175  geom::Vec3 GetClickedPosition();
176  Real GetDataMin() const;
177  Real GetDataMax() const;
178  bool GetInvert() const;
179  void SetInvert(bool invert);
180  Real GetGamma() const;
181  void SetGamma(Real gamma);
182  void SetViewerMin(Real min);
183  Real GetViewerMin() const;
184  void SetViewerMax(Real max);
185  Real GetViewerMax() const;
186  void UpdateNormalizer(Real min, Real max, Real gamma, bool invert);
187  int GetSlab();
188  void SetSlab(int slab);
189  void SetSelectionMode(int mode);
190  int GetSelectionMode();
191  void SetAntialiasing(bool f);
192  bool GetAntialiasing() const;
193  geom::Vec2 GetOffset() const;
194  void SetOffset(const geom::Vec2& offset);
195 
196 
197 
198 signals:
199  void clicked(const geom::Vec3& mousepos);
200  void zoomed(int zoomlevel);
201  void selected(const Extent& selection);
202  void deselected();
203  void slabChanged(int slab);
204  void released(void);
205 
206 protected:
207  QMenu* popupmenu_;
208 
209 private:
210  Real data_min_;
211  Real data_max_;
212  Point data_min_pos_;
213  Point data_max_pos_;
214  ViewerNormalizerPtr normalizer_;
215  QImage* image_;
216  QPixmap* pixmap_;
217  QRubberBand* rubberband_;
218  QPoint lastmouse_;
219  int zoom_level_;
220  bool update_raster_image_;
221  Real offset_x_, offset_y_;
222 
223  geom::Vec3 clicked_position_;
224  bool show_clicked_position_;
225 
226  Real zoom_scale_;
227  Real i_zoom_scale_;
228  int slab_;
229 
230  QCursor cursor_;
231  bool display_pixel_values_;
232  geom::Vec2 mouseposition_;
233 
234  int last_x_,last_y_;
235  int right_press_x_,right_press_y_;
236  Extent selection_;
237  int selection_mode_;
238 
239  RasterImage::Mode cmode_;
240  std::map<int, QCursor> cursors_;
241 
242  bool use_update_extent_;
243  Extent update_extent_;
244  bool fast_low_mag_;
245  bool fast_high_mag_;
246 
247  bool antialiasing_;
248 
249  void move(int dx, int dy);
250  void slab(int dz);
251  void zoom(int d);
252  void extract_ri();
253 
254  void draw_extent(QPainter& p);
255  void draw_pixel_values(QPainter& p);
256  void update_min_max();
257  void update_rubberband_from_selection_();
258 };
259 
260 }}} //ns
261 
262 #endif
263