[Kst] extragear/graphics/kst/kst/datasources/healpix

Ted Kisner tskisner.public at gmail.com
Tue Nov 1 22:47:19 CET 2005


SVN commit 476734 by tskisner:

Add support for saving/loading a healpix image from a kst file.

 M  +89 -19    healpix.cpp  
 M  +3 -1      healpix_source.h  


--- trunk/extragear/graphics/kst/kst/datasources/healpix/healpix.cpp #476733:476734
@@ -44,8 +44,7 @@
 #define HPUNIT_RADEC 0
 #define HPUNIT_LATLON 1
  
-HealpixSource::HealpixSource(KConfig *cfg, const QString& filename, const QString& type)
-: KstDataSource(cfg, filename, type) {
+HealpixSource::HealpixSource(KConfig *cfg, const QString& filename, const QString& type, const QDomElement& e) : KstDataSource(cfg, filename, type) {
   int ret;
   size_t poff;
    
@@ -80,7 +79,12 @@
       _vecTheta = 0;
       _vecPhi = 0;
       _vecQU = false;
+      kstdDebug() << "HEALPIX:  Calling loadConfig from constructor" << endl;
       loadConfig(cfg);
+      if (!e.isNull()) {
+        kstdDebug() << "HEALPIX:  Calling load from constructor" << endl;
+        load(e);
+      }
       
       // populate the metadata
       QString metaVal;
@@ -160,7 +164,7 @@
       healpix_strarr_free(_names, HEALPIX_FITS_MAXCOL);
       healpix_strarr_free(_units, HEALPIX_FITS_MAXCOL);
     }
-    
+    kstdDebug() << "HEALPIX:  constructor finished" << endl;
   }
 }
 
@@ -845,25 +849,86 @@
 
 void HealpixSource::save(QTextStream &ts, const QString& indent) {
   KstDataSource::save(ts, indent);
-  ts << indent << "<x dim=\"" << _nX << "\"/>" << endl;
-  ts << indent << "<y dim=\"" << _nY << "\"/>" << endl;
-  ts << indent << "<theta auto=\"" << _autoTheta << "\"/>" << endl;
-  ts << indent << "<theta units=\"" << _thetaUnits << "\"/>" << endl;
-  ts << indent << "<theta min=\"" << _thetaMin << "\"/>" << endl;
-  ts << indent << "<theta max=\"" << _thetaMax << "\"/>" << endl;
-  ts << indent << "<phi auto=\"" << _autoPhi << "\"/>" << endl;
-  ts << indent << "<phi units=\"" << _phiUnits << "\"/>" << endl;
-  ts << indent << "<phi min=\"" << _phiMin << "\"/>" << endl;
-  ts << indent << "<phi max=\"" << _phiMax << "\"/>" << endl;
-  ts << indent << "<vector theta=\"" << _vecTheta << "\"/>" << endl;
-  ts << indent << "<vector phi=\"" << _vecPhi << "\"/>" << endl;
-  ts << indent << "<vector degrade=\"" << _vecDegrade << "\"/>" << endl;
-  ts << indent << "<vector auto=\"" << _autoMag << "\"/>" << endl;
-  ts << indent << "<vector max=\"" << _maxMag << "\"/>" << endl;
-  ts << indent << "<vector QU=\"" << _vecQU << "\"/>" << endl;
+  ts << indent << "<dim x=\"" << _nX << "\" y=\"" << _nY << "\"/>" << endl;
+  ts << indent << "<theta auto=\"" << _autoTheta << "\" units=\"" << _thetaUnits << "\" min=\"" << _thetaMin << "\" max=\"" << _thetaMax << "\"/>" << endl;
+  ts << indent << "<phi auto=\"" << _autoPhi << "\" units=\"" << _phiUnits << "\" min=\"" << _phiMin << "\" max=\"" << _phiMax << "\"/>" << endl;
+  ts << indent << "<vector theta=\"" << _vecTheta << "\" phi=\"" << _vecPhi << "\" degrade=\"" << _vecDegrade << "\" auto=\"" << _autoMag << "\" max=\"" << _maxMag << "\" QU=\"" << _vecQU << "\"/>" << endl;
   return;
 }
 
