sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

colors format in mesh functions #51

Closed nilsbecker closed 5 years ago

nilsbecker commented 6 years ago

this is about the python wrapper - should i file in sciapp/ somewhere instead?

nilsbecker commented 6 years ago

in gr3.drawXXXmesh, the colors must be given as a flattened array of 3-tuples for each mesh component drawn iiuc. why not allow an (N, 3) array? it could be transformed into a flat view trivially?

FlorianRhiem commented 6 years ago

I am not certain that I understand your question correctly. Let's take gr3.drawconemesh for an example:

colors = floatarray(colors)
...
_gr3.gr3_drawconemesh(c_uint(n), positions.data, directions.data, colors.data, radii.data, lengths.data)

The colors, like the other array-like parameters, are converted using the floatarray helper class. For CPython, the following happens:

self.array = numpy.array(a, c_float)
self.data = self.array.ctypes.data_as(POINTER(c_float))

So anything can be used that can also be used to construct a numpy.array of datatype ctypes.c_float. The array shape is ignored, as GR3 only works with a pointer to the array's contiguous memory.

Could you provide an example which causes problems (N, 3) shaped arrays?


And yes, sciapp/python-gr would be the fitting repository as it contains the current code for the GR and GR3 Python wrappers.