Access Group Information

From Odwiki

Jump to: navigation, search


Contents

Access Group information with HDK

Working in HDK, you might want to be able to get into a group from Houdini (Pointgroup or Primitivegroup). Find the specific group you want, is straightforward, but howto access the information that the group actually contain?

Access HDK Macro

Simplest way to get access to a specific group, is to use HDK macros. So to get access to these, you just need to include the headers:

#include <GB/GB_Macros.h>
#include <GB/GB_ExtraMacros.h>

These headers gives you access to the macros you need, and lots of other macros aswell. Please look through the header files for more information about other macros.

Access Group list

When you have included the headers, you need to loop through the list that contains all the specific groups you are looking for. In Houdini there are two different grouptypes:

  1. Point group
  2. Primitive group

To access a point group, you need to call the following macro:

FOR_ALL_POINTGROUPS(GU_Detail *pTempGuDetail, GB_PointGroup *pPointGroupList)
{
 // -- Put your code here
}

This function loops through all existing point groups you may have. When it has accessed the last one, it simply exists the loop. The macro for primitive group, looks very much like the one for the point groups:

FOR_ALL_PRIMGROUPS(GU_Detail *pTempGuDetail, GB_PrimitiveGroup *pPrimitiveGroupList)
{
 // -- Put your code here
}

Access Group information

So now you have your specific group you want to access. But looking through the Grouppointer, there are not much data to retrieve. Why? Because you are only looking at the group itself, and not the data within the group. What you need to do, is to get inside the current group, to get all the data from the group.

For this, you need to use another macro. For points it looks like this:

FOR_ALL_GROUP_POINTS(GU_Detail *pTempGuDetail, GB_PointGroup *pGroup, GEO_Point *pPoint)
{
 // -- Put your code here
} 

And very similar for the primitive macro:

FOR_ALL_GROUP_PRIMITIVES(GU_Detail *pTempGuDetail, GB_PrimitiveGroup *pGroup, GEO_Primitive *pPrimitive)
{
 // -- Put your code here
} 

Remember! The pointer to the group MUST be valid. Otherwise the macro will crash!

Putting it all together

So now you have learned howto access the grouplist, and how to access a individual group and find its elements. Below is a simple pseudo code example on how it could look like, when accessing a group and retrieve its element variable:

const GU_Detail *pGuDetail = &GuDetail;
const GEO_Primitive *pPrimitive;
GB_PrimitiveGroup *pPrimitiveGroupList = NULL;
 FOR_ALL_PRIMGROUPS(pTempGuDetail, pPrimitiveGroupList)
 { 
   FOR_ALL_GROUP_PRIMITIVES(pTempGuDetail, pPrimitiveGroupList, pPrimitive)
    {
     int ElementNumValue = pPrimitive->getNum();
    }
 }

© 2009 od[force].net | advertise