Re: [osg-users] Warped scene with two sets of Geodes
Hi Ben, On 3 September 2014 22:55, Ben Morgan nee...@gmail.com wrote: Hi Robert, I found out what the Problem was--it *was* my code :-) In particular, it looks like mixing doubles and floats is very bad. Pretty much everything is a float except for the vertex array of a street. If I change that to float and convert the Points to Vec3 instead of Vec3d, then everything is good. Do you understand why this is a problem though? I can only provide a guess, and that would be that the Intel OpenGL doesn't handle double vertex data correctly, so you are stumbling across a driver bug. In general OpenGL hardware is based around floating point maths so the drivers normally convert any double data you pass it into floats before passing it to the GPU. Even if the driver does this correctly this conversion process slows performance down so it's best to keep osg::Geometry vertex/texcoord/normal etc. data all in float arrays such as Vec3Array. You can retain precision by translating your data to a local origin prior to conversion to float then place a MatrixTransform above your data to place it in the correct 3D position. The OSG by default uses double for all internal matrices that that when it accumulates the modelvew matrix during the cull traversal double precision is maintain for as long as possible before passing the final modelview matrix to OpenGL. Using this technique the OSG can handle whole earth data without any jitter/precision problems. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Warped scene with two sets of Geodes
Hi Robert, I found out what the Problem was—it *was* my code :-) In particular, it looks like mixing doubles and floats is very bad. Pretty much everything is a float except for the vertex array of a street. If I change that to float and convert the Points to Vec3 instead of Vec3d, then everything is good. Do you understand why this is a problem though? Thanks, –Ben On Tue, Sep 2, 2014 at 12:01 PM, Ben Morgan nee...@gmail.com wrote: Hi Robert, thanks for your reply. I'm kinda new in the OSG/OpenGL field, so I'm thankful for all the help and advice I can get. The goal of the project I'm working on is to develop algorithms for street label positioning on an active route. So I have a street network, a pointer that moves along a route in the network and a camera that follows the pointer, and then I have a bunch of labels that I position and move around. (I think I might have written something in this mailing list two years ago.) I never thought that it could be anything other than a mistake of my own. The problem occurs on the following configurations: Thinkpad T420 with i5 CPU/Graphics Card (Intel HD3000 I think) Arch Linux 3.16.1 OSG version 3.2.1 OSG version 3.0.1 G++ version 4.9.1 Intel Video Driver version 2.99.914 Intel DRI Software version 10.2.6 Thinkpad T60 with Radeon Graphics Card (I only did this quickly, so I don't have all the details) Arch Linux 3.16.1 OSG version 3.2.1 G++ version 4.9.1 I tried another program that I knew was working two years ago on this computer, and it has a similar issue (though different) now—the pointer is just not there. Additionally, the osgText labels are not showing up either. The past few days since your response, I also worked on getting it to compile on Windows 7, with Visual Studio 12. (FYI: I had to add an #include algorithm to osgText/Glyph.cpp for it to compile, otherwise it didn't see min/max.) I'll write again after I finish that. Is there a better way to represent the street network? Should I have a Group containing a bunch of street lines and then apply color and line width at that level? Or do I store the street lines all in a single Geode? I updated (and simplified) the source code listing to include the pointer drawing code—perhaps the problem lies there? (I also changed the street network to contain a bunch of drawables inside a single Geode. Is it better that way? Or am I going a completely wrong direction with that?) Thanks again for your help! –Ben PS: And here is the updated source code (also updated at StackOverflow): // My libraries: #include asl/util/color.h using namespace asl; #include straph/point.h #include straph/straph.h using namespace straph; // Standard and OSG libraries: #include utility #include boost/tuple/tuple.hpp // tie using namespace std; #include osg/ref_ptr #include osg/Array #include osg/Geometry #include osg/Geode #include osg/Group #include osg/LineWidth using namespace osg; #include osgUtil/Tessellator #include osgViewer/Viewer using namespace osgViewer; /* * Just FYI: A Polyline looks like this: * * typedef std::vectorPoint Polyline; * * And a Point basically is a simple struct: * * struct Point { * double x; * double y; * }; */ inline osg::Vec3d toVec3d(const straph::Point p, double elevation=0.0) { return osg::Vec3d(p.x, p.y, elevation); } Geometry* createStreet(const straph::Polyline path) { ref_ptrVec3dArray array (new Vec3dArray(path.size())); for (unsigned i = 0; i path.size(); ++i) { (*array)[i] = toVec3d(path[i]); } Geometry* geom = new Geometry; geom-setVertexArray(array.get()); geom-addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, array-size())); return geom; } Geode* load_streets() { unique_ptrStraph graph = read_shapefile(mexico/roads, 6); Geode* root = new Geode(); boost::graph_traitsstraph::Straph::edge_iterator ei, ee; for (boost::tie(ei, ee) = edges(*graph); ei != ee; ++ei) { const straph::Segment s = (*graph)[*ei]; root-addDrawable(createStreet(s.polyline)); } return root; } Geode* createPointer(double width, const Color body_color) { float f0 = 0.0f; float f3 = 3.0f; float f1 = 1.0f * width; float f2 = 2.0f * width; // Create vertex array ref_ptrVec3Array vertices (new Vec3Array(4)); (*vertices)[0].set( f0 , f0, f0 ); (*vertices)[1].set( -f1/f3, -f1/f3 , f0 ); (*vertices)[2].set( f0 , f2/f3 , f0 ); (*vertices)[3].set( f1/f3, -f1/f3 , f0 ); // Build the geometry object
Re: [osg-users] Warped scene with two sets of Geodes
Hi Robert, thanks for your reply. I'm kinda new in the OSG/OpenGL field, so I'm thankful for all the help and advice I can get. The goal of the project I'm working on is to develop algorithms for street label positioning on an active route. So I have a street network, a pointer that moves along a route in the network and a camera that follows the pointer, and then I have a bunch of labels that I position and move around. (I think I might have written something in this mailing list two years ago.) I never thought that it could be anything other than a mistake of my own. The problem occurs on the following configurations: Thinkpad T420 with i5 CPU/Graphics Card (Intel HD3000 I think) Arch Linux 3.16.1 OSG version 3.2.1 OSG version 3.0.1 G++ version 4.9.1 Intel Video Driver version 2.99.914 Intel DRI Software version 10.2.6 Thinkpad T60 with Radeon Graphics Card (I only did this quickly, so I don't have all the details) Arch Linux 3.16.1 OSG version 3.2.1 G++ version 4.9.1 I tried another program that I knew was working two years ago on this computer, and it has a similar issue (though different) now—the pointer is just not there. Additionally, the osgText labels are not showing up either. The past few days since your response, I also worked on getting it to compile on Windows 7, with Visual Studio 12. (FYI: I had to add an #include algorithm to osgText/Glyph.cpp for it to compile, otherwise it didn't see min/max.) I'll write again after I finish that. Is there a better way to represent the street network? Should I have a Group containing a bunch of street lines and then apply color and line width at that level? Or do I store the street lines all in a single Geode? I updated (and simplified) the source code listing to include the pointer drawing code—perhaps the problem lies there? (I also changed the street network to contain a bunch of drawables inside a single Geode. Is it better that way? Or am I going a completely wrong direction with that?) Thanks again for your help! –Ben PS: And here is the updated source code (also updated at StackOverflow): // My libraries: #include asl/util/color.h using namespace asl; #include straph/point.h #include straph/straph.h using namespace straph; // Standard and OSG libraries: #include utility #include boost/tuple/tuple.hpp // tie using namespace std; #include osg/ref_ptr #include osg/Array #include osg/Geometry #include osg/Geode #include osg/Group #include osg/LineWidth using namespace osg; #include osgUtil/Tessellator #include osgViewer/Viewer using namespace osgViewer; /* * Just FYI: A Polyline looks like this: * * typedef std::vectorPoint Polyline; * * And a Point basically is a simple struct: * * struct Point { * double x; * double y; * }; */ inline osg::Vec3d toVec3d(const straph::Point p, double elevation=0.0) { return osg::Vec3d(p.x, p.y, elevation); } Geometry* createStreet(const straph::Polyline path) { ref_ptrVec3dArray array (new Vec3dArray(path.size())); for (unsigned i = 0; i path.size(); ++i) { (*array)[i] = toVec3d(path[i]); } Geometry* geom = new Geometry; geom-setVertexArray(array.get()); geom-addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, array-size())); return geom; } Geode* load_streets() { unique_ptrStraph graph = read_shapefile(mexico/roads, 6); Geode* root = new Geode(); boost::graph_traitsstraph::Straph::edge_iterator ei, ee; for (boost::tie(ei, ee) = edges(*graph); ei != ee; ++ei) { const straph::Segment s = (*graph)[*ei]; root-addDrawable(createStreet(s.polyline)); } return root; } Geode* createPointer(double width, const Color body_color) { float f0 = 0.0f; float f3 = 3.0f; float f1 = 1.0f * width; float f2 = 2.0f * width; // Create vertex array ref_ptrVec3Array vertices (new Vec3Array(4)); (*vertices)[0].set( f0 , f0, f0 ); (*vertices)[1].set( -f1/f3, -f1/f3 , f0 ); (*vertices)[2].set( f0 , f2/f3 , f0 ); (*vertices)[3].set( f1/f3, -f1/f3 , f0 ); // Build the geometry object ref_ptrGeometry polygon (new Geometry); polygon-setVertexArray( vertices.get() ); polygon-addPrimitiveSet( new DrawArrays(GL_POLYGON, 0, 4) ); // Set the colors ref_ptrVec4Array body_colors (new Vec4Array(1)); (*body_colors)[0] = body_color.get(); polygon-setColorArray( body_colors.get() ); polygon-setColorBinding( Geometry::BIND_OVERALL ); // Create Geode object Geode* geode = new Geode; geode-addDrawable( polygon.get() ); return geode; } int
[osg-users] Warped scene with two sets of Geodes
I did post this question on StackOverflow ( http://stackoverflow.com/questions/25576762/warped-scene-with-two-sets-of-geodes ), but I assume that this is a more appropriate place for questions. I have a few objects that I want to combine into a scene graph: Street inherits from Geode and has a Geometry child drawable made up of a GL_LINE_STRIP. Pointer inherits from PositionAttitudeTransform and contains a Geode which contains two Geometry polygons. When I add a bunch of Streets to a Group, it looks just fine. When I add only the Pointer to a Group, it also looks fine. But if I somehow have them both in the scene, the second one is screwed up. (This does not happen if I have only two Pointers.) I posted some screenshots on the StackOverflow site, in case you want to see them. Probably I’m making some simple mistake—but I can’t see it! Here is some code that causes the problem (I tried to shorten it a little): // My libraries: #include asl/util/draw.h #include asl/util/color.h using namespace asl; #include straph/point.h #include straph/straph.h using namespace straph; // Standard and OSG libraries: #include utility #include boost/tuple/tuple.hpp // tie using namespace std; #include osg/ref_ptr #include osg/Array #include osg/Geometry #include osg/Group #include osg/LineWidth using namespace osg; #include osgUtil/Optimizer #include osgViewer/Viewer #include osgViewer/ViewerEventHandlers using namespace osgViewer; Geode* createStreet(const straph::Polyline path, double width, const Color color) { ref_ptrGeometry geom (new Geometry); // Set the shape: ref_ptrVec3dArray array (new Vec3dArray(path.size())); for (unsigned i = 0; i path.size(); ++i) { (*array)[i] = toVec3d(path[i]); } geom-setVertexArray(array.get()); geom-addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, array-size())); // Set the normals: ref_ptrVec3Array normals (new Vec3Array(1)); (*normals)[0].set( 0.0f, 0.0f, 1.0f ); geom-setNormalArray( normals.get() ); geom-setNormalBinding( Geometry::BIND_OVERALL ); // Set the colors: ref_ptrVec4Array colors = new Vec4Array(); colors-push_back(color.get()); geom-setColorArray(colors); geom-setColorBinding(osg::Geometry::BIND_OVERALL); Geode* g = new Geode(); g-addDrawable(geom.get()); // Set the line width. ref_ptrLineWidth lwidth (new LineWidth); lwidth-setWidth(width); g-getOrCreateStateSet()-setAttributeAndModes(lwidth, StateAttribute::ON); return g; } Group* load_streets() { unique_ptrStraph graph = read_shapefile(mexico/roads, 6); Group* root = new Group(); boost::graph_traitsstraph::Straph::edge_iterator ei, ee; for (boost::tie(ei, ee) = edges(*graph); ei != ee; ++ei) { const straph::Segment s = (*graph)[*ei]; root-addChild(createStreet(s.polyline, 2.0, TangoColor::Aluminium4)); } return root; } int main(int, char**) { Group* root = load_streets(); Pointer* p = new Pointer(6.0, TangoColor::Scarlet3, TangoColor::Black); root-addChild(p); Viewer viewer; viewer.setSceneData(root); viewer.getCamera()-setClearColor(Color(TangoColor::White).get()); viewer.run(); } Thanks for the help! :-)  –Ben Morgan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Warped scene with two sets of Geodes
HI Ben, The osg-users mailing list/forum is the appropriate place for support. I've read your post, the code you provided and screenshots and don't really know what to make of it all. I'd guess that others will be similarly confused but what might be work and what might not be. I don't understand why you are subclassing from OSG classes for this type of work, for 3rd parties like ourselves not party to the the code in these subclasses and without any knowledge of why felt the need to do this subclassing it really kinda hard to know where you are going with this code. I couldn't spot any obvious errors in your code, but I sure wouldn't write a tool to visualize a road network in the way you have - having lots of separate scene graph objects and state will introduce CPU and GPU overheads that will prevent getting the best performance for your system. You don't mention what hardware/GL driver/OS/OSG version you are using. This is all is important when trying to track down problems. It could be that you have a buggy OpenGL driver and little to do with your own code. There isn't much we can say to help at this point as there is just way too many unknowns about your software, hardware, OS, exactly nature of the problem etc. Robert. On 30 August 2014 12:32, Ben Morgan nee...@gmail.com wrote: I did post this question on StackOverflow ( http://stackoverflow.com/questions/25576762/warped-scene-with-two-sets-of-geodes ), but I assume that this is a more appropriate place for questions. I have a few objects that I want to combine into a scene graph: Street inherits from Geode and has a Geometry child drawable made up of a GL_LINE_STRIP. Pointer inherits from PositionAttitudeTransform and contains a Geode which contains two Geometry polygons. When I add a bunch of Streets to a Group, it looks just fine. When I add only the Pointer to a Group, it also looks fine. But if I somehow have them both in the scene, the second one is screwed up. (This does not happen if I have only two Pointers.) I posted some screenshots on the StackOverflow site, in case you want to see them. Probably I’m making some simple mistake—but I can’t see it! Here is some code that causes the problem (I tried to shorten it a little): // My libraries: #include asl/util/draw.h #include asl/util/color.h using namespace asl; #include straph/point.h #include straph/straph.h using namespace straph; // Standard and OSG libraries: #include utility #include boost/tuple/tuple.hpp // tie using namespace std; #include osg/ref_ptr #include osg/Array #include osg/Geometry #include osg/Group #include osg/LineWidth using namespace osg; #include osgUtil/Optimizer #include osgViewer/Viewer #include osgViewer/ViewerEventHandlers using namespace osgViewer; Geode* createStreet(const straph::Polyline path, double width, const Color color) { ref_ptrGeometry geom (new Geometry); // Set the shape: ref_ptrVec3dArray array (new Vec3dArray(path.size())); for (unsigned i = 0; i path.size(); ++i) { (*array)[i] = toVec3d(path[i]); } geom-setVertexArray(array.get()); geom-addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, array-size())); // Set the normals: ref_ptrVec3Array normals (new Vec3Array(1)); (*normals)[0].set( 0.0f, 0.0f, 1.0f ); geom-setNormalArray( normals.get() ); geom-setNormalBinding( Geometry::BIND_OVERALL ); // Set the colors: ref_ptrVec4Array colors = new Vec4Array(); colors-push_back(color.get()); geom-setColorArray(colors); geom-setColorBinding(osg::Geometry::BIND_OVERALL); Geode* g = new Geode(); g-addDrawable(geom.get()); // Set the line width. ref_ptrLineWidth lwidth (new LineWidth); lwidth-setWidth(width); g-getOrCreateStateSet()-setAttributeAndModes(lwidth, StateAttribute::ON); return g; } Group* load_streets() { unique_ptrStraph graph = read_shapefile(mexico/roads, 6); Group* root = new Group(); boost::graph_traitsstraph::Straph::edge_iterator ei, ee; for (boost::tie(ei, ee) = edges(*graph); ei != ee; ++ei) { const straph::Segment s = (*graph)[*ei]; root-addChild(createStreet(s.polyline, 2.0, TangoColor::Aluminium4)); } return root; } int main(int, char**) { Group* root = load_streets(); Pointer* p = new Pointer(6.0, TangoColor::Scarlet3, TangoColor::Black); root-addChild(p); Viewer viewer; viewer.setSceneData(root); viewer.getCamera()-setClearColor(Color(TangoColor::White).get()); viewer.run(); } Thanks for the help! :-)  –Ben Morgan ___ 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