summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2008-01-09 16:22:34 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2008-01-09 16:22:34 (GMT)
commit4b45e834c8a243d299f7b09960dc43db58cb7910 (patch)
tree81f58e6af8c70b1695ff374d085cacd15edd0d13
parent19104903490d2c67f9b385804a7f89df8f6fc48c (diff)
download2iv35-4b45e834c8a243d299f7b09960dc43db58cb7910.zip
2iv35-4b45e834c8a243d299f7b09960dc43db58cb7910.tar.gz
2iv35-4b45e834c8a243d299f7b09960dc43db58cb7910.tar.bz2
fix frame history!
-rw-r--r--Smoke/fluids.c37
-rw-r--r--Smoke/fluids.h14
-rw-r--r--Smoke/gtk_streamlines.c22
-rw-r--r--Smoke/renderer_gl.c32
-rw-r--r--Smoke/renderer_gl.h1
-rwxr-xr-xSmoke/smoke.binbin641810 -> 642974 bytes
-rw-r--r--Smoke/streamlines.c11
-rw-r--r--Smoke/streamlines.h3
8 files changed, 91 insertions, 29 deletions
diff --git a/Smoke/fluids.c b/Smoke/fluids.c
index 2ab0e81..2a59ef1 100644
--- a/Smoke/fluids.c
+++ b/Smoke/fluids.c
@@ -77,11 +77,10 @@ void fluids_init_simulation(int n, struct vis_data_arrays *vis_data)
height_array = (fftw_real*) malloc(dim2);
normal_array = (struct point*) malloc(dim2);
- frame_hist = (fftw_real*) malloc(dim2 * n);
- for (i = 0; i <= n; i++)
+ for (i = 0; i < HISTORY_SIZE; i++)
{
- frame_hist[i] = (fftw_real*) malloc(dim1);
+ vis_data->history[i] = (fftw_real*)malloc(dim1);
}
fluids_reset_simulation();
@@ -398,14 +397,36 @@ fftw_real *get_frame(struct vis_data_arrays *vis_data, int dataset)
return_value = vis_data->div_force;
break;
case DATASET_HIST:
- return_value = vis_data->history[0];
+// return_value = vis_data->history;
+ break;
}
return return_value;
}
-void populate_arrays(struct vis_data_arrays *vis_data)
+void add_history_frame(int dataset, struct vis_data_arrays *vis_data)
+{
+ static int hisdex = 0;
+ fftw_real *frame;
+
+
+ if (dataset != DATASET_HIST) {
+ frame = get_frame(vis_data, dataset);
+// printf("hisdex: %d\n", hisdex);
+
+ // if (hisdex) {
+ memcpy(vis_data->history[hisdex], frame, DIM * 2 * (DIM / 2) * sizeof(fftw_real));
+ // } else {
+ // memcpy(vis_data->history[0], frame, DIM * 2 * (DIM / 2) * sizeof(fftw_real));
+ // memcpy(vis_data->history[hisdex], vis_data->history[0], DIM * 2 * (DIM / 2) * sizeof(fftw_real));
+ // }
+ hisdex = (hisdex >= HISTORY_SIZE -1) ? 0 : hisdex +1;
+ }
+}
+
+
+void setup_arrays(struct vis_data_arrays *vis_data)
{
int idx, i, j;
float scale_min, scale_max;
@@ -441,7 +462,6 @@ void populate_arrays(struct vis_data_arrays *vis_data)
// }
- get_frame(vis_data, streamlines_get_dataset());
if (colormap_get_autoscaling()) {
if (scale_min > frame[idx]) { colormap_set_scale_min(frame[idx]); }
@@ -469,8 +489,9 @@ 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);
}
- populate_arrays(vis_data);
+ setup_arrays(vis_data);
dataset = smoke_get_dataset();
frame = get_frame(vis_data, dataset);
@@ -482,7 +503,7 @@ void fluids_calculate_one_simulation_step(struct vis_data_arrays *vis_data)
heightplots_set_frame(vis_data->height);
normals_set_frame(vis_data->normals);
-// streamlines_set_frame(vis_data->history);
+ streamlines_set_history(vis_data->history);
}
//------ VISUALIZATION CODE STARTS HERE -----------------------------------------------------------------
diff --git a/Smoke/fluids.h b/Smoke/fluids.h
index c9ba8b1..555614e 100644
--- a/Smoke/fluids.h
+++ b/Smoke/fluids.h
@@ -29,11 +29,13 @@ extern int frame_index;
#define VECTOR_VEL 0
#define VECTOR_FORCE 1
-#define GLYPH_LINES 0
-#define GLYPH_TRIANGLES 1
-#define GLYPH_CONES 2
-#define GLYPH_ARROWS 3
-#define GLYPH_QUAKE 4
+#define GLYPH_LINES 0
+#define GLYPH_TRIANGLES 1
+#define GLYPH_CONES 2
+#define GLYPH_ARROWS 3
+#define GLYPH_QUAKE 4
+
+#define HISTORY_SIZE 40
extern int winWidth, winHeight; //size of the graphics window, in pixels
extern int color_dir; //use direction color-coding or not
@@ -65,7 +67,7 @@ struct vis_data_arrays {
fftw_real *div_force;
fftw_real *height;
struct point *normals;
- fftw_real *history[50];
+ fftw_real *history[HISTORY_SIZE];
};
diff --git a/Smoke/gtk_streamlines.c b/Smoke/gtk_streamlines.c
index 0945b6d..8096b24 100644
--- a/Smoke/gtk_streamlines.c
+++ b/Smoke/gtk_streamlines.c
@@ -7,6 +7,8 @@
#include "palette.h"
#include "streamlines.h"
+#include "renderer_gl.h"
+
#include "gtk_streamlines.h"
@@ -33,6 +35,14 @@ static gboolean select_alpha(GtkRange *adjustment, gpointer data)
return TRUE;
}
+static gboolean select_history(GtkRange *adjustment, gpointer data)
+{
+ set_hisdex((int)gtk_range_get_value(adjustment));
+
+ return TRUE;
+}
+
+
GtkWidget *create_streamlines_page(void)
{
@@ -85,7 +95,7 @@ GtkWidget *create_streamlines_page(void)
adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(
- streamlines_get_num_colors(), 1, PALETTE_MAXCOLORS, 0.5, 5, 0.1));
+ streamlines_get_num_colors(), 1, PALETTE_MAXCOLORS, 0.5, 5, 0));
scale = gtk_hscale_new(adjustment);
gtk_scale_set_digits(GTK_SCALE(scale), 0);
g_signal_connect(GTK_RANGE(scale), "value-changed", G_CALLBACK(select_num_colors), NULL);
@@ -108,6 +118,16 @@ GtkWidget *create_streamlines_page(void)
gtk_box_pack_start(GTK_BOX(box), scale, FALSE, TRUE, 0);
gtk_widget_show(scale);
+
+ adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, HISTORY_SIZE -1, 5, 5, 0));
+ scale = gtk_hscale_new(adjustment);
+ gtk_scale_set_digits(GTK_SCALE(scale), 0);
+ g_signal_connect(GTK_RANGE(scale), "value-changed", G_CALLBACK(select_history), NULL);
+
+ gtk_box_pack_start(GTK_BOX(box), scale, FALSE, TRUE, 0);
+ gtk_widget_show(scale);
+
+
gtk_container_add(GTK_CONTAINER(frame), box);
gtk_widget_show(box);
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c
index 0ce22e7..96b9faa 100644
--- a/Smoke/renderer_gl.c
+++ b/Smoke/renderer_gl.c
@@ -322,6 +322,7 @@ void render_smoke(void)
frame = smoke_get_frame();
height = heightplots_get_frame();
normal = normals_get_frame();
+
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for (j = 0; j < DIM - 1; j++) //draw smoke
@@ -711,7 +712,7 @@ static void render_streamlines(void)
while (j < DIM)
{
- frame_history = frame_hist[j];
+ // frame_history = frame_hist[j];
cell_x = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width
cell_y = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell heigh
@@ -727,6 +728,11 @@ static void render_streamlines(void)
}
}
+static int hisdex = 0;
+
+void set_hisdex(int arg) {
+ hisdex = arg;
+}
static void render_flowvis(void)
{
@@ -734,12 +740,15 @@ static void render_flowvis(void)
double px,py;
fftw_real wn, hn;
struct color4f color;
+ fftw_real *history;
DIM = fluids_get_dim();
wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width
hn = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell height
+ history = streamlines_get_history(hisdex);
+
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for (j = 0; j < DIM - 1; j++) //draw smoke
@@ -751,38 +760,33 @@ static void render_flowvis(void)
py = hn + (fftw_real)j * hn;
idx = (j * DIM) + i;
- color = flowvis_get_color(get_dataset(idx));
+ color = flowvis_get_color(history[idx]);
glColor4f(color.r, color.g, color.b, color.a);
- glNormal3f(normal_array[idx].x, normal_array[idx].y, normal_array[idx].z);
- glVertex3f(px, py, height_array[idx]); // vertex 1
+ glVertex2f(px, py); // vertex 1
for (i = 0; i < DIM - 1; i++)
{
px = wn + (fftw_real)i * wn;
py = hn + (fftw_real)(j + 1) * hn;
idx = ((j + 1) * DIM) + i;
- get_dataset(idx);
- color = flowvis_get_color(get_dataset(idx));
+ color = flowvis_get_color(history[idx]);
glColor4f(color.r, color.g, color.b, color.a);
- glNormal3f(normal_array[idx].x, normal_array[idx].y, normal_array[idx].z);
- glVertex3f(px, py, height_array[idx]); // vertex 2
+ glVertex2f(px, py); // vertex 2
px = wn + (fftw_real)(i + 1) * wn;
py = hn + (fftw_real)j * hn;
idx = (j * DIM) + (i + 1);
- color = flowvis_get_color(get_dataset(idx));
+ color = flowvis_get_color(history[idx]);
glColor4f(color.r, color.g, color.b, color.a);
- glNormal3f(normal_array[idx].x, normal_array[idx].y, normal_array[idx].z);
- glVertex3f(px, py, height_array[idx]); // vertex 3
+ glVertex2f(px, py); // vertex 3
}
px = wn + (fftw_real)(DIM - 1) * wn;
py = hn + (fftw_real)(j + 1) * hn;
idx = ((j + 1) * DIM) + (DIM - 1);
- color = flowvis_get_color(get_dataset(idx));
+ color = flowvis_get_color(history[idx]);
glColor4f(color.r, color.g, color.b, color.a);
- glNormal3f(normal_array[idx].x, normal_array[idx].y, normal_array[idx].z);
- glVertex3f(px, py, height_array[idx]); // vertex 4
+ glVertex2f(px, py); // vertex 4
glEnd();
}
diff --git a/Smoke/renderer_gl.h b/Smoke/renderer_gl.h
index 09587d8..00fcea3 100644
--- a/Smoke/renderer_gl.h
+++ b/Smoke/renderer_gl.h
@@ -5,6 +5,7 @@ void renderer_init_gl(void);
void visualize(struct vis_data_arrays *vis_data);
+void set_hisdex(int arg);
void renderer_set_zoomspeed(int zoomspeed);
int renderer_get_zoomspeed(void);
diff --git a/Smoke/smoke.bin b/Smoke/smoke.bin
index 932362a..c49cc29 100755
--- a/Smoke/smoke.bin
+++ b/Smoke/smoke.bin
Binary files differ
diff --git a/Smoke/streamlines.c b/Smoke/streamlines.c
index a962180..be3dfe4 100644
--- a/Smoke/streamlines.c
+++ b/Smoke/streamlines.c
@@ -25,6 +25,7 @@ static int streamlines_dataset = DATASET_RHO;
static float streamlines_alpha = 1.0f;
static fftw_real *streamlines_frame;
+static fftw_real **streamlines_history;
void streamlines_set_render(int render_streamlines)
@@ -87,6 +88,16 @@ fftw_real *streamlines_get_frame(void)
return streamlines_frame;
}
+void streamlines_set_history(fftw_real **history)
+{
+ streamlines_history = history;
+}
+
+fftw_real *streamlines_get_history(int hisdex)
+{
+ return streamlines_history[hisdex];
+}
+
struct color4f streamlines_get_color(float value)
{
diff --git a/Smoke/streamlines.h b/Smoke/streamlines.h
index 0d2ce83..f1a3431 100644
--- a/Smoke/streamlines.h
+++ b/Smoke/streamlines.h
@@ -19,6 +19,9 @@ int streamlines_get_dataset(void);
void streamlines_set_frame(fftw_real *frame);
fftw_real *streamlines_get_frame(void);
+void streamlines_set_history(fftw_real **history);
+fftw_real *streamlines_get_history(int hisdex);
+
struct color4f streamlines_get_color(float value);