Jump to content

Accessings the points of a primitive


Recommended Posts

Hello!

I'm having some trouble accessing the points in a primitive. Here's what I have:


GEO_Primitive *prim;

GA_FOR_ALL_PRIMITIVES(gdp, prim)
{
GA_Range myRange = prim->getPointRange();
const GA_RangeTypeInterface *gwRTI = myRange.getRTI();
}
[/CODE]

So I'm looping through all the primitives in my gdp, and for each primitive, I would like to access the points per primitive to modify attribute data. However, this is about as far as I got. I also experimented with the GA_Iterator but that got nowhere. Would love some advice on this.

Thanks!

PS: What I want to do is, for each primitive, assign increasing ID values per point, each primitive's point ID always starts from 0.

Link to comment
Share on other sites

You can do something like this:

GEO_Primitive *prim;
GA_Range		 pt_range;
GA_Offset			 ptOff;

GA_FOR_ALL_PRIMITIVES(gdp, prim)
{
    pt_range = prim->getPointRange();
    for (GA_Iterator pt_it(pt_range); !pt_it.atEnd(); ++pt_it)
    {
		 ptOff = *pt_it;
		 // do something else
    }
}

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

UPDATE! Sorry guys, i should search forum a little bit better. Here is a graham post with code example, that answer all my questions ! Thx graham.

Hi guys. Here's the deal ))

I need to get prims referencing point and do some stuff with them. Here is my code:


// Inside point iterator....
GA_OffsetArray primsOffsets;
gdp->getPrimitivesReferencingPoint(primsOffsets, ptoffset);
GA_OffsetArray::const_iterator it;
primsOffsets.begin();
do
{
GA_Offset primoff = it.item();
std::cout << primoff << std::endl;
it.advance();
}
while(!it.atEnd());
[/CODE]

Unfortunately it crashing houdini. Code with do...while i found in documentation, but there was another type of iterator, i thought it may fit my needs. When i iterate over GA_OffsetArray with classic for loop, everything is ok. I use GA_Iterators for all my geometry iteration stuff, but i cant get it to work with UT_Iterator. I think it should be initialized somehow with GA_Range, but how do i know that range?

In UT_Iterator class documentation there is a note:

