Jump to content

Evaluating Expressions From Hdk


Recommended Posts

I was just curious, if anyone knew a way to evaluate an expression from within the hdk.

for instance, if I have a string input parameter on a custom SOP that is "rand(0)" , how would

I evaluate it and use it in my cook method.

thanks,

jeff

Link to comment
Share on other sites

I was just curious, if anyone knew a way to evaluate an expression from within the hdk.

for instance, if I have a string input parameter on a custom SOP that is "rand(0)" , how would

I evaluate it and use it in my cook method.

thanks,

jeff

20540[/snapback]

In OP/OP_Parameters.h there are methods like evalString.

As long as your expression is formated correctly it should evaluate the parameter.

`rand("0")`

If.....you want to pass a actual string to your custom SOP and then evaluate that expression internally....then I think you can use CMD_Manager::execute() to evalute the expression.

Ie:

UT_String foo("echo `");

foo += myExpression;

foo += "`"';

CMD_Manager::execute(foo);

There is probably a better way.......

Ed?

Link to comment
Share on other sites

You could use CH_Manager::evaluate(). Local variables won't work though.

eg. OPgetDirector()->getManager()->evaluate("rand(0)");

20545[/snapback]

thanks... that worked great!!!!!

one problem though, which i expected is that when i call rand(0) and a set of points, all the random values are exactly the same, b/c the seed is the same.

Is there a good way to either expose the $PT variable.

I can just override "$PT" by replacing it with whatever i want, but it seems wrong to do it this way.

thanks

jeff higgins

Link to comment
Share on other sites

Where are you calling this? If you're within the cook codepath of a SOP, then you could try:

evaluate(my_expr, current_time, getChannels()).

This is all assuming that you've already set up use of local variables of course. See the SOP_Flatten.C in the HDK examples.

Link to comment
Share on other sites

  • 2 months later...
You could use CH_Manager::evaluate(). Local variables won't work though.

eg. OPgetDirector()->getManager()->evaluate("rand(0)");

20545[/snapback]

revisting this after a while, I wouldn't mind being able to get local variables working.

would you know how to get this working.

The CH_Collection* local on the evaluate method looks like what i should be using, but

so far my attempts have been fruitless.

Link to comment
Share on other sites

i was looking at an older SOP_Flatten.C (ala v7), i still seem to be having a problem.

maybe i can explain more, because maybe local variables isn't really what i want.

i want a custom sop the will assign attributes based on an expression using other variables.

I will need to do more with them after this is established, which will require the use of the HDK.

so if in my network i have three point attribs X, Y, Z with (local variables $X, $Y, $Z), then I want to be able to have in my custom op set Z to an expression like sqrt($X*$X+$Y*$Y).

So my custom sop will have to iterate over all of the points and evaluate the string "sqrt($X*$X+$Y*$Y)".

I was thinking evalFloat would be what i need, but it doesn't seem to be working for me!

Thanks!

Link to comment
Share on other sites

evalFloat() should work provided you've setup the use of variables correctly. Here's the relevant code portions from SOP_Flatten.C.

eg. you need to do this first:

setVariableOrder(3, 2, 0, 1);
myCurGdp[0] = gdp;
setupLocalVars();

Then you need to do this for each point prior to calling evalFloat():

myCurPt[0] = ppt;

And finally, clean up when done:

resetLocalVarRefs();

Link to comment
Share on other sites

evalFloat() should work provided you've setup the use of variables correctly. Here's the relevant code portions from SOP_Flatten.C.

eg. you need to do this first:

setVariableOrder(3, 2, 0, 1);
myCurGdp[0] = gdp;
setupLocalVars();

Then you need to do this for each point prior to calling evalFloat():

myCurPt[0] = ppt;

And finally, clean up when done:

resetLocalVarRefs();

22409[/snapback]

using the follow in my cook method:

UT_String a = "$PT";

UT_String b = "rand($PT)";

setVariableOrder(3, 2, 0, 1);

myCurGdp[0] = gdp;

setupLocalVars();

GEO_Point* ppt;

FOR_ALL_GPOINTS(gdp, ppt)

{

myCurPt[0] = ppt;

cout << evalFloat( a, 0, context.myTime ) << " --> "

<< evalFloat( b, 0, context.myTime ) << endl;

}

resetLocalVarRefs();

but i would get the following error for every point in my grid

evalFloat: Invalid parameter name $PT

0 --> core_berkleydb1 evalFloat: Invalid parameter name rand($PT)

j.h.

Link to comment
Share on other sites

Surely thats because you are passing an "actual"  expression as a string rather than the name of a parameter which the user may have typed a parameter string into.

Are you doing this just to test the result or because you want to always evaluate rand($PT)?

22470[/snapback]

i'm doing this to test the result. I want to the user to be able to enter any valid expression as a string,

and then in my custom node i want to be able evaluate it for every point.

ideally i would have 2 such expressions (key, value) which would store values to a berkleydb.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...