VTK  9.5.20251216
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
109#include <token/Singletons.h> // For Schwarz counter.
110
111VTK_ABI_NAMESPACE_BEGIN
114class vtkStdString;
115class vtkStringArray;
116class vtkStringToken;
117class vtkVariant;
118class vtkVariantArray;
119class vtkDoubleArray;
121
122class VTKFILTERSSTATISTICS_EXPORT vtkStatisticsAlgorithm : public vtkTableAlgorithm
123{
124public:
126 void PrintSelf(ostream& os, vtkIndent indent) override;
127
137
147
156
165
174
179 virtual void SetInputModel(vtkDataObject* model)
180 {
182 }
183
189
191
194 vtkSetMacro(LearnOption, bool);
195 vtkGetMacro(LearnOption, bool);
196 vtkBooleanMacro(LearnOption, bool);
198
200
203 vtkSetMacro(DeriveOption, bool);
204 vtkGetMacro(DeriveOption, bool);
205 vtkBooleanMacro(DeriveOption, bool);
207
209
212 vtkSetMacro(AssessOption, bool);
213 vtkGetMacro(AssessOption, bool);
214 vtkBooleanMacro(AssessOption, bool);
216
218
221 vtkSetMacro(TestOption, bool);
222 vtkGetMacro(TestOption, bool);
223 vtkBooleanMacro(TestOption, bool);
225
227
233
235
239 vtkGetObjectMacro(AssessNames, vtkStringArray);
241
243
247 {
248 public:
250 virtual ~AssessFunctor() = default;
251 };
252
253
265 virtual int GetMaximumNumberOfColumnsPerRequest() const { return 0; }
266
280 virtual void SetColumnStatus(const char* namCol, int status);
281
285 virtual void ResetAllColumnStates();
286
292
296 virtual void ResetRequests();
297
306
311
325 virtual const char* GetColumnForRequest(vtkIdType r, vtkIdType c);
326
327 virtual int GetColumnForRequest(vtkIdType r, vtkIdType c, vtkStdString& columnName);
328
336 void AddColumn(const char* namCol);
337
348 void AddColumnPair(const char* namColX, const char* namColY);
349
357 virtual bool SetParameter(const char* parameter, int index, vtkVariant value);
358
364 virtual bool Aggregate(vtkDataObjectCollection* collection, vtkStatisticalModel* model) = 0;
365
367
375
377
387 vtkSetMacro(GhostsToSkip, unsigned char);
388 vtkGetMacro(GhostsToSkip, unsigned char);
390
392
401 vtkSetMacro(SkipInvalidValues, bool);
402 vtkGetMacro(SkipInvalidValues, bool);
403 vtkBooleanMacro(SkipInvalidValues, bool);
405
407
425 virtual std::string GetAlgorithmParameters() const;
427
429
440 const std::string& algorithmParameters);
441
451 template <typename Algorithm>
452 static void RegisterAlgorithm()
453 {
455 vtkStringToken className(alg->GetClassName());
458 }
459
460protected:
463
464 using AlgorithmConstructor = std::function<vtkSmartPointer<vtkStatisticsAlgorithm>()>;
465 using AlgorithmConstructorMap = std::unordered_map<vtkStringToken, AlgorithmConstructor>;
466
468 virtual bool ConfigureFromAlgorithmParameters(const std::string& algorithmParameters);
469
486 virtual void AppendAlgorithmParameters(std::string& algorithmParameters) const;
487
502 virtual std::size_t ConsumeNextAlgorithmParameter(
503 vtkStringToken parameterName, const std::string& algorithmParameters);
504
505 int FillInputPortInformation(int port, vtkInformation* info) override;
506 int FillOutputPortInformation(int port, vtkInformation* info) override;
507
509
514
518 virtual void Derive(vtkStatisticalModel*) = 0;
519
524
529
534
539 vtkTable* outData, vtkDataObject* inMeta, vtkStringArray* rowNames, AssessFunctor*& dfunc) = 0;
540
550 static std::size_t ConsumeString(const std::string& source, std::string& value);
551
553
561 static std::size_t ConsumeStringTuple(const std::string& source, std::vector<std::string>& tuple);
562 static std::size_t ConsumeStringTuple(const std::string& source, vtkStringArray* tuple);
564
574 static std::size_t ConsumeDouble(const std::string& source, double& value);
575 static std::size_t ConsumeDoubleTuple(const std::string& source, std::vector<double>& tuple);
576 static std::size_t ConsumeDoubleTuples(
577 const std::string& source, std::vector<std::vector<double>>& tuple);
578 static std::size_t ConsumeStringToDoublesMap(
579 const std::string& source, std::map<std::string, std::vector<double>>& map);
580
583 static std::size_t ConsumeInt(const std::string& source, int& value);
584
587
594 unsigned char GhostsToSkip;
598
599private:
601 void operator=(const vtkStatisticsAlgorithm&) = delete;
602};
603
604VTK_ABI_NAMESPACE_END
605#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:167
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:169
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:368