PicoGK Geometry Kernel

repository·main·Indexed 21 days ago

https://github.com/leap71/picogk

A compact, open-source geometry kernel developed by LEAP 71 for computational engineering. It provides a reduced instruction set for generating complex physical components such as rocket engines, heat exchangers, and electric motors. The library includes capabilities for voxel vectorization using Marching Squares and support for importing and exporting geometry via the ASCII CLI format used in Laser Powder Bed Fusion (LBPF) industrial 3D printers.

Tokens
1.8K
Snippets
6
Records
7
Agent score
27%

What's inside PicoGK

  1. Overview of PicoGK

    main
    PicoGK (“peacock”) is a compact, open-source geometry kernel developed by LEAP 71. It is designed as a deliberately reduced yet powerful instruction set for creating computational geometry specifically for engineering applications, such as electric motors, heat exchangers, 3D-printed rocket engines, and bio-inspired structures. It serves as a foundational component for the Computational Engineering technology stack.
  2. Read PolySliceStack from a CLI file

    main

    Use CliIo.oSlicesFromCliFile to import geometry from an ASCII CLI file.

    Note: Currently, only the ASCII format is supported; binary CLI files will throw a NotSupportedException.

    Returns

    A CliIo.Result object containing:

    • oSlices: The imported PolySliceStack.
    • oBBoxFile: The bounding box of the slices in the file.
    • bBinary: Whether the file was marked as binary.
    • fUnitsHeader: The units scale used in the file header.
    • b32BitAlign: Whether the file was aligned at 32-bit boundaries.
    • nVersion: The CLI export version.
    • strHeaderDate: The date string from the header.
    • nLayers: The number of layers in the file.
    • strWarnings: A string containing any warnings encountered during parsing.
    CliIo.Result result = CliIo.oSlicesFromCliFile("input.cli");
    PolySliceStack slices = result.oSlices;
  3. Save a voxel field to a .cli file

    main

    Use SaveToCliFile to export a voxel field into the .cli format, which is a quasi-industry standard for exchanging layer information with Laser Powder Bed Fusion (LBPF) industrial 3D printers.

    Key parameters:

    • strFileName: The destination file name for the .cli file.
    • fLayerHeight: The layer height in mm. Typical values are 0.03f (30 micron) or 0.06f (60 micron).
    • eFormat: Format options (defaults to CliIo.EFormat.FirstLayerWithContent).
    • bUseAbsXYOrigin: If true, the CLI file uses the absolute X/Y position in space where the voxel field was located. If false (default), slice positions are relative to the voxel field boundaries.
    • xProgress: An optional IProgress interface for reporting progress.
    // Example: Saving a voxel field with 30 micron layer height and absolute XY origin
    void ExportVoxelField(VoxelField field) 
    {
        field.SaveToCliFile(
            strFileName: "output_model.cli",
            fLayerHeight: 0.03f,
            eFormat: CliIo.EFormat.FirstLayerWithContent,
            bUseAbsXYOrigin: true
        );
    }
  4. Vectorize Voxels using Marching Squares

    main

    The Voxels.oVectorize method converts a voxel field into a PolySliceStack using the Marching Squares algorithm. This is useful for converting volumetric data into 2D slices for export to CLI or other formats.

    Parameters

    • fLayerHeight: The desired height between slices in MM. If set to 0, it defaults to the voxel size. The method interpolates slices between discrete voxel layers.
    • bUseAbsXYOrigin: If true, the X/Y coordinates in the resulting slices will correspond to the actual spatial position of the voxel field. If false, coordinates start at the bounding box origin (0,0).
    • xProgress: (Optional) An IProgress implementation for tracking progress.

    Behavior

    • The resulting PolySliceStack contains vectorized layers where outer contours are counter-clockwise and inner contours (islands) are clockwise.
    • Empty slices at the beginning and end of the stack are automatically removed.
    // Vectorize a voxel object with a 0.1mm layer height
    PolySliceStack slices = myVoxels.oVectorize(0.1f, true);
  5. Write PolySliceStack to a CLI file

    main

    Use CliIo.WriteSlicesToCliFile to export a stack of PolySlice objects to the ASCII CLI format. This format is used for representing 2D slice geometry in a text-based file.

    Parameters

    • oSlices: The PolySliceStack containing the geometry to export.
    • strFilePath: The destination file path.
    • eFormat: Determines how the first layer is handled via CliIo.EFormat:
      • UseEmptyFirstLayer: Adds an empty layer at Z=0 to allow readers to infer layer height.
      • FirstLayerWithContent: The first layer contains actual geometry (default).
    • strDate: (Optional) A date string (e.g., "2023-10-27"). If empty, the current date is used.
    • fUnitsInMM: (Optional) The unit scale in millimeters. Setting this to 1000.0f results in coordinates being written in meters.
    • xProgress: (Optional) An IProgress implementation for tracking export progress.
    CliIo.WriteSlicesToCliFile(
        mySliceStack,
        "output.cli",
        CliIo.EFormat.FirstLayerWithContent,
        "2023-01-01",
        1.0f
    );
  6. CliIo.EFormat options

    main

    The CliIo.EFormat enum defines how the first layer of a CLI file is structured during export.

    • UseEmptyFirstLayer: An intentionally empty layer is written at the start. This allows CLI readers to infer the layer height by calculating the distance between the first non-empty layer and the zero layer.
    • FirstLayerWithContent: The first layer contains the actual geometry (default behavior).
    public enum EFormat 
    {
        UseEmptyFirstLayer, 
        FirstLayerWithContent
    };
  7. CliIo.Result data structure

    main

    The CliIo.Result class holds the data and metadata returned after importing a CLI file.

    FieldTypeDescription
    oSlicesPolySliceStackThe stack of imported slices
    oBBoxFileBBox3The bounding box of the slices in the file
    bBinaryboolTrue if the file was binary
    fUnitsHeaderfloatUnits used in the header
    b32BitAlignboolTrue if the file was aligned at 32-bit boundaries
    nVersionUInt32Version number of the CLI export
    strHeaderDatestringDate string read from the header
    nLayersUInt32Number of layers in the file
    strWarningsstringWarnings encountered during reading
    public class Result
    {
        public PolySliceStack oSlices = new();
        public BBox3 oBBoxFile = new();
        public bool bBinary = false;
        public float fUnitsHeader = 0.0f;
        public bool b32BitAlign = false;
        public UInt32 nVersion = 0;
        public string strHeaderDate = "";
        public UInt32 nLayers = 0;
        public string strWarnings = "";
    }