Пример #1
0
void OnlineViewer_impl::load(const char* name_, const char* url)
{
    if (!scene->body(name_)){
        std::cout << "load(" << url << ")" << std::endl;
        OpenHRP::ModelLoader_var ml = hrp::getModelLoader(orb);
        OpenHRP::ModelLoader::ModelLoadOption opt;
        opt.readImage = true;
        opt.AABBdata.length(0);
        opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
        BodyInfo_var binfo = ml->getBodyInfoEx(url, opt);
        GLbody *glbody = new GLbody();
        hrp::BodyPtr body(glbody);
        hrp::loadBodyFromBodyInfo(body, binfo, false, GLlinkFactory);
        body->setName(name_);
        loadShapeFromBodyInfo(glbody, binfo);
        scene->addBody(body);
    }
}
Пример #2
0
void PyLink::addShapeFromFile(std::string url)
{
    RTC::Manager* manager = &RTC::Manager::instance();
    std::string nameServer = manager->getConfig()["corba.nameservers"];
    int comPos = nameServer.find(",");
    if (comPos < 0){
        comPos = nameServer.length();
    }
    nameServer = nameServer.substr(0, comPos);
    RTC::CorbaNaming naming(manager->getORB(), nameServer.c_str());
    
    OpenHRP::ModelLoader_var modelloader = hrp::getModelLoader(CosNaming::NamingContext::_duplicate(naming.getRootContext()));
    OpenHRP::ModelLoader::ModelLoadOption opt;
    opt.readImage = true;
    opt.AABBdata.length(0);
    opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
    OpenHRP::BodyInfo_var binfo = modelloader->getBodyInfoEx(url.c_str(), opt);
    OpenHRP::LinkInfoSequence_var lis = binfo->links();
    loadShapeFromLinkInfo(this, lis[0], binfo, createPyShape);
}
Пример #3
0
int main(int argc, char *argv[])
{
    int wsize=0;
    double maxEdgeLen=0.0;
    bool useDefaultLights=true;
    float bgColor[3]={0,0,0};
    
    for (int i=1; i<argc; i++){
        if (strcmp(argv[i], "-size")==0){
            wsize = atoi(argv[++i]);
        }else if(strcmp(argv[i], "-max-edge-length")==0){
            maxEdgeLen = atof(argv[++i]);
        }else if(strcmp(argv[i], "-no-default-lights")==0){
            useDefaultLights=false;
        }else if(strcmp(argv[i], "-bg")==0){
            bgColor[0] = atof(argv[++i]);
            bgColor[1] = atof(argv[++i]);
            bgColor[2] = atof(argv[++i]);
        }else if(strcmp(argv[i], "-h")==0 || strcmp(argv[i], "--help")==0){
            print_usage(argv[0]);
            return 1;
        }
    }
    
    CORBA::ORB_var orb = CORBA::ORB::_nil();
    
    try {
        
        orb = CORBA::ORB_init(argc, argv);
        
        CORBA::Object_var obj;
        
        obj = orb->resolve_initial_references("RootPOA");
        PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
        if(CORBA::is_nil(poa)){
            throw std::string("error: failed to narrow root POA.");
        }
        
        PortableServer::POAManager_var poaManager = poa->the_POAManager();
        if(CORBA::is_nil(poaManager)){
            throw std::string("error: failed to narrow root POA manager.");
        }
        
        LogManager<OpenHRP::WorldState> log;
        GLscene scene(&log);
        scene.setBackGroundColor(bgColor);
        scene.maxEdgeLen(maxEdgeLen);
        
        OnlineViewer_impl* OnlineViewerImpl 
            = new OnlineViewer_impl(orb, poa, &scene, &log);
        poa->activate_object(OnlineViewerImpl);
        OnlineViewer_var OnlineViewer = OnlineViewerImpl->_this();
        OnlineViewerImpl->_remove_ref();
        
        obj = orb->resolve_initial_references("NameService");
        CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(obj);
        if(CORBA::is_nil(namingContext)){
            throw std::string("error: failed to narrow naming context.");
        }
        
        CosNaming::Name name;
        name.length(1);
        name[0].id = CORBA::string_dup("OnlineViewer");
        name[0].kind = CORBA::string_dup("");
        namingContext->rebind(name, OnlineViewer);

        poaManager->activate();
        
        if (argc >= 2 && argv[1][0] != '-'){
            OpenHRP::ModelLoader_var ml = hrp::getModelLoader(namingContext);
            if (CORBA::is_nil(ml)){
                std::cerr << "openhrp-model-loader is not running" << std::endl;
                return 1;
            }
            OpenHRP::ModelLoader::ModelLoadOption opt;
            opt.readImage = true;
            opt.AABBdata.length(0);
            opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
            GLbody *glbody = new GLbody();
            std::string url = argv[1];
            if (argv[1][0] != '/'){
                char buf[MAXPATHLEN];
                std::string cwd = getcwd(buf, MAXPATHLEN);
                url = cwd + '/' + url;
            }
            hrp::BodyPtr body(glbody);
            body->setName("model");
            OpenHRP::BodyInfo_var binfo = ml->getBodyInfoEx(url.c_str(), opt);
            hrp::loadBodyFromBodyInfo(body, binfo, false, GLlinkFactory);
            loadShapeFromBodyInfo(glbody, binfo);
            scene.addBody(body);
        }
        
        GLlink::useAbsTransformToDraw();
        GLbody::useAbsTransformToDraw();

        SDLwindow window(&scene, &log);
        window.init(wsize, wsize);
        if (!useDefaultLights) scene.defaultLights(false);
        
        while(window.oneStep());
        
    }
    catch(OpenHRP::ModelLoader::ModelLoaderException ex){
        std::cerr << ex.description << std::endl;
    }
    catch (CORBA::SystemException& ex) {
        std::cerr << ex._rep_id() << std::endl;
    }
    catch (const std::string& error){
        std::cerr << error << std::endl;
    }
    
    try {
        orb->destroy();
    }
    catch(...){
        
    }
    
    return 0;
}