Skip to content
Snippets Groups Projects
Commit 27158e6b authored by David Gobbi's avatar David Gobbi Committed by Kitware Robot
Browse files

Merge topic 'numpy-int8-signed'


d4701cb4 Add note for int8 to vtkSignedCharArray conversion
78608d54 Remove numpy.character comments from numpy test
5267f004 Convert np.int8 to VTK_SIGNED_CHAR
2cab0baf Decouple numpy_support from pickle_support

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Tested-by: default avatarbuildbot <buildbot@kitware.com>
Reviewed-by: default avatarBen Boeckel <ben.boeckel@kitware.com>
Reviewed-by: default avatarCharles Gueunet <charles.gueunet@kitware.com>
Merge-request: !10623
parents f6473cd6 d4701cb4
No related branches found
No related tags found
No related merge requests found
......@@ -51,10 +51,6 @@ class TestNumpySupport(Testing.vtkTest):
# Test the different types of arrays.
t_z.append(numpy.array([-128, 0, 127], numpy.int8))
# FIXME: character arrays are a problem since there is no
# unique mapping to a VTK data type and back.
#t_z.append(numpy.array([-128, 0, 127], numpy.character))
t_z.append(numpy.array([-32768, 0, 32767], numpy.int16))
t_z.append(numpy.array([-2147483648, 0, 2147483647], numpy.int32))
t_z.append(numpy.array([0, 255], numpy.uint8))
......
......@@ -110,6 +110,9 @@ Changes made since VTK 9.2.0 include the following.
- OSMesa VTK wheels are now provided. These are available on VTK's official
channels (the VTK repository's Python index and `vtk.org`), but not PyPI
because OSMesa conflicts with other OpenGL packages.
- The numpy adapter (`util.numpy_support`) converts `numpy.int8` arrays to
`vtkSignedCharArray` rather than `vtkCharArray`, to ensure that signedness
is preserved by the conversion.
[](#changes-rendering)
### Rendering
......
......@@ -53,7 +53,7 @@ def get_vtk_array_type(numpy_array_type):
numpy.uint16:vtkConstants.VTK_UNSIGNED_SHORT,
numpy.uint32:vtkConstants.VTK_UNSIGNED_INT,
numpy.uint64:vtkConstants.VTK_UNSIGNED_LONG_LONG,
numpy.int8:vtkConstants.VTK_CHAR,
numpy.int8:vtkConstants.VTK_SIGNED_CHAR,
numpy.int16:vtkConstants.VTK_SHORT,
numpy.int32:vtkConstants.VTK_INT,
numpy.int64:vtkConstants.VTK_LONG_LONG,
......
......@@ -16,20 +16,18 @@ example using poly data:
The underlying serialization of the vtkDatObjects is based on the marshaling capabilities
found in vtkCommunicator. Importing this module adds entries for the most common data
objects in the global dispatch table used by pickle. NumPy is required as well since the
serialized data object gets pickled as a numpy array using the vtkmodules.util.numpy_support
module.
-serialized data object gets pickled as a numpy array.
"""
try:
import copyreg, pickle
import copyreg, pickle, numpy
except ImportError:
raise RuntimeError("This module depends on the pickle and copyreg modules. Please make\
sure that it is installed properly.")
raise RuntimeError("This module depends on the pickle, copyreg, and numpy modules.\
Please make sure that it is installed properly.")
from ..vtkParallelCore import vtkCommunicator
from ..vtkCommonCore import vtkCharArray
from .. import vtkCommonDataModel
from . import numpy_support
def unserialize_VTK_data_object(state):
"""Takes a state dictionary with entries:
......@@ -49,8 +47,10 @@ def unserialize_VTK_data_object(state):
DataSetClass = getattr(vtkCommonDataModel, state["Type"])
except:
raise TypeError("Could not find type " + type_string + " in vtkCommonDataModel module")
serialized_data = state["Serialized"]
new_data_object = DataSetClass()
char_array = numpy_support.numpy_to_vtk(state["Serialized"])
char_array = vtkCharArray()
char_array.SetVoidArray(serialized_data, memoryview(serialized_data).nbytes, 1)
if vtkCommunicator.UnMarshalDataObject(char_array, new_data_object) == 0:
raise RuntimeError("Marshaling data object failed")
return new_data_object
......@@ -70,7 +70,9 @@ def serialize_VTK_data_object(data_object):
char_array = vtkCharArray()
if vtkCommunicator.MarshalDataObject(data_object, char_array) == 0:
raise RuntimeError("UnMarshaling data object failed")
return unserialize_VTK_data_object, ({ "Type" : data_object_type, "Serialized" : numpy_support.vtk_to_numpy(char_array) },)
return unserialize_VTK_data_object, (
{ "Type" : data_object_type,
"Serialized" : numpy.frombuffer(char_array, numpy.int8, char_array.GetNumberOfValues()) },)
# Fill in global dispatch table for most vtkDataObject types
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment