Skip to content

Geometry

Core geometric entities for representing sliced models.

geometry

Core geometric entities: Layer, Path, and PrintPoint.

Layer dataclass

Layer(paths=list(), is_brim=False, number_of_brim_offsets=None, is_raft=False, min_max_z_height=(None, None))

Bases: Data

A Layer stores a group of ordered paths generated when a geometry is sliced.

Layers are typically organized horizontally, but can also be organized vertically (see VerticalLayer). A Layer consists of one or multiple Paths.

Attributes:

Name Type Description
paths list[Path]

List of paths in this layer.

is_brim bool

True if this layer is a brim layer.

number_of_brim_offsets int | None

The number of brim offsets this layer has (None if no brim).

is_raft bool

True if this layer is a raft layer.

min_max_z_height tuple[float | None, float | None]

Tuple containing the min and max z height of the layer.

total_number_of_points property

total_number_of_points

Returns the total number of points within the layer.

calculate_z_bounds

calculate_z_bounds()

Fills in the attribute self.min_max_z_height.

Source code in src/compas_slicer/geometry/layer.py
def calculate_z_bounds(self) -> None:
    """Fills in the attribute self.min_max_z_height."""
    if not self.paths:
        raise ValueError("Cannot calculate z_bounds because the list of paths is empty.")

    # Vectorized z extraction
    all_z = []
    for path in self.paths:
        for pt in path.points:
            all_z.append(pt[2])

    self.min_max_z_height = (min(all_z), max(all_z))

from_data classmethod

from_data(data)

Construct a layer from its data representation.

Parameters:

Name Type Description Default
data dict

The data dictionary.

required

Returns:

Type Description
Layer

The constructed layer.

Source code in src/compas_slicer/geometry/layer.py
@classmethod
def from_data(cls, data: dict[str, Any]) -> Layer:
    """Construct a layer from its data representation.

    Parameters
    ----------
    data : dict
        The data dictionary.

    Returns
    -------
    Layer
        The constructed layer.

    """
    return cls.__from_data__(data)

to_data

to_data()

Returns a dictionary of structured data representing the layer.

Returns:

Type Description
dict

The layer's data.

Source code in src/compas_slicer/geometry/layer.py
def to_data(self) -> dict[str, Any]:
    """Returns a dictionary of structured data representing the layer.

    Returns
    -------
    dict
        The layer's data.

    """
    return self.__data__

VerticalLayer dataclass

VerticalLayer(paths=list(), is_brim=False, number_of_brim_offsets=None, is_raft=False, min_max_z_height=(None, None), id=0, head_centroid=None)

Bases: Layer

Vertical ordering layer that stores print paths sorted in vertical groups.

It is created with an empty list of paths that is filled in afterwards.

Attributes:

Name Type Description
id int

Identifier of vertical layer.

head_centroid NDArray | None

Centroid of the last path's points.

append_

append_(path)

Add path to self.paths list.

Source code in src/compas_slicer/geometry/layer.py
def append_(self, path: Path) -> None:
    """Add path to self.paths list."""
    self.paths.append(path)
    self.compute_head_centroid()
    self.calculate_z_bounds()

compute_head_centroid

compute_head_centroid()

Find the centroid of all the points of the last path.

Source code in src/compas_slicer/geometry/layer.py
def compute_head_centroid(self) -> None:
    """Find the centroid of all the points of the last path."""
    pts = np.array(self.paths[-1].points)
    self.head_centroid = np.mean(pts, axis=0)

printout_details

printout_details()

Prints the details of the class.

Source code in src/compas_slicer/geometry/layer.py
def printout_details(self) -> None:
    """Prints the details of the class."""
    logger.info(f"VerticalLayer id: {self.id}")
    logger.info(f"Total number of paths: {len(self.paths)}")

from_data classmethod

from_data(data)

Construct a vertical layer from its data representation.

Parameters:

Name Type Description Default
data dict

The data dictionary.

required

Returns:

Type Description
VerticalLayer

The constructed vertical layer.

Source code in src/compas_slicer/geometry/layer.py
@classmethod
def from_data(cls, data: dict[str, Any]) -> VerticalLayer:
    """Construct a vertical layer from its data representation.

    Parameters
    ----------
    data : dict
        The data dictionary.

    Returns
    -------
    VerticalLayer
        The constructed vertical layer.

    """
    return cls.__from_data__(data)

