Re: [osg-users] Visibility of lines

2012-12-18 Thread Jen Hunter
Hi, 

I think there might be a small bug in osg::OcclusionQueryNode, that I've yet to 
find.

Here is a small example with a line triangle, that shows the problem.
I added no face geometry so the lines should basically always be visible when 
in view.
Each line is under an OcclusionQueryNode, but under some camera poses using the 
trackball manipulator, line 3 isn't visible, although it should be.
When I put all the lines in a osg::Group, they are visible.

Does anybody have an idea where the problem might be?


Code:

#include osg/Group 
#include osgViewer/Viewer 
#include osgViewer/ViewerEventHandlers
#include osgGA/TrackballManipulator
#include osg/OcclusionQueryNode
#include vector

 int main( int argc, char** argv ) 
 { 
int width = 640;
int height = 480;

osgViewer::Viewer viewer;
osg::ref_ptrosg::Camera camera = new osg::Camera;
camera-setClearColor(osg::Vec4(1.0, 1.0, 1.0, 0.0)); 
camera-setViewport( new osg::Viewport(0, 0, width, height) );
camera-setProjectionMatrixAsPerspective(30.0f, 
static_castdouble(width)/static_castdouble(height), 1.0f, 1.0f );
viewer.setCamera(camera);

osg::Group* rootnode = new osg::Group;
viewer.setSceneData(rootnode);
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.setUpViewInWindow(200, 200, width, height);
viewer.setCameraManipulator( new osgGA::TrackballManipulator );

std::vectorosg::Vec3 lines;

//Line 1
lines.push_back(osg::Vec3(-1,0,0));
lines.push_back(osg::Vec3(0,1,0));

//Line 2
lines.push_back(osg::Vec3(0,1,0));
lines.push_back(osg::Vec3(1,0,0));

//Line 3
lines.push_back(osg::Vec3(1,0,0));
lines.push_back( osg::Vec3(-1,0,0));

for(int i = 0; i  3; i++){

//osg::ref_ptrosg::Group parent = new osg::Group;
osg::ref_ptrosg::OcclusionQueryNode parent = new 
osg::OcclusionQueryNode;
parent-setVisibilityThreshold(1);
parent-setQueriesEnabled(true);

osg::Geometry* linesGeom = new osg::Geometry();
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices-push_back(lines.at(i+i));
vertices-push_back(lines.at(i+i+1));
osg::Vec4Array* color = new osg::Vec4Array;
color-push_back(osg::Vec4(1,0,0,1));
linesGeom-setColorArray(color);
linesGeom-setColorBinding(osg::Geometry::BIND_OVERALL);
linesGeom-setVertexArray(vertices);
linesGeom-addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINES,0,2));
osg::Geode* geode = new osg::Geode();
geode-addDrawable(linesGeom);
parent-addChild(geode);
rootnode-addChild(parent);
}
return viewer.run();
 }




Cheers,
Dakota

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51621#51621





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Visibility of lines

2012-12-12 Thread Jen Hunter
Hi Robert,

thank you for your reply. I appreciate your help :)

I'm sorry if I didn't express myself correctly. I also have to admit I'm not 
quite the expert on computer graphics.

Let's try to make it clearer. I want to know which of the lines on my model are 
visible in a rendered image. That would be the case if a line results in at 
least one drawn pixel.

I need to have this information for an AR application which performs edge 
tracking. Such approaches work with 2D-3D correspondences for each frame to 
estimate the camera parameters.
The recorded webcam image of an object shows of course only the edges of the 
object which are visible from the cameras point of view. To get the 
correspondences I need excactly the same lines on the model (from the last 
frame).

I programmed a working OPENGL example for finding out the visible lines using 
occlusion query glGetOcclusionQueryuivNV. 

At the moment I fail to understand how to make that work for OSG. I had a look 
at osgocclusionquery and the used OcclusionQueryNode and understand that it 
uses ARB_occlusion_query to check the pixel count.

I tried the following but the output of the visible lines is still incorrect:


Code:

osg::Node* scene = osgDB::readNodeFile(file.dae);
if (!scene) return 1;

osg::Group* rootnode = new osg::Group;
rootnode-addChild(scene);
viewer.setSceneData(rootnode);

GetLinesVisitor lineFinder; 
scene-accept(lineFinder);
lines = lineFinder.getLineVector();

for(int i = 0; i  lines.size(); i++){

osg::ref_ptrosg::OcclusionQueryNode parent = new 
osg::OcclusionQueryNode;
parent-setVisibilityThreshold( 0 );

osg::Geometry* linesGeom = new osg::Geometry();
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices-push_back(lines.at(i).start);
vertices-push_back(lines.at(i).end);
linesGeom-setVertexArray(vertices);
linesGeom-addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINES,0,2));

osg::Geode* geode = new osg::Geode();
geode-addDrawable(linesGeom);
parent-addChild(geode);


