Re: [osg-users] Implementing clone() on class derived from osg::Geometry and osg::MatrixTransform

2012-01-05 Thread Robert Osfield
Hi Peter,

I think you question is really about overriding virtual methods in
C++, but I'm not sure.

If call geometry-clone() and the geometry object is an instance of
PiFaceGeometry then the clone method called will be
PiFaceGeometry::clone() even if the geometry pointer you have is of
the parent class osg::Geometry. i.e.

  PiFaceGeometry* myFaceGeometry = new PiFaceGeometry;
  Geometry* geometry = myFaceGeometry;
  geometry-clone(); // will call PiFaceGeometry::clone().

Robert.

On 30 November 2011 12:18, Peter Bako bakopet...@gmail.com wrote:
 Hello guys!
 I have run a search over the topics, but I didn't find an answer for my 
 question, so here it is:

 I have my own derived class called PiFaceGeometry, which is derived from 
 osg::Geometry class, I use this to work with faces of solids - so I have the 
 type of face - cylinder, plane, and other which I store within this class and 
 also some other properties.
 I have a different class called SolidComponent, which is derived from 
 osg::MatrixTransform and represent machinery workpieces and tools.

 The problem is that sometimes I need to clone the SolidComponent (which 
 contains Geode as child with PiFaceGeometries, and can also contain other 
 SolidComponents as children). I think, I need a deep copy, because sometimes 
 I have to change the color of triangles, or am I wrong? The question is, how 
 should I reimplement the clone() function? I looked also into the osg source 
 code but I didn't understand the way, how to do this.

 How can I force the program to call PiFaceGeometry::clone() if this is only a 
 child of object, on which I called clone()?
 I am sorry If this question is silly, I am not a good C++ programmer and I 
 hate C++ :-P.

 Thank you for your responses!

 Cheers,
 Peter
 Code:

 class PiFaceGeometry: public osg::Geometry {
 public:
  osg::ref_ptrosg::IntArray edges;
  PiSurfaceType surfType;
  void changeFaceColor(osg::Vec4 color){...};
  PiFaceGeometry * clone(const osg::CopyOp copyop ){
      //how can I reuse Geometry::Clone(), if it returns a Geometry but I need 
 PiFaceGeometry?
  }
 };




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





 ___
 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] Implementing clone() on class derived from osg::Geometry and osg::MatrixTransform

2011-12-12 Thread Filip Arlet
Hi,

clone method is virtual and should return osg::Object*. you can dynamic cast 
(or even static cast if you are sure) to PiGeometry*.

How can I force the program to call PiFaceGeometry::clone() if this is only a 
child of object, on which I called clone()? 
 I am sorry If this question is silly, I am not a good C++ programmer and I 
hate C++
Learn something about virtual functions and polymorphism. Virtual functions 
does the magic for you and calls appropriate functions, if it's called from 
parent class.

About DEEP and SHALLOW copy: shalow copy makes memberwise clone, so every 
variable in original object copies to new one. Only problem there is pointer, 
new object have same value and points to same objects. For example with shalow 
copy MatrixTransform, new one will have shared children with original. But deep 
copy (there are several types - deep copy all, deep copy children etc.) copies 
them too.
What this does mean for your: you can simply call osg::Geometry::clone() and 
then do your job: copy variables edges and surfType, according to copyop (share 
array in shalow copy).

Cheers,
Filip

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





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


[osg-users] Implementing clone() on class derived from osg::Geometry and osg::MatrixTransform

2011-12-11 Thread Peter Bako
Hello guys! 
I have run a search over the topics, but I didn't find an answer for my 
question, so here it is:

I have my own derived class called PiFaceGeometry, which is derived from 
osg::Geometry class, I use this to work with faces of solids - so I have the 
type of face - cylinder, plane, and other which I store within this class and 
also some other properties.
I have a different class called SolidComponent, which is derived from 
osg::MatrixTransform and represent machinery workpieces and tools.

The problem is that sometimes I need to clone the SolidComponent (which 
contains Geode as child with PiFaceGeometries, and can also contain other 
SolidComponents as children). I think, I need a deep copy, because sometimes I 
have to change the color of triangles, or am I wrong? The question is, how 
should I reimplement the clone() function? I looked also into the osg source 
code but I didn't understand the way, how to do this.

How can I force the program to call PiFaceGeometry::clone() if this is only a 
child of object, on which I called clone()?
I am sorry If this question is silly, I am not a good C++ programmer and I hate 
C++ :-P.

Thank you for your responses!

Cheers,
Peter
Code:

class PiFaceGeometry: public osg::Geometry {
public:
 osg::ref_ptrosg::IntArray edges;
 PiSurfaceType surfType;
 void changeFaceColor(osg::Vec4 color){...};
 PiFaceGeometry * clone(const osg::CopyOp copyop ){
  //how can I reuse Geometry::Clone(), if it returns a Geometry but I need 
PiFaceGeometry?
 }
};




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





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