[vtkusers] Determining Actor type

David Gobbi david.gobbi at gmail.com
Sun Feb 21 09:02:07 EST 2010


The VTK RTTI has the advantage of being very robust on all platforms.
Even in this day and age, there are situations where a compiler's
native RTTI just doesn't work.  For example, gcc RTTI has some problem
related to shared libraries that cause it not to work for some of the
plugins that I build.  It's documented in the gcc faq:

http://gcc.gnu.org/faq.html

Because of issues like the above, code inside VTK never uses
dynamic_cast.  And I would discourage you from using dynamic_cast when
you write your own VTK classes, in case you ever want to contribute
them to VTK.

    David


On Sun, Feb 21, 2010 at 4:15 AM, Kenneth Porter <shiva at sewingwitch.com> wrote:
> --On Saturday, February 20, 2010 4:44 PM -0800 Kenneth Porter
> <shiva at sewingwitch.com> wrote:
>
>> Sorry, I just did an eyeball inspection of the implementation. I guess I
>> need to go back and see how this works with an intermediate class.
>
> Ok, my mistake, I missed the treewalker line in the IsTypeOf implementation:
>
>  static int IsTypeOf(const char *type) \
>  { \
>   if ( !strcmp(#thisClass,type) ) \
>     { \
>     return 1; \
>     } \
>   return superclass::IsTypeOf(type); \
>  } \
>
> The last line that invokes the superclass handles the intermediate classes
> by walking down the inheritance tree.
>
> I would speculate that dynamic_cast is more efficient if you're already
> building with RTTI enabled. (It can do a pointer comparison instead of a
> string comparison.) If you suppress RTTI with a compiler option (for
> example, to reduce space in the binary) then the VTK implementation reduces
> the memory footprint to just providing the RTTI info for the VTK library. Is
> there another advantage to using the VTK mechanism?
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list