Commit ee72b175 authored by Artem Fedoskin's avatar Artem Fedoskin
Browse files

Moved Projection enum from SkyMap to Projector. Introduced RootNode

class that handles texture generation and clipping.
parent ea7ea2d0
......@@ -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
......
......@@ -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();
......
......@@ -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
......
......@@ -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;
......
#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];
}
......@@ -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();
......
......@@ -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
......
#include "planetrootnode.h"
#include "skymaplite.h"
#include <QSGTexture>
#include <QQuickWindow>
PlanetRootNode::PlanetRootNode() {
}
/** *************************************************************************
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
......@@ -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);
......
......@@ -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
#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 ();
}
}
}
/** *************************************************************************
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
......@@ -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 {
......
......@@ -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
......
......@@ -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;
......
......@@ -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
......
......@@ -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;
......
......@@ -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
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment