-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwindow.lua
More file actions
192 lines (150 loc) · 3.85 KB
/
window.lua
File metadata and controls
192 lines (150 loc) · 3.85 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
--- Windows and their methods.
-- Standard library imports --
local getmetatable = getmetatable
local rawequal = rawequal
local type = type
-- Modules --
local af = require("arrayfire_lib")
local array = require("impl.array")
-- Imports --
local Call = array.Call
local IsArray = array.IsArray
local GetLib = array.GetLib
-- Exports --
local M = {}
-- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/graphics.cpp
--
local TempCell = {}
--
local function Temp (window, title, how)
TempCell.row, TempCell.col = window._r, window._c
TempCell.title = title
TempCell.cmap = how == "use_cmap" and window._cmap or af.AF_COLORMAP_DEFAULT
return TempCell
end
-- --
local Window = {}
local MetaValue = {}
--
Window.__index = Window
Window.__metatable = MetaValue
--- DOCME
function Window:__call (r, c)
self._r, self._c = r, c
return self
end
-- __gc = AF_THROW(af_destroy_window(wnd));
--
local function Get (window)
-- TODO: Use a proxy to gc the window...
return window.wnd
end
--- DOCME
function Window:close ()
return Call("af_is_window_closed", Get(self))
end
--- DOCME
function Window:destroy ()
if not self:close() then
Call("af_destroy_window", Get(self))
end
end
--- DOCME
function Window:grid (rows, cols)
Call("af_grid", Get(self), rows, cols)
end
--- DOCME
function Window:hist (X, minval, maxval, title)
Call("af_draw_hist", Get(self), X:get(), minval, maxval, Temp(self, title))
end
--- DOCME
function Window:image (in_arr, title)
Call("af_draw_image", Get(self), in_arr:get(), Temp(self, title, "use_cmap"))
end
--- DOCME
function Window:plot (X, Y, title)
Call("af_draw_plot", Get(self), X:get(), Y:get(), Temp(self, title))
end
function Window:plot3 (P, title)
P:eval()
Call("af_draw_plot3", Get(self), P:get(), Temp(self, title))
end
--[[
3.3
void Window::scatter(const array& X, const array& Y, af::markerType marker, const char* const title)
{
af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT};
AF_THROW(af_draw_scatter(get(), X.get(), Y.get(), marker, &temp));
}
void Window::scatter3(const array& P, af::markerType marker, const char* const title)
{
af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT};
AF_THROW(af_draw_scatter3(get(), P.get(), marker, &temp));
}
]]
--- DOCME
function Window:setPos (x, y)
Call("af_set_position", Get(self), x, y)
end
--- DOCME
function Window:setTitle (title)
Call("af_set_title", Get(self), title)
end
--- DOCME
function Window:setSize (w, h)
Call("af_set_size", Get(self), w, h)
end
--- DOCME
function Window:setColorMap (cmap)
self._cmap = af[cmap]
end
--- DOCME
function Window:show ()
Call("af_show", Get(self))
self._r, self._c = -1, -1
end
function Window:surface (a, b, c, d)
local xVals, yVals, title
if IsArray(b) then -- a: xVals, b: yVals, c: S, d: title
xVals, yVals, title = a, b, d
else -- a: S, b: title
local lib = GetLib()
xVals = lib.array(lib.seq(0, c:dims(0) - 1))
yVals = lib.array(lib.seq(0, c:dims(0) - 1))
title = b
end
Call("af_draw_surface", Get(self), xVals:get(), yVals:get(), S:get(), Temp(self, title))
end
--
local function Set (window, handle)
window.wnd = handle -- TODO: note about proxy...
end
--
local function InitWindow (window, w, h, title)
Set(window, Call("af_create_window", w, h, title or "ArrayFire"))
end
--
function M.Add (into)
for k, v in pairs{
--
IsWindow = function(item)
return rawequal(getmetatable(item), MetaValue)
end,
--
Window = function(a, b, c)
local window = { cnd = 0, _r = -1, _c = -1, _cmap = af.AF_COLORMAP_DEFAULT }
if a == nil or type(a) == "string" then -- a: title
InitWindow(window, 1280, 720, a)
elseif b then -- a: width, b: height, c: title
InitWindow(window, a, b, c)
else -- a: window
Set(window, a)
end
return setmetatable(window, Window)
end
} do
into[k] = v
end
end
-- Export the module.
return M