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

Make mappings work with 8 and 16 bit segmentations #3953

Merged
merged 4 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
- webKnossos now comes with a list of sample datasets that can be automatically downloaded and imported from the menu. [#3725](https://github.com/scalableminds/webknossos/pull/3725)
- Added a shortcut (Q) and button in the actions dropdown to screenshot the tracing views. The screenshots will contain everything that is visible in the tracing views, so feel free to disable the crosshairs in the settings or toggle the tree visibility using the (1) and (2) shortcuts before triggering the screenshot. [#3834](https://github.com/scalableminds/webknossos/pull/3834)
- Neuroglancer precomputed datasets can now be added to webKnossos using the webknossos-connect (wk-connect) service. To setup a wk-connect datastore follow the instructions in the [Readme](https://github.com/scalableminds/webknossos-connect). Afterwards, datasets can be added through "Add Dataset" - "Add Dataset via wk-connect". [#3843](https://github.com/scalableminds/webknossos/pull/3843)
- Added support for mappings for 8-bit and 16-bit segmentation layers. [#3953](https://github.com/scalableminds/webknossos/pull/3953)
- The dataset settings within the tracing view allow to select between different loading strategies now ("best quality first" and "progressive quality"). Additionally, the rendering can use different magnifications as a fallback (instead of only one magnification). [#3801](https://github.com/scalableminds/webknossos/pull/3801)
- The mapping selection dropbown is now sorted alphabetically. [#3864](https://github.com/scalableminds/webknossos/pull/3864)
- Added the possibility to filter datasets in the dashboard according to their availability. By default, datasets which are missing on disk (e.g., when the datastore was deleted) are not shown anymore. This behavior can be configured via the settings icon next to the search box in the dashboard. [#3883](https://github.com/scalableminds/webknossos/pull/3883)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ export function validateMinimumRequirements(specs: GpuSpecs): void {
export type DataTextureSizeAndCount = { textureSize: number, textureCount: number };

export function getPackingDegree(byteCount: number) {
// If the layer only holds one byte per voxel, we can pack 4 bytes using rgba channels
return byteCount === 1 ? 4 : 1;
// If the layer holds less than 4 byte per voxel, we can pack multiple voxels using rgba channels
if (byteCount === 1) return 4;
if (byteCount === 2) return 2;
return 1;
}

function getNecessaryVoxelCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DataBucket, bucketDebuggingFlags } from "oxalis/model/bucket_data_handl
import { createUpdatableTexture } from "oxalis/geometries/materials/plane_material_factory_helpers";
import { getBaseBucketsForFallbackBucket } from "oxalis/model/helpers/position_converter";
import { getMaxZoomStepDiff } from "oxalis/model/bucket_data_handling/loading_strategy_logic";
import { getPackingDegree } from "oxalis/model/bucket_data_handling/data_rendering_logic";
import { getRenderer } from "oxalis/controller/renderer";
import { getResolutions } from "oxalis/model/accessors/dataset_accessor";
import { waitForCondition } from "libs/utils";
Expand Down Expand Up @@ -57,7 +58,7 @@ export default class TextureBucketManager {
constructor(textureWidth: number, dataTextureCount: number, bytes: number) {
// If there is one byte per voxel, we pack 4 bytes into one texel (packingDegree = 4)
// Otherwise, we don't pack bytes together (packingDegree = 1)
this.packingDegree = bytes === 1 ? 4 : 1;
this.packingDegree = getPackingDegree(bytes);

this.maximumCapacity =
(this.packingDegree * dataTextureCount * textureWidth ** 2) / constants.BUCKET_SIZE;
Expand Down
9 changes: 9 additions & 0 deletions frontend/javascripts/oxalis/shaders/segmentation.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ export const getSegmentationId: ShaderModule = {

<% if (isMappingSupported) { %>
if (isMappingEnabled) {
// Depending on the packing degree, the returned volume color contains extra values
// which would make the binary search fail

<% if (segmentationPackingDegree === "4.0") { %>
volume_color = vec4(volume_color.r, 0.0, 0.0, 0.0);
<% } else if (segmentationPackingDegree === "2.0") { %>
volume_color = vec4(volume_color.r, volume_color.g, 0.0, 0.0);
<% } %>

float index = binarySearchIndex(
<%= segmentationName %>_mapping_lookup_texture,
mappingSize,
Expand Down
12 changes: 12 additions & 0 deletions frontend/javascripts/oxalis/shaders/texture_access.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ export const getColorForCoords: ShaderModule = {

float rgbaIndex = linearizeVec3ToIndexWithMod(offsetInBucket, bucketWidth, packingDegree);

if (packingDegree == 2.0) {
// It's essentially irrelevant what we return as the 3rd and 4th value here as we only have 2 byte of information.
// The caller needs to unpack this vec4 according to the packingDegree, see getSegmentationId for an example.
// The same goes for the following code where the packingDegree is 4 and we only have 1 byte of information.
if (rgbaIndex == 0.0) {
return vec4(bucketColor.r, bucketColor.g, bucketColor.r, bucketColor.g);
Copy link
Member

Choose a reason for hiding this comment

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

Why is the pattern rgrg? Can't wrap my head around it right now :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a comment :)

} else if (rgbaIndex == 1.0) {
return vec4(bucketColor.b, bucketColor.a, bucketColor.b, bucketColor.a);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment line here stating that the following code deals with packingDegree == 4.0? :) Took me a few seconds to figure out why there isn't a if (packingDegree == 4.0) { statement.

// The following code deals with packingDegree == 4.0
if (rgbaIndex == 0.0) {
return vec4(bucketColor.r);
} else if (rgbaIndex == 1.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "oxalis/view/settings/setting_input_views";
import type { UserConfiguration, OxalisState, Tracing } from "oxalis/store";
import type { APIDataset } from "admin/api_flow_types";
import { hasSegmentation } from "oxalis/model/accessors/dataset_accessor";
import {
enforceSkeletonTracing,
getActiveNode,
Expand Down Expand Up @@ -239,10 +240,7 @@ class UserSettingsView extends PureComponent<UserSettingsViewProps, State> {
const activeNodeRadius = getActiveNode(skeletonTracing)
.map(activeNode => activeNode.radius)
.getOrElse(0);
const isMergerModeSupported =
(this.props.dataset.dataSource.dataLayers || []).find(
layer => layer.category === "segmentation" && layer.elementClass === "uint32",
) != null;
const isMergerModeSupported = hasSegmentation(this.props.dataset);
panels.push(
<Panel header="Nodes & Trees" key="3a">
<NumberInputSetting
Expand Down Expand Up @@ -301,7 +299,7 @@ class UserSettingsView extends PureComponent<UserSettingsViewProps, State> {
disabled={!isMergerModeSupported}
tooltipText={
!isMergerModeSupported
? "The merger mode is only available for datasets with uint32 segmentations."
? "The merger mode is only available for datasets with a segmentation layer."
: null
}
/>
Expand Down