Jump to content

HDK - Iterating vertecies


Recommended Posts

Hi. :) I have a little experiense in pre H12 geometry library, but i completely lost in new GA library. I'm trying to iterate over all vertices of each primitive.... here' is how my code looks like, it compiles fine, but crash, right on display flag set:

.
.
.
GA_ROAttributeRef uv_ref = gdp->findVertexAttribute("uv");
GA_ROHandleV3 uv_h(uv_ref.getAttribute());
if (! uv_h.isInvalid())
   return error();

	const GA_Primitive *prim;
	const GA_PrimitiveList &primList = gdp->getPrimitiveList();
        GA_Range vtx_range;


	for (GA_Iterator pr_it(gdp->getPrimitiveRange()); !pr_it.atEnd(); ++pr_it)
	{
		GA_Offset prim_offset = pr_it.getOffset();
		prim = primList.get(prim_offset);
		vtx_range = prim->getVertexRange();
		for (GA_Iterator vtx_it(vtx_range.begin()); !vtx_it.atEnd(); ++vtx_it)
		{
			GA_Offset vtx_offset = vtx_it.getOffset()
			UT_Vector3 uv(uv_h.get(vtx_offset));
                        // Do something with uv.......

		}


	}
.
.
.

If i remove UT_Vector3 uv(uv_h.get(vtx_offset)), houdini doesn't crash anymore. Can you please tell me where i'm wrong. And is this a right approach for iterating over vertices? Strictly speaking, i need only one vertex from each primitive, how can i get it?

Thx!

Edited by Stalkerx777
Link to comment
Share on other sites

Guest mantragora

I don't like this line. It doesn't have much sense to me.

if (! uv_h.isInvalid())
   return error();

Change it to:

if (uv_h.isInvalid()) return error();

or put the whole code, from this line down, into

if (uv_h.isValid())
{
    // just don't add "error()" here
}

Edited by mantragora
Link to comment
Share on other sites

Thx for notes guys, but what about my main question? Why houdini crash on UT_Vector3 uv(uv_h.get(vtx_offset)). Is it a right way to get uv attribute given the GA_Offset?

I need only vertex 0 from each primitive, can i get him without iterating over all vertices? :unsure:

Link to comment
Share on other sites

Guest mantragora

Thx for notes guys, but what about my main question? Why houdini crash on UT_Vector3 uv(uv_h.get(vtx_offset)). Is it a right way to get uv attribute given the GA_Offset?

I need only vertex 0 from each primitive, can i get him without iterating over all vertices? :unsure:

Have you tried fixing the code ? It works if you change the line I mentioned.

Link to comment
Share on other sites

Have you tried fixing the code ? It works if you change the line I mentioned.

Ohhhh, my mistake! For some reason i wrote ( ! isInvalid ), but it should be (! isValid ) :lol: Thx mantragora, i'll fix it when i get home. Any ideas about how to get only first vertex without iterator?

Link to comment
Share on other sites

Guest mantragora

Something like this should work:

GA_Offset offset = *(prim->getVertexRange().begin());
UT_Vector3 uv(uv_h.get(offset));

cout << offset << "-(" << uv[0] << ", " << uv[1] << ", " << uv[2] << ")" << endl

Edited by mantragora
Link to comment
Share on other sites

Thx mantragora! Everything works fine now. I have one more question.

My SOP is assigning a couple off attributes to primitives. I think it should be possible to cook my sop only once, even if input geometry changes.For example - cached character. Topology doesn't changes, so maybe it's possible to cache it somehow.There is a duplicateChangedSource method, which takes GU_Topology as argument. I can't find any info on how to use this class....

Any ideas guys?

Link to comment
Share on other sites

I think it should be possible to cook my sop only once, even if input geometry changes.

cookMySop() will always be called if it's used input changes. However, your cookMySop() may choose to return cached geometry instead. This is how the Cache SOP works, for example. Personally, I don't recommend doing this yourself because it is relatively hard to do so in a manner in which dependencies work.

Link to comment
Share on other sites

cookMySop() will always be called if it's used input changes. However, your cookMySop() may choose to return cached geometry instead. This is how the Cache SOP works, for example. Personally, I don't recommend doing this yourself because it is relatively hard to do so in a manner in which dependencies work.

Ok, i get it. For now, i'm pretty satisfied with performance i get. I'll try to implement multithreading, it should be more valuable in terms of execution speed. Thx guys for help!

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