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

Data type casting between integer and floating point types #5

Open
moritz-h opened this issue Jun 10, 2021 · 0 comments
Open

Data type casting between integer and floating point types #5

moritz-h opened this issue Jun 10, 2021 · 0 comments

Comments

@moritz-h
Copy link
Member

I think it should be possible to cast between integer and floating point types in tpf_data, but I'm not 100% sure if this simply can be changes without side effects.

The problem is, that the ParaView plugin cannot read grids with grid coordinates stored as integers.

The point type is i.e. hardcoded here as floating point type:

const auto vof = tpf::vtk::get_grid<float_t, float_t, 3, 1>(in_grid, tpf::data::topology_t::CELL_DATA, this->GetInputArrayToProcess(0, in_grid));

The grid coordinates are extracted here:

node_coordinates.push_back(get_data<point_t, vtkFloatArray>(grid->GetXCoordinates(), std::string("X coordinates")));

So basically the array is read and should be casted to point_t. (side note: i think vtkFloatArray should be changed to vtk_array<point_t>::type)

And finally the dynamic casting happens here:

if (std::is_floating_point<value_t>::value)
{
// Try double and float
switch (data->GetDataType())
{
case VTK_FLOAT:
warn_mismatch<value_t, float>(array_name);
return get_data<value_t, typename vtk_array<float>::type, false>(data, array_name);
case VTK_DOUBLE:
warn_mismatch<value_t, double>(array_name);
return get_data<value_t, typename vtk_array<double>::type, false>(data, array_name);
}
}
else if (std::is_integral<value_t>::value && std::is_signed<value_t>::value)

The problem is when point_t is floating point, the array is expected to contain float or double values. But I think it should also cast any integer array type to point_t. In general casting int to float should not be worse than casting double to float. Warnings about the precision lost are thrown anyway.
But this is only the perspective from the grid coordinates array, this function probably is also used for data arrays in general and I don't know if casting is then wanted in all cases.

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

No branches or pull requests

1 participant