+void AnalogSignal::reset_pixel_values()
+{
+ value_at_pixel_pos_.clear();
+ current_pixel_pos_ = -1;
+ prev_value_at_pixel_ = std::numeric_limits<float>::quiet_NaN();
+}
+
+void AnalogSignal::process_next_sample_value(float x, float value)
+{
+ // Note: NAN is used to indicate the non-existance of a value at this pixel
+
+ if (isnan(prev_value_at_pixel_)) {
+ if (x < 0) {
+ min_value_at_pixel_ = value;
+ max_value_at_pixel_ = value;
+ prev_value_at_pixel_ = value;
+ current_pixel_pos_ = x;
+ } else
+ prev_value_at_pixel_ = std::numeric_limits<float>::quiet_NaN();
+ }
+
+ const int pixel_pos = (int)(x + 0.5);
+
+ if (pixel_pos > current_pixel_pos_) {
+ if (pixel_pos - current_pixel_pos_ == 1) {
+ if (isnan(prev_value_at_pixel_)) {
+ value_at_pixel_pos_.push_back(prev_value_at_pixel_);
+ } else {
+ // Average the min/max range to create one value for the previous pixel
+ const float avg = (min_value_at_pixel_ + max_value_at_pixel_) / 2;
+ value_at_pixel_pos_.push_back(avg);
+ }
+ } else {
+ // Interpolate values to create values for the intermediate pixels
+ const float start_value = prev_value_at_pixel_;
+ const float end_value = value;
+ const int steps = fabs(pixel_pos - current_pixel_pos_);
+ const double gradient = (end_value - start_value) / steps;
+ for (int i = 0; i < steps; i++) {
+ if (current_pixel_pos_ + i < 0)
+ continue;
+ value_at_pixel_pos_.push_back(start_value + i * gradient);
+ }
+ }
+
+ min_value_at_pixel_ = value;
+ max_value_at_pixel_ = value;
+ prev_value_at_pixel_ = value;
+ current_pixel_pos_ = pixel_pos;
+ } else {
+ // Another sample for the same pixel
+ if (value < min_value_at_pixel_)
+ min_value_at_pixel_ = value;
+ if (value > max_value_at_pixel_)
+ max_value_at_pixel_ = value;
+ }
+}
+