Module: GR3

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

Overview

Note:

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.

Note:

GR3 uses Numo::Narrray.

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.

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

Defined Under Namespace

Modules: CheckError, FFI Classes: Error, NotFoundError

Constant Summary collapse

IA_END_OF_LIST =

InitAttribute

0
IA_FRAMEBUFFER_WIDTH =
1
IA_FRAMEBUFFER_HEIGHT =
2
IA_NUM_THREADS =
3
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
PROJECTION_PERSPECTIVE =

Projection

0
PROJECTION_PARALLEL =
1
PROJECTION_ORTHOGRAPHIC =
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.



64
65
66
# File 'lib/gr3.rb', line 64

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. This function takes effect when the next image is created. Therefore if you want to take pictures of the same data from different perspectives, you can call and gr3_cameralookat(), gr3_getpixmap_(), gr3_cameralookat(), gr3_getpixmap_(), … without calling gr3_clear() and gr3_drawmesh() again.

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



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

.clearInteger

This function clears the draw list.

Returns:

  • (Integer)


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

.createheightmapmeshInteger

Returns:

  • (Integer)


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

.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)


275
276
277
278
279
# File 'lib/gr3.rb', line 275

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)


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

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, NArray)

    voxel sizes in each direction

  • offset (Array, NArray)

    coordinate origin in each direction

  • isolevel (Integer)

    isovalue at which the surface will be created

Returns:

  • (Integer)


414
415
416
417
418
419
420
# File 'lib/gr3.rb', line 414

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)


243
244
245
246
247
# File 'lib/gr3.rb', line 243

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

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

Returns:

  • (Integer)


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

def createmesh_nocopy(n, vertices, normals, colors)
  inquiry_int do |mesh|
    super(mesh, n, 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, NArray) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array, NArray) (defaults to: nil)

    coordinate origin in each direction



605
606
607
608
609
610
611
612
613
614
615
# File 'lib/gr3.rb', line 605

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)


446
447
448
449
450
# File 'lib/gr3.rb', line 446

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)


524
525
526
527
528
# File 'lib/gr3.rb', line 524

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, NArray) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array, NArray) (defaults to: nil)

    coordinate origin in each direction



626
627
628
629
630
631
632
633
# File 'lib/gr3.rb', line 626

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, NArray) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array, NArray) (defaults to: nil)

    coordinate origin in each direction



645
646
647
648
649
650
651
652
# File 'lib/gr3.rb', line 645

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, NArray) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array, NArray) (defaults to: nil)

    coordinate origin in each direction



664
665
666
667
668
669
670
671
# File 'lib/gr3.rb', line 664

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



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

.drawconemeshObject

This function allows drawing a cylinder without requiring a mesh.



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

.drawcubemeshObject



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

.drawcylindermeshObject

This function allows drawing a cylinder without requiring a mesh.



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

.drawheightmapObject



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

.drawimageInteger

Returns:

  • (Integer)


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

.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.

This function does not return an error code, because of its asynchronous nature. If gr3_getpixmap_() returns a GR3_ERROR_OPENGL_ERR, this might be caused by this function saving unuseable data into the draw list.

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



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

.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



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

.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



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/gr3.rb', line 540

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, NArray) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array, NArray) (defaults to: nil)

    coordinate origin in each direction

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

    the positions where the meshes should be drawn

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

    the forward directions the meshes should be facing at

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

    the up directions

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

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

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

    the scaling factors



754
755
756
757
758
759
760
761
762
763
764
# File 'lib/gr3.rb', line 754

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.



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

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

drawspins



531
532
533
534
535
536
537
# File 'lib/gr3.rb', line 531

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



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

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

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)


505
506
507
# File 'lib/gr3.rb', line 505

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, NArray) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array, NArray) (defaults to: nil)

    coordinate origin in each direction

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

    the positions where the meshes should be drawn

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

    the forward directions the meshes should be facing at

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

    the up directions

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

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

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

    the scaling factors



686
687
688
689
690
691
692
# File 'lib/gr3.rb', line 686

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, NArray) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array, NArray) (defaults to: nil)

    coordinate origin in each direction

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

    the positions where the meshes should be drawn

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

    the forward directions the meshes should be facing at

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

    the up directions

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

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

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

    the scaling factors



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

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, NArray) (defaults to: nil)

    voxel sizes in each direction

  • offset (Array, NArray) (defaults to: nil)

    coordinate origin in each direction

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

    the positions where the meshes should be drawn

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

    the forward directions the meshes should be facing at

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

    the up directions

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

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

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

    the scaling factors



728
729
730
731
732
733
734
# File 'lib/gr3.rb', line 728

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)


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

.freeObject



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

.getcameraprojectionparametersInteger

Get the projection parameters.

Parameters:

  • vfov (Array, NArray)

    Vertical field of view in degrees

  • znear (Array, NArray)

    The distance to the near clipping plane.

  • zfar (Array, NArray)

    The distance to the far clipping plane.

Returns:

  • (Integer)


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

.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 148

.geterrorstringString

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

Returns:

  • (String)


177
178
179
# File 'lib/gr3.rb', line 177

def geterrorstring(*)
  super.to_s
end

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

Returns:

  • (Integer)


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

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

Returns the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL.

Returns:

  • (Integer)

    the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL



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

.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)


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

def getrenderpathstring(*)
  super.to_s
end

.getviewmatrixObject

Parameters:

  • m (Array, NArray)

    the 4x4 column major view matrix



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

.gr3_initInteger

This method initializes the gr3 context.

Returns:

  • (Integer)


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

.selectidInteger

Returns:

  • (Integer)


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

.setbackgroundcolorObject

This function sets the background color.



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

.setcameraprojectionparametersInteger

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

The ratio between zFar and zNear influences the precision of the depth buffer, the greater (zFar/zNear), the more likely are errors. So you should try to keep both values as close to each other as possible while making sure everything you want to be visible, is visible.

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)


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

.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



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

.setobjectidObject



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

.setprojectiontypeObject

Parameters:

  • type (Integer)

    the new projection type: GR3_PROJECTION_PERSPECTIVE, GR3_PROJECTION_PARALLEL or GR3_PROJECTION_ORTHOGRAPHIC



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

.setqualityInteger

Set rendering quality

Parameters:

  • quality

    The quality to set

Returns:

  • (Integer)


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

.setviewmatrixObject

Parameters:

  • m (Array, NArray)

    the 4x4 column major view matrix



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

.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.



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

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.

After calling this function, gr3 is in the same state as when it was first loaded, except for context-independent variables, i.e. the logging callback.



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

.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.



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

.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.



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

.volume(data, algorithm) ⇒ Object



766
767
768
769
770
771
772
773
774
# File 'lib/gr3.rb', line 766

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