Module: GR3

Extended by:
CheckError, GRCommons::GRCommonUtils
Defined in:
lib/gr3.rb,
lib/gr3/ffi.rb,
lib/gr3/gr3base.rb,
lib/gr3/version.rb

Overview

OverView of GR.rb

+--------------------+  +--------------------+
| GR module          |  | GR3 module         |
| +----------------+ |  | +----------------+ |
| | GR::FFI        | |  | | GR3::FFI       | |
| | +   libGR.so   | |  | | +    libGR3.so | |
| +----------------+ |  | +----------------+ |
|   | define_method  |  |   | define_method  |
| +----------------+ |  | +----------------+ |
| | | GR::GRBase   | |  | | | GR3::GR3Base | |
| | v  (Pri^ate)   | |  | | v  (Pri^ate)   | |
| +++--------------+ |  | +++--------------+ |
|  | Extend          |  |  | Extend          |
|  v                 |  |  v       +-------+ |
|      +-----------+ |  |          | Check | |
|      | GR::Plot  | |  |       <--+ Error | |
|      +-----------+ |  |          +-------+ |
+--------------------+  +----------+---------+
          ^                        ^
          |  +------------------+  |
   Extend |  | GRCommons module |  | Extend
          |  | +--------------+ |  |
          |  | |    Fiddley   | |  |
          |  | +--------------+ |  |
          |  | +--------------+ |  |
          +----+ CommonUtils  +----+
          |  | +--------------+ |  |
          |  | +--------------+ |  |
          +----+    Version   +----+
          |  | +--------------+ |
          |  | +--------------+ |
          +----+JupyterSupport| |
             | +--------------+ |
             +------------------+

(You can edit the above AA diagram with asciiflow.com/)

Fiddley is Ruby-FFI compatible API layer for Fiddle.

