Jump to content

How To Obtain A List Of Existing Attributes?


Recommended Posts

Hi everyone,

i try to get a list of the existing attributes from a geometry, but everytime i call,

GEO_PointAttribDict  attribs = ((GEO_Detail*)gdp)->pointAttribs();

the whole thin crashes, even when trying to debug the stuff i only get a segmentation fault but no backtrack into my code.

does someome have managed it to get a list of all existing attributes of the incomming geometry ?

thx

Sebastian

Link to comment
Share on other sites

There are several things that could go wrong that I can think of immediately:

- The casting should be un-necessary if you have the right include files. Make sure you have #include <GU/GU_Detail.h>.

- Have you checked that gdp != NULL?

- pointAttribs() returns a reference, I think you're missing an & in there. I don't think there's a save operator=() that you can call.

- Is your gdp empty? Unless, you've duplicated your input first, it will be. If you want to find the list of point attributes from your input, lock your input and then use inputGeo().

- Finally, once you have your attribute dictionary, you can look through them like this:

	for (GB_Attribute *atr = attribs.getHead(); atr != NULL; atr = (GB_Attribute *)atr-&gt;next())
	{
		if (atr-&gt;getType() == GB_ATTRIB_MIXED)
			continue;
		cout &lt;&lt; atr-&gt;getName() &lt;&lt; " " &lt;&lt; atr-&gt;getType() &lt;&lt; " " &lt;&lt; atr-&gt;getSize() &lt;&lt; endl;
	}

Link to comment
Share on other sites

Strangely, the first code below works, the second (where gdp isn't a pointer) crashes, gdb telling me:

#0  0x00000031 in ?? ()
#1  0xb53d76b5 in UT_LinkList::clearActive () from /opt/sidefx/hfs9.0.719/dsolib/libHoudiniUT.so
#2  0xb60723de in GEO_Detail::~GEO_Detail () from /opt/sidefx/hfs9.0.719/dsolib/libHoudiniGEO.so
#3  0xb6166c8e in GU_Detail::~GU_Detail () from /opt/sidefx/hfs9.0.719/dsolib/libHoudiniGEO.so

Works fine:

	GU_Detail *gdp = new GU_Detail();
	UT_String points_bgeo;
	int t;

	if( argc!=2 )
	{
		fprintf(stderr,"Specify points path please.\n");
		exit (1);
	}

	if(!strcmp(argv[1], ""))
		points_bgeo = NULL;
	else
		points_bgeo = argv[1];

	if(gdp-&gt;load(points_bgeo,0))
	{
		fprintf(stderr,"Could not load seed points!\n");
		exit (1);
	}

	int numpoints = gdp-&gt;points().entries();
	fprintf(stderr,"Num points: %d\n", numpoints);

	GEO_PointAttribDict attribs = gdp-&gt;pointAttribs();

	for (GB_Attribute *atr = attribs.getHead(); atr != NULL; atr = (GB_Attribute *)atr-&gt;next())
	{
		if (atr-&gt;getType() == GB_ATTRIB_MIXED)
			continue;
		cout &lt;&lt; atr-&gt;getName() &lt;&lt; " " &lt;&lt; atr-&gt;getType() &lt;&lt; " " &lt;&lt; atr-&gt;getSize() &lt;&lt; endl;
	}

Segfaults at the end:

	GU_Detail gdp;
	UT_String points_bgeo;
	int t;

	if( argc!=2 )
	{
		fprintf(stderr,"Specify points path please.\n");
		exit (1);
	}

	if(!strcmp(argv[1], ""))
		points_bgeo = NULL;
	else
		points_bgeo = argv[1];

	if(gdp.load(points_bgeo,0))
	{
		fprintf(stderr,"Could not load seed points!\n");
		exit (1);
	}

	int numpoints = gdp.points().entries();
	fprintf(stderr,"Num points: %d\n", numpoints);

	GEO_PointAttribDict attribs = gdp.pointAttribs();

	for (GB_Attribute *atr = attribs.getHead(); atr != NULL; atr = (GB_Attribute *)atr-&gt;next())
	{
		if (atr-&gt;getType() == GB_ATTRIB_MIXED)
			continue;
		cout &lt;&lt; atr-&gt;getName() &lt;&lt; " " &lt;&lt; atr-&gt;getType() &lt;&lt; " " &lt;&lt; atr-&gt;getSize() &lt;&lt; endl;
	}

Link to comment
Share on other sites

hmm ... something i dont understand, ... or maybe missunderstand, ... i dont have to set gdp on my own, as long as its in an SOP node, right ?, because if i have to I'm wondering why my stuff is working without setting this variable.

here's my current code

	time = context.myTime;
    	duplicateSource(0, context);

	setVariableOrder(3, 2, 0, 1);
    	setCurGdh(0, myGdpHandle);
 	setupLocalVars();

	if (error() &lt; UT_ERROR_ABORT &amp;&amp; cookInputGroups(context) &lt; UT_ERROR_ABORT)
	{
		if (gdp != NULL)
		{
			GEO_PointAttribDict attribs = gdp-&gt;pointAttribs();
		}
		[... iterating over points]
	}
	myCurrPoint = -1;
	unlockInputs();
	resetLocalVarRefs();
	return error();

and it still crashes ... do I have to set gdp or is it set automatic in the SOP node ?

thx in advance

Sebastian

Link to comment
Share on other sites

@infernalspawn: ok, if you're inside a SOP_Node::cookMySop() code path, then gdp should be non-NULL already. I think you're still making the same mistake that pbowmar is. I'm not quite sure I understand your posted code since the attribute dictionary is the *same* for *all* points. So there should be no iterating over points at all.

@pbowmar:

- pointAttribs() returns a reference, I think you're missing an & in there. I don't think there's a safe operator=() that you can call.

GEO_PointAttribDict &attribs = gdp->pointAttribs();

Link to comment
Share on other sites

@pbowmar:

- pointAttribs() returns a reference, I think you're missing an & in there. I don't think there's a safe operator=() that you can call.

GEO_PointAttribDict &attribs = gdp->pointAttribs();

Cool, thanks Edward. I'm sure it's a C++ confusion on my part, of which of I have plenty!!

Cheers,

Peter B

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