sqzc3d API 参考
适用于 sqzc3d v0.4.x(ABI SQZC3D_ABI_VERSION=4)。
头文件
include/sqzc3d.h: public C APIinclude/sqzc3d_types.h: shared scalar and status typesinclude/sqzc3d_easy.h: lightweight C++ convenience helpers
初始化 helpers
API |
用途 |
|---|---|
|
以安全默认值填充 |
|
以安全默认值填充 |
|
streaming 全帧 points 读取的 preset。 |
|
streaming 且显式点选择的 preset。 |
|
window analysis preset(带 residual gate 默认值)。 |
|
interpolation 友好的 window 读取 preset。 |
|
以安全默认值填充 bundle-load options。 |
|
以零/默认填充 error-detail struct。 |
|
返回语义版本字符串。 |
|
返回 ABI 版本整数。 |
默认行为备注:
Option structs 必须设置
struct_size == sizeof(struct);请用sqzc3d_default_*_opt(...)初始化。sqzc3d_default_build_opt(...)默认会 materialize analogs(analog_enable = sqzc3d_ANALOG_EN_ON)。sqzc3d_build_opt_t::target_unit可将 materialized 的chunk->points_xyz转成mm、cm、m或km;NULL/空字符串表示保持 source units。当
analog_enable = sqzc3d_ANALOG_EN_AUTO时,sqzc3d_build_chunks会强制analog_size_soft_limit_bytes(默认500 MiB),若预计 analog payload 超过该限制则以sqzc3d_STATUS_INVALID_ARGUMENT失败。
生命周期
API |
用途 |
|---|---|
|
从文件路径打开 C3D。 |
|
从内存 buffer 打开 C3D。 |
|
释放 decoder handle。 |
|
获取最近一次 API 错误文本或结构化详情。 |
备注:
sqzc3d_open_memory会把输入 bytes 复制到 decoder 自己持有的内存源中读取。 调用返回后,caller 可以释放或修改原始 buffer;这不是 zero-copy borrowed-buffer API。Decoder 与 chunk handle 内部不做同步。同一个 handle 应一次只在一个线程中使用;如需并发调用, 由 caller 在外层加锁。
sqzc3d_last_error(NULL)与sqzc3d_last_error_detail(NULL, ...)会返回当前线程的最近一次错误。 这对sqzc3d_open_file/sqzc3d_open_memory在返回 decoder handle 之前就失败的情况非常有用。
在
SQZC3D_WITH_EZC3D=OFF时,sqzc3d_open_file、sqzc3d_open_memory、sqzc3d_build_chunks会返回sqzc3d_STATUS_NOT_IMPLEMENTED;以sqzc3d_get_features()为准。
Chunk 构建与查询
API |
用途 |
|---|---|
|
将指定 frame/point/analog 范围解析并 materialize 为一个 chunk 对象。 |
|
释放 chunk 资源。 |
|
获取 chunk shape。 |
|
可选的 chunk-local -> source-total point index 映射(若可用)。 |
|
可选的 |
|
可选的时间轴元数据(源 first/last frame、采样率、窗口起点)。 |
|
labels -> indices 映射。 |
|
按 frame、index list 或 selected frame+points 构建 points views。 |
|
按 sample range 或 channel list 构建 analog views。 |
Chunk point payload:
chunk->points_xyz:frame-major[T][P][3];若设置target_unit,这里已经完成单位转换。chunk->points_valid:frame-major[T][P]。chunk->points_residual:frame-major[T][P];raw decoded residual,保持 source point units。chunk->residual_nscalar:residual 可用时为T * P。单位元数据:
point_units_per_meter、target_units_per_meter、residual_units_per_meter、point_units_source。
Residual validity policy:
默认
sqzc3d_VALID_POLICY_FINITE_XYZ只按 finite xyz 判定 valid。sqzc3d_VALID_POLICY_FINITE_XYZ_AND_RESIDUAL_GATE会额外应用residual_gate_mm。residual_gate_mm永远以 millimeters 表示;sqzc3d 内部会换算到 residual source units 后比较。points_residual始终可读,不受 valid policy 影响,也不会随target_unit缩放。
View lifetime:
sqzc3d_points_view_t借用sqzc3d_chunk_t的 point storage;view 不可超过 source chunk 生命周期。非连续 point view 还会借用 caller 传入的
point_indices数组。sqzc3d_analogs_view_t对 chunk analog storage 和 caller 传入的channel_indices数组遵循同样规则。
Bundle 持久化
API |
用途 |
|---|---|
|
写出 |
|
从持久化 bundle 加载为 chunk。 |
|
带 strict flag 的严格加载变体。 |
Type-group metadata and default layout
chunk->type_group_names: group names(长度chunk->n_type_groups)。chunk->type_group_starts: prefix-sum offsets,长度n_type_groups + 1。chunk->type_group_indices: flattened group indices,位于 chunk-local point index space[0..n_points);indices[type_group_starts[i]..type_group_starts[i+1])是type_group_names[i]对应的 indices(索引到chunk->point_labels)。Optional:
sqzc3d_chunk_point_indices_total()在可用时提供 chunk-local -> source-total 映射。
在 v0.x 中,默认 points layout 固定为:
points_layout = sqzc3d_POINTS_LAYOUT_FRAME_MAJORpoints_pack = sqzc3d_POINTS_PACK_AOS_XYZ_VALID默认 easy 层契约:
PointWindow为 frame-major,AoS XYZ;valid与residual为 frame-major [T][K]。points_xyz_shape = [n_frames][n_points][3](contiguous)points_xyz_stride = [n_points*3, 3, 1]points_valid_shape = [n_frames][n_points](contiguous)points_valid_stride = [n_points, 1]points_residual_shape = [n_frames][n_points](contiguous)points_residual_stride = [n_points, 1]
v0.x 默认 analog layout 为 channel-major
(C, N):analog_shape = [n_analogs][n_frames*n_analog_by_frame](contiguous)analog_stride = [n_frames*n_analog_by_frame, 1]
特性与能力
API |
用途 |
|---|---|
|
读取运行时可用性 bits。 |
在实践中,这通常是第一步调用:在进入 feature-gated 路径之前,用它来判断当前 build 是否启用了 C3D 解析与 analog APIs。
Easy API
include/sqzc3d_easy.h 中的 header-only helpers:
sqzc3d::MakeFrameWindowBuildOpt/sqzc3d::ReadPointsWindow以选定的 preset 构建一个带 window 的 frame-range chunk。
sqzc3d::ReadPointsWindowByLabels基于 labels 的 windowing。
sqzc3d::FrameMajorPointsView将 chunk 指针转换为 frame-major AoS view,shape 为
[frame][point][xyz]。
sqzc3d::AnalogSamplesView将 chunk 指针转换为 analog view,采用 channel-major
(C, N)布局。
sqzc3d::FrameMajorAnalogViewTCS在底层
(C, N)存储之上提供非连续(strided)的 frame-major view(T, C, S)。
sqzc3d::PointIndicesFromTypeGroups将 type-group names 转换为一个扁平的 chunk-local point index list。
默认过滤语义:缺失 TYPE_GROUPS 元数据 => no-op(all points);group name 缺失 => 空集。
sqzc3d::PointIndicesFromTypeGroupsStrict严格变体,显式报错(返回
sqzc3d_STATUS_*)。
sqzc3d::ChunkQuery/sqzc3d::ChunkRecipe最小 AND-only 的 chunk-local filtering helpers(Query 绑定 chunk;Recipe 可复用)。
sqzc3d::ReorderFrameMajorToPointMajor供需要 point-major layout 的消费者使用的 reorder helper。
状态码与枚举
返回码为来自
sqzc3d_types.h的 C-style ints:sqzc3d_STATUS_SUCCESSsqzc3d_STATUS_INVALID_ARGUMENTsqzc3d_STATUS_DIMENSION_MISMATCHsqzc3d_STATUS_NOT_IMPLEMENTEDsqzc3d_STATUS_INTERNAL_ERROR
重要的 enum families:
input type:
sqzc3d_FILE、sqzc3d_MEMORYselection mode:indices/labels/all
read policy:
AUTO、DENSE、SPARSEvalid policy:
sqzc3d_VALID_POLICY_FINITE_XYZ、sqzc3d_VALID_POLICY_FINITE_XYZ_AND_RESIDUAL_GATE
备注
API 与 C89 兼容(C++ 可通过
extern "C"使用)。所有非
constout-parameters 都要求 caller 提供可写内存。由本库分配的资源必须使用对应的
freeAPIs 释放。public residual payload 已提供为 raw source-unit decoded residual;camera mask 还不是 public payload。
Python API
Python bindings 基于 pybind11。
Python 高层导出:
sqzc3d.version()sqzc3d.abi_version()sqzc3d.features()sqzc3d.read(...) -> sqzc3d.View(easy 层)sqzc3d.View(easy 层)sqzc3d.Recipe(sqzc3d.ChunkRecipe的 alias)sqzc3d.Decodersqzc3d.Chunksqzc3d.ChunkQuery/sqzc3d.ChunkRecipe(AND-only chunk-local filtering)sqzc3d.type_group_indices(chunk, group_names, strict=False)sqzc3d.load_bundle(path: str, strict: bool = True)sqzc3d.export_bundle(out_dir: str, chunk: sqzc3d.Chunk)
Easy 层
推荐大多数用户从这里开始。
read:
sqzc3d.read(source, *, start_frame=0, frame_count=-1, points=None, analogs=None, analog_range=None, label_norm=..., recipe=None, target_unit=None) -> View
选择器语义(Python):
None= default(ALL)[]= empty selection
View:
Selection state(labels-first):
view.point_labels(None | list[str])view.analog_labels(None | list[str])view.type_groups(list[str])
Data(properties):
view.points/view.points_validview.points_residualview.analogs/view.analogs_valid
Label accessors:
view.point["LANK"]/view.point_valid["LANK"]view.point_residual["LANK"]view.analog["EMG1"]/view.analog_valid["EMG1"]
Metadata:
view.meta(flat dict)view.meta_tree(EZ parameter tree;若可用;bundle 会保留;从 C3D 提取需要SQZC3D_WITH_EZC3D=ON)
Advanced escape hatch:
view._chunk(pybindChunk;indices/masks 等被视作 advanced)
Notes:
easy 层按设计为 labels-only。若你已有 indices,请使用 core API 并直接 slice 数组。
Decoder:
Decoder(path, label_norm=sqzc3d.SQZC3D_LABEL_NORM_EXACT)Decoder.read(start_frame=0, frame_count=-1, points=None, analogs=None, analog_range=None, target_unit="")Decoder.close()Decoder.source_path(只读)Decoder.closed(只读 bool)
Chunk:
chunk.points(selector=None, copy=True) -> (values, valid)chunk.residual(selector=None, copy=True) -> residualchunk.analogs(selector=None, layout="CN", copy=True) -> (values, valid)layout="tcs"会返回一个非连续的 frame-major view(T, C, S)(底层仍为 channel-major 存储)。
chunk.meta(dict)chunk.meta_tree(dict:若可用;bundle 会保留;open_memory也应可用)chunk.source_path(只读)
Python payload 语义:
pointsvalues:float64,默认 frame-major shape(T, P, 3),valid mask(T, P)dtypeuint8。residualvalues:float64,默认 frame-major shape(T, P),source point units。analogsvalues:layout="CN"默认:(C, N),其中N = n_frames * n_analog_by_framelayout="tcs":(T, C, S)non-contiguous view helper
selector:
None表示 all[]表示 emptyint或list/tuple[int]为 index selectionstr或list/tuple[str]为 label selection
非连续选择需要
copy=True;copy=False当前会抛RuntimeError,以避免隐藏的转换。