summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Fedoskin <afedoskin3@gmail.com>2016-05-15 15:41:17 (GMT)
committerArtem Fedoskin <afedoskin3@gmail.com>2016-05-15 15:41:17 (GMT)
commitee72b1758783f73ea0894b1250a0ccca71b0293a (patch)
tree4708e61c1bc28bfa37ecdb6cb940af6a062869cf
parentea7ea2d07b25b8bcec4dc2068b8aa4c03e1ad158 (diff)
Moved Projection enum from SkyMap to Projector. Introduced RootNode
class that handles texture generation and clipping.
-rw-r--r--kstars/CMakeLists.txt4
-rw-r--r--kstars/kstarsactions.cpp12
-rw-r--r--kstars/kstarsinit.cpp13
-rw-r--r--kstars/kstarslite.cpp1
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetitemnode.cpp30
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetnode.cpp2
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetnode.h4
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetrootnode.cpp9
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetrootnode.h (renamed from kstars/kstarslite/skyitems/nodes/planetitemnode.h)35
-rw-r--r--kstars/kstarslite/skyitems/nodes/pointnode.cpp6
-rw-r--r--kstars/kstarslite/skyitems/nodes/pointnode.h8
-rw-r--r--kstars/kstarslite/skyitems/nodes/rootnode.cpp69
-rw-r--r--kstars/kstarslite/skyitems/nodes/rootnode.h86
-rw-r--r--kstars/kstarslite/skyitems/planetsitem.cpp22
-rw-r--r--kstars/projections/azimuthalequidistantprojector.cpp4
-rw-r--r--kstars/projections/azimuthalequidistantprojector.h2
-rw-r--r--kstars/projections/equirectangularprojector.cpp4
-rw-r--r--kstars/projections/equirectangularprojector.h2
-rw-r--r--kstars/projections/gnomonicprojector.cpp4
-rw-r--r--kstars/projections/gnomonicprojector.h2
-rw-r--r--kstars/projections/lambertprojector.cpp4
-rw-r--r--kstars/projections/lambertprojector.h2
-rw-r--r--kstars/projections/orthographicprojector.cpp4
-rw-r--r--kstars/projections/orthographicprojector.h2
-rw-r--r--kstars/projections/projector.cpp12
-rw-r--r--kstars/projections/projector.h14
-rw-r--r--kstars/projections/stereographicprojector.cpp4
-rw-r--r--kstars/projections/stereographicprojector.h2
-rw-r--r--kstars/skymap.cpp12
-rw-r--r--kstars/skymap.h8
-rw-r--r--kstars/skymaplite.cpp161
-rw-r--r--kstars/skymaplite.h44
32 files changed, 378 insertions, 210 deletions
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index a92321d..1925dda 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -525,10 +525,12 @@ if(BUILD_KSTARS_LITE)
#SkyItems
kstarslite/skyitems/planetsitem.cpp
kstarslite/skyitems/skyitem.cpp
+ #Root Nodes
+ kstarslite/skyitems/nodes/rootnode.cpp
+ kstarslite/skyitems/nodes/planetrootnode.cpp
#Nodes
kstarslite/skyitems/nodes/planetnode.cpp
kstarslite/skyitems/nodes/pointnode.cpp
- kstarslite/skyitems/nodes/planetitemnode.cpp
)
#Qml files will be probably moved to user's data dir, but for use
#with QtCreator it is more convenient to have them here
diff --git a/kstars/kstarsactions.cpp b/kstars/kstarsactions.cpp
index b3d02a8..7caaf78 100644
--- a/kstars/kstarsactions.cpp
+++ b/kstars/kstarsactions.cpp
@@ -1202,17 +1202,17 @@ void KStars::slotCoordSys() {
void KStars::slotMapProjection() {
if ( sender() == actionCollection()->action("project_lambert") )
- Options::setProjection( SkyMap::Lambert );
+ Options::setProjection( Projector::Lambert );
if ( sender() == actionCollection()->action("project_azequidistant") )
- Options::setProjection( SkyMap::AzimuthalEquidistant );
+ Options::setProjection( Projector::AzimuthalEquidistant );
if ( sender() == actionCollection()->action("project_orthographic") )
- Options::setProjection( SkyMap::Orthographic );
+ Options::setProjection( Projector::Orthographic );
if ( sender() == actionCollection()->action("project_equirectangular") )
- Options::setProjection( SkyMap::Equirectangular );
+ Options::setProjection( Projector::Equirectangular );
if ( sender() == actionCollection()->action("project_stereographic") )
- Options::setProjection( SkyMap::Stereographic );
+ Options::setProjection( Projector::Stereographic );
if ( sender() == actionCollection()->action("project_gnomonic") )
- Options::setProjection( SkyMap::Gnomonic );
+ Options::setProjection( Projector::Gnomonic );
//DEBUG
qDebug() << "Projection system: " << Options::projection();
diff --git a/kstars/kstarsinit.cpp b/kstars/kstarsinit.cpp
index 7d1feba..6696a9c 100644
--- a/kstars/kstarsinit.cpp
+++ b/kstars/kstarsinit.cpp
@@ -38,6 +38,7 @@
#include "kstars.h"
#include "kstarsdata.h"
#include "skymap.h"
+#include "projections/projector.h"
#include "skyobjects/skyobject.h"
#include "skyobjects/ksplanetbase.h"
#include "simclock.h"
@@ -247,32 +248,32 @@ void KStars::initActions() {
<< i18n("&Lambert Azimuthal Equal-area" )
<< QKeySequence("F5" )
<< AddToGroup(projectionGroup)
- << Checked(Options::projection() == SkyMap::Lambert);
+ << Checked(Options::projection() == Projector::Lambert);
actionCollection()->addAction("project_azequidistant", this, SLOT( slotMapProjection() ) )
<< i18n("&Azimuthal Equidistant" )
<< QKeySequence("F6" )
<< AddToGroup(projectionGroup)
- << Checked(Options::projection() == SkyMap::AzimuthalEquidistant);
+ << Checked(Options::projection() == Projector::AzimuthalEquidistant);
actionCollection()->addAction("project_orthographic", this, SLOT( slotMapProjection() ) )
<< i18n("&Orthographic" )
<< QKeySequence("F7" )
<< AddToGroup(projectionGroup)
- << Checked(Options::projection() == SkyMap::Orthographic);
+ << Checked(Options::projection() == Projector::Orthographic);
actionCollection()->addAction("project_equirectangular", this, SLOT( slotMapProjection() ) )
<< i18n("&Equirectangular" )
<< QKeySequence("F8" )
<< AddToGroup(projectionGroup)
- << Checked(Options::projection() == SkyMap::Equirectangular);
+ << Checked(Options::projection() == Projector::Equirectangular);
actionCollection()->addAction("project_stereographic", this, SLOT( slotMapProjection() ) )
<< i18n("&Stereographic" )
<< QKeySequence("F9" )
<< AddToGroup(projectionGroup)
- << Checked(Options::projection() == SkyMap::Stereographic);
+ << Checked(Options::projection() == Projector::Stereographic);
actionCollection()->addAction("project_gnomonic", this, SLOT( slotMapProjection() ) )
<< i18n("&Gnomonic" )
<< QKeySequence("F10" )
<< AddToGroup(projectionGroup)
- << Checked(Options::projection() == SkyMap::Gnomonic);
+ << Checked(Options::projection() == Projector::Gnomonic);
//Settings Menu:
//Info Boxes option actions
diff --git a/kstars/kstarslite.cpp b/kstars/kstarslite.cpp
index 0e41612..9f2c35d 100644
--- a/kstars/kstarslite.cpp
+++ b/kstars/kstarslite.cpp
@@ -60,6 +60,7 @@ KStarsLite::KStarsLite( bool doSplash, bool startClock, const QString &startDate
/*SkyMapLite has to be loaded before KStarsData is initialized because SkyComponents derived classes
have to add SkyItems to the SkyMapLite*/
m_SkyMapLite = SkyMapLite::createInstance(skyMapLiteWrapper);
+ m_SkyMapLite->update();
// Set pinstance to yourself
pinstance = this;
diff --git a/kstars/kstarslite/skyitems/nodes/planetitemnode.cpp b/kstars/kstarslite/skyitems/nodes/planetitemnode.cpp
deleted file mode 100644
index 673a2c5..0000000
--- a/kstars/kstarslite/skyitems/nodes/planetitemnode.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "planetitemnode.h"
-#include "skymaplite.h"
-
-#include <QSGTexture>
-#include <QQuickWindow>
-
-PlanetItemNode::PlanetItemNode() {
- genCachedTextures();
-}
-
-void PlanetItemNode::genCachedTextures() {
- SkyMapLite* skyMap = SkyMapLite::Instance();
- QVector<QVector<QPixmap*>> images = skyMap->getImageCache();
-
- QQuickWindow *win = skyMap->window();
-
- textureCache = QVector<QVector<QSGTexture*>> (images.length());
-
- for(int i = 0; i < textureCache.length(); ++i) {
- int length = images[i].length();
- textureCache[i] = QVector<QSGTexture *>(length);
- for(int c = 1; c < length; ++c) {
- textureCache[i][c] = win->createTextureFromImage(images[i][c]->toImage());
- }
- }
-}
-
-QSGTexture* PlanetItemNode::getCachedTexture(int size, char spType) {
- return textureCache[SkyMapLite::Instance()->harvardToIndex(spType)][size];
-}
diff --git a/kstars/kstarslite/skyitems/nodes/planetnode.cpp b/kstars/kstarslite/skyitems/nodes/planetnode.cpp
index ef92ce3..c1e1f4d 100644
--- a/kstars/kstarslite/skyitems/nodes/planetnode.cpp
+++ b/kstars/kstarslite/skyitems/nodes/planetnode.cpp
@@ -25,7 +25,7 @@
#include "planetnode.h"
-PlanetNode::PlanetNode(SolarSystemSingleComponent* p, PlanetItemNode* parentNode)
+PlanetNode::PlanetNode(SolarSystemSingleComponent* p, RootNode* parentNode)
:m_planetPic(new QSGSimpleTextureNode), m_planet(p), m_planetOpacity(new QSGOpacityNode)
{
KSPlanetBase* pb = m_planet->planet();
diff --git a/kstars/kstarslite/skyitems/nodes/planetnode.h b/kstars/kstarslite/skyitems/nodes/planetnode.h
index 5deada4..0dc628d 100644
--- a/kstars/kstarslite/skyitems/nodes/planetnode.h
+++ b/kstars/kstarslite/skyitems/nodes/planetnode.h
@@ -22,7 +22,7 @@ class QSGSimpleTextureNode;
class QImage;
class SolarSystemSingleComponent;
class KSPlanetBase;
-class PlanetItemNode;
+class RootNode;
/** @class PlanetNode
*
@@ -42,7 +42,7 @@ public:
* @param planet used in PlanesItem to update position of PlanetNode
* @param parentNode used by PointNode to get textures from cache
*/
- PlanetNode(SolarSystemSingleComponent* planet, PlanetItemNode* parentNode);
+ PlanetNode(SolarSystemSingleComponent* planet, RootNode* parentNode);
/**
* @short setPointSize updates the size of m_point
* @param size new size of m_point
diff --git a/kstars/kstarslite/skyitems/nodes/planetrootnode.cpp b/kstars/kstarslite/skyitems/nodes/planetrootnode.cpp
new file mode 100644
index 0000000..24eb68c
--- /dev/null
+++ b/kstars/kstarslite/skyitems/nodes/planetrootnode.cpp
@@ -0,0 +1,9 @@
+#include "planetrootnode.h"
+#include "skymaplite.h"
+
+#include <QSGTexture>
+#include <QQuickWindow>
+
+PlanetRootNode::PlanetRootNode() {
+
+}
diff --git a/kstars/kstarslite/skyitems/nodes/planetitemnode.h b/kstars/kstarslite/skyitems/nodes/planetrootnode.h
index 9e0ffc6..6f73de8 100644
--- a/kstars/kstarslite/skyitems/nodes/planetitemnode.h
+++ b/kstars/kstarslite/skyitems/nodes/planetrootnode.h
@@ -1,5 +1,5 @@
/** *************************************************************************
- planetitemnode.h - K Desktop Planetarium
+ planetrootnode.h - K Desktop Planetarium
-------------------
begin : 05/05/2016
copyright : (C) 2016 by Artem Fedoskin
@@ -13,39 +13,20 @@
* (at your option) any later version. *
* *
***************************************************************************/
-#ifndef PLANETITEMNODE_H_
-#define PLANETITEMNODE_H_
-#include <QSGNode>
-
-class QSGSimpleTextureNode;
-class QImage;
+#ifndef PLANETROOTNODE_H_
+#define PLANETROOTNODE_H_
+#include "rootnode.h"
class PlanetNode;
-class QSGTexture;
-/** @class PlanetItemNode
- *
- * A QSGNode derived class used as a container for holding PlanetNodes. Upon construction
- * PlanetItemNode generates all textures that are used by stars
- *
- *@short A container for PlanetNodes that holds collection of textures for stars
+/** @class PlanetRootNode
+ *@short A RootNode derived class used as a container for holding PlanetNodes.
*@author Artem Fedoskin
*@version 1.0
*/
-class PlanetItemNode : public QSGNode {
+class PlanetRootNode : public RootNode {
public:
- PlanetItemNode();
- /**
- * @short returns cached texture from textureCache
- * @return cached QSGTexture from textureCache
- */
- QSGTexture* getCachedTexture(int size, char spType);
-
+ PlanetRootNode();
private:
- /**
- * @short initializes textureCache with cached images of stars in SkyMapLite
- */
- void genCachedTextures();
- QVector<QVector<QSGTexture *>> textureCache;
};
#endif
diff --git a/kstars/kstarslite/skyitems/nodes/pointnode.cpp b/kstars/kstarslite/skyitems/nodes/pointnode.cpp
index f20b176..5bc7896 100644
--- a/kstars/kstarslite/skyitems/nodes/pointnode.cpp
+++ b/kstars/kstarslite/skyitems/nodes/pointnode.cpp
@@ -19,10 +19,10 @@
#include "skymaplite.h"
#include "pointnode.h"
-#include "planetitemnode.h"
+#include "rootnode.h"
-PointNode::PointNode(char sp, PlanetItemNode* p, float size)
- :spType(sp), texture(new QSGSimpleTextureNode), parentNode(p)
+PointNode::PointNode(char sp, RootNode* p, float size)
+ :spType(sp), texture(new QSGSimpleTextureNode), parentNode(p), skyMapLite(SkyMapLite::Instance())
{
appendChildNode(texture);
setSize(size);
diff --git a/kstars/kstarslite/skyitems/nodes/pointnode.h b/kstars/kstarslite/skyitems/nodes/pointnode.h
index 7567bfe..86e39a8 100644
--- a/kstars/kstarslite/skyitems/nodes/pointnode.h
+++ b/kstars/kstarslite/skyitems/nodes/pointnode.h
@@ -18,6 +18,7 @@
#include <QSGSimpleTextureNode>
class PlanetItemNode;
+class SkyMapLite;
/** @class PointNode
*
@@ -29,6 +30,8 @@ class PlanetItemNode;
*@version 1.0
*/
+class RootNode;
+
class PointNode : public QSGOpacityNode {
public:
/**
@@ -37,7 +40,7 @@ public:
* @param parentNode pointer to top parent node, which holds texture cache
* @param size initial size of PointNode
*/
- PointNode(char spType, PlanetItemNode* parentNode, float size = 1);
+ PointNode(char spType, RootNode* parentNode, float size = 1);
/**
* @short setSize update size of PointNode with the given parameter
* @param size new size of PointNode
@@ -52,7 +55,8 @@ private:
char spType;
QSGSimpleTextureNode *texture;
// This pointer is important because parentNode holds texture cache
- PlanetItemNode* parentNode;
+ RootNode* parentNode;
+ SkyMapLite* skyMapLite;
};
#endif
diff --git a/kstars/kstarslite/skyitems/nodes/rootnode.cpp b/kstars/kstarslite/skyitems/nodes/rootnode.cpp
new file mode 100644
index 0000000..3c54e09
--- /dev/null
+++ b/kstars/kstarslite/skyitems/nodes/rootnode.cpp
@@ -0,0 +1,69 @@
+#include "rootnode.h"
+#include "skymaplite.h"
+#include "projections/projector.h"
+
+#include <QSGTexture>
+#include <QQuickWindow>
+
+RootNode::RootNode()
+ :m_polyNode(new QSGGeometryNode), m_skyMapLite(SkyMapLite::Instance())
+{
+ genCachedTextures();
+ updateClipPoly();
+ setIsRectangular(false);
+}
+
+void RootNode::genCachedTextures() {
+ QVector<QVector<QPixmap*>> images = m_skyMapLite->getImageCache();
+
+ QQuickWindow *win = m_skyMapLite->window();
+
+ m_textureCache = QVector<QVector<QSGTexture*>> (images.length());
+
+ for(int i = 0; i < m_textureCache.length(); ++i) {
+ int length = images[i].length();
+ m_textureCache[i] = QVector<QSGTexture *>(length);
+ for(int c = 1; c < length; ++c) {
+ m_textureCache[i][c] = win->createTextureFromImage(images[i][c]->toImage());
+ }
+ }
+}
+
+QSGTexture* RootNode::getCachedTexture(int size, char spType) {
+ return m_textureCache[SkyMapLite::Instance()->harvardToIndex(spType)][size];
+}
+
+void RootNode::appendSkyNode(QSGNode * skyNode) {
+ m_skyNodes.append(skyNode);
+ appendChildNode(skyNode);
+}
+
+void RootNode::updateClipPoly() {
+ QPolygonF newClip = m_skyMapLite->projector()->clipPoly();
+ if(m_clipPoly != newClip) {
+ m_clipPoly = newClip;
+ QVector<QPointF> triangles;
+
+ for(int i = 1; i < m_clipPoly.size() - 1; ++i) {
+ triangles.append(m_clipPoly[0]);
+ triangles.append(m_clipPoly[i]);
+ triangles.append(m_clipPoly[i+1]);
+ }
+
+ const int size = triangles.size();
+ if(!m_polyGeometry) {
+ m_polyGeometry = new QSGGeometry (QSGGeometry::defaultAttributes_Point2D (),
+ size);
+ m_polyGeometry->setDrawingMode (GL_TRIANGLES);
+ setGeometry(m_polyGeometry);
+ } else {
+ m_polyGeometry->allocate(size);
+ }
+
+ QSGGeometry::Point2D * vertex = m_polyGeometry->vertexDataAsPoint2D ();
+ for (int idx = 0; idx < size; idx++) {
+ vertex [idx].x = triangles[idx].x ();
+ vertex [idx].y = triangles[idx].y ();
+ }
+ }
+}
diff --git a/kstars/kstarslite/skyitems/nodes/rootnode.h b/kstars/kstarslite/skyitems/nodes/rootnode.h
new file mode 100644
index 0000000..70deed9
--- /dev/null
+++ b/kstars/kstarslite/skyitems/nodes/rootnode.h
@@ -0,0 +1,86 @@
+
+/** *************************************************************************
+ rootnode.h - K Desktop Planetarium
+ -------------------
+ begin : 14/05/2016
+ copyright : (C) 2016 by Artem Fedoskin
+ email : afedoskin3@gmail.com
+ ***************************************************************************/
+/** *************************************************************************
+ * *
+ * 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 *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef ROOTNODE_H_
+#define ROOTNODE_H_
+#include <QSGClipNode>
+#include <QPolygonF>
+
+class QSGSimpleTextureNode;
+class QImage;
+class QSGTexture;
+class SkyMapLite;
+
+/** @class RootNode
+ *
+ * A QSGClipNode derived class used as a container for holding nodes and for clipping. Upon construction
+ * RootNode generates all textures that are used by stars.
+ *
+ *@short A container for nodes that holds collection of textures for stars and provides clipping
+ *@author Artem Fedoskin
+ *@version 1.0
+ */
+
+class RootNode : public QSGClipNode {
+public:
+ RootNode();
+ /**
+ * @short returns cached texture from textureCache
+ * @param size size of the star
+ * @param spType spectral class
+ * @return cached QSGTexture from textureCache
+ */
+ QSGTexture* getCachedTexture(int size, char spType);
+
+ /**
+ * @brief Adds node to m_skyNodes and node tree
+ * @param skyNode pointer to skyNode that has to be added
+ */
+ void appendSkyNode(QSGNode * skyNode);
+
+ /**
+ * Triangulates clipping polygon provided by Projection system
+ * @short updates clipping geometry using triangles data in SkyMapLite
+ */
+ void updateClipPoly();
+
+ /**
+ * @return number of SkyNodes in m_skyNodes
+ */
+ inline int skyNodesCount() { return m_skyNodes.length(); }
+
+ /**
+ * @short returns a SkyNode in m_skyNodes with i index
+ * @param i index of SkyNode
+ * @return desired SkyNode
+ */
+ inline QSGNode * skyNodeAtIndex(int i) { return m_skyNodes[i]; }
+
+private:
+ /**
+ * @short initializes textureCache with cached images of stars in SkyMapLite
+ */
+ void genCachedTextures();
+ QVector<QVector<QSGTexture *>> m_textureCache;
+ SkyMapLite *m_skyMapLite;
+
+ QPolygonF m_clipPoly;
+ QSGGeometryNode *m_polyNode;
+ QSGGeometry *m_polyGeometry;
+ //To hold nodes that represent sky objects
+ QVector<QSGNode *> m_skyNodes;
+};
+#endif
diff --git a/kstars/kstarslite/skyitems/planetsitem.cpp b/kstars/kstarslite/skyitems/planetsitem.cpp
index 5b2d981..536a348 100644
--- a/kstars/kstarslite/skyitems/planetsitem.cpp
+++ b/kstars/kstarslite/skyitems/planetsitem.cpp
@@ -22,7 +22,7 @@
#include <QSGSimpleTextureNode>
#include <QQuickWindow>
#include "nodes/planetnode.h"
-#include "nodes/planetitemnode.h"
+#include "nodes/planetrootnode.h"
#include "Options.h"
@@ -42,7 +42,8 @@ void PlanetsItem::addPlanet(SolarSystemSingleComponent* planetComp) {
}
QSGNode* PlanetsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) {
- PlanetItemNode *n = static_cast<PlanetItemNode*>(oldNode);
+ PlanetRootNode *n = static_cast<PlanetRootNode*>(oldNode);
+ Q_UNUSED(updatePaintNodeData);
QRectF rect = boundingRect();
if (rect.isEmpty()) {
@@ -51,13 +52,13 @@ QSGNode* PlanetsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upd
}
if(!n) {
- n = new PlanetItemNode; // If no PlanetItemNode exists create one
+ n = new PlanetRootNode; // If no PlanetRootNode exists create one
int pCompLen = m_planetComponents.length();
if(pCompLen > 0) {
/* If there are some planets that have been already displayed once then recreate them
- in new instance of PlanetItemNode*/
+ in new instance of PlanetRootNode*/
for(int i = 0; i < pCompLen; ++i) {
- n->appendChildNode(new PlanetNode(m_planetComponents[i], n));
+ n->appendSkyNode(new PlanetNode(m_planetComponents[i], n));
}
}
}
@@ -66,14 +67,15 @@ QSGNode* PlanetsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upd
if(addLength > 0) { // If there are some new planets to add
for(int i = 0; i < addLength; ++i) {
m_planetComponents.append(m_toAdd[i]);
- n->appendChildNode(new PlanetNode(m_toAdd[i], n));
+ n->appendSkyNode(new PlanetNode(m_toAdd[i], n));
}
m_toAdd.clear();
}
-
- //Traverse all children nodes of PlanetItemNode
- for(int i = 0; i < n->childCount(); ++i) {
- PlanetNode* pNode = static_cast<PlanetNode*>(n->childAtIndex(i));
+ //Update clipping geometry. If m_clipPoly in SkyMapLite wasn't changed, geometry is not updated
+ n->updateClipPoly();
+ //Traverse all children nodes of PlanetRootNode
+ for(int i = 0; i < n->skyNodesCount(); ++i) {
+ PlanetNode* pNode = static_cast<PlanetNode*>(n->skyNodeAtIndex(i));
if(!pNode->planet()->selected()) {
pNode->hide();
} else {
diff --git a/kstars/projections/azimuthalequidistantprojector.cpp b/kstars/projections/azimuthalequidistantprojector.cpp
index 8b5e2ae..fbc1252 100644
--- a/kstars/projections/azimuthalequidistantprojector.cpp
+++ b/kstars/projections/azimuthalequidistantprojector.cpp
@@ -29,9 +29,9 @@ AzimuthalEquidistantProjector::AzimuthalEquidistantProjector(const ViewParams& p
}
-SkyMap::Projection AzimuthalEquidistantProjector::type() const
+Projector::Projection AzimuthalEquidistantProjector::type() const
{
- return SkyMap::AzimuthalEquidistant;
+ return AzimuthalEquidistant;
}
double AzimuthalEquidistantProjector::radius() const
diff --git a/kstars/projections/azimuthalequidistantprojector.h b/kstars/projections/azimuthalequidistantprojector.h
index 0b44f17..ba53d45 100644
--- a/kstars/projections/azimuthalequidistantprojector.h
+++ b/kstars/projections/azimuthalequidistantprojector.h
@@ -34,7 +34,7 @@ class AzimuthalEquidistantProjector : public Projector
public:
explicit AzimuthalEquidistantProjector(const ViewParams& p);
- virtual SkyMap::Projection type() const;
+ virtual Projection type() const;
virtual double radius() const;
virtual double projectionK(double x) const;
virtual double projectionL(double x) const;
diff --git a/kstars/projections/equirectangularprojector.cpp b/kstars/projections/equirectangularprojector.cpp
index f4c978e..6999102 100644
--- a/kstars/projections/equirectangularprojector.cpp
+++ b/kstars/projections/equirectangularprojector.cpp
@@ -29,9 +29,9 @@ EquirectangularProjector::EquirectangularProjector(const ViewParams& p)
}
-SkyMap::Projection EquirectangularProjector::type() const
+Projector::Projection EquirectangularProjector::type() const
{
- return SkyMap::Equirectangular;
+ return Equirectangular;
}
double EquirectangularProjector::radius() const
diff --git a/kstars/projections/equirectangularprojector.h b/kstars/projections/equirectangularprojector.h
index e2ffaa6..7dcf390 100644
--- a/kstars/projections/equirectangularprojector.h
+++ b/kstars/projections/equirectangularprojector.h
@@ -32,7 +32,7 @@ class EquirectangularProjector : public Projector
{
public:
explicit EquirectangularProjector(const ViewParams& p);
- virtual SkyMap::Projection type() const;
+ virtual Projection type() const;
virtual double radius() const;
virtual bool unusablePoint( const QPointF& p) const;
virtual Vector2f toScreenVec(const SkyPoint* o, bool oRefract = true, bool* onVisibleHemisphere = 0) const;
diff --git a/kstars/projections/gnomonicprojector.cpp b/kstars/projections/gnomonicprojector.cpp
index 69bd825..00f6679 100644
--- a/kstars/projections/gnomonicprojector.cpp
+++ b/kstars/projections/gnomonicprojector.cpp
@@ -25,9 +25,9 @@ GnomonicProjector::GnomonicProjector(const ViewParams& p)
}
-SkyMap::Projection GnomonicProjector::type() const
+Projector::Projection GnomonicProjector::type() const
{
- return SkyMap::Gnomonic;
+ return Gnomonic;
}
double GnomonicProjector::radius() const
diff --git a/kstars/projections/gnomonicprojector.h b/kstars/projections/gnomonicprojector.h
index d6d9175..3f6cb04 100644
--- a/kstars/projections/gnomonicprojector.h
+++ b/kstars/projections/gnomonicprojector.h
@@ -33,7 +33,7 @@ class GnomonicProjector : public Projector
public:
explicit GnomonicProjector(const ViewParams& p);
- virtual SkyMap::Projection type() const;
+ virtual Projection type() const;
virtual double radius() const;
virtual double projectionK(double x) const;
virtual double projectionL(double x) const;
diff --git a/kstars/projections/lambertprojector.cpp b/kstars/projections/lambertprojector.cpp
index c737636..aad1bc5 100644
--- a/kstars/projections/lambertprojector.cpp
+++ b/kstars/projections/lambertprojector.cpp
@@ -23,9 +23,9 @@ LambertProjector::LambertProjector(const ViewParams& p) : Projector(p)
{
}
-SkyMap::Projection LambertProjector::type() const
+Projector::Projection LambertProjector::type() const
{
- return SkyMap::Lambert;
+ return Lambert;
}
double LambertProjector::radius() const
diff --git a/kstars/projections/lambertprojector.h b/kstars/projections/lambertprojector.h
index 6fb4b66..27a569f 100644
--- a/kstars/projections/lambertprojector.h
+++ b/kstars/projections/lambertprojector.h
@@ -34,7 +34,7 @@ class LambertProjector : public Projector
public:
explicit LambertProjector(const ViewParams& p);
virtual ~LambertProjector() {}
- virtual SkyMap::Projection type() const;
+ virtual Projection type() const;
virtual double radius() const;
virtual double projectionK(double x) const;
virtual double projectionL(double x) const;
diff --git a/kstars/projections/orthographicprojector.cpp b/kstars/projections/orthographicprojector.cpp
index 240a180..a36d73c 100644
--- a/kstars/projections/orthographicprojector.cpp
+++ b/kstars/projections/orthographicprojector.cpp
@@ -25,9 +25,9 @@ OrthographicProjector::OrthographicProjector(const ViewParams& p)
}
-SkyMap::Projection OrthographicProjector::type() const
+Projector::Projection OrthographicProjector::type() const
{
- return SkyMap::Orthographic;
+ return Orthographic;
}
double OrthographicProjector::radius() const
diff --git a/kstars/projections/orthographicprojector.h b/kstars/projections/orthographicprojector.h
index 9731eb2..c717d6f 100644
--- a/kstars/projections/orthographicprojector.h
+++ b/kstars/projections/orthographicprojector.h
@@ -33,7 +33,7 @@ class OrthographicProjector : public Projector
public:
explicit OrthographicProjector(const ViewParams& p);
- virtual SkyMap::Projection type() const;
+ virtual Projection type() const;
virtual double radius() const;
virtual double projectionK(double x) const;
virtual double projectionL(double x) const;
diff --git a/kstars/projections/projector.cpp b/kstars/projections/projector.cpp
index c3abc49..47b8802 100644
--- a/kstars/projections/projector.cpp
+++ b/kstars/projections/projector.cpp
@@ -277,11 +277,7 @@ QVector< Vector2f > Projector::groundPoly(SkyPoint* labelpoint, bool *drawLabel)
double daz = 90.;
if ( m_vp.useAltAz ) {
daz = 0.5*m_vp.width*57.3/m_vp.zoomFactor; //center to edge, in degrees
- #if 0
- if ( type() == SkyMapLite::Orthographic ) {
- #else
- if ( type() == SkyMap::Orthographic ) {
- #endif
+ if ( type() == Orthographic ) {
daz = daz * 1.4;
}
daz = qMin(qreal(90.0), daz);
@@ -331,11 +327,7 @@ QVector< Vector2f > Projector::groundPoly(SkyPoint* labelpoint, bool *drawLabel)
//In Gnomonic projection, or if sufficiently zoomed in, we can complete
//the ground polygon by simply adding offscreen points
//FIXME: not just gnomonic
- #if 0
- if ( daz < 25.0 || type() == SkyMapLite::Gnomonic) {
- #else
- if ( daz < 25.0 || type() == SkyMap::Gnomonic) {
- #endif
+ if ( daz < 25.0 || type() == Gnomonic) {
ground.append( Vector2f( m_vp.width + 10.f, ground.last().y() ) );
ground.append( Vector2f( m_vp.width + 10.f, m_vp.height + 10.f ) );
ground.append( Vector2f( -10.f, m_vp.height + 10.f ) );
diff --git a/kstars/projections/projector.h b/kstars/projections/projector.h
index abb358f..dfc513a 100644
--- a/kstars/projections/projector.h
+++ b/kstars/projections/projector.h
@@ -67,12 +67,16 @@ public:
/** Update cached values for projector */
void setViewParams( const ViewParams& p );
+ enum Projection { Lambert,
+ AzimuthalEquidistant,
+ Orthographic,
+ Equirectangular,
+ Stereographic,
+ Gnomonic,
+ UnknownProjection };
+
/** Return the type of this projection */
- #if 0
- virtual SkyMapLite::Projection type() const = 0;
- #else
- virtual SkyMap::Projection type() const = 0;
- #endif
+ virtual Projection type() const = 0;
/** Return the FOV of this projection */
double fov() const;
diff --git a/kstars/projections/stereographicprojector.cpp b/kstars/projections/stereographicprojector.cpp
index 794740e..0c2fd9f 100644
--- a/kstars/projections/stereographicprojector.cpp
+++ b/kstars/projections/stereographicprojector.cpp
@@ -25,9 +25,9 @@ StereographicProjector::StereographicProjector(const ViewParams& p)
}
-SkyMap::Projection StereographicProjector::type() const
+Projector::Projection StereographicProjector::type() const
{
- return SkyMap::Stereographic;
+ return Stereographic;
}
double StereographicProjector::radius() const
diff --git a/kstars/projections/stereographicprojector.h b/kstars/projections/stereographicprojector.h
index f1150cc..ae234d4 100644
--- a/kstars/projections/stereographicprojector.h
+++ b/kstars/projections/stereographicprojector.h
@@ -33,7 +33,7 @@ class StereographicProjector : public Projector
public:
explicit StereographicProjector(const ViewParams& p);
- virtual SkyMap::Projection type() const;
+ virtual Projection type() const;
virtual double radius() const;
virtual double projectionK(double x) const;
virtual double projectionL(double x) const;
diff --git a/kstars/skymap.cpp b/kstars/skymap.cpp
index f05c429..5ecdeb1 100644
--- a/kstars/skymap.cpp
+++ b/kstars/skymap.cpp
@@ -1041,22 +1041,22 @@ void SkyMap::setupProjector() {
else {
delete m_proj;
switch( Options::projection() ) {
- case Gnomonic:
+ case Projector::Gnomonic:
m_proj = new GnomonicProjector(p);
break;
- case Stereographic:
+ case Projector::Stereographic:
m_proj = new StereographicProjector(p);
break;
- case Orthographic:
+ case Projector::Orthographic:
m_proj = new OrthographicProjector(p);
break;
- case AzimuthalEquidistant:
+ case Projector::AzimuthalEquidistant:
m_proj = new AzimuthalEquidistantProjector(p);
break;
- case Equirectangular:
+ case Projector::Equirectangular:
m_proj = new EquirectangularProjector(p);
break;
- case Lambert: default:
+ case Projector::Lambert: default:
//TODO: implement other projection classes
m_proj = new LambertProjector(p);
break;
diff --git a/kstars/skymap.h b/kstars/skymap.h
index 13a5144..dcc5839 100644
--- a/kstars/skymap.h
+++ b/kstars/skymap.h
@@ -93,14 +93,6 @@ class SkyMap : public QGraphicsView {
/** Destructor (empty) */
~SkyMap();
- enum Projection { Lambert,
- AzimuthalEquidistant,
- Orthographic,
- Equirectangular,
- Stereographic,
- Gnomonic,
- UnknownProjection };
-
/** @return the angular field of view of the sky map, in degrees.
*@note it must use either the height or the width of the window to calculate the
*FOV angle. It chooses whichever is larger.
diff --git a/kstars/skymaplite.cpp b/kstars/skymaplite.cpp
index 7bb4c0b..b022561 100644
--- a/kstars/skymaplite.cpp
+++ b/kstars/skymaplite.cpp
@@ -20,6 +20,12 @@
#include "projections/projector.h"
#include "projections/lambertprojector.h"
+#include "projections/gnomonicprojector.h"
+#include "projections/stereographicprojector.h"
+#include "projections/orthographicprojector.h"
+#include "projections/azimuthalequidistantprojector.h"
+#include "projections/equirectangularprojector.h"
+
#include "solarsystemsinglecomponent.h"
#include "Options.h"
@@ -30,42 +36,44 @@
#include <QSGSimpleRectNode>
#include <QSGNode>
#include <QBitmap>
+#include <QSGTexture>
+#include <QQuickWindow>
namespace {
- // Draw bitmap for zoom cursor. Width is size of pen to draw with.
- QBitmap zoomCursorBitmap(int width) {
- QBitmap b(32, 32);
- b.fill(Qt::color0);
- int mx = 16, my = 16;
- // Begin drawing
- QPainter p;
- p.begin( &b );
- p.setPen( QPen( Qt::color1, width ) );
- p.drawEllipse( mx - 7, my - 7, 14, 14 );
- p.drawLine( mx + 5, my + 5, mx + 11, my + 11 );
- p.end();
- return b;
- }
+// Draw bitmap for zoom cursor. Width is size of pen to draw with.
+QBitmap zoomCursorBitmap(int width) {
+ QBitmap b(32, 32);
+ b.fill(Qt::color0);
+ int mx = 16, my = 16;
+ // Begin drawing
+ QPainter p;
+ p.begin( &b );
+ p.setPen( QPen( Qt::color1, width ) );
+ p.drawEllipse( mx - 7, my - 7, 14, 14 );
+ p.drawLine( mx + 5, my + 5, mx + 11, my + 11 );
+ p.end();
+ return b;
+}
- // Draw bitmap for default cursor. Width is size of pen to draw with.
- QBitmap defaultCursorBitmap(int width) {
- QBitmap b(32, 32);
- b.fill(Qt::color0);
- int mx = 16, my = 16;
- // Begin drawing
- QPainter p;
- p.begin( &b );
- p.setPen( QPen( Qt::color1, width ) );
- // 1. diagonal
- p.drawLine (mx - 2, my - 2, mx - 8, mx - 8);
- p.drawLine (mx + 2, my + 2, mx + 8, mx + 8);
- // 2. diagonal
- p.drawLine (mx - 2, my + 2, mx - 8, mx + 8);
- p.drawLine (mx + 2, my - 2, mx + 8, mx - 8);
- p.end();
- return b;
- }
+// Draw bitmap for default cursor. Width is size of pen to draw with.
+QBitmap defaultCursorBitmap(int width) {
+ QBitmap b(32, 32);
+ b.fill(Qt::color0);
+ int mx = 16, my = 16;
+ // Begin drawing
+ QPainter p;
+ p.begin( &b );
+ p.setPen( QPen( Qt::color1, width ) );
+ // 1. diagonal
+ p.drawLine (mx - 2, my - 2, mx - 8, mx - 8);
+ p.drawLine (mx + 2, my + 2, mx + 8, mx + 8);
+ // 2. diagonal
+ p.drawLine (mx - 2, my + 2, mx - 8, mx + 8);
+ p.drawLine (mx + 2, my - 2, mx + 8, mx - 8);
+ p.end();
+ return b;
+}
}
SkyMapLite *SkyMapLite::pinstance = 0;
@@ -88,6 +96,34 @@ SkyMapLite::SkyMapLite(QQuickItem* parent)
initStarImages();
// Set pinstance to yourself
pinstance = this;
+ /*textureCache = QVector<QVector<QSGTexture*>> (imageCache.length());
+
+ for(int i = 0; i < textureCache.length(); ++i) {
+ int length = imageCache[i].length();
+ textureCache[i] = QVector<QSGTexture *>(length);
+ for(int c = 1; c < length; ++c) {
+ textureCache[i][c] = window()->createTextureFromImage(imageCache[i][c]->toImage());
+ }
+ }*/
+}
+
+QSGNode* SkyMapLite::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) {
+ /*if(!textureCache.length()) {
+ textureCache = QVector<QVector<QSGTexture*>> (imageCache.length());
+
+ for(int i = 0; i < textureCache.length(); ++i) {
+ int length = imageCache[i].length();
+ textureCache[i] = QVector<QSGTexture *>(length);
+ for(int c = 1; c < length; ++c) {
+ //textureCache[i][c] = window()->createTextureFromImage(imageCache[i][c]->toImage());
+ }
+ }
+ }*/
+ return oldNode;
+}
+
+QSGTexture* SkyMapLite::getCachedTexture(int size, char spType) {
+ return textureCache[harvardToIndex(spType)][size];
}
SkyMapLite* SkyMapLite::createInstance(QQuickItem* parent) {
@@ -97,7 +133,14 @@ SkyMapLite* SkyMapLite::createInstance(QQuickItem* parent) {
}
SkyMapLite::~SkyMapLite() {
-
+ // Delete image cache
+ foreach(QVector<QPixmap*> imgCache, imageCache) {
+ foreach(QPixmap* img, imgCache) delete img;
+ }
+ // Delete textures generated from image cache
+ foreach(QVector<QSGTexture*> tCache, textureCache) {
+ foreach(QSGTexture* t, tCache) delete t;
+ }
}
void SkyMapLite::setFocus( SkyPoint *p ) {
@@ -235,35 +278,33 @@ void SkyMapLite::setupProjector() {
p.useRefraction = Options::useRefraction();
p.zoomFactor = Options::zoomFactor();
p.fillGround = Options::showGround();
- if(!m_proj) m_proj = new LambertProjector(p);
- else m_proj->setViewParams(p);
//Check if we need a new projector
- /*if( m_proj && Options::projection() == m_proj->type() )
+ if( m_proj && Options::projection() == m_proj->type() )
m_proj->setViewParams(p);
else {
delete m_proj;
switch( Options::projection() ) {
- case Gnomonic:
- m_proj = new GnomonicProjector(p);
- break;
- case Stereographic:
- m_proj = new StereographicProjector(p);
- break;
- case Orthographic:
- m_proj = new OrthographicProjector(p);
- break;
- case AzimuthalEquidistant:
- m_proj = new AzimuthalEquidistantProjector(p);
- break;
- case Equirectangular:
- m_proj = new EquirectangularProjector(p);
- break;
- case Lambert: default:
- //TODO: implement other projection classes
- m_proj = new LambertProjector(p);
- break;
+ case Projector::Gnomonic:
+ m_proj = new GnomonicProjector(p);
+ break;
+ case Projector::Stereographic:
+ m_proj = new StereographicProjector(p);
+ break;
+ case Projector::Orthographic:
+ m_proj = new OrthographicProjector(p);
+ break;
+ case Projector::AzimuthalEquidistant:
+ m_proj = new AzimuthalEquidistantProjector(p);
+ break;
+ case Projector::Equirectangular:
+ m_proj = new EquirectangularProjector(p);
+ break;
+ case Projector::Lambert: default:
+ //TODO: implement other projection classes
+ m_proj = new LambertProjector(p);
+ break;
}
- }*/
+ }
}
void SkyMapLite::setZoomMouseCursor()
@@ -303,7 +344,7 @@ int SkyMapLite::harvardToIndex(char c) {
case 'g': case 'G': return 4;
case 'k': case 'K': return 5;
case 'm': case 'M': return 6;
- // For unknown spectral class assume A class (white star)
+ // For unknown spectral class assume A class (white star)
default: return 2;
}
}
@@ -395,15 +436,15 @@ void SkyMapLite::initStarImages()
p.drawEllipse( QRectF( 2, 2, 10, 10 ) );
}
p.end();
-//[nSPclasses][nStarSizes];
+ //[nSPclasses][nStarSizes];
// Cache array slice
QVector<QPixmap *> pmap = imageCache[ harvardToIndex(color) ];
pmap.append(new QPixmap());
for( int size = 1; size < nStarSizes; size++ ) {
//if( !pmap[size] ) {
- pmap.append(new QPixmap());
- *pmap[size] = BigImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
+ pmap.append(new QPixmap());
+ *pmap[size] = BigImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
//}
}
imageCache[ harvardToIndex(color) ] = pmap;
diff --git a/kstars/skymaplite.h b/kstars/skymaplite.h
index 34d300a..2a7bf10 100644
--- a/kstars/skymaplite.h
+++ b/kstars/skymaplite.h
@@ -24,6 +24,7 @@
#include <config-kstars.h>
#include <QQuickItem>
+#include <QPolygonF>
class dms;
class KStarsData;
@@ -32,6 +33,8 @@ class Projector;
class SolarSystemSingleComponent;
class PlanetsItem;
+class QSGTexture;
+
/** @class SkyMapLite
*
*This is the main item that displays all SkyItems. After its instantiation it is reparanted
@@ -55,7 +58,7 @@ protected:
*/
explicit SkyMapLite(QQuickItem* parent = 0);
- //virtual QSGNode* updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
+ virtual QSGNode* updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
public:
static SkyMapLite* createInstance(QQuickItem* parent = 0);
@@ -233,14 +236,22 @@ public:
/** @short Returns index for a Harvard spectral classification */
int harvardToIndex(char c);
- /** @short Initializes images of Stars and put it in cache (copied from SkyQPainter)*/
- void initStarImages();
-
/** @short returns cache of star images
* @return star images cache
*/
QVector<QVector<QPixmap*>> getImageCache();
+ /**
+ * @short returns cached texture from textureCache.
+ *
+ * Use outside of scene graph rendering thread (e.g. not during call to updatePaintNode)
+ * is prohibited!
+ * @param size size of the star
+ * @param spType spectral class
+ * @return cached QSGTexture from textureCache
+ */
+ QSGTexture* getCachedTexture(int size, char spType);
+
//bool isSlewing() const;
// NOTE: This method is draw-backend independent.
@@ -274,13 +285,6 @@ public:
SkyPoint getCenterPoint();*/
- // This can be later changed
- // Total number of sizes of stars.
- const int nStarSizes;
- // Total number of specatral classes
- // N.B. Must be in sync with harvardToIndex
- const int nSPclasses;
-
Projector* m_proj;
public slots:
@@ -292,20 +296,19 @@ public slots:
/** Recalculates the positions of objects in the sky, and then repaints the sky map.
* If the positions don't need to be recalculated, use update() instead of forceUpdate().
* This saves a lot of CPU time.
- * @param now if true, paintEvent() is run immediately. Otherwise, it is added to the event queue
*/
void forceUpdate();
- /** @short Convenience function; simply calls forceUpdate(true).
+ /** @short Left for compatibility reasons
* @see forceUpdate()
*/
void forceUpdateNow() { forceUpdate(); }
/**
* @short Update the focus point and call forceUpdate()
- * @param now is passed on to forceUpdate()
+ * @param now is saved for compatibility reasons
*/
- void slotUpdateSky( bool now ) { }
+ void slotUpdateSky( bool now ) {Q_UNUSED(now)}
/** Toggle visibility of geo infobox */
//void slotToggleGeoBox(bool);
@@ -512,6 +515,9 @@ private:
*/
void zoomOutOrMagStep( const int modifier );
+ /** @short Initializes images of Stars and puts them in cache (copied from SkyQPainter)*/
+ void initStarImages();
+
bool mouseButtonDown, midMouseButtonDown;
// true if mouseMoveEvent; needed by setMouseMoveCursor
bool mouseMoveCursor;
@@ -561,10 +567,18 @@ private:
const SkyPoint *m_rulerStartPoint; // Good to keep the original ruler start-point for purposes of dynamic_cast
+ // This can be later changed
+ // Total number of sizes of stars.
+ const int nStarSizes;
+ // Total number of specatral classes
+ // N.B. Must be in sync with harvardToIndex
+ const int nSPclasses;
//This can be later changed
// Cache for star images.
QVector<QVector<QPixmap*>> imageCache;
+ //Textures created from cached star images
+ QVector<QVector<QSGTexture*>> textureCache;
};