graphkit-vtk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/graphkit-vtk.rb +139 -0
- data/test/helper.rb +18 -0
- data/test/test_graphkit-vtk.rb +7 -0
- metadata +158 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "graphkit", "> 0.2"
|
6
|
+
gem "rubypython", "> 0.6"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "shoulda", ">= 0"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "bundler", "> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.8.4"
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Edmund Highcock
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= graphkit-vtk
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to graphkit-vtk
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Edmund Highcock. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "graphkit-vtk"
|
18
|
+
gem.homepage = "http://github.com/edmundhighcock/graphkit-vtk"
|
19
|
+
gem.license = "GPLv3"
|
20
|
+
gem.summary = %Q{An extension allowing graphkits to be rendered using the Visualization Toolkit.}
|
21
|
+
gem.description = %Q{An extension allowing graphkits to be rendered using the Visualization Toolkit. Uses the RubyPython gem to access the Python bindings for VTK.}
|
22
|
+
gem.email = "edmundhighcock@sourceforge.net"
|
23
|
+
gem.authors = ["Edmund Highcock"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
#require 'rcov/rcovtask'
|
36
|
+
#Rcov::RcovTask.new do |test|
|
37
|
+
##test.libs << 'test'
|
38
|
+
##test.pattern = 'test/**/test_*.rb'
|
39
|
+
##test.verbose = true
|
40
|
+
##test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
##end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "graphkit-vtk #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/graphkit-vtk.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
class GraphKit
|
2
|
+
class VTKObjectGroup
|
3
|
+
#The Python vtk module
|
4
|
+
attr_accessor :vtk_module
|
5
|
+
|
6
|
+
# The VTK object which reads the file
|
7
|
+
attr_accessor :reader
|
8
|
+
|
9
|
+
# The output of the Reader
|
10
|
+
attr_accessor :output
|
11
|
+
|
12
|
+
# The VTK mapper (which converts the data to image data)
|
13
|
+
attr_accessor :mapper
|
14
|
+
|
15
|
+
# The VTK actor which is responsible for the data
|
16
|
+
# within the window
|
17
|
+
attr_accessor :actor
|
18
|
+
|
19
|
+
# The VTK renderer which renders the image data
|
20
|
+
attr_accessor :renderer
|
21
|
+
|
22
|
+
# The VTK object which connects to the renderer
|
23
|
+
# and should be connected to an image writer to
|
24
|
+
# write image files.
|
25
|
+
attr_accessor :large_image_renderer
|
26
|
+
|
27
|
+
# The VTK window object into which the data is rendered
|
28
|
+
# It is what causes the renderer to act.
|
29
|
+
attr_accessor :renderer_window
|
30
|
+
|
31
|
+
# The VTK interactor
|
32
|
+
attr_accessor :interactor
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
# This method returns a VTKObjectGroup object, which
|
38
|
+
# contains references to the VTK/Python objects
|
39
|
+
# which are necessary to plot the graph.
|
40
|
+
def vtk_object_group(filename = nil)
|
41
|
+
# If we are not given a filename, need to write the
|
42
|
+
# data in VTK format... can change at some point?
|
43
|
+
temp_write = false
|
44
|
+
unless filename
|
45
|
+
temp_write = true
|
46
|
+
filename = Time.now.to_i.to_s + ".tmp.vtk"
|
47
|
+
to_vtk_legacy_fast(file_name: filename)
|
48
|
+
end
|
49
|
+
|
50
|
+
require 'rubypython'
|
51
|
+
RubyPython.start
|
52
|
+
vtk_og = VTKObjectGroup.new
|
53
|
+
vtk = vtk_og.vtk_module = RubyPython.import('vtk')
|
54
|
+
file_name = filename
|
55
|
+
|
56
|
+
vtk_og.reader = reader = vtk.vtkUnstructuredGridReader
|
57
|
+
reader.SetFileName(file_name)
|
58
|
+
reader.Update
|
59
|
+
|
60
|
+
if temp_write
|
61
|
+
FileUtils.rm(filename)
|
62
|
+
end
|
63
|
+
|
64
|
+
vtk_og.output = output = reader.GetOutput
|
65
|
+
scalar_range = output.GetScalarRange
|
66
|
+
|
67
|
+
vtk_og.mapper = mapper = vtk.vtkDataSetMapper
|
68
|
+
mapper.SetInput(output)
|
69
|
+
mapper.SetScalarRange(scalar_range)
|
70
|
+
|
71
|
+
vtk_og.actor = actor = vtk.vtkActor
|
72
|
+
actor.SetMapper(mapper)
|
73
|
+
|
74
|
+
vtk_og.renderer = renderer = vtk.vtkRenderer
|
75
|
+
renderer.AddActor(actor)
|
76
|
+
renderer.SetBackground(0,0,0)
|
77
|
+
|
78
|
+
vtk_og.renderer_window = renderer_window = vtk.vtkRenderWindow
|
79
|
+
renderer_window.SetSize(640,480)
|
80
|
+
renderer_window.AddRenderer(renderer)
|
81
|
+
|
82
|
+
render_large = vtk_og.large_image_renderer = vtk.vtkRenderLargeImage
|
83
|
+
render_large.SetInput(vtk_og.renderer)
|
84
|
+
render_large.SetMagnification(8)
|
85
|
+
|
86
|
+
#vtk_og.interactor = interactor = vtk.vtkRenderWindowInteractor
|
87
|
+
#interactor.SetRenderWindow(renderer_window)
|
88
|
+
#interactor.Initialize
|
89
|
+
#interactor.Start
|
90
|
+
|
91
|
+
return vtk_og
|
92
|
+
end
|
93
|
+
|
94
|
+
# Visualise the Graph using the Visualization Toolkit (VTK).
|
95
|
+
# If <tt>output_file</tt> is "window", display it in a window;
|
96
|
+
# otherwise, write to the file, e.g. my_graph.jpg, my_graph.gif
|
97
|
+
# If input_file is given it sould be a VTK data file. Otherwise
|
98
|
+
# it will write the data to a temporary VTK legacy data file.
|
99
|
+
#
|
100
|
+
# The optional block yields a VTKObjectGroup which contains references
|
101
|
+
# to all the VTK objects for arbitrary manipulation before
|
102
|
+
# rendering.
|
103
|
+
|
104
|
+
def vtk_render(output_file='window', input_file=nil, &block)
|
105
|
+
vtk_og = vtk_object_group(filename)
|
106
|
+
yield(vtk_og) if block
|
107
|
+
vtk = vtk_og.vtk_module
|
108
|
+
#filter = vtk.vtkWindowToImageFilter
|
109
|
+
#vtk_og.renderer_window.SetOffScreenRendering(1)
|
110
|
+
#gf = vtk.vtkGraphicsFactory
|
111
|
+
#gf.SetOffScreenOnlyMode(1)
|
112
|
+
vtk_og.renderer_window.Start
|
113
|
+
#vtk_og.reader.Update
|
114
|
+
#vtk_og.renderer.Update
|
115
|
+
#filter.SetInput(vtk_og.renderer_window)
|
116
|
+
case File.extname(output_file)
|
117
|
+
when '.jpeg', '.jpg'
|
118
|
+
jpeg_writer = vtk.vtkJPEGWriter
|
119
|
+
#vtk_og.renderer.DeviceRender
|
120
|
+
#jpeg_writer.SetInput(vtk_og.renderer.GetOutput)
|
121
|
+
#jpeg_writer.SetInput(render_large.GetOutput)
|
122
|
+
jpeg_writer.SetInput(vtk_og.large_image_renderer.GetOutput)
|
123
|
+
#filter.Update
|
124
|
+
jpeg_writer.SetFileName(output_file)
|
125
|
+
jpeg_writer.Write
|
126
|
+
end
|
127
|
+
vtk_og.renderer_window.Finalize
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'graphkit-vtk'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graphkit-vtk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Edmund Highcock
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: graphkit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>'
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>'
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rubypython
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>'
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.6'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>'
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.6'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>'
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.0.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>'
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.4
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.4
|
110
|
+
description: An extension allowing graphkits to be rendered using the Visualization
|
111
|
+
Toolkit. Uses the RubyPython gem to access the Python bindings for VTK.
|
112
|
+
email: edmundhighcock@sourceforge.net
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files:
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.md
|
118
|
+
- README.rdoc
|
119
|
+
files:
|
120
|
+
- .document
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- README.rdoc
|
125
|
+
- Rakefile
|
126
|
+
- VERSION
|
127
|
+
- lib/graphkit-vtk.rb
|
128
|
+
- test/helper.rb
|
129
|
+
- test/test_graphkit-vtk.rb
|
130
|
+
homepage: http://github.com/edmundhighcock/graphkit-vtk
|
131
|
+
licenses:
|
132
|
+
- GPLv3
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
hash: -985514157194302539
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 1.8.24
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: An extension allowing graphkits to be rendered using the Visualization Toolkit.
|
158
|
+
test_files: []
|