Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
draw.h File Reference
#include <ctype.h>
#include "fractions.h"
#include "gl/font.h"
#include "draw_json.h"
Include dependency graph for draw.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define colorize_args()
 
#define color_facet()
 
#define color_vertex(val)
 
#define colorize()
 
#define COLORBAR_PARAMS
 Parameters for an (optional) colorbar.
 
#define interpo(pv, v)    (!pv ? v : ((t - start)*(pv) + (end - t)*(v))/(end - start))
 

Functions

void clear ()
 
void view (float tx=0., float ty=0., float fov=0., float quat[4]={0}, float sx=1., float sy=1., float sz=1., unsigned width=800, unsigned height=800, unsigned samples=4, float bg[3]={0}, float theta=0., float phi=0., float psi=0., bool relative=false, float tz=0., float near=0., float far=0., float res=0., char *camera=NULL, MapFunc map=NULL, int cache=0, float p1x=0., float p1y=0., float p2x=0., float p2y=0., bview *view1=NULL)
 
macro translate (float x=0, float y=0., float z=0.)
 
macro mirror (coord n={0}, double alpha=0.)
 
static void mapped_position (bview *view, coord *p, double *r)
 
macro2 foreach_visible (bview *view, char flags=0, Reduce reductions=None)
 
macro2 foreach_visible_stencil (bview *view, char flags, Reduce reductions)
 
macro draw_lines (bview *view, float color[3], float lw)
 A similar technique can be used to traverse the cells which are both visible and intersected by a plane defined by.
 
static double interp (Point point, coord p, scalar col)
 
static double evaluate_expression (Point point, Node *n)
 
static bool assemble_node (Node *n)
 
static scalar compile_expression (char *expr, bool *isexpr)
 
macro colorized (float fc[3], bool constant_color, double cmap[NCMAP][3], bool use_texture)
 
trace bool colorbar (Colormap map=jet, float size=15, float pos[2]={-.95, -.95}, char *label="", double lscale=1, double min=-HUGE, double max=HUGE, bool horizontal=false, bool border=false, bool mid=false, float lc[3]={0}, float lw=3, float fsize=50, char *format="%g", int levels=50)
 
static bool cfilter (Point point, scalar c, double cmin)
 The somewhat complicated function below checks whether an interface fragment is present within a given cell.
 
static void glvertex3d (bview *view, double x, double y, double z)
 
static void glvertex2d (bview *view, double x, double y)
 
static void glvertex_normal3d (bview *view, Point point, vector n, double xp, double yp, double zp)
 
trace bool draw_vof (char *c, char *s=NULL, bool edges=false, double larger=0., int filled=0, char *color=NULL, double min=0, double max=0, double spread=0, bool linear=false, Colormap map=jet, float fc[3]={0}, float lc[3]={0}, float lw=1., bool expr=false, bool cbar=false, float size=15, float pos[2]={-.95, -.95}, char *label="", double lscale=1, bool horizontal=false, bool border=false, bool mid=false, float fsize=50, char *format="%g", int levels=50)
 
trace bool isoline (char *phi, double val=0., int n=1, bool edges=false, double larger=0., int filled=0, char *color=NULL, double min=0, double max=0, double spread=0, bool linear=false, Colormap map=jet, float fc[3]={0}, float lc[3]={0}, float lw=1., bool expr=false, bool cbar=false, float size=15, float pos[2]={-.95, -.95}, char *label="", double lscale=1, bool horizontal=false, bool border=false, bool mid=false, float fsize=50, char *format="%g", int levels=50)
 
trace bool cells (coord n={0, 0, 1}, double alpha=0., float lc[3]={0}, float lw=1.)
 
trace bool vectors (char *u, double scale=1, float lc[3]={0}, float lw=1., int level=-1)
 
trace bool squares (char *color, char *z=NULL, double min=0, double max=0, double spread=0, bool linear=false, Colormap map=jet, float fc[3]={0}, float lc[3]={0}, bool expr=false, coord n={0, 0, 1}, double alpha=0, float lw=1, bool cbar=false, float size=15, float pos[2]={-.95, -.95}, char *label="", double lscale=1, bool horizontal=false, bool border=false, bool mid=false, float fsize=50, char *format="%g", int levels=50)
 
