VTK  9.3.0
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
76 #ifndef vtkGaussianSplatter_h
77 #define vtkGaussianSplatter_h
78 
79 #include "vtkImageAlgorithm.h"
80 #include "vtkImagingHybridModule.h" // For export macro
81 
82 #include <cmath> // for std::exp
83 
84 #define VTK_ACCUMULATION_MODE_MIN 0
85 #define VTK_ACCUMULATION_MODE_MAX 1
86 #define VTK_ACCUMULATION_MODE_SUM 2
87 
88 VTK_ABI_NAMESPACE_BEGIN
89 class vtkDoubleArray;
91 class vtkGaussianSplatterAlgorithm;
92 
93 class VTKIMAGINGHYBRID_EXPORT vtkGaussianSplatter : public vtkImageAlgorithm
94 {
95 public:
97  void PrintSelf(ostream& os, vtkIndent indent) override;
98 
105 
107 
111  void SetSampleDimensions(int i, int j, int k);
112  void SetSampleDimensions(int dim[3]);
113  vtkGetVectorMacro(SampleDimensions, int, 3);
115 
117 
123  vtkSetVector6Macro(ModelBounds, double);
124  vtkGetVectorMacro(ModelBounds, double, 6);
126 
128 
133  vtkSetClampMacro(Radius, double, 0.0, 1.0);
134  vtkGetMacro(Radius, double);
136 
138 
143  vtkSetClampMacro(ScaleFactor, double, 0.0, VTK_DOUBLE_MAX);
144  vtkGetMacro(ScaleFactor, double);
146 
148 
153  vtkSetMacro(ExponentFactor, double);
154  vtkGetMacro(ExponentFactor, double);
156 
158 
163  vtkSetMacro(NormalWarping, vtkTypeBool);
164  vtkGetMacro(NormalWarping, vtkTypeBool);
165  vtkBooleanMacro(NormalWarping, vtkTypeBool);
167 
169 
176  vtkSetClampMacro(Eccentricity, double, 0.001, VTK_DOUBLE_MAX);
177  vtkGetMacro(Eccentricity, double);
179 
181 
184  vtkSetMacro(ScalarWarping, vtkTypeBool);
185  vtkGetMacro(ScalarWarping, vtkTypeBool);
186  vtkBooleanMacro(ScalarWarping, vtkTypeBool);
188 
190 
195  vtkSetMacro(Capping, vtkTypeBool);
196  vtkGetMacro(Capping, vtkTypeBool);
197  vtkBooleanMacro(Capping, vtkTypeBool);
199 
201 
205  vtkSetMacro(CapValue, double);
206  vtkGetMacro(CapValue, double);
208 
210 
216  vtkSetClampMacro(AccumulationMode, int, VTK_ACCUMULATION_MODE_MIN, VTK_ACCUMULATION_MODE_SUM);
217  vtkGetMacro(AccumulationMode, int);
218  void SetAccumulationModeToMin() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_MIN); }
219  void SetAccumulationModeToMax() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_MAX); }
220  void SetAccumulationModeToSum() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_SUM); }
223 
225 
229  vtkSetMacro(NullValue, double);
230  vtkGetMacro(NullValue, double);
232 
234 
238  void ComputeModelBounds(vtkDataSet* input, vtkImageData* output, vtkInformation* outInfo);
240  vtkCompositeDataSet* input, vtkImageData* output, vtkInformation* outInfo);
242 
244 
249  friend class vtkGaussianSplatterAlgorithm;
250  double SamplePoint(double x[3]) // for compilers who can't handle this
251  {
252  return (this->*Sample)(x);
253  }
254  void SetScalar(vtkIdType idx, double dist2, double* sPtr)
255  {
256  double v = (this->*SampleFactor)(this->S) *
257  std::exp(static_cast<double>(this->ExponentFactor * (dist2) / (this->Radius2)));
259 
260  if (!this->Visited[idx])
261  {
262  this->Visited[idx] = 1;
263  *sPtr = v;
264  }
265  else
266  {
267  switch (this->AccumulationMode)
268  {
270  if (*sPtr > v)
271  {
272  *sPtr = v;
273  }
274  break;
276  if (*sPtr < v)
277  {
278  *sPtr = v;
279  }
280  break;
282  *sPtr += v;
283  break;
284  }
285  } // not first visit
286  }
287 
288 protected:
290  ~vtkGaussianSplatter() override = default;
291 
295  void Cap(vtkDoubleArray* s);
296 
297  int SampleDimensions[3]; // dimensions of volume to splat into
298  double Radius; // maximum distance splat propagates (as fraction 0->1)
299  double ExponentFactor; // scale exponent of gaussian function
300  double ModelBounds[6]; // bounding box of splatting dimensions
301  vtkTypeBool NormalWarping; // on/off warping of splat via normal
302  double Eccentricity; // elliptic distortion due to normals
303  vtkTypeBool ScalarWarping; // on/off warping of splat via scalar
304  double ScaleFactor; // splat size influenced by scale factor
305  vtkTypeBool Capping; // Cap side of volume to close surfaces
306  double CapValue; // value to use for capping
307  int AccumulationMode; // how to combine scalar values
308 
309  double Gaussian(double x[3]);
310  double EccentricGaussian(double x[3]);
311  double ScalarSampling(double s) { return this->ScaleFactor * s; }
312  double PositionSampling(double) { return this->ScaleFactor; }
313 
314 private:
315  double Radius2;
316  double (vtkGaussianSplatter::*Sample)(double x[3]);
317  double (vtkGaussianSplatter::*SampleFactor)(double s);
318  char* Visited;
319  double Eccentricity2;
320  double* P;
321  double* N;
322  double S;
323  double Origin[3];
324  double Spacing[3];
325  double SplatDistance[3];
326  double NullValue;
327 
328  vtkGaussianSplatter(const vtkGaussianSplatter&) = delete;
329  void operator=(const vtkGaussianSplatter&) = delete;
330 };
331 
332 VTK_ABI_NAMESPACE_END
333 #endif
abstract superclass for composite (multi-block or AMR) datasets
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
dynamic, self-adjusting array of double
splat points into a volume with an elliptical, Gaussian distribution
static vtkGaussianSplatter * New()
Construct object with dimensions=(50,50,50); automatic computation of bounds; a splat radius of 0....
double EccentricGaussian(double x[3])
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
double SamplePoint(double x[3])
Provide access to templated helper class.
double PositionSampling(double)
const char * GetAccumulationModeAsString()
Specify the scalar accumulation mode.
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Subclasses can reimplement this method to collect information from their inputs and set information f...
void SetAccumulationModeToSum()
Specify the scalar accumulation mode.
void Cap(vtkDoubleArray *s)
int FillInputPortInformation(int port, vtkInformation *info) override
These method should be reimplemented by subclasses that have more than a single input or single outpu...
double ScalarSampling(double s)
void SetAccumulationModeToMax()
Specify the scalar accumulation mode.
void ComputeModelBounds(vtkDataSet *input, vtkImageData *output, vtkInformation *outInfo)
Compute the size of the sample bounding box automatically from the input data.
void ComputeModelBounds(vtkCompositeDataSet *input, vtkImageData *output, vtkInformation *outInfo)
Compute the size of the sample bounding box automatically from the input data.
~vtkGaussianSplatter() override=default
double Gaussian(double x[3])
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called in response to a REQUEST_DATA request from the executive.
void SetScalar(vtkIdType idx, double dist2, double *sPtr)
Provide access to templated helper class.
void SetSampleDimensions(int dim[3])
Set / get the dimensions of the sampling structured point set.
void SetAccumulationModeToMin()
Specify the scalar accumulation mode.
void SetSampleDimensions(int i, int j, int k)
Set / get the dimensions of the sampling structured point set.
Generic algorithm superclass for image algs.
topologically and geometrically regular array of data
Definition: vtkImageData.h:52
a simple class to control print indentation
Definition: vtkIndent.h:38
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
@ info
Definition: vtkX3D.h:376
@ port
Definition: vtkX3D.h:447
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_ACCUMULATION_MODE_SUM
#define VTK_ACCUMULATION_MODE_MIN
#define VTK_ACCUMULATION_MODE_MAX
int vtkIdType
Definition: vtkType.h:315
#define VTK_DOUBLE_MAX
Definition: vtkType.h:154