OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

CullVisitor::apply(Geode&) detected NaN,


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 27

PostPosted: Wed Aug 30, 2017 3:27 pm    Post subject:
CullVisitor::apply(Geode&) detected NaN,
Reply with quote

Hi,

I have the following message when I run my OSG application:

Code:

CullVisitor::apply(Geode&) detected NaN,
depth=nan, center=(1.79588 1.50488 1.42179),
matrix={
nan nan -nan -nan
nan nan -nan -nan
nan nan -nan -nan
nan nan -nan -nan
}



What this kind of warning/error means?
...

Thank you!

Cheers,
Rômulo
Back to top
View user's profile Send private message
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 27

PostPosted: Thu Aug 31, 2017 8:14 pm    Post subject:
Reply with quote

Up!

Rômulo
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11238

PostPosted: Fri Sep 01, 2017 8:49 am    Post subject:
CullVisitor::apply(Geode&) detected NaN,
Reply with quote

On 31 August 2017 at 21:14, Rômulo Cerqueira < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Up!


Down!


The report looks like the modelview matrix has NaN's in for some reason.  Without any information at when it happens, what you data is we can't say what might be causing this.



Robert.

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 27

PostPosted: Fri Sep 01, 2017 3:10 pm    Post subject:
Reply with quote

Ok Robert,

this is my current code (only .cpp):

Code:

#include "ImageViewerCaptureTool.hpp"
#include <iostream>
#include <unistd.h>
#include <osgDB/WriteFile>

namespace normal_depth_map {

ImageViewerCaptureTool::ImageViewerCaptureTool(uint width, uint height) {

// initialize the hide viewer;
initializeProperties(width, height);
}

ImageViewerCaptureTool::ImageViewerCaptureTool( double fovY, double fovX, uint value, bool isHeight) {
uint width, height;

if (isHeight) {
height = value;
width = height * tan(fovX * 0.5) / tan(fovY * 0.5);
} else {
width = value;
height = width * tan(fovY * 0.5) / tan(fovX * 0.5);
}

double aspectRatio = width * 1.0 / height;

initializeProperties(width, height);
_viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);

_viewer->getCamera()->setProjectionMatrixAsPerspective(fovY * 180.0 / M_PI, aspectRatio, 0.1, 1000);
}

void ImageViewerCaptureTool::initializeProperties(uint width, uint height) {
// initialize the hide viewer;
_viewer = new osgViewer::Viewer;
osg::Camera *camera = this->_viewer->getCamera();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->width = width;
traits->height = height;
traits->pbuffer = true;
traits->readDISPLAY();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
camera->setGraphicsContext(gc);
camera->setDrawBuffer(GL_FRONT);
camera->setViewport(new osg::Viewport(0, 0, width, height));

// initialize the class to get the image in float data resolution
_capture = new WindowCaptureScreen(gc);
_viewer->getCamera()->setFinalDrawCallback(_capture);
}

osg::ref_ptr<osg::Image> ImageViewerCaptureTool::grabImage(osg::ref_ptr<osg::Node> node ) {

_viewer->setSceneData(node);
_viewer->frame();
return _capture->captureImage();;
}

osg::ref_ptr<osg::Image> ImageViewerCaptureTool::getDepthBuffer() {
return _capture->getDepthBuffer();
}


void ImageViewerCaptureTool::setCameraPosition( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up) {
_viewer->getCamera()->setViewMatrixAsLookAt(eye, center, up);
}

void ImageViewerCaptureTool::getCameraPosition( osg::Vec3d& eye,osg::Vec3d& center, osg::Vec3d& up) {
_viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
}

void ImageViewerCaptureTool::setBackgroundColor(osg::Vec4d color) {
_viewer->getCamera()->setClearColor(color);
}

////////////////////////////////
////WindowCaptureScreen METHODS
////////////////////////////////

WindowCaptureScreen::WindowCaptureScreen(osg::ref_ptr<osg::GraphicsContext> gc) {
_mutex = new OpenThreads::Mutex();
_condition = new OpenThreads::Condition();
_image = new osg::Image();
_depth_buffer = new osg::Image();

// checks the GraficContext from the camera viewer
if (gc->getTraits()) {

GLenum pixelFormat;
if (gc->getTraits()->alpha) pixelFormat = GL_RGBA;
else pixelFormat = GL_RGB;

int width = gc->getTraits()->width;
int height = gc->getTraits()->height;

// allocates the image memory space
_image->allocateImage(width, height, 1, pixelFormat, GL_FLOAT);
_depth_buffer->allocateImage(width, height, 1, GL_DEPTH_COMPONENT, GL_FLOAT);
}
}

