VTK  9.7.20260723
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
101
102#ifndef vtkStatisticsAlgorithm_h
103#define vtkStatisticsAlgorithm_h
104
105#include "vtkFiltersStatisticsModule.h" // For export macro
106#include "vtkStringToken.h" // For constructor map
107#include "vtkTableAlgorithm.h"
108#include "vtkVariant.h" // For vtkVariant
109
110#include <token/Singletons.h> // For Schwarz counter.
111
112VTK_ABI_NAMESPACE_BEGIN
115class vtkStdString;
116class vtkStringArray;
117class vtkVariantArray;
118class vtkDoubleArray;
120
121class VTKFILTERSSTATISTICS_EXPORT vtkStatisticsAlgorithm : public vtkTableAlgorithm
122{
123public:
125 void PrintSelf(ostream& os, vtkIndent indent) override;
126
136
146
155
164
173
178 virtual void SetInputModel(vtkDataObject* model)
179 {
181 }
182
188
190
193 vtkSetMacro(LearnOption, bool);
194 vtkGetMacro(LearnOption, bool);
195 vtkBooleanMacro(LearnOption, bool);
197
199
202 vtkSetMacro(DeriveOption, bool);
203 vtkGetMacro(DeriveOption, bool);
204 vtkBooleanMacro(DeriveOption, bool);
206
208
211 vtkSetMacro(AssessOption, bool);
212 vtkGetMacro(AssessOption, bool);
213 vtkBooleanMacro(AssessOption, bool);
215
217
220 vtkSetMacro(TestOption, bool);
221 vtkGetMacro(TestOption, bool);
222 vtkBooleanMacro(TestOption, bool);
224
226
232
234
238 vtkGetObjectMacro(AssessNames, vtkStringArray);
240
242
246 {
247 public:
249 virtual ~AssessFunctor() = default;
250 };
251
252
264 virtual int GetMaximumNumberOfColumnsPerRequest() const { return 0; }
265
279 virtual void SetColumnStatus(const char* namCol, int status);
280
284 virtual void ResetAllColumnStates();
285
291
295 virtual void ResetRequests();
296
305
310
324 virtual const char* GetColumnForRequest(vtkIdType r, vtkIdType c);
325
326 virtual int GetColumnForRequest(vtkIdType r, vtkIdType c, vtkStdString& columnName);
327
335 void AddColumn(const char* namCol);
336
347 void AddColumnPair(const char* namColX, const char* namColY);
348
356 virtual bool SetParameter(const char* parameter, int index, vtkVariant value);
357
363 virtual bool Aggregate(vtkDataObjectCollection* collection, vtkStatisticalModel* model) = 0;
364
366
374
376
386 vtkSetMacro(GhostsToSkip, unsigned char);
387 vtkGetMacro(GhostsToSkip, unsigned char);
389
391
400 vtkSetMacro(SkipInvalidValues, bool);
401 vtkGetMacro(SkipInvalidValues, bool);
402 vtkBooleanMacro(SkipInvalidValues, bool);
404
406
424 virtual std::string GetAlgorithmParameters() const;
426
428
439 const std::string& algorithmParameters);
440
450 template <typename Algorithm>
451 static void RegisterAlgorithm()
452 {
454 vtkStringToken className(alg->GetClassName());
457 }
458
459protected:
462
463 using AlgorithmConstructor = std::function<vtkSmartPointer<vtkStatisticsAlgorithm>()>;
464 using AlgorithmConstructorMap = std::unordered_map<vtkStringToken, AlgorithmConstructor>;
465
467 virtual bool ConfigureFromAlgorithmParameters(const std::string& algorithmParameters);
468
485 virtual void AppendAlgorithmParameters(std::string& algorithmParameters) const;
486
501 virtual std::size_t ConsumeNextAlgorithmParameter(
502 vtkStringToken parameterName, const std::string& algorithmParameters);
503
504 int FillInputPortInformation(int port, vtkInformation* info) override;
505 int FillOutputPortInformation(int port, vtkInformation* info) override;
506
508
513
517 virtual void Derive(vtkStatisticalModel*) = 0;
518
523
528
533
538 vtkTable* outData, vtkDataObject* inMeta, vtkStringArray* rowNames, AssessFunctor*& dfunc) = 0;
539
549 static std::size_t ConsumeString(const std::string& source, std::string& value);
550
552
560 static std::size_t ConsumeStringTuple(const std::string& source, std::vector<std::string>& tuple);
561 static std::size_t ConsumeStringTuple(const std::string& source, vtkStringArray* tuple);
563
573 static std::size_t ConsumeDouble(const std::string& source, double& value);
574 static std::size_t ConsumeDoubleTuple(const std::string& source, std::vector<double>& tuple);
575 static std::size_t ConsumeDoubleTuples(
576 const std::string& source, std::vector<std::vector<double>>& tuple);
577 static std::size_t ConsumeStringToDoublesMap(
578 const std::string& source, std::map<std::string, std::vector<double>>& map);
579
582 static std::size_t ConsumeInt(const std::string& source, int& value);
583
586
593 unsigned char GhostsToSkip;
597
598private:
600 void operator=(const vtkStatisticsAlgorithm&) = delete;
601};
602
603VTK_ABI_NAMESPACE_END
604#endif
Proxy object to connect input/output ports.
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
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:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Allocate and hold a VTK object.
Definition vtkNew.h:168
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:170
An array holding vtkVariants.
A type representing the union of many types.
Definition vtkVariant.h:162
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition vtkType.h:363