diff options
author | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-10 19:01:54 (GMT) |
---|---|---|
committer | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-10 19:01:54 (GMT) |
commit | a6166a87472ccac5b5dbf84b675041a5801f2579 (patch) | |
tree | 0d84ff32c7cc91d52957e5241c74cb9633aea57a /Smoke | |
parent | e54408d705bea4b154b78686ee1ac4daca2240ca (diff) | |
download | 2iv35-a6166a87472ccac5b5dbf84b675041a5801f2579.zip 2iv35-a6166a87472ccac5b5dbf84b675041a5801f2579.tar.gz 2iv35-a6166a87472ccac5b5dbf84b675041a5801f2579.tar.bz2 |
glyphs and history now use 'new' structure.
Diffstat (limited to 'Smoke')
-rw-r--r-- | Smoke/colormap.c | 22 | ||||
-rw-r--r-- | Smoke/fluids.c | 152 | ||||
-rw-r--r-- | Smoke/fluids.h | 18 | ||||
-rw-r--r-- | Smoke/glyphs.c | 21 | ||||
-rw-r--r-- | Smoke/glyphs.h | 61 | ||||
-rw-r--r-- | Smoke/gtk_colormap.c | 1 | ||||
-rw-r--r-- | Smoke/renderer_gl.c | 65 | ||||
-rwxr-xr-x | Smoke/smoke.bin | bin | 651630 -> 652505 bytes |
8 files changed, 161 insertions, 179 deletions
diff --git a/Smoke/colormap.c b/Smoke/colormap.c index c3a5c8f..c7b5f61 100644 --- a/Smoke/colormap.c +++ b/Smoke/colormap.c @@ -157,28 +157,6 @@ fftw_real *colormap_get_frame(void) } - -static void colormap_autoscale(void) -{ - if (colormap_autoscaling) { - int k, DIM; - float value, scale_min, scale_max; - - scale_min = scale_max = get_dataset(0); - colormap_scale_min = scale_min; - colormap_scale_max = scale_max; - DIM = fluids_get_dim(); - - for (k = 1; k < DIM * DIM; k++) - { - value = get_dataset(k); - - if (scale_min > value) { colormap_scale_min = value; } - if (scale_max < value) { colormap_scale_max = value; } - } - } -} - static float remap(float value) { value -= colormap_scale_min; diff --git a/Smoke/fluids.c b/Smoke/fluids.c index f1d5ea6..83463e7 100644 --- a/Smoke/fluids.c +++ b/Smoke/fluids.c @@ -58,16 +58,16 @@ static int fluids_hisdex = 0; // for compatibility with the FFTW numerical library. void fluids_init_simulation(int n, struct vis_data_arrays *vis_data) { - int i; size_t dim1, dim2; + int i; size_t dim1, dim2, dim; DIM = n; - - dim1 = n * 2*(n/2+1)*sizeof(fftw_real); //Allocate data structures + dim = n * 2 *(n / 2 + 1); + dim1 = dim *sizeof(fftw_real); //Allocate data structures vx = (fftw_real*) malloc(dim1); vy = (fftw_real*) malloc(dim1); vx0 = (fftw_real*) malloc(dim1); vy0 = (fftw_real*) malloc(dim1); - dim2 = n * n * sizeof(fftw_real); + dim2 = n * n * sizeof(fftw_real); fx = (fftw_real*) malloc(dim2); fy = (fftw_real*) malloc(dim2); rho = (fftw_real*) malloc(dim2); @@ -76,11 +76,12 @@ void fluids_init_simulation(int n, struct vis_data_arrays *vis_data) plan_cr = rfftw2d_create_plan(n, n, FFTW_COMPLEX_TO_REAL, FFTW_IN_PLACE); height_array = (fftw_real*) malloc(dim2); - normal_array = (struct point*) malloc(dim2 *sizeof(struct point *)); + normal_array = (struct point *)malloc(dim *sizeof(struct point)); for (i = 0; i < HISTORY_SIZE; i++) { -// vis_data->history[i] = (fftw_real *)malloc(dim1); + vis_data->history_frame[i] = (fftw_real *)malloc(dim1); + vis_data->history_scalars[i] = (struct fftw_real_xy *)malloc(dim *sizeof(struct fftw_real_xy)); } fluids_reset_simulation(); @@ -88,10 +89,11 @@ void fluids_init_simulation(int n, struct vis_data_arrays *vis_data) vis_data->rho = rho; vis_data->force = (fftw_real *)malloc(dim2); vis_data->vel = (fftw_real *)malloc(dim1); + vis_data->scalars = (struct fftw_real_xy *)malloc(dim *sizeof(struct fftw_real_xy)); vis_data->div_force = (fftw_real *)malloc(dim2); vis_data->div_vel = (fftw_real *)malloc(dim1); vis_data->height = (fftw_real *)malloc(dim2); - vis_data->normals = (struct point *)malloc(dim2 *sizeof(struct point *)); + vis_data->normals = (struct point *)malloc(dim *sizeof(struct point)); } void fluids_reset_simulation(void) { @@ -308,6 +310,7 @@ struct point calculate_normal_vector(fftw_real *height, int index, int i, int j) p3.y = py; p3.z = height[index + 1]; + return vector_normal(p1, p2, p3); } @@ -373,8 +376,27 @@ float par_der(float vp1, float v, fftw_real cell) return (vp1 - v / cell); } +struct fftw_real_xy_p get_scalar_frames(struct vis_data_arrays *vis_data, int dataset) +{ + struct fftw_real_xy_p return_value; + + switch(dataset) + { + default: + case DATASET_VEL: + return_value.x = vx; + return_value.y = vy; + break; + case DATASET_FORCE: + return_value.x = fx; + return_value.y = fy; + break; + } + + return return_value; +} -fftw_real *get_frame(struct vis_data_arrays *vis_data, int dataset) +fftw_real *get_vector_frame(struct vis_data_arrays *vis_data, int dataset) { fftw_real *return_value; @@ -383,38 +405,37 @@ fftw_real *get_frame(struct vis_data_arrays *vis_data, int dataset) default: case DATASET_RHO: return_value = vis_data->rho; - break; + break; case DATASET_VEL: - return_value = vis_data->vel; - break; + return_value = vis_data->vel; + break; case DATASET_FORCE: - return_value = vis_data->force; - break; + return_value = vis_data->force; + break; case DATASET_DIVV: - return_value = vis_data->div_vel; - break; + return_value = vis_data->div_vel; + break; case DATASET_DIVF: - return_value = vis_data->div_force; - break; + return_value = vis_data->div_force; + break; case DATASET_HIST: -// return_value = vis_data->history; - break; +// return_value = vis_data->history_frame; + break; } return return_value; } -void add_history_frame(int dataset, struct vis_data_arrays *vis_data) +void add_history_frames(struct vis_data_arrays *vis_data, int dataset) { fftw_real *frame; if (dataset != DATASET_HIST) { - frame = get_frame(vis_data, dataset); + frame = get_vector_frame(vis_data, dataset); -// memcpy(vis_data->history[fluids_hisdex], frame, DIM * 2 * (DIM / 2 + 1) * sizeof(fftw_real)); - fluids_hisdex = (fluids_hisdex >= HISTORY_SIZE -1) ? 0 : fluids_hisdex +1; + memcpy(vis_data->history_frame[fluids_hisdex], frame, DIM * 2 * (DIM / 2 + 1) * sizeof(fftw_real)); } } @@ -422,15 +443,23 @@ void add_history_frame(int dataset, struct vis_data_arrays *vis_data) void setup_arrays(struct vis_data_arrays *vis_data) { int idx, i, j; - float scale_min, scale_max, l, m; - fftw_real *frame; + float scale_min, scale_max; + fftw_real *frame_smoke, *frame_streamlines; + struct fftw_real_xy_p scalar_frames_glyphs, scalar_frames_streamlines; + int dataset; fftw_real wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width fftw_real hn = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell height - frame = get_frame(vis_data, smoke_get_dataset()); - scale_min = scale_max = frame[0]; + frame_smoke = get_vector_frame(vis_data, smoke_get_dataset()); + frame_streamlines = get_vector_frame(vis_data, streamlines_get_dataset()); + scale_min = scale_max = frame_smoke[0]; + + dataset = glyphs_get_dataset_direction(); + scalar_frames_glyphs = get_scalar_frames(vis_data, dataset); + dataset = streamlines_get_dataset(); + scalar_frames_streamlines = get_scalar_frames(vis_data, dataset); for (j = 0; j < DIM; j++) { @@ -441,14 +470,19 @@ void setup_arrays(struct vis_data_arrays *vis_data) vis_data->rho[idx] = rho[idx]; vis_data->vel[idx] = vec_len2f(vx[idx], vy[idx]); vis_data->force[idx] = vec_len2f(fx[idx], fy[idx]); + vis_data->scalars[idx].x = scalar_frames_glyphs.x[idx]; + vis_data->scalars[idx].y = scalar_frames_glyphs.y[idx]; vis_data->div_vel[idx] = par_der(vx[idx + 1], vx[idx], wn) + par_der(vy[idx + 1], vy[idx], wn); vis_data->div_force[idx] = par_der(fx[idx + 1], fx[idx], hn) + par_der(fy[idx + 1], fy[idx], hn); + vis_data->history_frame[fluids_hisdex][idx] = frame_streamlines[idx]; +// vis_data->history_scalars[fluids_hisdex].x[idx] = scalar_frames_streamlines.x[idx]; +// vis_data->history_scalars[fluids_hisdex].y[idx] = scalar_frames_streamlines.y[idx]; vis_data->height[idx] = calculate_height_plot(heightplots_get_dataset(), idx); - vis_data->normals[idx] = calculate_normal_vector(vis_data->height, idx, i, j); + // vis_data->normals[idx] = calculate_normal_vector(vis_data->height, idx, i, j); - if (frame[idx] < scale_min && frame[idx] > FLT_MIN) scale_min = frame[idx]; - if (frame[idx] > scale_max) scale_max = frame[idx]; + if (frame_smoke[idx] < scale_min && frame_smoke[idx] > FLT_MIN) scale_min = frame_smoke[idx]; + if (frame_smoke[idx] > scale_max) scale_max = frame_smoke[idx]; } } @@ -471,6 +505,7 @@ void fluids_calculate_one_simulation_step(struct vis_data_arrays *vis_data) { int dataset; fftw_real *frame; + struct fftw_real_xy_p scalar_frames; if (fluids_calculate) { set_forces(); @@ -478,60 +513,35 @@ void fluids_calculate_one_simulation_step(struct vis_data_arrays *vis_data) diffuse_matter(DIM, vx, vy, rho, rho0, dt); calculate_height_plots(); calculate_normal_vectors(); - add_history_frame(streamlines_get_dataset(), vis_data); + + fluids_hisdex = (fluids_hisdex >= HISTORY_SIZE -1) ? 0 : fluids_hisdex +1; } setup_arrays(vis_data); dataset = smoke_get_dataset(); - frame = get_frame(vis_data, dataset); + frame = get_vector_frame(vis_data, dataset); smoke_set_frame(frame); - dataset = glyphs_get_dataset_color(); - frame = get_frame(vis_data, dataset); - glyphs_set_frame(frame); - heightplots_set_frame(vis_data->height); normals_set_frame(vis_data->normals); -// streamlines_set_history(vis_data->history); -} -//------ VISUALIZATION CODE STARTS HERE ----------------------------------------------------------------- -float get_dataset(int index) -{ - fftw_real cell_x = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width - fftw_real cell_y = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell heigh - float return_value, par_der_x, par_der_y; - return_value = 0; + dataset = glyphs_get_dataset_color(); + frame = get_vector_frame(vis_data, dataset); + glyphs_set_frame_color(frame); - switch (vis_dataset) - { - case DATASET_FORCE: - return_value = vec_len2f(fx[index], fy[index]); - break; - case DATASET_VEL: - return_value = vec_len2f(vx[index], vy[index]); - break; - default: - case DATASET_RHO: - return_value = (float)rho[index]; - break; - case DATASET_DIVV: - par_der_x = (float)vx[index + 1] - (vx[index] / cell_x); - par_der_y = (float)vy[index + 1] - (vy[index] / cell_y); - return_value = (float)(par_der_x + par_der_y); - break; - case DATASET_DIVF: - par_der_x = (float)fx[index + 1] - (fx[index] / cell_x); - par_der_y = (float)fy[index + 1] - (fy[index] / cell_y); - return_value = (float)(par_der_x + par_der_y); - break; - } - - return return_value; -} + dataset = glyphs_get_dataset_direction(); + scalar_frames = get_scalar_frames(vis_data, dataset); + glyphs_set_frames_direction(scalar_frames); + + dataset = isolines_get_dataset(); + frame = get_vector_frame(vis_data, dataset); + isolines_set_frame(frame); + streamlines_set_history(vis_data->history_frame); +} +//------ VISUALIZATION CODE STARTS HERE ----------------------------------------------------------------- void fluids_insert_smoke(int x, int y) { int xi,yi,X,Y; double dx, dy, len; diff --git a/Smoke/fluids.h b/Smoke/fluids.h index d023f35..22bfa83 100644 --- a/Smoke/fluids.h +++ b/Smoke/fluids.h @@ -58,27 +58,27 @@ struct point2f { float y; }; -struct scalar_frame { - fftw_real *x; - fftw_real *y; +struct fftw_real_xy { + fftw_real x; + fftw_real y; }; -struct scalar_history { - fftw_real *x[HISTORY_SIZE]; - fftw_real *y[HISTORY_SIZE]; +struct fftw_real_xy_p { + fftw_real *x; + fftw_real *y; }; struct vis_data_arrays { fftw_real *rho; fftw_real *vel; fftw_real *force; - struct scalar_frame frame; + struct fftw_real_xy *scalars; fftw_real *div_vel; fftw_real *div_force; fftw_real *height; struct point *normals; - fftw_real *frame_history[HISTORY_SIZE]; - struct scalar_history history; + fftw_real *history_frame[HISTORY_SIZE]; + struct fftw_real_xy *history_scalars[HISTORY_SIZE]; }; diff --git a/Smoke/glyphs.c b/Smoke/glyphs.c index 33f941d..c854e20 100644 --- a/Smoke/glyphs.c +++ b/Smoke/glyphs.c @@ -21,7 +21,8 @@ static int glyphs_dataset_color = DATASET_RHO; static int glyphs_dataset_direction = DATASET_RHO;
static float glyphs_alpha = 1.0f;
-static fftw_real *glyphs_frame;
+static fftw_real *glyphs_frame_color;
+struct fftw_real_xy_p glyphs_frame_direction;
void glyphs_set_render(int render_glyphs)
@@ -108,14 +109,24 @@ int glyphs_get_sort(void) return glyphs_sort;
}
-void glyphs_set_frame(fftw_real *frame)
+void glyphs_set_frame_color(fftw_real *frame)
{
- glyphs_frame = frame;
+ glyphs_frame_color = frame;
}
-fftw_real *glyphs_get_frame(void)
+fftw_real *glyphs_get_frame_color(void)
{
- return glyphs_frame;
+ return glyphs_frame_color;
+}
+
+void glyphs_set_frames_direction(struct fftw_real_xy_p frame)
+{
+ glyphs_frame_direction = frame;
+}
+
+struct fftw_real_xy_p glyphs_get_frames_direction(void)
+{
+ return glyphs_frame_direction;
}
diff --git a/Smoke/glyphs.h b/Smoke/glyphs.h index 200d603..c2eb616 100644 --- a/Smoke/glyphs.h +++ b/Smoke/glyphs.h @@ -1,35 +1,38 @@ -#ifndef _GLYPHS_H
+#ifndef _GLYPHS_H #define _GLYPHS_H #define GLYPH_LINES 0 #define GLYPH_TRIANGLES 1 #define GLYPH_CONES 2 #define GLYPH_ARROWS 3 -#define GLYPH_QUAKE 4
-
-void glyphs_set_render(int render_glyphs);
-int glyphs_get_render(void);
-
-void glyphs_set_num_colors(int num_colors);
-int glyphs_get_num_colors(void);
-
-void glyphs_set_colormap(int colormap);
-int glyphs_get_colormap(void);
-
-void glyphs_set_alpha(float alpha);
-float glyphs_get_alpha(void);
-
-void glyphs_set_dataset_color(int dataset);
-int glyphs_get_dataset_color(void);
-
-void glyphs_set_dataset_direction(int dataset);
-int glyphs_get_dataset_direction(void);
-
-void glyphs_set_sort(int sort);
-int glyphs_get_sort(void);
-
-void glyphs_set_frame(fftw_real *frame);
-fftw_real *glyphs_get_frame(void);
-
-struct color4f glyphs_get_color(float value);
-#endif
+#define GLYPH_QUAKE 4 + +void glyphs_set_render(int render_glyphs); +int glyphs_get_render(void); + +void glyphs_set_num_colors(int num_colors); +int glyphs_get_num_colors(void); + +void glyphs_set_colormap(int colormap); +int glyphs_get_colormap(void); + +void glyphs_set_alpha(float alpha); +float glyphs_get_alpha(void); + +void glyphs_set_dataset_color(int dataset); +int glyphs_get_dataset_color(void); + +void glyphs_set_dataset_direction(int dataset); +int glyphs_get_dataset_direction(void); + +void glyphs_set_sort(int sort); +int glyphs_get_sort(void); + +void glyphs_set_frame_color(fftw_real *frame); +fftw_real *glyphs_get_frame_color(void); + +void glyphs_set_frames_direction(struct fftw_real_xy_p frame); +struct fftw_real_xy_p glyphs_get_frames_direction(void); + +struct color4f glyphs_get_color(float value); +#endif diff --git a/Smoke/gtk_colormap.c b/Smoke/gtk_colormap.c index 09d04fe..169291d 100644 --- a/Smoke/gtk_colormap.c +++ b/Smoke/gtk_colormap.c @@ -5,6 +5,7 @@ #include "fluids.h" #include "palette.h" +#include "smoke.h" /* colormap and smoke are siblings */ #include "colormap.h" #include "gtk_colormap.h" diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c index 1e06356..a312f3d 100644 --- a/Smoke/renderer_gl.c +++ b/Smoke/renderer_gl.c @@ -342,7 +342,6 @@ void render_smoke(void) for (j = 0; j < DIM - 1; j++) //draw smoke { glBegin(GL_TRIANGLE_STRIP); - i = 0; idx = (j * DIM) + i; px = wn + (fftw_real)i * wn; @@ -351,7 +350,7 @@ void render_smoke(void) color = colormap_get_color(frame[idx]); glColor4f(color.r, color.b, color.g, color.a); - glNormal3f(normal[idx].x, normal[idx].y, normal[idx].z); +// glNormal3f(normal[idx].x, normal[idx].y, normal[idx].z); glVertex3f(px, py, pz); for (i = 0; i < DIM - 1; i++) @@ -362,7 +361,7 @@ void render_smoke(void) pz = height[idx] *heightplots_get_height(); color = colormap_get_color(frame[idx]); glColor4f(color.r, color.g, color.b, color.a); - glNormal3f(normal[idx].x, normal[idx].y, normal[idx].z); + // glNormal3f(normal[idx].x, normal[idx].y, normal[idx].z); glVertex3f(px, py, pz); idx = (j * DIM) + (i + 1); px = wn + (fftw_real)(i + 1) * wn; @@ -370,7 +369,7 @@ void render_smoke(void) pz = height[idx] *heightplots_get_height(); color = colormap_get_color(frame[idx]); glColor4f(color.r, color.g, color.b, color.a); - glNormal3f(normal[idx].x, normal[idx].y, normal[idx].z); + // glNormal3f(normal[idx].x, normal[idx].y, normal[idx].z); glVertex3f(px, py, pz); } @@ -380,7 +379,7 @@ void render_smoke(void) pz = height[idx] *heightplots_get_height(); color = colormap_get_color(frame[idx]); glColor4f(color.r, color.g, color.b, color.a); - glNormal3f(normal[idx].x, normal[idx].y, normal[idx].z); + // glNormal3f(normal[idx].x, normal[idx].y, normal[idx].z); glVertex3f(px, py, pz); glEnd(); } @@ -571,14 +570,18 @@ static void render_glyph(GLUquadricObj *qobj, float x_value, float y_value, floa static void render_glyphs(void) { int i, j, idx, DIM; - float value, scale, idxcf, idxrf; + float scale, idxcf, idxrf; struct color4f color; + fftw_real *frame_color; + struct fftw_real_xy_p frames_direction; GLUquadricObj *qobj = gluNewQuadric(); gluQuadricDrawStyle(qobj, GLU_FILL); gluQuadricNormals(qobj, GLU_SMOOTH); DIM = fluids_get_dim(); + frame_color = glyphs_get_frame_color(); + frames_direction = glyphs_get_frames_direction(); scale = (float)((float)DIM / (float)fluids_get_var_dim()); for (i = 0; i < fluids_get_var_dim(); i++) @@ -589,35 +592,10 @@ static void render_glyphs(void) idxrf = round(i * scale); idx = idxcf + idxrf; - switch (glyph_scalar) - { - default: - case SCALAR_RHO: - value = rho[idx]; - break; - - case SCALAR_VEL: - value = vec_len2f(vx[idx], vy[idx]); - break; - - case SCALAR_FORCE: - value = vec_len2f(fx[idx], fy[idx]); - break; - } - color = glyphs_get_color(value); + color = glyphs_get_color(frame_color[idx]); glColor4f(color.r, color.b, color.g, color.a); - switch (glyph_vector) - { - default: - case VECTOR_VEL: - render_glyph(qobj, vx[idx], vy[idx], i, j); - break; - - case VECTOR_FORCE: - render_glyph(qobj, fx[idx], fy[idx], i, j); - break; - } + render_glyph(qobj, frames_direction.x[idx], frames_direction.y[idx], i, j); } } @@ -650,8 +628,10 @@ static void render_isolines(void) float x_offset, y_offset, z_pos = 8.0f; struct color4f color; struct point p0, p1, p2, p3, e1, e2; + fftw_real *frame; DIM = fluids_get_dim(); + frame = isolines_get_frame(); wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width hn = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell height @@ -679,13 +659,13 @@ static void render_isolines(void) { state = 0; idx = (j * DIM) + i; - color = isolines_get_color(get_dataset(idx)); + color = isolines_get_color(frame[idx]); glColor4f(color.r, color.g, color.b, color.a); - v0 = get_dataset(idx + DIM); - v1 = get_dataset(idx + 1 + DIM); - v2 = get_dataset(idx + 1); - v3 = get_dataset(idx); + v0 = frame[idx + DIM]; + v1 = frame[idx + 1 + DIM]; + v2 = frame[idx + 1]; + v3 = frame[idx]; if (v0 >= threshold) { state += 1; } if (v1 >= threshold) { state += 2; } @@ -974,7 +954,6 @@ void renderer_reset_roll(void) //visualize: This is the main visualization function void visualize(struct vis_data_arrays *vis_data) { - // Rotate field glPushMatrix(); @@ -990,10 +969,6 @@ void visualize(struct vis_data_arrays *vis_data) render_grid(); } - if (isolines_get_render()) { - render_isolines(); - } - if (smoke_get_render()) { render_smoke(); } @@ -1001,6 +976,10 @@ void visualize(struct vis_data_arrays *vis_data) render_grid_smoke(); } + if (isolines_get_render()) { + render_isolines(); + } + if (glyphs_get_render()) { render_glyphs(); } diff --git a/Smoke/smoke.bin b/Smoke/smoke.bin Binary files differindex be3b34f..47111c1 100755 --- a/Smoke/smoke.bin +++ b/Smoke/smoke.bin |