1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkReduceTable.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 // .NAME vtkReduceTable - combine some of the rows of a table 16 // 17 // .SECTION Description 18 // Collapses the rows of the input table so that one particular 19 // column (the IndexColumn) does not contain any duplicate values. 20 // Thus the output table will have the same columns as the input 21 // table, but potentially fewer rows. One example use of this 22 // class would be to generate a summary table from a table of 23 // observations. 24 // When two or more rows of the input table share a value in the 25 // IndexColumn, the values from these rows will be combined on a 26 // column-by-column basis. By default, such numerical values will be 27 // reduced to their mean, and non-numerical values will be reduced to 28 // their mode. This default behavior can be changed by calling 29 // SetNumericalReductionMethod() or SetNonNumericalReductionMethod(). 30 // You can also specify the reduction method to use for a particular 31 // column by calling SetReductionMethodForColumn(). 32 33 #ifndef vtkReduceTable_h 34 #define vtkReduceTable_h 35 36 #include "vtkInfovisCoreModule.h" // For export macro 37 #include "vtkTableAlgorithm.h" 38 39 #include <map> // For ivar 40 #include <set> // For ivar 41 #include <vector> // For ivar 42 43 class vtkVariant; 44 45 class VTKINFOVISCORE_EXPORT vtkReduceTable : public vtkTableAlgorithm 46 { 47 public: 48 static vtkReduceTable* New(); 49 vtkTypeMacro(vtkReduceTable,vtkTableAlgorithm); 50 void PrintSelf(ostream& os, vtkIndent indent); 51 52 // Description: 53 // Get/Set the column that will be used to reduce the input table. 54 // Any rows sharing a value in this column will be collapsed into 55 // a single row in the output table. 56 vtkGetMacro(IndexColumn, vtkIdType); 57 vtkSetMacro(IndexColumn, vtkIdType); 58 59 // Description: 60 // Get/Set the method that should be used to combine numerical 61 // values. 62 vtkGetMacro(NumericalReductionMethod, int); 63 vtkSetMacro(NumericalReductionMethod, int); 64 65 // Description: 66 // Get/Set the method that should be used to combine non-numerical 67 // values. 68 vtkGetMacro(NonNumericalReductionMethod, int); 69 vtkSetMacro(NonNumericalReductionMethod, int); 70 71 // Description: 72 // Get the method that should be used to combine the values within 73 // the specified column. Returns -1 if no method has been set for 74 // this particular column. 75 int GetReductionMethodForColumn(vtkIdType col); 76 77 // Description: 78 // Set the method that should be used to combine the values within 79 // the specified column. 80 void SetReductionMethodForColumn(vtkIdType col, int method); 81 82 //BTX 83 // Description: 84 // Enum for methods of reduction 85 enum 86 { 87 MEAN, 88 MEDIAN, 89 MODE 90 }; 91 //ETX 92 93 protected: 94 vtkReduceTable(); 95 ~vtkReduceTable(); 96 97 int RequestData( 98 vtkInformation*, 99 vtkInformationVector**, 100 vtkInformationVector*); 101 102 // Description: 103 // Initialize the output table to have the same types of columns as 104 // the input table, but no rows. 105 void InitializeOutputTable(vtkTable *input, vtkTable *output); 106 107 // Description: 108 // Find the distinct values in the input table's index column. 109 // This function also populates the mapping of new row IDs to old row IDs. 110 void AccumulateIndexValues(vtkTable *input); 111 112 // Description: 113 // Populate the index column of the output table. 114 void PopulateIndexColumn(vtkTable *output); 115 116 // Description: 117 // Populate a non-index column of the output table. This involves 118 // potentially combining multiple values from the input table into 119 // a single value for the output table. 120 void PopulateDataColumn(vtkTable *input, vtkTable *output, vtkIdType col); 121 122 // Description: 123 // Find the mean of a series of values from the input table 124 // and store it in the output table. 125 void ReduceValuesToMean(vtkTable *input, vtkTable *output, 126 vtkIdType row, vtkIdType col, 127 std::vector<vtkIdType> oldRows); 128 129 // Description: 130 // Find the median of a series of values from the input table 131 // and store it in the output table. 132 void ReduceValuesToMedian(vtkTable *input, vtkTable *output, 133 vtkIdType row, vtkIdType col, 134 std::vector<vtkIdType> oldRows); 135 136 // Description: 137 // Find the mode of a series of values from the input table 138 // and store it in the output table. 139 void ReduceValuesToMode(vtkTable *input, vtkTable *output, 140 vtkIdType row, vtkIdType col, 141 std::vector<vtkIdType> oldRows); 142 143 vtkIdType IndexColumn; 144 std::set<vtkVariant> IndexValues; 145 std::map<vtkVariant, std::vector<vtkIdType> > NewRowToOldRowsMap; 146 std::map<vtkIdType, int> ColumnReductionMethods; 147 148 int NumericalReductionMethod; 149 int NonNumericalReductionMethod; 150 151 private: 152 vtkReduceTable(const vtkReduceTable&); // Not implemented 153 void operator=(const vtkReduceTable&); // Not implemented 154 }; 155 156 #endif 157