Bug 87016 - attempting to fit a curve to a histogram crashes kst
Summary: attempting to fit a curve to a histogram crashes kst
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Linux
: NOR crash
Target Milestone: ---
Assignee: Netterfield
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-12 05:23 UTC by Netterfield
Modified: 2004-08-12 16:40 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Netterfield 2004-08-12 05:23:27 UTC
Version:           0.99-devel (using KDE 3.2 BRANCH >= 20040204, Mandrake Linux Cooker i586 - Cooker)
Compiler:          gcc version 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)
OS:                Linux (i686) release 2.6.3-7mdk

Create a histogram and plot it.

select plot->rmb->fit->[histogramname]
select a fit (eg, fit gaussian) then <OK>

Kst crashes.

Correct behavior: kst doesn't crash - but instead fits a gaussian to the histogram.
Comment 1 Netterfield 2004-08-12 16:04:22 UTC
CVS commit by netterfield: 

Fix for 
Bug 87017: attempting to fit a curve to a psd crashes kst

work toward fixing
Bug 87016: attempting to fit a curve to a histogram crashes kst

BaseCurves now have getXVTag() etc which returns i18n("<None>") if
	they are not defined
The fit dialog now grabs BaseCurves not VCurves, and verifies that
	getXVTag and getYVTag are not <None>.
PSD's now return the proper things in get[XY}VTag().
The PSD's x vector is now the same lenght as the YV as a temp workaround for
Bug 87018 (fit problems)

CCMAIL: 87017-done@bugs.kde.org
CCMAIL: 87016@bugs.kde.org


  M +7 -2      kstbasecurve.h   1.19
  M +5 -2      kstfitdialog_i.cpp   1.32
  M +6 -7      kstpsdcurve.cpp   1.35
  M +3 -0      kstpsdcurve.h   1.21


--- kdeextragear-2/kst/kst/kstbasecurve.h  #1.18:1.19
@@ -23,4 +23,5 @@
 #include <qstring.h>
 #include <qcolor.h>
+#include <klocale.h>
 
 /**A class for handling curves for kst
@@ -29,5 +30,5 @@
  */
 
