]> 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     DataObject* GetInput( const std::string& id );
50     const DataObject* GetInput( const std::string& id ) const;
51     DataObject* GetOutput( const std::string& id );
52     const DataObject* GetOutput( const std::string& id ) const;
53
54     template< class _TType >
55       _TType* GetInputData( const std::string& name );
56
57     template< class _TType >
58       _TType* GetOutputData( const std::string& name );
59
60     bool SetInputPort( const std::string& id, const OutputPort& port );
61
62     void DisconnectInputs( );
63     void DisconnectOutputs( );
64     void Disconnect( );
65
66     // Pipeline execution
67     virtual void Modified( ) const ITK_OVERRIDE;
68     virtual itk::ModifiedTimeType GetMTime( ) const ITK_OVERRIDE;
69     virtual void Update( );
70
71     // Qt dialog creation
72     virtual ParametersQtDialog* CreateQtDialog( );
73     virtual bool IsInteractive( );
74     virtual void SetInteractionObjects( const std::vector< void* >& objs );
75
76   protected:
77     ProcessObject( );
78     virtual ~ProcessObject( );
79
80     void _AddInput( const std::string& name, bool required = true );
81     void _Error( const std::string& error );
82
83     template< class O >
84       inline void _AddOutput( const std::string& name );
85
86     template< class F >
87       inline F* _CreateITK( );
88     template< class F >
89       inline F* _CreateVTK( );
90
91     virtual void _GenerateData( ) = 0;
92
93   private:
94     // Purposely not implemented
95     ProcessObject( const Self& );
96     Self& operator=( const Self& );
97
98   protected:
99     Parameters m_Parameters;
100
101     typedef std::map< std::string, InputPort >  _TInputs;
102     typedef std::map< std::string, OutputPort > _TOutputs;
103     _TInputs  m_Inputs;
104     _TOutputs m_Outputs;
105
106     itk::ModifiedTimeType m_LastExecutionTime;
107     mutable long m_LastExecutionSpan;
108
109     bool m_PrintExecution;
110     std::ostream* m_PrintExecutionStream;
111   };
112
113 } // ecapseman
114
115 #include <cpPlugins/ProcessObject.hxx>
116
117 #endif // __CPPLUGINS__PROCESSOBJECT__H__
118
119 // eof - $RCSfile$