//A std::vector for all OcclusionQueryNodes. I later ask in a loop for 
each element oqNodes.at(i).get()-getPassed() and count the trues
oqNodes.push_back(parent);
rootnode-addChild(parent);
}






So here are my questions:

(1) How do I set up an OcclusionQueryNode for each line?

(2) Why does the approach from my previous post not work? Is the calculation of 
screen coordinates (using MVPW matrix) for a given vertex really so imprecise 
that I cannot count on this being the correct coordinates to look up in the 
depth buffer?


Cheers,
Dakota

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51538#51538





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How convert osg::Image to OpenCV IplImage

2012-10-30 Thread Jen Hunter
Hi Koduri,

for the project I'm working on I needed something similar.
Using the C++ API of OpenCV I found the following code to be working:


Code:

osgImg-readPixels( 0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE );
cv::Mat cvImg(osgImg-t(), osgImg-s(), CV_8UC3); 
cvImg.data = (uchar*)osgImg-data();

// Flipping because of different origins
cv::flip(cvImg, cvImg, 0);





Cheers,
Dakota

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50895#50895





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Origin of pixel coordinates?

2012-02-21 Thread Jen Hunter
Hi Paul,

oh ok, my fault. I should have thought of that.
Thank you very much for your reply, now it's clear. :)

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45632#45632





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Origin of pixel coordinates?

2012-02-17 Thread Jen Hunter
Dear community,

I use the OpenCV Library to collect feature points in an image and I need to do 
intersection testing through the 2D-coordinates of these feature points with 
osg.

The origin of the opencv image data structure is top left. The topmost pixel on 
the left side is 0,0 and the bottommost on the right side is 639, 479 for 
images with the resolution 640x480.

OpenSceneGraph has its origin at the bottom left.  That's no problem so far. If 
the origin of Osg was at 0,0 bottom left I would just need to use (x, (height - 
1) - y) to get a conversion.

But is the Origin of the visible osgviewer at 0,0? because when I use a 
PickHandler i get at each corner:

Bottom left: 0, 1
Bottom right: 639, 1
Top left: 0, 480
Top right: 639, 480

So, is the origin really at 0,1? I thought it was strange that x and y 
coordinate origin are different. If it was like that I would need to use (x, 
height - y) .

This is the code I used to check the coordinates. Is there something I missed 
or are my thoughts correct?


Code:

#include windows.h
#include iostream
#include osgViewer/Viewer
#include osgViewer/ViewerEventHandlers
#include osgGA/TrackballManipulator

class PickHandler : public osgGA::GUIEventHandler {

public: 
PickHandler(){}
~PickHandler() {}
bool handle(const osgGA::GUIEventAdapter ea,osgGA::GUIActionAdapter aa);
virtual void pick(osgViewer::View* view, const osgGA::GUIEventAdapter ea);
  
};

bool PickHandler::handle(const osgGA::GUIEventAdapter 
ea,osgGA::GUIActionAdapter aa){

switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::PUSH):
{
osgViewer::View* view = 
dynamic_castosgViewer::View*(aa);
if (view) pick(view,ea);
return false;
}
default:
return false;
}
}

void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter ea){
float x = ea.getX();
float y = ea.getY();
std::coutX: x  Y: ystd::endl;
}

int main( int argc, char **argv ){

osg::ref_ptrosg::Group root = new osg::Group;
osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer();
viewer-setSceneData(root.get());
viewer-addEventHandler(new osgViewer::StatsHandler);
viewer-setCameraManipulator(new osgGA::TrackballManipulator);
viewer-addEventHandler(new PickHandler());
viewer-setUpViewInWindow(100, 50, 640, 480);
viewer-run();
}




Thank you!
Dakota

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45529#45529





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] computeIntersections performance

2012-01-06 Thread Jen Hunter
Hi Robert,

thanks for your reply. :)

The stats of my scene are as follows:

Stateset: 17
Group: 7
Transform: 5
LOD: 0
Switch: 0
Geode: 57
Drawable: 175
Geometry:  175
Vertices: 10508
Primitives: 3993

I guess the model isn't as simple as described it. ;)
However, I really thinks it still isn't a very complex model, compared to 3D 
buildings or industrial gadgets. 

I tested it also with the dumptruck and cow osg files and the speed outcome is 
quite similiar. 

I made an example programm using the cow:

Code:

#include windows.h
#include iostream
#include vector

#include osgViewer/Viewer
#include osgViewer/ViewerEventHandlers
#include osg/io_utils
#include osg/MatrixTransform
#include osg/Geode
#include osg/Group
#include osgDB/ReadFile

int width = 640;
int height = 480;
std::string modelFile = cow.osg;

int main(int , char **){

//KD-Tree usage

osgDB::Registry::instance()-setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES);

osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer();
osg::ref_ptrosg::Group root = new osg::Group;
osg::ref_ptrosg::Node loadedModel = 
osgDB::readNodeFile(modelFile.c_str());
osg::ref_ptrosg::MatrixTransform arTransform = new 
osg::MatrixTransform();

