GallenWolf Posted October 19, 2012 Share Posted October 19, 2012 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. Quote Link to comment Share on other sites More sharing options...
graham Posted October 19, 2012 Share Posted October 19, 2012 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 } } 2 Quote Link to comment Share on other sites More sharing options...
GallenWolf Posted October 19, 2012 Author Share Posted October 19, 2012 ARGH! So it was GA_Iterator after all!!! Thank you so very much Graham! I owe you a pint Quote Link to comment Share on other sites More sharing options...
edward Posted October 22, 2012 Share Posted October 22, 2012 You can use GA_Iterator for everything. for (GA_Iterator pr_it(gdp->getPrimitiveRange()); !pr_it.atEnd(); ++pr_it) { GEO_Primitive *prim = gdp->getGEOPrimitive(*pr_it); /// etc... } Quote Link to comment Share on other sites More sharing options...
GallenWolf Posted October 22, 2012 Author Share Posted October 22, 2012 (edited) Thanks Edwards! I must admit I have no idea how to use iterators properly, got to give them a good run. Thanks again EDIT: Owe you a pint too ;-) Edited October 22, 2012 by GallenWolf Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted November 12, 2013 Share Posted November 12, 2013 (edited) 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 November 12, 2013 by Stalkerx777 Quote Link to comment Share on other sites More sharing options...
Macha Posted November 12, 2013 Share Posted November 12, 2013 Shouldn't that be it->item() ? Quote Link to comment Share on other sites More sharing options...
Macha Posted November 12, 2013 Share Posted November 12, 2013 Shouldn't that be it->item() ? Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 13, 2013 Share Posted November 13, 2013 (edited) 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->getPointRange()); !pointIt.atEnd(); pointIt.advance()) { auto report = "Point num: " + std::to_string(POINT) +" is referenced by: "; gdp->getPrimitivesReferencingPoint(prims, POINT); for (auto i = prims.begin(); i != prims.end(); ++i) { auto pNum = gdp->primitiveIndex(*i); report += std::to_string(pNum) + ", "; } std::cout << report << std::endl; } Without auto, iterator for GA_OffsetArray will look like this: for (UT_Array<exint>::iteratorT<true> i = prims.begin(); i != prims.end(); ++i) TO ADMINS: Formatting in tag SUCKS! Edited November 13, 2013 by mantragora Quote Link to comment Share on other sites More sharing options...
graham Posted November 13, 2013 Share Posted November 13, 2013 Without auto, iterator for GA_OffsetArray will look like this: for (UT_Array<exint>::iteratorT<true> 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? Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 13, 2013 Share Posted November 13, 2013 (edited) 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<exint>::iteratorT<true> 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 November 13, 2013 by mantragora Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted November 13, 2013 Share Posted November 13, 2013 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... Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 13, 2013 Share Posted November 13, 2013 (edited) 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 This example code is in Geometry Introduction section of documentation... But they are setting iterator to first vertex... GA_Primitive::const_iterator it; partsys->beginVertex(it); ...and you just left you iterator uninitialized. Can't help with the groups. Edited November 14, 2013 by mantragora Quote Link to comment Share on other sites More sharing options...
edward Posted November 15, 2013 Share Posted November 15, 2013 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 &prim_off : prims) { auto pNum = gdp->primitiveIndex(prim_off); report += std::to_string(pNum) + ", "; } This is why everyone needs to get their Linux-based studio onto gcc 4.6. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 15, 2013 Share Posted November 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
graham Posted November 15, 2013 Share Posted November 15, 2013 This is why everyone needs to get their Linux-based studio onto gcc 4.6. We just upgraded to 4.4! Quote Link to comment Share on other sites More sharing options...
edward Posted November 16, 2013 Share Posted November 16, 2013 We just upgraded to 4.4! Yes, unfortunately we lost on this. A year ago (or more?), we suggested going to the latest at the time (gcc 4.6+) but people balked. 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.