trace bool box (bool notics=false, float lc[3]={0}, float lw=1.)
 
trace bool isosurface (char *f, double v, char *color=NULL, double min=0, double max=0, double spread=0, bool linear=false, Colormap map=jet, float fc[3]={0}, float lc[3]={0}, float lw=1, bool expr=false, bool cbar=false, float size=15, float pos[2]={-.95, -.95}, char *label="", double lscale=1, bool horizontal=false, bool border=false, bool mid=false, float fsize=50, char *format="%g", int levels=50)
 
void travelling (double start=0, double end=0, float tx=0, float ty=0, float quat[4]={0}, float fov=0)
 
trace bool draw_string (char *str, int pos=0, float size=40, float lc[3]={0}, float lw=1)
 
trace bool labels (char *f, float lc[3]={0}, float lw=1, int level=-1)
 
trace bool lines (char *file, float lc[3]={0}, float lw=1.)
 

Variables

struct { 
 
   int(*   json )(char *s, int len) 
 
bview_interface [] 
 

Macro Definition Documentation

◆ color_facet

#define color_facet ( )
Value:
if (color && (!linear || col.i < 0)) { \
Color b = colormap_color (cmap, col.i < 0 ? \
(double) level : val(col,0,0,0), \
min, max); \
glColor3f (b.r/255., b.g/255., b.b/255.); \
}
if TRASH define &&NewPid *& val(newpid, 0, 0, 0)) -> pid > 0) @else @ define is_newpid()(((NewPid *)&val(newpid, 0, 0, 0)) ->pid > 0) @endif Array *linear_tree(size_t size, scalar newpid)
Definition balance.h:13
int min
Definition balance.h:192
int x
Definition common.h:76
size_t max
Definition mtrace.h:8
size *double * b
int int int level
Color colormap_color(double cmap[127][3], double val, double min, double max)
Definition output.h:308
Given a colormap and a minimum and maximum value, this function returns the red/green/blue triplet co...
Definition output.h:304
Array * color

Definition at line 592 of file draw.h.

◆ color_vertex

#define color_vertex (   val)
Value:
if (color && linear && col.i >= 0) { \
if (VertexBuffer.color) { \
glColor3f (b.r/255., b.g/255., b.b/255.); \
} \
else { \
double _v = val; \
if (max > min) \
glTexCoord1d (clamp(((_v) - min)/(max - min), 0., 1.)); \
} \
}
static number clamp(number x, number a, number b)
Definition common.h:15
struct @17 VertexBuffer

Definition at line 600 of file draw.h.

◆ COLORBAR_PARAMS

#define COLORBAR_PARAMS
Value:
bool cbar = false, \
float size = 15, float pos[2] = {-.95, -.95}, \
char * label = "", double lscale = 1, \
bool horizontal = false, bool border = false, \
bool mid = false, float fsize = 50, \
char * format = "%g", int levels = 50
double pos
Definition curvature.h:674
size_t size
@ border
Definition tree.h:61

Parameters for an (optional) colorbar.

Definition at line 798 of file draw.h.

◆ colorize

#define colorize ( )
Value:
colorized (fc, !VertexBuffer.color || !color, \
cmap, !VertexBuffer.color && \
color && linear && col.i >= 0)
macro colorized(float fc[3], bool constant_color, double cmap[NCMAP][3], bool use_texture)
Definition draw.h:615

Definition at line 642 of file draw.h.

◆ colorize_args

#define colorize_args ( )

Definition at line 554 of file draw.h.

◆ interpo

#define interpo (   pv,
  v 
)     (!pv ? v : ((t - start)*(pv) + (end - t)*(v))/(end - start))

<em>travelling()</em>: moves the camera to a different viewpoint

start: starting time of the camera motion. end: time at which the viewpoint should be reached. tx, ty, quat, fov: definition of the target viewpoint.

Definition at line 1615 of file draw.h.

Function Documentation

◆ assemble_node()

static bool assemble_node ( Node n)
static

Definition at line 465 of file draw.h.

