Hello all,  

I'm using OpenSG2.0 to read line strips out of a .wrl file and process them 
afterwards. I've attached a sample file containing three line strips. In 
principle these line segments are connected, i.e., they represent a closed 
curve. I have some trouble with the whole process and I do not know if there 
are bugs or I'm missing something.  

1) When reading the file, GL_LINES instead of GL_LINE_STRIPS are generated in 
the geometry core. A simple example shows the issue: At the end of the 
following code snipplet, the type of the geometry core is GL_LINES instead of 
GL_LINE_STRIP.   

OSG::GeometryRecPtr geo = OSG::Geometry::create();
OSG::GeoUInt8PropertyRecPtr types = OSG::GeoUInt8Property::create();    
OSG::GeoUInt32PropertyRecPtr lengths = SG::GeoUInt32Property::create();
OSG::GeoPnt3fPropertyRecPtr positions = OSG::GeoPnt3fProperty::create();
OSG::GeoUInt32PropertyRecPtr indices = SG::GeoUInt32Property::create(); 

ypes->addValue(GL_LINE_STRIP);
lengths->addValue(4);
for(unsigned int i = 0; i < 4; ++i)
{
        indices->addValue(i);
        positions->addValue(OSG::Vec3f(i * 0.1, 0.0f, 0.0f));
}
geo->setTypes(types);
geo->setLengths(lengths);
geo->setPositions(positions);
geo->setIndices(indices);

OSG::NodeRecPtr myNode = OSG::Node::create();
myNode->setCore(geo);
OSG::SceneFileHandler::the()->write(myNode, "test.wrl");

OSG::NodeRefPtr scene;
scene = OSG::SceneFileHandler::the()->read("test.wrl", NULL);

I fixed that in my application by traversing the generated scene graph and 
replacing all GL_LINES with GL_LINE_STRIP. 

2) In a second step I need to merge all geometry cores into one. As the 
geometry is spread over the whole the scenegraph and the GeometryMergeOp only 
works with direct children, I collected all geometry cores and put them "below" 
a group node ("newScene"). The merge operation works in principle, but it 
always results in two geometry cores: one with the merged geometry and another 
one. I assume that the "second" one is simply not deleted in the final step. 
Here is the code: 

OSG::Action::ResultE changeToLineStripAndCollectGeoNodes(OSG::Node*  node)
{
        OSG::Geometry * geo = dynamic_cast<OSG::Geometry* (node->getCore());
        if(geo)
        {
                OSG::GeoIntegralProperty* lengths = geo->getLengths();
                OSG::GeoIntegralProperty* indices = geo->getIndices();
                OSG::GeoIntegralProperty* types = geo->getTypes();
                for(unsigned int i = 0; i < types->size(); ++i)
                {
                types->setValue(GL_LINE_STRIP, i);
                }
                geoNodes.push_back(node);
        }
        return OSG::Action::Continue;
}

void processGeometry(OSG::NodeRecPtr& loadedGeo, OSG::NodeRecPtr& newScene)
{

OSG::traverse(loadedGeo,boost::bind(&changeToLineStripAndCollectGeoNodes, _1));

        newScene = OSG::makeCoredNode<OSG::Group>();
        for(unsigned int i = 0; i < geoNodes.size(); ++i)
        {
                newScene->addChild(geoNodes[i]);
        }

        OSG::GeometryMergeGraphOpRefPtr mergeOp = 
OSG::GeometryMergeGraphOp::create();
        mergeOp->traverse(newScene);
        
        // here newScene has two children, not one... 


3) In the third step, I call "createSharedIndex" in order to merge vertices 
that belong more than on line segment (these are the start- and end-vertices of 
the line strips.) With the attached file, only two of the three start-vertices 
are merged with the corresponding end-vertex. What may be the reason?)

4) Finally, I would like to make one linestrip out of the geometry. But the 
StipeGraphOp does not seem to work for linestrips (only tri- and quadstrips?)

Thanks for taking your time, best regards, 

Daniel 

                  
-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

Attachment: test.wrl
Description: Binary data

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today. 
http://p.sf.net/sfu/quest-dev2dev2 
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to