Re: [osg-users] Access vertices and faces after load the model

2009-05-29 Thread Xin Chen
Hello Guys,

  To my original problem. I found a website which is quite useful and 
works. Just in case others may need it. 

http://delta3d.wiki.sourceforge.net/Accessing+Underlying+OpenSceneGraph+Geometry

Thank you!

Cheers,
Xin

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





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


Re: [osg-users] Access vertices and faces after load the model

2009-05-29 Thread Thrall, Bryan
Paul Melis wrote on Friday, May 29, 2009 9:55 AM:

> Thrall, Bryan wrote:
>> Paul Martz wrote on Thursday, May 28, 2009 4:50 PM:
>> 
>>> You use a NodeVisitor to walk your scene graph and look for Geodes,
>>> then iterate over the Drawables that are attached to the Geodes,
using
>>> dynamic_cast to access the Drawable as a Geometry.
>>> 
>> 
>> Even better, I notice osg::Drawable has asGeometry(), which is
cheaper than
>> dynamic_cast<> :) 
>> 
> Wow, I wasn't expecting the difference to be this large, as virtual
> function calls aren't completely free either:
...
> 16:52|p...@tabu:~> ./t
> 1
> asGeometry(): 1.181 ms
> dynamic_cast<>(): 3.945 ms
> 16:52|p...@tabu:~> g++ -O3 -o t t.cpp -I ~/osg2.8/include/ -L
> ~/osg2.8/lib/ -losg -losgDB
> 16:52|p...@tabu:~> ./t
> 1
> asGeometry(): 0.839 ms
> dynamic_cast<>(): 3.611 ms
> 16:52|p...@tabu:~>

That's even more impressive than I was expecting!

-- 
Bryan Thrall
FlightSafety International
bryan.thr...@flightsafety.com
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Access vertices and faces after load the model

2009-05-29 Thread Paul Martz
Touché! :-)

Cheers,

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Thrall,
Bryan

Paul Martz wrote on Thursday, May 28, 2009 4:50 PM:
> You use a NodeVisitor to walk your scene graph and look for Geodes, 
> then iterate over the Drawables that are attached to the Geodes, using 
> dynamic_cast to access the Drawable as a Geometry.

Even better, I notice osg::Drawable has asGeometry(), which is cheaper than
dynamic_cast<> :)

--
Bryan Thrall
FlightSafety International
bryan.thr...@flightsafety.com

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


Re: [osg-users] Access vertices and faces after load the model

2009-05-29 Thread Paul Melis

Thrall, Bryan wrote:

Paul Martz wrote on Thursday, May 28, 2009 4:50 PM:
  

You use a NodeVisitor to walk your scene graph and look for Geodes,
then iterate over the Drawables that are attached to the Geodes, using
dynamic_cast to access the Drawable as a Geometry.



Even better, I notice osg::Drawable has asGeometry(), which is cheaper
than dynamic_cast<> :)
  
Wow, I wasn't expecting the difference to be this large, as virtual 
function calls aren't completely free either:


16:51|p...@tabu:~> cat t.cpp
// g++ -o t t.cpp -I ~/osg2.8/include/ -L ~/osg2.8/lib/ -losg -losgDB
#include 
#include 

float
timediff(struct timeval t0, struct timeval t1)
{
   return 1000 * (t1.tv_sec - t0.tv_sec) + (t1.tv_usec - t0.tv_usec) / 
1000.0;

}

int main()
{
   osg::Group* cow = (osg::Group*)osgDB::readNodeFile("cow.osg");
   osg::Geode* geode = (osg::Geode*)cow->getChild(0);
   osg::Drawable *draw = geode->getDrawable(0);

   boolisgeom = true;
   int i;
   struct timeval  t0, t1, t2;
   const int   N = 10;

   gettimeofday(&t0, NULL);
   for (i = 0; i < N; i++)
   isgeom = isgeom && (draw->asGeometry() != NULL);

   gettimeofday(&t1, NULL);
   for (i = 0; i < N; i++)
   isgeom = isgeom && (dynamic_cast(draw) != NULL);

   gettimeofday(&t2, NULL);

   printf("%d\n", isgeom);  // need to use isgeom, as otherwise it 
might be optimized away

   printf("asGeometry(): %.3f ms\n", timediff(t0, t1));
   printf("dynamic_cast<>(): %.3f ms\n", timediff(t1, t2));
}
16:52|p...@tabu:~> g++ -o t t.cpp -I ~/osg2.8/include/ -L ~/osg2.8/lib/ 
-losg -losgDB

16:52|p...@tabu:~> ./t
1
asGeometry(): 1.181 ms
dynamic_cast<>(): 3.945 ms
16:52|p...@tabu:~> g++ -O3 -o t t.cpp -I ~/osg2.8/include/ -L 
~/osg2.8/lib/ -losg -losgDB

16:52|p...@tabu:~> ./t
1
asGeometry(): 0.839 ms
dynamic_cast<>(): 3.611 ms
16:52|p...@tabu:~>




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


Re: [osg-users] Access vertices and faces after load the model