-typedef enum {KST_VCURVE, KST_PSDCURVE, KST_EQUATIONCURVE, KST_HISTOGRAM, KST_FITCURVE} KstCurveType;
+typedef enum {KST_VCURVE, KST_PSDCURVE, KST_EQUATIONCURVE, KST_HISTOGRAM} KstCurveType;
 
 class KstBaseCurve: public KstDataObject {
@@ -91,4 +92,8 @@ public:
   virtual int samplesPerFrame() const { return 1; }
   
+  virtual QString getXVTag() const {return i18n("<None>");}
+  virtual QString getYVTag() const {return i18n("<None>");}
+  virtual QString getYETag() const {return i18n("<None>");}
+  virtual QString getXETag() const {return i18n("<None>");}
   KstPoint Point;
 

--- kdeextragear-2/kst/kst/kstfitdialog_i.cpp  #1.31:1.32
@@ -121,6 +121,6 @@ void KstFitDialogI::show_setCurve(const 
                                   const QString& strWindow) {
 
-  KstVCurvePtr  curve;
-  KstVCurveList curves = kstObjectSubList<KstDataObject, KstVCurve>(KST::dataObjectList);
+  KstBaseCurvePtr  curve;
+  KstBaseCurveList curves = kstObjectSubList<KstDataObject, KstBaseCurve>(KST::dataObjectList);
   KstPluginList c = kstObjectSubList<KstDataObject, KstPlugin>(KST::dataObjectList);
   QString new_label;
@@ -136,4 +136,7 @@ void KstFitDialogI::show_setCurve(const 
   }
 
+  if ( _xvector==i18n("<None>") ) return;
+  if ( _yvector==i18n("<None>") ) return;
+
    _tagName->setText(newFitPluginString);
 

--- kdeextragear-2/kst/kst/kstpsdcurve.cpp  #1.34:1.35
@@ -10,5 +10,5 @@
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
+ *   it under the terms of the GNU Geeral Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
@@ -167,5 +167,5 @@ void KstPSDCurve::commonConstructor(cons
   last_n_new = 0;
 
-  KstVectorPtr iv = new KstVector(in_tag+"-freq", 2);
+  KstVectorPtr iv = new KstVector(in_tag+"-freq", PSDLen);
   KST::addVectorToList(iv);
   _fVector = _outputVectors.insert(FVECTOR, iv);
@@ -221,5 +221,5 @@ KstObject::UpdateType KstPSDCurve::updat
   KstVectorPtr iv = _inputVectors[INVECTOR];
 
-  double *psd;
+  double *psd,  *f;
 
   if (KstObject::checkUpdateCounter(update_counter))
@@ -245,7 +245,9 @@ KstObject::UpdateType KstPSDCurve::updat
 
   psd = (*_sVector)->value();
+  f = (*_fVector)->value();
 
   for (i_samp = 0; i_samp < PSDLen; i_samp++) {
     psd[i_samp] = 0;
+    f[i_samp] = i_samp*0.5*Freq/( PSDLen-1 );
   }
 
@@ -336,8 +338,4 @@ KstObject::UpdateType KstPSDCurve::updat
   MeanX = MaxX/2.0;
 
-  double *f = (*_fVector)->value();
-  f[0] = 0;
-  f[1] = Freq/2.0;
-
   (*_sVector)->update(update_counter);
   (*_fVector)->update(update_counter);
@@ -424,4 +422,5 @@ void KstPSDCurve::_adjustLengths() {
     PSDLen = psdlen;
     (*_sVector)->resize(PSDLen);
+    (*_fVector)->resize(PSDLen);
 
     ALen = PSDLen*2;

--- kdeextragear-2/kst/kst/kstpsdcurve.h  #1.20:1.21
@@ -74,4 +74,7 @@ public:
   virtual void _showDialog();
 
+  virtual QString getXVTag() const {return (*_fVector)->tagName();}
+  virtual QString getYVTag() const {return (*_sVector)->tagName();}
+
 private:
   double Freq;


Comment 2 Netterfield 2004-08-12 16:40:55 UTC
CVS commit by netterfield: 

Fix for Bug 87016: attempting to fit a curve to a histogram crashes kst

Fits to histograms now work.

Histograms export slave vectors 

CCMAIL: 87016-done@bugs.kde.org


  M +36 -0     ksthistogram.cpp   1.26
  M +7 -0      ksthistogram.h   1.18
  M +18 -15    ksthsdialog_i.cpp   1.61


--- kdeextragear-2/kst/kst/ksthistogram.cpp  #1.25:1.26
@@ -31,4 +31,6 @@
 #include <klocale.h>
 
+static const QString BINS = "B";
+static const QString HIST = "H";
 KstHistogram::KstHistogram(const QString &in_tag, KstVectorPtr in_V,
                            double xmin_in, double xmax_in,
@@ -137,8 +139,23 @@ void KstHistogram::commonConstructor(con
   Color = in_color;
 
+  KstVectorPtr iv = new KstVector(in_tag+"-bins", NBins);
+  KST::addVectorToList(iv);
+  _bVector = _outputVectors.insert(BINS, iv);
+
+  iv = new KstVector(in_tag+"-sv", NBins);
+  KST::addVectorToList(iv);
+  _hVector = _outputVectors.insert(HIST, iv);
+
   update();
 }
 
 KstHistogram::~KstHistogram() {
+  _bVector = _outputVectors.end();
+  _hVector = _outputVectors.end();
+  KST::vectorList.lock().writeLock();
+  KST::vectorList.remove(_outputVectors[BINS]);
+  KST::vectorList.remove(_outputVectors[HIST]);
+  KST::vectorList.lock().writeUnlock();
+
   delete[] Bins;
 }
@@ -213,4 +230,15 @@ KstObject::UpdateType KstHistogram::upda
   else MinPosX = 1.0;
 
+  double *bins =  (*_bVector)->value();
+  double *hist =  (*_hVector)->value();
+
+  for ( i_bin = 0; i_bin<NBins; i_bin++ ) {
+    bins[i_bin] = ( double( i_bin )+ 0.5 )*W + MinX;
+    hist[i_bin] = Bins[i_bin]*Normalization;
+  }
+
+  (*_bVector)->update(update_counter);
+  (*_hVector)->update(update_counter);
+
   return (UPDATE);
 }
@@ -254,4 +282,8 @@ void KstHistogram::setNBins(int in_n_bin
   Bins = new unsigned long[in_n_bins];
   W = (MaxX - MinX)/(double)NBins;
+
+  (*_bVector)->resize(NBins);
+  (*_hVector)->resize(NBins);
+
 }
 
@@ -368,3 +400,7 @@ void KstHistogram::AutoBin(KstVectorPtr 
 }
 
+bool KstHistogram::slaveVectorsUsed() const {
+  return true;
+}
+
 // vim: ts=2 sw=2 et

--- kdeextragear-2/kst/kst/ksthistogram.h  #1.17:1.18
@@ -77,4 +77,9 @@ public:
   virtual void _showDialog();
 
+  virtual bool slaveVectorsUsed() const;
+
+  virtual QString getXVTag() const {return (*_bVector)->tagName();}
+  virtual QString getYVTag() const {return (*_hVector)->tagName();}
+
 private:
   KstVectorPtr V;
@@ -93,4 +98,6 @@ private:
 
   KstHsNormType NormMode;
+
+  KstVectorMap::Iterator _bVector, _hVector;
 };
 

--- kdeextragear-2/kst/kst/ksthsdialog_i.cpp  #1.60:1.61
@@ -203,7 +203,9 @@ bool KstHsDialogI::new_I() {
 
   KstHistogramPtr hs;
-  { // make sure this iterator falls out of scope
-    KstReadLocker ml(&KST::vectorList.lock());
-    KstVectorList::Iterator i = KST::vectorList.findTag(_vector->selectedVector());
+
+  KST::vectorList.lock().readLock();
+  KstVectorList::Iterator i =
+    KST::vectorList.findTag(_vector->selectedVector());
+  KST::vectorList.lock().readUnlock();
     if (i == KST::vectorList.end()) {
       kdFatal() << "Bug in kst: the Vector field in plotDialog (Hs) refers to "
@@ -211,4 +213,5 @@ bool KstHsDialogI::new_I() {
     }
 
+  ( *i )->readLock();
     hs = new KstHistogram(tag_name, *i, new_min, new_max,
                           new_n_bins, new_norm_mode,
@@ -219,5 +222,4 @@ bool KstHsDialogI::new_I() {
     hs->setLineStyle(_curveAppearance->lineStyle());
     hs->Point.setType(_curveAppearance->pointType());
-  }
 
   if (hs) {
@@ -254,4 +256,5 @@ bool KstHsDialogI::new_I() {
       }
     }
+    ( *i )->readUnlock();
 
     KST::dataObjectList.lock().writeLock();