[Kst] extragear/graphics/kst/src
Barth Netterfield
netterfield at astro.utoronto.ca
Fri Oct 6 03:25:26 CEST 2006
SVN commit 592875 by netterfield:
Auto smart scale for images. 'i' cycles between levels.
M +18 -24 libkst/kstmatrix.cpp
M +4 -9 libkst/kstmatrix.h
M +32 -0 libkstapp/kst2dplot.cpp
M +5 -0 libkstapp/kst2dplot.h
M +15 -2 libkstmath/kstimage.cpp
M +1 -0 libkstmath/kstimage.h
--- trunk/extragear/graphics/kst/src/libkst/kstmatrix.cpp #592874:592875
@@ -50,8 +50,6 @@
_editable = false;
_saveable = false;
- _lastUpdateSmartThreshold = -1;
-
// must create scalars before setting tag name
createScalars();
setTagName(in_tag);
@@ -141,7 +139,6 @@
_z[index] = z;
return true;
}
-
double KstMatrix::minValue() const {
return _statScalars["min"]->value();
@@ -152,17 +149,22 @@
return _statScalars["max"]->value();
}
-double KstMatrix::minValueNoSpike() {
-/* if (noSpikeRangeDirty()) {
- calcNoSpikeRange();
- }*/
+double KstMatrix::minValueNoSpike() const {
+ // FIXME: it is expensive to calcNoSpikeRange
+ // so we have chosen here to only call it expicitly
+ // and no attempt is made to check if it is still up to date...
+ // It would be better to have these calls call
+ // calcNoSpikeRange iff the values were obsolete.
return _minNoSpike;
}
-double KstMatrix::maxValueNoSpike() {
-/* if (noSpikeRangeDirty()) {
- calcNoSpikeRange();
- }*/
+double KstMatrix::maxValueNoSpike() const {
+ // FIXME: it is expensive to calcNoSpikeRange
+ // so we have chosen here to only call it expicitly
+ // and no attempt is made to check if it is still up to date...
+ // It would be better to have these calls call
+ // calcNoSpikeRange iff the values were obsolete.
+
return _maxNoSpike;
}
@@ -186,7 +188,6 @@
if (n_notnan==0) {
_minNoSpike = 0;
_maxNoSpike = 0;
- _lastUpdateSmartThreshold = _lastUpdateCounter;
return;
}
@@ -194,8 +195,6 @@
per *= (double)n_notnan/(double)_NS;
max_n *= (double)_NS/(double)n_notnan;
- printf("%g %d, %d\n", per, n_notnan, _NS);
-
n_skip = (double)_NS/max_n;
if (n_skip<1.0) n_skip = 1.0;
@@ -213,11 +212,10 @@
}
min_of_max = -1E+300;
max_of_min = 1E+300;
-
+
i = n_list;
for (j=0; j<_NS; j=i*n_skip, i++) {
if (_z[j] < max_of_min) { // member for the min list
- //printf("******** z: %g max_of_min: %g\n", _z[j], max_of_min);
// replace max of min with the new value
for (k=0; k<n_list; k++) {
if (min_list[k]==max_of_min) {
@@ -259,13 +257,9 @@
// which will be slow.
_minNoSpike = max_of_min;
_maxNoSpike = min_of_max;
- _lastUpdateSmartThreshold = _lastUpdateCounter;
-}
-bool KstMatrix::noSpikeRangeDirty() {
- // FIXME: this only verifies that we haven't re-calced this update cycle - not
- // whether we re-calced since the last _dirty....
- return (_lastUpdateCounter != _lastUpdateSmartThreshold);
+ free(min_list);
+ free(max_list);
}
double KstMatrix::meanValue() const {
@@ -279,8 +273,8 @@
int KstMatrix::numNew() const {
return _numNew;
}
-
-
+
+
void KstMatrix::resetNumNew() {
_numNew = 0;
}
--- trunk/extragear/graphics/kst/src/libkst/kstmatrix.h #592874:592875
@@ -59,12 +59,12 @@
// return some stats on the z values
double minValue() const;
double maxValue() const;
-
+
// spike insensitive values
void calcNoSpikeRange(double per = 0.005);
- double maxValueNoSpike();
- double minValueNoSpike();
-
+ double maxValueNoSpike() const;
+ double minValueNoSpike() const;
+
// return mean of the z values
double meanValue() const;
@@ -136,7 +136,6 @@
bool _editable : 1;
bool _saveable : 1;
- int _lastUpdateSmartThreshold;
double _minNoSpike;
double _maxNoSpike;
@@ -156,10 +155,6 @@
// for resizing the internal array _z only
virtual bool resizeZ(int sz, bool reinit = true);
- // for smart range calculation..
- bool noSpikeRangeDirty();
-
-
// returns -1 if (x,y) is out of bounds
int zIndex(int x, int y);
--- trunk/extragear/graphics/kst/src/libkstapp/kst2dplot.cpp #592874:592875
@@ -651,6 +651,8 @@
_autoTickYLast = 0;
_isLogLast = false;
+ _i_per = 0;
+
setTagName(in_tag);
_isTied = false;
@@ -906,6 +908,12 @@
_yScaleMode = scalemode_in;
}
+void Kst2DPlot::autoSetColorScaleSpikeInsensitive(double per) {
+ KstImageList images = kstObjectSubList<KstBaseCurve,KstImage>(Curves);
+ for (KstImageList::Iterator i = images.begin(); i != images.end(); ++i) {
+ (*i)->setThresholdToSpikeInsensitive(per);
+ }
+}
bool Kst2DPlot::addCurve(KstBaseCurvePtr incurve) {
if (!Curves.contains(incurve)) {
@@ -3362,6 +3370,9 @@
case ZOOM_XY_MODES:
setXScaleMode(mode);
setYScaleMode(modeExtra);
+// if (modeExtra==NOSPIKE) { // guess this is what they wanted...
+// autoSetColorScaleSpikeInsensitive();
+// }
break;
case ZOOM_Y_LOCAL_MAX:
zoomSelfYLocalMax(false);
@@ -3508,6 +3519,10 @@
this, SLOT(menuYNormalize()), SHIFT + Key_N);
submenu->insertItem(i18n("Toggle Log Y Axis"),
this, SLOT(menuYLogSlot()), Key_L);
+ submenu->insertSeparator();
+ submenu->insertItem(i18n("Next &Image Color Scale"),
+ this, SLOT(menuNextColorScale()), Key_I);
+
submenu = new KPopupMenu(menu);
menu->insertItem(i18n("&Scroll"), submenu);
submenu->insertItem(i18n("Left"), this, SLOT(menuMoveLeft()), Key_Left);
@@ -4619,6 +4634,12 @@
}
}
+void Kst2DPlot::menuNextColorScale() {
+ if (_menuView) {
+ nextColorScale();
+ _menuView->paint();
+ }
+}
void Kst2DPlot::menuXZoomIn() {
if (_menuView) {
@@ -5107,11 +5128,19 @@
void Kst2DPlot::zoomSpikeInsensitiveMax(KstViewWidget *view) {
setXScaleMode(NOSPIKE);
setYScaleMode(NOSPIKE);
+ //autoSetColorScaleSpikeInsensitive();
KstApp::inst()->tiedZoomMode(ZOOM_XY_MODES, true, 0.0, NOSPIKE, NOSPIKE, view, tagName());
pushScale();
setDirty();
}
+void Kst2DPlot::nextColorScale() {
+ const double per[5] = {0.0, 0.0001, 0.001, 0.005, 0.02};
+ if (++_i_per>=5) {
+ _i_per = 0;
+ }
+ autoSetColorScaleSpikeInsensitive(per[_i_per]);
+}
void Kst2DPlot::keyPressEvent(QWidget *vw, QKeyEvent *e) {
KstViewWidget *view = static_cast<KstViewWidget*>(vw);
@@ -5175,6 +5204,9 @@
case Key_S:
zoomSpikeInsensitiveMax(view);
break;
+ case Key_I:
+ nextColorScale();
+ break;
case Key_Z:
zoomToggle();
cancelZoom(view);
--- trunk/extragear/graphics/kst/src/libkstapp/kst2dplot.h #592874:592875
@@ -124,6 +124,8 @@
void clearCurves();
void setXScaleMode(KstScaleModeType scalemode);
void setYScaleMode(KstScaleModeType scalemode);
+ void autoSetColorScaleSpikeInsensitive(double per);
+ void nextColorScale();
void pushAdjustLineWidth(int adjustment);
void popLineWidth();
@@ -430,6 +432,7 @@
void menuZoomSpikeInsensitiveMax();
void menuNextMarker();
void menuPrevMarker();
+ void menuNextColorScale();
void timezoneChanged(const QString& tz, int utcOffset);
@@ -598,6 +601,8 @@
int _xMajorTicks;
int _yMajorTicks;
+
+ int _i_per; // index for next image color range
KstPlotLabel *_xLabel, *_yLabel, *_topLabel, *_xTickLabel, *_yTickLabel, *_fullTickLabel;
--- trunk/extragear/graphics/kst/src/libkstmath/kstimage.cpp #592874:592875
@@ -294,16 +294,29 @@
void KstImage::setUpperThreshold(double z) {
setDirty();
- _zLower = z;
+ _zUpper = z;
}
void KstImage::setLowerThreshold(double z) {
setDirty();
- _zUpper = z;
+ _zLower = z;
}
+void KstImage::setThresholdToSpikeInsensitive(double per) {
+ if (per==0) {
+ setAutoThreshold(true);
+ } else {
+ matrix()->writeLock();
+ matrix()->calcNoSpikeRange(per);
+ matrix()->unlock();
+ setLowerThreshold(matrix()->minValueNoSpike());
+ setUpperThreshold(matrix()->maxValueNoSpike());
+ setAutoThreshold(false);
+ }
+}
+
void KstImage::changeToColorOnly(const QString &in_tag, KstMatrixPtr in_matrix,
double lowerZ, double upperZ, bool autoThreshold, KPalette* pal) {
setTagName(in_tag);
--- trunk/extragear/graphics/kst/src/libkstmath/kstimage.h #592874:592875
@@ -60,6 +60,7 @@
virtual void setUpperThreshold(double z);
virtual void setLowerThreshold(double z);
virtual void setAutoThreshold(bool yes);
+ virtual void setThresholdToSpikeInsensitive(double per = 0.005);
virtual double upperThreshold() const { return _zUpper; }
More information about the Kst
mailing list