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

Method ReduceValuesToMedian

Infovis/Core/vtkReduceTable.cxx:208–238  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

206
207//------------------------------------------------------------------------------
208void vtkReduceTable::ReduceValuesToMedian(
209 vtkTable* input, vtkTable* output, vtkIdType row, vtkIdType col, std::vector<vtkIdType> oldRows)
210{
211 if (!input->GetValue(0, col).IsNumeric())
212 {
213 vtkErrorMacro(<< "Median is unsupported for non-numerical data");
214 return;
215 }
216
217 // generate a vector of values
218 std::vector<double> values;
219 for (std::vector<vtkIdType>::iterator itr = oldRows.begin(); itr != oldRows.end(); ++itr)
220 {
221 values.push_back(input->GetValue(*itr, col).ToDouble());
222 }
223
224 // sort it
225 std::sort(values.begin(), values.end());
226
227 // get the median and store it in the output table
228 if (values.size() % 2 == 1)
229 {
230 output->SetValue(row, col, vtkVariant(values.at((values.size() - 1) / 2)));
231 }
232 else
233 {
234 double d1 = values.at((values.size() - 1) / 2);
235 double d2 = values.at(values.size() / 2);
236 output->SetValue(row, col, vtkVariant((d1 + d2) / 2.0));
237 }
238}
239
240//------------------------------------------------------------------------------
241void vtkReduceTable::ReduceValuesToMode(

Callers 1

PopulateDataColumnMethod · 0.95

Calls 11

sortFunction · 0.50
vtkVariantClass · 0.50
IsNumericMethod · 0.45
GetValueMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
ToDoubleMethod · 0.45
sizeMethod · 0.45
SetValueMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected