Пример #1
0
vctDynamicNArray<unsigned char,3> osaOSGStereo::GetRGBPlanarImage(size_t idx){
    
    // Get the left/right slave
    const osg::View::Slave& slave = getSlave( idx );
    osg::Camera* camera = slave._camera.get();
    
    // get the camera final draw callback
    osg::Camera::DrawCallback* dcb = NULL;
    dcb = camera->getFinalDrawCallback();
    
    osg::ref_ptr<osg::Referenced> ref = dcb->getUserData();
    osg::ref_ptr<osaOSGCamera::FinalDrawCallback::Data> data = NULL;
    data = dynamic_cast<osaOSGCamera::FinalDrawCallback::Data*>( ref.get() );
    if( data != NULL ){
        data->RequestRGBImage();
        osaSleep( 1.0 );
        cv::Mat rgbimage = data->GetRGBImage();
        cv::Size size = rgbimage.size();
        
        vctDynamicNArray<unsigned char, 3> x;
        x.SetSize( vctDynamicNArray<unsigned char, 3>::nsize_type( size.height, 
                                                                   size.width, 3 ) );
        memcpy( x.Pointer(), 
                rgbimage.ptr<unsigned char>(), 
                size.height*size.width*3 );
        
        return x;
    }
    return vctDynamicNArray<unsigned char, 3>();
}
Пример #2
0
    HostAndPort ReplicaSetMonitor::getSlave( const HostAndPort& prev ) {
        // make sure its valid 
        if ( prev.port() > 0 ) {
            scoped_lock lk( _lock );
            for ( unsigned i=0; i<_nodes.size(); i++ ) {
                if ( prev != _nodes[i].addr ) 
                    continue;

                if ( _nodes[i].ok ) 
                    return prev;
                break;
            }
        }
        
        return getSlave();
    }
Пример #3
0
cv::Mat osaOSGStereo::GetRGBImage( size_t idx ) {
    
    // Get the left/right slave
    const osg::View::Slave& slave = getSlave( idx );
    osg::ref_ptr< osg::Camera > camera = slave._camera.get();
    
    osg::ref_ptr< osg::Camera::DrawCallback > dcb;
    dcb = getCamera()->getFinalDrawCallback();
    
    // 
    osg::ref_ptr<osg::Referenced> ref = dcb->getUserData();
    osg::ref_ptr<osaOSGCamera::FinalDrawCallback::Data> data = NULL;
    data = dynamic_cast<osaOSGCamera::FinalDrawCallback::Data*>( ref.get() );
    if( data != NULL ){
        data->RequestRGBImage();
        osaSleep( 1.0 );
        return data->GetRGBImage();
    }
    return cv::Mat();
    
}
Пример #4
0
void osaOSGStereo::Initialize( const std::string& name ){
    
    // Create the graphic context traits. The reason why this is here is because
    // Windows somehow requires the context to be allocated within the same 
    // thread as the rendering thread. And this method is called within the 
    // camera thread
    {
        
        osg::ref_ptr<osg::GraphicsContext::Traits> traits;
        traits = new osg::GraphicsContext::Traits;
        traits->readDISPLAY();
        traits->x = x + 0;
        traits->y = y + 0;
        traits->width = width;
        traits->height = height;
        traits->windowName = name + std::string( "LEFT" );

        traits->windowDecoration = true;
        traits->doubleBuffer = true;
        traits->sharedContext = 0;
        
        // slave "0" is the first slave. In this case the "left" camera
        osg::View::Slave& slave = getSlave( osaOSGStereo::LEFT );
        osg::Camera* camera = slave._camera.get();
        
        osg::ref_ptr<osg::GraphicsContext> gc;
        gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
        camera->setGraphicsContext( gc.get() );
        
        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
        camera->setDrawBuffer( buffer );
        camera->setReadBuffer( buffer );
        camera->setClearColor( osg::Vec4d( 0.0, 0.0, 0.0, 0.0 ) );
        if( 0 < huds.size() )
            { huds[0]->Initialize( gc.get() ); }      
    }
    
    {
        
        osg::ref_ptr<osg::GraphicsContext::Traits> traits;
        traits = new osg::GraphicsContext::Traits;
        traits->readDISPLAY();
        traits->x = x + width;
        traits->y = y + 0;
        traits->width = width;
        traits->height = height;
        traits->windowName = name + std::string( "RIGHT" );

        traits->windowDecoration = true;
        traits->doubleBuffer = true;
        traits->sharedContext = 0;
        
        // slave "1" is the second slave. In this case the "right" camera
        osg::View::Slave& slave = getSlave( osaOSGStereo::RIGHT );
        osg::Camera* camera = slave._camera.get();
        
        osg::ref_ptr<osg::GraphicsContext> gc;
        gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
        camera->setGraphicsContext( gc.get() );
        
        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
        camera->setDrawBuffer(buffer);
        camera->setReadBuffer(buffer);
        camera->setClearColor( osg::Vec4d( 0.0, 0.0, 0.0, 0.0 ) );
        if( 1 < huds.size() )
            { huds[1]->Initialize( gc.get() ); }      
        
    }
    
}