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

[Feature] Remove implicit Float default type in vtkDataArray in favor of an explicit Error #3172

Open
sedghi opened this issue Nov 7, 2024 · 7 comments
Assignees
Labels
type: feature request 💡 Desired capabilities / enhancements

Comments

@sedghi
Copy link
Contributor

sedghi commented Nov 7, 2024

Motivation

vtkDataArray implicitly assumes a default data type of Float, which I believe is a mistake.

const DEFAULT_VALUES = {
  dataType: DefaultDataType,
};

While debugging a deep issue in Cornerstone, I discovered my mistake in my code:

const scalarArray = vtkDataArray.newInstance({
  name: 'Pixels',
  numberOfComponents: 1,
  values: [...newPixelData],
});

The data type defaulted to float, which caused problems with rendering floats in labelmap rendering with colors and outlines. Once I defined a typed array correctly, the issue was resolved.

I don't think there are many implicit assumptions elsewhere in vtk. I strongly support explicitly throwing an error or defining a typed array instead of using an array of numbers.

What do you think?

Detailed Description

Above

@sedghi sedghi added the type: feature request 💡 Desired capabilities / enhancements label Nov 7, 2024
@finetjul
Copy link
Member

finetjul commented Nov 8, 2024

(Not only the type was not correct, but in your example you alos made one copy too many...)

Regarding your suggestion, I don't have a preference.

@sedghi
Copy link
Contributor Author

sedghi commented Nov 8, 2024

Copying may or may not be an issue depending on the use case, but the implicit assumption of using Float is somewhat unusual compared to the rest of the vtk.js library. I don't believe we have other instances with default types, at least not in such an important context as vtkDataArray.

@jourdain
Copy link
Collaborator

jourdain commented Nov 8, 2024

VTK use float(32) by default for its points unless stated otherwise. As we only have 1 generic vtkDataArray we picked the same default. Are you saying we should remove the default and through an error if a typed array is not provided?

@sedghi
Copy link
Contributor Author

sedghi commented Nov 8, 2024

Can vtkDataArray represent something other than points, like scalar data for imageData? If so, I think the default float32 might be problematic, causing bugs that could be easily caught by an error if not typed array

@jourdain
Copy link
Collaborator

jourdain commented Nov 8, 2024

We will break a lot of apps out there that are fine to that float conversion. But that could be rolled into a breaking change release.

@floryst what do you think?

@floryst
Copy link
Collaborator

floryst commented Nov 11, 2024

How about logging a console warning about defaulting to Float32Array if Array.isArray(values) and a dataType is not explicitly provided? The docs could also be improved to communicate the defaults when users provide a plain JS array. I agree it would be better to only accept typed arrays so the user can be explicit about the desired data type, but I want to look at alternatives before making this a breaking change.

@sedghi
Copy link
Contributor Author

sedghi commented Nov 11, 2024

Warning is good for now, but maybe in future If you have other changes that might cause many apps to crash, consider bundling this one with them in the same version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request 💡 Desired capabilities / enhancements
Projects
None yet
Development

No branches or pull requests

4 participants