Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Building Scene Layer (BSL) OGC I3S standard #11678

Merged
merged 33 commits into from
Feb 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
808fcaa
- Added support for conversion from sRGB color space profile to linea…
Tamrat-B Dec 5, 2023
0b9869b
Added Support for BSL structure, BSL statistics, generic feature attr…
Tamrat-B Dec 5, 2023
d612e7b
I3S Building Scene Layer Sandcastle app
Tamrat-B Dec 5, 2023
a4da846
I3S BSL app icon
Tamrat-B Dec 5, 2023
f469a21
Added support for conversion from sRGB color space profile to linear …
Tamrat-B Dec 5, 2023
4f92b4a
added additional payload options
Tamrat-B Dec 5, 2023
a2066b0
- Added support for binary attribute data with values stored in objec…
Tamrat-B Dec 5, 2023
562d6e5
- Added support for 3D objects transparency
Tamrat-B Dec 5, 2023
89f6dbe
- Added support for BSL hierarchy of layers
Tamrat-B Dec 5, 2023
394f823
- Added support for the generic feature attribute driven filter
Tamrat-B Dec 5, 2023
1394e4a
Added support for BSL structure per the OGC I3S standard
Tamrat-B Dec 5, 2023
5a34b60
- Added support for symbolization defined in I3S Layer data
Tamrat-B Dec 5, 2023
1054536
Added support for EXT_mesh_features and EXT_structural_metadata glTF …
Tamrat-B Dec 5, 2023
e1d55f7
Added bsl layer tests
Tamrat-B Dec 5, 2023
04f3c51
Added I3S BSL ViewModel tests
Tamrat-B Dec 5, 2023
3e75b94
Added I3S BSL explorer
Tamrat-B Dec 5, 2023
969ac49
Added I3S Explorer tests
Tamrat-B Dec 5, 2023
b4b23a6
Added I3S BSL Explorer layer widget
Tamrat-B Dec 5, 2023
e03286b
Merge branch 'CesiumGS:main' into feature/i3s_bsl_support
Tamrat-B Jan 11, 2024
21b2f4f
updates based on review feedback
Tamrat-B Jan 11, 2024
efc7db5
Added I3S support PR to additions
Tamrat-B Feb 2, 2024
03a9125
removed non necessary options
Tamrat-B Feb 2, 2024
17784df
check before updating visibility
Tamrat-B Feb 2, 2024
c815c03
additional specs changes
Tamrat-B Feb 2, 2024
4bffc64
Merge branch 'main' into feature/i3s_bsl_support
Tamrat-B Feb 2, 2024
9f02cf3
Merge branch 'CesiumGS:main' into feature/i3s_bsl_support
Tamrat-B Feb 28, 2024
9d6dc59
Removed picking result from console output
Tamrat-B Feb 28, 2024
c7570c3
Remove console out if geoid transform is not needed
Tamrat-B Feb 28, 2024
88eae59
Default to model overview if present
Tamrat-B Feb 28, 2024
1aefdc9
update tests to account for model views
Tamrat-B Feb 28, 2024
cf8d1da
Added I3S Building Scene Layer support to March 1 release
Tamrat-B Feb 28, 2024
96aca3e
Handling edge case use cases where there is no Full Model and/or Over…
Tamrat-B Feb 28, 2024
a3ea292
Rename BSL -> BuildingSceneLayer
ggetz Feb 28, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- Added support for symbolization defined in I3S Layer data
  • Loading branch information
Tamrat-B committed Dec 5, 2023
commit 5a34b6001781f07bd791eb34a6eca3d108c74f07
337 changes: 337 additions & 0 deletions packages/engine/Source/Scene/I3SSymbology.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
import Color from "../Core/Color.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import srgbToLinear from "../Core/srgbToLinear.js";

/**
* This class implements an I3S symbology for I3S Layers.
* <p>
* Do not construct this directly, instead access symbology through {@link I3SLayer}.
* </p>
* @alias I3SSymbology
* @internalConstructor
*/
function I3SSymbology(layer) {
this._layer = layer;
this._defaultSymbology = undefined;
this._valueFields = [];
this._uniqueValueHash = undefined;
this._classBreaksHash = undefined;

this._parseLayerSymbology();
}

