Directory serializer#

The directory serializer keeps a Suite API store as a folder of readable JSON files, one file per query, point-cloud setting, clash and frame. It works with the same data API and fetch-and-save calls as the default SQLite serializer, and neither converts the other’s format. Choosing a store compares the two, and Persistence covers the shared API.

Store path#

The whole path that you pass names the store folder:

  • results/run_01 names the run_01 folder.

  • results/run.ovclashdb names a folder too. The serializer adds no filename extension and gives none a special meaning.

On POSIX, new manifest, record and transaction staging/control files use owner read/write permissions (0600, subject to the process umask). Rewriting an existing file preserves its permissions; transaction backup copies follow the source file permissions. Sharing a store requires suitable permissions on both its directories and its files.

Keep symbolic links out of the store:

  • The serializer rejects a symbolic link in the store’s normalized absolute path, ancestors included, in any path inside the store, and in a save_as() destination.

  • A link in the store path or in a save_as() destination reports Invalid directory store symbolic link: <path>.

  • On Windows, directory junctions and volume mount points are rejected as symbolic links. A volume mounted only into a folder cannot hold a store; assign it a drive letter instead.

  • Pass the physical path, or resolve a trusted alias first: str(Path(path).resolve()) in Python, or std::filesystem::weakly_canonical(path) in C++. weakly_canonical() resolves only existing components, so for a link whose target does not exist yet, pass the physical path.

  • An unnamed store also needs a system temporary directory whose path has no symbolic links.

Python#

from ovclash_suite import ClashData, ClashDataSerializerDirectory, ClashQuery

serializer = ClashDataSerializerDirectory()
data = ClashData(serializer)
try:
    data.open("results/run_01")
    query = ClashQuery(query_name="Pipe clearances", object_a_path="/World/Pipes",
                       object_b_path="/World/Structure")
    data.insert_query(query)
    for identifier, stored in data.fetch_all_queries().items():
        print(identifier, stored.query_name)
finally:
    data.destroy()
    serializer.destroy()

Output on a new store:

1 Pipe clearances
  • open() raises RuntimeError when the folder cannot be opened.

  • Each write commits by default.

  • ClashData.destroy() only closes a serializer that you supplied, so destroy the serializer too.

  • ClashData() without a serializer selects SQLite.

To save runtime results, pass data, or the serializer itself, as clash_data to ClashDetection.fetch_and_save_overlaps() or ClashDetection.run_async_fetch_and_save(). Fetching Suite runtime results describes both. The ovclash_suite example shows a complete run; pass the directory serializer’s ClashData instead of the default one.

Unnamed stores#

The serializer’s open("") opens an unnamed store in a private temporary folder. Deferred creation and unnamed stores gives the rules that both stores share, such as keeping the records with save_as(path). For a directory store:

  • With deferred creation, the default, the temporary folder is created on the first write.

  • After set_deferred_file_creation_until_first_write_op(False), the folder is created at open.

  • Closing or destroying the unnamed store deletes its folder.

C and C++#

Create the handle with ovclash_suite_data_create_directory() instead of ovclash_suite_data_create(). Every other ovclash_suite_data_* function, the cursors (the forward-only readers of stored overlaps and frames) and the fetch-and-save calls accept it. Check each returned status against OVCLASH_SUITE_STATUS_SUCCESS. This complete program opens the store relative to the working directory and prints its query count:

#include <ovclash_suite/ovclash_suite.h>
#include <stdio.h>

int main(void)
{
    ovclash_suite_data_t* data = NULL;
    ovclash_suite_result_t result = ovclash_suite_data_create_directory(&data);
    if (result.status == OVCLASH_SUITE_STATUS_SUCCESS)
    {
        const char path[] = "results/run_01";
        const ovclash_suite_string_t directory = { path, sizeof(path) - 1 };
        uint32_t query_count = 0;
        result = ovclash_suite_data_open(data, directory);
        if (result.status == OVCLASH_SUITE_STATUS_SUCCESS)
            result = ovclash_suite_data_get_query_count(data, &query_count);
        if (result.status == OVCLASH_SUITE_STATUS_SUCCESS)
            printf("queries: %u\n", (unsigned)query_count);
        ovclash_suite_result_t cleanup = ovclash_suite_data_destroy(data);
        if (cleanup.status != OVCLASH_SUITE_STATUS_SUCCESS)
            result = cleanup;
    }
    return result.status == OVCLASH_SUITE_STATUS_SUCCESS ? 0 : 1;
}

