File: vtkImageMathematics.h

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-7
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 206,000 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 181; javascript: 165; objc: 153; tcl: 59
file content (269 lines) | stat: -rw-r--r-- 8,355 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
 * @class   vtkImageMathematics
 * @brief   Add, subtract, multiply, divide, invert, sin,
 * cos, exp, log.
 *
 * vtkImageMathematics implements basic mathematic operations SetOperation is
 * used to select the filters behavior.  The filter can take two or one
 * input.
 */

#ifndef vtkImageMathematics_h
#define vtkImageMathematics_h

// Operation options.
#define VTK_ADD 0
#define VTK_SUBTRACT 1
#define VTK_MULTIPLY 2
#define VTK_DIVIDE 3
#define VTK_INVERT 4
#define VTK_SIN 5
#define VTK_COS 6
#define VTK_EXP 7
#define VTK_LOG 8
#define VTK_ABS 9
#define VTK_SQR 10
#define VTK_SQRT 11
#define VTK_MIN 12
#define VTK_MAX 13
#define VTK_ATAN 14
#define VTK_ATAN2 15
#define VTK_MULTIPLYBYK 16
#define VTK_ADDC 17
#define VTK_CONJUGATE 18
#define VTK_COMPLEX_MULTIPLY 19
#define VTK_REPLACECBYK 20

#include "vtkImagingMathModule.h" // For export macro
#include "vtkThreadedImageAlgorithm.h"

VTK_ABI_NAMESPACE_BEGIN
class VTKIMAGINGMATH_EXPORT vtkImageMathematics : public vtkThreadedImageAlgorithm
{
public:
  static vtkImageMathematics* New();
  vtkTypeMacro(vtkImageMathematics, vtkThreadedImageAlgorithm);
  void PrintSelf(ostream& os, vtkIndent indent) override;

  ///@{
  /**
   * Set/Get the Operation to perform.
   */
  vtkSetMacro(Operation, int);
  vtkGetMacro(Operation, int);
  ///@}

  /**
   * Set each pixel in the output image to the sum of the corresponding pixels
   * in Input1 and Input2.
   */
  void SetOperationToAdd() { this->SetOperation(VTK_ADD); }

  /**
   * Set each pixel in the output image to the difference of the corresponding pixels
   * in Input1 and Input2 (output = Input1 - Input2).
   */
  void SetOperationToSubtract() { this->SetOperation(VTK_SUBTRACT); }

  /**
   * Set each pixel in the output image to the product of the corresponding pixels
   * in Input1 and Input2.
   */
  void SetOperationToMultiply() { this->SetOperation(VTK_MULTIPLY); }

  /**
   * Set each pixel in the output image to the quotient of the corresponding pixels
   * in Input1 and Input2 (Output = Input1 / Input2).
   */
  void SetOperationToDivide() { this->SetOperation(VTK_DIVIDE); }

  void SetOperationToConjugate() { this->SetOperation(VTK_CONJUGATE); }

  void SetOperationToComplexMultiply() { this->SetOperation(VTK_COMPLEX_MULTIPLY); }

  /**
   * Set each pixel in the output image to 1 over the corresponding pixel
   * in Input1 and Input2 (output = 1 / Input1). Input2 is not used.
   */
  void SetOperationToInvert() { this->SetOperation(VTK_INVERT); }

  /**
   * Set each pixel in the output image to the sine of the corresponding pixel
   * in Input1. Input2 is not used.
   */
  void SetOperationToSin() { this->SetOperation(VTK_SIN); }

  /**
   * Set each pixel in the output image to the cosine of the corresponding pixel
   * in Input1. Input2 is not used.
   */
  void SetOperationToCos() { this->SetOperation(VTK_COS); }

  /**
   * Set each pixel in the output image to the exponential of the corresponding pixel
   * in Input1. Input2 is not used.
   */
  void SetOperationToExp() { this->SetOperation(VTK_EXP); }

  /**
   * Set each pixel in the output image to the log of the corresponding pixel
   * in Input1. Input2 is not used.
   */
  void SetOperationToLog() { this->SetOperation(VTK_LOG); }

  /**
   * Set each pixel in the output image to the absolute value of the corresponding pixel
   * in Input1. Input2 is not used.
   */
  void SetOperationToAbsoluteValue() { this->SetOperation(VTK_ABS); }

  /**
   * Set each pixel in the output image to the square of the corresponding pixel
   * in Input1. Input2 is not used.
   */
  void SetOperationToSquare() { this->SetOperation(VTK_SQR); }

  /**
   * Set each pixel in the output image to the square root of the corresponding pixel
   * in Input1. Input2 is not used.
   */
  void SetOperationToSquareRoot() { this->SetOperation(VTK_SQRT); }

