Re: [osg-users] Screeshots from multiple cameras/views

2010-06-25 Thread Ricky Flintoff

Tom Pearce wrote:
 Ricky,
 
 Based on the code you posted, you're taking a screenshot every frame - and 
 from the same position, no less.  You're creating the same matrix each time, 
 and thus setting the view matrix to be identical each frame.  Then you're 
 doing file I/O that is the exact same too.
 
 When I ran your code without doing all of this on every frame (i.e. returning 
 after the first frame or two) everything seemed to work.  In fact, I also ran 
 it exactly as you'd posted it, and it still executed without error, just very 
 slowly.  I'm not sure where the seg faults are coming from but perhaps you're 
 just bogging stuff down too much since the code isn't really doing something 
 you actually want it to do...?  In principle I don't see a problem with 
 moving the camera from one view to another and taking a picture from two (or 
 more) points - but the way it is set up right now isn't right.  At least, not 
 as I see it.
 
 Cheers,
 Tom

Thank you very much for running my code. I have decided to attack the problem 
by rendering the scene graph and then changing the view matrix in order to 
capture scene from different views. Also, when you ran my code, did you see the 
cow moving or rotating? I just wanted to make sure that you saw that. 
Again, thank you very much for your help.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29412#29412





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Screeshots from multiple cameras/views

2010-06-25 Thread Ricky Flintoff
Hi Robert,

robertosfield wrote:
 Hi Ricky,
 
 On Tue, Jun 22, 2010 at 3:54 AM, Ricky Flintoff  wrote:
 
  Thank you very very much for your suggestion! I actually ran into another 
  problem with the code. I tend to get segmentation faults. My idea was to 
  take multiple pictures as I changed the position of my camera.
  Any way I can get rid of these seg faults?
  
 
 This isn't something we can answer - it's your code, it's your crash,
 we know nothing about what might be causing it.  To get rid of seg
 faults you have use a debugger and work what is going wrong.
 
 Robert.
 ___
 osg-users mailing list
 
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
 
  --
 Post generated by Mail2Forum

Thanks a lot! Also, I was wondering if you know any good debugging tools for 
linux/osg? 
Thanks,
RIcky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29413#29413





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Screeshots from multiple cameras/views

2010-06-22 Thread Robert Osfield
Hi Ricky,

On Tue, Jun 22, 2010 at 3:54 AM, Ricky Flintoff rickyflint...@gmail.com wrote:
 Thank you very very much for your suggestion! I actually ran into another 
 problem with the code. I tend to get segmentation faults. My idea was to take 
 multiple pictures as I changed the position of my camera.
 Any way I can get rid of these seg faults?

This isn't something we can answer - it's your code, it's your crash,
we know nothing about what might be causing it.  To get rid of seg
faults you have use a debugger and work what is going wrong.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Screeshots from multiple cameras/views

2010-06-21 Thread Ricky Flintoff
Hi,

As a solution, I decided to change the viewpoint of the camera and then take 
pictures as I change the viewpoint. However, with the code I have, it's really 
slow (cow rotates very slowly) Any suggestions or ways I can over come this 
problem?


Code:
 
//capture an image of the scenegraph
class CCameraPostDrawCallback: public osg::Camera::DrawCallback {
public:
CCameraPostDrawCallback(const int cX, const int cY, const int w,
const int h, const std::string str) {
centerX = cX;
centerY = cY;
width = w;
height = h;
fileName = str;
}

void operator () (const osg::Camera cam) const {
//take a picture of the scene
osg::ref_ptrosg::Image screenShot = new osg::Image;
screenShot-readPixels(centerX, centerY, width, height, GL_RGB, 
GL_UNSIGNED_BYTE);
osgDB::writeImageFile(*screenShot, fileName);
}
private:
int centerX;
int centerY;
int width;
int height;
std::string fileName;
};

osg::Node* CreateScene() { //add rendering modifications
//load the osg model
osg::Node* loadedModel = osgDB::readNodeFile(cow.osg);
return loadedModel;
}

int main(int argc, char *argv[]) {
osgViewer::Viewer viewer;
viewer.setSceneData(CreateScene());
viewer.getCamera()-setProjectionMatrixAsPerspective(60., 1., 1., 100. );
viewer.setUpViewInWindow(0, 0, 500, 500);

//create a matrix to specify a distance from the viewpoint.
osg::Matrix trans;
trans.makeTranslate(0., 0., -12.);

//Rotation angle (in radians)
double angle(0.);
while (!viewer.done()) {
viewer.getCamera()-setPostDrawCallback(new CCameraPostDrawCallback(0, 
0, 500, 500, screenshot.jpg));

//Create the rotation matrix.
osg::Matrix rot;
rot.makeRotate(angle, osg::Vec3(1, 0., 0.));
angle += 0.01;
viewer.getCamera()-setViewMatrix(rot * trans);
viewer.frame();
}
}




 
Thank you!

