Jump to content


Is there a way to concatenate parameter tokens in VOPs?


  • Please log in to reply
8 replies to this topic

#1 magneto

magneto

    Grand Master

  • Members
  • PipPipPipPipPip
  • 1,295 posts
  • Joined: 04-October 11
  • Location:Canada
  • Name:Ryan K

Posted 31 May 2012 - 11:55 PM

I have a few parameters in one of my VOPs, and I want to combine their tokens like this:

$parameter1 + $parameter2 + $parameter3

where it could be:

Deform + Surface + Fast =

DeformSurfaceFast

I know I can do this with a single parameter where I can call it as a function, but I am wondering if it's possible to do with multiple parameters to form a function name that exists?


Thanks :)

#2 mantragora

mantragora

    Initiate

  • Members
  • PipPip
  • 229 posts
  • Joined: 08-December 11
  • Location:frozen hell
  • Name:to be, or not to be, TD ?

Posted 01 June 2012 - 05:31 AM

So basically you want to change concatenated tokens into function name just like you can in C# with reflection and dynamic method invocation ? In that case, you can't.

You still seems to think about VEX like if it was dynamic language. It's not. Stick with thinking about everything in it in like if it was "0-1". For dynamic things you have Python. If you need more than python can give you, you can use inlineCPP in it. If it's still not what you are looking for, you got HDK. End of story.

Edited by mantragora, 01 June 2012 - 05:12 PM.

magic happens here... sometimes

Vimeo
Twitter

#3 mantragora

mantragora

    Initiate

  • Members
  • PipPip
  • 229 posts
  • Joined: 08-December 11
  • Location:frozen hell
  • Name:to be, or not to be, TD ?

Posted 01 June 2012 - 07:44 AM

Anyway, if you are looking for simple concatination - not dynamic method invocation , for example - your menus returns strings as tokens, you can just concatinate them like any string with
string text = $menu1 + $menu2 + $menu3;

This will give you "DeformSurfaceFast" and then you can compare this string with if{}else{}whatever{} to call your function based on this.

Edited by mantragora, 01 June 2012 - 05:11 PM.

magic happens here... sometimes

Vimeo
Twitter

#4 magneto

magneto

    Grand Master

  • Members
  • PipPipPipPipPip
  • 1,295 posts
  • Joined: 04-October 11
  • Location:Canada
  • Name:Ryan K

Posted 01 June 2012 - 07:48 AM

Yes that's what I wanted. I thought it might allow that because just using the variable name actually allows you to call a function using its string token. So thought perhaps it would also allow combining them.

Otherwise, I will have to code a large if else statements and call a different function based on the menu choices.

#5 mantragora

mantragora

    Initiate

  • Members
  • PipPip
  • 229 posts
  • Joined: 08-December 11
  • Location:frozen hell
  • Name:to be, or not to be, TD ?

Posted 01 June 2012 - 08:01 AM

Dynamic method invocation is slow. VEX is made to be fast. It was thought as a shading language. You don't have dynamic calls in any other shading languages too. They must throw data from one end to other as fast as they can. All this sugar code is nice, but it is always slow.
magic happens here... sometimes

Vimeo
Twitter

#6 magneto

magneto

    Grand Master

  • Members
  • PipPipPipPipPip
  • 1,295 posts
  • Joined: 04-October 11
  • Location:Canada
  • Name:Ryan K

Posted 01 June 2012 - 09:56 AM

I also wonder if having if statements before the function call would be slow for VEX?

I don't mean inside the function itself but before it's decided which function to call.

Say you have 2 parameters, each have 3 options, so have 9 functions. If inside the VOP you have:

if ($option1 == 0 && $option2 == 0)
	function00();
...
if ($option1 == 2 && $option2 == 2)
	function22();

I wonder if this code is called for each point or only once? I assume only once because options don't change for each iteration.

But actual if statements inside VEX is something I avoid.

Edited by magneto, 01 June 2012 - 09:57 AM.


#7 mantragora

mantragora

    Initiate

  • Members
  • PipPip
  • 229 posts
  • Joined: 08-December 11
  • Location:frozen hell
  • Name:to be, or not to be, TD ?

Posted 01 June 2012 - 10:27 AM

As long as you don't force for each point yourself, it will call it once for all points. That's what SIMD is for.

Edited by mantragora, 02 June 2012 - 04:42 AM.

magic happens here... sometimes

Vimeo
Twitter

#8 magneto

magneto

    Grand Master

  • Members
  • PipPipPipPipPip
  • 1,295 posts
  • Joined: 04-October 11
  • Location:Canada
  • Name:Ryan K

Posted 01 June 2012 - 10:34 AM

Great then, no I don't loop each point manually.

#9 anim

anim

    Houdini Master

  • Members
  • PipPipPipPip
  • 915 posts
  • Joined: 23-August 07
  • Location:Slovakia, Bratislava
  • Name:Tomas Slancik

Posted 08 July 2012 - 05:13 PM

as far as I know functions (as well as all code in VEX) are run once per each point, not once per all points
in VEX (SIMD) they can run parallel, but still per each point, therefore you can have different result for each point

I never had performance problems with if statements within VEX, on the other hand they can speed up a lot, because it can decide for each point what to compute and what not, so I would not fear to use them
Tomas Slancik
Generalist
Slovakia




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users