| 725 | |
| 726 | template <typename T> |
| 727 | bool AccumulateSampleValues(T* array, int nc, vtkIdType begin, vtkIdType end, |
| 728 | std::vector<std::set<T, CompareWithNaN<T>>>& uniques, std::set<std::vector<T>>& tupleUniques, |
| 729 | unsigned int maxDiscreteValues) |
| 730 | { |
| 731 | // number of discrete components remaining (tracked during iteration): |
| 732 | int ndc = nc; |
| 733 | std::pair<typename std::set<T>::iterator, bool> result; |
| 734 | std::pair<typename std::set<std::vector<T>>::iterator, bool> tresult; |
| 735 | std::vector<T> tuple; |
| 736 | tuple.resize(nc); |
| 737 | // Here we iterate over the components and add to their respective lists |
| 738 | // of previously encountered values -- as long as there are not too many |
| 739 | // values already in the list. We also accumulate each component's value |
| 740 | // into a vtkVariantArray named tuple, which is added to the list of |
| 741 | // unique vectors -- again assuming it is not already too long. |
| 742 | for (vtkIdType i = begin; i < end && ndc; ++i) |
| 743 | { |
| 744 | // First, attempt a per-component insert. |
| 745 | for (int j = 0; j < nc; ++j) |
| 746 | { |
| 747 | if (uniques[j].size() > maxDiscreteValues) |
| 748 | continue; |
| 749 | T& val(array[i * nc + j]); |
| 750 | tuple[j] = val; |
| 751 | result = uniques[j].insert(val); |
| 752 | if (result.second) |
| 753 | { |
| 754 | if (uniques[j].size() == maxDiscreteValues + 1) |
| 755 | { |
| 756 | --ndc; |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | // Now, as long as no component has exceeded maxDiscreteValues unique |
| 761 | // values, it is worth seeing whether the tuple as a whole is unique: |
| 762 | if (nc > 1 && ndc == nc) |
| 763 | { |
| 764 | tresult = tupleUniques.insert(tuple); |
| 765 | (void)tresult; // nice to have when debugging. |
| 766 | } |
| 767 | } |
| 768 | return ndc == 0; |
| 769 | } |
| 770 | |
| 771 | //------------------------------------------------------------------------------ |
| 772 | template <typename U> |
no test coverage detected