WindowCaptureScreen::~WindowCaptureScreen() {
delete (_condition);
delete (_mutex);
}

osg::ref_ptr<osg::Image> WindowCaptureScreen::captureImage() {

//wait to finish the capture image in call back
_condition->wait(_mutex);
return _image;
}

osg::ref_ptr<osg::Image> WindowCaptureScreen::getDepthBuffer() {
return _depth_buffer;
}


void WindowCaptureScreen::operator ()(osg::RenderInfo& renderInfo) const {
osg::ref_ptr<osg::GraphicsContext> gc = renderInfo.getState()->getGraphicsContext();
if (gc->getTraits()) {
_mutex->lock();
_image->readPixels( 0, 0, _image->s(), _image->t(), _image->getPixelFormat(), GL_FLOAT);
_depth_buffer->readPixels(0, 0, _image->s(), _image->t(), _depth_buffer->getPixelFormat(), GL_FLOAT);

//grants the access to image
_condition->signal();
_mutex->unlock();
}
}

}



...

Thank you!

Cheers,
Rômulo
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11238

PostPosted: Fri Sep 01, 2017 3:23 pm    Post subject:
CullVisitor::apply(Geode&) detected NaN,
Reply with quote

Hi Romulo,


There is a lot of code in there which I wouldn't expect to affect the modelview and project matrices, my recommendation would be to create a small test example to test loading your data and setting your view and projection matrices as required without any of the frame capture code that will be getting in the way of working out what might be amiss.


You code also nothing about your scene graph, as this might well be the source of the issue there isn't much more we can guess at.


The best thing you can do at this point is go test your models against a standard example like osgviewer.  If the error occurs there then posting this so others can try and reproduce the problem.



Robert.






On 1 September 2017 at 16:10, Rômulo Cerqueira < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Ok Robert,

this is my current code (only .cpp):


Code:

#include "ImageViewerCaptureTool.hpp"
#include <iostream>
#include <unistd.h>
#include <osgDB/WriteFile>

namespace normal_depth_map {

ImageViewerCaptureTool::ImageViewerCaptureTool(uint width, uint height) {

// initialize the hide viewer;
initializeProperties(width, height);
}

ImageViewerCaptureTool::ImageViewerCaptureTool( double fovY, double fovX, uint value, bool isHeight) {
uint width, height;

if (isHeight) {
height = value;
width = height * tan(fovX * 0.5) / tan(fovY * 0.5);
} else {
width = value;
height = width * tan(fovY * 0.5) / tan(fovX * 0.5);
}

double aspectRatio = width * 1.0 / height;

initializeProperties(width, height);
_viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);

_viewer->getCamera()->setProjectionMatrixAsPerspective(fovY * 180.0 / M_PI, aspectRatio, 0.1, 1000);
}

void ImageViewerCaptureTool::initializeProperties(uint width, uint height) {
// initialize the hide viewer;
_viewer = new osgViewer::Viewer;
osg::Camera *camera = this->_viewer->getCamera();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->width = width;
traits->height = height;
traits->pbuffer = true;
traits->readDISPLAY();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
camera->setGraphicsContext(gc);
camera->setDrawBuffer(GL_FRONT);
camera->setViewport(new osg::Viewport(0, 0, width, height));

// initialize the class to get the image in float data resolution
_capture = new WindowCaptureScreen(gc);
_viewer->getCamera()->setFinalDrawCallback(_capture);
}

osg::ref_ptr<osg::Image> ImageViewerCaptureTool::grabImage(osg::ref_ptr<osg::Node> node ) {

_viewer->setSceneData(node);
_viewer->frame();
return _capture->captureImage();;
}

osg::ref_ptr<osg::Image> ImageViewerCaptureTool::getDepthBuffer() {
return _capture->getDepthBuffer();
}


void ImageViewerCaptureTool::setCameraPosition( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up) {
_viewer->getCamera()->setViewMatrixAsLookAt(eye, center, up);
}

void ImageViewerCaptureTool::getCameraPosition( osg::Vec3d& eye,osg::Vec3d& center, osg::Vec3d& up) {
_viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
}

void ImageViewerCaptureTool::setBackgroundColor(osg::Vec4d color) {
_viewer->getCamera()->setClearColor(color);
}

////////////////////////////////
////WindowCaptureScreen METHODS
////////////////////////////////

