disp3D 0.2.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.md +56 -0
- data/VERSION +1 -1
- data/disp3D.gemspec +24 -20
- data/example/stl_viewer/document_ctrl.rb +2 -2
- data/example/stl_viewer/qt_widget_controller.rb +3 -7
- data/example/tutorial/03_CameraScene.rb +5 -5
- data/example/tutorial/04_Qt.rb +4 -4
- data/example/tutorial/05_Pick.rb +13 -13
- data/example/tutorial/06_FileParser.rb +3 -3
- data/example/tutorial/07_SceneGraph.rb +16 -4
- data/example/tutorial/08_SceneGraph2.rb +16 -15
- data/example/tutorial/09_Texture.rb +28 -0
- data/example/tutorial/10_Animation.rb +27 -0
- data/example/tutorial/10_AnimationQt.rb +53 -0
- data/example/tutorial/11_MultiView.rb +41 -0
- data/example/tutorial/12_Light.rb +65 -0
- data/example/tutorial/13_RectPick.rb +38 -0
- data/example/tutorial/14_LineRubberband.rb +43 -0
- data/example/{test → tutorial}/data/test.png +0 -0
- data/example/{test → tutorial}/data/test2.jpg +0 -0
- data/lib/camera.rb +8 -0
- data/lib/compass.rb +21 -14
- data/lib/disp3D.rb +3 -0
- data/lib/gl_view.rb +70 -40
- data/lib/glut_window.rb +24 -18
- data/lib/light.rb +35 -21
- data/lib/manipulator.rb +0 -7
- data/lib/node/node.rb +100 -105
- data/lib/node/node_arrows.rb +1 -1
- data/lib/node/node_collection.rb +63 -17
- data/lib/node/node_cone.rb +49 -0
- data/lib/node/node_coord.rb +26 -11
- data/lib/node/node_leaf.rb +17 -11
- data/lib/node/node_lines.rb +1 -1
- data/lib/node/node_points.rb +2 -1
- data/lib/node/node_polylines.rb +1 -1
- data/lib/node/node_rectangle.rb +9 -4
- data/lib/node/node_sphere.rb +28 -0
- data/lib/node/node_tea_pod.rb +4 -4
- data/lib/node/node_text.rb +2 -2
- data/lib/node/node_tris.rb +1 -1
- data/lib/node/node_workplane.rb +33 -1
- data/lib/picker.rb +157 -3
- data/lib/qt_widget_gl.rb +24 -11
- data/lib/scene_graph.rb +3 -3
- data/test/node/test_node.rb +230 -0
- data/test/node/test_node_collection.rb +99 -79
- data/test/test_picker.rb +6 -6
- metadata +28 -24
- data/README.rdoc +0 -63
- data/example/test/capture_test.rb +0 -16
- data/example/test/dsl_test.rb +0 -46
- data/example/test/texture_test.rb +0 -39
- data/test/data/binary_test.stl +0 -0
- data/test/data/bunny-flatfoot.stl +0 -0
data/lib/qt_widget_gl.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
+
require 'forwardable'
|
1
2
|
require 'Qt'
|
2
3
|
require 'disp3D'
|
3
4
|
|
4
5
|
include Disp3D
|
5
6
|
class QtWidgetGL < Qt::GLWidget
|
7
|
+
extend Forwardable
|
8
|
+
|
6
9
|
attr_accessor :width
|
7
10
|
attr_accessor :height
|
8
11
|
|
9
12
|
attr_reader :load_proc
|
10
13
|
|
14
|
+
def_delegators :@view, :camera, :world_scene_graph, :camera_scene_graph
|
15
|
+
def_delegators :@view, :manipulator, :light, :picker
|
16
|
+
def_delegators :@view, :sync_to, :capture, :fit, :centering
|
17
|
+
|
11
18
|
def initialize(parent, width = 400, height = 400)
|
12
19
|
super(parent)
|
13
20
|
@width = width
|
@@ -21,10 +28,6 @@ class QtWidgetGL < Qt::GLWidget
|
|
21
28
|
super
|
22
29
|
end
|
23
30
|
|
24
|
-
def gl_view
|
25
|
-
@view
|
26
|
-
end
|
27
|
-
|
28
31
|
def set_load_proc(proc)
|
29
32
|
@load_proc = proc
|
30
33
|
end
|
@@ -49,18 +52,17 @@ class QtWidgetGL < Qt::GLWidget
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def mouseReleaseEvent(event)
|
52
|
-
|
53
|
-
@view.
|
55
|
+
glut_button = get_GLUT_button(event)
|
56
|
+
@view.mouse_release_process(glut_button, event.pos.x, event.pos.y)
|
54
57
|
end
|
55
58
|
|
56
59
|
def mousePressEvent(event)
|
57
|
-
|
58
|
-
@view.
|
60
|
+
glut_button = get_GLUT_button(event)
|
61
|
+
@view.mouse_press_process(glut_button, event.pos.x, event.pos.y)
|
59
62
|
end
|
60
63
|
|
61
64
|
def mouseMoveEvent(event)
|
62
|
-
@view.
|
63
|
-
need_update = @view.manipulator.motion(event.pos.x,event.pos.y)
|
65
|
+
need_update = @view.mouse_move_process(event.pos.x,event.pos.y)
|
64
66
|
if(need_update)
|
65
67
|
updateGL()
|
66
68
|
end
|
@@ -71,7 +73,18 @@ class QtWidgetGL < Qt::GLWidget
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def resizeGL(width, height)
|
74
|
-
@view.
|
76
|
+
@view.reshape(width, height)
|
77
|
+
end
|
78
|
+
|
79
|
+
def idle_process(wait_msec = nil, &block)
|
80
|
+
@idle_proc = block
|
81
|
+
@idle_process_timer_id = startTimer(wait_msec)
|
82
|
+
end
|
83
|
+
|
84
|
+
def timerEvent(event)
|
85
|
+
if( event.timerId == @idle_process_timer_id)
|
86
|
+
@idle_proc.call
|
87
|
+
end
|
75
88
|
end
|
76
89
|
end
|
77
90
|
|
data/lib/scene_graph.rb
CHANGED
data/test/node/test_node.rb
CHANGED
@@ -17,6 +17,236 @@ class NodeTestCase < MiniTest::Unit::TestCase
|
|
17
17
|
assert_equal(nil, node.post_translate)
|
18
18
|
|
19
19
|
assert_equal([], node.parents)
|
20
|
+
|
21
|
+
assert_equal(nil, node.name)
|
22
|
+
assert(node.instance_id.kind_of?(Integer))
|
23
|
+
|
24
|
+
node_with_name = Disp3D::Node.new(:node00)
|
25
|
+
assert_equal(:node00, node_with_name.name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_ancestor
|
29
|
+
node_group = Disp3D::NodeCollection.new()
|
30
|
+
node_group.open do
|
31
|
+
add_new :type => :Points, :geom => Vector3.new(), :name => :node01
|
32
|
+
add_new :type => :TeaPod, :name => :node02
|
33
|
+
add_new :type => :Text, :geom => Vector3.new(), :name => :node03
|
34
|
+
add_new :name => :node04 do
|
35
|
+
add_new :type => :Coord, :name => :node05
|
36
|
+
add_new :name => :node06 do
|
37
|
+
add_new :type => :Points, :geom => Vector3.new(), :name => :node07
|
38
|
+
add :node01
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
add_new :name => :node08 do
|
43
|
+
add :node02
|
44
|
+
add :node07
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
root_id = node_group.instance_id
|
49
|
+
node04_id = Disp3D::NodeDB.find_by_name(:node04).instance_id
|
50
|
+
node06_id = Disp3D::NodeDB.find_by_name(:node06).instance_id
|
51
|
+
node08_id = Disp3D::NodeDB.find_by_name(:node08).instance_id
|
52
|
+
|
53
|
+
assert_equal([root_id, node04_id, node06_id].sort , Disp3D::NodeDB.find_by_name(:node01).ancestors.sort)
|
54
|
+
assert_equal([root_id, node08_id].sort , Disp3D::NodeDB.find_by_name(:node02).ancestors.sort)
|
55
|
+
assert_equal([root_id].sort , Disp3D::NodeDB.find_by_name(:node03).ancestors.sort)
|
56
|
+
assert_equal([root_id, node04_id].sort , Disp3D::NodeDB.find_by_name(:node05).ancestors.sort)
|
57
|
+
assert_equal([root_id, node04_id, node06_id, node08_id].sort, Disp3D::NodeDB.find_by_name(:node07).ancestors.sort)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_create_and_update
|
61
|
+
node_group = Disp3D::NodeCollection.new()
|
62
|
+
# create test
|
63
|
+
node_group.open do
|
64
|
+
create :type => :TeaPod,
|
65
|
+
:size => 0.5,
|
66
|
+
:name => :node10
|
67
|
+
|
68
|
+
create :type => :Points,
|
69
|
+
:geom => Vector3.new(),
|
70
|
+
:size => 10.0,
|
71
|
+
:name => :node11,
|
72
|
+
:pre_translate => Vector3.new(1,0,1),
|
73
|
+
:post_translate => Vector3.new(1,0,1),
|
74
|
+
:rotate => Quat.from_axis(Vector3.new(1,0,0), Math::PI)
|
75
|
+
|
76
|
+
create :type => :Text,
|
77
|
+
:geom => Vector3.new(),
|
78
|
+
:name => :node12,
|
79
|
+
:text => "this is node12"
|
80
|
+
|
81
|
+
create :type => :Collection,
|
82
|
+
:name => :node13,
|
83
|
+
:pre_translate => Vector3.new(1,0,1),
|
84
|
+
:post_translate => Vector3.new(1,0,1),
|
85
|
+
:rotate => Quat.from_axis(Vector3.new(1,0,0), Math::PI)
|
86
|
+
|
87
|
+
create :type => :Points,
|
88
|
+
:geom => Vector3.new,
|
89
|
+
:name => :node14,
|
90
|
+
:colors => [1,1,0,1]
|
91
|
+
|
92
|
+
create :type => :Lines,
|
93
|
+
:geom => FiniteLine.new,
|
94
|
+
:name => :node14,
|
95
|
+
:colors => [1,1,0,1]
|
96
|
+
end
|
97
|
+
|
98
|
+
node10 = Disp3D::NodeDB.find_by_name(:node10)
|
99
|
+
assert_equal( Disp3D::NodeTeaPod, node10.class)
|
100
|
+
assert_equal( 0.5, node10.size)
|
101
|
+
|
102
|
+
node11 = Disp3D::NodeDB.find_by_name(:node11)
|
103
|
+
assert_equal( Disp3D::NodePoints, node11.class)
|
104
|
+
# assert_equal( Vector3.new, node11.geom)
|
105
|
+
assert_equal( 10.0, node11.size)
|
106
|
+
assert_equal( Vector3.new(1,0,1), node11.pre_translate)
|
107
|
+
assert_equal( Vector3.new(1,0,1), node11.post_translate)
|
108
|
+
assert_equal( Quat.from_axis(Vector3.new(1,0,0), Math::PI), node11.rotate)
|
109
|
+
|
110
|
+
node12 = Disp3D::NodeDB.find_by_name(:node12)
|
111
|
+
assert_equal( Disp3D::NodeText, node12.class)
|
112
|
+
assert_equal( "this is node12", node12.text )
|
113
|
+
|
114
|
+
node13 = Disp3D::NodeDB.find_by_name(:node13)
|
115
|
+
assert_equal( Disp3D::NodeCollection, node13.class)
|
116
|
+
assert_equal( Vector3.new(1,0,1), node13.pre_translate)
|
117
|
+
assert_equal( Vector3.new(1,0,1), node13.post_translate)
|
118
|
+
assert_equal( Quat.from_axis(Vector3.new(1,0,0), Math::PI), node13.rotate)
|
119
|
+
|
120
|
+
node14 = Disp3D::NodeDB.find_by_name(:node14)
|
121
|
+
assert_equal( Array, node14.class)
|
122
|
+
node14.each do |node|
|
123
|
+
assert_equal( :node14, node.name)
|
124
|
+
assert_equal( [1,1,0,1], node.colors)
|
125
|
+
assert( [Disp3D::NodePoints, Disp3D::NodeLines].include?(node.class) )
|
126
|
+
end
|
127
|
+
|
128
|
+
# update test
|
129
|
+
node_group.open do
|
130
|
+
update :name => :node10,
|
131
|
+
:size => 2.0
|
132
|
+
|
133
|
+
update :name => :node11,
|
134
|
+
:size => 4.0,
|
135
|
+
:geom => Vector3.new(3,2,1),
|
136
|
+
:pre_translate => Vector3.new(1,2,3),
|
137
|
+
:post_translate => Vector3.new(1,2,3),
|
138
|
+
:rotate => Quat.from_axis(Vector3.new(0,1,0), Math::PI/2.0)
|
139
|
+
|
140
|
+
update :name => :node12,
|
141
|
+
:geom => Vector3.new(),
|
142
|
+
:text => "this is node12 updated"
|
143
|
+
|
144
|
+
update :name => :node13,
|
145
|
+
:pre_translate => Vector3.new(3,2,1),
|
146
|
+
:post_translate => Vector3.new(3,2,-1),
|
147
|
+
:rotate => Quat.from_axis(Vector3.new(0,0,1), Math::PI)
|
148
|
+
|
149
|
+
update :name => :node14,
|
150
|
+
:colors => [0,1,1,1]
|
151
|
+
end
|
152
|
+
|
153
|
+
node10 = Disp3D::NodeDB.find_by_name(:node10)
|
154
|
+
assert_equal( Disp3D::NodeTeaPod, node10.class)
|
155
|
+
assert_equal( 2.0, node10.size)
|
156
|
+
|
157
|
+
node11 = Disp3D::NodeDB.find_by_name(:node11)
|
158
|
+
assert_equal( Disp3D::NodePoints, node11.class)
|
159
|
+
assert_equal( 4.0, node11.size)
|
160
|
+
assert_equal( Vector3.new(1,2,3), node11.pre_translate)
|
161
|
+
assert_equal( Vector3.new(1,2,3), node11.post_translate)
|
162
|
+
assert_equal( Quat.from_axis(Vector3.new(0,1,0), Math::PI/2.0), node11.rotate)
|
163
|
+
|
164
|
+
node12 = Disp3D::NodeDB.find_by_name(:node12)
|
165
|
+
assert_equal( Disp3D::NodeText, node12.class)
|
166
|
+
assert_equal( "this is node12 updated", node12.text )
|
167
|
+
|
168
|
+
node13 = Disp3D::NodeDB.find_by_name(:node13)
|
169
|
+
assert_equal( Disp3D::NodeCollection, node13.class)
|
170
|
+
assert_equal( Vector3.new(3,2,1), node13.pre_translate)
|
171
|
+
assert_equal( Vector3.new(3,2,-1), node13.post_translate)
|
172
|
+
assert_equal( Quat.from_axis(Vector3.new(0,0,1), Math::PI), node13.rotate)
|
173
|
+
|
174
|
+
node14 = Disp3D::NodeDB.find_by_name(:node14)
|
175
|
+
assert_equal( Array, node14.class)
|
176
|
+
node14.each do |node|
|
177
|
+
assert_equal( :node14, node.name)
|
178
|
+
assert_equal( [0,1,1,1], node.colors)
|
179
|
+
assert( [Disp3D::NodePoints, Disp3D::NodeLines].include?(node.class) )
|
180
|
+
end
|
20
181
|
end
|
21
182
|
|
183
|
+
def test_box_trans_form
|
184
|
+
node = Disp3D::Node.new
|
185
|
+
box = Box.new
|
186
|
+
box_org = box.clone
|
187
|
+
|
188
|
+
node_group = Disp3D::NodeCollection.new
|
189
|
+
node_group.pre_translate = Vector3.new(1,1,1)
|
190
|
+
node_group.open do
|
191
|
+
box = box_transform(box_org)
|
192
|
+
end
|
193
|
+
assert_equal(box_org.translate(Vector3.new(1,1,1)), box)
|
194
|
+
|
195
|
+
rotate_quat = Quat.from_axis( Vector3.new(1,0,0), 45.0/180.0*Math::PI )
|
196
|
+
node_group.rotate = rotate_quat
|
197
|
+
node_group.open do
|
198
|
+
box = box_transform(box_org)
|
199
|
+
end
|
200
|
+
assert_equal(box_org.translate(Vector3.new(1,1,1)).rotate(rotate_quat), box)
|
201
|
+
|
202
|
+
node_group.post_translate = Vector3.new(-1,-1,-1)
|
203
|
+
node_group.open do
|
204
|
+
box = box_transform(box_org)
|
205
|
+
end
|
206
|
+
assert_equal(box_org.translate(Vector3.new(1,1,1)).rotate(rotate_quat).translate(Vector3.new(-1,-1,-1)), box)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_delete
|
210
|
+
node_group = Disp3D::NodeCollection.new()
|
211
|
+
node_group.open do
|
212
|
+
create :type => :TeaPod,
|
213
|
+
:name => :node20
|
214
|
+
|
215
|
+
create :type => :Points,
|
216
|
+
:geom => Vector3.new(),
|
217
|
+
:name => :node21
|
218
|
+
|
219
|
+
create :type => :Text,
|
220
|
+
:geom => Vector3.new(),
|
221
|
+
:name => :node22
|
222
|
+
|
223
|
+
create :type => :Collection,
|
224
|
+
:name => :node23
|
225
|
+
|
226
|
+
create :type => :Coord,
|
227
|
+
:name => :node23 # same name
|
228
|
+
|
229
|
+
add :node20
|
230
|
+
add :node21
|
231
|
+
add :node23
|
232
|
+
end
|
233
|
+
assert_equal( 4, node_group.child_nodes.size)
|
234
|
+
assert_equal( Disp3D::NodeTeaPod, Disp3D::NodeDB.find_by_name(:node20).class)
|
235
|
+
node_ary = Disp3D::NodeDB.find_by_name(:node23)
|
236
|
+
assert_equal( Array, node_ary.class)
|
237
|
+
assert( node_ary.find { |node| node.class == Disp3D::NodeCollection })
|
238
|
+
assert( node_ary.find { |node| node.class == Disp3D::NodeCoord })
|
239
|
+
|
240
|
+
node_group.open do
|
241
|
+
delete :node20
|
242
|
+
end
|
243
|
+
assert_equal( 3, node_group.child_nodes.size)
|
244
|
+
assert_equal( nil, Disp3D::NodeDB.find_by_name(:node20))
|
245
|
+
|
246
|
+
node_group.open do
|
247
|
+
delete :node23
|
248
|
+
end
|
249
|
+
assert_equal( 1, node_group.child_nodes.size)
|
250
|
+
assert_equal( nil, Disp3D::NodeDB.find_by_name(:node23))
|
251
|
+
end
|
22
252
|
end
|
@@ -11,100 +11,120 @@ class NodeCollectionTestCase < MiniTest::Unit::TestCase
|
|
11
11
|
@gl_view = Disp3D::GLUTWindow.new(300, 300)
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
added_id = node_collection.add(node_point)
|
14
|
+
def test_add
|
15
|
+
node_group = Disp3D::NodeCollection.new()
|
16
|
+
|
18
17
|
node_ary = Array.new()
|
19
|
-
node_ary[0] = Disp3D::NodeTeaPod.new(
|
18
|
+
node_ary[0] = Disp3D::NodeTeaPod.new()
|
20
19
|
node_ary[1] = Disp3D::NodeLines.new(FiniteLine.new(Vector3.new(0,0,0),Vector3.new(1,1,1)))
|
21
|
-
added_id_ary = node_collection.add(node_ary)
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
path_id = -1
|
22
|
+
path_id_ary = -1
|
23
|
+
node_group.open do
|
24
|
+
create :type => :Points,
|
25
|
+
:geom => Vector3.new(),
|
26
|
+
:name => :node100
|
27
|
+
|
28
|
+
path_id = add :node100
|
29
|
+
path_id_ary = add node_ary
|
28
30
|
end
|
29
|
-
assert_equal(node_ary[0], node_collection.child(added_id_ary[0]))
|
30
|
-
assert_equal(node_ary[1], node_collection.child(added_id_ary[1]))
|
31
|
-
assert_equal(nil, node_collection.child(-1))
|
32
|
-
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
assert_equal(1,
|
42
|
-
|
43
|
-
|
44
|
-
ancestors = node_g_child.ancestors
|
45
|
-
assert_equal(2,ancestors.size)
|
46
|
-
assert(ancestors.include?(node_root.instance_id))
|
47
|
-
assert(ancestors.include?(node_child.instance_id))
|
48
|
-
|
49
|
-
node_root.add(node_g_child)
|
50
|
-
ancestors = node_g_child.ancestors
|
51
|
-
assert_equal(2,ancestors.size)
|
52
|
-
assert(ancestors.include?(node_root.instance_id))
|
53
|
-
assert(ancestors.include?(node_child.instance_id))
|
54
|
-
|
55
|
-
node_root.add(node_child)
|
56
|
-
ancestors = node_g_child.ancestors
|
57
|
-
assert_equal(2,ancestors.size)
|
58
|
-
assert(ancestors.include?(node_root.instance_id))
|
59
|
-
assert(ancestors.include?(node_child.instance_id))
|
60
|
-
|
61
|
-
node_g_child2 = Disp3D::NodeCollection.new()
|
62
|
-
node_child.add(node_g_child2)
|
63
|
-
ancestors = node_g_child2.ancestors
|
64
|
-
assert_equal(2,ancestors.size)
|
65
|
-
assert(ancestors.include?(node_root.instance_id))
|
66
|
-
assert(ancestors.include?(node_child.instance_id))
|
67
|
-
|
68
|
-
node_gg_child = Disp3D::NodeCollection.new()
|
69
|
-
node_g_child.add(node_gg_child)
|
70
|
-
ancestors = node_gg_child.ancestors
|
71
|
-
assert_equal(3,ancestors.size)
|
72
|
-
assert(ancestors.include?(node_root.instance_id))
|
73
|
-
assert(ancestors.include?(node_child.instance_id))
|
74
|
-
assert(ancestors.include?(node_g_child.instance_id))
|
75
|
-
|
76
|
-
node_g_child2.add(node_gg_child)
|
77
|
-
ancestors = node_gg_child.ancestors
|
78
|
-
assert_equal(4,ancestors.size)
|
79
|
-
assert(ancestors.include?(node_root.instance_id))
|
80
|
-
assert(ancestors.include?(node_child.instance_id))
|
81
|
-
assert(ancestors.include?(node_g_child.instance_id))
|
82
|
-
assert(ancestors.include?(node_g_child2.instance_id))
|
32
|
+
assert(node_group.include?(path_id))
|
33
|
+
assert_equal(Disp3D::NodeDB.find_by_name(:node100), node_group.child(path_id))
|
34
|
+
assert_equal(2, path_id_ary.size)
|
35
|
+
path_id_ary.each do |item|
|
36
|
+
assert(node_group.include?(item))
|
37
|
+
end
|
38
|
+
assert_equal(node_ary[0], node_group.child(path_id_ary[0]))
|
39
|
+
assert_equal(node_ary[1], node_group.child(path_id_ary[1]))
|
40
|
+
assert_equal(nil, node_group.child(-1))
|
83
41
|
end
|
84
42
|
|
85
|
-
def test_circular_reference
|
86
|
-
node_collection1 = Disp3D::NodeCollection.new()
|
87
|
-
node_collection2 = Disp3D::NodeCollection.new()
|
88
|
-
node_collection3 = Disp3D::NodeCollection.new()
|
89
|
-
node_collection1.add(node_collection2)
|
90
|
-
node_collection2.add(node_collection3)
|
91
43
|
|
92
|
-
|
44
|
+
def test_circular_reference
|
93
45
|
assert_raises Disp3D::CircularReferenceException do
|
94
|
-
|
46
|
+
Disp3D::NodeCollection.new().open do
|
47
|
+
add_new :name => :node101 do
|
48
|
+
add_new :name => :node102 do
|
49
|
+
add :node101
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
95
53
|
end
|
96
|
-
# @gl_view.world_scene_graph.add(node_collection1)
|
97
|
-
# @gl_view.gl_display()
|
98
54
|
end
|
99
55
|
|
100
56
|
def test_self_reference
|
101
|
-
node_collection1 = Disp3D::NodeCollection.new()
|
102
57
|
assert_raises Disp3D::CircularReferenceException do
|
103
|
-
|
58
|
+
Disp3D::NodeCollection.new().open do
|
59
|
+
add_new :name => :node111 do
|
60
|
+
add :node111
|
61
|
+
end
|
62
|
+
end
|
104
63
|
end
|
105
64
|
end
|
106
65
|
|
107
|
-
def
|
66
|
+
def test_add_new
|
67
|
+
# test add_new
|
68
|
+
node_group = Disp3D::NodeCollection.new()
|
69
|
+
node_group.open do
|
70
|
+
add_new :type => :TeaPod,
|
71
|
+
:size => 0.5,
|
72
|
+
:name => :node120
|
73
|
+
|
74
|
+
add_new :type => :Points,
|
75
|
+
:geom => Vector3.new(),
|
76
|
+
:size => 10.0,
|
77
|
+
:name => :node121,
|
78
|
+
:pre_translate => Vector3.new(1,0,1),
|
79
|
+
:post_translate => Vector3.new(1,0,1),
|
80
|
+
:rotate => Quat.from_axis(Vector3.new(1,0,0), Math::PI)
|
81
|
+
|
82
|
+
add_new :type => :Text,
|
83
|
+
:geom => Vector3.new(),
|
84
|
+
:name => :node122,
|
85
|
+
:text => "this is node12"
|
86
|
+
|
87
|
+
add_new :name => :node123, :post_translate => Vector3.new(1,0,1) do
|
88
|
+
add :node120
|
89
|
+
add_new :type => :Arrows,
|
90
|
+
:geom => FiniteLine.new(Vector3.new(), Vector3.new(1,2,3)),
|
91
|
+
:name => :node124
|
92
|
+
end
|
93
|
+
end
|
94
|
+
assert_equal(4, node_group.child_nodes.size)
|
95
|
+
childe_nodes_name_ary = node_group.child_nodes.collect{ |node| node.name }
|
96
|
+
assert_equal([:node120, :node121, :node122, :node123].sort,childe_nodes_name_ary.sort)
|
97
|
+
child_group_node = node_group.child_nodes.find{ |node| node.class == Disp3D::NodeCollection }
|
98
|
+
assert_equal(2, child_group_node.child_nodes.size)
|
99
|
+
childe_nodes_name_ary = child_group_node.child_nodes.collect{ |node| node.name }
|
100
|
+
assert_equal([:node120, :node124].sort,childe_nodes_name_ary.sort)
|
101
|
+
|
102
|
+
# remove test
|
103
|
+
|
104
|
+
# path id DB is created by drawing
|
105
|
+
@gl_view.world_scene_graph.add(node_group)
|
106
|
+
@gl_view.world_scene_graph.gl_display @gl_view
|
107
|
+
|
108
|
+
path_id_120_1 = node_group.child_path_id.find{ |path_id| node_group.child(path_id).name == :node120}
|
109
|
+
path_id_120_2 = child_group_node.child_path_id.find{ |path_id| child_group_node.child(path_id).name == :node120}
|
110
|
+
node_group.open do
|
111
|
+
remove path_id_120_1
|
112
|
+
end
|
113
|
+
assert_equal(3, node_group.child_nodes.size)
|
114
|
+
assert_equal(2, child_group_node.child_nodes.size)
|
115
|
+
|
116
|
+
node_group.open do
|
117
|
+
remove path_id_120_2
|
118
|
+
end
|
119
|
+
assert_equal(3, node_group.child_nodes.size)
|
120
|
+
assert_equal(1, child_group_node.child_nodes.size)
|
121
|
+
|
122
|
+
node = Disp3D::NodeDB.find_by_name(:node120)
|
123
|
+
assert_equal(Disp3D::NodeTeaPod, node.class)
|
124
|
+
assert_equal(0.5, node.size)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_boundary_box
|
108
128
|
box_geom = Box.new(Vector3.new(-1,-1,-1), Vector3.new(1,1,1))
|
109
129
|
box_node = Disp3D::NodeTris.new(TriMesh.from_box(box_geom))
|
110
130
|
bb = box_node.box
|
@@ -138,7 +158,7 @@ class NodeCollectionTestCase < MiniTest::Unit::TestCase
|
|
138
158
|
|
139
159
|
node_collection.rotate = Quat.from_axis(Vector3.new(1,0,0), angle_45)
|
140
160
|
bb = node_collection.box
|
141
|
-
assert_equal(Vector3.new(0,
|
142
|
-
assert_equal(Vector3.new(2,
|
161
|
+
assert_equal(Vector3.new(0, -Math.sqrt(2), 0), bb.min_point)
|
162
|
+
assert_equal(Vector3.new(2, Math.sqrt(2), 2*Math.sqrt(2),), bb.max_point)
|
143
163
|
end
|
144
164
|
end
|