PicoGK Geometry Kernel
repository·main·Indexed 21 days ago
https://github.com/leap71/picogkA 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.
What's inside PicoGK
- 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.
Read PolySliceStack from a CLI file
mainUse
CliIo.oSlicesFromCliFileto 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.Resultobject containing:oSlices: The importedPolySliceStack.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;Save a voxel field to a .cli file
mainUse
SaveToCliFileto export a voxel field into the.cliformat, 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.clifile.fLayerHeight: The layer height in mm. Typical values are0.03f(30 micron) or0.06f(60 micron).eFormat: Format options (defaults toCliIo.EFormat.FirstLayerWithContent).bUseAbsXYOrigin: Iftrue, the CLI file uses the absolute X/Y position in space where the voxel field was located. Iffalse(default), slice positions are relative to the voxel field boundaries.xProgress: An optionalIProgressinterface 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 ); }Vectorize Voxels using Marching Squares
mainThe
Voxels.oVectorizemethod converts a voxel field into aPolySliceStackusing 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 to0, it defaults to the voxel size. The method interpolates slices between discrete voxel layers.bUseAbsXYOrigin: Iftrue, the X/Y coordinates in the resulting slices will correspond to the actual spatial position of the voxel field. Iffalse, coordinates start at the bounding box origin (0,0).xProgress: (Optional) AnIProgressimplementation for tracking progress.
Behavior
- The resulting
PolySliceStackcontains 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);Write PolySliceStack to a CLI file
mainUse
CliIo.WriteSlicesToCliFileto export a stack ofPolySliceobjects to the ASCII CLI format. This format is used for representing 2D slice geometry in a text-based file.Parameters
oSlices: ThePolySliceStackcontaining the geometry to export.strFilePath: The destination file path.eFormat: Determines how the first layer is handled viaCliIo.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 to1000.0fresults in coordinates being written in meters.xProgress: (Optional) AnIProgressimplementation for tracking export progress.
CliIo.WriteSlicesToCliFile( mySliceStack, "output.cli", CliIo.EFormat.FirstLayerWithContent, "2023-01-01", 1.0f );CliIo.EFormat options
mainThe
CliIo.EFormatenum 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 };CliIo.Result data structure
mainThe
CliIo.Resultclass holds the data and metadata returned after importing a CLI file.Field Type Description 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 = ""; }