00001 #ifndef TRAFUCTRL_H
00002 #define TRAFUCTRL_H
00003
00004 #include <wx/control.h>
00005 #include <wx/panel.h>
00006 #include <wx/dcbuffer.h>
00007
00008 #include "trafupoint.h"
00009 #include "trafu_ctrl_event.h"
00010 #include "histogramdata.h"
00011 #include "trafu_data.h"
00012
00013 #include <list>
00014 #include <vector>
00015
00016
00017 class TraFuData;
00018
00020 class TransferFunctionCtrlCanvas : public wxControl
00021 {
00022 DECLARE_DYNAMIC_CLASS(TransferFunctionCtrlCanvas)
00023 DECLARE_EVENT_TABLE()
00024
00025 public:
00027 TransferFunctionCtrlCanvas() { Init(); }
00028
00030 TransferFunctionCtrlCanvas(wxWindow* parent,
00031 wxWindowID id,
00032 const wxPoint& pos = wxDefaultPosition,
00033 const wxSize& size = wxDefaultSize,
00034 long style = 0)
00035 {
00036 Init();
00037 Create(parent, id, pos, size, style);
00038 }
00039
00041 ~TransferFunctionCtrlCanvas()
00042 {
00043 }
00044
00046 void SetTraFuDataPointer(TraFuData *data);
00047
00049 bool Create(wxWindow* parent,
00050 wxWindowID id,
00051 const wxPoint& pos = wxDefaultPosition,
00052 const wxSize& size = wxDefaultSize,
00053 long style = wxSUNKEN_BORDER);
00054
00056 wxSize DoGetBestSize() const { return wxSize(650, 200); }
00057
00059 int GetCanvasHeight() { return GetClientRect().GetHeight() - this->m_colour_range_height + 1; }
00060
00062 int GetCanvasWidth() { return GetClientRect().GetWidth(); }
00063
00065 wxSize GetCanvasSize() const { return GetClientRect().GetSize() - wxSize(0, this->m_colour_range_height); }
00066
00068 void SetHistogramData(const HistogramData *histogramdata);
00069
00070 private:
00072 void SetMoving(Mapping_point_iterator_t target, bool holding);
00073
00075 void Init();
00076
00078 void NotifyChange();
00079
00081 void SetPointPosition(Mapping_point_iterator_t point, const wxPoint &pos);
00082
00084 Mapping_point_iterator_t GetHitPoint(const wxPoint &pos);
00085
00087 bool PointContains(Mapping_point_iterator_t point, const wxPoint &pos);
00088
00090 wxPoint GetPosition(const Mapping_point_iterator_t &point)
00091 {
00092 return wxPoint(point->m_density * GetCanvasWidth(), (1 - point->m_opacity) * GetCanvasHeight());
00093 }
00094
00096 void SetPosition(Mapping_point_iterator_t &point, const wxPoint &new_pos)
00097 {
00098 point->m_density = Density(new_pos);
00099 point->m_opacity = Opacity(new_pos);
00100 }
00101
00103 void SetColour(Mapping_point_t &point, const wxColor &new_color)
00104 {
00105 point.m_colour = tfRGB(new_color.Red(), new_color.Green(), new_color.Blue());
00106 }
00107
00109 wxColor GetColour(Mapping_point_t &point)
00110 {
00111 return wxColour(point.m_colour.red, point.m_colour.green, point.m_colour.blue);
00112 }
00113
00115 void SetRGB(Mapping_point_iterator_t &point, const tfRGB &colour)
00116 {
00117 point->m_colour = colour;
00118 }
00119
00121 tfRGB GetRGB(Mapping_point_iterator_t &point)
00122 {
00123 return point->m_colour;
00124 }
00125
00127 float Density(const wxPoint &pos)
00128 {
00129 return static_cast<float>(pos.x) / GetCanvasWidth();
00130 }
00131
00133 float Opacity(const wxPoint &pos)
00134 {
00135 return 1 - static_cast<float>(pos.y) / GetCanvasHeight();
00136 }
00137
00139 void AddNewPoint(const wxPoint &pos);
00140
00142 void AddNewPoint(const wxPoint &pos, const wxColour &colour);
00143
00145 void DeletePoint(Mapping_point_iterator_t target);
00146
00148 void DrawPoints(wxDC *dc);
00149
00151 void DrawHist(wxDC *dc);
00152
00154 void DrawRange(wxDC *dc);
00155
00156 int m_colour_range_height;
00157 int m_button_radius;
00158 TraFuData *m_points;
00159 Mapping_point_iterator_t m_active_point;
00160 const HistogramData *m_hist_data;
00161
00162 protected:
00165 void OnPaint(wxPaintEvent& event);
00166 void OnMouseEvent(wxMouseEvent& event);
00167 void OnSize(wxSizeEvent &event);
00169 };
00170
00171 #endif // TRAFUCTRL_H