summaryrefslogtreecommitdiffstats
path: root/Smoke/fluids.c
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2007-12-17 19:48:37 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2007-12-17 19:48:37 (GMT)
commit9363bc6887a7ffb9ea6c0f6a63a93c215e227502 (patch)
treedc5f962bdcc413a5bd4bff4d85c7842522a73fb3 /Smoke/fluids.c
parent1d771540b16ba07cb02be5490892465a2a5ab89a (diff)
download2iv35-9363bc6887a7ffb9ea6c0f6a63a93c215e227502.zip
2iv35-9363bc6887a7ffb9ea6c0f6a63a93c215e227502.tar.gz
2iv35-9363bc6887a7ffb9ea6c0f6a63a93c215e227502.tar.bz2
Added/splitted colormaps to a seperate file.
Diffstat (limited to 'Smoke/fluids.c')
-rw-r--r--Smoke/fluids.c153
1 files changed, 72 insertions, 81 deletions
diff --git a/Smoke/fluids.c b/Smoke/fluids.c
index 7614610..59984aa 100644
--- a/Smoke/fluids.c
+++ b/Smoke/fluids.c
@@ -11,11 +11,11 @@
#include <stdio.h>
#include "fluids.h"
+#include "palette.h"
#include "colormap.h"
#include "glyphs.h"
#include "seedpoint.h"
#include "streamlines.h"
-#include "palette.h"
#include "funcs.h"
//--- SIMULATION PARAMETERS ------------------------------------------------------------------------
@@ -39,11 +39,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
-float clamp_min = 0;
-float clamp_max = 0.9999f;
-int autoscale = FALSE;
-float scale_min = 0;
-float scale_max = 1;
int vis_dataset = DATASET_RHO;
int mousebutton;
int mousebuttonstate;
@@ -52,7 +47,6 @@ int use_glyphs = FALSE;
int glyph_scalar = SCALAR_RHO;
int glyph_vector = VECTOR_VEL;
int glyph_sort = GLYPH_CYLINDERS;
-int draw_options = FALSE;
GLuint startList;
float threshold1 = 0.2f;
float threshold2 = 2.0f;
@@ -309,15 +303,6 @@ void calculate_one_simulation_step(void)
//------ VISUALIZATION CODE STARTS HERE -----------------------------------------------------------------
-float remap(float value)
-{
- value -= scale_min;
- value /= (scale_max - scale_min);
-
- 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
// using a rainbow colormap. If method==0, simply use the white color
@@ -390,16 +375,18 @@ float get_dataset(int index)
void set_autoscaling(void)
{
int k;
- float value;
+ float value, scale_min, scale_max;
scale_min = scale_max = get_dataset(0);
+ colormap_set_scale_min(scale_min);
+ colormap_set_scale_max(scale_max);
for (k = 1; k < DIM * DIM; k++)
{
value = get_dataset(k);
- if (scale_min > value) { scale_min = value; }
- if (scale_max < value) { scale_max = value; }
+ if (scale_min > value) { colormap_set_scale_min(value); }
+ if (scale_max < value) { colormap_set_scale_max(value); }
}
//threshold = (scale_min + scale_max) / 2;
@@ -433,7 +420,7 @@ void draw_isolines(float threshold)
{
state = 0;
idx = (j * DIM) + i;
- colormap = set_colormap(scalar_col, get_dataset(idx), 1.0f);
+ colormap = set_palette(scalar_col, get_dataset(idx), 5);
glColor4f(colormap.r, colormap.g, colormap.b, 1.0f);
v0 = get_dataset(idx + DIM);
@@ -524,13 +511,10 @@ void draw_isolines(float threshold)
void render_smoke(void)
{
- static float fadein = 0;
int i, j, idx; double px,py;
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
- static int delay = 0;
- float hight_value = 0.0f;
- struct color4f colormap;
+ struct color4f color;
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
@@ -551,59 +535,63 @@ void render_smoke(void)
px = wn + (fftw_real)i * wn;
py = hn + (fftw_real)(j + 1) * hn;
idx = ((j + 1) * DIM) + i;
- colormap = set_colormap(scalar_col, get_dataset(idx), 1.0f);
- glColor4f(colormap.r, colormap.g, colormap.b, 1.0f);
+ color = colormap_get_color(get_dataset(idx));
+ glColor4f(color.r, color.g, color.b, 1.0f);
glVertex3f(px, py, height_array[idx]);
px = wn + (fftw_real)(i + 1) * wn;
py = hn + (fftw_real)j * hn;
idx = (j * DIM) + (i + 1);
- colormap = set_colormap(scalar_col, get_dataset(idx), 1.0f);
- glColor4f(colormap.r, colormap.g, colormap.b, 1.0f);
+ color = colormap_get_color(get_dataset(idx));
+ glColor4f(color.r, color.g, color.b, 1.0f);
glVertex3f(px, py, height_array[idx]);
}
px = wn + (fftw_real)(DIM - 1) * wn;
py = hn + (fftw_real)(j + 1) * hn;
idx = ((j + 1) * DIM) + (DIM - 1);
- colormap = set_colormap(scalar_col, get_dataset(idx), 1.0f);
- glColor4f(colormap.r, colormap.g, colormap.b, 1.0f);
+ color = colormap_get_color(get_dataset(idx));
+ glColor4f(color.r, color.g, color.b, 1.0f);
glVertex3f(px, py, height_array[idx]);
glEnd();
}
}
-//visualize: This is the main visualization function
-void visualize(void)
+void render_legend(void)
{
- static float fadein = 0;
- int i, j, idx; double px,py;
- 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
- static int delay = 0;
- float hight_value = 0.0f;
- struct color4f colormap;
-
- glTranslatef(xPos, yPos, zPos);
+ int i;
+ struct color4f color;
- for (i = 0; i < winWidth; i++)
+ 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);
-// if (value < clamp_min) value = clamp_min;
-// if (value > clamp_max) value = clamp_max;
- colormap = set_colormap(scalar_col, value, 1.0f);
+ color = colormap_get_color(value);
- clamp_scaled_min = clamp_min *winWidth;
- clamp_scaled_max = clamp_max *winWidth;
+ clamp_scaled_min = colormap_get_clamp_min() *winWidth;
+ clamp_scaled_max = colormap_get_clamp_max() *winWidth;
- scale_scaled_min = scale_min *winWidth;
- scale_scaled_max = scale_max *winWidth;
+ scale_scaled_min = colormap_get_scale_min() *winWidth;
+ scale_scaled_max = colormap_get_scale_max() *winWidth;
glBegin(GL_LINES);
+ if (colormap_get_scaling()) {
+ glColor3f(1, 0, 0);
+ glVertex2i(scale_scaled_min, winHeight -4);
+ glVertex2i(scale_scaled_min, winHeight -18);
+ glVertex2i(scale_scaled_max, winHeight -4);
+ glVertex2i(scale_scaled_max, winHeight -18);
+ }
+ if (colormap_get_clamping()) {
+ glColor4f(0.2, 0.2, 0.2, 1.0);
+ glVertex2i(clamp_scaled_min, winHeight -6);
+ glVertex2i(clamp_scaled_min, winHeight -18);
+ glVertex2i(clamp_scaled_max, winHeight -6);
+ glVertex2i(clamp_scaled_max, winHeight -18);
+ }
if (!(i %20)) {
glColor3f(0.7, 0.7, 0.7);
glVertex2i(i -1, winHeight -6);
@@ -613,33 +601,14 @@ void visualize(void)
glVertex2i(i +1, winHeight -6);
glVertex2i(i +1, winHeight -22);
} else {
- glColor3f(colormap.r, colormap.g, colormap.b);
+ glColor3f(color.r, color.g, color.b);
glVertex2i(i, winHeight -6);
glVertex2i(i, winHeight -18);
}
- glColor4f(0.2, 0.2, 0.2, 1.0);
- glVertex2i(clamp_scaled_min, winHeight -6);
- glVertex2i(clamp_scaled_min, winHeight -18);
- glVertex2i(clamp_scaled_max, winHeight -6);
- glVertex2i(clamp_scaled_max, winHeight -18);
- if (autoscale) {
- glColor3f(1, 0, 0);
- glVertex2i(scale_scaled_min, winHeight -4);
- glVertex2i(scale_scaled_min, winHeight -18);
- glVertex2i(scale_scaled_max, winHeight -4);
- glVertex2i(scale_scaled_max, winHeight -18);
- }
glEnd();
glBegin(GL_TRIANGLES);
- glColor3f(0.9, 0.9, 0.9);
- glVertex2i(clamp_scaled_min, winHeight -18);
- glVertex2i(clamp_scaled_min -4, winHeight -25);
- glVertex2i(clamp_scaled_min +4, winHeight -25);
- glVertex2i(clamp_scaled_max, winHeight -18);
- glVertex2i(clamp_scaled_max -4, winHeight -25);
- glVertex2i(clamp_scaled_max +4, winHeight -25);
- if (autoscale) {
+ if (colormap_get_scaling()) {
glColor3f(1, 0, 0);
glVertex2i(scale_scaled_min, winHeight -6);
glVertex2i(scale_scaled_min -4, winHeight);
@@ -648,8 +617,28 @@ void visualize(void)
glVertex2i(scale_scaled_max -4, winHeight);
glVertex2i(scale_scaled_max +4, winHeight);
}
+ if (colormap_get_clamping()) {
+ glColor3f(0.9, 0.9, 0.9);
+ glVertex2i(clamp_scaled_min, winHeight -18);
+ glVertex2i(clamp_scaled_min -4, winHeight -25);
+ glVertex2i(clamp_scaled_min +4, winHeight -25);
+ glVertex2i(clamp_scaled_max, winHeight -18);
+ glVertex2i(clamp_scaled_max -4, winHeight -25);
+ glVertex2i(clamp_scaled_max +4, winHeight -25);
+ }
glEnd();
}
+}
+
+//visualize: This is the main visualization function
+void visualize(void)
+{
+ 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
+
+ glTranslatef(xPos, yPos, zPos);
+
+ render_legend();
// Rotate field
glLoadIdentity();
@@ -707,20 +696,25 @@ void click(int button, int state, int mx, int my)
if (my <25) {
/* Click received on button bar */
+ float min, max;
if (my <13) {
/* Upper half */
/* check wether mx is min or max slider */
- if (mx <(rescale_to_winwidth(scale_min +((scale_max - scale_min) /2)))) {
+ min = colormap_get_scale_min();
+ max = colormap_get_scale_max();
+ if (mx <(rescale_to_winwidth(min +((max - min) /2)))) {
active_slider = MOUSE_SCALE_MIN;
- } else if (mx >(rescale_to_winwidth(scale_max -((scale_max - scale_min) /2)))) {
+ } else if (mx >(rescale_to_winwidth(max -((max - min) /2)))) {
active_slider = MOUSE_SCALE_MAX;
}
} else {
/* Bottom half */
+ min = colormap_get_clamp_min();
+ max = colormap_get_clamp_max();
/* check wether mx is min or max slider */
- if (mx <(rescale_to_winwidth(clamp_min +((clamp_max - clamp_min) /2)))) {
+ if (mx <(rescale_to_winwidth(min +((max - min) /2)))) {
active_slider = MOUSE_CLAMP_MIN;
- } else if (mx >(rescale_to_winwidth(clamp_max -((clamp_max - clamp_min) /2)))) {
+ } else if (mx >(rescale_to_winwidth(max -((max - min) /2)))) {
active_slider = MOUSE_CLAMP_MAX;
}
}
@@ -773,16 +767,16 @@ void drag(int mx, int my)
} else {
switch (active_slider) {
case MOUSE_SCALE_MIN:
- scale_min = (float)mx /winWidth;
+ colormap_set_scale_min((float)mx /winWidth);
break;
case MOUSE_SCALE_MAX:
- scale_max = (float)mx /winWidth;
+ colormap_set_scale_max((float)mx /winWidth);
break;
case MOUSE_CLAMP_MIN:
- clamp_min = (float)mx /winWidth;
+ colormap_set_clamp_min((float)mx /winWidth);
break;
case MOUSE_CLAMP_MAX:
- clamp_max = (float)mx /winWidth;
+ colormap_set_clamp_max((float)mx /winWidth);
break;
case MOUSE_SMOKE:
default:
@@ -805,9 +799,6 @@ int get_glyph_usage(void) { return use_glyphs; }
void selectColor(int arg) { scalar_col = arg; }
void select_dataset(int arg) { vis_dataset = arg; }
-void toggle_autoscale(void) { autoscale = (autoscale) ? FALSE : TRUE ; }
-void toggle_clamping(void) { }
-void show_options(void) { draw_options = (draw_options) ? FALSE : TRUE; }
void toggle_glyph_usage(void) { use_glyphs = (use_glyphs) ? FALSE : TRUE; }
void toggle_smoke_usage(void) { draw_smoke = (draw_smoke) ? FALSE : TRUE; }
void toggle_mouse_rotate(void) { rotate_plane = (rotate_plane) ? FALSE : TRUE; }