]> Creatis software - cpPlugins.git/blob - plugins/cpExtensions/SkeletonReader.cxx
yet another refactoring
[cpPlugins.git] / plugins / cpExtensions / SkeletonReader.cxx
1 #include <cpExtensions/SkeletonReader.h>
2 #include <cpInstances/DataObjects/Skeleton.h>
3
4 #include <cpExtensions/DataStructures/Skeleton.h>
5 #include <cpExtensions/Algorithms/SkeletonReader.h>
6 #include <cpPlugins/QT/OpenFileDialog.h>
7
8 #ifdef cpPlugins_QT4
9 #  include <QApplication>
10 #endif // cpPlugins_QT4
11
12 // -------------------------------------------------------------------------
13 QDialog* cpPluginscpExtensions::SkeletonReader::
14 CreateQDialog( )
15 {
16 #ifdef cpPlugins_QT4
17   cpPlugins::QT::OpenFileDialog* dlg = NULL;
18   if( QApplication::instance( ) != NULL )
19   {
20     dlg = new cpPlugins::QT::OpenFileDialog( );
21     dlg->SetParameters( &( this->m_Parameters ), "FileName" );
22
23   } // fi
24   return( dlg );
25 #else // cpPlugins_QT4
26   return( NULL );
27 #endif // cpPlugins_QT4
28 }
29
30 // -------------------------------------------------------------------------
31 cpPluginscpExtensions::SkeletonReader::
32 SkeletonReader( )
33   : Superclass( )
34 {
35   this->_ConfigureOutput< cpInstances::Skeleton >( "Output" );
36   this->m_Parameters.ConfigureAsOpenFileName( "FileName", "" );
37   this->m_Parameters.SetAcceptedFileExtensions(
38     "FileName",
39     "Skeleton files (*.txt)"
40     );
41 }
42
43 // -------------------------------------------------------------------------
44 cpPluginscpExtensions::SkeletonReader::
45 ~SkeletonReader( )
46 {
47 }
48
49 // -------------------------------------------------------------------------
50 void cpPluginscpExtensions::SkeletonReader::
51 _GenerateData( )
52 {
53   std::string success = "";
54 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
55   success = this->_GD0< 1 >( );
56 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
57 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
58   if( success != "" ) success = this->_GD0< 2 >( );
59 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
60 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
61   if( success != "" ) success = this->_GD0< 3 >( );
62 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
63 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
64   if( success != "" ) success = this->_GD0< 4 >( );
65 #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
66   if( success != "" )
67     this->_Error( success );
68 }
69
70 // -------------------------------------------------------------------------
71 template< unsigned int _VDim >
72 std::string cpPluginscpExtensions::SkeletonReader::
73 _GD0( )
74 {
75   typedef cpExtensions::DataStructures::Skeleton< _VDim > _TSkeleton;
76   typedef cpExtensions::Algorithms::SkeletonReader< _TSkeleton > _TReader;
77
78   auto filter = this->_CreateITK< _TReader >( );
79   filter->SetFileName( this->m_Parameters.GetOpenFileName( "FileName" ) );
80   try
81   {
82     filter->Update( );
83   }
84   catch( std::exception& err )
85   {
86     return( err.what( ) );
87
88   } // yrt
89   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
90   return( "" );
91 }
92
93 // eof - $RCSfile$