UNPKG

@itwin/core-common

Version:

iTwin.js components common to frontend and backend

214 lines • 11.1 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module DisplayStyles */ /** Settings that control how a point cloud reality model is displayed within a [Viewport]($frontend). * @note This is an immutable type - to modify its properties, use [[clone]]. * Eye-Dome Lighting (EDL) is a non-photorealistic, image-based shading technique that was designed to improve depth * perception in scientific visualization. It is particularly useful for visualizing monochrome point cloud data, but * also can be useful for point clouds with color information. * @note EDL mode is ignored (off) if the view is not perspective (camera is off) * @see [[RealityModelDisplaySettings.pointCloud]]. * @beta */ export class PointCloudDisplaySettings { /** The shape drawn for each point in the cloud. * Default: "round". */ shape; /** The method by which the size of each individual point is computed. * Default: "voxel". * @see [[pixelSize]] to configure the size for "pixel" mode. * @see [[voxelScale]], [[minPixelsPerVoxel]], and [[maxPixelsPerVoxel]] to configure the size for "voxel" mode. */ sizeMode; /** The radius of each point in pixels, when [[sizeMode]] is "pixel". * The size is expected to be a positive integer. The maximum size will vary based on the graphics hardware in use, but typically is limited to 32 or 64 pixels. * Default: 1 */ pixelSize; /** A scale factor applied to the size of each point, when [[sizeMode]] is "voxel". * The scale is expected to be a positive floating point number. * Default: 1.0 */ voxelScale; /** If [[sizeMode]] is "voxel", the minimum radius of each point in pixels. It is expected to be a positive integer no greater than [[maxPixelsPerVoxel]]. * Default: 2 */ minPixelsPerVoxel; /** If [[sizeMode]] is "voxel", the maximum radius of each point in pixels. It is expected to be a positive integer no less than [[minPixelsPerVoxel]]. * Default: 20. */ maxPixelsPerVoxel; /** The mode for the Eye-Dome Lighting (EDL) effect. * Default: "off" * @note EDL mode is ignored (off) if the view is not perspective (camera is off) */ edlMode; /** A strength value for the Eye Dome Lighting (EDL) effect. * The strength is expected to be a positive floating point number. * Default: 5.0 */ edlStrength; /** A radius value for the Eye Dome Lighting (EDL) effect. * The radius is expected to be a positive floating point number * It is used to deterimine how far away in pixels to sample for depth change * Default: 2.0 */ edlRadius; /** A flag for whether or not to apply filtering pass in the Eye Dome Lighting (EDL) effect. * It only applies if edlMode is "full" * Default: 1.0 */ edlFilter; /** A weighting value to apply to the full image when combining it with the half and quarter sized ones * It only applies if edlMode is "full" * The strength is expected to be a floating point number between 0 and 1 inclusive. * Default: 1.0 */ edlMixWts1; /** A weighting value to apply to the half sized image when combining it with the full and quarter sized ones * It only applies if edlMode is "full" * The strength is expected to be a floating point number between 0 and 1 inclusive. * Default: 0.5 */ edlMixWts2; /** A weighting value to apply to the quarter sized image when combining it with the full and half sized ones * It only applies if edlMode is "full" * The strength is expected to be a floating point number between 0 and 1 inclusive. * Default: 0.25 */ edlMixWts4; /** Settings with all properties initialized to their default values. */ static defaults = new PointCloudDisplaySettings(); constructor(props) { this.shape = props?.shape ?? "round"; this.sizeMode = props?.sizeMode ?? "voxel"; // No sanity checks here - e.g., min < max, pixelSize and voxelScale > 0, etc. this.pixelSize = props?.pixelSize ?? 1; this.voxelScale = props?.voxelScale ?? 1; this.minPixelsPerVoxel = props?.minPixelsPerVoxel ?? 2; this.maxPixelsPerVoxel = props?.maxPixelsPerVoxel ?? 20; this.edlMode = props?.edlMode ?? "off"; this.edlStrength = props?.edlStrength ?? 5; this.edlRadius = props?.edlRadius ?? 2; this.edlFilter = props?.edlFilter ?? 1; this.edlMixWts1 = props?.edlMixWts1 ?? 1.0; this.edlMixWts2 = props?.edlMixWts2 ?? 0.5; this.edlMixWts4 = props?.edlMixWts4 ?? 0.25; } /** Create display settings from their JSON representation. If `props` is `undefined`, the default settings are returned. */ static fromJSON(props) { return props ? new PointCloudDisplaySettings(props) : this.defaults; } /** Convert these settings to their JSON representation. */ toJSON() { const defs = PointCloudDisplaySettings.defaults; if (this.equals(defs)) return undefined; const props = {}; if (this.shape !== defs.shape) props.shape = this.shape; if (this.sizeMode !== defs.sizeMode) props.sizeMode = this.sizeMode; if (this.pixelSize !== defs.pixelSize) props.pixelSize = this.pixelSize; if (this.voxelScale !== defs.voxelScale) props.voxelScale = this.voxelScale; if (this.minPixelsPerVoxel !== defs.minPixelsPerVoxel) props.minPixelsPerVoxel = this.minPixelsPerVoxel; if (this.maxPixelsPerVoxel !== defs.maxPixelsPerVoxel) props.maxPixelsPerVoxel = this.maxPixelsPerVoxel; if (this.edlMode !== defs.edlMode) props.edlMode = this.edlMode; if (this.edlStrength !== defs.edlStrength) props.edlStrength = this.edlStrength; if (this.edlRadius !== defs.edlRadius) props.edlRadius = this.edlRadius; if (this.edlFilter !== defs.edlFilter) props.edlFilter = this.edlFilter; if (this.edlMixWts1 !== defs.edlMixWts1) props.edlMixWts1 = this.edlMixWts1; if (this.edlMixWts2 !== defs.edlMixWts2) props.edlMixWts2 = this.edlMixWts2; if (this.edlMixWts4 !== defs.edlMixWts4) props.edlMixWts4 = this.edlMixWts4; return props; } /** Create a copy of these settings, identical except for any properties explicitly specified by `changedProps`. */ clone(changedProps) { return PointCloudDisplaySettings.fromJSON({ ...this.toJSON(), ...changedProps, }); } /** Returns true if these settings are identical to `other`. */ equals(other) { if (this === other) return true; return this.shape === other.shape && this.sizeMode === other.sizeMode && this.pixelSize === other.pixelSize && this.voxelScale === other.voxelScale && this.minPixelsPerVoxel === other.minPixelsPerVoxel && this.maxPixelsPerVoxel === other.maxPixelsPerVoxel && this.edlMode === other.edlMode && this.edlStrength === other.edlStrength && this.edlRadius === other.edlRadius && this.edlFilter === other.edlFilter && this.edlMixWts1 === other.edlMixWts1 && this.edlMixWts2 === other.edlMixWts2 && this.edlMixWts4 === other.edlMixWts4; } } /** Settings that control how a reality model - whether a [[ContextRealityModel]] or a persistent reality [Model]($backend) - is displayed within a [Viewport]($frontend). * @see [[ContextRealityModel.displaySettings]] to apply these settings to a context reality model. * @see [[DisplayStyleSettings.setRealityModelDisplaySettings]] to apply these settings to a persistent reality model. * @note This is an immutable type - to modify its properties, use [[clone]]. * @beta */ export class RealityModelDisplaySettings { /** If the reality model's color is overridden with another color, a ratio in [0..1] with which to mix the two colors together. * A ratio of 0 uses only the reality model's color, a ratio of 1 uses only the override color, and a ratio of 0.5 mixes the two colors equally. * The color may be overridden using [[FeatureOverrides]] such as those supplied by a [FeatureOverrideProvider]($frontend), or by applying a [[SpatialClassifier]]. * Default: 0.5 */ overrideColorRatio; /** Settings that apply specifically to point cloud reality models. * Default: [[PointCloudDisplaySettings.defaults]]. */ pointCloud; /** Settings with all properties initialized to their default values. */ static defaults = new RealityModelDisplaySettings(undefined, PointCloudDisplaySettings.defaults); constructor(overrideColorRatio, pointCloud) { this.overrideColorRatio = overrideColorRatio ?? 0.5; this.pointCloud = pointCloud; } /** Create display settings from their JSON representation. If `props` is `undefined`, the default settings are returned. */ static fromJSON(props) { if (!props) return this.defaults; return new RealityModelDisplaySettings(props.overrideColorRatio, PointCloudDisplaySettings.fromJSON(props.pointCloud)); } /** Convert these settings to their JSON representation, which is `undefined` if all of their properties match the default settings. */ toJSON() { const pointCloud = this.pointCloud.toJSON(); const overrideColorRatio = this.overrideColorRatio === RealityModelDisplaySettings.defaults.overrideColorRatio ? undefined : this.overrideColorRatio; if (undefined === pointCloud && undefined === overrideColorRatio) return undefined; const props = {}; if (undefined !== pointCloud) props.pointCloud = pointCloud; if (undefined !== overrideColorRatio) props.overrideColorRatio = overrideColorRatio; return props; } /** Returns true if these settings are identical to `other`. */ equals(other) { if (this === other) return true; return this.overrideColorRatio === other.overrideColorRatio && this.pointCloud.equals(other.pointCloud); } /** Create a copy of these settings, identical except for any properties explicitly specified by `changedProps`. */ clone(changedProps) { const pointCloud = changedProps.pointCloud ? this.pointCloud.clone(changedProps.pointCloud) : this.pointCloud; const colorRatio = changedProps.hasOwnProperty("overrideColorRatio") ? changedProps.overrideColorRatio : this.overrideColorRatio; return new RealityModelDisplaySettings(colorRatio, pointCloud); } } //# sourceMappingURL=RealityModelDisplaySettings.js.map