References assemble_node(), HUGE, scalar::i, i, lookup_field(), n, nodata, p, pi, s, val(), and x.

Referenced by assemble_node(), and compile_expression().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box()

trace bool box ( bool  notics = false,
float  lc[3] = {0},
float  lw = 1. 
)

<em>box()</em>: displays box boundaries and axis coordinates

notics: do not draw tick marks (default is false). lc[]: an array of red, green, blue values between 0 and 1 which defines the line color. lw: the line width.

Definition at line 1397 of file draw.h.

Referenced by if(), and init_grid().

Here is the caller graph for this function:

◆ cells()

trace bool cells ( coord  n = {0,0,1},
double  alpha = 0.,
float  lc[3] = {0},
float  lw = 1. 
)

<em>cells()</em>: displays grid cells

In 3D the intersections of the cells with a plane are displayed. The default plane is \(z=0\). This can be changed by setting n and alpha which define the plane

\[ n_x x + n_y y + n_z z = \alpha \]

Definition at line 1128 of file draw.h.

Referenced by debug_plot(), and if().

Here is the caller graph for this function:

◆ cfilter()

static bool cfilter ( Point  point,
scalar  c,
double  cmin 
)
static

The somewhat complicated function below checks whether an interface fragment is present within a given cell.

The interface is defined by the volume fraction field c. cmin is the threshold below which a fragment is considered too small.

Definition at line 812 of file draw.h.

References c, dimension, HUGE, max, min, n, and x.

◆ clear()

void clear ( )

Drawing functions for <a href="view.h" target="_blank" >Basilisk View</a>

Definition at line 14 of file draw.h.

References draw(), get_view(), and view().

Referenced by process_line(), and redraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ colorbar()

trace bool colorbar ( Colormap  map = jet,
float  size = 15,
float  pos[2] = {-.95, -.95},
char label = "",
double  lscale = 1,
double  min = -HUGE,
double  max = HUGE,
bool  horizontal = false,
bool  border = false,
bool  mid = false,
float  lc[3] = {0},
float  lw = 3,
float  fsize = 50,
char format = "%g",
int  levels = 50 
)

<em>colorbar()</em>: draws a colorbar.

map: the colormap. size: the size. pos: the relative screen position (default is lower-left corner). label: a label. lscale: the label scale factor. min, max: the range. horizontal: true for anb horizontal colorbar. border: adds a border. mid: adds a mid-value label. lc: the line color. lw: the line width. fsize: another size. format: how to format numbers. levels: the number of subdivisions.

Note that this cannot be used with jview (yet) because it mixes surface and line rendering.

Definition at line 668 of file draw.h.

◆ colorized()

macro colorized ( float  fc[3],
bool  constant_color,
double  cmap[NCMAP][3],
bool  use_texture 
)

Definition at line 615 of file draw.h.

References colormap_color(), GL_CLAMP_TO_EDGE, GL_FLOAT, GL_LINEAR, GL_RGB, GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, glColor3f, glDisable, glEnable, glTexImage1D, glTexParameteri, i, j, and x.

Here is the call graph for this function:

◆ compile_expression()

static scalar compile_expression ( char expr,
bool isexpr 
)
static

Definition at line 512 of file draw.h.

References _i, add_cexpr(), assemble_node(), evaluate_expression(), free(), get_cexpr(), get_view(), point, restriction, s, strdup(), view(), and x.

Here is the call graph for this function:

◆ draw_lines()

macro draw_lines ( bview view,
float  color[3],
float  lw 
)

A similar technique can be used to traverse the cells which are both visible and intersected by a plane defined by.

\[ n_x x + n_y y + n_z z = \alpha \]

Definition at line 388 of file draw.h.

References color, GL_PROJECTION, glColor3f, glLineWidth, glMatrixMode, glPopMatrix, glPushMatrix, glTranslatef, view(), and x.

Here is the call graph for this function:

◆ draw_string()

trace bool draw_string ( char str,
int  pos = 0,
float  size = 40,
float  lc[3] = {0},
float  lw = 1 
)

<em>draw_string()</em>: draws strings on a separate layer (for annotations)