Build it as the C/C++ Quickstart describes; when find_package(ovclash) fails, Configuring with CMake lists the messages and their fixes. On a new store it prints queries: 0 and exits with status 0.

To save runtime results, pass the handle as data, with a NULL serializer, to ovclash_suite_runtime_fetch_and_save_async() or to the bounded ovclash_suite_runtime_fetch_and_save_begin(). The operation leases the store until you destroy the operation. Saving detection results covers the bounded and asynchronous calls, the lease and threading. The data API comments in include/ovclash_suite/ovclash_suite.h, which ships in the SDK archive, hold the full contract; References in the package lists that header.

Sample command line#

Before you begin, set up the samples as Running the Python samples describes. The C++ and Python Suite processors in samples/clash_suite_api/ write a directory store with --clashdir FOLDER. Add --clashdb FILE to write a SQLite store from the same run. On Linux, from the package root:

./samples/clash_suite_api/run_clash_suite_api_python.sh -- --stage samples/data/time_sampled.usda --object-a /Root/Xform_Primitives/Cube --object-b /Root/Xform_Primitives/Plane --clashdir results --json report.json

On Windows, run samples\clash_suite_api\run_clash_suite_api_python.bat with the same arguments. When the launcher cannot prepare its Python runtime, it stops with an error; Building and running the shipped samples lists the messages. A successful run exits with status 0 and writes the report.json export and this store:

results/
  .ovclash.lock
  manifest.json
  queries/
    1.json
  clashes/
    1/
      0x37a006cb02c4a437d94f59d46c9170f5/
        1/
          clash.json
          frames/
            1.json

The Clash Processor introduces the Clash Processor guide, samples/clash_suite_api/clash_processor.md in the package, which covers --append, combined SQLite and directory output, and the report paths that must not overlap the store. Samples describes the launchers.

Files#

A store has this shape:

run_01/
  manifest.json
  queries/
    1.json                     query identifier
  point_cloud_settings/
    1.json                     point-cloud settings identifier
  clashes/
    1/                         query identifier
      0x1234/                  clash hash
        7/                     clash record identifier
          clash.json
          frames/
            12.json            frame identifier
            13.json
  • Each clash sits under its query, its clash hash and its own record identifier. Equal hashes in different queries, and repeated records with the same hash, therefore stay distinct.

  • Frame files are named by frame identifier, because several frames can share a sample time.

  • Reads return clashes in hash order, and frames in sample-time order with NaN first. The record identifier breaks ties. This matches SQLite order and paging.

Clash hash folders#

  • A hash of lowercase hexadecimal digits, with an optional 0x prefix and at most 128 characters, is used as the folder name.

  • Any other hash becomes _ followed by the hexadecimal encoding of its bytes. That name is split into folder levels of at most 121 characters.

  • The overlap_id field of clash.json keeps the original hash.

Values#

  • Records use named JSON fields. Matrices, faces, outlines and points are numeric arrays.

  • Integers keep all 64 bits.

  • Finite floating-point values, negative zero included, round-trip exactly.

  • NaN and infinities are written as the strings "NaN", "+Infinity" and "-Infinity". NaN payloads and signs are lost.

  • Matrices must be finite.

  • The directory store accepts NaN scalars, such as a NaN sample time. A SQLite store rejects NaN in its REAL columns, so such records cannot be copied unchanged into a SQLite store.

  • Record strings must not contain NUL characters; a write with one fails. Query settings JSON may still contain the escape \u0000.

Record fields#

Each record file is one JSON object, and every field of it is required. The query, point-cloud settings and clash files carry the names and meanings of the Python model fields that The object model lists:

File

Record

Fields

queries/<id>.json

ClashQuery

Every field except clash_detect_settings, which is stored as settings and settings_text_bytes; see Query settings text.

point_cloud_settings/<id>.json

PointCloudSettings

Every field.

clashes/<query>/<hash>/<id>/clash.json

ClashInfo

Every field except clash_frame_info_items, plus frame_index and frame_count; see Indexes and record locations.

