Export: JSON and HTML Reports#

The Suite API has one generic table exporter with two output formats: a JSON document and a self-contained HTML page. The exporter knows nothing about clashes. It takes column definitions and row-major cell values, so it can render any table, including one you build from a .ovclashdb SQLite store.

This tutorial exports a small table, then the clashes of a store, then the same table from C.

Prerequisites#

Step 1: Export a small table#

from ovclash_suite import ExportColumnDef, export_to_json

columns = [ExportColumnDef(0, "Object"), ExportColumnDef(1, "Distance", True)]
rows = [["/World/A", 0.25], ["/World/B", None]]
print(export_to_json(columns, rows, {"Stage": "scene.usda"}).decode("utf-8"))

Expected output:

{
    "additional_info": {
        "Stage": "scene.usda"
    },
    "columns": [
        "Object",
        "Distance"
    ],
    "rows": [
        [
            "/World/A",
            "0.25"
        ],
        [
            "/World/B",
            ""
        ]
    ]
}

Every cell becomes text: 0.25 becomes "0.25", and None becomes an empty string.

Step 2: Export the clashes of a store#

This script reads the clashes of the first query in dynamic.ovclashdb and writes both formats:

from pathlib import Path

from ovclash_suite import ClashData, ExportColumnDef, export_to_html, export_to_json

columns = [
    ExportColumnDef(0, "Clash ID"),
    ExportColumnDef(1, "Min Distance", True),
    ExportColumnDef(2, "Object A"),
    ExportColumnDef(3, "Object B"),
]

data = ClashData()
try:
    data.open("dynamic.ovclashdb")
    query_id, query = next(iter(data.fetch_all_queries().items()))
    rows = [
        [info.overlap_id, f"{info.min_distance:.3f}", info.object_a_path, info.object_b_path]
        for info in data.find_all_overlaps_by_query_id(query_id, False).values()
    ]
finally:
    data.destroy()

info = {"Query": query.query_name, "Clashes": len(rows)}
html = export_to_html("Clash Detection Results", "time_sampled.usda", columns, rows, info)
Path("report.html").write_bytes(html)
Path("report.json").write_bytes(export_to_json(columns, rows, info))
print(f"Exported {len(rows)} rows to report.html and report.json.")

Expected output:

Exported 8 rows to report.html and report.json.

report.html shows the title “Clash Detection Results”, the stage as the subtitle, a two-row info table and the 8 clashes. The “Min Distance” column is right-aligned. report.json starts like this:

