Module: GR3
- Extended by:
- CheckError, GRCommons::GRCommonUtils
- Defined in:
- lib/gr3.rb,
lib/gr3/ffi.rb,
lib/gr3/gr3base.rb,
lib/gr3/version.rb
Overview
OverView of GR.rb
+--------------------+ +--------------------+
| GR module | | GR3 module |
| +----------------+ | | +----------------+ |
| | GR::FFI | | | | GR3::FFI | |
| | + libGR.so | | | | + libGR3.so | |
| +----------------+ | | +----------------+ |
| | define_method | | | define_method |
| +----------------+ | | +----------------+ |
| | | GR::GRBase | | | | | GR3::GR3Base | |
| | v (Pri^ate) | | | | v (Pri^ate) | |
| +++--------------+ | | +++--------------+ |
| | Extend | | | Extend |
| v | | v +-------+ |
| +-----------+ | | | Check | |
| | GR::Plot | | | <--+ Error | |
| +-----------+ | | +-------+ |
+--------------------+ +----------+---------+
^ ^
| +------------------+ |
Extend | | GRCommons module | | Extend
| | +--------------+ | |
| | | Fiddley | | |
| | +--------------+ | |
| | +--------------+ | |
+----+ CommonUtils +----+
| | +--------------+ | |
| | +--------------+ | |
+----+ Version +----+
| | +--------------+ |
| | +--------------+ |
+----+JupyterSupport| |
| +--------------+ |
+------------------+
(You can edit the above AA diagram with asciiflow.com/)
Fiddley is Ruby-FFI compatible API layer for Fiddle.
Why not GR::GR3?
-
kojix2 did not want to force gr3 to be loaded when gr is loaded.
-
kojix2 did not want to write ‘GR3 = GR::GR3` or something.
-
This is a opinion of kojix2 and may be changed by future maintainers.
GR3 uses Numo::Narrray.
-
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::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.
288 289 290 |
# File 'lib/gr3.rb', line 288 def cameralookat(*) super end |
.clear ⇒ Integer
This function clears the draw list.
169 170 171 |
# File 'lib/gr3.rb', line 169 def clear(*) super end |
.createheightmapmesh ⇒ Integer
324 325 326 |
# File 'lib/gr3.rb', line 324 def createheightmapmesh(*) super end |
.createindexedmesh(num_vertices, vertices, normals, colors, num_indices, indices) ⇒ Integer
This function creates an indexed mesh from vertex information (position, normal and color) and triangle information (indices). Returns a mesh.
251 252 253 254 255 |
# File 'lib/gr3.rb', line 251 def createindexedmesh(num_vertices, vertices, normals, colors, num_indices, indices) inquiry_int do |mesh| super(mesh, num_vertices, vertices, normals, colors, num_indices, indices) end end |
.createindexedmesh_nocopy(num_vertices, vertices, normals, colors, num_indices, indices) ⇒ Integer
This function creates a mesh from vertex position, normal and color data.
234 235 236 237 238 |
# File 'lib/gr3.rb', line 234 def createindexedmesh_nocopy(num_vertices, vertices, normals, colors, num_indices, indices) inquiry_int do |mesh| super(mesh, num_vertices, vertices, normals, colors, num_indices, indices) end end |
.createisosurfacemesh(grid, step, offset, isolevel) ⇒ Integer
This function creates an isosurface from voxel data using the marching cubes algorithm. Returns a mesh.
387 388 389 390 391 392 393 |
# File 'lib/gr3.rb', line 387 def createisosurfacemesh(grid, step, offset, isolevel) args = _preprocess_createslicemesh(grid, step, offset) grid = args.shift inquiry_int do |mesh| super(mesh, uint16(grid), isolevel, *args) end end |
.createmesh(n, vertices, normals, colors) ⇒ Integer
This function creates a int from vertex position, normal and color data. Returns a mesh.
226 227 228 229 230 |
# File 'lib/gr3.rb', line 226 def createmesh(n, vertices, normals, colors) inquiry_int do |mesh| super(mesh, n, vertices, normals, colors) end end |
.createmesh_nocopy(_n, vertices, normals, colors) ⇒ Integer
createmesh_nocopy
212 213 214 215 216 |
# File 'lib/gr3.rb', line 212 def createmesh_nocopy(_n, vertices, normals, colors) inquiry_int do |mesh| super(mesh, vertices, normals, colors) end end |
.createslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil) ⇒ Object
Creates meshes for slices through the given data, using the current GR colormap. Use the parameters x, y or z to specify what slices should be drawn and at which positions they should go through the data. If neither x nor y nor z are set, 0.5 will be used for all three. Returns meshes for the yz-slice, the xz-slice and the xy-slice.
563 564 565 566 567 568 569 570 571 572 573 |
# File 'lib/gr3.rb', line 563 def createslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil) if [x, y, z].all?(&:nil?) x = 0.5 y = 0.5 z = 0.5 end mesh_x = (createxslicemesh(grid, x, step, offset) if x) mesh_y = (createyslicemesh(grid, y, step, offset) if y) mesh_z = (createzslicemesh(grid, z, step, offset) if z) [mesh_x, mesh_y, mesh_z] end |
.createsurfacemesh(nx, ny, x, y, z, option = 0) ⇒ Integer
Create a mesh of a surface plot similar to gr_surface. Uses the current colormap. To apply changes of the colormap a new mesh has to be created.
417 418 419 420 421 |
# File 'lib/gr3.rb', line 417 def createsurfacemesh(nx, ny, x, y, z, option = 0) inquiry_int do |mesh| super(mesh, nx, ny, x, y, z, option) end end |
.createtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20) ⇒ Integer
Create a mesh object in the shape of a tube following a path given by a list of points. The colors and radii arrays specify the color and radius at each point.
484 485 486 487 488 |
# File 'lib/gr3.rb', line 484 def createtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20) inquiry_uint do |mesh| # mesh should be Int? super(mesh, n, points, colors, radii, num_steps, num_segments) end end |
.createxslicemesh(grid, x = 0.5, step = nil, offset = nil) ⇒ Object
Creates a meshes for a slices through the yz-plane of the given data, using the current GR colormap. Use the x parameter to set the position of the yz-slice. Returns a mesh for the yz-slice.
583 584 585 586 587 588 589 590 |
# File 'lib/gr3.rb', line 583 def createxslicemesh(grid, x = 0.5, step = nil, offset = nil) args = _preprocess_createslicemesh(grid, step, offset) grid = args.shift x = (x.clamp(0, 1) * args[0]).floor inquiry_int do |mesh| super(mesh, uint16(grid), x, *args) end end |
.createyslicemesh(grid, y = 0.5, step = nil, offset = nil) ⇒ Object
Creates a meshes for a slices through the xz-plane of the given data, using the current GR colormap. Use the y parameter to set the position of the xz-slice. Returns a mesh for the xz-slice.
600 601 602 603 604 605 606 607 |
# File 'lib/gr3.rb', line 600 def createyslicemesh(grid, y = 0.5, step = nil, offset = nil) args = _preprocess_createslicemesh(grid, step, offset) grid = args.shift y = (y.clamp(0, 1) * args[1]).floor inquiry_int do |mesh| super(mesh, uint16(grid), y, *args) end end |
.createzslicemesh(grid, z = 0.5, step = nil, offset = nil) ⇒ Object
Creates a meshes for a slices through the xy-plane of the given data, using the current GR colormap. Use the z parameter to set the position of the xy-slice. Returns a mesh for the xy-slice.
617 618 619 620 621 622 623 624 |
# File 'lib/gr3.rb', line 617 def createzslicemesh(grid, z = 0.5, step = nil, offset = nil) args = _preprocess_createslicemesh(grid, step, offset) grid = args.shift z = (z.clamp(0, 1) * args[2]).floor inquiry_int do |mesh| super(mesh, uint16(grid), z, *args) end end |
.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.
273 274 275 |
# File 'lib/gr3.rb', line 273 def deletemesh(*) super end |
.drawconemesh ⇒ Object
This function allows drawing a cylinder without requiring a mesh.
333 334 335 |
# File 'lib/gr3.rb', line 333 def drawconemesh(*) super end |
.drawcubemesh ⇒ Object
347 348 349 |
# File 'lib/gr3.rb', line 347 def drawcubemesh(*) super end |
.drawcylindermesh ⇒ Object
This function allows drawing a cylinder without requiring a mesh.
338 339 340 |
# File 'lib/gr3.rb', line 338 def drawcylindermesh(*) super end |
.drawheightmap ⇒ Object
328 329 330 |
# File 'lib/gr3.rb', line 328 def drawheightmap(*) super end |
.drawimage ⇒ Integer
206 207 208 |
# File 'lib/gr3.rb', line 206 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.
266 267 268 |
# File 'lib/gr3.rb', line 266 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.
436 437 438 |
# File 'lib/gr3.rb', line 436 def drawmesh_grlike(*) super end |
.drawmolecule(positions, colors = nil, radii = nil, spins = nil, bond_radius = nil, bond_color = nil, bond_delta = nil, set_camera = true, rotation = 0, tilt = 0) ⇒ Object
drawmolecule
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/gr3.rb', line 500 def drawmolecule(positions, colors = nil, radii = nil, spins = nil, bond_radius = nil, bond_color = nil, bond_delta = nil, set_camera = true, rotation = 0, tilt = 0) # Should `drawmolecule` take keyword arguments? # Setting default values later for now. # Should it be RubyArray instead of Narray? # If NArray is required, add no NArray error. positions = Numo::SFloat.cast(positions) n = positions.shape[0] colors = if colors.nil? Numo::SFloat.ones(n, 3) else Numo::SFloat.cast(colors).reshape(n, 3) end radii = if radii.nil? Numo::SFloat.new(n).fill(0.3) else Numo::SFloat.cast(radii).reshape(n) end bond_color ||= [0.8, 0.8, 0.8] bond_color = Numo::SFloat.cast(bond_color).reshape(3) bond_delta ||= 1.0 bond_radius ||= 0.1 if set_camera deg2rad = ->(degree) { degree * Math::PI / 180 } # room for improvement cx, cy, cz = *positions.mean(axis: 0) dx, dy, dz = *positions.ptp(axis: 0) d = [dx, dy].max / 2 / 0.4142 + 3 r = dz / 2 + d rx = r * Math.sin(deg2rad.call(tilt)) * Math.sin(deg2rad.call(rotation)) ry = r * Math.sin(deg2rad.call(tilt)) * Math.cos(deg2rad.call(rotation)) rz = r * Math.cos(deg2rad.call(tilt)) ux = Math.sin(deg2rad.call(tilt + 90)) * Math.sin(deg2rad.call(rotation)) uy = Math.sin(deg2rad.call(tilt + 90)) * Math.cos(deg2rad.call(rotation)) uz = Math.cos(deg2rad.call(tilt + 90)) cameralookat(cx + rx, cy + ry, cz + rz, cx, cy, cz, ux, uy, uz) setcameraprojectionparameters(45, d - radii.max - 3, d + dz + radii.max + 3) end super(n, positions, colors, radii, bond_radius, bond_color, bond_delta) if spins spins = Numo::SFloat.cast(spins).reshape(n, 3) drawspins(positions, spins, colors) end end |
.drawslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) ⇒ Object
raw slices through the given data, using the current GR colormap. Use the parameters x, y or z to specify what slices should be drawn and at which positions they should go through the data. If neither x nor y nor z are set, 0.5 will be used for all three.
695 696 697 698 699 700 701 702 703 704 705 |
# File 'lib/gr3.rb', line 695 def drawslicemeshes(grid, x = nil, y = nil, z = nil, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) meshes = createslicemeshes(grid, x, y, z, step, offset) meshes.each do |mesh| if mesh drawmesh(mesh, 1, position, direction, up, color, scale) deletemesh(mesh) end end end |
.drawspheremesh ⇒ Object
This function allows drawing a sphere without requiring a mesh.
343 344 345 |
# File 'lib/gr3.rb', line 343 def drawspheremesh(*) super end |
.drawspins(positions, directions, colors = nil, cone_radius = 0.4, cylinder_radius = 0.2, cone_height = 1.0, cylinder_height = 1.0) ⇒ Object
drawspins
491 492 493 494 495 496 497 |
# File 'lib/gr3.rb', line 491 def drawspins(positions, directions, colors = nil, cone_radius = 0.4, cylinder_radius = 0.2, cone_height = 1.0, cylinder_height = 1.0) n = positions.length colors = [1] * n * 3 if colors.nil? super(n, positions, directions, colors, cone_radius, cylinder_radius, cone_height, cylinder_height) end |
.drawsurface ⇒ Object
Convenience function for drawing a surfacemesh.
442 443 444 |
# File 'lib/gr3.rb', line 442 def drawsurface(*) super end |
.drawtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20) ⇒ Integer
drawtubemesh Draw a tube following a path given by a list of points. The colors and radii arrays specify the color and radius at each point.
470 471 472 |
# File 'lib/gr3.rb', line 470 def drawtubemesh(n, points, colors, radii, num_steps = 10, num_segments = 20) super(n, points, colors, radii, num_steps, num_segments) end |
.drawxslicemesh(grid, x = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) ⇒ Object
Draw a yz-slice through the given data, using the current GR colormap.
636 637 638 639 640 641 642 |
# File 'lib/gr3.rb', line 636 def drawxslicemesh(grid, x = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) mesh = createxslicemesh(grid, x, step, offset) drawmesh(mesh, 1, position, direction, up, color, scale) deletemesh(mesh) end |
.drawyslicemesh(grid, y = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) ⇒ Object
Draw a xz-slice through the given data, using the current GR colormap.
654 655 656 657 658 659 660 |
# File 'lib/gr3.rb', line 654 def drawyslicemesh(grid, y = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) mesh = createyslicemesh(grid, y, step, offset) drawmesh(mesh, 1, position, direction, up, color, scale) deletemesh(mesh) end |
.drawzslicemesh(grid, z = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) ⇒ Object
Draw a xy-slice through the given data, using the current GR colormap.
672 673 674 675 676 677 678 |
# File 'lib/gr3.rb', line 672 def drawzslicemesh(grid, z = 0.5, step = nil, offset = nil, position = [0, 0, 0], direction = [0, 0, 1], up = [0, 1, 0], color = [1, 1, 1], scale = [1, 1, 1]) mesh = createzslicemesh(grid, z, step, offset) drawmesh(mesh, 1, position, direction, up, color, scale) deletemesh(mesh) end |
.export ⇒ Integer
201 202 203 |
# File 'lib/gr3.rb', line 201 def export(*) super end |
.free ⇒ Object
136 137 138 |
# File 'lib/gr3.rb', line 136 def free(*) super end |
.getcameraprojectionparameters ⇒ Integer
Get the projection parameters.
305 306 307 |
# File 'lib/gr3.rb', line 305 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 145
|
.geterrorstring ⇒ String
This function returns a string representation of a given error code.
163 164 165 |
# File 'lib/gr3.rb', line 163 def geterrorstring(*) super.to_s end |
.getimage(width, height, use_alpha = true) ⇒ Integer
193 194 195 196 197 198 |
# File 'lib/gr3.rb', line 193 def getimage(width, height, use_alpha = true) bpp = use_alpha ? 4 : 3 inquiry(uint8: width * height * bpp) do |bitmap| super(width, height, (use_alpha ? 1 : 0), bitmap) end end |
.getprojectiontype ⇒ Integer
the current projection type: GR3_PROJECTION_PERSPECTIVE or GR3_PROJECTION_PARALLEL
370 371 372 |
# File 'lib/gr3.rb', line 370 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.
157 158 159 |
# File 'lib/gr3.rb', line 157 def getrenderpathstring(*) super.to_s end |
.getviewmatrix ⇒ Object
360 361 362 |
# File 'lib/gr3.rb', line 360 def getviewmatrix(*) super end |
.gr3_init ⇒ Integer
This method initializes the gr3 context.
132 133 134 |
# File 'lib/gr3.rb', line 132 def gr3_init(*) super end |
.selectid ⇒ Integer
356 357 358 |
# File 'lib/gr3.rb', line 356 def selectid(*) super end |
.setbackgroundcolor ⇒ Object
This function sets the background color.
319 320 321 |
# File 'lib/gr3.rb', line 319 def setbackgroundcolor(*) super end |
.setcameraprojectionparameters ⇒ Integer
This function sets the projection parameters. This function takes effect when the next image is created.
299 300 301 |
# File 'lib/gr3.rb', line 299 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.
314 315 316 |
# File 'lib/gr3.rb', line 314 def setlightdirection(*) super end |
.setobjectid ⇒ Object
351 352 353 |
# File 'lib/gr3.rb', line 351 def setobjectid(*) super end |
.setprojectiontype ⇒ Object
375 376 377 |
# File 'lib/gr3.rb', line 375 def setprojectiontype(*) super end |
.setquality ⇒ Integer
Set rendering quality
188 189 190 |
# File 'lib/gr3.rb', line 188 def setquality(*) super end |
.setviewmatrix ⇒ Object
364 365 366 |
# File 'lib/gr3.rb', line 364 def setviewmatrix(*) super end |
.surface(x, y, z, option) ⇒ Object
Create a surface plot with gr3 and draw it with gks as cellarray.
452 453 454 455 456 457 |
# File 'lib/gr3.rb', line 452 def surface(x, y, z, option) nx = x.length ny = y.length # TODO: Check out_of_bounds super(nx, ny, x, y, z, option) end |
.terminate ⇒ Object
This function terminates the gr3 context.
141 142 143 |
# File 'lib/gr3.rb', line 141 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.
175 176 177 |
# File 'lib/gr3.rb', line 175 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.
181 182 183 |
# File 'lib/gr3.rb', line 181 def useframebuffer(*) super end |
.volume(data, algorithm) ⇒ Object
707 708 709 710 711 712 713 714 715 |
# File 'lib/gr3.rb', line 707 def volume(data, algorithm) data = Numo::DFloat.cast(data) if data.is_a? Array inquiry i[double double] do |dmin, dmax| dmin.write_double(-1) dmax.write_double(-1) nx, ny, nz = data.shape super(nx, ny, nz, data, algorithm, dmin, dmax) end end |