VTK  9.3.20240418
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
136 #ifndef vtkGaussianSplatter_h
137 #define vtkGaussianSplatter_h
138 
139 #include "vtkImageAlgorithm.h"
140 #include "vtkImagingHybridModule.h" // For export macro
141 
142 #include <cmath> // for std::exp
143 
144 #define VTK_ACCUMULATION_MODE_MIN 0
145 #define VTK_ACCUMULATION_MODE_MAX 1
146 #define VTK_ACCUMULATION_MODE_SUM 2
147 
148 VTK_ABI_NAMESPACE_BEGIN
149 class vtkDoubleArray;
150 class vtkCompositeDataSet;
151 class vtkGaussianSplatterAlgorithm;
152 
153 class VTKIMAGINGHYBRID_EXPORT vtkGaussianSplatter : public vtkImageAlgorithm
154 {
155 public:
157  void PrintSelf(ostream& os, vtkIndent indent) override;
158 
165 
167 
171  void SetSampleDimensions(int i, int j, int k);
172  void SetSampleDimensions(int dim[3]);
173  vtkGetVectorMacro(SampleDimensions, int, 3);
175 
177 
183  vtkSetVector6Macro(ModelBounds, double);
184  vtkGetVectorMacro(ModelBounds, double, 6);
186 
188 
193  vtkSetClampMacro(Radius, double, 0.0, 1.0);
194  vtkGetMacro(Radius, double);
196 
198 
203  vtkSetClampMacro(ScaleFactor, double, 0.0, VTK_DOUBLE_MAX);
204  vtkGetMacro(ScaleFactor, double);
206 
208 
213  vtkSetMacro(ExponentFactor, double);
214  vtkGetMacro(ExponentFactor, double);
216 
218 
223  vtkSetMacro(NormalWarping, vtkTypeBool);
224  vtkGetMacro(NormalWarping, vtkTypeBool);
225  vtkBooleanMacro(NormalWarping, vtkTypeBool);
227 
229 
236  vtkSetClampMacro(Eccentricity, double, 0.001, VTK_DOUBLE_MAX);
237  vtkGetMacro(Eccentricity, double);
239 
241 
244  vtkSetMacro(ScalarWarping, vtkTypeBool);
245  vtkGetMacro(ScalarWarping, vtkTypeBool);
246  vtkBooleanMacro(ScalarWarping, vtkTypeBool);
248 
250 
255  vtkSetMacro(Capping, vtkTypeBool);
256  vtkGetMacro(Capping, vtkTypeBool);
257  vtkBooleanMacro(Capping, vtkTypeBool);
259 
261 
265  vtkSetMacro(CapValue, double);
266  vtkGetMacro(CapValue, double);
268 
270 
276  vtkSetClampMacro(AccumulationMode, int, VTK_ACCUMULATION_MODE_MIN, VTK_ACCUMULATION_MODE_SUM);
277  vtkGetMacro(AccumulationMode, int);
278  void SetAccumulationModeToMin() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_MIN); }
279  void SetAccumulationModeToMax() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_MAX); }
280  void SetAccumulationModeToSum() { this->SetAccumulationMode(VTK_ACCUMULATION_MODE_SUM); }
283 
285 
289  vtkSetMacro(NullValue, double);
290  vtkGetMacro(NullValue, double);
292 
294 
298  void ComputeModelBounds(vtkDataSet* input, vtkImageData* output, vtkInformation* outInfo);
300  vtkCompositeDataSet* input, vtkImageData* output, vtkInformation* outInfo);
302 
304 
309  friend class vtkGaussianSplatterAlgorithm;
310  double SamplePoint(double x[3]) // for compilers who can't handle this
311  {
312  return (this->*Sample)(x);
313  }
314  void SetScalar(vtkIdType idx, double dist2, double* sPtr)
315  {
316  double v = (this->*SampleFactor)(this->S) *
317  std::exp(static_cast<double>(this->ExponentFactor * (dist2) / (this->Radius2)));
319 
320  if (!this->Visited[idx])
321  {
322  this->Visited[idx] = 1;
323  *sPtr = v;
324  }
325  else
326  {
327  switch (this->AccumulationMode)
328  {
330  if (*sPtr > v)
331  {
332  *sPtr = v;
333  }
334  break;
336  if (*sPtr < v)
337  {
338  *sPtr = v;
339  }
340  break;
342  *sPtr += v;
343  break;
344  }
345  } // not first visit
346  }
347 
348 protected:
350  ~vtkGaussianSplatter() override = default;
351 
355  void Cap(vtkDoubleArray* s);
356 
357  int SampleDimensions[3]; // dimensions of volume to splat into
358  double Radius; // maximum distance splat propagates (as fraction 0->1)
359  double ExponentFactor; // scale exponent of gaussian function
360  double ModelBounds[6]; // bounding box of splatting dimensions
361  vtkTypeBool NormalWarping; // on/off warping of splat via normal
362  double Eccentricity; // elliptic distortion due to normals
363  vtkTypeBool ScalarWarping; // on/off warping of splat via scalar
364  double ScaleFactor; // splat size influenced by scale factor
365  vtkTypeBool Capping; // Cap side of volume to close surfaces
366  double CapValue; // value to use for capping
367  int AccumulationMode; // how to combine scalar values
368 
369  double Gaussian(double x[3]);
370  double EccentricGaussian(double x[3]);
371  double ScalarSampling(double s) { return this->ScaleFactor * s; }
372  double PositionSampling(double) { return this->ScaleFactor; }
373 
374 private:
375  double Radius2;
376  double (vtkGaussianSplatter::*Sample)(double x[3]);
377  double (vtkGaussianSplatter::*SampleFactor)(double s);
378  char* Visited;
379  double Eccentricity2;
380  double* P;
381  double* N;
382  double S;
383  double Origin[3];
384  double Spacing[3];
385  double SplatDistance[3];
386  double NullValue;
387 
388  vtkGaussianSplatter(const vtkGaussianSplatter&) = delete;
389  void operator=(const vtkGaussianSplatter&) = delete;
390 };
391 
392 VTK_ABI_NAMESPACE_END
393 #endif
abstract superclass for composite (multi-block or AMR) datasets
abstract class to specify dataset behavior
Definition: vtkDataSet.h:166
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:156
a simple class to control print indentation
Definition: vtkIndent.h:108
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