My bad,<br><br>I must admit that I actually don't know how to simply "reply" to a thread.  <br>anyway, here is my code : <br><br><br>void COSGMesh::Initialization(void)<br>{<br><br><br>    mp_RootNode = new osg::Group;<br>
<br>    mp_MeshGroup = new osg::Group;<br><br>    mp_InternalMatrixTransform = new osg::MatrixTransform;<br><br><br><br><br>//    osg::ref_ptr<osg::ShapeDrawable> Target (new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3f(),0.1f,0.1f)));<br>
//    osg::ref_ptr<osg::Geode> TargetGeode (new osg::Geode);<br>//    TargetGeode->addDrawable(Target.get());<br>//    mp_ModelMatrixTransform->addChild(TargetGeode.get());<br><br>    osg::ref_ptr<osg::Node> scene = osgDB::readNodeFile("./Data/11man-3d-headbold.osg");<br>
    if (!scene) scene = osgDB::readNodeFile("../Data/11man-3d-headbold.osg");<br>    if (!scene)<br>    {<br>        std::cerr << "No Mesh DAta available EXITING. please check data folder" << std::endl;<br>
        exit (EXIT_FAILURE);<br><br>    }<br><br><br>    const osg::BoundingSphere& bs = scene->getBound();<br><br>     float size = DEF_MESH_REAL_INIT_MAX_RADIUS/bs.radius();<br><br>     mp_InternalMatrixTransform = new osg::MatrixTransform;<br>
     mp_InternalMatrixTransform->setDataVariance(osg::Object::STATIC);<br>     mp_InternalMatrixTransform->setMatrix(osg::Matrix::translate(-bs.center())*<br>                                  osg::Matrix::scale(size*DEF_X_SIZE_MODIF_FACTOR,<br>
                                                      size*DEF_Z_SIZE_MODIF_FACTOR,<br>                                                      size*DEF_Y_SIZE_MODIF_FACTOR));<br><br>                                  // osg::Matrix::rotate(osg::inDegrees(0.0f),0.0f,0.0f,1.0f));<br>
<br>     mp_InternalMatrixTransform->addChild(scene.get());<br><br>     mp_ExternalPAT = new osg::PositionAttitudeTransform;<br>     mp_ExternalPAT->addChild(mp_InternalMatrixTransform);<br><br><br><br>     mp_ExternalPAT->setPosition(osg::Vec3d(mp_CurrT->data.db[0],mp_CurrT->data.db[2],-mp_CurrT->data.db[1]));<br>
     mp_ExternalPAT->setAttitude(osg::Quat(cvNorm(mp_CurrRvect),<br>                                        osg::Vec3d(mp_CurrRvect->data.db[0],<br>                                                  mp_CurrRvect->data.db[2],<br>
                                                  -mp_CurrRvect->data.db[1])<br>                                             )<br>                                 );<br><br><br><br><br><br>     mp_RootNode->addChild(mp_ExternalPAT);<br>
