Populations, Versions, and Views#

A population is the set of objects that queries read. This page explains where its objects come from, how it publishes versions, and how views and participation bits narrow what a query sees.

Population Sources#

There are two ways to feed objects into ovspatialquery. You choose one when you create a population:

  1. An ovstage population reads prims from an ovstage stage through an ovstage filter. Each time you publish, it reads the selected prims’ shapes and world transforms from the stage. This is the usual way, and it is declared in ovspatialquery_ovstage.h.

  2. An explicit population bypasses ovstage. Your program registers shapes once and then publishes rows of arrays: object IDs, shapes, and poses. Use it for geometry that does not live in a stage. It is declared in ovspatialquery_explicit.h.

The following table compares the two sources:

Aspect

ovstage Population

Explicit Population

Objects

Prims selected by an ovstage filter and an optional path scope. An empty filter selects every Sphere, Cube, Capsule, and Mesh.

Rows of arrays you supply

Geometry

Cube, Sphere, Capsule, Mesh (as its authored faces), and convex hulls from physics:approximation = "convexHull"

Definitions registered once: sphere, box, capsule, convex hull, triangle mesh

Object ID

The prim’s path token, stable for the population’s lifetime

A nonzero uint64 you choose and never reuse

Ordinals

The ovstage ordinal that sealed the state

Chosen by you. Each update must be larger than the last.

Update

A complete new snapshot of the filtered prims

A delta: complete rows, poses only, or poses and bits

You can create as many populations as you have publishers. A scene that an editor changes rarely and robot bodies that move every frame belong in two populations, because their versions advance on different clocks.

What an ovstage Population Publishes#

An ovstage population publishes whatever stage you give it, including content that was never prepared for queries. Each publication turns every selected prim into one object, or leaves the prim out and says why. The only prims it leaves out silently are the instancing prims that Instances lists. Stage content never makes a publication fail; only your call or setup can, as Excluded Prims lists.

Transforms#

Each prim’s world matrix is applied exactly, including non-uniform scale, shear, and mirroring. The library does not reduce it to a translation, a rotation, and per-axis scales, which would drop shear, so a sheared surface stays where the stage puts it. Each prim type follows its transform as far as the result stays exact:

USD Prim

Uniform Scale or Mirror

Non-Uniform Scale

Shear

Mesh, convex hull

exact

exact

exact

Cube

box

box

convex hull of its eight corners

Sphere, Capsule

exact

excluded

excluded

A Sphere or Capsule under non-uniform scale is left out with the reason UNSUPPORTED_SHAPE, because an ellipsoid is neither shape. Scales that agree within a relative 2⁻²⁰, as float32 transforms often do, count as uniform.

Meshes#

A Mesh is queried as its authored faces, whatever its subdivisionScheme. The faces listed in holeIndices are left out. A leftHanded mesh, or a mirrored one, keeps its authored front faces, so single-sided meshes face the way the stage shows them. An exact hit reports the authored face and its corner indices, as described in Result Types.

A mesh with physics:approximation = "convexHull" is published as the convex hull a PhysX simulation of the stage collides with: the hull PhysX cooks for that collider under a vertex limit. The limit is the mesh’s physxConvexHullCollision:hullVertexLimit, an int, clamped to 8 to 64; it is 64 when the stage has none, a negative one, or one stored as another type. The limit is read even where the mesh does not apply PhysxConvexHullCollisionAPI, which a simulation requires before it reads it. That hull has at most that many vertices and can leave some of the mesh’s points outside; refer to Convex Hulls. These properties, and the material bindings that Identity describes, are read only if the stage holds them. The RENDERING domain does not populate them, so open the stage with a selector for every prim’s physics, physxConvexHullCollision, and material:binding properties. Without them, a mesh publishes as its faces and reports no physics material, and a convex hull uses the limit 64. The following code opens a stage that way:

population = ovstage.population
physics = population.Selector(
    prim_predicate=population.PrimPredicate.all(),
    property_predicate=population.PropertyPredicate.in_namespace(
        "physics", "physxConvexHullCollision", "material:binding"
    ),
)
desc = population.Desc(domains=ovstage.PopulationDomain.RENDERING, selectors=[physics])
population.open_usd_from_string_with_desc(stage, SCENE, 1, 0.0, desc)

Note

A convex hull mesh for which PhysX cooks no hull is excluded, not replaced by a box. Refer to Convex Hulls.

Bounding Boxes#

Each object’s published bounding box is computed from its shape and its world matrix. ovstage’s world bounds (_worldExtent) only decide whether a prim has a spatial source. A stale or inaccurate authored extent therefore changes no box and excludes no prim. Bounds candidates and pairs use these boxes.

Instances#

Instancing publishes each instance, never the prims that only define what instances draw:

  1. Each selected prim inside a native instance (instanceable = true) is published like any other prim, at its own instance-proxy path and world matrix: one object, or an exclusion. The empty filter selects these proxies. An explicit filter selects them by usd-path or by an instance type such as CubeInstance; usd-prim-type IN [Cube] selects authored cubes only.

  2. ovstage writes proxy rows only when the stage is opened with RENDERING. Without them, a publication that selects a prototype copy returns NOT_SUPPORTED.

  3. A PointInstancer’s prototype prims, and ovstage’s copies of them, are never published. The point instances are not published either.