<id> is the record’s identifier, <query> the owning query’s identifier and <hash> the clash hash folder that Clash hash folders describes. A frame file, clashes/<query>/<hash>/<clash id>/frames/<id>.json, has these fields:

Field

Type

Required

Default or values

Description

identifier

integer

Yes

1 or more

The frame record identifier, which names the file.

clash_info_id

integer

Yes

The owning clash’s identifier

The clash that the frame belongs to.

timecode

number

Yes

Seconds; may be "NaN"

The sample time, in seconds despite the name.

min_distance

number

Yes

0 or more

The minimum distance in this frame, in stage units.

max_local_depth

number

Yes

-1 when not computed

The maximum local depth in this frame, in stage units.

overlap_elements

integer

Yes

0 or more

The overlapping triangles or points in this frame.

usd_faces0, usd_faces1

array of integers

Yes

Can be empty

The colliding face indices of each object, usd_faces_0 and usd_faces_1 in Python.

collision_outline

array of numbers

Yes

Six numbers per segment

The intersection outline, x y z x y z per segment.

object_0_matrix, object_1_matrix

array of numbers

Yes

Exactly 16 finite numbers, row-major

The local-to-world transforms of the two objects.

usd_points0

array of integers

Yes

Can be empty

The colliding point indices of a point-cloud clash, usd_points_0 in Python.

usd_points0_sizes

array of numbers

Yes

Can be empty

The point sizes of a point-cloud clash, usd_points_0_sizes in Python.

penetration_depth_px, penetration_depth_nx, penetration_depth_py, penetration_depth_ny, penetration_depth_pz, penetration_depth_nz

number

Yes

-1 when not computed

The penetration depths along the positive and negative X, Y and Z axes, in stage units.

The model types map to JSON types:

Model type

JSON type in a record file

int, and the flags present, save_to_session_layer and skip_rendering

Integer. A flag is 0 or 1.

OverlapType, ClashState

Integer: the enum’s numeric value.

float

Number, or the string "NaN", "+Infinity" or "-Infinity".

str, datetime

String. A timestamp is the storage string that the C record views carry.

Faces, outline and points

Array of numbers.

Matrix

Array of exactly 16 finite numbers, row-major.

Indexes and record locations#

Each clash.json holds a frame_index, with the identifier and sample time of each frame, and a frame_count:

Field

Type

Required

Default or values

Description

frame_index

array of objects

Yes

One object per frame, in read order

The clash’s frames.

frame_index[].identifier

integer

Yes

A frame file’s identifier

The frame record.

frame_index[].timecode

number

Yes

That frame’s timecode

The frame’s sample time, in seconds.

frame_count

integer

Yes

The length of frame_index

The number of frames.

An excerpt:

{
  "frame_count": 1,
  "frame_index": [{
      "identifier": 1,
      "timecode": 0
    }],
  "identifier": 1,
  "object_a_path": "/Root/Xform_Primitives/Cube",
  "object_b_path": "/Root/Xform_Primitives/Plane",
  "overlap_id": "0x37a006cb02c4a437d94f59d46c9170f5",
  "query_id": 1,
  "state": 1
}
  • Opening the store reads these indexes, not the frame geometry.

  • Open checks the count and that every indexed frame file exists. Reading a frame checks its file against the index.

  • Hand edits must keep the index, the count and the frame files consistent.

  • Each record file must sit at the path that its fields give: its identifier, and for a clash also its query_id and overlap_id. Open rejects a record that does not.

  • Keep other files out of queries/ and point_cloud_settings/. Open rejects any entry there that is not a record file.

  • Open ignores other files at the root and under clashes/, but it reads every clash.json.

Query settings text#

Query settings holds the original JSON value as text, whitespace included. settings_text_bytes is the length of that text in bytes. It does not count the one space that the writer puts after "settings":.

Field

Type

Required

Default or values

Description

settings

any JSON value, or null

Yes

The query’s settings JSON object

The settings, as Persisted query settings describes.

settings_text_bytes

integer

Yes

0 or more

The byte length of the settings text; 0 with null means empty settings text.

  • A count of zero with null means empty settings text. The JSON value null has a count of four.

  • If you edit settings by hand, update the count. The count starts after that space and must cover the whole JSON value. Whitespace beyond the count is dropped.

  • Other fields use their ordinary JSON form.

