[Question/Issue] Draw_editor example with segmentationLUT/Freesurfer
See original GitHub issueHello!
I have a question/issue regarding how to access and modify the raw data content of a stack. Particularly, my scene is data + a freesurfer labelmap generated with the segmentationLUT, which can be seen on this live fiddle.
What I want to do is to modify the contents of the stack (as a drawing tool would do, for instance). To do so in the most basic way, I access the contents of the stack2 after the stack2.pack() line and try to change some values. For instance the segmentation label 7 (voxel value present on the stack).
stack2.prepare();
// pixels packing for the fragment shaders now happens there
stack2.pack();
for(let i = 0; i < stack2._rawData[0].length; i++){
if(stack2._rawData[0][i] != 7) stack2._rawData[0][i] = 0;
}
var textures2 = [];
When I do this everything turns to 0 (transparent), except the 7 label, which works as intended. HOWEVER, when trying to do other things such as:
for(let i = 0; i < stack2._rawData[0].length; i++){
stack2._rawData[0][i] = 7;
}
var textures2 = [];
which should turn the entire stack to one color (the one of the segmentation label number 7) or
for(let i = 0; i < stack2._rawData[0].length; i++){
if(stack2._rawData[0][i] == 0) stack2._rawData[0][i] = 6;
}
var textures2 = [];
Which should turn everything transparent to color label number 6 for instance, etc. etc. it is not working, everything turns transparent as the labelmap is not applied. The stack values are changed though, what can be the issue there? can it be due to the pixel packing, the shader, the model stack…? Which would be the best way to modify the contents of the stack/texture?
Cheers,
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
so therewere a couple of issues:
1- the voxel increment is 4 because we are in 32 bits:
2- get the old value:
And that should be it.
Finally, I think
context.getImageData
should be moved out of the crazy i/j/k for loops: -> Get all image data into an array at the very beginning ofmapCanvasToData
. -> access the right index from array instead oflet pixel = <get right index>
._rawData
is the data to be passed to the shaders, encoded in8 bits
.The data you are looking is encoded in 32 bits (
stack2.bitsAllocated
). In order to directly update the “packed” _rawData, you’d have to do something like:That is a shortcut not to have to run “pack()” another time as it is expensive.
Depending on the format of the data you want to update, you would have to adjust the approach: https://github.com/FNNDSC/ami/blob/dev/src/models/models.stack.js#L523
http://jsfiddle.net/2f4bL2w3/19/
For reference, I’ve been doing something similar in the past but somehow it seems very slow now: https://fnndsc.github.io/ami/#editor_draw
(was much faster before 😕)
Please re-open in needed -