]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/BaseObjects/ProcessObject.h
8d7536c4b75ea3145904ea61a6c7450d60b5190c
[cpPlugins.git] / lib / cpPlugins / BaseObjects / ProcessObject.h
1 #ifndef __cpPlugins__BaseObjects__ProcessObject__h__
2 #define __cpPlugins__BaseObjects__ProcessObject__h__
3
4 #include <cpPlugins/BaseObjects/Object.h>
5 #include <cpPlugins/BaseObjects/Parameters.h>
6 #include <cpPlugins/BaseObjects/Port.h>
7 #include <set>
8
9 // -------------------------------------------------------------------------
10 class QDialog;
11 class vtkRenderWindowInteractor;
12
13 // -------------------------------------------------------------------------
14 namespace cpPlugins
15 {
16   namespace BaseObjects
17   {
18     /**
19      */
20     class cpPlugins_EXPORT ProcessObject
21       : public Object
22     {
23     public:
24       typedef ProcessObject                   Self;
25       typedef Object                          Superclass;
26       typedef itk::SmartPointer< Self >       Pointer;
27       typedef itk::SmartPointer< const Self > ConstPointer;
28
29     public:
30       itkTypeMacro( ProcessObject, Object );
31       cpPlugins_Id_Macro( ProcessObject, Object );
32
33       itkBooleanMacro( ExplicitExecution );
34       itkBooleanMacro( PrintExecution );
35
36       itkGetStringMacro( Name );
37       itkGetStringMacro( PluginName );
38       itkGetConstMacro( ExplicitExecution, bool );
39       itkGetConstMacro( LastExecutionSpan, long );
40       itkGetConstMacro( PrintExecution, bool );
41
42       itkSetStringMacro( Name );
43       itkSetStringMacro( PluginName );
44       itkSetMacro( ExplicitExecution, bool );
45       itkSetMacro( PrintExecution, bool );
46       itkSetObjectMacro( PrintExecutionStream, std::ofstream );
47
48     public:
49       Parameters* GetParameters( );
50       const Parameters* GetParameters( ) const;
51
52       virtual void SetITK( itk::LightObject* o ) final;
53       virtual void SetVTK( vtkObjectBase* o ) final;
54
55       // "Getters"
56       std::set< std::string > GetInputsNames( ) const;
57       std::set< std::string > GetOutputsNames( ) const;
58
59       unsigned int GetNumberOfInputs( ) const;
60       unsigned int GetNumberOfOutputs( ) const;
61       unsigned int GetInputSize( const std::string& n ) const;
62
63       template< class _TType = DataObject >
64         _TType* GetInput( const std::string& n, unsigned int i = 0 );
65
66       template< class _TType = DataObject >
67         const _TType* GetInput(
68           const std::string& n, unsigned int i = 0
69           ) const;
70
71       template< class _TType = itk::LightObject >
72         _TType* GetInputData( const std::string& n, unsigned int i = 0 );
73
74       template< class _TType = itk::LightObject >
75         const _TType* GetInputData(
76           const std::string& n, unsigned int i = 0
77           ) const;
78
79       template< class _TType = DataObject >
80         _TType* GetOutput( const std::string& n );
81
82       template< class _TType = DataObject >
83         const _TType* GetOutput( const std::string& n ) const;
84
85       template< class _TType = itk::LightObject >
86         _TType* GetOutputData( const std::string& n );
87
88       template< class _TType = itk::LightObject >
89         const _TType* GetOutputData( const std::string& n ) const;
90
91       // "Setters"
92       virtual void AddInput( const std::string& n, DataObject* o );
93       virtual void SetInput( const std::string& n, DataObject* o );
94
95       // Other interesting methods
96       void DisconnectInputs( );
97       void DisconnectOutputs( );
98       void Disconnect( );
99
100       // Pipeline execution
101       virtual void Modified( ) const cpPlugins_OVERRIDE;
102       virtual itk::ModifiedTimeType GetMTime( ) const cpPlugins_OVERRIDE;
103       virtual void Update( );
104
105       // Qt dialog creation
106       virtual QDialog* CreateQDialog( );
107       virtual void AddInteractor( vtkRenderWindowInteractor* i );
108       virtual bool IsInteractive( );
109
110     protected:
111       ProcessObject( );
112       virtual ~ProcessObject( );
113
114       // Error handling method
115       void _Error( const std::string& error );
116
117       // For configuration purposes
118       template< class _TType = DataObject >
119         void _ConfigureInput(
120           const std::string& name, bool required, bool multiple
121           );
122
123       template< class _TType = DataObject >
124         void _ConfigureOutput( const std::string& name );
125
126       template< class _TFilter >
127         _TFilter* _CreateITK( );
128
129       template< class _TFilter >
130         _TFilter* _CreateVTK( );
131
132       virtual void _GenerateData( ) = 0;
133
134     private:
135       // Purposely not implemented
136       ProcessObject( const Self& );
137       Self& operator=( const Self& );
138
139     protected:
140       Parameters m_Parameters;
141       std::string m_Name;
142       std::string m_PluginName;
143       bool m_ExplicitExecution;
144
145       std::map< std::string, Port* > m_Inputs;
146       std::map< std::string, Port* > m_Outputs;
147
148       itk::ModifiedTimeType m_LastExecutionTime;
149       mutable long m_LastExecutionSpan;
150
151       bool m_PrintExecution;
152       std::ostream* m_PrintExecutionStream;
153
154       typedef vtkSmartPointer< vtkRenderWindowInteractor > _TInteractor;
155       struct _TInteractorCmp
156       {
157         bool operator()(
158           const _TInteractor& a, const _TInteractor& b
159           ) const
160           { return( a.GetPointer( ) < b.GetPointer( ) ); }
161       };
162       std::set< _TInteractor, _TInteractorCmp > m_Interactors;
163     };
164
165   } // ecapseman
166
167 } // ecapseman
168
169 #include <cpPlugins/BaseObjects/ProcessObject.hxx>
170
171 #endif // __cpPlugins__BaseObjects__ProcessObject__h__
172
173 // eof - $RCSfile$