Commits

German Larrain committed 62403fa Merge

Merge with dev

Comments (0)

Files changed (4)

ars/graphics/__init__.py

 	__metaclass__ = ABCMeta
 
 	@abstractmethod
-	def __init__(self, pos=(0,0,0), cylinder_radius=0.05):
+	def __init__(self, pos=(0, 0, 0), rot=None, cylinder_radius=0.05):
 		self._actor = None
 
 	@property
 	def update_position_rotation(self, pos, rot):
 		self._position = pos
 		self._rotation = rot
-		self.adapter._update_body(self._actor, pos, rot)
+		self.adapter._update_pose(self._actor, pos, rot)
 
 	@property
 	def actor(self):
 
 	@staticmethod
 	@abstractmethod
-	def _update_body(body, pos, rot):
+	def _update_pose(obj, pos, rot):
 		raise NotImplementedError()
 
 

ars/graphics/adapters.py

 		raise exc.ArsError()
 
 	@staticmethod
-	def _update_body(body, pos, rot):
-		t = VtkAdapter._create_transform_matrix(pos, rot)
-		VtkAdapter._set_object_transform_matrix(body, t)
+	def _update_pose(obj, pos, rot):
+		trans = gemut.Transform(pos, rot)
+		vtk_tm = VtkAdapter._create_transform_matrix(trans)
+		VtkAdapter._set_object_transform_matrix(obj, vtk_tm)
 
 	def _timer_callback(self, obj, event):
 		self.timer_count += 1
 	#===========================================================================
 
 	@staticmethod
-	def _set_object_transform_matrix(obj, transMat):
-		obj.PokeMatrix(transMat)
+	def _set_object_transform_matrix(obj, vtk_tm):
+		"""Set ``obj``'s pose according to the transform ``vtk_tm``.
+
+		:param obj: object to be modified
+		:type obj: :class:`vtk.vtkProp3D`
+		:param vtk_tm: homogeneous transform
+		:type vtk_tm: :class:`vtk.vtkMatrix4x4`
+
+		"""
+		obj.PokeMatrix(vtk_tm)
 
 	@staticmethod
