diff --git a/doc/sphinx/installation.rst b/doc/sphinx/installation.rst index 16ad75fb45b..3c81315ae4f 100644 --- a/doc/sphinx/installation.rst +++ b/doc/sphinx/installation.rst @@ -313,7 +313,7 @@ Run the following commands: .. code-block:: bash brew install cmake python cython boost boost-mpi fftw \ - doxygen gsl numpy scipy ipython jupyter + doxygen gsl numpy scipy ipython jupyter freeglut brew install hdf5-mpi brew link --force cython pip install -c requirements.txt PyOpenGL matplotlib diff --git a/src/python/espressomd/visualization.py b/src/python/espressomd/visualization.py index 84f4293454f..2f0f1af5aca 100644 --- a/src/python/espressomd/visualization.py +++ b/src/python/espressomd/visualization.py @@ -1934,6 +1934,12 @@ def _rasterize_shape(self): continue return points + def _has_gle_features(self, feature_names): + for feature_name in feature_names: + if not bool(getattr(OpenGL.GLE, feature_name)): + return False + return True + class Cylinder(Shape): """ @@ -2004,6 +2010,8 @@ def __init__(self, shape, particle_type, color, material, self.length = self.shape.get_parameter('length') self.thickness = self.shape.get_parameter('thickness') self.central_angle = self.shape.get_parameter('central_angle') + self.use_gle = self._has_gle_features( + ["gleSpiral", "gleSetNumSides", "gleSetJoinStyle"]) def draw(self): """ @@ -2011,7 +2019,7 @@ def draw(self): Use rasterization of base class, otherwise. """ - if bool(OpenGL.GLE.gleSpiral) and self.central_angle == 0.: + if self.use_gle and self.central_angle == 0.: self._draw_using_gle() else: super().draw() @@ -2070,6 +2078,8 @@ def __init__(self, shape, particle_type, color, material, self.smoothing_radius = np.array( self.shape.get_parameter('smoothing_radius')) self.max_box_l = max(box_l) + self.use_gle = self._has_gle_features( + ["gleSpiral", "gleSetNumSides", "gleSetJoinStyle"]) def draw(self): """ @@ -2084,7 +2094,7 @@ def draw(self): ax, rx, ry = rotation_helper(self.axis) OpenGL.GL.glRotatef(ax, rx, ry, 0.0) - if bool(OpenGL.GLE.gleSpiral): + if self.use_gle: self._draw_using_gle() else: self._draw_using_primitives() @@ -2092,27 +2102,25 @@ def draw(self): OpenGL.GL.glPopMatrix() def _draw_using_gle(self): - # if available, use the GL Extrusion library - if bool(OpenGL.GLE.gleSpiral): - n = max(10, self.quality // 3) - contour = [[0.5 * self.max_box_l, -0.5 * self.length]] - for theta in np.linspace(0, 0.5 * np.pi, n): - contour.append([(1. - np.sin(theta)) * self.smoothing_radius, - -0.5 * self.length + (1. - np.cos(theta)) * self.smoothing_radius]) - for theta in np.linspace(0.5 * np.pi, np.pi, n): - contour.append([(1. - np.sin(theta)) * self.smoothing_radius, - 0.5 * self.length - (1. + np.cos(theta)) * self.smoothing_radius]) - contour.append([0.5 * self.max_box_l, 0.5 * self.length]) - - normals = np.diff(np.array(contour), axis=0) - normals /= np.linalg.norm(normals, ord=2, axis=1, keepdims=True) - normals = np.roll(normals, 1, axis=1) - normals[:, 0] *= -1 - - OpenGL.GLE.gleSetJoinStyle(OpenGL.GLE.TUBE_JN_ANGLE) - OpenGL.GLE.gleSetNumSides(max(90, 3 * self.quality)) - OpenGL.GLE.gleSpiral(contour, normals, [0, 0, 1], self.radius, 0., 0., 0., - [[1, 0, 0], [0, 1, 0]], [[0, 0, 0], [0, 0, 0]], 0., 360) + n = max(10, self.quality // 3) + contour = [[0.5 * self.max_box_l, -0.5 * self.length]] + for theta in np.linspace(0, 0.5 * np.pi, n): + contour.append([(1. - np.sin(theta)) * self.smoothing_radius, + -0.5 * self.length + (1. - np.cos(theta)) * self.smoothing_radius]) + for theta in np.linspace(0.5 * np.pi, np.pi, n): + contour.append([(1. - np.sin(theta)) * self.smoothing_radius, + 0.5 * self.length - (1. + np.cos(theta)) * self.smoothing_radius]) + contour.append([0.5 * self.max_box_l, 0.5 * self.length]) + + normals = np.diff(np.array(contour), axis=0) + normals /= np.linalg.norm(normals, ord=2, axis=1, keepdims=True) + normals = np.roll(normals, 1, axis=1) + normals[:, 0] *= -1 + + OpenGL.GLE.gleSetJoinStyle(OpenGL.GLE.TUBE_JN_ANGLE) + OpenGL.GLE.gleSetNumSides(max(90, 3 * self.quality)) + OpenGL.GLE.gleSpiral(contour, normals, [0, 0, 1], self.radius, 0., 0., 0., + [[1, 0, 0], [0, 1, 0]], [[0, 0, 0], [0, 0, 0]], 0., 360) def _draw_using_primitives(self): clip_plane = get_extra_clip_plane()