------------------------------------------------------------------------------
| 239 | |
| 240 | //------------------------------------------------------------------------------ |
| 241 | void vtkReduceTable::ReduceValuesToMode( |
| 242 | vtkTable* input, vtkTable* output, vtkIdType row, vtkIdType col, std::vector<vtkIdType> oldRows) |
| 243 | { |
| 244 | // setup a map to determine how frequently each value appears |
| 245 | std::map<vtkVariant, int> modeMap; |
| 246 | std::map<vtkVariant, int>::iterator mapItr; |
| 247 | for (std::vector<vtkIdType>::iterator vectorItr = oldRows.begin(); vectorItr != oldRows.end(); |
| 248 | ++vectorItr) |
| 249 | { |
| 250 | vtkVariant v = input->GetValue(*vectorItr, col); |
| 251 | mapItr = modeMap.find(v); |
| 252 | if (mapItr == modeMap.end()) |
| 253 | { |
| 254 | modeMap[v] = 1; |
| 255 | } |
| 256 | else |
| 257 | { |
| 258 | mapItr->second += 1; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | // use our map to find the mode & store it in the output table |
| 263 | int maxCount = -1; |
| 264 | vtkVariant mode; |
| 265 | for (mapItr = modeMap.begin(); mapItr != modeMap.end(); ++mapItr) |
| 266 | { |
| 267 | if (mapItr->second > maxCount) |
| 268 | { |
| 269 | mode = mapItr->first; |
| 270 | maxCount = mapItr->second; |
| 271 | } |
| 272 | } |
| 273 | output->SetValue(row, col, mode); |
| 274 | } |
| 275 | |
| 276 | //------------------------------------------------------------------------------ |
| 277 | int vtkReduceTable::GetReductionMethodForColumn(vtkIdType col) |