1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkDemandDrivenPipeline.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 vtkDemandDrivenPipeline - Executive supporting on-demand execution.
16 // .SECTION Description
17 // vtkDemandDrivenPipeline is an executive that will execute an
18 // algorithm only when its outputs are out-of-date with respect to its
19 // inputs.
20 
21 #ifndef vtkDemandDrivenPipeline_h
22 #define vtkDemandDrivenPipeline_h
23 
24 #include "vtkCommonExecutionModelModule.h" // For export macro
25 #include "vtkExecutive.h"
26 
27 class vtkAbstractArray;
28 class vtkDataArray;
29 class vtkDataSetAttributes;
30 class vtkDemandDrivenPipelineInternals;
31 class vtkFieldData;
32 class vtkInformation;
33 class vtkInformationIntegerKey;
34 class vtkInformationVector;
35 class vtkInformationKeyVectorKey;
36 class vtkInformationUnsignedLongKey;
37 
38   ///\defgroup InformationKeys Information Keys
39   /// The VTK pipeline relies on algorithms providing information about their
40   /// input and output and responding to requests.  The information objects used
41   /// to perform these actions map known keys to values.  This is a list of keys
42   /// that information objects use and what each key should be used for.
43   ///
44 
45 class VTKCOMMONEXECUTIONMODEL_EXPORT vtkDemandDrivenPipeline : public vtkExecutive
46 {
47 public:
48   static vtkDemandDrivenPipeline* New();
49   vtkTypeMacro(vtkDemandDrivenPipeline,vtkExecutive);
50   void PrintSelf(ostream& os, vtkIndent indent);
51 
52   // Description:
53   // Generalized interface for asking the executive to fulfill update
54   // requests.
55   virtual int ProcessRequest(vtkInformation* request,
56                              vtkInformationVector** inInfo,
57                              vtkInformationVector* outInfo);
58 
59   // Description:
60   // Implement the pipeline modified time request.
61   virtual int
62   ComputePipelineMTime(vtkInformation* request,
63                        vtkInformationVector** inInfoVec,
64                        vtkInformationVector* outInfoVec,
65                        int requestFromOutputPort,
66                        unsigned long* mtime);
67 
68   // Description:
69   // Bring the algorithm's outputs up-to-date.  Returns 1 for success
70   // and 0 for failure.
71   virtual int Update();
72   virtual int Update(int port);
73 
74   // Description:
75   // Get the PipelineMTime for this exective.
76   vtkGetMacro(PipelineMTime, unsigned long);
77 
78   // Description:
79   // Set whether the given output port releases data when it is
80   // consumed.  Returns 1 if the the value changes and 0 otherwise.
81   virtual int SetReleaseDataFlag(int port, int n);
82 
83   // Description:
84   // Get whether the given output port releases data when it is consumed.
85   virtual int GetReleaseDataFlag(int port);
86 
87   // Description:
88   // Bring the PipelineMTime up to date.
89   virtual int UpdatePipelineMTime();
90 
91   // Description:
92   // Bring the output data object's existence up to date.  This does
93   // not actually produce data, but does create the data object that
94   // will store data produced during the UpdateData step.
95   virtual int UpdateDataObject();
96 
97   // Description:
98   // Bring the output information up to date.
99   virtual int UpdateInformation();
100 
101   // Description:
102   // Bring the output data up to date.  This should be called only
103   // when information is up to date.  Use the Update method if it is
104   // not known that the information is up to date.
105   virtual int UpdateData(int outputPort);
106 
107   // Description:
108   // Key defining a request to make sure the output data objects exist.
109   // @ingroup InformationKeys
110   static vtkInformationRequestKey* REQUEST_DATA_OBJECT();
111 
112   // Description:
113   // Key defining a request to make sure the output information is up to date.
114   // @ingroup InformationKeys
115   static vtkInformationRequestKey* REQUEST_INFORMATION();
116 
117   // Description:
118   // Key defining a request to make sure the output data are up to date.
119   // @ingroup InformationKeys
120   static vtkInformationRequestKey* REQUEST_DATA();
121 
122   // Description:
123   // Key defining a request to mark outputs that will NOT be generated
124   // during a REQUEST_DATA.
125   // @ingroup InformationKeys
126   static vtkInformationRequestKey* REQUEST_DATA_NOT_GENERATED();
127 
128   // Description:
129   // Key to specify in pipeline information the request that data be
130   // released after it is used.
131   // @ingroup InformationKeys
132   static vtkInformationIntegerKey* RELEASE_DATA();
133 
134   // Description:
135   // Key to store a mark for an output that will not be generated.
136   // Algorithms use this to tell the executive that they will not
137   // generate certain outputs for a REQUEST_DATA.
138   // @ingroup InformationKeys
139   static vtkInformationIntegerKey* DATA_NOT_GENERATED();
140 
141   // Description:
142   // Create (New) and return a data object of the given type.
143   // This is here for backwards compatibility. Use
144   // vtkDataObjectTypes::NewDataObject() instead.
145   static vtkDataObject* NewDataObject(const char* type);
146 
147 protected:
148   vtkDemandDrivenPipeline();
149   ~vtkDemandDrivenPipeline();
150 
151   // Helper methods to send requests to the algorithm.
152   virtual int ExecuteDataObject(vtkInformation* request,
153                                 vtkInformationVector** inInfo,
154                                 vtkInformationVector* outInfo);
155   virtual int ExecuteInformation(vtkInformation* request,
156                                  vtkInformationVector** inInfo,
157                                  vtkInformationVector* outInfo);
158   virtual int ExecuteData(vtkInformation* request,
159                           vtkInformationVector** inInfo,
160                           vtkInformationVector* outInfo);
161 
162 
163   // Reset the pipeline update values in the given output information object.
164   virtual void ResetPipelineInformation(int, vtkInformation*);
165 
166   // Check whether the data object in the pipeline information for an
167   // output port exists and has a valid type.
168   virtual int CheckDataObject(int port, vtkInformationVector* outInfo);
169 
170 
171   // Input connection validity checkers.
172   int InputCountIsValid(vtkInformationVector **);
173   int InputCountIsValid(int port,vtkInformationVector **);
174   int InputTypeIsValid(vtkInformationVector **);
175   int InputTypeIsValid(int port,vtkInformationVector **);
176   virtual int InputTypeIsValid(int port, int index,vtkInformationVector **);
177   int InputFieldsAreValid(vtkInformationVector **);
178   int InputFieldsAreValid(int port,vtkInformationVector **);
179   virtual int InputFieldsAreValid(int port, int index,vtkInformationVector **);
180 
181   // Field existence checkers.
182   int DataSetAttributeExists(vtkDataSetAttributes* dsa, vtkInformation* field);
183   int FieldArrayExists(vtkFieldData* data, vtkInformation* field);
184   int ArrayIsValid(vtkAbstractArray* array, vtkInformation* field);
185 
186   // Input port information checkers.
187   int InputIsOptional(int port);
188   int InputIsRepeatable(int port);
189 
190   // Decide whether the output data need to be generated.
191   virtual int NeedToExecuteData(int outputPort,
192                                 vtkInformationVector** inInfoVec,
193                                 vtkInformationVector* outInfoVec);
194 
195   // Handle before/after operations for ExecuteData method.
196   virtual void ExecuteDataStart(vtkInformation* request,
197                                 vtkInformationVector** inInfoVec,
198                                 vtkInformationVector* outInfoVec);
199   virtual void ExecuteDataEnd(vtkInformation* request,
200                               vtkInformationVector** inInfoVec,
201                               vtkInformationVector* outInfoVec);
202   virtual void MarkOutputsGenerated(vtkInformation* request,
203                                     vtkInformationVector** inInfoVec,
204                                     vtkInformationVector* outInfoVec);
205 
206   // Largest MTime of any algorithm on this executive or preceding
207   // executives.
208   unsigned long PipelineMTime;
209 
210   // Time when information or data were last generated.
211   vtkTimeStamp DataObjectTime;
212   vtkTimeStamp InformationTime;
213   vtkTimeStamp DataTime;
214 
215 //BTX
216   friend class vtkCompositeDataPipeline;
217 //ETX
218 
219 
220   vtkInformation *InfoRequest;
221   vtkInformation *DataObjectRequest;
222   vtkInformation *DataRequest;
223 
224 private:
225   vtkDemandDrivenPipeline(const vtkDemandDrivenPipeline&);  // Not implemented.
226   void operator=(const vtkDemandDrivenPipeline&);  // Not implemented.
227 };
228 
229 #endif
230