These prims are left out without being listed as exclusions.

Excluded Prims#

A prim that the population cannot publish exactly is left out of the version, and the publication result lists it. The publication still succeeds and still becomes the head. Publishing fails only for errors in your call or setup. Such errors include an invalid handle or ordinal, an unsupported ovstage version, a budget, a lost device, and native instances on a stage opened without the domain that writes their proxy rows.

Each excluded prim carries one of these reasons:

Reason

When

NO_SPATIAL_SOURCE

ovstage keeps no world bounds for a prim of a published type.

UNSUPPORTED_TYPE

The filter selected a prim type that is not published, such as an Xform, a Cylinder, or a Scope.

UNSUPPORTED_SHAPE

A Sphere or Capsule has non-uniform scale or shear.

MALFORMED_GEOMETRY

Invalid topology, points, or transform, such as a zero scale, a hull without volume, or a mesh whose faces are all holes. A convex hull mesh for which PhysX cooks no hull is excluded rather than replaced by a box.

RESHAPE_PENDING

Only for a version prepared on a CUDA device: the prim’s proportions changed, and it returns at the next publication.

The following figure shows a program that selects four prims and publishes two of them:

One publication keeps the stretched and the sheared Cube exactly and lists the two prims it leaves out.

The program publishes the stage, prints the exclusions, and casts both rays:

import ovstage

from ovspatialquery import Library, OvstageExclusionReason, RaycastQuery

SCENE = """#usda 1.0
def Xform "World"
{
    def Cube "Crate"
    {
        double size = 2
        double3 xformOp:translate = (4, 0, 0)
        float3 xformOp:scale = (0.5, 1, 1)
        uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:scale"]
    }
    def Sphere "Egg"
    {
        double radius = 0.5
        double3 xformOp:translate = (4, 3, 0)
        float3 xformOp:scale = (1, 2, 1)
        uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:scale"]
    }
    def Cylinder "Post"
    {
        double3 xformOp:translate = (8, 0, 0)
        uniform token[] xformOpOrder = ["xformOp:translate"]
    }
    def Cube "Ramp"
    {
        double size = 1
        matrix4d xformOp:transform = (
            (1, 0, 0, 0), (0.5, 1, 0, 0), (0, 0, 1, 0), (7, 3, 0, 1)
        )
        uniform token[] xformOpOrder = ["xformOp:transform"]
    }
}
"""

stage = ovstage.Stage("exclusions")
RENDERING = ovstage.PopulationDomain.RENDERING
ovstage.population.open_usd_from_string(stage, SCENE, 1, 0.0, RENDERING)
stage.advance_write_floor(ordinal=1).wait()
stage.compute_hierarchy(1, 2, ovstage.HierarchyComputationModel.DEFAULT_CPU)
stage.advance_write_floor(ordinal=2).wait()
paths = ovstage.PathDictionary(stage)

world = ovstage.Filter(
    [ovstage.Predicate("usd-path", ovstage.FilterOp.PREFIX, ["/World/"])]
)

with Library.open(require_ovstage=True) as library, library.instance() as instance:
    population = instance.ovstage(ovstage, stage).create_population(world)

    # The publication succeeds and lists every prim it left out.
    with population.enqueue_set(2) as publication:
        publication.wait()
        result = publication.fetch_population_update()
    print("published", result.object_count, "excluded", result.excluded_object_count)
    for object_id, reason in zip(result.excluded_objects, result.exclusion_reasons):
        name = OvstageExclusionReason(reason).name
        print("  excluded", paths.path_to_string(ovstage.PrimPath(int(object_id))), name)

    # One ray along +x past the Crate, one past the Egg to the sheared Ramp.
    for y in (0.0, 3.25):
        ray = population.target.raycast_closest(
            RaycastQuery(origin=(0, y, 0), unit_direction=(1, 0, 0), max_distance=20)
        )
        path = paths.path_to_string(ovstage.PrimPath(ray.hit.object_id))
        print("ray at y", y, "hit", path, "at distance", round(ray.hit.distance, 3))

# Destroy the stage once nothing uses it, rather than at interpreter exit.
stage.destroy()

It prints this output:

Output#
published 2 excluded 2
  excluded /World/Egg UNSUPPORTED_SHAPE
  excluded /World/Post UNSUPPORTED_TYPE
ray at y 0.0 hit /World/Crate at distance 3.5
ray at y 3.25 hit /World/Ramp at distance 6.625

