help with optimization... how to reduce code in VEX?
2431 8 2- Luis Riera
- Member
- 6 posts
- Joined: June 2014
- Offline
Hi, im a new user of Houdini, I was wondering if there is such a thing like Visual Basic:
for i = 1 to 3
push(array, @data&i);
next i
So I can optimize my code if I decide to use a lot of data. Im sorry for the newbie question, but im just learning Houdini, and so far I got my scene to work (A bar graph), but I want to optimize it. This is my vex code:
float array;
push(array, @data1);
push(array, @data2);
push(array, @data3);
f@maxValue = max(array);
@data1 = @data1 / @maxValue;
@data2 = @data2 / @maxValue;
@data3 = @data3 / @maxValue;
thanks.
for i = 1 to 3
push(array, @data&i);
next i
So I can optimize my code if I decide to use a lot of data. Im sorry for the newbie question, but im just learning Houdini, and so far I got my scene to work (A bar graph), but I want to optimize it. This is my vex code:
float array;
push(array, @data1);
push(array, @data2);
push(array, @data3);
f@maxValue = max(array);
@data1 = @data1 / @maxValue;
@data2 = @data2 / @maxValue;
@data3 = @data3 / @maxValue;
thanks.
Edited by Luis Riera - July 30, 2018 16:03:02
- BabaJ
- Member
- 2129 posts
- Joined: Sept. 2015
- Offline
I don't know of a syntax that is ‘simple’ like your Visual Basic example.
I do know a couple ways that use some string work, which would mimic your example, but…
Looking at your screendhot I don't think you need to do what you want the way you have it set up.
You could take advantage of the fact the the wrangle runs over each primitive and each primitive can have different values for the same attribute.
In this case you could simply use @data - and make the distinctions based on prim number.
And before your prim wrangle do your getting a max value in a detail wrangle.
Post your hip and when I'm on latter I will modify it to show you..unless you understand what I'm saying or someone pops in with the ‘equivalent’ syntax.
I do know a couple ways that use some string work, which would mimic your example, but…
Looking at your screendhot I don't think you need to do what you want the way you have it set up.
You could take advantage of the fact the the wrangle runs over each primitive and each primitive can have different values for the same attribute.
In this case you could simply use @data - and make the distinctions based on prim number.
And before your prim wrangle do your getting a max value in a detail wrangle.
Post your hip and when I'm on latter I will modify it to show you..unless you understand what I'm saying or someone pops in with the ‘equivalent’ syntax.
- Luis Riera
- Member
- 6 posts
- Joined: June 2014
- Offline
- BabaJ
- Member
- 2129 posts
- Joined: Sept. 2015
- Offline
Hi Luis,
Ok so I looked at your hip.
Without having seen your original file, it appeared that wanting to fill your array through a loop without having to type out each attribute was your goal.
Usually something like this is very usefull when you have data changing dynamically and/or your not sure how many elements you are going to be dealing with.
But in your set up you are referencing parameters you manually created for the attributes e.g. @data1
So basically you just had to do a bit of extra ‘leg’ work (typing the specific attribute to push into the array) after the creation of the paramter, it's referencing, and promotion as an attribute.
In the context of your setup and the array you create; To me is fine as is, trying to do anything more is just extra uneccessary work(building the array differently).
I'm mean why go through all what your doing and just simply do a channel reference for your distance offset on each extrude? Using a Python expression to get the max values.
Your executing the same code over each prim, although it is multi-threaded…so I really can't guess in this case which is faster; Ref maybe using Python expression.
Ok so I looked at your hip.
Without having seen your original file, it appeared that wanting to fill your array through a loop without having to type out each attribute was your goal.
Usually something like this is very usefull when you have data changing dynamically and/or your not sure how many elements you are going to be dealing with.
But in your set up you are referencing parameters you manually created for the attributes e.g. @data1
So basically you just had to do a bit of extra ‘leg’ work (typing the specific attribute to push into the array) after the creation of the paramter, it's referencing, and promotion as an attribute.
In the context of your setup and the array you create; To me is fine as is, trying to do anything more is just extra uneccessary work(building the array differently).
I'm mean why go through all what your doing and just simply do a channel reference for your distance offset on each extrude? Using a Python expression to get the max values.
Your executing the same code over each prim, although it is multi-threaded…so I really can't guess in this case which is faster; Ref maybe using Python expression.
Edited by BabaJ - July 31, 2018 15:54:13
- Luis Riera
- Member
- 6 posts
- Joined: June 2014
- Offline
I did it, because I dont know another way to do it.. I thought about creating a line, assigning the data to each point on the line and driving the extrude with the result through a copy stamp node, but I didnt knew how to execute that, or if that could work… so I ended up doing everything manually. Anyway.. my next test will be a Pie Chart, then a line graphic chart, and hopefully I'll learn more doing that.
Thanks. Originally I used a Detail wrangle node with a promote attribute to primitives, but it didnt work.
Thanks. Originally I used a Detail wrangle node with a promote attribute to primitives, but it didnt work.
- BabaJ
- Member
- 2129 posts
- Joined: Sept. 2015
- Offline
Well as an excercise for future reference you could do what I changed in your file.
Removed your wrangle that was running over the primitives and replaced it with a detail wrangle to calculate the Max value.
Then in your extrude nodes turned off the distance scale parameters of the local folders and put python in the distance paramter that references the detail node where the @Max attribute was created.
Removed your wrangle that was running over the primitives and replaced it with a detail wrangle to calculate the Max value.
Then in your extrude nodes turned off the distance scale parameters of the local folders and put python in the distance paramter that references the detail node where the @Max attribute was created.
Edited by BabaJ - July 31, 2018 20:38:01
- BabaJ
- Member
- 2129 posts
- Joined: Sept. 2015
- Offline
Just for fun I tried looking into some more python.
In this file, you can now continue to add more ‘data’ parameters to your ‘CONTROL’ node and don't have to do anything to the detail wrangle.
So long as you keeping the data paramter naming convention and not add other parameters to the CONTROL node. ( if you do, the substraction amount in the detail node will have to be updated ).
In this file, you can now continue to add more ‘data’ parameters to your ‘CONTROL’ node and don't have to do anything to the detail wrangle.
So long as you keeping the data paramter naming convention and not add other parameters to the CONTROL node. ( if you do, the substraction amount in the detail node will have to be updated ).
- BabaJ
- Member
- 2129 posts
- Joined: Sept. 2015
- Offline
Or you could remove the detail wrangler altogether and move the equivalent code over to the Python Source Editor - Under the Windows TAB folder upper left in UI.
Then just change the python expression code for each distance parameter of the extrudes to reflect this.
Then just change the python expression code for each distance parameter of the extrudes to reflect this.
Edited by BabaJ - Aug. 1, 2018 09:49:08
- Luis Riera
- Member
- 6 posts
- Joined: June 2014
- Offline
BabaJ
Well as an excercise for future reference you could do what I changed in your file.
Removed your wrangle that was running over the primitives and replaced it with a detail wrangle to calculate the Max value.
Then in your extrude nodes turned off the distance scale parameters of the local folders and put python in the distance paramter that references the detail node where the @Max attribute was created.
this was a very clever solution!
thanks for all the help.
-
- Quick Links