Re: [osg-users] Visitor concept. No finalize?

2011-01-26 Thread Peter Amstutz
If it's so important it get called automatically, why can't you run your
finalize code in the destructor?

On 1/25/2011 3:36 PM, Sam Warns wrote:
 Hi,

 that is exactly the point. My RemoveXVisitor  SHOULD remove nodes but since 
 it is not possible to do that in apply and there is no finalize method that 
 gets automatically called after accept has finished, it is only possible to 
 remove nodes by providing a custom member which the user must call manually.

 That is what I am talking about, it is not possible for a Visitor to do 
 certain things without having the user explicitly call members of it after 
 the accept call.

 I did not demand a finalize method and I understand Robert's statement that 
 flexibility is achieved by relying on the user. Never the less would a 
 finalize method decrease any flexibility and power of it.

 (Btw: I have never experienced that handing over responsibility to the user 
 (which is the developer at this point) produced any good results, but this is 
 only my experience) 

 Thanks,
 Sam

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





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


-- 
Peter Amstutz
Senior Software Engineer
Technology Solutions Experts
Natick, MA
02131

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


Re: [osg-users] Visitor concept. No finalize?

2011-01-26 Thread Sam Warns
This would require the user to be aware of the fact that the Visitor has not 
finished its work after dtor is called.

This is even more user unfriendly in my point of view.

Sam

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





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


Re: [osg-users] Visitor concept. No finalize?

2011-01-25 Thread Robert Osfield
Hi Sam,

You can't remove an object from it's a parent in a apply() method as
this would invalidate the iterators of the calling code (the
traverse() method that calls the node-accept() which in turn calls
the apply()).

It's safe to remove the children of a node you are passed in a the
apply method, but not removing that node from it's parent.  Another
approach is to collect the list of nodes you want to remove in list
during the traversal using the node visitor than have a method you
call after traversal that does all the operations on the nodes, this
way you can avoid invalidating iterators.

The second half of your post I couldn't make any sense of so can't
comment on this.

Robert.


On Tue, Jan 25, 2011 at 7:26 AM, Sam Warns the_vincu...@hotmail.com wrote:
 Hi,

 I was writing a Visitor that performed an extraction of certain elements from 
 a scenegraph. My first try was to remove the nodes in question from their 
 parents directly in the apply method which lead to some exceptions.
 So what am I doing wrong? I mean I would except some finalize method which is 
 called when the visitor is finished.
 Currently the only remaining function is the getter function for the nodes, 
 that should be extracted. So in apply I have stored references to the object 
 which I can only extract when using the getter so that the removal logic can 
 be executed.
 This works so far but if I do not call the getter no extraction code is 
 executed and nothing really happened.

 What am I doing wrong?


 Thank you,
 Sam

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





 ___
 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] Visitor concept. No finalize?

2011-01-25 Thread Sam Warns
Hi Robert,

the second half of my post is about the second option you was talking about.
The apply only gathers the nodes in question and does nothing else then there 
is another method that performs the removal from parent.
But the issue with that is, that if I do not call this method, no removal is 
done.
That was, what I was talking about. The visitor finished its work but as long 
as the user do not call an additional method the removal from parent has not 
been done yet.

I was hoping for a finish method that is automatically called after the 
visitors work has been finished. This finish method could then perform the 
necessary removal operation (or any other).


Thank you!

Cheers,
Sam

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





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


Re: [osg-users] Visitor concept. No finalize?

2011-01-25 Thread Robert Osfield
Hi Sam,

You have complete control over what you do before and after traversal,
there really isn't any need to have a finalize method as it would only
restrict what users can do over what they can already do.

If you wanted an finialize method in your visitor  then just write a
method like:

  MyVisitor : public NodeVisitor {

   void apply(...) // all my apply overrides your need...

   void process(Node* node)
   {
// do what you want to initialize the visitor prior
// to traversing the scene graph
node-accept(node);
 // do what you want after traversal
   }
   };

   MyVisitor myvistor;
   myvisitor-process(node);

The visitor implementation is deliberately designed to allow you to be
flexible, it's up to you how you want to go about implementing the
details for the purpose of your application.

Robert.

On Tue, Jan 25, 2011 at 10:21 AM, Sam Warns the_vincu...@hotmail.com wrote:
 Hi Robert,

 the second half of my post is about the second option you was talking about.
 The apply only gathers the nodes in question and does nothing else then there 
 is another method that performs the removal from parent.
 But the issue with that is, that if I do not call this method, no removal is 
 done.
 That was, what I was talking about. The visitor finished its work but as long 
 as the user do not call an additional method the removal from parent has not 
 been done yet.

 I was hoping for a finish method that is automatically called after the 
 visitors work has been finished. This finish method could then perform the 
 necessary removal operation (or any other).


 Thank you!

 Cheers,
 Sam

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





 ___
 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] Visitor concept. No finalize?

2011-01-25 Thread Sam Warns
Hi Robert,

I am aware of the possibility to define my own methods in the visitor but the 
point I was trying to explain is, that if I apply a visitor on a scene I would 
except that this visitor has finished its work after calling the 
node-accept(myVisitor)

