/
RealityModelDisplaySettings.ts
318 lines (277 loc) · 13.8 KB
/
RealityModelDisplaySettings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*---------------------------------------------------------------------------------------------
* 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
*/
/** Specifies how the sizes of the individual points within a point cloud are computed.
* - "pixel": Each point is an exact number of pixels in diameter, as specified by [[PointCloudDisplaySettings.pixelSize]].
* - "voxel": Each point is the size of a "voxel" in meters, as specified by the [Tile]($frontend) to which the point belongs.
* @see [[PointCloudDisplaySettings.sizeMode]].
* @beta
*/
export type PointCloudSizeMode = "voxel" | "pixel";
/** Specifies the shape drawn for each individual point within a point cloud.
* - "round": Each point is drawn as a circle.
* - "square": Each point is drawn as a square.
* @see [[PointCloudDisplaySettings.shape]].
* @beta
*/
export type PointCloudShape = "square" | "round";
/** Specifies the Eye-Dome Lighting mode used for a point cloud.
* - "off": EDL is not calculated
* - "on": EDL is calculated using a single pass.
* - "full" EDL is calculated with full algorithm including optional filtering
* @see [[PointCloudDisplaySettings.edlMode]].
* @beta
*/
export type PointCloudEDLMode = "off" | "on" | "full";
/** The JSON representation of [[PointCloudDisplaySettings]].
* @beta
*/
export interface PointCloudDisplayProps {
/** See [[PointCloudDisplaySettings.sizeMode]]. */
sizeMode?: PointCloudSizeMode;
/** See [[PointCloudDisplaySettings.voxelScale]]. */
voxelScale?: number;
/** See [[PointCloudDisplaySettings.minPixelsPerVoxel]]. */
minPixelsPerVoxel?: number;
/** See [[PointCloudDisplaySettings.maxPixelsPerVoxel]]. */
maxPixelsPerVoxel?: number;
/** See [[PointCloudDisplaySettings.pixelSize]]. */
pixelSize?: number;
/** See [[PointCloudDisplaySettings.shape]]. */
shape?: PointCloudShape;
/** See [[PointCloudDisplaySettings.edlMode]]. */
edlMode?: PointCloudEDLMode;
/** See [[PointCloudDisplaySettings.edlStrength]]. */
edlStrength?: number;
/** See [[PointCloudDisplaySettings.edlRadius]]. */
edlRadius?: number;
/** See [[PointCloudDisplaySettings.edlFilter]]. */
edlFilter?: number;
/** See [[PointCloudDisplaySettings.edlMixWts1]]. */
edlMixWts1?: number;
/** See [[PointCloudDisplaySettings.edlMixWts2]]. */
edlMixWts2?: number;
/** See [[PointCloudDisplaySettings.edlMixWts4]]. */
edlMixWts4?: number;
}
/** The JSON representation of [[RealityModelDisplaySettings]].
* @beta
*/
export interface RealityModelDisplayProps {
/** See [[RealityModelDisplaySettings.pointCloud]]. */
pointCloud?: PointCloudDisplayProps;
/** See [[RealityModelDisplaySettings.overrideColorRatio]]. */
overrideColorRatio?: number;
// ###TODO when we need it: mesh?: RealityMeshDisplayProps;
}
/** 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".
*/
public readonly shape: PointCloudShape;
/** 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.
*/
public readonly sizeMode: PointCloudSizeMode;
/** 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
*/
public readonly pixelSize: number;
/** 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
*/
public readonly voxelScale: number;
/** 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
*/
public readonly minPixelsPerVoxel: number;
/** 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.
*/
public readonly maxPixelsPerVoxel: number;
/** 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)
*/
public readonly edlMode: PointCloudEDLMode;
/** A strength value for the Eye Dome Lighting (EDL) effect.
* The strength is expected to be a positive floating point number.
* Default: 5.0
*/
public readonly edlStrength: number;
/** 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
*/
public readonly edlRadius: number;
/** 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
*/
public readonly edlFilter?: number;
/** 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
*/
public readonly edlMixWts1?: number;
/** 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
*/
public readonly edlMixWts2?: number;
/** 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
*/
public readonly edlMixWts4?: number;
/** Settings with all properties initialized to their default values. */
public static defaults = new PointCloudDisplaySettings();
private constructor(props?: PointCloudDisplayProps) {
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. */
public static fromJSON(props?: PointCloudDisplayProps): PointCloudDisplaySettings {
return props ? new PointCloudDisplaySettings(props) : this.defaults;
}
/** Convert these settings to their JSON representation. */
public toJSON(): PointCloudDisplayProps | undefined {
const defs = PointCloudDisplaySettings.defaults;
if (this.equals(defs))
return undefined;
const props: PointCloudDisplayProps = { };
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`. */
public clone(changedProps: PointCloudDisplayProps): PointCloudDisplaySettings {
return PointCloudDisplaySettings.fromJSON({
...this.toJSON(),
...changedProps,
});
}
/** Returns true if these settings are identical to `other`. */
public equals(other: PointCloudDisplaySettings): boolean {
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
*/
public readonly overrideColorRatio: number;
/** Settings that apply specifically to point cloud reality models.
* Default: [[PointCloudDisplaySettings.defaults]].
*/
public readonly pointCloud: PointCloudDisplaySettings;
/** Settings with all properties initialized to their default values. */
public static defaults = new RealityModelDisplaySettings(undefined, PointCloudDisplaySettings.defaults);
private constructor(overrideColorRatio: number | undefined, pointCloud: PointCloudDisplaySettings) {
this.overrideColorRatio = overrideColorRatio ?? 0.5;
this.pointCloud = pointCloud;
}
/** Create display settings from their JSON representation. If `props` is `undefined`, the default settings are returned. */
public static fromJSON(props?: RealityModelDisplayProps): RealityModelDisplaySettings {
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. */
public toJSON(): RealityModelDisplayProps | undefined {
const pointCloud = this.pointCloud.toJSON();
const overrideColorRatio = this.overrideColorRatio === RealityModelDisplaySettings.defaults.overrideColorRatio ? undefined : this.overrideColorRatio;
if (undefined === pointCloud && undefined === overrideColorRatio)
return undefined;
const props: RealityModelDisplayProps = { };
if (undefined !== pointCloud)
props.pointCloud = pointCloud;
if (undefined !== overrideColorRatio)
props.overrideColorRatio = overrideColorRatio;
return props;
}
/** Returns true if these settings are identical to `other`. */
public equals(other: RealityModelDisplaySettings): boolean {
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`. */
public clone(changedProps: RealityModelDisplayProps): RealityModelDisplaySettings {
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);
}
}