Module: GR3
- Extended by:
- CheckError, GRCommons::GRCommonUtils, GRCommons::SearchSharedLibrary
- 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.
-
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.
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
-
.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
createmesh_nocopy.
-
.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 referenc 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
drawtubemesh 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::SearchSharedLibrary
recursive_search, search_shared_library
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.
60 61 62 |
# File 'lib/gr3.rb', line 60 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.
281 282 283 |
# File 'lib/gr3.rb', line 281 def cameralookat(*) super end |
.clear ⇒ Integer
This function clears the draw list.
162 163 164 |
# File 'lib/gr3.rb', line 162 def clear(*) super end |
.createheightmapmesh ⇒ Integer
317 318 319 |
# File 'lib/gr3.rb', line 317 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.
244 245 246 247 248 |
# File 'lib/gr3.rb', line 244 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.
227 228 229 230 231 |
# File 'lib/gr3.rb', line 227 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.
380 381 382 383 384 385 386 |
# File 'lib/gr3.rb', line 380 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.
219 220 221 222 223 |
# File 'lib/gr3.rb', line 219 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
205 206 207 208 209 |
# File 'lib/gr3.rb', line 205 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.
556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/gr3.rb', line 556 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.
410 411 412 413 414 |
# File 'lib/gr3.rb', line 410 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.
477 478 479 480 481 |
# File 'lib/gr3.rb', line 477 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.
576 577 578 579 580 581 582 583 |
# File 'lib/gr3.rb', line 576 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.
593 594 595 596 597 598 599 600 |
# File 'lib/gr3.rb', line 593 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.
610 611 612 613 614 615 616 617 |
# File 'lib/gr3.rb', line 610 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 referenc counter, so a user must not use the mesh after calling this function.
266 267 268 |
# File 'lib/gr3.rb', line 266 def deletemesh(*) super end |
.drawconemesh ⇒ Object
This function allows drawing a cylinder without requiring a mesh.
326 327 328 |
# File 'lib/gr3.rb', line 326 def drawconemesh(*) super end |
.drawcubemesh ⇒ Object
340 341 342 |
# File 'lib/gr3.rb', line 340 def drawcubemesh(*) super end |
.drawcylindermesh ⇒ Object
This function allows drawing a cylinder without requiring a mesh.
331 332 333 |
# File 'lib/gr3.rb', line 331 def drawcylindermesh(*) super end |
.drawheightmap ⇒ Object
321 322 323 |
# File 'lib/gr3.rb', line 321 def drawheightmap(*) super end |
.drawimage ⇒ Integer
199 200 201 |
# File 'lib/gr3.rb', line 199 def drawimage(*) super end |
.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.
259 260 261 |
# File 'lib/gr3.rb', line 259 def drawmesh(*) super end |
.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.
429 430 431 |
# File 'lib/gr3.rb', line 429 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
493 494 495 496 497 498 499 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 |
# File 'lib/gr3.rb', line 493 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.
688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/gr3.rb', line 688 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.
336 337 338 |
# File 'lib/gr3.rb', line 336 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
484 485 486 487 488 489 490 |
# File 'lib/gr3.rb', line 484 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.
435 436 437 |
# File 'lib/gr3.rb', line 435 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.
463 464 465 |
# File 'lib/gr3.rb', line 463 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.
629 630 631 632 633 634 635 |
# File 'lib/gr3.rb', line 629 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.
647 648 649 650 651 652 653 |
# File 'lib/gr3.rb', line 647 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.
665 666 667 668 669 670 671 |
# File 'lib/gr3.rb', line 665 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
194 195 196 |
# File 'lib/gr3.rb', line 194 def export(*) super end |
.free ⇒ Object
129 130 131 |
# File 'lib/gr3.rb', line 129 def free(*) super end |
.getcameraprojectionparameters ⇒ Integer
Get the projection parameters.
298 299 300 |
# File 'lib/gr3.rb', line 298 def getcameraprojectionparameters(*) super end |
.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 138
|
.geterrorstring ⇒ String
This function returns a string representation of a given error code.
156 157 158 |
# File 'lib/gr3.rb', line 156 def geterrorstring(*) super.to_s end |
.getimage(width, height, use_alpha = true) ⇒ Integer
186 187 188 189 190 191 |
# File 'lib/gr3.rb', line 186 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
the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL
363 364 365 |
# File 'lib/gr3.rb', line 363 def getprojectiontype(*) super end |
.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.
150 151 152 |
# File 'lib/gr3.rb', line 150 def getrenderpathstring(*) super.to_s end |
.getviewmatrix ⇒ Object
353 354 355 |
# File 'lib/gr3.rb', line 353 def getviewmatrix(*) super end |
.gr3_init ⇒ Integer
This method initializes the gr3 context.
125 126 127 |
# File 'lib/gr3.rb', line 125 def gr3_init(*) super end |
.selectid ⇒ Integer
349 350 351 |
# File 'lib/gr3.rb', line 349 def selectid(*) super end |
.setbackgroundcolor ⇒ Object
This function sets the background color.
312 313 314 |
# File 'lib/gr3.rb', line 312 def setbackgroundcolor(*) super end |
.setcameraprojectionparameters ⇒ Integer
This function sets the projection parameters. This function takes effect when the next image is created.
292 293 294 |
# File 'lib/gr3.rb', line 292 def setcameraprojectionparameters(*) super end |
.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.
307 308 309 |
# File 'lib/gr3.rb', line 307 def setlightdirection(*) super end |
.setobjectid ⇒ Object
344 345 346 |
# File 'lib/gr3.rb', line 344 def setobjectid(*) super end |
.setprojectiontype ⇒ Object
368 369 370 |
# File 'lib/gr3.rb', line 368 def setprojectiontype(*) super end |
.setquality ⇒ Integer
Set rendering quality
181 182 183 |
# File 'lib/gr3.rb', line 181 def setquality(*) super end |
.setviewmatrix ⇒ Object
357 358 359 |
# File 'lib/gr3.rb', line 357 def setviewmatrix(*) super end |
.surface(x, y, z, option) ⇒ Object
Create a surface plot with gr3 and draw it with gks as cellarray.
445 446 447 448 449 450 |
# File 'lib/gr3.rb', line 445 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.
134 135 136 |
# File 'lib/gr3.rb', line 134 def terminate(*) super end |
.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.
168 169 170 |
# File 'lib/gr3.rb', line 168 def usecurrentframebuffer(*) super end |
.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.
174 175 176 |
# File 'lib/gr3.rb', line 174 def useframebuffer(*) super end |
.volume(data, algorithm) ⇒ Object
700 701 702 703 704 705 706 707 708 |
# File 'lib/gr3.rb', line 700 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 |