Return a correctly transformed polygon soup of the
        current scene.

        Returns
        ----------
        triangles: (n,3,3) float, triangles in space
188181
def triangles(self):
        
        triangles = collections.deque()
        triangles_node = collections.deque()

        for node_name in self.graph.nodes_geometry:
            # which geometry does this node refer to
            transform, geometry_name = self.graph[node_name]

            # get the actual potential mesh instance
            geometry = self.geometry[geometry_name]
            if not hasattr(geometry, 'triangles'):
                continue
            # append the (n, 3, 3) triangles to a sequence
            triangles.append(
                transformations.transform_points(
                    geometry.triangles.copy().reshape((-1, 3)),
                    matrix=transform))
            # save the node names for each triangle
            triangles_node.append(
                np.tile(node_name,
                        len(geometry.triangles)))
        # save the resulting nodes to the cache
        self._cache['triangles_node'] = np.hstack(triangles_node)
        triangles = np.vstack(triangles).reshape((-1, 3, 3))
        return triangles
774389
def bounds(self) -> Tuple[float, float, float, float]:
        
        return self.shape.bounds
454449
def polygon(surf, points, color):
    """"""

    gfxdraw.aapolygon(surf, points, color)
    gfxdraw.filled_polygon(surf, points, color)

    x = min([x for (x, y) in points])
    y = min([y for (x, y) in points])
    xm = max([x for (x, y) in points])
    ym = max([y for (x, y) in points])

    return pygame.Rect(x, y, xm - x, ym - y)
214439
def hull(self):
        
        from scipy.spatial import ConvexHull
        if len(self.coordinates) >= 4:
            inds = ConvexHull(self.coordinates).vertices
            return self.coordinates[inds]
        else:
            return self.coordinates
726659
def to_edgelist(self):
        
        # save cleaned edges
        export = []
        # loop through (node, node, edge attributes)
        for edge in nx.to_edgelist(self.transforms):
            a, b, c = edge
            # geometry is a node property but save it to the
            # edge so we don't need two dictionaries
            if 'geometry' in self.transforms.node[b]:
                c['geometry'] = self.transforms.node[b]['geometry']
            # save the matrix as a float list
            c['matrix'] = np.asanyarray(c['matrix'], dtype=np.float64).tolist()
            export.append((a, b, c))
        return export
480982
def raster_to_shape(raster):
    """"""
    left = raster.bounds.left
    right = raster.bounds.right
    top = raster.bounds.top
    bottom = raster.bounds.bottom

    top_left = (left, top)
    top_right = (right, top)
    bottom_left = (left, bottom)
    bottom_right = (right, bottom)

    return Polygon((
        top_left, top_right, bottom_right, bottom_left, top_left,
    ))
1055270
def _bbox_to_area_polygon(self, bbox):
        
        projected_bbox = bbox.transform(self.crs)
        return projected_bbox.geometry
434255
def polygon_from_points(points):
    
    polygon = []
    for pair in points.split(" "):
        x_y = pair.split(",")
        polygon.append([float(x_y[0]), float(x_y[1])])
    return polygon
1200393
def bounds_tree(triangles):
    
    triangles = np.asanyarray(triangles, dtype=np.float64)
    if not util.is_shape(triangles, (-1, 3, 3)):
        raise ValueError('Triangles must be (n,3,3)!')

    # the (n,6) interleaved bounding box for every triangle
    triangle_bounds = np.column_stack((triangles.min(axis=1),
                                       triangles.max(axis=1)))
    tree = util.bounds_tree(triangle_bounds)
    return tree
50222
def get_geometry(self):
        
        return (self.thet0, self.thet, self.phi0, self.phi, self.alpha, 
            self.beta)
305939
def faces(self):
        

        if self._faces is None:
            if self._vertices is None:
                return None
            self.triangulate()
        return self._faces
450303
def polygon_to_points(coords, z=None):
    

    bounds = array(coords).astype('int')

    bmax = bounds.max(0)
    bmin = bounds.min(0)

    path = Path(bounds)

    grid = meshgrid(range(bmin[0], bmax[0]+1), range(bmin[1], bmax[1]+1))

    grid_flat = zip(grid[0].ravel(), grid[1].ravel())

    points = path.contains_points(grid_flat).reshape(grid[0].shape).astype('int')
    points = where(points)
    points = (vstack([points[0], points[1]]).T + bmin[-1::-1]).tolist()
    if z is not None:
        points = map(lambda p: [p[0], p[1], z], points)

    return points
521770
def to_mesh(self):
        
        result = Trimesh(vertices=self.vertices.copy(),
                         faces=self.faces.copy(),
                         face_normals=self.face_normals.copy(),
                         process=False)
        return result
677195
def to_nibabel(image):
    
    if image.dimension != 3:
        raise ValueError('Only 3D images currently supported')

    import nibabel as nib
    array_data = image.numpy()
    affine = np.hstack([image.direction*np.diag(image.spacing),np.array(image.origin).reshape(3,1)])
    affine = np.vstack([affine, np.array([0,0,0,1.])])
    affine[:2,:] *= -1
    new_img = nib.Nifti1Image(array_data, affine)
    return new_img
348907
def shape(self) -> Tuple[int, ...]:
        
        return tuple(bins.bin_count for bins in self._binnings)
1223645
def shapes(self):
        
        from pptx.shapes.shapetree import GroupShapes
        return GroupShapes(self._element, self)
910761
def allPolygons(self):
        
        polygons = self.polygons[:]
        if self.front: 
            polygons.extend(self.front.allPolygons())
        if self.back: 
            polygons.extend(self.back.allPolygons())
        return polygons