Run-time type information and vtkWhatever::New()

pahsieh at usgs.gov pahsieh at usgs.gov
Mon Jan 17 20:40:16 EST 2000


Brian:

If you just want to determine the type of data set (structured points
versus polydata, etc)
you can invoke GetClassName, which is a virtual function defined in
vtkObject.

Paul



                                                                                                       
                    Brian Alexander Todd                                                               
                    <bat5 at po.cwru.edu>              To:     vtkusers at gsao.med.ge.com                   
                    Sent by:                        cc:                                                
                    owner-vtkusers at gsao.gso.        Subject:     Run-time type information and         
                    med.ge.com                      vtkWhatever::New()                                 
                                                                                                       
                                                                                                       
                    01/17/00 01:42 PM                                                                  
                                                                                                       
                                                                                                       



Dear vtkusers,

I have a question about navigating the vtk class heirarchy.
I have an application that uses a "document/view" architecture.
The doc maintains a list of <vtkDataSet *> and the views render
the data using pipelines that depend on what the exact type of
vtkDataSet is (vtkStructuredPoints, vtkPolyData, etc.).  At somepoint,
the view is required to figure out exactly what kind of object the
vtkDataSet pointer points to so it can decide which pipeline to use.
Naturally, I assumed I should use dynamic_cast to do this, since the
type will not be known at compile-time.  I ran into some problems doing
this

If I run this block of code under WinNT 4.0 (SP 5) and VC++ 6.0 (SP 3),

           vtkDataSet * vtkds;
           vtkStructuredPoints * vtksp1 = vtkStructuredPoints::New();
           vtkStructuredPoints * vtksp2;

           vtkds = vtksp1;
           vtksp2 = dynamic_cast<vtkStructuredPoints *>( vtkds );

           std::cout << vtksp1 << std::endl;
           std::cout << vtksp2 << std::endl;

The program returns,

           00300570
           00000000

This confused me because it means the program was unable to
convert back to the subclass vtkStructuredPoints after handing
the pointer off to the polymorphic vtkDataSet.  However, if
I through out the vtkStructuredPoints::New idea and go with the
normal "new vtkStructuredPoints", as in,

           vtkDataSet * vtkds;
           vtkStructuredPoints * vtksp1 = new vtkStructuredPoints;
           vtkStructuredPoints * vtksp2;

           vtkds = vtksp1;
           vtksp2 = dynamic_cast<vtkStructuredPoints *>( vtkds );

           std::cout << vtksp1 << std::endl;
           std::cout << vtksp2 << std::endl;

then the program returns,

           00300570
           00300570

which is the expected behavior.

So, basically, I have two questions.  Why does this happen (out of
curiousoty) and what can I do to get run-time type identification
so that make my program works (more importantly)?

Thank you,
Brian Todd
           _____________________________________________________
  ________|                                                     |________
  \       |   Brian Todd                email: bat5 at po.cwru.edu |       /
   \      |   N.O.B.L.                   home: (216) 791-2407   |      /
    \     |   C.W.R.U.                 office: (216) 368-4209   |     /
    /     |   Cleveland, OH 44106         fax: (216) 368-4969   |     \
   /      |_____________________________________________________|      \
  /___________)                                              (__________\


-----------------------------------------------------------------------------

This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------








-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list