00001 #ifndef FLOWVIS_CANVAS_H
00002 #define FLOWVIS_CANVAS_H
00003
00004 #include <wx/glcanvas.h>
00005 #include <wx/colour.h>
00006
00007 #include <memory>
00008 #include <vector>
00009
00010 #include "flowvis_data.h"
00011 #include "flowvis_program.h"
00012 #include "streamlines.h"
00013
00015 class TransferFunctionSampler {
00016 public:
00018 struct Color {
00019 float r, g, b, a;
00020 };
00021
00023
00026 virtual Color MapDensity(float density) = 0;
00027 };
00028
00029 namespace
00030 {
00032 float AngleR(vec3 velocity)
00033 {
00034 float pi = 3.14159265f;
00035
00036 vec3 basic(0, 1);
00037
00038
00039 velocity[2] = 0;
00040 velocity = !velocity;
00041 float radians = acos(basic * velocity) / (basic.length() * velocity.length());
00042
00043 if(velocity[0] < 0)
00044 {
00045 radians = (2 * pi) - radians;
00046 }
00047
00048 return radians;
00049 }
00050
00052 float Angle(vec3 velocity)
00053 {
00054 return 180 / 3.14159265f * AngleR(velocity);
00055 }
00056 }
00057
00059 struct ArrowPoint
00060 {
00062 ArrowPoint(float pos_x, float pos_y, vec3 velocity)
00063 : x(pos_x)
00064 , y(pos_y)
00065 {
00066 length = velocity.length();
00067 rotation = Angle(velocity);
00068 }
00069
00070 float x;
00071
00072 float y;
00073
00074 float rotation;
00075
00076 float length;
00077 };
00078
00079 typedef std::vector<ArrowPoint> ArrowPoints_T;
00080
00082 struct F_RGB
00083 {
00085
00086 float red;
00087 float green;
00088 float blue;
00090
00092 F_RGB operator =(const wxColor &color)
00093 {
00094 red = static_cast<float>(color.Red()) / 255.0f;
00095 green = static_cast<float>(color.Green()) / 255.0f;
00096 blue = static_cast<float>(color.Blue()) / 255.0f;
00097
00098 return *this;
00099 }
00100 };
00101
00103 struct StreamlinePlotSettings
00104 {
00105 bool plot;
00106 F_RGB color;
00107 bool plot_tapering;
00108 bool plot_glyphs;
00109 int glyph_density;
00110 GLuint glyph_texture;
00111 };
00112
00114 struct StreamlineAlgSettings
00115 {
00116 float stepsize;
00117 float dsep;
00118 float dtest;
00119 SLIterAlg interploation;
00120 int maxiter;
00121 };
00122
00124 struct Arrows
00125 {
00127 Arrows()
00128 : plot(false)
00129 , nr_x(0)
00130 , nr_y(0)
00131 , arrow_texture(-1)
00132 {
00133 }
00134
00136 ArrowPoints_T arrow_points;
00137
00138 bool plot;
00139 int nr_x;
00140 int nr_y;
00141 GLuint arrow_texture;
00142 };
00143
00145 class FlowVisCanvas : public wxGLCanvas
00146 {
00147 public:
00149 enum RenderMode_E
00150 {
00151 FVC_SCREEN,
00152 FVC_VALUE_INTER,
00153 FVC_ARROW_INTER
00154 };
00155
00157 FlowVisCanvas(wxWindow *parent, wxWindowID id = wxID_ANY);
00158
00160 ~FlowVisCanvas() { SetCurrent(); }
00161
00163 void SetData(std::auto_ptr<FlowVisData> data);
00164
00166 void SetBackgroundSet(int set_nr);
00167
00169 void UpdateTransferFunction(TransferFunctionSampler *sampler, int set_to_update);
00170
00173 void LoadArrowTexture();
00174
00177 void LoadGlyphTexture();
00178
00180 void SetArrows(int x, int y);
00181
00184 void SetArrowPlot(bool plot_arrows);
00185 void SetStreamlinePlot(bool plot_streamlines);
00186 void SetBackgroundPlot(bool plot_background);
00188
00191 void SetLineColor(wxColour new_color);
00192 void SetLineTapering(bool plot_tapering);
00193 void SetLineGlyphs(bool plot_glyphs);
00194 void SetGlyphDensity(int new_density);
00196
00199 void SetDsep(float dsep);
00200 void SetDtest(float dtest);
00201 void SetIntegType(int integ_index);
00202 void SetMaxIter(int maxiter);
00203 void SetStepSize(float step_size);
00205
00207 void Prepare_Streamlines();
00208
00210 void RenderToFile(const wxString& file_name, int width, int height);
00211
00213 RenderMode_E m_mode;
00214
00215 protected:
00218
00220 void OnPaint(wxPaintEvent &event );
00221
00223 void OnSize(wxSizeEvent &event);
00224
00226 void OnEraseBackground(wxEraseEvent &event);
00227
00229
00230 private:
00231 DECLARE_EVENT_TABLE()
00232
00233
00234 void Render();
00235
00238 void Render_Background();
00239 void Render_Arrows();
00240 void Render_ToScreen();
00241 void Render_ValueInter(int set);
00242 void Render_ArrowInter();
00243 void Render_Streamlines();
00245
00247 bool InitGL();
00248
00250 bool CheckGL();
00251
00253 void InitTextures();
00254
00256 void CreateEvenlySpacedArrows();
00257
00259 enum GLStatus {
00260 GLS_INIT_PENDING,
00261 GLS_INIT_FAILED,
00262 GLS_OK
00263 };
00264
00265 GLStatus m_glstatus;
00266 std::auto_ptr<FlowVisData> m_data;
00267 std::auto_ptr<FlowVisProgram> m_program;
00268
00269 std::vector<GLuint> m_tex_background;
00270 std::vector<GLuint> m_tex_bg_trafu;
00271 int m_background_set;
00272 GLint m_viewport_width;
00273 GLint m_viewport_height;
00274
00275 std::vector<Streamline> m_streamlines;
00276 bool m_plot_background;
00277
00278 StreamlinePlotSettings m_sl_settings;
00279 StreamlineAlgSettings m_sl_algorithm;
00280
00281 float m_line_base_thickness;
00282
00283 Arrows m_arrow_data;
00284 };
00285
00286 #endif // FLOWVIS_CANVAS_H