[CODE]
for(CONTAINER::Iterator it=p.iterator(); it.get(s); ) {
// do stuff
[/CODE]

What is [b]p[/b] and [b]s[/b]? Anyway, please show me an example with UT_Iterator.

[color=#800000]And one more important question![/color]

[color=#800000]When i call [/color]getPrimitivesReferencingPoint(), i get array of GA_Offsets for prims. As i know GA_Offset != primitive number. For prim number i need GA_Index, right?

Currently i get it this way:

[CODE]
GEO_Primitive *prim = gdp->getGEOPrimitive(primOffset);
GA_Index primIndex = prim->getMapIndex();
[/CODE]

Is it ok? Maybe there is a better/faster way to get primitive number from GA_Offset?

Waiting for your help guys!

Edited by Stalkerx777
Link to comment
Share on other sites

Guest mantragora

Instead of looking for some fancy named iterators in documentation, use the one built-in into GA_OffsetArray with auto, if you are on a compiler that supports C++11.

Example:

auto POINT = 25;
GA_OffsetArray prims;

for(GA_Iterator pointIt(gdp-&gt;getPointRange()); !pointIt.atEnd(); pointIt.advance())
{
   auto report = "Point num: " + std::to_string(POINT) +" is referenced by: ";
   gdp-&gt;getPrimitivesReferencingPoint(prims, POINT);

   for (auto i = prims.begin(); i != prims.end(); ++i)
   {
    auto pNum = gdp-&gt;primitiveIndex(*i);
    report += std::to_string(pNum) + ", ";
   }
   std::cout &lt;&lt; report &lt;&lt; std::endl;
}

Without auto, iterator for GA_OffsetArray will look like this:

for (UT_Array&lt;exint&gt;::iteratorT&lt;true&gt; i = prims.begin(); i != prims.end(); ++i)

TO ADMINS: Formatting in

 tag SUCKS!
Edited by mantragora
Link to comment
Share on other sites

Without auto, iterator for GA_OffsetArray will look like this:

for (UT_Array&lt;exint&gt;::iteratorT&lt;true&gt; i = prims.begin(); i != prims.end(); ++i)

Isn't it easier/cleaner to just use the typedef defined GA_Offset::const_iterator?

for (GA_Offset::const_iterator it=prims.begin(); !it.atEnd(); ++it)

Unfortunately it crashing houdini. Code with do...while i found in documentation, but there was another type of iterator, i thought it may fit my needs.

Looking at the code, I'm pretty sure it is crashing because you don't actually assign your iterator to the start of the offset array. It is basically uninitialized and when you try to get an offset from it there's no guarantee whatever it tries to give you back on the first iteration is a valid primitive offset. What documentation did you find that example in?

Link to comment
Share on other sites

Guest mantragora

Isn't it easier/cleaner to just use the typedef defined GA_Offset::const_iterator?

I prefer auto right now, that's why I don't have to even bother with writing

for (UT_Array&lt;exint&gt;::iteratorT&lt;true&gt; i = prims.begin(); i != prims.end(); ++i)

or

for (GA_Offset::const_iterator it = prims.begin(); !it.atEnd(); ++it)

just

for (auto i = prims.begin(); i != prims.end(); ++i)

or

for (auto i = prims.begin(); !i.atEnd(); ++i)    

or if I go down to the bottom and slim it even more, just

for (auto i : prims)

with a help of C++11. Now that's what I would call "easier/cleaner" :)

Thanks to this I don't have to chase names that I don't remember in documentation... and your way was already mentioned, so I figured I will show something else ;)

Edited by mantragora
Link to comment
Share on other sites

Looking at the code, I'm pretty sure it is crashing because you don't actually assign your iterator to the start of the offset array. It is basically uninitialized and when you try to get an offset from it there's no guarantee whatever it tries to give you back on the first iteration is a valid primitive offset. What documentation did you find that example in?

This example code is in Geometry Introduction section of documentation....


GU_Detail gdp;
GU_PrimParticle *partsys;
float one = 1;
if (partsys = GU_PrimParticle::build(&gdp, 4))
{
GA_Primitive::const_iterator it;
partsys->beginVertex(it);
do
{
// Initially all particles spring from (3,1,1):
gdp->setPos3(it.getPointOffset(), 3, 1, 1);
it.advance();
}
while (!it.atEnd());
partsys->getRenderAttribs().setType(GEO_PARTICLE_TUBES);
partsys->getRenderAttribs().setMotionblur(1)
partsys->getRenderAttribs().setBlurTime(0.03);
partsys->getRenderAttribs().setSize(0.05);
}
[/CODE]

To [b]mantragora:[/b]

Yes, auto keyword is pretty nice. I'm on debian 6 with gcc 4.6. No c++11 candies i think. :) BTW, according to this link, auto , was there since 4.4. Although i'm a python programmer, i don't like this auto....I prefer to write types explicitly.

One more question guys: Is there any union/intersection ability between two GA_PrimitiveGroup? I need groupA to contain reverse of groupB, There are some operator overloaded, like bitwise ^. Don't get how to use it... :huh:

Link to comment
Share on other sites

Guest mantragora
Although i'm a python programmer, i don't like this auto....I prefer to write types explicitly.

I don't have this problem because in Visual Studio, if I hover mouse on variable, I get popup with its type even if it was specified as Auto :D

This example code is in Geometry Introduction section of documentation...

But they are setting iterator to first vertex...

GA_Primitive::const_iterator it;
partsys-&gt;beginVertex(it);

...and you just left you iterator uninitialized.

Can't help with the groups.

Edited by mantragora
Link to comment
Share on other sites

Instead of looking for some fancy named iterators in documentation, use the one built-in into GA_OffsetArray with auto, if you are on a compiler that supports C++11.

YES! Have you tried range-based for loops yet with the iterators? I haven't checked whether the various iterators we have always have an end() method but they should! Then the loop should come down to something like this:

for (const auto &amp;prim_off : prims)
{
auto pNum = gdp-&gt;primitiveIndex(prim_off);
report += std::to_string(pNum) + ", ";
}

This is why everyone needs to get their Linux-based studio onto gcc 4.6.

Link to comment
Share on other sites

Guest mantragora

YES! Have you tried range-based for loops yet with the iterators?

Yes I did.

I love override keyword too. It saved me couple hours of figuring out why something doesn't work. It turned out that there is a change in HDK that I was not aware of, and with this keyword added compiler complained that there is no virtual method in base class that I want to implement.

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