00001 #ifndef VOLUME_CANVAS_H
00002 #define VOLUME_CANVAS_H
00003
00004 #include <glew.h>
00005 #include <wx/glcanvas.h>
00006 #include <memory>
00007 #include "volprogram.h"
00008 #include "histogramdata.h"
00009
00011 class TransferFunctionSampler {
00012 public:
00014 struct Color {
00015 float r, g, b, a;
00016 };
00017
00019
00022 virtual Color MapDensity(float density) = 0;
00023 };
00024
00026 enum Viewmode {
00027 VM_3D,
00028 VM_SLICE_X,
00029 VM_SLICE_Y,
00030 VM_SLICE_Z
00031 };
00032
00034 class VolumeCanvas: public wxGLCanvas {
00035 public:
00036 VolumeCanvas(wxWindow *parent, wxWindowID id = wxID_ANY);
00037
00038 ~VolumeCanvas()
00039 {
00040 SetCurrent();
00041 delete m_volprog;
00042 }
00043
00046 void OpenFile(const char *filename);
00047
00049 Viewmode GetViewmode() const
00050 {
00051 return m_viewmode;
00052 }
00053
00055 void SetViewmode(Viewmode viewmode)
00056 {
00057 m_viewmode = viewmode;
00058 }
00059
00061 int GetSizeX() const
00062 {
00063 return m_sizex;
00064 }
00065
00067 int GetSizeY() const
00068 {
00069 return m_sizey;
00070 }
00071
00073 int GetSizeZ() const
00074 {
00075 return m_sizez;
00076 }
00077
00079 void SetSlice(int value)
00080 {
00081 m_slice = value;
00082 }
00083
00085 int GetSlice() const
00086 {
00087 return m_slice;
00088 }
00089
00091 void Set3dOrientation(float rx, float ry, float rz)
00092 {
00093 m_rotx = rx;
00094 m_roty = ry;
00095 m_rotz = rz;
00096 }
00097
00099 void Get3dOrientation(float* rx, float* ry, float* rz)
00100 {
00101 *rx = m_rotx;
00102 *ry = m_roty;
00103 *rz = m_rotz;
00104 }
00105
00107 const HistogramData *GetHistogramData() const
00108 {
00109 return m_histogramdata.get();
00110 }
00111
00112 void UpdateTransferFunction(TransferFunctionSampler *sampler);
00113
00114 void RenderToFile(const wxString & file_name, int width, int height);
00115
00116 protected:
00119
00121 void OnPaint(wxPaintEvent &);
00122
00124 void OnSize(wxSizeEvent &);
00125
00127 void OnEraseBackground(wxEraseEvent &);
00128
00130
00131 private:
00132 DECLARE_EVENT_TABLE()
00133
00134
00135 enum GLStatus {
00136 GLS_INIT_PENDING,
00137 GLS_INIT_FAILED,
00138 GLS_OK
00139 };
00140
00141 GLStatus m_glstatus;
00142 GLuint m_volume_texture;
00143 GLuint m_transfer_texture;
00144 VolProgram *m_volprog;
00145
00146 GLint m_viewport_width;
00147 GLint m_viewport_height;
00148
00149 Viewmode m_viewmode;
00150
00153 int m_sizex;
00154 int m_sizey;
00155 int m_sizez;
00156 int m_slice;
00158
00161 float m_rotx, m_roty, m_rotz;
00163
00164 std::auto_ptr<HistogramData> m_histogramdata;
00165
00167 void Render() const;
00168
00170 void Render3dView() const;
00171
00173 void RenderSliceView() const;
00174
00176 bool InitGL();
00177
00179 bool CheckGL();
00180 };
00181
00182 #endif