Jump to content

Problems with GB_ATTRIB_STRING


Recommended Posts

I have a simple Add SOP (which creates a single point) followed by an AttribCreate SOP. I want to attach a string attribute to the point, which seems to be no problem (I set the type to string and, when I open the spreadsheet, I see the value). This then plugs into a custom SOP, which can not seem to find the attribute. The code is below:

int offsetStr = myGDP->findPointAttrib( "ccn", GB_ATTRIB_STRING );  // always returns -1
int offsetFlt = myGDP->findPointAttrib( "ccn", GB_ATTRIB_FLOAT );   // returns -1 or #

When I search for the type by GB_ATTRIB_STRING, I ALWAYS get -1. When I set the type to float in the AttribCreate, and then search by GB_ATTRIB_FLOAT, I get a proper offset.

What am I missing?

Thanks in advance!

Link to comment
Share on other sites

I have a simple Add SOP (which creates a single point) followed by an AttribCreate SOP. I want to attach a string attribute to the point, which seems to be no problem (I set the type to string and, when I open the spreadsheet, I see the value). This then plugs into a custom SOP, which can not seem to find the attribute. The code is below:

int offsetStr = myGDP->findPointAttrib( "ccn", GB_ATTRIB_STRING );  // always returns -1
int offsetFlt = myGDP->findPointAttrib( "ccn", GB_ATTRIB_FLOAT );   // returns -1 or #

When I search for the type by GB_ATTRIB_STRING, I ALWAYS get -1. When I set the type to float in the AttribCreate, and then search by GB_ATTRIB_FLOAT, I get a proper offset.

What am I missing?

Thanks in advance!

16155[/snapback]

I believe that GB_ATTRIB_STRING has been deprecated in favour of GB_ATTRIB_INDEX.

void
addString(GU_Detail *gdp)
{
    GB_Attribute	*attrib;
    int    minus_one = -1;
    int    i, handle;
    int    string_id, *avalue;
    GEO_Primitive	*prim;
    char   value[32];

    attrib = gdp->addPrimAttrib("cnn", sizeof(int), GB_ATTRIB_INDEX,
    (void *)&minus_one);
    handle = gdp->findPrimAttrib("cnn", sizeof(int), GB_ATTRIB_INDEX);
    if (handle >= 0)
    {
	for (i = 0; i < gdp->primitives().entries(); i++)
	{
     // Get a pointer to the primitive's attribute data
     avalue = gdp->primitives()(i)->getAttribData(handle);

     // Set the value of the string
     sprintf(value, "value%d", i%10);

     // Add the string value to the attribute container and set
     // the primitive's attribute value to the appropriate
     // index.
     *avalue = attrib->addIndex(value);
	}
    }
}

Something like this. As well, you might have to access it using the

prims() or points() function (which return string values).

Hope this helps,

Link to comment
Share on other sites

I believe that GB_ATTRIB_STRING has been deprecated in favour of GB_ATTRIB_INDEX.

Hope this helps,

16164[/snapback]

Aha! Yes, indeed ... if I search for my string attribute via GB_ATTRIB_INDEX, I get an offset. Unfortunately, this now leads me to have to ask two more questions:

1) How do I access the data? I'm going through points().head()->getAttribData( offset ) ... but I'm not sure what I'm being returned. I was hoping it was the character string, but when I dereference the pointer, the first value is 0.

2) Does it actually say somewhere that GB_ATTRIB_STRING "isn't used any more"?

Thanks!

Link to comment
Share on other sites

Aha! Yes, indeed ... if I search for my string attribute via GB_ATTRIB_INDEX, I get an offset.  Unfortunately, this now leads me to have to ask two more questions:

1) How do I access the data? I'm going through points().head()->getAttribData( offset ) ... but I'm not sure what I'm being returned. I was hoping it was the character string, but when I dereference the pointer, the first value is 0.

2) Does it actually say somewhere that GB_ATTRIB_STRING "isn't used any more"?

