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

Miller, James V (CRD) millerjv at crd.ge.com
Tue Jan 18 08:46:05 EST 2000


An ability to do an operation similar to dynamic_cast is in the works.  I believe that we do not use
dynamic_cast since it requires that your code and all the support libraries you use be compiled with
the RTTI option. 

However, last week we discussed how we could provide a CastTo and an IsA (or IsTypeOf) capability.  I
believe we were a couple of Perl scripts away from having the code converted to provided these
functions. So it should be RSN.



> -----Original Message-----
> From: Brian Alexander Todd [mailto:bat5 at po.cwru.edu]
> Sent: Monday, January 17, 2000 4:43 PM
> To: vtkusers at gsao.med.ge.com
> Subject: Run-time type information and vtkWhatever::New()
> 
> 
> 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