00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef DATA_VIEWER_PANEL_BASE_HH_
00026 #define DATA_VIEWER_PANEL_BASE_HH_
00027
00028 #include <map>
00029 #include <boost/shared_ptr.hpp>
00030
00031 #include <QWidget>
00032 #include <QCursor>
00033 #include <QMenu>
00034 #include <QPen>
00035 #include <QBrush>
00036 #include <QRubberBand>
00037
00038
00039 #include <ost/base.hh>
00040 #include <ost/img/extent.hh>
00041 #include <ost/img/normalizer_impl.hh>
00042 #include <ost/img/raster_image/raster_image.hh>
00043
00044 #include <ost/gui/module_config.hh>
00045 #include <ost/gui/data_viewer/viewer_normalizer.hh>
00046
00047 #include <ost/img/normalizer_impl.hh>
00048
00049
00050 namespace ost { namespace img { namespace gui {
00051
00052
00053 class DLLEXPORT_OST_GUI DataViewerPanelBase: public QWidget,
00054 public DataObserver
00055 {
00056 Q_OBJECT;
00057
00058 public:
00059 DataViewerPanelBase(const Data& data,QWidget* parent);
00060 virtual ~DataViewerPanelBase();
00061
00062 void SetData(const Data& d);
00063
00065
00066 virtual void paintEvent(QPaintEvent* event);
00067 virtual void resizeEvent(QResizeEvent* event);
00068 virtual void wheelEvent (QWheelEvent* event);
00069 virtual void mousePressEvent(QMouseEvent* event);
00070 virtual void mouseReleaseEvent(QMouseEvent* event);
00071 virtual void mouseMoveEvent(QMouseEvent* event);
00072 virtual void keyPressEvent(QKeyEvent * event);
00073
00074
00075
00076
00078
00079 virtual void ObserverUpdate();
00080 virtual void ObserverUpdate(const Extent& e);
00081 virtual void ObserverUpdate(const Point& p);
00082 virtual void ObserverRelease();
00083
00085
00086
00088 void UpdateView(bool update_raster_image=true);
00089
00091 ViewerNormalizerPtr GetNormalizer() const;
00092
00094 void Renormalize();
00095
00096
00098
00101 Extent GetSelection() const;
00102
00104 Point WinToPoint(int mx, int my) const;
00105 Point WinToPoint(const QPoint& p) const;
00106
00108 geom::Vec2 WinToFracPoint(const QPoint& p) const;
00109 geom::Vec2 WinToFracPoint(int mx, int my) const;
00110 geom::Vec2 WinToFracPointCenter(const QPoint& p) const;
00111 geom::Vec2 WinToFracPointCenter(int mx, int my) const;
00112
00114 QPoint PointToWin(const Point& p) const;
00116 QPoint FracPointToWin(const geom::Vec2& p) const;
00118 QPoint FracPointToWinCenter(const geom::Vec2& p) const;
00119
00121 bool IsWithin(const QPoint& p) const;
00122
00124 Real GetZoomScale() const;
00125
00127 void SetZoomScale(Real zoom);
00128
00130 Extent GetExtent();
00131
00133 geom::Vec3 GetPixelSampling();
00134
00135
00137 void SetDefaultCursor(const QCursor& c);
00138 void SetDefaultCursor(int id);
00139
00141 void SetCursor(const QCursor& c);
00142 void SetCursor(int id);
00143
00145 void SetDisplayPixelValues(bool show);
00146 bool GetDisplayPixelValues(){return display_pixel_values_;};
00147
00149 void Recenter();
00150
00152 void CenterSelection();
00153
00155
00157 void SetColorMode(RasterImage::Mode m);
00158 RasterImage::Mode GetColorMode(){return cmode_;};
00159
00161 void SetFastLowMagnificationDrawing(bool flag){fast_low_mag_=flag;UpdateView();}
00162 bool GetFastLowMagnificationDrawing(){return fast_low_mag_;}
00163 void SetFastHighMagnificationDrawing(bool flag){fast_high_mag_=flag;UpdateView();}
00164 bool GetFastHighMagnificationDrawing(){return fast_high_mag_;}
00165
00166 geom::Vec2 GetMousePosition(){return mouseposition_;};
00167 void MoveTo(const geom::Vec2& p);
00168 ImageHandle Extract(const Extent& e);
00169 void HideClickedPosition();
00170 void ShowClickedPosition(bool show);
00171 bool ClickedPositionIsVisible();
00172 bool HasSelection();
00173 geom::Vec3 GetClickedPosition();
00174 Real GetDataMin() const;
00175 Real GetDataMax() const;
00176 bool GetInvert() const;
00177 void SetInvert(bool invert);
00178 void UpdateNormalizer(Real min, Real max, Real gamma, bool invert);
00179 int GetSlab();
00180 void SetSlab(int slab);
00181 void SetSelectionMode(int mode);
00182 int GetSelectionMode();
00183 void SetAntialiasing(bool f);
00184 bool GetAntialiasing() const;
00185
00186 signals:
00187 void clicked(const geom::Vec3& mousepos);
00188 void zoomed(int zoomlevel);
00189 void selected(const Extent& selection);
00190 void deselected();
00191 void slabChanged(int slab);
00192 void released(void);
00193
00194 protected:
00195 QMenu* popupmenu_;
00196
00197 private:
00198 Real data_min_;
00199 Real data_max_;
00200 Point data_min_pos_;
00201 Point data_max_pos_;
00202 ViewerNormalizerPtr normalizer_;
00203 QImage* image_;
00204 QPixmap* pixmap_;
00205 QPoint lastmouse_;
00206 int zoom_level_;
00207 bool update_raster_image_;
00208
00209 Real center_x_, center_y_;
00210 Real offset_x_, offset_y_;
00211
00212 geom::Vec3 clicked_position_;
00213 bool show_clicked_position_;
00214
00215 Real zoom_scale_;
00216 Real i_zoom_scale_;
00217 int slab_;
00218
00219 QCursor cursor_;
00220 bool display_pixel_values_;
00221 geom::Vec2 mouseposition_;
00222
00223 int last_x_,last_y_;
00224 int right_press_x_,right_press_y_;
00225 bool selection_dragging_;
00226 QRect selection_rect_;
00227 Extent selection_;
00228 QPen selection_pen_;
00229 QBrush selection_brush_;
00230 bool selection_state_;
00231 int selection_mode_;
00232
00233 RasterImage::Mode cmode_;
00234 std::map<int, QCursor> cursors_;
00235
00236 bool use_update_extent_;
00237 Extent update_extent_;
00238 bool fast_low_mag_;
00239 bool fast_high_mag_;
00240
00241 bool antialiasing_;
00242
00243 void move(int dx, int dy);
00244 void slab(int dz);
00245 void zoom(int d);
00246 void on_resize(int w, int h);
00247 void extract_ri();
00248
00249 void draw_extent(QPainter& p);
00250 void draw_pixel_values(QPainter& p);
00251 void set_clippingregion(QPainter& p);
00252 void update_min_max();
00253 };
00254
00255 }}}
00256
00257 #endif
00258