Merging geometry from multiple inputs

Jeff Lait jlait at fiji.sidefx.com
Fri Jul 30 14:38:21 EDT 2004


On Fri, Jul 30, 2004 at 11:06:44AM -0700, Mark Story wrote:
> 
> I've got a SOP that uses multiple inputs, but am having trouble merging 
> the geometry of all the inputs so the output of the SOP has all the 
> geometry presented to the inputs.  I haven't found any examples in the 
> toolkit samples, so I'm shootin' in the dark here (and missing the 
> target!).  It fails at the merge() or copy() method.  I've successfully 
> processed the geo from all the inputs for what the SOP "does", write out 
> Real Flow files, but I want the user to see all the geo when the display 
> flag is on, not just the first input which is what I've done in the interim.
> 
> Here's what I've been trying:
> 
> gdp->clearAndDestroy();
> myGdp->clearAndDestroy();

	myGdp is a member GU_Detail *, right?

> // For each object (input)
> for(current_obj = 0; current_obj < num_inputs; current_obj++) {
> 
>    if (lockInputs(context) >= UT_ERROR_ABORT) {
>    cout << "Could not lock input" << endl;
>    return error();
>    }

	Here, you are locking ALL of the inputs to merge each object.
With 7.0 and unloading, this can get expensive, as the unlock may
unload the input, thinking you are done with it.
	Two approaches are:
1) Move the lockInputs(), unlockInputs() outside of this loop.
2) Use lockInput() and unlockInput() to do each input individually.

> 
>    // Duplicate the geometry from the first input
>    // duplicateSource(current_obj, context);
>    inputGeo(current_obj, context);

	This would have to be myGdp = inputGeo(...), I think?

>    unlockInputs();

	After unlockInputs(), any GDP you got from inputGeo, etc, may
be invalid!  Your input is only guaranteed to be cooked & have a gdp
within the lock calls.

>    // gdp->merge((GEO_Detail &)myGdp);
>    gdp->copy((GEO_Detail &)myGdp);

	Merge should work.  However, copy is preferred as it is more
efficient.  It requires a bit of work using the GB_COPY_* flags
though.

> }
> 
> gdp->clearAndDestroy();
> gdp = myGdp;

	I'm afraid I don't understand this part.

> Any hints?  Examples?

	How about the source for the Merge SOP?
	My comments with triple slashes (///)

OP_ERROR
SOP_Merge::cookMySop(OP_Context &context)
{
    GU_Detail   *src;
    int          i, max, cnt;
    GU_Detail    blank_gdp;

    max = nInputs();
    cnt = 0;

    for (i = 0; i < max; i++)
    {
        // It is possible, despite the collapsing of inputs,
        // that some interior inputs are null.  They could, for
        // example,
        // be indirect references.
	/// (Specifically, you wire your sop into one of the subnet
	///  inputs, and that subnet input isn't wired up.)
        if (!getInput(i))
            continue;

        if (lockInput(i, context) < UT_ERROR_ABORT)
        {
            if (src = (GU_Detail *)inputGeo(i, context))
            {
                cnt++;

                if (cnt == 1)
                    gdp->copy(*src, GB_COPY_START);
                else
                    gdp->copy(*src, GB_COPY_ADD);

            }

            unlockInput(i);
        }
        else
            break;

    }

    if (error() >= UT_ERROR_ABORT || !cnt)
    {
        gdp->stashAll();
	/// The merge has failed here, or had no valid inputs.
	/// stashAll() is very similar to clearAndDestroy.
	/// You'd likely want return error() here.
    }
    else
    {
	/// We have to tell the copy that we are done so it
	/// properly cleans everything up.
	/// Copying a blank gdp makes for simpler logic than
	/// trying to detect the last copy ahead of time.
        gdp->copy(blank_gdp, GB_COPY_END);

	/// This select call is what highlights everything yellow.
	/// You likely don't want this.
        select(GU_SPrimitive);
    }

    /// All inputs have been copied into gdp.

    return error();
}

	I hope this clarifies things.
-- 
	- Jeff Lait



More information about the Sidefx-devkit-list mailing list