to_data

to_data()

Returns a dictionary of structured data representing the vertical layer.

Returns:

Type Description
dict

The vertical layer's data.

Source code in src/compas_slicer/geometry/layer.py
def to_data(self) -> dict[str, Any]:
    """Returns a dictionary of structured data representing the vertical layer.

    Returns
    -------
    dict
        The vertical layer's data.

    """
    return self.__data__

Path dataclass

Path(points=list(), is_closed=False)

Bases: Data

A Path is a connected contour within a Layer.

A Path consists of a list of compas.geometry.Points.

Attributes:

Name Type Description
points list[Point]

List of points defining the path.

is_closed bool

True if the Path is a closed curve, False if the Path is open. If the path is closed, the first and the last point are identical.

from_data classmethod

from_data(data)

Construct a path from its data representation.

Parameters:

Name Type Description Default
data dict

The data dictionary.

required

Returns:

Type Description
Path

The constructed path.

Source code in src/compas_slicer/geometry/path.py
@classmethod
def from_data(cls, data: dict[str, Any]) -> Path:
    """Construct a path from its data representation.

    Parameters
    ----------
    data : dict
        The data dictionary.

    Returns
    -------
    Path
        The constructed path.

    """
    return cls.__from_data__(data)

to_data

to_data()

Returns a dictionary of structured data representing the path.

Returns:

Type Description
dict

The path's data.

Source code in src/compas_slicer/geometry/path.py
def to_data(self) -> dict[str, Any]:
    """Returns a dictionary of structured data representing the path.

    Returns
    -------
    dict
        The path's data.

    """
    return self.__data__

PrintPoint dataclass

PrintPoint(pt, layer_height, mesh_normal, up_vector=(lambda: Vector(0, 0, 1))(), frame=None, extruder_toggle=None, velocity=None, wait_time=None, blend_radius=None, closest_support_pt=None, distance_to_support=None, is_feasible=True, attributes=dict())

Bases: Data

A PrintPoint consists of a compas.geometry.Point and printing attributes.

Attributes:

Name Type Description
pt Point

A compas Point consisting of x, y, z coordinates.

layer_height float

The distance between the point on this layer and the previous layer.

mesh_normal Vector

Normal of the mesh at this PrintPoint.

up_vector Vector

Vector in up direction.

frame Frame

Frame with x-axis pointing up, y-axis pointing towards the mesh normal.

extruder_toggle bool | None

True if extruder should be on, False if off.

velocity float | None

Velocity for printing (print speed), in mm/s.

wait_time float | None

Time in seconds to wait at this PrintPoint.

blend_radius float | None

Blend radius in mm.

closest_support_pt Point | None

Closest support point.

distance_to_support float | None

Distance to support.

is_feasible bool

Whether this print point is feasible.

attributes dict[str, Any]

Additional attributes transferred from the mesh.

get_frame

get_frame()

Returns a Frame with x-axis pointing up, y-axis towards mesh normal.

Source code in src/compas_slicer/geometry/print_point.py
def get_frame(self) -> Frame:
    """Returns a Frame with x-axis pointing up, y-axis towards mesh normal."""
    return self._compute_frame()

to_data

to_data()

Returns a dictionary of structured data representing the PrintPoint.

Returns:

Type Description
dict

The PrintPoint's data.

Source code in src/compas_slicer/geometry/print_point.py
def to_data(self) -> dict[str, Any]:
    """Returns a dictionary of structured data representing the PrintPoint.

    Returns
    -------
    dict
        The PrintPoint's data.

    """
    return self.__data__

from_data classmethod

from_data(data)

Construct a PrintPoint from its data representation.

Parameters:

Name Type Description Default
data dict

The data dictionary.

required

Returns:

Type Description
PrintPoint

The constructed PrintPoint.

Source code in src/compas_slicer/geometry/print_point.py
@classmethod
def from_data(cls, data: dict[str, Any]) -> PrintPoint:
    """Construct a PrintPoint from its data representation.

    Parameters
    ----------
    data : dict
        The data dictionary.

    Returns
    -------
    PrintPoint
        The constructed PrintPoint.

    """
    # Handle legacy format with "point" key instead of "pt"
    if "point" in data and "pt" not in data:
        data["pt"] = data.pop("point")
    return cls.__from_data__(data)