Thanks!

16167[/snapback]

The GB_Attribute class holds a list of strings. The integer value stored with the attribute is an index into those strings. You have to ask the GB_Attribute what the string is.

   const char *string = attrib->getIndex(integer_attribute_value);

Link to comment
Share on other sites

The GB_Attribute class holds a list of strings.  The integer value stored with the attribute is an index into those strings.  You have to ask the GB_Attribute what the string is.

   const char *string = attrib->getIndex(integer_attribute_value);

16171[/snapback]

Ok, that's fine ... but how do I get a GB_Attribute from a GEO_Point or a GU_Detail?

Link to comment
Share on other sites

Guest xionmark
2) Does it actually say somewhere that GB_ATTRIB_STRING "isn't used any more"?

I haven't seen anything that says it's not used anymore ... however, I always get a -1 returned as opposed to GB_ATTRIB_INDEX always returning the "correct" offset.

--Mark

Link to comment
Share on other sites

Guest xionmark
Ok, that's fine ... but how do I get a GB_Attribute from a GEO_Point or a GU_Detail?

16172[/snapback]

Well, I did something like this:

GB_Attribute * myGB_Attr = gdp->attribs().find("sd_obj_tex_fname");
        obj_tex_fname = gdp->findAttrib("sd_obj_tex_fname", GB_ATTRIB_INDEX);


if(myGB_Attr != NULL) {
    cout << "getType: " << myGB_Attr->getType() << endl;
    cout << "getTypeInfo: " << myGB_Attr->getTypeInfo() << endl;
    cout << "getName: " << myGB_Attr->getName() << endl;
    cout << "getSize: " << myGB_Attr->getSize() << endl;
    cout << "getAllocSize: " << myGB_Attr->getAllocSize() << endl;
    cout << "getIndex: " << myGB_Attr->getIndex("sd_obj_tex_fname") << endl;
    cout << "getIndex: " << myGB_Attr->getIndex(obj_tex_fname) << endl;
    cout << "getIndexSize: " << myGB_Attr->getIndexSize() << endl;
}

But the getIndex(obj_tex_fname) call segv's. The getIndex("sd_obj_tex_fname") call always returns a -1 ... so I'm still not able to grab the string from the attributes.

By the way, is it a UT_String or cinst char * that gets returned from getAttribData()?

--Mark

Link to comment
Share on other sites

Guest xionmark
Ok, that's fine ... but how do I get a GB_Attribute from a GEO_Point or a GU_Detail?

16172[/snapback]

Well, I did something like this:

GB_Attribute * myGB_Attr = gdp->attribs().find("sd_obj_tex_fname");
        obj_tex_fname = gdp->findAttrib("sd_obj_tex_fname", GB_ATTRIB_INDEX);


if(myGB_Attr != NULL) {
    cout << "getType: " << myGB_Attr->getType() << endl;
    cout << "getTypeInfo: " << myGB_Attr->getTypeInfo() << endl;
    cout << "getName: " << myGB_Attr->getName() << endl;
    cout << "getSize: " << myGB_Attr->getSize() << endl;
    cout << "getAllocSize: " << myGB_Attr->getAllocSize() << endl;
    cout << "getIndex: " << myGB_Attr->getIndex("sd_obj_tex_fname") << endl;
    cout << "getIndex: " << myGB_Attr->getIndex(obj_tex_fname) << endl;
    cout << "getIndexSize: " << myGB_Attr->getIndexSize() << endl;
}

But the getIndex(obj_tex_fname) call always segv's. The getIndex("sd_obj_tex_fname") call always returns a -1 ... so I'm still not able to grab the string from the attributes.

By the way, is it a UT_String or const char * that gets returned from getAttribData() when trying to retrieve a string attribute?

--Mark

Link to comment
Share on other sites

Guest xionmark

Woohoo!

OK, I got some results, here's the hacked code (i.e. needs cleanup but works):

=====================================

