예제 #1
0
/* 'name' should be 1-element STRSXP or SYMSXP */
SEXP setAttrib(SEXP vec, SEXP name, SEXP val)
{
    PROTECT(vec);
    PROTECT(name);

    if (isString(name))
	name = install(translateChar(STRING_ELT(name, 0)));
    if (val == R_NilValue) {
	UNPROTECT(2);
	return removeAttrib(vec, name);
    }

    /* We allow attempting to remove names from NULL */
    if (vec == R_NilValue)
	error(_("attempt to set an attribute on NULL"));

    if (NAMED(val)) val = duplicate(val);
    SET_NAMED(val, NAMED(val) | NAMED(vec));
    UNPROTECT(2);

    if (name == R_NamesSymbol)
	return namesgets(vec, val);
    else if (name == R_DimSymbol)
	return dimgets(vec, val);
    else if (name == R_DimNamesSymbol)
	return dimnamesgets(vec, val);
    else if (name == R_ClassSymbol)
	return classgets(vec, val);
    else if (name == R_TspSymbol)
	return tspgets(vec, val);
    else if (name == R_CommentSymbol)
	return commentgets(vec, val);
    else if (name == R_RowNamesSymbol)
	return row_names_gets(vec, val);
    else
	return installAttrib(vec, name, val);
}
예제 #2
0
OP_ERROR SOP_UniPdist::cookMySop(OP_Context &context)
{
    // Before we do anything, we must lock our inputs.  Before returning,
    // we have to make sure that the inputs get unlocked.
    if (lockInputs(context) >= UT_ERROR_ABORT)
	return error();

    // Duplicate input geometry
    duplicateSource(0, context);

	float time = context.getTime();
	float dist = evalFloat(distanceName.getToken(), 0, time);
	
	GA_PointGroup *removeGroup = gdp->newPointGroup(REMOVE_GROUP_NAME);
	GA_PointGroup *keepGroup   = gdp->newPointGroup(KEEP_GROUP_NAME);
	

    // Flag the SOP as being time dependent (i.e. cook on time changes)
    flags().timeDep = 1;

	//Create a removeAttrib
	GA_RWHandleI removeAttrib(gdp->addIntTuple(GA_ATTRIB_POINT, "__remove__", 1));
	
	//Creating PointTree
	GEO_PointTreeGAOffset pttree;
	//Build PointTree with all the points
	pttree.build(gdp,NULL);
	
	
	//Create the Array wich holds the distance for the current point in the for loop
	UT_FloatArray ptdist;
	
	// Index offset
	const GA_IndexMap points = gdp->getPointMap();
	GA_Size ptoffsetindex;
	ptoffsetindex = points.offsetSize()-points.indexSize();
	

	//set all
	for (GA_Iterator ptoff(gdp->getPointRange()); !ptoff.atEnd(); ++ptoff) 
	{
		removeAttrib.set(*ptoff,0);
	}

	
	
	
	
	// loop over all points, find second closest point
	for (GA_Iterator ptoff(gdp->getPointRange()); !ptoff.atEnd(); ++ptoff)

	{
		int removeMe;
		removeMe = int(removeAttrib.get(*ptoff));
		if(removeMe)
		{
			removeGroup->addIndex(*ptoff-ptoffsetindex);
			continue;
		}
			
		// Create the Array which holds a list sorted on distance to current point in the for loop
		GEO_PointTree::IdxArrayType plist; //plist
		UT_Vector3 pos = gdp->getPos3(*ptoff); // create pos
		pttree.findAllCloseIdx(pos,dist,plist); // find all points within the search radius
		
		
		unsigned int tempListP = plist.entries(); //create a int for entries in the array

		for(int i=0;i < tempListP; ++i)
		{
			removeAttrib.set(plist[i],1); //set the tempList points to be removed
		}
		removeAttrib.set(*ptoff,0);
		keepGroup->addIndex(*ptoff-ptoffsetindex);
	}
	pttree.clear(); //clear the pointtree
	
	
    unlockInputs();
    return error();
}