]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/ProcessObject.h
Code cleaning
[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     void DisconnectInputs( );
82     void DisconnectOutputs( );
83     void Disconnect( );
84
85     // Pipeline execution
86     virtual void Modified( ) const ITK_OVERRIDE;
87     virtual itk::ModifiedTimeType GetMTime( ) const ITK_OVERRIDE;
88     virtual void Update( );
89
90     // Qt dialog creation
91     virtual QDialog* CreateQDialog( );
92     virtual bool IsInteractive( );
93     virtual void SetInteractionObjects( const std::vector< void* >& objs );
94
95   protected:
96     ProcessObject( );
97     virtual ~ProcessObject( );
98
99     void _AddInput( const std::string& name, bool required = true );
100     void _Error( const std::string& error );
101
102     template< class O >
103       inline void _AddOutput( const std::string& name );
104
105     template< class F >
106       inline F* _CreateITK( );
107     template< class F >
108       inline F* _CreateVTK( );
109
110     virtual void _GenerateData( ) = 0;
111
112   private:
113     // Purposely not implemented
114     ProcessObject( const Self& );
115     Self& operator=( const Self& );
116
117   protected:
118     Parameters m_Parameters;
119     std::string m_Name;
120     std::string m_PluginName;
121     bool m_CouldHaveExplicitReExecution;
122     bool m_ExplicitReExecution;
123
124     typedef std::map< std::string, InputPort >  _TInputs;
125     typedef std::map< std::string, OutputPort > _TOutputs;
126     _TInputs  m_Inputs;
127     _TOutputs m_Outputs;
128
129     itk::ModifiedTimeType m_LastExecutionTime;
130     mutable long m_LastExecutionSpan;
131
132     bool m_PrintExecution;
133     std::ostream* m_PrintExecutionStream;
134   };
135
136 } // ecapseman
137
138 #include <cpPlugins/ProcessObject.hxx>
139
140 #endif // __CPPLUGINS__PROCESSOBJECT__H__
141
142 // eof - $RCSfile$