]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/ProcessObject.h
...
[cpPlugins.git] / lib / cpPlugins / ProcessObject.h
1 #ifndef __CPPLUGINS__PROCESSOBJECT__H__
2 #define __CPPLUGINS__PROCESSOBJECT__H__
3
4 #include <map>
5 #include <set>
6 #include <cpPlugins/Object.h>
7 #include <cpPlugins/Parameters.h>
8 #include <cpPlugins/Port.h>
9
10 class QDialog;
11
12 namespace cpPlugins
13 {
14   /**
15    */
16   class cpPlugins_EXPORT ProcessObject
17     : public Object
18   {
19   public:
20     typedef ProcessObject                   Self;
21     typedef Object                          Superclass;
22     typedef itk::SmartPointer< Self >       Pointer;
23     typedef itk::SmartPointer< const Self > ConstPointer;
24
25   public:
26     itkTypeMacro( ProcessObject, Object );
27     cpPlugins_Id_Macro( ProcessObject, Object );
28
29     itkBooleanMacro( ExplicitReExecution );
30     itkBooleanMacro( PrintExecution );
31
32     itkGetStringMacro( Name );
33     itkGetStringMacro( PluginName );
34     itkGetConstMacro( ExplicitReExecution, bool );
35     itkGetConstMacro( CouldHaveExplicitReExecution, bool );
36     itkGetConstMacro( LastExecutionSpan, long );
37     itkGetConstMacro( PrintExecution, bool );
38
39     itkSetStringMacro( Name );
40     itkSetStringMacro( PluginName );
41     itkSetMacro( ExplicitReExecution, bool );
42     itkSetMacro( PrintExecution, bool );
43     itkSetObjectMacro( PrintExecutionStream, std::ofstream );
44
45   public:
46     Parameters* GetParameters( );
47     const Parameters* GetParameters( ) const;
48
49     virtual void SetITK( itk::LightObject* o ) final;
50     virtual void SetVTK( vtkObjectBase* o ) final;
51
52     // IO management
53     std::set< std::string > GetInputsNames( ) const;
54     std::set< std::string > GetOutputsNames( ) const;
55     unsigned int GetNumberOfInputs( ) const;
56     unsigned int GetNumberOfOutputs( ) const;
57
58     OutputPort& GetOutputPort( const std::string& id );
59     const OutputPort& GetOutputPort( const std::string& id ) const;
60
61     template< class _TType = DataObject >
62       inline _TType* GetInput( const std::string& id );
63
64     template< class _TType = DataObject >
65       inline const _TType* GetInput( const std::string& id ) const;
66
67     template< class _TType = DataObject >
68       inline _TType* GetOutput( const std::string& id );
69
70     template< class _TType = DataObject >
71       inline const _TType* GetOutput( const std::string& id ) const;
72
73     template< class _TType = itk::LightObject >
74       inline _TType* GetInputData( const std::string& name );
75
76     template< class _TType = itk::LightObject >
77       inline _TType* GetOutputData( const std::string& name );
78
79     bool SetInputPort( const std::string& id, const OutputPort& port );
80
81     template< class _TType >
82       inline bool SetInput( const std::string& id, _TType* obj );
83
84     void DisconnectInputs( );
85     void DisconnectOutputs( );
86     void Disconnect( );
87
88     // Pipeline execution
89     virtual void Modified( ) const ITK_OVERRIDE;
90     virtual itk::ModifiedTimeType GetMTime( ) const ITK_OVERRIDE;
91     virtual void Update( );
92
93     // Qt dialog creation
94     virtual QDialog* CreateQDialog( );
95     virtual bool IsInteractive( );
96     virtual void SetInteractionObjects( const std::vector< void* >& objs );
97
98   protected:
99     ProcessObject( );
100     virtual ~ProcessObject( );
101
102     void _AddInput( const std::string& name, bool required = true );
103     void _Error( const std::string& error );
104
105     template< class O >
106       inline void _AddOutput( const std::string& name );
107
108     template< class F >
109       inline F* _CreateITK( );
110     template< class F >
111       inline F* _CreateVTK( );
112
113     virtual void _GenerateData( ) = 0;
114
115   private:
116     // Purposely not implemented
117     ProcessObject( const Self& );
118     Self& operator=( const Self& );
119
120   protected:
121     Parameters m_Parameters;
122     std::string m_Name;
123     std::string m_PluginName;
124     bool m_CouldHaveExplicitReExecution;
125     bool m_ExplicitReExecution;
126
127     typedef std::map< std::string, InputPort >  _TInputs;
128     typedef std::map< std::string, OutputPort > _TOutputs;
129     _TInputs  m_Inputs;
130     _TOutputs m_Outputs;
131
132     itk::ModifiedTimeType m_LastExecutionTime;
133     mutable long m_LastExecutionSpan;
134
135     bool m_PrintExecution;
136     std::ostream* m_PrintExecutionStream;
137   };
138
139 } // ecapseman
140
141 #include <cpPlugins/ProcessObject.hxx>
142
143 #endif // __CPPLUGINS__PROCESSOBJECT__H__
144
145 // eof - $RCSfile$