OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
occtl_io_stl.h File Reference

OCCT-Light: STL file I/O (stereolithography mesh format). More...

#include <stddef.h>
#include <stdint.h>
#include "occtl_core.h"
#include "occtl_topo.h"
Include dependency graph for occtl_io_stl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  occtl_io_stl_write_options
 

Macros

#define OCCTL_IO_STL_WRITE_OPTIONS_VERSION_1   1u
 
#define OCCTL_IO_STL_WRITE_OPTIONS_INIT   {OCCTL_IO_STL_WRITE_OPTIONS_VERSION_1, NULL, 0}
 

Typedefs

typedef struct occtl_io_stl_write_options occtl_io_stl_write_options_t
 

Functions

void occtl_io_stl_write_options_init (occtl_io_stl_write_options_t *options)
 
occtl_status_t occtl_io_stl_read (const char *path, occtl_graph_t **out_graph, occtl_node_id_t *out_root)
 
occtl_status_t occtl_io_stl_read_memory (const uint8_t *data, size_t size, occtl_graph_t **out_graph, occtl_node_id_t *out_root)
 
occtl_status_t occtl_io_stl_write (const occtl_graph_t *graph, occtl_node_id_t root, const char *path, const occtl_io_stl_write_options_t *options)
 
occtl_status_t occtl_io_stl_write_memory (const occtl_graph_t *graph, occtl_node_id_t root, const occtl_io_stl_write_options_t *options, uint8_t *out_data, size_t capacity, size_t *out_size)
 

Detailed Description

OCCT-Light: STL file I/O (stereolithography mesh format).

Reads and writes STL files (binary and ASCII) via OCCT's DESTL_Provider / DESTL_ConfigurationNode.

STL is mesh-only (no B-spline preservation) — the caller should tessellate with #occtl_mesh_build beforehand if the source is a precise geometry.

UIDs are not preserved across the round-trip — the STL file format has no identity slot. Use occtl_uid_to_bytes / occtl_uid_from_bytes for an out-of-band UID handshake if persistent identity is required.

Typedef Documentation

◆ occtl_io_stl_write_options_t

Options for occtl_io_stl_write and occtl_io_stl_write_memory. Pass NULL for defaults (binary output).

Function Documentation

◆ occtl_io_stl_read()

occtl_status_t occtl_io_stl_read ( const char *  path,
occtl_graph_t **  out_graph,
occtl_node_id_t out_root 
)

Reads an STL file and ingests it into a freshly-created graph.

Parameters
[in]pathBorrows it. NUL-terminated UTF-8 path to the file. Must be non-NULL.
[out]out_graphOwns it. Receives a new graph on success; NULL on failure.
[out]out_rootBorrows it. Receives the NodeId of the root entity.
Return values
OCCTL_OKOn success.
OCCTL_INVALID_ARGUMENTpath, out_graph, or out_root is NULL.
OCCTL_IO_ERRORFile not found or unreadable.
OCCTL_FORMAT_ERRORFile contents were not a valid STL stream.

\par Thread Safety Yes.

See also
occtl_io_stl_write, occtl_de_read

◆ occtl_io_stl_read_memory()

occtl_status_t occtl_io_stl_read_memory ( const uint8_t *  data,
size_t  size,
occtl_graph_t **  out_graph,
occtl_node_id_t out_root 
)

Reads an STL payload from caller-owned memory into a freshly-created graph.

Parameters
[in]dataBorrows it. Readable byte buffer containing STL data. Must be non-NULL when size is non-zero.
[in]sizeNumber of bytes available at data. Must be > 0.
[out]out_graphOwns it. Receives a new graph on success; NULL on failure.
[out]out_rootBorrows it. Receives the NodeId of the root entity.
Return values
OCCTL_OKOn success.
OCCTL_INVALID_ARGUMENTdata, out_graph, or out_root is NULL, or size is zero.
OCCTL_FORMAT_ERRORPayload contents were not a valid STL stream.
OCCTL_TOPOLOGY_INVALIDPayload decoded but could not be ingested into BRepGraph.

\par Thread Safety Yes.

See also
occtl_io_stl_write_memory, occtl_io_stl_read

◆ occtl_io_stl_write()

occtl_status_t occtl_io_stl_write ( const occtl_graph_t graph,
occtl_node_id_t  root,
const char *  path,
const occtl_io_stl_write_options_t options 
)

Writes the topology rooted at root to an STL file.

Format (binary/ASCII) is taken from options; pass NULL for default binary output.

Parameters
[in]graphBorrows it. Must be non-NULL.
[in]rootRoot node id to serialise.
[in]pathBorrows it. NUL-terminated UTF-8 path; existing file is overwritten.
[in]optionsBorrows it. May be NULL.
Return values
OCCTL_OKOn success.
OCCTL_INVALID_ARGUMENTgraph or path is NULL; or options has invalid fields (non-NULL p_next, ascii_mode not in {0,1}).
OCCTL_NOT_FOUNDroot is invalid or has been removed.
OCCTL_VERSION_MISMATCHoptions has an unsupported struct_version.
OCCTL_IO_ERRORFilesystem failure or unwritable file.

\par Thread Safety Yes (read-only on graph).

See also
occtl_io_stl_read, occtl_de_write

◆ occtl_io_stl_write_memory()

occtl_status_t occtl_io_stl_write_memory ( const occtl_graph_t graph,
occtl_node_id_t  root,
const occtl_io_stl_write_options_t options,
uint8_t *  out_data,
size_t  capacity,
size_t *  out_size 
)

Writes the topology rooted at root to caller-owned memory.

Use the standard two-call buffer pattern: call once with out_data NULL and capacity zero to receive the required byte count in out_size, then call again with a buffer of at least that size.

Parameters
[in]graphBorrows it. Must be non-NULL.
[in]rootRoot node id to serialise.
[in]optionsBorrows it. May be NULL.
[out]out_dataBorrows it. Writable output buffer, or NULL for sizing.
[in]capacitySize of out_data in bytes.
[out]out_sizeBorrows it. Receives the required byte count.
Return values
OCCTL_OKOn success. Sizing calls also return OK.
OCCTL_INVALID_ARGUMENTgraph or out_size is NULL; or options has invalid fields (non-NULL p_next, ascii_mode not in {0,1}).
OCCTL_NOT_FOUNDroot is invalid or has been removed.
OCCTL_VERSION_MISMATCHoptions has an unsupported struct_version.
OCCTL_BUFFER_TOO_SMALLout_data is non-NULL and capacity is smaller than out_size.
OCCTL_IO_ERROROCCT failed to serialise the shape.

\par Thread Safety Yes (read-only on graph).

See also
occtl_io_stl_read_memory, occtl_io_stl_write

◆ occtl_io_stl_write_options_init()

void occtl_io_stl_write_options_init ( occtl_io_stl_write_options_t options)

Initialises options to default values matching OCCTL_IO_STL_WRITE_OPTIONS_INIT.

NULL-tolerant.

Parameters
[out]optionsBorrows it. May be NULL (no-op).

\par Thread Safety Yes.

See also
occtl_io_stl_write, occtl_io_stl_write_memory