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

Colors for mappings #2965

Merged
merged 14 commits into from
Jul 30, 2018
Merged

Colors for mappings #2965

merged 14 commits into from
Jul 30, 2018

Conversation

daniel-wer
Copy link
Member

This PR adds the possibility to add custom colors for mappings as well as to hide unmapped segments.
Up to 256 colors (hsv hue values) can be specified which are then used in order to color the equivalence classes of the mapping. The interface using the API is not as clean yet (see my description in https://discuss.webknossos.org/t/colors-for-mappings/602/27?u=dwerner) but as the single user of that feature will be using the json mapping interface, I think that is fine for now. We'll hopefully align the json and API mappings interface in the near future.

Note that the are now two ways that segments can end up to be transparent. If the user specifies the hideUnmappedIds flag and doesn't map a segment id, it will be transparent. Also if the user specifies not enough entries in the mappingColors array (e.g.: 3 equivalence classes, but only 2 hue values), the segments of the equivalence classes without a color will be transparent.
Thinking about it while writing this PR description, maybe it would be better to have a default color in that second case. If I remember correctly I introduced this behavior in the beginning to solve the hideUnmappedIds feature, which I solved differently now ^^

URL of deployed dev instance (used for testing):

Steps to test:

  • Open a tracing using the ROI2017_wkw dataset.

    • Use this user script to activate a mapping with custom colors:
    webknossos.apiReady(3).then(api => {
    	const segmentationLayerName = api.data.getVolumeTracingLayerName();
    	api.data.setMapping(
    		segmentationLayerName,
    		{ 1230341: 1, 1230557: 1, 1227259: 2, 1236582: 2 },
        	        { colors: [0.0, 0.2, 0.5], hideUnmappedIds: true }
    	);
    });
    • All unmapped ids should be transparent, and the mapped ids should have the specified colors.
  • Locally, add a mapping file like this in the mappings folder of the segmentation folder of a dataset (don't forget to add the mapping name in the datasource.json):

    {
      "name": "colors",
      "classes": [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
      "colors": [0.2, 0.5, 0.9],
      "hideUnmappedIds": true
    }
    • Then open a volume tracing of that dataset, brush using the ids 1, 4, and 7
    • Activate the mapping using mappings.activate("colors")
    • The respective segments should have the specified colors
  • Mappings without custom colors should work as before

  • Disabling/Enabling mappings should work as before

Issues:


Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

Very nice! Works like a charm 👍

  • I agree that a default color should be used when there are not enough colors, but the hide-option is not set. If that's done, the PR should be ready to merge :)

@@ -186,6 +191,10 @@ class PlaneMaterialFactory extends AbstractPlaneMaterialFactory {
type: "t",
value: mappingLookupTexture,
};
this.uniforms[sanitizeName(`${segmentationLayer.name}_mapping_color_texture`)] = {
type: "t",
value: mappingColorTexture,
Copy link
Member

Choose a reason for hiding this comment

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

I hope the increased texture uniform count will not become a problem for older hardware :/ Can you test on browserstack whether iPad still works? 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

Mappings will be disallowed (and the textures won't be attached, see the check a couple of lines above which is not visible here) if there are not enough textures available (Model.isMappingSupported), so this shouldn't be a problem, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's right. However, the uniform is always defined in JS-land. I'm not sure whether this has implications on some systems. But probably not. We'll see :)

Copy link
Member Author

Choose a reason for hiding this comment

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

The uniform "definition" is inside a if (segmentationLayer != null && Model.isMappingSupported) { check, so it should not have any implications :)

getLargestSegmentId(): number {
const segmentationLayer = getLayerByName(Store.getState().dataset, this.layerName);
if (segmentationLayer.category !== "segmentation") {
throw new Error("Mappings class must be instantiated with a segmenation layer.");
Copy link
Member

Choose a reason for hiding this comment

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

segmentation

updateMappingColorTexture(mappingColors: ?Array<number>) {
mappingColors = mappingColors || [];
const float32Colors = new Float32Array(
MAPPING_COLOR_TEXTURE_WIDTH * MAPPING_COLOR_TEXTURE_WIDTH,
Copy link
Member

Choose a reason for hiding this comment

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

MAPPING_COLOR_TEXTURE_WIDTH ** 2 is shorter :)

@@ -119,7 +124,7 @@ ${compileShader(
getRelativeCoords,
getWorldCoordUVW,
getMaybeFilteredColorOrFallback,
convertCellIdToRGB,
hasSegmentation ? convertCellIdToRGB : null,
Copy link
Member

Choose a reason for hiding this comment

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

👍

@daniel-wer
Copy link
Member Author

@philippotto I applied your PR feedback, most notably a default color is now used, when there are not enough colors specified. I'd go on and merge this today :)

@philippotto
Copy link
Member

@philippotto I applied your PR feedback, most notably a default color is now used, when there are not enough colors specified. I'd go on and merge this today :)

Nice, sounds excellent 👍

@daniel-wer daniel-wer merged commit d0554da into master Jul 30, 2018
@daniel-wer daniel-wer deleted the colors-for-mappings branch July 30, 2018 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color for mappings
2 participants