2009-05-29 Thread Thrall, Bryan
Paul Martz wrote on Thursday, May 28, 2009 4:50 PM:
> You use a NodeVisitor to walk your scene graph and look for Geodes,
> then iterate over the Drawables that are attached to the Geodes, using
> dynamic_cast to access the Drawable as a Geometry.

Even better, I notice osg::Drawable has asGeometry(), which is cheaper
than dynamic_cast<> :)

-- 
Bryan Thrall
FlightSafety International
bryan.thr...@flightsafety.com
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Paul Martz
Just to kind of sum up what has been said here...

To get the vertices and other vertex attributes, you use get* methods in the
Geometry class. See the Geometry header file.

There could be dozens, possibly thousands of Geometry objects in your scene
graph. You use a NodeVisitor to walk your scene graph and look for Geodes,
then iterate over the Drawables that are attached to the Geodes, using
dynamic_cast to access the Drawable as a Geometry. For more info here, grep
for "NodeVisitor" in the OSG source code. NodeVisitors are used throughout
OSG, so finding them should be easy. Also take a look at the Geode header,
and note that Geometry derives from Drawable.

Finally, the OSG Quick Start Guide has lots of applicable information that
will help you out: http://stores.lulu.com/pmartz. It seems like there have
been a lot of posts recently by people who have not bothered to take a look
at this free resource.

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

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


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Chris 'Xenon' Hanson
Xin Chen wrote:

>Thanks for your reply. I did look at the source code to load .stl 
> models. I found that there are _vertices and _normal variables in the source 
> code. That's why I'm asking if there is a way to access those parameters. Any 
> idea or sample code? Thank you. 

  I think those are only temporary variables specific to the STL loader, and 
they don't
persist after the loader has created the scene graph.

-- 
Chris 'Xenon' Hanson, omo sanza lettere  Xenon AlphaPixel.com
PixelSense Landsat processing now available! http://www.alphapixel.com/demos/
"There is no Truth. There is only Perception. To Perceive is to Exist." - Xen
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Jason Daly

Jason Daly wrote:
If you really do need to get at the low-level data, you can use the 
NodeVisitor method I described previously.  You'll need to create a 
class that inherits from osg::NodeVisitor and overrides the 
apply(Geometry *) method to perform whatever operations you need on each 
Geometry in your scene.  You also might want to look at the 
AttributeFunctor class inside osg::Drawable and/or the PrimitiveFunctor 
class inside osg::Geometry.  These allow you to perform similar 
operations on the vertices and/or primitives (triangles, quads, etc.) 
inside the Geometry object.
  


I should point out you can also just get the attribute arrays (vertices, 
normals, etc) by calling the appropriate get*Array() method on the 
Geometry.  For example, getVertexArray() will fetch the vertex 
coordinate array.


You can do the same with the primitives by calling getPrimitiveSet().  
You'll probably need to familiarize yourself with the different types of 
primitive sets (DrawArrays, DrawArrayLengths, and DrawElements) as well.


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


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Ismail Pazarbasi
2009/5/28 Xin Chen :
> Hello Ismail,
>
>       Thanks for your reply. I did look at the source code to load .stl 
> models. I found that there are _vertices and _normal variables in the source 
> code. That's why I'm asking if there is a way to access those parameters. Any 
> idea or sample code? Thank you.
>
> Xin
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=13131#13131
>
Hello Xin,

no, I have no source code about that. I know it isn't the way to deal
with such situations; but all I can recommend is to walk through the
source code and Google for it! The fact that source code available is
available to us means that we are supposed to use it as much as we can
(again; it'd be much better if we had documentation covering
_everything_ - but it's too difficult to write one).

Normals could be accessed via osg::Geode::getNormal methods (you
have normal idices, data and binding method - see include/Geometry).
To do that, you need to traverse the returned graph (that is, the
Node* returned). In your NodeVisitor, you can do:
osg::Geode* pGeode = dynamic_cast(pNode); // where, pNode
is pointer to node
if (pGeode) // this is a geode node - query normals
{
   pGeode->getNormal // depends on what you want; normal indices,
binding method, etc. see member methods
}
(to traverse, you need to call "traverse" method on the Node* returned
with a reference to a custom NodeVisitor. See Jason's post, which I
believe covers "how to do it" part)

However, because I've never used any osg plugin (but freetype,
implicitly via osgText), I am not exactly sure whether this is
correct.

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


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Jason Daly

Xin Chen wrote:

Thank you for the reply. I do need the vertices and faces. My 
application is to load CAD model and simulate the projection (X-ray image) of 
the model according to the materials. So the ability to access individual 
vertices are important for my application. Any easy ways to build a program 
that able to load different types of model and also can access individual 
vertices and faces? Thanks
  


I'm not sure what you mean by "simulate the projection ... according to 
the materials".   Can you elaborate?


If you really do need to get at the low-level data, you can use the 
NodeVisitor method I described previously.  You'll need to create a 
class that inherits from osg::NodeVisitor and overrides the 
apply(Geometry *) method to perform whatever operations you need on each 
Geometry in your scene.  You also might want to look at the 
AttributeFunctor class inside osg::Drawable and/or the PrimitiveFunctor 
class inside osg::Geometry.  These allow you to perform similar 
operations on the vertices and/or primitives (triangles, quads, etc.) 
inside the Geometry object.