Object.defineProperties(I3SSymbology.prototype, {
/**
* Gets the default symbology data.
* @memberof I3SSymbology.prototype
* @type {object}
* @readonly
*/
defaultSymbology: {
get: function () {
return this._defaultSymbology;
},
},
});

function convertColor(color, transparency) {
// color is represented as a three or four-element array, values range from 0 through 255.
// transparency value has to lie between 100 (full transparency) and 0 (full opacity).
const convertedColor = [];
for (let i = 0; i < color.length; i++) {
const floatColor = Color.byteToFloat(color[i]);
if (i < 3) {
convertedColor.push(srgbToLinear(floatColor));
} else {
convertedColor.push(floatColor);
}
}
if (convertedColor.length === 3) {
if (defined(transparency)) {
convertedColor.push(1.0 - transparency / 100.0);
} else {
convertedColor.push(1.0);
}
}
return convertedColor;
}

function parseSymbol(symbol, isColorCaptured) {
const symbology = {
edges: undefined,
material: undefined,
};
if (defined(symbol) && defined(symbol.symbolLayers)) {
for (let i = 0; i < symbol.symbolLayers.length; i++) {
const symbolLayer = symbol.symbolLayers[i];
if (symbolLayer.type === "Fill") {
const edges = symbolLayer.edges;
const outline = symbolLayer.outline;
if (defined(edges)) {
symbology.edges = {};
if (defined(edges.color)) {
symbology.edges.color = convertColor(
edges.color,
edges.transparency
);
}
} else if (defined(outline)) {
symbology.edges = {};
if (defined(outline.color)) {
symbology.edges.color = convertColor(
outline.color,
outline.transparency
);
}
}

if (!isColorCaptured) {
const material = symbolLayer.material;
if (defined(material)) {
symbology.material = {
colorMixMode: material.colorMixMode,
};
if (defined(material.color)) {
symbology.material.color = convertColor(
material.color,
material.transparency
);
}
}
}
break;
}
}
}
return symbology;
}

function buildUniqueValueHash(renderer, isColorCaptured) {
if (defined(renderer.uniqueValueGroups)) {
const valueHash = {};
for (
let groupIndex = 0;
groupIndex < renderer.uniqueValueGroups.length;
groupIndex++
) {
const classes = renderer.uniqueValueGroups[groupIndex].classes;
if (defined(classes)) {
for (let classIndex = 0; classIndex < classes.length; classIndex++) {
const classSymbology = parseSymbol(
classes[classIndex].symbol,
isColorCaptured
);
const values = classes[classIndex].values;
for (let valueIndex = 0; valueIndex < values.length; valueIndex++) {
const fieldValues = values[valueIndex];
let hash = valueHash;
for (
let fieldIndex = 0;
fieldIndex < fieldValues.length;
fieldIndex++
) {
const fieldValue = fieldValues[fieldIndex];
if (fieldIndex === fieldValues.length - 1) {
hash[fieldValue] = classSymbology;
} else {
if (!defined(hash[fieldValue])) {
hash[fieldValue] = {};
}
hash = hash[fieldValue];
}
}
}
}
}
}
return valueHash;
}
if (defined(renderer.uniqueValueInfos)) {
const valueHash = {};
for (
let infoIndex = 0;
infoIndex < renderer.uniqueValueInfos.length;
infoIndex++
) {
const info = renderer.uniqueValueInfos[infoIndex];
valueHash[info.value] = parseSymbol(info.symbol, isColorCaptured);
}
return valueHash;
}
return undefined;
}

