Jump to content


HDK - Iterating vertecies


  • Please log in to reply
11 replies to this topic

#1 Stalkerx777

Stalkerx777

    Initiate

  • Members
  • PipPip
  • 147 posts
  • Joined: 09-June 08
  • Location:Russia, Moscow
  • Name:Alex Sadroutdinov

Posted 21 August 2012 - 11:39 AM

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, 22 August 2012 - 04:25 AM.

Posted Image

#2 mantragora

mantragora

    Initiate

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

Posted 21 August 2012 - 02:08 PM

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, 21 August 2012 - 07:33 PM.

magic happens here... sometimes

Vimeo
Twitter

#3 edward

edward

    Grand Master

  • Members
  • PipPipPipPipPip
  • 3,325 posts
  • Joined: 10-September 02
  • Name:e.d.w.a.r.d. .

Posted 21 August 2012 - 02:44 PM

One can also simplify:

GA_ROAttributeRef uv_ref = gdp->findVertexAttribute("uv");
GA_ROHandleV3 uv_h(uv_ref.getAttribute());

to

GA_ROHandleV3 uv_h(gdp, GA_ATTRIB_VERTEX, "uv");


don't panic!

#4 Stalkerx777

Stalkerx777

    Initiate

  • Members
  • PipPip
  • 147 posts
  • Joined: 09-June 08
  • Location:Russia, Moscow
  • Name:Alex Sadroutdinov

Posted 22 August 2012 - 04:24 AM

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:
Posted Image

#5 mantragora

mantragora

    Initiate

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

Posted 22 August 2012 - 04:30 AM

View PostStalkerx777, on 22 August 2012 - 04:24 AM, said:

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.
magic happens here... sometimes

Vimeo
Twitter

#6 Stalkerx777

Stalkerx777

    Initiate

  • Members
  • PipPip
  • 147 posts
  • Joined: 09-June 08
  • Location:Russia, Moscow
  • Name:Alex Sadroutdinov

Posted 22 August 2012 - 06:39 AM

View Postmantragora, on 22 August 2012 - 04:30 AM, said:

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?
Posted Image

#7 mantragora

mantragora

    Initiate

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

Posted 22 August 2012 - 07:31 AM

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, 22 August 2012 - 07:50 AM.

magic happens here... sometimes

Vimeo
Twitter

#8 Stalkerx777

Stalkerx777

    Initiate

  • Members
  • PipPip
  • 147 posts
  • Joined: 09-June 08
  • Location:Russia, Moscow
  • Name:Alex Sadroutdinov

Posted 22 August 2012 - 01:13 PM

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?
Posted Image

#9 mantragora

mantragora

    Initiate

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

Posted 22 August 2012 - 04:50 PM

View PostStalkerx777, on 22 August 2012 - 01:13 PM, said:

I can't find any info on how to use this class....

Maybe because it's not a class but method ? ;)

Anyway, all those examples contains code how to use it SOP/SOP_BrushHairLen.C, SOP/SOP_CustomBrush.C, and SOP/SOP_IKSample.C. duplicateChangedSource
magic happens here... sometimes

Vimeo
Twitter

#10 edward

edward

    Grand Master

  • Members
  • PipPipPipPipPip
  • 3,325 posts
  • Joined: 10-September 02
  • Name:e.d.w.a.r.d. .

Posted 23 August 2012 - 05:31 AM

There's two duplicateChangedSource() methods, don't use the one with GU_Topology. Basically, I wouldn't recommend using GU_Topology at all.
don't panic!

#11 edward

edward

    Grand Master

  • Members
  • PipPipPipPipPip
  • 3,325 posts
  • Joined: 10-September 02
  • Name:e.d.w.a.r.d. .

Posted 23 August 2012 - 05:40 AM

View PostStalkerx777, on 22 August 2012 - 01:13 PM, said:

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.
don't panic!

#12 Stalkerx777

Stalkerx777

    Initiate

  • Members
  • PipPip
  • 147 posts
  • Joined: 09-June 08
  • Location:Russia, Moscow
  • Name:Alex Sadroutdinov

Posted 23 August 2012 - 09:38 AM

View Postedward, on 23 August 2012 - 05:40 AM, said:

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!
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users