Created by: portnov
Addressed problem description
Lists manipulation, such as "wrap list", "make nesting level deeper", "concatenate lists" and so on, is a very important part of Sverchok. And in complex setups, there can be a dozen of nodes that do just that.
On the other hand, we have restrictions of nesting level of input data in many nodes — for example, a node can usually consume list of lists of vertices, but not list of lists of lists of vertices; and such restrictions are not only because it would be harder to code support for more nesting levels, but also because if you support more nesting level on the input you will most probably have more nesting levels on the output, so the nesting level of the data can grow to infinity while passing through a series of nodes. The user will be just unable to handle such deep data nesting in mind, so there will appear more and more nodes in each tree that just "simplify" data shape.
Solution description
Let's consider the following approach (see also Grasshopper's implementation). Each socket has a drop-down menu with postprocessing options:
- Stage 1. Optionally, one of:
- Flatten - convert any nesting level to level 1, e.g.
[[[1], [2], [3,4]]]
=>[1, 2, 3, 4]
. - Simplify - similar to Flatten, but leave some small nesting. This is actual, for example, for Vertices sockets - you do not want to concatenate coordinates of different vertices into one big list. E.g.,
[[[1,2,3], [4,5,6]], [[7,8,9], [10,11,12]]]
=>[[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]]
.
- Optional stage 2: Graft (the word is taken from GH, I do not find it too intuitive, suggestions are welcome). If enabled, this takes data from the previous stage, with whatever nesting level it had, and adds another nesting level by wrapping each "atomic item" of data into a separate list. For example, for numbers this should do
[[1, 2, 3]]
->[[[1], [2], [3]]]
. For vertices, it should do[[1,2,3], [4,5,6]]
->[[[1,2,3]], [[4,5,6]]]
. So this is similar to List Split node with split length = 1. - Optional stage 3: Wrap. If enabled, take data from previous stage and add another pair of
[]
around.[[1,2,3]]
->[[[1,2,3]]]
. - Optional. Socket class-specific postprocessing options. For example, for Curve and Surface sockets, there will be "Reparametrize" option, to change the domain of each curve/surface from whatever it was to
[0; 1]
.
Not all options have sense for all types of nodes, and in some cases some of options will just do nothing (for example, if the node already outputs list of level 1, then Flatten will do nothing). Set of available options is defined for each socket class, and sometimes socket class refers to node class to decide if the option should be available.
Preflight checklist
Put an x letter in each brackets when you're done this item:
-
Code changes complete. -
Code documentation complete. -
Documentation for users complete (or not required, if user never sees these changes). -
Manual testing done. -
Unit-tests implemented. -
Ready for merge.