1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkExecutive.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkExecutive - Superclass for all pipeline executives in VTK.
16 // .SECTION Description
17 // vtkExecutive is the superclass for all pipeline executives in VTK.
18 // A VTK executive is responsible for controlling one instance of
19 // vtkAlgorithm.  A pipeline consists of one or more executives that
20 // control data flow.  Every reader, source, writer, or data
21 // processing algorithm in the pipeline is implemented in an instance
22 // of vtkAlgorithm.
23 
24 #ifndef vtkExecutive_h
25 #define vtkExecutive_h
26 
27 #include "vtkCommonExecutionModelModule.h" // For export macro
28 #include "vtkObject.h"
29 
30 class vtkAlgorithm;
31 class vtkAlgorithmOutput;
32 class vtkAlgorithmToExecutiveFriendship;
33 class vtkDataObject;
34 class vtkExecutiveInternals;
35 class vtkInformation;
36 class vtkInformationExecutivePortKey;
37 class vtkInformationExecutivePortVectorKey;
38 class vtkInformationIntegerKey;
39 class vtkInformationRequestKey;
40 class vtkInformationKeyVectorKey;
41 class vtkInformationVector;
42 
43 class VTKCOMMONEXECUTIONMODEL_EXPORT vtkExecutive : public vtkObject
44 {
45 public:
46   vtkTypeMacro(vtkExecutive,vtkObject);
47   void PrintSelf(ostream& os, vtkIndent indent);
48 
49   // Description:
50   // Get the algorithm to which this executive has been assigned.
51   vtkAlgorithm* GetAlgorithm();
52 
53   // Description:
54   // Generalized interface for asking the executive to fulfill
55   // pipeline requests.
56   virtual int ProcessRequest(vtkInformation* request,
57                              vtkInformationVector** inInfo,
58                              vtkInformationVector* outInfo);
59 
60   // Description:
61   // A special version of ProcessRequest meant specifically for the
62   // pipeline modified time request.  This is an optimization since
63   // the request is called so often and it travels the full length of
64   // the pipeline.  We augment the signature with method arguments
65   // containing the common information, specifically the output port
66   // through which the request was made and the resulting modified
67   // time.  Note that unlike ProcessRequest the request information
68   // object may be NULL for this method.  It also does not contain a
69   // request identifcation key because the request is known from the
70   // method name.
71   virtual int
72   ComputePipelineMTime(vtkInformation* request,
73                        vtkInformationVector** inInfoVec,
74                        vtkInformationVector* outInfoVec,
75                        int requestFromOutputPort,
76                        unsigned long* mtime);
77 
78   // Description:
79   // Bring the output information up to date.
UpdateInformation()80   virtual int UpdateInformation() {return 1;}
81 
82   // Description:
83   // Bring the algorithm's outputs up-to-date.  Returns 1 for success
84   // and 0 for failure.
85   virtual int Update();
86   virtual int Update(int port);
87 
88   // Description:
89   // Get the number of input/output ports for the algorithm associated
90   // with this executive.  Returns 0 if no algorithm is set.
91   int GetNumberOfInputPorts();
92   int GetNumberOfOutputPorts();
93 
94   // Description:
95   // Get the number of input connections on the given port.
96   int GetNumberOfInputConnections(int port);
97 
98   // Description:
99   // Get the pipeline information object for the given output port.
100   virtual vtkInformation* GetOutputInformation(int port);
101 
102   // Description:
103   // Get the pipeline information object for all output ports.
104   vtkInformationVector* GetOutputInformation();
105 
106   // Description:
107   // Get the pipeline information for the given input connection.
108   vtkInformation* GetInputInformation(int port, int connection);
109 
110   // Description:
111   // Get the pipeline information vectors for the given input port.
112   vtkInformationVector* GetInputInformation(int port);
113 
114   // Description:
115   // Get the pipeline information vectors for all inputs
116   vtkInformationVector** GetInputInformation();
117 
118   // Description:
119   // Get the executive managing the given input connection.
120   vtkExecutive* GetInputExecutive(int port, int connection);
121 
122   // Description:
123   // Get/Set the data object for an output port of the algorithm.
124   virtual vtkDataObject* GetOutputData(int port);
125   virtual void SetOutputData(int port, vtkDataObject*, vtkInformation *info);
126   virtual void SetOutputData(int port, vtkDataObject*);
127 
128   // Description:
129   // Get the data object for an input port of the algorithm.
130   virtual vtkDataObject* GetInputData(int port, int connection);
131   virtual vtkDataObject* GetInputData(int port, int connection,
132                                       vtkInformationVector **inInfoVec);
133 
134   // Description:
135   // Get the output port that produces the given data object.
136   // Works only if the data was producer by this executive's
137   // algorithm.
138   // virtual vtkAlgorithmOutput* GetProducerPort(vtkDataObject*);
139 
140   // Description:
141   // Set a pointer to an outside instance of input or output
142   // information vectors.  No references are held to the given
143   // vectors, and setting this does not change the executive object
144   // modification time.  This is a preliminary interface to use in
145   // implementing filters with internal pipelines, and may change
146   // without notice when a future interface is created.
147   void SetSharedInputInformation(vtkInformationVector** inInfoVec);
148   void SetSharedOutputInformation(vtkInformationVector* outInfoVec);
149 
150   // Description:
151   // Participate in garbage collection.
152   virtual void Register(vtkObjectBase* o);
153   virtual void UnRegister(vtkObjectBase* o);
154 
155   // Description:
156   // Information key to store the executive/port number producing an
157   // information object.
158   static vtkInformationExecutivePortKey* PRODUCER();
159 
160   // Description:
161   // Information key to store the executive/port number pairs
162   // consuming an information object.
163   static vtkInformationExecutivePortVectorKey* CONSUMERS();
164 
165   // Description:
166   // Information key to store the output port number from which a
167   // request is made.
168   static vtkInformationIntegerKey* FROM_OUTPUT_PORT();
169 
170   // Description:
171   // Keys to program vtkExecutive::ProcessRequest with the default
172   // behavior for unknown requests.
173   static vtkInformationIntegerKey* ALGORITHM_BEFORE_FORWARD();
174   static vtkInformationIntegerKey* ALGORITHM_AFTER_FORWARD();
175   static vtkInformationIntegerKey* ALGORITHM_DIRECTION();
176   static vtkInformationIntegerKey* FORWARD_DIRECTION();
177   static vtkInformationKeyVectorKey* KEYS_TO_COPY();
178   //BTX
179   enum { RequestUpstream, RequestDownstream };
180   enum { BeforeForward, AfterForward };
181   //ETX
182 
183   // Description:
184   // An API to CallAlgorithm that allows you to pass in the info objects to
185   // be used
186   virtual int CallAlgorithm(vtkInformation* request, int direction,
187                             vtkInformationVector** inInfo,
188                             vtkInformationVector* outInfo);
189 
190 protected:
191   vtkExecutive();
192   ~vtkExecutive();
193 
194   // Helper methods for subclasses.
195   int InputPortIndexInRange(int port, const char* action);
196   int OutputPortIndexInRange(int port, const char* action);
197 
198   // Called by methods to check for a recursive pipeline update.  A
199   // request should be fulfilled without making another request.  This
200   // is used to help enforce that behavior.  Returns 1 if no recursive
201   // request is occurring, and 0 otherwise.  An error message is
202   // produced automatically if 0 is returned.  The first argument is
203   // the name of the calling method (the one that should not be
204   // invoked recursively during an update).  The second argument is
205   // the recursive request information object, if any.  It is used to
206   // construct the error message.
207   int CheckAlgorithm(const char* method, vtkInformation* request);
208 
209   virtual int ForwardDownstream(vtkInformation* request);
210   virtual int ForwardUpstream(vtkInformation* request);
211   virtual void CopyDefaultInformation(vtkInformation* request, int direction,
212                                       vtkInformationVector** inInfo,
213                                       vtkInformationVector* outInfo);
214 
215   // Reset the pipeline update values in the given output information object.
216   virtual void ResetPipelineInformation(int port, vtkInformation*)=0;
217 
218   // Bring the existence of output data objects up to date.
219   virtual int UpdateDataObject()=0;
220 
221   // Garbage collection support.
222   virtual void ReportReferences(vtkGarbageCollector*);
223 
224   virtual void SetAlgorithm(vtkAlgorithm* algorithm);
225 
226   // The algorithm managed by this executive.
227   vtkAlgorithm* Algorithm;
228 
229   // Flag set when the algorithm is processing a request.
230   int InAlgorithm;
231 
232   // Pointers to an outside instance of input or output information.
233   // No references are held.  These are used to implement internal
234   // pipelines.
235   vtkInformationVector** SharedInputInformation;
236   vtkInformationVector* SharedOutputInformation;
237 
238 private:
239   // Store an information object for each output port of the algorithm.
240   vtkInformationVector* OutputInformation;
241 
242   // Internal implementation details.
243   vtkExecutiveInternals* ExecutiveInternal;
244 
245   //BTX
246   friend class vtkAlgorithmToExecutiveFriendship;
247   //ETX
248 private:
249   vtkExecutive(const vtkExecutive&);  // Not implemented.
250   void operator=(const vtkExecutive&);  // Not implemented.
251 };
252 
253 #endif
254