VTK  9.7.1
vtkGaussianSplatter.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
67 #ifndef vtkGaussianSplatter_h
68 #define vtkGaussianSplatter_h
69 
70 #include "vtkImageAlgorithm.h"
71 #include "vtkImagingHybridModule.h" // For export macro
72 
73 #include <algorithm> // std::min, std::max
74 #include <cmath> // for std::exp
75 
76 #define VTK_ACCUMULATION_MODE_MIN 0
77 #define VTK_ACCUMULATION_MODE_MAX 1
78 #define VTK_ACCUMULATION_MODE_SUM 2
79 
80 VTK_ABI_NAMESPACE_BEGIN
81 class vtkDoubleArray;
83 class vtkGaussianSplatterAlgorithm;
84 
85 class VTKIMAGINGHYBRID_EXPORT vtkGaussianSplatter : public vtkImageAlgorithm
86 {
87 public:
89  void PrintSelf(ostream& os, vtkIndent indent) override;
90 
96  static vtkGaussianSplatter* New();
97 
99 
103  void SetSampleDimensions(int i, int j, int k);
104  void SetSampleDimensions(int dim[3]);
105  vtkGetVectorMacro(SampleDimensions, int, 3);
107 
109 
115  vtkSetVector6Macro(ModelBounds, double);
116  vtkGetVectorMacro(ModelBounds, double, 6);
118 
120 
125  vtkSetClampMacro(Radius, double, 0.0, 1.0);
126  vtkGetMacro(Radius, double);
128 
130 
135  vtkSetClampMacro(ScaleFactor, double, 0.0, VTK_DOUBLE_MAX);
136  vtkGetMacro(ScaleFactor, double);
138 
140 
145  vtkSetMacro(ExponentFactor, double);
146  vtkGetMacro(ExponentFactor, double);
148 
150 
155  vtkSetMacro(NormalWarping, vtkTypeBool);
156  vtkGetMacro(NormalWarping, vtkTypeBool);
157  vtkBooleanMacro(NormalWarping, vtkTypeBool);
159 
161 
168  vtkSetClampMacro(Eccentricity, double, 0.001, VTK_DOUBLE_MAX);
169  vtkGetMacro(Eccentricity, double);
171 
173 
176  vtkSetMacro(ScalarWarping, vtkTypeBool);
177  vtkGetMacro(ScalarWarping, vtkTypeBool);
178  vtkBooleanMacro(ScalarWarping, vtkTypeBool);
180 
182 
187  vtkSetMacro(Capping, vtkTypeBool);
188  vtkGetMacro(Capping, vtkTypeBool);
189  vtkBooleanMacro(Capping, vtkTypeBool);
191 
193 
197  vtkSetMacro(CapValue, double);
198  vtkGetMacro(CapValue, double);
200 
202 
208  vtkSetClampMacro(AccumulationMode, int, VTK_ACCUMULATION_MODE_MIN, VTK_ACCUMULATION_MODE_SUM);
209  vtkGetMacro(AccumulationMode, int);
210  void SetAccumulationModeToMin() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_MIN); }
211  void SetAccumulationModeToMax() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_MAX); }
212  void SetAccumulationModeToSum() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_SUM); }
213  const char* GetAccumulationModeAsString();
215 
217 
221  vtkSetMacro(NullValue, double);
222  vtkGetMacro(NullValue, double);
224 
226 
230  void ComputeModelBounds(vtkDataSet* input, vtkImageData* output, vtkInformation* outInfo);
231  void ComputeModelBounds(
232  vtkCompositeDataSet* input, vtkImageData* output, vtkInformation* outInfo);
234 
236 
241  friend class vtkGaussianSplatterAlgorithm;
242  double SamplePoint(double x[3]) // for compilers who can't handle this
243  {
244  return (this->*Sample)(x);
245  }
246  void SetScalar(vtkIdType idx, double dist2, double* sPtr)
247  {
248  double v =
249  (this->*SampleFactor)(this->S) * std::exp(this->ExponentFactor * (dist2) / (this->Radius2));
250 
251  if (!this->Visited[idx])
252  {
253  this->Visited[idx] = 1;
254  *sPtr = v;
255  }
256  else
257  {
258  switch (this->AccumulationMode)
259  {
261  *sPtr = std::min(*sPtr, v);
262  break;
264  *sPtr = std::max(*sPtr, v);
265  break;
267  *sPtr += v;
268  break;
269  }
270  } // not first visit
271  }
273 
274 protected:
276  ~vtkGaussianSplatter() override = default;
277 
278  int FillInputPortInformation(int port, vtkInformation* info) override;
281  void Cap(vtkDoubleArray* s);
282 
283  int SampleDimensions[3]; // dimensions of volume to splat into
284  double Radius; // maximum distance splat propagates (as fraction 0->1)
285  double ExponentFactor; // scale exponent of gaussian function
286  double ModelBounds[6]; // bounding box of splatting dimensions
287  vtkTypeBool NormalWarping; // on/off warping of splat via normal
288  double Eccentricity; // elliptic distortion due to normals
289  vtkTypeBool ScalarWarping; // on/off warping of splat via scalar
290  double ScaleFactor; // splat size influenced by scale factor
291  vtkTypeBool Capping; // Cap side of volume to close surfaces
292  double CapValue; // value to use for capping
293  int AccumulationMode; // how to combine scalar values
294 
295  double Gaussian(double x[3]);
296  double EccentricGaussian(double x[3]);
297  double ScalarSampling(double s) { return this->ScaleFactor * s; }
298  double PositionSampling(double) { return this->ScaleFactor; }
299 
300 private:
301  double Radius2;
302  double (vtkGaussianSplatter::*Sample)(double x[3]);
303  double (vtkGaussianSplatter::*SampleFactor)(double s);
304  char* Visited;
305  double Eccentricity2;
306  double* P;
307  double* N;
308  double S;
309  double Origin[3];
310  double Spacing[3];
311  double SplatDistance[3];
312  double NullValue;
313 
314  vtkGaussianSplatter(const vtkGaussianSplatter&) = delete;
315  void operator=(const vtkGaussianSplatter&) = delete;
316 };
317 
318 VTK_ABI_NAMESPACE_END
319 #endif
void SetAccumulationModeToMin()
Specify the scalar accumulation mode.
#define VTK_DOUBLE_MAX
Definition: vtkType.h:202
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
#define VTK_ACCUMULATION_MODE_MAX
int vtkIdType
Definition: vtkType.h:363
void SetAccumulationModeToMax()
Specify the scalar accumulation mode.
splat points into a volume with an elliptical, Gaussian distribution
dynamic, self-adjusting array of double
int vtkTypeBool
Definition: vtkABI.h:64
abstract superclass for composite (multi-block or AMR) datasets
a simple class to control print indentation
Definition: vtkIndent.h:28
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
Subclasses can reimplement this method to collect information from their inputs and set information f...
double PositionSampling(double)
#define VTK_ACCUMULATION_MODE_SUM
void SetAccumulationModeToSum()
Specify the scalar accumulation mode.
void SetScalar(vtkIdType idx, double dist2, double *sPtr)
Provide access to templated helper class.
#define VTK_ACCUMULATION_MODE_MIN
double SamplePoint(double x[3])
Provide access to templated helper class.
int FillInputPortInformation(int port, vtkInformation *info) override
These method should be reimplemented by subclasses that have more than a single input or single outpu...
Generic algorithm superclass for image algs.
Store zero or more vtkInformation instances.
static vtkAlgorithm * New()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called in response to a REQUEST_DATA request from the executive.
#define max(a, b)
double ScalarSampling(double s)