ruby-gr 0.0.14 → 0.0.19
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 +141 -13
- data/lib/gr.rb +172 -54
- data/lib/gr/ffi.rb +10 -1
- data/lib/gr/grbase.rb +2 -3
- data/lib/gr/plot.rb +160 -123
- data/lib/gr3.rb +51 -40
- data/lib/gr3/ffi.rb +11 -2
- data/lib/gr3/gr3base.rb +2 -3
- data/lib/gr_commons/define_methods.rb +2 -2
- data/lib/gr_commons/fiddley.rb +1 -1
- data/lib/gr_commons/gr_common_utils.rb +53 -27
- data/lib/gr_commons/version.rb +1 -1
- data/lib/grm.rb +45 -0
- data/lib/grm/ffi.rb +63 -0
- data/lib/grm/grmbase.rb +13 -0
- data/lib/grm/version.rb +5 -0
- metadata +8 -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,9 +85,12 @@ 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
96
|
# This module is for adding error checking to all methods in GR3.
|
@@ -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
@@ -73,8 +73,17 @@ module GR3
|
|
73
73
|
try_extern 'void gr3_setviewmatrix(const float *m)'
|
74
74
|
try_extern 'int gr3_getprojectiontype(void)'
|
75
75
|
try_extern 'void gr3_setprojectiontype(int type)'
|
76
|
-
# try_extern 'unsigned int gr3_triangulate(const unsigned short *data,
|
77
|
-
#
|
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)'
|
78
87
|
try_extern 'int gr3_createisosurfacemesh(int *mesh, unsigned short *data, ' \
|
79
88
|
'unsigned short isolevel, unsigned int dim_x, unsigned int dim_y, unsigned int dim_z, ' \
|
80
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
|
@@ -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/fiddley.rb
CHANGED
@@ -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
data/lib/grm.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GRM
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :ffi_lib
|
8
|
+
end
|
9
|
+
|
10
|
+
# Platforms | path
|
11
|
+
# Windows | bin/libGRM.dll
|
12
|
+
# MacOSX | lib/libGRM.so (NOT .dylib)
|
13
|
+
# Ubuntu | lib/libGRM.so
|
14
|
+
if Object.const_defined?(:RubyInstaller)
|
15
|
+
ENV['GRDIR'] ||= [
|
16
|
+
RubyInstaller::Runtime.msys2_installation.msys_path,
|
17
|
+
RubyInstaller::Runtime.msys2_installation.mingwarch
|
18
|
+
].join(File::ALT_SEPARATOR)
|
19
|
+
self.ffi_lib = File.expand_path('bin/libGRM.dll', ENV['GRDIR'])
|
20
|
+
RubyInstaller::Runtime.add_dll_directory(File.dirname(ffi_lib))
|
21
|
+
else
|
22
|
+
raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
|
23
|
+
|
24
|
+
self.ffi_lib = File.expand_path('lib/libGRM.so', ENV['GRDIR'])
|
25
|
+
end
|
26
|
+
|
27
|
+
# change the default encoding to UTF-8.
|
28
|
+
ENV['GKS_ENCODING'] ||= 'utf8'
|
29
|
+
|
30
|
+
require_relative 'gr_commons/gr_commons'
|
31
|
+
require_relative 'grm/version'
|
32
|
+
require_relative 'grm/ffi'
|
33
|
+
require_relative 'grm/grmbase'
|
34
|
+
|
35
|
+
# `inquiry` methods etc. are defined here.
|
36
|
+
extend GRCommons::GRCommonUtils
|
37
|
+
|
38
|
+
# `XXX` is the default type in GR.
|
39
|
+
# A Ruby array or NArray passed to GR method is automatically converted to
|
40
|
+
# a Fiddley::MemoryPointer in the GRBase class.
|
41
|
+
extend GRMBase
|
42
|
+
|
43
|
+
class << self
|
44
|
+
end
|
45
|
+
end
|
data/lib/grm/ffi.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fiddle/import'
|
4
|
+
|
5
|
+
module GRM
|
6
|
+
# FFI Wrapper module for GRM.
|
7
|
+
# The functions for GRM are listed here.
|
8
|
+
# Add functions here when a new version of GR is released.
|
9
|
+
module FFI
|
10
|
+
extend Fiddle::Importer
|
11
|
+
|
12
|
+
begin
|
13
|
+
dlload GRM.ffi_lib
|
14
|
+
rescue LoadError
|
15
|
+
raise LoadError, 'Could not find GR Framework'
|
16
|
+
end
|
17
|
+
|
18
|
+
extend GRCommons::Extern
|
19
|
+
|
20
|
+
# Currently, the declarations of GRM functions are distributed in several
|
21
|
+
# header files.
|
22
|
+
|
23
|
+
# https://github.com/sciapp/gr/blob/master/lib/grm/args.h
|
24
|
+
|
25
|
+
try_extern 'grm_args_t *grm_args_new(void)'
|
26
|
+
try_extern 'void grm_args_delete(grm_args_t *args)'
|
27
|
+
# Fiddle does not currently support variable-length arguments in C.
|
28
|
+
try_extern 'int grm_args_push(grm_args_t *args, const char *key, const char *value_format, ...)'
|
29
|
+
try_extern 'int grm_args_push_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, int apply_padding)'
|
30
|
+
try_extern 'int grm_args_contains(const grm_args_t *args, const char *keyword)'
|
31
|
+
try_extern 'void grm_args_clear(grm_args_t *args)'
|
32
|
+
try_extern 'void grm_args_remove(grm_args_t *args, const char *key)'
|
33
|
+
|
34
|
+
# https://github.com/sciapp/gr/blob/master/lib/grm/dump.h
|
35
|
+
try_extern 'void grm_dump(const grm_args_t *args, FILE *f)'
|
36
|
+
try_extern 'void grm_dump_json(const grm_args_t *args, FILE *f)'
|
37
|
+
try_extern 'char *grm_dump_json_str(void)'
|
38
|
+
|
39
|
+
# https://github.com/sciapp/gr/blob/master/lib/grm/event.h
|
40
|
+
# grm_event_type_t is an enum.
|
41
|
+
# In the original fiddley, there is code for an enum.
|
42
|
+
# But GR's fiddley doesn't have it.
|
43
|
+
# try_extern 'int grm_register(grm_event_type_t type, grm_event_callback_t callback)'
|
44
|
+
# try_extern 'int grm_unregister(grm_event_type_t type)'
|
45
|
+
|
46
|
+
# https://github.com/sciapp/gr/blob/master/lib/grm/interaction.h
|
47
|
+
try_extern 'int grm_input(const grm_args_t *input_args)'
|
48
|
+
# try_extern 'int grm_get_box(const int x1, const int y1, const int x2, const int y2, const int keep_aspect_ratio, int *x, int *y, int *w, int *h)'
|
49
|
+
# try_extern 'grm_tooltip_info_t *grm_get_tooltip(const int, const int)'
|
50
|
+
|
51
|
+
# https://github.com/sciapp/gr/blob/master/lib/grm/net.h
|
52
|
+
# try_extern 'void *grm_open(int is_receiver, const char *name, unsigned int id,
|
53
|
+
# const char *(*custom_recv)(const char *, unsigned int),
|
54
|
+
# int (*custom_send)(const char *, unsigned int, const char *))
|
55
|
+
try_extern 'grm_args_t *grm_recv(const void *p, grm_args_t *args)'
|
56
|
+
# Fiddle does not currently support variable-length arguments in C.
|
57
|
+
try_extern 'int grm_send(const void *p, const char *data_desc, ...)'
|
58
|
+
try_extern 'int grm_send_buf(const void *p, const char *data_desc, const void *buffer, int apply_padding)'
|
59
|
+
try_extern 'int grm_send_ref(const void *p, const char *key, char format, const void *ref, int len)'
|
60
|
+
try_extern 'int grm_send_args(const void *p, const grm_args_t *args)'
|
61
|
+
try_extern 'void grm_close(const void *p)'
|
62
|
+
end
|
63
|
+
end
|
data/lib/grm/grmbase.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GRM
|
4
|
+
# This module automatically converts Ruby arrays and Numo::Narray into
|
5
|
+
# Fiddley::MemoryPointer.
|
6
|
+
module GRMBase
|
7
|
+
extend GRCommons::DefineMethods
|
8
|
+
define_ffi_methods(FFI,
|
9
|
+
prefix: 'grm_',
|
10
|
+
default_type: :float) # FIXME!
|
11
|
+
end
|
12
|
+
private_constant :GRMBase
|
13
|
+
end
|
data/lib/grm/version.rb
ADDED
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.19
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -147,10 +147,15 @@ files:
|
|
147
147
|
- lib/gr_commons/gr_commons.rb
|
148
148
|
- lib/gr_commons/jupyter_support.rb
|
149
149
|
- lib/gr_commons/version.rb
|
150
|
+
- lib/grm.rb
|
151
|
+
- lib/grm/ffi.rb
|
152
|
+
- lib/grm/grmbase.rb
|
153
|
+
- lib/grm/version.rb
|
150
154
|
homepage: https://github.com/red-data-tools/GR.rb
|
151
155
|
licenses:
|
152
156
|
- MIT
|
153
|
-
metadata:
|
157
|
+
metadata:
|
158
|
+
msys2_mingw_dependencies: gr
|
154
159
|
post_install_message:
|
155
160
|
rdoc_options: []
|
156
161
|
require_paths:
|