package mesh-display

  1. Overview
  2. Docs

Source file mesh_display.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(* File: mesh_display.ml

   Copyright (C) 2008-

     Christophe Troestler <Christophe.Troestler@umons.ac.be>
     WWW: http://math.umons.ac.be/an/software/

   This library is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 2.1 or
   later as published by the Free Software Foundation, with the special
   exception on linking described in the file LICENSE.

   This library is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file
   LICENSE for more details. *)


(** Displaying the mesh with Graphics *)

open Printf
open Graphics
open Mesh_utils
open Mesh_common

(* TODO:

   - allow to zoom in and out
   - display the segments in another color
   - allow to switch on and off the nodes #
*)

let draw ?width ?height ?color ?points ?point_idx ?triangle_idx ?voronoi
         ?point_marker_color
         (mesh: 'a #Mesh.t) =
  if Mesh.is_c_layout mesh then
    Mesh_displayC.draw ?width ?height ?color ?points ?point_idx ?triangle_idx
                       ?voronoi ?point_marker_color
                       (mesh_to_c mesh)
  else
    Mesh_displayF.draw ?width ?height ?color ?points ?point_idx ?triangle_idx
                       ?voronoi ?point_marker_color
                       (mesh_to_fortran mesh)

let init_graph width height =
  let xbd = 10 and ybd = 10 in
  (* Drawing itself *)
  open_graph (sprintf " %ix%i-40+40" (width + 2 * xbd) (height + 2 * ybd));
  moveto xbd ybd

let hold_graph () =
  (* Wait for the key 'q' to be pressed. *)
  try
    while true do
      let status = wait_next_event [Button_down; Key_pressed] in
      if status.button
        || (status.keypressed && (status.key = 'q' || status.key = 'Q')) then (
        close_graph();
        raise Exit
      );
    done
  with Exit -> ()

let display ?(width=600) ?(height=600) ?color ?points ?point_idx ?triangle_idx
            ?voronoi ?point_marker_color mesh =
  init_graph width height;
  set_window_title("Mesh (" ^ Filename.basename Sys.argv.(0) ^ ")");
  draw ~width ~height ?color ?points ?point_idx ?triangle_idx
       ?voronoi ?point_marker_color
       mesh;
  hold_graph()

let level_curves ?(width=600) ?(height=600) ?boundary (mesh: 'a #Mesh.t)
                 (z: 'a Mesh.vec) ?level_eq levels =
  if Mesh.is_c_layout mesh then
    Mesh_displayC.level_curves ~width ~height ?boundary
                               (mesh_to_c mesh) (vec_to_c z) ?level_eq levels
  else
    Mesh_displayF.level_curves ~width ~height ?boundary
                               (mesh_to_fortran mesh) (vec_to_fortran z)
                               ?level_eq levels

let display_level_curves ?(width=600) ?(height=600) ?boundary mesh z
    ?level_eq levels =
  init_graph width height;
  set_window_title("Mesh (" ^ Filename.basename Sys.argv.(0) ^ ")");
  level_curves ~width ~height ?boundary mesh z ?level_eq levels;
  hold_graph()

let super_level ?(width=600) ?(height=600) ?boundary (mesh: 'a #Mesh.t)
                (z: 'a Mesh.vec) level color =
  if Mesh.is_c_layout mesh then
    Mesh_displayC.super_level ~width ~height ?boundary
                              (mesh_to_c mesh) (vec_to_c z) level color
  else
    Mesh_displayF.super_level ~width ~height ?boundary
                              (mesh_to_fortran mesh) (vec_to_fortran z)
                              level color

let sub_level ?(width=600) ?(height=600) ?boundary (mesh: 'a #Mesh.t)
              (z: 'a Mesh.vec) level color =
  if Mesh.is_c_layout mesh then
    Mesh_displayC.sub_level ~width ~height ?boundary
                            (mesh_to_c mesh) (vec_to_c z) level color
  else
    Mesh_displayF.sub_level ~width ~height ?boundary
                            (mesh_to_fortran mesh) (vec_to_fortran z)
                            level color
OCaml

Innovation. Community. Security.