OSG::Action::ResultE changeGeo(OSG::Node *node)
{   
    OSG::Geometry *geo = dynamic_cast<OSG::Geometry *>(node->getCore());
    
    if(geo == NULL)
        return OSG::Action::Continue;


    OSG::GeoColor3fPropertyRefPtr col = dynamic_cast<OSG::GeoColor3fProperty *>(geo->getColors());
    if(col == NULL)
    {
        col = OSG::GeoColor3fProperty::create();

        col->resize(geo->getPositions()->getSize());
        
        // Change the geometry to use the new colors
        geo->setColors(col);
        // If multi-indexed, make the colors use the same index as
        // the geometry
        if(geo->getIndex(OSG::Geometry::PositionsIndex) != NULL)
        {
            geo->setIndex(geo->getIndex(OSG::Geometry::PositionsIndex),
                          OSG::Geometry::ColorsIndex                   );
        }
    }
    
    OSG::Real32 size = col->getSize();
    for(OSG::UInt32 i = 0; i < size; ++i)
    {
        OSG::Color3f c;
        c[0] = 0.0f;
        c[1] = static_cast<OSG::Real32>(i) / size;
        c[2] = 0.0f;
        col->setValue(c, i);
    }
    
    return OSG::Action::Continue; 
}
void prepareSceneGraph(OSG::Node * const node)
{
    if(!prepared)
    {
        polygonChunk = OSG::PolygonChunk::create();
        prepared = true;
    }

    OSG::NodeCore *core  =node->getCore();
    if(core != NULL)
    {
        OSG::Geometry *geo   = dynamic_cast<OSG::Geometry *>(core);
        if(geo != NULL)
        {
            OSG::Material *mat = geo->getMaterial();
            if(mat != NULL)
            {
                OSG::ChunkMaterial *cmat = 
                    dynamic_cast<OSG::ChunkMaterial *>(mat);
                if(cmat->find(OSG::PolygonChunk::getClassType()) == NULL)
                {
                    cmat->addChunk(polygonChunk);
                }
            }
            // get num positions
            OSG::GeoVectorProperty *positionsPtr=geo->getPositions();
            if(positionsPtr != NULL)
                sum_positions += positionsPtr->size32();
            // get num triangles
            OSG::UInt32 triangle=0;
            OSG::UInt32 line=0;
            OSG::UInt32 point=0;
            calcPrimitiveCount(geo,triangle,line,point);
            sum_triangles += triangle;
            // sum of geometry nodes
            ++sum_geometries;
        }
        else
        {
            OSG::MaterialGroup *matGrp = 
                dynamic_cast<OSG::MaterialGroup *>(core);
            if(matGrp != NULL)
            {
                OSG::Material *mat = matGrp->getMaterial();
                if(mat != NULL)
                {
                    OSG::ChunkMaterial *cmat = 
                        dynamic_cast<OSG::ChunkMaterial *>(mat);
                    if(cmat->find(OSG::PolygonChunk::getClassType()) == NULL)
                    {
                        cmat->addChunk(polygonChunk);
                    }
                }
            }
            else
            {
                OSG::ProxyGroup *proxy = dynamic_cast<OSG::ProxyGroup *>(core);
                if(proxy != NULL)
                {
                    sum_triangles += proxy->getTriangles();
                    sum_positions += proxy->getPositions();
                    sum_geometries += proxy->getGeometries();
                }
            }
        }
    }
    for(OSG::MFUnrecChildNodePtr::const_iterator nI=node->getMFChildren()->begin();
        nI != node->getMFChildren()->end();
        ++nI)
    {
        prepareSceneGraph(*nI);
    }
}