Jump to content

How to limit a numeric value by the number of points in the geometry?


Recommended Posts

I have a Python SOP with some parameters where the artist can specify how many points to deform, but that number should not exceed the number of points in the input geometry.

How can I make it so it can't go past that?

Can I type an expression into the Range field in the parameters tab of the operator type properties dialog?

Or is there a command like evalParm to set a value inside the code so I will have to set it myself if it's over a certain number?

Otherwise internally I cap the value, but the UI still shows the entered value which is not what I want.

Thanks :)

Link to comment
Share on other sites

You can't be sure that the number of points on one frame will be the same the next. The param might be valid one frame and invalid the next.

None of the particle POP nodes that worked on point count restrict the value limit. So I think Houdini users understand how your SOP will work.

Link to comment
Share on other sites

Thanks hopbin, I didn't know that.

But what happens if you type in values that are way over the limit?

Say your SOP creates a curve using a subset of points in your point cloud, and you only have 10k points and you type 11k, etc.

If I don't limit the UI values then I should limit the value internally otherwise I will run into out of range exceptions. But this should be fine per frame as I assume Houdini will reevaluate the SOP per frame.

Link to comment
Share on other sites

But what happens if you type in values that are way over the limit?

It's generally considered a good habit to validate user inputs in your code.

http://www.sidefx.com/docs/houdini11.0/hom/pythonsop

raise hou.NodeError("Invalid parameter settings")

Houdini's help is pretty extensive and worth reading.

Edited by rdg
Link to comment
Share on other sites

Thanks that makes sense. I glanced through that page before, but not sure if I should flag error state for invalid value ranges.

The SOP I am writing, it will be common to use the value ladder to see the curve being drawn, but if you go over the limit, I want the tool to "cap" the value.

I feel this is in the same spirit of limiting the values using the operator type properties dialog, say for negative values, instead of raising an error flag for the user.

Link to comment
Share on other sites

Parameter ranges should be fixed. It's often more of a pain to handle dynamic ranges and adds little value to the user experience.

Sure, setting a parameter value to 11k might have undesired results, but the same is true if you set the birth rate to something wrong in a particle system.

@rdg raises a good point. Throwing an exception is a good approach, but you have to decide what the correct behavior is. Should the asset produce a null output upon an invalid parameter, or should it produce something close to the desired result?

If you throw an exception, then it's possible that you'll catch the problem during rendering of a sequence and fix it. If you don't throw an exception, you might not know there was a problem until an entire sequence is finished. Another argument is, you have to restart the sequence if there was an error. So there are two sides to the coin.

Finally, look at the time consumed by such a simple thing. Why is it these things always take up so much brain power?

Link to comment
Share on other sites

Well I am asking how to do it, not why, as I know this is not an exceptional case. In general I only throw an exception when the world I model through code is not what I assumed it to be.

POP approach seems to be in line with how I handle this, as hopbin pointed out, so I will handle it on the code side only.

  • Like 1
Link to comment
Share on other sites

Thanks Graham, Switch SOP behaves just like my SOP. If the value is greater than the number of connections, it uses the last input. The negative values are also prevented via a hard limit on the minimum value.

I will just add a warning, and it will be good.

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...