ruby-gr 0.0.3 → 0.0.4
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/lib/gr.rb +970 -34
- data/lib/gr/ffi.rb +3 -0
- data/lib/gr3.rb +248 -82
- data/lib/gr3/ffi.rb +1 -0
- data/lib/gr_commons.rb +1 -0
- data/lib/gr_commons/attach_function.rb +1 -0
- data/lib/gr_commons/define_methods.rb +1 -0
- data/lib/gr_commons/gr_common_utils.rb +1 -0
- data/lib/gr_commons/jupyter_support.rb +12 -5
- data/lib/gr_commons/version.rb +1 -1
- metadata +2 -2
data/lib/gr/ffi.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'ffi'
|
4
4
|
|
5
5
|
module GR
|
6
|
+
# FFI Wrapper module for GR
|
6
7
|
module FFI
|
7
8
|
extend ::FFI::Library
|
8
9
|
|
@@ -191,5 +192,7 @@ module GR
|
|
191
192
|
attach_function :gr_shadelines, %i[int pointer pointer int int int], :void
|
192
193
|
attach_function :gr_panzoom, %i[double double double double pointer pointer pointer pointer], :void
|
193
194
|
# attach_function :gr_findboundary
|
195
|
+
attach_function :gr_setresamplemethod, %i[uint], :void
|
196
|
+
attach_function :gr_inqresamplemethod, %i[pointer], :void
|
194
197
|
end
|
195
198
|
end
|
data/lib/gr3.rb
CHANGED
@@ -71,6 +71,11 @@ module GR3
|
|
71
71
|
end
|
72
72
|
|
73
73
|
# This function allows the user to find out how his commands are rendered.
|
74
|
+
# If gr3 is initialized, a string in the format:
|
75
|
+
# `"gr3 - " + window toolkit + " - " + framebuffer extension + " - " + OpenGL version + " - " + OpenGL renderer string`.
|
76
|
+
# For example `"gr3 - GLX - GL_ARB_framebuffer_object - 2.1 Mesa 7.10.2 - Software Rasterizer"`
|
77
|
+
# might be returned on a Linux system (using GLX) with an available GL_ARB_framebuffer_object implementation.
|
78
|
+
# If gr3 is not initialized `"Not initialized"` is returned.
|
74
79
|
def getrenderpathstring(*)
|
75
80
|
super
|
76
81
|
end
|
@@ -85,14 +90,20 @@ module GR3
|
|
85
90
|
super
|
86
91
|
end
|
87
92
|
|
93
|
+
# Use the currently bound framebuffer as the framebuffer used for drawing to OpenGL (using gr3.drawimage).
|
94
|
+
# This function is only needed when you do not want to render to 0, the default framebuffer.
|
88
95
|
def usecurrentframebuffer(*)
|
89
96
|
super
|
90
97
|
end
|
91
98
|
|
99
|
+
# Set the framebuffer used for drawing to OpenGL (using gr3.drawimage).
|
100
|
+
# This function is only needed when you do not want to render to 0, the default framebuffer.
|
92
101
|
def useframebuffer(*)
|
93
102
|
super
|
94
103
|
end
|
95
104
|
|
105
|
+
# Set rendering quality
|
106
|
+
# @param quality [] The quality to set
|
96
107
|
def setquality(*)
|
97
108
|
super
|
98
109
|
end
|
@@ -121,9 +132,15 @@ module GR3
|
|
121
132
|
end
|
122
133
|
|
123
134
|
# This function creates a int from vertex position, normal and color data.
|
124
|
-
|
135
|
+
# Returns a mesh.
|
136
|
+
# @param n [Integer] the number of vertices in the mesh
|
137
|
+
# @param vertices [Array, NArray] the vertex positions
|
138
|
+
# @param normals [Array, NArray] the vertex normals
|
139
|
+
# @param colors [Array, NArray] the vertex colors,
|
140
|
+
# they should be white (1,1,1) if you want to change the color for each drawn mesh
|
141
|
+
def createmesh(n, vertices, normals, colors)
|
125
142
|
inquiry_int do |mesh|
|
126
|
-
super(mesh, vertices, normals, colors)
|
143
|
+
super(mesh, n, vertices, normals, colors)
|
127
144
|
end
|
128
145
|
end
|
129
146
|
|
@@ -134,31 +151,63 @@ module GR3
|
|
134
151
|
end
|
135
152
|
end
|
136
153
|
|
137
|
-
# This function creates
|
154
|
+
# This function creates an indexed mesh from vertex information (position,
|
155
|
+
# normal and color) and triangle information (indices).
|
156
|
+
# Returns a mesh.
|
157
|
+
# @param num_vertices [Integer] the number of vertices in the mesh
|
158
|
+
# @param vertices [Array, NArray] the vertex positions
|
159
|
+
# @param normals [Array, NArray] the vertex normals
|
160
|
+
# @param colors [Array, NArray] the vertex colors,
|
161
|
+
# they should be white (1,1,1) if you want to change the color for each drawn mesh
|
162
|
+
# @param num_indices [Integer] the number of indices in the mesh (three times the number of triangles)
|
163
|
+
# @param indices [Array, NArray] the index array (vertex indices for each triangle)
|
138
164
|
def createindexedmesh(num_vertices, vertices, normals, colors, num_indices, indices)
|
139
165
|
inquiry_int do |mesh|
|
140
166
|
super(mesh, num_vertices, vertices, normals, colors, num_indices, indices)
|
141
167
|
end
|
142
168
|
end
|
143
169
|
|
144
|
-
# This function adds a mesh to the draw list, so it will be drawn when the user calls
|
170
|
+
# This function adds a mesh to the draw list, so it will be drawn when the user calls getpixmap.
|
171
|
+
# The given data stays owned by the user, a copy will be saved in the draw list and the mesh reference counter will be increased.
|
172
|
+
# @param mesh [Integer] The mesh to be drawn
|
173
|
+
# @param n [Integer] The number of meshes to be drawn
|
174
|
+
# @param positions [Array, NArray] The positions where the meshes should be drawn
|
175
|
+
# @param directions [Array, NArray] The forward directions the meshes should be facing at
|
176
|
+
# @param ups [Array, NArray] The up directions
|
177
|
+
# @param colors [Array, NArray] The colors the meshes should be drawn in, it will be multiplied with each vertex color
|
178
|
+
# @param scales [Array, NArray] The scaling factors
|
145
179
|
def drawmesh(*)
|
146
180
|
super
|
147
181
|
end
|
148
182
|
|
149
183
|
# This function marks a mesh for deletion and removes the user’s reference from the mesh’s referenc counter,
|
150
184
|
# so a user must not use the mesh after calling this function.
|
185
|
+
# @param mesh [Integer] The mesh that should be marked for deletion
|
151
186
|
def deletemesh(*)
|
152
187
|
super
|
153
188
|
end
|
154
189
|
|
155
190
|
# This function sets the view matrix by getting the position of the camera,
|
156
191
|
# the position of the center of focus and the direction which should point up.
|
192
|
+
# @param camera_x [Array, NArray] The x-coordinate of the camera
|
193
|
+
# @param camera_y [Array, NArray] The y-coordinate of the camera
|
194
|
+
# @param camera_z [Array, NArray] The z-coordinate of the camera
|
195
|
+
# @param center_x [Array, NArray] The x-coordinate of the center of focus
|
196
|
+
# @param center_y [Array, NArray] The y-coordinate of the center of focus
|
197
|
+
# @param center_z [Array, NArray] The z-coordinate of the center of focus
|
198
|
+
# @param up_x [Array, NArray] The x-component of the up direction
|
199
|
+
# @param up_y [Array, NArray] The y-component of the up direction
|
200
|
+
# @param up_z [Array, NArray] The z-component of the up direction
|
157
201
|
def cameralookat(*)
|
158
202
|
super
|
159
203
|
end
|
160
204
|
|
161
205
|
# This function sets the projection parameters.
|
206
|
+
# This function takes effect when the next image is created.
|
207
|
+
# @param vertical_field_of_view [Numeric] This parameter is the vertical field of view in degrees.
|
208
|
+
# It must be greater than 0 and less than 180.
|
209
|
+
# @param zNear [Numeric] The distance to the near clipping plane.
|
210
|
+
# @param zFar [Numeric] The distance to the far clipping plane.
|
162
211
|
def setcameraprojectionparameters(*)
|
163
212
|
super
|
164
213
|
end
|
@@ -169,6 +218,10 @@ module GR3
|
|
169
218
|
end
|
170
219
|
|
171
220
|
# This function sets the direction of light.
|
221
|
+
# If it is called with (0, 0, 0), the light is always pointing into the same direction as the camera.
|
222
|
+
# @param x [Numeric] The x-component of the light's direction
|
223
|
+
# @param y [Numeric] The y-component of the light's direction
|
224
|
+
# @param z [Numeric] The z-component of the light's direction
|
172
225
|
def setlightdirection(*)
|
173
226
|
super
|
174
227
|
end
|
@@ -186,14 +239,17 @@ module GR3
|
|
186
239
|
super
|
187
240
|
end
|
188
241
|
|
242
|
+
# This function allows drawing a cylinder without requiring a mesh.
|
189
243
|
def drawconemesh(*)
|
190
244
|
super
|
191
245
|
end
|
192
246
|
|
247
|
+
# This function allows drawing a cylinder without requiring a mesh.
|
193
248
|
def drawcylindermesh(*)
|
194
249
|
super
|
195
250
|
end
|
196
251
|
|
252
|
+
# This function allows drawing a sphere without requiring a mesh.
|
197
253
|
def drawspheremesh(*)
|
198
254
|
super
|
199
255
|
end
|
@@ -218,10 +274,12 @@ module GR3
|
|
218
274
|
super
|
219
275
|
end
|
220
276
|
|
277
|
+
# the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL
|
221
278
|
def getprojectiontype(*)
|
222
279
|
super
|
223
280
|
end
|
224
281
|
|
282
|
+
# @param type [Integer] the new projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL
|
225
283
|
def setprojectiontype(*)
|
226
284
|
super
|
227
285
|
end
|
@@ -229,40 +287,74 @@ module GR3
|
|
229
287
|
# This function creates an isosurface from voxel data using the
|
230
288
|
# marching cubes algorithm.
|
231
289
|
# Returns a mesh.
|
290
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
291
|
+
# @param step [Array] voxel sizes in each direction
|
292
|
+
# @param offset [Array] coordinate origin in each direction
|
293
|
+
# @param isolevel [Integer] isovalue at which the surface will be created
|
232
294
|
def createisosurfacemesh(grid, step, offset, isolevel)
|
233
|
-
|
234
|
-
|
235
|
-
offset_x, offset_y, offset_z = offset
|
236
|
-
# NArray does not have the strides method
|
237
|
-
bytesize = grid.class.byte_size
|
238
|
-
stride_x = 1
|
239
|
-
stride_y = dim_y
|
240
|
-
stride_z = dim_y * dim_z
|
241
|
-
# stride_x, stride_y, stride_z = stride
|
295
|
+
args = _preprocess_createslicemesh(grid, step, offset)
|
296
|
+
grid = args.shift
|
242
297
|
inquiry_int do |mesh|
|
243
|
-
super(mesh, uint16(grid), isolevel,
|
244
|
-
stride_x, stride_y, stride_z, step_x, step_y, step_z, offset_x, offset_y, offset_z)
|
298
|
+
super(mesh, uint16(grid), isolevel, *args)
|
245
299
|
end
|
246
300
|
end
|
247
301
|
|
248
302
|
# Create a mesh of a surface plot similar to gr_surface.
|
303
|
+
# Uses the current colormap. To apply changes of the colormap
|
304
|
+
# a new mesh has to be created.
|
305
|
+
# @param nx [Integer] number of points in x-direction
|
306
|
+
# @param ny [Integer] number of points in y-direction
|
307
|
+
# @param px [Array, NArray] an array containing the x-coordinates
|
308
|
+
# @param py [Array, NArray] an array containing the y-coordinates
|
309
|
+
# @param pz [Array, NArray] an array of length nx * ny containing the z-coordinates
|
310
|
+
# @param option [Integer] option for the surface mesh; the GR3_SURFACE constants can be combined with bitwise or. See the table below.
|
311
|
+
# * 0 : GR3_SURFACE_DEFAULT
|
312
|
+
# * default behavior
|
313
|
+
# * 1 : GR3_SURFACE_NORMALS
|
314
|
+
# * interpolate the vertex normals from the gradient
|
315
|
+
# * 2 : GR3_SURFACE_FLAT
|
316
|
+
# * set all z-coordinates to zero
|
317
|
+
# * 4 : GR3_SURFACE_GRTRANSFORM
|
318
|
+
# * use gr_inqwindow, gr_inqspace and gr_inqscale to transform the data to NDC coordinates
|
319
|
+
# * 8 : GR3_SURFACE_GRCOLOR
|
320
|
+
# * color the surface according to the current gr colormap
|
321
|
+
# * 16 : GR3_SURFACE_GRZSHADED
|
322
|
+
# * like GR3_SURFACE_GRCOLOR, but use the z-value directly as color index
|
249
323
|
def createsurfacemesh(nx, ny, px, py, pz, option = 0)
|
250
324
|
inquiry_int do |mesh|
|
251
325
|
super(mesh, nx, ny, px, py, pz, option)
|
252
326
|
end
|
253
327
|
end
|
254
328
|
|
255
|
-
# Draw a mesh with the projection of gr.
|
329
|
+
# Draw a mesh with the projection of gr. It uses the current
|
330
|
+
# projection parameters (rotation, tilt) of gr.
|
331
|
+
# This function alters the projection type, the projection parameters,
|
332
|
+
# the viewmatrix and the light direction. If necessary, the user has to
|
333
|
+
# save them before the call to this function and restore them after
|
334
|
+
# the call to gr3_drawimage.
|
335
|
+
# @param mesh [Integer] the mesh to be drawn
|
336
|
+
# @param n [Integer] the number of meshes to be drawn
|
337
|
+
# @param positions [Array, NArray] the positions where the meshes should be drawn
|
338
|
+
# @param directions [Array, NArray] the forward directions the meshes should be facing at
|
339
|
+
# @param ups [Array, NArray] the up directions
|
340
|
+
# @param colors [Array, NArray] the colors the meshes should be drawn in, it will be multiplied with each vertex color
|
341
|
+
# @param scales [Array, NArray] the scaling factors
|
256
342
|
def drawmesh_grlike(*)
|
257
343
|
super
|
258
344
|
end
|
259
345
|
|
260
346
|
# Convenience function for drawing a surfacemesh.
|
347
|
+
# @param mesh [Integer] the mesh to be drawn
|
261
348
|
def drawsurface(*)
|
262
349
|
super
|
263
350
|
end
|
264
351
|
|
265
352
|
# Create a surface plot with gr3 and draw it with gks as cellarray.
|
353
|
+
# @param px [Array, NArray] an array containing the x-coordinates
|
354
|
+
# @param py [Array, NArray] an array containing the y-coordinates
|
355
|
+
# @param pz [Array, NArray] an array of length nx * ny containing the z-coordinates
|
356
|
+
# @param option [Integer] see the option parameter of gr_surface.
|
357
|
+
# OPTION_COLORED_MESH and OPTION_Z_SHADED_MESH are supported.
|
266
358
|
def surface(px, py, pz, _option)
|
267
359
|
nx = px.length
|
268
360
|
ny = py.length
|
@@ -271,11 +363,28 @@ module GR3
|
|
271
363
|
end
|
272
364
|
|
273
365
|
# drawtubemesh
|
366
|
+
# Draw a tube following a path given by a list of points. The colors and
|
367
|
+
# radii arrays specify the color and radius at each point.
|
368
|
+
# @param n [Integer] the number of points given
|
369
|
+
# @param points [Array, NArray] the points the tube should go through
|
370
|
+
# @param colors [Array, NArray] the color at each point
|
371
|
+
# @param radii [Array, NArray] the desired tube radius at each point
|
372
|
+
# @param num_steps [Integer] the number of steps between each point, allowing for a more smooth tube
|
373
|
+
# @param num_segments [Integer] the number of segments each ring of the tube consists of,
|
374
|
+
# e.g. 3 would yield a triangular tube
|
274
375
|
def drawtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20)
|
275
376
|
super(n, points, colors, radii, num_steps, num_segments)
|
276
377
|
end
|
277
378
|
|
278
|
-
#
|
379
|
+
# Create a mesh object in the shape of a tube following a path given by a
|
380
|
+
# list of points. The colors and radii arrays specify the color and radius at
|
381
|
+
# each point.
|
382
|
+
# @param n [Integer] the number of points given
|
383
|
+
# @param points [Array, NArray] the points the tube should go through
|
384
|
+
# @param colors [Array, NArray] the color at each point
|
385
|
+
# @param radii [Array, NArray] the desired tube radius at each point
|
386
|
+
# @param num_steps [Integer] the number of steps between each point, allowing for a more smooth tube
|
387
|
+
# @param num_segments [Integer] the number of segments each ring of the tube consists of, e.g. 3 would yield a triangular tube
|
279
388
|
def createtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20)
|
280
389
|
inquiry_uint do |mesh| # mesh should be Int?
|
281
390
|
super(mesh, n, points, colors, radii, num_steps, num_segments)
|
@@ -349,69 +458,38 @@ module GR3
|
|
349
458
|
# drawn and at which positions they should go through the data. If neither
|
350
459
|
# x nor y nor z are set, 0.5 will be used for all three.
|
351
460
|
# Returns meshes for the yz-slice, the xz-slice and the xy-slice.
|
461
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
462
|
+
# @param x [Numeric] the position of the slice through the xz-plane (0 to 1)
|
463
|
+
# @param y [Numeric] the position of the slice through the xz-plane (0 to 1)
|
464
|
+
# @param z [Numeric] the position of the slice through the xz-plane (0 to 1)
|
465
|
+
# @param step [Array] voxel sizes in each direction
|
466
|
+
# @param offset [Array] coordinate origin in each direction
|
352
467
|
def createslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil)
|
353
468
|
if [x, y, z].all?(&:nil?)
|
354
469
|
x = 0.5
|
355
470
|
y = 0.5
|
356
471
|
z = 0.5
|
357
472
|
end
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
[
|
362
|
-
end
|
363
|
-
|
364
|
-
def preprocess_createslicemesh(grid, step, offset)
|
365
|
-
# TODO: raise error when grid is not narray
|
366
|
-
# grid
|
367
|
-
case grid.class::MAX
|
368
|
-
when Integer
|
369
|
-
input_max = grid.class::MAX
|
370
|
-
when Float
|
371
|
-
# floating point values are expected to be in range [0, 1]
|
372
|
-
# Complex narrays are not taken into account
|
373
|
-
input_max = 1
|
374
|
-
grid[grid > 1] = 1
|
375
|
-
else
|
376
|
-
raise ArgumentError, 'grid must be three dimensional array of Real numbers'
|
377
|
-
end
|
378
|
-
scaling_factor = Numo::UInt16::MAX / input_max.to_f
|
379
|
-
grid = (grid.cast_to(Numo::UInt64) * scaling_factor).cast_to(Numo::UInt16) # room for improvement
|
380
|
-
|
381
|
-
# step & offset
|
382
|
-
nx, ny, nz = grid.shape
|
383
|
-
if step.nil? && offset.nil?
|
384
|
-
step = [2.0 / (nx - 1), 2.0 / (ny - 1), 2.0 / (nz - 1)]
|
385
|
-
offset = [-1.0, -1.0, -1.0]
|
386
|
-
elsif offset.nil?
|
387
|
-
offset = [-step[0] * (nx - 1) / 2.0,
|
388
|
-
-step[1] * (ny - 1) / 2.0,
|
389
|
-
-step[2] * (nz - 1) / 2.0]
|
390
|
-
elsif step.nil?
|
391
|
-
step = [-offset[0] * 2.0 / (nx - 1),
|
392
|
-
-offset[1] * 2.0 / (ny - 1),
|
393
|
-
-offset[2] * 2.0 / (nz - 1)]
|
394
|
-
end
|
395
|
-
|
396
|
-
step_x, step_y, step_z = step
|
397
|
-
offset_x, offset_y, offset_z = offset
|
398
|
-
|
399
|
-
[grid, nx, ny, nz, step_x, step_y, step_z, offset_x, offset_y, offset_z]
|
473
|
+
mesh_x = (createxslicemesh(grid, x, step, offset) if x)
|
474
|
+
mesh_y = (createyslicemesh(grid, y, step, offset) if y)
|
475
|
+
mesh_z = (createzslicemesh(grid, z, step, offset) if z)
|
476
|
+
[mesh_x, mesh_y, mesh_z]
|
400
477
|
end
|
401
478
|
|
402
479
|
# Creates a meshes for a slices through the yz-plane of the given data,
|
403
480
|
# using the current GR colormap. Use the x parameter to set the position of
|
404
481
|
# the yz-slice.
|
405
482
|
# Returns a mesh for the yz-slice.
|
483
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
484
|
+
# @param x [Numeric] the position of the slice through the xz-plane (0 to 1)
|
485
|
+
# @param step [Array] voxel sizes in each direction
|
486
|
+
# @param offset [Array] coordinate origin in each direction
|
406
487
|
def createxslicemesh(grid, x = 0.5, step = nil, offset = nil)
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
stride_y = ny
|
411
|
-
stride_z = ny * nz
|
488
|
+
args = _preprocess_createslicemesh(grid, step, offset)
|
489
|
+
grid = args.shift
|
490
|
+
x = (x.clamp(0, 1) * args[0]).floor
|
412
491
|
inquiry_int do |mesh|
|
413
|
-
super(mesh, grid, x,
|
414
|
-
step_x, step_y, step_z, offset_x, offset_y, offset_z)
|
492
|
+
super(mesh, uint16(grid), x, *args)
|
415
493
|
end
|
416
494
|
end
|
417
495
|
|
@@ -419,15 +497,16 @@ module GR3
|
|
419
497
|
# using the current GR colormap. Use the y parameter to set the position of
|
420
498
|
# the xz-slice.
|
421
499
|
# Returns a mesh for the xz-slice.
|
500
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
501
|
+
# @param y [Numeric] the position of the slice through the xz-plane (0 to 1)
|
502
|
+
# @param step [Array] voxel sizes in each direction
|
503
|
+
# @param offset [Array] coordinate origin in each direction
|
422
504
|
def createyslicemesh(grid, y = 0.5, step = nil, offset = nil)
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
stride_y = 1
|
427
|
-
stride_z = nx * nz
|
505
|
+
args = _preprocess_createslicemesh(grid, step, offset)
|
506
|
+
grid = args.shift
|
507
|
+
y = (y.clamp(0, 1) * args[1]).floor
|
428
508
|
inquiry_int do |mesh|
|
429
|
-
super(mesh, grid, y,
|
430
|
-
step_x, step_y, step_z, offset_x, offset_y, offset_z)
|
509
|
+
super(mesh, uint16(grid), y, *args)
|
431
510
|
end
|
432
511
|
end
|
433
512
|
|
@@ -435,19 +514,29 @@ module GR3
|
|
435
514
|
# using the current GR colormap. Use the z parameter to set the position of
|
436
515
|
# the xy-slice.
|
437
516
|
# Returns a mesh for the xy-slice.
|
517
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
518
|
+
# @param z [Numeric] the position of the slice through the xz-plane (0 to 1)
|
519
|
+
# @param step [Array] voxel sizes in each direction
|
520
|
+
# @param offset [Array] coordinate origin in each direction
|
438
521
|
def createzslicemesh(grid, z = 0.5, step = nil, offset = nil)
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
stride_y = ny
|
443
|
-
stride_z = 1
|
522
|
+
args = _preprocess_createslicemesh(grid, step, offset)
|
523
|
+
grid = args.shift
|
524
|
+
z = (z.clamp(0, 1) * args[2]).floor
|
444
525
|
inquiry_int do |mesh|
|
445
|
-
super(mesh, grid, z,
|
446
|
-
step_x, step_y, step_z, offset_x, offset_y, offset_z)
|
526
|
+
super(mesh, uint16(grid), z, *args)
|
447
527
|
end
|
448
528
|
end
|
449
529
|
|
450
530
|
# Draw a yz-slice through the given data, using the current GR colormap.
|
531
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
532
|
+
# @param x [Numeric] the position of the slice through the yz-plane (0 to 1)
|
533
|
+
# @param step [Array] voxel sizes in each direction
|
534
|
+
# @param offset [Array] coordinate origin in each direction
|
535
|
+
# @param position [Array] the positions where the meshes should be drawn
|
536
|
+
# @param direction [Array] the forward directions the meshes should be facing at
|
537
|
+
# @param up [Array] the up directions
|
538
|
+
# @param color [Array] the colors the meshes should be drawn in, it will be multiplied with each vertex color
|
539
|
+
# @param scale [Array] the scaling factors
|
451
540
|
def drawxslicemesh(grid, x = 0.5, step = nil, offset = nil,
|
452
541
|
position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
|
453
542
|
color = [1, 1, 1], scale = [1, 1, 1])
|
@@ -457,6 +546,15 @@ module GR3
|
|
457
546
|
end
|
458
547
|
|
459
548
|
# Draw a xz-slice through the given data, using the current GR colormap.
|
549
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
550
|
+
# @param y [Numeric] the position of the slice through the xz-plane (0 to 1)
|
551
|
+
# @param step [Array] voxel sizes in each direction
|
552
|
+
# @param offset [Array] coordinate origin in each direction
|
553
|
+
# @param position [Array] the positions where the meshes should be drawn
|
554
|
+
# @param direction [Array] the forward directions the meshes should be facing at
|
555
|
+
# @param up [Array] the up directions
|
556
|
+
# @param color [Array] the colors the meshes should be drawn in, it will be multiplied with each vertex color
|
557
|
+
# @param scale [Array] the scaling factors
|
460
558
|
def drawyslicemesh(grid, y = 0.5, step = nil, offset = nil,
|
461
559
|
position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
|
462
560
|
color = [1, 1, 1], scale = [1, 1, 1])
|
@@ -466,6 +564,15 @@ module GR3
|
|
466
564
|
end
|
467
565
|
|
468
566
|
# Draw a xy-slice through the given data, using the current GR colormap.
|
567
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
568
|
+
# @param z [Numeric] the position of the slice through the xy-plane (0 to 1)
|
569
|
+
# @param step [Array] voxel sizes in each direction
|
570
|
+
# @param offset [Array] coordinate origin in each direction
|
571
|
+
# @param position [Array] the positions where the meshes should be drawn
|
572
|
+
# @param direction [Array] the forward directions the meshes should be facing at
|
573
|
+
# @param up [Array] the up directions
|
574
|
+
# @param color [Array] the colors the meshes should be drawn in, it will be multiplied with each vertex color
|
575
|
+
# @param scale [Array] the scaling factors
|
469
576
|
def drawzslicemesh(grid, z = 0.5, step = nil, offset = nil,
|
470
577
|
position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
|
471
578
|
color = [1, 1, 1], scale = [1, 1, 1])
|
@@ -478,6 +585,17 @@ module GR3
|
|
478
585
|
# Use the parameters x, y or z to specify what slices should be drawn and at
|
479
586
|
# which positions they should go through the data. If neither x nor y nor
|
480
587
|
# z are set, 0.5 will be used for all three.
|
588
|
+
# @param grid [NArray] 3D narray array containing the voxel data
|
589
|
+
# @param x [Numeric] the position of the slice through the yz-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 xy-plane (0 to 1)
|
592
|
+
# @param step [Array] voxel sizes in each direction
|
593
|
+
# @param offset [Array] coordinate origin in each direction
|
594
|
+
# @param position [Array] the positions where the meshes should be drawn
|
595
|
+
# @param direction [Array] the forward directions the meshes should be facing at
|
596
|
+
# @param up [Array] the up directions
|
597
|
+
# @param color [Array] the colors the meshes should be drawn in, it will be multiplied with each vertex color
|
598
|
+
# @param scale [Array] the scaling factors
|
481
599
|
def drawslicemeshes(grid, x = nil, y = nil, z = nil, step = nil,
|
482
600
|
offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
|
483
601
|
color = [1, 1, 1], scale = [1, 1, 1])
|
@@ -500,14 +618,59 @@ module GR3
|
|
500
618
|
super(nx, ny, nz, data, algorithm, dmin, dmax)
|
501
619
|
end
|
502
620
|
end
|
503
|
-
end
|
504
621
|
|
505
|
-
|
622
|
+
private
|
623
|
+
|
624
|
+
def _preprocess_createslicemesh(grid, step, offset)
|
625
|
+
# TODO: raise error when grid is not narray
|
626
|
+
# grid
|
627
|
+
case grid.class::MAX
|
628
|
+
when Integer
|
629
|
+
input_max = grid.class::MAX
|
630
|
+
when Float
|
631
|
+
# floating point values are expected to be in range [0, 1]
|
632
|
+
# Complex narrays are not taken into account
|
633
|
+
input_max = 1
|
634
|
+
grid[grid > 1] = 1
|
635
|
+
else
|
636
|
+
raise ArgumentError, 'grid must be three dimensional array of Real numbers'
|
637
|
+
end
|
638
|
+
scaling_factor = Numo::UInt16::MAX / input_max.to_f
|
639
|
+
grid = (grid.cast_to(Numo::UInt64) * scaling_factor).cast_to(Numo::UInt16) # room for improvement
|
640
|
+
|
641
|
+
# step & offset
|
642
|
+
nx, ny, nz = grid.shape
|
643
|
+
if step.nil? && offset.nil?
|
644
|
+
step = [2.0 / (nx - 1), 2.0 / (ny - 1), 2.0 / (nz - 1)]
|
645
|
+
offset = [-1.0, -1.0, -1.0]
|
646
|
+
elsif offset.nil?
|
647
|
+
offset = [-step[0] * (nx - 1) / 2.0,
|
648
|
+
-step[1] * (ny - 1) / 2.0,
|
649
|
+
-step[2] * (nz - 1) / 2.0]
|
650
|
+
elsif step.nil?
|
651
|
+
step = [-offset[0] * 2.0 / (nx - 1),
|
652
|
+
-offset[1] * 2.0 / (ny - 1),
|
653
|
+
-offset[2] * 2.0 / (nz - 1)]
|
654
|
+
end
|
655
|
+
|
656
|
+
step_x, step_y, step_z = step
|
657
|
+
offset_x, offset_y, offset_z = offset
|
658
|
+
|
659
|
+
# strides
|
660
|
+
stride_x = ny * nz
|
661
|
+
stride_y = nz
|
662
|
+
stride_z = 1
|
663
|
+
|
664
|
+
[grid, nx, ny, nz, stride_x, stride_y, stride_z, step_x, step_y, step_z, offset_x, offset_y, offset_z]
|
665
|
+
end
|
666
|
+
end
|
506
667
|
|
668
|
+
# InitAttribute
|
507
669
|
IA_END_OF_LIST = 0
|
508
670
|
IA_FRAMEBUFFER_WIDTH = 1
|
509
671
|
IA_FRAMEBUFFER_HEIGHT = 2
|
510
672
|
|
673
|
+
# Error
|
511
674
|
ERROR_NONE = 0
|
512
675
|
ERROR_INVALID_VALUE = 1
|
513
676
|
ERROR_INVALID_ATTRIBUTE = 2
|
@@ -520,6 +683,7 @@ module GR3
|
|
520
683
|
ERROR_CANNOT_OPEN_FILE = 9
|
521
684
|
ERROR_EXPORT = 10
|
522
685
|
|
686
|
+
# Quality
|
523
687
|
QUALITY_OPENGL_NO_SSAA = 0
|
524
688
|
QUALITY_OPENGL_2X_SSAA = 2
|
525
689
|
QUALITY_OPENGL_4X_SSAA = 4
|
@@ -531,9 +695,11 @@ module GR3
|
|
531
695
|
QUALITY_POVRAY_8X_SSAA = 8 + 1
|
532
696
|
QUALITY_POVRAY_16X_SSAA = 16 + 1
|
533
697
|
|
698
|
+
# Drawable
|
534
699
|
DRAWABLE_OPENGL = 1
|
535
700
|
DRAWABLE_GKS = 2
|
536
701
|
|
702
|
+
# SurfaceOption
|
537
703
|
SURFACE_DEFAULT = 0
|
538
704
|
SURFACE_NORMALS = 1
|
539
705
|
SURFACE_FLAT = 2
|