diff options
author | Wilrik de Loose <wilrik@wilrik.nl> | 2007-12-14 12:24:12 (GMT) |
---|---|---|
committer | Wilrik de Loose <wilrik@wilrik.nl> | 2007-12-14 12:24:12 (GMT) |
commit | dbc6530ef4b5a5ce4284b0cb32e2f61677b47b18 (patch) | |
tree | a5f54b566e9c4b7fe34edb7ef0a271fa56bb8d2b | |
parent | 9aaa000d79789033ea531c7d2c140fee1283305c (diff) | |
download | 2iv35-dbc6530ef4b5a5ce4284b0cb32e2f61677b47b18.zip 2iv35-dbc6530ef4b5a5ce4284b0cb32e2f61677b47b18.tar.gz 2iv35-dbc6530ef4b5a5ce4284b0cb32e2f61677b47b18.tar.bz2 |
-rw-r--r-- | Smoke/Week 2.ncb | bin | 15518720 -> 15518720 bytes | |||
-rw-r--r-- | Smoke/Week 2.suo | bin | 28672 -> 44032 bytes | |||
-rw-r--r-- | Smoke/Week 2.vcproj | 16 | ||||
-rw-r--r-- | Smoke/fluids.c | 201 | ||||
-rw-r--r-- | Smoke/fluids.h | 291 | ||||
-rw-r--r-- | Smoke/funcs.c | 6 | ||||
-rw-r--r-- | Smoke/funcs.h | 14 | ||||
-rw-r--r-- | Smoke/glyphs.c | 31 | ||||
-rw-r--r-- | Smoke/gtk.c | 72 | ||||
-rw-r--r-- | Smoke/seedpoint.c | 15 | ||||
-rw-r--r-- | Smoke/seedpoint.h | 3 |
11 files changed, 288 insertions, 361 deletions
diff --git a/Smoke/Week 2.ncb b/Smoke/Week 2.ncb Binary files differindex 99fd4a7..cc88001 100644 --- a/Smoke/Week 2.ncb +++ b/Smoke/Week 2.ncb diff --git a/Smoke/Week 2.suo b/Smoke/Week 2.suo Binary files differindex 0058556..18403e8 100644 --- a/Smoke/Week 2.suo +++ b/Smoke/Week 2.suo diff --git a/Smoke/Week 2.vcproj b/Smoke/Week 2.vcproj index 261e15c..ae9e5b5 100644 --- a/Smoke/Week 2.vcproj +++ b/Smoke/Week 2.vcproj @@ -187,6 +187,10 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
>
<File
+ RelativePath=".\colormap.c"
+ >
+ </File>
+ <File
RelativePath="fftw-2.1.3\fftw\config.c"
>
</File>
@@ -751,6 +755,10 @@ >
</File>
<File
+ RelativePath=".\streamlines.c"
+ >
+ </File>
+ <File
RelativePath="fftw-2.1.3\fftw\timer.c"
>
</File>
@@ -772,6 +780,10 @@ Filter="h;hpp;hxx;hm;inl;inc"
>
<File
+ RelativePath=".\colormap.h"
+ >
+ </File>
+ <File
RelativePath="fftw-2.1.3\fftw\config.h"
>
</File>
@@ -807,6 +819,10 @@ RelativePath=".\seedpoint.h"
>
</File>
+ <File
+ RelativePath=".\streamlines.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
diff --git a/Smoke/fluids.c b/Smoke/fluids.c index e9756df..8832a3a 100644 --- a/Smoke/fluids.c +++ b/Smoke/fluids.c @@ -11,8 +11,10 @@ #include <stdio.h> #include "fluids.h" +#include "colormap.h" #include "glyphs.h" #include "seedpoint.h" +#include "streamlines.h" #include "funcs.h" //--- SIMULATION PARAMETERS ------------------------------------------------------------------------ @@ -36,7 +38,6 @@ int draw_smoke = 0; //draw the smoke or not int draw_vecs = 1; //draw the vector field or not int scalar_col = 0; //method for scalar coloring int frozen = 0; //toggles on/off the animation -int olivers_color = 256; float clamp_min = 0; float clamp_max = 0.9999f; int autoscale = FALSE; @@ -52,7 +53,7 @@ int glyph_vector = VECTOR_VEL; int glyph_sort = GLYPH_CYLINDERS; int draw_options = FALSE; GLuint startList; -float threshold1 = 1.8f; +float threshold1 = 0.2f; float threshold2 = 2.0f; int isolines_nr = 1; int prev_mx = 0; @@ -75,20 +76,21 @@ float zPos = -725.0f; //------ SIMULATION CODE STARTS HERE ----------------------------------------------------------------- + //init_simulation: Initialize simulation data structures as a function of the grid size 'n'. // Although the simulation takes place on a 2D grid, we allocate all data structures as 1D arrays, // for compatibility with the FFTW numerical library. void init_simulation(int n) { float LightAmbient[] = { 0.25f, 0.25f, 0.25f, 1.0f }; // Ambient light values - float LightPosition[] = { 0.0f, 0.0f, -900.0f, 1.0f }; // Position of the light source + float LightPosition[] = { 0.0f, 0.0f, -700.0f, 1.0f }; // Position of the light source int i; size_t dim; dim = n * 2*(n/2+1)*sizeof(fftw_real); //Allocate data structures - vx = (fftw_real*) malloc(dim); - vy = (fftw_real*) malloc(dim); - vx0 = (fftw_real*) malloc(dim); - vy0 = (fftw_real*) malloc(dim); + vx = (fftw_real*) malloc(dim); + vy = (fftw_real*) malloc(dim); + vx0 = (fftw_real*) malloc(dim); + vy0 = (fftw_real*) malloc(dim); dim = n * n * sizeof(fftw_real); fx = (fftw_real*) malloc(dim); fy = (fftw_real*) malloc(dim); @@ -96,8 +98,9 @@ void init_simulation(int n) rho0 = (fftw_real*) malloc(dim); plan_rc = rfftw2d_create_plan(n, n, FFTW_REAL_TO_COMPLEX, FFTW_IN_PLACE); plan_cr = rfftw2d_create_plan(n, n, FFTW_COMPLEX_TO_REAL, FFTW_IN_PLACE); + hight_array = (fftw_real*) malloc(dim); - frame_hist = (int*) malloc(n * sizeof(int *)); + frame_hist = (int*) malloc(n * sizeof(int *)); for (i = 0; i <= n; i++) { @@ -116,7 +119,7 @@ void init_simulation(int n) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_DEPTH_TEST); - glEnable(GL_LIGHTING); + //glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); @@ -250,10 +253,10 @@ void calculate_hight_plot(void) switch (vis_dataset) { case DATASET_FORCE: - hight_array[i] = sqrt(fx[i] * fx[i] + fy[i] * fy[i]) * 100; + hight_array[i] = quake_root(fx[i] * fx[i] + fy[i] * fy[i]) * 100; break; case DATASET_VEL: - hight_array[i] = sqrt(vx[i] * vx[i] + vy[i] * vy[i]) * 2000; + hight_array[i] = quake_root(vx[i] * vx[i] + vy[i] * vy[i]) * 2000; break; case DATASET_RHO: hight_array[i] = rho[i] * 10; @@ -305,44 +308,6 @@ void calculate_one_simulation_step(void) //------ VISUALIZATION CODE STARTS HERE ----------------------------------------------------------------- - -//rainbow: Implements a color palette, mapping the scalar 'value' to a rainbow color RGB -void rainbow(float value,float* R,float* G,float* B) -{ - const float dx=0.8f; - if (value<0) value=0; if (value>1) value=1; - value = (6-2*dx)*value+dx; - *R = (float)max(0.0f,(3-fabs(value-4.0f)-fabs(value-5.0f))/2.0f); - *G = (float)max(0.0f,(4-fabs(value-2.0f)-fabs(value-4.0f))/2.0f); - *B = (float)max(0.0f,(3-fabs(value-1.0f)-fabs(value-2.0f))/2.0f); -} - - -void colormap_fire(float value,float* R,float* G,float* B) -{ - /* Colormap Fire - * A fire effect deals with two parts, first a drop from red to yellow (halfway) - * during which time the Red component remains full e.g. 1. The Green component is - * slowly added to turn the red into orange, and then yellow (R & G =Y). After this - * point, the Red and Green component (e.g. yellow) have to drop simulataniously - * to go from yellow down to black. - */ - *B = 0; - *G = 0; - *R = 0; - - if (value <= (0.01)) { - /* whilst value is 0 - 0.5 both red and green equally change to create yellow*/ - *R = *G = value; - } else { - /* whilst value is 0.5 - 1 Red is always fully on while the Green component is - * added in steps to go from red to orange to yellow. - */ - *G = 0.9f - value; - *R = 0.8f; // not 1, makes red deeper, more intense - } -} - float remap(float value) { value -= scale_min; @@ -351,73 +316,6 @@ float remap(float value) return value; } -//set_colormap: Sets three different types of colormaps -struct color4f set_colormap(float vy, int draw_bar, float alpha) -{ - float R, G, B; - struct color4f return_value; - - if (autoscale) - { - vy = remap(vy); - } - - if (!(draw_bar)) - { - if (vy < clamp_min) vy = clamp_min; - if (vy > clamp_max) vy = clamp_max; - } else { - - } - - vy *= olivers_color; - vy = (float)(int)(vy); - vy /= olivers_color; - - if (scalar_col==COLOR_BLUE_GREEN_RED) { - if (vy < -0.1) { - R = G = 0; - vy -= -0.1; - vy /= 0.9; - B = -vy; - } else if (vy < 0.1) { - R = B = 0; - vy += 0.1; - vy /= 0.2; - G = vy; - } else { - vy -= 0.1; - vy /= 0.9; - R = vy; - G = B = 0; - } - } else if (scalar_col==COLOR_BLACKWHITE) { - R = G = B = vy; - } - else if (scalar_col==COLOR_WILRIK) { - colormap_fire(vy, &R, &G, &B); - } - else if (scalar_col==COLOR_OLIVER) { - rainbow(vy,&R,&G,&B); - } - else if (scalar_col==COLOR_RAINBOW) - rainbow(vy,&R,&G,&B); - else if (scalar_col==COLOR_BANDS) - { - const int NLEVELS = 7; - vy *= NLEVELS; vy = (float)(int)(vy); vy/= NLEVELS; - rainbow(vy,&R,&G,&B); - } - - glColor4f(R,G,B,alpha); - - return_value.r = R; - return_value.g = G; - return_value.b = B; - return_value.a = alpha; - return return_value; -} - //direction_to_color: Set the current color by mapping a direction vector (x,y), using // the color mapping method 'method'. If method==1, map the vector direction @@ -463,10 +361,10 @@ float get_dataset(int index) switch (vis_dataset) { case DATASET_FORCE: - return_value = (float)sqrt((fx[index] * fx[index]) + (fy[index] * fy[index])); + return_value = (float)quake_root((fx[index] * fx[index]) + (fy[index] * fy[index])); break; case DATASET_VEL: - return_value = (float)sqrt((vx[index] * vx[index]) + (vy[index] * vy[index])); + return_value = (float)quake_root((vx[index] * vx[index]) + (vy[index] * vy[index])); break; case DATASET_RHO: default: @@ -502,7 +400,7 @@ void set_autoscaling(void) if (scale_max < value) { scale_max = value; } } - //rho_threshold = (scale_min + scale_max) / 2; + //threshold = (scale_min + scale_max) / 2; } #define percentage(a, b) (min(a, b) / max(a, b)) @@ -532,7 +430,7 @@ void draw_isolines(float threshold) { state = 0; idx = (j * DIM) + i; - set_colormap(get_dataset(idx), 0, 1.0f); + set_colormap(scalar_col, get_dataset(idx), 0, 1.0f); v0 = get_dataset(idx + DIM); v1 = get_dataset(idx + 1 + DIM); @@ -623,7 +521,6 @@ void draw_isolines(float threshold) //visualize: This is the main visualization function void visualize(void) { - float dataset; static float fadein = 0; int i, j, idx; double px,py; fftw_real wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width @@ -633,18 +530,13 @@ void visualize(void) glTranslatef(xPos, yPos, zPos); - if (delay == 10) { - set_autoscaling(); - delay = 0; - } else delay++; - for (i = 0; i < winWidth; i++) { float value, clamp_scaled_min, clamp_scaled_max, scale_scaled_min, scale_scaled_max; value = (float)((float)i/winWidth); - set_colormap(value, TRUE, 1.0f); + set_colormap(scalar_col, value, TRUE, 1.0f); clamp_scaled_min = clamp_min *winWidth; clamp_scaled_max = clamp_max *winWidth; @@ -745,19 +637,19 @@ void visualize(void) px = wn + (fftw_real)i * wn; py = hn + (fftw_real)(j + 1) * hn; idx = ((j + 1) * DIM) + i; - set_colormap(get_dataset(idx), FALSE, 1.0f); + set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f); glVertex3f(px, py, hight_array[idx]); px = wn + (fftw_real)(i + 1) * wn; py = hn + (fftw_real)j * hn; idx = (j * DIM) + (i + 1); - set_colormap(get_dataset(idx), FALSE, 1.0f); + set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f); glVertex3f(px, py, hight_array[idx]); } px = wn + (fftw_real)(DIM - 1) * wn; py = hn + (fftw_real)(j + 1) * hn; idx = ((j + 1) * DIM) + (DIM - 1); - set_colormap(get_dataset(idx), FALSE, 1.0f); + set_colormap(scalar_col, get_dataset(idx), FALSE, 1.0f); glVertex3f(px, py, hight_array[idx]); glEnd(); } @@ -765,43 +657,7 @@ void visualize(void) draw_glyphs(); render_seedpoints(); - - /* Draw the options screen if enabled, hide otherwise */ - if (draw_options) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glBegin(GL_QUADS); - glColor4f(0, 0, 0, 0.2); - glVertex2d(40, 40); - glVertex2d(40, winHeight -40); - glVertex2d(winWidth -40, winHeight -40); - glVertex2d(winWidth -40, 40); - glEnd(); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glBegin(GL_QUADS); - glColor4f(0.9, 0.9, 0.9, 0.2); - glVertex2d(40, 40); - glVertex2d(40, winHeight -40); - glVertex2d(winWidth -40, winHeight -40); - glVertex2d(winWidth -40, 40); - glEnd(); - glBegin(GL_QUADS); - glColor3f(1, 1, 1); - glVertex2d(50, 50); - glVertex2d(50, 70); - glVertex2d(70, 70); - glVertex2d(70, 50); - glEnd(); - if (use_glyphs) { - glBegin(GL_LINES); - glVertex2d(50, 50); - glVertex2d(70, 70); - glVertex2d(50, 70); - glVertex2d(70, 50); - glEnd(); - } - } else { - fadein = 0; - } + render_streamlines(); } @@ -816,10 +672,10 @@ void keyboard(unsigned char key, int x, int y) case 't': dt -= 0.001; break; case 'T': dt += 0.001; break; case 'c': color_dir = (color_dir +1) %3; break; - case 'S': vec_scale *= 1.2; break; - case 's': vec_scale *= 0.8; break; - case 'V': visc *= 5; break; - case 'v': visc *= 0.2; break; + case 'S': vec_scale *= 1.2f; break; + case 's': vec_scale *= 0.8f; break; + case 'V': visc *= 5.0f; break; + case 'v': visc *= 0.2f; break; case 'y': toggle_glyph_usage(); break; case 'x': toggle_smoke_usage(); break; case 'm': scalar_col++; if (scalar_col>COLOR_OLIVER) scalar_col=COLOR_BLACKWHITE; break; @@ -906,7 +762,7 @@ void drag(int mx, int my) // Add force at the cursor location my = winHeight - my; dx = mx - lmx; dy = my - lmy; - len = sqrt(dx * dx + dy * dy); + len = vec_len(dx, dy); if (len != 0.0) { dx *= 0.1 / len; dy *= 0.1 / len; } fx[Y * DIM + X] += dx; fy[Y * DIM + X] += dy; @@ -946,7 +802,6 @@ void zoom_out(void) int get_glyph_usage(void) { return use_glyphs; } void selectColor(int arg) { scalar_col = arg; } -void selectOliverscolor(int arg) { olivers_color = arg; } void select_dataset(int arg) { vis_dataset = arg; } void toggle_autoscale(void) { autoscale = (autoscale) ? FALSE : TRUE ; } void toggle_clamping(void) { } diff --git a/Smoke/fluids.h b/Smoke/fluids.h index 19f775b..452f1c5 100644 --- a/Smoke/fluids.h +++ b/Smoke/fluids.h @@ -5,154 +5,145 @@ #include <GL/gl.h>
#include <GL/glu.h>
-//--- SIMULATION PARAMETERS ------------------------------------------------------------------------ - -extern const int DIM; //size of simulation grid -extern double dt; //simulation time step -extern float visc; //fluid viscosity -extern fftw_real *vx, *vy; //(vx,vy) = velocity field at the current moment -extern fftw_real *vx0, *vy0; //(vx0,vy0) = velocity field at the previous moment -extern fftw_real *fx, *fy; //(fx,fy) = user-controlled simulation forces, steered with the mouse -extern fftw_real *rho, *rho0; //smoke density at the current (rho) and previous (rho0) moment -extern rfftwnd_plan plan_rc, plan_cr; //simulation domain discretization - -//--- VISUALIZATION PARAMETERS --------------------------------------------------------------------- -#define DATASET_RHO 0 -#define DATASET_VEL 1 -#define DATASET_FORCE 2 -#define DATASET_DIVV 3 -#define DATASET_DIVF 4 - -#define COLOR_BLACKWHITE 0 -#define COLOR_RAINBOW 1 -#define COLOR_BANDS 2 -#define COLOR_BLUE_GREEN_RED 3 -#define COLOR_WILRIK 4 -#define COLOR_OLIVER 5 - -#define MOUSE_SMOKE 0 -#define MOUSE_SCALE_MIN 1 -#define MOUSE_SCALE_MAX 2 -#define MOUSE_CLAMP_MIN 3 -#define MOUSE_CLAMP_MAX 4 - -#define GLYPHS_OFF 0 -#define GLYPHS_ON 1 - -#define SCALAR_RHO 0 -#define SCALAR_VEL 1 -#define SCALAR_FORCE 2 - -#define VECTOR_VEL 0 -#define VECTOR_FORCE 1 - -#define GLYPH_ARROWS 0 -#define GLYPH_LINES 1 -#define GLYPH_CYLINDERS 2 -#define GLYPH_SPHERES 3 - -extern int winWidth, winHeight; //size of the graphics window, in pixels -extern int color_dir; //use direction color-coding or not -extern float vec_scale; //scaling of hedgehogs -extern int draw_smoke; //draw the smoke or not -extern int draw_vecs; //draw the vector field or not -extern int scalar_col; //method for scalar coloring -extern int frozen; //toggles on/off the animation -extern int olivers_color; -extern float clamp_min; -extern float clamp_max; -extern int autoscale; -extern float scale_min; -extern float scale_max; -extern int vis_dataset; -extern int mousebutton; -extern int mousebuttonstate; -extern int active_slider; -extern int use_glyphs; -extern int glyph_scalar; -extern int glyph_vector; -extern int draw_options; - -extern float xPos; -extern float yPos; -extern float zPos; - -void init_simulation(int n); - -void visualize(void); - -int rescale_to_winwidth(float value); - -void drag(int mx, int my); - -void click(int button, int state, int mx, int my); - -void keyboard(unsigned char key, int x, int y); - -void calculate_one_simulation_step(void); - -int get_glyph_usage(void); - -////////////////// - -void init_simulation(int n); -int rescale_to_winwidth(float value); -void FFT(int direction,void* vx); -int clamp(float x); -void solve(int n, fftw_real* vx, fftw_real* vy, fftw_real* vx0, fftw_real* vy0, fftw_real visc, fftw_real dt); -void diffuse_matter(int n, fftw_real *vx, fftw_real *vy, fftw_real *rho, fftw_real *rho0, fftw_real dt); -void set_forces(void); -void calculate_hight_plot(void); -void copy_frame(void); -void calculate_one_simulation_step(void); -void rainbow(float value,float* R,float* G,float* B); -void colormap_fire(float value,float* R,float* G,float* B); -float remap(float value); -struct color4f set_colormap(float vy, int draw_bar, float alpha); -void direction_to_color(float x, float y, int method); -float get_dataset(int index); -void set_autoscaling(void); -void draw_isolines(float threshold); -void visualize(void); -void keyboard(unsigned char key, int x, int y); -void click(int button, int state, int mx, int my); -void mouse_rotate(int mx, int my); -void drag(int mx, int my); - -////////////////// - -void zoom_in(void); -void zoom_out(void); -int get_glyph_usage(void); -void selectColor(int arg); -void selectOliverscolor(int arg); -void select_dataset(int arg); -void toggle_autoscale(void); -void toggle_clamping(void); -void show_options(void); -void toggle_glyph_usage(void); -void toggle_smoke_usage(void); -void toggle_mouse_rotate(void); -void toggle_seed_insert(void); -void set_glyph_scalar(int arg); -void set_glyph_vector(int arg); - -int get_var_dims(void); -void set_var_dims(int); -int get_glyph_sort(void); -void set_glyph_sort(int sort); - -struct point { - float x; - float y; - float z; -}; - -struct color4f { - float r; - float g; - float b; - float a; -}; - +//--- SIMULATION PARAMETERS ------------------------------------------------------------------------
+
+extern const int DIM; //size of simulation grid
+extern double dt; //simulation time step
+extern float visc; //fluid viscosity
+extern fftw_real *vx, *vy; //(vx,vy) = velocity field at the current moment
+extern fftw_real *vx0, *vy0; //(vx0,vy0) = velocity field at the previous moment
+extern fftw_real *fx, *fy; //(fx,fy) = user-controlled simulation forces, steered with the mouse
+extern fftw_real *rho, *rho0; //smoke density at the current (rho) and previous (rho0) moment
+extern rfftwnd_plan plan_rc, plan_cr; //simulation domain discretization
+extern fftw_real *hight_array; //used for hight plot +extern int *frame_hist; +extern int frame_index;
+
+//--- VISUALIZATION PARAMETERS ---------------------------------------------------------------------
+#define DATASET_RHO 0
+#define DATASET_VEL 1
+#define DATASET_FORCE 2
+#define DATASET_DIVV 3
+#define DATASET_DIVF 4
+
+#define COLOR_BLACKWHITE 0
+#define COLOR_RAINBOW 1
+#define COLOR_BANDS 2
+#define COLOR_BLUE_GREEN_RED 3
+#define COLOR_WILRIK 4
+#define COLOR_OLIVER 5
+
+#define MOUSE_SMOKE 0
+#define MOUSE_SCALE_MIN 1
+#define MOUSE_SCALE_MAX 2
+#define MOUSE_CLAMP_MIN 3
+#define MOUSE_CLAMP_MAX 4
+
+#define GLYPHS_OFF 0
+#define GLYPHS_ON 1
+
+#define SCALAR_RHO 0
+#define SCALAR_VEL 1
+#define SCALAR_FORCE 2
+
+#define VECTOR_VEL 0
+#define VECTOR_FORCE 1
+
+#define GLYPH_ARROWS 0
+#define GLYPH_LINES 1
+#define GLYPH_CYLINDERS 2
+#define GLYPH_SPHERES 3
+
+extern int winWidth, winHeight; //size of the graphics window, in pixels
+extern int color_dir; //use direction color-coding or not
+extern float vec_scale; //scaling of hedgehogs
+extern int draw_smoke; //draw the smoke or not
+extern int draw_vecs; //draw the vector field or not
+extern int scalar_col; //method for scalar coloring
+extern int frozen; //toggles on/off the animation
+extern float clamp_min;
+extern float clamp_max;
+extern int autoscale;
+extern float scale_min;
+extern float scale_max;
+extern int vis_dataset;
+extern int mousebutton;
+extern int mousebuttonstate;
+extern int active_slider;
+extern int use_glyphs;
+extern int glyph_scalar;
+extern int glyph_vector;
+extern int draw_options;
+
+extern float xPos;
+extern float yPos;
+extern float zPos;
+
+void init_simulation(int n);
+
+void visualize(void);
+
+int rescale_to_winwidth(float value);
+
+void drag(int mx, int my);
+
+void click(int button, int state, int mx, int my);
+
+void keyboard(unsigned char key, int x, int y);
+
+void calculate_one_simulation_step(void);
+
+int get_glyph_usage(void);
+
+//////////////////
+
+void init_simulation(int n);
+int rescale_to_winwidth(float value);
+void FFT(int direction,void* vx);
+int clamp(float x);
+void solve(int n, fftw_real* vx, fftw_real* vy, fftw_real* vx0, fftw_real* vy0, fftw_real visc, fftw_real dt);
+void diffuse_matter(int n, fftw_real *vx, fftw_real *vy, fftw_real *rho, fftw_real *rho0, fftw_real dt);
+void set_forces(void);
+void calculate_hight_plot(void);
+void copy_frame(void);
+void calculate_one_simulation_step(void);;
+float remap(float value);
+void direction_to_color(float x, float y, int method);
+float get_dataset(int index);
+void set_autoscaling(void);
+void draw_isolines(float threshold);
+void visualize(void);
+void keyboard(unsigned char key, int x, int y);
+void click(int button, int state, int mx, int my);
+void mouse_rotate(int mx, int my);
+void drag(int mx, int my);
+
+//////////////////
+
+void zoom_in(void);
+void zoom_out(void);
+int get_glyph_usage(void);
+void selectColor(int arg);
+void select_dataset(int arg);
+void toggle_autoscale(void);
+void toggle_clamping(void);
+void show_options(void);
+void toggle_glyph_usage(void);
+void toggle_smoke_usage(void);
+void toggle_mouse_rotate(void);
+void toggle_seed_insert(void);
+void set_glyph_scalar(int arg);
+void set_glyph_vector(int arg);
+
+int get_var_dims(void);
+void set_var_dims(int);
+int get_glyph_sort(void);
+void set_glyph_sort(int sort);
+
+struct point {
+ float x;
+ float y;
+ float z;
+};
+
#endif diff --git a/Smoke/funcs.c b/Smoke/funcs.c index eb8cc2d..e760c72 100644 --- a/Smoke/funcs.c +++ b/Smoke/funcs.c @@ -7,7 +7,7 @@ #include "funcs.h"
-float square_root(float number)
+float quake_root(float number)
{
long i;
float x, y;
@@ -25,5 +25,5 @@ float square_root(float number) float vec_len(float x, float y)
{
- return (square_root((x * x) + (y * y)));
-}
\ No newline at end of file + return (quake_root((x * x) + (y * y)));
+}
diff --git a/Smoke/funcs.h b/Smoke/funcs.h index f21011f..f5720a1 100644 --- a/Smoke/funcs.h +++ b/Smoke/funcs.h @@ -1,14 +1,14 @@ #ifndef _FUNCS_H
#define _FUNCS_H
- -#define max(a, b) (a > b ? a : b) -#define min(a, b) (a < b ? a : b) -#define round(x) (int)(x < 0 ? x - 0.5 : x + 0.5) - -#define FALSE 0 +
+#define max(a, b) (a > b ? a : b)
+#define min(a, b) (a < b ? a : b)
+#define round(x) (int)(x < 0 ? x - 0.5 : x + 0.5)
+
+#define FALSE 0
#define TRUE !FALSE
-float square_root(float number);
+float quake_root(float number);
float vec_len(float x, float y);
#endif
diff --git a/Smoke/glyphs.c b/Smoke/glyphs.c index 9dd2914..751179e 100644 --- a/Smoke/glyphs.c +++ b/Smoke/glyphs.c @@ -11,21 +11,21 @@ void render_glyph(float x_value, float y_value, float i, float j)
{
- float x0, y0, z0, x1, y1, z1, x_dev, y_dev, z_dev, size, length;
+ float x0, y0, z0, x1, y1, z1, x_dev, y_dev, size, length;
float scale = (float)((float)DIM / (float)get_var_dims()) / 6;
double theta, in_prod;
- fftw_real wn, hn; - - GLuint startList = glGenLists(1); - GLUquadricObj *qobj = gluNewQuadric(); - - gluQuadricDrawStyle(qobj, GLU_FILL); - gluQuadricNormals(qobj, GLU_SMOOTH); - glNewList(startList, GL_COMPILE); - gluCylinder(qobj, 10, 0.2, 8, 8, 8); + fftw_real wn, hn;
+
+ GLuint startList = glGenLists(1);
+ GLUquadricObj *qobj = gluNewQuadric();
+
+ gluQuadricDrawStyle(qobj, GLU_FILL);
+ gluQuadricNormals(qobj, GLU_SMOOTH);
+ glNewList(startList, GL_COMPILE);
+ gluCylinder(qobj, 10, 0.2, 8, 8, 8);
glEndList();
- size = sqrt((x_value * x_value * 20) + (y_value * y_value * 20)) * 3 * scale;
+ size = quake_root((x_value * x_value * 20) + (y_value * y_value * 20)) * 3 * scale;
wn = (fftw_real)winWidth / (fftw_real)(get_var_dims() + 1); // Grid cell width
hn = (fftw_real)winHeight / (fftw_real)(get_var_dims() + 1); // Grid cell heigh
@@ -41,7 +41,7 @@ void render_glyph(float x_value, float y_value, float i, float j) // inner product
x_dev = x1 - x0;
y_dev = y1 - y0;
- length = sqrt(x_dev * x_dev + y_dev * y_dev);
+ length = quake_root(x_dev * x_dev + y_dev * y_dev);
x_dev = (length == 0) ? 0 : x_dev / length;
y_dev = (length == 0) ? 1 : y_dev / length;
@@ -79,7 +79,7 @@ void render_glyph(float x_value, float y_value, float i, float j) case GLYPH_CYLINDERS:
x_dev = x1 - x0;
y_dev = y1 - y0;
- length = sqrt(x_dev * x_dev + y_dev * y_dev) / 8;
+ length = quake_root(x_dev * x_dev + y_dev * y_dev) / 8;
glPushMatrix();
@@ -104,6 +104,9 @@ void render_glyph(float x_value, float y_value, float i, float j) glPopMatrix();
break;
}
+
+ gluDeleteQuadric(qobj);
+ glDeleteLists(startList, 1);
}
void draw_glyphs(void)
@@ -138,7 +141,7 @@ void draw_glyphs(void) break;
}
- set_colormap(value, FALSE, 0.5f);
+ set_colormap(scalar_col, value, FALSE, 0.5f);
switch (glyph_vector)
{
default:
diff --git a/Smoke/gtk.c b/Smoke/gtk.c index 724291e..8b8e8c5 100644 --- a/Smoke/gtk.c +++ b/Smoke/gtk.c @@ -48,6 +48,8 @@ #include <rfftw.h> //the numerical simulation FFTW library #include "fluids.h" +#include "seedpoint.h" + /************************************************************************** * The following section contains all the macro definitions. @@ -257,18 +259,18 @@ motion_notify_event (GtkWidget *widget, if (event->state & GDK_BUTTON1_MASK) { - g_print (" 1"); + //g_print (" 1"); drag((int)event->x, (int)event->y); } if (event->state & GDK_BUTTON2_MASK) { - g_print (" 2"); + //g_print (" 2"); } if (event->state & GDK_BUTTON3_MASK) { - g_print (" 3"); + //g_print (" 3"); } // g_print ("\n"); @@ -313,7 +315,7 @@ button_press_event (GtkWidget *widget, if (event->button == 1) { /*** Fill in the details here. ***/ - g_print ("button 1\n"); + //g_print ("button 1\n"); // fluids click(1, (event->type == GDK_BUTTON_PRESS) ? 0 : 1, (int)event->x, (int)event->y); // endf @@ -324,12 +326,12 @@ button_press_event (GtkWidget *widget, if (event->button == 2) { /*** Fill in the details here. ***/ - g_print ("button 2\n"); + //g_print ("button 2\n"); return TRUE; } - g_print ("\n"); + //g_print ("\n"); return FALSE; } @@ -340,11 +342,11 @@ button_press_event_popup_menu (GtkWidget *widget, GdkEventButton *event, gpointer data) { - g_print ("%s: \"button_press_event_popup\": ", gtk_widget_get_name (widget)); + //g_print ("%s: \"button_press_event_popup\": ", gtk_widget_get_name (widget)); if (event->button == 3) { - g_print ("button 3\n"); + //g_print ("button 3\n"); /* Popup menu. */ gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, @@ -352,7 +354,7 @@ button_press_event_popup_menu (GtkWidget *widget, return TRUE; } - g_print ("\n"); + //g_print ("\n"); return FALSE; } @@ -409,7 +411,7 @@ key_press_event (GtkWidget *widget, break; case GDK_m: - scalar_col++; if (scalar_col>COLOR_OLIVER) scalar_col=COLOR_BLACKWHITE; + scalar_col++; if (scalar_col > COLOR_OLIVER) scalar_col = COLOR_BLACKWHITE; break; case GDK_a: @@ -851,6 +853,47 @@ GtkWidget *create_height_plots_page(void) return page; } +GtkWidget *create_stream_tubes_page(void) +{ + int i, max; + GtkWidget *page; + GtkWidget *frame; + GtkWidget *box; + GtkWidget *button; + GtkWidget *combo; + GList *glist; + + glist = NULL; + + page = gtk_vbox_new(FALSE, 0); + + frame = gtk_frame_new("Seed points"); + + box = gtk_hbox_new(FALSE, 0); + + combo = gtk_combo_new(); + + max = get_cur_seedpoint(); + for (i = 0; i < max; i++) + { + glist = g_list_append(glist, strcat("Seedpoint ", (char *)i)); + } + + gtk_combo_set_popdown_strings (GTK_COMBO (combo), glist); + + gtk_box_pack_start(GTK_BOX(box), combo, FALSE, TRUE, 0); + gtk_widget_show(combo); + + gtk_container_add(GTK_CONTAINER(frame), box); + gtk_widget_show(box); + + gtk_box_pack_start(GTK_BOX(page), frame, FALSE, TRUE, 0); + + gtk_widget_show(frame); + + return page; +} + /*** *** Creates the simple application window with one *** drawing area that has an OpenGL-capable visual. @@ -1031,6 +1074,15 @@ create_window (GdkGLConfig *glconfig) gtk_notebook_append_page(GTK_NOTEBOOK(settings_notebook), notebook_page, notebook_page_label); + notebook_page_label = gtk_label_new("Stream tubes"); + gtk_widget_show(notebook_page_label); + + notebook_page = create_stream_tubes_page(); + gtk_container_add(GTK_CONTAINER(window), notebook_page); + gtk_widget_show(notebook_page); + + gtk_notebook_append_page(settings_notebook, notebook_page, notebook_page_label); + return window; } diff --git a/Smoke/seedpoint.c b/Smoke/seedpoint.c index c19da14..d285e84 100644 --- a/Smoke/seedpoint.c +++ b/Smoke/seedpoint.c @@ -5,10 +5,6 @@ #include <windows.h>
#endif
-#include <rfftw.h>
-#include <GL/gl.h>
-#include <GL/glu.h>
-
#include "fluids.h"
#include "seedpoint.h"
@@ -75,5 +71,16 @@ void render_seedpoints(void) }
gluDeleteQuadric(qobj);
+ glDeleteLists(lid, 1);
+
+}
+int get_cur_seedpoint(void)
+{
+ return cur_seedpoint;
}
+
+void set_cur_seedpoint(int seed_nr)
+{
+ cur_seedpoint = seed_nr;
+}
\ No newline at end of file diff --git a/Smoke/seedpoint.h b/Smoke/seedpoint.h index feb9545..0bbbf47 100644 --- a/Smoke/seedpoint.h +++ b/Smoke/seedpoint.h @@ -7,5 +7,8 @@ void create_seedpoint(float mx, float my); void delete_seedpoint(int seedpoint_nr);
void render_seedpoints(void);
+int get_cur_seedpoint(void);
+void set_cur_seedpoint(int seed_nr);
+
#endif
|