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
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.
-
It is difficult to write GR3 modules with only Ruby arrays.
-
Numo::Narray has better performance and is easier to read.
-
Numo::Narray does not work with JRuby.
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
- TRANSPARENCY_OPAQUE =
0
- TRANSPARENCY_TRANSMIT =
1
- TRANSPARENCY_FILTER =
2
- VOLUME_EMISSION =
0
- VOLUME_ABSORPTION =
1
- VOLUME_MIP =
2
- 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
-
.ffi_lib ⇒ Object
Returns the value of attribute ffi_lib.
Class Method Summary collapse
-
.cameralookat ⇒ Object
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.
-
.clear ⇒ Integer
This function clears the draw list.
- .createheightmapmesh ⇒ Integer
-
.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).
-
.createindexedmesh_nocopy(num_vertices, vertices, normals, colors, num_indices, indices) ⇒ Integer
This function creates a mesh from vertex position, normal and color data.
-
.createisosurfacemesh(grid, step, offset, isolevel) ⇒ Integer
This function creates an isosurface from voxel data using the marching cubes algorithm.
-
.createmesh(n, vertices, normals, colors) ⇒ Integer
This function creates a int from vertex position, normal and color data.
-
.createmesh_nocopy(n, vertices, normals, colors) ⇒ Integer
This function creates a mesh from vertex position, normal and color data.
-
.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.
-
.createsurfacemesh(nx, ny, x, y, z, option = 0) ⇒ Integer
Create a mesh of a surface plot similar to gr_surface.
-
.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.
-
.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.
-
.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.
-
.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.
-
.deletemesh ⇒ Object
This function marks a mesh for deletion and removes the user’s reference from the mesh’s reference counter, so a user must not use the mesh after calling this function.
-
.drawconemesh ⇒ Object
This function allows drawing a cylinder without requiring a mesh.
- .drawcubemesh ⇒ Object
-
.drawcylindermesh ⇒ Object
This function allows drawing a cylinder without requiring a mesh.
- .drawheightmap ⇒ Object
- .drawimage ⇒ Integer
-
.drawmesh ⇒ Object
This function adds a mesh to the draw list, so it will be drawn when the user calls getpixmap.
-
.drawmesh_grlike ⇒ Object
Draw a mesh with the projection of gr.
-
.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.
-
.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.
-
.drawspheremesh ⇒ Object
This function allows drawing a sphere without requiring a mesh.
-
.drawspins(positions, directions, colors = nil, cone_radius = 0.4, cylinder_radius = 0.2, cone_height = 1.0, cylinder_height = 1.0) ⇒ Object
drawspins.
-
.drawsurface ⇒ Object
Convenience function for drawing a surfacemesh.
-
.drawtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20) ⇒ Integer
Draw a tube following a path given by a list of points.
-
.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.
-
.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.
-
.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.
- .export ⇒ Integer
- .free ⇒ Object
-
.getcameraprojectionparameters ⇒ Integer
Get the projection parameters.
-
.geterror ⇒ Integer
This function returns information on the most recent GR3 error.
-
.geterrorstring ⇒ String
This function returns a string representation of a given error code.
- .getimage(width, height, use_alpha = true) ⇒ Integer
-
.getprojectiontype ⇒ Integer
The current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL.
-
.getrenderpathstring ⇒ String
This function allows the user to find out how his commands are rendered.
- .getviewmatrix ⇒ Object
-
.gr3_init ⇒ Integer
This method initializes the gr3 context.
- .selectid ⇒ Integer
-
.setbackgroundcolor ⇒ Object
This function sets the background color.
-
.setcameraprojectionparameters ⇒ Integer
This function sets the projection parameters.
-
.setlightdirection ⇒ Object
This function sets the direction of light.
- .setobjectid ⇒ Object
- .setprojectiontype ⇒ Object
-
.setquality ⇒ Integer
Set rendering quality.
- .setviewmatrix ⇒ Object
-
.surface(x, y, z, option) ⇒ Object
Create a surface plot with gr3 and draw it with gks as cellarray.
-
.terminate ⇒ Object
This function terminates the gr3 context.
-
.usecurrentframebuffer ⇒ Object
Use the currently bound framebuffer as the framebuffer used for drawing to OpenGL (using gr3.drawimage).
-
.useframebuffer ⇒ Object
Set the framebuffer used for drawing to OpenGL (using gr3.drawimage).
- .volume(data, algorithm) ⇒ Object
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
Class Attribute Details
.ffi_lib ⇒ Object
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
.cameralookat ⇒ Object
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.
|
# File 'lib/gr3.rb', line 312
|
.clear ⇒ Integer
This function clears the draw list.
|
# File 'lib/gr3.rb', line 185
|
.createheightmapmesh ⇒ Integer
|
# File 'lib/gr3.rb', line 371
|
.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.
279 280 281 282 283 |
# File 'lib/gr3.rb', line 279 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.
256 257 258 259 260 |
# File 'lib/gr3.rb', line 256 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.
418 419 420 421 422 423 424 |
# File 'lib/gr3.rb', line 418 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.
247 248 249 250 251 |
# File 'lib/gr3.rb', line 247 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.
230 231 232 233 234 |
# File 'lib/gr3.rb', line 230 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.
609 610 611 612 613 614 615 616 617 618 619 |
# File 'lib/gr3.rb', line 609 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.
450 451 452 453 454 |
# File 'lib/gr3.rb', line 450 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.
528 529 530 531 532 |
# File 'lib/gr3.rb', line 528 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.
630 631 632 633 634 635 636 637 |
# File 'lib/gr3.rb', line 630 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.
649 650 651 652 653 654 655 656 |
# File 'lib/gr3.rb', line 649 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.
668 669 670 671 672 673 674 675 |
# File 'lib/gr3.rb', line 668 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 |
.deletemesh ⇒ Object
This function marks a mesh for deletion and removes the user’s reference from the mesh’s reference counter, so a user must not use the mesh after calling this function.
|
# File 'lib/gr3.rb', line 304
|
.drawconemesh ⇒ Object
This function allows drawing a cylinder without requiring a mesh.
|
# File 'lib/gr3.rb', line 376
|
.drawcubemesh ⇒ Object
|
# File 'lib/gr3.rb', line 385
|
.drawcylindermesh ⇒ Object
This function allows drawing a cylinder without requiring a mesh.
|
# File 'lib/gr3.rb', line 379
|
.drawheightmap ⇒ Object
|
# File 'lib/gr3.rb', line 374
|
.drawimage ⇒ Integer
|
# File 'lib/gr3.rb', line 224
|
.drawmesh ⇒ Object
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.
|
# File 'lib/gr3.rb', line 285
|
.drawmesh_grlike ⇒ Object
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.
|
# File 'lib/gr3.rb', line 456
|
.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
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 591 592 593 594 |
# File 'lib/gr3.rb', line 544 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) return unless spins spins = Numo::SFloat.cast(spins).reshape(n, 3) drawspins(positions, spins, colors) 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.
758 759 760 761 762 763 764 765 766 767 768 |
# File 'lib/gr3.rb', line 758 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 |
.drawspheremesh ⇒ Object
This function allows drawing a sphere without requiring a mesh.
|
# File 'lib/gr3.rb', line 382
|
.drawspins(positions, directions, colors = nil, cone_radius = 0.4, cylinder_radius = 0.2, cone_height = 1.0, cylinder_height = 1.0) ⇒ Object
drawspins
535 536 537 538 539 540 541 |
# File 'lib/gr3.rb', line 535 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 |
.drawsurface ⇒ Object
Convenience function for drawing a surfacemesh.
|
# File 'lib/gr3.rb', line 474
|
.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.
509 510 511 |
# File 'lib/gr3.rb', line 509 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.
690 691 692 693 694 695 696 |
# File 'lib/gr3.rb', line 690 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.
711 712 713 714 715 716 717 |
# File 'lib/gr3.rb', line 711 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.
732 733 734 735 736 737 738 |
# File 'lib/gr3.rb', line 732 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 |
.export ⇒ Integer
|
# File 'lib/gr3.rb', line 221
|
.free ⇒ Object
|
# File 'lib/gr3.rb', line 143
|
.getcameraprojectionparameters ⇒ Integer
Get the projection parameters.
|
# File 'lib/gr3.rb', line 349
|
.geterror ⇒ Integer
This method is defined in the CheckError module.
This function returns information on the most recent GR3 error.
|
# File 'lib/gr3.rb', line 152
|
.geterrorstring ⇒ String
This function returns a string representation of a given error code.
181 182 183 |
# File 'lib/gr3.rb', line 181 def geterrorstring(*) super.to_s end |
.getimage(width, height, use_alpha = true) ⇒ Integer
214 215 216 217 218 219 |
# File 'lib/gr3.rb', line 214 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 |
.getprojectiontype ⇒ Integer
Returns the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL.
|
# File 'lib/gr3.rb', line 398
|
.getrenderpathstring ⇒ String
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.
173 174 175 |
# File 'lib/gr3.rb', line 173 def getrenderpathstring(*) super.to_s end |
.getviewmatrix ⇒ Object
|
# File 'lib/gr3.rb', line 392
|
.gr3_init ⇒ Integer
This method initializes the gr3 context.
|
# File 'lib/gr3.rb', line 137
|
.selectid ⇒ Integer
|
# File 'lib/gr3.rb', line 389
|
.setbackgroundcolor ⇒ Object
This function sets the background color.
|
# File 'lib/gr3.rb', line 368
|
.setcameraprojectionparameters ⇒ Integer
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.
|
# File 'lib/gr3.rb', line 331
|
.setlightdirection ⇒ Object
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.
|
# File 'lib/gr3.rb', line 359
|
.setobjectid ⇒ Object
|
# File 'lib/gr3.rb', line 387
|
.setprojectiontype ⇒ Object
|
# File 'lib/gr3.rb', line 402
|
.setquality ⇒ Integer
Set rendering quality
|
# File 'lib/gr3.rb', line 205
|
.setviewmatrix ⇒ Object
|
# File 'lib/gr3.rb', line 395
|
.surface(x, y, z, option) ⇒ Object
Create a surface plot with gr3 and draw it with gks as cellarray.
488 489 490 491 492 493 |
# File 'lib/gr3.rb', line 488 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 |
.terminate ⇒ Object
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 145
|
.usecurrentframebuffer ⇒ Object
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 191
|
.useframebuffer ⇒ Object
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 198
|
.volume(data, algorithm) ⇒ Object
770 771 772 773 774 775 776 777 778 |
# File 'lib/gr3.rb', line 770 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 |