]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/BaseObjects/ProcessObject.h
...
[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       bool HasInput( const std::string& n ) const;
59       bool HasOutput( const std::string& n ) const;
60
61       unsigned int GetNumberOfInputs( ) const;
62       unsigned int GetNumberOfOutputs( ) const;
63       unsigned int GetInputSize( const std::string& n ) const;
64       bool IsInputMultiple( const std::string& n ) const;
65
66       template< class _TType = DataObject >
67       inline _TType* GetInput( const std::string& n, unsigned int i = 0 );
68
69       template< class _TType = DataObject >
70       inline const _TType* GetInput(
71         const std::string& n, unsigned int i = 0
72         ) const;
73
74       template< class _TType = itk::LightObject >
75       inline _TType* GetInputData( const std::string& n, unsigned int i = 0 );
76
77       template< class _TType = itk::LightObject >
78       inline const _TType* GetInputData(
79         const std::string& n, unsigned int i = 0
80         ) const;
81
82       template< class _TType = DataObject >
83       inline _TType* GetOutput( const std::string& n );
84
85       template< class _TType = DataObject >
86       inline const _TType* GetOutput( const std::string& n ) const;
87
88       template< class _TType = itk::LightObject >
89       inline _TType* GetOutputData( const std::string& n );
90
91       template< class _TType = itk::LightObject >
92       inline const _TType* GetOutputData( const std::string& n ) const;
93
94       // "Setters"
95       virtual void AddInput( const std::string& n, DataObject* o );
96       virtual void SetInput( const std::string& n, DataObject* o );
97
98       // Other interesting methods
99       void DisconnectInput( const std::string& n, unsigned int id );
100       void DisconnectInputs( );
101       void DisconnectOutputs( );
102       void Disconnect( );
103
104       // Pipeline execution
105       virtual void Modified( ) const cpPlugins_OVERRIDE;
106       virtual void Update( );
107
108       // Qt dialog creation
109       virtual QDialog* CreateQDialog( );
110       virtual void AddInteractor( vtkRenderWindowInteractor* i );
111       virtual bool IsInteractive( );
112
113     protected:
114       ProcessObject( );
115       virtual ~ProcessObject( );
116
117       // Error handling method
118       void _Error( const std::string& error );
119
120       // For configuration purposes
121       template< class _TType = DataObject >
122       inline void _ConfigureInput(
123         const std::string& name, bool required, bool multiple
124         );
125
126       template< class _TType = DataObject >
127       inline void _ConfigureOutput( const std::string& name );
128
129       template< class _TFilter >
130       inline _TFilter* _CreateITK( );
131
132       template< class _TFilter >
133       inline _TFilter* _CreateVTK( );
134
135       virtual void _GenerateData( ) = 0;
136
137     private:
138       // Purposely not implemented
139       ProcessObject( const Self& );
140       Self& operator=( const Self& );
141
142     protected:
143       Parameters m_Parameters;
144       std::string m_Name;
145       std::string m_PluginName;
146       bool m_ExplicitExecution;
147
148       std::map< std::string, Port* > m_Inputs;
149       std::map< std::string, Port* > m_Outputs;
150
151       itk::ModifiedTimeType m_LastExecutionTime;
152       mutable long m_LastExecutionSpan;
153
154       bool m_PrintExecution;
155       std::ostream* m_PrintExecutionStream;
156     };
157
158   } // ecapseman
159
160 } // ecapseman
161
162 #include <cpPlugins/BaseObjects/ProcessObject.hxx>
163
164 #endif // __cpPlugins__BaseObjects__ProcessObject__h__
165
166 // eof - $RCSfile$