{
    "additional_info": {
        "Query": "Example Dynamic Query",
        "Clashes": "8"
    },
    "columns": [
        "Clash ID",
        "Min Distance",
        "Object A",
        "Object B"
    ],
    "rows": [
        [
            "0x19cd3f588ebbe2ceb23cc376f9087468",
            "2.952",
            "/Root/STATION_TIME_SAMPLED/STATION/SKID/lnk/Mesh1/NV_Mesh1",
            "/Root/Xform_Primitives/Cube"
        ],

samples/clash_suite_api/clash_suite_api_python.py exports its full ten-column clash table the same way when you give it a JSON or HTML output path (--json, --html or the positional paths); Samples describes the sample. The Clash Processor introduces the Clash Processor guide, samples/clash_suite_api/clash_processor.md in the package, which describes those options.

The Kit-compatible module omni.physxclashdetectioncore.clash_detect_export forwards both functions to ovclash_suite. For the differences from Kit’s exporter, see Kit compatibility.

Step 3: Export from C#

This complete program, for a C source file of your own, exports the table from Step 1 and prints it:

#include <ovclash_suite/ovclash_suite.h>

#include <stdio.h>

int main(void)
{
    const ovclash_suite_export_column_t columns[] = {
        { 0u, { "Object", 6u }, 0u },
        { 1u, { "Distance", 8u }, 1u },
    };
    const ovclash_suite_string_t rows[] = {
        { "/World/A", 8u }, { "0.25", 4u }, /* row 0 */
        { "/World/B", 8u }, { NULL, 0u },   /* row 1: an empty cell */
    };
    const ovclash_suite_export_info_t info[] = { { { "Stage", 5u }, { "scene.usda", 10u } } };
    ovclash_suite_export_text_t* text = NULL;
    ovclash_suite_string_t view = { NULL, 0u };

    if (ovclash_suite_export_rows_json_text(columns, 2u, rows, 4u, 2u, info, 1u, &text).status !=
            OVCLASH_SUITE_STATUS_SUCCESS ||
        ovclash_suite_export_text_get_view(text, &view).status != OVCLASH_SUITE_STATUS_SUCCESS)
    {
        ovclash_suite_string_t error = ovclash_suite_get_thread_last_error();
        fprintf(stderr, "export failed: %.*s\n", (int)error.length, error.ptr ? error.ptr : "");
        ovclash_suite_export_text_destroy(text); /* accepts NULL */
        return 1;
    }
    printf("%.*s\n", (int)view.length, view.ptr); /* view is valid until the handle is destroyed */
    ovclash_suite_export_text_destroy(text);
    return 0;
}

Build it against the SDK archive as Linking describes. When find_package(ovclash) fails, Configuring with CMake lists the messages and their fixes. The program prints the same JSON as Step 1 and exits with status 0. The export functions need no stage and no runtime.

Columns and rows#

A column has a label, an order and an alignment flag.

  • order is the zero-based index of the column’s cell within each row. It must be less than the number of columns.

  • Several columns may read the same cell.

  • Columns are emitted in list order; order does not reorder them.

  • To reorder the displayed columns without rebuilding the rows, reorder the column list and keep each entry’s order pointing at its cell. Changing order alone keeps the header in place and changes the cells under it.

  • Every cell is text. The alignment flag (alignment in Python, right_aligned in C) right-aligns the column in HTML. JSON ignores it.

Python API#

export_to_json() and export_to_html() are module-level functions in ovclash_suite. ClashDetection has no export methods.

export_to_json(column_defs, rows, additional_info=None) -> bytes
export_to_html(title, subtitle, column_defs, rows, additional_info=None) -> bytes
  • column_defs is an iterable of ExportColumnDef(order, name, alignment=False), a frozen dataclass with these fields:

    Field

    Type

    Required

    Default or values

    Description

    order

    int

    Yes

    0 to the number of columns minus 1

    The zero-based index of the cell that this column reads within each row.

    name

    str

    Yes

    Any text

    The column label.

    alignment

    bool

    No

    False

    True right-aligns the column in HTML; JSON ignores it.

  • rows is an iterable of rows. Each row must hold exactly one value per column. Each value is converted with str(), and None becomes an empty string.

  • additional_info is an optional dict of name/value metadata, converted with str() like the cells. Its entries keep the order you pass.

Both functions return the UTF-8 document as bytes. Write it with Path.write_bytes(), not write_text(). They render through the owned text handle of the C ABI, so a large document is built once. They raise:

  • ValueError for a row with the wrong number of values, before anything reaches the C ABI. The message names the row index, for example “Export row 0 contains 1 values; expected exactly 2”. A column order outside the uint32 range also raises ValueError.

  • RuntimeError when the native exporter rejects the input, for example a column order that is not less than the number of columns.

C ABI#

The C ABI has the same two exports in two output styles. All export functions are synchronous and take no runtime or data handle. When a call fails, ovclash_suite_get_thread_last_error() returns the reason.

Owned text handle. Use this style for large outputs. It renders the document once and returns it in an opaque handle. Step 3 uses it.

  • ovclash_suite_export_rows_json_text(columns, column_count, row_values, row_value_count, row_count, additional_info, additional_info_count, &out_text)

  • ovclash_suite_export_rows_html_text(title, subtitle, columns, ..., &out_text)

  • ovclash_suite_export_text_get_view(text, &view) fills view with a borrowed ovclash_suite_string_t. The view is valid until the handle is destroyed.

  • ovclash_suite_export_text_destroy(text) releases the handle. It accepts null.

  • A failed export call sets *out_text to null.

Caller-supplied buffer. Call once with a null out_buffer and out_buffer_size 0. out_required_size receives the byte count without the trailing null. Allocate at least out_required_size + 1 bytes and call again. Each call renders the whole document, so this style renders it twice.

  • ovclash_suite_export_rows_json(columns, column_count, row_values, row_value_count, row_count, additional_info, additional_info_count, out_buffer, out_buffer_size, out_required_size)

  • ovclash_suite_export_rows_html(title, subtitle, columns, ..., out_buffer, out_buffer_size, out_required_size)

The two input structs:

Field

Type

Required

Default or values

Description

ovclash_suite_export_column_t::order

uint32_t

Yes

Less than column_count

The index of the column’s cell within each row; see Columns and rows.

ovclash_suite_export_column_t::name

ovclash_suite_string_t

Yes

UTF-8 text

The column label.

ovclash_suite_export_column_t::right_aligned

uint32_t

Yes

0, or non-zero to right-align

Right-aligns the column in HTML; JSON ignores it.

ovclash_suite_export_info_t::name

ovclash_suite_string_t

Yes

UTF-8 text

The metadata key.

ovclash_suite_export_info_t::value

ovclash_suite_string_t

Yes

UTF-8 text

The metadata value.

The exporter reads its inputs only during the call, so caller storage need not outlive it. Row values are a flat counted array of ovclash_suite_string_t in row-major order:

  • The cell of column c in row r is row_values[r * column_count + columns[c].order].

  • row_value_count must therefore be at least row_count * column_count.

  • The C++ sample in the SDK archive (samples/clash_suite_api/ClashSuiteApi.cpp, which Samples describes) builds this array from a vector<vector<string>> in flattenRows().

Input validation#

Every export function validates all of its inputs before it renders anything. A call fails on:

  • a string span with a null ptr and a non-zero length, or text that is not valid UTF-8, in any title, subtitle, column name, cell or metadata entry;

  • a null array with a non-zero count;

  • a column order that is not less than column_count;

  • a row_value_count smaller than row_count * column_count, or a product that overflows size_t;

  • a null out_required_size or out_text.

Cells beyond row_count * column_count are validated but not rendered. A buffer call also fails when out_buffer is too small for the text plus its trailing null, or is null with a non-zero out_buffer_size. It still reports the required size. The comments on each export function in include/ovclash_suite/ovclash_suite.h (SDK archive) give its full error contract; References in the package lists that header.

What the output looks like#

JSON is a single object with up to three keys. Every cell is a string; see the output of Step 1.

Field

Type

Required

Default or values

Description

additional_info

object of strings

No

Present only when metadata was supplied

The metadata entries, name to value, in the order passed.

columns

array of strings

Yes

[] when empty

The column labels, in column order.

rows

array of arrays of strings

Yes

[] when empty

One array of cell texts per row, in column order.

  • additional_info appears only when metadata was supplied. columns and rows are always present, as [] when empty.

  • The text uses four-space indentation and ends without a newline.

  • Characters below U+0020 are escaped. Every non-ASCII character is written as \uXXXX escapes, a surrogate pair above U+FFFF, so the output is ASCII.

HTML is a complete HTML 4.0 strict document in UTF-8 with an inline stylesheet:

  • title becomes the document <title> and the <h1>. subtitle becomes the <h2>. The samples pass the stage path as the subtitle.

  • Metadata renders as a two-column info table above the data table.

  • Each column’s alignment flag becomes the align attribute of its header and body cells.

  • The exporter HTML-escapes the title, subtitle, labels, metadata and cells. Pass plain text: pre-escaped text is escaped again.

  • A cell whose text starts with /, such as a prim path, gets <wbr> break opportunities around each separator, so long paths wrap.

  • A column named exactly Image renders each cell as <img width="200" src="..."/>, with the cell text as the source.

  • The body ends with the fixed italic note “Document generated by NVIDIA Omniverse Clash Detection.”

Peak export memory includes the complete document; see Performance.

Helpers#

These helpers format values the way the Suite API and its exporter do:

Helper

Python

C

Format a 128-bit clash hash as the clash-id string: 0x and lowercase hexadecimal digits without leading zeros (0x0 for zero)

format_int128_hex(hi, lo)

ovclash_suite_format_int128_hex(hi, lo, buffer, size, &required)

Combine two 64-bit words into one Python integer

make_int128(hi, lo)

–

Escape &, <, >, " and ' as HTML character references, as the HTML exporter does

html_escape(text)

ovclash_suite_html_escape(text, buffer, size, &required)

Current local time in the storage format YYYY-MM-DD HH:MM:SS.ffffff

– (not exported from ovclash_suite; record timestamps default to it)

ovclash_suite_current_timestamp(buffer, size, &required)

User name for last_modified_by

current_user_name()

ovclash_suite_current_user_name(buffer, size, &required)

Use html_escape for HTML you write around an export; the exporter escapes its own output.

The C helpers use the same size query as the buffer exports. Pass a null buffer with size 0 to learn out_required_size, then call again with storage. The C++ sample in the SDK archive, samples/clash_suite_api/ClashSuiteApi.cpp, wraps that pattern once in copyCapiString() and uses it for the timestamp and the user name.

Result#

You can produce a JSON or HTML report from any table, including stored clash records, in either language. Next: Legacy Containers covers the Kit-era .clashDetection files that the same data handle reads and writes.