Skip to content

Commit

Permalink
Trac #7232: fix tachyon segfault introduced by #6542
Browse files Browse the repository at this point in the history
This pretty much says it all:

{{{
sage: a = 1
sage: b = 0
sage: c = 0
sage:
sage: f = lambda t: ((a*c*cos(t) - b*sin(t))/sqrt(a^2+b^2), (b*c*cos(t)
+
....: a*sin(t))/sqrt(a^2+b^2), cos(t)*sqrt(a^2+b^2))
sage: t = Tachyon(camera_center=(0,0,0))
sage: t.texture('t')
sage: t.light((-20,-20,40), 0.2, (1,1,1))
sage: t.parametric_plot(f,0,2*pi,'t',min_depth=6)
sage:
sage: t.show()
sh: line 1:  2214 Segmentation fault      tachyon
/Users/wstein/.sage//temp/flat.local/2161//tmp_2.dat -format PNG -o
/Users/wstein/.sage//temp/flat.local/2161//tmp_1.png > /dev/null
}}}

Note, that this was I think caused by #6542.

URL: http://trac.sagemath.org/7232
Reported by: was
Ticket author(s): Frédéric Chapoton
Reviewer(s): Karl-Dieter Crisman, Niles Johnson
  • Loading branch information
Release Manager authored and vbraun committed Aug 15, 2014
2 parents 645ffbf + f8cb975 commit 91c9f90
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions src/sage/plot/plot3d/tachyon.py
Expand Up @@ -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
Expand All @@ -63,6 +62,7 @@

from math import sqrt


class Tachyon(SageObject):
r"""
Create a scene the can be rendered using the Tachyon ray tracer.
Expand All @@ -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.
Expand Down Expand Up @@ -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::
Expand All @@ -224,15 +233,19 @@ 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 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
Expand Down Expand Up @@ -276,7 +289,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:
Expand Down Expand Up @@ -320,7 +332,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::
Expand Down Expand Up @@ -381,7 +393,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::
Expand Down Expand Up @@ -409,7 +421,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::
Expand Down Expand Up @@ -512,7 +524,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::
Expand Down Expand Up @@ -542,7 +554,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::
Expand Down Expand Up @@ -1207,13 +1219,14 @@ def str(self):
%s
"""%(tostr(self._a), tostr(self._b),tostr(self._c), self._color)


class TachyonSmoothTriangle(SmoothTriangle):
r"""
A triangle along with a normal vector, which is used for smoothing.
"""
def str(self):
r"""
Returns the scene string for a smoothed triangle.
Return the scene string for a smoothed triangle.
EXAMPLES::
Expand All @@ -1230,7 +1243,6 @@ def str(self):
tostr(self._da), tostr(self._db), tostr(self._dc), self._color)



class TachyonTriangleFactory(TriangleFactory):
r"""
A class to produce triangles of various rendering types.
Expand Down

0 comments on commit 91c9f90

Please sign in to comment.