WindowCaptureScreen::WindowCaptureScreen(osg::ref_ptr<osg::GraphicsContext> gc) {
_mutex = new OpenThreads::Mutex();
_condition = new OpenThreads::Condition();
_image = new osg::Image();
_depth_buffer = new osg::Image();

// checks the GraficContext from the camera viewer
if (gc->getTraits()) {

GLenum pixelFormat;
if (gc->getTraits()->alpha) pixelFormat = GL_RGBA;
else pixelFormat = GL_RGB;

int width = gc->getTraits()->width;
int height = gc->getTraits()->height;

// allocates the image memory space
_image->allocateImage(width, height, 1, pixelFormat, GL_FLOAT);
_depth_buffer->allocateImage(width, height, 1, GL_DEPTH_COMPONENT, GL_FLOAT);
}
}

WindowCaptureScreen::~WindowCaptureScreen() {
delete (_condition);
delete (_mutex);
}

osg::ref_ptr<osg::Image> WindowCaptureScreen::captureImage() {

//wait to finish the capture image in call back
_condition->wait(_mutex);
return _image;
}

osg::ref_ptr<osg::Image> WindowCaptureScreen::getDepthBuffer() {
return _depth_buffer;
}


void WindowCaptureScreen::operator ()(osg::RenderInfo& renderInfo) const {
osg::ref_ptr<osg::GraphicsContext> gc = renderInfo.getState()->getGraphicsContext();
if (gc->getTraits()) {
_mutex->lock();
_image->readPixels( 0, 0, _image->s(), _image->t(), _image->getPixelFormat(), GL_FLOAT);
_depth_buffer->readPixels(0, 0, _image->s(), _image->t(), _depth_buffer->getPixelFormat(), GL_FLOAT);

//grants the access to image
_condition->signal();
_mutex->unlock();
}
}

}





...

Thank you!

Cheers,
Rômulo

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





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 337

PostPosted: Fri Sep 01, 2017 4:32 pm    Post subject:
Re: CullVisitor::apply(Geode&) detected NaN,
Reply with quote

Hi Rômulo
If it can help,
I believe to remember to have spotted potential 0 division in osgGA CameraManipulator.cpp
try replace l113 with
Code:
 
viewAngle=sin(viewAngle);
if( viewAngle<10e-3){
    OSG_WARN<<"osgGA/CameraManipulator.cpp correct bad sin l115"<<std::endl;
   viewAngle=10e-3;
}
dist = boundingSphere.radius() /viewAngle ;

see if your problem comes from here and post your diagnostic here
cheers
romulogcerqueira wrote:
Hi,

I have the following message when I run my OSG application:

Code:

CullVisitor::apply(Geode&) detected NaN,
depth=nan, center=(1.79588 1.50488 1.42179),
matrix={
nan nan -nan -nan
nan nan -nan -nan
nan nan -nan -nan
nan nan -nan -nan
}



What this kind of warning/error means?
...

Thank you!

Cheers,
Rômulo
Back to top
View user's profile Send private message
ckuliukas
User


Joined: 22 Nov 2014
Posts: 32

PostPosted: Sat Sep 02, 2017 2:52 am    Post subject:
Reply with quote

I would run your app in debug mode, break in CullVisitor::apply(osg::Geode), then take a look at the matrix stacks and see where the nans are coming from

_________________
http://www.hrwallingford.com/facilities/ship-simulation-centre
Back to top
View user's profile Send private message
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 27

PostPosted: Sat Sep 02, 2017 10:04 pm    Post subject:
Reply with quote

Hi guys,

I found and solved the problem! Very Happy

When I grab the osg scene at first time, my view matrix is NaN; from the second time, this matrix is correctly filled.

Then, I modified the grabImage method to replace when the view matrix is NaN by the identity matrix, as follows:

Code:

osg::ref_ptr<osg::Image> ImageViewerCaptureTool::grabImage(osg::ref_ptr<osg::Node> node) {
    // set the current root node
    _viewer->setSceneData(node);

    // if the view matrix is invalid (NaN), use the identity
    osg::ref_ptr<osg::Camera> camera = _viewer->getCamera();
    if (camera->getViewMatrix().isNaN())
        camera->setViewMatrix(osg::Matrix::identity());

    // grab the current frame
    _viewer->frame();
    return _capture->captureImage();
}


Thanks for all messages!

Cheers,

Rômulo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts How can I get pixels 3D coordinates a... YrieixLeprince General 2 Wed Apr 12, 2017 9:49 am View latest post
No new posts Displaying Geode Bounding Box sam General 1 Wed Mar 08, 2017 8:37 pm View latest post
No new posts osgUtil::CullVisitor missing const qu... mp3butcher Submission 3 Sat Jul 02, 2016 1:37 pm View latest post
No new posts CullVisitor object not getting proper... Rick Irons General 11 Mon May 23, 2016 4:53 pm View latest post
No new posts Remove unnecessary dynamic_cast's in ... scrawl Submission 6 Fri Nov 27, 2015 2:36 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP