| 261 | } |
| 262 | |
| 263 | bool vtkVisualStatistics::Aggregate( |
| 264 | vtkDataObjectCollection* inMetaColl, vtkStatisticalModel* outMeta) |
| 265 | { |
| 266 | if (!this->Superclass::Aggregate(inMetaColl, outMeta)) |
| 267 | { |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | // Get hold of the first model (data object) in the collection |
| 272 | int itemIndex; |
| 273 | int numItems = inMetaColl->GetNumberOfItems(); |
| 274 | // Skip collection entries until we find one with a histogram table: |
| 275 | vtkTable* histogramTab = nullptr; |
| 276 | vtkTable* summaryTab = nullptr; |
| 277 | for (itemIndex = 0; itemIndex < numItems; ++itemIndex) |
| 278 | { |
| 279 | // Verify that the first primary statistics are present |
| 280 | auto* inMeta = vtkStatisticalModel::SafeDownCast(inMetaColl->GetItemAsObject(itemIndex)); |
| 281 | histogramTab = inMeta ? inMeta->GetTable(vtkStatisticalModel::Learned, 1) : nullptr; |
| 282 | summaryTab = inMeta ? inMeta->GetTable(vtkStatisticalModel::Learned, 2) : nullptr; |
| 283 | if (histogramTab && summaryTab && histogramTab->GetNumberOfRows() > 0) |
| 284 | { |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | if (!histogramTab) |
| 289 | { |
| 290 | return true; |
| 291 | } |
| 292 | |
| 293 | // Use this first model to initialize the aggregated one |
| 294 | vtkNew<vtkTable> aggregatedTab; |
| 295 | aggregatedTab->DeepCopy(histogramTab); |
| 296 | vtkNew<vtkTable> aggregatedSummaryTab; |
| 297 | aggregatedSummaryTab->DeepCopy(summaryTab); |
| 298 | |
| 299 | // Now, loop over all remaining models and update aggregated each time |
| 300 | for (++itemIndex; itemIndex < numItems; ++itemIndex) |
| 301 | { |
| 302 | // Verify that the current primary statistics are indeed contained in a table |
| 303 | auto* inMeta = vtkStatisticalModel::SafeDownCast(inMetaColl->GetItemAsObject(itemIndex)); |
| 304 | histogramTab = inMeta ? inMeta->GetTable(vtkStatisticalModel::Learned, 1) : nullptr; |
| 305 | summaryTab = inMeta ? inMeta->GetTable(vtkStatisticalModel::Learned, 2) : nullptr; |
| 306 | if (!histogramTab || !summaryTab || |
| 307 | histogramTab->GetNumberOfRows() != aggregatedTab->GetNumberOfRows()) |
| 308 | { |
| 309 | continue; |
| 310 | } |
| 311 | |
| 312 | // This will print an error if aggregatedTab and histogramTab are not conformal. |
| 313 | vtkSumTables::SumTables(aggregatedTab, histogramTab); |
| 314 | vtkSumTables::SumTables( |
| 315 | aggregatedSummaryTab, summaryTab, /*checkOnly*/ false, /*allowAbstractColumns*/ true); |
| 316 | } |
| 317 | |
| 318 | // Finally set the output histogram statistics table. |
| 319 | outMeta->SetNumberOfTables(vtkStatisticalModel::Learned, 3); |
| 320 | outMeta->SetTable(vtkStatisticalModel::Learned, 1, aggregatedTab, "Histogram Statistics"); |