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

Peter Kümmel syntheticpp at gmx.net
Thu Aug 26 18:06:05 CEST 2010


I've changed the DataSource API by renaming the type 'Optional' into 'DataInfo'
which is much more consistent because we already have a ReadInfo type.

But I've patched the fisimage only blind without the eyes of the compiler,
so don't wonder if it compiles not any more it could be I've overseen something,
but the changs should be minimal.

Peter



On 18.08.2010 04:51, Barth Netterfield wrote:
> SVN commit 1164944 by netterfield:
> 
> Port the fitsimage data source to new api.
> There are still some deficiencies (like reading x/y scaling and units)
> 
> 
> 
>  M  +3 -3      datasources/datasources.pro  
>  M  +140 -152  datasources/fitsimage/fitsimage.cpp  
>  M  +10 -15    datasources/fitsimage/fitsimage.h  
>  M  +2 -1      datasources/fitsimage/fitsimage.pro  
>  M  +1 -1      libkst/datasource.h  
> 
> 
> --- branches/work/kst/portto4/kst/src/datasources/datasources.pro #1164943:1164944
> @@ -9,9 +9,9 @@
>  
>  LibExists(cfitsio) {
>      message(CFITSIO configured.  Plugins will be built.)
> -#    SUBDIRS += fitsimage lfiio healpix planckIDEF
> -#    CONFIG += link_pkgconfig
> -#    PKGCONFIG += cfitsio
> +    SUBDIRS += fitsimage 
> +    !win32:CONFIG += link_pkgconfig
> +    !win32:PKGCONFIG += cfitsio
>  }
>  
>  LibExists(getdata) {
> --- branches/work/kst/portto4/kst/src/datasources/fitsimage/fitsimage.cpp #1164943:1164944
> @@ -12,12 +12,15 @@
>  #include "fitsimage.h"
>  
>  #include <QXmlStreamWriter>
> -//#include <fitsio.h>
> +
>  #include <math.h>
>  
>  #include "kst_i18n.h"
>  
> +using namespace Kst;
> +
>  static const QString fitsTypeString = I18N_NOOP("FITS image");
> +static const QString DefaultMatrixName = I18N_NOOP("1");
>  
>  class FitsImageSource::Config {
>    public:
> @@ -39,141 +42,107 @@
>      }
>  };
>  
> +//
> +// Matrix interface
> +//
>  
> -FitsImageSource::FitsImageSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e)
> -: Kst::DataSource(store, cfg, filename, type, None), _config(0L) {
> -  _fptr = 0L;
> -  _valid = false;
>  
> -  if (!type.isEmpty() && type != fitsTypeString) {
> -    return;
> -  }
> +class DataInterfaceFitsImageMatrix : public DataSource::DataInterface<DataMatrix> {
> +public:
>  
> -  _config = new FitsImageSource::Config;
> -  _config->read(cfg, filename);
> -  if (!e.isNull()) {
> -    _config->load(e);
> -  }
> +  DataInterfaceFitsImageMatrix(fitsfile **fitsfileptr) : _fitsfileptr(fitsfileptr) {}
>  
> -  if (init()) {
> -    _valid = true;
> -  }
> +  // read one element
> +  int read(const QString&, DataMatrix::ReadInfo&);
>  
> -  update();
> -}
> +  // named elements
> +  QStringList list() const { return _matrixList; }
> +  bool isListComplete() const { return true; }
> +  bool isValid(const QString&) const;
>  
> +  // T specific
> +  const DataMatrix::Optional optional(const QString&) const;
> +  void setOptional(const QString&, const DataMatrix::Optional&) {}
>  
> +  // meta data
> +  QMap<QString, double> metaScalars(const QString&) { return QMap<QString, double>(); }
> +  QMap<QString, QString> metaStrings(const QString&) { return QMap<QString, QString>(); }
>  
> -FitsImageSource::~FitsImageSource() {
> -  int status;
> -  if (_fptr) {
> -    fits_close_file( _fptr, &status );
> -    _fptr = 0L;
> -  }
> -}
>  
> -const QString& FitsImageSource::typeString() const {
> -  return fitsTypeString;
> -}
> +  // no interface
> +  fitsfile **_fitsfileptr;
> +  QStringList _matrixList;
>  
> +  void init();
> +  void clear();
> +};
>  
> -
> -bool FitsImageSource::reset() {
> -  init();
> -  return true;
> -}
> -
> -
> -bool FitsImageSource::init() {
> -  int status = 0;
> -
> +void DataInterfaceFitsImageMatrix::clear()
> +{
>    _matrixList.clear();
> -  _fieldList.clear();
> -  _frameCount = 0;
> -
> -  fits_open_image( &_fptr, _filename.latin1( ), READONLY, &status );
> -  if (status == 0) {
> -    _fieldList.append("INDEX");
> -    _fieldList.append("1");
> -    _matrixList.append("1");
> -    return update() == Kst::Object::UPDATE;
> -  } else {
> -    fits_close_file( _fptr, &status );
> -    _fptr = 0L;
>    }
> -  return false;
> -}
>  
> -
> -Kst::Object::UpdateType FitsImageSource::update() {
> -  long n_axes[3];
> -  int status = 0;
> -
> -  fits_get_img_size( _fptr,  2,  n_axes,  &status );
> -
> -  int newNF = n_axes[0]*n_axes[1];
> -  bool isnew = newNF != _frameCount;
> -
> -  _frameCount = newNF;
> -
> -  return (isnew ? Kst::Object::UPDATE : Kst::Object::NO_CHANGE);
> +void DataInterfaceFitsImageMatrix::init()
> +{
> +  _matrixList.append(DefaultMatrixName); // FIXME: fits vectirs have real names...
>  }
>  
> -
> -bool FitsImageSource::matrixDimensions( const QString& matrix, int* xDim, int* yDim) {
> +const DataMatrix::Optional DataInterfaceFitsImageMatrix::optional(const QString& matrix) const
> +{
>    long n_axes[3];
>    int status = 0;
>  
> -  if (!_matrixList.contains(matrix)) {
> -    return false;
> +  if ( !*_fitsfileptr || !_matrixList.contains( matrix ) ) {
> +    return DataMatrix::Optional();
>    }
>  
> -  fits_get_img_size( _fptr,  2,  n_axes,  &status );
> +  fits_get_img_size( *_fitsfileptr,  2,  n_axes,  &status );
>  
>    if (status) {
> -    return false;
> +    return DataMatrix::Optional();
>    }
>  
> -  *xDim = n_axes[0];
> -  *yDim = n_axes[1];
> +  DataMatrix::Optional opt;
> +  opt.samplesPerFrame = 1;
> +  opt.xSize = n_axes[0];
> +  opt.ySize = n_axes[1];
>  
> -  return true;
> +  return opt;
>  }
>  
> +//int FitsImageSource::readMatrix(Kst::MatrixData* data, const QString& field, int xStart,
> +//                                     int yStart, int xNumSteps, int yNumSteps) {
>  
> -int FitsImageSource::readMatrix(Kst::MatrixData* data, const QString& field, int xStart,
> -                                     int yStart, int xNumSteps, int yNumSteps) {
> +int DataInterfaceFitsImageMatrix::read(const QString& field, DataMatrix::ReadInfo& p) {
>    long n_axes[2],  fpixel[2] = {1, 1};
>    double nullval = NAN;
>    double blank = 0.0;
>    long n_elements;
> -  int i,  px, py,  anynull,  ni;
> -  int y0, y1, x0, x1;
> -  double *z;
> +  int px, py,  anynull;
>    int status = 0;
>    double *buffer;
>  
> -  if (!_matrixList.contains(field)) {
> -    return false;
> +  if ((!*_fitsfileptr) || (!_matrixList.contains(field))) {
> +    return 0;
>    }
>  
> -  fits_get_img_size( _fptr,  2,  n_axes,  &status );
> +  fits_get_img_size( *_fitsfileptr,  2,  n_axes,  &status );
>  
>    if (status) {
> -    return false;
> +    return 0;
>    }
>  
>    n_elements = n_axes[0]*n_axes[1];
>    buffer = (double*)malloc(n_elements*sizeof(double));
>  
> -  fits_read_pix( _fptr,  TDOUBLE, fpixel, n_elements, &nullval, buffer, &anynull,  &status );
> +  fits_read_pix( *_fitsfileptr,  TDOUBLE, fpixel, n_elements, &nullval, buffer, &anynull,  &status );
>  
>    // Check to see if the file is using the BLANK keyword
>    // to indicate the NULL value for the image.  This is
>    // not correct useage for floating point images, but 
>    // it is used frequently nonetheless... 
>    char charBlank[] = "BLANK";
> -  fits_read_key(_fptr, TDOUBLE, charBlank, &blank, NULL, &status);
> +  fits_read_key(*_fitsfileptr, TDOUBLE, charBlank, &blank, NULL, &status);
>    if (status) { //keyword does not exist, ignore it
>      status = 0;
>    } else { //keyword is used, replace pixels with this value
> @@ -185,19 +154,19 @@
>      }
>    }
>  
> -  y0 = yStart;
> -  y1 = yStart+yNumSteps;
> +  int y0 = p.yStart;
> +  int y1 = p.yStart + p.yNumSteps;
> +  int x0 = p.xStart;
> +  int x1 = p.xStart + p.xNumSteps;
> +  double* z = p.data->z;
>  
> -  x0 = xStart;
> -  x1 = xStart + xNumSteps;
> -  ni = xNumSteps * yNumSteps - 1;
> +  int ni = p.xNumSteps * p.yNumSteps - 1;
>  
> -  i = 0;
> +  int i = 0;
>  
> -  z = data->z;
> -  if (field=="1") {
> -    for (px = xStart; px < x1; px++) {
> -      for (py = y1-1; py >= yStart; py--) {
> +  if (field==DefaultMatrixName) {
> +    for (px = p.xStart; px < x1; px++) {
> +      for (py = y1-1; py >= p.yStart; py--) {
>          z[ni - i] = buffer[px + py*n_axes[0]];
>          i++;
>        }
> @@ -225,10 +194,10 @@
>  //   fits_read_key(_fptr, TDOUBLE, charCRPix2, &cy, NULL, &status);
>  // 
>  //   if (status) {
> -    data->xMin = x0;
> -    data->yMin = y0;
> -    data->xStepSize = 1;
> -    data->yStepSize = 1;
> +    p.data->xMin = x0;
> +    p.data->yMin = y0;
> +    p.data->xStepSize = 1;
> +    p.data->yStepSize = 1;
>  //   } else {
>  //     dx = fabs(dx);
>  //     dy = fabs(dy);
> @@ -242,63 +211,100 @@
>  }
>  
>  
> -int FitsImageSource::readField(double *v, const QString& field, int s, int n) {
> -  int i = 0;
> -
> -  if (!_fieldList.contains(field)) {
> -    return false;
> +bool DataInterfaceFitsImageMatrix::isValid(const QString& field) const {
> +  return  _matrixList.contains( field );
>    }
>  
> -  if (field=="INDEX") {
> -    for (i = 0; i < n; i++) {
> -      v[i] = i+s;
> -    }
> -  } else if (field=="1") {
> -    double *buffer;
> -    long fpixel[2] = {1, 1};
> -    double nullval = 0;
> -    int status = 0, anynull;
>  
> -    buffer = (double*)malloc(_frameCount*sizeof(double));
> +FitsImageSource::FitsImageSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e)
> +: Kst::DataSource(store, cfg, filename, type), _config(0L),
> +  im(new DataInterfaceFitsImageMatrix(&_fptr))
> +{
> +  setInterface(im);
>  
> -    fits_read_pix( _fptr,  TDOUBLE, fpixel, _frameCount, &nullval, buffer, &anynull,  &status );
> +  setUpdateType(None);
>  
> -    for (i = 0; i < n; i++) {
> -      v[i] = buffer[i+s];
> +  _fptr = 0L;
> +  _valid = false;
> +
> +  if (!type.isEmpty() && type != fitsTypeString) {
> +    return;
>      }
>  
> -    free( buffer );
> +  _config = new FitsImageSource::Config;
> +  _config->read(cfg, filename);
> +  if (!e.isNull()) {
> +    _config->load(e);
> +  }
>  
> +  if (init()) {
> +    _valid = true;
>    }
>  
> -  return(i);
> +  registerChange();
>  }
>  
>  
> -bool FitsImageSource::isValidField(const QString& field) const {
> -  return  _fieldList.contains( field );
> +
> +FitsImageSource::~FitsImageSource() {
> +  int status;
> +  if (_fptr) {
> +    fits_close_file( _fptr, &status );
> +    _fptr = 0L;
>  }
> +  delete _config;
> +  _config = 0L;
> +}
>  
> +const QString& FitsImageSource::typeString() const {
> +  return fitsTypeString;
> +}
>  
> -bool FitsImageSource::isValidMatrix(const QString& field) const {
> -  return  _matrixList.contains( field );
> +
> +
> +void FitsImageSource::reset() {
> +  init();
> +  Object::reset();
>  }
>  
> +bool FitsImageSource::init() {
> +  int status = 0;
> +  fits_open_image( &_fptr, _filename.toAscii(), READONLY, &status );
>  
> -int FitsImageSource::samplesPerFrame(const QString &field) {
> -  Q_UNUSED(field)
> -  return 1;
> +  im->clear();
> +  if (status == 0) {
> +    im->init();
> +
> +    registerChange();
> +    return true;
> +  } else {
> +    fits_close_file( _fptr, &status );
> +    _fptr = 0L;
> +    return false;
>  }
> +}
>  
>  
> -int FitsImageSource::frameCount(const QString& field) const {
> -  Q_UNUSED(field)
> -  return _frameCount;
> +Kst::Object::UpdateType FitsImageSource::internalDataSourceUpdate() {
> +  /*
> +  long n_axes[3];
> +  int status = 0;
> +
> +  fits_get_img_size( _fptr,  2,  n_axes,  &status );
> +
> +  int newNF = n_axes[0]*n_axes[1];
> +  bool isnew = newNF != _frameCount;
> +
> +  _frameCount = newNF;
> +
> +  */
> +  //return (isnew ? Kst::Object::Updated : Kst::Object::NoChange);
> +  return (Kst::Object::NoChange);
>  }
>  
>  
>  bool FitsImageSource::isEmpty() const {
> -  return _frameCount < 1;
> +  return im->optional(DefaultMatrixName).xSize < 1;
>  }
>  
>  
> @@ -312,24 +318,6 @@
>  }
>  
>  
> -int FitsImageSource::readScalar(double &S, const QString& scalar) {
> -  if (scalar == "FRAMES") {
> -    S = _frameCount;
> -    return 1;
> -  }
> -  return 0;
> -}
> -
> -
> -int FitsImageSource::readString(QString &S, const QString& string) {
> -  if (string == "FILE") {
> -    S = _filename;
> -    return 1;
> -  }
> -  return 0;
> -}
> -
> -
>  QString FitsImagePlugin::pluginName() const { return "FITS Image Source Reader"; }
>  QString FitsImagePlugin::pluginDescription() const { return "FITS Image Source Reader"; }
>  
> @@ -361,7 +349,7 @@
>      *typeSuggestion = fitsTypeString;
>    }
>    if ( understands(cfg, filename) ) {
> -    matrixList.append( "1" );
> +    matrixList.append( DefaultMatrixName );
>    }
>    return matrixList;
>  
> @@ -433,8 +421,8 @@
>      *typeSuggestion = fitsTypeString;
>    }
>    if (understands(cfg, filename)) {
> -    fieldList.append("INDEX");
> -    fieldList.append( "1" );
> +    //fieldList.append("INDEX");
> +    //fieldList.append( DefaultMatrixName );
>    }
>    return fieldList;
>  }
> @@ -447,7 +435,7 @@
>    int ret_val = 0;
>    int naxis;
>  
> -  fits_open_image( &ffits, filename.latin1( ), READONLY, &status );
> +  fits_open_image( &ffits, filename.toAscii(), READONLY, &status );
>    fits_get_img_dim( ffits, &naxis,  &status);
>  
>    if ((status == 0) && (naxis > 1)) {
> --- branches/work/kst/portto4/kst/src/datasources/fitsimage/fitsimage.h #1164943:1164944
> @@ -15,8 +15,12 @@
>  
>  #include <datasource.h>
>  #include <dataplugin.h>
> -#include <libcfitsio0/fitsio.h>
>  
> +//#include <libcfitsio0/fitsio.h>
> +#include <fitsio.h>
> +
> +class DataInterfaceFitsImageMatrix;
> +
>  class FitsImageSource : public Kst::DataSource {
>    Q_OBJECT
>  
> @@ -26,19 +30,10 @@
>      ~FitsImageSource();
>  
>      bool init();
> -    bool reset();
> +    virtual void reset();
>  
> -    Kst::Object::UpdateType update();
> +    Kst::Object::UpdateType internalDataSourceUpdate();
>  
> -    bool matrixDimensions( const QString& matrix, int* xDim, int* yDim);
> -    int readMatrix(Kst::MatrixData* data, const QString& matrix, int xStart, int yStart, int xNumSteps, int yNumSteps);
> -    bool isValidMatrix(const QString& field) const;
> -
> -    int readField(double *v, const QString &field, int s, int n);
> -    bool isValidField(const QString &field) const;
> -
> -    int samplesPerFrame(const QString &field);
> -    int frameCount(const QString& field = QString::null) const;
>      bool isEmpty() const;
>      QString fileType() const;
>  
> @@ -48,13 +43,13 @@
>  
>      class Config;
>  
> -    int readScalar(double &S, const QString& scalar);
> -    int readString(QString &S, const QString& string);
> -
>    private:
>      int _frameCount;
>      fitsfile *_fptr;
>      mutable Config *_config;
> +
> +    DataInterfaceFitsImageMatrix* im;
> +
>  };
>  
>  
> --- branches/work/kst/portto4/kst/src/datasources/fitsimage/fitsimage.pro #1164943:1164944
> @@ -1,4 +1,5 @@
> -include($$PWD/../../../kst.pri)
> +TOPOUT_REL=../../..
> +include($$PWD/$$TOPOUT_REL/kst.pri)
>  include($$PWD/../../../datasourceplugin.pri)
>  
>  TARGET = $$kstlib(kst2data_fitsimage)
> --- branches/work/kst/portto4/kst/src/libkst/datasource.h #1164943:1164944
> @@ -179,7 +179,7 @@
>      virtual bool isEmpty() const;
>  
>      /** Reset to initial state of the source, just as though no data had been
> -     *  read and the file had just been opened.  Return true on success.
> +     *  read and the file had just been opened.
>       */
>      virtual void reset();
>  
> _______________________________________________
> Kst mailing list
> Kst at kde.org
> https://mail.kde.org/mailman/listinfo/kst
> 


More information about the Kst mailing list