nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.23k stars 232 forks source link

Sverchok data structure #2761

Open Durman opened 4 years ago

Durman commented 4 years ago

Sverchok has fixed data structure:

[object 1, object 2, ..., object N]

Possible type of objects:

Possible type of values in list:

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?

Durman commented 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?

portnov commented 4 years ago

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.

ly29 commented 4 years ago

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]
nortikin commented 4 years ago

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]]

Durman commented 4 years ago

View to data structure from point of view normal socket and dictionary socket: socket_data dict_data

Durman commented 4 years ago

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.

zeffii commented 4 years ago

yep. https://github.com/nortikin/sverchok/issues/882 (2016) https://github.com/nortikin/sverchok/issues/688#issuecomment-111143209 (2015)

Durman commented 4 years ago

I'm talking about not only how to keep data but also how efficiently to manipulate with it.

nortikin commented 4 years ago

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.

Durman commented 2 years ago

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).