arTransform-getOrCreateStateSet()-setRenderBinDetails(100, 
RenderBin);
arTransform-addChild(loadedModel);
root-addChild(arTransform.get());

viewer-setSceneData(root.get());
viewer-addEventHandler(new osgViewer::StatsHandler);
viewer-setUpViewInWindow(200, 200, width, height);

osg::Matrix trans;
trans.makeTranslate( 0., 0., -12. );
osg::Matrix rot;
rot.makeRotate(
  osg::DegreesToRadians(-90.0), osg::Vec3(1,0,0), 
  osg::DegreesToRadians(0.0), osg::Vec3(0,1,0) , 
  osg::DegreesToRadians(0.0), osg::Vec3(0,0,1) ); 

viewer-getCamera()-setViewMatrix(rot * trans);

//  generate random image points -

struct ImgPoint{
double x;
double y;
};

int numImagePoints = 800;
srand((unsigned)time(0));

std::vectorImgPoint points;
for (int i = 0; i  numImagePoints; i++) {
ImgPoint p = {(rand()/(double)RAND_MAX)*width, 
(rand()/(double)RAND_MAX)*height };
points.push_back(p);
}

//  intersections -

std::vectorImgPoint intersectionPoints;
std::vectorosg::Vec3d modelPoints;

//necessary so that Y values won't be inverted if there hasn't been 
mouse interaction yet
viewer-getEventQueue()-getCurrentEventState()-setMouseYOrientation( 
osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS );


//time start
LONGLONG g_Frequency, g_CurentCount, g_LastCount; 
if (!QueryPerformanceFrequency((LARGE_INTEGER*)g_Frequency)) 
printf(%s\n, Performance Counter nicht vorhanden); 
QueryPerformanceCounter((LARGE_INTEGER*)g_CurentCount);

osgUtil::LineSegmentIntersector::Intersections intersections;
std::vectorImgPoint::iterator myPointVectorIterator;

for(myPointVectorIterator = points.begin(); myPointVectorIterator != 
points.end(); myPointVectorIterator++){
if(viewer-computeIntersections(myPointVectorIterator-x,  
myPointVectorIterator-y, intersections)){

intersectionPoints.push_back(*myPointVectorIterator); 
osgUtil::LineSegmentIntersector::Intersection 
first = *(intersections.begin()); 

modelPoints.push_back(first.getWorldIntersectPoint());
}
}

//time stop
QueryPerformanceCounter((LARGE_INTEGER*)g_LastCount); 
double dTimeDiff = 
(((double)(g_LastCount-g_CurentCount))/((double)g_Frequency)); 
dTimeDiff = dTimeDiff * 1000;
printf(%s %s %f \n, Intersection:, (ms): \n, dTimeDiff);

std::coutNumber Image Points:  points.size()std::endl;
std::coutNumber Model Points intersected :  
modelPoints.size()std::endl;

while (!viewer-done()){
viewer-frame();
}
}




Maybe I do something wrong. The only line I use for KD Tree usage is the first 
line in main. Is that correct?

Or is geometry like the model I have or cow or dumptruck already to complex too 
use for realtime intersection testing with ~800 points?


Thanks!

Cheers,
Jen

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=44668#44668





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] computeIntersections performance

2011-12-14 Thread Jen Hunter
Hi,

I'm curious about the time it takes to do intersection testing.

I have roughly 800 Image points that I need to check for intersection with my 
model.
My model isn't really complicated, it's basically just a huge box with a few 
rectangular elements that stand out a bit.
It was created using Sketchup and is in Collada file format. I use the method 
computeIntersections. I'm working with OSG 2.8.2.

However, even with kdtree support it takes about 120 to 190 ms to test for the 
800 intersections.
Without kdtrees it takes up to above 400 ms. I'm confused that it varies so 
much when the setup of the scene I tested was always the same.

I am by no means an expert in computer graphics, so I ask you. 
Is it normal that it takes so long even for kdtrees, or is it likely that I do 
something terribly wrong?

Thank you!

Cheers,
Dakota

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=44379#44379





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Left-handed to right-handed

2011-10-24 Thread Jen Hunter
Hi,

I am currently working on a pose estimation combined with OpenSceneGraph 
rendering.
It seems that the POSIT algorithm from OpenCv needs modelpoints from a left 
handed coordinate system. 
I am working with Sketchup exported Collada files that are right handed. 
OpenSceneGraph is as OpenGL right handed as well.

So I calculate the pose with the POSIT algorithm with left handed input 3D 
points and get a left handed pose.
When I apply a negative scaling along z and change the winding order to 
osg::FrontFace::CLOCKWISE it is displayed left-handed.

For various reasons I'd rather have it displayed right-handed as usual.

I was wondering if there is a way to transform a left-handed modelview matrix 
into a right-handed one?

I'd really appreciate any idea.

Thank you!
Dakota

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43516#43516





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org