Hello Gabriel,

Gabriel Zachman wrote:
We believe that the osgSceneViewer shows the wrong polygon / triangle count.

We've got an object that consists only of triangles (we are pretty sure).
Here is the link: http://cg.in.tu-clausthal.de/research/colldet_benchmark/data/objects/Apollo.zip
In that archive there is a file called Apollo_7962.wrl

Our own sed-based polygon counting script reports 7962 polygons.
The instantreality player reports the same count.
Our own software computes the count and finds the same number.

We have tried the faceIterator and the triangleIterator, both yield the same result.

hm, I can not reproduce this. Did you count the triangles in all geometries ?

If attached the test I've modified (push 'c' to trigger the triangle counting), but it essentially runs the following traversal function over the scene:

UInt32 geoCount = 0;
UInt32 triCount = 0;

Action::ResultE
countTriangles(NodePtr &pNode)
{
    NodeCorePtr pCore = pNode->getCore();
    GeometryPtr pGeo  = GeometryPtr::dcast(pCore);

    if(pGeo != NullFC)
    {
        FLOG(("Found geometry [%d]\n", ++geoCount));

        TriangleIterator triIt  = pGeo->beginTriangles();
        TriangleIterator triEnd = pGeo->endTriangles  ();

        UInt32 localTriCount = 0;

        for(; triIt != triEnd; ++triIt)
        {
            ++localTriCount;
            ++triCount;
        }

        FLOG(("    localTriCount [%d]  triCount [%d]\n", localTriCount, 
triCount));
    }

    return Action::Continue;
}

traverse(scene,
         osgTypedFunctionFunctor1CPtrRef<
             Action::ResultE,
             NodePtr        >(countTriangles));

Could you please give a bit more details on what results you get and how you obtain your triangle count?

        Thanks,
                Carsten

// Headers
#include <OSGGLUT.h>
#include <OSGConfig.h>
#include <OSGSimpleGeometry.h>
#include <OSGGLUTWindow.h>
#include <OSGSimpleSceneManager.h>
#include <OSGAction.h>

#include <OSGStatCollector.h>

// New Headers

// the general scene file loading handler
#include <OSGSceneFileHandler.h>


#include <OSGTriangleIterator.h>

// Activate the OpenSG namespace
OSG_USING_NAMESPACE

// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;

StatCollector stats;
NodePtr       scene;

UInt32 geoCount = 0;
UInt32 triCount = 0;

Action::ResultE
countTriangles(NodePtr &pNode)
{
    NodeCorePtr pCore = pNode->getCore();
    GeometryPtr pGeo  = GeometryPtr::dcast(pCore);

    if(pGeo != NullFC)
    {
        FLOG(("Found geometry [%d]\n", ++geoCount));

        TriangleIterator triIt  = pGeo->beginTriangles();
        TriangleIterator triEnd = pGeo->endTriangles  ();

        UInt32 localTriCount = 0;

        for(; triIt != triEnd; ++triIt)
        {
            ++localTriCount;
            ++triCount;
        }

        FLOG(("    localTriCount [%d]  triCount [%d]\n", localTriCount, 
triCount));
    }

    return Action::Continue;
}


// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );

// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    // load the scene
    
    if(argc < 2)
    {
        FWARNING(("No file given!\n"));
        FWARNING(("Supported file formats:\n"));
        
        std::list<const char*> suffixes;
        SceneFileHandler::the().getSuffixList(suffixes);
        
        for(std::list<const char*>::iterator it  = suffixes.begin();
                                        it != suffixes.end();
                                        ++it)
        {
            FWARNING(("%s\n", *it));
        }

        scene = makeTorus(.5, 2, 16, 16);
    }
    else
    {
        /*
            All scene file loading is handled via the SceneFileHandler.
        */
        scene = SceneFileHandler::the().read(argv[1]);
    }


    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin );
    mgr->setRoot  (scene);

    // show the whole scene
    mgr->showAll();

    mgr->getAction()->setStatistics(&stats);

    // GLUT main loop
    glutMainLoop();

    return 0;
}

//
// GLUT callback functions
//

// redraw the window
void display(void)
{
    mgr->redraw();
    
    std::string str;
    stats.putToString(str);
    FLOG(("Stats: %s\n",str.c_str()));
}

// react to size changes
void reshape(int w, int h)
{
    mgr->resize(w, h);
    glutPostRedisplay();
}

// react to mouse button presses
void mouse(int button, int state, int x, int y)
{
    if (state)
        mgr->mouseButtonRelease(button, x, y);
    else
        mgr->mouseButtonPress(button, x, y);
        
    glutPostRedisplay();
}

// react to mouse motions with pressed buttons
void motion(int x, int y)
{
    mgr->mouseMove(x, y);
    glutPostRedisplay();
}

// react to keys
void keyboard(unsigned char k, int , int )
{
    switch(k)
    {
    case 'c':
    {
        traverse(scene, 
                 osgTypedFunctionFunctor1CPtrRef<
                     Action::ResultE, 
                     NodePtr        >(countTriangles));
        FLOG(("\n\tTotal geometries [%d]\n\tTotal triangles [%d]\n", geoCount, 
triCount));

        geoCount = 0;
        triCount = 0;
    }
    break;

    case 27:    exit(1);
    }
}

// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    
    int winid = glutCreateWindow("OpenSG");
    
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    return winid;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to