Why not GR::GR3?

  • kojix2 did not want to force gr3 to be loaded when gr is loaded.

  • kojix2 did not want to write ‘GR3 = GR::GR3` or something.

  • This is a opinion of kojix2 and may be changed by future maintainers.

GR3 uses Numo::Narrray.

This is a procedural interface to the GR3 in GR plotting library, github.com/sciapp/gr

Defined Under Namespace

Modules: CheckError, FFI Classes: Error

Constant Summary collapse

IA_END_OF_LIST =

InitAttribute

0
IA_FRAMEBUFFER_WIDTH =
1
IA_FRAMEBUFFER_HEIGHT =
2
ERROR_NONE =

Error

0
ERROR_INVALID_VALUE =
1
ERROR_INVALID_ATTRIBUTE =
2
ERROR_INIT_FAILED =
3
ERROR_OPENGL_ERR =
4
ERROR_OUT_OF_MEM =
5
ERROR_NOT_INITIALIZED =
6
ERROR_CAMERA_NOT_INITIALIZED =
7
ERROR_UNKNOWN_FILE_EXTENSION =
8
ERROR_CANNOT_OPEN_FILE =
9
ERROR_EXPORT =
10
QUALITY_OPENGL_NO_SSAA =

Quality

0
QUALITY_OPENGL_2X_SSAA =
2
QUALITY_OPENGL_4X_SSAA =
4
QUALITY_OPENGL_8X_SSAA =
8
QUALITY_OPENGL_16X_SSAA =
16
QUALITY_POVRAY_NO_SSAA =
0 + 1
QUALITY_POVRAY_2X_SSAA =
2 + 1
QUALITY_POVRAY_4X_SSAA =
4 + 1
QUALITY_POVRAY_8X_SSAA =
8 + 1
QUALITY_POVRAY_16X_SSAA =
16 + 1
DRAWABLE_OPENGL =

Drawable

1
DRAWABLE_GKS =
2
SURFACE_DEFAULT =

SurfaceOption

0
SURFACE_NORMALS =
1
SURFACE_FLAT =
2
SURFACE_GRTRANSFORM =
4
SURFACE_GRCOLOR =
8
SURFACE_GRZSHADED =
16
ATOM_COLORS =
[[0, 0, 0],
[255, 255, 255], [217, 255, 255], [204, 128, 255],
[194, 255, 0], [255, 181, 181], [144, 144, 144],
[48, 80, 248], [255, 13, 13], [144, 224, 80],
[179, 227, 245], [171, 92, 242], [138, 255, 0],
[191, 166, 166], [240, 200, 160], [255, 128, 0],
[255, 255, 48], [31, 240, 31], [128, 209, 227],
[143, 64, 212], [61, 225, 0], [230, 230, 230],
[191, 194, 199], [166, 166, 171], [138, 153, 199],
[156, 122, 199], [224, 102, 51], [240, 144, 160],
[80, 208, 80], [200, 128, 51], [125, 128, 176],
[194, 143, 143], [102, 143, 143], [189, 128, 227],
[225, 161, 0], [166, 41, 41], [92, 184, 209],
[112, 46, 176], [0, 255, 0], [148, 255, 255],
[148, 224, 224], [115, 194, 201], [84, 181, 181],
[59, 158, 158], [36, 143, 143], [10, 125, 140],
[0, 105, 133], [192, 192, 192], [255, 217, 143],
[166, 117, 115], [102, 128, 128], [158, 99, 181],
[212, 122, 0], [148, 0, 148], [66, 158, 176],
[87, 23, 143], [0, 201, 0], [112, 212, 255],
[255, 255, 199], [217, 225, 199], [199, 225, 199],
[163, 225, 199], [143, 225, 199], [97, 225, 199],
[69, 225, 199], [48, 225, 199], [31, 225, 199],
[0, 225, 156], [0, 230, 117], [0, 212, 82],
[0, 191, 56], [0, 171, 36], [77, 194, 255],
[77, 166, 255], [33, 148, 214], [38, 125, 171],
[38, 102, 150], [23, 84, 135], [208, 208, 224],
[255, 209, 35], [184, 184, 208], [166, 84, 77],
[87, 89, 97], [158, 79, 181], [171, 92, 0],
[117, 79, 69], [66, 130, 150], [66, 0, 102],
[0, 125, 0], [112, 171, 250], [0, 186, 255],
[0, 161, 255], [0, 143, 255], [0, 128, 255],
[0, 107, 255], [84, 92, 242], [120, 92, 227],
[138, 79, 227], [161, 54, 212], [179, 31, 212],
[179, 31, 186], [179, 13, 166], [189, 13, 135],
[199, 0, 102], [204, 0, 89], [209, 0, 79],
[217, 0, 69], [224, 0, 56], [230, 0, 46],
[235, 0, 38], [255, 0, 255], [255, 0, 255],
[255, 0, 255], [255, 0, 255], [255, 0, 255],
[255, 0, 255], [255, 0, 255], [255, 0, 255],
[255, 0, 255]].map! { |i| i.map! { |j| j / 255.0 } }
ATOM_NUMBERS =
atom_number.freeze
ATOM_VALENCE_RADII =
[0, # Avoid atomic number to index conversion
230, 930, 680, 350, 830, 680, 680, 680, 640,
1120, 970, 1100, 1350, 1200, 750, 1020, 990,
1570, 1330, 990, 1440, 1470, 1330, 1350, 1350,
1340, 1330, 1500, 1520, 1450, 1220, 1170, 1210,
1220, 1210, 1910, 1470, 1120, 1780, 1560, 1480,
1470, 1350, 1400, 1450, 1500, 1590, 1690, 1630,
1460, 1460, 1470, 1400, 1980, 1670, 1340, 1870,
1830, 1820, 1810, 1800, 1800, 1990, 1790, 1760,
1750, 1740, 1730, 1720, 1940, 1720, 1570, 1430,
1370, 1350, 1370, 1320, 1500, 1500, 1700, 1550,
1540, 1540, 1680, 1700, 2400, 2000, 1900, 1880,
1790, 1610, 1580, 1550, 1530, 1510, 1500, 1500,
1500, 1500, 1500, 1500, 1500, 1500, 1600, 1600,
1600, 1600, 1600, 1600, 1600, 1600, 1600, 1600,
1600, 1600, 1600, 1600, 1600, 1600].map { |i| i / 1000.0 }
ATOM_RADII =
ATOM_VALENCE_RADII.map { |i| i * 0.4 }
VERSION =
GRCommons::VERSION

Constants included from GRCommons::GRCommonUtils

GRCommons::GRCommonUtils::SUPPORTED_TYPES

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from GRCommons::GRCommonUtils

create_ffi_pointer, double, equal_length, float, inquiry, inquiry_double, inquiry_int, inquiry_uint, int, narray?, read_ffi_pointer, uint, uint16, uint8

Methods included from CheckError

geterror

Class Attribute Details

.ffi_libObject

Returns the value of attribute ffi_lib.



60
61
62
# File 'lib/gr3.rb', line 60

def ffi_lib
  @ffi_lib
end

Class Method Details

.cameralookatObject

This function sets the view matrix by getting the position of the camera, the position of the center of focus and the direction which should point up.

Parameters:

  • camera_x (Array, NArray)

    The x-coordinate of the camera

  • camera_y (Array, NArray)

    The y-coordinate of the camera

  • camera_z (Array, NArray)

    The z-coordinate of the camera

  • center_x (Array, NArray)

    The x-coordinate of the center of focus

  • center_y (Array, NArray)

    The y-coordinate of the center of focus

  • center_z (Array, NArray)

    The z-coordinate of the center of focus

  • up_x (Array, NArray)

    The x-component of the up direction

  • up_y (Array, NArray)

    The y-component of the up direction

  • up_z (Array, NArray)

    The z-component of the up direction



288
289
290
# File 'lib/gr3.rb', line 288

def cameralookat(*)
  super
end

.clearInteger

This function clears the draw list.

Returns:

  • (Integer)


169
170
171
# File 'lib/gr3.rb', line 169

def clear(*)
  super
end

.createheightmapmeshInteger

Returns:

  • (Integer)


324
325
326
# File 'lib/gr3.rb', line 324

def createheightmapmesh(*)
  super
end

.createindexedmesh(num_vertices, vertices, normals, colors, num_indices, indices) ⇒ Integer

This function creates an indexed mesh from vertex information (position, normal and color) and triangle information (indices). Returns a mesh.

Parameters:

  • num_vertices (Integer)

    the number of vertices in the mesh

  • vertices (Array, NArray)

    the vertex positions

  • normals (Array, NArray)

    the vertex normals

  • colors (Array, NArray)

    the vertex colors, they should be white (1,1,1) if you want to change the color for each drawn mesh

  • num_indices (Integer)

    the number of indices in the mesh (three times the number of triangles)

  • indices (Array, NArray)

    the index array (vertex indices for each triangle)

Returns:

  • (Integer)


251
252
253
254
255
# File 'lib/gr3.rb', line 251

def createindexedmesh(num_vertices, vertices, normals, colors, num_indices, indices)
  inquiry_int do |mesh|
    super(mesh, num_vertices, vertices, normals, colors, num_indices, indices)
  end
end

.createindexedmesh_nocopy(num_vertices, vertices, normals, colors, num_indices, indices) ⇒ Integer

This function creates a mesh from vertex position, normal and color data.

Returns:

  • (Integer)


234
235
236
237
238
# File 'lib/gr3.rb', line 234

def createindexedmesh_nocopy(num_vertices, vertices, normals, colors, num_indices, indices)
  inquiry_int do |mesh|
    super(mesh, num_vertices, vertices, normals, colors, num_indices, indices)
  end
end

.createisosurfacemesh(grid, step, offset, isolevel) ⇒ Integer

This function creates an isosurface from voxel data using the marching cubes algorithm. Returns a mesh.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • step (Array)

    voxel sizes in each direction

  • offset (Array)

    coordinate origin in each direction

  • isolevel (Integer)

    isovalue at which the surface will be created

Returns:

  • (Integer)


387
388
389
390
391
392
393
# File 'lib/gr3.rb', line 387

def createisosurfacemesh(grid, step, offset, isolevel)
  args = _preprocess_createslicemesh(grid, step, offset)
  grid = args.shift
  inquiry_int do |mesh|
    super(mesh, uint16(grid), isolevel, *args)
  end
end

.createmesh(n, vertices, normals, colors) ⇒ Integer

This function creates a int from vertex position, normal and color data. Returns a mesh.

Parameters:

  • n (Integer)

    the number of vertices in the mesh

  • vertices (Array, NArray)

    the vertex positions

  • normals (Array, NArray)

    the vertex normals

  • colors (Array, NArray)

    the vertex colors, they should be white (1,1,1) if you want to change the color for each drawn mesh

Returns:

  • (Integer)


226
227
228
229
230
# File 'lib/gr3.rb', line 226

def createmesh(n, vertices, normals, colors)
  inquiry_int do |mesh|
    super(mesh, n, vertices, normals, colors)
  end
end

.createmesh_nocopy(_n, vertices, normals, colors) ⇒ Integer

createmesh_nocopy

Returns:

  • (Integer)


212
213
214
215
216
# File 'lib/gr3.rb', line 212

def createmesh_nocopy(_n, vertices, normals, colors)
  inquiry_int do |mesh|
    super(mesh, vertices, normals, colors)
  end
end

.createslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil) ⇒ Object

Creates meshes for slices through the given data, using the current GR colormap. Use the parameters x, y or z to specify what slices should be drawn and at which positions they should go through the data. If neither x nor y nor z are set, 0.5 will be used for all three. Returns meshes for the yz-slice, the xz-slice and the xy-slice.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • x (Numeric) (defaults to: nil)

    the position of the slice through the xz-plane (0 to 1)

  • y (Numeric) (defaults to: nil)

    the position of the slice through the xz-plane (0 to 1)

  • z (Numeric) (defaults to: nil)

    the position of the slice through the xz-plane (0 to 1)

  • step (Array) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array) (defaults to: nil)

    coordinate origin in each direction



563
564
565
566
567
568
569
570
571
572
573
# File 'lib/gr3.rb', line 563

def createslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil)
  if [x, y, z].all?(&:nil?)
    x = 0.5
    y = 0.5
    z = 0.5
  end
  mesh_x = (createxslicemesh(grid, x, step, offset) if x)
  mesh_y = (createyslicemesh(grid, y, step, offset) if y)
  mesh_z = (createzslicemesh(grid, z, step, offset) if z)
  [mesh_x, mesh_y, mesh_z]
end

.createsurfacemesh(nx, ny, x, y, z, option = 0) ⇒ Integer

Create a mesh of a surface plot similar to gr_surface. Uses the current colormap. To apply changes of the colormap a new mesh has to be created.

Parameters:

  • nx (Integer)

    number of points in x-direction

  • ny (Integer)

    number of points in y-direction

  • x (Array, NArray)

    an array containing the x-coordinates

  • y (Array, NArray)

    an array containing the y-coordinates

  • z (Array, NArray)

    an array of length nx * ny containing the z-coordinates

  • option (Integer) (defaults to: 0)

    option for the surface mesh; the GR3_SURFACE constants can be combined with bitwise or. See the table below.

    • 0 : GR3_SURFACE_DEFAULT

      • default behavior

    • 1 : GR3_SURFACE_NORMALS

      • interpolate the vertex normals from the gradient

    • 2 : GR3_SURFACE_FLAT

      • set all z-coordinates to zero

    • 4 : GR3_SURFACE_GRTRANSFORM

      • use gr_inqwindow, gr_inqspace and gr_inqscale to transform the data to NDC coordinates

    • 8 : GR3_SURFACE_GRCOLOR

      • color the surface according to the current gr colormap

    • 16 : GR3_SURFACE_GRZSHADED

      • like GR3_SURFACE_GRCOLOR, but use the z-value directly as color index

Returns:

  • (Integer)


417
418
419
420
421
# File 'lib/gr3.rb', line 417

def createsurfacemesh(nx, ny, x, y, z, option = 0)
  inquiry_int do |mesh|
    super(mesh, nx, ny, x, y, z, option)
  end
end

.createtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20) ⇒ Integer

Create a mesh object in the shape of a tube following a path given by a list of points. The colors and radii arrays specify the color and radius at each point.

Parameters:

  • n (Integer)

    the number of points given

  • points (Array, NArray)

    the points the tube should go through

  • colors (Array, NArray)

    the color at each point

  • radii (Array, NArray)

    the desired tube radius at each point

  • num_steps (Integer) (defaults to: 10)

    the number of steps between each point, allowing for a more smooth tube

  • num_segments (Integer) (defaults to: 20)

    the number of segments each ring of the tube consists of, e.g. 3 would yield a triangular tube

Returns:

  • (Integer)


484
485
486
487
488
# File 'lib/gr3.rb', line 484

def createtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20)
  inquiry_uint do |mesh| # mesh should be Int?
    super(mesh, n, points, colors, radii, num_steps, num_segments)
  end
end

.createxslicemesh(grid, x = 0.5, step = nil, offset = nil) ⇒ Object

Creates a meshes for a slices through the yz-plane of the given data, using the current GR colormap. Use the x parameter to set the position of the yz-slice. Returns a mesh for the yz-slice.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • x (Numeric) (defaults to: 0.5)

    the position of the slice through the xz-plane (0 to 1)

  • step (Array) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array) (defaults to: nil)

    coordinate origin in each direction



583
584
585
586
587
588
589
590
# File 'lib/gr3.rb', line 583

def createxslicemesh(grid, x = 0.5, step = nil, offset = nil)
  args = _preprocess_createslicemesh(grid, step, offset)
  grid = args.shift
  x = (x.clamp(0, 1) * args[0]).floor
  inquiry_int do |mesh|
    super(mesh, uint16(grid), x, *args)
  end
end

.createyslicemesh(grid, y = 0.5, step = nil, offset = nil) ⇒ Object

Creates a meshes for a slices through the xz-plane of the given data, using the current GR colormap. Use the y parameter to set the position of the xz-slice. Returns a mesh for the xz-slice.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • y (Numeric) (defaults to: 0.5)

    the position of the slice through the xz-plane (0 to 1)

  • step (Array) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array) (defaults to: nil)

    coordinate origin in each direction



600
601
602
603
604
605
606
607
# File 'lib/gr3.rb', line 600

def createyslicemesh(grid, y = 0.5, step = nil, offset = nil)
  args = _preprocess_createslicemesh(grid, step, offset)
  grid = args.shift
  y = (y.clamp(0, 1) * args[1]).floor
  inquiry_int do |mesh|
    super(mesh, uint16(grid), y, *args)
  end
end

.createzslicemesh(grid, z = 0.5, step = nil, offset = nil) ⇒ Object

Creates a meshes for a slices through the xy-plane of the given data, using the current GR colormap. Use the z parameter to set the position of the xy-slice. Returns a mesh for the xy-slice.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • z (Numeric) (defaults to: 0.5)

    the position of the slice through the xz-plane (0 to 1)

  • step (Array) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array) (defaults to: nil)

    coordinate origin in each direction



617
618
619
620
621
622
623
624
# File 'lib/gr3.rb', line 617

def createzslicemesh(grid, z = 0.5, step = nil, offset = nil)
  args = _preprocess_createslicemesh(grid, step, offset)
  grid = args.shift
  z = (z.clamp(0, 1) * args[2]).floor
  inquiry_int do |mesh|
    super(mesh, uint16(grid), z, *args)
  end
end

.deletemeshObject

This function marks a mesh for deletion and removes the user’s reference from the mesh’s referenc counter, so a user must not use the mesh after calling this function.

Parameters:

  • mesh (Integer)

    The mesh that should be marked for deletion



273
274
275
# File 'lib/gr3.rb', line 273

def deletemesh(*)
  super
end

.drawconemeshObject

This function allows drawing a cylinder without requiring a mesh.



333
334
335
# File 'lib/gr3.rb', line 333

def drawconemesh(*)
  super
end

.drawcubemeshObject



347
348
349
# File 'lib/gr3.rb', line 347

def drawcubemesh(*)
  super
end

.drawcylindermeshObject

This function allows drawing a cylinder without requiring a mesh.



338
339
340
# File 'lib/gr3.rb', line 338

def drawcylindermesh(*)
  super
end

.drawheightmapObject



328
329
330
# File 'lib/gr3.rb', line 328

def drawheightmap(*)
  super
end

.drawimageInteger

Returns:

  • (Integer)


206
207
208
# File 'lib/gr3.rb', line 206

def drawimage(*)
  super
end

.drawmeshObject

This function adds a mesh to the draw list, so it will be drawn when the user calls getpixmap. 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.

Parameters:

  • mesh (Integer)

    The mesh to be drawn

  • n (Integer)

    The number of meshes to be drawn

  • positions (Array, NArray)

    The positions where the meshes should be drawn

  • directions (Array, NArray)

    The forward directions the meshes should be facing at

  • ups (Array, NArray)

    The up directions

  • colors (Array, NArray)

    The colors the meshes should be drawn in, it will be multiplied with each vertex color

  • scales (Array, NArray)

    The scaling factors



266
267
268
# File 'lib/gr3.rb', line 266

def drawmesh(*)
  super
end

.drawmesh_grlikeObject

Draw a mesh with the projection of gr. It uses the current projection parameters (rotation, tilt) of gr. This function alters the projection type, the projection parameters, the viewmatrix and the light direction. If necessary, the user has to save them before the call to this function and restore them after the call to gr3_drawimage.

Parameters:

  • mesh (Integer)

    the mesh to be drawn

  • n (Integer)

    the number of meshes to be drawn

  • positions (Array, NArray)

    the positions where the meshes should be drawn

  • directions (Array, NArray)

    the forward directions the meshes should be facing at

  • ups (Array, NArray)

    the up directions

  • colors (Array, NArray)

    the colors the meshes should be drawn in, it will be multiplied with each vertex color

  • scales (Array, NArray)

    the scaling factors



436
437
438
# File 'lib/gr3.rb', line 436

def drawmesh_grlike(*)
  super
end

.drawmolecule(positions, colors = nil, radii = nil, spins = nil, bond_radius = nil, bond_color = nil, bond_delta = nil, set_camera = true, rotation = 0, tilt = 0) ⇒ Object

drawmolecule



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/gr3.rb', line 500

def drawmolecule(positions, colors = nil, radii = nil, spins = nil,
                 bond_radius = nil, bond_color = nil, bond_delta = nil,
                 set_camera = true, rotation = 0, tilt = 0)
  # Should `drawmolecule` take keyword arguments?
  # Setting default values later for now.

  # Should it be RubyArray instead of Narray?
  # If NArray is required, add no NArray error.
  positions = Numo::SFloat.cast(positions)
  n = positions.shape[0]

  colors = if colors.nil?
             Numo::SFloat.ones(n, 3)
           else
             Numo::SFloat.cast(colors).reshape(n, 3)
           end

  radii = if radii.nil?
            Numo::SFloat.new(n).fill(0.3)
          else
            Numo::SFloat.cast(radii).reshape(n)
          end

  bond_color ||= [0.8, 0.8, 0.8]
  bond_color = Numo::SFloat.cast(bond_color).reshape(3)
  bond_delta ||= 1.0
  bond_radius ||= 0.1

  if set_camera
    deg2rad = ->(degree) { degree * Math::PI / 180 } # room for improvement
    cx, cy, cz = *positions.mean(axis: 0)
    dx, dy, dz = *positions.ptp(axis: 0)
    d = [dx, dy].max / 2 / 0.4142 + 3
    r = dz / 2 + d
    rx = r * Math.sin(deg2rad.call(tilt)) * Math.sin(deg2rad.call(rotation))
    ry = r * Math.sin(deg2rad.call(tilt)) * Math.cos(deg2rad.call(rotation))
    rz = r * Math.cos(deg2rad.call(tilt))
    ux = Math.sin(deg2rad.call(tilt + 90)) * Math.sin(deg2rad.call(rotation))
    uy = Math.sin(deg2rad.call(tilt + 90)) * Math.cos(deg2rad.call(rotation))
    uz = Math.cos(deg2rad.call(tilt + 90))
    cameralookat(cx + rx, cy + ry, cz + rz, cx, cy, cz, ux, uy, uz)
    setcameraprojectionparameters(45, d - radii.max - 3, d + dz + radii.max + 3)
  end

  super(n, positions, colors, radii, bond_radius, bond_color, bond_delta)

  if spins
    spins = Numo::SFloat.cast(spins).reshape(n, 3)
    drawspins(positions, spins, colors)
  end
end

.drawslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) ⇒ Object

raw slices through the given data, using the current GR colormap. Use the parameters x, y or z to specify what slices should be drawn and at which positions they should go through the data. If neither x nor y nor z are set, 0.5 will be used for all three.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • x (Numeric) (defaults to: nil)

    the position of the slice through the yz-plane (0 to 1)

  • y (Numeric) (defaults to: nil)

    the position of the slice through the xz-plane (0 to 1)

  • z (Numeric) (defaults to: nil)

    the position of the slice through the xy-plane (0 to 1)

  • step (Array) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array) (defaults to: nil)

    coordinate origin in each direction

  • position (Array) (defaults to: [0, 0, 0])

    the positions where the meshes should be drawn

  • direction (Array) (defaults to: [0, 0, 1])

    the forward directions the meshes should be facing at

  • up (Array) (defaults to: [0, 1, 0])

    the up directions

  • color (Array) (defaults to: [1, 1, 1])

    the colors the meshes should be drawn in, it will be multiplied with each vertex color

  • scale (Array) (defaults to: [1, 1, 1])

    the scaling factors



695
696
697
698
699
700
701
702
703
704
705
# File 'lib/gr3.rb', line 695

def drawslicemeshes(grid, x = nil, y = nil, z = nil, step = nil,
                    offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
                    color = [1, 1, 1], scale = [1, 1, 1])
  meshes = createslicemeshes(grid, x, y, z, step, offset)
  meshes.each do |mesh|
    if mesh
      drawmesh(mesh, 1, position, direction, up, color, scale)
      deletemesh(mesh)
    end
  end
end

.drawspheremeshObject

This function allows drawing a sphere without requiring a mesh.



343
344
345
# File 'lib/gr3.rb', line 343

def drawspheremesh(*)
  super
end

.drawspins(positions, directions, colors = nil, cone_radius = 0.4, cylinder_radius = 0.2, cone_height = 1.0, cylinder_height = 1.0) ⇒ Object

drawspins



491
492
493
494
495
496
497
# File 'lib/gr3.rb', line 491

def drawspins(positions, directions, colors = nil,
              cone_radius = 0.4, cylinder_radius = 0.2,
              cone_height = 1.0, cylinder_height = 1.0)
  n = positions.length
  colors = [1] * n * 3 if colors.nil?
  super(n, positions, directions, colors, cone_radius, cylinder_radius, cone_height, cylinder_height)
end

.drawsurfaceObject

Convenience function for drawing a surfacemesh.

Parameters:

  • mesh (Integer)

    the mesh to be drawn



442
443
444
# File 'lib/gr3.rb', line 442

def drawsurface(*)
  super
end

.drawtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20) ⇒ Integer

drawtubemesh Draw a tube following a path given by a list of points. The colors and radii arrays specify the color and radius at each point.

Parameters:

  • n (Integer)

    the number of points given

  • points (Array, NArray)

    the points the tube should go through

  • colors (Array, NArray)

    the color at each point

  • radii (Array, NArray)

    the desired tube radius at each point

  • num_steps (Integer) (defaults to: 10)

    the number of steps between each point, allowing for a more smooth tube

  • num_segments (Integer) (defaults to: 20)

    the number of segments each ring of the tube consists of, e.g. 3 would yield a triangular tube

Returns:

  • (Integer)


470
471
472
# File 'lib/gr3.rb', line 470

def drawtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20)
  super(n, points, colors, radii, num_steps, num_segments)
end

.drawxslicemesh(grid, x = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) ⇒ Object

Draw a yz-slice through the given data, using the current GR colormap.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • x (Numeric) (defaults to: 0.5)

    the position of the slice through the yz-plane (0 to 1)

  • step (Array) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array) (defaults to: nil)

    coordinate origin in each direction

  • position (Array) (defaults to: [0, 0, 0])

    the positions where the meshes should be drawn

  • direction (Array) (defaults to: [0, 0, 1])

    the forward directions the meshes should be facing at

  • up (Array) (defaults to: [0, 1, 0])

    the up directions

  • color (Array) (defaults to: [1, 1, 1])

    the colors the meshes should be drawn in, it will be multiplied with each vertex color

  • scale (Array) (defaults to: [1, 1, 1])

    the scaling factors



636
637
638
639
640
641
642
# File 'lib/gr3.rb', line 636

def drawxslicemesh(grid, x = 0.5, step = nil, offset = nil,
                   position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
                   color = [1, 1, 1], scale = [1, 1, 1])
  mesh = createxslicemesh(grid, x, step, offset)
  drawmesh(mesh, 1, position, direction, up, color, scale)
  deletemesh(mesh)
end

.drawyslicemesh(grid, y = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) ⇒ Object

Draw a xz-slice through the given data, using the current GR colormap.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • y (Numeric) (defaults to: 0.5)

    the position of the slice through the xz-plane (0 to 1)

  • step (Array) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array) (defaults to: nil)

    coordinate origin in each direction

  • position (Array) (defaults to: [0, 0, 0])

    the positions where the meshes should be drawn

  • direction (Array) (defaults to: [0, 0, 1])

    the forward directions the meshes should be facing at

  • up (Array) (defaults to: [0, 1, 0])

    the up directions

  • color (Array) (defaults to: [1, 1, 1])

    the colors the meshes should be drawn in, it will be multiplied with each vertex color

  • scale (Array) (defaults to: [1, 1, 1])

    the scaling factors



654
655
656
657
658
659
660
# File 'lib/gr3.rb', line 654

def drawyslicemesh(grid, y = 0.5, step = nil, offset = nil,
                   position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
                   color = [1, 1, 1], scale = [1, 1, 1])
  mesh = createyslicemesh(grid, y, step, offset)
  drawmesh(mesh, 1, position, direction, up, color, scale)
  deletemesh(mesh)
end

.drawzslicemesh(grid, z = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) ⇒ Object

Draw a xy-slice through the given data, using the current GR colormap.

Parameters:

  • grid (NArray)

    3D narray array containing the voxel data

  • z (Numeric) (defaults to: 0.5)

    the position of the slice through the xy-plane (0 to 1)

  • step (Array) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array) (defaults to: nil)

    coordinate origin in each direction

  • position (Array) (defaults to: [0, 0, 0])

    the positions where the meshes should be drawn

  • direction (Array) (defaults to: [0, 0, 1])

    the forward directions the meshes should be facing at

  • up (Array) (defaults to: [0, 1, 0])

    the up directions

  • color (Array) (defaults to: [1, 1, 1])

    the colors the meshes should be drawn in, it will be multiplied with each vertex color

  • scale (Array) (defaults to: [1, 1, 1])

    the scaling factors



672
673
674
675
676
677
678
# File 'lib/gr3.rb', line 672

def drawzslicemesh(grid, z = 0.5, step = nil, offset = nil,
                   position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0],
                   color = [1, 1, 1], scale = [1, 1, 1])
  mesh = createzslicemesh(grid, z, step, offset)
  drawmesh(mesh, 1, position, direction, up, color, scale)
  deletemesh(mesh)
end

.exportInteger

Returns:

  • (Integer)


201
202
203
# File 'lib/gr3.rb', line 201

def export(*)
  super
end

.freeObject



136
137
138
# File 'lib/gr3.rb', line 136

def free(*)
  super
end

.getcameraprojectionparametersInteger

Get the projection parameters.

Returns:

  • (Integer)


305
306
307
# File 'lib/gr3.rb', line 305

def getcameraprojectionparameters(*)
  super
end

.geterrorInteger

Note:

This method is defined in the CheckError module.

This function returns information on the most recent GR3 error.

Returns:

  • (Integer)


# File 'lib/gr3.rb', line 145


.geterrorstringString

This function returns a string representation of a given error code.

Returns:

  • (String)


163
164
165
# File 'lib/gr3.rb', line 163

def geterrorstring(*)
  super.to_s
end

.getimage(width, height, use_alpha = true) ⇒ Integer

Returns:

  • (Integer)


193
194
195
196
197
198
# File 'lib/gr3.rb', line 193

def getimage(width, height, use_alpha = true)
  bpp = use_alpha ? 4 : 3
  inquiry(uint8: width * height * bpp) do |bitmap|
    super(width, height, (use_alpha ? 1 : 0), bitmap)
  end
end

.getprojectiontypeInteger

the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL

Returns:

  • (Integer)


370
371
372
# File 'lib/gr3.rb', line 370

def getprojectiontype(*)
  super
end

.getrenderpathstringString

This function allows the user to find out how his commands are rendered. If gr3 is initialized, a string in the format: ‘“gr3 - ” + window toolkit + “ - ” + framebuffer extension + “ - ” + OpenGL version + “ - ” + OpenGL renderer string`. For example `“gr3 - GLX - GL_ARB_framebuffer_object - 2.1 Mesa 7.10.2 - Software Rasterizer”` might be returned on a Linux system (using GLX) with an available GL_ARB_framebuffer_object implementation. If gr3 is not initialized `“Not initialized”` is returned.

