Example #1
0
    def make_value_scatter(self, grid: ChunkGrid, mask: ChunkGrid[bool],
                           **kwargs):

        items = list(grid.items(mask=mask))
        points, values = zip(*items)  # type: Sequence[Vec3i], Sequence
        pts = np.array(points, dtype=np.float32) + 0.5
        values = np.array(values)

        merge_default(kwargs, marker=dict(color=values))
        return self.make_scatter(pts, **kwargs)
    def make_mesh(self,
                  vertices: np.ndarray,
                  faces: np.ndarray,
                  offset: Optional[Vec3f] = None,
                  **kwargs):
        merge_default(kwargs, **self.default_mesh_kwargs)
        kwargs.setdefault("flatshading", True)

        offset = (0, 0, 0) if offset is None else offset

        vertices = vertices + offset
        x, y, z = self._unwrap(vertices)
        i, j, k = self._unwrap(faces)

        return go.Mesh3d(x=x, y=y, z=z, i=i, j=j, k=k, **kwargs)
    def make_wireframe(self,
                       vertices: np.ndarray,
                       faces: np.ndarray,
                       size=0.5,
                       **kwargs):
        merge_default(kwargs, mode='lines', marker=dict(size=size))
        # arr = np.array([
        #     [
        #         (vertices[min(fi, fj)], vertices[max(fi, fj)]),
        #         (vertices[min(fi, fk)], vertices[max(fi, fk)]),
        #         (vertices[min(fj, fk)], vertices[max(fj, fk)])
        #     ]
        #     for fi, fj, fk in faces
        # ]).reshape((-1, 2, 3))
        # nan = np.ones(3, dtype=vertices.dtype) * np.nan
        # lines = np.array([(l0, l1, nan) for l0, l1 in np.unique(arr, axis=0)]).reshape((-1, 3))

        nan = np.ones(3, dtype=vertices.dtype) * np.nan
        lines = np.array([(vertices[fi], vertices[fj], vertices[fk],
                           vertices[fi], nan)
                          for fi, fj, fk in faces]).reshape((-1, 3))
        x, y, z = lines.T
        return go.Scatter3d(x=x, y=y, z=z, **kwargs)
Example #4
0
 def plot(self, *args: np.ndarray, size=0.5, **kwargs):
     fig = self.make_figure()
     merge_default(kwargs, mode='markers', marker=dict(size=size))
     for d in args:
         fig.add_trace(self.make_scatter(d, **kwargs))
     return fig
Example #5
0
 def make_scatter(self, pts: np.ndarray, size=0.5, **kwargs):
     merge_default(kwargs, mode='markers', marker=dict(size=size))
     x, y, z = self._unwrap(pts)
     return go.Scatter3d(x=x, y=y, z=z, **kwargs)