VTK  9.3.1
vtkAlgorithm.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
29 #ifndef vtkAlgorithm_h
30 #define vtkAlgorithm_h
31 
32 #include "vtkCommonExecutionModelModule.h" // For export macro
33 #include "vtkObject.h"
34 
35 VTK_ABI_NAMESPACE_BEGIN
36 class vtkAbstractArray;
37 class vtkAlgorithmInternals;
38 class vtkAlgorithmOutput;
39 class vtkCollection;
40 class vtkDataArray;
41 class vtkDataObject;
42 class vtkExecutive;
43 class vtkInformation;
50 
51 class VTKCOMMONEXECUTIONMODEL_EXPORT vtkAlgorithm : public vtkObject
52 {
53 public:
54  static vtkAlgorithm* New();
55  vtkTypeMacro(vtkAlgorithm, vtkObject);
56  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
79  {
82  DEFAULT_PRECISION
83  };
84 
89  vtkTypeBool HasExecutive();
90 
95  vtkExecutive* GetExecutive();
96 
102  virtual void SetExecutive(vtkExecutive* executive);
103 
127  virtual vtkTypeBool ProcessRequest(
128  vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outInfo);
129 
134  vtkTypeBool ProcessRequest(
135  vtkInformation* request, vtkCollection* inInfo, vtkInformationVector* outInfo);
136 
142  virtual int ComputePipelineMTime(vtkInformation* request, vtkInformationVector** inInfoVec,
143  vtkInformationVector* outInfoVec, int requestFromOutputPort, vtkMTimeType* mtime);
144 
152  virtual int ModifyRequest(vtkInformation* request, int when);
153 
160  vtkInformation* GetInputPortInformation(int port);
161 
168  vtkInformation* GetOutputPortInformation(int port);
169 
171 
174  vtkGetObjectMacro(Information, vtkInformation);
175  virtual void SetInformation(vtkInformation*);
177 
181  int GetNumberOfInputPorts();
182 
186  int GetNumberOfOutputPorts();
187 
189 
192  bool UsesGarbageCollector() const override { return true; }
194 
198  void SetAbortExecuteAndUpdateTime();
199 
201 
205  vtkSetMacro(AbortExecute, vtkTypeBool);
206  vtkGetMacro(AbortExecute, vtkTypeBool);
207  vtkBooleanMacro(AbortExecute, vtkTypeBool);
209 
211 
214  vtkGetMacro(Progress, double);
216 
222  void UpdateProgress(double amount);
223 
227  bool CheckAbort();
228 
230 
236  {
237  this->ContainerAlgorithm = containerAlg;
238  };
239  vtkAlgorithm* GetContainerAlgorithm() { return this->ContainerAlgorithm; };
241 
243 
250  vtkSetMacro(AbortOutput, bool);
251  vtkGetMacro(AbortOutput, bool);
253 
255 
267  void SetProgressShiftScale(double shift, double scale);
268  vtkGetMacro(ProgressShift, double);
269  vtkGetMacro(ProgressScale, double);
271 
273 
280  void SetProgressText(const char* ptext);
281  vtkGetStringMacro(ProgressText);
283 
285 
289  vtkGetMacro(ErrorCode, unsigned long);
291 
292  // left public for performance since it is used in inner loops
293  std::atomic<vtkTypeBool> AbortExecute;
294 
299  static vtkInformationIntegerKey* INPUT_IS_OPTIONAL();
303  static vtkInformationIntegerKey* INPUT_IS_REPEATABLE();
307  static vtkInformationInformationVectorKey* INPUT_REQUIRED_FIELDS();
311  static vtkInformationStringVectorKey* INPUT_REQUIRED_DATA_TYPE();
315  static vtkInformationInformationVectorKey* INPUT_ARRAYS_TO_PROCESS();
319  static vtkInformationIntegerKey* INPUT_PORT();
323  static vtkInformationIntegerKey* INPUT_CONNECTION();
324 
333  static vtkInformationIntegerKey* CAN_PRODUCE_SUB_EXTENT();
334 
347  static vtkInformationIntegerKey* CAN_HANDLE_PIECE_REQUEST();
348 
353  static vtkInformationIntegerKey* ABORTED();
354 
356 
364  virtual void SetInputArrayToProcess(
365  int idx, int port, int connection, int fieldAssociation, const char* name);
366  virtual void SetInputArrayToProcess(
367  int idx, int port, int connection, int fieldAssociation, int fieldAttributeType);
368  virtual void SetInputArrayToProcess(int idx, vtkInformation* info);
370 
394  virtual void SetInputArrayToProcess(int idx, int port, int connection,
395  const char* fieldAssociation, const char* attributeTypeorName);
396 
400  vtkInformation* GetInputArrayInformation(int idx);
401 
402  // from here down are convenience methods that really are executive methods
403 
407  void RemoveAllInputs();
408 
413  vtkDataObject* GetOutputDataObject(int port);
414 
419  vtkDataObject* GetInputDataObject(int port, int connection);
420 
422 
435  virtual void SetInputConnection(int port, vtkAlgorithmOutput* input);
436  virtual void SetInputConnection(vtkAlgorithmOutput* input);
438 
440 
449  virtual void AddInputConnection(int port, vtkAlgorithmOutput* input);
450  virtual void AddInputConnection(vtkAlgorithmOutput* input);
452 
462  virtual void RemoveInputConnection(int port, vtkAlgorithmOutput* input);
463 
467  virtual void RemoveInputConnection(int port, int idx);
468 
472  virtual void RemoveAllInputConnections(int port);
473 
482  virtual void SetInputDataObject(int port, vtkDataObject* data);
483  virtual void SetInputDataObject(vtkDataObject* data) { this->SetInputDataObject(0, data); }
484 
490  virtual void AddInputDataObject(int port, vtkDataObject* data);
491  virtual void AddInputDataObject(vtkDataObject* data) { this->AddInputDataObject(0, data); }
492 
499  vtkAlgorithmOutput* GetOutputPort(int index);
501 
505  int GetNumberOfInputConnections(int port);
506 
510  int GetTotalNumberOfInputConnections();
511 
515  vtkAlgorithmOutput* GetInputConnection(int port, int index);
516 
521  vtkAlgorithm* GetInputAlgorithm(int port, int index, int& algPort);
522 
526  vtkAlgorithm* GetInputAlgorithm(int port, int index);
527 
532 
537  vtkExecutive* GetInputExecutive(int port, int index);
538 
543 
552  vtkInformation* GetInputInformation(int port, int index);
553 
558 
566  vtkInformation* GetOutputInformation(int port);
567 
569 
572  virtual void Update(int port);
573  virtual void Update();
575 
598  virtual vtkTypeBool Update(int port, vtkInformationVector* requests);
599 
605  virtual vtkTypeBool Update(vtkInformation* requests);
606 
613  virtual int UpdatePiece(
614  int piece, int numPieces, int ghostLevels, const int extents[6] = nullptr);
615 
621  virtual int UpdateExtent(const int extents[6]);
622 
629  virtual int UpdateTimeStep(double time, int piece = -1, int numPieces = 1, int ghostLevels = 0,
630  const int extents[6] = nullptr);
631 
635  virtual void UpdateInformation();
636 
640  virtual void UpdateDataObject();
641 
645  virtual void PropagateUpdateExtent();
646 
650  virtual void UpdateWholeExtent();
651 
656  void ConvertTotalInputToPortConnection(int ind, int& port, int& conn);
657 
658  //======================================================================
659  // The following block of code is to support old style VTK applications. If
660  // you are using these calls there are better ways to do it in the new
661  // pipeline
662  //======================================================================
663 
665 
668  virtual void SetReleaseDataFlag(vtkTypeBool);
669  virtual vtkTypeBool GetReleaseDataFlag();
670  void ReleaseDataFlagOn();
671  void ReleaseDataFlagOff();
673 
674  //========================================================================
675 
677 
683  int UpdateExtentIsEmpty(vtkInformation* pinfo, vtkDataObject* output);
684  int UpdateExtentIsEmpty(vtkInformation* pinfo, int extentType);
686 
691  static void SetDefaultExecutivePrototype(vtkExecutive* proto);
692 
694 
699  int* GetUpdateExtent() VTK_SIZEHINT(6) { return this->GetUpdateExtent(0); }
700  int* GetUpdateExtent(int port) VTK_SIZEHINT(6);
701  void GetUpdateExtent(int& x0, int& x1, int& y0, int& y1, int& z0, int& z1)
702  {
703  this->GetUpdateExtent(0, x0, x1, y0, y1, z0, z1);
704  }
705  void GetUpdateExtent(int port, int& x0, int& x1, int& y0, int& y1, int& z0, int& z1);
706  void GetUpdateExtent(int extent[6]) { this->GetUpdateExtent(0, extent); }
707  void GetUpdateExtent(int port, int extent[6]);
709 
711 
716  int GetUpdatePiece() { return this->GetUpdatePiece(0); }
717  int GetUpdatePiece(int port);
719  int GetUpdateNumberOfPieces(int port);
720  int GetUpdateGhostLevel() { return this->GetUpdateGhostLevel(0); }
721  int GetUpdateGhostLevel(int port);
723 
725 
734  void SetProgressObserver(vtkProgressObserver*);
735  vtkGetObjectMacro(ProgressObserver, vtkProgressObserver);
737 
738 protected:
739  vtkAlgorithm();
740  ~vtkAlgorithm() override;
741 
742  // Time stamp to store the last time any filter was aborted.
744 
745  // Time stamp to store the last time this filter checked for an
746  // abort.
748 
749  // Keys used to indicate that input/output port information has been
750  // filled.
751  static vtkInformationIntegerKey* PORT_REQUIREMENTS_FILLED();
752 
753  // Arbitrary extra information associated with this algorithm
755 
760  bool CheckUpstreamAbort();
761 
767  virtual int FillInputPortInformation(int port, vtkInformation* info);
768 
774  virtual int FillOutputPortInformation(int port, vtkInformation* info);
775 
779  virtual void SetNumberOfInputPorts(int n);
780 
784  virtual void SetNumberOfOutputPorts(int n);
785 
786  // Helper methods to check input/output port index ranges.
787  int InputPortIndexInRange(int index, const char* action);
788  int OutputPortIndexInRange(int index, const char* action);
789 
794  int GetInputArrayAssociation(int idx, vtkInformationVector** inputVector);
795 
797 
805  int GetInputArrayAssociation(int idx, int connection, vtkInformationVector** inputVector);
806  int GetInputArrayAssociation(int idx, vtkDataObject* input);
808 
810 
814  vtkDataArray* GetInputArrayToProcess(int idx, vtkInformationVector** inputVector);
815  vtkDataArray* GetInputArrayToProcess(
816  int idx, vtkInformationVector** inputVector, int& association);
818 
820 
828  vtkDataArray* GetInputArrayToProcess(int idx, int connection, vtkInformationVector** inputVector);
829  vtkDataArray* GetInputArrayToProcess(
830  int idx, int connection, vtkInformationVector** inputVector, int& association);
831  vtkDataArray* GetInputArrayToProcess(int idx, vtkDataObject* input);
832  vtkDataArray* GetInputArrayToProcess(int idx, vtkDataObject* input, int& association);
834 
836 
840  vtkAbstractArray* GetInputAbstractArrayToProcess(int idx, vtkInformationVector** inputVector);
841  vtkAbstractArray* GetInputAbstractArrayToProcess(
842  int idx, vtkInformationVector** inputVector, int& association);
844 
846 
854  vtkAbstractArray* GetInputAbstractArrayToProcess(
855  int idx, int connection, vtkInformationVector** inputVector);
856  vtkAbstractArray* GetInputAbstractArrayToProcess(
857  int idx, int connection, vtkInformationVector** inputVector, int& association);
858  vtkAbstractArray* GetInputAbstractArrayToProcess(int idx, vtkDataObject* input);
859  vtkAbstractArray* GetInputAbstractArrayToProcess(int idx, vtkDataObject* input, int& association);
861 
869  vtkInformation* GetInputArrayFieldInformation(int idx, vtkInformationVector** inputVector);
870 
877  virtual vtkExecutive* CreateDefaultExecutive();
878 
880 
884  vtkSetMacro(ErrorCode, unsigned long);
885  unsigned long ErrorCode;
887 
888  // Progress/Update handling
889  double Progress;
891 
892  // Garbage collection support.
893  void ReportReferences(vtkGarbageCollector*) override;
894 
895  // executive methods below
896 
903  virtual void SetNthInputConnection(int port, int index, vtkAlgorithmOutput* input);
904 
911  virtual void SetNumberOfInputConnections(int port, int n);
912 
914 
922  {
923  this->SetInputDataObject(port, input);
924  }
926  {
927  this->AddInputDataObject(port, input);
928  }
929 
931 
932 private:
933  vtkExecutive* Executive;
934  vtkInformationVector* InputPortInformation;
935  vtkInformationVector* OutputPortInformation;
936  vtkAlgorithmInternals* AlgorithmInternal;
937  static void ConnectionAdd(
938  vtkAlgorithm* producer, int producerPort, vtkAlgorithm* consumer, int consumerPort);
939  static void ConnectionRemove(
940  vtkAlgorithm* producer, int producerPort, vtkAlgorithm* consumer, int consumerPort);
941  static void ConnectionRemoveAllInput(vtkAlgorithm* consumer, int port);
942  static void ConnectionRemoveAllOutput(vtkAlgorithm* producer, int port);
943 
944  vtkAlgorithm(const vtkAlgorithm&) = delete;
945  void operator=(const vtkAlgorithm&) = delete;
946 
947  double ProgressShift;
948  double ProgressScale;
949  vtkAlgorithm* ContainerAlgorithm;
950  bool AbortOutput;
951 };
952 
953 VTK_ABI_NAMESPACE_END
954 #endif
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:500
vtkAlgorithm * GetContainerAlgorithm()
Set/get a Container algorithm for this algorithm.
Definition: vtkAlgorithm.h:239
abstract base class for most VTK objects
Definition: vtkObject.h:51
DesiredOutputPrecision
Values used for setting the desired output precision for various algorithms.
Definition: vtkAlgorithm.h:78
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void GetUpdateExtent(int extent[6])
These functions return the update extent for output ports that use 3D extents.
Definition: vtkAlgorithm.h:706
int GetUpdatePiece()
These functions return the update extent for output ports that use piece extents. ...
Definition: vtkAlgorithm.h:716
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
static vtkTimeStamp LastAbortTime
Definition: vtkAlgorithm.h:743
int * GetUpdateExtent()
These functions return the update extent for output ports that use 3D extents.
Definition: vtkAlgorithm.h:699
Abstract superclass for all arrays.
record modification and/or execution time
Definition: vtkTimeStamp.h:24
vtkAlgorithm * GetInputAlgorithm()
Equivalent to GetInputAlgorithm(0, 0).
Definition: vtkAlgorithm.h:531
vtkInformation * GetInputInformation()
Equivalent to GetInputInformation(0, 0)
Definition: vtkAlgorithm.h:557
virtual void AddInputDataObject(vtkDataObject *data)
Definition: vtkAlgorithm.h:491
Superclass for all pipeline executives in VTK.
Definition: vtkExecutive.h:38
void SetInputDataInternal(int port, vtkDataObject *input)
These methods are used by subclasses to implement methods to set data objects directly as input...
Definition: vtkAlgorithm.h:921
Key for string values in vtkInformation.
Detect and break reference loops.
Proxy object to connect input/output ports.
int vtkTypeBool
Definition: vtkABI.h:64
void AddInputDataInternal(int port, vtkDataObject *input)
Definition: vtkAlgorithm.h:925
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:51
vtkInformation * Information
Definition: vtkAlgorithm.h:754
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void ReportReferences(vtkGarbageCollector *)
Key for integer values in vtkInformation.
int GetUpdateNumberOfPieces()
These functions return the update extent for output ports that use piece extents. ...
Definition: vtkAlgorithm.h:718
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
#define VTK_SIZEHINT(...)
Key for String vector values.
char * ProgressText
Definition: vtkAlgorithm.h:890
void SetContainerAlgorithm(vtkAlgorithm *containerAlg)
Set/get a Container algorithm for this algorithm.
Definition: vtkAlgorithm.h:235
virtual void SetInputDataObject(vtkDataObject *data)
Definition: vtkAlgorithm.h:483
unsigned long ErrorCode
The error code contains a possible error that occurred while reading or writing the file...
Definition: vtkAlgorithm.h:884
double Progress
Definition: vtkAlgorithm.h:889
create and manipulate ordered lists of objects
Definition: vtkCollection.h:44
int GetUpdateGhostLevel()
These functions return the update extent for output ports that use piece extents. ...
Definition: vtkAlgorithm.h:720
vtkTimeStamp LastAbortCheckTime
Definition: vtkAlgorithm.h:747
bool UsesGarbageCollector() const override
Participate in garbage collection.
Definition: vtkAlgorithm.h:192
Store zero or more vtkInformation instances.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkProgressObserver * ProgressObserver
Definition: vtkAlgorithm.h:930
general representation of visualization data
Definition: vtkDataObject.h:54
vtkExecutive * GetInputExecutive()
Equivalent to GetInputExecutive(0, 0)
Definition: vtkAlgorithm.h:542
void GetUpdateExtent(int &x0, int &x1, int &y0, int &y1, int &z0, int &z1)
These functions return the update extent for output ports that use 3D extents.
Definition: vtkAlgorithm.h:701
Basic class to optionally replace vtkAlgorithm progress functionality.
static vtkExecutive * DefaultExecutivePrototype
Definition: vtkAlgorithm.h:913
std::atomic< vtkTypeBool > AbortExecute
Definition: vtkAlgorithm.h:289