str: string to display. pos: position: "0" bottom left, "1" top left, "2" top right and "3" bottom right (default 0). size: the size of the text, given as the number of characters which can fit within the width of the screen. Default is 40. lc[]: an array of red, green, blue values between 0 and 1 which defines the text color. lw: the line width.

Definition at line 1659 of file draw.h.

Referenced by if().

Here is the caller graph for this function:

◆ draw_vof()

trace bool draw_vof ( char c,
char s = NULL,
bool  edges = false,
double  larger = 0.,
int  filled = 0,
char color = NULL,
double  min = 0,
double  max = 0,
double  spread = 0,
bool  linear = false,
Colormap  map = jet,
float  fc[3] = {0},
float  lc[3] = {0},
float  lw = 1.,
bool  expr = false,
bool  cbar = false,
float  size = 15,
float  pos[2] = {-.95, -.95},
char label = "",
double  lscale = 1,
bool  horizontal = false,
bool  border = false,
bool  mid = false,
float  fsize = 50,
char format = "%g",
int  levels = 50 
)

<em>draw_vof()</em>: displays VOF-reconstructed interfaces

c: the name (as a string) of the Volume-Of-Fluid field. s: the (optional) name of the face fraction field. edges: whether to display the edges or the facets. larger: makes each cell larger by this factor. This helps close the gaps in the VOF interface representation. Default is 1.1 in 3D and when edges are not displayed, otherwise it is 1. filled: in 2D, whether to fill the inside (1) or outside (-1). color: use this field to color each interface fragment. min, max: the minimum and maximum values to use for color mapping. spread: the "spread factor" to use if min and max are not defined. The maximum and minimum values will be taken as the average plus or minus spread times the standard deviation. Default is 5. If negative, the minimum and maximum values of the field are used. linear: if true the color will be linearly interpolated for each vertex of the facet. map: the colormap to use. Default is jet. fc[]: an array of red, green, blue values between 0 and 1 which defines the facet color. lc[]: an array of red, green, blue values between 0 and 1 which defines the line color. lw: the line width.

Definition at line 897 of file draw.h.

Referenced by if().

Here is the caller graph for this function:

◆ evaluate_expression()

static double evaluate_expression ( Point  point,
Node n 
)
static

Definition at line 410 of file draw.h.

References assert, evaluate_expression(), i, k, n, point, pow(), s, undefined(), x, y, and z.

Referenced by compile_expression(), and evaluate_expression().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ foreach_visible()

macro2 foreach_visible ( bview view,
char  flags = 0,
Reduce  reductions = None 
)

Definition at line 308 of file draw.h.

References _i, cell(), L0, Point::level, mapped_position(), point, POINT_VARIABLES(), VertexBuffer, view(), x, y, and z.

Here is the call graph for this function:

◆ foreach_visible_stencil()

macro2 foreach_visible_stencil ( bview view,
char  flags,
Reduce  reductions 
)

Definition at line 333 of file draw.h.

References flags, foreach_stencil(), and reductions.

Here is the call graph for this function:

◆ glvertex2d()

static void glvertex2d ( bview view,
double  x,
double  y 
)
static

Definition at line 849 of file draw.h.

References glVertex2d, p, view(), x, and y.

Here is the call graph for this function:

◆ glvertex3d()

static void glvertex3d ( bview view,
double  x,
double  y,
double  z 
)
static

Definition at line 838 of file draw.h.

References glVertex3d, p, view(), x, y, and z.

Referenced by glvertex_normal3d().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ glvertex_normal3d()

static void glvertex_normal3d ( bview view,
Point  point,
vector  n,
double  xp,
double  yp,
double  zp 
)
static

Definition at line 859 of file draw.h.

References dimension, glNormal3d, glvertex3d(), interp(), n, point, v, view(), x, coord::x, and y.

Here is the call graph for this function:

◆ interp()

static double interp ( Point  point,
coord  p,
scalar  col 
)
inlinestatic

Definition at line 405 of file draw.h.

References interpolate_linear(), p, point, x, y, and z.

Referenced by glvertex_normal3d().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isoline()

