nortikin / sverchok

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

Vectorize Input option in monads/node groups #863

Closed ly29 closed 7 years ago

ly29 commented 8 years ago

skarmavbild 2016-09-06 kl 12 17 08

Since we have many nodes that needs be vectorized and some that can't be easily done without redoing a lot (like 80-90% of nodes). I now introduce a simple option for apply a node group/monad to the input.

This calls the monad on the level 1 input wrapped as separate objects, and the output is extended on the same level not appended and preserving structure.

skarmavbild 2016-09-06 kl 11 15 08 Note that this layout would work if we didn't split the lists as well, but more complex scenarios wouldn't

    def process_split(self):
        monad = self.monad
        in_node = monad.input_node
        out_node = monad.output_node
        ul = make_tree_from_nodes([out_node.name], monad, down=False)

        data_out = [[] for s in self.outputs]

        data = [s.sv_get(deepcopy=False) for s in self.inputs]

        for data in zip(*match_long_repeat(data)):
            for idx, d in enumerate(data):
                in_node.outputs[idx].sv_set([d])
            do_update(ul, monad.nodes)
            for idx, s in enumerate(out_node.inputs[:-1]):
                data_out[idx].extend(s.sv_get(deepcopy=False))

        for idx, socket in enumerate(self.outputs):
            if socket.is_linked:
                socket.sv_set(data_out[idx])
ly29 commented 8 years ago

@enzyme69 I assigned you since I would like your feedback on this.

ly29 commented 8 years ago

The options does need to a better name, @zeffii any idea?

ly29 commented 8 years ago

It works like map basically apply the monad to the input...

ly29 commented 8 years ago

An enumerate version would be nice, but would requires some more changes in the monad code or an special node a bit like frame info. Hmm

zeffii commented 8 years ago

straight up call it vectorize.

ly29 commented 8 years ago

Good call.

Monad Info Node skarmavbild 2016-09-06 kl 11 57 59 Gives two outputs with the total number of loops the monad will do and the current one it is in.

Only appears in menu while editing a monad.

zeffii commented 8 years ago

I suspect there will be scenarios where there's a big speed difference between a node that was vectorized internally by hand (when it was possible to reuse calculations) vs a vectorized monad.

The sooner nodes becomes merely symbolic representations of modular code structures the better.. but that's the fundamental rewrite.

ly29 commented 8 years ago

that's the fundamental rewrite

Exactly. With 180 nodes it is a monumental task, even though a number of nodes probably should/could be dropped. That is without doing the structure for making it possible. Also is more complicated because the nodes are sometime more clever than is good for them.

zeffii commented 8 years ago

well, i won't lie, the thought of that gives me a headache. Even if it's the obvious way forward.

ly29 commented 8 years ago

me too.

But this is a good kind of compromise step, small overhead extending possibilities.

zeffii commented 8 years ago

btw, which node will return a list without consecutive repeats? :)

ly29 commented 8 years ago

in a way this makes things work as they should, the nodes don't know they are being called many times and manipulated into doing things.

ly29 commented 8 years ago

That could kind of be transitional step of doing the deep vectorization without rewriting all the nodes, writing a function calling the node for each input separately at the old standard levels... Okay so this could actually work out with rewriting all nodes... Mind slowly blown...

ly29 commented 8 years ago

btw, which node will return a list without consecutive repeats? :)

No sure I understand this @zeffii

zeffii commented 8 years ago

i'm getting that sense that the more granular a node is, the more appropriate it is to do no vectorization internally at all.

zeffii commented 8 years ago

No sure I understand this @zeffii

its offtopic. was wondering if there's a list node i'm forgetting about, one that returns a list with no consecutive repeats ( preferably also without any dupes) . am writing a scriptnode anyway..

ly29 commented 8 years ago

Like below? No I was thinking about that earlier today as well :)

