Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file mesh_common.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222# 1 "src/mesh_common.ml"(* File: mesh_common.ml
Copyright (C) 2014
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 Lesser General Public License version 3 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. *)openPrintfopenBigarraytype'layoutvec=(float,float64_elt,'layout)Array1.ttype'layoutmat=(float,float64_elt,'layout)Array2.ttype'layoutint_vec=(int,int_elt,'layout)Array1.ttype'layoutint_mat=(int,int_elt,'layout)Array2.tletmax2ab=if(a:int)>bthenaelsebletmax4abcd=max2(max2ab)(max2cd)class['l]pslg(layout:'llayout)=letempty_mat=Array2.createfloat64layout20andempty_int_mat=Array2.createintlayout20andempty_int_vec=Array1.createintlayout0inobjectmethodpoint=empty_matmethodpoint_marker=empty_int_vecmethodsegment=empty_int_matmethodsegment_marker=empty_int_vecmethodhole=empty_matmethodregion=empty_matendclasstype['layout]t=objectinherit['layout]pslgmethodtriangle:'layoutint_matmethodneighbor:'layoutint_matmethodedge:'layoutint_matmethodedge_marker:'layoutint_vecendclasstype['layout]voronoi=objectmethodpoint:'layoutmatmethodedge:'layoutint_matmethodnormal:'layoutmatend(* Construct the object via a function so that the function parameters
are evaluated first and the method execution is just retrieving the
value. *)letmake_mesh~point~point_marker~segment~segment_marker~hole~region~triangle~neighbor~edge~edge_marker=(objectmethodpoint=pointmethodpoint_marker=point_markermethodsegment=segmentmethodsegment_marker=segment_markermethodhole=holemethodregion=regionmethodtriangle=trianglemethodneighbor=neighbormethodedge=edgemethodedge_marker=edge_markerend:_t)letlayout(mesh:_#pslg)=Array2.layoutmesh#pointletis_c_layout(mesh:_#pslg)=Mesh_utils.is_c_layout(Array2.layoutmesh#point)letpslg_to_c(m:_#pslg)=(Obj.magicm:c_layoutpslg)letpslg_to_fortran(m:_#pslg)=(Obj.magicm:fortran_layoutpslg)letmesh_to_c(m:_#t)=(Obj.magicm:c_layoutt)letmesh_to_fortran(m:_#t)=(Obj.magicm:fortran_layoutt)letmesh_transform(mesh:'l#t)f_cf_fortran=ifis_c_layoutmeshthenletmesh':c_layoutt=f_c(mesh_to_cmesh)in(Obj.magicmesh':'lt)elseletmesh':fortran_layoutt=f_fortran(mesh_to_fortranmesh)in(Obj.magicmesh':'lt)(** LaTeX commands *)letnormdxdy=(* Watch out for overflow in computing sqrt(dx^2 + dy^2) *)letdx=abs_floatdxanddy=abs_floatdyinifdx=0.0thendyelseifdy=0.0thendxelseifdx>=dythenletq=dy/.dxindx*.sqrt(1.0+.q*.q)elseletq=dx/.dyindy*.sqrt(1.0+.q*.q)(*
let latex_begin fh width height xmin ymin =
fprintf fh "\\begin{picture}(%.13g,%.13g)(%.13g,%.13g)\n"
width height xmin ymin;
fprintf fh " %% \\meshline{x}{y}{angle}{length}\n";
fprintf fh " \\providecommand{\\meshline}[5]{%%
\\put(#2,#3){\\rotatebox{#4}{\\rlap{\\smash{%%
\\color{#1}%%
\\vrule width #5\\unitlength height 0.1pt depth 0.1pt}}}}}\n";
fprintf fh " \\providecommand{\\meshpoint}[3]{%%
\\put(#2,#3){\\makebox(0,0){\\footnotesize $\\bullet$}}}\n"
let latex_end fh =
fprintf fh "\\end{picture}\n"
*)(* PGF output *)letlatex_beginfhwidthheightxminymin=fprintffh"\\begin{pgfscope}\n";fprintffh" %% Written by OCaml Mesh. width: %g, height: %g, xmin: %g, \
ymin: %g\n"widthheightxminymin;fprintffh" %% \\meshline{R,G,B}{x1}{y1}{x2}{y2}\n";(* We need to put the path in a scope otherwise one gets "TeX
capacity exceeded". *)fprintffh" \\providecommand{\\meshline}[5]{%%
\\begin{pgfscope}
\\definecolor{ocamlmesh}{RGB}{#1}
\\pgfsetcolor{ocamlmesh}
\\pgfpathmoveto{\\pgfpointxy{#2}{#3}}
\\pgfpathlineto{\\pgfpointxy{#4}{#5}}
\\pgfusepath{stroke}
\\end{pgfscope}}\n";fprintffh" %% \\meshpoint{point number}{x}{y}\n";fprintffh" \\providecommand{\\meshpoint}[3]{}\n";fprintffh" %% \\meshtriangle{R,G,B}{x1}{y1}{x2}{y2}{x3}{y3}\n";fprintffh" \\providecommand{\\meshtriangle}[7]{%%
\\begin{pgfscope}
\\definecolor{ocamlmesh}{RGB}{#1}
\\pgfsetcolor{ocamlmesh}
\\pgfpathmoveto{\\pgfpointxy{#2}{#3}}
\\pgfpathlineto{\\pgfpointxy{#4}{#5}}
\\pgfpathlineto{\\pgfpointxy{#6}{#7}}
\\pgfusepath{fill}
\\end{pgfscope}}\n";fprintffh" %% \\meshfilltriangle{R,G,B}{x1}{y1}{x2}{y2}{x3}{y3}\n";fprintffh" \\providecommand{\\meshfilltriangle}[7]{%%
\\begin{pgfscope}
\\definecolor{ocamlmesh}{RGB}{#1}
\\pgfsetcolor{ocamlmesh}
\\pgfpathmoveto{\\pgfpointxy{#2}{#3}}
\\pgfpathlineto{\\pgfpointxy{#4}{#5}}
\\pgfpathlineto{\\pgfpointxy{#6}{#7}}
\\pgfusepath{fill}
\\end{pgfscope}}\n";fprintffh" %% \\meshfillquadrilateral{R,G,B}{x1}{y1}{x2}{y2}{x3}{y3}\
{x4}{y4}\n";fprintffh" \\providecommand{\\meshfillquadrilateral}[9]{%%
\\begin{pgfscope}
\\definecolor{ocamlmesh}{RGB}{#1}
\\pgfsetcolor{ocamlmesh}
\\pgfpathmoveto{\\pgfpointxy{#2}{#3}}
\\pgfpathlineto{\\pgfpointxy{#4}{#5}}
\\pgfpathlineto{\\pgfpointxy{#6}{#7}}
\\pgfpathlineto{\\pgfpointxy{#8}{#9}}
\\pgfusepath{fill}
\\end{pgfscope}}\n"letlatex_endfh=fprintffh"\\end{pgfscope}\n"letdegrees_per_radian=45./.atan1.(* More efficient than couples of floats *)typepoint={x:float;y:float}letblack=0x000000letcolor_to_stringc=letb=cland0xFFinletg=(clsr8)land0xFFinletr=(clsr16)land0xFFinsprintf"%i,%i,%i"rgbletlinefhcolor{x=x0;y=y0}{x=x1;y=y1}=(* let dx = x1 -. x0
and dy = y1 -. y0 in
fprintf fh " \\meshline{%s}{%.12f}{%.12f}{%.12f}{%.12f}\n%!"
color x0 y0 (degrees_per_radian *. atan2 dy dx) (norm dx dy)
*)fprintffh" \\meshline{%s}{%.12f}{%.12f}{%.12f}{%.12f}\n%!"(color_to_stringcolor)x0y0x1y1letpoint_xyfhixy=fprintffh" \\meshpoint{%i}{%.12f}{%.13f}\n"ixyletpointfhi{x=x;y=y}=point_xyfhixylettrianglefhcolor{x=x1;y=y1}{x=x2;y=y2}{x=x3;y=y3}=fprintffh" \\meshtriangle{%s}{%.12f}{%.12f}{%.12f}{%.12f}{%.12f}{%.12f}\n"(color_to_stringcolor)x1y1x2y2x3y3letfill_trianglefhcolor{x=x1;y=y1}{x=x2;y=y2}{x=x3;y=y3}=fprintffh" \\meshfilltriangle{%s}{%.12f}{%.12f}{%.12f}{%.12f}\
{%.12f}{%.12f}\n"(color_to_stringcolor)x1y1x2y2x3y3letfill_quadrilateralfhcolor{x=x1;y=y1}{x=x2;y=y2}{x=x3;y=y3}{x=x4;y=y4}=fprintffh" \\meshfillquadrilateral{%s}{%.12f}{%.12f}{%.12f}{%.12f}\
{%.12f}{%.12f}{%.12f}{%.12f}\n"(color_to_stringcolor)x1y1x2y2x3y3x4y4