UNPKG

@itwin/core-frontend

Version:
179 lines 8.35 kB
/** @packageDocumentation * @module Rendering */ import { Id64String } from "@itwin/core-bentley"; import { BatchType, Feature, GeometryClass, ModelFeature } from "@itwin/core-common"; import { ContourHit, HitPath, HitPriority } from "../HitDetail"; import { IModelConnection } from "../IModelConnection"; import type { Viewport } from "../Viewport"; import { Transform } from "@itwin/core-geometry"; /** Describes aspects of a pixel as read from a [[Viewport]]. * @see [[Viewport.readPixels]]. * @public * @extensions */ export declare namespace Pixel { /** Describes a single pixel within a [[Pixel.Buffer]]. */ class Data { /** The feature that produced the pixel. */ readonly feature?: Feature; readonly modelId?: Id64String; /** The pixel's depth in [[CoordSystem.Npc]] coordinates (0 to 1), or -1 if depth was not written or not requested. */ readonly distanceFraction: number; /** The type of geometry that produced the pixel. */ readonly type: GeometryType; /** The planarity of the geometry that produced the pixel. */ readonly planarity: Planarity; /** @internal */ readonly batchType?: BatchType; /** The iModel from which the geometry producing the pixel originated. */ readonly iModel?: IModelConnection; /** Information about the [contour line]($docs/learning/display/ContourDisplay.md), if any, that generated this pixel. * @beta */ readonly contour?: ContourHit; /** @internal */ readonly transformFromIModel?: Transform; /** @internal */ readonly tileId?: string; /** The Id of the [ViewAttachment]($backend), if any, from which the pixel originated. * @beta */ readonly viewAttachmentId?: Id64String; /** True if the pixel originated from a [[SpatialViewState]] attached via a [SectionDrawing]($backend). * @beta */ readonly inSectionDrawingAttachment: boolean; /** @internal */ get isClassifier(): boolean; /** @internal */ constructor(args?: { feature?: ModelFeature; distanceFraction?: number; type?: GeometryType; planarity?: Planarity; batchType?: BatchType; iModel?: IModelConnection; tileId?: string; viewAttachmentId?: string; inSectionDrawingAttachment?: boolean; transformFromIModel?: Transform; contour?: ContourHit; }); /** The Id of the element that produced the pixel. */ get elementId(): Id64String | undefined; /** The Id of the [SubCategory]($backend) that produced the pixel. */ get subCategoryId(): Id64String | undefined; /** The class of geometry that produced the pixel. */ get geometryClass(): GeometryClass | undefined; /** Computes the [[HitPriority]] of this pixel based on its [[type]] and [[planarity]]. */ computeHitPriority(): HitPriority; /** Convert this pixel to a [[Pixel.HitProps]] suitable for constructing a [[HitDetail]]. * @param viewport The viewport in which the hit originated. */ toHitProps(viewport: Viewport): Pixel.HitProps; } /** Describes a subset of [[HitDetailProps]] computed from a [[Pixel.Data]], suitable for constructing a [[HitDetail]]. * For example, the following function creates a `HitDetail` from a `Pixel.Data` and other hit information: * ```ts * function makeHitDetail(pixel: Pixel.Data, viewport: ScreenViewport, testPoint: Point3d, hitSource: HitSource, hitPoint: Point3d, distXY: number): HitDetail { * return new HitDetail({ * ...pixel.toHitProps(viewport), * viewport, testPoint, hitSource, hitPoint, distXY, * }; * } * ``` * @see [[Data.toHitProps]] to convert a [[Pixel.Data]] to a `HitProps`. * @public */ interface HitProps { /** The source of the geometry. This may be a persistent element Id, or a transient Id used for, e.g., pickable decorations. */ sourceId: Id64String; /** The hit geometry priority/classification. */ priority: HitPriority; /** The distance in view coordinates between the hit and the near plane. */ distFraction: number; /** The [SubCategory]($backend) to which the hit geometry belongs. */ subCategoryId?: Id64String; /** The class of the hit geometry. */ geometryClass?: GeometryClass; /** The Id of the [[ModelState]] from which the hit originated. */ modelId?: Id64String; /** The IModelConnection from which the hit originated. * This should almost always be left undefined, unless the hit is known to have originated from an iModel * other than the one associated with the viewport. * @internal */ sourceIModel?: IModelConnection; /** @internal */ transformFromSourceIModel?: Transform; /** @internal chiefly for debugging */ tileId?: string; /** True if the hit originated from a reality model classifier. * @alpha */ isClassifier?: boolean; /** Path through which the hit was located. * @beta */ path?: HitPath; /** Information about the [contour line]($docs/learning/display/ContourDisplay.md), if any, from which the hit originated. * @beta */ contour?: ContourHit; } /** Describes the type of geometry that produced the [[Pixel.Data]]. */ enum GeometryType { /** [[Pixel.Selector.GeometryAndDistance]] was not specified, or the type could not be determined. */ Unknown = 0,// Geometry was not selected, or type could not be determined /** No geometry was rendered to this pixel. */ None = 1, /** A surface produced this pixel. */ Surface = 2, /** A point primitive or polyline produced this pixel. */ Linear = 3, /** This pixel was produced by an edge of a surface. */ Edge = 4, /** This pixel was produced by a silhouette edge of a curved surface. */ Silhouette = 5 } /** Describes the planarity of the foremost geometry which produced the pixel. */ enum Planarity { /** [[Pixel.Selector.GeometryAndDistance]] was not specified, or the planarity could not be determined. */ Unknown = 0, /** No geometry was rendered to this pixel. */ None = 1, /** Planar geometry produced this pixel. */ Planar = 2, /** Non-planar geometry produced this pixel. */ NonPlanar = 3 } /** * Bit-mask by which callers of [[Viewport.readPixels]] specify which aspects are of interest. * Aspects not specified will be omitted from the returned data. */ enum Selector { None = 0, /** Select the [[Feature]] which produced each pixel. */ Feature = 1,// eslint-disable-line @typescript-eslint/no-shadow /** Select the type and planarity of geometry which produced each pixel as well as the fraction of its distance between the near and far planes. */ GeometryAndDistance = 4, /** Select the [[ContourHit]]s describing which if any contour line produced each pixel. */ Contours = 8, /** Select all aspects of each pixel. */ All = 13 } /** A rectangular array of pixels as read from a [[Viewport]]'s frame buffer. Each pixel is represented as a [[Pixel.Data]] object. * The contents of the pixel buffer will be specified using device pixels, not CSS pixels. See [[Viewport.devicePixelRatio]] and [[Viewport.cssPixelsToDevicePixels]]. * @see [[Viewport.readPixels]]. */ interface Buffer { /** Retrieve the data associated with the pixel at (x,y) in view coordinates. */ getPixel(x: number, y: number): Data; } /** A function which receives the results of a call to [[Viewport.readPixels]]. * @note The contents of the buffer become invalid once the Receiver function returns. Do not store a reference to it. */ type Receiver = (pixels: Buffer | undefined) => void; } //# sourceMappingURL=Pixel.d.ts.map