trace bool isoline ( char phi,
double  val = 0.,
int  n = 1,
bool  edges = false,
double  larger = 0.,
int  filled = 0,
char color = NULL,
double  min = 0,
double  max = 0,
double  spread = 0,
bool  linear = false,
Colormap  map = jet,
float  fc[3] = {0},
float  lc[3] = {0},
float  lw = 1.,
bool  expr = false,
bool  cbar = false,
float  size = 15,
float  pos[2] = {-.95, -.95},
char label = "",
double  lscale = 1,
bool  horizontal = false,
bool  border = false,
bool  mid = false,
float  fsize = 50,
char format = "%g",
int  levels = 50 
)

<em>isoline()</em>: displays isolines

Draws a single isoline at val of field phi, or n isolines between min and max (included).

Extra parameters are the same as for draw_vof().

Definition at line 1071 of file draw.h.

Referenced by if().

Here is the caller graph for this function:

◆ isosurface()

trace bool isosurface ( char f,
double  v,
char color = NULL,
double  min = 0,
double  max = 0,
double  spread = 0,
bool  linear = false,
Colormap  map = jet,
float  fc[3] = {0},
float  lc[3] = {0},
float  lw = 1,
bool  expr = false,
bool  cbar = false,
float  size = 15,
float  pos[2] = {-.95, -.95},
char label = "",
double  lscale = 1,
bool  horizontal = false,
bool  border = false,
bool  mid = false,
float  fsize = 50,
char format = "%g",
int  levels = 50 
)

<em>isosurface()</em>: displays an isosurface of a field

f: the name (as a string) of the field. v: the value of the isosurface. edges: whether to draw the edges of isosurface facets. color: use this field to color each interface fragment.

The min, max, spread, map etc. arguments work as described in draw_vof().

Definition at line 1535 of file draw.h.

Referenced by if().

Here is the caller graph for this function:

◆ labels()

trace bool labels ( char f,
float  lc[3] = {0},
float  lw = 1,
int  level = -1 
)

<em>labels()</em>: displays label fields

Definition at line 1706 of file draw.h.

Referenced by if().

Here is the caller graph for this function:

◆ lines()

trace bool lines ( char file,
float  lc[3] = {0},
float  lw = 1. 
)

<em>lines()</em>: from a file.

file: the gnuplot-formatted file containing the polyline(s). lc[]: an array of red, green, blue values between 0 and 1 which defines the line color. lw: the line width.

Definition at line 1754 of file draw.h.

◆ mapped_position()

static void mapped_position ( bview view,
coord p,
double r 
)
static

Utility functions

The tree structure is used to traverse only the cells which are within the field of view of the camera.

Definition at line 292 of file draw.h.

References i, j, k, p, q, sq(), view(), vector::x, x, vector::y, y, and z.

Referenced by foreach_visible().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mirror()

macro mirror ( coord  n = {0},
double  alpha = 0. 
)

<em>mirror()</em>: symmetry relative to a plane.

The block following this command will be drawn in a coordinate system symmetric relative to the given plane. The plane is given by \(n\) and \(\alpha\) as explained in squares().

Definition at line 241 of file draw.h.

◆ squares()

trace bool squares ( char color,
char z = NULL,
double  min = 0,
double  max = 0,
double  spread = 0,
bool  linear = false,
Colormap  map = jet,
float  fc[3] = {0},
float  lc[3] = {0},
bool  expr = false,
coord  n = {0,0,1},
double  alpha = 0,
float  lw = 1,
bool  cbar = false,
float  size = 15,
float  pos[2] = {-.95, -.95},
char label = "",
double  lscale = 1,
bool  horizontal = false,
bool  border = false,
bool  mid = false,
float  fsize = 50,
char format = "%g",
int  levels = 50 
)

<em>squares()</em>: displays colormapped fields

The field name is given by color. The min, max, spread, map etc. arguments work as described in draw_vof().

In 2D, if z is specified, and linear is the true, the corresponding expression is used as z-coordinate.

In 3D the intersections of the field with a plane are displayed. The default plane is \(z=0\). This can be changed by setting n and alpha which define the plane

\[ n_x x + n_y y + n_z z = \alpha \]

