Hi All and Thanks for your feedback, Please find the reproduced example and obj file at the attachment, it doesn't have any visual aids,with 1st user click program creates leftbottom of rectangle, second user click creates righttop, for intersection rectangle and invokes PolytopeIntersector. If I select them all I'd expect totally 5 objects to be picked, but program produces 420. There is a high chance that as Sebastian Messerschmidtemphasized, I pick all vertices but can you confirm it ? > Admittedly, the current behaviour is of PolytopeIntersector is not very > space- or time-efficient > for your use-case. I think a useful extension would be some kind of > "only-first-intersection"-flag > which should reduce the number of generated intersecions for cases like yours.
I'm bit confused here, its a common practice to use rectangular, polygonal circle area selection in 3D applicaitons (e.g. Blender),that is even been suggested by the OSG Beginner book Chapter 9 "Have a go hero – selecting geometries in a rectangular region" the proper usage is POlytopeIntersector. Regards, > Date: Wed, 6 Aug 2014 09:43:14 +0200 > From: [email protected] > To: [email protected] > Subject: Re: [osg-users] [MASSMAIL] Erratical behaviour with > PolytopeIntersector > > Hello, > > On 08/04/2014 11:18 AM, Sonya Blade wrote: > > Dear All, > > > > I'm experiencing very weird problem when using the polytope intersector. > > Since there is not any explicit example on how > > to use polytope example with rectangular selection I use osgPick example in > > OSG and modify the codes to suit my need. > > The canonical example for PolytopeIntersector is osgkeyboardmouse which shows > one possible usage. > > > Normally the below code picks the objects on scene but shows that 400 > > picked objects which is not correct and far beyond of > > scene object range where that I have, I only have 5-6 object in scene, > > As Sebastian Messerschmidt has suggested the PolytopeIntersector returns > intersections on > a per-primitive level and that also includes all primitives inside the > polytope. > > If you only want results on a higher level (e.g. per drawable) you can just > modify > the counting loop in you code to eliminate duplicate drawables. > > Admittedly, the current behaviour is of PolytopeIntersector is not very > space- or time-efficient > for your use-case. I think a useful extension would be some kind of > "only-first-intersection"-flag > which should reduce the number of generated intersecions for cases like yours. > > > Cheers, > > Peter > > > What could be the reason of that malfunctioning ? I 'll appreciate your > > guidance on that !. > > > > case (osgGA::GUIEventAdapter::RELEASE): > > { > > if (btn_counter == 1 ) > > { > > firstX = ea.getX(); firstY = ea.getY(); > > btn_counter = 2; > > break; > > } > > > > if (btn_counter==2) > > { > > btn_counter = 1; > > osgUtil::PolytopeIntersector* polytop = new > > osgUtil::PolytopeIntersector( osgUtil::Intersector::WINDOW, firstX,firstY, > > ea.getX(), ea.getY() ); > > osgUtil::IntersectionVisitor iv(polytop); > > view->getCamera()->accept(iv); > > > > int k; > > if (polytop->containsIntersections() ) > > { > > > > osgUtil::PolytopeIntersector::Intersections > > intersections= polytop->getIntersections(); > > osg::Vec3 screenpos = > > osg::Vec3(ea.getX(),ea.getY(),0); > > > > > > for(osgUtil::PolytopeIntersector::Intersections::iterator hitr = > > intersections.begin(); > > hitr != intersections.end(); ++hitr) > > { > > k+=1; > > std::cout<< k << "----" << > > hitr->drawable->getName()<< hitr->drawable->className()<<"\n" ; > > > > } > > } > > } > > } > > } > > } > > }; > > > > > > > > _______________________________________________ > > osg-users mailing list > > [email protected] > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
test.obj
Description: Binary data
/* OpenSceneGraph example, osganimate.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <osg/Notify>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osg/Geometry>
#include <osg/Geode>
#include <osgUtil/IntersectionVisitor>
#include <osgUtil/Optimizer>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgSim/OverlayNode>
#include <osgViewer/Viewer>
#include <iostream>
int btn_counter;
float firstX, firstY;
class MyHandler : public osgGA::GUIEventHandler{
public:
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
if (!view) return false;
switch (ea.getEventType())
{
case (osgGA::GUIEventAdapter::RELEASE):
{
if (btn_counter == 1 )
{
firstX = ea.getX(); firstY = ea.getY();
btn_counter = 2;
break;
}
if (btn_counter==2)
{
btn_counter = 1;
osgUtil::PolytopeIntersector* polytop = new osgUtil::PolytopeIntersector( osgUtil::Intersector::WINDOW,
firstX,firstY, ea.getX()+2, ea.getY()+2 );
osgUtil::IntersectionVisitor iv(polytop);
//iv.setTraversalMask(0x1);
view->getCamera()->accept(iv);
int k=0;
polytop->setIntersectionLimit(osgUtil::Intersector::LIMIT_ONE_PER_DRAWABLE );
if (polytop->containsIntersections() )
{
osgUtil::PolytopeIntersector::Intersections& intersections= polytop->getIntersections();
osgUtil::PolytopeIntersector::Intersection intr = polytop->getFirstIntersection();
osg::Vec3 screenpos = osg::Vec3(ea.getX(),ea.getY(),0);
for(osgUtil::PolytopeIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end(); ++hitr)
{
k=k+1;
// osg::NodePath pth= hitr->nodePath;
std::cout<< k << "----" << hitr->drawable->getName()<< hitr->drawable->className()<<"\n" ;
//std::cout<<k<<intr.drawable->getName()<< "----"<< intr.drawable->className()<<"\n" ;
}
//intersections.clear();
break;
}
}
return false;
}
}
}
};
int main( int argc, char **argv )
{
// initialize the viewer.
osgViewer::Viewer viewer;
btn_counter =1;
// tilt the scene so the default eye position is looking down on the model.
osg::MatrixTransform* rootnode = new osg::MatrixTransform;
rootnode->setMatrix(osg::Matrix::rotate(osg::inDegrees(90.0f),1.0f,0.0f,0.0f));
rootnode->setMatrix(osg::Matrix::scale(0.2,-4,0.2));
for (int i=0; i<5; i++)
{
osg::PositionAttitudeTransform* trans =new osg::PositionAttitudeTransform();
trans->setPosition(osg::Vec3(rand()%20, 0,rand()%20));
osg::Node* loadedModel = osgDB::readNodeFile("./test.obj");
//osg::Node* loadedModel = osgDB::readNodeFile("D:/TEST_FOLDER_asus/ENGINES/OpenSceneGraph-Data-3.0.0/glider.osgt");
loadedModel->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON);
//rootnode->addChild(loadedModel);
trans->addChild(loadedModel);
rootnode->addChild(trans);
}
// run optimization over the scene graph
osgUtil::Optimizer optimzer;
optimzer.optimize(rootnode);
// set the scene to render
viewer.setSceneData(rootnode);
//viewer.setCameraManipulator(new osgGA::OrbitManipulator());
viewer.setUpViewInWindow(100, 100, 800, 400);
viewer.addEventHandler(new MyHandler);
// normal viewer usage.
return viewer.run();
}
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