+void HealpixSource::load(const QDomElement& e) {
+  QDomNode n = e.firstChild();
+  while (!n.isNull()) {
+    QDomElement e = n.toElement();
+    if (!e.isNull()) {
+      if (e.tagName() == "dim") {
+        kstdDebug() << "HEALPIX:  loading dim tag" << endl;
+        if (e.hasAttribute("x")) {
+          _nX = e.attribute("x").toInt();
+        }
+        if (e.hasAttribute("y")) {
+          _nX = e.attribute("y").toInt();
+        }
+      } else if (e.tagName() == "theta") {
+        kstdDebug() << "HEALPIX:  loading theta tag" << endl;
+        if (e.hasAttribute("auto")) {
+          _autoTheta = e.attribute("auto").toInt();
+        }
+        if (e.hasAttribute("units")) {
+          _thetaUnits = e.attribute("units").toInt();
+        }
+        if (e.hasAttribute("min")) {
+          _thetaMin = e.attribute("min").toDouble();
+        }
+        if (e.hasAttribute("max")) {
+          _thetaMax = e.attribute("max").toDouble();
+        }
+      } else if (e.tagName() == "phi") {
+        kstdDebug() << "HEALPIX:  loading phi tag" << endl;
+        if (e.hasAttribute("auto")) {
+          _autoPhi = e.attribute("auto").toInt();
+        }
+        if (e.hasAttribute("units")) {
+          _phiUnits = e.attribute("units").toInt();
+        }
+        if (e.hasAttribute("min")) {
+          _phiMin = e.attribute("min").toDouble();
+        }
+        if (e.hasAttribute("max")) {
+          _phiMax = e.attribute("max").toDouble();
+        }
+      } else if (e.tagName() == "vector") {
+        kstdDebug() << "HEALPIX:  loading vector tag" << endl;
+        if (e.hasAttribute("auto")) {
+          _autoMag = e.attribute("auto").toInt();
+        }
+        if (e.hasAttribute("degrade")) {
+          _vecDegrade = e.attribute("degrade").toInt();
+        }
+        if (e.hasAttribute("theta")) {
+          _vecTheta = e.attribute("theta").toInt();
+        }
+        if (e.hasAttribute("phi")) {
+          _vecPhi = e.attribute("phi").toInt();
+        }
+        if (e.hasAttribute("QU")) {
+          _vecQU = e.attribute("QU").toInt();
+        }
+        if (e.hasAttribute("max")) {
+          _maxMag = e.attribute("max").toDouble();
+        }
+      }
+    }
+    n = n.nextSibling();
+  }
+  QString str;
+  QString indent = "  ";
+  QTextStream ts(&str, IO_WriteOnly);
+  save(ts, indent);
+  kstdDebug() << str << endl;
+  return;
+}
+
 bool HealpixSource::isEmpty() const {
   if (!_valid) {
     return true;
@@ -1164,6 +1229,11 @@
   return new HealpixSource(cfg, filename, type);
 }
 
+KstDataSource *load_healpix(KConfig *cfg, const QString& filename, const QString& type, const QDomElement& e) {
+  kstdDebug() << "HEALPIX:  Calling load_healpix " << filename << endl;
+  return new HealpixSource(cfg, filename, type, e);
+}
+
 QStringList provides_healpix() {
   QStringList rc;
   rc += "HEALPIX";
--- trunk/extragear/graphics/kst/kst/datasources/healpix/healpix_source.h #476733:476734
@@ -26,7 +26,7 @@
 
 class HealpixSource : public KstDataSource {
   public:
-    HealpixSource(KConfig *cfg, const QString& filename, const QString& type);
+    HealpixSource(KConfig *cfg, const QString& filename, const QString& type, const QDomElement& e = QDomElement());
 
     ~HealpixSource();
     
@@ -53,6 +53,8 @@
     QString fileType() const;
 
     void save(QTextStream &ts, const QString& indent = QString::null);
+    
+    void load(const QDomElement& e);
 
     bool isEmpty() const;
     


More information about the Kst mailing list