=== modified file 'src/core/StelSkyLayer.hpp' --- old/src/core/StelSkyLayer.hpp 2012-01-11 10:50:37 +0000 +++ new/src/core/StelSkyLayer.hpp 2012-07-11 16:50:04 +0000 @@ -22,6 +22,7 @@ #include #include #include +#include "StelCore.hpp" class StelCore; class StelPainter; @@ -52,6 +53,12 @@ //! links and copyrights. virtual QString getLayerDescriptionHtml() const {return "No description.";} + //! Set the reference frame type. + void setFrameType(StelCore::FrameType ft) {frameType = ft;} + + //! Get the reference frame type. + StelCore::FrameType getFrameType() {return frameType;} + signals: //! Emitted when loading of data started or stopped. //! @param b true if data loading started, false if finished. @@ -60,6 +67,9 @@ //! Emitted when the percentage of loading tiles/tiles to be displayed changed. //! @param percentage the percentage of loaded data. void percentLoadedChanged(int percentage); +private: + //! Reference frametype for painter + StelCore::FrameType frameType; }; //! @file StelSkyLayerMgr.hpp === modified file 'src/core/StelSkyLayerMgr.cpp' --- old/src/core/StelSkyLayerMgr.cpp 2012-07-09 15:57:25 +0000 +++ new/src/core/StelSkyLayerMgr.cpp 2012-07-12 07:09:29 +0000 @@ -162,8 +162,20 @@ glEnable(GL_BLEND); foreach (SkyLayerElem* s, allSkyLayers) { - if (s->show) + if (s->show) + { + if (s->layer->getFrameType() == StelCore::FrameAltAz) + { + sPainter.setProjector(core->getProjection(StelCore::FrameAltAz)); + } + else + { + // TODO : Use the respective reference frames, once every SkyLayer + // object sets their frame type. Defaulting to Equatorial frame now. + sPainter.setProjector(core->getProjection(StelCore::FrameJ2000)); + } s->layer->draw(core, sPainter, 1.); + } } } @@ -284,6 +296,73 @@ vm["worldCoords"] = ol; StelSkyLayerP tile = StelSkyLayerP(new StelSkyImageTile(vm, 0)); + tile->setFrameType(StelCore::FrameJ2000); + QString key = insertSkyLayer(tile, filename, visible); + if (key == id) + return true; + else + return false; + } + catch (std::runtime_error& e) + { + qWarning() << "Could not find image" << filename << ":" << e.what(); + return false; + } +} + +bool StelSkyLayerMgr::loadSkyImageAltAz(const QString& id, const QString& filename, + double alt0, double azi0, + double alt1, double azi1, + double alt2, double azi2, + double alt3, double azi3, + double minRes, double maxBright, bool visible) +{ + if (allSkyLayers.contains(id)) + { + qWarning() << "Image ID" << id << "already exists, removing old image before loading"; + removeSkyLayer(id); + } + + QString path; + // Possible exception sources: + // - StelFileMgr file not found + // - list index out of range in insertSkyImage + try + { + path = StelFileMgr::findFile(filename); + + QVariantMap vm; + QVariantList l; + QVariantList cl; // coordinates list for adding worldCoords and textureCoords + QVariantList c; // a list for a pair of coordinates + QVariantList ol; // outer list - we want a structure 3 levels deep... + vm["imageUrl"] = QVariant(path); + vm["maxBrightness"] = QVariant(maxBright); + vm["minResolution"] = QVariant(minRes); + vm["shortName"] = QVariant(id); + + // textureCoords (define the ordering of worldCoords) + cl.clear(); + ol.clear(); + c.clear(); c.append(0); c.append(0); cl.append(QVariant(c)); + c.clear(); c.append(1); c.append(0); cl.append(QVariant(c)); + c.clear(); c.append(1); c.append(1); cl.append(QVariant(c)); + c.clear(); c.append(0); c.append(1); cl.append(QVariant(c)); + ol.append(QVariant(cl)); + vm["textureCoords"] = ol; + + // world coordinates + cl.clear(); + ol.clear(); + c.clear(); c.append(alt0); c.append(azi0); cl.append(QVariant(c)); + c.clear(); c.append(alt1); c.append(azi1); cl.append(QVariant(c)); + c.clear(); c.append(alt2); c.append(azi2); cl.append(QVariant(c)); + c.clear(); c.append(alt3); c.append(azi3); cl.append(QVariant(c)); + ol.append(QVariant(cl)); + vm["worldCoords"] = ol; + + StelSkyLayerP tile = StelSkyLayerP(new StelSkyImageTile(vm, 0)); + tile->setFrameType(StelCore::FrameAltAz); QString key = insertSkyLayer(tile, filename, visible); if (key == id) return true; === modified file 'src/core/StelSkyLayerMgr.hpp' --- old/src/core/StelSkyLayerMgr.hpp 2012-02-17 18:12:37 +0000 +++ new/src/core/StelSkyLayerMgr.hpp 2012-07-11 18:00:35 +0000 @@ -102,6 +102,32 @@ double ra3, double dec3, double minRes, double maxBright, bool visible); + //! Load an image from a file. This should not be called directly from + //! scripts because it is not thread safe. Instead use the similarly + //! named function in the core scripting object. + //! @param id a string identifier for the image + //! @param filename the name of the image file to load. Will be + //! searched for using StelFileMgr, so partial names are fine. + //! @param alt0 altitude angle of corner 0 in degrees + //! @param azi0 azimuth angle of corner 0 in degrees + //! @param alt1 altitude angle of corner 1 in degrees + //! @param azi1 azimuth angle of corner 1 in degrees + //! @param alt2 altitude angle of corner 2 in degrees + //! @param azi2 azimuth angle of corner 2 in degrees + //! @param alt3 altitude angle of corner 3 in degrees + //! @param azi3 azimuth angle of corner 3 in degrees + //! @param minRes the minimum resolution setting for the image + //! @param maxBright the maximum brightness setting for the image + //! @param visible initial visibility setting + bool loadSkyImageAltAz(const QString& id, const QString& filename, + double alt0, double azi0, + double alt1, double azi1, + double alt2, double azi2, + double alt3, double azi3, + double minRes, double maxBright, bool visible); + + + //! Decide to show or not to show a layer by it's ID. //! @param id the id of the layer whose status is to be changed. //! @param b the new shown value: === modified file 'src/scripting/StelMainScriptAPI.cpp' --- old/src/scripting/StelMainScriptAPI.cpp 2012-06-24 19:00:56 +0000 +++ new/src/scripting/StelMainScriptAPI.cpp 2012-07-11 17:15:15 +0000 @@ -69,6 +69,7 @@ if(StelSkyLayerMgr* smgr = GETSTELMODULE(StelSkyLayerMgr)) { connect(this, SIGNAL(requestLoadSkyImage(const QString&, const QString&, double, double, double, double, double, double, double, double, double, double, bool)), smgr, SLOT(loadSkyImage(const QString&, const QString&, double, double, double, double, double, double, double, double, double, double, bool))); + connect(this, SIGNAL(requestLoadSkyImageAltAz(const QString&, const QString&, double, double, double, double, double, double, double, double, double, double, bool)), smgr, SLOT(loadSkyImageAltAz(const QString&, const QString&, double, double, double, double, double, double, double, double, double, double, bool))); connect(this, SIGNAL(requestRemoveSkyImage(const QString&)), smgr, SLOT(removeSkyLayer(const QString&))); } @@ -361,6 +362,8 @@ minRes, maxBright, visible); } + + void StelMainScriptAPI::loadSkyImage(const QString& id, const QString& filename, const QString& ra, const QString& dec, double angSize, double rotation, double minRes, double maxBright, bool visible) @@ -370,6 +373,51 @@ rotation, minRes, maxBright, visible); } +void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename, + double alt0, double azi0, + double alt1, double azi1, + double alt2, double azi2, + double alt3, double azi3, + double minRes, double maxBright, bool visible) +{ + QString path = "scripts/" + filename; + emit(requestLoadSkyImageAltAz(id, path, alt0, azi0, alt1, azi1, alt2, azi2, alt3, azi3, minRes, maxBright, visible)); +} + +void StelMainScriptAPI::loadSkyImageAltAz(const QString& id, const QString& filename, + double alt, double azi, double angSize, double rotation, + double minRes, double maxBright, bool visible) +{ + Vec3f XYZ; + static const float RADIUS_NEB = 1.; + + StelUtils::spheToRect((180-azi)*M_PI/180., alt*M_PI/180., XYZ); + XYZ*=RADIUS_NEB; + float texSize = RADIUS_NEB * sin(angSize/2/60*M_PI/180); + Mat4f matPrecomp = Mat4f::translation(XYZ) * + Mat4f::zrotation((180-azi)*M_PI/180.) * + Mat4f::yrotation(-alt*M_PI/180.) * + Mat4f::xrotation((rotation+90)*M_PI/180.); + + Vec3f corners[4]; + corners[0] = matPrecomp * Vec3f(0.f,-texSize,-texSize); + corners[1] = matPrecomp * Vec3f(0.f,-texSize, texSize); + corners[2] = matPrecomp * Vec3f(0.f, texSize,-texSize); + corners[3] = matPrecomp * Vec3f(0.f, texSize, texSize); + + // convert back to alt/azi (radians) + Vec3f cornersAltAz[4]; + for(int i=0; i<4; i++) + StelUtils::rectToSphe(&cornersAltAz[i][0], &cornersAltAz[i][1], corners[i]); + + loadSkyImageAltAz(id, filename, + cornersAltAz[0][0]*180./M_PI, cornersAltAz[0][1]*180./M_PI, + cornersAltAz[1][0]*180./M_PI, cornersAltAz[1][1]*180./M_PI, + cornersAltAz[3][0]*180./M_PI, cornersAltAz[3][1]*180./M_PI, + cornersAltAz[2][0]*180./M_PI, cornersAltAz[2][1]*180./M_PI, + minRes, maxBright, visible); +} + void StelMainScriptAPI::removeSkyImage(const QString& id) { emit(requestRemoveSkyImage(id)); === modified file 'src/scripting/StelMainScriptAPI.hpp' --- old/src/scripting/StelMainScriptAPI.hpp 2012-06-19 15:37:19 +0000 +++ new/src/scripting/StelMainScriptAPI.hpp 2012-07-11 17:20:28 +0000 @@ -331,6 +331,7 @@ double ra3, double dec3, double minRes=2.5, double maxBright=14, bool visible=true); + //! Convenience function which allows the user to provide RA and DEC angles //! as strings (e.g. "12d 14m 8s" or "5h 26m 8s" - formats accepted by //! StelUtils::getDecAngle()). @@ -367,6 +368,49 @@ const QString& ra, const QString& dec, double angSize, double rotation, double minRes=2.5, double maxBright=14, bool visible=true); + //! Load an image which will have sky coordinates. + //! @param id a string ID to be used when referring to this + //! image (e.g. when changing the displayed status or deleting + //! it. + //! @param filename the file name of the image. If a relative + //! path is specified, "scripts/" will be prefixed before the + //! image is searched for using StelFileMgr. + //! @param alt0 The altitude angle of the first corner of the image in degrees + //! @param azi0 The azimuth angle of the first corner of the image in degrees + //! @param alt1 The altitude angle of the second corner of the image in degrees + //! @param azi1 The azimuth angle of the second corner of the image in degrees + //! @param alt2 The altitude angle of the third corner of the image in degrees + //! @param azi2 The azimuth angle of the third corner of the image in degrees + //! @param alt3 The altitude angle of the fourth corner of the image in degrees + //! @param azi3 The azimuth angle of the fourth corner of the image in degrees + //! @param minRes The minimum resolution setting for the image + //! @param maxBright The maximum brightness setting for the image + //! @param visible The initial visibility of the image + void loadSkyImageAltAz(const QString& id, const QString& filename, + double alt0, double azi0, + double alt1, double azi1, + double alt2, double azi2, + double alt3, double azi3, + double minRes=2.5, double maxBright=14, bool visible=true); + + //! Convenience function which allows loading of a sky image based on a + //! central coordinate, angular size and rotation. + //! @param id a string ID to be used when referring to this + //! image (e.g. when changing the displayed status or deleting it. + //! @param filename the file name of the image. If a relative + //! path is specified, "scripts/" will be prefixed before the + //! image is searched for using StelFileMgr. + //! @param alt The altitude angle of the center of the image in degrees + //! @param azi The azimuth angle of the center of the image in degrees + //! @param angSize The angular size of the image in arc minutes + //! @param rotation The clockwise rotation angle of the image in degrees + //! @param minRes The minimum resolution setting for the image + //! @param maxBright The maximum brightness setting for the image + //! @param visible The initial visibility of the image + void loadSkyImageAltAz(const QString& id, const QString& filename, + double alt, double azi, double angSize, double rotation, + double minRes=2.5, double maxBright=14, bool visible=true); + //! Remove a SkyImage. //! @param id the ID of the image to remove. void removeSkyImage(const QString& id); @@ -512,6 +556,13 @@ double c5, double c6, double c7, double c8, double minRes, double maxBright, bool visible); + void requestLoadSkyImageAltAz(const QString& id, const QString& filename, + double c1, double c2, + double c3, double c4, + double c5, double c6, + double c7, double c8, + double minRes, double maxBright, bool visible); + void requestRemoveSkyImage(const QString& id);