Skip to content

Cloud

Cloud is a subclass of NumPy ndarrays to represent pointclouds in a continuous 3dimensional space. Clouds add spatial properties and functionalities such as bounds and voxelate]

maxbound property readonly

Real maximum bound of the point cloud

Returns:

Type Description
numpy.ndarray

real maximum bound

minbound property readonly

Real minimum bound of the point cloud

Returns:

Type Description
numpy.ndarray

real minimum bound

fast_notebook_vis(self, plot, color='#66beed')

Adds the pointcloud to a pyvista ITK plotter and returns it. ITK plotters are specifically used in notebooks to plot the geometry inside the notebook environment It is mainly used to rapidly visualize the content of the lattice for visual confirmation

Parameters:

Name Type Description Default
plot pyvista.PlotterITK

a pyvista ITK plotter

required

Returns:

Type Description
pyvista.PlotterITK

pyvista ITK plotter containing lattice features such as cells, bounding box, cell centroids

p = pyvista.PlotterITK()
cloud.fast_notebook_vis(p)
Source code in topogenesis/datastructures/datastructures.py
def fast_notebook_vis(self, plot, color="#66beed"):
    """Adds the pointcloud to a pyvista ITK plotter and returns it. ITK plotters are specifically used in notebooks to plot the geometry inside the notebook environment It is mainly used to rapidly visualize the content of the lattice for visual confirmation

    Args:
        plot (pyvista.PlotterITK): a pyvista ITK plotter

    Returns:
        pyvista.PlotterITK: pyvista ITK plotter containing lattice features such as cells, bounding box, cell centroids

    ```python
    p = pyvista.PlotterITK()
    cloud.fast_notebook_vis(p)
    ```
    """
    # adding the original point cloud: blue
    plot.add_points(pv.PolyData(self), color=color)

    return plot

fast_vis(self, plot, color='#66beed')

Adds the pointcloud to a pyvista plotter and returns it. It is mainly used to rapidly visualize the point cloud

Parameters:

Name Type Description Default
plot pyvista.Plotter

a pyvista plotter

required

Returns:

Type Description
pyvista.Plotter

the same pyvista plotter containing points of the pointcloud

Usage Example:

p = pyvista.Plotter()
cloud.fast_vis(
Source code in topogenesis/datastructures/datastructures.py
def fast_vis(self, plot, color="#66beed"):
    """Adds the pointcloud to a pyvista plotter and returns it. 
    It is mainly used to rapidly visualize the point cloud

    Args:
        plot (pyvista.Plotter): a pyvista plotter

    Returns:
        pyvista.Plotter: the same pyvista plotter containing points of the pointcloud

    **Usage Example:**
    ```python
    p = pyvista.Plotter()
    cloud.fast_vis(
    ```
    """

    # adding the original point cloud: blue
    plot.add_mesh(pv.PolyData(self),
                  color=color,
                  point_size=3,
                  render_points_as_spheres=True,
                  label="Point Cloud")

    return plot

from_mesh_vertices(mesh_path) classmethod

Extracts the vertices of a mesh as the point cloud

Parameters:

Name Type Description Default
mesh_path str

path to the mesh file

required

Returns:

Type Description
topogenesis.Cloud

The point cloud including the vertices of the mesh

Source code in topogenesis/datastructures/datastructures.py
@classmethod
def from_mesh_vertices(cls, mesh_path: str):
    """ Extracts the vertices of a mesh as the point cloud

    Args:
        mesh_path (str): path to the mesh file

    Returns:
        topogenesis.Cloud: The point cloud including the vertices of the mesh
    """
    # load the mesh using pyvista
    pv_mesh = pv.read(mesh_path)

    # extract vertices
    vertices = np.array(pv_mesh.points).astype(np.float64)

    # return vertices as cloud
    return cls(vertices)

voxelate(self, unit, tol=1e-06, **kwargs)

will voxelate the pointcloud based on a given unit size and returns a boolean lattice that describes which cells of the discrete space contained at least one point

Parameters:

Name Type Description Default
unit int, numpy.array

describes the cell size of the resultant discrete space

required

Exceptions:

Type Description
ValueError

if the size of the unit array does not correspond to

the number of dimensions in point cloud

Returns:

Type Description
topogenesis.Lattice

boolean lattice describing which cells has contained at least one point

Source code in topogenesis/datastructures/datastructures.py
def voxelate(self, unit, tol=1e-6, **kwargs):
    """will voxelate the pointcloud based on a given unit size and returns a boolean lattice that describes which cells of the discrete space contained at least one point 

    Args:
        unit (int, numpy.array): describes the cell size of the resultant discrete space

    Raises:
        ValueError: if the size of the unit array does not correspond to 
    the number of dimensions in point cloud

    Returns:
        topogenesis.Lattice: boolean lattice describing which cells has contained at least one point
    """

    unit = np.array(unit)
    if unit.size != 1 and unit.size != self.minbound.size:
        raise ValueError(
            'the length of unit array needs to be either 1 or equal to the dimension of point cloud')
    elif unit.size == 1:
        unit = np.tile(unit, self.minbound.shape)

    closed = kwargs.get('closed', False)

    if closed:
        # R3 to Z3 : finding the closest voxel to each point
        point_scaled = self / unit
        # shift the hit points in each 2-dimension (n in 1-axes)
        shifts = np.array(list(itertools.product([-1, 0, 1], repeat=3)))
        shifts_steps = np.sum(np.absolute(shifts), axis=1)
        chosen_shift_ind = np.argwhere(shifts_steps == 3).ravel()
        sel_shifts = shifts[chosen_shift_ind]

        vox_ind = [np.rint(point_scaled + s * tol)
                   for s in sel_shifts]
        vox_ind = np.vstack(vox_ind)

    else:
        vox_ind = np.rint(self / unit).astype(int)

    # removing repetitions
    unique_vox_ind = np.unique(vox_ind, axis=0).astype(int)

    # mapping the voxel indices to real space
    reg_pnt = unique_vox_ind * unit

    # initializing the volume
    l = lattice([self.minbound - unit, self.maxbound + unit], unit=unit,
                dtype=bool, default_value=False)

    # map the indices to start from zero
    mapped_ind = unique_vox_ind - np.rint(l.minbound/l.unit).astype(int)

    # setting the occupied voxels to True
    l[mapped_ind[:, 0], mapped_ind[:, 1], mapped_ind[:, 2]] = True

    return l