--"J"

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


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Xin Chen

ismailp wrote:
> 2009/5/28 Xin Chen <>:
> 
> > Hi,
> > 
> >    I'm new to OSG. I use the following code to load my model, which is 
> > successful.  How can I access the vertices and faces of the model? Thank 
> > you.
> > 
> > nNode = osgDB::readNodeFile("D:/Livingroom.3DS");
> > 
> > 
> > 
> > 
> > 
> > Thank you!
> > 
> > Cheers,
> > xinchen
> > 
> > --
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=13087#13087
> > 
> > 
> > 
> > 
> > 
> > ___
> > osg-users mailing list
> > 
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> > 
> 
> Hi Xin,
> 
> I am not a plugin user (except freetype), but I could easily say; you
> need to traverse the graph starting from Node returned! I don't know
> how that graph is constructed (that is, how a face is represented -
> probably a geode). It could be a good start to see 3ds plugin's source
> code. As far as I can see, it's relatively complicated, but may give
> you a start. Did you see/debug its source code? If you haven't already
> done so, compile OpenSceneGraph with debug configuration and step into
> 3DS plugin. To understand how it works, you may need to create a very
> simple 3DS file with one quad and its normals (may be) and load it
> instead of a complicated one.
> 
> Ismail
> ___
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  --
> Post generated by Mail2Forum



Hello Ismail, 

   Thanks for your reply. I did look at the source code to load .stl 
models. I found that there are _vertices and _normal variables in the source 
code. That's why I'm asking if there is a way to access those parameters. Any 
idea or sample code? Thank you. 

Xin

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





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


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Xin Chen

Jason Daly wrote:
> Xin Chen wrote:
> 
> > Hi,
> > 
> > I'm new to OSG. I use the following code to load my model, which is 
> > successful.  How can I access the vertices and faces of the model? Thank 
> > you.
> > 
> > nNode = osgDB::readNodeFile("D:/Livingroom.3DS");
> > 
> > 
> 
> Access them for what purpose?
> 
> When your model is loaded, a scene graph is created from it.  This scene 
> might contain several different sets of vertices, normals, texture 
> coordinates, and primitives.  If you just want to look at them, you can 
> create a custom NodeVisitor to find all the osg::Geometry objects in the 
> scene, then query the vertex arrays and primitive sets from each 
> Geometry object. 
> 
> Chances are that there is an easier way to do what you want, but we 
> can't help you until you tell us what you're trying to do.
> 
> --"J"
> 
> ___
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  --
> Post generated by Mail2Forum



Hello J,

Thank you for the reply. I do need the vertices and faces. My 
application is to load CAD model and simulate the projection (X-ray image) of 
the model according to the materials. So the ability to access individual 
vertices are important for my application. Any easy ways to build a program 
that able to load different types of model and also can access individual 
vertices and faces? Thanks

Xin

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





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


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Ismail Pazarbasi
2009/5/28 Xin Chen :
> Hi,
>
>    I'm new to OSG. I use the following code to load my model, which is 
> successful.  How can I access the vertices and faces of the model? Thank you.
>
> nNode = osgDB::readNodeFile("D:/Livingroom.3DS");
>
>
>
>
>
> Thank you!
>
> Cheers,
> xinchen
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=13087#13087
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>

Hi Xin,

I am not a plugin user (except freetype), but I could easily say; you
need to traverse the graph starting from Node returned! I don't know
how that graph is constructed (that is, how a face is represented -
probably a geode). It could be a good start to see 3ds plugin's source
code. As far as I can see, it's relatively complicated, but may give
you a start. Did you see/debug its source code? If you haven't already
done so, compile OpenSceneGraph with debug configuration and step into
3DS plugin. To understand how it works, you may need to create a very
simple 3DS file with one quad and its normals (may be) and load it
instead of a complicated one.

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


Re: [osg-users] Access vertices and faces after load the model

2009-05-28 Thread Jason Daly

Xin Chen wrote:

Hi,
   
I'm new to OSG. I use the following code to load my model, which is successful.  How can I access the vertices and faces of the model? Thank you.


nNode = osgDB::readNodeFile("D:/Livingroom.3DS");
  


Access them for what purpose?

When your model is loaded, a scene graph is created from it.  This scene 
might contain several different sets of vertices, normals, texture 
coordinates, and primitives.  If you just want to look at them, you can 
create a custom NodeVisitor to find all the osg::Geometry objects in the 
scene, then query the vertex arrays and primitive sets from each 
Geometry object. 

Chances are that there is an easier way to do what you want, but we 
can't help you until you tell us what you're trying to do.


--"J"

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


[osg-users] Access vertices and faces after load the model

2009-05-28 Thread Xin Chen
Hi,
   
I'm new to OSG. I use the following code to load my model, which is 
successful.  How can I access the vertices and faces of the model? Thank you.

nNode = osgDB::readNodeFile("D:/Livingroom.3DS");





Thank you!

Cheers,
xinchen

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





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