VTK  9.7.1
vtkStatisticsAlgorithm.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright 2011 Sandia Corporation
3 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
43 #ifndef vtkStatisticsAlgorithm_h
44 #define vtkStatisticsAlgorithm_h
45 
46 #include "vtkFiltersStatisticsModule.h" // For export macro
47 #include "vtkStringToken.h" // For constructor map
48 #include "vtkTableAlgorithm.h"
49 
50 #include <token/Singletons.h> // For Schwarz counter.
51 
52 VTK_ABI_NAMESPACE_BEGIN
55 class vtkStdString;
56 class vtkStringArray;
57 class vtkStringToken;
58 class vtkVariant;
59 class vtkVariantArray;
60 class vtkDoubleArray;
62 
63 class VTKFILTERSSTATISTICS_EXPORT vtkStatisticsAlgorithm : public vtkTableAlgorithm
64 {
65 public:
67  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
73  {
74  INPUT_DATA = 0,
75  LEARN_PARAMETERS = 1,
76  INPUT_MODEL = 2
77  };
78 
83  {
84  OUTPUT_DATA = 0,
85  OUTPUT_MODEL = 1,
86  OUTPUT_TEST = 2
87  };
88 
94  {
96  }
97 
103  {
105  }
106 
112  {
114  }
115 
120  virtual void SetInputModel(vtkDataObject* model)
121  {
123  }
124 
129  virtual vtkStatisticalModel* GetOutputModel();
130 
132 
135  vtkSetMacro(LearnOption, bool);
136  vtkGetMacro(LearnOption, bool);
137  vtkBooleanMacro(LearnOption, bool);
139 
141 
144  vtkSetMacro(DeriveOption, bool);
145  vtkGetMacro(DeriveOption, bool);
146  vtkBooleanMacro(DeriveOption, bool);
148 
150 
153  vtkSetMacro(AssessOption, bool);
154  vtkGetMacro(AssessOption, bool);
155  vtkBooleanMacro(AssessOption, bool);
157 
159 
162  vtkSetMacro(TestOption, bool);
163  vtkGetMacro(TestOption, bool);
164  vtkBooleanMacro(TestOption, bool);
166 
168 
171  vtkSetMacro(NumberOfPrimaryTables, vtkIdType);
172  vtkGetMacro(NumberOfPrimaryTables, vtkIdType);
174 
176 
179  virtual void SetAssessNames(vtkStringArray*);
180  vtkGetObjectMacro(AssessNames, vtkStringArray);
182 
184 
188  {
189  public:
190  virtual void operator()(vtkDoubleArray*, vtkIdType) = 0;
191  virtual ~AssessFunctor() = default;
192  };
194 
206  virtual int GetMaximumNumberOfColumnsPerRequest() const { return 0; }
207 
221  virtual void SetColumnStatus(const char* namCol, int status);
222 
226  virtual void ResetAllColumnStates();
227 
232  virtual int RequestSelectedColumns();
233 
237  virtual void ResetRequests();
238 
246  virtual vtkIdType GetNumberOfRequests();
247 
251  virtual vtkIdType GetNumberOfColumnsForRequest(vtkIdType request);
252 
266  virtual const char* GetColumnForRequest(vtkIdType r, vtkIdType c);
267 
268  virtual int GetColumnForRequest(vtkIdType r, vtkIdType c, vtkStdString& columnName);
269 
277  void AddColumn(const char* namCol);
278 
289  void AddColumnPair(const char* namColX, const char* namColY);
290 
298  virtual bool SetParameter(const char* parameter, int index, vtkVariant value);
299 
305  virtual bool Aggregate(vtkDataObjectCollection* collection, vtkStatisticalModel* model) = 0;
306 
308 
314  bool CopyRequests(vtkStatisticsAlgorithmPrivate* requests);
316 
318 
328  vtkSetMacro(GhostsToSkip, unsigned char);
329  vtkGetMacro(GhostsToSkip, unsigned char);
331 
333 
342  vtkSetMacro(SkipInvalidValues, bool);
343  vtkGetMacro(SkipInvalidValues, bool);
344  vtkBooleanMacro(SkipInvalidValues, bool);
346 
348 
366  virtual std::string GetAlgorithmParameters() const;
368 
370 
380  static vtkSmartPointer<vtkStatisticsAlgorithm> NewFromAlgorithmParameters(
381  const std::string& algorithmParameters);
382 
392  template <typename Algorithm>
393  static void RegisterAlgorithm()
394  {
395  vtkNew<Algorithm> alg;
396  vtkStringToken className(alg->GetClassName());
398  { return vtkSmartPointer<Algorithm>::New(); };
399  }
400 
401 protected:
403  ~vtkStatisticsAlgorithm() override;
404 
405  using AlgorithmConstructor = std::function<vtkSmartPointer<vtkStatisticsAlgorithm>()>;
406  using AlgorithmConstructorMap = std::unordered_map<vtkStringToken, AlgorithmConstructor>;
407 
409  virtual bool ConfigureFromAlgorithmParameters(const std::string& algorithmParameters);
410 
427  virtual void AppendAlgorithmParameters(std::string& algorithmParameters) const;
428 
443  virtual std::size_t ConsumeNextAlgorithmParameter(
444  vtkStringToken parameterName, const std::string& algorithmParameters);
445 
446  int FillInputPortInformation(int port, vtkInformation* info) override;
448 
450 
454  virtual void Learn(vtkTable*, vtkTable*, vtkStatisticalModel*) = 0;
455 
459  virtual void Derive(vtkStatisticalModel*) = 0;
460 
464  virtual void Assess(vtkTable*, vtkStatisticalModel*, vtkTable*) = 0;
465 
469  void Assess(vtkTable*, vtkStatisticalModel*, vtkTable*, int);
470 
474  virtual void Test(vtkTable*, vtkStatisticalModel*, vtkTable*) = 0;
475 
479  virtual void SelectAssessFunctor(
480  vtkTable* outData, vtkDataObject* inMeta, vtkStringArray* rowNames, AssessFunctor*& dfunc) = 0;
481 
491  static std::size_t ConsumeString(const std::string& source, std::string& value);
492 
494 
502  static std::size_t ConsumeStringTuple(const std::string& source, std::vector<std::string>& tuple);
503  static std::size_t ConsumeStringTuple(const std::string& source, vtkStringArray* tuple);
505 
515  static std::size_t ConsumeDouble(const std::string& source, double& value);
516  static std::size_t ConsumeDoubleTuple(const std::string& source, std::vector<double>& tuple);
517  static std::size_t ConsumeDoubleTuples(
518  const std::string& source, std::vector<std::vector<double>>& tuple);
519  static std::size_t ConsumeStringToDoublesMap(
520  const std::string& source, std::map<std::string, std::vector<double>>& map);
521 
524  static std::size_t ConsumeInt(const std::string& source, int& value);
525 
527  static AlgorithmConstructorMap& GetConstructorMap();
528 
535  unsigned char GhostsToSkip;
539 
540 private:
542  void operator=(const vtkStatisticsAlgorithm&) = delete;
543 };
544 
545 VTK_ABI_NAMESPACE_END
546 #endif
static void RegisterAlgorithm()
Register a subclass of this algorithm.
std::unordered_map< vtkStringToken, AlgorithmConstructor > AlgorithmConstructorMap
Return a new instance of a subclass named and configured by the algorithmParameters.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
A base class for a functor that assesses data.
vtkStatisticsAlgorithmPrivate * Internals
a base class for statistical modeling of other data
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
An array holding vtkVariants.
Store vtkAlgorithm input/output information.
static AlgorithmConstructorMap & GetConstructorMap()
Return a map of registered algorithm types.
maintain an unordered list of data objects
InputPorts
enumeration values to specify input port types
virtual void SetInputModelConnection(vtkAlgorithmOutput *model)
A convenience method for setting the input model connection (if one is expected or allowed)...
a vtkAbstractArray subclass for strings
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
OutputIndices
enumeration values to specify output port types
int vtkIdType
Definition: vtkType.h:363
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
Port 1 is for learn parameters (initial guesses, etc.)
A type representing the union of many types.
Definition: vtkVariant.h:52
Proxy object to connect input/output ports.
dynamic, self-adjusting array of double
Base class for statistics algorithms.
virtual void SetLearnOptionParameterConnection(vtkAlgorithmOutput *params)
A convenience method for setting learn input parameters (if one is expected or allowed).
a simple class to control print indentation
Definition: vtkIndent.h:28
int Test(int argc, char *argv[], const char *dfile, const InitializationCallback &initCallback)
std::function< vtkSmartPointer< vtkStatisticsAlgorithm >()> AlgorithmConstructor
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
Represent a string by its integer hash.
void SetInputData(vtkDataObject *obj)
Assign a data object as input.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:59
Allocate and hold a VTK object.
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
Superclass for algorithms that produce only vtkTables as output.
Store zero or more vtkInformation instances.
virtual void SetInputModel(vtkDataObject *model)
A convenience method for setting the input model (if one is expected or allowed). ...
virtual void SetLearnOptionParameters(vtkDataObject *params)
A convenience method for setting learn input parameters (if one is expected or allowed).
general representation of visualization data
Definition: vtkDataObject.h:55
int FillOutputPortInformation(int port, vtkInformation *info) override
Fill the output port information objects for this algorithm.
virtual int GetMaximumNumberOfColumnsPerRequest() const
Provide a limit on the number of columns per request for this algorithm subclass. ...
Port 2 is for a priori models.