MCPcopy Create free account
hub / github.com/Kitware/VTK / ReduceValuesToMode

Method ReduceValuesToMode

Infovis/Core/vtkReduceTable.cxx:241–274  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

239
240//------------------------------------------------------------------------------
241void 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//------------------------------------------------------------------------------
277int vtkReduceTable::GetReductionMethodForColumn(vtkIdType col)

Callers 1

PopulateDataColumnMethod · 0.95

Calls 5

beginMethod · 0.45
endMethod · 0.45
GetValueMethod · 0.45
findMethod · 0.45
SetValueMethod · 0.45

Tested by

no test coverage detected