---------------------------------------------------------------------------- Normalize cntrlPoints so that the range goes from (0, 1). The cntrlPoints are assumed to be using log-space interpolation if "log_space" is true. The result is always in linear space irrespective of the original interpolation space. originalRange is filled with the original range of the cntrlPoints before rescaling.
| 87 | // originalRange is filled with the original range of the cntrlPoints before |
| 88 | // rescaling. |
| 89 | bool vtkNormalize(std::vector<vtkTuple<double, 4>>& cntrlPoints, bool log_space, |
| 90 | vtkTuple<double, 2>* originalRange = nullptr) |
| 91 | { |
| 92 | if (cntrlPoints.empty()) |
| 93 | { |
| 94 | // nothing to do, but not an error, so return true. |
| 95 | return true; |
| 96 | } |
| 97 | if (cntrlPoints.size() == 1) |
| 98 | { |
| 99 | if (originalRange) |
| 100 | { |
| 101 | (*originalRange)[0] = cntrlPoints[0][0]; |
| 102 | (*originalRange)[1] = cntrlPoints[0][0]; |
| 103 | } |
| 104 | |
| 105 | // Only 1 control point in the property. We'll add 2 points, however. |
| 106 | cntrlPoints.resize(2); |
| 107 | cntrlPoints[1] = cntrlPoints[0]; |
| 108 | cntrlPoints[0][0] = 0.0; |
| 109 | cntrlPoints[1][0] = 1.0; |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | // sort the points by x, just in case user didn't add them correctly. |
| 114 | std::sort(cntrlPoints.begin(), cntrlPoints.end(), StrictWeakOrdering()); |
| 115 | |
| 116 | const double old_range[2] = { cntrlPoints.front().GetData()[0], cntrlPoints.back().GetData()[0] }; |
| 117 | if (log_space && (old_range[0] <= 0 || old_range[1] <= 0)) |
| 118 | { |
| 119 | vtkGenericWarningMacro("Range not valid for log. Assuming control points " |
| 120 | "are not specified in log space."); |
| 121 | log_space = false; |
| 122 | } |
| 123 | if (originalRange) |
| 124 | { |
| 125 | (*originalRange)[0] = old_range[0]; |
| 126 | (*originalRange)[1] = old_range[1]; |
| 127 | } |
| 128 | |
| 129 | // if in log_space, let's convert all the control point values to |
| 130 | // log. |
| 131 | if (log_space) |
| 132 | { |
| 133 | for (size_t cc = 0; cc < cntrlPoints.size(); ++cc) |
| 134 | { |
| 135 | cntrlPoints[cc][0] = log10(cntrlPoints[cc][0]); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // now simply normalize the cntrlPoints. |
| 140 | const double range[2] = { cntrlPoints.front()[0], cntrlPoints.back()[0] }; |
| 141 | if (range[0] == 0.0 && range[1] == 1.0) |
| 142 | { |
| 143 | // nothing to do. |
| 144 | return true; |
| 145 | } |
| 146 | const double denominator = (range[1] - range[0]); |
no test coverage detected