Main Page | Report this Page
Computers Forum Index  »  Computer - Graphics - API (Opengl)  »  Recognize objects on a chart at specific position...
Page 1 of 1    

Recognize objects on a chart at specific position...

Author Message
cognacc...
Posted: Fri Aug 28, 2009 2:12 pm
Guest
Hi

Im developing a chart for sailing boats.
as a part of my exam project.
If i have my OpenGL graphics window, and i
click in it with the mouse, somewhere on the chart.
I want to recognize the "object" im clicking on and forexample
reference textual information belonging to that OpenGL
primitive / point / line / etc.
Is there a way to do that, that i am missing?.


mic
 
Wolfgang Draxinger...
Posted: Sat Aug 29, 2009 12:21 am
Guest
cognacc wrote:

Quote:
I want to recognize the "object" im clicking on and forexample
reference textual information belonging to that OpenGL
primitive / point / line / etc.
Is there a way to do that, that i am missing?.

Although OpenGL provides a so called "selection mode", I strongly discourage
its use. Instead perform ray-intersection tests yourself:

Inversely project your mouse position (gluUnProject) at Z_near and Z_far,
this gives you the vector of the ray, your mouse pointer is casting into the
scene.
Test this ray against (all) the objects in the scene. To speed things up,
manage your objects in a space subdivision structure (Octree, Kd tree, BSP).
These spatial subdivision structures provide very fast tests through which
object's bounding areas the ray passes. For simple object selection (like
files in a file manager), this simple test normally is sufficient.
For more fine grained intersection tests, work down from easy (=fast) to
hard (=slow). In this order: Ray<->Bounding Sphere, Ray<->Bounding Box (Axis
Aligned), Ray<->Convex Hull, Ray<->Triangle Soup. The last two tests can of
course be again accelerated by sorting the triangles into their own spatial
subdivision structure.

Since such intersection tests are so commonplace, there are ready to use
intersection and collision test libraries. OPCODE, RAPID, SOLID are a few of
them to name.

OPCODE homepage: <http://www.codercorner.com/Opcode.htm>


Wolfgang
 
cognacc...
Posted: Sat Aug 29, 2009 8:14 am
Guest
On Aug 28, 10:21 pm, Wolfgang Draxinger <wdraxin... at (no spam) darkstargames.de>
wrote:
Quote:
cognacc wrote:
I want to recognize the "object" im clicking on and forexample
reference textual information belonging to that OpenGL
primitive / point / line / etc.
Is there a way to do that, that i am missing?.

Although OpenGL provides a so called "selection mode", I strongly discourage
its use. Instead perform ray-intersection tests yourself:

I found a "picking" tutorial, which i think uses what you call
selection.
http://www.lighthouse3d.com/opengl/picking/

Quote:
   Inversely project your mouse position (gluUnProject) at Z_near and Z_far,
this gives you the vector of the ray, your mouse pointer is casting into the
scene.

I don't understand completely all the words you use(ray is the vector
on my 2D chart, no z-axis (0) ) Smile,
but the meaning is clear i think, use a vector operation to compare
with, right?

Quote:
   Test this ray against (all) the objects in the scene. To speed things up,
manage your objects in a space subdivision structure (Octree, Kd tree, BSP).
These spatial subdivision structures provide very fast tests through which
object's bounding areas the ray passes.

well my first idea was to sort and index my data objects using the geo
position(or a hash thereof), or something along those lines.
but that seemed to be a bit impractical.
Isn that about the same thing as you suggest?

Will gluUnProject be faster than that (maybe because of some hardware
support)

ps. for now my chart is only using 2D dimensions ie no depth.

Why is selection slow?.
I thought i would use the geo position or a transform of that, as an
index key.
like glLoadName(positionTranformedID)
(this is the same as selection right?)
reading this now: http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node35.html

Quote:
For simple object selection (like
files in a file manager), this simple test normally is sufficient.
   For more fine grained intersection tests, work down from easy (=fast) to
hard (=slow). In this order: Ray<->Bounding Sphere, Ray<->Bounding Box (Axis
Aligned), Ray<->Convex Hull, Ray<->Triangle Soup. The last two tests can of
course be again accelerated by sorting the triangles into their own spatial
subdivision structure.

I think i'm to newbie in OpenGL to go there just yet. :)

