Persistence: Stores, Records and Clash States#
The Suite API saves clash results in a store
that the caller opens explicitly. Every store holds the same four record types:
queries, clashes, frames and point-cloud
settings. Two built-in stores
keep them, a SQLite database file and a folder of JSON files, and both work through one data
API: the Python ClashData facade over a serializer, the class that reads and writes one kind of
store, and the C ovclash_suite_data_t handle.
This page covers what all stores share:
Choosing a store compares the two built-in stores.
The walkthrough reads the store that Suite Workflows wrote, reviews its clashes and reads it again from C.
The object model, Opening and committing and CRUD are the reference for the records and the handle.
Saving detection results and Clash states cover fetch-and-save, its transaction rules and the clash states it maintains.
Custom stores, Numeric fidelity, Schema compatibility and Failures that do not raise complete the reference.
SQLite serializer and Directory serializer
document each store’s format. Legacy Containers covers the
.clashDetection file of Kit’s clash detection extension, a
legacy container, and Export turns records into JSON or HTML
reports.
Choosing a store#
SQLite serializer |
Directory serializer |
|
|---|---|---|
Python class |
|
|
C constructor |
|
|
Store |
One SQLite database file, by convention with the |
One folder of readable JSON files, one file per record |
Legacy |
Opens them, and exports them through |
Not supported; the suffix is part of the folder name |
Handles on one store |
Several, serialized by SQLite file locking |
One at a time, through an operating-system lock |
NaN in scalar values |
Rejected |
Stored |
Sign of a scalar zero |
Lost |
Kept |
Format versions |
Per-table schema versions with forward migration |
One format version, no migration |
Interrupted commits |
SQLite’s own journal |
Restored after a process stops; not guaranteed after an operating-system crash or power loss |
Runtime requirement |
The system SQLite library |
None |
Choose the SQLite serializer for large stores, compact storage and write throughput. It is the default. Choose the directory serializer when people or tools must read, diff or version the records as text. It costs more than SQLite in parsing, memory and file count, and it keeps every clash header in memory while the store is open.
Neither store converts the other’s format. To move records from one store to the other, read them through one handle and insert them through another. A NaN that the directory store holds cannot be written to a SQLite store. A custom store keeps records in storage that you implement, under the same transaction contract.
Walkthrough#
Before you begin, Step 1 to Step 3 need:
dynamic.ovclashdbin the current directory. Run the script from Step 3 of Suite Workflows to create it. It holds one query with 8 clashes.The
ovclash_suitePython package for the Python steps. Run each script from the directory that holdsdynamic.ovclashdb.For the C step,
<ovclash_suite/ovclash_suite.h>and the ovclash library from the SDK archive.
The steps use the default SQLite serializer. Apart from creating and destroying the serializer (Directory serializer shows how), the Python code is the same for a directory store.
Step 1: Read the store#
This script lists the queries, the clashes of each query and the first frames of one clash:
from ovclash_suite import ClashData
data = ClashData()
try:
data.open("dynamic.ovclashdb")
if not data.is_open():
raise RuntimeError(data.last_error() or "could not open dynamic.ovclashdb")
for query_id, query in data.fetch_all_queries().items():
print(f"Query {query_id}: {query.query_name}")
overlaps = data.find_all_overlaps_by_query_id(query_id, False) # without frames
for info in overlaps.values():
mesh = info.object_a_path.rsplit("/", 1)[-1]
kind = "hard" if info.is_hard_clash else "soft"
print(
f" {mesh}: {kind}, {info.state.name}, {info.num_records} frames,"
f" min distance {info.min_distance:.3f}"
)
first = next(iter(overlaps.values()))
frames = data.fetch_clash_frame_info_by_clash_info_id(first.identifier, num_frames_to_load=3)
print(f"First frames of {first.object_a_path.rsplit('/', 1)[-1]}:")
for frame in frames:
print(f" t={frame.timecode:.3f} s, {frame.overlap_tris} triangles")
finally:
data.destroy()
Expected output:
Query 1: Example Dynamic Query
NV_Mesh1: soft, NEW, 5 frames, min distance 2.952
NV_Mesh11: hard, NEW, 61 frames, min distance 0.000
NV_Mesh3: hard, NEW, 6 frames, min distance 0.000
NV_Mesh12: hard, NEW, 9 frames, min distance 0.000
NV_Mesh2: hard, NEW, 6 frames, min distance 0.000
NV_Mesh4: hard, NEW, 8 frames, min distance 0.000
NV_Mesh5: hard, NEW, 8 frames, min distance 0.000
NV_Mesh0: soft, NEW, 5 frames, min distance 2.372
First frames of NV_Mesh1:
t=4.208 s, 108 triangles
t=4.250 s, 118 triangles
t=4.292 s, 64 triangles
find_all_overlaps_by_query_id()returns adictkeyed byoverlap_id, the clash hash as text. The clashes come inoverlap_idorder.is_hard_clashis true for a hard clash: a mesh clash withmin_distance0 that is not a contact.is_contactis true when such a pair’smax_local_depthstays withindepth_epsilon, or is exactly 0 whendepth_epsilonis not positive.is_soft_clashis true for a soft clash, a mesh clash with a positivemin_distance. The meshes do not touch, but they are closer than the query’s tolerance of 5 units.Every clash starts as
NEW. Fetch-and-save maintains the state; see Clash states.
Step 2: Review clashes in one transaction#
This script approves the soft clashes and writes all changes in one transaction:
from ovclash_suite import ClashData, ClashState
data = ClashData()
try:
data.open("dynamic.ovclashdb")
query_id = next(iter(data.fetch_all_queries()))
for info in data.find_all_overlaps_by_query_id(query_id, False).values():
if info.is_soft_clash: # closer than the tolerance, but not touching
info.state = ClashState.APPROVED # also refreshes last_modified_*
info.comment = "Clearance accepted in review."
data.update_overlap(info, update_also_frame_info=False, commit=False)
data.commit() # one transaction for the whole batch
counts = data.get_overlaps_count_by_query_id_grouped_by_state(query_id)
for state, count in counts.items():
print(f"{state.name}: {count}")
finally:
data.destroy()
Expected output:
NEW: 6
APPROVED: 2
commit=Falsebatches the writes. The singlecommit()writes them together. See CRUD for the batching and rollback rules.update_also_frame_info=Falsekeeps the stored frames. The defaultTruereplaces the stored frames with the frames attached toinfo. AClashInforead withfetch_also_frame_info=Falsehas none attached, so the default would delete its frames.Assigning a review field refreshes the modification metadata. See The object model for the fields you can assign.
Step 3: Read the store from C#
This program opens the same store, reads the first query and walks its clashes with a cursor.
Save it as a C source file, and build and link it against the SDK archive as
C/C++ Quickstart shows. When the build cannot find the headers or the
program does not start, see Configuring with CMake
and Starting a C or C++ program. Run it from the
directory that holds dynamic.ovclashdb:
#include <ovclash_suite/ovclash_suite.h>
#include <stdio.h>
static int ok(ovclash_suite_result_t result)
{
return result.status == OVCLASH_SUITE_STATUS_SUCCESS;
}
int main(void)
{
static const char path[] = "dynamic.ovclashdb";
const ovclash_suite_string_t store = { path, sizeof(path) - 1u };
ovclash_suite_data_t* data = NULL;
ovclash_suite_overlap_cursor_t* cursor = NULL;
ovclash_suite_query_view_t query;
ovclash_suite_clash_info_record_view_t overlap;
uint32_t has_value = 0u;
int64_t query_id = -1;
int status = 1;
if (!ok(ovclash_suite_data_create(&data)) || !ok(ovclash_suite_data_open(data, store)) ||
!ok(ovclash_suite_data_get_query_at(data, 0u, &query)))
goto cleanup;
query_id = query.identifier; /* the view is reused by the next query read */
printf("Query %lld: %.*s\n", (long long)query_id, (int)query.query_name.length, query.query_name.ptr);
/* offset 0, limit 0: every overlap of the query, without frame payloads */
if (!ok(ovclash_suite_data_get_overlaps_by_query(data, query_id, 0, 0, &cursor))) goto cleanup;
for (;;)
{
/* has_value is 0 both at the end and on error, so check the status first */
if (!ok(ovclash_suite_overlap_cursor_next(cursor, &overlap, &has_value))) goto cleanup;
if (!has_value) break; /* running out of rows is not an error */
/* overlap borrows cursor memory until the next advance: copy what you keep */
printf(" %.*s: state %u, %u frames\n", (int)overlap.overlap_id.length, overlap.overlap_id.ptr,
overlap.state, overlap.frame_count);
}
status = 0;
cleanup:
if (status != 0)
{
ovclash_suite_string_t error = ovclash_suite_get_thread_last_error();
fprintf(stderr, "error: %.*s\n", (int)error.length, error.ptr ? error.ptr : "");
}
ovclash_suite_overlap_cursor_destroy(cursor); /* destroy cursors before their data handle */
ovclash_suite_data_destroy(data);
return status;
}
Expected output after Step 2 (state 1 is NEW,
state 2 is APPROVED):
Query 1: Example Dynamic Query
0x19cd3f588ebbe2ceb23cc376f9087468: state 2, 5 frames
0x25f2f5911be3e91fef42b2afd3180bc1: state 1, 61 frames
0x5d8c8297e92d15be6ca04d7842fd78cd: state 1, 6 frames
0x69e4fae9370fa52b7ea3db54ad637eca: state 1, 9 frames
0x7689304c8a4904a09ead603b938dd79f: state 1, 6 frames
0xa872e774aa37600c3cf14ddc3ae7d4ae: state 1, 8 frames
0xbf454dfc1d8736ec3b36be0e4141862: state 1, 8 frames
0xfc4b56832f4edf849d49ff547777a49f: state 2, 5 frames
Frames explains why sequential reads should use a cursor. You can now open a store, read its queries, clashes and frames, and review clashes in one transaction, in either language.
The object model#
Four record types are persisted:
Record |
Python class |
C record view |
Holds |
Belongs to |
|---|---|---|---|---|
Query |
|
|
Query name, both scope paths, settings JSON, ROI paths, comment and modification metadata |
– |
Clash |
|
|
One mesh, duplicate or point-cloud clash: detection results and review fields |
A query, through |
Frame |
|
|
One sample of a clash: metrics, both object matrices, and face, outline and point buffers |
A clash, through |
Point-cloud settings |
|
|
Source prim path, destination path, rendering flags and level-of-detail (LOD) limit |
– |
The tables in this section list the fields of the Python classes. Every field is an optional
constructor keyword argument with the default shown. The C record views carry the same fields:
strings as ovclash_suite_string_t, flags as uint32_t, timestamps as storage strings, and the
query settings as settings_json text. The field comments in
<ovclash_suite/ovclash_suite_types.h> define each C field.
ClashQuery is the root of a run.
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Signed 64-bit record identifier. |
|
|
|
The user-facing query name. |
|
|
|
The scope of search sets A and B as text: prim paths separated by spaces, tabs or newlines, the form that |
|
|
|
|
|
|
The current time |
When the query was created and last modified. |
|
|
The current user name |
Who modified the query last. |
|
|
|
A free-form comment. |
|
|
|
The ROI paths, region-of-interest include and exclude paths. They are stored, serialized and read back unchanged, but detection does not use them, so two queries that differ only in them produce identical results. |
get_settings_as_str() and load_settings_from_str() convert clash_detect_settings to and from
its stored JSON text.
ClashInfo is the row a report renders, a clash record.
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
The store’s record identifier. |
|
|
|
The identifier of the owning query. |
|
|
|
The clash hash as text: |
|
|
|
|
|
|
|
False when the last fetch-and-save into the query did not detect the clash. |
|
|
|
Minimum distance in stage units; 0 when the meshes touch or interpenetrate. |
|
|
|
Maximum local depth in stage units. |
|
|
|
The depth epsilon and tolerance that the clash was detected with. |
|
|
|
The prim paths of the two objects. |
|
|
|
The mesh hashes of the two objects as text. |
|
|
|
The first and last sample time of the clash, in seconds. |
|
|
|
The number of frames. |
|
|
|
The number of overlapping elements, triangles or points. |
|
|
|
The clash state; see Clash states. |
|
|
|
A priority that your application assigns. |
|
|
|
The person who owns the review. |
|
|
The current time |
When the record was created and last modified. |
|
|
The current user name |
Who modified the record last. |
|
|
|
A review comment. |
|
|
|
The attached frames; |
|
|
|
Penetration depths along the positive and negative X, Y and Z axes, in stage units. |
The detection fields run from overlap_type to overlap_elements, plus the six
penetration_depth_* axes. The review fields are state, priority, person_in_charge and
comment, and the two timestamps and last_modified_by record changes.
is_contact, is_hard_clash, is_soft_clash, is_duplicate and is_point_cloud_clash
classify a record from its own fields, without a native call.
Two ClashInfo rules:
Most fields are read-only after construction. Assigning
identifier,query_id,overlap_id,overlap_type,present,min_distance,depth_epsilon,tolerance, anobject_a_*orobject_b_*field,start_time,end_time,num_records,overlap_elements,creation_timestamporlast_modified_byraisesAttributeError.Editable fields refresh the modification metadata. Assigning
state,priority,person_in_charge,comment,max_local_depthor apenetration_depth_*field goes through the native model. It setslast_modified_timestampto the current time andlast_modified_byto the current user.
The underscore-prefixed legacy aliases, such as _state, bypass both rules. Fetch-and-save
maintains present and state; see Clash states.
ClashFrameInfo is one sample of a clash, a frame.
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
The sample time, in seconds despite the name. |
|
|
|
Minimum distance in this frame, in stage units. |
|
|
|
Maximum local depth in this frame, in stage units. |
|
|
|
The number of overlapping elements in this frame. |
|
|
Empty |
The authored face indices of each object that collide. |
|
|
Empty |
The intersection outline as segments, |
|
Four rows of four |
Identity |
The row-major local-to-world transforms of the two objects. |
|
|
Empty |
The colliding point indices of a point-cloud clash. |
|
|
Empty |
The point sizes of a point-cloud clash. |
|
|
|
Penetration depths along the positive and negative X, Y and Z axes, in stage units. |
overlap_trisreturnsoverlap_elementswhen the frame has nousd_points_0, as in a mesh frame.overlap_pointsreturns it when the frame hasusd_points_0, as in a point-cloud frame. The other property returns 0.A static clash and a duplicate have one frame. A dynamic clash has one frame per sample where the pair still overlapped.
PointCloudSettings belongs to no query. ovclash stores and reads it back but never acts on
it.
Field |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
The store’s record identifier. |
|
|
|
The source point-cloud prim path. |
|
|
|
The destination path for generated data. |
|
|
|
Whether generated data goes to the session layer. |
|
|
|
Whether rendering of the point cloud is skipped. |
|
|
|
The maximum level of detail (LOD), stored as given; no value has a special meaning, and the default is effectively unlimited. |
Each of the four classes has a class-level VERSION, equal to its SQLite table’s
schema version. Each also has a
serialize_to_dict() / deserialize_from_dict() pair for the legacy dictionary format.
deserialize_from_dict() returns None for malformed data.
Opening and committing#
ClashDataSerializerSqlite and ClashDataSerializerDirectory each own a native
ovclash_suite_data_t, created by ovclash_suite_data_create() and
ovclash_suite_data_create_directory(). ClashData is a facade over any
AbstractClashDataSerializer:
ClashData()creates and owns a closed SQLite serializer.ClashData(serializer)uses a serializer you own.destroy()then only closes it, and you destroy the serializer yourself.
This script opens or creates results.ovclashdb in the current directory, adds one query and
commits it:
from ovclash_suite import ClashData, ClashQuery
data = ClashData()
try:
data.open("results.ovclashdb")
if not data.is_open():
raise RuntimeError(data.last_error() or "could not open results.ovclashdb")
query = ClashQuery(query_name="Example query")
data.insert_query(query, commit=False) # pending until commit()
data.commit()
print(f"Saved query {query.identifier}")
finally:
data.destroy()
It prints Saved query <identifier>, where <identifier> is the identifier that the store
assigned.
Call |
Behavior |
|---|---|
|
Closes any open store, then opens |
|
Reports whether a store is open, including an unnamed one. |
|
Commits pending writes. |
|
Without a path, commits pending writes. On a SQLite store opened or migrated from a |
|
SQLite copies the store to |
|
Attempts to commit pending writes, including partial fetch results, then closes. A failed commit requests rollback, raises, and keeps the store for inspection and retry. |
|
Closes like |
These rows describe ClashData over a built-in serializer. A custom store
defines its own behavior. SQLite serializer and
Directory serializer give each store’s details.
The C calls follow the same sequence. This function belongs in a C source file of your program; it opens the same store, prints its query count and commits:
#include <stdio.h>
#include <ovclash_suite/ovclash_suite.h>
/* Returns 0 on success. */
static int count_queries(void)
{
ovclash_suite_data_t* data = NULL;
const char path[] = "results.ovclashdb";
const ovclash_suite_string_t store = { path, sizeof(path) - 1 };
uint32_t count = 0u;
int status = 1;
if (ovclash_suite_data_create(&data).status == OVCLASH_SUITE_STATUS_SUCCESS &&
ovclash_suite_data_open(data, store).status == OVCLASH_SUITE_STATUS_SUCCESS &&
ovclash_suite_data_get_query_count(data, &count).status == OVCLASH_SUITE_STATUS_SUCCESS &&
ovclash_suite_data_commit(data).status == OVCLASH_SUITE_STATUS_SUCCESS)
{
printf("%u queries\n", count);
status = 0;
}
ovclash_suite_data_destroy(data); /* accepts NULL */
return status;
}
ovclash_suite_data_get_file_path() and ovclash_suite_data_get_file_size() report the store’s
path and size. ovclash_suite_data_get_last_error() returns the handle’s last failure text.
Handle and cursor lifetime:
Python read methods materialize their results and release their native cursors before returning.
A live fetch operation blocks writes, commit and store lifecycle changes (open, save, save-as, migrate, close and destroy) until it is destroyed. An async fetch also blocks reads from other threads.
A live overlap or frame cursor blocks lifecycle changes, even when it is exhausted.
In Python, exhaust or close the fetch generator and any
fetch_iter_saved_frames()iterator before you close or reopen the store.
Suite fetch and cursor lifetime has the full table.
Deferred creation and unnamed stores#
Creating a missing store waits for the first write by default. Opening a missing path creates no file or folder; the first write creates it. Change this with
ovclash_suite_data_set_deferred_file_creation_until_first_write_op()or theClashData.deferred_file_creation_until_first_write_opproperty.open("")on a built-in serializer opens an unnamed store: a private temporary database for SQLite, a private temporary folder for a directory store. Its path is empty, andovclash_suite_data_get_file_size()fails for it. It supports reads, writes and fetch-and-save.Closing or destroying an unnamed store deletes its records. To keep them, call
save_as(path)before closing. The named copy becomes the current store.ClashData.open("")does nothing. Open the unnamed store through the serializer, then pass that serializer toClashData(serializer).
Each store has its own path rules: see SQLite store path and Directory store path.
Use the class constants instead of literal extensions:
ClashDataSerializerSqlite.SERIALIZED_FILE_EXTis.ovclashdb.ClashData.CLASH_DATA_LAYER_FILE_EXTis.clashDetection.ClashDataSerializerDirectory.SERIALIZED_FILE_EXTis empty.
CRUD#
CRUD stands for create, read, update and delete, the record operations of the data API. Every C
insert, update and remove function has two forms: a plain one and a _with_commit one.
The plain form is not “no commit”: it calls the
_with_commitform withcommit = 1.To batch a run’s writes into one transaction, pass
commit = 0to the_with_commitform and callovclash_suite_data_commit()once at the end.The bulk
ovclash_suite_data_replace_frames_by_overlap_with_commit()has only the_with_commitform.In Python, the
commitkeyword argument makes the same choice and defaults toTrue.Pending writes are committed by
commit(),save(),save_as(),close(),destroy()or a later write withcommit=True.
Note
A write that fails after its storage write began rolls back the handle’s whole pending transaction, on both built-in stores. Every earlier write made with
commit = 0is discarded, including writes that returned success. Committed data is kept. Such failures include:
constraint, SQLite and filesystem errors, and a failed commit;
a NaN
REALvalue on a SQLite store;a non-finite frame matrix;
a record string containing NUL on a directory store.
Argument, open-state, fetch-reservation and not-found failures are reported before the write begins and leave pending writes untouched. Validate inputs before a batch, or commit before a write that may fail.
Return values with the built-in serializers:
Python inserts return the stored identifier.
insert_clash_frame_info_from_clash_info()instead returns the number of frames it wrote.Update methods and single-record remove methods return 1, or 0 when the identifier is not stored.
remove_all_overlaps_by_query_id()andremove_clash_frame_info_by_clash_info_id()return the number of records removed.find_query()and thefind_point_cloud_settings*()methods returnNonewhen no record matches. A Cfindfunction then fails with an empty last-error text, which separates absence from an error.
In C, fill a record view from the object model table and call the insert and update functions:
The insert and update functions copy input strings and buffers.
Views returned by a read are borrowed. A getter that is not a cursor reuses a per-kind scratch record on the data handle. Copy its view before the next read of the same kind, any write, close or destroy.
A cursor view belongs to its cursor.
In the tables of Queries, Overlaps, Frames and Point-cloud settings, the C column names the plain form.
Queries#
Python |
C |
|---|---|
|
|
|
|
|
|
|
|
|
|
With
update_identifier=True(nonzero in C), an insert generates a new identifier. Python also writes it back to the object.With
False, the store keeps the record’s own identifier. A negative identifier still gets a generated one, which Python does not write back.Clash and point-cloud-settings inserts work the same way.
Removing a query also removes its clashes and their frames.
fetch_all_queries()returnsdict[int, ClashQuery]keyed by identifier. It raisesRuntimeErrorwhen the count or any counted row cannot be read; it never returns a partial inventory.fetch_all_point_cloud_settings()follows the same rule.Neither inventory call holds one snapshot across its count and row reads. Writes through another handle can change the inventory between them.
Overlaps#
These calls read and write clash records (ClashInfo); the data API names them overlaps.
Python |
C |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Reading clashes:
The
overlap_idparameter offind_all_overlaps_by_overlap_id()andremove_overlap_by_id()takes record identifiers (ClashInfo.identifier), not clash hashes. Identifiers that are not stored are skipped.Both
find_all_overlaps_*methods returndict[str, ClashInfo]keyed byoverlap_id, the clash-hash text, not by record identifier.Both take
num_frames_to_loadandfirst_frame_offset. The by-query form also takesnum_overlaps_to_loadandfirst_overlap_offset. A count of-1loads all;0or another negative count loads none.Pass
fetch_also_frame_info=Falseto read summaries without frame geometry.The grouped-by-state form returns
dict[ClashState, int]and omits states without clashes. A stored state that names noClashStatecounts asNEW. In C,ovclash_suite_data_get_overlap_state_count_by_query()returns the number of state buckets, andovclash_suite_data_get_overlap_state_count_at()reads one bucket, in ascending state order, into anovclash_suite_state_count_view_t.
ovclash_suite_state_count_view_t, in <ovclash_suite/ovclash_suite_types.h>:
Field |
Type |
Required |
Default or values |
Description |
|---|---|---|---|---|
|
|
Yes |
An |
The state of the bucket, as stored. The C ABI does not merge unknown values into |
|
|
Yes |
1 or more |
The clashes of the query in that state. |
Writing clashes with frames:
insert_overlap()andupdate_overlap()convert every attached frame before writing anything. They write the clash row uncommitted, and the frame replacement appliescommitto both.With
update_also_frame_info=True, the stored frames are replaced by the attached ones. An update of aClashInforead without frames therefore deletes its stored frames.A frame that cannot be converted raises
ValueErrorwith nothing written.A frame write the store rejects, such as a non-finite matrix, rolls back the whole pending transaction, the clash row included.
More than 1,000,000 frames are rejected before the frame write begins, and the clash row stays pending.
insert_overlap()setsclash_info.identifieronly after both writes succeed.
Turning frames off still writes placeholder frames. With insert_also_frame_info=False, the
store creates one placeholder frame (identity matrices, no geometry) for each frame attached to
clash_info. An insert that reuses an identifier replaces that clash’s stored frames with the
placeholders. With update_also_frame_info=False, the store creates placeholders only while the
clash has no stored frames. In C, the frame_count field of
ovclash_suite_clash_info_record_view_t controls these placeholders. Set it to 0 and write real
frames with ovclash_suite_data_replace_frames_by_overlap_with_commit().
Frames#
Python |
C |
|---|---|
|
|
|
|
|
|
|
|
|
|
clash_info_id must name a stored clash. insert_clash_frame_info_from_clash_info() replaces
every stored frame of the clash with the frames attached to clash_info. It does so in one bulk
call that validates all frames before it changes anything.
Read records sequentially through a cursor, not by index.
ovclash_suite_data_get_frames_by_overlap() and ovclash_suite_data_get_overlaps_by_query()
each open one forward-only cursor, and stepping it reads each row once. An indexed getter such as
ovclash_suite_data_get_frame_by_overlap_at() can instead skip the preceding rows on every call;
SQLite reads gives the cost. The Python read methods already use
cursors.
The two cursors spell “all” differently. The overlap cursor’s limit is 0 for all remaining
clashes. The frame cursor’s max_frame_count is negative for all and 0 for none. Negative
offsets start at zero in both.
Cursor rules:
A view from
ovclash_suite_overlap_cursor_next()orovclash_suite_frame_cursor_next()borrows cursor-owned memory. The next advance or the cursor’s destruction invalidates it, so copy what you need first.Running out of rows is not an error. The call succeeds and sets
*out_has_value(overlaps) or*out_has_frame(frames) to 0.Destroy every cursor with
ovclash_suite_overlap_cursor_destroy()orovclash_suite_frame_cursor_destroy()before its data handle.
Both stores validate stored data when they read it, and a malformed record fails the read instead of being skipped. SQLite reads and Indexes and record locations list the checks.
Point-cloud settings#
Python |
C |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Saving detection results#
Fetch-and-save writes the results of a completed detection run into a store, as the clashes and
frames of one stored query. It keeps the identifiers and review fields of the clashes that the
store already holds, and it maintains their present flag and clash state
(Clash states).
Caller |
Calls |
|---|---|
Python, on the calling thread |
|
Python, on a background worker |
|
C, in bounded steps on the calling thread |
|
C, on a background worker |
|
C, one overlap at a time |
|
The destination is an open built-in store, or a custom store. In Python, pass a
ClashData or a serializer as clash_data. In C, pass the data handle with a NULL serializer.
Fetching Suite runtime results describes the Python
generator and AsyncFetchAndSave.
The bounded C loop, as a function for a C source file of your program. Call it after a
completed run of runtime, with data open and query_id stored in it:
#include <ovclash_suite/ovclash_suite.h>
/* Saves the completed run as the clashes of the stored query query_id. Pass the query's own
* SETTING_TOLERANCE, SETTING_DEPTH_EPSILON and SETTING_DUP_MESHES values. Returns 0 on success. */
static int fetch_and_save(ovclash_suite_runtime_t* runtime,
ovclash_suite_data_t* data,
int64_t query_id,
double tolerance,
double depth_epsilon,
uint32_t include_duplicates)
{
ovclash_suite_fetch_and_save_t* fetch = NULL;
uint32_t complete = 0u;
ovclash_suite_result_t r = ovclash_suite_runtime_fetch_and_save_begin(
runtime, data, NULL, query_id, tolerance, depth_epsilon, include_duplicates,
1u /* resolve_stale */, &fetch);
while (r.status == OVCLASH_SUITE_STATUS_SUCCESS && !complete)
{
double progress = 0.0;
r = ovclash_suite_runtime_fetch_and_save_next(fetch, &progress, &complete);
}
ovclash_suite_runtime_fetch_and_save_destroy(fetch); /* accepts NULL; consumes it, even on error */
return r.status == OVCLASH_SUITE_STATUS_SUCCESS ? 0 : 1;
}
Step 4 of Suite Workflows runs this
loop in a complete program. The SDK archive’s samples/clash_suite_api/ClashSuiteApi.cpp runs it
with progress reporting, and also runs the background ovclash_suite_runtime_fetch_and_save_async()
variant.
Rules for the fetch operation:
Pass the values the query stores:
SETTING_TOLERANCEastolerance,SETTING_DEPTH_EPSILONasdepth_epsilonandSETTING_DUP_MESHESasinclude_duplicates. The Python wrapper does the same, with 0.0, -1.0 and false for a missing setting.include_duplicatesdoes not follow the runtime’s currentonly_find_duplicatessetting.Each step bounds its work, not its time. Each
ovclash_suite_runtime_fetch_and_save_next()call handles at most 1,024 frame reports and 1,024 overlaps, and stops once about 8 MiB of report payload is acquired; one indivisible report can exceed that. Reconciling absent clashes scans at most 1,024 stored identifiers per call, so it can take several calls.beginenumerates every stored identifier of the query and is not bounded. The call that reports completion has committed.Threading follows the runtime’s settings. Fetch preparation uses
single_threaded,new_task_managerandnb_tasks, which may differ from the ones detection used. Set them beforebeginand keep them untildestroy. Frame preparation for a directory store, or for a custom store with aprepare_framecallback, can use worker threads. SQLite frame encoding and every storage write stay on the driving thread: the calling thread for the bounded C calls and the Python generator, the background worker for the asynchronous calls. Python progress, modification and timing callbacks stay on the iterating thread.Destroy the operation before you close its runtime or data handle. A live operation leases both; Suite fetch and cursor lifetime lists what it blocks.
ovclash_suite_runtime_save_overlap_to_data() persists one runtime overlap and its frames in one
call. It keeps the review fields of a stored clash with the same query_id and overlap_id. A
record the engine cannot report is dropped instead of failing the call; compare out_frame_count
with nb_records from ovclash_suite_get_overlap_data() to detect the loss.
Fetch-and-save failures and transaction boundaries#
Fetch-and-save is not all-or-nothing for every failure. The rules in this section hold for every fetch call of Saving detection results, on both built-in stores and custom stores, and in serial and parallel modes. The storage transaction belongs to the data handle, so a rollback or the final commit also affects unrelated writes pending on that handle.
Outcome |
Transaction behavior |
|---|---|
Successful completion |
Reconciles absent clashes and commits before it reports completion, even for an empty result. The commit publishes every pending write on the handle. Intermediate batches do not commit. |
A storage callback, a transaction, a frame release or a saved-data read fails after initialization |
Requests rollback of the whole pending transaction, including earlier batches of the same fetch and other uncommitted writes on the same destination. |
Extraction, frame preparation (including a failed |
Restores the incomplete streamed clash record, if any, and keeps earlier completed pending writes. If that restore fails, it requests a full rollback. |
Initialization fails |
Leaves writes that were pending before |
Cancellation is observed before the commit |
Stops further reconciliation and the commit. Completed writes and absent-state updates already applied stay pending, unless restoring the incomplete clash record fails and forces a full rollback. |
The operation is destroyed before completion |
Restores the incomplete clash record, falls back to a full rollback if that fails, and never commits. Completed writes stay pending. |
A clash record is streamed when fetch-and-save writes it before all the reports of its overlap are captured, as for a long dynamic clash.
Committed data is always kept.
A failed operation cannot resume. Destroy it and start a new one. Destruction consumes the operation even when its cleanup reports an error. In Python, close an abandoned generator before closing the store.
Closing or destroying a built-in data handle attempts to commit. Error cleanup can therefore save partial results. If that commit fails, the handle requests a rollback and stays available for inspection or retry, so the pending writes may be gone.
Callbacks after the final commit cannot undo it. In Python, the last modification notification, the final
progress_callbackcall andtiming_callbackrun after the final commit. An exception they raise leaves the results committed.A record without an available report is skipped. The engine can report
OVCLASH_SUITE_STATUS_UNAVAILABLEfor a record while the overlap’s data stays readable. The fetch then drops that frame, prints apersisted X of Y recordsnotice to stderr, and continues. The storednum_recordsthen counts only the persisted frames. Compare it withnb_recordsfromovclash_suite_get_overlap_data()when the loss matters. An overlap whose records all fail fails the fetch.
The public data API has no rollback function, and destruction is not one. To publish results only after complete success, fetch into a separate staging store and publish it once completion is confirmed.
Clash states#
Every stored clash has a clash state, its review state: ClashState in
Python, ovclash_suite_clash_state_t in C.
State |
Value |
Set by |
|---|---|---|
|
1 |
Fetch-and-save, for a clash it stores for the first time |
|
2 |
Your application |
|
3 |
Fetch-and-save with state updates, for a stored clash that the run no longer detects |
|
4 |
Your application |
|
5 |
Your application |
|
6 |
Fetch-and-save with state updates, for a stored clash that the run detects again |
Fetch-and-save keeps record identifiers and review fields, and it marks a stored clash that the run
no longer detects as not present (present = False) in every mode. With state updates enabled, it
also reconciles the states:
Stored clash |
State updates on |
State updates off |
|---|---|---|
Detected again, normal or duplicate |
Becomes |
Keeps its state. |
Absent from the new results |
Becomes |
Keeps its state and is marked not present. |
New |
Starts |
Starts |
Select the mode:
In C, pass a nonzero
resolve_staleto the fetch call for state updates, or zero to keep the stored states.In Python, state updates are on by default. Set
ExtensionConfig.update_clash_states_after_detection(fromomni.physxclashdetectioncore.config) toFalsebefore the fetch starts to keep the stored states. The same flag controls theACTIVEupdate inClashDetection.process_overlap()andprocess_duplicate().
The approval comparison#
An APPROVED clash keeps its approval only when the new run detects exactly what the store holds:
Identity. The query and the clash hash, the hash of the ordered pair of prim paths, establish result identity. A matching clash hash alone does not preserve an approval.
Compared contents. Type, tolerance, depth epsilon, object paths and mesh checksums, the aggregate results, and every frame’s times, matrices, metrics and geometry, in persisted order.
Ignored. Record identifiers, review fields, timestamps and user penetration-depth annotations.
Precision. Values compare at the precision of the Suite C ABI: binary64 for scalars, times and matrices, and binary32 for outlines and point sizes. The comparison uses no epsilon. Signed zeros are equal, a NaN never counts as unchanged, and subnormals stay distinct from zero, whatever the caller’s floating-point controls.
The comparison needs a reader for the stored results:
Built-in stores and Python custom stores supply it automatically. A Python custom store serves the saved frames through
fetch_iter_saved_frames(); see Custom stores.A custom C or C++ store passes an
ovclash_suite_fetch_saved_data_reader_ttoovclash_suite_runtime_fetch_and_save_begin_with_reader()orovclash_suite_runtime_fetch_and_save_async_with_reader(). Pass a null reader with a built-in destination.With state updates on and no reader, a re-detected
APPROVEDclash becomesACTIVE, because unchanged contents cannot be proven.
ovclash_suite_fetch_saved_data_reader_t, in <ovclash_suite/ovclash_suite_serializer.h>. Every
callback runs on the thread that drives the fetch, takes user_data first, and acknowledges
success by writing exactly 1 to out_success after it has built complete outputs:
Member |
C type |
Required |
Default or values |
Purpose |
|---|---|---|---|---|
|
|
No |
Any pointer, or null |
Your context, passed unchanged as the first argument of every reader callback. |
|
|
Yes |
Non-null |
Reads the saved header of |
|
|
Yes |
Non-null |
Reads the complete saved frame at the zero-based persisted |
|
|
No |
Null: nothing is released |
Releases a reader-owned cursor. It must succeed when no cursor is open. |
Output strings and arrays stay valid until the next reader callback.
Kit’s clash-detection extension sets every re-detected clash to ACTIVE;
Kit compatibility lists that difference.
Custom stores#
A custom store keeps records in storage that you implement, and receives fetch-and-save results under the same transaction contract as the built-in stores. The built-in lifetime guards protect only the built-in stores: a custom store keeps its destination stable for the whole fetch and enforces its own lifetime and connection rules.
In Python, derive from AbstractClashDataSerializer, implement its record methods, and pass
an instance to ClashData(serializer) or directly to the fetch call.
Override
fetch_transaction(operation). Without that override, fetching raisesNotImplementedErrorbefore any work starts, because rollback cannot be emulated through the record methods.The other
fetch_*hooks have defaults built on the record methods:fetch_visit_existing(),fetch_find_overlap(),fetch_write_overlap(),fetch_clear_frames(),fetch_append_frame(),fetch_mark_absent()andfetch_iter_saved_frames(). The defaults need record methods that raise on persistence errors. Override a hook when its default is slow for your store. Overridefetch_visit_existing()when the store allows several records with the same clash hash.Identifiers that the hooks return fit a signed 64-bit integer and are never -1, which
ClashInforeserves for an unsaved record.For long
APPROVEDhistories, overridefetch_iter_saved_frames(identifier, first_frame_offset=0)with a forward cursor. The cursor yields owned frames in persisted order and has aclose()method. The fetch may close it and reopen it at a nonzero offset around writes. The default issues one ranged read per frame.Threads. The hooks run on the calling thread, or on the background worker of an asynchronous fetch. Progress, modification and timing notifications stay on the iterating thread.
The docstrings of AbstractClashDataSerializer and its fetch_* hooks give the full contract.
In C or C++, fill an ovclash_suite_fetch_serializer_t callback table, the serializer
interface of a custom store, and pass it to the fetch call with a NULL data handle; exactly one
of the two is non-null. Each callback acknowledges success by writing exactly 1 to its
out_success argument, and no exception may cross the C ABI.
Member |
C type |
Required |
Default or values |
Purpose |
|---|---|---|---|---|
|
|
No |
Any pointer, or null |
Your context, passed unchanged as the first argument of every callback. |
|
|
Yes |
Non-null |
Enumerates the stored identifiers of the query once, during initialization, by calling |
|
|
Yes |
Non-null |
Looks up one stored clash header by query and clash hash text ( |
|
|
Yes |
Non-null |
Inserts or updates one clash header and returns its stable identifier. |
|
|
Yes |
Non-null |
Removes all stored frames of one clash. |
|
|
Yes |
Non-null |
Appends one frame to a clash. |
|
|
Yes |
Non-null |
Marks a stored clash not present, and also |
|
|
Yes |
Non-null |
Applies one |
|
|
No; set both or neither with |
Null: frames are not prepared, and |
Encodes a frame, possibly on a worker thread, for a later |
|
|
No; set both or neither with |
Null with a null |
Releases one non-null encoded payload. |
|
|
No |
Null: the engine reports a generic diagnostic |
Publishes the store’s diagnostic text after a failed callback. |
Custom serializers gives the thread and borrowed-input
rules, and the comments in <ovclash_suite/ovclash_suite_serializer.h> define every callback.
Both languages implement the same transaction operations:
Python |
C |
The store must |
|---|---|---|
|
|
Start the pending transaction, or reuse the open one. It precedes every write batch and every reconciliation batch, so it must be idempotent. |
|
|
Publish every pending write, unrelated ones included. It is requested only when the fetch completes, always after a |
|
|
Discard the whole pending transaction, including earlier batches and unrelated pending writes. It is requested at most once per operation, after a persistence failure, so it need not be idempotent. |
|
|
Set a restore point before a streamed clash record is replaced. |
|
|
Release the restore point after the final header of the streamed clash record is written. |
|
|
Restore the incomplete streamed clash record to its restore point and keep the other pending writes. A failed abort leads to a rollback. |
The engine cannot recover when your rollback fails, and a failed commit or rollback cannot undo side effects your store already published. Such a store may need recovery at the application level. Fetch-and-save failures and transaction boundaries says when the engine requests each operation. To keep unchanged approvals in a C store, also supply the saved-data reader described in The approval comparison.
Numeric fidelity#
The stores keep numbers as follows:
Value |
SQLite store |
Directory store |
|---|---|---|
Integers |
64 bits |
64 bits |
Finite scalars |
Exact, except that a negative zero reads back as a positive zero |
Exact, negative zero included |
Infinite scalars |
Stored |
Stored as the strings |
NaN scalars |
Rejected: the write fails and rolls back the pending transaction |
Stored as the string |
Frame matrices |
Exact; must be finite |
Exact; must be finite |
Face, outline and point buffers |
Exact, stored as raw bytes |
Exact for finite values |
Persisted values, and the JSON that the native layer writes for settings and models, do not depend on the caller’s locale, rounding or denormal controls.
That JSON spells negative zero as
-0.0, matrix and float-array elements included.A record that holds a NaN scalar cannot be copied unchanged from a directory store into a SQLite store.
The approval comparison compares values at the precision of the Suite C ABI.
SQLite values and Directory values give each store’s encoding.
Schema compatibility#
Each store records the version of its format, and open refuses a store newer than the build:
A SQLite store records a schema version per table. An older file with a registered migration path must be migrated before it opens. An older file without one, and a file newer than the build, never open, and no migration recovers them. See Schema versions and forward compatibility.
A directory store records one format version in
manifest.json, and has no migration path. See Manifest and internal files.
Purpose |
Python |
C |
|---|---|---|
Is the open store’s format current? |
|
|
Could it be migrated? |
|
|
Migrate it in place |
|
|
On a serializer, data_structures_compatible() and
data_structures_migration_to_latest_version_possible() are methods; on ClashData they are
properties of the same names.
Failures that do not raise#
A native failure normally becomes a Python exception that carries the native error text. The data and serializer classes keep the legacy return contract in these places:
ClashDatawithout an open store, or without a serializer, returnsFalse,0,None,{}or[]from its record methods,save()andsave_as(), according to the result type, and logs nothing. Itsclose()andcommit()then do nothing. A destroyed built-in serializer returns the same values from its record methods and does nothing onclose()andcommit(). Itsopen(),save()andsave_as()raise.SQLite
open()leaves an incompatible database closed without raising. It logs the reason as a warning through theovclash_suitelogger, asovclash_suite: store left closed after open(<path>): <reason>, where<path>is the path you passed and<reason>isSQLite database tables are incompatible; migration to the latest version is possibleorSQLite database tables are incompatible and cannot be migrated to the latest version. Inspectis_open(),data_structures_compatibleanddata_structures_migration_to_latest_version_possible.migrate_data_structures_to_latest_version()returnsFalseinstead of raising, and logs the reason as a warning:ovclash_suite: migrate_data_structures_to_latest_version(<path>) failed: <reason>, where<reason>is the native error text.ClashQuery.load_settings_from_str()returnsFalsefor empty or invalid JSON, and logs nothing.
For the SQLite open and the migration, last_error() returns the reason the call recorded.
Without it, a store left closed looks exactly like an empty one.
Everything else raises: other open failures, directory format errors included, and native close,
commit and destroy failures. fetch_all_queries() and fetch_all_point_cloud_settings() raise
RuntimeError instead of returning a partial dictionary.