Re: [osg-users] osgswig: iterating over a vertex array

2009-02-26 Thread R Fritz
Thanks for the response.  I'll try tackling it with ctypes, then.  Not  
an elegant solution, but I think I can get it to work.


Randolph

On Feb 25, 2009, at 11:35 PM, Gerwin de Haan wrote:


Hi Randolph,

this is a typical problem of (python) wrappers; the getVertexArray
returns a general Array, which is currently not wrapped. The trick
would be to somewhere cast the general Array back to its specific
type in Python, e.g. a Vec3Array. We've used some of these tricks in
the wrappings themselves by a dynamic_cast through C++ run-time type
information (not accessible to users), and some you can access
yourself, e.g. osg.Node.asLOD .

To fix your particular problem we might introduce extensions to Array
such as osg.Array.asVec3Array etc, or better would be to automatically
let SWIG convert all returning values of Array to its real type. In
any case this means diving into SWIG specifics. I'll post this as an
issue on the list
(http://code.google.com/p/osgswig/issues/detail?id=27), but I cannot
give guarantees when it will be picked up.

Gerwin



On Thu, Feb 26, 2009 at 5:19 AM, Randolph Fritz rfr...@u.washington.edu 
 wrote:
I'm writing a prototype OSG to Radiance exporter in Python.  I've  
got to the
point of code that iterates over all geodes in the scene graph.  
Problem
is--then what? Is the only way to read the elements of the arrays  
ctype and

pointers? Or is there something a bit simpler and safer?

Perhaps-relevant bit of code:
  def apply_Geode(self,ge):
  for i in range(ge.getNumDrawables()):
  geom = ge.getDrawable(i).asGeometry()
  if geom:
  arr = geom.getVertexArray()
  for i in range(arr.getNumElements()):
  # This doesn't seem to work--what does?
 arr.accept(i,self.val)


--
Randolph Fritz
 design machine group
 architecture department
 university of washington
rfr...@u.washington.edu

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


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


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


Re: [osg-users] osgswig: iterating over a vertex array

2009-02-26 Thread Randolph Fritz

The following code appears to work:

   def apply_Geode(self,ge):
   for i in range(ge.getNumDrawables()):
   geom = ge.getDrawable(i).asGeometry()
   if geom:
   arr = geom.getVertexArray()
   if arr.getType() != osg.Array.Vec3ArrayType:
   raise LumError, 'Type of vertex array not 
three-element vectors'

   # aagh!
   sz = arr.getDataSize()
   pvec = 
ctypes.pointer(c_float.from_address(int(arr.getDataPointer(

   o = 0
   for i in range(arr.getNumElements()):
   self.file.write('  %f %f %f\n' % (pvec[o], 
pvec[o+1], pvec[o+2]))

   o += sz

I do not recommend this as a coding style, but it seems to be the only 
way to do this at the moment.


Randolph

Gerwin de Haan wrote:

Hi Randolph,

this is a typical problem of (python) wrappers; the getVertexArray
returns a general Array, which is currently not wrapped. The trick
would be to somewhere cast the general Array back to its specific
type in Python, e.g. a Vec3Array. We've used some of these tricks in
the wrappings themselves by a dynamic_cast through C++ run-time type
information (not accessible to users), and some you can access
yourself, e.g. osg.Node.asLOD .

To fix your particular problem we might introduce extensions to Array
such as osg.Array.asVec3Array etc, or better would be to automatically
let SWIG convert all returning values of Array to its real type. In
any case this means diving into SWIG specifics. I'll post this as an
issue on the list
(http://code.google.com/p/osgswig/issues/detail?id=27), but I cannot
give guarantees when it will be picked up.

Gerwin



On Thu, Feb 26, 2009 at 5:19 AM, Randolph Fritz rfr...@u.washington.edu wrote:
  

I'm writing a prototype OSG to Radiance exporter in Python.  I've got to the
point of code that iterates over all geodes in the scene graph. Problem
is--then what? Is the only way to read the elements of the arrays ctype and
pointers? Or is there something a bit simpler and safer?

Perhaps-relevant bit of code:
  def apply_Geode(self,ge):
  for i in range(ge.getNumDrawables()):
  geom = ge.getDrawable(i).asGeometry()
  if geom:
  arr = geom.getVertexArray()
  for i in range(arr.getNumElements()):
  # This doesn't seem to work--what does?
 arr.accept(i,self.val)


--
Randolph Fritz
 design machine group
 architecture department
 university of washington
rfr...@u.washington.edu

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



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



--
Randolph Fritz
 design machine group
 architecture department
 university of washington
rfr...@u.washington.edu

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


Re: [osg-users] osgswig: iterating over a vertex array

2009-02-25 Thread Gerwin de Haan
Hi Randolph,

this is a typical problem of (python) wrappers; the getVertexArray
returns a general Array, which is currently not wrapped. The trick
would be to somewhere cast the general Array back to its specific
type in Python, e.g. a Vec3Array. We've used some of these tricks in
the wrappings themselves by a dynamic_cast through C++ run-time type
information (not accessible to users), and some you can access
yourself, e.g. osg.Node.asLOD .

To fix your particular problem we might introduce extensions to Array
such as osg.Array.asVec3Array etc, or better would be to automatically
let SWIG convert all returning values of Array to its real type. In
any case this means diving into SWIG specifics. I'll post this as an
issue on the list
(http://code.google.com/p/osgswig/issues/detail?id=27), but I cannot
give guarantees when it will be picked up.

Gerwin



On Thu, Feb 26, 2009 at 5:19 AM, Randolph Fritz rfr...@u.washington.edu wrote:
 I'm writing a prototype OSG to Radiance exporter in Python.  I've got to the
 point of code that iterates over all geodes in the scene graph. Problem
 is--then what? Is the only way to read the elements of the arrays ctype and
 pointers? Or is there something a bit simpler and safer?

 Perhaps-relevant bit of code:
   def apply_Geode(self,ge):
       for i in range(ge.getNumDrawables()):
           geom = ge.getDrawable(i).asGeometry()
           if geom:
               arr = geom.getVertexArray()
               for i in range(arr.getNumElements()):
                   # This doesn't seem to work--what does?
                  arr.accept(i,self.val)


 --
 Randolph Fritz
  design machine group
  architecture department
  university of washington
 rfr...@u.washington.edu

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

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