function buildClassBreaksHash(renderer, isColorCaptured) {
if (defined(renderer.classBreakInfos)) {
const classBreakInfos = [...renderer.classBreakInfos];
classBreakInfos.sort(function (a, b) {
const aMax = defaultValue(a.classMaxValue, a.classMinValue);
const bMax = defaultValue(b.classMaxValue, b.classMinValue);
return aMax - bMax;
});
const valueHash = {
ranges: [],
symbols: [],
};

if (defined(renderer.minValue)) {
valueHash.ranges.push(renderer.minValue);
valueHash.symbols.push(undefined);
}
for (let infoIndex = 0; infoIndex < classBreakInfos.length; infoIndex++) {
const info = classBreakInfos[infoIndex];
if (defined(info.classMinValue)) {
if (
valueHash.ranges.length === 0 ||
info.classMinValue > valueHash.ranges[valueHash.ranges.length - 1]
) {
valueHash.ranges.push(info.classMinValue);
valueHash.symbols.push(undefined);
}
}
if (defined(info.classMaxValue)) {
if (
valueHash.ranges.length === 0 ||
info.classMaxValue > valueHash.ranges[valueHash.ranges.length - 1]
) {
valueHash.ranges.push(info.classMaxValue);
valueHash.symbols.push(parseSymbol(info.symbol, isColorCaptured));
}
}
}
valueHash.symbols.push(undefined);

return valueHash;
}
return undefined;
}

/**
* @private
*/
I3SSymbology.prototype._parseLayerSymbology = function () {
const drawingInfo = this._layer.data.drawingInfo;
if (defined(drawingInfo) && defined(drawingInfo.renderer)) {
const cachedDrawingInfo = this._layer.data.cachedDrawingInfo;
const isColorCaptured =
defined(cachedDrawingInfo) && cachedDrawingInfo.color === true;
const renderer = drawingInfo.renderer;
if (renderer.type === "simple") {
this._defaultSymbology = parseSymbol(renderer.symbol, isColorCaptured);
} else if (renderer.type === "uniqueValue") {
this._defaultSymbology = parseSymbol(
renderer.defaultSymbol,
isColorCaptured
);
this._valueFields.push(renderer.field1);
if (defined(renderer.field2)) {
this._valueFields.push(renderer.field2);
}
if (defined(renderer.field3)) {
this._valueFields.push(renderer.field3);
}
this._uniqueValueHash = buildUniqueValueHash(renderer, isColorCaptured);
} else if (renderer.type === "classBreaks") {
this._defaultSymbology = parseSymbol(
renderer.defaultSymbol,
isColorCaptured
);
this._valueFields.push(renderer.field);
this._classBreaksHash = buildClassBreaksHash(renderer, isColorCaptured);
}
}
};

function findHashForUniqueValues(hash, values, hashLevel, valueIndex) {
const levelValues = values[hashLevel];
if (valueIndex < levelValues.length) {
const hashValue = levelValues[valueIndex];
const innerHash = hash[hashValue];
if (defined(innerHash) && ++hashLevel < values.length) {
return findHashForUniqueValues(innerHash, values, hashLevel, valueIndex);
}
return innerHash;
}
return undefined;
}

function bisect(array, value) {
let low = 0;
let high = array.length;
if (low < high) {
do {
const mid = (low + high) >>> 1;
if (array[mid] < value) {
low = mid + 1;
} else {
high = mid;
}
} while (low < high);
}
return low;
}

function findHashForClassBreaks(hash, values, valueIndex) {
const value = values[valueIndex];
const range = bisect(hash.ranges, value);
return hash.symbols[range];
}

/**
* @private
*/
I3SSymbology.prototype._getSymbology = async function (node) {
const symbology = {
default: this._defaultSymbology,
};

if (this._valueFields.length > 0) {
const promises = [];
for (let i = 0; i < this._valueFields.length; i++) {
promises.push(node.loadField(this._valueFields[i]));
}
await Promise.all(promises);

const fieldsValues = [];
for (let i = 0; i < this._valueFields.length; i++) {
fieldsValues.push(node.fields[this._valueFields[i]].values);
}

let featureHashFn;
if (defined(this._uniqueValueHash)) {
featureHashFn = (featureIndex) =>
findHashForUniqueValues(
this._uniqueValueHash,
fieldsValues,
0,
featureIndex
);
} else if (defined(this._classBreaksHash)) {
featureHashFn = (featureIndex) =>
findHashForClassBreaks(
this._classBreaksHash,
fieldsValues[0],
featureIndex
);
}

if (defined(featureHashFn)) {
const firstFieldValues = fieldsValues[0];
for (
let featureIndex = 0;
featureIndex < firstFieldValues.length;
featureIndex++
) {
const featureSymbology = featureHashFn(featureIndex);
if (defined(featureSymbology)) {
symbology[featureIndex] = featureSymbology;
}
}
}
}

return symbology;
};

export default I3SSymbology;