ICE array cumulative sum

204 views
Skip to first unread message

Mathieu Leclaire

unread,
Nov 11, 2011, 12:46:07 PM11/11/11
to soft...@listproc.autodesk.com
Hi guys,

I can't figure out a way to do this without using a loop. I have an
array of scalars (ex: 0.1, 0.2, 0.1, 0.4...) and I would like to convert
it to an array of cumulative summations (like this: 0.1, 0.3, 0.4,
0.8...) but this array can not be generated by a loop. It must remain
free of any execute port. Does anybody know how I could do that?

-Mathieu

Bradley Gabe

unread,
Nov 11, 2011, 12:53:09 PM11/11/11
to soft...@listproc.autodesk.com
Start with your source array, and create a new array from it.

Using the Sub Incides values from your source array, you can probably use a combination of the [Select SubArray in Array] compound feeding into a [Get Array Sum] node to build your new Array.

Sorry, don't have time to test this, but I'm almost certain I have done before what you are trying to do, so it should be possible.

Mathieu Leclaire

unread,
Nov 11, 2011, 12:59:31 PM11/11/11
to soft...@listproc.autodesk.com
That's what I initially tried. Select SubArray in Array can not accept an array as an input for the End Index.

Sam Cuttriss

unread,
Nov 11, 2011, 1:06:51 PM11/11/11
to soft...@listproc.autodesk.com
i have tried the same, there was a discussion on the list. ("simply stepping through ice arrays")
here is stephen blairs tinkering on the xsisuppport blog.


i think many loops and counters could be avoided if more of the core nodes accepted arrays.
ie: i often want to test an array of values with "find in array", hoping for an array of boolean results.
i guess without native support for 2d arrays this becomes messy.

Mathieu Leclaire

unread,
Nov 11, 2011, 1:20:24 PM11/11/11
to soft...@listproc.autodesk.com
Again, the problem here is that it as to use a loop (repeat or while) connected to an execute port... I can not have any such procedure. It has to become a compound that takes the array as an input and outputs the cumulative sum as an output without any execution node. I'm looking into programming myself a custom node to do this, but I was looking to see if there already was an alternative way to do this directly in ICE without using loops.

Sam Cuttriss

unread,
Nov 11, 2011, 1:25:49 PM11/11/11
to soft...@listproc.autodesk.com
I agree %100
these need to be achievable without loops, counters, extra execute or set/ get data nodes.
if many of the core nodes were made slightly more polymorphic (to accept arrays and return arrays) we could be far more efficient.

Christian Gotzinger

unread,
Nov 11, 2011, 1:52:29 PM11/11/11
to soft...@listproc.autodesk.com
Do you happen to be working on a point cloud?
Particles can be misused to do stuff like this in parallel.

See attached screenshot.
array-sum.jpg

Mathieu Leclaire

unread,
Nov 11, 2011, 2:00:58 PM11/11/11
to soft...@listproc.autodesk.com
You are creating one value per particle and then converting them to a global array. I need to calculate the sums per particle array... each particle will have a different array.

-Mathieu

Christian Gotzinger wrote:



Sam Cuttriss

unread,
Nov 11, 2011, 2:02:33 PM11/11/11
to soft...@listproc.autodesk.com
particle abuse, i like it!!!

Christian Gotzinger

unread,
Nov 11, 2011, 2:50:29 PM11/11/11
to soft...@listproc.autodesk.com
Here's a version that calculates an array per point. However, you need additional particles that don't carry arrays. In my example, I use three particles, each with an array. They contain a total of 3+2+2=7 entries. So I need 7 particles to do the calculation, only 3 of which carry actual arrays. I hope that made sense.

See the screenshot.
per-point-cumulative.jpg

Mathieu Leclaire

unread,
Nov 11, 2011, 4:36:51 PM11/11/11
to soft...@listproc.autodesk.com
Oh... thank you. I'm not sure I fully understand what you are doing and I will come back to it later to fully wrap my head around it. In the end, I've compiled myself a custom ICE node that does exactly what I needed. It is easier that way and it'll probably be much faster to evaluate as well. Thank you very much for all your suggestions.

Cheers,
-Mathieu

Christian Gotzinger wrote:



Helge Mathee

