]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/PolyDataReader.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / PolyDataReader.cxx
1 #include <cpPlugins/Plugins/PolyDataReader.h>
2 #include <cpPlugins/Interface/PolyData.h>
3
4 #include <vtkErrorCode.h>
5 #include <vtkPolyDataReader.h>
6
7 // -------------------------------------------------------------------------
8 std::string cpPlugins::Plugins::PolyDataReader::
9 GetClassName( ) const
10 {
11   return( "cpPlugins::Plugins::PolyDataReader" );
12 }
13
14 // -------------------------------------------------------------------------
15 cpPlugins::Plugins::PolyDataReader::
16 PolyDataReader( )
17   : Superclass( )
18 {
19   this->SetNumberOfOutputs( 1 );
20   this->_MakeOutput< cpPlugins::Interface::PolyData >( 0 );
21
22   using namespace cpPlugins::Interface;
23   this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
24   this->m_Parameters = this->m_DefaultParameters;
25 }
26
27 // -------------------------------------------------------------------------
28 cpPlugins::Plugins::PolyDataReader::
29 ~PolyDataReader( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 std::string cpPlugins::Plugins::PolyDataReader::
35 _GenerateData( )
36 {
37   // Get filename
38   using namespace cpPlugins::Interface;
39   Parameters::TString fname =
40     this->m_Parameters.GetValueAsString( "FileName" );
41
42   // Create a possible reader
43   vtkPolyDataReader* reader =
44     dynamic_cast< vtkPolyDataReader* >( this->m_Reader.GetPointer( ) );
45   if( reader == NULL )
46   {
47     this->m_Reader = vtkSmartPointer< vtkPolyDataReader >::New( );
48     reader =
49       dynamic_cast< vtkPolyDataReader* >( this->m_Reader.GetPointer( ) );
50
51   } // fi
52   reader->SetFileName( fname.c_str( ) );
53   reader->Update( );
54   unsigned long error = reader->GetErrorCode( );
55   if( error == vtkErrorCode::NoError )
56   {
57     if( this->m_Outputs[ 0 ].IsNotNull( ) )
58     {
59       cpPlugins::Interface::PolyData* pdata =
60         dynamic_cast< cpPlugins::Interface::PolyData* >(
61           this->m_Outputs[ 0 ].GetPointer( )
62           );
63       if( pdata != NULL )
64         pdata->SetRealDataObject( reader->GetOutput( ) );
65
66     } // fi
67     return( "" );
68   }
69   else
70     return( vtkErrorCode::GetStringFromErrorCode( error ) );
71 }
72
73 // eof - $RCSfile$