Showing with 32 additions and 64 deletions.
  1. +1 −0 src/kst/main.cpp
  2. +29 −62 src/libkst/matrix.cpp
  3. +1 −1 src/libkstapp/plotitem.cpp
  4. +1 −1 src/libkstmath/image.cpp
1 change: 1 addition & 0 deletions src/kst/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int main(int argc, char *argv[]) {
}
#endif

srand(time(NULL));
Kst::Application app(argc, argv);

//--------
Expand Down
91 changes: 29 additions & 62 deletions src/libkst/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <math.h>
#include <QDebug>
#include <QXmlStreamWriter>
#include <QList>

#include "debug.h"
#include "math_kst.h"
Expand Down Expand Up @@ -197,19 +198,26 @@ double Matrix::maxValueNoSpike() const {
}

void Matrix::calcNoSpikeRange(double per) {
double *min_list, *max_list, min_of_max, max_of_min;
int n_list;
int max_n = 50000; // the most samples we will look at...
double n_skip;
int n_check; // the number of (randomly selected) samples to check.
int n_checked;
double x=0;
int n_notnan;
QList<double> pixels;
double max = -1E300;
double min = 1E300;

int i,j, k;
int i;
unsigned long j;

if (per>0.5) per = 0.49;

// count number of points which aren't nans.
for (i=n_notnan=0; i<_NS; ++i) {
if (!KST_ISNAN(_z[i])) {
n_notnan++;
} else {
max = qMax(max, _z[i]);
min = qMin(min, _z[i]);
}
}

Expand All @@ -218,74 +226,33 @@ void Matrix::calcNoSpikeRange(double per) {
_maxNoSpike = 0;

return;
}
} else if (per<=0) {
_minNoSpike = min;
_maxNoSpike = max;
return;

if (per < 0) {
per = 0;
}
per *= (double)n_notnan/(double)_NS;
max_n *= int((double)_NS/(double)n_notnan);

n_skip = (double)_NS/max_n;
if (n_skip<1.0) n_skip = 1.0;

n_list = int(double(_NS)*per/n_skip);
n_check = 100000;

min_list = (double *)malloc(n_list * sizeof(double));
max_list = (double *)malloc(n_list * sizeof(double));
n_checked = 0;

pixels.clear();

// prefill the list
for (i=0; i<n_list; ++i) {
min_list[i] = 1E+300;
max_list[i] = -1E+300;
}
min_of_max = -1E+300;
max_of_min = 1E+300;

i = n_list;
for (j=0; j<_NS; j=int(i*n_skip), ++i) {
if (_z[j] < max_of_min) { // member for the min list
// replace max of min with the new value
for (k=0; k<n_list; ++k) {
if (min_list[k]==max_of_min) {
x = min_list[k] = _z[j];
break;
}
}
max_of_min = x;
// find the new max_of_min
for (k=0; k<n_list; ++k) {
if (min_list[k] > max_of_min) {
max_of_min = min_list[k];
}
}
}
if (_z[j] > min_of_max) { // member for the max list
//printf("******** z: %g min_of_max: %g\n", _z[j], min_of_max);
// replace min of max with the new value
for (k=0; k<n_list; ++k) {
if (max_list[k]==min_of_max) {
x = max_list[k] = _z[j];
break;
}
}
// find the new min_of_max
min_of_max = x;
for (k=0; k<n_list; ++k) {
if (max_list[k] < min_of_max) {
min_of_max = max_list[k];
}
}
while (n_checked < n_check) {
j = size_t(double(rand())*double(_NS-1)/(double(RAND_MAX)));
x = _z[j];
if (!KST_ISNAN(x)) {
pixels.append(x);
n_checked++;
}
}
qSort(pixels);

// FIXME: this needs a z spike insensitive algorithm...
_minNoSpike = max_of_min;
_maxNoSpike = min_of_max;
_minNoSpike = pixels[size_t(n_check*per)];
_maxNoSpike = pixels[size_t(n_check*(1.0-per)-1)];

free(min_list);
free(max_list);
}

double Matrix::meanValue() const {
Expand Down
2 changes: 1 addition & 1 deletion src/libkstapp/plotitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3007,7 +3007,7 @@ void PlotItem::zoomMaximum(bool force) {
}

void PlotItem::adjustImageColorScale() {
const double per[] = {0.0, 0.0001, 0.001, 0.005, 0.02};
const double per[] = {0.0, 0.0001, 0.001, 0.005, 0.02, 0.1};
const int length = sizeof(per) / sizeof(double);

if (++_i_per >= length) {
Expand Down
2 changes: 1 addition & 1 deletion src/libkstmath/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ void Image::updatePaintObjects(const CurveRenderContext& context) {
if (image->hasColorMap()) {
int hXlXDiff = d2i(img_Hx_pix - img_Lx_pix);
int hYlYDiff = d2i(img_Hy_pix - img_Ly_pix - 1);
_image = QImage(hXlXDiff, hYlYDiff, QImage::Format_RGB32);
_image = QImage(hXlXDiff, hYlYDiff, QImage::Format_ARGB32);
//_image.fill(0);
int ih = _image.height();
int iw = _image.width();
Expand Down