unread,
Nov 13, 2011, 1:56:16 PM11/13/11
to soft...@listproc.autodesk.com
It is totally easy to build a set of custom nodes to do this. The overhead is absolutely minimal with the ICE SDK. Could be accumulative Add and Multiply, Polymorphic to support all math-able types as arrays. Beer-ware, anybody?

Christian Gotzinger

unread,
Nov 13, 2011, 5:12:08 PM11/13/11
to soft...@listproc.autodesk.com
Not for all of us I'm afraid.
I believe there is no built-in way to do per-element loops? As bad as using Repeat may be, but it doesn't even work per point or per polygon.

Guillaume Laforge

unread,
Nov 13, 2011, 8:44:36 PM11/13/11
to soft...@listproc.autodesk.com
> Not for all of us I'm afraid.

But Helge suggestion would be a very good excuse for you to learn how to build a custom ICE node ;)
It is not so complicated... once you've done one.

Alok Gandhi

unread,
Nov 13, 2011, 9:23:23 PM11/13/11
to soft...@listproc.autodesk.com
"It is not so complicated... once you've done one."

And just to prove Guillaume's point, here is one that I built, exactly doing what Mathieu wanted at the start this thread (as he said he already wrote one).

It took me about 10 minutes, (the SDK wizards generate the base code so nicely). Of course, it goes without saying, you need some c++ knowledge, a little ICE API, and have the right compilers.

This nodes takes in a float array per point, adds array values cumulatively and output the new array. Sincerest apologies if you do not like the color of the node ; also 'fibonacci' is not a proper name for this one, as it is for natural numbers but the logic is remarkably same, so I borrowed that name.

Compiled for 64 bit, it only takes in floats and per point context but can be extended for polymorphism. If anybody is looking for some source code for writing polymorphic ICE node dealing with arrays, a good example can be found here.

Cheers !!
fibonacci.dll

Christian Gotzinger

unread,
Nov 14, 2011, 6:28:39 AM11/14/11
to soft...@listproc.autodesk.com
You know, I will actually try that this week.
I already know some C++, and I'm usually good at figuring things out by looking at examples. But I'm a bit unsure where to start.

Alok mentioned the need of the right compilers. Do I have to buy one or will this work (I need 64 bit):
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

I'm also unsure about the workflow: How do you test your code as you work on it? Is there some kind of learning resource for this available? I don't need anything super detailed, just a nudge in the right direction.

Nic Groot Bluemink

unread,
Nov 14, 2011, 6:46:53 AM11/14/11
to soft...@listproc.autodesk.com
Hey Christian,

You can use the Express editions, but they need a bit of fiddling to work with 64bit.
This worked for 2008 for me - http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/
The softimage wiki has further suggestions for 2010, I haven't tried that yet - http://softimage.wiki.softimage.com/index.php/Cpp_64_bit_Visual_CPP_Express(XSISDK)

-Nic
--
Technical Pretty Picture Making Person
Kettle

Alok Gandhi

unread,
Nov 14, 2011, 7:41:41 AM11/14/11
to soft...@listproc.autodesk.com
Hi Christian, 

The testing/debugging workflow is pretty straightforward, compile - test. Most errors- syntatic, std exceptions, missing includes will be thrown during compile/build time. If the compilation goes through then test node in an ICE graph. 

Just remember, your node my connect well but still would not work, in case of semantic errors. So be sure to stress test them by forcing them to evaluate, like show values or use them with some non-trivial data like point position etc.


There are a bunch of cutom ice node examples in the SDK, you can defenitely start there. 

Nic has already covered the compilers part well. 

Good luck !!

Sent from my iPhone

Christian Gotzinger

unread,
Nov 14, 2011, 7:58:40 AM11/14/11
to soft...@listproc.autodesk.com
Thank you both!
I will get the Visual Studio set up and dig myself into examples and documentation. Will report back...

Guillaume Laforge

unread,
Nov 14, 2011, 9:15:29 AM11/14/11
to soft...@listproc.autodesk.com
Cool :)

Now, you could add support for all numerical inputs ;).
It is a little bit more complicated as you will need to use some templates in the evaluate callback. You can find an example in the SDK (in the custom Pass Through node I think).

Cheers,
Guillaume

Alok Gandhi

unread,
Nov 14, 2011, 9:42:30 AM11/14/11
to soft...@listproc.autodesk.com
Yep using template classes, and it is also there is the in the link I posted before.
Reply all
Reply to author
Forward
0 new messages