Updates and deletes#

  • An update rewrites the affected record file.

  • Deleting a query also deletes its clashes and frames.

  • Changing a clash’s query or hash moves its folder and frame files.

  • Deletes and moves remove the folders that they leave empty, up to the store root. They keep unrelated files.

  • Updating only a clash’s header, such as its state or comment, leaves its frame files untouched.

Manifest and internal files#

manifest.json holds the format name, the format version and the next identifier of each record kind:

Field

Type

Required

Default or values

Description

format

string

Yes

"ovclash-directory"

The format name.

version

integer

Yes

1

The format version.

next_query_id, next_overlap_id, next_frame_id, next_point_cloud_settings_id

integer

Yes

1 or more, or -1

The next identifier of each record kind. Opening the store raises each one above the largest identifier of its kind.

Another format name or version fails the open with Incompatible directory store format or version, and a counter below 1 other than -1 with Invalid directory identifier counter. The manifest of the store that the Sample command line writes:

{
  "format": "ovclash-directory",
  "next_frame_id": 2,
  "next_overlap_id": 2,
  "next_point_cloud_settings_id": 1,
  "next_query_id": 2,
  "version": 1
}

Version 1 is the only format, so migration only validates the manifest and reopens the store. The root can also hold internal files:

  • .ovclash.lock, the ownership lock;

  • .ovclash-transaction/, while writes are pending;

  • .ovclash-manifest.tmp, during creation.

For an open, named store, the serializer’s get_file_size() (ovclash_suite_data_get_file_size() in C) sums all regular files under the root, internal and unrelated files included. An unnamed store reports an error.

Commits and ownership#

The commit arguments and commit() work as CRUD describes:

  • Pending writes are visible through the owning handle. They reach the record files at commit.

  • A write that fails after it began, for example on a NUL character, rolls back every pending write.

  • Closing or destroying the store first attempts to commit pending writes.

  • Fetch-and-save failures and transaction boundaries covers fetch-and-save failures.

save_as() first commits pending writes. Then:

  • When the destination is the current root, it does nothing more, apart from creating a store that a deferred open has not created yet.

  • Any other destination must be absent or an empty folder, outside the current store. save_as() copies the store there and makes the copy current. A named source keeps its records; an unnamed source is deleted.

  • A failed copy removes what it wrote. The source stays current, and you can retry the same destination.

Threads:

  • Serialize all calls on one handle, reads included. Handles for different stores can work concurrently.

  • Writes and commits run on the thread that makes the call. For an asynchronous fetch, that is its background worker.

  • A commit also flushes the files that it publishes with up to 15 short-lived helper threads, whatever the runtime threading settings.

  • During fetch-and-save, frame JSON encoding can use the runtime’s worker threads; Saving detection results describes those settings.

One handle at a time owns a store, through an operating-system lock on .ovclash.lock:

  • A second handle that opens the store fails with Directory store is already open or its lock cannot be acquired.

  • .ovclash.lock stays after closing. The operating-system lock, not the file, marks ownership.

  • With deferred creation, opening a missing or empty folder writes nothing. The handle takes ownership when its first write creates the store. If another handle creates the store first, that write fails; reopen before writing.

  • Close the owner before you open the folder from another handle or edit its files with another program.

  • Opening a nonempty folder without manifest.json, or a store with an unsupported format version, fails.

Interrupted commits#

Writes stage record files in .ovclash-transaction/. A commit backs up the records that it replaces or deletes, writes a journal and then publishes the staged files.

  • If the process stops during a commit, the next open restores the previous records, unless a completion marker shows that the commit finished.

  • Do not delete .ovclash-transaction/ while recovery is pending.

  • A commit that fails restores the previous records and discards the pending writes. If that restoration fails too, the handle rejects writes. Fix the filesystem problem, then close the store; closing retries the recovery.

  • The next open retries an interrupted first creation only when the folder holds just the store’s own initialization files. It rejects other contents and leaves them in place.

Recovery covers an interrupted process. Record files are flushed to disk, but folder entries are not. Recovery after an operating-system crash, power loss or hardware failure is therefore not guaranteed.