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