Returns:

  • (String)


157
158
159
# File 'lib/gr3.rb', line 157

def getrenderpathstring(*)
  super.to_s
end

.getviewmatrixObject



360
361
362
# File 'lib/gr3.rb', line 360

def getviewmatrix(*)
  super
end

.gr3_initInteger

This method initializes the gr3 context.

Returns:

  • (Integer)


132
133
134
# File 'lib/gr3.rb', line 132

def gr3_init(*)
  super
end

.selectidInteger

Returns:

  • (Integer)


356
357
358
# File 'lib/gr3.rb', line 356

def selectid(*)
  super
end

.setbackgroundcolorObject

This function sets the background color.



319
320
321
# File 'lib/gr3.rb', line 319

def setbackgroundcolor(*)
  super
end

.setcameraprojectionparametersInteger

This function sets the projection parameters. This function takes effect when the next image is created.

Parameters:

  • vertical_field_of_view (Numeric)

    This parameter is the vertical field of view in degrees. It must be greater than 0 and less than 180.

  • zNear (Numeric)

    The distance to the near clipping plane.

  • zFar (Numeric)

    The distance to the far clipping plane.

Returns:

  • (Integer)


299
300
301
# File 'lib/gr3.rb', line 299

def setcameraprojectionparameters(*)
  super
