Skip to content

Tomo slice viewer#109

Draft
tomkane-dls wants to merge 30 commits into
mainfrom
tomo-slice-viewer
Draft

Tomo slice viewer#109
tomkane-dls wants to merge 30 commits into
mainfrom
tomo-slice-viewer

Conversation

@tomkane-dls

Copy link
Copy Markdown
Contributor

No description provided.

@tomkane-dls

Copy link
Copy Markdown
Contributor Author

I am having some trouble running a local version of visr at the moment, so i will have to see how it actually looks on Monday, but in the meantime i had a look through the code. The main problem with how its implemented is that we are creating so many new objects every time the slider is used, which is something that will be very costly. With our Volume it would likely not seem to make any difference, but it could do with larger arrays, and it will be much tidier to avoid this in general.

This is creating new arrays for every row, every time the slider hits a new value

for (let row = 0; row < volumeShape[1]; row++) {
        const line: number[] = [];

and also the arrays are dynamically sized (they grow every iteration) which is a similar cost

array.push(volumeData[index]);

I think its very helpful to understand the maths underneath so probably better to have done it manually first - but i had a look and actually the problem is solved much more simply than we thought. We don't have to worry about manually striding the data, we can use ndarray to create a volume (i think we should add this to tomography view - I will take another look at the 3D viewer to see if we can simplify that by just passing the volume as well), and then use ndarrays internal logic to do the exact same thing your code is doing but without creating any new objects

const volume = ndarray(volumeData, volumeShape);

and then select a slice with something like

switch(plane)
  case x
    const slice = volume.pick(sliceIndex, null, null);
  case y
  ...

or even:

const slice = volume.pick(
  axis === 0 ? sliceIndex : null,
  ...
);

@tomkane-dls tomkane-dls requested a review from Abigail-Yates July 3, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants