8000 Added clear_scene() to Grid class. Tests required (once grid_updating… · NickNgHK/robotics-toolbox-python@57c3854 · GitHub
[go: up one dir, main page]

Skip to content

Commit 57c3854

Browse files
committed
Added clear_scene() to Grid class. Tests required (once grid_updating optimised).
1 parent e145bd9 commit 57c3854

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

graphics/graphics_grid.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def draw_grid(self):
2121
num_squares = 10 # Length of the grid in each direction (in units)
2222
relative_cam = True # Whether the grid follows the camera rotation and movement
2323

24-
the_grid = self.create_grid(relative_cam, num_squares)
24+
the_grid = self.__create_grid(relative_cam, num_squares)
2525
self.grid_object[0] = the_grid
2626

2727
# Update the labels instead of recreating them
2828
create_grid_numbers(self.grid_object[1], relative_cam, num_squares)
2929

30-
def create_grid(self, bool_camera_relative, num_squares):
30+
def __create_grid(self, bool_camera_relative, num_squares):
3131
"""
3232
Draw a grid along each 3D plane, that is closest to the camera.
3333
@@ -171,6 +171,30 @@ def set_visibility(self, is_visible):
171171
# TODO this will need to be uncommented once grid_object reuse is done
172172
#for number in self.grid_object[1]:
173173
# number.visible = is_visible
174+
175+
def clear_scene(self):
176+
"""
177+
Clear the canvas of all objects (keeping the grid)
178+
179+
Due to how VPython operates, there is no 'deletion' of objects directly.
180+
To 'delete' objects, first they must be rendered invisible.
181+
182+
Then: if a new object with the same variable name is used, the previous memory will be freed.
183+
Or: del variable_name will free its memory.
184+
If the object wasn't invisible, it would remain visible in the scene.
185+
186+
Since the scene doesnt track variable names, the best way to clear the scene is to render all objects invisible,
187+
and have the user assume they are all deleted. However, all objects can be redisplayed by setting the visibility
188+
"""
189+
# Save current grid visibility
190+
grid_visibility = self.grid_object[0].visible
191+
192+
# Set all objects invisible
193+
for scene_object in scene.objects:
194+
scene_object.visible = False
195+
196+
# Set grid visibility to previous
197+
self.set_visibility(grid_visibility)
174198

175199

176200
def create_line(pos1, pos2):

tests/graphics_test_features.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
These functions are not ordinary testing functions.
33
These tests cannot be automated, and must be manually validated.
44
5-
To execute, import all from this file into the console. "from graphics.graphics_test_features import *"
5+
To execute, import all from this file into the console. "from tests.graphics_test_features import *"
66
Next select which test you which to run, and call the function.
77
A canvas will be created and display the respective graphics.
88
Verify the output is as expected.
@@ -139,6 +139,15 @@ def test_puma560_angle_change():
139139
puma560.print_joint_angles(True)
140140

141141

142+
def test_clear_scene():
143+
the_grid = init_canvas()
144+
puma560 = import_puma_560()
145+
puma560.move_base(vector(1, 1, 0))
146+
sleep(2)
147+
the_grid.clear_scene()
148+
del puma560
149+
150+
142151
def test_animate_joints():
143152
pass
144153

0 commit comments

Comments
 (0)
0