Jump to content

Find connected primitives


Recommended Posts

Hi all!

I am trying to write algorithm of finding primitives which connected between each others

and working like combination of the sop nodes connectivity + partition. I've written some code

but it works much slower than combination of nodes (connectivity + partition).

Could you please give me an advice how to make my algorithm faster.

Thanks!

Here is the part of my code:

	//.......cookMySop(OP_Context &context) {
	GEO_Closure closure(*gdp);
	GEO_Primitive* currentPrim=NULL;
	UT_IntArray primlist;
	GB_PointRefArray prefarr(gdp,0);

	int connectivityAttrCounter=1;
	int iteration=0;
	GEO_PrimList primitives = gdp->primitives();
	currentPrim=primitives.head();

	//Go to part of primitives
	while(currentPrim)
	{
		iteration=0;
		//Enter to the recursion function and find neighbor primititves
		int newConnectivity = findConnectivityPrimitives(gdp, closure, currentPrim, h, connectivityAttrCounter, iteration, primitives);
		//if newConnectivity==1 it's means that current part of primitive is define and mark
		if (newConnectivity==1)
			connectivityAttrCounter++;
		//set currentPrim to head of GEO_PrimList primitives
		currentPrim=primitives.head();
	}
    //...}

int MyNode::findConnectivityPrimitives( GU_Detail* gdp,
                                        GEO_Closure& closure,
                                        GEO_Primitive* currentPrim,
                                        GEO_AttributeHandle* connectivityAttr,
                                        int& connectivityAttrCounter,
                                        int& iteration,
                                        GEO_PrimList& primitives
                                        )
{
	//Set attribute handle
	connectivityAttr->setElement(currentPrim);
	//Check connectivity attribute if it not =0, then cook this prim
	if(!connectivityAttr->getI())
	{
		int primNum = currentPrim->getNum();
		//Set connectivity primitive attribute
		connectivityAttr->setI(connectivityAttrCounter);

		UT_IntArray primitivelist;
		GB_PointRefArray pointrefarr(gdp,0);

		//Go to all Edge and find polys using edge:
		int vrtxs = currentPrim->getVertexCount();
		for(int i=0; i<vrtxs ; i++)
		{ 
			closure.findPolysUsingEdge( *(currentPrim->getVertex(i).getPt()),
										*(currentPrim->getVertex(i+1).getPt()),
										primitivelist,
										pointrefarr
										);
			//Go to all primitives in primitivelist anf if it's not current fint in it:
			for(int j=0; j<primitivelist.entries() && primitivelist.entries()>1; j++)
			{
				int currentPrimNum = primitivelist(j);
                // Enter to the recursion function and find neighbor primititves
				if (currentPrimNum != primNum)
					findConnectivityPrimitives(gdp, closure, gdp->primitives()(currentPrimNum), connectivityAttr, connectivityAttrCounter, iteration, primitives);
			}
		}
		//remove cooked primitive from GEO_PrimList primitives
		primitives.remove(currentPrim);
		return 1;
	}
	else return 0;
}

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