Quote:
OPCODE homepage: <http://www.codercorner.com/Opcode.htm

thank, will look into it.


mic
 
cognacc...
Posted: Sat Aug 29, 2009 10:34 pm
Guest
On Aug 29, 2:57 pm, Wolfgang Draxinger <wdraxin... at (no spam) darkstargames.de>
wrote:

Thank you Wolfgang for a very detailed explanation Smile
More than i hoped for.

Quote:
I think i'm to newbie in OpenGL to go there just yet. :)

Well, that's not OpenGL at all. It's only math and programming and nothing
OpenGL or other renderers. Though you will find such math/code oftenly in
close proximity to OpenGL or other renderer's code.

Well i (kinda) know that, but some times just adding another complex
subject at
the same same adds to the confusion, so i start out small.
And then build / add on that later on.
I was good at vector calculation/operations, but that was some years
ago (2-3)

Regards michael
 
Wolfgang Draxinger...
Posted: Sun Aug 30, 2009 3:01 pm
Guest
cognacc wrote:

Quote:
I was good at vector calculation/operations, but that was some years
ago (2-3)

That's like riding a bike. Worst thing you'll have to refresh are
eigenvalue/eigenvector calculations.

I'm sure, you can do that. And if you're stuck, our pals from
comp.graphics.algorithms will gladly help you.


Wolfgang
 
jbwest...
Posted: Mon Aug 31, 2009 4:02 am
Guest
"cognacc" <michael.cognacc at (no spam) gmail.com> wrote in message
news:3482892c-4756-4985-a2c9-e3a81eb26cfc at (no spam) f10g2000vbf.googlegroups.com...
On Aug 29, 2:57 pm, Wolfgang Draxinger <wdraxin... at (no spam) darkstargames.de>
wrote:

Thank you Wolfgang for a very detailed explanation Smile
More than i hoped for.

Quote:
I think i'm to newbie in OpenGL to go there just yet. :)

Well, that's not OpenGL at all. It's only math and programming and nothing
OpenGL or other renderers. Though you will find such math/code oftenly in
close proximity to OpenGL or other renderer's code.

Well i (kinda) know that, but some times just adding another complex
subject at
the same same adds to the confusion, so i start out small.
And then build / add on that later on.
I was good at vector calculation/operations, but that was some years
ago (2-3)

Regards michael

Excellent answer. Always use the simplest thing that works for you. Octrees
or whatever for a barchart is way too much code, wayy too much chance to
make a mistake. If you only want to know which bar they are pointing at,
that's even simpler to do -- just keep track of the min/max for each bar &
compare to the gluUnproject() of the mouse position.

jbw
 
cognacc...
Posted: Mon Aug 31, 2009 6:53 pm
Guest
On Aug 31, 2:02 am, "jbwest" <jbw... at (no spam) acm.org> wrote:


Quote:
Excellent answer. Always use the simplest thing that works for you. Octrees
or whatever for a barchart is way too much code, wayy too much chance to
make a mistake. If you only want to know which bar they are pointing at,
that's even simpler to do -- just keep track of the min/max for each bar &
compare to the gluUnproject() of the mouse position.

Thanks, blush,
I can see i made a very bad description error, of charts.
I didnt think of the other ways it could be interpreted.

Its a Map - in Naval language called a chart Smile
as in, it charts the territory.

