1%%
2%%  libigl.erl --
3%%
4%%     This module interfaces some functions in libigl.
5%%
6%%  Copyright (c) 2019 Dan Gudmundsson
7%%
8%%  See the file "license.terms" for information on usage and redistribution
9%%  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
11-module(libigl).
12
13-export([lscm/4]).
14-export([harmonic/4]).
15-export([slim/5]).
16-on_load(init/0).
17-define(nif_stub,nif_stub_error(?LINE)).
18
19-type triangles() :: nonempty_list().
20-type point2d() :: {float(), float()}.
21
22-type energy_type() :: 'arap' | 'log_arap' | 'symmetric_dirichlet' |
23                       'conformal' | 'exp_conformal' | 'exp_symmetric_dirichlet'.
24
25%% Least square conformal maps
26%% At least bind two BorderVs with UV-positions in BorderPos
27-spec lscm(Vs::[e3d_vec:point()],Fs::triangles(),[BVs::integer()], BPos::[point2d()]) ->
28          [point2d()] | {'error', term()} | 'false'.
29lscm(_Vs,_Fs,_BorderVs,_BorderPos) ->
30    ?nif_stub.
31
32
33%% Harmonic mapping
34%% All BorderVs must be present and have an initial mapping in BorderPos
35-spec harmonic(Vs::[e3d_vec:point()],Fs::triangles(),[BVs::integer()], BPos::[point2d()]) ->
36                  [point2d()].
37harmonic(_Vs,_Fs,_BorderVs,_BorderPos) ->
38    ?nif_stub.
39
40
41%% Slim Scalable Locally Injective Mappings
42%% UVInitPos must contain an initial (non-flipped) UV-mapping of all verts
43%% Stops when change is less then eps
44-spec slim(VS::[e3d_vec:point()], Fs::triangles(),
45           UVInitPos::[point2d()], energy_type(), Eps::float()) -> [point2d()].
46slim(_Vs,_Fs, _InitUVs, _Type, _Eps) ->
47    ?nif_stub.
48
49%%% Nif init
50
51nif_stub_error(Line) ->
52    erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}).
53
54init() ->
55    case get(wings_not_running) of
56	undefined ->
57            Name = "libigl",
58	    Dir = case code:priv_dir(wings) of
59                      {error, _} -> filename:join(wings_util:lib_dir(wings),"priv");
60                      Priv -> Priv
61                  end,
62            Nif = filename:join(Dir, Name),
63            erlang:load_nif(Nif, 0);
64	_ ->
65	    false
66    end.
67
68