VTK  9.5.20250812
vtkONNXInference.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
18#ifndef vtkONNXInference_h
19#define vtkONNXInference_h
20
21#include "vtkFiltersONNXModule.h" // For export macro
23
24#include <memory> // For std::unique_ptr
25#include <vector> // For std::vector
26
27VTK_ABI_NAMESPACE_BEGIN
29namespace Ort
30{
31class AllocatorWithDefaultOptions;
32class Value;
33}
34
35class VTKFILTERSONNX_EXPORT vtkONNXInference : public vtkUnstructuredGridAlgorithm
36{
37public:
39 void PrintSelf(ostream& os, vtkIndent indent) override;
40
42
44
47 void SetModelFile(const std::string& file);
48 vtkGetMacro(ModelFile, std::string);
50
54 void SetTimeStepValue(vtkIdType idx, double timeStepValue);
55
61
67
71 void SetInputParameter(vtkIdType idx, float InputParameter);
72
78
82 vtkGetMacro(InputSize, int);
83
89
91
95 vtkSetMacro(TimeStepIndex, int);
96 vtkGetMacro(TimeStepIndex, int);
98
100
103 vtkSetMacro(OutputDimension, int);
104 vtkGetMacro(OutputDimension, int);
106
108
112 vtkSetMacro(OnCellData, bool);
113 vtkGetMacro(OnCellData, bool);
115
116protected:
118 ~vtkONNXInference() override = default;
119
124
126
127private:
128 vtkONNXInference(const vtkONNXInference&) = delete;
129 void operator=(const vtkONNXInference&) = delete;
130
135 void InitializeSession();
136
141 std::vector<Ort::Value> RunModel(Ort::Value& inputTensor);
142
143 // Input related parameters
144 std::string ModelFile;
145 int64_t InputSize = 0;
146 std::vector<float> InputParameters;
147 std::vector<double> TimeStepValues;
148 int TimeStepIndex = -1;
149
150 // Output related parameters
151 int OutputDimension = 1;
152 bool OnCellData = true;
153
154 bool Initialized = false;
155 std::unique_ptr<vtkONNXInferenceInternals> Internals;
156};
157VTK_ABI_NAMESPACE_END
158
159#endif // vtkONNXInference_h
a simple class to control print indentation
Definition vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Infer an ONNX model.
void ClearInputParameters()
Clear the input parameters vector.
void ClearTimeStepValues()
Clear the time step values vector.
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is required to inform the pipeline of the time steps.
~vtkONNXInference() override=default
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
void SetInputParameter(vtkIdType idx, float InputParameter)
Set an input parameter at a given index.
static vtkONNXInference * New()
void SetTimeStepValue(vtkIdType idx, double timeStepValue)
Set a time value at a given index.
void SetModelFile(const std::string &file)
Get/Set the path to the ONNX model and load it.
void SetNumberOfInputParameters(vtkIdType nb)
Set the number of input parameters.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetNumberOfTimeStepValues(vtkIdType nb)
Set the number of time step values.
Superclass for algorithms that produce only unstructured grid as output.
VTK internal class for hiding ONNX members.
int vtkIdType
Definition vtkType.h:332