Copying points from one GU_Detail to another

   1380   3   0
User Avatar
Member
7 posts
Joined: Aug. 2012
Offline
I'm writing a SOP in C++. I have an input GU_Detail and I wish to copy some its points, including all attributes, to my output GU_Detail. However, for each point I decide copy over, I need its GA_Offset, so I can add my own attributes or change the ones that exist. How can I do this?

Right now, I'm doing something like:
// Copy the points and their attributes
for (GA_Iterator it(gdp_input->getPointRange()); !it.atEnd(); ++it)
{
GA_PointGroup* grp = gdp_input->newPointGroup(“tmpgrp”, false);
grp->addOffset(*it);
GA_Range range(*grp);
gdp->mergePoints(*gdp_input, range);

// need the offset here for further operations
}


While this successfully copies points and their attributes from “gdp_input” to “gdp”, it doesn't give me an offset.

I could then do something like:
// need the offset here for further operations
GA_IndexMap tmpMap(*gdp, GA_ATTRIB_POINT);
offset = tmpMap.lastOffset();
}
But there is no indication in the documentation (if it could be called that) of ‘lastOffset’ what exactly ‘last’ means. Is it the most-recently added point? The largest offset? The offset of the largest index? None of these?
User Avatar
Member
7 posts
Joined: Aug. 2012
Offline
To answer my own question, I can track the current index of the point I'm adding, and then use the indexToOffset() function to get the offset I need.
User Avatar
Member
7722 posts
Joined: July 2005
Offline
riotnrrd
// need the offset here for further operations
GA_IndexMap tmpMap(*gdp, GA_ATTRIB_POINT);
offset = tmpMap.lastOffset();
}
But there is no indication in the documentation (if it could be called that) of ‘lastOffset’ what exactly ‘last’ means. Is it the most-recently added point? The largest offset? The offset of the largest index? None of these?

It means all of of these if you're talking about the GA_IndexMap reference returned by gdp->getPointMap(). I'm not sure why you would create a temporary GA_IndexMap object. The reason why lastOffset() is all of those conditions that you mention is because points are always added to the end of the index map, increasing the last point index/offset by 1. Note that while the the point indices/offsets grow by 1, they may not be the same value because offset “holes” will be left whenever points are deleted.

Note that instead of gdp->getPointMap().lastOffset(), there is also the equivalent: gdp->pointOffset(gdp->getNumPoints() - 1)
User Avatar
Member
7722 posts
Joined: July 2005
Offline
riotnrrd
// Copy the points and their attributes
for (GA_Iterator it(gdp_input->getPointRange()); !it.atEnd(); ++it)
{
GA_PointGroup* grp = gdp_input->newPointGroup(“tmpgrp”, false);
grp->addOffset(*it);
GA_Range range(*grp);
gdp->mergePoints(*gdp_input, range);

// need the offset here for further operations
}


Note that this code is awfully inefficient. Plus, you also need to destroy the created point group.

As a more efficient transformation of the above code, I would do something more like this:

GA_Index begin_i = gdp->getNumPoints();
gdp->mergePoints(*gdp_input, gdp_input->getPointRange());
GA_Offset end_off = gdp->pointOffset(gdp->getNumPoints());
// process merged points
for (GA_Offset ptoff = gdp->pointOffset(begin_i); ptoff < end_off; ptoff++)
{
// process point ptoff
}
  • Quick Links