Cheers,
Ricky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29188#29188





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Screeshots from multiple cameras/views

2010-06-21 Thread Robert Osfield
Hi Ricky,

You are doing two things that are very expensive - reading back from
GPU and writing to disk.  You can help lower the cost of GPU read by
using double buffer of PBO, and the cost of writng to disk by using a
separate thread.  Both topics aren't straight forward and pretty
advanced topics.  Go read the osg-users archives for guidance on these
topics.

Robert.

On Mon, Jun 21, 2010 at 8:21 AM, Ricky Flintoff rickyflint...@gmail.com wrote:
 Hi,

 As a solution, I decided to change the viewpoint of the camera and then take 
 pictures as I change the viewpoint. However, with the code I have, it's 
 really slow (cow rotates very slowly) Any suggestions or ways I can over come 
 this problem?


 Code:

 //capture an image of the scenegraph
 class CCameraPostDrawCallback: public osg::Camera::DrawCallback {
 public:
    CCameraPostDrawCallback(const int cX, const int cY, const int w,
            const int h, const std::string str) {
        centerX = cX;
        centerY = cY;
        width = w;
        height = h;
        fileName = str;
    }

    void operator () (const osg::Camera cam) const {
        //take a picture of the scene
        osg::ref_ptrosg::Image screenShot = new osg::Image;
        screenShot-readPixels(centerX, centerY, width, height, GL_RGB, 
 GL_UNSIGNED_BYTE);
        osgDB::writeImageFile(*screenShot, fileName);
    }
 private:
    int centerX;
    int centerY;
    int width;
    int height;
    std::string fileName;
 };

 osg::Node* CreateScene() { //add rendering modifications
    //load the osg model
    osg::Node* loadedModel = osgDB::readNodeFile(cow.osg);
    return loadedModel;
 }

 int main(int argc, char *argv[]) {
    osgViewer::Viewer viewer;
    viewer.setSceneData(CreateScene());
    viewer.getCamera()-setProjectionMatrixAsPerspective(60., 1., 1., 100. );
    viewer.setUpViewInWindow(0, 0, 500, 500);

    //create a matrix to specify a distance from the viewpoint.
    osg::Matrix trans;
    trans.makeTranslate(0., 0., -12.);

    //Rotation angle (in radians)
    double angle(0.);
    while (!viewer.done()) {
        viewer.getCamera()-setPostDrawCallback(new CCameraPostDrawCallback(0, 
 0, 500, 500, screenshot.jpg));

        //Create the rotation matrix.
        osg::Matrix rot;
        rot.makeRotate(angle, osg::Vec3(1, 0., 0.));
        angle += 0.01;
        viewer.getCamera()-setViewMatrix(rot * trans);
        viewer.frame();
    }
 }





 Thank you!

 Cheers,
 Ricky

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=29188#29188





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Screeshots from multiple cameras/views

2010-06-21 Thread Ricky Flintoff
Hi,

Thank you very very much for your suggestion! I actually ran into another 
problem with the code. I tend to get segmentation faults. My idea was to take 
multiple pictures as I changed the position of my camera. 
Any way I can get rid of these seg faults?
Thank you!

Cheers,
Ricky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29237#29237





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Screeshots from multiple cameras/views

2010-06-21 Thread Tom Pearce
Ricky,

Based on the code you posted, you're taking a screenshot every frame - and from 
the same position, no less.  You're creating the same matrix each time, and 
thus setting the view matrix to be identical each frame.  Then you're doing 
file I/O that is the exact same too.

When I ran your code without doing all of this on every frame (i.e. returning 
after the first frame or two) everything seemed to work.  In fact, I also ran 
it exactly as you'd posted it, and it still executed without error, just very 
slowly.  I'm not sure where the seg faults are coming from but perhaps you're 
just bogging stuff down too much since the code isn't really doing something 
you actually want it to do...?  In principle I don't see a problem with moving 
the camera from one view to another and taking a picture from two (or more) 
points - but the way it is set up right now isn't right.  At least, not as I 
see it.

Cheers,
Tom

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29238#29238





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Screeshots from multiple cameras/views

2010-06-19 Thread Ricky Flintoff
Hi,

I am new to OSG. I have gone through several example code, tutorial and the OSG 
quick start guide in order to understand OSG functionality. My goal is to 
essentially produce a framework that researchers could use to evaluate object 
tracking algorithms. 
In order to successfully accomplish this, I want to create a setup that allows 
user to render their models and take screen shots from several different angles 
of their models. 
I have been able to accomplish this with a single camera. However, I am having 
a hard time with the next step: creating multiple cameras (should I be using 
multiple cameras or a master-slave system?) in the scene and taking screen 
shots from there. Is there any tutorial that specifically addresses this? I 
couldn't find it. Any help on this would be great!

Thank you!

Cheers,
Ricky

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29169#29169





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org