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