end

.setlightdirectionObject

This function sets the direction of light. If it is called with (0, 0, 0), the light is always pointing into the same direction as the camera.

Parameters:

  • x (Numeric)

    The x-component of the light’s direction

  • y (Numeric)

    The y-component of the light’s direction

  • z (Numeric)

    The z-component of the light’s direction



314
315
316
# File 'lib/gr3.rb', line 314

def setlightdirection(*)
  super
end

.setobjectidObject



351
352
353
# File 'lib/gr3.rb', line 351

def setobjectid(*)
  super
end

.setprojectiontypeObject

Parameters:

  • type (Integer)

    the new projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL



375
376
377
# File 'lib/gr3.rb', line 375

def setprojectiontype(*)
  super
end

.setqualityInteger

Set rendering quality

Parameters:

  • quality

    The quality to set

Returns:

  • (Integer)


188
189
190
# File 'lib/gr3.rb', line 188

def setquality(*)
  super
end

.setviewmatrixObject



364
365
366
# File 'lib/gr3.rb', line 364

def setviewmatrix(*)
  super
end

.surface(x, y, z, option) ⇒ Object

Create a surface plot with gr3 and draw it with gks as cellarray.

Parameters:

  • x (Array, NArray)

    an array containing the x-coordinates

  • y (Array, NArray)

    an array containing the y-coordinates

  • z (Array, NArray)

    an array of length nx * ny containing the z-coordinates

  • option (Integer)

    see the option parameter of gr_surface. OPTION_COLORED_MESH and OPTION_Z_SHADED_MESH are supported.



