Beispiel #1
0
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);
}                           
Beispiel #2
0
UT_ErrorSeverity
GusdTfErrorScope::_Update()
{
    int sev = UT_ERROR_NONE;

    if(_mgr && _sev > UT_ERROR_NONE) {
        auto end = _mark.GetEnd();

        UT_WorkBuffer buf;

        for(auto it = _mark.GetBegin(); it != end; ++it) {

            UT_SourceLocation loc(it->GetSourceFileName().c_str(),
                                  it->GetSourceLineNumber());
            buf.clear();
            // XXX: Not sure what verbosity level we want for errors.
            //      Maybe make it configurable from the environment?
            if(1) {
                _FormatErrorVerbose(it->GetDiagnosticCode(),
                                    it->GetContext(), it->GetCommentary(), buf);
            } else {
                _FormatErrorSimple(it->GetDiagnosticCode(),
                                   it->GetContext(), it->GetCommentary(), buf);
            }
            
            sev = _mgr->addGeneric("Common", UT_ERROR_JUST_STRING,
                                   buf.buffer(), _sev, &loc);
        }
    }
    _mark.Clear();
    return UT_ErrorSeverity(sev);
}
Beispiel #3
0
static void dumpOptions(IMG_DeepShadow &fp) {
	const UT_Options * opt;
	UT_WorkBuffer wbuf;
	if (opt = fp.getTBFOptions()) {
		wbuf.strcpy("DSM Options: ");
		opt->appendPyDictionary(wbuf);
		printf("%s\n", wbuf.buffer());
	}
}
Beispiel #4
0
void CanvasUI::show()
{
    // Null ptr to get the new widget as a window
    QWidget* parent = 0;
    FabricDFGWidgetPtr dfgw(new FabricDFGWidget(parent, &m_view));
    dfgw->setOp(m_op);
    m_view.setWidget(dfgw);
    UT_WorkBuffer opFullName;
    m_op->getFullPath(opFullName);
    dfgw->setWindowTitle(opFullName.buffer());
    dfgw->show();
    dfgw->activateWindow();
}
Beispiel #5
0
UsdPrim
GusdUSD_StageProxy::Accessor::GetPrimAtPath(const SdfPath& path,
                                            GusdUT_ErrorContext* err) const
{
    UT_ASSERT_P(_proxy);

    if(UsdPrim prim = GetStage()->GetPrimAtPath(path))
        return prim;
    if(err) {
        UT_WorkBuffer buf;
        buf.sprintf("Invalid prim <%s>", path.GetString().c_str());
        err->AddError(buf.buffer());
    }
    return UsdPrim();
}
Beispiel #6
0
ratReader::ratReader(Read *r, int fd): Reader(r)
{
    // Init: 
    buffer = NULL;
    loaded = false;
    rat    = NULL;
    use_scanline_engine = true;
    parms = new IMG_FileParms();
    
    // Read knobs:
    ratReaderFormat* rrf = dynamic_cast<ratReaderFormat*>(r->handler());
    if (rrf)
    {
        if (rrf->reverse_scanlines())
            parms->orientImage(IMG_ORIENT_LEFT_FIRST, IMG_ORIENT_TOP_FIRST);

        use_scanline_engine = rrf->use_scanline_engine(); 
    }
    else
        parms->orientImage(IMG_ORIENT_LEFT_FIRST, IMG_ORIENT_Y_NONE);

    // Set some of the settings, which are assumed currently by both ::engines. 
    // Leaving them as they are would require some serious switches in logic bellow.
    parms->setDataType(IMG_FLOAT);
    parms->setInterleaved(IMG_INTERLEAVED);
    parms->setComponentOrder(IMG_COMPONENT_RGBA);
    
    // Create and open rat file, get stats:
    rat = IMG_File::open(r->filename(), parms);

    // TODO: Meta data attempt:
    #if defined(DEBUG)
    UT_String info;
    rat->getAdditionalInfo(info);
    iop->warning("Rat info: %s\n", info.buffer());
    for (int i = 0; i < rat->getNumOptions(); i++)
    {
        iop->warning("%s: %s", rat->getOptionName(i), rat->getOptionValue(i));
    }
    UT_SharedPtr<UT_Options> opt;
    UT_WorkBuffer wbuf;
    if (opt = rat->imageTextureOptions())
    {
        wbuf.strcpy("DSM Options: ");
        opt->appendPyDictionary(wbuf);
        iop->warning("Options %i: %s\n", opt->getNumOptions(), wbuf.buffer());
    }
    #endif
    if (!rat)
    {
        iop->error("Failed to open .rat file.");
    }
    const IMG_Stat &stat = rat->getStat();
    depth = 0;
    #if defined(DEBUG)
    iop->warning("Rat opened: %s", r->filename());
    #endif

    // Since RAT can store varying bitdepth per plane, pixel-byte algebra doesn't 
    // help in finding out a number of channels. We need to iterate over planes. 
    for (int i = 0; i < stat.getNumPlanes(); i++)
    {
        IMG_Plane *plane = stat.getPlane(i);

        // The easiest yet not unequivocal way to determine 2d versus deep RAT files:
        if (!strcmp(plane->getName(), "Depth-Complexity"))
            iop->warning("ratReader will treat DCM files as a 2d images. (ignoring deep pixels)");

        #if defined(DEBUG)
        iop->warning("Plane name: %s", plane->getName());
        #endif
        depth += IMGvectorSize(plane->getColorModel()); 
    } 

    ChannelSet mask;
    for (int i = 0; i < stat.getNumPlanes(); i++)
    {
        IMG_Plane *plane = stat.getPlane(i);
        const int  nchan = IMGvectorSize(plane->getColorModel());

        for (int j = 0; j < nchan; j++)
        {
            std::string chan = std::string(plane->getComponentName(j) ? plane->getComponentName(j): "r"); 

            if      (chan == "r") chan = "red"; 
            else if (chan == "g") chan = "green";
            else if (chan == "b") chan = "blue"; 
            else if (chan == "a") chan = "alpha";

            std::string chan_name = std::string(plane->getName()) + std::string(".") + chan;
            std::set<Channel> channels;
            lookupChannels(channels, chan_name.c_str());

            if (!channels.empty()) 
            {
                for (std::set<Channel>::iterator it = channels.begin(); it != channels.end(); it++) 
                {
                    Channel channel = *it;
                    channel_map[channel]= chan_name.c_str();
                    std::pair<int, int> idx(i, j);
                    rat_chan_index[channel] = idx;
                     
                    #if defined(DEBUG)
                    iop->warning("Rat %s (%i,%i) becomes %s", chan_name.c_str(), i, j, getName(channel));
                    #endif
                    mask += channel;
                }
            }
            else
                iop->warning("Can't create a channel from %s", chan_name.c_str());
        }
    }
    // Set info:
    #if defined(DEBUG)
    iop->warning("Channel number: %i", depth);
    #endif
    set_info(stat.getDataWidth(), stat.getDataHeight(), depth);
    info_.channels(mask);
}
Beispiel #7
0
bool
GusdUSD_StageProxy::_Load(ScopedLock& lock,
                          UsdStage::InitialLoadSet loadSet,
                          const UnorderedPathSet* pathsToLoad,
                          GusdUT_ErrorContext* err)
{
    if(!_microNode.requiresUpdate(0)) {
        /* XXX: Errors copied will currently only include errors,
           not warning. This is because TfErrorMark, which is being used to
           capture USD errors, is currently not able to capture warnings.
           
           This means that in the event that the stage is valid, very little
           work will be done. This is expected to change in Tf eventually,
           in which case every stage lookup may involve an excess amount of
           warning copying on every lookup, possibly impacting performance.
           May need to revisit this approach of copying all errors when Tf
           starts allowing warnings to be captured.*/
        if(err)
            _CopyErrors(*err);

        if(pathsToLoad && _primLoader) {
            if(_primLoader->LoadIfNeeded(lock, *pathsToLoad, _stage,
                                         /*have lock*/ false))
                lock.DowngradeToReader();
        }
        return _stage;
    }
    if(lock.UpgradeToWriter() || _microNode.requiresUpdate(0)) {
        /* Mark the proxy clean, so that we don't attempt to load
           again even if loading has failed. To attempt to reload,
           the node should be dirtied with MarkDirty() prior to
           the next load attempt.*/
        _microNode.update(0);

        _errors.clearAndDestroyErrors();

        GusdUT_ErrorManager errMgr(_errors);
        GusdUT_TfErrorScope scope(errMgr);
        
        if(_stage) {
            /* Asking to load when we already have a stage means
               we should reload the stage.*/
            _Reload(_stage);
            
            lock.DowngradeToReader();

            // XXX: Can reloading fail?
            return true;
        }

        if(SdfLayerRefPtr rootLyr =
           SdfLayer::FindOrOpen(_key->path.GetString())) {
            
            // Load the stage from the cache.
            UsdStageCacheContext ctx(_cache.GetCache());
            if(UsdStageRefPtr stage = UsdStage::Open(
                   rootLyr, _key->sessionLyr, _key->resolverCtx, loadSet)) {
                
                _realPath = TfToken(TfRealPath( _key->path));
                struct stat attrib;
                if( stat(_realPath.GetText(), &attrib) == 0 ) {
                    _mtime = attrib.st_mtime;
                }

                UT_ASSERT(_cache.GetCache().Contains(stage));
                _stage = stage;

                _InitLoadSet(loadSet);
                _stageData.Update(stage);

                if(pathsToLoad && _primLoader) {
                    _primLoader->Load(SdfPathSet(pathsToLoad->begin(),
                                                 pathsToLoad->end()), stage);
                }
            }
        } else {
            /* Sdf doesn't throw errors here, so we need
               to report the failure ourselves.*/
            UT_WorkBuffer buf;
            buf.sprintf("Failed to open layer: %s",
                        _key->path.GetString().c_str());
            GusdUT_LogGenericError(_errors, buf.buffer());
        }
    }
    if(err) 
        _CopyErrors(*err);
    lock.DowngradeToReader();
    return _stage;
}