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