452
453
454
455
456
457
# File 'lib/gr3.rb', line 452

def surface(x, y, z, option)
  nx = x.length
  ny = y.length
  # TODO: Check out_of_bounds
  super(nx, ny, x, y, z, option)
end

.terminateObject

This function terminates the gr3 context.



141
142
143
# File 'lib/gr3.rb', line 141

def terminate(*)
  super
end

.usecurrentframebufferObject

Use the currently bound framebuffer as the framebuffer used for drawing to OpenGL (using gr3.drawimage). This function is only needed when you do not want to render to 0, the default framebuffer.



175
176
177
# File 'lib/gr3.rb', line 175

def usecurrentframebuffer(*)
  super
end

.useframebufferObject

Set the framebuffer used for drawing to OpenGL (using gr3.drawimage). This function is only needed when you do not want to render to 0, the default framebuffer.



181
182
183
# File 'lib/gr3.rb', line 181

def useframebuffer(*)
  super
end

.volume(data, algorithm) ⇒ Object



707
708
709
710
711
712
713
714
715
# File 'lib/gr3.rb', line 707

def volume(data, algorithm)
  data = Numo::DFloat.cast(data) if data.is_a? Array
  inquiry i[double double] do |dmin, dmax|
    dmin.write_double(-1)
    dmax.write_double(-1)
    nx, ny, nz = data.shape
    super(nx, ny, nz, data, algorithm, dmin, dmax)
  end
end