Its a navigational map/chart showing landmarks "seamarks"?, depth
markers, boyos,
airport terminals, and later on other ships (which might be presendted
by pixel graphics "above" the map.
So that is complex enough for me.

The problem with naming selection, might be , im about to research
that, the GL_NAME_STACK_DEPTH
Might be too small.

The map/charts data (S-57) can be divided into 3 parts:; general
information(scale, conversion factors, etc) vector information(the
node and edges to display)
feature information(descriptive, sometimes textual information about
the "vector" objects).

From the general infdormation, the number of different "primitives"
described in the dataset if given
b14:NOGR:894 - err can't remember
b14:NOLR:7
b14:NOIN:154
b14:NOCN:1074
b14:NOED:1370



> jbw
 
cognacc...
Posted: Mon Aug 31, 2009 7:08 pm
Guest
sorry hit reply by accident before i got to proof read it.

From the general information, the number of different "primitives"
described in the dataset is given
b14:NOGR:894 - no of geo records
b14:NOLR:7 - no of collect records
b14:NOIN:154 - no of isolated nodes
b14:NOCN:1074- no of connected nodes
b14:NOED:1370- no of edges

so as you can see i get 894 geo records, or about 2500 node / Edge
descriptions, that each might be a distinct object
I however only need to be able to pick special Point of Interests, for
demonstration purpose. (like airports, boyuos and so on)


ps S-57 is amongst other things used to describe ENC's Electronic
Nautical Charts (to be used in an ECDIS system (out of my scope of
assignment))


hey two links:
http://en.wikipedia.org/wiki/IHO

Scroll down to ENC sample -that how my charts (should)look like.
http://destinsharks.com/boat-stuff/36


Hope i didnt bore you with this, i find this quite exciting.

mic
 
jbwest...
Posted: Tue Sep 01, 2009 4:12 am
Guest
"cognacc" <michael.cognacc at (no spam) gmail.com> wrote in message
news:c6196b0a-f7f5-4676-96a6-2226839aaf81 at (no spam) f33g2000vbm.googlegroups.com...
On Aug 31, 2:02 am, "jbwest" <jbw... at (no spam) acm.org> wrote:


Quote:
Excellent answer. Always use the simplest thing that works for you.
Octrees
or whatever for a barchart is way too much code, wayy too much chance to
make a mistake. If you only want to know which bar they are pointing at,
that's even simpler to do -- just keep track of the min/max for each bar &
compare to the gluUnproject() of the mouse position.

Thanks, blush,
I can see i made a very bad description error, of charts.
I didnt think of the other ways it could be interpreted.

Its a Map - in Naval language called a chart Smile
as in, it charts the territory.

Its a navigational map/chart showing landmarks "seamarks"?, depth
markers, boyos,
airport terminals, and later on other ships (which might be presendted
by pixel graphics "above" the map.
So that is complex enough for me.

The problem with naming selection, might be , im about to research
that, the GL_NAME_STACK_DEPTH
Might be too small.

The map/charts data (S-57) can be divided into 3 parts:; general
information(scale, conversion factors, etc) vector information(the
node and edges to display)
feature information(descriptive, sometimes textual information about
the "vector" objects).

From the general infdormation, the number of different "primitives"
described in the dataset if given
b14:NOGR:894 - err can't remember
b14:NOLR:7
b14:NOIN:154
b14:NOCN:1074
b14:NOED:1370



Quote:
jbw



You only need a stack depth of 2. You don't keep pushing the name stack.
That total number of entities can probably be picked with GL_SELECTION in a
trivial amount of code & time.

jbw
 
cognacc...
Posted: Wed Sep 02, 2009 6:23 pm
Guest
On Sep 1, 2:12 am, "jbwest" <jbw... at (no spam) acm.org> wrote:

Quote:
You only need a stack depth of 2. You don't keep pushing the name stack.


So i reread the material of picking and selection naming (hit count
etc).

I maybe think about this the wrong way.
But if i pick / select a part of an object(object constructed of nodes
and lines), without having "named" them
then if i click / hit one node of a larger object, i want to change
the colour on the complete "object" / collection of primitives
that belongs to that set.

That can't be done without "naming" them our use some kind of method
like wolfgang suggests. can it?
My ide was that naming was an easy way to avoid making these
comparisons for a start(creating a prototype).

I'm i missing something completely ?

Quote:
That total number of entities can probably be picked with GL_SELECTION in a
trivial amount of code & time.

Yes, trivial amount of time but how would i know the associated nodes
to the complete object.
ie. lets say i show stone henge as a collection of nodes and there are
also other nodes to specify other things!.
each stone is represented by 1 node.
if i click on anyone single node/stone, i want all stones / nodes to
turn from grey to red.

1. I would have to check that the nodes are the ones associated to the
stonehenge object.
2. I would have to compare to the position of all nodes, is there an
object at that position
3. See which object has a node of that position and then get all other
nodes associated to that object.

mhh

mic
 
jbwest...
Posted: Thu Sep 03, 2009 5:16 am
Guest
"cognacc" <michael.cognacc at (no spam) gmail.com> wrote in message
news:03130d08-bb83-482f-91e1-d6dda47b9408 at (no spam) z24g2000yqb.googlegroups.com...
On Sep 1, 2:12 am, "jbwest" <jbw... at (no spam) acm.org> wrote:

Quote:
You only need a stack depth of 2. You don't keep pushing the name stack.


So i reread the material of picking and selection naming (hit count
etc).

I maybe think about this the wrong way.
But if i pick / select a part of an object(object constructed of nodes
and lines), without having "named" them
then if i click / hit one node of a larger object, i want to change
the colour on the complete "object" / collection of primitives
that belongs to that set.

That can't be done without "naming" them our use some kind of method
like wolfgang suggests. can it?
My ide was that naming was an easy way to avoid making these
comparisons for a start(creating a prototype).

I'm i missing something completely ?

Quote:
That total number of entities can probably be picked with GL_SELECTION in
a
trivial amount of code & time.

Yes, trivial amount of time but how would i know the associated nodes
to the complete object.
ie. lets say i show stone henge as a collection of nodes and there are
also other nodes to specify other things!.
each stone is represented by 1 node.
if i click on anyone single node/stone, i want all stones / nodes to
turn from grey to red.

1. I would have to check that the nodes are the ones associated to the
stonehenge object.
2. I would have to compare to the position of all nodes, is there an
object at that position
3. See which object has a node of that position and then get all other
nodes associated to that object.

mhh

mic



=============


Let's try this

while in SELECT mode;

push a name indicating which object -- stonehenge 1
draw stonehange
pop a name
push a name indicating stonehenge 2
draw stonehange 2
pop a name.

Get it? You don't need a deep stack of names, just one name per pickable
object.
A deeper stack could conceptually be used for identifying sub-objects;
pushname (stomnehenge1)
pushname (top part)
draw top part
popname
pushname (front face)
draw front face
popname
etc...
popname // stonehange 1
pushname(stonehnge 2)
etc ...


You pick; you get back a name corresponding to (1) or (2) or (both [if you
pick in an overlap area]) or none.


If you application doesn't understand what "stonehenge 1" is, then OpenGL
surely can't, right ? You want to highlight all bricks associated with
"stonehenge 1", so you need to have that list in your data structure to do
that anyway.

By the way, a convenient tricky "name" to use is an address of something
interesting (an object, say, or a function that draws that object, or
similar) cast to a GLint. if 64 bit, you'll need to push 2 names, address
high and address low.

This all works well -- well with human gui time-- for up to tens or hundreds
of thousands of primitives, in my experience.
Much more if you compute the bounding box of an object (you'll need to for
the alternative way to pick), and then decide if the bounding box contains
the pick. This way generally culls most of your picture out of the
GL_SEL:ECT mechanism so that in some cases (many objects not usually
overlapping) you can handle many many hundreds of thousands of objects
and/or millions of primitives. Because, for a scene with few overlapping
objects, GL_SELECT really is only working on a very few of them, a tiny
percentage.

Another trick is highlighting -- switch the drawbuffer to the font buffer,
draw the object in a highlighted color, wireframe, whatever and then switch
the drawbuffer back & flush. Do Not swapbuffers. This will give you an
immediate highlight without a redraw, but has side effects (may leave
"dandruff") due to z-fighting unless you are careful.


Others are big fans of using computation ray-object intersection, it
generally requires a fair bit of code & refactoring so that objects bounding
areas are put into a tree structure, and then fine-grain ray-element
intersection tests for all the bits of an object is coded up. You need to
deal with near misses as well as (if you care) whether or not that part of
the object happens to be fully transparent (and thus, possibly shouldn't be
pickable).. The latter is often overlooked with bad results.

At that point I'd frankly consider using a simple scene graph that does all
that for me. Especially if you are using computed curved surfaces (NURBS,
etc).

jbw
 
cognacc...
Posted: Thu Sep 03, 2009 2:30 pm
Guest
Ahh i think i get it.
I thought of the stack as the one holding my names/handles.
And if i emptied the namestack i thought i could not get at that data.
(like loosing a filehandle/pointer)

but its more of a rubberstamp i put on the data i want rendered.
Thats still there even if i empty the name stack (and remove it, and
turn it upside down etc and so on).

Well i do some more programming to get a better feel for it.

Thanks.
Esp. i like the bonus info i get(you can also do this and do that, but
that means ...)


mic
 
 
Page 1 of 1    
All times are GMT
The time now is Sun Nov 22, 2009 4:42 pm