Definition at line 1231 of file draw.h.

Referenced by if().

Here is the caller graph for this function:

◆ translate()

macro translate ( float  x = 0,
float  y = 0.,
float  z = 0. 
)

<em>translate()</em>: translates the origin.

The block following this command will be drawn in a translated coordinate system.

Definition at line 216 of file draw.h.

References _view, draw(), _bview::frustum, GL_MODELVIEW, glMatrixMode, glPopMatrix, glPushMatrix, glTranslatef, x, y, and z.

Here is the call graph for this function:

◆ travelling()

void travelling ( double  start = 0,
double  end = 0,
float  tx = 0,
float  ty = 0,
float  quat[4] = {0},
float  fov = 0 
)

Definition at line 1618 of file draw.h.

Referenced by if().

Here is the caller graph for this function:

◆ vectors()

trace bool vectors ( char u,
double  scale = 1,
float  lc[3] = {0},
float  lw = 1.,
int  level = -1 
)

<em>vectors()</em>: displays vector fields

The vectors are scaled using the scale factor.

Definition at line 1166 of file draw.h.

◆ view()

void view ( float  tx = 0.,
float  ty = 0.,
float  fov = 0.,
float  quat[4] = {0},
float  sx = 1.,
float  sy = 1.,
float  sz = 1.,
unsigned  width = 800,
unsigned  height = 800,
unsigned  samples = 4,
float  bg[3] = {0},
float  theta = 0.,
float  phi = 0.,
float  psi = 0.,
bool  relative = false,
float  tz = 0.,
float  near = 0.,
float  far = 0.,
float  res = 0.,
char camera = NULL,
MapFunc  map = NULL,
int  cache = 0,
float  p1x = 0.,
float  p1y = 0.,
float  p2x = 0.,
float  p2y = 0.,
bview view1 = NULL 
)

<em>view()</em>: sets up viewing parameters

tx, ty: shifts the camera center point. fov: changes the field-of-view. quat[]: the quaternion defining the camera angles. sx, sy, sz: stretch factors for each axis. width, height, samples: the width and height (in pixels) of the image to render (default is 800 x 800). The image can optionally be generated by first rendering an image with samples times more pixels in each direction followed by subsampling. This provides a form of antialiasing. Default is four samples. bg[]: an array of red, green, blue values between 0 and 1 which defines the background color. theta, phi, psi: Euler-like angles (in radians), used (instead of quat[]) to define the camera angle. relative: whether the theta and phi angles are absolute or relative to the current position (i.e. increments of the current angles). tz, near, far: an alternative way of specifying the camera, compatible with the camera parameters in interactive Basilisk View. camera: predefined camera angles: "left", "right", "top", "bottom", "front", "back" and "iso". map: an optional coordinate mapping function. cache: the maximum number of cached compiled expressions.

Definition at line 52 of file draw.h.

Referenced by bview_draw(), clear(), compile_expression(), compose_image(), draw(), draw_lines(), foreach_visible(), glvertex2d(), glvertex3d(), glvertex_normal3d(), if(), mapped_position(), process_line(), redraw(), save(), and vertex_buffer_glBegin().

Here is the caller graph for this function:

Variable Documentation

◆ [struct]

struct { ... } bview_interface[]
Initial value:
= {
{ _box_json },
{ NULL }
}
int _draw_vof_json(char *s, int len)
Definition draw_json.h:62
int _cells_json(char *s, int len)
Definition draw_json.h:132
int _labels_json(char *s, int len)
Definition draw_json.h:274
int _vectors_json(char *s, int len)
Definition draw_json.h:148
int _squares_json(char *s, int len)
Definition draw_json.h:166
int _box_json(char *s, int len)
Definition draw_json.h:194
int _isoline_json(char *s, int len)
Definition draw_json.h:96
int _lines_json(char *s, int len)
Definition draw_json.h:290

Interface export

This is used by bview to automatically generate the user interface.

Referenced by bview_interface_json().

◆ json

int(* json) (char *s, int len) ( char s,
int  len 
)

Definition at line 1815 of file draw.h.

Referenced by bview_interface_json().