Open Durman opened 4 years ago
Also we could discuss adding numpy arrays to Sverchok layout.
We already has nodes which can generates one and two dimensional arrays (number range
and vector math
nodes). The question is how we are going to deal with edges and faces data?
There is no problem in converting edges data to two dimensional array of numpy but it not as easy with faces. They can be presented in numpy either like this [array(i1, i2, ..., in), array(i1, i2, .., in), ...]
or like this array(list(i1, i2, .., in), list(i1, i2, .., in)
. (I'm not very familiar with numpy, probably there is other ways.) Neither of them can gain benefits from numpy data structure.
Probably we should not convert edges and faces into numpy arrays?
I do not see reasons to convert edges / faces to numpy data. Numpy is good for numeric manipulations — for example, multiply all vectors by 2 to scale the box. But there is usually no reason to multiply all indices in edge/face data... Usually we do not do anything with that indices at all, we just add or remove some edges/faces.
It is easy enough to represent edges and faces as np data. See here for some simple examples: https://github.com/Sverchok/Sverchok/blob/master/util/smesh.py
If it is worth it is another issue.
If the original had been working only with one object it would have been easier to generalize.
- 2 Triangle faces and polygon face
[[0, 1, 2], [0, 1, 4 ,3]]
- one list of index and one of index data
[0 1 2 0 1 4 3]
[0 3]
[3 4]
there was no goal. we have done the best what we can with Nedovizin @Cfyzzz but maybe it is fast to achive and lets you create non-regular lists [[1,2,3],[1,2]]
View to data structure from point of view normal socket and dictionary socket:
It looks like I have found how faces should be represented in numpy:
sv_faces = [[0, 1, 2], [3, 4, 5, 6, 7], [8, 9, 10, 11]]
Numpy faces:
loops = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
slices = np.array([0, 3, 8])
For example there is need of converting vertex selecting mask to face selecting mask:
selected_vertex = [0, 1, 2, 8, 9]
selected_loops = np.isin(loops, selected_vertex, True)
selected_faces = np.logical_and.reduceat(selected_loops, slices) # np.array(True, False, False)
This approach is 5-6 times faster then python implementation, with mesh of 1 000 000 points and 100 000 selected points.
I'm talking about not only how to keep data but also how efficiently to manipulate with it.
I'm talking about not only how to keep data but also how efficiently to manipulate with it.
it is all included by any of ways.
I found new Python library - awkward array. It can create arrays with nested arrays of different length. Such arrays can be handled by NumPy and Numba libraries. But also it has some limitations so it requires a prototype to determine whether we can rely on it. Potentially it can improve performance of handling polygons and objects (vectorization).
Sverchok has fixed data structure:
[object 1, object 2, ..., object N]
Possible type of objects:
Possible type of values in list:
[0, 1, .., n]
[(0, 1), (1, 2), .., (i, ii)]
[(0, 0, 0), (1, 0, 0), .., (i, ii, iii)]
[(0, 1, .., n), (10, 11, .., n), .., (i, ii, .., n)]
In most cases I think only one object is used by most users. My understanding of availability of objects in Sverchok is that they help to repeat the same process many times with different set of input data.
I would like to ask the question: @zeffii @nortikin @ly29 What was initial goal of having such data structure with multiple objects?