<br><br><br><br>    m_Optimizer.optimize(mp_RootNode);<br><br>    // set the scene to render<br>    m_Viewer.setSceneData(mp_RootNode);<br><br><br><br><br>    m_Viewer.setCameraManipulator(new osgGA::TrackballManipulator());<br>
<br>}<br><br><br><br>void COSGMesh::SetCameraMatrix(IntrinseqParameters IntraParameters)<br>{<br><br>    CreateMatOnDemand(&K, cvSize(3,3), CV_64FC1);<br>    cvSetZero(K);<br>    CreateMatOnDemand(&K_inv, cvSize(3,3), CV_64FC1);<br>
    cvSetZero(K_inv);<br><br>    K->data.db[0]    =    IntraParameters.m_FocLength/IntraParameters.m_UPixSize;<br>    K->data.db[2]    =    IntraParameters.m_U0;<br>    K->data.db[4]    =    IntraParameters.m_FocLength/IntraParameters.m_VPixSize;<br>
    K->data.db[5]    =    IntraParameters.m_V0;<br>    K->data.db[8]    =    1.;<br><br>    cvInvert(K,K_inv);<br><br>    m_CameraIntraParam = IntraParameters ;<br><br><br>    if (mp_VirtualCamera == NULL)<br>        mp_VirtualCamera =  new osg::Camera;<br>
<br>    if (mp_ViewerCamera == NULL)<br>        mp_ViewerCamera =  new osg::Camera;<br><br><br><br>    // Recuperation parametres "intrinseques"<br><br>    double fovy = (180./CV_PI)*2.  * ((CV_PI/2.)<br>        -atan(2.*(m_CameraIntraParam.m_FocLength/m_CameraIntraParam.m_VPixSize)/m_SimImageSize.height));<br>
    double aspectRatio = ((m_SimImageSize.width * m_CameraIntraParam.m_UPixSize)<br>                            /(m_SimImageSize.height * m_CameraIntraParam.m_VPixSize));<br>    int xoffset = cvRound(m_CameraIntraParam.m_U0 - (double)m_SimImageSize.width/2.);<br>
    int yoffset = cvRound(((double)m_SimImageSize.height/2.) - m_CameraIntraParam.m_V0);<br><br>    double zNear = DEF_ZNEAR;   // 10 cm<br>    double zFar    =  DEF_ZFAR;      // 5 m<br><br>    std::cout << fovy << std::endl;<br>
    std::cout << aspectRatio << std::endl;<br>    std::cout << xoffset << std::endl;<br>    std::cout << yoffset << std::endl;<br>    std::cout << zNear << std::endl;<br>    std::cout << zFar << std::endl;<br>
<br><br>    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;<br>    traits->x = xoffset + 0;<br>    traits->y = yoffset + 0;<br>    traits->width = m_SimImageSize.width;<br>
    traits->height = m_SimImageSize.height;<br>    traits->windowDecoration = true;<br>    traits->doubleBuffer = false;<br>    traits->sharedContext = 0;<br>    traits->windowName = " Viewer Cam";<br>
<br>    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());<br><br>    mp_ViewerCamera->setGraphicsContext(gc.get());<br>    mp_ViewerCamera->setViewport(new osg::Viewport(xoffset,yoffset, traits->width, traits->height));<br>
<br>    traits->x += m_SimImageSize.width;<br>    traits->windowName = "Virtual Cam";<br><br>    osg::ref_ptr<osg::GraphicsContext> gc_2 = osg::GraphicsContext::createGraphicsContext(traits.get());<br>
<br>    mp_VirtualCamera->setGraphicsContext(gc_2.get());<br>    mp_VirtualCamera->setViewport(new osg::Viewport(xoffset,yoffset, traits->width, traits->height));<br><br><br>    mp_VirtualCamera->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f));<br>
    mp_VirtualCamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);<br><br><br><br>  // set up projection.<br><br>      // set view<br>  mp_VirtualCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);<br>
  //m_VirtualCamera->setViewMatrixAsLookAt(bs.center()-osg::Vec3(0.0f,2.0f,0.0f)*bs.radius(),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));<br><br>  mp_VirtualCamera->setViewMatrixAsLookAt(osg::Vec3(0.0f, 0.0f,0.0f),osg::Vec3(0.0f,2.0f,0.0f),osg::Vec3(0.0f,0.0f,1.0f));<br>
  mp_VirtualCamera->setProjectionMatrixAsPerspective(fovy,aspectRatio,zNear,zFar);<br><br><br><br>  // set the m_VirtualCamera to render before the main Camera.<br>  mp_VirtualCamera->setRenderOrder(osg::Camera::PRE_RENDER);<br>
 <br><br> //mp_VirtualCamera->setRenderTargetImplementation(osg::Camera::SEPERATE_WINDOW);<br>  mp_VirtualCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);<br><br><br><br><br>  mp_Image = new osg::Image;<br>
  //image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE);<br>  mp_Image->allocateImage(m_SimImageSize.width, m_SimImageSize.height, 1, GL_DEPTH_COMPONENT, GL_FLOAT);<br><br>  // attach the image so its copied on each frame.<br>
  unsigned int samples = 0;<br>  unsigned int colorSamples = 0;<br>  mp_VirtualCamera->attach(osg::Camera::DEPTH_BUFFER, mp_Image, samples, colorSamples);<br><br><br>  m_Viewer.addSlave(mp_ViewerCamera, osg::Matrixd(), osg::Matrixd());<br>
