------------------------------------------------------------------------------
| 79 | |
| 80 | //------------------------------------------------------------------------------ |
| 81 | bool vtkPlotBag::UpdateCache() |
| 82 | { |
| 83 | if (!this->Superclass::UpdateCache()) |
| 84 | { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | vtkTable* table = this->Data->GetInput(); |
| 89 | |
| 90 | this->MedianPoints->Reset(); |
| 91 | this->Q3Points->Reset(); |
| 92 | |
| 93 | if (!this->Points) |
| 94 | { |
| 95 | return false; |
| 96 | } |
| 97 | vtkDataArray* density = vtkDataArray::SafeDownCast(table->GetColumn(2)); |
| 98 | if (!density) |
| 99 | { |
| 100 | vtkDebugMacro(<< "Update event called with no input table or density column set."); |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | vtkPoints2D* points = this->Points; |
| 105 | |
| 106 | vtkIdType nbPoints = density->GetNumberOfTuples(); |
| 107 | |
| 108 | // Fetch and sort arrays according their density |
| 109 | std::vector<DensityVal> ids; |
| 110 | ids.reserve(nbPoints); |
| 111 | auto range = vtk::DataArrayTupleRange(density); |
| 112 | int counter = 0; |
| 113 | for (typename decltype(range)::ConstTupleReferenceType tuple : range) |
| 114 | { |
| 115 | ids.emplace_back(tuple[0], counter); |
| 116 | counter++; |
| 117 | } |
| 118 | std::sort(ids.begin(), ids.end()); |
| 119 | |
| 120 | vtkNew<vtkPointsProjectedHull> q3Points; |
| 121 | q3Points->Allocate(nbPoints); |
| 122 | vtkNew<vtkPointsProjectedHull> medianPoints; |
| 123 | medianPoints->Allocate(nbPoints); |
| 124 | |
| 125 | // Compute total density sum |
| 126 | double densitySum = 0.0; |
| 127 | for (vtkIdType i = 0; i < nbPoints; i++) |
| 128 | { |
| 129 | densitySum += density->GetTuple1(i); |
| 130 | } |
| 131 | |
| 132 | double sum = 0.0; |
| 133 | double const medianDensity = 0.5 * densitySum; |
| 134 | double const q3Density = 0.99 * densitySum; |
| 135 | for (vtkIdType i = 0; i < nbPoints; i++) |
| 136 | { |
| 137 | double x[2]; |
| 138 | points->GetPoint(ids[i].Id, x); |
no test coverage detected