If I have a RemoveXVisitor and I as the user and not the writer of it use this 
visitor as I am used to use them by


Code:

RemoveXVisitor v;
node-accept(v);




I would expect that the Visitor has done it's work, which it actually didn't 
since there is no finalize method I would need to write:

Code:

RemoveXVisitor v;
node-accept(v);
v.doTheJobActually();




So there is a discrepancy between what I would except from a visitor after it 
was passed to accept and what a visitor is able to do in it's apply method

Greetings
Sam

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





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


Re: [osg-users] Visitor concept. No finalize?

2011-01-25 Thread Robert Osfield
Hi Sam,

I simply don't get why your are expecting things from the NodeVisitor
that it isn't intended to provide, and what you can very simply
provide yourself.

There are many examples of NodeVisitor's in action in the OSG please
do a search through the code base.

Robert.

On Tue, Jan 25, 2011 at 11:34 AM, Sam Warns the_vincu...@hotmail.com wrote:
 Hi Robert,

 I am aware of the possibility to define my own methods in the visitor but the 
 point I was trying to explain is, that if I apply a visitor on a scene I 
 would except that this visitor has finished its work after calling the 
 node-accept(myVisitor)

 If I have a RemoveXVisitor and I as the user and not the writer of it use 
 this visitor as I am used to use them by


 Code:

 RemoveXVisitor v;
 node-accept(v);




 I would expect that the Visitor has done it's work, which it actually didn't 
 since there is no finalize method I would need to write:

 Code:

 RemoveXVisitor v;
 node-accept(v);
 v.doTheJobActually();




 So there is a discrepancy between what I would except from a visitor after it 
 was passed to accept and what a visitor is able to do in it's apply method

 Greetings
 Sam

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





 ___
 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] Visitor concept. No finalize?

2011-01-25 Thread Sam Warns
Hi Robert,

I suppose I expect that because let's say a RemoveGroupsVisitor should remove 
Groups from a given graph, when I apply this visitor to a scene by


Code:

RemoveGroupsVisitor r;
scene-accept(r);




I personally would expect that now the groups are removed, which they are not 
by the limitation of the apply methods

Regards
Sam

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





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


Re: [osg-users] Visitor concept. No finalize?

2011-01-25 Thread Robert Osfield
Hi Sam,

Your expectations are unreasonable, please them recalibrate otherwise
you are going to constantly disappointed that everything in the world
doesn't conform to you prior conceptions.  In the case of the
NodeVisitor where you are seeing a limitation, it's actually a
positive and deliberate feature.

The OSG's NodeVisitor is extremely powerful and flexible, this is
achieved by handing over responsibility to the developer and makes as
few assumptions as possible.  With this it does have usage patterns
that you have to follow, there are plenty of examples that illustrate
it's use, and I have given you examples and explanations.

Robert.

On Tue, Jan 25, 2011 at 11:54 AM, Sam Warns the_vincu...@hotmail.com wrote:
 Hi Robert,

 I suppose I expect that because let's say a RemoveGroupsVisitor should 
 remove Groups from a given graph, when I apply this visitor to a scene by


 Code:

 RemoveGroupsVisitor r;
 scene-accept(r);




 I personally would expect that now the groups are removed, which they are not 
 by the limitation of the apply methods

 Regards
 Sam

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





 ___
 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] Visitor concept. No finalize?

2011-01-25 Thread Paul Martz

On 1/25/2011 4:34 AM, Sam Warns wrote:

Hi Robert,

I am aware of the possibility to define my own methods in the visitor but the 
point I was trying to explain is, that if I apply a visitor on a scene I would 
except that this visitor has finished its work after calling the 
node-accept(myVisitor)

If I have a RemoveXVisitor and I as the user and not the writer of it use this 
visitor as I am used to use them by


Code:

RemoveXVisitor v;
node-accept(v);




I would expect that the Visitor has done it's work, which it actually didn't since there 
is no finalize method I would need to write:

Code:

RemoveXVisitor v;
node-accept(v);
v.doTheJobActually();




So there is a discrepancy between what I would except from a visitor after it 
was passed to accept and what a visitor is able to do in it's apply method


If your RemoveXVisitor doesn't actually remove anything, but instead collects 
references to X (that you might remove later with a separate operation), then 
perhaps you should consider changing the name of the visitor to CollectXVisitor 
to more accurately describe its purpose, so that other developers don't get 
confused about what it does (as you are describing above).

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


Re: [osg-users] Visitor concept. No finalize?

2011-01-25 Thread Sam Warns
Hi,

that is exactly the point. My RemoveXVisitor  SHOULD remove nodes but since it 
is not possible to do that in apply and there is no finalize method that gets 
automatically called after accept has finished, it is only possible to remove 
nodes by providing a custom member which the user must call manually.

That is what I am talking about, it is not possible for a Visitor to do certain 
things without having the user explicitly call members of it after the accept 
call.

I did not demand a finalize method and I understand Robert's statement that 
flexibility is achieved by relying on the user. Never the less would a finalize 
method decrease any flexibility and power of it.

(Btw: I have never experienced that handing over responsibility to the user 
(which is the developer at this point) produced any good results, but this is 
only my experience) 

Thanks,
Sam

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





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