geo3d.geometry.voxel ==================== .. py:module:: geo3d.geometry.voxel Classes ------- .. autoapisummary:: geo3d.geometry.voxel.Voxel geo3d.geometry.voxel.VoxelGrid2D Module Contents --------------- .. py:class:: Voxel(coordinates: tuple[int, int], state: int = 0, value: float = np.nan) Class for defining a Voxel object. Attrs: STATE_LABELS (dict): A dictionary defining the possible states of a voxel. .. py:attribute:: STATE_LABELS .. py:attribute:: _coordinates .. py:attribute:: _state :value: 0 .. py:attribute:: _value .. py:property:: coordinates :type: tuple[int, int] Returns the coordinates of the voxel. :returns: The coordinates of the voxel. :rtype: tuple .. py:property:: state :type: int Returns the state of the voxel. :returns: The state of the voxel. :rtype: int .. py:property:: value :type: float Returns the value of the voxel. :returns: The numeric value of the voxel. np.nan if empty. :rtype: float .. py:method:: __repr__() -> str Special method to represent a Voxel object. :returns: The representation of the Voxel object. :rtype: str .. py:class:: VoxelGrid2D(x0: float, y0: float, nx: int, ny: int, size: int) Class for defining a 2D grid of voxels. In analogy with images, a grid is composed of multiple channels. Ech channel has a name and a particular agencement of its voxels and their values. .. py:attribute:: x0 .. py:attribute:: y0 .. py:attribute:: nx .. py:attribute:: ny .. py:attribute:: size .. py:attribute:: grid_base .. py:attribute:: channel_dict .. py:method:: get_channel(name: str) -> numpy.typing.NDArray Get a particular channel from the grid. :param name: the channel name. :type name: str :returns: The channel grid as an array of Voxels. :rtype: np.ndarray .. py:property:: shape :type: tuple[int, int] Returns the grid shape. :returns: (nx, ny) :rtype: tuple .. py:method:: voxels(attr: str, channel_name: str) -> numpy.typing.NDArray[numpy.floating] Get an array of voxels from a grid channel. :param attr: The voxel's attribute to extract ('state' or 'value'). :param channel_name: Name of the channel. :type channel_name: str :returns: A 2D-array of voxels. :rtype: np.ndarray .. py:method:: neighbors(coordinate: tuple[int, int]) -> List[tuple[int, int]] Get the 8 neighbors of a voxel in a grid. :param coordinate: The coordinates of the voxel. :type coordinate: tuple :returns: The list of the neighbors of the voxel. :rtype: List .. py:method:: fill(coordinate: tuple[int, int], channel_name: str) -> None Fill a voxel. :param coordinate: The coordinate of the voxel to fill. :type coordinate: tuple :param channel_name: name of the channel to fill. :type channel_name: str .. py:method:: occupancy(coordinate: tuple[int, int], channel_name: str) -> float Compute the occupancy of a voxel. Each voxel in the grid has 8 neighbors (expect those at the bordure). The occupancy is defined by the number of neighbors of a voxel that have a 'fill' state. An occupancy of 3 means that for a given voxel, there is exactly 3 neighbors having the 'fill' state. :param coordinate: The coordinate of the voxel. :type coordinate: tuple :param channel_name: name of the channel to fill. :type channel_name: str :returns: The occupancy value. :rtype: int .. py:method:: occupancy_condition(coordinate: tuple[int, int], channel_name: str, threshold: int = 3) -> bool Get a boolean status of the occupancy of a voxel. The voxel is filled only if its occupancy is lower than a threhsold. :param coordinate: The coordinate of the voxel. :type coordinate: tuple :param threshold: The threshold on occupancy. Defaults to 3. :type threshold: int :param channel_name: name of the grid to fill. :type channel_name: str :returns: True if the occupancy is lower than the threshold :rtype: bool .. py:method:: fill_elements(n: int, channel_name: str) -> int Fill in elements in empty voxels. :param n: The number of voxels to fill. :type n: int :param channel_name: name of the channel to fill. :type channel_name: str :returns: The number of voxels that were filled. :rtype: int .. py:method:: enlarge(extra_rows: int) -> None Enlarge the grid by adding extra rows at the top of the grid. :param extra_rows: The number of rows to add. :type extra_rows: int .. py:method:: interpolate_values(channel_name: str) -> None Interpolate the values of the voxels of a channel. :param channel_name: name of the channel. :type channel_name: str .. py:method:: add_channel(name: str, grid_array: numpy.ndarray, metadata: dict) -> None Add a channel tp the grid. :param name: The name of the channel. Must be unique in the channels dictionary. :type name: str :param grid_array: The 2D array of values. :type grid_array: np.ndarray :param metadata: A dictionary of metadata having the keys 'classes', 'func_agg', and 'dimension'. :type metadata: dict .. py:method:: plot(channel_name: str, kind: str = 'state') -> None Plot the voxels grid from a channel. The plot of a grid is made by a scatter plot. 2 kinds are possible, 'state' to visualize the occupancy state of each voxel, or 'value' to visualize the numeric value of each voxel. :param channel_name: The name of the channel. :type channel_name: str :param kind: The kind of plot ('state' or 'value'). Defaults to 'state'. :type kind: str, optional