Notice the following about this program:

  1. The result’s excluded_objects holds the object IDs, sorted by value, and exclusion_reasons the reason of each, in OvstageExclusionReason. Both have excluded_object_count rows. In Python they are array.array copies that stay readable after the operation closes. numpy.asarray reads them without copying.

  2. In C, ovspatialquery_population_update_result_t holds the same columns as two host DLPack tensors, uint64 and int32. They stay valid until you destroy the operation.

  3. The list is complete for every publication, not a change from the previous one. A prim that becomes publishable again, for example after its scale turns uniform, returns at the next publication.

  4. An excluded prim is absent from the version, so the second ray passes the Egg. The stretched Crate is an exact box, and the ray meets the Ramp’s sheared face at 7 − 0.5 + 0.5 × 0.25.

Tip

If your program must not query a version with exclusions, check excluded_object_count after each publication. Keep reading the last version without exclusions by its exact ordinal, as Version Selection describes, while it is still retained.

Versions and Retention#

Each publication captures one sealed state and becomes a version labeled with that state’s ordinal. The newest is the head. Publication is atomic: a version becomes the head in one step or nothing changes.

The population also keeps the latest retained_ordinal_capacity prior heads, so a query can select an older state by its exact ordinal. A delayed sensor reads the world as it was when its data was captured, without a copy and without a global switch. The following figure shows a population that retains two prior versions:

Retention decides what can be selected. An operation keeps alive what it already selected.

The figure shows three rules:

  • Ordinals are the source’s numbers. Ordinals that were sealed but never published (102, 103) are never replayed, and a population never renumbers them.

  • An admitted operation keeps the version it selected until it is destroyed, even after that version leaves the retention window.

  • Leaving the window ends selection. A new query for that ordinal returns ORDINAL_NOT_RETAINED.

Choose retained_ordinal_capacity when you create the population. It cannot change later. The head and every retained version count against the instance’s memory budget. A publication that does not fit fails atomically instead of evicting a version a reader can still select.

Views and Participation Bits#

Two tools narrow what a query can see, and they answer different questions:

A view is a stable subset of one population, defined once by a filter: an ovstage filter for an ovstage population, or a list of object IDs for an explicit one. It shares every version and all acceleration data of its population and copies nothing. Use a view for a subset many queries share, such as the surfaces a robot can drive on.

Important

An ovstage view becomes ready with the next publication of its population, so create it before you publish.

An ovstage filter is an AND of tests, so it cannot select “everything under /World except /World/Scaffolding.” A scope can. It is an include list and an exclude list of prim paths, which create_population and create_view take beside the filter. For each prim, the nearest listed path at or above it decides. An include admits the prim, and an exclude removes it. When one path is in both lists, the exclude wins. An include below an exclude brings that subtree back. Paths compare by element, so /World/Env does not cover /World/Environment. With no includes, the scope starts from every prim the filter selects:

props = population.create_view(ovstage.Filter([]), exclude_paths=["/World/Scaffolding"])

A prim outside the scope is not selected, as if the filter had rejected it, so it is never listed in excluded_objects. In C, the scope is the scope member of the population and view descriptors, and its entries are path tokens from the stage’s path dictionary. A scope is fixed when you create the population or view; create another view for another scope.

Participation bits are 128 bits per object, captured with each publication. A query passes query_bits, and accepts an object when the two share at least one set bit. Zero accepts everything. This is the test and the width of the PhysX PxFilterData scene-query filter. Use bits for categories that change per query, such as “obstacles only.”

In Python, a bits value is an int from 0 to 2**128 - 1. In C, it is an ovspatialquery_participation_bits_t whose words[0] holds bits 0 to 63 and words[1] holds bits 64 to 127. A column of bits, one row per query or object, is a uint64[N,2] array in the same word order.

The following figure casts one ray three ways: against the population, with obstacle bits, and through a view:

The same ray against the population, the population with OBSTACLE bits, and a view.

For an ovstage population, you assign bits with a participation table: listed prim paths get their bits and every other object gets a default. In Python, population.set_participation_map(default_bits, {"/World/Crate": OBSTACLE}) takes prim path strings or path tokens. Without a table, every object has all 128 bits set. For an explicit population, the bits are an optional column of the publication, all bits set by default. Either way, a version keeps the bits it was published with, so a query against a retained ordinal sees the categories of that moment.

Identity#

Every hit carries two identities and a material:

  • The object ID names the source object within its population. For ovstage, it is the prim’s path token, which ovstage.PathDictionary(stage).path_to_string(ovstage.PrimPath(object_id)) turns back into a path. ovstage 0.3 has no PrimPath and takes object_id itself. A prim re-created at the same path keeps its ID. IDs from different populations are not comparable.

  • The geometry reference names one immutable stored shape and is comparable across every population of an instance. Two prims that share a prototype share a reference. Editing its geometry gives later publications a different reference. Retained versions keep their original geometry references and stored shapes.

  • The material, material_id, is the value the population assigns to the reported surface. Zero means none. For ovstage, it is the path value of the bound physics material, else of the bound material. An exact hit on a mesh face reports the binding of a face subset that lists the face, and the mesh’s material when no such binding counts. A subset’s physics binding always counts, and its other binding only when the mesh has no physics binding. For an explicit population, you supply the values as optional columns. A version keeps the materials it was published with. An ovstage version prepared on a CUDA device, and an explicit publication from CUDA columns, report zero.