VTK  9.6.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
42
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
52VTK_ABI_NAMESPACE_BEGIN
55class vtkStdString;
56class vtkStringArray;
57class vtkStringToken;
58class vtkVariant;
59class vtkVariantArray;
60class vtkDoubleArray;
62
63class VTKFILTERSSTATISTICS_EXPORT vtkStatisticsAlgorithm : public vtkTableAlgorithm
64{
65public:
67 void PrintSelf(ostream& os, vtkIndent indent) override;
68
78
88
97
106
115
120 virtual void SetInputModel(vtkDataObject* model)
121 {
123 }
124
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
174
176
180 vtkGetObjectMacro(AssessNames, vtkStringArray);
182
184
188 {
189 public:
191 virtual ~AssessFunctor() = default;
192 };
193
194
206 virtual int GetMaximumNumberOfColumnsPerRequest() const { return 0; }
207
221 virtual void SetColumnStatus(const char* namCol, int status);
222
226 virtual void ResetAllColumnStates();
227
233
237 virtual void ResetRequests();
238
247
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
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
381 const std::string& algorithmParameters);
382
392 template <typename Algorithm>
393 static void RegisterAlgorithm()
394 {
396 vtkStringToken className(alg->GetClassName());
399 }
400
401protected:
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;
447 int FillOutputPortInformation(int port, vtkInformation* info) override;
448
450
455
459 virtual void Derive(vtkStatisticalModel*) = 0;
460
465
470
475
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
528
535 unsigned char GhostsToSkip;
539
540private:
542 void operator=(const vtkStatisticsAlgorithm&) = delete;
543};
544
545VTK_ABI_NAMESPACE_END
546#endif
Proxy object to connect input/output ports.
maintain an unordered list of data objects
general representation of visualization data
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Allocate and hold a VTK object.
Definition vtkNew.h:58
Hold a reference to a vtkObjectBase instance.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
a base class for statistical modeling of other data
A base class for a functor that assesses data.
virtual void operator()(vtkDoubleArray *, vtkIdType)=0
static std::size_t ConsumeStringTuple(const std::string &source, std::vector< std::string > &tuple)
Turn a tuple of strings into a vtkStringArray, returning the number of bytes consumed.
bool CopyRequests(vtkStatisticsAlgorithmPrivate *requests)
Copy requests for analysis from another container into this algorithm.
static AlgorithmConstructorMap & GetConstructorMap()
Return a map of registered algorithm types.
static vtkSmartPointer< vtkStatisticsAlgorithm > NewFromAlgorithmParameters(const std::string &algorithmParameters)
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual void SetAssessNames(vtkStringArray *)
Set/get assessment names.
virtual void SetColumnStatus(const char *namCol, int status)
Add or remove a column from the current analysis request.
virtual void AppendAlgorithmParameters(std::string &algorithmParameters) const
Subclasses must override this method if they have any internal ivars that affect the behavior of Requ...
virtual int GetColumnForRequest(vtkIdType r, vtkIdType c, vtkStdString &columnName)
virtual vtkStatisticalModel * GetOutputModel()
A convenience method for fetching an output model that returns the proper type so downcasting is not ...
~vtkStatisticsAlgorithm() override
Return a new instance of a subclass named and configured by the algorithmParameters.
static std::size_t ConsumeString(const std::string &source, std::string &value)
Turn a quoted string value into std::string, returning the number of bytes consumed.
std::function< vtkSmartPointer< vtkStatisticsAlgorithm >()> AlgorithmConstructor
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual void ResetAllColumnStates()
Set the status of each and every column in the current request to OFF (0).
static std::size_t ConsumeStringTuple(const std::string &source, vtkStringArray *tuple)
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual std::string GetAlgorithmParameters() const
Provide a serialization of this object's internal state so it can be recreated by a vtkStatisticalMod...
virtual void SetInputModelConnection(vtkAlgorithmOutput *model)
A convenience method for setting the input model connection (if one is expected or allowed).
void Assess(vtkTable *, vtkStatisticalModel *, vtkTable *, int)
A convenience implementation for generic assessment with variable number of variables.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual const char * GetColumnForRequest(vtkIdType r, vtkIdType c)
Provide the name of the c-th column for the r-th request.
OutputIndices
enumeration values to specify output port types
@ OUTPUT_TEST
Output 2 contains result of statistical test(s).
@ OUTPUT_MODEL
Output 1 contains any generated model.
@ OUTPUT_DATA
Output 0 mirrors the input data, plus optional assessment columns.
virtual void Learn(vtkTable *, vtkTable *, vtkStatisticalModel *)=0
Execute the calculations required by the Learn option, given some input Data.
virtual void ResetRequests()
Empty the list of current requests.
virtual void SelectAssessFunctor(vtkTable *outData, vtkDataObject *inMeta, vtkStringArray *rowNames, AssessFunctor *&dfunc)=0
A pure virtual method to select the appropriate assessment functor.
virtual vtkIdType GetNumberOfRequests()
Return the number of requests.
static std::size_t ConsumeDoubleTuple(const std::string &source, std::vector< double > &tuple)
void AddColumnPair(const char *namColX, const char *namColY)
Convenience method to create a request with a single column name pair (namColX, namColY) in a single ...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual bool ConfigureFromAlgorithmParameters(const std::string &algorithmParameters)
Loop over algorithmParameters until all are consumed or an error occurs.
static void RegisterAlgorithm()
Register a subclass of this algorithm.
virtual void Assess(vtkTable *, vtkStatisticalModel *, vtkTable *)=0
Execute the calculations required by the Assess option.
static std::size_t ConsumeDouble(const std::string &source, double &value)
Turn tuples (or respectively tuples of tuples) of numbers into a vector (or respectively a vector of ...
static std::size_t ConsumeInt(const std::string &source, int &value)
Turn a string holding an integer value into an integer, returning the number of bytes consumed by the...
virtual bool Aggregate(vtkDataObjectCollection *collection, vtkStatisticalModel *model)=0
Given a collection of models, calculate an aggregate model.
static std::size_t ConsumeDoubleTuples(const std::string &source, std::vector< std::vector< double > > &tuple)
virtual void SetLearnOptionParameterConnection(vtkAlgorithmOutput *params)
A convenience method for setting learn input parameters (if one is expected or allowed).
virtual int GetMaximumNumberOfColumnsPerRequest() const
Provide a limit on the number of columns per request for this algorithm subclass.
virtual void SetInputModel(vtkDataObject *model)
A convenience method for setting the input model (if one is expected or allowed).
vtkStatisticsAlgorithmPrivate * Internals
void AddColumn(const char *namCol)
Convenience method to create a request with a single column name namCol in a single call; this is the...
std::unordered_map< vtkStringToken, AlgorithmConstructor > AlgorithmConstructorMap
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual int RequestSelectedColumns()
Use the current column status values to produce a new request for statistics to be produced when Requ...
int FillOutputPortInformation(int port, vtkInformation *info) override
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual vtkIdType GetNumberOfColumnsForRequest(vtkIdType request)
Return the number of columns for a given request.
virtual void Test(vtkTable *, vtkStatisticalModel *, vtkTable *)=0
Execute the calculations required by the Test option.
static std::size_t ConsumeStringToDoublesMap(const std::string &source, std::map< std::string, std::vector< double > > &map)
vtkStatisticsAlgorithm()
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual std::size_t ConsumeNextAlgorithmParameter(vtkStringToken parameterName, const std::string &algorithmParameters)
Consume a single parameter value, setting the value on this instance of the class.
virtual void Derive(vtkStatisticalModel *)=0
Execute the calculations required by the Derive option.
virtual bool SetParameter(const char *parameter, int index, vtkVariant value)
A convenience method (in particular for access from other applications) to set parameter values of Le...
int FillInputPortInformation(int port, vtkInformation *info) override
Return a new instance of a subclass named and configured by the algorithmParameters.
virtual void SetLearnOptionParameters(vtkDataObject *params)
A convenience method for setting learn input parameters (if one is expected or allowed).
InputPorts
enumeration values to specify input port types
@ LEARN_PARAMETERS
Port 1 is for learn parameters (initial guesses, etc.).
@ INPUT_MODEL
Port 2 is for a priori models.
@ INPUT_DATA
Port 0 is for learn data.
Wrapper around std::string to keep symbols short.
a vtkAbstractArray subclass for strings
Represent a string by its integer hash.
void SetInputData(vtkDataObject *obj)
Assign a data object as input.
A table, which contains similar-typed columns of data.
Definition vtkTable.h:60
An array holding vtkVariants.
A type representing the union of many types.
Definition vtkVariant.h:53
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition vtkType.h:368