-	def _create_transform_matrix(pos, rot):
-		"""
-		pos: a 3-tuple
-		rot: a 9-tuple
+	def _create_transform_matrix(trans):
+		"""Create a homogeneous transform matrix valid for VTK.
+
+		:param trans: homogeneous transform
+		:type trans: :class:`ars.utils.geometry.Transform`
+		:return: a VTK-valid transform matrix
+		:rtype: :class:`vtk.vtkMatrix4x4`
 
 		"""
-		t = gemut.Transform(pos, rot)
 		vtk_matrix = vtk.vtkMatrix4x4()
-		vtk_matrix.DeepCopy(t.get_long_tuple())
+		vtk_matrix.DeepCopy(trans.get_long_tuple())
 
 		return vtk_matrix
 
 
 
 class Axes(VtkBody, gp.Axes):
-	def __init__(self, pos=(0,0,0), cylinder_radius=0.05):
-		gp.Axes.__init__(self, pos, cylinder_radius)
+	def __init__(self, pos=(0, 0, 0), rot=None, cylinder_radius=0.05):
+		gp.Axes.__init__(self, pos, rot, cylinder_radius)
 
 		# 2 different methods may be used here
 		# see http://stackoverflow.com/questions/7810632/
 		axesActor.AxisLabelsOn()
 		axesActor.SetShaftTypeToCylinder()
 		axesActor.SetCylinderRadius(cylinder_radius)
+		VtkAdapter._update_pose(axesActor, pos, rot)
 
 		self._actor = axesActor
 
 		boxMapper.SetInputConnection(box.GetOutputPort())
 		boxActor = vtk.vtkActor()
 
-		VtkAdapter._update_body(boxActor, pos, rot)
+		VtkAdapter._update_pose(boxActor, pos, rot)
 		boxActor.SetMapper(boxMapper)
 
 		self._actor = boxActor
 		coneMapper.SetInputConnection(cone.GetOutputPort())
 		coneActor = vtk.vtkActor()
 
-		VtkAdapter._update_body(coneActor, center, rot)
+		VtkAdapter._update_pose(coneActor, center, rot)
 		coneActor.SetMapper(coneMapper)
 
 		self._actor = coneActor
 		sphereMapper.SetInputConnection(sphere.GetOutputPort())
 		sphereActor = vtk.vtkActor()
 
-		VtkAdapter._update_body(sphereActor, center, rot)
+		VtkAdapter._update_pose(sphereActor, center, rot)
 		sphereActor.SetMapper(sphereMapper)
 
 		self._actor = sphereActor
 		cylMapper.SetInputConnection(transFilter.GetOutputPort())
 		cylActor = vtk.vtkActor()
 
-		VtkAdapter._update_body(cylActor, center, rot)
+		VtkAdapter._update_pose(cylActor, center, rot)
 		cylActor.SetMapper(cylMapper)
 
 		self._actor = cylActor
 		assembly.AddPart(sphereActor1)
 		assembly.AddPart(sphereActor2)
 
-		VtkAdapter._update_body(assembly, center, rot)
+		VtkAdapter._update_pose(assembly, center, rot)
 		self._actor = assembly
 
 
 
 		# actor: represents an object (geometry & properties) in a rendered scene
 		triangles_actor = vtk.vtkActor()
-		VtkAdapter._update_body(triangles_actor, pos, rot)
+		VtkAdapter._update_pose(triangles_actor, pos, rot)
 		triangles_actor.SetMapper(mapper)
 
 		self._actor = triangles_actor

ars/model/simulator/__init__.py

 		return actors
 
 	def add_object(self, sim_object):
-		"""Adds an object to the internal dictionary of simulated ones"""
+		"""Add ``sim_object`` to the internal dictionary of simulated objects.
+
+		If its name equals an already registered key, it will be modified
+		using its string representation, for example:
+
+		>>> sim.add_object(sim_object)
+		sphere/<ars.model.simulator.SimulatedBody object at 0x3a4bed0>
+
+		:param sim_object: object to add
+		:type sim_object: :class:`SimulatedObject`
+		:return: name/key of the object
+		:rtype: string
+
+		"""
 		name = sim_object.get_name()
 		if (name in self._objects.keys()) and name:
-			name = name + '/' + str(sim_object.body)
+			name = name + '/' + str(sim_object)
 			sim_object.set_name(name)
 		self._objects[name] = sim_object
 		return name

tests/external-libs/VTK/vtk_axes.py

+import vtk
+import ars.utils.geometry as gemut
+
+
+def _set_object_transform_matrix(obj, vtk_tm):
+	obj.PokeMatrix(vtk_tm)
+
+
+def _create_transform_matrix(trans):
+	vtk_matrix = vtk.vtkMatrix4x4()
+	vtk_matrix.DeepCopy(trans.get_long_tuple())
+
+	return vtk_matrix
+
+
+ren = vtk.vtkRenderer()
+renWin = vtk.vtkRenderWindow()
+renWin.AddRenderer(ren)
+iren = vtk.vtkRenderWindowInteractor()
+iren.SetRenderWindow(renWin)
+
+axesActor1 = vtk.vtkAxesActor()
+axesActor1.AxisLabelsOn()
+axesActor1.SetShaftTypeToCylinder()
+axesActor1.SetCylinderRadius(0.05)
+
+axesActor2 = vtk.vtkAxesActor()
+axesActor2.AxisLabelsOn()
+axesActor2.SetShaftTypeToCylinder()
+axesActor2.SetCylinderRadius(0.05)
+
+trans = gemut.Transform((0.5, 0.5, 0), (0, 0, 1, 1, 0, 0, 0, 1, 0))
+vtk_tm = _create_transform_matrix(trans)
+_set_object_transform_matrix(axesActor2, vtk_tm)
+
+
+ren.AddActor(axesActor1)
+ren.AddActor(axesActor2)
+iren.Initialize()
+renWin.Render()
+iren.Start()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.