a = [1, 3, 4, 5, 6, 1, 2, 4, 5, 6]
seen = set()
b = []
for x in a:
    if not x in seen:
        b.append(x)
        seen.add(x)

print(b)

Or like?

a = [1, 1, 2, 3, 1, 2, 2, 2,2 , 3, 3]
prev = a[0]
b = [prev]
for x in a[1:]:
    if not x == prev:
        b.append(x)
    prev = x

print(b)
ly29 commented 8 years ago

A brief example of what was is possible now that didn't work. skarmavbild 2016-09-06 kl 13 19 44 skarmavbild 2016-09-06 kl 13 21 39

zeffii commented 8 years ago

yeah, that's completely nuts :) :+1:

enzyme69 commented 8 years ago

circlesdesign_processing

Watching Ly doing his magic with awe... I like the spikes adaptive poly, complex underneath, simple to use.

So, previously Monad cannot take multiple inputs? confused

All I want to do is to make Array of Array of Circles.

Earlier, I made video live noding and failed to do a simple Seed vectorizing on Circle or on Randomize Vertices...

enzyme69 commented 8 years ago

But then again, I was silly:

screen shot 2016-09-06 at 22 19 27 screen shot 2016-09-06 at 22 17 32 screen shot 2016-09-06 at 22 17 24

It works this way...

Circle > List of Integer > Seed > not vectorizing! List of Integer > Circle > Seed push > vectorizing!

ly29 commented 8 years ago

The monad could take multiple inputs, it was like an ordinary node. But some nodes cannot be properly vectorized, now you can get around that using the monad new vectorize option.

enzyme69 commented 8 years ago

Ok once there is update with this enhanced Monad I will test.

ly29 commented 8 years ago

There is right now. And as bonus bmesh viewer has object out like in #853

enzyme69 commented 8 years ago

screen shot 2016-09-06 at 22 41 57 screen shot 2016-09-06 at 22 35 40

Still not sure if what I am trying to do is possible now or not.

enzyme69 commented 8 years ago

screen shot 2016-09-06 at 23 09 06 I tried your Monad example with multiple objects, it works like magic. Almost like LOOP.

When I check, it does not work right away, I need to update by playing the timeline.

However, still investigating why my array of array does not work. Such simple circle duplications.

ly29 commented 8 years ago

Well it is new some bugs a probably lurking around, the vectorize property needs a small thing.

enzyme69 commented 8 years ago

Wait the minute, I have a feeling I asked this few times before. http://blendersushi.blogspot.com.au/2014/01/sverchok-revisiting-procedural-stacking.html

Kind of like to make array of tower of tower. And Nikitron tried to explain few times....

Maybe I'll find the answer tomorrow morning.

ly29 commented 8 years ago

skarmavbild 2016-09-06 kl 15 42 30

Towers with different seeds and different height, new version. For 0.5.6.1 tower.zip skarmavbild 2016-09-06 kl 15 22 23 skarmavbild 2016-09-06 kl 15 22 52

ly29 commented 8 years ago

If you use matrix it is good idea to apply inside of monad since that is one the things where vectorization fails to behave totally. The list split is needed for now, trying to think about ways around that...

zeffii commented 8 years ago

for all it's potential faults, this does address the simpler needs. Reckon we write a suite of nodes specifically for inside the monad, which are at their core non-vectorized?

ly29 commented 8 years ago

I rather spend my efforts writing total vectorization using these techniques wrapping the nodes and then converting the nodes to the simpler system gradually removing the need for the wrapper. Combined with SN3 and similar syntax for nodes redux would have arrived. Some spring cleaning would be needed of course.

ly29 commented 8 years ago

It is fairly clear to me that the split should be an option in node interface next to vectorize.

enzyme69 commented 8 years ago

Wait the minute, I have a feeling I asked this few times before. http://blendersushi.blogspot.com.au/2014/01/sverchok-revisiting-procedural-stacking.html

