Re: [osg-users] PolytopeIntersector, LineSegmentIntersector, and PagedLOD
Hi Chris, I also fight a long time with PolytopeIntersector and PagedLOD. Did you add callback to read your PagedLOD? See osgSim::LineOfSight for an example. Does it help? Regards 2014-03-12 21:15 GMT+01:00 Chris Long : > Hi, > > I'm getting unexpected behavior from PolytopeIntersector and was wondering > if it might have something to do with the PagedLODs in my scene graph. > > I want to find all polygons in a rectilinear volume in my model, in model > coordinates (not related to any view on the screen) based on two corner > vertices. > > The weird thing is that if I use the two corner points as the ends of a > LineSegmentIntersector, I find intersections, but a PolytopeIntersector > with Polytope made from a BoundingBox with those same corner points, over > the same graph, finds no intersections. > > Shouldn't the PolytopeIntersector at least find the geometry that the > LineSegmentIntersector does? > > I thought I might have the direction of the planes backwards for the > Polytope, so I tried flip() but either way I get no intersections. > > I've read through the code and it looks like there might be issues related > to the PagedLODs in my scene graph. Any idea if PolytopeIntersector and > PagedLOD play together well or not? > > I've looked for examples and read code for PolytopeIntersector, but there > doesn't seem to be much out there, and most of it uses View-based > intersection, not model-based. > > Thank you! > > Cheers, > Chris > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=58575#58575 > > > > > > ___ > 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 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] PagedLOD and IntersectionVisitor
Robert, Thank you for your idea. Something that I forgive to mention in my posts is that the data I use to build the polytopes are in a geographic reference system, and my models are in local coordinates. I thus used to add a MatrixTransform to my input model (and to several nodes I had to create for my particular purpose). It seems that removing all this MatrixTransforms (translations) and simply translating GIS data did the trick. So, problem solved! Thanks again for your help. Regards, Olivier 2013/11/22 Robert Osfield > Hi Olivier, > > It sounds like the next thing to investigate would be the size of the > bounding sphere that it's testing against, perhaps there is an error in the > bounding sphere settings that is resulting in the traversal being culled > prematurely. > > Robert. > > > On 22 November 2013 14:03, Olivier Tournaire wrote: > >> Hi Robert, >> >> Thank you for your answer. Unfortunately, I cannot share the model ... >> However, I can share the code. >> >> Here it is: >> >> // Building a osgUtil::PolytopeIntersector from a CONCAVE planar polygon >> >> /* 1) split the concave polygon in its convex rings */ >> /* 2) iterate over each convex ring to build a convex >> osg::Polyope */ >> >> // Begin loop over convex rings >> osg::Polytope currentBuildingPolytope; >> for(int j=0;j> { >> osg::Vec3d A( ring.getX(j), ring.getY(j), ring.getZ(j) ); >> osg::Vec3d B( ring.getX(j+1), ring.getY(j+1), ring.getZ(j+1) ); >> osg::Vec3d C( ring.getX(j+1), ring.getY(j+1), >> ring.getZ(j+1)+delta ); // delta > 0. >> >> osg::Vec3d AB = B-A; AB.normalize(); >> osg::Vec3d BC = C-B; BC.normalize(); >> osg::Vec3d n = BC^AB; n.normalize(); >> >> osg::Plane p(n,A); >> currentBuildingPolytope.add(p); >> } >> osg::ref_ptr >> currentPolytopeIntersector = new >> osgUtil::PolytopeIntersector(currentBuildingPolytope); >> >> currentPolytopeIntersector->setDimensionMask(osgUtil::PolytopeIntersector::DimTwo); >> // End loop over convex rings >> >> /* 3) add the convex osg::Polytope to a vector< >> ref_ptr > */ >> _polytopeIntersectors.push_back(currentPolytopeIntersector); >> >> /* 4) Find intersections of the model with the previously build >> osgUtil::PolytopeIntersectors */ >> bool hasIntersections = false; >> for(unsigned int i=0;i<_polytopeIntersectors.size();++i) >> { >> osgUtil::IntersectionVisitor >> visitor(_polytopeIntersectors[i].get()); >> osg::ref_ptr _readCallback >> = new osgSim::DatabaseCacheReadCallback; >> visitor.setReadCallback(_readCallback); >> model->accept(visitor); // model contains one triangle per >> Drawable >> >> if(_polytopeIntersectors[i]->containsIntersections()) >> { >> hasIntersections = true; >> _numIntersections += >> _polytopeIntersectors[i]->getIntersections().size(); >> // ... >> } >> // ... >> } >> >> If you see anything wrong, please let me know. >> >> As I tols in my first post, the reader callback works quite well (my DB >> model contains around 150 files). Debugging my application, the method >> IntersectionVisitor::apply(osg::PagedLOD& plod) exits on the first line >> only if _intersectorStack.back()->enter(node); returns false. This happen >> in LineSegmentIntersector::intersects(const osg::BoundingSphere& bs), >> because of this line: >> if (d<0.0) return false; >> which seems to mean that the bounding sphere of the current PagedLOD is >> not intersected by the line. >> >> Hope this give you more :) >> >> Regards, >> >> Olivier >> >> >> 2013/11/21 Robert Osfield >> >>> Hi Oliver, >>> >>> I have looked at the OSG code and can't see a specific cause, but then I >>> don't have your code or models so it's all just guessing. >>> >>> Does LineOfSight work fine for you? If so I'd recommend stepping >>> through to see what happening and then compare it with your own usage. >>> >>> Robert. >>> >>> >>> On 19 November 2013 19:58, Olivier Tournaire wrote: >>> >>>> Hi all, >>>> >>>> Sorry for the noi
Re: [osg-users] PagedLOD and IntersectionVisitor
Hi Robert, Thank you for your answer. Unfortunately, I cannot share the model ... However, I can share the code. Here it is: // Building a osgUtil::PolytopeIntersector from a CONCAVE planar polygon /* 1) split the concave polygon in its convex rings */ /* 2) iterate over each convex ring to build a convex osg::Polyope */ // Begin loop over convex rings osg::Polytope currentBuildingPolytope; for(int j=0;j 0. osg::Vec3d AB = B-A; AB.normalize(); osg::Vec3d BC = C-B; BC.normalize(); osg::Vec3d n = BC^AB; n.normalize(); osg::Plane p(n,A); currentBuildingPolytope.add(p); } osg::ref_ptr currentPolytopeIntersector = new osgUtil::PolytopeIntersector(currentBuildingPolytope); currentPolytopeIntersector->setDimensionMask(osgUtil::PolytopeIntersector::DimTwo); // End loop over convex rings /* 3) add the convex osg::Polytope to a vector< ref_ptr > */ _polytopeIntersectors.push_back(currentPolytopeIntersector); /* 4) Find intersections of the model with the previously build osgUtil::PolytopeIntersectors */ bool hasIntersections = false; for(unsigned int i=0;i<_polytopeIntersectors.size();++i) { osgUtil::IntersectionVisitor visitor(_polytopeIntersectors[i].get()); osg::ref_ptr _readCallback = new osgSim::DatabaseCacheReadCallback; visitor.setReadCallback(_readCallback); model->accept(visitor); // model contains one triangle per Drawable if(_polytopeIntersectors[i]->containsIntersections()) { hasIntersections = true; _numIntersections += _polytopeIntersectors[i]->getIntersections().size(); // ... } // ... } If you see anything wrong, please let me know. As I tols in my first post, the reader callback works quite well (my DB model contains around 150 files). Debugging my application, the method IntersectionVisitor::apply(osg::PagedLOD& plod) exits on the first line only if _intersectorStack.back()->enter(node); returns false. This happen in LineSegmentIntersector::intersects(const osg::BoundingSphere& bs), because of this line: if (d<0.0) return false; which seems to mean that the bounding sphere of the current PagedLOD is not intersected by the line. Hope this give you more :) Regards, Olivier 2013/11/21 Robert Osfield > Hi Oliver, > > I have looked at the OSG code and can't see a specific cause, but then I > don't have your code or models so it's all just guessing. > > Does LineOfSight work fine for you? If so I'd recommend stepping through > to see what happening and then compare it with your own usage. > > Robert. > > > On 19 November 2013 19:58, Olivier Tournaire wrote: > >> Hi all, >> >> Sorry for the noise, but, as I did not receive any answer, I am >> interested if someone has an idea on the topic. >> >> Regards, >> >> Olivier >> >> >> 2013/11/15 Olivier Tournaire >> >>> Hi, >>> >>> I am currently trying to retrieve some specific triangles in a PagedLOD >>> model. To do so, I use a PolytopeIntersector with an IntersectionVisitor. >>> As my model is a PagedLOD, I have set up a reader callback, directly taken >>> from osgSim::LineOfSight. >>> >>> The intersector works, but not as expected: it gives me the triangles at >>> the lowest resolution, whereas I would expect to have them at the finest >>> LOD. Debugging my program showed me that the void >>> IntersectionVisitor::apply(osg::PagedLOD& plod) method goes where it has to >>> (i.e., it traverses correctly all childs until the best resolution). >>> >>> As the IntersectionVisitor sets up by default to use >>> the USE_HIGHEST_LEVEL_OF_DETAIL flag, I am wondering if I am missing >>> something and if you could give some pointers on how to achieve triangles >>> extraction at the finest LOD. >>> >>> The "header" root file is: >>> >>> osg::PagedLOD { >>> UniqueID 1 >>> Name "Tile_+001_+006.osgb" >>> CenterMode USER_DEFINED_CENTER >>> UserCenter -741.555 904.039 94.1168 213.403 >>> RangeMode PIXEL_SIZE_ON_SCREEN >>> RangeList 2 { >>> 0 106.702 >>> 106.702 1e+030 >>> } >>> DatabasePath FALSE >>> RangeDataList 2 { >>> "" >>> "Tile_+001_+006_L15_0.osgb" >>> } >>> PriorityList 2 { >>> 0 1 >>> 0 1 >>> } >>
Re: [osg-users] PagedLOD and IntersectionVisitor
Hi all, Sorry for the noise, but, as I did not receive any answer, I am interested if someone has an idea on the topic. Regards, Olivier 2013/11/15 Olivier Tournaire > Hi, > > I am currently trying to retrieve some specific triangles in a PagedLOD > model. To do so, I use a PolytopeIntersector with an IntersectionVisitor. > As my model is a PagedLOD, I have set up a reader callback, directly taken > from osgSim::LineOfSight. > > The intersector works, but not as expected: it gives me the triangles at > the lowest resolution, whereas I would expect to have them at the finest > LOD. Debugging my program showed me that the void > IntersectionVisitor::apply(osg::PagedLOD& plod) method goes where it has to > (i.e., it traverses correctly all childs until the best resolution). > > As the IntersectionVisitor sets up by default to use > the USE_HIGHEST_LEVEL_OF_DETAIL flag, I am wondering if I am missing > something and if you could give some pointers on how to achieve triangles > extraction at the finest LOD. > > The "header" root file is: > > osg::PagedLOD { > UniqueID 1 > Name "Tile_+001_+006.osgb" > CenterMode USER_DEFINED_CENTER > UserCenter -741.555 904.039 94.1168 213.403 > RangeMode PIXEL_SIZE_ON_SCREEN > RangeList 2 { > 0 106.702 > 106.702 1e+030 > } > DatabasePath FALSE > RangeDataList 2 { > "" > "Tile_+001_+006_L15_0.osgb" > } > PriorityList 2 { > 0 1 > 0 1 > } > > The "header" of the child file (Tile_+001_+006_L15_0.osgb) is: > > osg::PagedLOD { > UniqueID 1 > Name "Tile_+001_+006_L15_0.osgb" > CenterMode USER_DEFINED_CENTER > UserCenter -741.869 906.466 94.7166 206.312 > RangeMode PIXEL_SIZE_ON_SCREEN > RangeList 2 { > 0 206.312 > 206.312 1e+030 > } > DatabasePath FALSE > RangeDataList 2 { > "" > "Tile_+001_+006_L16_00.osgb" > } > PriorityList 2 { > 0 1 > 0 1 > } > > > Hope you could help > > Regards, > > Olivier > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] PagedLOD and IntersectionVisitor
Hi, I am currently trying to retrieve some specific triangles in a PagedLOD model. To do so, I use a PolytopeIntersector with an IntersectionVisitor. As my model is a PagedLOD, I have set up a reader callback, directly taken from osgSim::LineOfSight. The intersector works, but not as expected: it gives me the triangles at the lowest resolution, whereas I would expect to have them at the finest LOD. Debugging my program showed me that the void IntersectionVisitor::apply(osg::PagedLOD& plod) method goes where it has to (i.e., it traverses correctly all childs until the best resolution). As the IntersectionVisitor sets up by default to use the USE_HIGHEST_LEVEL_OF_DETAIL flag, I am wondering if I am missing something and if you could give some pointers on how to achieve triangles extraction at the finest LOD. The "header" root file is: osg::PagedLOD { UniqueID 1 Name "Tile_+001_+006.osgb" CenterMode USER_DEFINED_CENTER UserCenter -741.555 904.039 94.1168 213.403 RangeMode PIXEL_SIZE_ON_SCREEN RangeList 2 { 0 106.702 106.702 1e+030 } DatabasePath FALSE RangeDataList 2 { "" "Tile_+001_+006_L15_0.osgb" } PriorityList 2 { 0 1 0 1 } The "header" of the child file (Tile_+001_+006_L15_0.osgb) is: osg::PagedLOD { UniqueID 1 Name "Tile_+001_+006_L15_0.osgb" CenterMode USER_DEFINED_CENTER UserCenter -741.869 906.466 94.7166 206.312 RangeMode PIXEL_SIZE_ON_SCREEN RangeList 2 { 0 206.312 206.312 1e+030 } DatabasePath FALSE RangeDataList 2 { "" "Tile_+001_+006_L16_00.osgb" } PriorityList 2 { 0 1 0 1 } Hope you could help Regards, Olivier ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Struggling trying to convert geometry coordinates in PagedLOD
Hi Robert, 2013/3/14 Robert Osfield > Hi Olivier, > > > On 13 March 2013 18:44, Olivier Tournaire wrote: > > However, having a detailed look at the original data, I saw that (A > PagedLOD > > has always a single Geode with a single Drawable): > > * PagedLOD center/radius is not the same as the Geode bound center/radius > > The PageLOD's coordinate frame is in world coordinates while the leaf > nodes that sit below the MatrixTransform are in local coordinates so > one should expect the values of the bounding volume and center/radius > to be different. > OK, but in the original data, there is no MatrixTransform between the PagedLOD and the Geode. So, do not understand why center/radius are different. > > > In the current version of my code, I set the PagedLOD center as the new > > center computed from the coordinate transform, and set its radius > according > > to the Geode bound radius after conversion. I tried, to update the > PagedLOD > > raidus keeping the initial ratio, but the problem is still there. > > However, this might also be related to the PagedLOD center. Do you have > any > > idea on how to update its value, taking into account the new and old > Geode > > centers, the old PagedLOD center? > > The answer is above, the PagedLOD should be set up in world > coordinates not local coordinates. > > Robert. > ___ > 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 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Struggling trying to convert geometry coordinates in PagedLOD
Hi Robert, Thank you for your reply. Regarding the precision issue, I take care to do all computation in double (which works because original coordinates are in local reference frame), and, once transformed, I can safely use float without loss of precision. As VPB and osgEarth, the MatrixTransform is below the PagedLOD and directly above the Geode as you suggested. However, having a detailed look at the original data, I saw that (A PagedLOD has always a single Geode with a single Drawable): * PagedLOD center/radius is not the same as the Geode bound center/radius In the current version of my code, I set the PagedLOD center as the new center computed from the coordinate transform, and set its radius according to the Geode bound radius after conversion. I tried, to update the PagedLOD raidus keeping the initial ratio, but the problem is still there. However, this might also be related to the PagedLOD center. Do you have any idea on how to update its value, taking into account the new and old Geode centers, the old PagedLOD center? Regards, Olivier 2013/3/13 Robert Osfield > Hi Olivier, > > I principle what you are doing sounds reasonable. The only odd bit in > the description is that your data is already in OSG form before you > transform it into local coords, to me this seems like a missed > opportunity - as osg::Geometry stores coords with Vec3Array by default > so will be using float positions so open to precision issues, > subsequently moving these vertices into local coords won't fix the > precision problem as it's already backed into the data. Tools like > VirtualPlanetBuilder and osgEarth all convert from > geographic/geocentric coords that use doubles for position to local > coords with floats for the vertex data and doubles in the > MatrixTransform that decorate the local coordinate frames. > > The problems with missing tiles/wrong tiles suggests to be an issue > with LOD range or centers. I guess it could also be something like > placing the transforms in the wrong place so that the LOD > centers/ranges aren't in the coordinate frame you think they are in. > Both VirtualPlanetBuilder and osgEarth place the MatrixTransform below > the PagedLOD and directly above the geometry. > > Robert. > > On 13 March 2013 11:54, Olivier Tournaire wrote: > > Hi Robert, > > > > So, I will try to summarize my post, without any code :) With my first > post, > > I tried to be as complete as possible to clearly describe the issue, with > > all the related code. Sorry for this. > > > > Thus, I am trying to convert geometry coordinates of Drawables contained > in > > Geodes. My Geodes are children of PagedLOD, and there is a single Geode > per > > PagedLOD. For a given part of my terrain, I have more than 1000 files, > with > > 9 levels of details. > > > > To convert the coordinates, I simply parse the coordinates in my original > > geometries, apply the transformation (code of my own and with proj4) and > > then use the setVertexArray method to replace the geometry coordinates > in my > > drawables. I do this for each file. I center the coordinates around > (0,0,0) > > because they are in 10e+06, and then add on top of my Geodes a > translation > > MatrixTransform which value come from the barycenter of the points. If my > > Geode is contained in a PagedLOD, I also set the UserCenter to this > value. > > > > The problem is that when I view the transformed hierarchy in osgviewer, > > sometimes, when I am really close from the terrain, some tiles > disappear. If > > I move a few, they appear again. It also seems that the "order" of the > > loaded tiles is incorrect. Both problems are illustrated by this images: > > http://imageshack.us/photo/my-images/109/badtiles.png/ > > http://imageshack.us/photo/my-images/685/pagedlodsranges.jpg/ > > > > > > > > Hope you could help. > > > > Best regards, > > > > Olivier > > > > 2013/3/13 Robert Osfield > >> > >> Hi Oliver, > >> > >> On 13 March 2013 07:54, Olivier Tournaire wrote: > >> > No one on this? > >> > >> I suspect you lost a lot of readers with the volume of your post, > >> please remember that all members of the community are busy working and > >> only have a little time to read and keep up with posts and write > >> replies. Try distilling the issue you have down to what others might > >> be able to easily understand and provide an answer for. > >> > >> Robert. > >> ___ > >> osg-users mailing list > >> osg-users@lists.openscenegraph.org &
Re: [osg-users] Struggling trying to convert geometry coordinates in PagedLOD
Hi Robert, So, I will try to summarize my post, without any code :) With my first post, I tried to be as complete as possible to clearly describe the issue, with all the related code. Sorry for this. Thus, I am trying to convert geometry coordinates of Drawables contained in Geodes. My Geodes are children of PagedLOD, and there is a single Geode per PagedLOD. For a given part of my terrain, I have more than 1000 files, with 9 levels of details. To convert the coordinates, I simply parse the coordinates in my original geometries, apply the transformation (code of my own and with proj4) and then use the setVertexArray method to replace the geometry coordinates in my drawables. I do this for each file. I center the coordinates around (0,0,0) because they are in 10e+06, and then add on top of my Geodes a translation MatrixTransform which value come from the barycenter of the points. If my Geode is contained in a PagedLOD, I also set the UserCenter to this value. The problem is that when I view the transformed hierarchy in osgviewer, sometimes, when I am really close from the terrain, some tiles disappear. If I move a few, they appear again. It also seems that the "order" of the loaded tiles is incorrect. Both problems are illustrated by this images: http://imageshack.us/photo/my-images/109/badtiles.png/ http://imageshack.us/photo/my-images/685/pagedlodsranges.jpg/ Hope you could help. Best regards, Olivier 2013/3/13 Robert Osfield > Hi Oliver, > > On 13 March 2013 07:54, Olivier Tournaire wrote: > > No one on this? > > I suspect you lost a lot of readers with the volume of your post, > please remember that all members of the community are busy working and > only have a little time to read and keep up with posts and write > replies. Try distilling the issue you have down to what others might > be able to easily understand and provide an answer for. > > Robert. > ___ > 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 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] PagedLOD and coordinates transform
Hi all, I have a question regarding PagedLOD. I use as input a hierarchy of files. The vertices in the geometries are in a local reference system, and, for some reason, in need to transform them to a projected coordinate system : Lambert 93. I have a transformation which works fine. However, Lambert 93 coordinates are around 100 for X and around 600 for Y. I thus center them with the barycenter of all the vertices in the geometry and apply a MatrixTransform (translate) with this center with the Geode as child (and the PagedLOD as parent). I also set the PagedLOD user center to this value. To be sure to not loss anything in the scene graph I just replace the "old" geometry with the "new" one using setVertexArray This process works fine (I work in double precision). However, when having a look at the details, it seems that they is a remaining problem. It seems that LODs are not correctly displayed : https://www.dropbox.com/s/ulg311af9qizlz3/pagedlods_ranges.jpeg. This image is a screenshot of my terrain viewed from top (perpendicular). It seems to me that some LODs are not correct since some of them are more detailled than some others whereas they are at the same or a lower distance. Sometimes, when I am very close ftom the terrain and rotate, the closest tile disappear, and, if I move a few, it appears again. I guess this is a ranges or culling problem. For now, I do not change them. They are in PIXEL_SIZE_ON_SCREEN. I tried to update them by multiplying or dividing the values by a ratio of old and new boundingsphere radius, but the problem remains. In the original data, the problem does not appear. Do you have any idea on how to solve this issue? Regards, Olivier ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org