ruby-gr 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -4
- data/lib/gr.rb +960 -834
- data/lib/gr/ffi.rb +2 -1
- data/lib/gr/plot.rb +74 -29
- data/lib/gr3.rb +286 -230
- data/lib/gr_commons/define_methods.rb +5 -5
- data/lib/gr_commons/fiddley.rb +6 -6
- data/lib/gr_commons/gr_common_utils.rb +5 -5
- data/lib/gr_commons/gr_logger.rb +106 -0
- data/lib/gr_commons/jupyter_support.rb +5 -5
- data/lib/gr_commons/search_shared_library.rb +3 -2
- data/lib/gr_commons/version.rb +1 -1
- data/lib/grm/ffi.rb +0 -1
- metadata +4 -18
- data/lib/gr/plot.rb.md +0 -172
data/lib/gr/ffi.rb
CHANGED
@@ -174,7 +174,7 @@ module GR
|
|
174
174
|
try_extern 'void gr_shadepoints(int, double *, double *, int, int, int)'
|
175
175
|
try_extern 'void gr_shadelines(int, double *, double *, int, int, int)'
|
176
176
|
try_extern 'void gr_panzoom(double, double, double, double, double *, double *, double *, double *)'
|
177
|
-
|
177
|
+
try_extern 'int gr_findboundary(int, double *, double *, double, double (*)(double, double), int, int *)'
|
178
178
|
try_extern 'void gr_setresamplemethod(unsigned int flag)'
|
179
179
|
try_extern 'void gr_inqresamplemethod(unsigned int *flag)'
|
180
180
|
try_extern 'void gr_path(int, double *, double *, const char *)'
|
@@ -202,5 +202,6 @@ module GR
|
|
202
202
|
try_extern 'void gr_inqtext3d(double, double, double, char *, int axis, double *, double *)'
|
203
203
|
try_extern 'void gr_settextencoding(int)'
|
204
204
|
try_extern 'void gr_inqtextencoding(int *)'
|
205
|
+
# gr_setcallback(char *(*)(const char *));
|
205
206
|
end
|
206
207
|
end
|
data/lib/gr/plot.rb
CHANGED
@@ -38,12 +38,49 @@ module GR
|
|
38
38
|
|
39
39
|
# Keyword options conform to GR.jl.
|
40
40
|
KW_ARGS = %i[accelerate algorithm alpha ax backgroundcolor barwidth baseline
|
41
|
-
clabels clear clim color colormap crange figsize grid
|
42
|
-
isovalue kind label labels levels location nbins
|
43
|
-
scale size spec subplot tilt title update xaxis
|
44
|
-
xlabel xlim xlog xrange xticks yaxis yflip ylabel
|
45
|
-
zflip yrange yticks viewport vp where window zaxis
|
46
|
-
zlog zrange zticks].freeze
|
41
|
+
clabels clear clim color colormap crange figsize font grid
|
42
|
+
horizontal isovalue kind label labels levels location nbins
|
43
|
+
ratio rotation scale size spec subplot tilt title update xaxis
|
44
|
+
xflip xform xlabel xlim xlog xrange xticks yaxis yflip ylabel
|
45
|
+
ylim ylog zflip yrange yticks viewport vp where window zaxis
|
46
|
+
zlabel zlim zlog zrange zticks].freeze
|
47
|
+
|
48
|
+
FONTS = {
|
49
|
+
times_roman: 101,
|
50
|
+
times_italic: 102,
|
51
|
+
times_bold: 103,
|
52
|
+
times_bolditalic: 104,
|
53
|
+
helvetica_regular: 105,
|
54
|
+
helvetica_oblique: 106,
|
55
|
+
helvetica_bold: 107,
|
56
|
+
helvetica_boldoblique: 108,
|
57
|
+
courier_regular: 109,
|
58
|
+
courier_oblique: 110,
|
59
|
+
courier_bold: 111,
|
60
|
+
courier_boldoblique: 112,
|
61
|
+
symbol: 113,
|
62
|
+
bookman_light: 114,
|
63
|
+
bookman_lightitalic: 115,
|
64
|
+
bookman_demi: 116,
|
65
|
+
bookman_demiitalic: 117,
|
66
|
+
newcenturyschlbk_roman: 118,
|
67
|
+
newcenturyschlbk_italic: 119,
|
68
|
+
newcenturyschlbk_bold: 120,
|
69
|
+
newcenturyschlbk_bolditalic: 121,
|
70
|
+
avantgarde_book: 122,
|
71
|
+
avantgarde_bookoblique: 123,
|
72
|
+
avantgarde_demi: 124,
|
73
|
+
avantgarde_demioblique: 125,
|
74
|
+
palatino_roman: 126,
|
75
|
+
palatino_italic: 127,
|
76
|
+
palatino_bold: 128,
|
77
|
+
palatino_bolditalic: 129,
|
78
|
+
zapfchancery_mediumitalic: 130,
|
79
|
+
zapfdingbats: 131,
|
80
|
+
cmuserif_math: 232, # original: cmuserif-math
|
81
|
+
dejavusans: 233,
|
82
|
+
pingfangsc: 234
|
83
|
+
}.freeze
|
47
84
|
|
48
85
|
@last_plot = nil
|
49
86
|
class << self
|
@@ -345,29 +382,29 @@ module GR
|
|
345
382
|
GR.axes(xtick, ytick, xorg[1], yorg[1], -majorx, -majory, -ticksize)
|
346
383
|
end
|
347
384
|
|
348
|
-
if kvs
|
385
|
+
if kvs.has_key?(:title)
|
349
386
|
GR.savestate
|
350
387
|
GR.settextalign(GR::TEXT_HALIGN_CENTER, GR::TEXT_VALIGN_TOP)
|
351
|
-
text(0.5 * (viewport[0] + viewport[1]), vp[3], kvs[:title])
|
388
|
+
text(0.5 * (viewport[0] + viewport[1]), vp[3], kvs[:title].to_s)
|
352
389
|
GR.restorestate
|
353
390
|
end
|
354
391
|
if %i[wireframe surface plot3 scatter3 trisurf volume].include?(kind)
|
355
|
-
xlabel = kvs[:xlabel] || ''
|
356
|
-
ylabel = kvs[:ylabel] || ''
|
357
|
-
zlabel = kvs[:zlabel] || ''
|
392
|
+
xlabel = (kvs[:xlabel] || '').to_s
|
393
|
+
ylabel = (kvs[:ylabel] || '').to_s
|
394
|
+
zlabel = (kvs[:zlabel] || '').to_s
|
358
395
|
GR.titles3d(xlabel, ylabel, zlabel)
|
359
396
|
else
|
360
397
|
if kvs.has_key?(:xlabel)
|
361
398
|
GR.savestate
|
362
399
|
GR.settextalign(GR::TEXT_HALIGN_CENTER, GR::TEXT_VALIGN_BOTTOM)
|
363
|
-
text(0.5 * (viewport[0] + viewport[1]), vp[2] + 0.5 * charheight, kvs[:xlabel])
|
400
|
+
text(0.5 * (viewport[0] + viewport[1]), vp[2] + 0.5 * charheight, kvs[:xlabel].to_s)
|
364
401
|
GR.restorestate
|
365
402
|
end
|
366
403
|
if kvs.has_key?(:ylabel)
|
367
404
|
GR.savestate
|
368
405
|
GR.settextalign(GR::TEXT_HALIGN_CENTER, GR::TEXT_VALIGN_TOP)
|
369
406
|
GR.setcharup(-1, 0)
|
370
|
-
text(vp[0] + 0.5 * charheight, 0.5 * (viewport[2] + viewport[3]), kvs[:ylabel])
|
407
|
+
text(vp[0] + 0.5 * charheight, 0.5 * (viewport[2] + viewport[3]), kvs[:ylabel].to_s)
|
371
408
|
GR.restorestate
|
372
409
|
end
|
373
410
|
end
|
@@ -475,7 +512,7 @@ module GR
|
|
475
512
|
if kvs.has_key?(:title)
|
476
513
|
GR.savestate
|
477
514
|
GR.settextalign(GR::TEXT_HALIGN_CENTER, GR::TEXT_VALIGN_TOP)
|
478
|
-
text(0.5 * (viewport[0] + viewport[1]), vp[3], kvs[:title])
|
515
|
+
text(0.5 * (viewport[0] + viewport[1]), vp[3], kvs[:title].to_s)
|
479
516
|
GR.restorestate
|
480
517
|
end
|
481
518
|
GR.selntran(1)
|
@@ -577,9 +614,22 @@ module GR
|
|
577
614
|
# Not yet.
|
578
615
|
end
|
579
616
|
|
580
|
-
|
581
|
-
|
582
|
-
|
617
|
+
if kvs.has_key?(:font)
|
618
|
+
name = kvs[:font]
|
619
|
+
# 'Cmuserif-Math' => :cmuserif_math
|
620
|
+
sym_name = name.to_s.gsub('-','_').downcase.to_sym
|
621
|
+
if FONTS.include?(sym_name)
|
622
|
+
font = FONTS[sym_name]
|
623
|
+
GR.settextfontprec(font, font > 200 ? 3 : 0)
|
624
|
+
else
|
625
|
+
warn "Unknown font name: #{name}" # should raise error?
|
626
|
+
end
|
627
|
+
else
|
628
|
+
# The following fonts are the default in GR.jl
|
629
|
+
# Japanese, Chinese, Korean, etc. cannot be displayed.
|
630
|
+
|
631
|
+
# GR.settextfontprec(232, 3) # CM Serif Roman
|
632
|
+
end
|
583
633
|
|
584
634
|
set_viewport(kind, kvs[:subplot])
|
585
635
|
unless kvs[:ax]
|
@@ -748,9 +798,10 @@ module GR
|
|
748
798
|
else
|
749
799
|
h = levels
|
750
800
|
end
|
751
|
-
|
801
|
+
case kind
|
802
|
+
when :contour
|
752
803
|
GR._contour_(x, y, h, z, clabels ? 1 : 1000)
|
753
|
-
|
804
|
+
when :contourf
|
754
805
|
GR._contourf_(x, y, h, z, clabels ? 1 : 0)
|
755
806
|
end
|
756
807
|
colorbar(0, h.length)
|
@@ -1054,6 +1105,7 @@ module GR
|
|
1054
1105
|
end
|
1055
1106
|
|
1056
1107
|
def inqtext(x, y, s)
|
1108
|
+
s = s.to_s
|
1057
1109
|
if s.length >= 2 && s[0] == '$' && s[-1] == '$'
|
1058
1110
|
GR.inqmathtex(x, y, s[1..-2])
|
1059
1111
|
elsif s.include?('\\') || s.include?('_') || s.include?('^')
|
@@ -1064,6 +1116,7 @@ module GR
|
|
1064
1116
|
end
|
1065
1117
|
|
1066
1118
|
def text(x, y, s)
|
1119
|
+
s = s.to_s
|
1067
1120
|
if s.length >= 2 && s[0] == '$' && s[-1] == '$'
|
1068
1121
|
GR.mathtex(x, y, s[1..-2])
|
1069
1122
|
elsif s.include?('\\') || s.include?('_') || s.include?('^')
|
@@ -1163,20 +1216,12 @@ module GR
|
|
1163
1216
|
[w, h]
|
1164
1217
|
end
|
1165
1218
|
|
1166
|
-
# NOTE: duplicated definition (GRCommonUtils)
|
1167
1219
|
def equal_length(*args)
|
1168
|
-
|
1169
|
-
unless lengths.all? { |l| l == lengths[0] }
|
1170
|
-
raise ArgumentError,
|
1171
|
-
'Sequences must have same length.'
|
1172
|
-
end
|
1173
|
-
|
1174
|
-
lengths[0]
|
1220
|
+
GRCommons::GRCommonUtils.equal_length(*args)
|
1175
1221
|
end
|
1176
1222
|
|
1177
|
-
# NOTE: duplicated definition (GRCommonUtils)
|
1178
1223
|
def narray?(data)
|
1179
|
-
|
1224
|
+
GRCommons::GRCommonUtils.narray?(data)
|
1180
1225
|
end
|
1181
1226
|
end
|
1182
1227
|
|
data/lib/gr3.rb
CHANGED
@@ -40,16 +40,18 @@
|
|
40
40
|
#
|
41
41
|
# Fiddley is Ruby-FFI compatible API layer for Fiddle.
|
42
42
|
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
43
|
+
# @note
|
44
|
+
# Why not GR::GR3?
|
45
|
+
# * kojix2 did not want to force gr3 to be loaded when gr is loaded.
|
46
|
+
# * kojix2 did not want to write `GR3 = GR::GR3` or something.
|
47
|
+
# * This is a opinion of kojix2 and may be changed by future maintainers.
|
47
48
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# *
|
49
|
+
# @note
|
50
|
+
# GR3 uses Numo::Narrray.
|
51
|
+
# * It is difficult to write GR3 modules with only Ruby arrays.
|
52
|
+
# * Numo::Narray has better performance and is easier to read.
|
53
|
+
# * Numo::Narray does not work with JRuby.
|
54
|
+
# * https://github.com/ruby-numo/numo-narray/issues/147
|
53
55
|
#
|
54
56
|
# This is a procedural interface to the GR3 in GR plotting library,
|
55
57
|
# https://github.com/sciapp/gr
|
@@ -117,70 +119,82 @@ module GR3
|
|
117
119
|
end
|
118
120
|
extend CheckError
|
119
121
|
|
120
|
-
# Now you can see a lot of methods just calling super here.
|
121
|
-
# They are written to help the yard generate the documentation.
|
122
122
|
class << self
|
123
123
|
# This method initializes the gr3 context.
|
124
|
+
#
|
124
125
|
# @return [Integer]
|
125
|
-
|
126
|
-
|
127
|
-
end
|
126
|
+
#
|
127
|
+
# @!method gr3_init
|
128
128
|
|
129
|
-
|
130
|
-
super
|
131
|
-
end
|
129
|
+
# @!method free
|
132
130
|
|
133
131
|
# This function terminates the gr3 context.
|
134
|
-
|
135
|
-
|
136
|
-
|
132
|
+
#
|
133
|
+
# After calling this function, gr3 is in the same state as when it was first
|
134
|
+
# loaded, except for context-independent variables, i.e. the logging callback.
|
135
|
+
#
|
136
|
+
# @!method terminate
|
137
137
|
|
138
|
-
#
|
138
|
+
# @note This method is defined in the CheckError module.
|
139
|
+
#
|
139
140
|
# This function returns information on the most recent GR3 error.
|
141
|
+
#
|
140
142
|
# @return [Integer]
|
141
|
-
#
|
143
|
+
#
|
144
|
+
# @!method geterror
|
142
145
|
|
143
146
|
# This function allows the user to find out how his commands are rendered.
|
147
|
+
#
|
144
148
|
# If gr3 is initialized, a string in the format:
|
145
|
-
# `"gr3 - " + window toolkit + " - " + framebuffer extension + " - "
|
146
|
-
#
|
147
|
-
#
|
149
|
+
# `"gr3 - " + window toolkit + " - " + framebuffer extension + " - "
|
150
|
+
# + OpenGL version + " - " + OpenGL renderer string`.
|
151
|
+
# For example
|
152
|
+
# `"gr3 - GLX - GL_ARB_framebuffer_object - 2.1 Mesa 7.10.2 - Software Rasterizer"`
|
153
|
+
# might be returned on a Linux system (using GLX) with an available
|
154
|
+
# GL_ARB_framebuffer_object implementation.
|
148
155
|
# If gr3 is not initialized `"Not initialized"` is returned.
|
156
|
+
#
|
149
157
|
# @return [String]
|
158
|
+
#
|
150
159
|
def getrenderpathstring(*)
|
151
160
|
super.to_s
|
152
161
|
end
|
153
162
|
|
154
163
|
# This function returns a string representation of a given error code.
|
164
|
+
#
|
155
165
|
# @return [String]
|
166
|
+
#
|
156
167
|
def geterrorstring(*)
|
157
168
|
super.to_s
|
158
169
|
end
|
159
170
|
|
160
171
|
# This function clears the draw list.
|
172
|
+
#
|
161
173
|
# @return [Integer]
|
162
|
-
|
163
|
-
|
164
|
-
end
|
174
|
+
#
|
175
|
+
# @!method clear
|
165
176
|
|
166
|
-
# Use the currently bound framebuffer as the framebuffer used for drawing to
|
167
|
-
#
|
168
|
-
|
169
|
-
|
170
|
-
|
177
|
+
# Use the currently bound framebuffer as the framebuffer used for drawing to
|
178
|
+
# OpenGL (using gr3.drawimage).
|
179
|
+
# This function is only needed when you do not want to render to 0, the
|
180
|
+
# default framebuffer.
|
181
|
+
#
|
182
|
+
# @!method usecurrentframebuffer
|
171
183
|
|
172
184
|
# Set the framebuffer used for drawing to OpenGL (using gr3.drawimage).
|
173
|
-
#
|
174
|
-
|
175
|
-
|
176
|
-
|
185
|
+
#
|
186
|
+
# This function is only needed when you do not want to render to 0, the
|
187
|
+
# default framebuffer.
|
188
|
+
#
|
189
|
+
# @!method useframebuffer
|
177
190
|
|
178
191
|
# Set rendering quality
|
192
|
+
#
|
179
193
|
# @param quality [] The quality to set
|
194
|
+
#
|
180
195
|
# @return [Integer]
|
181
|
-
|
182
|
-
|
183
|
-
end
|
196
|
+
#
|
197
|
+
# @!method setquality
|
184
198
|
|
185
199
|
# @return [Integer]
|
186
200
|
def getimage(width, height, use_alpha = true)
|
@@ -191,31 +205,31 @@ module GR3
|
|
191
205
|
end
|
192
206
|
|
193
207
|
# @return [Integer]
|
194
|
-
|
195
|
-
super
|
196
|
-
end
|
208
|
+
# @!method export
|
197
209
|
|
198
210
|
# @return [Integer]
|
199
|
-
|
200
|
-
super
|
201
|
-
end
|
211
|
+
# @!method drawimage
|
202
212
|
|
203
|
-
#
|
213
|
+
# This function creates a mesh from vertex position, normal and color data.
|
214
|
+
#
|
204
215
|
# @return [Integer]
|
205
|
-
def createmesh_nocopy(
|
216
|
+
def createmesh_nocopy(n, vertices, normals, colors)
|
206
217
|
inquiry_int do |mesh|
|
207
|
-
super(mesh, vertices, normals, colors)
|
218
|
+
super(mesh, n, vertices, normals, colors)
|
208
219
|
end
|
209
220
|
end
|
210
221
|
|
211
222
|
# This function creates a int from vertex position, normal and color data.
|
212
223
|
# Returns a mesh.
|
213
|
-
#
|
224
|
+
#
|
225
|
+
# @param n [Integer] the number of vertices in the mesh
|
214
226
|
# @param vertices [Array, NArray] the vertex positions
|
215
|
-
# @param normals
|
216
|
-
# @param colors
|
217
|
-
#
|
227
|
+
# @param normals [Array, NArray] the vertex normals
|
228
|
+
# @param colors [Array, NArray] the vertex colors, they should be
|
229
|
+
# white (1,1,1) if you want to change the color for each drawn mesh
|
230
|
+
#
|
218
231
|
# @return [Integer]
|
232
|
+
#
|
219
233
|
def createmesh(n, vertices, normals, colors)
|
220
234
|
inquiry_int do |mesh|
|
221
235
|
super(mesh, n, vertices, normals, colors)
|
@@ -223,6 +237,7 @@ module GR3
|
|
223
237
|
end
|
224
238
|
|
225
239
|
# This function creates a mesh from vertex position, normal and color data.
|
240
|
+
#
|
226
241
|
# @return [Integer]
|
227
242
|
def createindexedmesh_nocopy(num_vertices, vertices, normals, colors, num_indices, indices)
|
228
243
|
inquiry_int do |mesh|
|
@@ -233,150 +248,159 @@ module GR3
|
|
233
248
|
# This function creates an indexed mesh from vertex information (position,
|
234
249
|
# normal and color) and triangle information (indices).
|
235
250
|
# Returns a mesh.
|
236
|
-
#
|
237
|
-
# @param
|
238
|
-
# @param
|
239
|
-
# @param
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
251
|
+
#
|
252
|
+
# @param num_vertices [Integer] the number of vertices in the mesh
|
253
|
+
# @param vertices [Array, NArray] the vertex positions
|
254
|
+
# @param normals [Array, NArray] the vertex normals
|
255
|
+
# @param colors [Array, NArray] the vertex colors, they should be
|
256
|
+
# white (1,1,1) if you want to change
|
257
|
+
# the color for each drawn mesh
|
258
|
+
# @param num_indices [Integer] the number of indices in the mesh
|
259
|
+
# (three times the number of triangles)
|
260
|
+
# @param indices [Array, NArray] the index array (vertex indices for
|
261
|
+
# each triangle)
|
262
|
+
#
|
243
263
|
# @return [Integer]
|
264
|
+
#
|
244
265
|
def createindexedmesh(num_vertices, vertices, normals, colors, num_indices, indices)
|
245
266
|
inquiry_int do |mesh|
|
246
267
|
super(mesh, num_vertices, vertices, normals, colors, num_indices, indices)
|
247
268
|
end
|
248
269
|
end
|
249
270
|
|
250
|
-
# This function adds a mesh to the draw list, so it will be drawn when the
|
251
|
-
# The given data stays owned by the user, a copy will
|
252
|
-
#
|
253
|
-
#
|
254
|
-
#
|
271
|
+
# This function adds a mesh to the draw list, so it will be drawn when the
|
272
|
+
# user calls getpixmap. The given data stays owned by the user, a copy will
|
273
|
+
# be saved in the draw list and the mesh reference counter will be increased.
|
274
|
+
#
|
275
|
+
# This function does not return an error code, because of its asynchronous
|
276
|
+
# nature. If gr3_getpixmap_() returns a GR3_ERROR_OPENGL_ERR, this might be
|
277
|
+
# caused by this function saving unuseable data into the draw list.
|
278
|
+
#
|
279
|
+
# @param mesh [Integer] The mesh to be drawn
|
280
|
+
# @param n [Integer] The number of meshes to be drawn
|
281
|
+
# @param positions [Array, NArray] The positions where the meshes should be drawn
|
255
282
|
# @param directions [Array, NArray] The forward directions the meshes should be facing at
|
256
|
-
# @param ups
|
257
|
-
# @param colors
|
258
|
-
#
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
# This function marks a mesh for deletion and removes the user’s reference
|
264
|
-
# so a user must not use the mesh after
|
283
|
+
# @param ups [Array, NArray] The up directions
|
284
|
+
# @param colors [Array, NArray] The colors the meshes should be drawn in,
|
285
|
+
# it will be multiplied with each vertex color
|
286
|
+
# @param scales [Array, NArray] The scaling factors
|
287
|
+
#
|
288
|
+
# @!method drawmesh
|
289
|
+
|
290
|
+
# This function marks a mesh for deletion and removes the user’s reference
|
291
|
+
# from the mesh’s referenc counter, so a user must not use the mesh after
|
292
|
+
# calling this function.
|
293
|
+
#
|
265
294
|
# @param mesh [Integer] The mesh that should be marked for deletion
|
266
|
-
|
267
|
-
|
268
|
-
end
|
295
|
+
#
|
296
|
+
# @!method deletemesh
|
269
297
|
|
270
298
|
# This function sets the view matrix by getting the position of the camera,
|
271
299
|
# the position of the center of focus and the direction which should point up.
|
300
|
+
# This function takes effect when the next image is created. Therefore if
|
301
|
+
# you want to take pictures of the same data from different perspectives,
|
302
|
+
# you can call and gr3_cameralookat(), gr3_getpixmap_(), gr3_cameralookat(),
|
303
|
+
# gr3_getpixmap_(), … without calling gr3_clear() and gr3_drawmesh() again.
|
304
|
+
#
|
272
305
|
# @param camera_x [Array, NArray] The x-coordinate of the camera
|
273
306
|
# @param camera_y [Array, NArray] The y-coordinate of the camera
|
274
307
|
# @param camera_z [Array, NArray] The z-coordinate of the camera
|
275
308
|
# @param center_x [Array, NArray] The x-coordinate of the center of focus
|
276
309
|
# @param center_y [Array, NArray] The y-coordinate of the center of focus
|
277
310
|
# @param center_z [Array, NArray] The z-coordinate of the center of focus
|
278
|
-
# @param up_x
|
279
|
-
# @param up_y
|
280
|
-
# @param up_z
|
281
|
-
|
282
|
-
|
283
|
-
end
|
311
|
+
# @param up_x [Array, NArray] The x-component of the up direction
|
312
|
+
# @param up_y [Array, NArray] The y-component of the up direction
|
313
|
+
# @param up_z [Array, NArray] The z-component of the up direction
|
314
|
+
#
|
315
|
+
# @!method cameralookat
|
284
316
|
|
285
317
|
# This function sets the projection parameters.
|
286
318
|
# This function takes effect when the next image is created.
|
287
|
-
#
|
288
|
-
#
|
319
|
+
#
|
320
|
+
# The ratio between zFar and zNear influences the precision of the depth
|
321
|
+
# buffer, the greater (zFar/zNear), the more likely are errors. So you should
|
322
|
+
# try to keep both values as close to each other as possible while making
|
323
|
+
# sure everything you want to be visible, is visible.
|
324
|
+
#
|
325
|
+
# @param vertical_field_of_view [Numeric]
|
326
|
+
# This parameter is the vertical field of view in degrees.
|
327
|
+
# It must be greater than 0 and less than 180.
|
289
328
|
# @param zNear [Numeric] The distance to the near clipping plane.
|
290
|
-
# @param zFar
|
329
|
+
# @param zFar [Numeric] The distance to the far clipping plane.
|
330
|
+
#
|
291
331
|
# @return [Integer]
|
292
|
-
|
293
|
-
|
294
|
-
end
|
332
|
+
#
|
333
|
+
# @!method setcameraprojectionparameters
|
295
334
|
|
296
335
|
# Get the projection parameters.
|
336
|
+
#
|
337
|
+
# @param vfov [Array, NArray] Vertical field of view in degrees
|
338
|
+
# @param znear [Array, NArray] The distance to the near clipping plane.
|
339
|
+
# @param zfar [Array, NArray] The distance to the far clipping plane.
|
340
|
+
#
|
297
341
|
# @return [Integer]
|
298
|
-
|
299
|
-
|
300
|
-
end
|
342
|
+
#
|
343
|
+
# @!method getcameraprojectionparameters
|
301
344
|
|
302
|
-
# This function sets the direction of light.
|
303
|
-
#
|
345
|
+
# This function sets the direction of light. If it is called with (0, 0, 0),
|
346
|
+
# the light is always pointing into the same direction as the camera.
|
347
|
+
#
|
304
348
|
# @param x [Numeric] The x-component of the light's direction
|
305
349
|
# @param y [Numeric] The y-component of the light's direction
|
306
350
|
# @param z [Numeric] The z-component of the light's direction
|
307
|
-
|
308
|
-
|
309
|
-
end
|
351
|
+
#
|
352
|
+
# @!method setlightdirection
|
310
353
|
|
311
354
|
# This function sets the background color.
|
312
|
-
|
313
|
-
super
|
314
|
-
end
|
355
|
+
# @!method setbackgroundcolor
|
315
356
|
|
316
357
|
# @return [Integer]
|
317
|
-
|
318
|
-
super
|
319
|
-
end
|
358
|
+
# @!method createheightmapmesh
|
320
359
|
|
321
|
-
|
322
|
-
super
|
323
|
-
end
|
360
|
+
# @!method drawheightmap
|
324
361
|
|
325
362
|
# This function allows drawing a cylinder without requiring a mesh.
|
326
|
-
|
327
|
-
super
|
328
|
-
end
|
363
|
+
# @!method drawconemesh
|
329
364
|
|
330
365
|
# This function allows drawing a cylinder without requiring a mesh.
|
331
|
-
|
332
|
-
super
|
333
|
-
end
|
366
|
+
# @!method drawcylindermesh
|
334
367
|
|
335
368
|
# This function allows drawing a sphere without requiring a mesh.
|
336
|
-
|
337
|
-
super
|
338
|
-
end
|
369
|
+
# @!method drawspheremesh
|
339
370
|
|
340
|
-
|
341
|
-
super
|
342
|
-
end
|
371
|
+
# @!method drawcubemesh
|
343
372
|
|
344
|
-
|
345
|
-
super
|
346
|
-
end
|
373
|
+
# @!method setobjectid
|
347
374
|
|
348
375
|
# @return [Integer]
|
349
|
-
|
350
|
-
super
|
351
|
-
end
|
376
|
+
# @!method selectid
|
352
377
|
|
353
|
-
|
354
|
-
|
355
|
-
end
|
378
|
+
# @param m [Array, NArray] the 4x4 column major view matrix
|
379
|
+
# @!method getviewmatrix
|
356
380
|
|
357
|
-
|
358
|
-
|
359
|
-
end
|
381
|
+
# @param m [Array, NArray] the 4x4 column major view matrix
|
382
|
+
# @!method setviewmatrix
|
360
383
|
|
361
|
-
# the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL
|
362
384
|
# @return [Integer]
|
363
|
-
|
364
|
-
|
365
|
-
end
|
385
|
+
# the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL
|
386
|
+
# @!method getprojectiontype
|
366
387
|
|
367
|
-
# @param type [Integer]
|
368
|
-
|
369
|
-
|
370
|
-
|
388
|
+
# @param type [Integer]
|
389
|
+
# the new projection type: GR3_PROJECTION_PERSPECTIVE,
|
390
|
+
# GR3_PROJECTION_PARALLEL or GR3_PROJECTION_ORTHOGRAPHIC
|
391
|
+
# @!method setprojectiontype
|
371
392
|
|
372
393
|
# This function creates an isosurface from voxel data using the
|
373
394
|
# marching cubes algorithm.
|
374
395
|
# Returns a mesh.
|
375
|
-
#
|
376
|
-
# @param
|
377
|
-
# @param
|
378
|
-
# @param
|
396
|
+
#
|
397
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
398
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
399
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
400
|
+
# @param isolevel [Integer] isovalue at which the surface will be created
|
401
|
+
#
|
379
402
|
# @return [Integer]
|
403
|
+
#
|
380
404
|
def createisosurfacemesh(grid, step, offset, isolevel)
|
381
405
|
args = _preprocess_createslicemesh(grid, step, offset)
|
382
406
|
grid = args.shift
|
@@ -388,10 +412,11 @@ module GR3
|
|
388
412
|
# Create a mesh of a surface plot similar to gr_surface.
|
389
413
|
# Uses the current colormap. To apply changes of the colormap
|
390
414
|
# a new mesh has to be created.
|
391
|
-
#
|
392
|
-
# @param
|
393
|
-
# @param
|
394
|
-
# @param
|
415
|
+
#
|
416
|
+
# @param nx [Integer] number of points in x-direction
|
417
|
+
# @param ny [Integer] number of points in y-direction
|
418
|
+
# @param x [Array, NArray] an array containing the x-coordinates
|
419
|
+
# @param y [Array, NArray] an array containing the y-coordinates
|
395
420
|
# @param z [Array, NArray] an array of length nx * ny containing the z-coordinates
|
396
421
|
# @param option [Integer] option for the surface mesh; the GR3_SURFACE constants can be combined with bitwise or. See the table below.
|
397
422
|
# * 0 : GR3_SURFACE_DEFAULT
|
@@ -406,6 +431,7 @@ module GR3
|
|
406
431
|
# * color the surface according to the current gr colormap
|
407
432
|
# * 16 : GR3_SURFACE_GRZSHADED
|
408
433
|
# * like GR3_SURFACE_GRCOLOR, but use the z-value directly as color index
|
434
|
+
#
|
409
435
|
# @return [Integer]
|
410
436
|
def createsurfacemesh(nx, ny, x, y, z, option = 0)
|
411
437
|
inquiry_int do |mesh|
|
@@ -419,29 +445,32 @@ module GR3
|
|
419
445
|
# the viewmatrix and the light direction. If necessary, the user has to
|
420
446
|
# save them before the call to this function and restore them after
|
421
447
|
# the call to gr3_drawimage.
|
422
|
-
#
|
423
|
-
# @param
|
424
|
-
# @param
|
448
|
+
#
|
449
|
+
# @param mesh [Integer] the mesh to be drawn
|
450
|
+
# @param n [Integer] the number of meshes to be drawn
|
451
|
+
# @param positions [Array, NArray] the positions where the meshes should be drawn
|
425
452
|
# @param directions [Array, NArray] the forward directions the meshes should be facing at
|
426
|
-
# @param ups
|
427
|
-
# @param colors
|
428
|
-
#
|
429
|
-
|
430
|
-
|
431
|
-
|
453
|
+
# @param ups [Array, NArray] the up directions
|
454
|
+
# @param colors [Array, NArray] the colors the meshes should be drawn in,
|
455
|
+
# it will be multiplied with each vertex color
|
456
|
+
# @param scales [Array, NArray] the scaling factors
|
457
|
+
#
|
458
|
+
# @!method drawmesh_grlike
|
432
459
|
|
433
460
|
# Convenience function for drawing a surfacemesh.
|
461
|
+
#
|
434
462
|
# @param mesh [Integer] the mesh to be drawn
|
435
|
-
|
436
|
-
|
437
|
-
end
|
463
|
+
#
|
464
|
+
# @!method drawsurface
|
438
465
|
|
439
466
|
# Create a surface plot with gr3 and draw it with gks as cellarray.
|
440
|
-
#
|
441
|
-
# @param
|
442
|
-
# @param
|
443
|
-
# @param
|
444
|
-
#
|
467
|
+
#
|
468
|
+
# @param x [Array, NArray] an array containing the x-coordinates
|
469
|
+
# @param y [Array, NArray] an array containing the y-coordinates
|
470
|
+
# @param z [Array, NArray] an array of length nx * ny containing the z-coordinates
|
471
|
+
# @param option [Integer] see the option parameter of gr_surface.
|
472
|
+
# OPTION_COLORED_MESH and OPTION_Z_SHADED_MESH are supported.
|
473
|
+
#
|
445
474
|
def surface(x, y, z, option)
|
446
475
|
nx = x.length
|
447
476
|
ny = y.length
|
@@ -449,17 +478,20 @@ module GR3
|
|
449
478
|
super(nx, ny, x, y, z, option)
|
450
479
|
end
|
451
480
|
|
452
|
-
# drawtubemesh
|
453
481
|
# Draw a tube following a path given by a list of points. The colors and
|
454
482
|
# radii arrays specify the color and radius at each point.
|
455
|
-
#
|
483
|
+
#
|
484
|
+
# @param n [Integer] the number of points given
|
456
485
|
# @param points [Array, NArray] the points the tube should go through
|
457
486
|
# @param colors [Array, NArray] the color at each point
|
458
|
-
# @param radii
|
459
|
-
# @param num_steps
|
460
|
-
#
|
461
|
-
#
|
487
|
+
# @param radii [Array, NArray] the desired tube radius at each point
|
488
|
+
# @param num_steps [Integer] the number of steps between each point,
|
489
|
+
# allowing for a more smooth tube
|
490
|
+
# @param num_segments [Integer] the number of segments each ring of the tube
|
491
|
+
# consists of, e.g. 3 would yield a triangular tube
|
492
|
+
#
|
462
493
|
# @return [Integer]
|
494
|
+
#
|
463
495
|
def drawtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20)
|
464
496
|
super(n, points, colors, radii, num_steps, num_segments)
|
465
497
|
end
|
@@ -467,12 +499,17 @@ module GR3
|
|
467
499
|
# Create a mesh object in the shape of a tube following a path given by a
|
468
500
|
# list of points. The colors and radii arrays specify the color and radius at
|
469
501
|
# each point.
|
470
|
-
#
|
471
|
-
# @param
|
472
|
-
# @param
|
473
|
-
# @param
|
474
|
-
# @param
|
475
|
-
# @param
|
502
|
+
#
|
503
|
+
# @param n [Integer] the number of points given
|
504
|
+
# @param points [Array, NArray] the points the tube should go through
|
505
|
+
# @param colors [Array, NArray] the color at each point
|
506
|
+
# @param radii [Array, NArray] the desired tube radius at each point
|
507
|
+
# @param num_steps [Integer] the number of steps between each point,
|
508
|
+
# allowing for a more smooth tube
|
509
|
+
# @param num_segments [Integer] the number of segments each ring of the
|
510
|
+
# tube consists of, e.g. 3 would yield a
|
511
|
+
# triangular tube
|
512
|
+
#
|
476
513
|
# @return [Integer]
|
477
514
|
def createtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20)
|
478
515
|
inquiry_uint do |mesh| # mesh should be Int?
|
@@ -547,12 +584,14 @@ module GR3
|
|
547
584
|
# drawn and at which positions they should go through the data. If neither
|
548
585
|
# x nor y nor z are set, 0.5 will be used for all three.
|
549
586
|
# Returns meshes for the yz-slice, the xz-slice and the xy-slice.
|
550
|
-
#
|
551
|
-
# @param
|
552
|
-
# @param
|
553
|
-
# @param
|
554
|
-
# @param
|
555
|
-
# @param
|
587
|
+
#
|
588
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
589
|
+
# @param x [Numeric] the position of the slice through the xz-plane (0 to 1)
|
590
|
+
# @param y [Numeric] the position of the slice through the xz-plane (0 to 1)
|
591
|
+
# @param z [Numeric] the position of the slice through the xz-plane (0 to 1)
|
592
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
593
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
594
|
+
#
|
556
595
|
def createslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil)
|
557
596
|
if [x, y, z].all?(&:nil?)
|
558
597
|
x = 0.5
|
@@ -569,10 +608,11 @@ module GR3
|
|
569
608
|
# using the current GR colormap. Use the x parameter to set the position of
|
570
609
|
# the yz-slice.
|
571
610
|
# Returns a mesh for the yz-slice.
|
572
|
-
#
|
573
|
-
# @param
|
574
|
-
# @param
|
575
|
-
# @param
|
611
|
+
#
|
612
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
613
|
+
# @param x [Numeric] the position of the slice through the xz-plane (0 to 1)
|
614
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
615
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
576
616
|
def createxslicemesh(grid, x = 0.5, step = nil, offset = nil)
|
577
617
|
args = _preprocess_createslicemesh(grid, step, offset)
|
578
618
|
grid = args.shift
|
@@ -586,10 +626,12 @@ module GR3
|
|
586
626
|
# using the current GR colormap. Use the y parameter to set the position of
|
587
627
|
# the xz-slice.
|
588
628
|
# Returns a mesh for the xz-slice.
|
589
|
-
#
|
590
|
-
# @param
|
591
|
-
# @param
|
592
|
-
# @param
|
629
|
+
#
|
630
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
631
|
+
# @param y [Numeric] the position of the slice through the xz-plane (0 to 1)
|
632
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
633
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
634
|
+
#
|
593
635
|
def createyslicemesh(grid, y = 0.5, step = nil, offset = nil)
|
594
636
|
args = _preprocess_createslicemesh(grid, step, offset)
|
595
637
|
grid = args.shift
|
@@ -603,10 +645,12 @@ module GR3
|
|
603
645
|
# using the current GR colormap. Use the z parameter to set the position of
|
604
646
|
# the xy-slice.
|
605
647
|
# Returns a mesh for the xy-slice.
|
606
|
-
#
|
607
|
-
# @param
|
608
|
-
# @param
|
609
|
-
# @param
|
648
|
+
#
|
649
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
650
|
+
# @param z [Numeric] the position of the slice through the xz-plane (0 to 1)
|
651
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
652
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
653
|
+
#
|
610
654
|
def createzslicemesh(grid, z = 0.5, step = nil, offset = nil)
|
611
655
|
args = _preprocess_createslicemesh(grid, step, offset)
|
612
656
|
grid = args.shift
|
@@ -617,15 +661,18 @@ module GR3
|
|
617
661
|
end
|
618
662
|
|
619
663
|
# Draw a yz-slice through the given data, using the current GR colormap.
|
620
|
-
#
|
621
|
-
# @param
|
622
|
-
# @param
|
623
|
-
# @param
|
624
|
-
# @param
|
625
|
-
# @param
|
626
|
-
# @param
|
627
|
-
# @param
|
628
|
-
# @param
|
664
|
+
#
|
665
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
666
|
+
# @param x [Numeric] the position of the slice through the yz-plane (0 to 1)
|
667
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
668
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
669
|
+
# @param position [Array, NArray] the positions where the meshes should be drawn
|
670
|
+
# @param direction [Array, NArray] the forward directions the meshes should be facing at
|
671
|
+
# @param up [Array, NArray] the up directions
|
672
|
+
# @param color [Array, NArray] the colors the meshes should be drawn in,
|
673
|
+
# it will be multiplied with each vertex color
|
674
|
+
# @param scale [Array, NArray] the scaling factors
|
675
|
+
#
|
629
676
|
def drawxslicemesh(grid, x = 0.5, step = nil, offset = nil,
|
630
677
|
position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
|
631
678
|
color = [1, 1, 1], scale = [1, 1, 1])
|
@@ -635,15 +682,18 @@ module GR3
|
|
635
682
|
end
|
636
683
|
|
637
684
|
# Draw a xz-slice through the given data, using the current GR colormap.
|
638
|
-
#
|
639
|
-
# @param
|
640
|
-
# @param
|
641
|
-
# @param
|
642
|
-
# @param
|
643
|
-
# @param
|
644
|
-
# @param
|
645
|
-
# @param
|
646
|
-
# @param
|
685
|
+
#
|
686
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
687
|
+
# @param y [Numeric] the position of the slice through the xz-plane (0 to 1)
|
688
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
689
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
690
|
+
# @param position [Array, NArray] the positions where the meshes should be drawn
|
691
|
+
# @param direction [Array, NArray] the forward directions the meshes should be facing at
|
692
|
+
# @param up [Array, NArray] the up directions
|
693
|
+
# @param color [Array, NArray] the colors the meshes should be drawn in,
|
694
|
+
# it will be multiplied with each vertex color
|
695
|
+
# @param scale [Array, NArray] the scaling factors
|
696
|
+
#
|
647
697
|
def drawyslicemesh(grid, y = 0.5, step = nil, offset = nil,
|
648
698
|
position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
|
649
699
|
color = [1, 1, 1], scale = [1, 1, 1])
|
@@ -653,15 +703,18 @@ module GR3
|
|
653
703
|
end
|
654
704
|
|
655
705
|
# Draw a xy-slice through the given data, using the current GR colormap.
|
656
|
-
#
|
657
|
-
# @param
|
658
|
-
# @param
|
659
|
-
# @param
|
660
|
-
# @param
|
661
|
-
# @param
|
662
|
-
# @param
|
663
|
-
# @param
|
664
|
-
# @param
|
706
|
+
#
|
707
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
708
|
+
# @param z [Numeric] the position of the slice through the xy-plane (0 to 1)
|
709
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
710
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
711
|
+
# @param position [Array, NArray] the positions where the meshes should be drawn
|
712
|
+
# @param direction [Array, NArray] the forward directions the meshes should be facing at
|
713
|
+
# @param up [Array, NArray] the up directions
|
714
|
+
# @param color [Array, NArray] the colors the meshes should be drawn in,
|
715
|
+
# it will be multiplied with each vertex color
|
716
|
+
# @param scale [Array, NArray] the scaling factors
|
717
|
+
#
|
665
718
|
def drawzslicemesh(grid, z = 0.5, step = nil, offset = nil,
|
666
719
|
position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
|
667
720
|
color = [1, 1, 1], scale = [1, 1, 1])
|
@@ -674,17 +727,20 @@ module GR3
|
|
674
727
|
# Use the parameters x, y or z to specify what slices should be drawn and at
|
675
728
|
# which positions they should go through the data. If neither x nor y nor
|
676
729
|
# z are set, 0.5 will be used for all three.
|
730
|
+
#
|
677
731
|
# @param grid [NArray] 3D narray array containing the voxel data
|
678
|
-
# @param x
|
679
|
-
# @param y
|
680
|
-
# @param z
|
681
|
-
# @param step
|
682
|
-
# @param offset
|
683
|
-
# @param position
|
684
|
-
# @param direction [Array] the forward directions the meshes should be facing at
|
685
|
-
# @param up
|
686
|
-
# @param color
|
687
|
-
#
|
732
|
+
# @param x [Numeric] the position of the slice through the yz-plane (0 to 1)
|
733
|
+
# @param y [Numeric] the position of the slice through the xz-plane (0 to 1)
|
734
|
+
# @param z [Numeric] the position of the slice through the xy-plane (0 to 1)
|
735
|
+
# @param step [Array, NArray] voxel sizes in each direction
|
736
|
+
# @param offset [Array, NArray] coordinate origin in each direction
|
737
|
+
# @param position [Array, NArray] the positions where the meshes should be drawn
|
738
|
+
# @param direction [Array, NArray] the forward directions the meshes should be facing at
|
739
|
+
# @param up [Array, NArray] the up directions
|
740
|
+
# @param color [Array, NArray] the colors the meshes should be drawn in,
|
741
|
+
# it will be multiplied with each vertex color
|
742
|
+
# @param scale [Array, NArray] the scaling factors
|
743
|
+
#
|
688
744
|
def drawslicemeshes(grid, x = nil, y = nil, z = nil, step = nil,
|
689
745
|
offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
|
690
746
|
color = [1, 1, 1], scale = [1, 1, 1])
|