DynamicSpatialClassifier Interface
A SpatialClassifier that uses geoemtry produced at run-time to classify a reality model. The geometry is supplied by a TileTreeReference. A simple example of creating and applying a dynamic classifier:
/** A spatial region described by a bounding sphere, used to classify a reality model. */
interface ClassifiedRegion {
/** The center point of the bounding sphere. */
center: Point3d;
/** The radius of the bounding sphere. */
radius: number;
/** The name of the region, to serve as a tooltip when the user hovers over the classified region of the reality model. */
name: string;
/** The color in which to draw the classified region of the reality model. */
color: ColorDef;
}
/** Classify spherical regions of a reality model, either by planar projection (`classifyByVolume=false`) or by bounding volume (`classifyByVolume=true`). */
export function classifyRealityModel(model: ContextRealityModelState, regions: ClassifiedRegion[], classifyByVolume: boolean): void {
const modelId = model.iModel.transientIds.getNext();
// Create a GraphicBuilder to define the classifier geometry.
const builder = IModelApp.renderSystem.createGraphic({
type: GraphicType.Scene,
computeChordTolerance: () => 0.01,
pickable: {
modelId,
id: modelId,
isVolumeClassifier: classifyByVolume,
},
});
const regionIdsAndNames: Array<{ name: string, id: Id64String }> = [];
for (const region of regions) {
// Assign a unique Id to each region, so we can identify them when the user interacts with them in a viewport.
const regionId = model.iModel.transientIds.getNext();
regionIdsAndNames.push({ id: regionId, name: region.name });
// Add a sphere representing the region.
builder.setSymbology(region.color, region.color, 1);
builder.activatePickableId(regionId);
builder.addSolidPrimitive(Sphere.createCenterRadius(region.center, region.radius));
}
// Create a tile tree reference to provide the graphics at display time.
const tileTreeReference = TileTreeReference.createFromRenderGraphic({
graphic: builder.finish(),
modelId,
iModel: model.iModel,
getToolTip: async (hit) => Promise.resolve(regionIdsAndNames.find((x) => x.id === hit.sourceId)?.name),
});
// Direct the reality model to use our tile tree reference for classification.
model.classifiers.activeClassifier = {
tileTreeReference,
name: "Regions",
flags: new SpatialClassifierFlags(undefined, undefined, classifyByVolume),
};
}
@see SpatialClassifiersState to configure a reality model's classifiers.
Properties
Name | Type | Description | |
---|---|---|---|
flags | SpatialClassifierFlags | Flags controlling how to apply the classifier. | |
name | string | A user-friendly name appropriate for use in a user interface. | |
tileTreeReference | TileTreeReference | A reference to the TileTree that supplies the graphics used to classify the reality model. |
Defined in
Last Updated: 17 December, 2024
Found something wrong, missing, or unclear on this page?Raise an issue in our repo.