Kind of like to make array of tower of tower. And Nikitron tried to explain few times....

Maybe I'll find the answer tomorrow morning.

ly29 commented 8 years ago

There is tower example a bit up in the thread

enzyme69 commented 8 years ago

​Thanks Ly, I will check soon.

I remember: [] > [] > Line can make Lines with different point numbers.

My understanding: Monad in the past is only for organizational, however, it now can do "vectorized", so, if we provide 3 items, it will do "stuff" into that 3 items, kind of like special sverchok looping / unpacking.

The advantage of Sverchok should be more clear, whilst in AN, Object Instancing needs to be provided before the LOOP, in Sverchok we can have loop happening forward?

ly29 commented 8 years ago

skarmavbild 2016-09-07 kl 07 07 27 An more advanced adaptive polygons example.

In Sverchok every node is a loop so to speak, but sometimes – for various reasons, something loop slightly differently, mostly noted with nodes that build complexity, like generators like line, circle etc. This provides a way to force objects to accumulate.

Also now you could make line vectorize the way you would like to...

ly29 commented 8 years ago

skarmavbild 2016-09-07 kl 09 19 03

Split option now present. Working example of "Towers" tower.zip

I am struggling a bit with explaining how this actually works...

zeffii commented 8 years ago

that's the money shot @ly29 :) really cool.

zeffii commented 8 years ago

@enzyme69 essentially the vectorization / split inputs allows you to consider the nodes inside the monad as a single operation, that can handle lists as inputs and perform as if the whole is vectorized.

another term, and possibly better in hindsight, that would have been appropriate is multiplex

image

from the wikipedia page. this almost describes it..

telephony_multiplexer_system

https://en.wikipedia.org/wiki/Multiplexing (ofcourse the technical details are completely different)

ly29 commented 8 years ago

Think of it as if you take the heaviest layout that produces a mesh and wraps up into one node than can be used as any of the standard generators.

enzyme69 commented 8 years ago

I wanted to take advantage of "vectorize" and "split", but got quite confused...

For example, I want to Monad this:

prtscr capture_44

Below, I group stuff, but does not make the result more elegant. prtscr capture_46 prtscr capture_45

Any idea? I will ask the same question at AN Github.

enzyme69 commented 8 years ago

Actually with Sverchok, I think this "vectorization" deals is much more complex but possibly more robust than AN.

With AN, I cannot get my head around this problem:

prtscr capture_48 prtscr capture_47

With Sverchok, I think that's (should be) simpler.

I probably wrote something about it on my blog, but I have to refresh my memory.

Now, with Monad, things should be even simpler, I think.

ly29 commented 8 years ago

Without looking into the specifics put try to a range int as input into the monad with vectorize and split ticked. Also review the tower example.

enzyme69 commented 8 years ago

Still in the process of breaking your tower example. I can see you are using List Split. Pulling my hair, maybe tomorrow I can see more clearly.

ly29 commented 8 years ago

Press upgrade also, some fixes to make things simpler there

ly29 commented 8 years ago

So list split doesn't have to be used.

enzyme69 commented 8 years ago

My guess is vectorization and list split option inside Monad will reduce a bunch of nodes. But still trying to understand those 2 concepts. Will focus on that...

enzyme69 commented 8 years ago

Ok apparently, it's possible using AN, because it has this Line Mesh inside: https://github.com/JacquesLucke/animation_nodes/issues/604

ly29 commented 8 years ago

For using the monad to vectorize think like this, skarmavbild 2016-09-07 kl 22 13 14

  1. Produce the geometry you want with relevant inputs, number of stories for example skarmavbild 2016-09-07 kl 22 14 12
  2. Make it into a monad skarmavbild 2016-09-07 kl 22 14 33
  3. Make variations by plug in say an int range into number of stories (for example) skarmavbild 2016-09-07 kl 22 16 41

Other ideas are also possible, but as a start I think it is a good algorithm