##// END OF EJS Templates
Creates method to compute resolutions of a dataset...
Alexandre Leroux -
r990:01201e853d86
parent child
Show More
@@ -12,6 +12,17 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeriesUtils)
12 */
12 */
13 struct SCIQLOP_CORE_EXPORT DataSeriesUtils {
13 struct SCIQLOP_CORE_EXPORT DataSeriesUtils {
14 /**
14 /**
15 * Represents a resolution used to generate the data of a mesh on the x-axis or in Y.
16 *
17 * A resolution is represented by a value and flag indicating if it's in the logarithmic scale
18 * @sa Mesh
19 */
20 struct Resolution {
21 double m_Val{std::numeric_limits<double>::quiet_NaN()};
22 bool m_Logarithmic{false};
23 };
24
25 /**
15 * Processes data from a data series to complete the data holes with a fill value.
26 * Processes data from a data series to complete the data holes with a fill value.
16 *
27 *
17 * A data hole is determined by the resolution passed in parameter: if, between two continuous
28 * A data hole is determined by the resolution passed in parameter: if, between two continuous
@@ -75,6 +86,54 struct SCIQLOP_CORE_EXPORT DataSeriesUtils {
75 double fillValue = std::numeric_limits<double>::quiet_NaN(),
86 double fillValue = std::numeric_limits<double>::quiet_NaN(),
76 double minBound = std::numeric_limits<double>::quiet_NaN(),
87 double minBound = std::numeric_limits<double>::quiet_NaN(),
77 double maxBound = std::numeric_limits<double>::quiet_NaN());
88 double maxBound = std::numeric_limits<double>::quiet_NaN());
89 /**
90 * Computes the resolution of a dataset passed as a parameter.
91 *
92 * The resolution of a dataset is the minimum difference between two values that follow in the
93 * set.
94 * For example:
95 * - for the set [0, 2, 4, 8, 10, 11, 13] => the resolution is 1 (difference between 10 and 11).
96 *
97 * A resolution can be calculated on the logarithmic scale (base of 10). In this case, the
98 * dataset is first converted to logarithmic values.
99 * For example:
100 * - for the set [10, 100, 10000, 1000000], the values are converted to [1, 2, 4, 6] => the
101 * logarithmic resolution is 1 (difference between 1 and 2).
102 *
103 * @param begin the iterator pointing to the beginning of the dataset
104 * @param end the iterator pointing to the end of the dataset
105 * @param logarithmic computes a logarithmic resolution or not
106 * @return the resolution computed
107 * @warning the method considers the dataset as sorted and doesn't control it.
108 */
109 template <typename Iterator>
110 static Resolution resolution(Iterator begin, Iterator end, bool logarithmic = false);
78 };
111 };
79
112
113 template <typename Iterator>
114 DataSeriesUtils::Resolution DataSeriesUtils::resolution(Iterator begin, Iterator end,
115 bool logarithmic)
116 {
117 // Retrieves data into a work dataset
118 using ValueType = typename Iterator::value_type;
119 std::vector<ValueType> values{};
120 std::copy(begin, end, std::back_inserter(values));
121
122 // Converts data if logarithmic flag is activated
123 if (logarithmic) {
124 std::for_each(values.begin(), values.end(),
125 [logarithmic](auto &val) { val = std::log10(val); });
126 }
127
128 // Computes the differences between the values in the dataset
129 std::adjacent_difference(values.begin(), values.end(), values.begin());
130
131 // Retrieves the smallest difference
132 auto resolutionIt = std::min_element(values.begin(), values.end());
133 auto resolution
134 = resolutionIt != values.end() ? *resolutionIt : std::numeric_limits<double>::quiet_NaN();
135
136 return Resolution{resolution, logarithmic};
137 }
138
80 #endif // SCIQLOP_DATASERIESUTILS_H
139 #endif // SCIQLOP_DATASERIESUTILS_H
General Comments 0
You need to be logged in to leave comments. Login now