Source

ars / ars / graphics / __init__.py

from abc import ABCMeta, abstractmethod


class Axes(object):

	__metaclass__ = ABCMeta

	@abstractmethod
	def __init__(self, pos=(0, 0, 0), rot=None, cylinder_radius=0.05):
		self._actor = None

	@property
	def actor(self):
		return self._actor


class Body(object):

	"""
	Abstract class. Not coupled (at all) with VTK or any other graphics library

	"""

	__metaclass__ = ABCMeta

	adapter = None

	@abstractmethod
	def __init__(self, center, rot):
		self._position = center
		self._rotation = rot
		self._color = None
		self._actor = None

	def update_position_rotation(self, pos, rot):
		self._position = pos
		self._rotation = rot
		self.adapter._update_pose(self._actor, pos, rot)

	@property
	def actor(self):
		return self._actor

	@abstractmethod
	def get_color(self):
		return self._color

	@abstractmethod
	def set_color(self, color):
		self._color = color


class Box(Body):

	__metaclass__ = ABCMeta

	@abstractmethod
	def __init__(self, size, pos, rot=None):
		super(Box, self).__init__(pos, rot)


class Cone(Body):

	__metaclass__ = ABCMeta

	@abstractmethod
	def __init__(self, height, radius, center, rot=None, resolution=100):
		"""Constructor.

		:param resolution: it is the circumferential number of facets
		:type resolution: int

		"""
		super(Cone, self).__init__(center, rot)


class Sphere(Body):

	__metaclass__ = ABCMeta

	@abstractmethod
	def __init__(self, radius, center, rot=None, phi_resolution=50,
                 theta_resolution=50):
		"""Constructor.

		:param phi_resolution: resolution in the latitude (phi) direction
		:type phi_resolution: int
		:param theta_resolution: resolution in the longitude (theta) direction
		:type theta_resolution: int

		"""
		super(Sphere, self).__init__(center, rot)


class Cylinder(Body):

	__metaclass__ = ABCMeta

	@abstractmethod
	def __init__(self, length, radius, center, rot=None, resolution=10):
		super(Cylinder, self).__init__(center, rot)


class Capsule(Body):

	__metaclass__ = ABCMeta

	@abstractmethod
	def __init__(self, length, radius, center, rot=None, resolution=10):
		super(Capsule, self).__init__(center, rot)


class Trimesh(Body):

	__metaclass__ = ABCMeta

	@abstractmethod
	def __init__(self, vertices, faces, pos=None, rot=None):
		super(Trimesh, self).__init__(pos, rot)


class Adapter(object):

	"""
	Abstract class. Not coupled (at all) with VTK or any other graphics library

	"""

	__metaclass__ = ABCMeta

	@abstractmethod
	def __init__(self, *args, **kwargs):
		self.timer_count = 0
		self.on_idle_parent_callback = None
		self.on_reset_parent_callback = None
		self.on_key_press_parent_callback = None
		self._window_started = False

	@abstractmethod
	def add_object(self, obj):
		"""Add ``obj`` to the visualization controlled by this adapter.

		:param obj:
		:type obj: :class:`Body`

		"""
		raise NotImplementedError()

	@abstractmethod
	def remove_object(self, obj):
		"""Remove ``obj`` from the visualization controlled by this adapter.

		:param obj:
		:type obj: :class:`Body`

		"""
		raise NotImplementedError()

	def add_objects_list(self, obj_list):
		for obj in obj_list:
			self.add_object(obj)

	@abstractmethod
	def start_window(
            self, on_idle_callback, on_reset_callback, on_key_press_callback):
		raise NotImplementedError()

	@abstractmethod
	def restart_window(self):
		raise NotImplementedError()

	@abstractmethod
	def finalize_window(self):
		"""Finalize window and remove/clear associated resources."""
		raise NotImplementedError()

	@abstractmethod
	def _timer_callback(self, obj, event):
		raise NotImplementedError()

	@abstractmethod
	def _key_press_callback(self, obj, event):
		raise NotImplementedError()

	@abstractmethod
	def reset(self):
		raise NotImplementedError()

	@staticmethod
	@abstractmethod
	def _update_pose(obj, pos, rot):
		raise NotImplementedError()


class ScreenshotRecorder(object):

	__metaclass__ = ABCMeta

	file_extension = None  # e.g. 'png'

	def __init__(self, base_filename):
		self.base_filename = base_filename
		self.last_write_time = None
		self.period = None

	@abstractmethod
	def write(self, index, time):
		"""Write render-window's currently displayed image to a file.

		The image format (thus the file extension too) to use must be defined
		by the implementation.

		Image's filename is determined by :meth:`calc_filename`.

		:param index: image's index to use for filename calculation
		:type index: int
		:param time:
		:type time:

		"""
		raise NotImplementedError()

	def calc_filename(self, index=1):
		"""Calculate a filename using ``index`` for a new image.

		:param index: image's index to use for filename calculation
		:type index: int
		:return: image's filename
		:rtype: str

		"""
		return '%s%d.%s' % (self.base_filename, index, self.file_extension)
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.