Points Selection

Started by
14 comments, last by Flatus 16 years, 2 months ago
Can someone help me with selection? I am drawing a big cloud of points (over 5000) and want to select the points with mouse and highlight them (nearest single point). The example with planets from opengl books doesn't help me much, because I am not defining any names to the points and I not using SWITCH function (too much data). Thanks
Advertisement
Quote:Original post by backspin
Can someone help me with selection? I am drawing a big cloud of points (over 5000) and want to select the points with mouse and highlight them (nearest single point). The example with planets from opengl books doesn't help me much, because I am not defining any names to the points and I not using SWITCH function (too much data). Thanks
I would use a 'picking volume' for this. Using this method, you would build a list of points contained by the volume, and then select the one closest to the camera view plane.

The details kind of depend on what tools you're using. Are you using a math library of some sort? What language are you programming in?
I am writing an application in Visual C++ 6.0 in MFC. I am not using any complicated tools or methods. I was trying to use GLUT library, but the effect was not so good. I just want to draw point (already done) and select them with mouse click.

I'd reconsider using GL picking. It's easy, it works and it's about as efficient as anything you or I are likely to come up with (it's not blindingly fast but then this isn't a trivial procedure).

Here's a tutorial.

http://gpwiki.org/index.php/OpenGL:Tutorials:Picking
Ok, but what with the Names? Should I give every single point a name? I was also thinking about reading OpenGL coordinates and then after mouse click save one(x,y) and compare with the rest, but somethings wrong with my points translation and also I get huge numbers after rotating, moving or zooming.
It seems likely that your transformation problems stem from getting confused between object space, camera space and screen space.

Between the world and the screen a vertex is subjected to a shearing (perspective) and projection transformation. It gets 'flattened' into screen x,y coordinates and given a depth value. These screen coordinates are not the same as the world coordinates, even if your screen and world axes are aligned, and the depth value is not even the same type of value as a world z value... it is more like a layer number in photoshop. The original 3D data about the vertex is discarded, which is why GL employs the technique of redrawing objects to a selection buffer and giving them names so you can tell what it is that you picked.

If you want each individual point to be selectable then you give them each a name (an integer value)... if they are all in one array then you can use the index value as the name, then when your picking result is the name '27' you know that vertex[27] was selected.

[Edited by - ElectricVoodoo on February 13, 2008 5:49:17 AM]
thats my drawing function:

for(int i=0; i<points_limit; i++)
{
glBegin(GL_POINTS);
glLoadName(i);
glVertex3f(xpoint, ypoint, zpoint);
glEnd();

if(i<points_limit && line_link[i+1]=="" && lines_or_dots==0)
{
glBegin(GL_LINES);
glLoadName(i);
glVertex3f(xpoint, ypoint, zpoint);
glVertex3f(xpoint[i+1], ypoint[i+1], zpoint[i+1]);
glEnd();
}
}

my question is the LoadName() function correct? Then I get no errors or warnings in my code by still the hits value is zero. I know that the point are very small and it is hard to hit one but I have a big cloud of point, so I think I shoud hit something. Is there something to set the range around a point?
I found out when I enable glSwapBuffers() the application crashes. I included glut.h and also glup32.lib
Have you created a suitable buffer and passed it to GL with glSelectBuffer()?
Have you properly initialized the name stack by calling glInitNames and glPushName(0)?
Have you enabled glRenderMode(GL_SELECT)?
Have you taken into account that GL screen coordinates start from the bottom left although window coordinates start from the top left?

To increase the size of the hit region:

gluPickMatrix(mousex,
mousey,
PICK_REGION_SIZE, PICK_REGION_SIZE,
viewport);

PICK_REGION_SIZE is the size of your square hit region.
It is much faster if each point is rendered with another color into the back buffer (16m or 2³² should be enough) After that read the pixel below the mouse with glReadPixel. The opengl picking is not supported in hardware on many cards...

This topic is closed to new replies.

Advertisement