[Kst] branches/work/kst/portto4/kst/src

Barth Netterfield netterfield at astro.utoronto.ca
Thu Oct 23 16:55:10 CEST 2008


SVN commit 875177 by netterfield:

Encourage histograms to not crash kst when read from file or from command line.
They were being created with invalid slave vectors, so resize killed thing.
Also, set the name in the constructor, not in change(...).



 M  +1 -7      libkstapp/commandlineparser.cpp  
 M  +30 -20    libkstmath/histogram.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.cpp #875176:875177
@@ -250,7 +250,6 @@
       CreatePlotForCurve *cmd = new CreatePlotForCurve();
       cmd->createItem();
       pi = static_cast<PlotItem*> ( cmd->item() );
-      //pi = new PlotItem(_document->currentView()); xxxx
 
       pi->setName ( plot_name );
       _plotNames.append(plot_name);
@@ -422,15 +421,10 @@
         DataSourcePtr ds = DataSource::findOrLoadSource ( _document->objectStore(), file );
 
         DataVectorPtr hv = createOrFindDataVector ( field, ds );
-
         Q_ASSERT ( _document && _document->objectStore() );
         HistogramPtr histogram = _document->objectStore()->createObject<Histogram> ();
 
-        histogram->setVector ( hv );
-        histogram->setXRange ( -1.0, 1.0 );
-        histogram->setNumberOfBins ( 60 );
-        histogram->setNormalizationType ( Histogram::Number );
-        histogram->setRealTimeAutoBin ( true );
+        histogram->change(hv, -1, 1, 60, Histogram::Number, true);
 
         histogram->writeLock();
         histogram->update ();
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.cpp #875176:875177
@@ -42,6 +42,27 @@
   setRealTimeAutoBin(false);
   _typeString = staticTypeString;
   _type = "Histogram";
+
+  // _Bins, _bVector and _hVector need to be valid, 
+  // so initialize them as size 2 (where 2 is a small valid number)
+  _Bins = new unsigned long[2];
+
+  VectorPtr v = store->createObject<Vector>();
+  v->setProvider(this);
+  v->setSlaveName("bin");
+  v->resize(2);
+  _bVector = _outputVectors.insert(BINS, v).value();
+
+  v = store->createObject<Vector>();
+  v->setProvider(this);
+  v->setSlaveName("num");
+  v->resize(2);
+  _hVector = _outputVectors.insert(HIST, v).value();
+
+  _shortName = "H"+QString::number(_hnum);
+  if (_hnum>max_hnum) 
+    max_hnum = _hnum;
+  _hnum++;
 }
 
 
@@ -54,7 +75,6 @@
 
   _NormalizationMode = in_norm_mode;
   _realTimeAutoBin = realTimeAutoBin;
-  _Bins = 0L;
   _NumberOfBins = 0;
 
   _inputVectors[RAWVECTOR] = in_V;
@@ -75,29 +95,14 @@
   if (_NumberOfBins < 2) {
     _NumberOfBins = 2;
   }
+
+  delete[] _Bins;
   _Bins = new unsigned long[_NumberOfBins];
   _NS = 3 * _NumberOfBins + 1;
 
-  Q_ASSERT(store());
-  VectorPtr v = store()->createObject<Vector>();
+  _bVector->resize(_NumberOfBins);
+  _hVector->resize(_NumberOfBins);
 
-  v->setProvider(this);
-  v->setSlaveName("bin");
-  v->resize(_NumberOfBins);
-  _bVector = _outputVectors.insert(BINS, v).value();
-
-  v = store()->createObject<Vector>();
-
-  v->setProvider(this);
-  v->setSlaveName("num");
-  v->resize(_NumberOfBins);
-  _hVector = _outputVectors.insert(HIST, v).value();
-
-  _shortName = "H"+QString::number(_hnum);
-  if (_hnum>max_hnum) 
-    max_hnum = _hnum;
-  _hnum++;
-
   setDirty();
 }
 
@@ -234,6 +239,7 @@
     _MaxX = xmax_in + 1.0;
   }
   _W = (_MaxX - _MinX)/double(_NumberOfBins);
+  setDirty();
 }
 
 
@@ -243,9 +249,11 @@
   }
   if (_NumberOfBins != in_n_bins) {
     _NumberOfBins = in_n_bins;
+
     delete[] _Bins;
     _Bins = new unsigned long[_NumberOfBins];
     memset(_Bins, 0, _NumberOfBins*sizeof(*_Bins));
+
     _bVector->resize(_NumberOfBins);
     _hVector->resize(_NumberOfBins);
   }
@@ -264,6 +272,7 @@
   if (new_v) {
     connect(new_v, SIGNAL(updated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
     _inputVectors[RAWVECTOR] = new_v;
+    setDirty();
   }
 }
 
@@ -366,6 +375,7 @@
 
 void Histogram::setRealTimeAutoBin(bool autoBin) {
   _realTimeAutoBin = autoBin;
+  setDirty();
 }
 
 


More information about the Kst mailing list