jhiggins Posted August 15, 2005 Share Posted August 15, 2005 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 Quote Link to comment Share on other sites More sharing options...
Wolfwood Posted August 15, 2005 Share Posted August 15, 2005 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? Quote Link to comment Share on other sites More sharing options...
edward Posted August 15, 2005 Share Posted August 15, 2005 You could use CH_Manager::evaluate(). Local variables won't work though. eg. OPgetDirector()->getManager()->evaluate("rand(0)"); Quote Link to comment Share on other sites More sharing options...
jhiggins Posted August 17, 2005 Author Share Posted August 17, 2005 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 Quote Link to comment Share on other sites More sharing options...
edward Posted August 17, 2005 Share Posted August 17, 2005 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. Quote Link to comment Share on other sites More sharing options...
jhiggins Posted October 28, 2005 Author Share Posted October 28, 2005 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. Quote Link to comment Share on other sites More sharing options...
edward Posted October 29, 2005 Share Posted October 29, 2005 As previously mentioned, see SOP_Flatten.C in the HDK examples. Quote Link to comment Share on other sites More sharing options...
jhiggins Posted November 2, 2005 Author Share Posted November 2, 2005 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! Quote Link to comment Share on other sites More sharing options...
edward Posted November 5, 2005 Share Posted November 5, 2005 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(); Quote Link to comment Share on other sites More sharing options...
jhiggins Posted November 8, 2005 Author Share Posted November 8, 2005 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. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted November 8, 2005 Share Posted November 8, 2005 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)? Quote Link to comment Share on other sites More sharing options...
jhiggins Posted November 9, 2005 Author Share Posted November 9, 2005 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. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted November 10, 2005 Share Posted November 10, 2005 I would just go ahead and set up your user parameters then, once you have that pointing your evalFloat functions at them should make it work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.