diff options
Diffstat (limited to 'silx/gui/plot3d/scene/utils.py')
-rw-r--r-- | silx/gui/plot3d/scene/utils.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/silx/gui/plot3d/scene/utils.py b/silx/gui/plot3d/scene/utils.py index 930a087..04abd04 100644 --- a/silx/gui/plot3d/scene/utils.py +++ b/silx/gui/plot3d/scene/utils.py @@ -184,6 +184,32 @@ def unindexArrays(mode, indices, *arrays): return tuple(numpy.ascontiguousarray(data[indices]) for data in arrays) +def triangleStripToTriangles(strip): + """Convert a triangle strip to a set of triangles. + + The order of the corners is inverted for odd triangles. + + :param numpy.ndarray strip: + Array of triangle corners of shape (N, 3). + N must be at least 3. + :return: Equivalent triangles corner as an array of shape (N, 3, 3) + :rtype: numpy.ndarray + """ + strip = numpy.array(strip).reshape(-1, 3) + assert len(strip) >= 3 + + triangles = numpy.empty((len(strip) - 2, 3, 3), dtype=strip.dtype) + triangles[0::2, 0] = strip[0:-2:2] + triangles[0::2, 1] = strip[1:-1:2] + triangles[0::2, 2] = strip[2::2] + + triangles[1::2, 0] = strip[3::2] + triangles[1::2, 1] = strip[2:-1:2] + triangles[1::2, 2] = strip[1:-2:2] + + return triangles + + def trianglesNormal(positions): """Return normal for each triangle. @@ -514,3 +540,19 @@ class Plane(event.Notifier): def move(self, step): """Move the plane of step along the normal.""" self.point += step * self.normal + + def segmentIntersection(self, s0, s1): + """Compute the plane intersection with segment [s0, s1]. + + :param s0: First end of the segment + :type s0: 1D numpy.ndarray-like of length 3 + :param s1: Second end of the segment + :type s1: 1D numpy.ndarray-like of length 3 + :return: The intersection points. The number of points goes + from 0 (no intersection) to 2 (segment in the plane) + :rtype: list of 1D numpy.ndarray + """ + if not self.isPlane: + return [] + else: + return segmentPlaneIntersect(s0, s1, self.normal, self.point) |