<br><br>  mp_VirtualCamera->addChild(mp_ExternalPAT);<br><br>  mp_RootNode->addChild(mp_VirtualCamera);<br><br>  allocateOnDemand(&mp_Z_Buffer,m_SimImageSize,IPL_DEPTH_32F,1);<br><br><br>}<br><br><br><br><br><br>
void COSGMesh::SetCurrentROI(void)<br>{<br>    double FocalLengthNorm = K->data.db[0];<br>    double XPixOpticalAxePosition = K->data.db[2];<br>    double YPixOpticalAxePosition = K->data.db[5];<br><br>    double MIN_X = mp_CurrT->data.db[0] - DEF_MESH_REAL_INIT_MAX_RADIUS;<br>
    double MIN_Y = mp_CurrT->data.db[1] - DEF_MESH_REAL_INIT_MAX_RADIUS;<br>    double MIN_Z = mp_CurrT->data.db[2] - DEF_MESH_REAL_INIT_MAX_RADIUS;<br><br>    double MAX_X = mp_CurrT->data.db[0] + DEF_MESH_REAL_INIT_MAX_RADIUS;<br>
    double MAX_Y = mp_CurrT->data.db[1] + DEF_MESH_REAL_INIT_MAX_RADIUS;<br><br>    double MIN_U = FocalLengthNorm * MIN_X/MIN_Z + XPixOpticalAxePosition;<br>    double MIN_V = FocalLengthNorm * MIN_Y/MIN_Z + YPixOpticalAxePosition;<br>
    double MAX_U = FocalLengthNorm * MAX_X/MIN_Z + XPixOpticalAxePosition;<br>    double MAX_V = FocalLengthNorm * MAX_Y/MIN_Z + YPixOpticalAxePosition;<br><br>    m_CurrentROI = cvRect(cvRound(MIN_U),cvRound(MIN_V),cvRound(MAX_U-MIN_U),cvRound(MAX_V-MIN_V));<br>
<br><br><br><br>}<br><br><br><br><br>void COSGMesh::SetCurrentTransform(CvMat * R, CvMat *T)<br>{<br><br>    if (R->cols * R->rows == 9)<br>    {<br>        cvCopy(R, mp_CurrRmat);<br>        cvRodrigues2(R , mp_CurrRvect);<br>
    }<br>    else<br>    {<br>        cvCopy(R, mp_CurrRvect);<br>        cvRodrigues2(R , mp_CurrRmat);<br>    }<br><br>    cvCopy(T,mp_CurrT);<br><br><br><br>    mp_ExternalPAT->setPosition(osg::Vec3d(mp_CurrT->data.db[0],mp_CurrT->data.db[2],-mp_CurrT->data.db[1]));<br>
    mp_ExternalPAT->setAttitude(osg::Quat(cvNorm(mp_CurrRvect),<br>                                        osg::Vec3d(mp_CurrRvect->data.db[0],<br>                                                  mp_CurrRvect->data.db[2],<br>
                                                  -mp_CurrRvect->data.db[1])<br>                                            )<br>                                );<br><br><br>    this->SetCurrentROI();<br>    this->apply();<br>
<br>}<br><br><br><br><br>void COSGMesh::AddIncrementalTransform(CvMat * R, CvMat *T)<br>{<br><br>    if (R->cols * R->rows == 9)<br>    {<br>        cvGEMM( R, mp_CurrT, 1., T , 1., mp_CurrT);<br>        cvGEMM(R, mp_CurrRmat,  1.,NULL, 0., mp_CurrRmat);<br>
        cvRodrigues2(mp_CurrRmat , mp_CurrRvect);<br>    }<br>    else<br>    {<br>        cvRodrigues2(R , mp_TmpRotMat);<br>        cvGEMM( mp_TmpRotMat, mp_CurrT, 1., T , 1., mp_CurrT);<br>        cvGEMM(mp_TmpRotMat, mp_CurrRmat,  1.,NULL, 0., mp_CurrRmat);<br>
<br><br>        cvRodrigues2(mp_CurrRmat , mp_CurrRvect);<br>    }<br><br><br>    mp_ExternalPAT->setPosition(osg::Vec3d(mp_CurrT->data.db[0],mp_CurrT->data.db[2],-mp_CurrT->data.db[1]));<br>    mp_ExternalPAT->setAttitude(osg::Quat(cvNorm(mp_CurrRvect),<br>
                                        osg::Vec3d(mp_CurrRvect->data.db[0],<br>                                                  mp_CurrRvect->data.db[2],<br>                                                  -mp_CurrRvect->data.db[1])<br>
                                            )<br>                                );<br><br>    this->SetCurrentROI();<br>    this->apply();<br>}<br><br><br><br><br><br><br><br>void COSGMesh::apply()<br>{<br><br><br>
    mp_Image->dirty();<br>//    m_Viewer.updateTraversal();<br>    m_Viewer.frame();<br><br>}<br><br><br><br>"Initialization" and "SetCameraMatrix" are called by the COSGMesh instance's constructor.<br>
<br>and the use of the instance takes the following form : <br><br><br>while (!done)<br>{<br> // do something <br><br>COSGMesh_instance->AddIncrementalTransform(somerotation, sometranslation);<br>COSGMesh_instance->"GiveMeApointerOn_mp_Image()";    //(actually the depth map)<br>
<br>//do something<br>}<br><br><br>1. - I dont know how to specify that the viewer have to be single-threaded  (shame on me)<br><br>2 - when i try " mp_VirtualCamera->setRenderTargetImplementation(osg::Camera::SEPERATE_WINDOW);" i'm quite surprise to observe <b>two</b> unnamed windows that <b>alternatively</b> display the mp_VirtualCamera view<br>
<br><br>thank you for your patience...<br><br><br><br><br><br><br><br><br><br>