00001
00008 #ifndef TRANSFERFUNCTIONWIDGET_H
00009 #define TRANSFERFUNCTIONWIDGET_H
00010
00011 #include <wx/wx.h>
00012 #include <vector>
00013 #include <fstream>
00014 #include "Color4.h"
00015 #include "MathCommon.h"
00016 #include "TransferTexture.h"
00017
00018 class TransferFunctionPlot;
00019
00025 class TransferPlotChangeListner
00026 {
00027 public:
00028
00034 virtual void TransferPlotChanged(TransferFunctionPlot *plot) = 0;
00035 };
00036
00042 class TransferFunctionPlot : public wxWindow
00043 {
00044 public:
00045
00051 TransferFunctionPlot(wxWindow *parent);
00052
00056 ~TransferFunctionPlot();
00057
00062 enum PlotMode
00063 {
00064 MOVE = 0,
00065 ADD,
00066 REMOVE,
00067
00068 NUMBER_OF_MODES
00069 };
00070
00076 void SetPlotMode(PlotMode m);
00077
00081 void ResetPlot();
00082
00088 void DelayRealtimeUpdate(bool v) { delayUpdates = v; }
00089
00095 void DrawAll(bool b);
00096
00102 void DrawHistogram(bool b);
00103
00107 void MakeRedActive();
00108
00112 void MakeGreenActive();
00113
00117 void MakeBlueActive();
00118
00122 void MakeAlphaActive();
00123
00129 void OnPaint(wxPaintEvent &e);
00130
00136 void MouseMove(wxMouseEvent &m);
00137
00143 void MouseLeftUp(wxMouseEvent &m);
00144
00150 void MouseLeftDown(wxMouseEvent &m);
00151
00157 void MouseWheel(wxMouseEvent &m);
00158
00164 void MouseLeave(wxMouseEvent &m);
00165
00171 void SetListner(TransferPlotChangeListner *l);
00172
00178 void UpdateTexture(TransferTexture *tex);
00179
00185 void Load(const char *file);
00186
00192 void Save(const char *file);
00193
00197 void RefreshListner();
00198
00204 void SetHistogram(const unsigned int *h);
00205
00206 protected:
00207
00215 void DrawPlot(wxPaintDC &dc, const std::vector<PlotPoint> &plot, const Color4f &color) const;
00216
00224 void DrawPlotPoints(wxPaintDC &dc, const std::vector<PlotPoint> &plot, const Color4f &color) const;
00225
00233 void PlotPointToScreen(const PlotPoint &p, int &x, int &y) const;
00234
00242 void ScreenToPlotPoint(int x, int y, PlotPoint &p) const;
00243
00251 int PlotDataValueToXCoord(int dataValue) const;
00252
00260 int PlotValueToYCoord(float value) const;
00261
00271 bool SelectPoint(wxCoord x, wxCoord y);
00272
00282 int SelectPoint(wxCoord x, wxCoord y, const std::vector<PlotPoint> &plot) const;
00283
00290 void AddPoint(wxCoord x, wxCoord y);
00291
00298 void RemovePoint(wxCoord x, wxCoord y);
00299
00309 bool LoadPlot(std::ifstream &file, std::vector<PlotPoint> &plot, int n);
00310
00317 void SavePlot(std::ofstream &file, const std::vector<PlotPoint> &plot);
00318
00319 std::vector<PlotPoint> redPlot;
00320 std::vector<PlotPoint> greenPlot;
00321 std::vector<PlotPoint> bluePlot;
00322 std::vector<PlotPoint> alphaPlot;
00323
00324 bool delayUpdates;
00325 bool drawHistogram;
00326 bool drawAll;
00327
00328 int currDataValue;
00329 float currValue;
00330
00331 PlotMode mode;
00332
00333 int selectedPoint;
00334 std::vector<PlotPoint> *activePlot;
00335 Color4f activePlotColor;
00336 bool mouseDown;
00337
00338 wxBitmap bgGrid;
00339 wxBitmap histogram;
00340
00341 TransferPlotChangeListner *listner;
00342
00343 DECLARE_EVENT_TABLE()
00344 };
00345
00351 class TransferFunctionWidget : public wxWindow
00352 {
00353 public:
00354
00360 TransferFunctionWidget(wxWindow *parent);
00361
00365 ~TransferFunctionWidget();
00366
00372 void DelayRealtimeUpdate(bool v) { plot->DelayRealtimeUpdate(v); }
00373
00379 void OnDrawAllClick(wxCommandEvent &e);
00380
00386 void OnDrawHistogramClick(wxCommandEvent &e);
00387
00393 void OnActivePlotSelection(wxCommandEvent &e);
00394
00400 void OnPlotModeSelection(wxCommandEvent &e);
00401
00407 void OnSaveClick(wxCommandEvent &e);
00408
00414 void OnLoadClick(wxCommandEvent &e);
00415
00421 void OnRefreshClick(wxCommandEvent &e);
00422
00428 void OnResetClick(wxCommandEvent &e);
00429
00435 void SetHistogram(const unsigned int *h) { plot->SetHistogram(h); }
00436
00442 void SetListner(TransferPlotChangeListner *l) { plot->SetListner(l); }
00443
00444 protected:
00445
00446 TransferFunctionPlot *plot;
00447
00448 wxCheckBox *drawAll;
00449 wxCheckBox *drawHistogram;
00450
00451 DECLARE_EVENT_TABLE()
00452 };
00453
00454 #endif