  /**
   * Set each pixel in the output image to the minimum of the corresponding pixels
   * in Input1 and Input2. (Output = min(Input1, Input2))
   */
  void SetOperationToMin() { this->SetOperation(VTK_MIN); }

  /**
   * Set each pixel in the output image to the maximum of the corresponding pixels
   * in Input1 and Input2. (Output = max(Input1, Input2))
   */
  void SetOperationToMax() { this->SetOperation(VTK_MAX); }

  /**
   * Set each pixel in the output image to the arctangent of the corresponding pixel
   * in Input1. Input2 is not used.
   */
  void SetOperationToATAN() { this->SetOperation(VTK_ATAN); }

  void SetOperationToATAN2() { this->SetOperation(VTK_ATAN2); }

  /**
   * Set each pixel in the output image to the product of ConstantK with the
   * corresponding pixel in Input1. Input2 is not used.
   */
  void SetOperationToMultiplyByK() { this->SetOperation(VTK_MULTIPLYBYK); }

  /**
   * Set each pixel in the output image to the product of ConstantC with the
   * corresponding pixel in Input1. Input2 is not used.
   */
  void SetOperationToAddConstant() { this->SetOperation(VTK_ADDC); }

  /**
   * Find every pixel in Input1 that equals ConstantC and set the corresponding pixels
   * in the Output to ConstantK. Input2 is not used.
   */
  void SetOperationToReplaceCByK() { this->SetOperation(VTK_REPLACECBYK); }

  ///@{
  /**
   * A constant used by some operations (typically multiplicative). Default is 1.
   */
  vtkSetMacro(ConstantK, double);
  vtkGetMacro(ConstantK, double);
  ///@}

  ///@{
  /**
   * A constant used by some operations (typically additive). Default is 0.
   */
  vtkSetMacro(ConstantC, double);
  vtkGetMacro(ConstantC, double);
  ///@}

  ///@{
  /**
   * How to handle divide by zero. Default is 0.
   */
  vtkSetMacro(DivideByZeroToC, vtkTypeBool);
  vtkGetMacro(DivideByZeroToC, vtkTypeBool);
  vtkBooleanMacro(DivideByZeroToC, vtkTypeBool);
  ///@}

  ///@{
  /**
   * Set the inputs to this filter. For some operations, the second input
   * is not used.
   */
  virtual void SetInput1Data(vtkDataObject* in) { this->SetInputData(0, in); }
  virtual void SetInput2Data(vtkDataObject* in) { this->AddInputData(0, in); }
  void SetInputConnection(int idx, vtkAlgorithmOutput* input) override;
  void SetInputConnection(vtkAlgorithmOutput* input) override
  {
    this->SetInputConnection(0, input);
  }
  ///@}

  /**
   * Replace one of the input connections with a new input.  You can
   * only replace input connections that you previously created with
   * AddInputConnection() or, in the case of the first input,
   * with SetInputConnection().
   */
  virtual void ReplaceNthInputConnection(int idx, vtkAlgorithmOutput* input);

  ///@{
  /**
   * Assign a data object as input. Note that this method does not
   * establish a pipeline connection. Use SetInputConnection() to
   * setup a pipeline connection.
   */
  void SetInputData(int idx, vtkDataObject* input);
  void SetInputData(vtkDataObject* input) { this->SetInputData(0, input); }
  ///@}

  ///@{
  /**
   * Get one input to this filter. This method is only for support of
   * old-style pipeline connections.  When writing new code you should
   * use vtkAlgorithm::GetInputConnection(0, num).
   */
  vtkDataObject* GetInput(int idx);
  vtkDataObject* GetInput() { return this->GetInput(0); }
  ///@}

  /**
   * Get the number of inputs to this filter. This method is only for
   * support of old-style pipeline connections.  When writing new code
   * you should use vtkAlgorithm::GetNumberOfInputConnections(0).
   */
  int GetNumberOfInputs() { return this->GetNumberOfInputConnections(0); }

protected:
  vtkImageMathematics();
  ~vtkImageMathematics() override = default;

  int Operation;
  double ConstantK;
  double ConstantC;
  vtkTypeBool DivideByZeroToC;

  int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;

  void ThreadedRequestData(vtkInformation* request, vtkInformationVector** inputVector,
    vtkInformationVector* outputVector, vtkImageData*** inData, vtkImageData** outData,
    int outExt[6], int threadId) override;

  int FillInputPortInformation(int port, vtkInformation* info) override;

private:
  vtkImageMathematics(const vtkImageMathematics&) = delete;
  void operator=(const vtkImageMathematics&) = delete;
};

VTK_ABI_NAMESPACE_END
#endif