Jump to content

Using Groups


Recommended Posts

Any pointers with using groups. I've tried using the code from the example Flatten.C but for some unknown reason it throws up this error during compile.

SOP_TriToQuad.C(170) : error C2664: 'OP_Network::getGroups' : cannot convert parameter 1 from 'UT_String' to 'UT_PtrArray<utPtr> &'
        with
        [
            utPtr=OP_Group *
        ]
        A reference that is not to 'const' cannot be bound to a non-lvalue

How can this work in Flatten but not in my sop?

Link to comment
Share on other sites

Hey Simon,

Hard to tell exactly what's going from that error (and I haven't looked at the Flatten sop), but it *seems* like you tried to pass a UT_String as a first parameter to OP_Network::getGroups(). Looking at the OP_Network class, I see the getGroups method defined as

int          getGroups(UT_PtrArray<OP_Group *> &list, int internal=0);

So the first argument should be a UT_PtrArray of OP_Group pointers -- which presumably the getGroups() method would fill for you. It also returns an int, so I'm guessing this return value represents the number of groups that got stuffed into the UT_PtrArray<OP_Group *> reference that you passed in (giving you an upper limit for indexing). On the other hand, you can always retrieve the number of objects in a UT_PtrArray<> via its entries() method, so maybe that return value is a failure/success boolean (I notice they use int for bool in a lot of boolean returns).

So... based on a whole lot of speculation, I'd say the intended usage is something like this:

//...//
UT_OpNetwork net(//...//);       //I assume you're defining this somehow...
UT_PtrArray&lt;OP_Group *&gt; list;    //empty array of OP_Group pointers
int ngroups = net.getGroups(list); //fill up the list

// At this point, if ngroups is a group count, then it should
// have a value equal to list.entries(). If it's meant to be a boolean,
// then it should have a value equal to (list.entries()&gt;0)  -- you need 
// to test this...

Hope that helps somewhat :unsure:

Link to comment
Share on other sites

It's weird the flatten sop compiles no problem so I assumed it would work. I'll check out your suggestions, they certainly make sense given the errors, I just can't make out how flatten throws no errors, I literally just copy pasted the whole cookinputgroups method wholesale from it.

OP_ERROR
SOP_Flatten::cookInputGroups(OP_Context &amp;context, int alone)
{
    // If we are called by the handle, then "alone" equals 1.  In that
    // case, we have to lock the inputs oursevles, and unlock them
    // before exiting this method.
    if (alone) if (lockInputs(context) &gt;= UT_ERROR_ABORT) return error();

    UT_String  grp_name;

    // The "gdp" variable is only available if we are called from the SOP
    // itself.  So, if we are called by a handle, we have to get the
    // geometry oursevles.
    GU_Detail	*pgdp = alone ? (GU_Detail *)inputGeo(0, context) : gdp;

    myGroup = 0;

    getGroups(grp_name);  // Get the group string.

    // If the group string is not null, then we try to parse the group.
    if (grp_name.isstring())
    {
	myGroup = parsePointGroups((const char *)grp_name, pgdp);

	// If the group is not valid, then the group string is invalid
	// as well.  Thus, we add an error to this SOP.
	if (!myGroup)
	{
     addError(SOP_ERR_BADGROUP, grp_name);
	}
	else if (!alone)
	{
     // If the parsed group is valid, then we want to highlight
     // only the group.  The second argument of "1" means that
     // we want the selection to have the same type as our group.
     select(*(GB_BaseGroup *)myGroup, 1);
	}
    }
    else if (!alone)
    {
	// If no group string is specified, then we operate on the entire
	// geometry, so we highlight every point for this SOP.
	select(GU_SPoint);
    }

    // This is where we notify our handles (if any) if the inputs have changed.
    checkInputChanged(0, -1, myDetailGroupPair, pgdp, myGroup);

    // If we are called by the handles, then we have to unlock our inputs.
    if (alone)
    {
	destroyAdhocGroups();
	unlockInputs();
    }

    return error();
}

As you can see they use UT_String, and I've compiled this code and it works fine.

I kinda didn't want to change it without understanding why it needed to be.

Link to comment
Share on other sites

It's weird the flatten sop compiles no problem so I assumed it would work. I'll check out your suggestions, they certainly make sense given the errors, I just can't make out how flatten throws no errors, I literally just copy pasted the whole cookinputgroups method wholesale from it.

Ah... I think I see...

That getGroups() function being used in the SOP_Flatten::cookInputGroups() method has nothing to do with OP_Network::getGroups()... and yet in your case, it is the OP_Network member of that name which is getting used. Here's what I think is happening:

1. The class SOP_Flatten defines an inline private method

void getGroups(UT_String &str) { evalString(str, 0, 0, 0); }

which simply evaluates the string parameter's current value. An unfortunate choice of name for the function since it's overloading OP_Network::getGroups().

2. When *you* call getGroups() (whithout a namespace class qualifier) from within your cook method, the compiler resolves it to the OP_Network::getGroups(), which *doesn't* take a UT_String as an argument... and it coughs up the error.

So... I'm guessing that you should either:

A ) Implement a private member "getGroups()" as in the Flatten SOP (which just resolves the parameter's current value). Or..

B ) Replace the line in your copy/paste code that currently reads:

getGroups(grp_name); // Get the group string.

with something like:

evalString(grp_name,0,0,0); // this does the same thing...

yes, no, beer?

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