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