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

NRRDLoader: Fix loading 16-bits file with custom axes. #25367

Merged
merged 3 commits into from
Jan 31, 2023

Conversation

LinkunGao
Copy link
Contributor

@LinkunGao LinkunGao commented Jan 30, 2023

Related issue: #24501

Description

The key issue for this issue is that some 16-bit NRRD files do have not standard vectors.
So using the old if judgment statement cannot get a good result for loading them.

issue code:

const xIndex = headerObject.vectors.findIndex((vector) => vector[0] !== 0);
const yIndex = headerObject.vectors.findIndex((vector) => vector[1] !== 0);
const zIndex = headerObject.vectors.findIndex((vector) => vector[2] !== 0);

The 16-bit NRRD files vectors are like this below:

const vectors = [
  [0.803031719442651, -1.6481526752133598e-10, 0.02944583724545901],
  [1.647045751213251e-10, 0.80357140302658, 6.039481950867172e-12],
  [-0.04030796800931726, -5.359717066245572e-17, 1.0992581595808804],
];

Thus under this if statement, it will always get xIndex=yIndex=zIndex=0
Then for the axis array we always get only direction ["z"]. Not the ["x","y","z"].

So I add a new if statement inside this if to solve this issue:

let axisOrder = [];
if (xIndex !== yIndex && xIndex !== zIndex && yIndex !== zIndex) {
	axisOrder[xIndex] = "x";
	axisOrder[yIndex] = "y";
	axisOrder[zIndex] = "z";
} else {
	axisOrder = ["x", "y", "z"];
}

Instead

let axisOrder = [];
axisOrder[xIndex] = "x";
axisOrder[yIndex] = "y";
axisOrder[zIndex] = "z";

Then, as for the segmentation purpose, I also add a setSegementation() function.

        /**
	 *
	 * @param {boolean} segmentation is a option for user to choose
	 */
	setSegmentation(segmentation) {
		this.segmentation = segmentation;
	}

       ...

      if (!headerObject.vectors || this.segmentation) {
          volume.matrix.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
      }

If the user use loader.setSegementation(true) outside, we can get the NRRD Original size slices/images, not the RASDimention one size.

  • Reset the code format

@Mugen87 Mugen87 changed the title fixed load 16-bits NRRD file with aixs cannot find issue NRRDLoader: Fixed load 16-bits file with custom axes. Jan 30, 2023
@Mugen87 Mugen87 changed the title NRRDLoader: Fixed load 16-bits file with custom axes. NRRDLoader: Fix loading 16-bits file with custom axes. Jan 30, 2023
@Mugen87 Mugen87 added this to the r150 milestone Jan 30, 2023
@mrdoob mrdoob merged commit f24db3d into mrdoob:dev Jan 31, 2023
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.

None yet

3 participants