From be9cf5a30a96fdde6628b0d5d173762cf78db1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 2 Aug 2014 22:29:01 +0200 Subject: [PATCH 1/2] trac #7232 warning if camera and observed point coincide in tachyon scenes --- src/sage/plot/plot3d/tachyon.py | 62 ++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/sage/plot/plot3d/tachyon.py b/src/sage/plot/plot3d/tachyon.py index 7c47b39a925..2e93f1472d7 100644 --- a/src/sage/plot/plot3d/tachyon.py +++ b/src/sage/plot/plot3d/tachyon.py @@ -42,14 +42,13 @@ - Marshall Hampton: improved doctests, rings, axis-aligned boxes. -TODO: +.. TODO: -- clean up trianglefactory stuff + - clean up trianglefactory stuff """ from tri_plot import Triangle, SmoothTriangle, TriangleFactory, TrianglePlot - from sage.interfaces.tachyon import tachyon_rt from sage.structure.sage_object import SageObject @@ -63,6 +62,7 @@ from math import sqrt + class Tachyon(SageObject): r""" Create a scene the can be rendered using the Tachyon ray tracer. @@ -78,7 +78,7 @@ class Tachyon(SageObject): - ``camera_center`` - (default (-3, 0, 0)) - ``updir`` - (default (0, 0, 1)) - ``look_at`` - (default (0,0,0)) - - ``viewdir`` - (default None) + - ``viewdir`` - (default ``None``) - ``projection`` - (default 'PERSPECTIVE') OUTPUT: A Tachyon 3d scene. @@ -192,20 +192,29 @@ class Tachyon(SageObject): sage: t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1) sage: t.plane((0,0,-100), (0,0,-100), 'white') sage: t.show() + + If the optional parameter ``viewdir`` is not set, the camera + center should not coincide with the point which + is looked at (see :trac:`7232`):: + + sage: t = Tachyon(xres=80,yres=80, camera_center=(2,5,2), look_at=(2,5,2)) + Traceback (most recent call last): + ... + ValueError: camera_center and look_at coincide """ def __init__(self, xres=350, yres=350, - zoom = 1.0, - antialiasing = False, - aspectratio = 1.0, - raydepth = 8, - camera_center = (-3, 0, 0), - updir = (0, 0, 1), - look_at = (0,0,0), - viewdir = None, - projection = 'PERSPECTIVE'): + zoom=1.0, + antialiasing=False, + aspectratio=1.0, + raydepth=8, + camera_center=(-3, 0, 0), + updir=(0, 0, 1), + look_at=(0, 0, 0), + viewdir=None, + projection='PERSPECTIVE'): r""" - Creates an instance of the Tachyon class. + Create an instance of the Tachyon class. EXAMPLES:: @@ -224,15 +233,17 @@ def __init__(self, self._projection = projection self._objects = [] if viewdir is None: - self._viewdir = [look_at[i] - camera_center[i] for i in range(3)] + if look_at != camera_center: + self._viewdir = [look_at[i] - camera_center[i] + for i in range(3)] + else: + raise ValueError('camera_center and look_at coincide') else: self._viewdir = viewdir - - def __repr__(self): r""" - Returns the string representation of the Tachyon object, + Return the string representation of the Tachyon object, which is just the scene string input to tachyon. EXAMPLES:: @@ -248,7 +259,9 @@ def __repr__(self): def save_image(self, filename=None, *args, **kwds): r""" - Save an image representation of self. The image type is + Save an image representation of self. + + The image type is determined by the extension of the filename. For example, this could be ``.png``, ``.jpg``, ``.gif``, ``.pdf``, ``.svg``. Currently this is implemented by calling the @@ -292,7 +305,6 @@ def save(self, filename='sage.png', verbose=0, block=True, extra_opts=''): r""" INPUT: - - ``filename`` - (default: 'sage.png') output filename; the extension of the filename determines the type. Supported types include: @@ -336,7 +348,7 @@ def save(self, filename='sage.png', verbose=0, block=True, extra_opts=''): def show(self, verbose=0, extra_opts=''): r""" - Creates a PNG file of the scene. + Create a PNG file of the scene. EXAMPLES:: @@ -397,7 +409,7 @@ def _camera(self): def str(self): r""" - Returns the complete tachyon scene file as a string. + Return the complete tachyon scene file as a string. EXAMPLES:: @@ -425,7 +437,7 @@ def str(self): def light(self, center, radius, color): r""" - Creates a light source of the given center, radius, and color. + Create a light source of the given center, radius, and color. EXAMPLES:: @@ -528,7 +540,7 @@ def texture(self, name, ambient=0.2, diffuse=0.8, def texture_recolor(self, name, colors): r""" - Recolors default textures. + Recolor default textures. EXAMPLES:: @@ -558,7 +570,7 @@ def texture_recolor(self, name, colors): def sphere(self, center, radius, texture): r""" - Creates the scene information for a sphere with the given + Create the scene information for a sphere with the given center, radius, and texture. EXAMPLES:: From f8cb9754f8ac01164e98fc11fa731a0b66ab0648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 10 Aug 2014 13:18:17 +0200 Subject: [PATCH 2/2] trac #7232 oops, mistake in merge, now corrected --- src/sage/plot/plot3d/tachyon.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/sage/plot/plot3d/tachyon.py b/src/sage/plot/plot3d/tachyon.py index e0032d3da8c..6196a5cbebb 100644 --- a/src/sage/plot/plot3d/tachyon.py +++ b/src/sage/plot/plot3d/tachyon.py @@ -241,23 +241,6 @@ def __init__(self, else: self._viewdir = viewdir - def __repr__(self): - r""" - Return the string representation of the Tachyon object. - - This is just the scene string input to tachyon. - - EXAMPLES:: - - sage: q = Tachyon() - sage: q.light((1,1,1), 1,(1,1,1)) - sage: q.texture('s') - sage: q.sphere((0,0,0),1,'s') - sage: q.__repr__()[-20:] - ' \n end_scene' - """ - return self.str() - def save_image(self, filename=None, *args, **kwds): r""" Save an image representation of ``self``.