本文整理汇总了C++中OP_Context类的典型用法代码示例。如果您正苦于以下问题:C++ OP_Context类的具体用法?C++ OP_Context怎么用?C++ OP_Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OP_Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cookMySop
OP_ERROR SOP_SceneCacheSource::cookMySop( OP_Context &context )
{
flags().setTimeDep( true );
std::string file;
if ( !ensureFile( file ) )
{
addError( SOP_ATTRIBUTE_INVALID, ( file + " is not a valid .scc" ).c_str() );
gdp->clearAndDestroy();
return error();
}
std::string path = getPath();
Space space = getSpace();
UT_String shapeFilterStr;
evalString( shapeFilterStr, pShapeFilter.getToken(), 0, 0 );
UT_StringMMPattern shapeFilter;
shapeFilter.compile( shapeFilterStr );
UT_String p( "P" );
UT_String attributeFilter;
evalString( attributeFilter, pAttributeFilter.getToken(), 0, 0 );
if ( !p.match( attributeFilter ) )
{
attributeFilter += " P";
}
ConstSceneInterfacePtr scene = this->scene( file, path );
if ( !scene )
{
addError( SOP_ATTRIBUTE_INVALID, ( path + " is not a valid location in " + file ).c_str() );
gdp->clearAndDestroy();
return error();
}
MurmurHash hash;
hash.append( file );
hash.append( path );
hash.append( space );
hash.append( shapeFilterStr );
hash.append( attributeFilter );
if ( !m_loaded || m_hash != hash )
{
gdp->clearAndDestroy();
}
Imath::M44d transform = ( space == World ) ? worldTransform( file, path, context.getTime() ) : Imath::M44d();
SceneInterface::Path rootPath;
scene->path( rootPath );
loadObjects( scene, transform, context.getTime(), space, shapeFilter, attributeFilter.toStdString(), rootPath.size() );
m_loaded = true;
m_hash = hash;
return error();
}
示例2: readLock
OP_ERROR
GusdOBJ_usdcamera::_Cook(OP_Context& ctx)
{
_LoadCamera(ctx.getTime(), ctx.getThread());
/* XXX: There's a potential race condition here, between
loading and stealing cached errors.
Would be better to keep the camera cache locked
until the error stealing is done.*/
UT_AutoReadLock readLock(_lock);
stealErrors(_errors, /*borrow*/ true);
return error();
}
示例3: errMgr
OP_ERROR
GusdSOP_usdimport::_Cook(OP_Context& ctx)
{
fpreal t = ctx.getTime();
UT_String traversal;
evalString( traversal, "import_traversal", 0, t );
ErrorChoice errorMode = static_cast<ErrorChoice>(evalInt("missingframe", 0, t ));
auto lockedMgr = getLockedErrorManager();
GusdUT_ErrorManager errMgr(*lockedMgr);
GusdUT_ErrorContext errContext(errMgr,
errorMode == MISSINGFRAME_WARN ? UT_ERROR_WARNING : UT_ERROR_ABORT);
const GusdUSD_Traverse* trav = NULL;
if(traversal != _NOTRAVERSE_NAME) {
const auto& table = GusdUSD_TraverseTable::GetInstance();
trav = table.FindTraversal(traversal);
if(!trav) {
UT_WorkBuffer buf;
buf.sprintf("Failed locating traversal '%s'", traversal.c_str());
return errContext.AddError(buf.buffer());
}
}
return getInput(0) ? _ExpandPrims(ctx, trav, errContext)
: _CreateNewPrims(ctx, trav, errContext);
}
示例4: rng
OP_ERROR
GusdSOP_usdimport::_ExpandPrims(OP_Context& ctx,
const GusdUSD_Traverse* traverse,
GusdUT_ErrorContext& err)
{
if(!traverse)
return UT_ERROR_NONE; // Nothing to do!
fpreal t = ctx.getTime();
// Construt a range and bind prims.
bool packedPrims = !evalInt("import_class", 0, t);
GA_AttributeOwner owner = packedPrims ?
GA_ATTRIB_PRIMITIVE : GA_ATTRIB_POINT;
GA_Range rng(gdp->getIndexMap(owner),
UTverify_cast<const GA_ElementGroup*>(_group));
UT_Array<UsdPrim> rootPrims;
GusdDefaultArray<UsdTimeCode> times;
GusdDefaultArray<GusdPurposeSet> purposes;
{
GusdStageCacheReader cache;
if(!GusdGU_USD::BindPrims(cache, rootPrims, *gdp, rng,
/*variants*/ nullptr,
&purposes, ×, &err)) {
return err();
}
}
if(!times.IsVarying())
times.SetConstant(evalFloat("import_time", 0, t));
// Traverse to find a new prim selection.
UT_Array<GusdUSD_Traverse::PrimIndexPair> expandedPrims;
{
UT_UniquePtr<GusdUSD_Traverse::Opts> opts(traverse->CreateOpts());
if(opts) {
if(!opts->Configure(*this, t))
return err();
}
if(!traverse->FindPrims(rootPrims, times, purposes, expandedPrims,
/*skip root*/ true, opts.get()))
return err();
}
GA_AttributeFilter filter(GA_AttributeFilter::selectPublic());
GusdGU_USD::AppendExpandedRefPoints(
*gdp, *gdp, rng, expandedPrims, filter,
GUSD_PATH_ATTR, GUSD_PRIMPATH_ATTR, &err);
if(evalInt("import_delold", 0, t)) {
if(packedPrims)
gdp->destroyPrimitives(rng, /*and points*/ true);
else
gdp->destroyPoints(rng); // , GA_DESTROY_DEGENERATE);
}
return err();
}
示例5: cookMySop
OP_ERROR SOP_Density::cookMySop(OP_Context &context)
{
//Lock inputs and cehck everything is ok
OP_AutoLockInputs inputs(this);
if (inputs.lock(context) >= UT_ERROR_ABORT){
return error();
}
// duplicate source from input 0
duplicateSource(0,context);
flags().timeDep = 1;
//Varaibles
fpreal ctime = context.getTime();//ctime is the currrent time e.g frame 1020 in a 24fps project is 1020.0/24 = 42.666666667
float radius = SOP_Density::RADIUS(ctime);
int neighbours = SOP_Density::NEIGHBOURS(ctime);
UT_String attrstr;
SOP_Density::ATTRIBNAME(attrstr,ctime);
//create the actual attribute to store the density
GA_RWHandleF densityAttr(gdp->addFloatTuple(GA_ATTRIB_POINT,attrstr,1));
//create ppoint tree object
GEO_PointTreeGAOffset pointtree;
pointtree.build(gdp,NULL);
GA_Offset ptoff;
GA_FOR_ALL_PTOFF(gdp,ptoff){
GEO_PointTree::IdxArrayType pointlist; //generate array to put points from ptree in
GEO_PointTree::IdxArrayType distancelist; // generate array to put distance from ptree
UT_Vector3 pos = gdp->getPos3(ptoff); //vector pos for points current position
UT_FloatArray distance; //Array to store the calculated distance
//ptree.findAllCloseIdx(pos,radius,pointlist) //find all points within the given radius
int numclosept = pointtree.findNearestGroupIdx(pos,radius,neighbours,distancelist,distance);
float weight = 1.0/numclosept;
float sum = 0.0; //total sum of distance
for(int i = 0;i<numclosept;++i){
sum += distance(i);
}
sum *= weight;
if(numclosept >= 1){
densityAttr.set(ptoff,sum);
}else{
densityAttr.set(ptoff,-1.0);
}
}
示例6: ctm
int
GusdOBJ_usdcamera::applyInputIndependentTransform(OP_Context& ctx, UT_DMatrix4& mx)
{
mx.identity();
fpreal t = ctx.getTime();
if(UsdGeomCamera cam = _LoadCamera(t, ctx.getThread()))
{
float frame = evalFloat(_frameIdx, 0, t);
GfMatrix4d ctm(1.);
bool stat = true;
bool resetsXformStack = false;
switch(evalInt("xformmode", 0, t))
{
case _POSTMULTCTM_TRANSFORM:
stat = true;
ctm = cam.ComputeLocalToWorldTransform(frame);
break;
case _CTM_TRANSFORM:
stat = true;
ctm = cam.ComputeParentToWorldTransform(frame);
break;
case _OBJ_TRANSFORM:
// XXX: how do we reset xformStack here?
// Is that (or should that
// be) handled by the Compute calls above?
stat = cam.GetLocalTransformation(&ctm, &resetsXformStack, frame);
break;
default: // _IGNORE_TRANSFORM:
stat = true;
ctm.SetIdentity();
break;
}
if(!stat)
{
stealErrors(_errors, /*borrow*/ true);
return 0;
}
mx = GusdUT_Gf::Cast(ctm);
}
return OBJ_Camera::applyInputIndependentTransform(ctx, mx);
}
示例7: getStringParam
std::string getStringParam(OP_Parameters& node, OP_Context &context,
const std::string& label, bool trimspace)
{
UT_String s;
node.evalString(s, label.c_str(), 0, context.getTime());
if(trimspace)
s.trimSpace();
return s.toStdString();
}
示例8: error
OP_ERROR
SOP_Cleave::cookMySop(OP_Context &context)
{
const GA_PrimitiveGroup *polyGroup;
GEO_Primitive *prim;
GQ_Detail *gqd;
int i,j,k;
UT_Vector4 np,p;
// 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();
float now = context.getTime();
duplicateSource(0, context, 0, 1);
// Here we determine which groups we have to work on. We only
// handle poly groups.
UT_String groups;
getGroups(groups);
if (groups.isstring()) polyGroup = parsePrimitiveGroups(groups);
else polyGroup = 0;
if (error() >= UT_ERROR_ABORT) {
unlockInputs();
return error();
}
UT_Interrupt* boss = UTgetInterrupt();
// Start the interrupt server
boss->opStart("Cleaving Polys");
// separate out all polys to be cleaved
GA_PrimitiveGroup* cleave_group = gdp->newPrimitiveGroup("cleave",1);
GA_PrimitiveGroup* not_cleave_group = gdp->newPrimitiveGroup("not_cleave",1);
if (polyGroup) {
GA_FOR_ALL_PRIMITIVES(gdp,prim)
{
if ( (prim->getTypeId()==GEO_PRIMPOLY) && (polyGroup->contains(prim)!=0))
cleave_group->add(prim);
else
not_cleave_group->add(prim);
}
} else {
示例9: error
OP_ERROR
SOP_PrimGroupCentroid::cookMySop(OP_Context &context)
{
fpreal now;
int method, mode;
now = context.getTime();
if (lockInputs(context) >= UT_ERROR_ABORT)
return error();
// The partitioning mode.
mode = MODE(now);
// Find out which calculation method we are attempting.
method = METHOD(now);
// Binding geometry.
if (nConnectedInputs() == 2)
{
// Duplicate the source.
duplicateSource(0, context);
// Bind to the centroids. If the function returns 1, unlock
// the inputs and return.
if (bindToCentroids(now, mode, method))
{
unlockInputs();
return error();
}
}
// Creating centroids.
else
{
// Clear out any previous data.
gdp->clearAndDestroy();
// Build the centroids. If the function returns 1, unlock
// the inputs and return.
if (buildCentroids(now, mode, method))
{
unlockInputs();
return error();
}
}
unlockInputs();
return error();
}
示例10: cookMySop
/* ******************************************************************************
* Function Name : cookMySop()
*
* Description : Cook this SOP node
*
* Input Arguments : None
*
* Return Value : OP_ERROR
*
***************************************************************************** */
OP_ERROR SOP_RF_Import::cookMySop(OP_Context & context)
{
char GUI_str[128];
OP_ERROR myError;
float now = context.getTime();
OP_Node::flags().timeDep = 1;
myTotalPoints = 0; // Set the NPT local variable value
myCurrPoint = 0; // Initialize the PT local variable
FNAME(myFileName, now);
myFileType = FTYPE(now);
disableParms();
sprintf(GUI_str, "%s", "");
setString((UT_String)GUI_str, CH_STRING_LITERAL, ARG_RF_IMPORT_VER, 0, now);
setString((UT_String)GUI_str, CH_STRING_LITERAL, ARG_RF_IMPORT_INFO1, 0, now);
setString((UT_String)GUI_str, CH_STRING_LITERAL, ARG_RF_IMPORT_INFO2, 0, now);
sprintf(GUI_str, "Version: %s", SOP_Version.c_str());
setString((UT_String)GUI_str, CH_STRING_LITERAL, ARG_RF_IMPORT_INFO3, 0, now);
#ifdef DEBUG
std::cout << "cookMySop() - myFileType = " << myFileType << endl;
#endif
switch(myFileType) {
case 0:
myError = ReadRFParticleFile(context);
break;
case 1:
myError = ReadRFMeshFile(context);
break;
case 2:
myError = ReadRFSDFile(context);
break;
case 3:
myError = ReadRFRWCFile(context);
break;
default:
return error();
}
myCurrPoint = -1;
return myError;
}
示例11: cookInputAllGroups
OP_ERROR
GusdSOP_usdimport::cookInputGroups(OP_Context& ctx, int alone)
{
if(!getInput(0))
return UT_ERROR_NONE;
int groupIdx = getParmList()->getParmIndex("import_group");
int classIdx = getParmList()->getParmIndex("import_class");
bool packedPrims = !evalInt(classIdx, 0, ctx.getTime());
GA_GroupType groupType = packedPrims ?
GA_GROUP_PRIMITIVE : GA_GROUP_POINT;
return cookInputAllGroups(ctx, _group, alone,
/* do selection*/ true,
groupIdx, classIdx, groupType);
}
示例12: cookMySop
/// Cook the SOP! This method does all the work
OP_ERROR SOP_ProceduralHolder::cookMySop( OP_Context &context )
{
IECore::MessageHandler::Scope handlerScope( getMessageHandler() );
// some defaults and useful variables
float now = context.getTime();
// force eval of our nodes parameters with our hidden parameter expression
evalInt( "__evaluateParameters", 0, now );
// update parameters on procedural from our Houdini parameters
IECore::ParameterisedProceduralPtr procedural = IECore::runTimeCast<IECore::ParameterisedProcedural>( getParameterised() );
// check for a valid parameterised on this SOP
if ( !procedural )
{
UT_String msg( "Procedural Holder has no parameterised class to operate on!" );
addError( SOP_MESSAGE, msg );
return error();
}
if( lockInputs(context) >= UT_ERROR_ABORT )
{
return error();
}
// start our work
UT_Interrupt *boss = UTgetInterrupt();
boss->opStart("Building ProceduralHolder Geometry...");
gdp->clearAndDestroy();
setParameterisedValues( now );
ToHoudiniCortexObjectConverterPtr converter = new ToHoudiniCortexObjectConverter( procedural );
if ( !converter->convert( myGdpHandle ) )
{
addError( SOP_MESSAGE, "Unable to store procedural on gdp" );
}
// tidy up & go home!
boss->opEnd();
unlockInputs();
return error();
}
示例13: rain
OP_ERROR
SOP_Rain::cookMySop(OP_Context &context)
{
//UT_Interrupt *boss;
if (error() < UT_ERROR_ABORT)
{
//boss = UTgetInterrupt();
//boss->opStart("Start generating rain");
fpreal now = TIME(context.getTime());
long nPoints = NPOINTS( now );
UT_Vector3 rainDirection = RAINDIRECTION(now);
//rainDirection.normalize(); //TODO: check for (0,0,0) vector
RainData rain( now,
nPoints, BOUNDMIN (now), BOUNDMAX (now),
rainDirection,
DICEMIN(now), DICEMAX(now), SEED(now),
SPEED (now),
SPEEDVARIENCE (now));
if(rain.getAllocationState() == false || isPointsNumberChanged_ == true)
{
rain.allocate(nPoints);
}
if( rain.getAllocationState() == true &&
( rain.getCachedState() == false || isParameterChanged_ == true ) )
{
rain.computeInitialPositions();
rain.setCachedState(true);
}
if (isPointsGenerated_ == false)
{
printf("Generate Points procedure\n");
gdp->clearAndDestroy();
generatePoints(gdp, nPoints);
isPointsGenerated_ = true;
}
for ( GA_Iterator pr_it(gdp->getPrimitiveRange());
!pr_it.atEnd();
++pr_it)
{
GEO_Primitive* prim = gdp->getGEOPrimitive(*pr_it);
GA_Range range = prim->getPointRange();
rain.shiftPositions( gdp, range);
}
//boss->opEnd();
}
isParameterChanged_ = false;
isPointsNumberChanged_ = false;
//unlockInputs();
return error();
}
示例14: cookMySop
OP_ERROR SOP_AddEdges::cookMySop(OP_Context &context)
{
typedef dgal::simple_mesh<Imath::V3f> simple_mesh;
typedef dgal::EdgeIntersection<unsigned int, float> edge_intersection;
typedef std::pair<unsigned int, unsigned int> edge_type;
hdk_utils::ScopedCook scc(*this, context, "Performing edges add");
if(!scc.good())
return error();
double now = context.getTime();
// inputs
const GU_Detail* gdp0 = inputGeo(0);
if (!gdp0 ) {
SOP_ADD_FATAL(SOP_MESSAGE, "Not enough sources specified.");
}
unsigned int npoints0 = gdp0->points().entries();
UT_String edgesAttrib;
evalString(edgesAttrib, "edges_string", 0, now);
std::string edgesAttribStr = edgesAttrib.toStdString();
std::vector<std::string> toks;
pystring::split(edgesAttribStr, toks);
if(toks.empty())
{
duplicateSource(0, context);
return error();
}
simple_mesh m, m2;
simple_mesh* pm = NULL;
std::vector<int> points_remap;
std::vector<int> polys_remap;
dgal::MeshRemapSettings<int> remap_settings(true, true, true, 0, 0, &points_remap, &polys_remap);
std::map<std::string, unsigned int> new_points;
// create new points
{
std::vector<edge_intersection> edgeints;
std::string s = pystring::replace(edgesAttribStr, ",", " ");
std::vector<std::string> toks;
pystring::split(s, toks);
for(unsigned int i=0; i<toks.size(); ++i)
{
// new point will be in form 'X-Y:f'
if(toks[i].find('-') != std::string::npos)
{
s = pystring::replace(toks[i], "-", " ");
s = pystring::replace(s, ":", " ");
std::istringstream strm(s);
edge_intersection ei;
try {
strm >> ei.m_point1 >> ei.m_point2 >> ei.m_u;
}
catch(const std::exception&) {
continue;
}
new_points[toks[i]] = npoints0 + edgeints.size();
edgeints.push_back(ei);
}
}
if(new_points.empty())
{
// no new points means no point remapping
remap_settings.m_genPointRemapping = false;
remap_settings.m_identity_point_mapping = true;
}
else
{
dgal::addMeshPoints<GEO_Detail, std::vector<edge_intersection>::const_iterator>(
*gdp0, m, edgeints.begin(), edgeints.end(), &points_remap, &polys_remap);
pm = &m;
}
}
示例15: cookMySop
OP_ERROR SOP_SceneCacheSource::cookMySop( OP_Context &context )
{
// make sure the state is valid
if ( boost::indeterminate( m_static ) )
{
sceneChanged();
}
flags().setTimeDep( bool( !m_static ) );
std::string file;
if ( !ensureFile( file ) )
{
addError( SOP_ATTRIBUTE_INVALID, ( file + " is not a valid .scc" ).c_str() );
gdp->clearAndDestroy();
return error();
}
std::string path = getPath();
Space space = getSpace();
GeometryType geometryType = (GeometryType)this->evalInt( pGeometryType.getToken(), 0, 0 );
UT_String shapeFilterStr;
evalString( shapeFilterStr, pShapeFilter.getToken(), 0, 0 );
UT_StringMMPattern shapeFilter;
shapeFilter.compile( shapeFilterStr );
UT_String p( "P" );
UT_String attributeFilter;
evalString( attributeFilter, pAttributeFilter.getToken(), 0, 0 );
if ( !p.match( attributeFilter ) )
{
attributeFilter += " P";
}
ConstSceneInterfacePtr scene = this->scene( file, path );
if ( !scene )
{
addError( SOP_ATTRIBUTE_INVALID, ( path + " is not a valid location in " + file ).c_str() );
gdp->clearAndDestroy();
return error();
}
MurmurHash hash;
hash.append( file );
hash.append( path );
hash.append( space );
hash.append( shapeFilterStr );
hash.append( attributeFilter );
hash.append( geometryType );
hash.append( getObjectOnly() );
if ( !m_loaded || m_hash != hash )
{
gdp->clearAndDestroy();
}
Imath::M44d transform = ( space == World ) ? worldTransform( file, path, context.getTime() ) : Imath::M44d();
SceneInterface::Path rootPath;
scene->path( rootPath );
UT_Interrupt *progress = UTgetInterrupt();
if ( !progress->opStart( ( "Cooking objects for " + getPath() ).c_str() ) )
{
addError( SOP_ATTRIBUTE_INVALID, "Cooking interrupted before it started" );
gdp->clearAndDestroy();
return error();
}
loadObjects( scene, transform, context.getTime(), space, shapeFilter, attributeFilter.toStdString(), geometryType, rootPath.size() );
if ( progress->opInterrupt( 100 ) )
{
addError( SOP_ATTRIBUTE_INVALID, "Cooking interrupted" );
gdp->clearAndDestroy();
m_loaded = false;
m_hash = MurmurHash();
}
else
{
m_loaded = true;
m_hash = hash;
}
progress->opEnd();
return error();
}