├── .ocamlformat ├── .gitignore ├── src ├── dune ├── lowlevel.mli ├── lowlevel.ml ├── gr.ml └── gr.mli ├── gr.opam.template ├── examples ├── dune ├── example_simple.ml ├── example_complex.ml ├── example_lowlevel.ml └── example_dynamic.ml ├── CHANGES.md ├── dune-project ├── LICENSE ├── gr.opam └── README.md /.ocamlformat: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | .merlin 3 | *.install 4 | -------------------------------------------------------------------------------- /src/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name gr) 3 | (public_name gr) 4 | (libraries ctypes ctypes.foreign)) 5 | -------------------------------------------------------------------------------- /gr.opam.template: -------------------------------------------------------------------------------- 1 | doc: "https://mseri.github.io/ocaml-gr" 2 | post-messages: "Make sure that libGR (gr-framework.org) is installed and, in case of error, that either of the GRDIR or LIBGRPATH env variables is set" -------------------------------------------------------------------------------- /examples/dune: -------------------------------------------------------------------------------- 1 | (executables 2 | (names example_simple example_complex example_lowlevel example_dynamic) 3 | (libraries ctypes gr owl unix)) 4 | 5 | (alias 6 | (name runtest) 7 | (deps example_simple.exe example_complex.exe example_lowlevel.exe 8 | example_dynamic.exe)) 9 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # 0.0.2 (3-8-2021) 2 | 3 | - Makes more sense to show the ticks labels by default (Chris00 #9 5261354) 4 | - Use default ocamlformat output 5 | - Move to ocaml 4.10 and drop use of stdcompat 6 | - Fix use of GRDIR, make LIBGRPATH more standard and fix for macos dylib version (Chris00 #8 3056f1e) 7 | - Moved `workstation_type` into `Workstation`` 8 | - Cleanup of documentation 9 | 10 | # 0.0.1 (25-09-2019) 11 | - First release 12 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 1.11) 2 | 3 | (using fmt 1.2) 4 | 5 | (generate_opam_files true) 6 | 7 | (name gr) 8 | 9 | (source 10 | (github mseri/ocaml-gr)) 11 | 12 | (license ISC) 13 | 14 | (authors "Marcello Seri") 15 | 16 | (maintainers "Marcello Seri") 17 | 18 | (package 19 | (name gr) 20 | (synopsis "OCaml bindings to the GR plotting library") 21 | (description 22 | "GR is based on an implementation of a Graphical Kernel System (GKS) and OpenGL. As a self-contained system it can quickly and easily be integrated into existing applications.\nGR is characterized by its high interoperability and can be used with modern web technologies and mobile devices.") 23 | (depends 24 | (ocaml 25 | (>= 4.10)) 26 | (dune 27 | (>= 1.11)) 28 | (ctypes 29 | (>= 0.15)) 30 | (ctypes-foreign :true) 31 | (base-unix :with-test) 32 | (owl 33 | (and 34 | :with-test 35 | (>= 0.6.0))))) 36 | -------------------------------------------------------------------------------- /examples/example_simple.ml: -------------------------------------------------------------------------------- 1 | let wait_until_keypressed s = 2 | print_string s; 3 | let termio = Unix.tcgetattr Unix.stdin in 4 | let () = 5 | Unix.tcsetattr Unix.stdin Unix.TCSADRAIN 6 | { termio with Unix.c_icanon = false } 7 | in 8 | let _ = input_char stdin in 9 | Unix.tcsetattr Unix.stdin Unix.TCSADRAIN termio 10 | 11 | let () = 12 | let xarray = Owl.Arr.of_arrays [| [| 0.0; 0.2; 0.4; 0.6; 0.8; 1.0 |] |] in 13 | let yarray = Owl.Arr.of_arrays [| [| 0.3; 0.5; 0.4; 0.2; 0.6; 0.7 |] |] in 14 | let open Gr in 15 | polyline ~linetype:DASHED_DOTTED ~linewidth:0.7 ~coloridx:23 xarray yarray; 16 | let t = tick 0. 1. in 17 | axes t t; 18 | wait_until_keypressed "Press any key to continue"; 19 | Workstation.clear (); 20 | Owl.Arr.( 21 | polymarker ~markertype:CIRCLE ~markersize:3.0 ~coloridx:15 22 | (transpose xarray) (transpose yarray)); 23 | axes t t; 24 | wait_until_keypressed "Press any key to exit" 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Owl Numerical Library 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /gr.opam: -------------------------------------------------------------------------------- 1 | # This file is generated by dune, edit dune-project instead 2 | opam-version: "2.0" 3 | synopsis: "OCaml bindings to the GR plotting library" 4 | description: """ 5 | GR is based on an implementation of a Graphical Kernel System (GKS) and OpenGL. As a self-contained system it can quickly and easily be integrated into existing applications. 6 | GR is characterized by its high interoperability and can be used with modern web technologies and mobile devices.""" 7 | maintainer: ["Marcello Seri"] 8 | authors: ["Marcello Seri"] 9 | license: "ISC" 10 | homepage: "https://github.com/mseri/ocaml-gr" 11 | bug-reports: "https://github.com/mseri/ocaml-gr/issues" 12 | depends: [ 13 | "ocaml" {>= "4.10"} 14 | "dune" {>= "1.11"} 15 | "ctypes" {>= "0.15"} 16 | "ctypes-foreign" {true} 17 | "base-unix" {with-test} 18 | "owl" {with-test & >= "0.6.0"} 19 | ] 20 | build: [ 21 | ["dune" "subst"] {pinned} 22 | [ 23 | "dune" 24 | "build" 25 | "-p" 26 | name 27 | "-j" 28 | jobs 29 | "@install" 30 | "@runtest" {with-test} 31 | "@doc" {with-doc} 32 | ] 33 | ] 34 | dev-repo: "git+https://github.com/mseri/ocaml-gr.git" 35 | doc: "https://mseri.github.io/ocaml-gr" 36 | post-messages: "Make sure that libGR (gr-framework.org) is installed and, in case of error, that either of the GRDIR or LIBGRPATH env variables is set" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lowlevel bindigs to the [GR](http://gr-framework.org) plotting framework 2 | 3 | Based on version [0.37.0](https://github.com/sciapp/gr/tree/v0.37.0/lib/gks), the one installed by hombrew on osx (`brew install libgr`) at the time of creating the bindings. 4 | 5 | To install, first install `libGR` and set the `GRDIR` env variable, then run `opam install gr`. 6 | 7 | The documentation is published here: [online documentation](http://www.mseri.me/ocaml-gr/gr/index.html). 8 | 9 | Currently `libGr` is only looked via `GRDIR` or through the default library paths of your system. 10 | You can customise this by unsetting `GRDIR` and specifying the path to `libGR.so` (or `libGR.dylib`) with the environment variable `LIBGRPATH`. 11 | 12 | The tests are only compiling the examples. 13 | You can run them as follows: 14 | ``` 15 | $ GRDIR=~/gr dune exec examples/example_simple.exe 16 | $ GRDIR=~/gr dune exec examples/example_complex.exe 17 | $ GRDIR=~/gr dune exec examples/example_lowlevel.exe 18 | $ GRDIR=~/gr dune exec examples/example_dynamic.exe 19 | ``` 20 | Make sure that GRDIR or LIBGRPATH are pointing to the right path. 21 | 22 | ## Disclaimer 23 | 24 | Very incomplete: I don't know how to deal with the ``meta thingy'' in ctypes, and I have yet to bind the GKS library. 25 | 26 | At some point I would like to add a high level interface, but I cannot predict when I will be able to put in thee time. 27 | 28 | Contributions are welcome. -------------------------------------------------------------------------------- /examples/example_complex.ml: -------------------------------------------------------------------------------- 1 | let wait_until_keypressed () = 2 | print_string "Press any key to exit"; 3 | let termio = Unix.tcgetattr Unix.stdin in 4 | let () = 5 | Unix.tcsetattr Unix.stdin Unix.TCSADRAIN 6 | { termio with Unix.c_icanon = false } 7 | in 8 | let _ = input_char stdin in 9 | Unix.tcsetattr Unix.stdin Unix.TCSADRAIN termio 10 | 11 | let () = 12 | let open Owl in 13 | let xs = Arr.init [| 100 |] (fun _ -> -2.0 +. (4.0 *. Random.float 1.)) in 14 | let ys = Arr.init [| 100 |] (fun _ -> -2.0 +. (4.0 *. Random.float 1.)) in 15 | let zs = Arr.map2 (fun x y -> x *. exp (-.((x ** 2.) +. (y ** 2.)))) xs ys in 16 | let h = Arr.init [| 20 |] (fun i -> -0.5 +. (float_of_int i /. 19.0)) in 17 | let open Gr in 18 | (* Customise Style 19 | Note that we left 0.05 on the viewport ymax 20 | for the title *) 21 | set_viewport 0.1 0.95 0.1 0.9; 22 | set_window (-2.0) 2.0 (-2.0) 2.0; 23 | set_space (-0.5) 0.5 0 90 |> ignore; 24 | set_markersize 1.0; 25 | set_markertype SOLID_CIRCLE; 26 | set_char_height 0.024; 27 | set_text_align (Some CENTER) None; 28 | set_text_font_prec TIMES_ROMAN; 29 | (* Plot surface, contours and markers *) 30 | let xa, ya, za = gridit xs ys zs (200, 200) in 31 | surface ~options:CELL_ARRAY xa ya za; 32 | contour xa ya h za; 33 | polymarker xs ys; 34 | (* Plot the axes *) 35 | set_char_height 0.02; 36 | axes ~origin:(-2.0, -2.0) ~major:(2, 2) ~tick_size:0.01 0.25 0.25; 37 | (* Add the title *) 38 | set_char_height 0.025; 39 | math_tex (0.5, 0.9) 40 | {|\mbox{Attempt to plot tex stuff, e.g. } \int_0^1\sin(x)|}; 41 | (* Wait until keypressed... *) 42 | wait_until_keypressed () 43 | -------------------------------------------------------------------------------- /examples/example_lowlevel.ml: -------------------------------------------------------------------------------- 1 | let wait_until_keypressed () = 2 | print_string "Press any key to exit"; 3 | let termio = Unix.tcgetattr Unix.stdin in 4 | let () = 5 | Unix.tcsetattr Unix.stdin Unix.TCSADRAIN 6 | { termio with Unix.c_icanon = false } 7 | in 8 | let _ = input_char stdin in 9 | Unix.tcsetattr Unix.stdin Unix.TCSADRAIN termio 10 | 11 | let () = 12 | let to_carray = Ctypes.(CArray.of_list double) in 13 | let captr = Ctypes.CArray.start in 14 | let xs = List.init 100 (fun _ -> -2.0 +. (4.0 *. Random.float 1.)) in 15 | let ys = List.init 100 (fun _ -> -2.0 +. (4.0 *. Random.float 1.)) in 16 | let zs = 17 | List.fold_left2 18 | (fun acc x y -> (x *. exp (-.((x ** 2.) +. (y ** 2.)))) :: acc) 19 | [] xs ys 20 | |> List.rev |> to_carray 21 | in 22 | let xs = to_carray xs in 23 | let ys = to_carray ys in 24 | let xa = Ctypes.(CArray.make double 200) in 25 | let ya = Ctypes.(CArray.make double 200) in 26 | let za = Ctypes.(CArray.make double @@ (200 * 200)) in 27 | let open Gr.Lowlevel in 28 | setviewport 0.1 0.95 0.1 0.9; 29 | setwindow (-2.0) 2.0 (-2.0) 2.0; 30 | setspace (-0.5) 0.5 0 90 |> ignore; 31 | setmarkersize 1.0; 32 | setmarkertype (-1); 33 | setcharheight 0.024; 34 | settextalign 2 0; 35 | settextfontprec 101 0; 36 | gridit 100 (captr xs) (captr ys) (captr zs) 200 200 (captr xa) (captr ya) 37 | (captr za); 38 | let h = 39 | List.init 20 (fun i -> -0.5 +. (float_of_int i /. 19.0)) |> to_carray 40 | in 41 | surface 200 200 (captr xa) (captr ya) (captr za) 5; 42 | contour 200 200 20 (captr xa) (captr ya) (captr h) (captr za) 0; 43 | polymarker 100 (captr xs) (captr ys); 44 | axes 0.25 0.25 (-2.0) (-2.0) 2 2 0.01; 45 | mathtex 0.5 0.9 {|\mbox{Attempt to plot tex stuff, e.g. } \int_0^1\sin(x)|}; 46 | wait_until_keypressed () 47 | -------------------------------------------------------------------------------- /examples/example_dynamic.ml: -------------------------------------------------------------------------------- 1 | open Owl 2 | 3 | let of_array' a : Arr.arr = Arr.of_array a [| 2 |] 4 | 5 | let rk4 x h y f = 6 | let ( + ) = ( +. ) in 7 | let ( * ) = ( *. ) in 8 | let ( $* ) = Arr.( $* ) in 9 | let k1 = h $* f x y in 10 | let k2 = h $* f (x + (0.5 * h)) Arr.(y + (0.5 $* k1)) in 11 | let k3 = h $* f (x + (0.5 * h)) Arr.(y + (0.5 $* k2)) in 12 | let k4 = h $* f (x + h) Arr.(y + k3) in 13 | (x + h, Arr.(y + ((k1 + ((k2 + k3) *$ 2.0) + k4) /$ 6.0))) 14 | 15 | let damped_pendulum_deriv (gamma, length) _t state = 16 | let theta, omega = (Arr.get state [| 0 |], Arr.get state [| 1 |]) in 17 | of_array' 18 | [| omega; (~-.gamma *. omega) -. (9.81 /. length *. Maths.sin theta) |] 19 | 20 | let pendulum t theta omega acceleration = 21 | let open Gr in 22 | Workstation.clear (); 23 | set_viewport 0. 1. 0. 1.; 24 | let x = of_array' [| 0.5; 0.5 +. (Maths.sin theta *. 0.4) |] in 25 | let y = of_array' [| 0.8; 0.8 -. (Maths.cos theta *. 0.4) |] in 26 | let open Arr in 27 | (* draw pivot point *) 28 | fillarea 29 | (Arr.of_array [| 0.46; 0.54; 0.54; 0.46 |] [| 4 |]) 30 | (Arr.of_array [| 0.79; 0.79; 0.81; 0.81 |] [| 4 |]); 31 | polyline ~linewidth:1. ~coloridx:1 x y; 32 | (* draw rod *) 33 | polymarker ~markersize:5. ~markertype:SOLID_CIRCLE ~coloridx:86 34 | x.${[ 1 ]} 35 | y.${[ 1 ]}; 36 | (* draw rod *) 37 | let v = 0.05 *. omega in 38 | (* show angular velocity *) 39 | set_linecolorindex 4; 40 | Lowlevel.drawarrow x.%{1} y.%{1} 41 | (x.%{1} +. (v *. Maths.cos theta)) 42 | (y.%{1} +. (v *. Maths.sin theta)); 43 | set_linecolorindex 2; 44 | let a = 0.05 *. acceleration in 45 | (* show angular acceleration *) 46 | Lowlevel.drawarrow x.%{1} y.%{1} 47 | (x.%{1} +. (a *. Maths.sin theta)) 48 | (y.%{1} +. (v *. Maths.cos theta)); 49 | set_text_font_prec TIMES_BOLD ~precision:STRING; 50 | set_char_height 0.032; 51 | set_text_colorindex 1; 52 | tex_text (0.05, 0.925) "Damped Pendulum" |> ignore; 53 | set_char_height 0.040; 54 | math_tex (0.4, 0.22) {|\omega=\dot{\theta}|}; 55 | math_tex (0.4, 0.1) {|\dot{\omega}=-\gamma\omega-\frac{g}{l}sin(\theta)|}; 56 | set_char_height 0.028; 57 | tex_text (0.05, 0.22) @@ Printf.sprintf "t:%7.2f" t |> ignore; 58 | tex_text (0.05, 0.16) 59 | @@ Printf.sprintf "\\theta:%7.2f" (theta /. Float.pi *. 180.) 60 | |> ignore; 61 | set_text_colorindex 4; 62 | tex_text (0.05, 0.10) @@ Printf.sprintf "\\omega:%7.2f" omega |> ignore; 63 | set_text_colorindex 2; 64 | tex_text (0.05, 0.04) @@ Printf.sprintf "y_{a}:%6.2f" acceleration |> ignore; 65 | Workstation.update () 66 | 67 | let theta = 70.0 (* initial angle *) 68 | 69 | let gamma = 0.1 (* damping coefficient *) 70 | 71 | let length = 1.0 (* pendulum length *) 72 | 73 | let dt = 0.04 74 | 75 | let () = 76 | let state = ref @@ of_array' [| theta *. Float.pi /. 180.; 0. |] in 77 | let t = ref 0. in 78 | while !t < 30. do 79 | let t', state' = rk4 !t dt !state (damped_pendulum_deriv (gamma, length)) in 80 | t := t'; 81 | state := state'; 82 | let theta, omega = (Arr.get !state [| 0 |], Arr.get !state [| 1 |]) in 83 | let acceleration = 84 | Maths.sqrt (2.0 *. 9.81 *. length *. (1. -. Maths.cos theta)) 85 | in 86 | pendulum !t theta omega acceleration 87 | done 88 | -------------------------------------------------------------------------------- /src/lowlevel.mli: -------------------------------------------------------------------------------- 1 | (** 2 | {1 Lowlevel bindings to the GR-framewokr C interface.} 3 | 4 | For the documentation refer to the {{: https://gr-framework.org/c-gr.html} GR Reference}. 5 | 6 | The lookup of the "libGR.so" library can be overriden providing the full path to the library so file by setting the [LIBGRPATH] env variable. 7 | *) 8 | 9 | type vertex_t 10 | 11 | val vertex : vertex_t Ctypes.structure Ctypes.typ 12 | 13 | val vertex_x : (float, vertex_t Ctypes.structure) Ctypes.field 14 | 15 | val vertex_y : (float, vertex_t Ctypes.structure) Ctypes.field 16 | 17 | val opengks : unit -> unit 18 | 19 | val closegks : unit -> unit 20 | 21 | val inqdspsize : 22 | float Ctypes_static.ptr -> 23 | float Ctypes_static.ptr -> 24 | int Ctypes_static.ptr -> 25 | int Ctypes_static.ptr -> 26 | unit 27 | 28 | val openws : int -> string -> int -> unit 29 | 30 | val closews : int -> unit 31 | 32 | val activatews : int -> unit 33 | 34 | val deactivatews : int -> unit 35 | 36 | val clearws : unit -> unit 37 | 38 | val updatews : unit -> unit 39 | 40 | val polyline : int -> float Ctypes_static.ptr -> float Ctypes_static.ptr -> unit 41 | 42 | val polymarker : 43 | int -> float Ctypes_static.ptr -> float Ctypes_static.ptr -> unit 44 | 45 | val text : float -> float -> string -> unit 46 | 47 | val fillarea : int -> float Ctypes_static.ptr -> float Ctypes_static.ptr -> unit 48 | 49 | val cellarray : 50 | float -> 51 | float -> 52 | float -> 53 | float -> 54 | int -> 55 | int -> 56 | int -> 57 | int -> 58 | int -> 59 | int -> 60 | int Ctypes_static.ptr -> 61 | unit 62 | 63 | val gdp : 64 | int -> 65 | float Ctypes_static.ptr -> 66 | float Ctypes_static.ptr -> 67 | int -> 68 | int -> 69 | int Ctypes_static.ptr -> 70 | unit 71 | 72 | val spline : 73 | int -> 74 | float Ctypes_static.ptr -> 75 | float Ctypes_static.ptr -> 76 | int -> 77 | int -> 78 | unit 79 | 80 | val gridit : 81 | int -> 82 | float Ctypes_static.ptr -> 83 | float Ctypes_static.ptr -> 84 | float Ctypes_static.ptr -> 85 | int -> 86 | int -> 87 | float Ctypes_static.ptr -> 88 | float Ctypes_static.ptr -> 89 | float Ctypes_static.ptr -> 90 | unit 91 | 92 | val setlinetype : int -> unit 93 | 94 | val setlinewidth : float -> unit 95 | 96 | val setlinecolorind : int -> unit 97 | 98 | val setmarkertype : int -> unit 99 | 100 | val setmarkersize : float -> unit 101 | 102 | val setmarkercolorind : int -> unit 103 | 104 | val settextfontprec : int -> int -> unit 105 | 106 | val setcharexpan : float -> unit 107 | 108 | val setcharspace : float -> unit 109 | 110 | val settextcolorind : int -> unit 111 | 112 | val setcharheight : float -> unit 113 | 114 | val setcharup : float -> float -> unit 115 | 116 | val settextpath : int -> unit 117 | 118 | val settextalign : int -> int -> unit 119 | 120 | val setfillintstyle : int -> unit 121 | 122 | val setfillstyle : int -> unit 123 | 124 | val setfillcolorind : int -> unit 125 | 126 | val setcolorrep : int -> float -> float -> float -> unit 127 | 128 | val setwindow : float -> float -> float -> float -> unit 129 | 130 | val inqwindow : 131 | float Ctypes_static.ptr -> 132 | float Ctypes_static.ptr -> 133 | float Ctypes_static.ptr -> 134 | float Ctypes_static.ptr -> 135 | unit 136 | 137 | val setviewport : float -> float -> float -> float -> unit 138 | 139 | val inqviewport : 140 | float Ctypes_static.ptr -> 141 | float Ctypes_static.ptr -> 142 | float Ctypes_static.ptr -> 143 | float Ctypes_static.ptr -> 144 | unit 145 | 146 | val selntran : int -> unit 147 | 148 | val setclip : int -> unit 149 | 150 | val setwswindow : float -> float -> float -> float -> unit 151 | 152 | val setwsviewport : float -> float -> float -> float -> unit 153 | 154 | val createseg : int -> unit 155 | 156 | val copysegws : int -> unit 157 | 158 | val redrawsegws : unit -> unit 159 | 160 | val setsegtran : 161 | int -> float -> float -> float -> float -> float -> float -> float -> unit 162 | 163 | val closeseg : unit -> unit 164 | 165 | val emergencyclosegks : unit -> unit 166 | 167 | val updategks : unit -> unit 168 | 169 | val setspace : float -> float -> int -> int -> int 170 | 171 | val inqspace : 172 | float Ctypes_static.ptr -> 173 | float Ctypes_static.ptr -> 174 | int Ctypes_static.ptr -> 175 | int Ctypes_static.ptr -> 176 | unit 177 | 178 | val setscale : int -> int 179 | 180 | val inqscale : int Ctypes_static.ptr -> unit 181 | 182 | val textext : float -> float -> string -> int 183 | 184 | val inqtextext : 185 | float -> 186 | float -> 187 | string -> 188 | float Ctypes_static.ptr -> 189 | float Ctypes_static.ptr -> 190 | unit 191 | 192 | val axes : float -> float -> float -> float -> int -> int -> float -> unit 193 | 194 | val axeslbl : 195 | float -> 196 | float -> 197 | float -> 198 | float -> 199 | int -> 200 | int -> 201 | float -> 202 | (float -> float -> string -> float -> unit) -> 203 | (float -> float -> string -> float -> unit) -> 204 | unit 205 | 206 | val grid : float -> float -> float -> float -> int -> int -> unit 207 | 208 | val grid3d : 209 | float -> 210 | float -> 211 | float -> 212 | float -> 213 | float -> 214 | float -> 215 | int -> 216 | int -> 217 | int -> 218 | unit 219 | 220 | val verrorbars : 221 | int -> 222 | float Ctypes_static.ptr -> 223 | float Ctypes_static.ptr -> 224 | float Ctypes_static.ptr -> 225 | float Ctypes_static.ptr -> 226 | unit 227 | 228 | val herrorbars : 229 | int -> 230 | float Ctypes_static.ptr -> 231 | float Ctypes_static.ptr -> 232 | float Ctypes_static.ptr -> 233 | float Ctypes_static.ptr -> 234 | unit 235 | 236 | val polyline3d : 237 | int -> 238 | float Ctypes_static.ptr -> 239 | float Ctypes_static.ptr -> 240 | float Ctypes_static.ptr -> 241 | unit 242 | 243 | val polymarker3d : 244 | int -> 245 | float Ctypes_static.ptr -> 246 | float Ctypes_static.ptr -> 247 | float Ctypes_static.ptr -> 248 | unit 249 | 250 | val axes3d : 251 | float -> 252 | float -> 253 | float -> 254 | float -> 255 | float -> 256 | float -> 257 | int -> 258 | int -> 259 | int -> 260 | float -> 261 | unit 262 | 263 | val titles3d : string -> string -> string -> unit 264 | 265 | val surface : 266 | int -> 267 | int -> 268 | float Ctypes_static.ptr -> 269 | float Ctypes_static.ptr -> 270 | float Ctypes_static.ptr -> 271 | int -> 272 | unit 273 | 274 | val contour : 275 | int -> 276 | int -> 277 | int -> 278 | float Ctypes_static.ptr -> 279 | float Ctypes_static.ptr -> 280 | float Ctypes_static.ptr -> 281 | float Ctypes_static.ptr -> 282 | int -> 283 | unit 284 | 285 | val contourf : 286 | int -> 287 | int -> 288 | int -> 289 | float Ctypes_static.ptr -> 290 | float Ctypes_static.ptr -> 291 | float Ctypes_static.ptr -> 292 | float Ctypes_static.ptr -> 293 | int -> 294 | unit 295 | 296 | val tricontour : 297 | int -> 298 | float Ctypes_static.ptr -> 299 | float Ctypes_static.ptr -> 300 | float Ctypes_static.ptr -> 301 | int -> 302 | float Ctypes_static.ptr -> 303 | unit 304 | 305 | val hexbin : 306 | int -> float Ctypes_static.ptr -> float Ctypes_static.ptr -> int -> int 307 | 308 | val setcolormap : int -> unit 309 | 310 | val inqcolormap : int Ctypes_static.ptr -> unit 311 | 312 | val colorbar : unit -> unit 313 | 314 | val inqcolor : int -> int Ctypes_static.ptr -> unit 315 | 316 | val inqcolorfromrgb : float -> float -> float -> int 317 | 318 | val hsvtorgb : 319 | float -> 320 | float -> 321 | float -> 322 | float Ctypes_static.ptr -> 323 | float Ctypes_static.ptr -> 324 | float Ctypes_static.ptr -> 325 | unit 326 | 327 | val tick : float -> float -> float 328 | 329 | val validaterange : float -> float -> int 330 | 331 | val adjustlimits : float Ctypes_static.ptr -> float Ctypes_static.ptr -> unit 332 | 333 | val adjustrange : float Ctypes_static.ptr -> float Ctypes_static.ptr -> unit 334 | 335 | val beginprint : string -> unit 336 | 337 | val beginprintext : string -> string -> string -> string -> unit 338 | 339 | val endprint : unit -> unit 340 | 341 | val ndctowc : float Ctypes_static.ptr -> float Ctypes_static.ptr -> unit 342 | 343 | val wctondc : float Ctypes_static.ptr -> float Ctypes_static.ptr -> unit 344 | 345 | val wc3towc : 346 | float Ctypes_static.ptr -> 347 | float Ctypes_static.ptr -> 348 | float Ctypes_static.ptr -> 349 | unit 350 | 351 | val drawrect : float -> float -> float -> float -> unit 352 | 353 | val fillrect : float -> float -> float -> float -> unit 354 | 355 | val drawarc : float -> float -> float -> float -> int -> int -> unit 356 | 357 | val fillarc : float -> float -> float -> float -> int -> int -> unit 358 | 359 | val drawpath : 360 | int -> 361 | vertex_t Ctypes.structure Ctypes_static.ptr -> 362 | Unsigned.uchar Ctypes_static.ptr -> 363 | int -> 364 | unit 365 | 366 | val setarrowstyle : int -> unit 367 | 368 | val setarrowsize : float -> unit 369 | 370 | val drawarrow : float -> float -> float -> float -> unit 371 | 372 | val readimage : 373 | string -> 374 | int Ctypes_static.ptr -> 375 | int Ctypes_static.ptr -> 376 | int Ctypes_static.ptr Ctypes_static.ptr -> 377 | int 378 | 379 | val drawimage : 380 | float -> 381 | float -> 382 | float -> 383 | float -> 384 | int -> 385 | int -> 386 | int Ctypes_static.ptr -> 387 | int -> 388 | unit 389 | 390 | val importgraphics : string -> int 391 | 392 | val setshadow : float -> float -> float -> unit 393 | 394 | val settransparency : float -> unit 395 | 396 | val setcoordxform : float Ctypes_static.ptr Ctypes_static.ptr -> unit 397 | 398 | val begingraphics : string -> unit 399 | 400 | val endgraphics : unit -> unit 401 | 402 | val getgraphics : unit -> string 403 | 404 | val drawgraphics : string -> int 405 | 406 | val mathtex : float -> float -> string -> unit 407 | 408 | val inqmathtex : 409 | float -> 410 | float -> 411 | string -> 412 | float Ctypes_static.ptr -> 413 | float Ctypes_static.ptr -> 414 | unit 415 | 416 | val beginselection : int -> int -> unit 417 | 418 | val endselection : unit -> unit 419 | 420 | val moveselection : float -> float -> unit 421 | 422 | val resizeselection : int -> float -> float -> unit 423 | 424 | val inqbbox : 425 | float Ctypes_static.ptr -> 426 | float Ctypes_static.ptr -> 427 | float Ctypes_static.ptr -> 428 | float Ctypes_static.ptr -> 429 | unit 430 | 431 | val precision : unit -> float 432 | 433 | val setregenflags : int -> unit 434 | 435 | val inqregenflags : unit -> int 436 | 437 | val savestate : unit -> unit 438 | 439 | val restorestate : unit -> unit 440 | 441 | val selectcontext : int -> unit 442 | 443 | val destroycontext : int -> unit 444 | 445 | val uselinespec : string -> int 446 | 447 | val delaunay : 448 | int -> 449 | float Ctypes_static.ptr -> 450 | float Ctypes_static.ptr -> 451 | int Ctypes_static.ptr -> 452 | int Ctypes_static.ptr Ctypes_static.ptr -> 453 | unit 454 | 455 | val reducepoints : 456 | int -> 457 | float Ctypes_static.ptr -> 458 | float Ctypes_static.ptr -> 459 | int -> 460 | float Ctypes_static.ptr -> 461 | float Ctypes_static.ptr -> 462 | unit 463 | 464 | val trisurface : 465 | int -> 466 | float Ctypes_static.ptr -> 467 | float Ctypes_static.ptr -> 468 | float Ctypes_static.ptr -> 469 | unit 470 | 471 | val gradient : 472 | int -> 473 | int -> 474 | float Ctypes_static.ptr -> 475 | float Ctypes_static.ptr -> 476 | float Ctypes_static.ptr -> 477 | float Ctypes_static.ptr -> 478 | float Ctypes_static.ptr -> 479 | unit 480 | 481 | val quiver : 482 | int -> 483 | int -> 484 | float Ctypes_static.ptr -> 485 | float Ctypes_static.ptr -> 486 | float Ctypes_static.ptr -> 487 | float Ctypes_static.ptr -> 488 | int -> 489 | unit 490 | 491 | val interp2 : 492 | int -> 493 | int -> 494 | float Ctypes_static.ptr -> 495 | float Ctypes_static.ptr -> 496 | float Ctypes_static.ptr -> 497 | int -> 498 | int -> 499 | float Ctypes_static.ptr -> 500 | float Ctypes_static.ptr -> 501 | float Ctypes_static.ptr -> 502 | int -> 503 | float -> 504 | unit 505 | 506 | val version : unit -> string 507 | 508 | val shade : 509 | int -> 510 | float Ctypes_static.ptr -> 511 | float Ctypes_static.ptr -> 512 | int -> 513 | int -> 514 | float Ctypes_static.ptr -> 515 | int -> 516 | int -> 517 | int Ctypes_static.ptr -> 518 | unit 519 | 520 | val shadepoints : 521 | int -> 522 | float Ctypes_static.ptr -> 523 | float Ctypes_static.ptr -> 524 | int -> 525 | int -> 526 | int -> 527 | unit 528 | 529 | val shadelines : 530 | int -> 531 | float Ctypes_static.ptr -> 532 | float Ctypes_static.ptr -> 533 | int -> 534 | int -> 535 | int -> 536 | unit 537 | 538 | val panzoom : 539 | float -> 540 | float -> 541 | float -> 542 | float Ctypes_static.ptr -> 543 | float Ctypes_static.ptr -> 544 | float Ctypes_static.ptr -> 545 | float Ctypes_static.ptr -> 546 | unit 547 | 548 | val get_size_and_pointers : 549 | ('a, 'b, 'c) Bigarray.Genarray.t -> 550 | ('d, 'e, 'f) Bigarray.Genarray.t -> 551 | int * 'a Ctypes.ptr * 'd Ctypes.ptr 552 | 553 | val get_size_and_pointer : 554 | ('a, 'b, 'c) Bigarray.Genarray.t -> int * 'a Ctypes.ptr 555 | -------------------------------------------------------------------------------- /src/lowlevel.ml: -------------------------------------------------------------------------------- 1 | open Ctypes 2 | open Foreign 3 | 4 | (* version >= 0.37.0 *) 5 | 6 | (* The API is documented here: https://gr-framework.org/c-gr.html *) 7 | (* See also https://gr-framework.org/about.html - at a certain point it would be nice to also have bindings for GKS and GR3 *) 8 | 9 | (** {1} Lowlevel API bindings *) 10 | let libGRpath = 11 | let path = 12 | try Sys.getenv "LIBGRPATH" 13 | with Not_found -> ( 14 | try Sys.getenv "GRDIR" ^ "/lib/" with Not_found -> "") 15 | in 16 | let lib = path ^ "libGR." in 17 | (* brittle, temporary until we move to use generated stubs *) 18 | let ext = if Sys.file_exists (lib ^ "dylib") then "dylib" else "so" in 19 | lib ^ ext 20 | 21 | let libGR = Dl.dlopen ~flags:[ Dl.RTLD_LAZY ] ~filename:libGRpath 22 | 23 | let foreign = foreign ~from:libGR 24 | 25 | type vertex_t 26 | 27 | let vertex : vertex_t structure typ = structure "vertex_t" 28 | 29 | let vertex_x = field vertex "x" double 30 | 31 | let vertex_y = field vertex "y" double 32 | 33 | let () = seal vertex 34 | 35 | let opengks = foreign "gr_opengks" (void @-> returning void) 36 | 37 | let closegks = foreign "gr_closegks" (void @-> returning void) 38 | 39 | let inqdspsize = 40 | foreign "gr_inqdspsize" 41 | (ptr double @-> ptr double @-> ptr int @-> ptr int @-> returning void) 42 | 43 | (* void let openws = foreign "gr_openws" (int workstation_id @-> ptr charconnection @-> int type) 44 | workstation_id: a workstation identifier 45 | connection: a connection identifier 46 | type: the desired workstation type 47 | *) 48 | let openws = foreign "gr_openws" (int @-> string @-> int @-> returning void) 49 | 50 | let closews = foreign "gr_closews" (int @-> returning void) 51 | 52 | let activatews = foreign "gr_activatews" (int @-> returning void) 53 | 54 | let deactivatews = foreign "gr_deactivatews" (int @-> returning void) 55 | 56 | let clearws = foreign "gr_clearws" (void @-> returning void) 57 | 58 | let updatews = foreign "gr_updatews" (void @-> returning void) 59 | 60 | (* let polyline = foreign "gr_polyline" (int n @-> ptr doublex @-> ptr doubley) 61 | Draw a polyline using the current line attributes @-> starting from the first data point and ending at the last data point. 62 | The values for x and y are in world coordinates. 63 | The attributes that control the appearance of a polyline are linetype @-> linewidth and color index. 64 | 65 | Parameters 66 | n: The number of points 67 | x: A pointer to the X coordinates 68 | y: A pointer to the Y coordinates 69 | *) 70 | let polyline = 71 | foreign "gr_polyline" (int @-> ptr double @-> ptr double @-> returning void) 72 | 73 | let polymarker = 74 | foreign "gr_polymarker" (int @-> ptr double @-> ptr double @-> returning void) 75 | 76 | let text = foreign "gr_text" (double @-> double @-> string @-> returning void) 77 | 78 | (* 79 | (* Can be nasty to deal with: 80 | https://discuss.ocaml.org/t/ctypes-pass-ocaml-bytes-to-c-functions/2156/4 81 | http://lists.ocaml.org/pipermail/ctypes/2017-December/000248.html *) 82 | let inqtext = 83 | foreign 84 | "gr_inqtext" 85 | (double @-> double @-> ptr char @-> ptr double @-> ptr double @-> returning void) 86 | *) 87 | 88 | let fillarea = 89 | foreign "gr_fillarea" (int @-> ptr double @-> ptr double @-> returning void) 90 | 91 | let cellarray = 92 | foreign "gr_cellarray" 93 | (double @-> double @-> double @-> double @-> int @-> int @-> int @-> int 94 | @-> int @-> int @-> ptr int @-> returning void) 95 | 96 | let gdp = 97 | foreign "gr_gdp" 98 | (int @-> ptr double @-> ptr double @-> int @-> int @-> ptr int 99 | @-> returning void) 100 | 101 | let spline = 102 | foreign "gr_spline" 103 | (int @-> ptr double @-> ptr double @-> int @-> int @-> returning void) 104 | 105 | let gridit = 106 | foreign "gr_gridit" 107 | (int @-> ptr double @-> ptr double @-> ptr double @-> int @-> int 108 | @-> ptr double @-> ptr double @-> ptr double @-> returning void) 109 | 110 | let setlinetype = foreign "gr_setlinetype" (int @-> returning void) 111 | 112 | (* let inqlinetype = foreign "gr_inqlinetype" (ptr int @-> returning void) *) 113 | let setlinewidth = foreign "gr_setlinewidth" (double @-> returning void) 114 | 115 | (* let inqlinewidth = foreign "gr_inqlinewidth" (ptr double @-> returning void) *) 116 | let setlinecolorind = foreign "gr_setlinecolorind" (int @-> returning void) 117 | 118 | (* let inqlinecolorind = foreign "gr_inqlinecolorind" (ptr int @-> returning void) *) 119 | let setmarkertype = foreign "gr_setmarkertype" (int @-> returning void) 120 | 121 | (* let inqmarkertype = foreign "gr_inqmarkertype" (ptr int @-> returning void) *) 122 | let setmarkersize = foreign "gr_setmarkersize" (double @-> returning void) 123 | 124 | let setmarkercolorind = foreign "gr_setmarkercolorind" (int @-> returning void) 125 | 126 | (* let inqmarkercolorind = foreign "gr_inqmarkercolorind" (ptr int @-> returning void) *) 127 | let settextfontprec = 128 | foreign "gr_settextfontprec" (int @-> int @-> returning void) 129 | 130 | let setcharexpan = foreign "gr_setcharexpan" (double @-> returning void) 131 | 132 | let setcharspace = foreign "gr_setcharspace" (double @-> returning void) 133 | 134 | let settextcolorind = foreign "gr_settextcolorind" (int @-> returning void) 135 | 136 | let setcharheight = foreign "gr_setcharheight" (double @-> returning void) 137 | 138 | let setcharup = foreign "gr_setcharup" (double @-> double @-> returning void) 139 | 140 | let settextpath = foreign "gr_settextpath" (int @-> returning void) 141 | 142 | let settextalign = foreign "gr_settextalign" (int @-> int @-> returning void) 143 | 144 | let setfillintstyle = foreign "gr_setfillintstyle" (int @-> returning void) 145 | 146 | let setfillstyle = foreign "gr_setfillstyle" (int @-> returning void) 147 | 148 | let setfillcolorind = foreign "gr_setfillcolorind" (int @-> returning void) 149 | 150 | let setcolorrep = 151 | foreign "gr_setcolorrep" 152 | (int @-> double @-> double @-> double @-> returning void) 153 | 154 | let setwindow = 155 | foreign "gr_setwindow" 156 | (double @-> double @-> double @-> double @-> returning void) 157 | 158 | let inqwindow = 159 | foreign "gr_inqwindow" 160 | (ptr double @-> ptr double @-> ptr double @-> ptr double @-> returning void) 161 | 162 | let setviewport = 163 | foreign "gr_setviewport" 164 | (double @-> double @-> double @-> double @-> returning void) 165 | 166 | let inqviewport = 167 | foreign "gr_inqviewport" 168 | (ptr double @-> ptr double @-> ptr double @-> ptr double @-> returning void) 169 | 170 | let selntran = foreign "gr_selntran" (int @-> returning void) 171 | 172 | let setclip = foreign "gr_setclip" (int @-> returning void) 173 | 174 | let setwswindow = 175 | foreign "gr_setwswindow" 176 | (double @-> double @-> double @-> double @-> returning void) 177 | 178 | let setwsviewport = 179 | foreign "gr_setwsviewport" 180 | (double @-> double @-> double @-> double @-> returning void) 181 | 182 | let createseg = foreign "gr_createseg" (int @-> returning void) 183 | 184 | let copysegws = foreign "gr_copysegws" (int @-> returning void) 185 | 186 | let redrawsegws = foreign "gr_redrawsegws" (void @-> returning void) 187 | 188 | let setsegtran = 189 | foreign "gr_setsegtran" 190 | (int @-> double @-> double @-> double @-> double @-> double @-> double 191 | @-> double @-> returning void) 192 | 193 | let closeseg = foreign "gr_closeseg" (void @-> returning void) 194 | 195 | let emergencyclosegks = foreign "gr_emergencyclosegks" (void @-> returning void) 196 | 197 | let updategks = foreign "gr_updategks" (void @-> returning void) 198 | 199 | let setspace = 200 | foreign "gr_setspace" (double @-> double @-> int @-> int @-> returning int) 201 | 202 | let inqspace = 203 | foreign "gr_inqspace" 204 | (ptr double @-> ptr double @-> ptr int @-> ptr int @-> returning void) 205 | 206 | let setscale = foreign "gr_setscale" (int @-> returning int) 207 | 208 | let inqscale = foreign "gr_inqscale" (ptr int @-> returning void) 209 | 210 | let textext = 211 | foreign "gr_textext" (double @-> double @-> string @-> returning int) 212 | 213 | let inqtextext = 214 | foreign "gr_inqtextext" 215 | (double @-> double @-> string @-> ptr double @-> ptr double 216 | @-> returning void) 217 | 218 | (* 219 | void let axes = foreign "gr_axes" (double x_tick @-> double y_tick @-> double x_org @-> double y_org @-> int major_x @-> int major_y @-> double tick_size) 220 | 221 | Draw X and Y coordinate axes with linearly and/or logarithmically spaced tick marks. 222 | Tick marks are positioned along each axis so that major tick marks fall on the axes origin (whether visible or not). 223 | Major tick marks are labeled with the corresponding data values. 224 | Axes are drawn according to the scale of the window. 225 | Axes and tick marks are drawn using solid lines; line color and width can be modified using the let setlinetype = foreign "gr_setlinetype" and let setlinewidth = foreign "gr_setlinewidth" functions. 226 | Axes are drawn according to the linear or logarithmic transformation established by the let setscale = foreign "gr_setscale" function. 227 | 228 | Parameters 229 | x_tick: The interval between minor tick marks on the X axis. 230 | y_tick: The interval between minor tick marks on the Y axis. 231 | x_org: The world coordinate of the origin (point of intersection) of the X axis. 232 | y_org: The world coordinate of the origin (point of intersection) of the Y axis. 233 | major_x: Unitless integer value specifying the number of minor tick intervals between major tick marks on the X axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis. 234 | major_y: Unitless integer value specifying the number of minor tick intervals between major tick marks on the Y axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis. 235 | tick_size: The length of minor tick marks specified in a normalized device coordinate unit. Major tick marks are twice as long as minor tick marks. A negative value reverses the tick marks on the axes from inward facing to outward facing (or vice versa) 236 | *) 237 | let axes = 238 | foreign "gr_axes" 239 | (double @-> double @-> double @-> double @-> int @-> int @-> double 240 | @-> returning void) 241 | 242 | let axeslbl = 243 | foreign "gr_axeslbl" 244 | (double @-> double @-> double @-> double @-> int @-> int @-> double 245 | @-> funptr (double @-> double @-> string @-> double @-> returning void) 246 | @-> funptr (double @-> double @-> string @-> double @-> returning void) 247 | @-> returning void) 248 | 249 | let grid = 250 | foreign "gr_grid" 251 | (double @-> double @-> double @-> double @-> int @-> int @-> returning void) 252 | 253 | let grid3d = 254 | foreign "gr_grid3d" 255 | (double @-> double @-> double @-> double @-> double @-> double @-> int 256 | @-> int @-> int @-> returning void) 257 | 258 | let verrorbars = 259 | foreign "gr_verrorbars" 260 | (int @-> ptr double @-> ptr double @-> ptr double @-> ptr double 261 | @-> returning void) 262 | 263 | let herrorbars = 264 | foreign "gr_herrorbars" 265 | (int @-> ptr double @-> ptr double @-> ptr double @-> ptr double 266 | @-> returning void) 267 | 268 | let polyline3d = 269 | foreign "gr_polyline3d" 270 | (int @-> ptr double @-> ptr double @-> ptr double @-> returning void) 271 | 272 | let polymarker3d = 273 | foreign "gr_polymarker3d" 274 | (int @-> ptr double @-> ptr double @-> ptr double @-> returning void) 275 | 276 | let axes3d = 277 | foreign "gr_axes3d" 278 | (double @-> double @-> double @-> double @-> double @-> double @-> int 279 | @-> int @-> int @-> double @-> returning void) 280 | 281 | let titles3d = 282 | foreign "gr_titles3d" (string @-> string @-> string @-> returning void) 283 | 284 | let surface = 285 | foreign "gr_surface" 286 | (int @-> int @-> ptr double @-> ptr double @-> ptr double @-> int 287 | @-> returning void) 288 | 289 | let contour = 290 | foreign "gr_contour" 291 | (int @-> int @-> int @-> ptr double @-> ptr double @-> ptr double 292 | @-> ptr double @-> int @-> returning void) 293 | 294 | let contourf = 295 | foreign "gr_contourf" 296 | (int @-> int @-> int @-> ptr double @-> ptr double @-> ptr double 297 | @-> ptr double @-> int @-> returning void) 298 | 299 | let tricontour = 300 | foreign "gr_tricontour" 301 | (int @-> ptr double @-> ptr double @-> ptr double @-> int @-> ptr double 302 | @-> returning void) 303 | 304 | let hexbin = 305 | foreign "gr_hexbin" 306 | (int @-> ptr double @-> ptr double @-> int @-> returning int) 307 | 308 | let setcolormap = foreign "gr_setcolormap" (int @-> returning void) 309 | 310 | let inqcolormap = foreign "gr_inqcolormap" (ptr int @-> returning void) 311 | 312 | let colorbar = foreign "gr_colorbar" (void @-> returning void) 313 | 314 | let inqcolor = foreign "gr_inqcolor" (int @-> ptr int @-> returning void) 315 | 316 | let inqcolorfromrgb = 317 | foreign "gr_inqcolorfromrgb" (double @-> double @-> double @-> returning int) 318 | 319 | let hsvtorgb = 320 | foreign "gr_hsvtorgb" 321 | (double @-> double @-> double @-> ptr double @-> ptr double @-> ptr double 322 | @-> returning void) 323 | 324 | let tick = foreign "gr_tick" (double @-> double @-> returning double) 325 | 326 | let validaterange = 327 | foreign "gr_validaterange" (double @-> double @-> returning int) 328 | 329 | let adjustlimits = 330 | foreign "gr_adjustlimits" (ptr double @-> ptr double @-> returning void) 331 | 332 | let adjustrange = 333 | foreign "gr_adjustrange" (ptr double @-> ptr double @-> returning void) 334 | 335 | let beginprint = foreign "gr_beginprint" (string @-> returning void) 336 | 337 | let beginprintext = 338 | foreign "gr_beginprintext" 339 | (string @-> string @-> string @-> string @-> returning void) 340 | 341 | let endprint = foreign "gr_endprint" (void @-> returning void) 342 | 343 | let ndctowc = foreign "gr_ndctowc" (ptr double @-> ptr double @-> returning void) 344 | 345 | let wctondc = foreign "gr_wctondc" (ptr double @-> ptr double @-> returning void) 346 | 347 | let wc3towc = 348 | foreign "gr_wc3towc" 349 | (ptr double @-> ptr double @-> ptr double @-> returning void) 350 | 351 | let drawrect = 352 | foreign "gr_drawrect" 353 | (double @-> double @-> double @-> double @-> returning void) 354 | 355 | let fillrect = 356 | foreign "gr_fillrect" 357 | (double @-> double @-> double @-> double @-> returning void) 358 | 359 | let drawarc = 360 | foreign "gr_drawarc" 361 | (double @-> double @-> double @-> double @-> int @-> int @-> returning void) 362 | 363 | let fillarc = 364 | foreign "gr_fillarc" 365 | (double @-> double @-> double @-> double @-> int @-> int @-> returning void) 366 | 367 | let drawpath = 368 | foreign "gr_drawpath" 369 | (int @-> ptr vertex @-> ptr uchar @-> int @-> returning void) 370 | 371 | let setarrowstyle = foreign "gr_setarrowstyle" (int @-> returning void) 372 | 373 | let setarrowsize = foreign "gr_setarrowsize" (double @-> returning void) 374 | 375 | let drawarrow = 376 | foreign "gr_drawarrow" 377 | (double @-> double @-> double @-> double @-> returning void) 378 | 379 | let readimage = 380 | foreign "gr_readimage" 381 | (string @-> ptr int @-> ptr int @-> ptr (ptr int) @-> returning int) 382 | 383 | let drawimage = 384 | foreign "gr_drawimage" 385 | (double @-> double @-> double @-> double @-> int @-> int @-> ptr int @-> int 386 | @-> returning void) 387 | 388 | let importgraphics = foreign "gr_importgraphics" (string @-> returning int) 389 | 390 | let setshadow = 391 | foreign "gr_setshadow" (double @-> double @-> double @-> returning void) 392 | 393 | let settransparency = foreign "gr_settransparency" (double @-> returning void) 394 | 395 | (* This should be an actual double[3][2] *) 396 | let setcoordxform = 397 | foreign "gr_setcoordxform" (ptr (ptr double) @-> returning void) 398 | 399 | let begingraphics = foreign "gr_begingraphics" (string @-> returning void) 400 | 401 | let endgraphics = foreign "gr_endgraphics" (void @-> returning void) 402 | 403 | let getgraphics = foreign "gr_getgraphics" (void @-> returning string) 404 | 405 | let drawgraphics = foreign "gr_drawgraphics" (string @-> returning int) 406 | 407 | let mathtex = 408 | foreign "gr_mathtex" (double @-> double @-> string @-> returning void) 409 | 410 | let inqmathtex = 411 | foreign "gr_inqmathtex" 412 | (double @-> double @-> string @-> ptr double @-> ptr double 413 | @-> returning void) 414 | 415 | let beginselection = foreign "gr_beginselection" (int @-> int @-> returning void) 416 | 417 | let endselection = foreign "gr_endselection" (void @-> returning void) 418 | 419 | let moveselection = 420 | foreign "gr_moveselection" (double @-> double @-> returning void) 421 | 422 | let resizeselection = 423 | foreign "gr_resizeselection" (int @-> double @-> double @-> returning void) 424 | 425 | let inqbbox = 426 | foreign "gr_inqbbox" 427 | (ptr double @-> ptr double @-> ptr double @-> ptr double @-> returning void) 428 | 429 | let precision = foreign "gr_precision" (void @-> returning double) 430 | 431 | let setregenflags = foreign "gr_setregenflags" (int @-> returning void) 432 | 433 | let inqregenflags = foreign "gr_inqregenflags" (void @-> returning int) 434 | 435 | let savestate = foreign "gr_savestate" (void @-> returning void) 436 | 437 | let restorestate = foreign "gr_restorestate" (void @-> returning void) 438 | 439 | let selectcontext = foreign "gr_selectcontext" (int @-> returning void) 440 | 441 | let destroycontext = foreign "gr_destroycontext" (int @-> returning void) 442 | 443 | let uselinespec = foreign "gr_uselinespec" (string @-> returning int) 444 | 445 | let delaunay = 446 | foreign "gr_delaunay" 447 | (int @-> ptr double @-> ptr double @-> ptr int 448 | @-> ptr (ptr int) 449 | @-> returning void) 450 | 451 | let reducepoints = 452 | foreign "gr_reducepoints" 453 | (int @-> ptr double @-> ptr double @-> int @-> ptr double @-> ptr double 454 | @-> returning void) 455 | 456 | let trisurface = 457 | foreign "gr_trisurface" 458 | (int @-> ptr double @-> ptr double @-> ptr double @-> returning void) 459 | 460 | let gradient = 461 | foreign "gr_gradient" 462 | (int @-> int @-> ptr double @-> ptr double @-> ptr double @-> ptr double 463 | @-> ptr double @-> returning void) 464 | 465 | let quiver = 466 | foreign "gr_quiver" 467 | (int @-> int @-> ptr double @-> ptr double @-> ptr double @-> ptr double 468 | @-> int @-> returning void) 469 | 470 | let interp2 = 471 | foreign "gr_interp2" 472 | (int @-> int @-> ptr double @-> ptr double @-> ptr double @-> int @-> int 473 | @-> ptr double @-> ptr double @-> ptr double @-> int @-> double 474 | @-> returning void) 475 | 476 | (* 477 | (* omitting meta_args_t for now *) 478 | DLLEXPORT gr_meta_args_t *gr_newmeta(void); 479 | DLLEXPORT void gr_deletemeta(gr_meta_args_t * ); 480 | DLLEXPORT void gr_meta_args_push_arg(gr_meta_args_t *, const char *, ..); 481 | DLLEXPORT void gr_meta_args_push_arg_buf( 482 | gr_meta_args_t *, const char *, const void *, int); 483 | DLLEXPORT void gr_meta_args_push_kwarg( 484 | gr_meta_args_t *, const char *, const char *, .. ); 485 | DLLEXPORT void gr_meta_args_push_kwarg_buf( 486 | gr_meta_args_t *, const char *, const char *, const void *, int); 487 | DLLEXPORT void *gr_openmeta( 488 | int, const char *, unsigned int, const char *( * )(const char *, unsigned int), 489 | int ( * )(const char *, unsigned int, const char * )); 490 | DLLEXPORT gr_meta_args_t *gr_recvmeta(const void *p, gr_meta_args_t * ); 491 | DLLEXPORT int gr_sendmeta(const void *, const char *, .. ); 492 | DLLEXPORT int gr_sendmeta_buf(const void *, const char *, const void *, int); 493 | DLLEXPORT int gr_sendmeta_ref(const void *, const char *, char, const void *, int); 494 | DLLEXPORT int gr_sendmeta_args(const void *p, const gr_meta_args_t * ); 495 | DLLEXPORT void gr_closemeta(const void * ); 496 | DLLEXPORT int gr_plotmeta(const gr_meta_args_t * ); 497 | DLLEXPORT int gr_readmeta(gr_meta_args_t *, const char * ); 498 | #ifndef NDEBUG 499 | DLLEXPORT void gr_dumpmeta(const gr_meta_args_t *, FILE * ); 500 | DLLEXPORT void gr_dumpmeta_json(const gr_meta_args_t *, FILE * ); 501 | #endif 502 | *) 503 | let version = foreign "gr_version" (void @-> returning string) 504 | 505 | let shade = 506 | foreign "gr_shade" 507 | (int @-> ptr double @-> ptr double @-> int @-> int @-> ptr double @-> int 508 | @-> int @-> ptr int @-> returning void) 509 | 510 | let shadepoints = 511 | foreign "gr_shadepoints" 512 | (int @-> ptr double @-> ptr double @-> int @-> int @-> int 513 | @-> returning void) 514 | 515 | let shadelines = 516 | foreign "gr_shadelines" 517 | (int @-> ptr double @-> ptr double @-> int @-> int @-> int 518 | @-> returning void) 519 | 520 | let panzoom = 521 | foreign "gr_panzoom" 522 | (double @-> double @-> double @-> ptr double @-> ptr double @-> ptr double 523 | @-> ptr double @-> returning void) 524 | 525 | (** {2} Helpers *) 526 | 527 | let get_size_and_pointers x y = 528 | let xd = Bigarray.Genarray.dims x in 529 | let yd = Bigarray.Genarray.dims y in 530 | let n = 531 | match (xd, yd) with 532 | | [| lx |], [| ly |] when lx = ly -> lx 533 | | [| 1; lx |], [| 1; ly |] when lx = ly -> lx 534 | | [| lx; 1 |], [| ly; 1 |] when lx = ly -> lx 535 | | [| lx |], [| ly |] -> 536 | raise 537 | @@ Invalid_argument 538 | (Printf.sprintf "Arrays of different lenghts: %d, %d" lx ly) 539 | | [| 1; lx |], [| 1; ly |] -> 540 | raise 541 | @@ Invalid_argument 542 | (Printf.sprintf "Arrays of different lenghts: %d, %d" lx ly) 543 | | [| lx; 1 |], [| ly; 1 |] -> 544 | raise 545 | @@ Invalid_argument 546 | (Printf.sprintf "Arrays of different lenghts: %d, %d" lx ly) 547 | | _ -> 548 | raise @@ Invalid_argument (Printf.sprintf "Incompatible arrays shape") 549 | in 550 | let x = Ctypes.(bigarray_start genarray x) in 551 | let y = Ctypes.(bigarray_start genarray y) in 552 | (n, x, y) 553 | 554 | let get_size_and_pointer x = 555 | let xd = Bigarray.Genarray.dims x in 556 | let n = 557 | match xd with 558 | | [| lx |] -> lx 559 | | [| 1; lx |] -> lx 560 | | [| lx; 1 |] -> lx 561 | | _ -> raise @@ Invalid_argument "Array of invalid dimension" 562 | in 563 | let x = Ctypes.(bigarray_start genarray x) in 564 | (n, x) 565 | -------------------------------------------------------------------------------- /src/gr.ml: -------------------------------------------------------------------------------- 1 | module Lowlevel = Lowlevel 2 | 3 | (** Available line types, see also {{: https://gr-framework.org/linetypes.html} GR Line Types} *) 4 | type linetype = 5 | | SOLID (** Solid line *) 6 | | DASHED (** Dashed line *) 7 | | DOTTED (** Dotted line *) 8 | | DASHED_DOTTED (** Dashed-dotted line *) 9 | | DASH_2_DOT (** Sequence of one dash followed by two dots *) 10 | | DASH_3_DOT (** Sequence of one dash followed by three dots *) 11 | | LONG_DASH (** Sequence of long dashes *) 12 | | LONG_SHORT_DASH (** Sequence of a long dash followed by a short dash *) 13 | | SPACED_DASH (** Sequence of dashes double spaced *) 14 | | SPACED_DOT (** Sequence of dots double spaced *) 15 | | DOUBLE_DOT (** Sequence of pairs of dots *) 16 | | TRIPLE_DOT (** Sequence of groups of three dots *) 17 | 18 | let int_of_linetype = function 19 | | SOLID -> 1 20 | | DASHED -> 2 21 | | DOTTED -> 3 22 | | DASHED_DOTTED -> 4 23 | | DASH_2_DOT -> -1 24 | | DASH_3_DOT -> -2 25 | | LONG_DASH -> -3 26 | | LONG_SHORT_DASH -> -4 27 | | SPACED_DASH -> -5 28 | | SPACED_DOT -> -6 29 | | DOUBLE_DOT -> -7 30 | | TRIPLE_DOT -> -8 31 | 32 | (* let linetype_of_int = function 33 | | 1 -> SOLID 34 | | 2 -> DASHED 35 | | 3 -> DOTTED 36 | | 4 -> DASHED_DOTTED 37 | | -1 -> DASH_2_DOT 38 | | -2 -> DASH_3_DOT 39 | | -3 -> LONG_DASH 40 | | -4 -> LONG_SHORT_DASH 41 | | -5 -> SPACED_DASH 42 | | -6 -> SPACED_DOT 43 | | -7 -> DOUBLE_DOT 44 | | -8 -> TRIPLE_DOT 45 | | d -> failwith @@ "Error when inferring line type. Got " ^ string_of_int d *) 46 | 47 | (** Available marker types, see also {{: https://gr-framework.org/markertypes.html} GR Marker Types} *) 48 | type markertype = 49 | | DOT (** Smallest displayable dot *) 50 | | PLUS (** Plus sign *) 51 | | ASTERISK (** Asterisk *) 52 | | CIRCLE (** Hollow circle *) 53 | | DIAGONAL_CROSS (** Diagonal cross *) 54 | | SOLID_CIRCLE (** Filled circle *) 55 | | TRIANGLE_UP (** Hollow triangle pointing upward *) 56 | | SOLID_TRI_UP (** Filled triangle pointing upward *) 57 | | TRIANGLE_DOWN (** Hollow triangle pointing downward *) 58 | | SOLID_TRI_DOWN (** Filled triangle pointing downward *) 59 | | SQUARE (** Hollow square *) 60 | | SOLID_SQUARE (** Filled square *) 61 | | BOWTIE (** Hollow bowtie *) 62 | | SOLID_BOWTIE (** Filled bowtie *) 63 | | HGLASS (** Hollow hourglass *) 64 | | SOLID_HGLASS (** Filled hourglass *) 65 | | DIAMOND (** Hollow diamond *) 66 | | SOLID_DIAMOND (** Filled Diamond *) 67 | | STAR (** Hollow star *) 68 | | SOLID_STAR (** Filled Star *) 69 | | TRI_UP_DOWN (** Hollow triangles pointing up and down overlaid *) 70 | | SOLID_TRI_RIGHT (** Filled triangle point right *) 71 | | SOLID_TRI_LEFT (** Filled triangle pointing left *) 72 | | HOLLOW_PLUS (** Hollow plus sign *) 73 | | SOLID_PLUS (** Solid plus sign *) 74 | | PENTAGON (** Pentagon *) 75 | | HEXAGON (** Hexagon *) 76 | | HEPTAGON (** Heptagon *) 77 | | OCTAGON (** Octagon *) 78 | | STAR_4 (** 4-pointed star *) 79 | | STAR_5 (** 5-pointed star (pentagram) *) 80 | | STAR_6 (** 6-pointed star (hexagram) *) 81 | | STAR_7 (** 7-pointed star (heptagram) *) 82 | | STAR_8 (** 8-pointed star (octagram) *) 83 | | VLINE (** verical line *) 84 | | HLINE (** horizontal line *) 85 | | OMARK (** o-mark *) 86 | 87 | let int_of_markertype = function 88 | | DOT -> 1 89 | | PLUS -> 2 90 | | ASTERISK -> 3 91 | | CIRCLE -> 4 92 | | DIAGONAL_CROSS -> 5 93 | | SOLID_CIRCLE -> -1 94 | | TRIANGLE_UP -> -2 95 | | SOLID_TRI_UP -> -3 96 | | TRIANGLE_DOWN -> -4 97 | | SOLID_TRI_DOWN -> -5 98 | | SQUARE -> -6 99 | | SOLID_SQUARE -> -7 100 | | BOWTIE -> -8 101 | | SOLID_BOWTIE -> -9 102 | | HGLASS -> -10 103 | | SOLID_HGLASS -> -11 104 | | DIAMOND -> -12 105 | | SOLID_DIAMOND -> -13 106 | | STAR -> -14 107 | | SOLID_STAR -> -15 108 | | TRI_UP_DOWN -> -16 109 | | SOLID_TRI_RIGHT -> -17 110 | | SOLID_TRI_LEFT -> -18 111 | | HOLLOW_PLUS -> -19 112 | | SOLID_PLUS -> -20 113 | | PENTAGON -> -21 114 | | HEXAGON -> -22 115 | | HEPTAGON -> -23 116 | | OCTAGON -> -24 117 | | STAR_4 -> -25 118 | | STAR_5 -> -26 119 | | STAR_6 -> -27 120 | | STAR_7 -> -28 121 | | STAR_8 -> -29 122 | | VLINE -> -30 123 | | HLINE -> -31 124 | | OMARK -> -32 125 | 126 | (* let markertype_of_int = function 127 | | 1 -> DOT 128 | | 2 -> PLUS 129 | | 3 -> ASTERISK 130 | | 4 -> CIRCLE 131 | | 5 -> DIAGONAL_CROSS 132 | | -1 -> SOLID_CIRCLE 133 | | -2 -> TRIANGLE_UP 134 | | -3 -> SOLID_TRI_UP 135 | | -4 -> TRIANGLE_DOWN 136 | | -5 -> SOLID_TRI_DOWN 137 | | -6 -> SQUARE 138 | | -7 -> SOLID_SQUARE 139 | | -8 -> BOWTIE 140 | | -9 -> SOLID_BOWTIE 141 | | -10 -> HGLASS 142 | | -11 -> SOLID_HGLASS 143 | | -12 -> DIAMOND 144 | | -13 -> SOLID_DIAMOND 145 | | -14 -> STAR 146 | | -15 -> SOLID_STAR 147 | | -16 -> TRI_UP_DOWN 148 | | -17 -> SOLID_TRI_RIGHT 149 | | -18 -> SOLID_TRI_LEFT 150 | | -19 -> HOLLOW_PLUS 151 | | -20 -> SOLID_PLUS 152 | | -21 -> PENTAGON 153 | | -22 -> HEXAGON 154 | | -23 -> HEPTAGON 155 | | -24 -> OCTAGON 156 | | -25 -> STAR_4 157 | | -26 -> STAR_5 158 | | -27 -> STAR_6 159 | | -28 -> STAR_7 160 | | -29 -> STAR_8 161 | | -30 -> VLINE 162 | | -31 -> HLINE 163 | | -32 -> OMARK 164 | | d -> failwith @@ "Error when inferring marker type. Got " ^ string_of_int d *) 165 | 166 | type scale_options = 167 | | OPTION_X_LOG (** Logarithmic X-axis *) 168 | | OPTION_Y_LOG (** Logarithmic Y-axis *) 169 | | OPTION_Z_LOG (** Logarithmic Z-axis *) 170 | | OPTION_FLIP_X (** Flip X-axis *) 171 | | OPTION_FLIP_Y (** Flip Y-axis *) 172 | | OPTION_FLIP_Z (** Flip Z-axis *) 173 | 174 | let int_of_scale_options opts = 175 | let int_of = function 176 | | OPTION_X_LOG -> 1 177 | | OPTION_Y_LOG -> 2 178 | | OPTION_Z_LOG -> 4 179 | | OPTION_FLIP_X -> 8 180 | | OPTION_FLIP_Y -> 16 181 | | OPTION_FLIP_Z -> 32 182 | in 183 | List.fold_left (fun acc s -> acc + int_of s) 0 opts 184 | 185 | type spline_algo = 186 | | GeneralizedCrossValidatedSmoothing 187 | | InterpolatingNaturalCubic 188 | | CubicBSpline 189 | 190 | let int_of_spline_algo = function 191 | | GeneralizedCrossValidatedSmoothing -> 1 192 | | InterpolatingNaturalCubic -> 0 193 | | CubicBSpline -> -1 194 | 195 | (** Available fonts, see also {{: https://gr-framework.org/fonts.html} GR Font list} *) 196 | type font = 197 | | TIMES_ROMAN 198 | | TIMES_ITALIC 199 | | TIMES_BOLD 200 | | TIMES_BOLDITALIC 201 | | HELVETICA 202 | | HELVETICA_OBLIQUE 203 | | HELVETICA_BOLD 204 | | HELVETICA_BOLDOBLIQUE 205 | | COURIER 206 | | COURIER_OBLIQUE 207 | | COURIER_BOLD 208 | | COURIER_BOLDOBLIQUE 209 | | SYMBOL 210 | | BOOKMAN_LIGHT 211 | | BOOKMAN_LIGHTITALIC 212 | | BOOKMAN_DEMI 213 | | BOOKMAN_DEMIITALIC 214 | | NEWCENTURYSCHLBK_ROMAN 215 | | NEWCENTURYSCHLBK_ITALIC 216 | | NEWCENTURYSCHLBK_BOLD 217 | | NEWCENTURYSCHLBK_BOLDITALIC 218 | | AVANTGARDE_BOOK 219 | | AVANTGARDE_BOOKOBLIQUE 220 | | AVANTGARDE_DEMI 221 | | AVANTGARDE_DEMIOBLIQUE 222 | | PALATINO_ROMAN 223 | | PALATINO_ITALIC 224 | | PALATINO_BOLD 225 | | PALATINO_BOLDITALIC 226 | | ZAPFCHANCERY_MEDIUMITALIC 227 | | ZAPFDINGBATS 228 | 229 | let int_of_font = function 230 | | TIMES_ROMAN -> 101 231 | | TIMES_ITALIC -> 102 232 | | TIMES_BOLD -> 103 233 | | TIMES_BOLDITALIC -> 104 234 | | HELVETICA -> 105 235 | | HELVETICA_OBLIQUE -> 106 236 | | HELVETICA_BOLD -> 107 237 | | HELVETICA_BOLDOBLIQUE -> 108 238 | | COURIER -> 109 239 | | COURIER_OBLIQUE -> 110 240 | | COURIER_BOLD -> 111 241 | | COURIER_BOLDOBLIQUE -> 112 242 | | SYMBOL -> 113 243 | | BOOKMAN_LIGHT -> 114 244 | | BOOKMAN_LIGHTITALIC -> 115 245 | | BOOKMAN_DEMI -> 116 246 | | BOOKMAN_DEMIITALIC -> 117 247 | | NEWCENTURYSCHLBK_ROMAN -> 118 248 | | NEWCENTURYSCHLBK_ITALIC -> 119 249 | | NEWCENTURYSCHLBK_BOLD -> 120 250 | | NEWCENTURYSCHLBK_BOLDITALIC -> 121 251 | | AVANTGARDE_BOOK -> 122 252 | | AVANTGARDE_BOOKOBLIQUE -> 123 253 | | AVANTGARDE_DEMI -> 124 254 | | AVANTGARDE_DEMIOBLIQUE -> 125 255 | | PALATINO_ROMAN -> 126 256 | | PALATINO_ITALIC -> 127 257 | | PALATINO_BOLD -> 128 258 | | PALATINO_BOLDITALIC -> 129 259 | | ZAPFCHANCERY_MEDIUMITALIC -> 130 260 | | ZAPFDINGBATS -> 131 261 | 262 | type text_precision = 263 | | STRING (** String precision (higher quality) *) 264 | | CHAR (** Character precision (medium quality) *) 265 | | STROKE (** Stroke precision (lower quality) *) 266 | 267 | let int_of_text_precision = function STRING -> 0 | CHAR -> 1 | STROKE -> 2 268 | 269 | type text_path_direction = 270 | | RIGHT (** left-to-right *) 271 | | LEFT (** right-to-left *) 272 | | UP (** downside-up *) 273 | | DOWN (** upside-down *) 274 | 275 | let int_of_text_path_direction = function 276 | | RIGHT -> 0 277 | | LEFT -> 1 278 | | UP -> 2 279 | | DOWN -> 3 280 | 281 | type text_halign = 282 | | NORMAL 283 | | LEFT (** Left justify *) 284 | | CENTER (** Center justify *) 285 | | RIGHT (** Right justify *) 286 | 287 | let int_of_text_halign = function 288 | | NORMAL -> 0 289 | | LEFT -> 1 290 | | CENTER -> 2 291 | | RIGHT -> 3 292 | 293 | type text_valign = 294 | | NORMAL 295 | | TOP (** Align with the top of the characters *) 296 | | CAP (** Aligned with the cap of the characters *) 297 | | HALF (** Aligned with the half line of the characters *) 298 | | BASE (** Aligned with the base line of the characters *) 299 | | BOTTOM (** Aligned with the bottom line of the characters *) 300 | 301 | let int_of_text_valign = function 302 | | NORMAL -> 0 303 | | TOP -> 1 304 | | CAP -> 2 305 | | HALF -> 3 306 | | BASE -> 4 307 | | BOTTOM -> 5 308 | 309 | type pattern_style = int 310 | (** Pattern style, see also {{: https://gr-framework.org/patterns.html} GR Fill Patterns and Hatches} *) 311 | 312 | let pattern_style n = 313 | if n > 0 && n < 109 then n else failwith "pattern_style out of range" 314 | 315 | type hatch_style = int 316 | (** Hatch style, see also {{: https://gr-framework.org/patterns.html} GR Fill Patterns and Hatches} *) 317 | 318 | let hatch_style n = 319 | if n > 1 && n < 11 then n else failwith "hatch_style out of range" 320 | 321 | type fill_style = 322 | | HOLLOW (** No filling. Just draw the bounding polyline *) 323 | | SOLID (** Fill the interior of the polygon using the fill color index *) 324 | | PATTERN of pattern_style 325 | (** Fill the interior of the polygon using the style index as a pattern index *) 326 | | HATCH of hatch_style 327 | (** Fill the interior of the polygon using the style index as a cross-hatched style *) 328 | 329 | let int_of_fill_style = function 330 | | HOLLOW -> 0 331 | | SOLID -> 1 332 | | PATTERN _ -> 2 333 | | HATCH _ -> 3 334 | 335 | (** Color Maps, see also {{: https://gr-framework.org/colormaps.html} GR Color Maps} *) 336 | type color_map = 337 | | Uniform 338 | | Temperature 339 | | Grayscale 340 | | Glowing 341 | | Rainbowlike 342 | | Geologic 343 | | Greenscale 344 | | Cyanscale 345 | | Bluescale 346 | | Magentascale 347 | | Redscale 348 | | Flame 349 | | Brownscale 350 | | Pilatus 351 | | Autumn 352 | | Bone 353 | | Cool 354 | | Copper 355 | | Gray 356 | | Hot 357 | | Hsv 358 | | Jet 359 | | Pink 360 | | Spectral 361 | | Spring 362 | | Summer 363 | | Winter 364 | | Gist_Earth 365 | | Gist_Heat 366 | | Gist_Ncar 367 | | Gist_Rainbow 368 | | Gist_Stern 369 | | Afmhot 370 | | Brg 371 | | Bwr 372 | | Coolwarm 373 | | Cmrmap 374 | | Cubehelix 375 | | Gnuplot 376 | | Gnuplot2 377 | | Ocean 378 | | Rainbow 379 | | Seismic 380 | | Terrain 381 | | Viridis 382 | | Inferno 383 | | Plasma 384 | | Magma 385 | 386 | let int_of_color_map = function 387 | | Uniform -> 0 388 | | Temperature -> 1 389 | | Grayscale -> 2 390 | | Glowing -> 3 391 | | Rainbowlike -> 4 392 | | Geologic -> 5 393 | | Greenscale -> 6 394 | | Cyanscale -> 7 395 | | Bluescale -> 8 396 | | Magentascale -> 9 397 | | Redscale -> 10 398 | | Flame -> 11 399 | | Brownscale -> 12 400 | | Pilatus -> 13 401 | | Autumn -> 14 402 | | Bone -> 15 403 | | Cool -> 16 404 | | Copper -> 17 405 | | Gray -> 18 406 | | Hot -> 19 407 | | Hsv -> 20 408 | | Jet -> 21 409 | | Pink -> 22 410 | | Spectral -> 23 411 | | Spring -> 24 412 | | Summer -> 25 413 | | Winter -> 26 414 | | Gist_Earth -> 27 415 | | Gist_Heat -> 28 416 | | Gist_Ncar -> 29 417 | | Gist_Rainbow -> 30 418 | | Gist_Stern -> 31 419 | | Afmhot -> 32 420 | | Brg -> 33 421 | | Bwr -> 34 422 | | Coolwarm -> 35 423 | | Cmrmap -> 36 424 | | Cubehelix -> 37 425 | | Gnuplot -> 38 426 | | Gnuplot2 -> 39 427 | | Ocean -> 40 428 | | Rainbow -> 41 429 | | Seismic -> 42 430 | | Terrain -> 43 431 | | Viridis -> 44 432 | | Inferno -> 45 433 | | Plasma -> 46 434 | | Magma -> 47 435 | 436 | type surface_options = 437 | | LINES (** Use X Y polylines to denote the surface *) 438 | | MESH (** Use a wire grid to denote the surface *) 439 | | FILLED_MESH (** Applies an opaque grid to the surface *) 440 | | Z_SHADED_MESH (** Applies Z-value shading to the surface *) 441 | | COLORED_MESH (** Applies a colored grid to the surface *) 442 | | CELL_ARRAY 443 | (** Applies a grid of individually-colored cells to the surface *) 444 | | SHADED_MESH (** Applies light source shading to the 3-D surface *) 445 | 446 | let int_of_surface_options = function 447 | | LINES -> 0 448 | | MESH -> 1 449 | | FILLED_MESH -> 2 450 | | Z_SHADED_MESH -> 3 451 | | COLORED_MESH -> 4 452 | | CELL_ARRAY -> 5 453 | | SHADED_MESH -> 6 454 | 455 | module Workstation = struct 456 | type id = W of int 457 | 458 | (** Available workstation types, see also {{: https://gr-framework.org/workstations.html} GR Workstation Types} *) 459 | type workstation_type = 460 | | WISS (** Workstation Independent Segment ptr Storage *) 461 | | WinGDI (** Windows ptr GDI *) 462 | | PS_1 (**PostScript (b/w \@-> color) *) 463 | | PS_2 (**PostScript (b/w \@-> color) *) 464 | | PS_3 (**PostScript (b/w \@-> color) *) 465 | | PS_4 (**PostScript (b/w \@-> color) *) 466 | | PDFPlain (** Portable Document Format ptr plain *) 467 | | PDFCompressed (** Portable Document Format ptr compressed *) 468 | | X_1 (** X ptr Windows *) 469 | | X_2 (** X ptr Windows *) 470 | | X_3 (** X ptr Windows *) 471 | | X_4 (** X ptr Windows *) 472 | | SunRF (** Sun Raster file (RF) *) 473 | | GIF87 (** Graphics Interchange Format ptr GIF87 *) 474 | | GIF89 (**Graphics Interchange Format ptr GIF89 *) 475 | | MotifUIL (** Motif User Interface Language (UIL) *) 476 | | BMP (** Windows Bitmap (BMP) *) 477 | | JPEG (** JPEG image ptr file *) 478 | | PNG (** Portable Network Graphics file (PNG) *) 479 | | TIFF (** Tagged Image File Format (TIFF) *) 480 | | Gtk (** ptr Gtk *) 481 | | Wx (** ptr wxWidgets *) 482 | | Qt4 (** ptr Qt4 *) 483 | | SVG (** Scaleable Vector Graphics (SVG) *) 484 | | WMF (** Windows ptr Metafile *) 485 | | Quartz (** ptr Quartz *) 486 | | Sock (** Socket ptr driver *) 487 | | ZMQ (** 0MQ ptr driver *) 488 | | OGL (** ptr OpenGL *) 489 | 490 | let int_of_workstation_type = function 491 | | WISS -> 5 492 | | WinGDI -> 41 493 | | PS_1 -> 61 494 | | PS_2 -> 62 495 | | PS_3 -> 63 496 | | PS_4 -> 64 497 | | PDFPlain -> 101 498 | | PDFCompressed -> 102 499 | | X_1 -> 210 500 | | X_2 -> 211 501 | | X_3 -> 213 502 | | X_4 -> 212 503 | | SunRF -> 214 504 | | GIF87 -> 215 505 | | GIF89 -> 218 506 | | MotifUIL -> 216 507 | | BMP -> 320 508 | | JPEG -> 321 509 | | PNG -> 322 510 | | TIFF -> 323 511 | | Gtk -> 371 512 | | Wx -> 380 513 | | Qt4 -> 381 514 | | SVG -> 382 515 | | WMF -> 390 516 | | Quartz -> 400 517 | | Sock -> 410 518 | | ZMQ -> 415 519 | | OGL -> 420 520 | 521 | let wid id = W id 522 | 523 | let open' (W id) conn typ = 524 | Lowlevel.openws id conn (int_of_workstation_type typ) 525 | 526 | let close (W id) = Lowlevel.closews id 527 | 528 | let activate (W id) = Lowlevel.activatews id 529 | 530 | let deactivate (W id) = Lowlevel.deactivatews id 531 | 532 | let clear = Lowlevel.clearws 533 | 534 | let update = Lowlevel.updatews 535 | 536 | let set_window = Lowlevel.setwswindow 537 | 538 | let set_viewport = Lowlevel.setwsviewport 539 | 540 | let copy_segment = Lowlevel.copysegws 541 | 542 | let redraw_segment = Lowlevel.redrawsegws 543 | end 544 | 545 | module Gks = struct 546 | let emergency_close = Lowlevel.emergencyclosegks 547 | 548 | let update = Lowlevel.updategks 549 | end 550 | 551 | module State = struct 552 | let save () = Lowlevel.savestate () 553 | 554 | let restore () = Lowlevel.restorestate () 555 | 556 | let with_sandbox f = 557 | save (); 558 | Fun.protect ~finally:restore f 559 | end 560 | 561 | let set_window = Lowlevel.setwindow 562 | 563 | let set_viewport = Lowlevel.setviewport 564 | 565 | let select_transformation = Lowlevel.selntran 566 | 567 | let clip c = Lowlevel.setclip (if c then 1 else 2) 568 | 569 | type segment = int 570 | 571 | let segment i = i 572 | 573 | let create_segment = Lowlevel.createseg 574 | 575 | let set_segment_transform = Lowlevel.setsegtran 576 | 577 | let close_segment = Lowlevel.closeseg 578 | 579 | let set_space = Lowlevel.setspace 580 | 581 | let set_linetype lt = lt |> int_of_linetype |> Lowlevel.setlinetype 582 | 583 | let set_linewidth = Lowlevel.setlinewidth 584 | 585 | let set_linecolorindex = function 586 | | c when c >= 0 && c < 1256 -> Lowlevel.setlinecolorind c 587 | | c -> 588 | failwith @@ "Color index must be in the range [0, 1256]. Got " 589 | ^ string_of_int c 590 | 591 | let set_markertype mt = mt |> int_of_markertype |> Lowlevel.setmarkertype 592 | 593 | let set_markersize = Lowlevel.setmarkersize 594 | 595 | let set_markercolorindex = function 596 | | c when c >= 0 && c < 1256 -> Lowlevel.setmarkercolorind c 597 | | c -> 598 | failwith @@ "Color index must be in the range [0, 1256]. Got " 599 | ^ string_of_int c 600 | 601 | let set_arrowstyle s = 602 | if s < 0 || s > 18 then 603 | failwith @@ Printf.sprintf "Only styles 1..18 are supported. Got %d" s; 604 | Lowlevel.setarrowstyle s 605 | 606 | let set_arrowsize = Lowlevel.setarrowsize 607 | 608 | let set_text_font_prec ?(precision = STRING) font = 609 | Lowlevel.settextfontprec (int_of_font font) (int_of_text_precision precision) 610 | 611 | let set_char_expand_factor = Lowlevel.setcharexpan 612 | 613 | let set_text_colorindex = function 614 | | c when c >= 0 && c < 1256 -> Lowlevel.settextcolorind c 615 | | c -> 616 | failwith @@ "Color index must be in the range [0, 1256]. Got " 617 | ^ string_of_int c 618 | 619 | let set_char_height = Lowlevel.setcharheight 620 | 621 | let set_char_up (x, y) = Lowlevel.setcharup x y 622 | 623 | let set_char_space = Lowlevel.setcharspace 624 | 625 | let set_text_path direction = 626 | Lowlevel.settextpath (int_of_text_path_direction direction) 627 | 628 | let set_text_align : text_halign option -> text_valign option -> unit = 629 | fun horizontal vertical -> 630 | let horizontal = Option.value ~default:NORMAL horizontal in 631 | let vertical = Option.value ~default:NORMAL vertical in 632 | Lowlevel.settextalign 633 | (int_of_text_halign horizontal) 634 | (int_of_text_valign vertical) 635 | 636 | let set_fill_interior_style style = 637 | Lowlevel.setfillintstyle (int_of_fill_style style); 638 | match style with 639 | | PATTERN pat -> Lowlevel.setfillstyle pat 640 | | HATCH hat -> Lowlevel.setfillstyle hat 641 | | _ -> () 642 | 643 | let set_fill_colorindex = function 644 | | c when c >= 0 && c < 1256 -> Lowlevel.setfillcolorind c 645 | | c -> 646 | failwith @@ "Color index must be in the range [0, 1256]. Got " 647 | ^ string_of_int c 648 | 649 | let set_color_representation index (red, green, blue) = 650 | if index < 0 || index >= 1256 then 651 | failwith @@ "Color index must be in the range [0, 1256]. Got " 652 | ^ string_of_int index; 653 | if 654 | (red < 0.0 || red > 1.0) 655 | || (green < 0.0 || green > 1.0) 656 | || blue < 0.0 || blue > 1.0 657 | then 658 | failwith 659 | @@ Printf.sprintf 660 | "Color values must be in the range [0.0, 1.0]. Got: (%f, %f, %f)" red 661 | green blue; 662 | Lowlevel.setcolorrep index red green blue 663 | 664 | let set_colormap cmap = Lowlevel.setcolormap (int_of_color_map cmap) 665 | 666 | let set_scale scale = Lowlevel.setscale (int_of_scale_options scale) 667 | 668 | let set_shadow (offsetx, offsety) blur = Lowlevel.setshadow offsetx offsety blur 669 | 670 | let set_transparency alpha = 671 | if alpha < 0.0 && alpha > 1.0 then 672 | failwith @@ "Alpha index must be between 0.0 and 1.0"; 673 | Lowlevel.settransparency alpha 674 | 675 | let set_coord_transform transform = 676 | let transform = 677 | match Bigarray.Genarray.dims transform with 678 | | [| 3; 2 |] -> transform 679 | | [| 2; 3 |] -> failwith "Need a 3x2 array, got a 2x3 array" 680 | | _ -> failwith "Need a 3x2 array but got something different" 681 | in 682 | Lowlevel.setcoordxform Ctypes.(bigarray_start genarray transform) 683 | 684 | module Graphics = struct 685 | type t = string 686 | 687 | let beging = Lowlevel.begingraphics 688 | 689 | let endg = Lowlevel.endgraphics 690 | 691 | let get : unit -> t = Lowlevel.getgraphics 692 | 693 | let draw = Lowlevel.drawgraphics 694 | 695 | let import = Lowlevel.importgraphics 696 | end 697 | 698 | let polyline ?linetype ?linewidth ?coloridx x y = 699 | State.with_sandbox (fun () -> 700 | Option.iter set_linetype linetype; 701 | Option.iter set_linewidth linewidth; 702 | Option.iter set_linecolorindex coloridx; 703 | let n, x, y = Lowlevel.get_size_and_pointers x y in 704 | Lowlevel.polyline n x y) 705 | 706 | let polyline3d ?linetype ?linewidth ?coloridx x y z = 707 | State.with_sandbox (fun () -> 708 | Option.iter set_linetype linetype; 709 | Option.iter set_linewidth linewidth; 710 | Option.iter set_linecolorindex coloridx; 711 | let n, x, y = Lowlevel.get_size_and_pointers x y in 712 | let _nz, z = Lowlevel.get_size_and_pointer z in 713 | (* TODO: Check z dimension *) 714 | Lowlevel.polyline3d n x y z) 715 | 716 | let polymarker ?markertype ?markersize ?coloridx x y = 717 | State.with_sandbox (fun () -> 718 | Option.iter set_markertype markertype; 719 | Option.iter set_markersize markersize; 720 | Option.iter set_markercolorindex coloridx; 721 | let n, x, y = Lowlevel.get_size_and_pointers x y in 722 | Lowlevel.polymarker n x y) 723 | 724 | let polymarker3d ?markertype ?markersize ?coloridx x y z = 725 | State.with_sandbox (fun () -> 726 | Option.iter set_markertype markertype; 727 | Option.iter set_markersize markersize; 728 | Option.iter set_markercolorindex coloridx; 729 | let n, x, y = Lowlevel.get_size_and_pointers x y in 730 | let _nz, z = Lowlevel.get_size_and_pointer z in 731 | (* TODO: Check z dimension *) 732 | Lowlevel.polymarker3d n x y z) 733 | 734 | let text = Lowlevel.text 735 | 736 | let fillarea x y = 737 | let n, x', y' = Lowlevel.get_size_and_pointers x y in 738 | Lowlevel.fillarea n x' y' 739 | 740 | let cellarray (xmin, xmax) (ymin, ymax) (dimx, dimy) (scol, srow) (ncol, nrow) 741 | colors = 742 | let color' = Ctypes.(bigarray_start genarray colors) in 743 | Lowlevel.cellarray xmin xmax ymin ymax dimx dimy scol srow ncol nrow color' 744 | 745 | (* let gdp = ... (* No idea what this does... *) *) 746 | 747 | let spline ?linetype ?linewidth ?coloridx x y m algo = 748 | State.with_sandbox (fun () -> 749 | Option.iter set_linetype linetype; 750 | Option.iter set_linewidth linewidth; 751 | Option.iter set_linecolorindex coloridx; 752 | let n, x', y' = Lowlevel.get_size_and_pointers x y in 753 | Lowlevel.spline n x' y' m (int_of_spline_algo algo)) 754 | 755 | let gridit x y z (nx, ny) = 756 | let x' = Bigarray.(Genarray.create float64 c_layout [| nx |]) in 757 | let y' = Bigarray.(Genarray.create float64 c_layout [| ny |]) in 758 | let z' = Bigarray.(Genarray.create float64 c_layout [| nx * ny |]) in 759 | let n, x, y = Lowlevel.get_size_and_pointers x y in 760 | let nz, z = Lowlevel.get_size_and_pointer z in 761 | if nz <> n then 762 | failwith 763 | @@ Printf.sprintf "Expected arrays with dimensions n, n, n. Got %d, %d, %d" 764 | n n nz; 765 | Lowlevel.gridit n x y z nx ny 766 | Ctypes.(bigarray_start genarray x') 767 | Ctypes.(bigarray_start genarray y') 768 | Ctypes.(bigarray_start genarray z'); 769 | (x', y', z') 770 | 771 | let tex_text (x, y) text = Lowlevel.textext x y text 772 | 773 | let math_tex (x, y) tex = Lowlevel.mathtex x y tex 774 | 775 | let axes ?(scale = []) ?linetype ?linewidth ?coloridx ?(origin = (0.0, 0.0)) 776 | ?(major = (1, 1)) ?(tick_size = -0.01) x_tick y_tick = 777 | State.with_sandbox (fun () -> 778 | if scale <> [] then set_scale scale |> ignore; 779 | Option.iter set_linetype linetype; 780 | Option.iter set_linewidth linewidth; 781 | Option.iter set_linecolorindex coloridx; 782 | let x_org, y_org = origin in 783 | let major_x, major_y = major in 784 | Lowlevel.axes x_tick y_tick x_org y_org major_x major_y tick_size) 785 | 786 | let axes_labels ?(scale = []) ?linetype ?linewidth ?coloridx 787 | ?(origin = (0.0, 0.0)) ?(major = (1, 1)) ?(tick_size = -0.01) 788 | (fpx : float -> float -> string -> float -> unit) 789 | (fpy : float -> float -> string -> float -> unit) x_tick y_tick = 790 | State.with_sandbox (fun () -> 791 | if scale <> [] then 792 | Lowlevel.setscale (int_of_scale_options scale) |> ignore; 793 | Option.iter set_linetype linetype; 794 | Option.iter set_linewidth linewidth; 795 | Option.iter set_linecolorindex coloridx; 796 | let x_org, y_org = origin in 797 | let major_x, major_y = major in 798 | Lowlevel.axeslbl x_tick y_tick x_org y_org major_x major_y tick_size fpx 799 | fpy) 800 | 801 | let axes3d ?(scale = []) ?linetype ?linewidth ?coloridx 802 | ?(origin = (0.0, 0.0, 0.0)) ?(major = (1, 1, 1)) ?(tick_size = -0.01) x_tick 803 | y_tick z_tick = 804 | State.with_sandbox (fun () -> 805 | if scale <> [] then set_scale scale |> ignore; 806 | Option.iter set_linetype linetype; 807 | Option.iter set_linewidth linewidth; 808 | Option.iter set_linecolorindex coloridx; 809 | let x_org, y_org, z_org = origin in 810 | let major_x, major_y, major_z = major in 811 | Lowlevel.axes3d x_tick y_tick z_tick x_org y_org z_org major_x major_y 812 | major_z tick_size) 813 | 814 | let surface ?(options = LINES) x y z = 815 | let nx, x = Lowlevel.get_size_and_pointer x in 816 | let ny, y = Lowlevel.get_size_and_pointer y in 817 | let nz, z = Lowlevel.get_size_and_pointer z in 818 | if nz <> nx * ny then 819 | failwith 820 | @@ Printf.sprintf 821 | "Expected arrays with dimensions n, n', n*n'. Got %d, %d, %d" nx ny nz; 822 | Lowlevel.surface nx ny x y z (int_of_surface_options options) 823 | 824 | let contour ?(major_h = 0) x y h z = 825 | (* TODO: validate z *) 826 | let nx, x = Lowlevel.get_size_and_pointer x in 827 | let ny, y = Lowlevel.get_size_and_pointer y in 828 | let nh, h = Lowlevel.get_size_and_pointer h in 829 | let _nz, z = Lowlevel.get_size_and_pointer z in 830 | Lowlevel.contour nx ny nh x y h z major_h 831 | 832 | let contourf ?(major_h = 0) x y h z = 833 | (* TODO: validate z *) 834 | let nx, x = Lowlevel.get_size_and_pointer x in 835 | let ny, y = Lowlevel.get_size_and_pointer y in 836 | let nh, h = Lowlevel.get_size_and_pointer h in 837 | let _nz, z = Lowlevel.get_size_and_pointer z in 838 | Lowlevel.contourf nx ny nh x y h z major_h 839 | 840 | let grid ?(scale = []) ?linetype ?linewidth ?coloridx ?(origin = (0.0, 0.0)) 841 | ?(major = (1, 1)) x_tick y_tick = 842 | State.with_sandbox (fun () -> 843 | if scale <> [] then set_scale scale |> ignore; 844 | Option.iter set_linetype linetype; 845 | Option.iter set_linewidth linewidth; 846 | Option.iter set_linecolorindex coloridx; 847 | let x_org, y_org = origin in 848 | let major_x, major_y = major in 849 | Lowlevel.grid x_tick y_tick x_org y_org major_x major_y) 850 | 851 | let grid3d ?(scale = []) ?linetype ?linewidth ?coloridx 852 | ?(origin = (0.0, 0.0, 0.0)) ?(major = (1, 1, 1)) x_tick y_tick z_tick = 853 | State.with_sandbox (fun () -> 854 | if scale <> [] then set_scale scale |> ignore; 855 | Option.iter set_linetype linetype; 856 | Option.iter set_linewidth linewidth; 857 | Option.iter set_linecolorindex coloridx; 858 | let x_org, y_org, z_org = origin in 859 | let major_x, major_y, major_z = major in 860 | Lowlevel.grid3d x_tick y_tick z_tick x_org y_org z_org major_x major_y 861 | major_z) 862 | 863 | let vertical_errorbars x y el eu = 864 | let n, x, y = Lowlevel.get_size_and_pointers x y in 865 | let ne, el, eu = Lowlevel.get_size_and_pointers el eu in 866 | if n <> ne then 867 | failwith 868 | @@ Printf.sprintf "Expected arrays of the same dimensions. Got: %d, %d" n ne; 869 | Lowlevel.verrorbars n x y el eu 870 | 871 | let horizontal_errorbars x y el eu = 872 | let n, x, y = Lowlevel.get_size_and_pointers x y in 873 | let ne, el, eu = Lowlevel.get_size_and_pointers el eu in 874 | if n <> ne then 875 | failwith 876 | @@ Printf.sprintf "Expected arrays of the same dimensions. Got: %d, %d" n ne; 877 | Lowlevel.herrorbars n x y el eu 878 | 879 | let titles3d = Lowlevel.titles3d 880 | 881 | let tricontour x y z levels = 882 | let nx, x = Lowlevel.get_size_and_pointer x in 883 | let _ny, y = Lowlevel.get_size_and_pointer y in 884 | let _nz, z = Lowlevel.get_size_and_pointer z in 885 | let nlevels, levels = Lowlevel.get_size_and_pointer levels in 886 | Lowlevel.tricontour nx x y z nlevels levels 887 | 888 | (* (* TODO: I don't know what this function does... *) 889 | let hexbin = foreign "gr_hexbin" (int @-> ptr double @-> ptr double @-> int @-> returning int) 890 | *) 891 | 892 | let colorbar () = Lowlevel.colorbar () 893 | 894 | (* 895 | (* TODO: postponed *) 896 | let hsvtorgb = foreign "gr_hsvtorgb" (double @-> double @-> double @-> ptr double@-> ptr double @-> ptr double @-> returning void) 897 | *) 898 | 899 | let tick = Lowlevel.tick 900 | 901 | module Print = struct 902 | let validate path = 903 | if 904 | not 905 | @@ List.fold_left 906 | (fun acc suffix -> acc || Filename.check_suffix path suffix) 907 | false 908 | [ 909 | ".ps"; 910 | ".eps"; 911 | ".pdf"; 912 | ".bmp"; 913 | ".jpeg"; 914 | ".jpg"; 915 | ".png"; 916 | ".tiff"; 917 | ".tif"; 918 | ".svg"; 919 | ".wmf"; 920 | ".mp4"; 921 | ".webm"; 922 | ".ogg"; 923 | ] 924 | then failwith @@ Printf.sprintf "Unsupported file type: %s" path 925 | 926 | let beginp path = 927 | validate path; 928 | Lowlevel.beginprint path 929 | 930 | let endp = Lowlevel.endprint 931 | 932 | let beginp_extended path mode format orientation = 933 | validate path; 934 | let mode = 935 | match mode with `Color -> "Color" | `GreyScale -> "GreyScale" 936 | in 937 | let orientation = 938 | match orientation with 939 | | `Landscape -> "Landscape" 940 | | `Portrait -> "Portrait" 941 | in 942 | let format = 943 | match format with 944 | | `A4 -> "A4" 945 | | `B5 -> "B5" 946 | | `Letter -> "Letter" 947 | | `Legal -> "Legal" 948 | | `Executive -> "Executive" 949 | | `A0 -> "A0" 950 | | `A1 -> "A1" 951 | | `A2 -> "A2" 952 | | `A3 -> "A3" 953 | | `A5 -> "A5" 954 | | `A6 -> "A6" 955 | | `A7 -> "A7" 956 | | `A8 -> "A8" 957 | | `A9 -> "A9" 958 | | `B0 -> "B0" 959 | | `B1 -> "B1" 960 | | `B10 -> "B10" 961 | | `B2 -> "B2" 962 | | `B3 -> "B3" 963 | | `B4 -> "B4" 964 | | `B6 -> "B6" 965 | | `B7 -> "B7" 966 | | `B8 -> "B8" 967 | | `B9 -> "B9" 968 | | `C5E -> "C5E" 969 | | `Comm10E -> "Comm10E" 970 | | `DLE -> "DLE" 971 | | `Folio -> "Folio" 972 | | `Ledger -> "Ledger" 973 | | `Tabloid -> "Tabloid" 974 | in 975 | Lowlevel.beginprintext path mode format orientation 976 | end 977 | 978 | (* 979 | (* TODO: operates on double pointers - postponed *) 980 | let ndctowc = foreign "gr_ndctowc" (ptr double @-> ptr double @-> returning void) 981 | let wctondc = foreign "gr_wctondc" (ptr double @-> ptr double @-> returning void) 982 | let wc3towc = foreign "gr_wc3towc" (ptr double @-> ptr double @-> ptr double @-> returning void) 983 | *) 984 | 985 | let drawrect ?linetype ?linewidth ?coloridx left right bottom up = 986 | State.with_sandbox (fun () -> 987 | Option.iter set_linetype linetype; 988 | Option.iter set_linewidth linewidth; 989 | Option.iter set_linecolorindex coloridx; 990 | Lowlevel.drawrect left right bottom up) 991 | 992 | let fillrect ?fillstyle ?fillcoloridx ?linetype ?linewidth ?coloridx left right 993 | bottom up = 994 | State.with_sandbox (fun () -> 995 | Option.iter set_linetype linetype; 996 | Option.iter set_linewidth linewidth; 997 | Option.iter set_linecolorindex coloridx; 998 | Option.iter set_fill_interior_style fillstyle; 999 | Option.iter set_fill_colorindex fillcoloridx; 1000 | Lowlevel.fillrect left right bottom up) 1001 | 1002 | let drawarc ?linetype ?linewidth ?coloridx left right bottom up a1 a2 = 1003 | State.with_sandbox (fun () -> 1004 | Option.iter set_linetype linetype; 1005 | Option.iter set_linewidth linewidth; 1006 | Option.iter set_linecolorindex coloridx; 1007 | Lowlevel.drawarc left right bottom up a1 a2) 1008 | 1009 | let fillarc ?fillstyle ?fillcoloridx ?linetype ?linewidth ?coloridx left right 1010 | bottom up a1 a2 = 1011 | State.with_sandbox (fun () -> 1012 | Option.iter set_linetype linetype; 1013 | Option.iter set_linewidth linewidth; 1014 | Option.iter set_linecolorindex coloridx; 1015 | Option.iter set_fill_interior_style fillstyle; 1016 | Option.iter set_fill_colorindex fillcoloridx; 1017 | Lowlevel.fillarc left right bottom up a1 a2) 1018 | 1019 | let drawpath vertices codes fill = 1020 | let code_to_uchar = function 1021 | | `STOP -> Unsigned.UChar.of_int 0 1022 | | `MOVETO -> Unsigned.UChar.of_int 1 1023 | | `LINETO -> Unsigned.UChar.of_int 2 1024 | | `CURVE3 -> Unsigned.UChar.of_int 3 1025 | | `CURVE4 -> Unsigned.UChar.of_int 4 1026 | | `CLOSEPOLY -> Unsigned.UChar.of_int 0x4f 1027 | in 1028 | let fill = if fill then 1 else 0 in 1029 | let n = Array.length vertices in 1030 | let open Ctypes in 1031 | let cvertices = CArray.make Lowlevel.vertex n in 1032 | let ccodes = CArray.make uchar n in 1033 | for i = 0 to n - 1 do 1034 | let x, y = vertices.(i) in 1035 | let v = make Lowlevel.vertex in 1036 | setf v Lowlevel.vertex_x x; 1037 | setf v Lowlevel.vertex_y y; 1038 | CArray.set cvertices i v; 1039 | CArray.set ccodes i (code_to_uchar codes.(i)) 1040 | done; 1041 | Lowlevel.drawpath n CArray.(start cvertices) CArray.(start ccodes) fill 1042 | 1043 | let drawarrow ?arrowsize ?arrowstyle (x1, y1) (x2, y2) = 1044 | State.with_sandbox (fun () -> 1045 | Option.iter set_arrowsize arrowsize; 1046 | Option.iter set_arrowstyle arrowstyle; 1047 | Lowlevel.drawarrow x1 y1 x2 y2) 1048 | 1049 | (* TODO: 1050 | let readimage = foreign "gr_readimage" (string @-> ptr int @-> ptr int @-> ptr (ptr int) @-> returning int) 1051 | *) 1052 | 1053 | let drawimage (xmin, ymin) (xmax, ymax) image_data model = 1054 | let model = match model with `RGB -> 0 | `HSV -> 1 in 1055 | let width, height, image_data = 1056 | match Bigarray.Genarray.dims image_data with 1057 | | [| width; height |] -> 1058 | (width, height, Ctypes.(bigarray_start genarray image_data)) 1059 | | _ -> failwith "Expecting a 2D array, but got something else!" 1060 | in 1061 | Lowlevel.drawimage xmin ymin xmax ymax width height image_data model 1062 | 1063 | module Selection = struct 1064 | let begins = Lowlevel.beginselection 1065 | 1066 | let ends = Lowlevel.endselection 1067 | 1068 | let move x y = Lowlevel.moveselection x y 1069 | 1070 | let resize kind x y = Lowlevel.resizeselection kind x y 1071 | end 1072 | 1073 | (* 1074 | TODO: 1075 | inqbbox &xmin &xmax &ymin &ymax 1076 | uselinespec linespec 1077 | *) 1078 | 1079 | (* let with_ws ?(typ = PNG) plot = 1080 | let id = Random.int 1024 in 1081 | try 1082 | Lowlevel.openws id ("plot" ^ string_of_int id) (int_of_workstation_type typ); 1083 | plot id; 1084 | Lowlevel.closews id 1085 | with 1086 | | exn -> 1087 | (try Lowlevel.closews id with 1088 | | _ -> ()); 1089 | raise exn 1090 | *) 1091 | -------------------------------------------------------------------------------- /src/gr.mli: -------------------------------------------------------------------------------- 1 | (** {1 OCaml Bindings for the GR Framework} 2 | 3 | GR is based on an implementation of a Graphical Kernel System (GKS) and OpenGL. As a self-contained system it can quickly and easily be integrated into existing applications. 4 | 5 | The GR framework can be used in imperative programming systems or integrated into modern object-oriented systems, in particular those based on GUI toolkits. 6 | GR is characterized by its high interoperability and can be used with modern web technologies and mobile devices. 7 | The GR framework is especially suitable for real-time environments. 8 | 9 | The bindings aree based on version 0.37.0, but should work in any successive version. 10 | 11 | Make sure libgr is installed. Currently the library is only looked through the default library paths of your system or using [GRDIR]. 12 | You can customise this further by specifying the path to [libGR.so] or [libGR.dylib] via the environment variable [LIBGRPATH]. 13 | *) 14 | 15 | module Lowlevel = Lowlevel 16 | (** This module contains the bindings to the lowlevel C interface. *) 17 | 18 | (** Available line types, see also {{: https://gr-framework.org/linetypes.html} GR Line Types} *) 19 | type linetype = 20 | | SOLID (** Solid line *) 21 | | DASHED (** Dashed line *) 22 | | DOTTED (** Dotted line *) 23 | | DASHED_DOTTED (** Dashed-dotted line *) 24 | | DASH_2_DOT (** Sequence of one dash followed by two dots *) 25 | | DASH_3_DOT (** Sequence of one dash followed by three dots *) 26 | | LONG_DASH (** Sequence of long dashes *) 27 | | LONG_SHORT_DASH (** Sequence of a long dash followed by a short dash *) 28 | | SPACED_DASH (** Sequence of dashes double spaced *) 29 | | SPACED_DOT (** Sequence of dots double spaced *) 30 | | DOUBLE_DOT (** Sequence of pairs of dots *) 31 | | TRIPLE_DOT (** Sequence of groups of three dots *) 32 | 33 | (** Available marker types, see also {{: https://gr-framework.org/markertypes.html} GR Marker Types} *) 34 | type markertype = 35 | | DOT (** Smallest displayable dot *) 36 | | PLUS (** Plus sign *) 37 | | ASTERISK (** Asterisk *) 38 | | CIRCLE (** Hollow circle *) 39 | | DIAGONAL_CROSS (** Diagonal cross *) 40 | | SOLID_CIRCLE (** Filled circle *) 41 | | TRIANGLE_UP (** Hollow triangle pointing upward *) 42 | | SOLID_TRI_UP (** Filled triangle pointing upward *) 43 | | TRIANGLE_DOWN (** Hollow triangle pointing downward *) 44 | | SOLID_TRI_DOWN (** Filled triangle pointing downward *) 45 | | SQUARE (** Hollow square *) 46 | | SOLID_SQUARE (** Filled square *) 47 | | BOWTIE (** Hollow bowtie *) 48 | | SOLID_BOWTIE (** Filled bowtie *) 49 | | HGLASS (** Hollow hourglass *) 50 | | SOLID_HGLASS (** Filled hourglass *) 51 | | DIAMOND (** Hollow diamond *) 52 | | SOLID_DIAMOND (** Filled Diamond *) 53 | | STAR (** Hollow star *) 54 | | SOLID_STAR (** Filled Star *) 55 | | TRI_UP_DOWN (** Hollow triangles pointing up and down overlaid *) 56 | | SOLID_TRI_RIGHT (** Filled triangle point right *) 57 | | SOLID_TRI_LEFT (** Filled triangle pointing left *) 58 | | HOLLOW_PLUS (** Hollow plus sign *) 59 | | SOLID_PLUS (** Solid plus sign *) 60 | | PENTAGON (** Pentagon *) 61 | | HEXAGON (** Hexagon *) 62 | | HEPTAGON (** Heptagon *) 63 | | OCTAGON (** Octagon *) 64 | | STAR_4 (** 4-pointed star *) 65 | | STAR_5 (** 5-pointed star (pentagram) *) 66 | | STAR_6 (** 6-pointed star (hexagram) *) 67 | | STAR_7 (** 7-pointed star (heptagram) *) 68 | | STAR_8 (** 8-pointed star (octagram) *) 69 | | VLINE (** verical line *) 70 | | HLINE (** horizontal line *) 71 | | OMARK (** o-mark *) 72 | 73 | type scale_options = 74 | | OPTION_X_LOG (** Logarithmic X-axis *) 75 | | OPTION_Y_LOG (** Logarithmic Y-axis *) 76 | | OPTION_Z_LOG (** Logarithmic Z-axis *) 77 | | OPTION_FLIP_X (** Flip X-axis *) 78 | | OPTION_FLIP_Y (** Flip Y-axis *) 79 | | OPTION_FLIP_Z (** Flip Z-axis *) 80 | 81 | type spline_algo = 82 | | GeneralizedCrossValidatedSmoothing 83 | | InterpolatingNaturalCubic 84 | | CubicBSpline 85 | 86 | type font = 87 | | TIMES_ROMAN 88 | | TIMES_ITALIC 89 | | TIMES_BOLD 90 | | TIMES_BOLDITALIC 91 | | HELVETICA 92 | | HELVETICA_OBLIQUE 93 | | HELVETICA_BOLD 94 | | HELVETICA_BOLDOBLIQUE 95 | | COURIER 96 | | COURIER_OBLIQUE 97 | | COURIER_BOLD 98 | | COURIER_BOLDOBLIQUE 99 | | SYMBOL 100 | | BOOKMAN_LIGHT 101 | | BOOKMAN_LIGHTITALIC 102 | | BOOKMAN_DEMI 103 | | BOOKMAN_DEMIITALIC 104 | | NEWCENTURYSCHLBK_ROMAN 105 | | NEWCENTURYSCHLBK_ITALIC 106 | | NEWCENTURYSCHLBK_BOLD 107 | | NEWCENTURYSCHLBK_BOLDITALIC 108 | | AVANTGARDE_BOOK 109 | | AVANTGARDE_BOOKOBLIQUE 110 | | AVANTGARDE_DEMI 111 | | AVANTGARDE_DEMIOBLIQUE 112 | | PALATINO_ROMAN 113 | | PALATINO_ITALIC 114 | | PALATINO_BOLD 115 | | PALATINO_BOLDITALIC 116 | | ZAPFCHANCERY_MEDIUMITALIC 117 | | ZAPFDINGBATS 118 | 119 | type text_precision = 120 | | STRING (** String precision (higher quality) *) 121 | | CHAR (** Character precision (medium quality) *) 122 | | STROKE (** Stroke precision (lower quality) *) 123 | 124 | type text_path_direction = 125 | | RIGHT (** left-to-right *) 126 | | LEFT (** right-to-left *) 127 | | UP (** downside-up *) 128 | | DOWN (** upside-down *) 129 | 130 | type text_halign = 131 | | NORMAL 132 | | LEFT (** Left justify *) 133 | | CENTER (** Center justify *) 134 | | RIGHT (** Right justify *) 135 | 136 | type text_valign = 137 | | NORMAL 138 | | TOP (** Align with the top of the characters *) 139 | | CAP (** Aligned with the cap of the characters *) 140 | | HALF (** Aligned with the half line of the characters *) 141 | | BASE (** Aligned with the base line of the characters *) 142 | | BOTTOM (** Aligned with the bottom line of the characters *) 143 | 144 | type pattern_style 145 | (** Pattern style, see also {{: https://gr-framework.org/patterns.html} GR Fill Patterns and Hatches} *) 146 | 147 | val pattern_style : int -> pattern_style 148 | 149 | type hatch_style 150 | (** Hatch style, see also {{: https://gr-framework.org/patterns.html} GR Fill Patterns and Hatches} *) 151 | 152 | val hatch_style : int -> hatch_style 153 | 154 | type fill_style = 155 | | HOLLOW (** No filling. Just draw the bounding polyline *) 156 | | SOLID (** Fill the interior of the polygon using the fill color index *) 157 | | PATTERN of pattern_style 158 | (** Fill the interior of the polygon using the style index as a pattern index *) 159 | | HATCH of hatch_style 160 | (** Fill the interior of the polygon using the style index as a cross-hatched style *) 161 | 162 | (** Color Maps, see also {{: https://gr-framework.org/colormaps.html} GR Color Maps} *) 163 | type color_map = 164 | | Uniform 165 | | Temperature 166 | | Grayscale 167 | | Glowing 168 | | Rainbowlike 169 | | Geologic 170 | | Greenscale 171 | | Cyanscale 172 | | Bluescale 173 | | Magentascale 174 | | Redscale 175 | | Flame 176 | | Brownscale 177 | | Pilatus 178 | | Autumn 179 | | Bone 180 | | Cool 181 | | Copper 182 | | Gray 183 | | Hot 184 | | Hsv 185 | | Jet 186 | | Pink 187 | | Spectral 188 | | Spring 189 | | Summer 190 | | Winter 191 | | Gist_Earth 192 | | Gist_Heat 193 | | Gist_Ncar 194 | | Gist_Rainbow 195 | | Gist_Stern 196 | | Afmhot 197 | | Brg 198 | | Bwr 199 | | Coolwarm 200 | | Cmrmap 201 | | Cubehelix 202 | | Gnuplot 203 | | Gnuplot2 204 | | Ocean 205 | | Rainbow 206 | | Seismic 207 | | Terrain 208 | | Viridis 209 | | Inferno 210 | | Plasma 211 | | Magma 212 | 213 | type surface_options = 214 | | LINES (** Use X Y polylines to denote the surface *) 215 | | MESH (** Use a wire grid to denote the surface *) 216 | | FILLED_MESH (** Applies an opaque grid to the surface *) 217 | | Z_SHADED_MESH (** Applies Z-value shading to the surface *) 218 | | COLORED_MESH (** Applies a colored grid to the surface *) 219 | | CELL_ARRAY 220 | (** Applies a grid of individually-colored cells to the surface *) 221 | | SHADED_MESH (** Applies light source shading to the 3-D surface *) 222 | 223 | type segment 224 | 225 | (** *) 226 | module Workstation : sig 227 | type id 228 | 229 | (** Available workstation types, see also {{: https://gr-framework.org/workstations.html} GR Workstation Types} *) 230 | type workstation_type = 231 | | WISS (** Workstation Independent Segment ptr Storage *) 232 | | WinGDI (** Windows ptr GDI *) 233 | | PS_1 (**PostScript (b/w \@-> color) *) 234 | | PS_2 (**PostScript (b/w \@-> color) *) 235 | | PS_3 (**PostScript (b/w \@-> color) *) 236 | | PS_4 (**PostScript (b/w \@-> color) *) 237 | | PDFPlain (** Portable Document Format ptr plain *) 238 | | PDFCompressed (** Portable Document Format ptr compressed *) 239 | | X_1 (** X ptr Windows *) 240 | | X_2 (** X ptr Windows *) 241 | | X_3 (** X ptr Windows *) 242 | | X_4 (** X ptr Windows *) 243 | | SunRF (** Sun Raster file (RF) *) 244 | | GIF87 (** Graphics Interchange Format ptr GIF87 *) 245 | | GIF89 (**Graphics Interchange Format ptr GIF89 *) 246 | | MotifUIL (** Motif User Interface Language (UIL) *) 247 | | BMP (** Windows Bitmap (BMP) *) 248 | | JPEG (** JPEG image ptr file *) 249 | | PNG (** Portable Network Graphics file (PNG) *) 250 | | TIFF (** Tagged Image File Format (TIFF) *) 251 | | Gtk (** ptr Gtk *) 252 | | Wx (** ptr wxWidgets *) 253 | | Qt4 (** ptr Qt4 *) 254 | | SVG (** Scaleable Vector Graphics (SVG) *) 255 | | WMF (** Windows ptr Metafile *) 256 | | Quartz (** ptr Quartz *) 257 | | Sock (** Socket ptr driver *) 258 | | ZMQ (** 0MQ ptr driver *) 259 | | OGL (** ptr OpenGL *) 260 | 261 | val wid : int -> id 262 | 263 | val open' : id -> string -> workstation_type -> unit 264 | (** [open' workstation_id connection type] opens a graphical workstation. 265 | 266 | Parameters 267 | 268 | - [workstation_id]: a workstation identifier 269 | - [connection]: a connection identifier 270 | - [type]: the desired workstation type 271 | *) 272 | 273 | val close : id -> unit 274 | 275 | val activate : id -> unit 276 | 277 | val deactivate : id -> unit 278 | 279 | val clear : unit -> unit 280 | 281 | val update : unit -> unit 282 | 283 | val set_window : float -> float -> float -> float -> unit 284 | (** [set_window xmin xmax ymin ymax] sets the area of the NDC viewport that is to be drawn in the workstation window. 285 | 286 | This function defines the rectangular area of the Normalized Device Coordinate space to be output to the device. 287 | By default, the workstation transformation will map the range \[0,1\] x \[0,1\] in NDC onto the largest square on the workstation’s display surface. 288 | The aspect ratio of the workstation window is maintained at 1 to 1. 289 | 290 | Parameters 291 | 292 | - [xmin]: The left horizontal coordinate of the workstation window (0 <= [xmin] < [xmax]). 293 | - [xmax]: The right horizontal coordinate of the workstation window ([xmin] < [xmax] <= 1). 294 | - [ymin]: The bottom vertical coordinate of the workstation window (0 <= [ymin] < [ymax]). 295 | - [ymax]: The top vertical coordinate of the workstation window ([ymin] < [ymax] <= 1). 296 | *) 297 | 298 | val set_viewport : float -> float -> float -> float -> unit 299 | (** [set_viewport xmin xmax ymin ymax] defines the size of the workstation graphics window in meters. 300 | 301 | This function places a workstation window on the display of the specified size in meters. 302 | This command allows the workstation window to be accurately sized for a display or hardcopy device, and is often useful for sizing graphs for desktop publishing applications. 303 | 304 | Parameters 305 | 306 | - [xmin]: The left horizontal coordinate of the workstation window. 307 | - [xmax]: The right horizontal coordinate of the workstation window. 308 | - [ymin]: The bottom vertical coordinate of the workstation window. 309 | - [ymax]: The top vertical coordinate of the workstation window. 310 | *) 311 | 312 | val copy_segment : segment -> unit 313 | 314 | val redraw_segment : unit -> unit 315 | end 316 | 317 | module Gks : sig 318 | val emergency_close : unit -> unit 319 | 320 | val update : unit -> unit 321 | end 322 | 323 | module State : sig 324 | val save : unit -> unit 325 | 326 | val restore : unit -> unit 327 | 328 | val with_sandbox : (unit -> 'a) -> 'a 329 | end 330 | 331 | val set_window : float -> float -> float -> float -> unit 332 | (** [set_window xmin xmax ymin ymax] establishes a window, or rectangular subspace, of world coordinates to be plotted. If you desire log scaling or mirror-imaging of axes, use the gr_setscale function. 333 | 334 | This function defines the rectangular portion of the World Coordinate space (WC) to be associated with the specified normalization transformation. 335 | The WC window and the Normalized Device Coordinates (NDC) viewport define the normalization transformation through which all output primitives are mapped. 336 | The WC window is mapped onto the rectangular NDC viewport which is, in turn, mapped onto the display surface of the open and active workstation, in device coordinates. 337 | By default, GR uses the range \[0,1\] x \[0,1\], in world coordinates, as the normalization transformation window. 338 | 339 | Parameters 340 | 341 | - [xmin]: The left horizontal coordinate of the window ([xmin] < [xmax]). 342 | - [xmax]: The right horizontal coordinate of the window ([xmin] < [xmax]). 343 | - [ymin]: The bottom vertical coordinate of the window ([ymin] < [ymax]). 344 | - [ymax]: The top vertical coordinate of the window ([ymin] < [ymax]). 345 | 346 | *) 347 | 348 | val set_viewport : float -> float -> float -> float -> unit 349 | (** [set_viewport xmin xmax ymin ymax] establishes a rectangular subspace of normalized device coordinates. 350 | 351 | This function defines the rectangular portion of the Normalized Device Coordinate (NDC) space to be associated with the specified normalization transformation. 352 | The NDC viewport and World Coordinate (WC) window define the normalization transformation through which all output primitives pass. 353 | The WC window is mapped onto the rectangular NDC viewport which is, in turn, mapped onto the display surface of the open and active workstation, in device coordinates. 354 | 355 | Parameters 356 | 357 | - [xmin]: The left horizontal coordinate of the viewport (0 <= [xmin] < [xmax]). 358 | - [xmax]: The right horizontal coordinate of the viewport ([xmin] < [xmax] <= 1). 359 | - [ymin]: The bottom vertical coordinate of the viewport (0 <= [ymin] < [ymax]). 360 | - [ymax]: The top vertical coordinate of the viewport ([ymin] < [ymax] <= 1). 361 | 362 | *) 363 | 364 | val select_transformation : int -> unit 365 | (** [select_transformation transform] selects a predefined transformation from world coordinates to normalized device coordinates. 366 | 367 | Parameters 368 | 369 | - [transform]: A normalization transformation number: 370 | {ul 371 | {- [0] selects the identity transformation in which both the window and viewport have the range of 0 to 1;} 372 | {- [>= 1] selects a normalization transformation as defined by [set_window] and [set_viewport].} 373 | } 374 | *) 375 | 376 | val clip : bool -> unit 377 | (** [clip indicator] sets the clipping indicator. 378 | This function enables or disables clipping of the image drawn in the current window. 379 | Clipping is defined as the removal of those portions of the graph that lie outside of the defined viewport. If clipping is on, GR does not draw generated output primitives past the viewport boundaries. If clipping is off, primitives may exceed the viewport boundaries, and they will be drawn to the edge of the workstation window. 380 | By default, clipping is on. 381 | 382 | Parameters 383 | 384 | - [indicator]: An indicator specifying whether clipping is on or off. 385 | {ul 386 | {- [false] clipping is off. Data outside of the window will be drawn.} 387 | {- [true] clipping is on. Data outside of the window will not be drawn.} 388 | } 389 | *) 390 | 391 | val segment : int -> segment 392 | 393 | val create_segment : segment -> unit 394 | 395 | val set_segment_transform : 396 | segment -> float -> float -> float -> float -> float -> float -> float -> unit 397 | 398 | val close_segment : unit -> unit 399 | 400 | val set_space : float -> float -> int -> int -> int 401 | (** [set_space zmin zmax rotation tilt] sets the abstract Z-space used for mapping three-dimensional output primitives into the current world coordinate space. 402 | 403 | This function establishes the limits of an abstract Z-axis and defines the angles for rotation and for the viewing angle (tilt) of a simulated three-dimensional graph, used for mapping corresponding output primitives into the current window. 404 | These settings are used for all subsequent three-dimensional output primitives until other values are specified. 405 | Angles of rotation and viewing angle must be specified between 0 and 90 degrees. 406 | 407 | Parameters 408 | 409 | - [zmin]: Minimum value for the Z-axis. 410 | - [zmax]: Maximum value for the Z-axis. 411 | - [rotation]: Angle for the rotation of the X axis, in degrees. 412 | - [tilt]: Viewing angle of the Z axis, in degrees. 413 | *) 414 | 415 | val set_linetype : linetype -> unit 416 | 417 | val set_linewidth : float -> unit 418 | (** [set_linewidth lw] defines the line width of subsequent polyline output primitives. 419 | 420 | The line width is calculated as the nominal line width generated on the workstation multiplied by the line width scale factor. 421 | This value is mapped by the workstation to the nearest available line width. 422 | The default line width is 1.0, or 1 times the line width generated on the graphics device. 423 | *) 424 | 425 | val set_linecolorindex : int -> unit 426 | (** [set_linecolorindex c] defines the color of subsequent polyline output primitives. 427 | Note: c < 1256 428 | *) 429 | 430 | val set_markertype : markertype -> unit 431 | 432 | val set_markersize : float -> unit 433 | (** [set_markersize ms] specify the marker size for polymarkers. 434 | 435 | The polymarker size is calculated as the nominal size generated on the graphics device multiplied by the marker size scale factor. 436 | *) 437 | 438 | val set_markercolorindex : int -> unit 439 | (** [set_markercolorindex c] define the color of subsequent markers output primitives. 440 | Note: c < 1256 441 | *) 442 | 443 | (** [set_arrowstyle style] sets the arrow style to be used for subsequent arrow commands. 444 | 445 | This function defines the arrow style for subsequent arrow primitives. 446 | The default arrow style is 1. 447 | 448 | Parameters 449 | 450 | 451 | - [style]: The arrow style to be used. Available styles are: 452 | 453 | + simple, single-ended 454 | + simple, single-ended, acute head 455 | + hollow, single-ended 456 | + filled, single-ended 457 | + triangle, single-ended 458 | + filled triangle, single-ended 459 | + kite, single-ended 460 | + filled kite, single-ended 461 | + simple, double-ended 462 | + simple, double-ended, acute head 463 | + hollow, double-ended 464 | + filled, double-ended 465 | + triangle, double-ended 466 | + filled triangle, double-ended 467 | + kite, double-ended 468 | + filled kite, double-ended 469 | + double line, single-ended 470 | + double line, double-ended 471 | 472 | (*TODO: Use a sum type.*) 473 | *) 474 | 475 | val set_arrowstyle : int -> unit 476 | 477 | val set_arrowsize : float -> unit 478 | (** [set_arrowsize size] sets the arrow size to be used for subsequent arrow commands. 479 | 480 | This function defines the arrow size for subsequent arrow primitives. 481 | The default arrow size is 1. 482 | 483 | Parameters 484 | 485 | - [size]: The arrow size to be used 486 | 487 | *) 488 | 489 | val set_text_font_prec : ?precision:text_precision -> font -> unit 490 | (** [set_text_font_prec ?precision font] specifies the text font and precision for subsequent text output primitives. 491 | 492 | The appearance of a font depends on the text precision value specified. 493 | STRING, CHARACTER or STROKE precision allows for a greater or lesser realization of the text primitives, for efficiency. 494 | STRING is the default precision for GR and produces the highest quality output. 495 | 496 | XXX: CHARACTER and STROKE precision seem to be broken (and to break the [axes] command with it...)! 497 | *) 498 | 499 | val set_char_expand_factor : float -> unit 500 | (** [set_char_expand_factor factor] sets the current character expansion factor (width to height ratio). 501 | 502 | This function defines the width of subsequent text output primitives. 503 | The expansion factor alters the width of the generated characters, but not their height. 504 | The default text expansion factor is 1, or one times the normal width-to-height ratio of the text. 505 | 506 | Parameters 507 | 508 | - [factor]: Text expansion factor applied to the nominal text width-to-height ratio 509 | *) 510 | 511 | val set_text_colorindex : int -> unit 512 | (** [set_text_colorindex color] sets the current text color index. 513 | 514 | This function defines the color of subsequent text output primitives. 515 | GR uses the default foreground color (black=1) for the default text color index. 516 | 517 | Parameters 518 | 519 | - [color]: The text color index (COLOR < 1256) 520 | *) 521 | 522 | val set_char_height : float -> unit 523 | (** [set_char_height height] sets the current character height. 524 | 525 | This function defines the height of subsequent text output primitives. 526 | Text height is defined as a percentage of the default window. 527 | GR uses the default text height of 0.027 (2.7% of the height of the default window). 528 | *) 529 | 530 | val set_char_up : float * float -> unit 531 | (** [set_char_up (x, y)] 532 | Set the current character text angle up vector. 533 | This function defines the vertical rotation of subsequent text output primitives. 534 | The text up vector is initially set to (0, 1), horizontal to the baseline. 535 | 536 | Parameters 537 | 538 | - [x]: X coordinate of the text up vector 539 | - [y]: Y coordinate of the text up vector 540 | *) 541 | 542 | val set_char_space : float -> unit 543 | 544 | val set_text_path : text_path_direction -> unit 545 | (** [set_text_path direction] defines the current direction in which subsequent text will be drawn. *) 546 | 547 | val set_text_align : text_halign option -> text_valign option -> unit 548 | (** [set_text_align horizontal vertical] specifies how the characters in a text primitive will be aligned in horizontal and vertical space. 549 | The default text alignment indicates horizontal left alignment and vertical baseline alignment. 550 | *) 551 | 552 | val set_fill_interior_style : fill_style -> unit 553 | (** [set_fill_interior_style style] sets the fill area interior style to be used for fill areas. 554 | 555 | This function defines the interior style for subsequent fill area output primitives. 556 | The default interior style is HOLLOW. 557 | *) 558 | 559 | val set_fill_colorindex : int -> unit 560 | (** [set_fill_colorindex color] sets the current fill area color index. 561 | 562 | This function defines the color of subsequent fill area output primitives. 563 | GR uses the default foreground color (black=1) for the default fill area color index. 564 | 565 | Parameters 566 | 567 | - [color]: The fill area color index (COLOR < 1256) 568 | *) 569 | 570 | val set_color_representation : int -> float * float * float -> unit 571 | (** [set_color_representation index (red, green, blue)] redefines an existing color index representation by specifying an RGB color triplet. 572 | 573 | Parameters 574 | 575 | - [index]: Color index in the range 0 to 1256 576 | - [red]: Red intensity in the range 0.0 to 1.0 577 | - [green]: Green intensity in the range 0.0 to 1.0 578 | - [blue]: Blue intensity in the range 0.0 to 1.0 579 | 580 | *) 581 | 582 | val set_colormap : color_map -> unit 583 | (** [set_colormap cmap] sets the currently used colormap. 584 | 585 | A list of colormaps can be found at: {{: https://gr-framework.org/colormaps.html} GR Colormaps}. 586 | *) 587 | 588 | val set_scale : scale_options list -> int 589 | 590 | val set_shadow : float * float -> float -> unit 591 | (** [set_shadow (offsetx, offsety) blur] 592 | Allows drawing of shadows, realized by images painted underneath, and offset from, graphics objects such that the shadow mimics the effect of a light source cast on the graphics objects. 593 | 594 | Parameters 595 | 596 | - [offsetx]: An x-offset, which specifies how far in the horizontal direction the shadow is offset from the object 597 | - [offsety]: A y-offset, which specifies how far in the vertical direction the shadow is offset from the object 598 | - [blur]: A blur value, which specifies whether the object has a hard or a diffuse edge 599 | *) 600 | 601 | val set_transparency : float -> unit 602 | (** [set_transparency alpha] sets the value of the alpha component associated with GR colors. 603 | 604 | Parameters 605 | 606 | - [alpha]: An alpha value (0.0 - 1.0) 607 | *) 608 | 609 | val set_coord_transform : 610 | (float Ctypes_static.ptr, 'a, 'b) Bigarray.Genarray.t -> unit 611 | (** [set_coord_transform transform] 612 | Change the coordinate transformation according to the given matrix. 613 | Parameters 614 | 615 | - [mat]: 2D transformation matrix (3x2) 616 | *) 617 | 618 | module Graphics : sig 619 | type t 620 | 621 | val beging : t -> unit 622 | (** [beging path] 623 | Open a file for graphics output. 624 | 625 | [beging] allows to write all graphics output into a XML-formatted file until the [endg] functions is called. 626 | The resulting file may later be imported with the [import] function. 627 | 628 | Parameters 629 | 630 | - [path]: Filename for the graphics file. 631 | *) 632 | 633 | val endg : unit -> unit 634 | 635 | val get : unit -> t 636 | 637 | val draw : t -> int 638 | 639 | val import : string -> int 640 | end 641 | 642 | val polyline : 643 | ?linetype:linetype -> 644 | ?linewidth:float -> 645 | ?coloridx:int -> 646 | (float, 'a, 'b) Bigarray.Genarray.t -> 647 | (float, 'c, 'd) Bigarray.Genarray.t -> 648 | unit 649 | (** 650 | [polyline ?linetype ?linewidth ?coloridx x y] draws a polyline using the current line attributes, starting from the first data point and ending at the last data point. 651 | 652 | The values for [x] and [y] are in world coordinates. 653 | The attributes that control the appearance of a polyline are [linetype], [linewidth] and [color index]. 654 | *) 655 | 656 | val polyline3d : 657 | ?linetype:linetype -> 658 | ?linewidth:float -> 659 | ?coloridx:int -> 660 | (float, 'a, 'b) Bigarray.Genarray.t -> 661 | (float, 'c, 'd) Bigarray.Genarray.t -> 662 | (float, 'e, 'f) Bigarray.Genarray.t -> 663 | unit 664 | (** 665 | [polyline3d ?linetype ?linewidth ?coloridx x y z] draws a polyline using the current line attributes, starting from the first data point and ending at the last data point. 666 | 667 | The values for [x], [y] and [z] are in world coordinates. 668 | The attributes that control the appearance of a polyline are [linetype], [linewidth] and [color index]. 669 | *) 670 | 671 | val polymarker : 672 | ?markertype:markertype -> 673 | ?markersize:float -> 674 | ?coloridx:int -> 675 | (float, 'a, 'b) Bigarray.Genarray.t -> 676 | (float, 'c, 'd) Bigarray.Genarray.t -> 677 | unit 678 | (** 679 | [polymarker ?markertype ?markersize ?coloridx x y] draws marker symbols centered at the given data points. 680 | 681 | The values for [x] and [y] are in world coordinates. 682 | The attributes that control the appearance of a polyline are [markertype], [markersize] and [color index]. 683 | *) 684 | 685 | val polymarker3d : 686 | ?markertype:markertype -> 687 | ?markersize:float -> 688 | ?coloridx:int -> 689 | (float, 'a, 'b) Bigarray.Genarray.t -> 690 | (float, 'c, 'd) Bigarray.Genarray.t -> 691 | (float, 'e, 'f) Bigarray.Genarray.t -> 692 | unit 693 | (** 694 | [polymarker3d ?markertype ?markersize ?coloridx x y z] draws marker symbols centered at the given data points. 695 | 696 | The values for [x], [y] and [z] are in world coordinates. 697 | The attributes that control the appearance of a polyline are [markertype], [markersize] and [color index]. 698 | *) 699 | 700 | val text : float -> float -> string -> unit 701 | (** [text x y content] draws a text at position [x], [y] using the current text attributes. 702 | 703 | The values for [x] and [y] are in normalized device coordinates. 704 | The attributes that control the appearance of text are text [font] and [precision], [character expansion factor], [character spacing], [text color index], [character height], [character up vector], [text path] and [text alignment]. 705 | 706 | (* TODO: add styling options *) 707 | *) 708 | 709 | val fillarea : 710 | (float, 'a, 'b) Bigarray.Genarray.t -> 711 | (float, 'c, 'd) Bigarray.Genarray.t -> 712 | unit 713 | (** 714 | [fillarea x y] allows you to specify a polygonal shape of an area to be filled. 715 | The vectors [x] and [y] specify the coordinates of the polygonal shape corners. 716 | 717 | The attributes that control the appearance of fill areas are fill area [interior style], fill area [style index] and fill area [color index]. 718 | (* TODO: add styling options *) 719 | *) 720 | 721 | val cellarray : 722 | float * float -> 723 | float * float -> 724 | int * int -> 725 | int * int -> 726 | int * int -> 727 | (int, 'a, 'b) Bigarray.Genarray.t -> 728 | unit 729 | (** [cellarray (xmin, xmax) (ymin, ymax) (dimx, dimy) (scol, srow) (ncol, nrow) color] displays rasterlike images in a device-independent manner. 730 | The cell array function partitions a rectangle given by two corner points into DIMX X DIMY cells, each of them colored individually by the corresponding color index of the given cell array. 731 | 732 | The values for [xmin], [xmax], [ymin] and [ymax] are in world coordinates. 733 | 734 | Parameters 735 | 736 | - [xmin]: X coordinate of the lower left point of the rectangle 737 | - [ymin]: Y coordinate of the lower left point of the rectangle 738 | - [xmax]: X coordinate of the upper right point of the rectangle 739 | - [ymax]: Y coordinate of the upper right point of the rectangle 740 | - [dimx]: X dimension of the color index array 741 | - [dimy]: Y dimension of the color index array 742 | - [scol]: number of leading columns in the color index array 743 | - [srow]: number of leading rows in the color index array 744 | - [ncol]: total number of columns in the color index array 745 | - [nrow]: total number of rows in the color index array 746 | - [color]: color index array 747 | 748 | Note: [nonuniformcellarray] and [polycellarray] have been introduced in newer versions of gr. 749 | *) 750 | 751 | val spline : 752 | ?linetype:linetype -> 753 | ?linewidth:float -> 754 | ?coloridx:int -> 755 | (float, 'a, 'b) Bigarray.Genarray.t -> 756 | (float, 'c, 'd) Bigarray.Genarray.t -> 757 | int -> 758 | spline_algo -> 759 | unit 760 | (** [spline ?linetype ?linewidth ?coloridx x y m method_t] generates a cubic spline-fit, starting from the first data point and ending at the last data point. 761 | 762 | The values for [x] and [y] are in world coordinates. 763 | The attributes that control the appearance of a spline-fit are [linetype], [linewidth] and [color index]. 764 | 765 | Parameters 766 | 767 | - [x]: The X coordinates 768 | - [y]: The Y coordinates 769 | - [m]: The number of points in the polygon to be drawn 770 | - [method]: The smoothing method 771 | 772 | *) 773 | 774 | val gridit : 775 | (float, 'a, 'b) Bigarray.Genarray.t -> 776 | (float, 'c, 'd) Bigarray.Genarray.t -> 777 | (float, 'e, 'f) Bigarray.Genarray.t -> 778 | int * int -> 779 | (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Genarray.t 780 | * (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Genarray.t 781 | * (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Genarray.t 782 | (** [gridit x y z (nx, ny)] interpolates data from arbitrary points at points on a rectangular grid. 783 | 784 | Parameters 785 | 786 | - [x]: The X coordinates of the input points 787 | - [y]: The Y coordinates of the input points 788 | - [z]: The values of the points 789 | - [nx]: The number of points in X direction for the output grid 790 | - [ny]: The number of points in Y direction for the output grid 791 | 792 | Returns the tuple (x', y', z') with 793 | 794 | - [x']: The points in X direction for the output grid 795 | - [y']: The points in Y direction for the output grid 796 | - [z']: The interpolated values on the [nx] x [ny] grid points 797 | *) 798 | 799 | val tex_text : float * float -> string -> int 800 | (** [tex_text (x, y) text] draws a text at position [x], [y] using the current text attributes. 801 | Strings can be defined to create basic mathematical expressions and Greek letters. 802 | 803 | The values for X and Y are in normalized device coordinates. 804 | The attributes that control the appearance of text are text [font] and [precision], [character expansion factor], [character spacing], [text color index], [character height], [character up vector], [text path] and [text alignment]. 805 | 806 | Parameters 807 | 808 | - [x]: The X coordinate of starting position of the text string 809 | - [y]: The Y coordinate of starting position of the text string 810 | - [text]: The text to be drawn 811 | 812 | The character string is interpreted to be a simple mathematical formula. 813 | The following notations apply: 814 | 815 | - Subscripts and superscripts: These are indicated by carets (‘^’) and underscores (‘_’). 816 | If the sub/superscript contains more than one character, it must be enclosed in curly braces (‘\{\}’). 817 | - Fractions are typeset with A ‘/’ B, where A stands for the numerator and B for the denominator. 818 | 819 | To include a Greek letter you must specify the corresponding keyword after a backslash (‘') character. The text translator produces uppercase or lowercase Greek letters depending on the case of the keyword. 820 | For more sophisticated mathematical formulas, you should use the gr_mathtex function. 821 | 822 | See the full documentation at {{: https://gr-framework.org/c-gr.html#_CPPv410gr_textextddPc} GR Documentation for gr_textext}. 823 | *) 824 | 825 | val math_tex : float * float -> string -> unit 826 | (** [math_tex (x, y) tex] generates a character string starting at the given location. 827 | Strings can be defined to create mathematical symbols and Greek letters using LaTeX syntax. 828 | 829 | Parameters 830 | 831 | - [x]: The X coordinate of the starting position of the text string 832 | - [y]: The Y coordinate of the starting position of the text string 833 | - [tex]: The TeX text string to be drawn 834 | *) 835 | 836 | val axes : 837 | ?scale:scale_options list -> 838 | ?linetype:linetype -> 839 | ?linewidth:float -> 840 | ?coloridx:int -> 841 | ?origin:float * float -> 842 | ?major:int * int -> 843 | ?tick_size:float -> 844 | float -> 845 | float -> 846 | unit 847 | (** [axes ?scale ?linetype ?linewidth ?origin:(0,0) ?major:(1,1) ?size:1 x_tick y_tick] draws X and Y coordinate axes with linearly and/or logarithmically spaced tick marks. 848 | Tick marks are positioned along each axis so that major tick marks fall on the axes origin (whether visible or not). 849 | Major tick marks are labeled with the corresponding data values. 850 | Axes are drawn according to the scale of the window. 851 | 852 | Parameters 853 | 854 | - [x_tick]: The interval between minor tick marks on the X axis. 855 | - [y_tick]: The interval between minor tick marks on the Y axis. 856 | - [x_org]: The world coordinate of the origin (point of intersection) of the X axis. 857 | - [y_org]: The world coordinate of the origin (point of intersection) of the Y axis. 858 | - [major_x]: Unitless integer value specifying the number of minor tick intervals between major tick marks on the X axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis. 859 | - [major_y]: Unitless integer value specifying the number of minor tick intervals between major tick marks on the Y axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis. 860 | - [tick_size]: The length of minor tick marks specified in a normalized device coordinate unit. Major tick marks are twice as long as minor tick marks. A negative value reverses the tick marks on the axes from inward facing to outward facing (or vice versa) 861 | *) 862 | 863 | val axes_labels : 864 | ?scale:scale_options list -> 865 | ?linetype:linetype -> 866 | ?linewidth:float -> 867 | ?coloridx:int -> 868 | ?origin:float * float -> 869 | ?major:int * int -> 870 | ?tick_size:float -> 871 | (float -> float -> string -> float -> unit) -> 872 | (float -> float -> string -> float -> unit) -> 873 | float -> 874 | float -> 875 | unit 876 | (** [axes_labels ?(scale = []) ?linetype ?linewidth ?coloridx ?(origin = 0.0, 0.0) ?(major = 1, 1) ?(tick_size = -0.01) (fpx : float -> float -> string -> float -> unit) (fpy : float -> float -> string -> float -> unit) x_tick y_tick] creates axes in the current workspace and supply a custom function for changing the behaviour of the tick labels. 877 | 878 | Similar to [axes] but allows more fine-grained control over tick labels and text positioning by supplying callback functions. 879 | Within the callback function you can use normal GR text primitives for performing any manipulations on the label text. 880 | 881 | See [axes] for more details on drawing axes. 882 | 883 | Parameters 884 | 885 | - [x_tick]: The interval between minor tick marks on the X axis. 886 | - [y_tick]: The interval between minor tick marks on the Y axis. 887 | - [x_org]: The world coordinate of the origin (point of intersection) of the X axis. 888 | - [y_org]: The world coordinate of the origin (point of intersection) of the Y axis. 889 | - [major_x]: Unitless integer value specifying the number of minor tick intervals between major tick marks on the X axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis. 890 | - [major_y]: Unitless integer value specifying the number of minor tick intervals between major tick marks on the Y axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis. 891 | - [tick_size]: The length of minor tick marks specified in a normalized device coordinate unit. Major tick marks are twice as long as minor tick marks. A negative value reverses the tick marks on the axes from inward facing to outward facing (or vice versa). 892 | - [fpx]: Function pointer to a function that returns a label for a given tick on the X axis. The callback function should have the following arguments: 893 | - [x]: NDC of the label in X direction. 894 | - [y]: NDC of the label in Y direction. 895 | - [svalue]: Internal string representation of the text drawn by GR at (x,y). 896 | - [value]: Floating point representation of the label drawn at (x,y). 897 | - [fpy]: Exactly same as the fpx above, but for the the Y axis. 898 | 899 | *) 900 | 901 | val axes3d : 902 | ?scale:scale_options list -> 903 | ?linetype:linetype -> 904 | ?linewidth:float -> 905 | ?coloridx:int -> 906 | ?origin:float * float * float -> 907 | ?major:int * int * int -> 908 | ?tick_size:float -> 909 | float -> 910 | float -> 911 | float -> 912 | unit 913 | (** [axes3d ?scale ?linetype ?linewidth ?origin:(0,0,0) ?major:(1,1,1) ?size:1 x_tick y_tick z_tick] draws X, Y and Z coordinate axes with linearly and/or logarithmically spaced tick marks. 914 | Tick marks are positioned along each axis so that major tick marks fall on the axes origin (whether visible or not). 915 | Major tick marks are labeled with the corresponding data values. 916 | Axes are drawn according to the scale of the window. 917 | 918 | Parameters 919 | 920 | - [x_tick]: The interval between minor tick marks on the X axis. 921 | - [y_tick]: The interval between minor tick marks on the Y axis. 922 | - [z_tick]: The length in world coordinates of the interval between minor grid lines in Z direction. 923 | - [x_org]: The world coordinate of the origin (point of intersection) of the X axis. 924 | - [y_org]: The world coordinate of the origin (point of intersection) of the Y axis. 925 | - [z_org]: The world coordinate of the origin (point of intersection) of the Z axis. 926 | - [major_x]: Unitless integer value specifying the number of minor tick intervals between major tick marks on the X axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis. 927 | - [major_y]: Unitless integer value specifying the number of minor tick intervals between major tick marks on the Y axis. Values of 0 or 1 imply no minor ticks. Negative values specify no labels will be drawn for the associated axis. 928 | - [major_z]: Unitless integer value specifying the number of minor grid lines between major grid lines on the Z axis. Values of 0 or 1 imply no grid lines. 929 | - [tick_size]: The length of minor tick marks specified in a normalized device coordinate unit. Major tick marks are twice as long as minor tick marks. A negative value reverses the tick marks on the axes from inward facing to outward facing (or vice versa) 930 | 931 | *) 932 | 933 | val surface : 934 | ?options:surface_options -> 935 | (float, 'a, 'b) Bigarray.Genarray.t -> 936 | (float, 'c, 'd) Bigarray.Genarray.t -> 937 | (float, 'e, 'f) Bigarray.Genarray.t -> 938 | unit 939 | (** [surface x y z ?option] draws a three-dimensional surface plot for the given data points. 940 | 941 | Here, [x] and [y] define a grid, [z] is a singly dimensioned array containing at least nx * ny data points. 942 | [z] describes the surface height at each point on the grid. 943 | 944 | Parameters 945 | 946 | - [x]: X coordinates 947 | - [y]: Y coordinates 948 | - [z]: Z coordinates 949 | - [option]: Surface display option 950 | *) 951 | 952 | val contour : 953 | ?major_h:int -> 954 | (float, 'a, 'b) Bigarray.Genarray.t -> 955 | (float, 'c, 'd) Bigarray.Genarray.t -> 956 | (float, 'e, 'f) Bigarray.Genarray.t -> 957 | (float, 'g, 'h) Bigarray.Genarray.t -> 958 | unit 959 | (** [contour ?major_h x y h z] sraw contours of a three-dimensional data set whose values are specified over a rectangular mesh. 960 | Contour lines may optionally be labeled. 961 | 962 | Parameters 963 | 964 | - [x]: X coordinates 965 | - [y]: Y coordinates 966 | - [h]: height values 967 | - [pz]: Z coordinates 968 | - [major_h]: Directs GR to label contour lines. 969 | For example, a value of 3 would label every third line. 970 | A value of 1 will label every line. 971 | A value of 0 produces no labels. 972 | To produce colored contour lines, add an offset of 1000 to [major_h]. 973 | 974 | *) 975 | 976 | val contourf : 977 | ?major_h:int -> 978 | (float, 'a, 'b) Bigarray.Genarray.t -> 979 | (float, 'c, 'd) Bigarray.Genarray.t -> 980 | (float, 'e, 'f) Bigarray.Genarray.t -> 981 | (float, 'g, 'h) Bigarray.Genarray.t -> 982 | unit 983 | (** [contourf ?(major_h = 0) x y h z] draws filled contour plot of a three-dimensional data set whose values are specified over a rectangular mesh. 984 | 985 | Parameters 986 | 987 | - [x]: X coordinates 988 | - [y]: Y coordinates 989 | - [h]: height values. If NULL, use nh evenly distributed height values between minimum and maximum Z value. 990 | - [major_h]: Directs GR to label contour lines. 991 | For example, a value of 3 would label every third line. 992 | A value of 1 will label every line. A value of 0 produces no labels. 993 | To produce colored contour lines, add an offset of 1000 to [major_h] 994 | 995 | *) 996 | 997 | val grid : 998 | ?scale:scale_options list -> 999 | ?linetype:linetype -> 1000 | ?linewidth:float -> 1001 | ?coloridx:int -> 1002 | ?origin:float * float -> 1003 | ?major:int * int -> 1004 | float -> 1005 | float -> 1006 | unit 1007 | (** [grid ?scale ?linetype ?linewidth ?origin:(0,0) ?major:(1,1) x_tick y_tick] draws a linear and/or logarithmic grid. 1008 | 1009 | Major grid lines correspond to the axes origin and major tick marks whether visible or not. 1010 | Minor grid lines are drawn at points equal to minor tick marks. 1011 | Major grid lines are drawn using black lines and minor grid lines are drawn using gray lines. 1012 | 1013 | Parameters 1014 | 1015 | - [x_tick]: The length in world coordinates of the interval between minor grid lines in X direction. 1016 | - [y_tick]: The length in world coordinates of the interval between minor grid lines in Y direction. 1017 | - [x_org]: The world coordinate of the origin (point of intersection) of the X axis. 1018 | - [y_org]: The world coordinate of the origin (point of intersection) of the Y axis. 1019 | - [major_x]: Unitless integer value specifying the number of minor grid lines between major grid lines on the X axis. Values of 0 or 1 imply no grid lines. 1020 | - [major_y]: Unitless integer value specifying the number of minor grid lines between major grid lines on the Y axis. Values of 0 or 1 imply no grid lines. 1021 | 1022 | *) 1023 | 1024 | val grid3d : 1025 | ?scale:scale_options list -> 1026 | ?linetype:linetype -> 1027 | ?linewidth:float -> 1028 | ?coloridx:int -> 1029 | ?origin:float * float * float -> 1030 | ?major:int * int * int -> 1031 | float -> 1032 | float -> 1033 | float -> 1034 | unit 1035 | (** [grid3d ?scale ?linetype ?linewidth ?origin:(0,0,0) ?major:(1,1,1) x_tick y_tick z_tick] draws a linear and/or logarithmic grid. 1036 | 1037 | Major grid lines correspond to the axes origin and major tick marks whether visible or not. 1038 | Minor grid lines are drawn at points equal to minor tick marks. 1039 | Major grid lines are drawn using black lines and minor grid lines are drawn using gray lines. 1040 | 1041 | Parameters 1042 | 1043 | - [x_tick]: The length in world coordinates of the interval between minor grid lines in X direction. 1044 | - [y_tick]: The length in world coordinates of the interval between minor grid lines in Y direction. 1045 | - [z_tick]: The length in world coordinates of the interval between minor grid lines in Z direction. 1046 | - [x_org]: The world coordinate of the origin (point of intersection) of the X axis. 1047 | - [y_org]: The world coordinate of the origin (point of intersection) of the Y axis. 1048 | - [z_org]: The world coordinate of the origin (point of intersection) of the Z axis. 1049 | - [major_x]: Unitless integer value specifying the number of minor grid lines between major grid lines on the X axis. Values of 0 or 1 imply no grid lines. 1050 | - [major_y]: Unitless integer value specifying the number of minor grid lines between major grid lines on the Y axis. Values of 0 or 1 imply no grid lines. 1051 | - [major_z]: Unitless integer value specifying the number of minor grid lines between major grid lines on the Z axis. Values of 0 or 1 imply no grid lines. 1052 | 1053 | *) 1054 | 1055 | val vertical_errorbars : 1056 | (float, 'a, 'b) Bigarray.Genarray.t -> 1057 | (float, 'c, 'd) Bigarray.Genarray.t -> 1058 | (float, 'e, 'f) Bigarray.Genarray.t -> 1059 | (float, 'g, 'h) Bigarray.Genarray.t -> 1060 | unit 1061 | (** [vertical_errorbars x y el eu] draws a standard vertical error bar graph. 1062 | 1063 | Parameters 1064 | 1065 | - [px]: X coordinates 1066 | - [py]: Y coordinates 1067 | - [el]: absolute values of the lower error bar data 1068 | - [eu]: absolute values of the upper error bar data 1069 | *) 1070 | 1071 | val horizontal_errorbars : 1072 | (float, 'a, 'b) Bigarray.Genarray.t -> 1073 | (float, 'c, 'd) Bigarray.Genarray.t -> 1074 | (float, 'e, 'f) Bigarray.Genarray.t -> 1075 | (float, 'g, 'h) Bigarray.Genarray.t -> 1076 | unit 1077 | (** [horizontal_errorbars x y el eu] draws a standard horizontal error bar graph. 1078 | 1079 | Parameters 1080 | 1081 | - [px]: X coordinates 1082 | - [py]: Y coordinates 1083 | - [el]: absolute values of the lower error bar data 1084 | - [eu]: absolute values of the upper error bar data 1085 | *) 1086 | 1087 | val titles3d : string -> string -> string -> unit 1088 | (** [titles3d x_title y_title z_title] displays axis titles just outside of their respective axes. 1089 | 1090 | Parameters 1091 | 1092 | - [x_title]: The text to be displayed on the X axis 1093 | - [y_title]: The text to be displayed on the Y axis 1094 | - [z_title]: The text to be displayed on the Z axis 1095 | *) 1096 | 1097 | val tricontour : 1098 | (float, 'a, 'b) Bigarray.Genarray.t -> 1099 | (float, 'c, 'd) Bigarray.Genarray.t -> 1100 | (float, 'e, 'f) Bigarray.Genarray.t -> 1101 | (float, 'g, 'h) Bigarray.Genarray.t -> 1102 | unit 1103 | (** [tricontour x y z levels] draws a contour plot for the given triangle mesh. 1104 | 1105 | Parameters 1106 | 1107 | - [x]: X coordinates 1108 | - [y]: Y coordinates 1109 | - [z]: Z coordinates 1110 | - [levels]: contour levels 1111 | *) 1112 | 1113 | val colorbar : unit -> unit 1114 | (** [colorbar ()] plots a colorbar. *) 1115 | 1116 | val tick : float -> float -> float 1117 | 1118 | module Print : sig 1119 | val beginp : string -> unit 1120 | (** [beginp path] opens and activates a print device. 1121 | 1122 | This function opens an additional graphics output device. 1123 | The device type is obtained from the given file extension. 1124 | 1125 | Parameters 1126 | 1127 | - [pathname]: Filename for the print device. 1128 | 1129 | The following file types are supported: 1130 | 1131 | - .ps, .eps PostScript 1132 | - .pdf Portable Document Format 1133 | - .bmp Windows Bitmap (BMP) 1134 | - .jpeg, .jpg JPEG image file 1135 | - .png Portable Network Graphics file (PNG) 1136 | - .tiff, .tif Tagged Image File Format (TIFF) 1137 | - .svg Scalable Vector Graphics 1138 | - .wmf Windows Metafile 1139 | - .mp4 MPEG-4 video file 1140 | - .webm WebM video file 1141 | - .ogg Ogg video file 1142 | *) 1143 | 1144 | val endp : unit -> unit 1145 | 1146 | val beginp_extended : 1147 | string -> 1148 | [< `Color | `GreyScale ] -> 1149 | [< `A0 1150 | | `A1 1151 | | `A2 1152 | | `A3 1153 | | `A4 1154 | | `A5 1155 | | `A6 1156 | | `A7 1157 | | `A8 1158 | | `A9 1159 | | `B0 1160 | | `B1 1161 | | `B10 1162 | | `B2 1163 | | `B3 1164 | | `B4 1165 | | `B5 1166 | | `B6 1167 | | `B7 1168 | | `B8 1169 | | `B9 1170 | | `C5E 1171 | | `Comm10E 1172 | | `DLE 1173 | | `Executive 1174 | | `Folio 1175 | | `Ledger 1176 | | `Legal 1177 | | `Letter 1178 | | `Tabloid ] -> 1179 | [< `Landscape | `Portrait ] -> 1180 | unit 1181 | (** [beginprint_ext path mode format orientation] opens and activates a print device with the given layout attributes. 1182 | 1183 | The available formats are: 1184 | 1185 | - A4 0.210 x 0.297 1186 | - B5 0.176 x 0.250 1187 | - Letter 0.216 x 0.279 1188 | - Legal 0.216 x 0.356 1189 | - Executive 0.191 x 0.254 1190 | - A0 0.841 x 1.189 1191 | - A1 0.594 x 0.841 1192 | - A2 0.420 x 0.594 1193 | - A3 0.297 x 0.420 1194 | - A5 0.148 x 0.210 1195 | - A6 0.105 x 0.148 1196 | - A7 0.074 x 0.105 1197 | - A8 0.052 x 0.074 1198 | - A9 0.037 x 0.052 1199 | - B0 1.000 x 1.414 1200 | - B1 0.500 x 0.707 1201 | - B10 0.031 x 0.044 1202 | - B2 0.500 x 0.707 1203 | - B3 0.353 x 0.500 1204 | - B4 0.250 x 0.353 1205 | - B6 0.125 x 0.176 1206 | - B7 0.088 x 0.125 1207 | - B8 0.062 x 0.088 1208 | - B9 0.044 x 0.062 1209 | - C5E 0.163 x 0.229 1210 | - Comm10E 0.105 x 0.241 1211 | - DLE 0.110 x 0.220 1212 | - Folio 0.210 x 0.330 1213 | - Ledger 0.432 x 0.279 1214 | - Tabloid 0.279 x 0.432 1215 | 1216 | Parameters 1217 | 1218 | - [pathname]: Filename for the print device. 1219 | - [mode]: Output mode (Color, GrayScale) 1220 | - [format]: Output format (see table) 1221 | - [orientation]: Page orientation (Landscape, Portait) 1222 | *) 1223 | end 1224 | 1225 | val drawrect : 1226 | ?linetype:linetype -> 1227 | ?linewidth:float -> 1228 | ?coloridx:int -> 1229 | float -> 1230 | float -> 1231 | float -> 1232 | float -> 1233 | unit 1234 | (** [drawrect ?linetype ?linewidth ?coloridx left right bottom up] draws a rectangle. 1235 | 1236 | Parameters 1237 | 1238 | - [left]: Left edge of the rectangle 1239 | - [right]: Right edge of the rectangle 1240 | - [bottom]: Bottom edge of the rectangle 1241 | - [up]: Upper edge of the rectangle 1242 | *) 1243 | 1244 | val fillrect : 1245 | ?fillstyle:fill_style -> 1246 | ?fillcoloridx:int -> 1247 | ?linetype:linetype -> 1248 | ?linewidth:float -> 1249 | ?coloridx:int -> 1250 | float -> 1251 | float -> 1252 | float -> 1253 | float -> 1254 | unit 1255 | (** [fillrect ?fillstyle ?fillcoloridx ?linetype ?linewidth ?coloridx left right bottom up] draws a filled rectangle. 1256 | 1257 | Parameters 1258 | 1259 | - [left]: Left edge of the rectangle 1260 | - [right]: Right edge of the rectangle 1261 | - [bottom]: Bottom edge of the rectangle 1262 | - [up]: Upper edge of the rectangle 1263 | *) 1264 | 1265 | val drawarc : 1266 | ?linetype:linetype -> 1267 | ?linewidth:float -> 1268 | ?coloridx:int -> 1269 | float -> 1270 | float -> 1271 | float -> 1272 | float -> 1273 | int -> 1274 | int -> 1275 | unit 1276 | (** [drawarc ?linetype ?linewidth ?coloridx left right bottom up a1 a2] draws a circular or elliptical arc covering the specified rectangle. 1277 | 1278 | The resulting arc begins at a1 and ends at a2 degrees. 1279 | Angles are interpreted such that 0 degrees is at the 3 o’clock position. 1280 | The center of the arc is the center of the given rectangle. 1281 | 1282 | Parameters 1283 | 1284 | - [left]: Left edge of the rectangle 1285 | - [right]: Right edge of the rectangle 1286 | - [bottom]: Bottom edge of the rectangle 1287 | - [up]: Upper edge of the rectangle 1288 | - [a1]: The start angle 1289 | - [a2]: The end angle 1290 | *) 1291 | 1292 | val fillarc : 1293 | ?fillstyle:fill_style -> 1294 | ?fillcoloridx:int -> 1295 | ?linetype:linetype -> 1296 | ?linewidth:float -> 1297 | ?coloridx:int -> 1298 | float -> 1299 | float -> 1300 | float -> 1301 | float -> 1302 | int -> 1303 | int -> 1304 | unit 1305 | (** [fillarc ?fillstyle ?fillcoloridx ?linetype ?linewidth ?coloridx left right bottom up] draws a filled circular or elliptical arc covering the specified rectangle. 1306 | 1307 | The resulting arc begins at a1 and ends at a2 degrees. 1308 | Angles are interpreted such that 0 degrees is at the 3 o’clock position. 1309 | The center of the arc is the center of the given rectangle. 1310 | 1311 | Parameters 1312 | 1313 | - [left]: Left edge of the rectangle 1314 | - [right]: Right edge of the rectangle 1315 | - [bottom]: Bottom edge of the rectangle 1316 | - [up]: Upper edge of the rectangle 1317 | - [a1]: The start angle 1318 | - [a2]: The end angle 1319 | *) 1320 | 1321 | val drawpath : 1322 | (float * float) array -> 1323 | [< `CLOSEPOLY | `CURVE3 | `CURVE4 | `LINETO | `MOVETO | `STOP ] array -> 1324 | bool -> 1325 | unit 1326 | (** [drawpath vertices codes fill] draws simple and compound outlines consisting of line segments and bezier curves. 1327 | 1328 | The following path codes are recognized: 1329 | 1330 | - `STOP end the entire path 1331 | - `MOVETO move to the given vertex 1332 | - `LINETO draw a line from the current position to the given vertex 1333 | - `CURVE3 draw a quadratic Bezier curve 1334 | - `CURVE4 draw a cubic Bezier curve 1335 | - `CLOSEPOLY draw a line segment to the start point of the current path 1336 | 1337 | Parameters 1338 | 1339 | - [vertices]: the vertices (x,y) 1340 | - [codes]: path codes 1341 | - [fill]: A flag indication whether resulting path is to be filled or not 1342 | *) 1343 | 1344 | val drawarrow : 1345 | ?arrowsize:float -> ?arrowstyle:int -> float * float -> float * float -> unit 1346 | (** [drawarrow ?arrowsize ?arrowstyle (x1, y1) (x2, y2)] draws an arrow between two points. 1347 | 1348 | Different arrow styles (angles between arrow tail and wing, optionally filled heads, double headed arrows) are available. 1349 | Check the documentation of [set_arrowstyle] and [set_arrowsize] for more information. 1350 | 1351 | Parameters 1352 | 1353 | - [x1]: The X coordinate of the arrow start point (tail) 1354 | - [y1]: The Y coordinate of the arrow start point (tail) 1355 | - [x2]: The X coordinate of the arrow end point (head) 1356 | - [y2]: The Y coordinate of the arrow end point (head) 1357 | *) 1358 | 1359 | val drawimage : 1360 | float * float -> 1361 | float * float -> 1362 | (int, 'a, 'b) Bigarray.Genarray.t -> 1363 | [< `HSV | `RGB ] -> 1364 | unit 1365 | (** [drawimage (xmin, ymin) (xmax, ymax) image_data model] draws an image into a given rectangular area. 1366 | 1367 | The points (xmin, ymin) and (xmax, ymax) are world coordinates defining diagonally opposite corner points of a rectangle. 1368 | This rectangle is divided into width by height cells. 1369 | The two-dimensional array data specifies colors for each cell. 1370 | 1371 | Parameters 1372 | 1373 | - [xmin]: X coordinate of the lower left point of the rectangle 1374 | - [ymin]: Y coordinate of the lower left point of the rectangle 1375 | - [xmax]: X coordinate of the upper right point of the rectangle 1376 | - [ymax]: Y coordinate of the upper right point of the rectangle 1377 | - [width]: X dimension of the color index array 1378 | - [height]: Y dimension of the color index array 1379 | - [data]: color array 1380 | - [model]: color model 1381 | 1382 | The available color models are: 1383 | 1384 | - RGB 0 AABBGGRR 1385 | - HSV 1 AAVVSSHH 1386 | *) 1387 | 1388 | module Selection : sig 1389 | val begins : int -> int -> unit 1390 | (** [beings index kind] *) 1391 | 1392 | val ends : unit -> unit 1393 | 1394 | val move : float -> float -> unit 1395 | (** [resize x y] *) 1396 | 1397 | val resize : int -> float -> float -> unit 1398 | (** [resize kind x y] *) 1399 | end 1400 | 1401 | (* val with_ws : ?typ:workstation_type -> (int -> 'a) -> unit *) 1402 | --------------------------------------------------------------------------------