Hi Everybody,
I was wondering if anybody knows how to check if an edge is valid using HDK. For example in HOM there is this function hou.Geometry.findEdge(Point1,Point2) and it will return a hou.Edge object if the two points create an edge and None if they dont. So it is pretty simple and so far I can't find any equivalent in HDK for this. My first thought was that maybe GA_Detail class has some similar function but it doesnt. And the GA_Edge class has an isValid() function however, it always returns me 1 even if the points does not create an edge.
Does anybody has any recommandation about this?
Thanks
Ati
HDK GA_Edge question
4076 5 2- ati3d
- Member
- 6 posts
- Joined: 10月 2011
- Offline
- graham
- Member
- 1922 posts
- Joined: 11月 2006
- Offline
GA_Edge::isValid() is a test to ensure both points in the edge are valid points. To test if an edge actually exists with those points you need to use GA_Primitive::hasEdge, along with your target GA_Edge, to test which primitives might have that edge.
Graham Thompson, Technical Artist @ Rockstar Games
- ati3d
- Member
- 6 posts
- Joined: 10月 2011
- Offline
- neil_math_comp
- Member
- 1743 posts
- Joined: 3月 2012
- Offline
ati3d
Thank you!
By using gdp->getPrimitivesReferencingPoint() I could get all the primitives which connected to either one of the points of my edge, and then iterating over the primitives I am just calling the hasEdge() function. It works perfectly
If you'd like a slight optimization, (you might have already done something like this), the primitive has to contain both points, and the results of getPrimitivesReferencingPoint are sorted, so you could do:
// You can keep the arrays outside a loop to save reallocation.
GA_OffsetArray p0primitives;
GA_OffsetArray p1primitives;
GA_OffsetArray edgeprimitives;
…
getPrimitivesReferencingPoint(p0primitives, edge->p0());
getPrimitivesReferencingPoint(p1primitives, edge->p1());
primitives0.sortedIntersection(p1primitives, edgeprimitives);
// edgeprimitives will *probably* contain zero or two primitives now,
// but you still need to check hasEdge(), because edge could
// refer to, e.g., a diagonal of a quad instead of an actual edge,
// (in which case, edgeprimitives will *probably* contain only one
// primitive).
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
- ati3d
- Member
- 6 posts
- Joined: 10月 2011
- Offline
Oh, this example code is really usefull. As my next step I also wanted to get an easier way to find out which primitives sharing that edge.
Now it is looking like this, and works perfect.
GA_OffsetArray fpPrims;
GA_OffsetArray spPrims;
GA_OffsetArray intersectedPrims;
GA_OffsetArray::const_iterator prim_it;
gdp->getPrimitivesReferencingPoint(fpPrims,*_firstPoint);
gdp->getPrimitivesReferencingPoint(spPrims,*_secondPoint);
fpPrims.sortedIntersection(spPrims,intersectedPrims);
//std::cout<<“Neighbour primitives:”<<std::endl;
GA_Edge edge(*_firstPoint,*_secondPoint);
int validEdge = 0;
if (intersectedPrims.entries() == 2)
{
for (prim_it = intersectedPrims.begin(); !prim_it.atEnd(); ++prim_it)
{
std::cout<<“PrimNum : ”<<gdp->primitiveIndex(*prim_it)<<std::endl;
if (gdp->getPrimitiveList().get(gdp->primitiveIndex(*prim_it))->hasEdge(edge) == 1)
{
validEdge++;
}
}
}
I was also looking into how to get the neighbourpoints of any of my selected point. It works fine, however I am getting the warning that GU_Detail::buildRingZeroPoints(…) are deprected, and so far I couldn't find anything to replace it.
UT_PtrArray<UT_PtrArray<GEO_Point*>*> ringzero;
UT_IntArray ringvalence;
gdp->buildRingZeroPoints(ringzero, &ringvalence);
UT_Array<int> neighbourPointsArray;
int entries;
entries = ringzero->entries();
for (int i = 0; i<entries; i++)
{
if (gdp->pointIndex(*_secondPoint) != (*ringzero)->getNum())
{
neighbourPointsArray.append((*ringzero)->getNum());
std::cout<<“NeighbourPoint: ”<<(*ringzero)->getNum()<<std::endl;
}
}
Now it is looking like this, and works perfect.
GA_OffsetArray fpPrims;
GA_OffsetArray spPrims;
GA_OffsetArray intersectedPrims;
GA_OffsetArray::const_iterator prim_it;
gdp->getPrimitivesReferencingPoint(fpPrims,*_firstPoint);
gdp->getPrimitivesReferencingPoint(spPrims,*_secondPoint);
fpPrims.sortedIntersection(spPrims,intersectedPrims);
//std::cout<<“Neighbour primitives:”<<std::endl;
GA_Edge edge(*_firstPoint,*_secondPoint);
int validEdge = 0;
if (intersectedPrims.entries() == 2)
{
for (prim_it = intersectedPrims.begin(); !prim_it.atEnd(); ++prim_it)
{
std::cout<<“PrimNum : ”<<gdp->primitiveIndex(*prim_it)<<std::endl;
if (gdp->getPrimitiveList().get(gdp->primitiveIndex(*prim_it))->hasEdge(edge) == 1)
{
validEdge++;
}
}
}
I was also looking into how to get the neighbourpoints of any of my selected point. It works fine, however I am getting the warning that GU_Detail::buildRingZeroPoints(…) are deprected, and so far I couldn't find anything to replace it.
UT_PtrArray<UT_PtrArray<GEO_Point*>*> ringzero;
UT_IntArray ringvalence;
gdp->buildRingZeroPoints(ringzero, &ringvalence);
UT_Array<int> neighbourPointsArray;
int entries;
entries = ringzero->entries();
for (int i = 0; i<entries; i++)
{
if (gdp->pointIndex(*_secondPoint) != (*ringzero)->getNum())
{
neighbourPointsArray.append((*ringzero)->getNum());
std::cout<<“NeighbourPoint: ”<<(*ringzero)->getNum()<<std::endl;
}
}
- neil_math_comp
- Member
- 1743 posts
- Joined: 3月 2012
- Offline
ati3dCareful! The GA_PrimitiveList is accessed by GA_Offset, not GA_Index! It should be:
gdp->getPrimitiveList().get(gdp->primitiveIndex(*prim_it))
gdp->getPrimitiveList().get(*prim_it)
The first one will happen to work in most cases, but may crash in cases where some primitives have been deleted in an earlier SOP up the chain.
I am getting the warning that GU_Detail::buildRingZeroPoints(…) are deprected, and so far I couldn't find anything to replace it.There should be a non-deprecated version with the signature:
GU_Detail::buildRingZeroPoints(UT_Array<GA_OffsetArray> &ringzero, UT_IntArray *ringvalence);
and the second parameter can be NULL if you don't need the redundant array indicating the lengths of the other arrays. Using that version:
UT_Array<GA_OffsetArray> ringzero;
gdp->buildRingZeroPoints(ringzero, NULL);
GA_Index firstptind = gdp->pointIndex(*_firstPoint);
GA_OffsetArray neighbourPointsArray;
exint entries = ringzero->entries();
for (exint i = 0; i<entries; i++)
{
if (*_secondPoint != ringzero)
{
neighbourPointsArray.append(ringzero);
std::cout<<“NeighbourPoint: ”<<(gdp->pointIndex(ringzero))<<std::endl;
}
}
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
-
- Quick Links