vtk-ruby 5.0.4.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/VTK/common.rb +7 -0
- data/lib/VTK/common.rb.rule +1 -0
- data/lib/VTK/filtering.rb +7 -0
- data/lib/VTK/filtering.rb.rule +1 -0
- data/lib/VTK/genericfiltering.rb +7 -0
- data/lib/VTK/genericfiltering.rb.rule +1 -0
- data/lib/VTK/graphics.rb +7 -0
- data/lib/VTK/graphics.rb.rule +1 -0
- data/lib/VTK/gtk.rb +5 -0
- data/lib/VTK/gtk.rb.rule +1 -0
- data/lib/VTK/gtk/GtkGLExtVTKRenderWindow.rb +635 -0
- data/lib/VTK/gtk/GtkGLExtVTKRenderWindow.rb.rule +1 -0
- data/lib/VTK/gtk/GtkGLExtVTKRenderWindowInteractor.rb +355 -0
- data/lib/VTK/gtk/GtkGLExtVTKRenderWindowInteractor.rb.rule +1 -0
- data/lib/VTK/gtk/GtkVTKRenderWindow.rb +615 -0
- data/lib/VTK/gtk/GtkVTKRenderWindow.rb.rule +1 -0
- data/lib/VTK/gtk/GtkVTKRenderWindowInteractor.rb +336 -0
- data/lib/VTK/gtk/GtkVTKRenderWindowInteractor.rb.rule +1 -0
- data/lib/VTK/hybrid.rb +7 -0
- data/lib/VTK/hybrid.rb.rule +1 -0
- data/lib/VTK/imaging.rb +7 -0
- data/lib/VTK/imaging.rb.rule +1 -0
- data/lib/VTK/io.rb +7 -0
- data/lib/VTK/io.rb.rule +1 -0
- data/lib/VTK/parallel.rb +7 -0
- data/lib/VTK/parallel.rb.rule +1 -0
- data/lib/VTK/rendering.rb +7 -0
- data/lib/VTK/rendering.rb.rule +1 -0
- data/lib/VTK/tk.rb +4 -0
- data/lib/VTK/tk.rb.rule +1 -0
- data/lib/VTK/tk/vtkLoadRubyTkWidgets.rb +54 -0
- data/lib/VTK/tk/vtkLoadRubyTkWidgets.rb.rule +1 -0
- data/lib/VTK/tk/vtkTkImageViewerWidget.rb +377 -0
- data/lib/VTK/tk/vtkTkImageViewerWidget.rb.rule +1 -0
- data/lib/VTK/tk/vtkTkPhotoImage.rb +28 -0
- data/lib/VTK/tk/vtkTkPhotoImage.rb.rule +1 -0
- data/lib/VTK/tk/vtkTkRenderWidget.rb +486 -0
- data/lib/VTK/tk/vtkTkRenderWidget.rb.rule +1 -0
- data/lib/VTK/tk/vtkTkRenderWindowInteractor.rb +394 -0
- data/lib/VTK/tk/vtkTkRenderWindowInteractor.rb.rule +1 -0
- data/lib/VTK/util.rb +6 -0
- data/lib/VTK/util.rb.rule +1 -0
- data/lib/VTK/util/colors.rb +223 -0
- data/lib/VTK/util/colors.rb.rule +1 -0
- data/lib/VTK/util/misc.rb +68 -0
- data/lib/VTK/util/misc.rb.rule +1 -0
- data/lib/VTK/util/vtkConstants.rb +123 -0
- data/lib/VTK/util/vtkConstants.rb.rule +1 -0
- data/lib/VTK/util/vtkImageExportToArray.rb +96 -0
- data/lib/VTK/util/vtkImageExportToArray.rb.rule +1 -0
- data/lib/VTK/util/vtkImageImportFromArray.rb +116 -0
- data/lib/VTK/util/vtkImageImportFromArray.rb.rule +1 -0
- data/lib/VTK/volumerendering.rb +7 -0
- data/lib/VTK/volumerendering.rb.rule +1 -0
- data/lib/VTK/vtkCommon.dll +0 -0
- data/lib/VTK/vtkCommon.exp +0 -0
- data/lib/VTK/vtkCommon.lib +0 -0
- data/lib/VTK/vtkCommonRuby.dll +0 -0
- data/lib/VTK/vtkCommonRuby.exp +0 -0
- data/lib/VTK/vtkCommonRuby.lib +0 -0
- data/lib/VTK/vtkCommonRubyD.dll +0 -0
- data/lib/VTK/vtkCommonRubyD.exp +0 -0
- data/lib/VTK/vtkCommonRubyD.lib +0 -0
- data/lib/VTK/vtkDICOMParser.dll +0 -0
- data/lib/VTK/vtkDICOMParser.exp +0 -0
- data/lib/VTK/vtkDICOMParser.lib +0 -0
- data/lib/VTK/vtkFiltering.dll +0 -0
- data/lib/VTK/vtkFiltering.exp +0 -0
- data/lib/VTK/vtkFiltering.lib +0 -0
- data/lib/VTK/vtkFilteringRuby.dll +0 -0
- data/lib/VTK/vtkFilteringRuby.exp +0 -0
- data/lib/VTK/vtkFilteringRuby.lib +0 -0
- data/lib/VTK/vtkFilteringRubyD.dll +0 -0
- data/lib/VTK/vtkFilteringRubyD.exp +0 -0
- data/lib/VTK/vtkFilteringRubyD.lib +0 -0
- data/lib/VTK/vtkGenericFiltering.dll +0 -0
- data/lib/VTK/vtkGenericFiltering.exp +0 -0
- data/lib/VTK/vtkGenericFiltering.lib +0 -0
- data/lib/VTK/vtkGenericFilteringRuby.dll +0 -0
- data/lib/VTK/vtkGenericFilteringRuby.exp +0 -0
- data/lib/VTK/vtkGenericFilteringRuby.lib +0 -0
- data/lib/VTK/vtkGenericFilteringRubyD.dll +0 -0
- data/lib/VTK/vtkGenericFilteringRubyD.exp +0 -0
- data/lib/VTK/vtkGenericFilteringRubyD.lib +0 -0
- data/lib/VTK/vtkGraphics.dll +0 -0
- data/lib/VTK/vtkGraphics.exp +0 -0
- data/lib/VTK/vtkGraphics.lib +0 -0
- data/lib/VTK/vtkGraphicsRuby.dll +0 -0
- data/lib/VTK/vtkGraphicsRuby.exp +0 -0
- data/lib/VTK/vtkGraphicsRuby.lib +0 -0
- data/lib/VTK/vtkGraphicsRubyD.dll +0 -0
- data/lib/VTK/vtkGraphicsRubyD.exp +0 -0
- data/lib/VTK/vtkGraphicsRubyD.lib +0 -0
- data/lib/VTK/vtkHybrid.dll +0 -0
- data/lib/VTK/vtkHybrid.exp +0 -0
- data/lib/VTK/vtkHybrid.lib +0 -0
- data/lib/VTK/vtkHybridRuby.dll +0 -0
- data/lib/VTK/vtkHybridRuby.exp +0 -0
- data/lib/VTK/vtkHybridRuby.lib +0 -0
- data/lib/VTK/vtkHybridRubyD.dll +0 -0
- data/lib/VTK/vtkHybridRubyD.exp +0 -0
- data/lib/VTK/vtkHybridRubyD.lib +0 -0
- data/lib/VTK/vtkIO.dll +0 -0
- data/lib/VTK/vtkIO.exp +0 -0
- data/lib/VTK/vtkIO.lib +0 -0
- data/lib/VTK/vtkIORuby.dll +0 -0
- data/lib/VTK/vtkIORuby.exp +0 -0
- data/lib/VTK/vtkIORuby.lib +0 -0
- data/lib/VTK/vtkIORubyD.dll +0 -0
- data/lib/VTK/vtkIORubyD.exp +0 -0
- data/lib/VTK/vtkIORubyD.lib +0 -0
- data/lib/VTK/vtkImaging.dll +0 -0
- data/lib/VTK/vtkImaging.exp +0 -0
- data/lib/VTK/vtkImaging.lib +0 -0
- data/lib/VTK/vtkImagingRuby.dll +0 -0
- data/lib/VTK/vtkImagingRuby.exp +0 -0
- data/lib/VTK/vtkImagingRuby.lib +0 -0
- data/lib/VTK/vtkImagingRubyD.dll +0 -0
- data/lib/VTK/vtkImagingRubyD.exp +0 -0
- data/lib/VTK/vtkImagingRubyD.lib +0 -0
- data/lib/VTK/vtkNetCDF.dll +0 -0
- data/lib/VTK/vtkNetCDF.exp +0 -0
- data/lib/VTK/vtkNetCDF.lib +0 -0
- data/lib/VTK/vtkParallel.dll +0 -0
- data/lib/VTK/vtkParallel.exp +0 -0
- data/lib/VTK/vtkParallel.lib +0 -0
- data/lib/VTK/vtkParallelRuby.dll +0 -0
- data/lib/VTK/vtkParallelRuby.exp +0 -0
- data/lib/VTK/vtkParallelRuby.lib +0 -0
- data/lib/VTK/vtkParallelRubyD.dll +0 -0
- data/lib/VTK/vtkParallelRubyD.exp +0 -0
- data/lib/VTK/vtkParallelRubyD.lib +0 -0
- data/lib/VTK/vtkParseOGLExt.exe +0 -0
- data/lib/VTK/vtkRendering.dll +0 -0
- data/lib/VTK/vtkRendering.exp +0 -0
- data/lib/VTK/vtkRendering.lib +0 -0
- data/lib/VTK/vtkRenderingRuby.dll +0 -0
- data/lib/VTK/vtkRenderingRuby.exp +0 -0
- data/lib/VTK/vtkRenderingRuby.lib +0 -0
- data/lib/VTK/vtkRenderingRubyD.dll +0 -0
- data/lib/VTK/vtkRenderingRubyD.exp +0 -0
- data/lib/VTK/vtkRenderingRubyD.lib +0 -0
- data/lib/VTK/vtkVREncodeString.exe +0 -0
- data/lib/VTK/vtkVolumeRendering.dll +0 -0
- data/lib/VTK/vtkVolumeRendering.exp +0 -0
- data/lib/VTK/vtkVolumeRendering.lib +0 -0
- data/lib/VTK/vtkVolumeRenderingRuby.dll +0 -0
- data/lib/VTK/vtkVolumeRenderingRuby.exp +0 -0
- data/lib/VTK/vtkVolumeRenderingRuby.lib +0 -0
- data/lib/VTK/vtkVolumeRenderingRubyD.dll +0 -0
- data/lib/VTK/vtkVolumeRenderingRubyD.exp +0 -0
- data/lib/VTK/vtkVolumeRenderingRubyD.lib +0 -0
- data/lib/VTK/vtkWidgets.dll +0 -0
- data/lib/VTK/vtkWidgets.exp +0 -0
- data/lib/VTK/vtkWidgets.lib +0 -0
- data/lib/VTK/vtkWidgetsRuby.dll +0 -0
- data/lib/VTK/vtkWidgetsRuby.exp +0 -0
- data/lib/VTK/vtkWidgetsRuby.lib +0 -0
- data/lib/VTK/vtkWidgetsRubyD.dll +0 -0
- data/lib/VTK/vtkWidgetsRubyD.exp +0 -0
- data/lib/VTK/vtkWidgetsRubyD.lib +0 -0
- data/lib/VTK/vtkWrapRuby.exe +0 -0
- data/lib/VTK/vtkWrapRubyInit.exe +0 -0
- data/lib/VTK/vtk_dummy.rb +3 -0
- data/lib/VTK/vtkexoIIc.dll +0 -0
- data/lib/VTK/vtkexoIIc.exp +0 -0
- data/lib/VTK/vtkexoIIc.lib +0 -0
- data/lib/VTK/vtkexpat.dll +0 -0
- data/lib/VTK/vtkexpat.exp +0 -0
- data/lib/VTK/vtkexpat.lib +0 -0
- data/lib/VTK/vtkfreetype.dll +0 -0
- data/lib/VTK/vtkfreetype.exp +0 -0
- data/lib/VTK/vtkfreetype.lib +0 -0
- data/lib/VTK/vtkftgl.dll +0 -0
- data/lib/VTK/vtkftgl.exp +0 -0
- data/lib/VTK/vtkftgl.lib +0 -0
- data/lib/VTK/vtkjpeg.dll +0 -0
- data/lib/VTK/vtkjpeg.exp +0 -0
- data/lib/VTK/vtkjpeg.lib +0 -0
- data/lib/VTK/vtkpng.dll +0 -0
- data/lib/VTK/vtkpng.exp +0 -0
- data/lib/VTK/vtkpng.lib +0 -0
- data/lib/VTK/vtkruby.exe +0 -0
- data/lib/VTK/vtksys.dll +0 -0
- data/lib/VTK/vtksys.exp +0 -0
- data/lib/VTK/vtksys.lib +0 -0
- data/lib/VTK/vtksysEncodeExecutable.exe +0 -0
- data/lib/VTK/vtksysProcessFwd9x.exe +0 -0
- data/lib/VTK/vtktiff.dll +0 -0
- data/lib/VTK/vtktiff.exp +0 -0
- data/lib/VTK/vtktiff.lib +0 -0
- data/lib/VTK/vtkzlib.dll +0 -0
- data/lib/VTK/vtkzlib.exp +0 -0
- data/lib/VTK/vtkzlib.lib +0 -0
- data/lib/VTK/widgets.rb +7 -0
- data/lib/VTK/widgets.rb.rule +1 -0
- data/lib/setup.rb +104 -0
- data/lib/vtk.rb +35 -0
- data/lib/vtk_dummy.rb +3 -0
- metadata +256 -0
data/lib/VTK/common.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# generated from CMake
|
@@ -0,0 +1 @@
|
|
1
|
+
# generated from CMake
|
@@ -0,0 +1 @@
|
|
1
|
+
# generated from CMake
|
data/lib/VTK/graphics.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# generated from CMake
|
data/lib/VTK/gtk.rb
ADDED
data/lib/VTK/gtk.rb.rule
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# generated from CMake
|
@@ -0,0 +1,635 @@
|
|
1
|
+
=begin
|
2
|
+
Description:
|
3
|
+
|
4
|
+
This provides a VTK widget for pyGtk. This embeds a vtkRenderWindow
|
5
|
+
This provides a VTK widget end
|
6
|
+
inside a GTK widget. This is based on GtkVTKRenderWindow.rb.
|
7
|
+
|
8
|
+
The extensions here allow the use of gtkglext rather than gtkgl &&
|
9
|
+
ruby-gtk2 rather than pygtk-0. It requires ruby-gtk2.0.0 || later.
|
10
|
+
|
11
|
+
There is a working example at the bottom.
|
12
|
+
|
13
|
+
Credits:
|
14
|
+
|
15
|
+
License:
|
16
|
+
|
17
|
+
VTK license.
|
18
|
+
|
19
|
+
=end
|
20
|
+
|
21
|
+
require 'rbconfig'
|
22
|
+
require 'gtk2'
|
23
|
+
require 'gtkglext'
|
24
|
+
require 'vtk'
|
25
|
+
|
26
|
+
|
27
|
+
class GtkGLExtVTKRenderWindowBase < Gtk::DrawingArea
|
28
|
+
|
29
|
+
=begin
|
30
|
+
A base class that enables one to embed a vtkRenderWindow into
|
31
|
+
a pyGTK widget. This class embeds the RenderWindow correctly.
|
32
|
+
Provided are some empty methods that can be overloaded to provide
|
33
|
+
a user defined interaction behaviour. The event handling
|
34
|
+
functions have names that are somewhat similar to the ones in the
|
35
|
+
vtkInteractorStyle class included with VTK.
|
36
|
+
=end
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
super
|
40
|
+
|
41
|
+
glconfig = Gdk::GLConfig.new(Gdk::GLConfig::MODE_RGB|
|
42
|
+
Gdk::GLConfig::MODE_DEPTH)
|
43
|
+
|
44
|
+
set_gl_capability(glconfig)
|
45
|
+
|
46
|
+
@RenderWindow = Vtk::RenderWindow.new
|
47
|
+
# private attributes
|
48
|
+
@Created = false
|
49
|
+
|
50
|
+
# used by the LOD actors
|
51
|
+
@DesiredUpdateRate = 15
|
52
|
+
@StillUpdateRate = 0.0001
|
53
|
+
|
54
|
+
self.ConnectSignals
|
55
|
+
|
56
|
+
# need this to be able to handle key_press events.
|
57
|
+
set_flags(Gtk::Window::CAN_FOCUS)
|
58
|
+
# default size
|
59
|
+
set_size_request(300, 300)
|
60
|
+
end
|
61
|
+
|
62
|
+
def ConnectSignals
|
63
|
+
signal_connect("realize"){|wid,event| OnRealize(wid,event)}
|
64
|
+
signal_connect("expose_event"){|wid,event| OnExpose(wid,event)}
|
65
|
+
signal_connect("configure_event"){|wid,event| OnConfigure(wid,event)}
|
66
|
+
signal_connect("button_press_event"){|wid,event| OnButtonDown(wid,event)}
|
67
|
+
signal_connect("button_release_event"){|wid,event| OnButtonUp(wid,event)}
|
68
|
+
signal_connect("motion_notify_event"){|wid,event| OnMouseMove(wid,event)}
|
69
|
+
signal_connect("enter_notify_event"){|wid,event| OnEnter(wid,event)}
|
70
|
+
signal_connect("leave_notify_event"){|wid,event| OnLeave(wid,event)}
|
71
|
+
signal_connect("key_press_event"){|wid,event| OnKeyPress(wid,event)}
|
72
|
+
signal_connect("delete_event"){|wid,event| OnDestroy(wid,event)}
|
73
|
+
add_events(Gdk::Event::EXPOSURE_MASK|
|
74
|
+
Gdk::Event::BUTTON_PRESS_MASK |
|
75
|
+
Gdk::Event::BUTTON_RELEASE_MASK |
|
76
|
+
Gdk::Event::KEY_PRESS_MASK |
|
77
|
+
Gdk::Event::POINTER_MOTION_MASK |
|
78
|
+
Gdk::Event::POINTER_MOTION_HINT_MASK |
|
79
|
+
Gdk::Event::ENTER_NOTIFY_MASK |
|
80
|
+
Gdk::Event::LEAVE_NOTIFY_MASK)
|
81
|
+
end
|
82
|
+
|
83
|
+
def GetRenderWindow
|
84
|
+
return @RenderWindow
|
85
|
+
end
|
86
|
+
|
87
|
+
def GetRenderer
|
88
|
+
@RenderWindow.GetRenderers.InitTraversal
|
89
|
+
return @RenderWindow.GetRenderers.GetNextItem
|
90
|
+
end
|
91
|
+
|
92
|
+
def SetDesiredUpdateRate(rate)
|
93
|
+
=begin
|
94
|
+
Mirrors the method with the same name in vtkRenderWindowInteractor.
|
95
|
+
=end
|
96
|
+
@DesiredUpdateRate = rate
|
97
|
+
end
|
98
|
+
|
99
|
+
def GetDesiredUpdateRate
|
100
|
+
=begin
|
101
|
+
Mirrors the method with the same name in vtkRenderWindowInteractor.
|
102
|
+
=end
|
103
|
+
return @DesiredUpdateRate
|
104
|
+
end
|
105
|
+
|
106
|
+
def SetStillUpdateRate(rate)
|
107
|
+
=begin
|
108
|
+
Mirrors the method with the same name in vtkRenderWindowInteractor.
|
109
|
+
=end
|
110
|
+
@StillUpdateRate = rate
|
111
|
+
end
|
112
|
+
|
113
|
+
def GetStillUpdateRate
|
114
|
+
=begin
|
115
|
+
Mirrors the method with the same name in vtkRenderWindowInteractor.
|
116
|
+
=end
|
117
|
+
return @StillUpdateRate
|
118
|
+
end
|
119
|
+
|
120
|
+
def Render
|
121
|
+
if @Created
|
122
|
+
@RenderWindow.Render
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def OnRealize(wid, event)
|
127
|
+
if !@Created
|
128
|
+
# you can't get the xid without the window being realized.
|
129
|
+
realize
|
130
|
+
if Config::CONFIG["host_os"] =~ /win32/
|
131
|
+
# win_id = @widget.window.handle.to_s
|
132
|
+
win_id = window.handle.to_s
|
133
|
+
else
|
134
|
+
# win_id = @widget.window.xid.to_s
|
135
|
+
win_id = window.xid.to_s
|
136
|
+
end
|
137
|
+
@RenderWindow.SetWindowInfo(win_id)
|
138
|
+
@Created = true
|
139
|
+
end
|
140
|
+
return true
|
141
|
+
end
|
142
|
+
|
143
|
+
def Created
|
144
|
+
return @Created
|
145
|
+
end
|
146
|
+
|
147
|
+
def OnConfigure(wid, event)
|
148
|
+
# @widget=widget
|
149
|
+
@RenderWindow.SetSize(event.width, event.height)
|
150
|
+
self.Render
|
151
|
+
return true
|
152
|
+
end
|
153
|
+
|
154
|
+
def OnExpose(wid, event)
|
155
|
+
self.Render
|
156
|
+
return true
|
157
|
+
end
|
158
|
+
|
159
|
+
def OnDestroy(wid, event)
|
160
|
+
self.hide
|
161
|
+
del(@RenderWindow)
|
162
|
+
self.destroy
|
163
|
+
return true
|
164
|
+
end
|
165
|
+
|
166
|
+
def OnButtonDown(wid, event)
|
167
|
+
=begin
|
168
|
+
Mouse button pressed.
|
169
|
+
=end
|
170
|
+
@RenderWindow.SetDesiredUpdateRate(@DesiredUpdateRate)
|
171
|
+
return true
|
172
|
+
end
|
173
|
+
|
174
|
+
def OnButtonUp(wid, event)
|
175
|
+
=begin
|
176
|
+
Mouse button released.
|
177
|
+
=end
|
178
|
+
@RenderWindow.SetDesiredUpdateRate(@StillUpdateRate)
|
179
|
+
return true
|
180
|
+
end
|
181
|
+
|
182
|
+
def OnMouseMove(wid, event)
|
183
|
+
=begin
|
184
|
+
Mouse has moved.
|
185
|
+
=end
|
186
|
+
return true
|
187
|
+
end
|
188
|
+
|
189
|
+
def OnEnter(wid, event)
|
190
|
+
=begin
|
191
|
+
Entering the vtkRenderWindow.
|
192
|
+
=end
|
193
|
+
return true
|
194
|
+
end
|
195
|
+
|
196
|
+
def OnLeave(wid, event)
|
197
|
+
=begin
|
198
|
+
Leaving the vtkRenderWindow.
|
199
|
+
=end
|
200
|
+
return true
|
201
|
+
end
|
202
|
+
|
203
|
+
def OnKeyPress(wid, event)
|
204
|
+
=begin
|
205
|
+
Key pressed.
|
206
|
+
=end
|
207
|
+
return true
|
208
|
+
end
|
209
|
+
|
210
|
+
def OnKeyRelease(wid, event)
|
211
|
+
=begin
|
212
|
+
"Key released."
|
213
|
+
=end
|
214
|
+
return true
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
class GtkGLExtVTKRenderWindow < GtkGLExtVTKRenderWindowBase
|
220
|
+
|
221
|
+
=begin
|
222
|
+
An example of a fully functional GtkGLExtVTKRenderWindow that
|
223
|
+
is based on the vtkRenderWidget.py provided with the VTK
|
224
|
+
sources.
|
225
|
+
=end
|
226
|
+
|
227
|
+
def initialize
|
228
|
+
super
|
229
|
+
|
230
|
+
@CurrentRenderer = nil
|
231
|
+
@CurrentCamera = nil
|
232
|
+
@CurrentZoom = 1.0
|
233
|
+
@CurrentLight = nil
|
234
|
+
|
235
|
+
@ViewportCenterX = 0
|
236
|
+
@ViewportCenterY = 0
|
237
|
+
|
238
|
+
@Picker = Vtk::CellPicker.new
|
239
|
+
@PickedAssembly = nil
|
240
|
+
@PickedProperty = Vtk::Property.new
|
241
|
+
@PickedProperty.SetColor(1, 0, 0)
|
242
|
+
@PrePickedProperty = nil
|
243
|
+
|
244
|
+
@OldFocus = nil
|
245
|
+
|
246
|
+
# these record the previous mouse position
|
247
|
+
@LastX = 0
|
248
|
+
@LastY = 0
|
249
|
+
end
|
250
|
+
|
251
|
+
def OnButtonDown(wid, event)
|
252
|
+
@RenderWindow.SetDesiredUpdateRate(@DesiredUpdateRate)
|
253
|
+
return self.StartMotion(wid, event)
|
254
|
+
return true
|
255
|
+
end
|
256
|
+
|
257
|
+
def OnButtonUp(wid, event)
|
258
|
+
@RenderWindow.SetDesiredUpdateRate(@StillUpdateRate)
|
259
|
+
return self.EndMotion(wid, event)
|
260
|
+
return true
|
261
|
+
end
|
262
|
+
|
263
|
+
def OnMouseMove(wid, event=nil)
|
264
|
+
if ((event.state & Gdk::Window::ModifierType::BUTTON1_MASK) == Gdk::Window::ModifierType::BUTTON1_MASK)
|
265
|
+
if ((event.state & Gdk::Window::ModifierType::SHIFT_MASK) == Gdk::Window::ModifierType::SHIFT_MASK)
|
266
|
+
m = self.pointer
|
267
|
+
self.Pan(m[0], m[1])
|
268
|
+
else
|
269
|
+
m = self.pointer
|
270
|
+
self.Rotate(m[0], m[1])
|
271
|
+
end
|
272
|
+
elsif ((event.state & Gdk::Window::ModifierType::BUTTON2_MASK) == Gdk::Window::ModifierType::BUTTON2_MASK)
|
273
|
+
m = self.pointer
|
274
|
+
self.Pan(m[0], m[1])
|
275
|
+
elsif ((event.state & Gdk::Window::ModifierType::BUTTON3_MASK) == Gdk::Window::ModifierType::BUTTON3_MASK)
|
276
|
+
m = self.pointer
|
277
|
+
self.Zoom(m[0], m[1])
|
278
|
+
else
|
279
|
+
return true
|
280
|
+
end
|
281
|
+
|
282
|
+
return true
|
283
|
+
end
|
284
|
+
|
285
|
+
def OnEnter(wid, event=nil)
|
286
|
+
# a render hack because grab_focus blanks the renderwin
|
287
|
+
self.grab_focus
|
288
|
+
w = self.pointer
|
289
|
+
self.UpdateRenderer(w[0], w[1])
|
290
|
+
return true
|
291
|
+
end
|
292
|
+
|
293
|
+
def OnKeyPress(wid, event=nil)
|
294
|
+
#if (event.keyval == Gdk::Keyval.from_name("q") ||
|
295
|
+
# event.keyval == Gdk::Kyval.from_name("Q")):
|
296
|
+
# Gtk.main_quit
|
297
|
+
|
298
|
+
if (event.keyval == Gdk::Keyval.from_name('r') ||
|
299
|
+
event.keyval == Gdk::Keyval.from_name('R')):
|
300
|
+
self.Reset
|
301
|
+
return true
|
302
|
+
elsif (event.keyval == Gdk::Keyval.from_name('w') ||
|
303
|
+
event.keyval == Gdk::Keyval.from_name('W')):
|
304
|
+
self.Wireframe
|
305
|
+
return true
|
306
|
+
elsif (event.keyval == Gdk::Keyval.from_name('s') ||
|
307
|
+
event.keyval == Gdk::Keyval.from_name('S')):
|
308
|
+
self.Surface
|
309
|
+
return true
|
310
|
+
elsif (event.keyval == Gdk::Keyval.from_name('p') ||
|
311
|
+
event.keyval == Gdk::Keyval.from_name('P')):
|
312
|
+
m = self.pointer
|
313
|
+
self.PickActor(m[0], m[1])
|
314
|
+
return true
|
315
|
+
else
|
316
|
+
return true
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def GetZoomFactor
|
321
|
+
return @CurrentZoom
|
322
|
+
end
|
323
|
+
|
324
|
+
def SetZoomFactor(zf)
|
325
|
+
@CurrentZoom = zf
|
326
|
+
end
|
327
|
+
|
328
|
+
def GetPicker
|
329
|
+
return @Picker
|
330
|
+
end
|
331
|
+
|
332
|
+
def Render
|
333
|
+
if (@CurrentLight)
|
334
|
+
light = @CurrentLight
|
335
|
+
light.SetPosition(@CurrentCamera.GetPosition)
|
336
|
+
light.SetFocalPoint(@CurrentCamera.GetFocalPoint)
|
337
|
+
end
|
338
|
+
|
339
|
+
super
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
def UpdateRenderer(x,y)
|
344
|
+
=begin
|
345
|
+
UpdateRenderer will identify the renderer under the mouse && set
|
346
|
+
up @CurrentRenderer, @CurrentCamera, && @CurrentLight.
|
347
|
+
=end
|
348
|
+
# windowX,windowY = self.widget.window.get_size
|
349
|
+
windowX,windowY = window.size
|
350
|
+
|
351
|
+
renderers = @RenderWindow.GetRenderers
|
352
|
+
numRenderers = renderers.GetNumberOfItems
|
353
|
+
|
354
|
+
@CurrentRenderer = nil
|
355
|
+
renderers.InitTraversal
|
356
|
+
for i in 0...numRenderers
|
357
|
+
renderer = renderers.GetNextItem
|
358
|
+
vx,vy = [0,0]
|
359
|
+
if (windowX > 1)
|
360
|
+
vx = x.to_f/(windowX-1)
|
361
|
+
end
|
362
|
+
if (windowY > 1)
|
363
|
+
vy = (windowY-y.to_f-1)/(windowY-1)
|
364
|
+
end
|
365
|
+
(vpxmin,vpymin,vpxmax,vpymax) = renderer.GetViewport
|
366
|
+
|
367
|
+
if (vx >= vpxmin && vx <= vpxmax && vy >= vpymin && vy <= vpymax)
|
368
|
+
@CurrentRenderer = renderer
|
369
|
+
@ViewportCenterX = windowX.to_f*(vpxmax-vpxmin)/2.0 +vpxmin
|
370
|
+
@ViewportCenterY = windowY.to_f*(vpymax-vpymin)/2.0 +vpymin
|
371
|
+
@CurrentCamera = @CurrentRenderer.GetActiveCamera
|
372
|
+
lights = @CurrentRenderer.GetLights
|
373
|
+
lights.InitTraversal
|
374
|
+
break if @CurrentLight = lights.GetNextItem
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
@LastX = x
|
379
|
+
@LastY = y
|
380
|
+
end
|
381
|
+
|
382
|
+
def GetCurrentRenderer
|
383
|
+
if @CurrentRenderer.nil?
|
384
|
+
renderers = @RenderWindow.GetRenderers
|
385
|
+
numRenderers = renderers.GetNumberOfItems
|
386
|
+
|
387
|
+
renderers.InitTraversal
|
388
|
+
for i in 0...numRenderers
|
389
|
+
break if renderer = renderers.GetNextItem
|
390
|
+
end
|
391
|
+
@CurrentRenderer = renderer
|
392
|
+
end
|
393
|
+
return @CurrentRenderer
|
394
|
+
end
|
395
|
+
|
396
|
+
def GetCurrentCamera
|
397
|
+
if @CurrentCamera.nil?
|
398
|
+
renderer = self.GetCurrentRenderer
|
399
|
+
@CurrentCamera = renderer.GetActiveCamera
|
400
|
+
end
|
401
|
+
return @CurrentCamera
|
402
|
+
end
|
403
|
+
|
404
|
+
def StartMotion(wid, event=nil)
|
405
|
+
x = event.x
|
406
|
+
y = event.y
|
407
|
+
self.UpdateRenderer(x,y)
|
408
|
+
return true
|
409
|
+
end
|
410
|
+
|
411
|
+
def EndMotion(wid, event=nil)
|
412
|
+
if @CurrentRenderer
|
413
|
+
self.Render
|
414
|
+
end
|
415
|
+
return true
|
416
|
+
end
|
417
|
+
|
418
|
+
def Rotate(x,y)
|
419
|
+
if @CurrentRenderer
|
420
|
+
|
421
|
+
@CurrentCamera.Azimuth(@LastX - x)
|
422
|
+
@CurrentCamera.Elevation(y - @LastY)
|
423
|
+
@CurrentCamera.OrthogonalizeViewUp
|
424
|
+
|
425
|
+
@LastX = x
|
426
|
+
@LastY = y
|
427
|
+
|
428
|
+
@CurrentRenderer.ResetCameraClippingRange
|
429
|
+
self.Render
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
def Pan(x,y)
|
434
|
+
if @CurrentRenderer
|
435
|
+
|
436
|
+
renderer = @CurrentRenderer
|
437
|
+
camera = @CurrentCamera
|
438
|
+
(pPoint0,pPoint1,pPoint2) = camera.GetPosition
|
439
|
+
(fPoint0,fPoint1,fPoint2) = camera.GetFocalPoint
|
440
|
+
|
441
|
+
if (camera.GetParallelProjection)
|
442
|
+
renderer.SetWorldPoint(fPoint0,fPoint1,fPoint2,1.0)
|
443
|
+
renderer.WorldToDisplay
|
444
|
+
fx,fy,fz = renderer.GetDisplayPoint
|
445
|
+
renderer.SetDisplayPoint(fx-x+@LastX,
|
446
|
+
fy+y-@LastY,
|
447
|
+
fz)
|
448
|
+
renderer.DisplayToWorld
|
449
|
+
fx,fy,fz,fw = renderer.GetWorldPoint
|
450
|
+
camera.SetFocalPoint(fx,fy,fz)
|
451
|
+
|
452
|
+
renderer.SetWorldPoint(pPoint0,pPoint1,pPoint2,1.0)
|
453
|
+
renderer.WorldToDisplay
|
454
|
+
fx,fy,fz = renderer.GetDisplayPoint
|
455
|
+
renderer.SetDisplayPoint(fx-x+@LastX,
|
456
|
+
fy+y-@LastY,
|
457
|
+
fz)
|
458
|
+
renderer.DisplayToWorld
|
459
|
+
fx,fy,fz,fw = renderer.GetWorldPoint
|
460
|
+
camera.SetPosition(fx,fy,fz)
|
461
|
+
|
462
|
+
else
|
463
|
+
(fPoint0,fPoint1,fPoint2) = camera.GetFocalPoint
|
464
|
+
# Specify a point location in world coordinates
|
465
|
+
renderer.SetWorldPoint(fPoint0,fPoint1,fPoint2,1.0)
|
466
|
+
renderer.WorldToDisplay
|
467
|
+
# Convert world point coordinates to display coordinates
|
468
|
+
dPoint = renderer.GetDisplayPoint
|
469
|
+
focalDepth = dPoint[2]
|
470
|
+
|
471
|
+
aPoint0 = @ViewportCenterX + (x - @LastX)
|
472
|
+
aPoint1 = @ViewportCenterY - (y - @LastY)
|
473
|
+
|
474
|
+
renderer.SetDisplayPoint(aPoint0,aPoint1,focalDepth)
|
475
|
+
renderer.DisplayToWorld
|
476
|
+
|
477
|
+
(rPoint0,rPoint1,rPoint2,rPoint3) = renderer.GetWorldPoint
|
478
|
+
if (rPoint3 != 0.0)
|
479
|
+
rPoint0 = rPoint0/rPoint3
|
480
|
+
rPoint1 = rPoint1/rPoint3
|
481
|
+
rPoint2 = rPoint2/rPoint3
|
482
|
+
end
|
483
|
+
|
484
|
+
camera.SetFocalPoint((fPoint0 - rPoint0) + fPoint0,
|
485
|
+
(fPoint1 - rPoint1) + fPoint1,
|
486
|
+
(fPoint2 - rPoint2) + fPoint2)
|
487
|
+
|
488
|
+
camera.SetPosition((fPoint0 - rPoint0) + pPoint0,
|
489
|
+
(fPoint1 - rPoint1) + pPoint1,
|
490
|
+
(fPoint2 - rPoint2) + pPoint2)
|
491
|
+
end
|
492
|
+
|
493
|
+
@LastX = x
|
494
|
+
@LastY = y
|
495
|
+
|
496
|
+
self.Render
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
def Zoom(x,y)
|
501
|
+
if @CurrentRenderer
|
502
|
+
|
503
|
+
renderer = @CurrentRenderer
|
504
|
+
camera = @CurrentCamera
|
505
|
+
|
506
|
+
zoomFactor = 1.02**(0.5*(@LastY - y))
|
507
|
+
@CurrentZoom = @CurrentZoom * zoomFactor
|
508
|
+
|
509
|
+
if camera.GetParallelProjection
|
510
|
+
parallelScale = camera.GetParallelScale/zoomFactor
|
511
|
+
camera.SetParallelScale(parallelScale)
|
512
|
+
else
|
513
|
+
camera.Dolly(zoomFactor)
|
514
|
+
renderer.ResetCameraClippingRange
|
515
|
+
end
|
516
|
+
|
517
|
+
@LastX = x
|
518
|
+
@LastY = y
|
519
|
+
|
520
|
+
self.Render
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
def Reset
|
525
|
+
if @CurrentRenderer
|
526
|
+
@CurrentRenderer.ResetCamera
|
527
|
+
end
|
528
|
+
|
529
|
+
self.Render
|
530
|
+
end
|
531
|
+
|
532
|
+
def Wireframe
|
533
|
+
actors = @CurrentRenderer.GetActors
|
534
|
+
numActors = actors.GetNumberOfItems
|
535
|
+
actors.InitTraversal
|
536
|
+
for i in 0...numActors
|
537
|
+
actor = actors.GetNextItem
|
538
|
+
actor.GetProperty.SetRepresentationToWireframe
|
539
|
+
end
|
540
|
+
|
541
|
+
self.Render
|
542
|
+
end
|
543
|
+
|
544
|
+
def Surface
|
545
|
+
actors = @CurrentRenderer.GetActors
|
546
|
+
numActors = actors.GetNumberOfItems
|
547
|
+
actors.InitTraversal
|
548
|
+
for i in 0...numActors
|
549
|
+
actor = actors.GetNextItem
|
550
|
+
actor.GetProperty.SetRepresentationToSurface
|
551
|
+
end
|
552
|
+
|
553
|
+
self.Render
|
554
|
+
end
|
555
|
+
|
556
|
+
def PickActor(x,y)
|
557
|
+
if @CurrentRenderer
|
558
|
+
|
559
|
+
renderer = @CurrentRenderer
|
560
|
+
picker = @Picker
|
561
|
+
|
562
|
+
windowX,windowY = window.size
|
563
|
+
# windowX,windowY = self.widget.window.get_size
|
564
|
+
picker.Pick(x,(windowY - y - 1),0.0,renderer)
|
565
|
+
assembly = picker.GetAssembly
|
566
|
+
|
567
|
+
if (@PickedAssembly != nil && @PrePickedProperty != nil)
|
568
|
+
@PickedAssembly.SetProperty(@PrePickedProperty)
|
569
|
+
# release hold of the property
|
570
|
+
@PrePickedProperty.UnRegister(@PrePickedProperty)
|
571
|
+
@PrePickedProperty = nil
|
572
|
+
end
|
573
|
+
|
574
|
+
if (assembly != nil)
|
575
|
+
@PickedAssembly = assembly
|
576
|
+
@PrePickedProperty = @PickedAssembly.GetProperty
|
577
|
+
# hold onto the property
|
578
|
+
@PrePickedProperty.Register(@PrePickedProperty)
|
579
|
+
@PickedAssembly.SetProperty(@PickedProperty)
|
580
|
+
end
|
581
|
+
|
582
|
+
self.Render
|
583
|
+
end
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
|
588
|
+
def main
|
589
|
+
|
590
|
+
Gtk.init
|
591
|
+
Gtk::GL.init
|
592
|
+
|
593
|
+
# The main window
|
594
|
+
window = Gtk::Window.new
|
595
|
+
window.set_title("A GtkGLExtVTKRenderWindow Demo!")
|
596
|
+
window.signal_connect("destroy"){ Gtk.main_quit }
|
597
|
+
window.signal_connect("delete_event"){ Gtk.main_quit }
|
598
|
+
window.set_border_width(10)
|
599
|
+
|
600
|
+
vtkgtk = GtkGLExtVTKRenderWindow.new
|
601
|
+
vtkgtk.show
|
602
|
+
|
603
|
+
vbox = Gtk::VBox.new(false, 3)
|
604
|
+
vbox.show
|
605
|
+
vbox.pack_start(vtkgtk)
|
606
|
+
|
607
|
+
button = Gtk::Button.new('My Button')
|
608
|
+
button.show
|
609
|
+
vbox.pack_start(button)
|
610
|
+
window.add(vbox)
|
611
|
+
|
612
|
+
window.set_size_request(400, 400)
|
613
|
+
|
614
|
+
# The VTK stuff.
|
615
|
+
cone = Vtk::ConeSource.new
|
616
|
+
cone.SetResolution(80)
|
617
|
+
coneMapper = Vtk::PolyDataMapper.new
|
618
|
+
coneMapper.SetInput(cone.GetOutput)
|
619
|
+
#coneActor = Vtk::LODActor.new
|
620
|
+
coneActor = Vtk::Actor.new
|
621
|
+
coneActor.SetMapper(coneMapper)
|
622
|
+
coneActor.GetProperty.SetColor(0.5, 0.5, 1.0)
|
623
|
+
ren = Vtk::Renderer.new
|
624
|
+
vtkgtk.GetRenderWindow.AddRenderer(ren)
|
625
|
+
ren.AddActor(coneActor)
|
626
|
+
|
627
|
+
# show the main window && start event processing.
|
628
|
+
window.show
|
629
|
+
Gtk.main
|
630
|
+
end
|
631
|
+
|
632
|
+
|
633
|
+
if $0 == __FILE__
|
634
|
+
main
|
635
|
+
end
|