graphkit-vtk 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/graphkit-vtk.gemspec +2 -2
- data/lib/graphkit-vtk.rb +167 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/graphkit-vtk.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "graphkit-vtk"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Edmund Highcock"]
|
12
|
-
s.date = "2012-12-
|
12
|
+
s.date = "2012-12-31"
|
13
13
|
s.description = "An extension allowing graphkits to be rendered using the Visualization Toolkit. Uses the RubyPython gem to access the Python bindings for VTK."
|
14
14
|
s.email = "edmundhighcock@sourceforge.net"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/graphkit-vtk.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
class GraphKit
|
2
2
|
class VTKObjectGroup
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@other_objects = {}
|
6
|
+
end
|
3
7
|
#The Python vtk module
|
4
8
|
attr_accessor :vtk_module
|
5
9
|
|
@@ -12,9 +16,14 @@ class GraphKit
|
|
12
16
|
# The VTK mapper (which converts the data to image data)
|
13
17
|
attr_accessor :mapper
|
14
18
|
|
15
|
-
# The
|
19
|
+
# The vtkActor which is responsible for the data
|
16
20
|
# within the window
|
17
21
|
attr_accessor :actor
|
22
|
+
|
23
|
+
# The vtkVolume which is responsible for the data
|
24
|
+
# within the window in the case of volume
|
25
|
+
# rendering
|
26
|
+
attr_accessor :volume
|
18
27
|
|
19
28
|
# The VTK renderer which renders the image data
|
20
29
|
attr_accessor :renderer
|
@@ -30,6 +39,9 @@ class GraphKit
|
|
30
39
|
|
31
40
|
# The VTK interactor
|
32
41
|
attr_accessor :interactor
|
42
|
+
|
43
|
+
# A hash containing other VTK objects
|
44
|
+
attr_reader :other_objects
|
33
45
|
|
34
46
|
|
35
47
|
end
|
@@ -220,6 +232,160 @@ class GraphKit
|
|
220
232
|
end
|
221
233
|
|
222
234
|
|
235
|
+
# This method returns a VTKObjectGroup object, which
|
236
|
+
# contains references to the VTK/Python objects
|
237
|
+
# which are necessary to plot a graph using
|
238
|
+
# volume rendering.
|
239
|
+
#
|
240
|
+
# function can be :raycast or :tetrahedra
|
241
|
+
#
|
242
|
+
def vtk_volume_object_group( function = :raycast, filename = nil)
|
243
|
+
# If we are not given a filename, need to write the
|
244
|
+
# data in VTK format... can change at some point?
|
245
|
+
temp_write = false
|
246
|
+
unless filename
|
247
|
+
temp_write = true
|
248
|
+
filename = (Time.now.to_i).to_s + rand(1000000).to_s + ".tmp.vtk"
|
249
|
+
to_vtk_legacy_fast(file_name: filename)
|
250
|
+
end
|
251
|
+
|
252
|
+
require 'rubypython'
|
253
|
+
RubyPython.start
|
254
|
+
vtk_og = VTKObjectGroup.new
|
255
|
+
vtk = vtk_og.vtk_module = RubyPython.import('vtk')
|
256
|
+
file_name = filename
|
257
|
+
|
258
|
+
vtk_og.reader = reader = vtk.vtkUnstructuredGridReader
|
259
|
+
reader.SetFileName(file_name)
|
260
|
+
reader.Update
|
261
|
+
|
262
|
+
if temp_write
|
263
|
+
FileUtils.rm(filename)
|
264
|
+
end
|
265
|
+
|
266
|
+
vtk_og.output = output = reader.GetOutput
|
267
|
+
ep 'scalar_range', scalar_range = output.GetScalarRange
|
268
|
+
#
|
269
|
+
|
270
|
+
tf = vtk_og.other_objects[:tetrahedra_filter] = vtk.vtkDataSetTriangleFilter
|
271
|
+
tf.SetInput(output)
|
272
|
+
|
273
|
+
|
274
|
+
volprop = vtk_og.other_objects[:volume_property]= vtk.vtkVolumeProperty
|
275
|
+
coltranfunc = vtk_og.other_objects[:color_transfer_function] = vtk.vtkColorTransferFunction
|
276
|
+
opacfunc = vtk_og.other_objects[:opacity_function] = vtk.vtkPiecewiseFunction
|
277
|
+
|
278
|
+
min, max = scalar_range.to_a
|
279
|
+
ep scalar_range.to_a
|
280
|
+
max = max.to_s.to_f
|
281
|
+
min = min.to_s.to_f
|
282
|
+
ep 'max', max, max.class, 'min', min, min.class
|
283
|
+
|
284
|
+
coltranfunc.AddRGBPoint(min, 0.0, 0.0, 1.0)
|
285
|
+
coltranfunc.AddRGBPoint(min + 1.0*(max-min)/5.0, 0.0, 1.0, 1.0)
|
286
|
+
coltranfunc.AddRGBPoint(min + 2.0*(max-min)/5.0, 1.0, 0.0, 0.0)
|
287
|
+
coltranfunc.AddRGBPoint(min + 3.0*(max-min)/5.0, 1.0, 1.0, 0.0)
|
288
|
+
coltranfunc.AddRGBPoint(min + 4.0*(max-min)/5.0, 0.0, 1.0, 0.0)
|
289
|
+
coltranfunc.AddRGBPoint(min + 5.0*(max-min)/5.0, 1.0, 1.0, 1.0)
|
290
|
+
|
291
|
+
opacfunc.AddPoint(min, 1)
|
292
|
+
opacfunc.AddPoint(max, 1)
|
293
|
+
|
294
|
+
volprop.SetColor(coltranfunc)
|
295
|
+
volprop.SetScalarOpacity(opacfunc)
|
296
|
+
|
297
|
+
|
298
|
+
case function
|
299
|
+
when :raycast
|
300
|
+
vtk_og.mapper = mapper = vtk.vtkUnstructuredGridVolumeRayCastMapper
|
301
|
+
mapper.SetInput(tf.GetOutput)
|
302
|
+
mapper.SetRayCastFunction(vtk.vtkUnstructuredGridBunykRayCastFunction)
|
303
|
+
when :zsweep
|
304
|
+
vtk_og.mapper = mapper = vtk.vtkUnstructuredGridVolumeZSweepMapper
|
305
|
+
mapper.SetInput(tf.GetOutput)
|
306
|
+
mapper.SetRayIntegrator(vtk.vtkUnstructuredGridHomogeneousRayIntegrator )
|
307
|
+
when :tetrahedra
|
308
|
+
vtk_og.mapper = mapper = vtk.vtkProjectedTetrahedraMapper
|
309
|
+
mapper.SetInput(tf.GetOutput)
|
310
|
+
#mapper.SetRayCastFunction(vtk.vtkUnstructuredGridBunykRayCastFunction)
|
311
|
+
end
|
312
|
+
#mapper.SetScalarRange(scalar_range)
|
313
|
+
|
314
|
+
#look_up_table = vtk.vtkLookupTable
|
315
|
+
#look_up_table.SetNumberOfColors(64)
|
316
|
+
#look_up_table.SetHueRange(0.0, 0.667)
|
317
|
+
#mapper.SetLookupTable(look_up_table)
|
318
|
+
mapper.SetScalarModeToDefault
|
319
|
+
#mapper.CreateDefaultLookupTable
|
320
|
+
#mapper.ScalarVisibilityOn
|
321
|
+
#mapper.SelectColorArray('myvals')
|
322
|
+
|
323
|
+
|
324
|
+
vtk_og.volume = volume = vtk.vtkVolume
|
325
|
+
volume.SetMapper(mapper)
|
326
|
+
volume.SetProperty(volprop)
|
327
|
+
volume.VisibilityOn
|
328
|
+
|
329
|
+
vtk_og.renderer = renderer = vtk.vtkRenderer
|
330
|
+
renderer.AddVolume(volume)
|
331
|
+
#renderer.SetBackground(0,0,0)
|
332
|
+
|
333
|
+
vtk_og.renderer_window = renderer_window = vtk.vtkRenderWindow
|
334
|
+
renderer_window.SetSize(640,480)
|
335
|
+
renderer_window.AddRenderer(renderer)
|
336
|
+
|
337
|
+
render_large = vtk_og.large_image_renderer = vtk.vtkRenderLargeImage
|
338
|
+
render_large.SetInput(vtk_og.renderer)
|
339
|
+
render_large.SetMagnification(4)
|
340
|
+
|
341
|
+
vtk_og.interactor = interactor = vtk.vtkRenderWindowInteractor
|
342
|
+
interactor.SetRenderWindow(renderer_window)
|
343
|
+
interactor.Initialize
|
344
|
+
#interactor.Start
|
345
|
+
|
346
|
+
return vtk_og
|
347
|
+
end
|
348
|
+
|
349
|
+
# Visualise the GraphKit using the Visualization Toolkit (VTK)
|
350
|
+
# volume rendering classes.
|
351
|
+
# If <tt>output_file</tt> is "window", display it in a window;
|
352
|
+
# otherwise, write to the file, e.g. my_graph.jpg, my_graph.gif.
|
353
|
+
# The 'window' option will not work where VTK has been compiled
|
354
|
+
# for off screen rendering only.
|
355
|
+
#
|
356
|
+
# If input_file is given it sould be a VTK data file. Otherwise
|
357
|
+
# it will write the data to a temporary VTK legacy data file.
|
358
|
+
#
|
359
|
+
# The optional block yields a VTKObjectGroup which contains references
|
360
|
+
# to all the VTK objects for arbitrary manipulation before
|
361
|
+
# rendering.
|
362
|
+
|
363
|
+
def vtk_render_volume(output_file='window', function = :raycast, input_file=nil, &block)
|
364
|
+
vtk_og = vtk_volume_object_group(function, filename)
|
365
|
+
yield(vtk_og) if block
|
366
|
+
vtk = vtk_og.vtk_module
|
367
|
+
#filter = vtk.vtkWindowToImageFilter
|
368
|
+
#vtk_og.renderer_window.SetOffScreenRendering(1)
|
369
|
+
#gf = vtk.vtkGraphicsFactory
|
370
|
+
#gf.SetOffScreenOnlyMode(1)
|
371
|
+
vtk_og.renderer_window.Start
|
372
|
+
#vtk_og.reader.Update
|
373
|
+
#vtk_og.renderer.Update
|
374
|
+
#filter.SetInput(vtk_og.renderer_window)
|
375
|
+
case File.extname(output_file)
|
376
|
+
when '.jpeg', '.jpg'
|
377
|
+
jpeg_writer = vtk.vtkJPEGWriter
|
378
|
+
#vtk_og.renderer.DeviceRender
|
379
|
+
#jpeg_writer.SetInput(vtk_og.renderer.GetOutput)
|
380
|
+
#jpeg_writer.SetInput(render_large.GetOutput)
|
381
|
+
jpeg_writer.SetInput(vtk_og.large_image_renderer.GetOutput)
|
382
|
+
#filter.Update
|
383
|
+
jpeg_writer.SetFileName(output_file)
|
384
|
+
jpeg_writer.Write
|
385
|
+
end
|
386
|
+
vtk_og.renderer_window.Finalize
|
387
|
+
|
388
|
+
end
|
223
389
|
|
224
390
|
|
225
391
|
end #module VTK
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphkit-vtk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: graphkit
|
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
segments:
|
145
145
|
- 0
|
146
|
-
hash:
|
146
|
+
hash: 2250138545871999803
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|