const char * obj_tex_fname_str;

obj_tex_fname = gdp->findAttribute("sd_obj_tex_fname", sizeof(int), GB_ATTRIB_INDEX, GEO_DETAIL_DICT);
cout << "obj_tex_fname: " << obj_tex_fname << endl;

GB_Attribute * myGB_Attr = gdp->attribs().find("sd_obj_tex_fname", GB_ATTRIB_INDEX);

if(myGB_Attr != NULL) {
    int *p_obj_tex_fname_idx = ((int *)gdp->attribs().getAttribData(obj_tex_fname));
    cout << "obj_tex_fname_idx: " << *p_obj_tex_fname_idx << endl;
    obj_tex_fname_str = myGB_Attr->getIndex(*p_obj_tex_fname_idx);
    cout << "obj_tex_fname_str: " << obj_tex_fname_str << endl;
}

--Mark

Link to comment
Share on other sites

Woohoo!

OK, I got some results, here's the hacked code (i.e. needs cleanup but works):

=====================================

const char * obj_tex_fname_str;

obj_tex_fname = gdp->findAttribute("sd_obj_tex_fname", sizeof(int), GB_ATTRIB_INDEX, GEO_DETAIL_DICT);
cout << "obj_tex_fname: " << obj_tex_fname << endl;

GB_Attribute * myGB_Attr = gdp->attribs().find("sd_obj_tex_fname", GB_ATTRIB_INDEX);

if(myGB_Attr != NULL) {
    int *p_obj_tex_fname_idx = ((int *)gdp->attribs().getAttribData(obj_tex_fname));
    cout << "obj_tex_fname_idx: " << *p_obj_tex_fname_idx << endl;
    obj_tex_fname_str = myGB_Attr->getIndex(*p_obj_tex_fname_idx);
    cout << "obj_tex_fname_str: " << obj_tex_fname_str << endl;
}

--Mark

16231[/snapback]

Looks great, but do you know how to extend this to get string attributes on points (i.e., not detail attributes)?

Link to comment
Share on other sites

Guest xionmark
Looks great, but do you know how to extend this to get string attributes on points (i.e., not detail attributes)?

16236[/snapback]

Nope, not yet. But will try later today if I get the time.

--Mark

Link to comment
Share on other sites

Nope, not yet.  But will try later today if I get the time.

--Mark

16237[/snapback]

Aha! Issue resolved (kudos to Jeff Lait)!

int myOffset = myGDP->findPointAttrib( "ccn", GB_ATTRIB_INDEX );
const GEO_Point *point = myGDP->points().head();
for( int i = 0; point; point = myGDP->points().next( point ), i++ )
{
  GB_Attribute *myAttr =
    myGDP->pointAttribs().find( "ccn", GB_ATTRIB_INDEX );
  int myIndex =
    *( int* )point->getAttribData( myOffset );
  const char* myString =
    cacheNameAttr->getIndex( cacheNameIndex ) );
  // DO SOMETHING INTERESTING WITH myString
}

Link to comment
Share on other sites

  • 3 years later...

int test = gdp->addPointAttrib("tex", sizeof(UT_String), GB_ATTRIB_INDEX, 0);

int texID = gdp->findPointAttrib("tex", GB_ATTRIB_INDEX);

GB_Attribute *texAttr = gdp->pointAttribs().find("tex", GB_ATTRIB_INDEX);

string tex = "Mandril.pic"

FOR_ALL_GPOINTS(gdp, ppt)

{

int texIndex = *(int*)ppt->getAttribData(texID);

const char *texString = texAttr->getIndex(texIndex);

texString = tex.c_str();

}

FOR_ALL_GPOINTS(gdp, ppt)

{

int texIndex = *(int*)ppt->getAttribData(texID);

UT_String pTex = texAttr->getIndex(texIndex);

cout<<pTex<<endl;

}

But the result is ""

Does anyone know why it so?

Thanks

Edited by Nasyrov
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...