VTK  9.7.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 "vtkArrayComponents.h" // For enum
33 #include "vtkCommonExecutionModelModule.h" // For export macro
34 #include "vtkObject.h"
35 #include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
36 
37 VTK_ABI_NAMESPACE_BEGIN
38 class vtkAbstractArray;
39 class vtkAlgorithmInternals;
40 class vtkAlgorithmOutput;
41 class vtkCollection;
42 class vtkDataArray;
43 class vtkDataObject;
44 class vtkExecutive;
45 class vtkInformation;
52 
53 class VTKCOMMONEXECUTIONMODEL_EXPORT VTK_MARSHALMANUAL vtkAlgorithm : public vtkObject
54 {
55 public:
56  static vtkAlgorithm* New();
57  vtkTypeMacro(vtkAlgorithm, vtkObject);
58  void PrintSelf(ostream& os, vtkIndent indent) override;
59 
81  {
84  DEFAULT_PRECISION
85  };
86 
91  vtkTypeBool HasExecutive();
92 
97  vtkExecutive* GetExecutive();
98 
104  virtual void SetExecutive(vtkExecutive* executive);
105 
129  virtual vtkTypeBool ProcessRequest(
130  vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outInfo);
131 
136  vtkTypeBool ProcessRequest(
137  vtkInformation* request, vtkCollection* inInfo, vtkInformationVector* outInfo);
138 
144  virtual int ComputePipelineMTime(vtkInformation* request, vtkInformationVector** inInfoVec,
145  vtkInformationVector* outInfoVec, int requestFromOutputPort, vtkMTimeType* mtime);
146 
154  virtual int ModifyRequest(vtkInformation* request, int when);
155 
162  vtkInformation* GetInputPortInformation(int port);
163 
170  vtkInformation* GetOutputPortInformation(int port);
171 
173 
176  vtkGetObjectMacro(Information, vtkInformation);
177  virtual void SetInformation(vtkInformation*);
179 
183  int GetNumberOfInputPorts();
184 
188  int GetNumberOfOutputPorts();
189 
191 
194  bool UsesGarbageCollector() const override { return true; }
196 
200  void SetAbortExecuteAndUpdateTime();
201 
203 
207  vtkSetMacro(AbortExecute, vtkTypeBool);
208  vtkGetMacro(AbortExecute, vtkTypeBool);
209  vtkBooleanMacro(AbortExecute, vtkTypeBool);
211 
213 
216  vtkGetMacro(Progress, double);
218 
224  void UpdateProgress(double amount);
225 
229  bool CheckAbort();
230 
232 
238  {
239  this->ContainerAlgorithm = containerAlg;
240  }
241  vtkAlgorithm* GetContainerAlgorithm() { return this->ContainerAlgorithm; }
243 
245 
252  vtkSetMacro(AbortOutput, bool);
253  vtkGetMacro(AbortOutput, bool);
254  vtkBooleanMacro(AbortOutput, bool);
256 
258 
270  void SetProgressShiftScale(double shift, double scale);
271  vtkGetMacro(ProgressShift, double);
272  vtkGetMacro(ProgressScale, double);
274 
276 
283  void SetProgressText(const char* ptext);
284  vtkGetStringMacro(ProgressText);
286 
288 
292  vtkGetMacro(ErrorCode, unsigned long);
294 
295  // left public for performance since it is used in inner loops
296  std::atomic<vtkTypeBool> AbortExecute;
297 
302  static vtkInformationIntegerKey* INPUT_IS_OPTIONAL();
306  static vtkInformationIntegerKey* INPUT_IS_REPEATABLE();
310  static vtkInformationInformationVectorKey* INPUT_REQUIRED_FIELDS();
314  static vtkInformationStringVectorKey* INPUT_REQUIRED_DATA_TYPE();
318  static vtkInformationInformationVectorKey* INPUT_ARRAYS_TO_PROCESS();
322  static vtkInformationIntegerKey* INPUT_PORT();
326  static vtkInformationIntegerKey* INPUT_CONNECTION();
327 
336  static vtkInformationIntegerKey* CAN_PRODUCE_SUB_EXTENT();
337 
350  static vtkInformationIntegerKey* CAN_HANDLE_PIECE_REQUEST();
351 
356  static vtkInformationIntegerKey* ABORTED();
357 
359 
376  void SetInputArrayToProcess(
377  const char* name, int fieldAssociation, int component = vtkArrayComponents::AllComponents);
380 
402  virtual void SetInputArrayToProcess(
403  int idx, int port, int connection, int fieldAssociation, const char* name);
418  virtual void SetInputArrayToProcess(
419  int idx, int port, int connection, int fieldAssociation, const char* name, int component);
421 
423 
437  virtual void SetInputArrayToProcess(
438  int idx, int port, int connection, int fieldAssociation, int fieldAttributeType);
454  virtual void SetInputArrayToProcess(
455  int idx, int port, int connection, int fieldAssociation, int fieldAttributeType, int component);
457 
462  virtual void SetInputArrayToProcess(int idx, vtkInformation* info);
463 
465 
495  virtual void SetInputArrayToProcess(int idx, int port, int connection,
496  const char* fieldAssociation, const char* attributeTypeorName);
497  virtual void SetInputArrayToProcess(int idx, int port, int connection,
498  const char* fieldAssociation, const char* attributeTypeorName, const char* component);
500 
504  int GetNumberOfInputArraySpecifications();
505 
516  bool ResetInputArraySpecifications();
517 
521  vtkInformation* GetInputArrayInformation(int idx);
522 
523  // from here down are convenience methods that really are executive methods
524 
528  void RemoveAllInputs();
529 
534  vtkDataObject* GetOutputDataObject(int port);
535 
540  vtkDataObject* GetInputDataObject(int port, int connection);
541 
543 
556  virtual void SetInputConnection(int port, vtkAlgorithmOutput* input);
557  virtual void SetInputConnection(vtkAlgorithmOutput* input);
559 
561 
570  virtual void AddInputConnection(int port, vtkAlgorithmOutput* input);
571  virtual void AddInputConnection(vtkAlgorithmOutput* input);
573 
583  virtual void RemoveInputConnection(int port, vtkAlgorithmOutput* input);
584 
588  virtual void RemoveInputConnection(int port, int idx);
589 
593  virtual void RemoveAllInputConnections(int port);
594 
603  virtual void SetInputDataObject(int port, vtkDataObject* data);
604  virtual void SetInputDataObject(vtkDataObject* data) { this->SetInputDataObject(0, data); }
605 
611  virtual void AddInputDataObject(int port, vtkDataObject* data);
612  virtual void AddInputDataObject(vtkDataObject* data) { this->AddInputDataObject(0, data); }
613 
620  vtkAlgorithmOutput* GetOutputPort(int index);
622 
626  int GetNumberOfInputConnections(int port);
627 
631  int GetTotalNumberOfInputConnections();
632 
636  vtkAlgorithmOutput* GetInputConnection(int port, int index);
637 
642  vtkAlgorithm* GetInputAlgorithm(int port, int index, int& algPort);
643 
647  vtkAlgorithm* GetInputAlgorithm(int port, int index);
648 
653 
658  vtkExecutive* GetInputExecutive(int port, int index);
659 
664 
673  vtkInformation* GetInputInformation(int port, int index);
674 
679 
687  vtkInformation* GetOutputInformation(int port);
688 
690 
694  virtual bool Update(int port);
696  virtual bool Update();
698 
721  virtual vtkTypeBool Update(int port, vtkInformationVector* requests);
722 
728  virtual vtkTypeBool Update(vtkInformation* requests);
729 
736  virtual int UpdatePiece(
737  int piece, int numPieces, int ghostLevels, const int extents[6] = nullptr);
738 
745  virtual int UpdateExtent(const int extents[6]);
746 
754  virtual int UpdateTimeStep(double time, int piece = -1, int numPieces = 1, int ghostLevels = 0,
755  const int extents[6] = nullptr);
756 
761  virtual bool UpdateInformation();
762 
766  virtual bool UpdateDataObject();
767 
771  virtual void PropagateUpdateExtent();
772 
777  virtual bool UpdateWholeExtent();
778 
783  void ConvertTotalInputToPortConnection(int ind, int& port, int& conn);
784 
785  //======================================================================
786  // The following block of code is to support old style VTK applications. If
787  // you are using these calls there are better ways to do it in the new
788  // pipeline
789  //======================================================================
790 
792 
795  virtual void SetReleaseDataFlag(vtkTypeBool);
796  virtual vtkTypeBool GetReleaseDataFlag();
797  void ReleaseDataFlagOn();
798  void ReleaseDataFlagOff();
800 
801  //========================================================================
802 
804 
810  int UpdateExtentIsEmpty(vtkInformation* pinfo, vtkDataObject* output);
811  int UpdateExtentIsEmpty(vtkInformation* pinfo, int extentType);
813 
818  static void SetDefaultExecutivePrototype(vtkExecutive* proto);
819 
821 
826  int* GetUpdateExtent() VTK_SIZEHINT(6) { return this->GetUpdateExtent(0); }
827  int* GetUpdateExtent(int port) VTK_SIZEHINT(6);
828  void GetUpdateExtent(int& x0, int& x1, int& y0, int& y1, int& z0, int& z1)
829  {
830  this->GetUpdateExtent(0, x0, x1, y0, y1, z0, z1);
831  }
832  void GetUpdateExtent(int port, int& x0, int& x1, int& y0, int& y1, int& z0, int& z1);
833  void GetUpdateExtent(int extent[6]) { this->GetUpdateExtent(0, extent); }
834  void GetUpdateExtent(int port, int extent[6]);
836 
838 
843  int GetUpdatePiece() { return this->GetUpdatePiece(0); }
844  int GetUpdatePiece(int port);
846  int GetUpdateNumberOfPieces(int port);
847  int GetUpdateGhostLevel() { return this->GetUpdateGhostLevel(0); }
848  int GetUpdateGhostLevel(int port);
850 
852 
861  void SetProgressObserver(vtkProgressObserver*);
862  vtkGetObjectMacro(ProgressObserver, vtkProgressObserver);
864 
866 
876  void SetNoPriorTemporalAccessInformationKey(int key);
877  void SetNoPriorTemporalAccessInformationKey();
879 
884  void RemoveNoPriorTemporalAccessInformationKey();
885 
886 protected:
887  vtkAlgorithm();
888  ~vtkAlgorithm() override;
889 
890  // Time stamp to store the last time any filter was aborted.
892 
893  // Time stamp to store the last time this filter checked for an
894  // abort.
896 
897  // Keys used to indicate that input/output port information has been
898  // filled.
899  static vtkInformationIntegerKey* PORT_REQUIREMENTS_FILLED();
900 
901  // Arbitrary extra information associated with this algorithm
903 
908  bool CheckUpstreamAbort();
909 
915  virtual int FillInputPortInformation(int port, vtkInformation* info);
916 
922  virtual int FillOutputPortInformation(int port, vtkInformation* info);
923 
927  virtual void SetNumberOfInputPorts(int n);
928 
932  virtual void SetNumberOfOutputPorts(int n);
933 
934  // Helper methods to check input/output port index ranges.
935  int InputPortIndexInRange(int index, const char* action);
936  int OutputPortIndexInRange(int index, const char* action);
937 
942  int GetInputArrayAssociation(int idx, vtkInformationVector** inputVector);
943 
945 
953  int GetInputArrayAssociation(int idx, int connection, vtkInformationVector** inputVector);
954  int GetInputArrayAssociation(int idx, vtkDataObject* input);
956 
976  int GetInputArrayComponent(int idx);
977 
979 
983  vtkDataArray* GetInputArrayToProcess(int idx, vtkInformationVector** inputVector);
984  vtkDataArray* GetInputArrayToProcess(
985  int idx, vtkInformationVector** inputVector, int& association);
987 
989 
997  vtkDataArray* GetInputArrayToProcess(int idx, int connection, vtkInformationVector** inputVector);
998  vtkDataArray* GetInputArrayToProcess(
999  int idx, int connection, vtkInformationVector** inputVector, int& association);
1000  vtkDataArray* GetInputArrayToProcess(int idx, vtkDataObject* input);
1001  vtkDataArray* GetInputArrayToProcess(int idx, vtkDataObject* input, int& association);
1003 
1005 
1009  vtkAbstractArray* GetInputAbstractArrayToProcess(int idx, vtkInformationVector** inputVector);
1010  vtkAbstractArray* GetInputAbstractArrayToProcess(
1011  int idx, vtkInformationVector** inputVector, int& association);
1013 
1015 
1023  vtkAbstractArray* GetInputAbstractArrayToProcess(
1024  int idx, int connection, vtkInformationVector** inputVector);
1025  vtkAbstractArray* GetInputAbstractArrayToProcess(
1026  int idx, int connection, vtkInformationVector** inputVector, int& association);
1027  vtkAbstractArray* GetInputAbstractArrayToProcess(int idx, vtkDataObject* input);
1028  vtkAbstractArray* GetInputAbstractArrayToProcess(int idx, vtkDataObject* input, int& association);
1030 
1032 
1061  vtkSmartPointer<vtkAbstractArray> GetInputArray(int idx, int connection,
1062  vtkInformationVector** inputVector, int& association,
1063  int requestedComponent = vtkArrayComponents::Requested);
1064  vtkSmartPointer<vtkAbstractArray> GetInputArray(int idx, vtkDataObject* input, int& association,
1065  int requestedComponent = vtkArrayComponents::Requested);
1066  template <typename ArrayType, typename... Params>
1068  {
1069  auto abstractArray = this->GetInputArray(std::forward<Params>(params)...);
1070  auto* castArray = ArrayType::SafeDownCast(abstractArray.GetPointer());
1071  auto result = vtkSmartPointer<ArrayType>(castArray);
1072  return result;
1073  }
1075 
1083  vtkInformation* GetInputArrayFieldInformation(int idx, vtkInformationVector** inputVector);
1084 
1091  virtual vtkExecutive* CreateDefaultExecutive();
1092 
1094 
1098  vtkSetMacro(ErrorCode, unsigned long);
1099  unsigned long ErrorCode;
1101 
1102  // Progress/Update handling
1103  double Progress;
1105 
1106  // Garbage collection support.
1107  void ReportReferences(vtkGarbageCollector*) override;
1108 
1109  // executive methods below
1110 
1117  virtual void SetNthInputConnection(int port, int index, vtkAlgorithmOutput* input);
1118 
1125  virtual void SetNumberOfInputConnections(int port, int n);
1126 
1128 
1136  {
1137  this->SetInputDataObject(port, input);
1138  }
1140  {
1141  this->AddInputDataObject(port, input);
1142  }
1143 
1145 
1146 private:
1147  vtkExecutive* Executive;
1148  vtkInformationVector* InputPortInformation;
1149  vtkInformationVector* OutputPortInformation;
1150  vtkAlgorithmInternals* AlgorithmInternal;
1151  static void ConnectionAdd(
1152  vtkAlgorithm* producer, int producerPort, vtkAlgorithm* consumer, int consumerPort);
1153  static void ConnectionRemove(
1154  vtkAlgorithm* producer, int producerPort, vtkAlgorithm* consumer, int consumerPort);
1155  static void ConnectionRemoveAllInput(vtkAlgorithm* consumer, int port);
1156  static void ConnectionRemoveAllOutput(vtkAlgorithm* producer, int port);
1157 
1158  vtkAlgorithm(const vtkAlgorithm&) = delete;
1159  void operator=(const vtkAlgorithm&) = delete;
1160 
1161  double ProgressShift;
1162  double ProgressScale;
1163  vtkAlgorithm* ContainerAlgorithm;
1164  bool AbortOutput;
1165 };
1166 
1167 VTK_ABI_NAMESPACE_END
1168 #endif
vtkAlgorithmOutput * GetOutputPort()
Definition: vtkAlgorithm.h:621
vtkAlgorithm * GetContainerAlgorithm()
Set/get a Container algorithm for this algorithm.
Definition: vtkAlgorithm.h:241
abstract base class for most VTK objects
Definition: vtkObject.h:52
DesiredOutputPrecision
Values used for setting the desired output precision for various algorithms.
Definition: vtkAlgorithm.h:80
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:833
int GetUpdatePiece()
These functions return the update extent for output ports that use piece extents. ...
Definition: vtkAlgorithm.h:843
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
static vtkTimeStamp LastAbortTime
Definition: vtkAlgorithm.h:891
int * GetUpdateExtent()
These functions return the update extent for output ports that use 3D extents.
Definition: vtkAlgorithm.h:826
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:652
#define VTK_UNBLOCKTHREADS
vtkInformation * GetInputInformation()
Equivalent to GetInputInformation(0, 0)
Definition: vtkAlgorithm.h:678
virtual void AddInputDataObject(vtkDataObject *data)
Definition: vtkAlgorithm.h:612
Superclass for all pipeline executives in VTK.
Definition: vtkExecutive.h:39
void SetInputDataInternal(int port, vtkDataObject *input)
These methods are used by subclasses to implement methods to set data objects directly as input...
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)
Superclass for all sources, filters, and sinks in VTK.
Definition: vtkAlgorithm.h:53
vtkInformation * Information
Definition: vtkAlgorithm.h:902
#define VTK_MARSHALMANUAL
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:845
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
#define VTK_SIZEHINT(...)
Key for String vector values.
#define vtkAlgorithm
char * ProgressText
void SetContainerAlgorithm(vtkAlgorithm *containerAlg)
Set/get a Container algorithm for this algorithm.
Definition: vtkAlgorithm.h:237
virtual void SetInputDataObject(vtkDataObject *data)
Definition: vtkAlgorithm.h:604
unsigned long ErrorCode
The error code contains a possible error that occurred while reading or writing the file...
create and manipulate ordered lists of objects
Definition: vtkCollection.h:39
int GetUpdateGhostLevel()
These functions return the update extent for output ports that use piece extents. ...
Definition: vtkAlgorithm.h:847
vtkTimeStamp LastAbortCheckTime
Definition: vtkAlgorithm.h:895
bool UsesGarbageCollector() const override
Participate in garbage collection.
Definition: vtkAlgorithm.h:194
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
general representation of visualization data
Definition: vtkDataObject.h:55
vtkExecutive * GetInputExecutive()
Equivalent to GetInputExecutive(0, 0)
Definition: vtkAlgorithm.h:663
vtkSmartPointer< ArrayType > GetInputArrayAs(Params &&...params)
Get an array from the input at index idx.
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:828
Basic class to optionally replace vtkAlgorithm progress functionality.
static vtkExecutive * DefaultExecutivePrototype
std::atomic< vtkTypeBool > AbortExecute
Definition: vtkAlgorithm.h:292