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

Include segmentation layers in handling maximum number of renderable layers restricted by hardware #6211

Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class PlaneMaterialFactory {
true,
),
);
const oldVisibilityPerLayer = {};
const oldVisibilityPerLayer: Record<string, boolean> = {};
this.storePropertyUnsubscribers.push(
listenToStoreProperty(
(state) => state.datasetConfiguration.layers,
Expand All @@ -431,9 +431,7 @@ class PlaneMaterialFactory {
const isSegmentationLayer = dataLayer.isSegmentation;

if (
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
oldVisibilityPerLayer[dataLayer.name] != null &&
// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
oldVisibilityPerLayer[dataLayer.name] !== isLayerEnabled
) {
if (settings.isDisabled) {
Expand All @@ -443,7 +441,6 @@ class PlaneMaterialFactory {
}
}

// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
oldVisibilityPerLayer[dataLayer.name] = isLayerEnabled;
const name = sanitizeName(dataLayer.name);
this.updateUniformsForLayer(settings, name, elementClass, isSegmentationLayer);
Expand Down Expand Up @@ -660,16 +657,19 @@ class PlaneMaterialFactory {
...this.leastRecentlyVisibleColorLayers,
..._.without(disabledLayer, ...this.leastRecentlyVisibleColorLayers),
];
const names = enabledLayer
.concat(this.leastRecentlyVisibleColorLayers)

// Perform a uniq operation on leastRecentlyVisibleColorLayers to avoid that
// that invalid shaders are generated (due to duplicate layer names) when switching
// between the visibility of different segmentation layers.
const names = _.uniq(enabledLayer.concat(this.leastRecentlyVisibleColorLayers))
.slice(0, maximumLayerCountToRender)
.sort();
const sanitizedColorLayerNames = names
.filter(({ isSegmentationLayer }) => !isSegmentationLayer)
.map(({ name }) => sanitizeName(name));
const sanitizedSegmentationLayerNames = names
.filter(({ isSegmentationLayer }) => isSegmentationLayer)
.map(({ name }) => sanitizeName(name));

const [sanitizedColorLayerNames, sanitizedSegmentationLayerNames] = _.partition(
names,
({ isSegmentationLayer }) => !isSegmentationLayer,
).map((layers) => layers.map(({ name }) => sanitizeName(name)));

Comment on lines +673 to +677
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhh 😲 , very nice 🚀

return [sanitizedColorLayerNames, sanitizedSegmentationLayerNames];
}

Expand Down