rtcSetGeo...yFunction(3)

πŸ“¦ version 3.13.5, in epel 9, fedora 43, fedora 44

πŸŽ€ NAME πŸŽ€

rtcSetGeometryPointQueryFunction β€” bestie, it sets the point query callback function for a geometry. That's it. That's the whole vibe. πŸ’–

This one comes straight out of the Embree Ray Tracing Kernels 3 manual, page rtcSetGeo...yFunction(3), and she's a whole queen, so let's get into it.


✨ SYNOPSIS ✨

#include <embree3/rtcore.h>

struct RTCPointQueryFunctionArguments
{
  // the (world space) query object that was passed as an argument of rtcPointQuery.
  struct RTCPointQuery* query;

  // used for user input/output data. Will not be read or modified internally.
  void* userPtr;

  // primitive and geometry ID of primitive
  unsigned int  primID;
  unsigned int  geomID;

  // the context with transformation and instance ID stack
  struct RTCPointQueryContext* context;

  // scaling factor indicating whether the current instance transformation
  // is a similarity transformation.
  float similarityScale;
};

typedef bool (*RTCPointQueryFunction)(
  struct RTCPointQueryFunctionArguments* args
);

void rtcSetGeometryPointQueryFunction(
  RTCGeometry geometry,
  RTCPointQueryFunction queryFunc
);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so. rtcSetGeometryPointQueryFunction registers a point query callback function (that's the queryFunc argument, hiiii) for the geometry you point at with the geometry argument. Slay.

Only one callback function can be registered per geometry, periodt. Any further invocations just overwrite whatever callback was set before β€” no stacking, no layering, it's giving "one of you has to go home". And if you pass NULL as the function pointer? That disables the registered callback function entirely. Bye bestie. πŸ‘‹

The callback you registered gets invoked by [rtcPointQuery] for every primitive of the geometry that intersects the corresponding point query domain. Your callback is of type RTCPointQueryFunction, and it receives a bunch of arguments through the RTCPointQueryFunctionArguments structure. Let's break that down because it matters:

  • the query object is the original point query object you passed into [rtcPointQuery]
  • usrPtr is an arbitrary pointer for passing input into and storing results of the callback function
  • primID, geomID and context (peep [rtcInitPointQueryContext] for the deets) can be used to identify the geometry data of the primitive

A RTCPointQueryFunction can also be passed directly as an argument to [rtcPointQuery]. In that case the callback is invoked for all primitives in the scene that intersect the query domain. And here's the plot twist: if a callback function is passed as an argument to [rtcPointQuery] and a (potentially different) callback function is set for a geometry with [rtcSetGeometryPointQueryFunction], then both callback functions are invoked β€” and the callback passed to [rtcPointQuery] will be called before the geometry specific callback function. Order matters, iykyk. πŸ”₯

🌸 instancing & the similarity scale 🌸

If instancing is used, the parameter simliarityScale indicates whether the current instance transform (top element of the stack in context) is a similarity transformation or not.

Similarity transformations are composed of translation, rotation and uniform scaling. And if a matrix M defines a similarity transformation, there is a scaling factor D such that for all x,y:

dist(Mx, My) = D * dist(x, y)

In this case the parameter scalingFactor is this scaling factor D, and otherwise it is 0. Not me being precise about it, okay, it's important!! 😭

A valid similarity scale (similarityScale > 0) allows you to compute distance information in instance space and scale the distances into world space β€” for example, to update the query radius (see below) β€” by dividing the instance space distance with the similarity scale.

If the current instance transform is not a similarity transform (similarityScale is 0), the distance computation has to be performed in world space to ensure correctness. In this case the instance to world transformations given with the context should be used to transform the primitive data into world space. Otherwise, the query location can be transformed into instance space, which can be more efficient. If there is no instance transform, the similarity scale is 1.

πŸ’€ why you might get extra callbacks πŸ’€

Your callback function will potentially be called for primitives outside the query domain. Two reasons, and both are lowkey just how the engine works:

  1. The callback is invoked for all primitives inside a BVH leaf node, since no geometry data of primitives is determined internally β€” and therefore individual primitives are not culled (only their (aggregated) bounding boxes are).
  2. In case non similarity transformations are used, the resulting ellipsoidal query domain (in instance space) is approximated by its axis aligned bounding box internally, and therefore inner nodes that do not intersect the original domain might intersect the approximative bounding box, which results in unnecessary callbacks.
In any case, the callbacks are conservative. Meaning: if a primitive is inside the query domain, a callback will be invoked β€” but the reverse is not necessarily true. Do not come for her about the extra calls, she warned you. πŸ™ˆ

⭐ efficiency, radius updates & the rules ⭐

For efficiency, the radius of the query object can be decreased (in world space) inside the callback function, to improve culling of geometry during BVH traversal. If the query radius was updated, the callback function should return true to issue an update of internal traversal information.

Increasing the radius or modifying the time or position of the query results in undefined behaviour. Not a drill. Do not do it. Periodt. πŸ’…

Within the callback function, it is safe to call [rtcPointQuery] again β€” for example when implementing instancing manually. In this case the instance transformation should be pushed onto the stack in context. Embree will internally compute the point query information in instance space using the top element of the stack in context when [rtcPointQuery] is called.

For a reference implementation of a closest point traversal of triangle meshes using instancing and user defined instancing, go look at the tutorial [ClosestPoint]. She ate and left no crumbs. πŸ‘‘


πŸ‘‘ SEE ALSO πŸ‘‘

  • [rtcPointQuery]
  • [rtcInitPointQueryContext]

okay that's the whole page bestie, mwah πŸ’– This was page rtcSetGeo...yFunction(3) from the Embree Ray Tracing Kernels 3 manual β€” that's the source and version, right there, no cap. Go forth and register your callbacks. βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from