VTK
dox/Common/ExecutionModel/vtkAlgorithm.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkAlgorithm.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00040 #ifndef __vtkAlgorithm_h
00041 #define __vtkAlgorithm_h
00042 
00043 #include "vtkCommonExecutionModelModule.h" // For export macro
00044 #include "vtkObject.h"
00045 
00046 class vtkAbstractArray;
00047 class vtkAlgorithmInternals;
00048 class vtkAlgorithmOutput;
00049 class vtkCollection;
00050 class vtkDataArray;
00051 class vtkDataObject;
00052 class vtkExecutive;
00053 class vtkInformation;
00054 class vtkInformationInformationVectorKey;
00055 class vtkInformationIntegerKey;
00056 class vtkInformationStringKey;
00057 class vtkInformationStringVectorKey;
00058 class vtkInformationVector;
00059 class vtkProgressObserver;
00060 
00061 class VTKCOMMONEXECUTIONMODEL_EXPORT vtkAlgorithm : public vtkObject
00062 {
00063 public:
00064   static vtkAlgorithm *New();
00065   vtkTypeMacro(vtkAlgorithm,vtkObject);
00066   void PrintSelf(ostream& os, vtkIndent indent);
00067 
00069 
00080   enum DesiredOutputPrecision
00081     {
00082     SINGLE_PRECISION,
00083     DOUBLE_PRECISION,
00084     DEFAULT_PRECISION
00085     };
00087 
00090   int HasExecutive();
00091 
00094   vtkExecutive* GetExecutive();
00095 
00099   virtual void SetExecutive(vtkExecutive* executive);
00100 
00102 
00116   virtual int ProcessRequest(vtkInformation* request,
00117                              vtkInformationVector** inInfo,
00118                              vtkInformationVector* outInfo);
00120 
00122 
00124   int ProcessRequest(vtkInformation* request,
00125                      vtkCollection* inInfo,
00126                      vtkInformationVector* outInfo);
00128 
00130 
00133   virtual int
00134   ComputePipelineMTime(vtkInformation* request,
00135                        vtkInformationVector** inInfoVec,
00136                        vtkInformationVector* outInfoVec,
00137                        int requestFromOutputPort,
00138                        unsigned long* mtime);
00140 
00146   virtual int ModifyRequest(vtkInformation* request, int when);
00147 
00152   vtkInformation* GetInputPortInformation(int port);
00153 
00158   vtkInformation* GetOutputPortInformation(int port);
00159 
00161 
00162   vtkGetObjectMacro(Information, vtkInformation);
00163   virtual void SetInformation(vtkInformation*);
00165 
00167   int GetNumberOfInputPorts();
00168 
00170   int GetNumberOfOutputPorts();
00171 
00173 
00174   virtual void Register(vtkObjectBase* o);
00175   virtual void UnRegister(vtkObjectBase* o);
00177 
00179 
00181   vtkSetMacro(AbortExecute,int);
00182   vtkGetMacro(AbortExecute,int);
00183   vtkBooleanMacro(AbortExecute,int);
00185 
00187 
00188   vtkSetClampMacro(Progress,double,0.0,1.0);
00189   vtkGetMacro(Progress,double);
00191 
00195   void UpdateProgress(double amount);
00196 
00198 
00203   void SetProgressText(const char* ptext);
00204   vtkGetStringMacro(ProgressText);
00206 
00208 
00210   vtkGetMacro( ErrorCode, unsigned long );
00212 
00213   // left public for performance since it is used in inner loops
00214   int AbortExecute;
00215 
00217 
00218   static vtkInformationIntegerKey* INPUT_IS_OPTIONAL();
00219   static vtkInformationIntegerKey* INPUT_IS_REPEATABLE();
00220   static vtkInformationInformationVectorKey* INPUT_REQUIRED_FIELDS();
00221   static vtkInformationStringVectorKey* INPUT_REQUIRED_DATA_TYPE();
00222   static vtkInformationInformationVectorKey* INPUT_ARRAYS_TO_PROCESS();
00223   static vtkInformationIntegerKey* INPUT_PORT();
00224   static vtkInformationIntegerKey* INPUT_CONNECTION();
00226 
00227 
00229 
00235   virtual void SetInputArrayToProcess(int idx, int port, int connection,
00236                               int fieldAssociation,
00237                               const char *name);
00238   virtual void SetInputArrayToProcess(int idx, int port, int connection,
00239                               int fieldAssociation,
00240                               int fieldAttributeType);
00241   virtual void SetInputArrayToProcess(int idx, vtkInformation *info);
00243 
00245 
00259   virtual void SetInputArrayToProcess(int idx, int port, int connection,
00260                               const char* fieldAssociation,
00261                               const char* attributeTypeorName);
00263 
00265   vtkInformation *GetInputArrayInformation(int idx);
00266 
00267   // from here down are convenience methods that really are executive methods
00268 
00269 
00270 
00272   void RemoveAllInputs();
00273 
00276   vtkDataObject* GetOutputDataObject(int port);
00277 
00279 
00281   vtkDataObject *GetInputDataObject(int port,
00282                                     int connection);
00284 
00286 
00295   virtual void SetInputConnection(int port, vtkAlgorithmOutput* input);
00296   virtual void SetInputConnection(vtkAlgorithmOutput* input);
00298 
00300 
00305   virtual void AddInputConnection(int port, vtkAlgorithmOutput* input);
00306   virtual void AddInputConnection(vtkAlgorithmOutput* input);
00308 
00315   virtual void RemoveInputConnection(int port, vtkAlgorithmOutput* input);
00316 
00318   virtual void RemoveInputConnection(int port, int idx);
00319 
00321   virtual void RemoveAllInputConnections(int port);
00322 
00324 
00331   virtual void SetInputDataObject(int port, vtkDataObject* data);
00332   virtual void SetInputDataObject(vtkDataObject* data)
00333     { this->SetInputDataObject(0, data); }
00335 
00337 
00340   virtual void AddInputDataObject(int port, vtkDataObject* data);
00341   virtual void AddInputDataObject(vtkDataObject* data)
00342     { this->AddInputDataObject(0, data); }
00344 
00346 
00350   vtkAlgorithmOutput* GetOutputPort(int index);
00351   vtkAlgorithmOutput* GetOutputPort() {
00352     return this->GetOutputPort(0); }
00354 
00356   int GetNumberOfInputConnections(int port);
00357 
00359   int GetTotalNumberOfInputConnections();
00360 
00362   vtkAlgorithmOutput* GetInputConnection(int port, int index);
00363 
00366   vtkAlgorithm* GetInputAlgorithm(int port, int index, int& algPort);
00367 
00369   vtkAlgorithm* GetInputAlgorithm(int port, int index);
00370 
00372 
00373   vtkAlgorithm* GetInputAlgorithm()
00374   {
00375     return this->GetInputAlgorithm(0, 0);
00376   }
00378 
00380   vtkExecutive* GetInputExecutive(int port, int index);
00381 
00383 
00384   vtkExecutive* GetInputExecutive()
00385   {
00386     return this->GetInputExecutive(0, 0);
00387   }
00389 
00396   vtkInformation* GetInputInformation(int port, int index);
00397 
00399 
00400   vtkInformation* GetInputInformation()
00401   {
00402     return this->GetInputInformation(0, 0);
00403   }
00405 
00410   vtkInformation* GetOutputInformation(int port);
00411 
00413 
00414   virtual void Update(int port);
00415   virtual void Update();
00417 
00418 
00420   virtual void UpdateInformation();
00421 
00423   virtual void PropagateUpdateExtent();
00424 
00426   virtual void UpdateWholeExtent();
00427 
00430   void ConvertTotalInputToPortConnection(int ind, int& port, int& conn);
00431 
00432   //======================================================================
00433   //The following block of code is to support old style VTK applications. If
00434   //you are using these calls there are better ways to do it in the new
00435   //pipeline
00436   //======================================================================
00437 
00439 
00440   virtual void SetReleaseDataFlag(int);
00441   virtual int GetReleaseDataFlag();
00442   void ReleaseDataFlagOn();
00443   void ReleaseDataFlagOff();
00445 
00446   //========================================================================
00447 
00449 
00453   int UpdateExtentIsEmpty(vtkInformation *pinfo, vtkDataObject *output);
00454   int UpdateExtentIsEmpty(vtkInformation *pinfo, int extentType);
00456 
00459   static void SetDefaultExecutivePrototype(vtkExecutive* proto);
00460 
00464   virtual double ComputePriority();
00465 
00467 
00469   static vtkInformationIntegerKey* PRESERVES_DATASET();
00470   static vtkInformationIntegerKey* PRESERVES_GEOMETRY();
00471   static vtkInformationIntegerKey* PRESERVES_BOUNDS();
00472   static vtkInformationIntegerKey* PRESERVES_TOPOLOGY();
00473   static vtkInformationIntegerKey* PRESERVES_ATTRIBUTES();
00474   static vtkInformationIntegerKey* PRESERVES_RANGES();
00475   static vtkInformationIntegerKey* MANAGES_METAINFORMATION();
00477 
00482   int SetUpdateExtentToWholeExtent(int port);
00483 
00487   int SetUpdateExtentToWholeExtent();
00488 
00490 
00491   void SetUpdateExtent(int port,
00492                        int piece,int numPieces, int ghostLevel);
00494 
00496 
00498   void SetUpdateExtent(int piece,int numPieces, int ghostLevel)
00499   {
00500     this->SetUpdateExtent(0, piece, numPieces, ghostLevel);
00501   }
00503 
00505   void SetUpdateExtent(int port, int extent[6]);
00506 
00508 
00509   void SetUpdateExtent(int extent[6])
00510   {
00511     this->SetUpdateExtent(0, extent);
00512   }
00514 
00516 
00518   int* GetUpdateExtent()
00519   {
00520     return this->GetUpdateExtent(0);
00521   }
00522   int* GetUpdateExtent(int port);
00523   void GetUpdateExtent(int& x0, int& x1, int& y0, int& y1,
00524                        int& z0, int& z1)
00525   {
00526     this->GetUpdateExtent(0, x0, x1, y0, y1, z0, z1);
00527   }
00528   void GetUpdateExtent(int port,
00529                        int& x0, int& x1, int& y0, int& y1,
00530                        int& z0, int& z1);
00531   void GetUpdateExtent(int extent[6])
00532   {
00533     this->GetUpdateExtent(0, extent);
00534   }
00535   void GetUpdateExtent(int port, int extent[6]);
00537 
00539 
00541   int GetUpdatePiece()
00542   {
00543     return this->GetUpdatePiece(0);
00544   }
00545   int GetUpdatePiece(int port);
00546   int GetUpdateNumberOfPieces()
00547   {
00548     return this->GetUpdateNumberOfPieces(0);
00549   }
00550   int GetUpdateNumberOfPieces(int port);
00551   int GetUpdateGhostLevel()
00552   {
00553     return this->GetUpdateGhostLevel(0);
00554   }
00555   int GetUpdateGhostLevel(int port);
00557 
00559 
00565   void SetProgressObserver(vtkProgressObserver*);
00566   vtkGetObjectMacro(ProgressObserver, vtkProgressObserver);
00568 
00569 protected:
00570   vtkAlgorithm();
00571   ~vtkAlgorithm();
00572 
00573   // Keys used to indicate that input/output port information has been
00574   // filled.
00575   static vtkInformationIntegerKey* PORT_REQUIREMENTS_FILLED();
00576 
00577   // Arbitrary extra information associated with this algorithm
00578   vtkInformation* Information;
00579 
00583   virtual int FillInputPortInformation(int port, vtkInformation* info);
00584 
00588   virtual int FillOutputPortInformation(int port, vtkInformation* info);
00589 
00591   virtual void SetNumberOfInputPorts(int n);
00592 
00594   virtual void SetNumberOfOutputPorts(int n);
00595 
00596   // Helper methods to check input/output port index ranges.
00597   int InputPortIndexInRange(int index, const char* action);
00598   int OutputPortIndexInRange(int index, const char* action);
00599 
00603   int GetInputArrayAssociation(int idx, vtkInformationVector **inputVector);
00604 
00606 
00612   int GetInputArrayAssociation(int idx, int connection,
00613                                vtkInformationVector **inputVector);
00614   int GetInputArrayAssociation(int idx, vtkDataObject* input);
00616 
00617 
00619 
00621   vtkDataArray *GetInputArrayToProcess(int idx,vtkInformationVector **inputVector);
00622   vtkDataArray *GetInputArrayToProcess(int idx,
00623                                        vtkInformationVector **inputVector,
00624                                        int& association);
00626 
00628 
00634   vtkDataArray *GetInputArrayToProcess(int idx,
00635                                        int connection,
00636                                        vtkInformationVector **inputVector);
00637   vtkDataArray *GetInputArrayToProcess(int idx,
00638                                        int connection,
00639                                        vtkInformationVector **inputVector,
00640                                        int& association);
00641   vtkDataArray *GetInputArrayToProcess(int idx,
00642                                        vtkDataObject* input);
00643   vtkDataArray *GetInputArrayToProcess(int idx,
00644                                        vtkDataObject* input,
00645                                        int& association);
00647 
00648 
00650 
00652   vtkAbstractArray *GetInputAbstractArrayToProcess(int idx,vtkInformationVector **inputVector);
00653   vtkAbstractArray *GetInputAbstractArrayToProcess
00654     (int idx, vtkInformationVector **inputVector, int& association);
00656 
00658 
00664   vtkAbstractArray *GetInputAbstractArrayToProcess(int idx,
00665                                        int connection,
00666                                        vtkInformationVector **inputVector);
00667   vtkAbstractArray *GetInputAbstractArrayToProcess(int idx,
00668                                        int connection,
00669                                        vtkInformationVector **inputVector,
00670                                        int& association);
00671   vtkAbstractArray *GetInputAbstractArrayToProcess(int idx,
00672                                        vtkDataObject* input);
00673   vtkAbstractArray *GetInputAbstractArrayToProcess(int idx,
00674                                        vtkDataObject* input,
00675                                        int& association);
00677 
00678 
00679 
00681 
00686   vtkInformation *GetInputArrayFieldInformation(int idx,
00687                                                 vtkInformationVector **inputVector);
00689 
00690 
00695   virtual vtkExecutive* CreateDefaultExecutive();
00696 
00698 
00700   vtkSetMacro( ErrorCode, unsigned long );
00701   unsigned long ErrorCode;
00703 
00704   // Progress/Update handling
00705   double Progress;
00706   char  *ProgressText;
00707 
00708   // Garbage collection support.
00709   virtual void ReportReferences(vtkGarbageCollector*);
00710 
00711   // executive methods below
00712 
00714 
00718   virtual void SetNthInputConnection(int port, int index,
00719                                      vtkAlgorithmOutput* input);
00721 
00726   virtual void SetNumberOfInputConnections(int port, int n);
00727 
00728   static vtkExecutive* DefaultExecutivePrototype;
00729 
00731 
00735   void SetInputDataInternal(int port, vtkDataObject *input)
00736     { this->SetInputDataObject(port, input); }
00737   void AddInputDataInternal(int port, vtkDataObject *input)
00738     { this->AddInputDataObject(port, input); }
00740 
00741   vtkProgressObserver* ProgressObserver;
00742 
00743 private:
00744   vtkExecutive* Executive;
00745   vtkInformationVector* InputPortInformation;
00746   vtkInformationVector* OutputPortInformation;
00747   vtkAlgorithmInternals* AlgorithmInternal;
00748   static void ConnectionAdd(vtkAlgorithm* producer, int producerPort,
00749                             vtkAlgorithm* consumer, int consumerPort);
00750   static void ConnectionRemove(vtkAlgorithm* producer, int producerPort,
00751                                vtkAlgorithm* consumer, int consumerPort);
00752   static void ConnectionRemoveAllInput(vtkAlgorithm* consumer, int port);
00753   static void ConnectionRemoveAllOutput(vtkAlgorithm* producer, int port);
00754 
00755 private:
00756   vtkAlgorithm(const vtkAlgorithm&);  // Not implemented.
00757   void operator=(const vtkAlgorithm&);  // Not implemented.
00758 };
00759 
00760 #endif