Hi Robert,
You are quite right, not to merge the changes in the IntersectKdTree::intersect
method. I have tested our application/datasets against svn/trunk 11008 with the
merged KdTree files.
It solved that problem.
However, during the testing, I found another combination that fails to find
intersections. This time KdTree works fine, but the other way (without KdTree)
it fails.
It could easily be reproduced by just changing a little in the test example,
which is updated and attached.
I do not have any solution to this problem yet. Shall I continue with this
thread or submit in a new one, if I find a way to solve the new problem.
Regards,
Lars.
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Robert
Osfield
Sent: den 26 januari 2010 14:04
To: OpenSceneGraph Submissions
Subject: Re: [osg-submissions] LineSegmentIntersector using KdTree sometimes
fails
Hi Lars,
Thanks for the fix and test example. I've merged most of your changes
to KdTree - in particular the change in parameter Vec3d type to the
KdTree::intersect() method, and in the IntersectKdTree constructor.
I didn't find it necessary to merge the change the
IntersectKdTree::intersect method as it's internal maths is all Vec3
based so I didn't see any advantage in making this change. Your test
example works fine without merging this.
As a more general issue, I do wonder about whether we should still
instigate a full Vec3d/Vec3 implementation where the later can be used
for speed, and the full Vec3d math version used where precision is
more critical. There is a limit on precision though as the vertex
data on geometry is in Vec3's.
The combined changes are now checked into svn/trunk. Could you please
test with your application/datasets to make sure that things are still
working at your end.
Cheers,
Robert.
On Tue, Jan 19, 2010 at 4:49 PM, Nilsson Lars
<[email protected]> wrote:
> Hi Robert
>
>
>
> Attached is a small program doing intersection calculations, both with and
> without KdTree. The geometry is a TRIANGLE_STRIP consisting of five
> vertices, all with the same rather high Z-value. If the intersection
> calculation uses KdTree, it fails. When I changed osg::Vec3 to osg::Vec3d in
> a few places in osg::KdTree it finds the correct intersection point.
>
>
>
> Another way to solve the problem was to increase the expansion of the
> bounding-box in osgUtil::LineSegmentIntersector::intersectAndClip.
>
>
>
> The version of OSG that I use is 2.9.6.
>
>
>
> Because I do not have enough knowledge in KdTree to understand what other
> implications these changes may have, I tried a week ago to start a
> discussion in osg-user mailing list to find out if either of these fixes
> seems to be reasonable. But there was no response. Now it is up to you to
> decide which one, or none of them to be used.
>
>
>
> Regards,
>
> Lars Nilsson
>
>
>
>
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
#include <iostream>
#include <osg/Geode>
#include <osg/KdTree>
#include <osgUtil/LineSegmentIntersector>
int main(int argc, char *argv[])
{
for (int i=0; i<2; ++i) {
const bool useKdTree = (i == 0);
const float Z = 3000.0;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(86093.9, 30625.9, Z));
vertices->push_back(osg::Vec3(86077.8, 30669.0, Z));
vertices->push_back(osg::Vec3(83483.4, 29653.5, Z));
vertices->push_back(osg::Vec3(83000.0, 30000.0, Z));
vertices->push_back(osg::Vec3(80000.0, 30000.0, Z)); // at least 5 vertices
are needed to invoke KdTree (default)
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
geometry->setVertexArray(vertices.get());
geometry->addPrimitiveSet(new
osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, vertices->size()));
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(geometry.get());
if (useKdTree) {
osg::ref_ptr<osg::KdTreeBuilder> kdTreeBuilder = new osg::KdTreeBuilder;
geode->accept(*(kdTreeBuilder.get()));
}
const osg::Vec2d XY(84718.3, 30129.7);
const osg::Vec3d start(XY, 0.0);
const osg::Vec3d end(XY, 1e9);
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new
osgUtil::LineSegmentIntersector(start, end);
osgUtil::IntersectionVisitor iv(intersector.get());
iv.reset();
geode->accept(iv);
osgUtil::LineSegmentIntersector::Intersections& intersections =
intersector->getIntersections();
std::cout << "KdTree " << (useKdTree ? "on " : "off ");
if (intersections.empty()) std::cout << "No intersections ";
else std::cout << intersections.begin()->localIntersectionPoint[2];
std::cout << std::endl;
}
return 0;
}
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org