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
00032
00033 #include <ost/base.hh>
00034 #include <ost/img/extent.hh>
00035 #include <ost/img/data_observer.hh>
00036 #include <ost/img/normalizer_impl.hh>
00037 #include <ost/img/raster_image/raster_image.hh>
00038
00039 #include <ost/gui/module_config.hh>
00040 #include <ost/gui/data_viewer/viewer_normalizer.hh>
00041
00042 #include <ost/img/normalizer_impl.hh>
00043
00044 #include <QWidget>
00045 #include <QCursor>
00046 #include <QMenu>
00047 #include <QPen>
00048 #include <QBrush>
00049 #include <QRubberBand>
00050
00051 namespace ost { namespace img { namespace gui {
00052
00053
00054 class DLLEXPORT_OST_GUI DataViewerPanelBase: public QWidget,
00055 public DataObserver
00056 {
00057 Q_OBJECT;
00058
00059 public:
00060 DataViewerPanelBase(const ImageHandle& data,QWidget* parent);
00061 virtual ~DataViewerPanelBase();
00062
00063 virtual void SetData(const ImageHandle& d);
00064
00066
00067 virtual void paintEvent(QPaintEvent* event);
00068 virtual void resizeEvent(QResizeEvent* event);
00069 virtual void wheelEvent (QWheelEvent* event);
00070 virtual void mousePressEvent(QMouseEvent* event);
00071 virtual void mouseReleaseEvent(QMouseEvent* event);
00072 virtual void mouseMoveEvent(QMouseEvent* event);
00073 virtual void keyPressEvent(QKeyEvent * event);
00074
00075
00077
00078 virtual void ObserverUpdate();
00079 virtual void ObserverUpdate(const Extent& e);
00080 virtual void ObserverUpdate(const Point& p);
00081 virtual void ObserverRelease();
00082
00084
00085
00087 void UpdateView(bool update_raster_image=true);
00088 void UpdateView(const QRect& rect,bool update_raster_image=true);
00089
00091 ViewerNormalizerPtr GetNormalizer() const;
00092
00094 void Renormalize();
00095
00096
00098
00101 Extent GetSelection() const;
00102
00104 void SetSelection(const Extent& extent);
00105
00107 Point WinToPoint(int mx, int my) const;
00108 Point WinToPoint(const QPoint& p) const;
00109
00111 geom::Vec2 WinToFracPoint(const QPoint& p) const;
00112 geom::Vec2 WinToFracPoint(int mx, int my) const;
00113 geom::Vec2 WinToFracPointCenter(const QPoint& p) const;
00114 geom::Vec2 WinToFracPointCenter(int mx, int my) const;
00115
00117 QPoint PointToWin(const Point& p) const;
00119 QPoint FracPointToWin(const geom::Vec2& p) const;
00121 QPoint FracPointToWinCenter(const geom::Vec2& p) const;
00122
00124 bool IsWithin(const QPoint& p) const;
00125
00127 Real GetZoomScale() const;
00128
00130 void SetZoomScale(Real zoom);
00131
00133 Extent GetExtent();
00134
00136 geom::Vec3 GetPixelSampling();
00137
00138
00140 void SetDefaultCursor(const QCursor& c);
00141 void SetDefaultCursor(int id);
00142
00144 void SetCursor(const QCursor& c);
00145 void SetCursor(int id);
00146
00148 void SetDisplayPixelValues(bool show);
00149 bool GetDisplayPixelValues(){return display_pixel_values_;};
00150
00152 void Recenter();
00153
00154
00156
00158 void SetColorMode(RasterImage::Mode m);
00159 RasterImage::Mode GetColorMode(){return cmode_;};
00160
00162 void SetFastLowMagnificationDrawing(bool flag);
00163 bool GetFastLowMagnificationDrawing();
00164 void SetFastHighMagnificationDrawing(bool flag);
00165 bool GetFastHighMagnificationDrawing();
00166
00167 geom::Vec2 GetMousePosition(){return mouseposition_;};
00168 void MoveTo(const geom::Vec2& p);
00169 ImageHandle Extract(const Extent& e);
00170 void HideClickedPosition();
00171 void ShowClickedPosition(bool show);
00172 bool ClickedPositionIsVisible();
00173 bool HasSelection();
00174 geom::Vec3 GetClickedPosition();
00175 Real GetDataMin() const;
00176 Real GetDataMax() const;
00177 bool GetInvert() const;
00178 void SetInvert(bool invert);
00179 Real GetGamma() const;
00180 void SetGamma(Real gamma);
00181 void SetViewerMin(Real min);
00182 Real GetViewerMin() const;
00183 void SetViewerMax(Real max);
00184 Real GetViewerMax() const;
00185 void UpdateNormalizer(Real min, Real max, Real gamma, bool invert);
00186 int GetSlab();
00187 void SetSlab(int slab);
00188 void SetSelectionMode(int mode);
00189 int GetSelectionMode();
00190 void SetAntialiasing(bool f);
00191 bool GetAntialiasing() const;
00192 geom::Vec2 GetOffset() const;
00193 void SetOffset(const geom::Vec2& offset);
00194
00195
00196
00197 signals:
00198 void clicked(const geom::Vec3& mousepos);
00199 void zoomed(int zoomlevel);
00200 void selected(const Extent& selection);
00201 void deselected();
00202 void slabChanged(int slab);
00203 void released(void);
00204
00205 protected:
00206 QMenu* popupmenu_;
00207
00208 protected slots:
00209
00210 void toggle_phase_color();
00211 void normalize();
00212 void center();
00213 void toggle_invert();
00214 void toggle_display_pixels();
00215 void toggle_show_click_pos();
00216 void zoom_plus();
00217 void zoom_minus();
00218 void zoom_reset();
00219 void slab_plus();
00220 void slab_minus();
00221 void slab_start();
00222 void slab_end();
00223 void slab_center();
00224 void toggle_fast_low_mag();
00225 void toggle_fast_high_mag();
00226 void toggle_antialiasing();
00227
00228
00229 private:
00230 Real data_min_;
00231 Real data_max_;
00232 Point data_min_pos_;
00233 Point data_max_pos_;
00234 ViewerNormalizerPtr normalizer_;
00235 QImage* image_;
00236 QPixmap* pixmap_;
00237 QRubberBand* rubberband_;
00238 QPoint lastmouse_;
00239 int zoom_level_;
00240 bool update_raster_image_;
00241 Real offset_x_, offset_y_;
00242
00243 geom::Vec3 clicked_position_;
00244 bool show_clicked_position_;
00245
00246 Real zoom_scale_;
00247 Real i_zoom_scale_;
00248 int slab_;
00249
00250 QCursor cursor_;
00251 bool display_pixel_values_;
00252 geom::Vec2 mouseposition_;
00253
00254 int last_x_,last_y_;
00255 int right_press_x_,right_press_y_;
00256 Extent selection_;
00257 int selection_mode_;
00258
00259 RasterImage::Mode cmode_;
00260 std::map<int, QCursor> cursors_;
00261
00262 bool use_update_extent_;
00263 Extent update_extent_;
00264 bool fast_low_mag_;
00265 bool fast_high_mag_;
00266
00267 bool antialiasing_;
00268 Point drag_start_;
00269 QAction* phase_toggle_action_;
00270 QAction* invert_toggle_action_;
00271 QAction* show_click_pos_toggle_action_;
00272 QAction* fast_low_mag_toggle_action_;
00273 QAction* fast_high_mag_toggle_action_;
00274 QAction* display_pixel_toggle_action_;
00275 QAction* antialiasing_toggle_action_;
00276
00277
00278 void move(int dx, int dy);
00279 void slab(int dz);
00280 void zoom(int d);
00281 void extract_ri();
00282
00283 void draw_extent(QPainter& p);
00284 void draw_pixel_values(QPainter& p);
00285 void update_min_max();
00286 void update_rubberband_from_selection_();
00287 };
00288
00289 }}}
00290
00291 #endif
00292