ruby-gr 0.0.13 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +24 -0
- data/README.md +58 -7
- data/lib/gr.rb +175 -57
- data/lib/gr/ffi.rb +14 -4
- data/lib/gr/grbase.rb +2 -3
- data/lib/gr/plot.rb +172 -136
- data/lib/gr3.rb +52 -41
- data/lib/gr3/ffi.rb +15 -5
- data/lib/gr3/gr3base.rb +2 -3
- data/lib/gr_commons/define_methods.rb +4 -4
- data/lib/gr_commons/extern.rb +2 -1
- data/lib/gr_commons/fiddley.rb +9 -10
- data/lib/gr_commons/gr_common_utils.rb +53 -27
- data/lib/gr_commons/gr_commons.rb +1 -1
- data/lib/gr_commons/version.rb +1 -1
- metadata +4 -3
data/lib/gr3.rb
CHANGED
@@ -2,43 +2,48 @@
|
|
2
2
|
|
3
3
|
# OverView of GR.rb
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
5
|
+
# +--------------------+ +--------------------+
|
6
|
+
# | GR module | | GR3 module |
|
7
|
+
# | +----------------+ | | +----------------+ |
|
8
|
+
# | | GR::FFI | | | | GR3::FFI | |
|
9
|
+
# | | + libGR.so | | | | + libGR3.so | |
|
10
|
+
# | +----------------+ | | +----------------+ |
|
11
|
+
# | | define_method | | | define_method |
|
12
|
+
# | +----------------+ | | +----------------+ |
|
13
|
+
# | | | GR::GRBase | | | | | GR3::GR3Base | |
|
14
|
+
# | | v (Pri^ate) | | | | v (Pri^ate) | |
|
15
|
+
# | +++--------------+ | | +++--------------+ |
|
16
|
+
# | | Extend | | | Extend |
|
17
|
+
# | v | | v +-------+ |
|
18
|
+
# | +-----------+ | | | Check | |
|
19
|
+
# | | GR::Plot | | | <--+ Error | |
|
20
|
+
# | +-----------+ | | +-------+ |
|
21
|
+
# +--------------------+ +----------+---------+
|
22
|
+
# ^ ^
|
23
|
+
# | +------------------+ |
|
24
|
+
# Extend | | GRCommons module | | Extend
|
25
|
+
# | | +--------------+ | |
|
26
|
+
# | | | Fiddley | | |
|
27
|
+
# | | +--------------+ | |
|
28
|
+
# | | +--------------+ | |
|
29
|
+
# +----+ CommonUtils +----+
|
30
|
+
# | | +--------------+ | |
|
31
|
+
# | | +--------------+ | |
|
32
|
+
# +----+ Version +----+
|
33
|
+
# | | +--------------+ |
|
34
|
+
# | | +--------------+ |
|
35
|
+
# +----+JupyterSupport| |
|
36
|
+
# | +--------------+ |
|
37
|
+
# +------------------+
|
38
|
+
#
|
39
|
+
# (You can edit the above AA diagram with http://asciiflow.com/)
|
40
|
+
#
|
41
|
+
# Fiddley is Ruby-FFI compatible API layer for Fiddle.
|
37
42
|
#
|
38
43
|
# Why not GR::GR3?
|
39
44
|
# * kojix2 did not want to force gr3 to be loaded when gr is loaded.
|
40
45
|
# * kojix2 did not want to write `GR3 = GR::GR3` or something.
|
41
|
-
# * This is a opinion of kojix2 and may be changed
|
46
|
+
# * This is a opinion of kojix2 and may be changed by future maintainers.
|
42
47
|
#
|
43
48
|
# GR3 uses Numo::Narrray.
|
44
49
|
# * It is difficult to write GR3 modules with only Ruby arrays.
|
@@ -55,20 +60,24 @@ module GR3
|
|
55
60
|
attr_accessor :ffi_lib
|
56
61
|
end
|
57
62
|
|
58
|
-
raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
|
59
|
-
|
60
63
|
# Platforms | path
|
61
64
|
# Windows | bin/libGR3.dll
|
62
65
|
# MacOSX | lib/libGR3.so (NOT .dylib)
|
63
66
|
# Ubuntu | lib/libGR3.so
|
64
67
|
if Object.const_defined?(:RubyInstaller)
|
68
|
+
ENV['GRDIR'] ||= [
|
69
|
+
RubyInstaller::Runtime.msys2_installation.msys_path,
|
70
|
+
RubyInstaller::Runtime.msys2_installation.mingwarch
|
71
|
+
].join(File::ALT_SEPARATOR)
|
65
72
|
self.ffi_lib = File.expand_path('bin/libGR3.dll', ENV['GRDIR'])
|
66
73
|
RubyInstaller::Runtime.add_dll_directory(File.dirname(ffi_lib))
|
67
74
|
else
|
75
|
+
raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
|
76
|
+
|
68
77
|
self.ffi_lib = File.expand_path('lib/libGR3.so', ENV['GRDIR'])
|
69
78
|
end
|
70
79
|
|
71
|
-
# change the default encoding to UTF-8
|
80
|
+
# change the default encoding to UTF-8.
|
72
81
|
ENV['GKS_ENCODING'] ||= 'utf8'
|
73
82
|
|
74
83
|
require_relative 'gr_commons/gr_commons'
|
@@ -76,12 +85,15 @@ module GR3
|
|
76
85
|
require_relative 'gr3/ffi'
|
77
86
|
require_relative 'gr3/gr3base'
|
78
87
|
|
79
|
-
# `
|
88
|
+
# `inquiry` methods etc. are defined here.
|
89
|
+
extend GRCommons::GRCommonUtils
|
90
|
+
|
91
|
+
# `float` is the default type in GR3.
|
80
92
|
# A Ruby array or NArray passed to GR3 method is automatically converted to
|
81
|
-
# a
|
93
|
+
# a Fiddley::MemoryPointer in the GR3Base class.
|
82
94
|
extend GR3Base
|
83
95
|
|
84
|
-
# This module is for adding error checking to all methods in GR3
|
96
|
+
# This module is for adding error checking to all methods in GR3.
|
85
97
|
module CheckError
|
86
98
|
def geterror
|
87
99
|
line = GRCommons::Fiddley::MemoryPointer.new(:int)
|
@@ -113,8 +125,7 @@ module GR3
|
|
113
125
|
extend CheckError
|
114
126
|
|
115
127
|
# Now you can see a lot of methods just calling super here.
|
116
|
-
#
|
117
|
-
# Yes. They are written to help the yard generate the documentation.
|
128
|
+
# They are written to help the yard generate the documentation.
|
118
129
|
class << self
|
119
130
|
# This method initializes the gr3 context.
|
120
131
|
# @return [Integer]
|
data/lib/gr3/ffi.rb
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
require 'fiddle/import'
|
4
4
|
|
5
5
|
module GR3
|
6
|
-
# FFI Wrapper module for GR3
|
6
|
+
# FFI Wrapper module for GR3.
|
7
|
+
# The functions for GR3 are listed here.
|
8
|
+
# Add functions here when a new version of GR is released.
|
7
9
|
module FFI
|
8
10
|
extend Fiddle::Importer
|
9
11
|
|
@@ -16,8 +18,7 @@ module GR3
|
|
16
18
|
extend GRCommons::Extern
|
17
19
|
|
18
20
|
# https://github.com/sciapp/gr/blob/master/lib/gr3/gr3.h
|
19
|
-
#
|
20
|
-
|
21
|
+
# keep same order
|
21
22
|
try_extern 'int gr3_init(int *attrib_list)'
|
22
23
|
try_extern 'void gr3_free(void *pointer)'
|
23
24
|
try_extern 'void gr3_terminate(void)'
|
@@ -72,8 +73,17 @@ module GR3
|
|
72
73
|
try_extern 'void gr3_setviewmatrix(const float *m)'
|
73
74
|
try_extern 'int gr3_getprojectiontype(void)'
|
74
75
|
try_extern 'void gr3_setprojectiontype(int type)'
|
75
|
-
# try_extern 'unsigned int gr3_triangulate(const unsigned short *data,
|
76
|
-
#
|
76
|
+
# try_extern 'unsigned int gr3_triangulate(const unsigned short *data, ' \
|
77
|
+
# 'unsigned short isolevel, unsigned int dim_x, unsigned int dim_y, unsigned int dim_z, ' \
|
78
|
+
# 'unsigned int stride_x, unsigned int stride_y, unsigned int stride_z, ' \
|
79
|
+
# 'double step_x, double step_y, double step_z, double offset_x, double offset_y, double offset_z, ' \
|
80
|
+
# 'gr3_triangle_t **triangles_p)'
|
81
|
+
# try_extern 'void gr3_triangulateindexed(const unsigned short *data, ' \
|
82
|
+
# 'unsigned short isolevel, unsigned int dim_x, unsigned int dim_y, unsigned int dim_z, ' \
|
83
|
+
# 'unsigned int stride_x, unsigned int stride_y, unsigned int stride_z, ' \
|
84
|
+
# 'double step_x, double step_y, double step_z, double offset_x, double offset_y, double offset_z, ' \
|
85
|
+
# 'unsigned int *num_vertices, gr3_coord_t **vertices, gr3_coord_t **normals, ' \
|
86
|
+
# 'unsigned int *num_indices, unsigned int **indices)'
|
77
87
|
try_extern 'int gr3_createisosurfacemesh(int *mesh, unsigned short *data, ' \
|
78
88
|
'unsigned short isolevel, unsigned int dim_x, unsigned int dim_y, unsigned int dim_z, ' \
|
79
89
|
'unsigned int stride_x, unsigned int stride_y, unsigned int stride_z, ' \
|
data/lib/gr3/gr3base.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GR3
|
4
|
-
# This module automatically converts Ruby arrays and Numo::Narray into
|
4
|
+
# This module automatically converts Ruby arrays and Numo::Narray into
|
5
|
+
# Fiddley::MemoryPointer.
|
5
6
|
module GR3Base
|
6
7
|
extend GRCommons::DefineMethods
|
7
8
|
define_ffi_methods(FFI,
|
@@ -15,6 +16,4 @@ module GR3
|
|
15
16
|
default_type: :double)
|
16
17
|
end
|
17
18
|
private_constant :GR3Base
|
18
|
-
|
19
|
-
extend GRCommons::GRCommonUtils
|
20
19
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GRCommons
|
4
|
-
# This module
|
4
|
+
# This module provides a way to add FFI methods to the GRBase and GR3Base modules.
|
5
5
|
module DefineMethods
|
6
6
|
private
|
7
7
|
|
8
8
|
def define_ffi_methods(ffi_class, prefix: '', default_type: :double)
|
9
9
|
ffi_class.ffi_methods.each do |method|
|
10
|
-
# delete_prefix (Ruby >= 2.5)
|
10
|
+
# Use delete_prefix (Ruby >= 2.5)
|
11
11
|
method_name = method.to_s.sub(/^#{prefix}/, '')
|
12
12
|
|
13
13
|
# FIXME: Refactoring required
|
@@ -16,9 +16,9 @@ module GRCommons
|
|
16
16
|
args.map! do |arg|
|
17
17
|
case arg
|
18
18
|
when Array
|
19
|
-
send(default_type, arg)
|
19
|
+
GRCommons::GRCommonUtils.send(default_type, arg)
|
20
20
|
when ->(x) { defined?(Numo::NArray) && x.is_a?(Numo::NArray) }
|
21
|
-
send(default_type, arg)
|
21
|
+
GRCommons::GRCommonUtils.send(default_type, arg)
|
22
22
|
else
|
23
23
|
arg
|
24
24
|
end
|
data/lib/gr_commons/extern.rb
CHANGED
@@ -5,9 +5,10 @@ module GRCommons
|
|
5
5
|
module Extern
|
6
6
|
attr_reader :ffi_methods
|
7
7
|
|
8
|
+
# Improved extern method.
|
8
9
|
# 1. Ignore functions that cannot be attached.
|
9
|
-
# For compatiblity with older versions of GR.
|
10
10
|
# 2. Available function (names) are stored in @ffi_methods.
|
11
|
+
# For compatiblity with older versions of GR.
|
11
12
|
def try_extern(signature, *opts)
|
12
13
|
@ffi_methods ||= []
|
13
14
|
begin
|
data/lib/gr_commons/fiddley.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Fiddley v0.0.8
|
4
|
-
# https://github.com/unak/fiddley
|
5
|
-
#
|
6
|
-
# Copyright (c) 2017 NAKAMURA Usaku usa@garbagecollect.jp
|
7
|
-
#
|
8
|
-
# Released under the 2-Clause BSD License.
|
9
|
-
|
10
|
-
# NOTE: kojix2 added, removed, and modified several methods.
|
11
|
-
|
12
3
|
require 'fiddle/import'
|
13
4
|
|
14
5
|
module GRCommons
|
15
|
-
# Ruby-FFI compatible API layer for Fiddle
|
6
|
+
# Fiddley v0.0.8 - Ruby-FFI compatible API layer for Fiddle
|
7
|
+
# https://github.com/unak/fiddley
|
8
|
+
#
|
9
|
+
# Copyright (c) 2017 NAKAMURA Usaku usa@garbagecollect.jp
|
10
|
+
#
|
11
|
+
# Released under the 2-Clause BSD License.
|
12
|
+
#
|
13
|
+
# NOTE: This module is only part of the original code.
|
14
|
+
# kojix2 adds, deletes, and modifies several methods.
|
16
15
|
module Fiddley
|
17
16
|
# NOTE: GR.rb supports 2.4 +. Unpack 1 does not work under 2.3.
|
18
17
|
|
@@ -5,7 +5,7 @@ require 'gr_commons/fiddley'
|
|
5
5
|
module GRCommons
|
6
6
|
# This module provides functionality common to GR and GR3.
|
7
7
|
module GRCommonUtils
|
8
|
-
|
8
|
+
module_function
|
9
9
|
|
10
10
|
def equal_length(*args)
|
11
11
|
lengths = args.map(&:length)
|
@@ -17,34 +17,60 @@ module GRCommons
|
|
17
17
|
lengths[0]
|
18
18
|
end
|
19
19
|
|
20
|
+
# This constants is used in the test.
|
20
21
|
SUPPORTED_TYPES = %i[uint8 uint16 int uint double float].freeze
|
21
22
|
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
23
|
+
# convert Ruby Array or NArray into packed string.
|
24
|
+
def uint8(data)
|
25
|
+
if narray?(data)
|
26
|
+
Numo::UInt8.cast(data).to_binary
|
27
|
+
else
|
28
|
+
Fiddley::Utils.array2str(:uint8, data.to_a.flatten)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# convert Ruby Array or NArray into packed string.
|
33
|
+
def uint16(data)
|
34
|
+
if narray?(data)
|
35
|
+
Numo::UInt16.cast(data).to_binary
|
36
|
+
else
|
37
|
+
Fiddley::Utils.array2str(:uint16, data.to_a.flatten)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# convert Ruby Array or NArray into packed string.
|
42
|
+
def int(data)
|
43
|
+
if narray?(data)
|
44
|
+
Numo::Int32.cast(data).to_binary
|
45
|
+
else
|
46
|
+
Fiddley::Utils.array2str(:int32, data.to_a.flatten)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# convert Ruby Array or NArray into packed string.
|
51
|
+
def uint(data)
|
52
|
+
if narray?(data)
|
53
|
+
Numo::UInt32.cast(data).to_binary
|
54
|
+
else
|
55
|
+
Fiddley::Utils.array2str(:uint, data.to_a.flatten)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# convert Ruby Array or NArray into packed string.
|
60
|
+
def double(data)
|
61
|
+
if narray?(data)
|
62
|
+
Numo::DFloat.cast(data).to_binary
|
63
|
+
else
|
64
|
+
Fiddley::Utils.array2str(:double, data.to_a.flatten)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# convert Ruby Array or NArray into packed string.
|
69
|
+
def float(data)
|
70
|
+
if narray?(data)
|
71
|
+
Numo::SFloat.cast(data).to_binary
|
72
|
+
else
|
73
|
+
Fiddley::Utils.array2str(:float, data.to_a.flatten)
|
48
74
|
end
|
49
75
|
end
|
50
76
|
|
data/lib/gr_commons/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-gr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,7 +150,8 @@ files:
|
|
150
150
|
homepage: https://github.com/red-data-tools/GR.rb
|
151
151
|
licenses:
|
152
152
|
- MIT
|
153
|
-
metadata:
|
153
|
+
metadata:
|
154
|
+
msys2_mingw_dependencies: gr
|
154
155
|
post_install_message:
|
155
156
|
rdoc_options: []
|
156
157
|
require_paths:
|