summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Fedoskin <afedoskin3@gmail.com>2016-06-18 09:02:54 (GMT)
committerArtem Fedoskin <afedoskin3@gmail.com>2016-06-18 09:02:54 (GMT)
commite782b2201100e67bb0514fd4b719f4e363a6df22 (patch)
treea89683d494164f8b03ee0d32597e13dfa8caaf92
parent7fd5cf743a9a47255d635ebc48dd83a70cff86d9 (diff)
Added support for unnamed static stars. Started working on dynamic
stars.
-rw-r--r--kstars/CMakeLists.txt1
-rw-r--r--kstars/kstarslite/skyitems/deepstaritem.cpp368
-rw-r--r--kstars/kstarslite/skyitems/deepstaritem.h57
-rw-r--r--kstars/kstarslite/skyitems/labelsitem.cpp5
-rw-r--r--kstars/kstarslite/skyitems/labelsitem.h2
-rw-r--r--kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp14
-rw-r--r--kstars/kstarslite/skyitems/staritem.cpp61
-rw-r--r--kstars/kstarslite/skyitems/staritem.h5
-rw-r--r--kstars/skycomponents/deepstarcomponent.cpp20
-rw-r--r--kstars/skycomponents/deepstarcomponent.h2
-rw-r--r--kstars/skycomponents/starblock.cpp52
-rw-r--r--kstars/skycomponents/starblock.h27
-rw-r--r--kstars/skycomponents/starblocklist.cpp12
-rw-r--r--kstars/skycomponents/starcomponent.cpp1
-rw-r--r--kstars/skymaplite.cpp30
-rw-r--r--kstars/skymaplite.h12
16 files changed, 621 insertions, 48 deletions
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index 9154b08..49f0cff 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -557,6 +557,7 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyitems/labelsitem.cpp
kstarslite/skyitems/constellationnamesitem.cpp
kstarslite/skyitems/staritem.cpp
+ kstarslite/skyitems/deepstaritem.cpp
#Lines
kstarslite/skyitems/lines/linesitem.cpp
kstarslite/skyitems/lines/equatoritem.cpp
diff --git a/kstars/kstarslite/skyitems/deepstaritem.cpp b/kstars/kstarslite/skyitems/deepstaritem.cpp
new file mode 100644
index 0000000..9325afb
--- /dev/null
+++ b/kstars/kstarslite/skyitems/deepstaritem.cpp
@@ -0,0 +1,368 @@
+/** *************************************************************************
+ deepstaritem.cpp - K Desktop Planetarium
+ -------------------
+ begin : 17/06/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. *
+ * *
+ ***************************************************************************/
+
+#include "Options.h"
+#include "projections/projector.h"
+
+#include "skynodes/pointsourcenode.h"
+#include "labelsitem.h"
+#include "deepstaritem.h"
+
+#include "deepstarcomponent.h"
+#include "starcomponent.h"
+
+#include "starblockfactory.h"
+#include "skymesh.h"
+#include "rootnode.h"
+
+DeepStarItem::DeepStarItem(DeepStarComponent *deepStarComp, RootNode *rootNode)
+ :SkyItem(LabelsItem::label_t::NO_LABEL, rootNode), m_deepStarComp(deepStarComp),
+ m_staticStars(deepStarComp->staticStars)
+{
+ m_starBlockList = &m_deepStarComp->m_starBlockList;
+
+ //Test
+ Options::setShowStarMagnitudes(false);
+ Options::setShowStarNames(true);
+
+ for(int c = 0; c < m_starBlockList->size(); ++c) {
+ TrixelNode *trixel = new TrixelNode;
+ appendChildNode(trixel);
+ if(m_staticStars) {
+ int blockCount = m_starBlockList->at( c )->getBlockCount();
+
+ for( int i = 0; i < blockCount; ++i ) {
+ StarBlock *block = m_starBlockList->at( c )->block( i );
+ // qDebug() << "---> Drawing stars from block " << i << " of trixel " <<
+ // currentRegion << ". SB has " << block->getStarCount() << " stars" << endl;
+ int starCount = block->getStarCount();
+ for( int j = 0; j < starCount; j++ ) {
+
+ StarObject *star = &(block->star( j )->star);
+
+ if(star) {
+ PointSourceNode *point = new PointSourceNode(star, rootNode, LabelsItem::label_t::NO_LABEL, star->spchar(),
+ star->mag(), i);
+ trixel->appendChildNode(point);
+ }
+ }
+ }
+ }
+ }
+
+ m_skyMesh = SkyMesh::Instance();
+ m_StarBlockFactory = StarBlockFactory::Instance();
+}
+
+void DeepStarItem::update() {
+#ifndef KSTARS_LITE
+ //adjust maglimit for ZoomLevel
+ // double lgmin = log10(MINZOOM);
+ // double lgmax = log10(MAXZOOM);
+ // double lgz = log10(Options::zoomFactor());
+ // TODO: Enable hiding of faint stars
+
+ float maglim = StarComponent::zoomMagnitudeLimit();
+
+ if( maglim < triggerMag )
+ return;
+
+ m_zoomMagLimit = maglim;
+
+ m_skyMesh->inDraw( true );
+
+ SkyPoint* focus = map->focus();
+ m_skyMesh->aperture( focus, radius + 1.0, DRAW_BUF ); // divide by 2 for testing
+
+ MeshIterator region(m_skyMesh, DRAW_BUF);
+
+ magLim = maglim;
+
+ // If we are to hide the fainter stars (eg: while slewing), we set the magnitude limit to hideStarsMag.
+ if( hideFaintStars && maglim > hideStarsMag )
+ maglim = hideStarsMag;
+
+ StarBlockFactory *m_StarBlockFactory = StarBlockFactory::Instance();
+ // m_StarBlockFactory->drawID = m_skyMesh->drawID();
+ // qDebug() << "Mesh size = " << m_skyMesh->size() << "; drawID = " << m_skyMesh->drawID();
+ QTime t;
+ int nTrixels = 0;
+
+ t_dynamicLoad = 0;
+ t_updateCache = 0;
+ t_drawUnnamed = 0;
+
+ visibleStarCount = 0;
+
+ t.start();
+
+ // Mark used blocks in the LRU Cache. Not required for static stars
+ if( !staticStars ) {
+ while( region.hasNext() ) {
+ Trixel currentRegion = region.next();
+ for( int i = 0; i < m_starBlockList.at( currentRegion )->getBlockCount(); ++i ) {
+ StarBlock *prevBlock = ( ( i >= 1 ) ? m_starBlockList.at( currentRegion )->block( i - 1 ) : NULL );
+ StarBlock *block = m_starBlockList.at( currentRegion )->block( i );
+
+ if( i == 0 && !m_StarBlockFactory->markFirst( block ) )
+ qDebug() << "markFirst failed in trixel" << currentRegion;
+ if( i > 0 && !m_StarBlockFactory->markNext( prevBlock, block ) )
+ qDebug() << "markNext failed in trixel" << currentRegion << "while marking block" << i;
+ if( i < m_starBlockList.at( currentRegion )->getBlockCount()
+ && m_starBlockList.at( currentRegion )->block( i )->getFaintMag() < maglim )
+ break;
+
+ }
+ }
+ t_updateCache = t.restart();
+ region.reset();
+ }
+
+ while ( region.hasNext() ) {
+ ++nTrixels;
+ Trixel currentRegion = region.next();
+
+ // NOTE: We are guessing that the last 1.5/16 magnitudes in the catalog are just additions and the star catalog
+ // is actually supposed to reach out continuously enough only to mag m_FaintMagnitude * ( 1 - 1.5/16 )
+ // TODO: Is there a better way? We may have to change the magnitude tolerance if the catalog changes
+ // Static stars need not execute fillToMag
+
+ if( !staticStars && !m_starBlockList.at( currentRegion )->fillToMag( maglim ) && maglim <= m_FaintMagnitude * ( 1 - 1.5/16 ) ) {
+ qDebug() << "SBL::fillToMag( " << maglim << " ) failed for trixel "
+ << currentRegion << " !"<< endl;
+ }
+
+ t_dynamicLoad += t.restart();
+
+ // qDebug() << "Drawing SBL for trixel " << currentRegion << ", SBL has "
+ // << m_starBlockList[ currentRegion ]->getBlockCount() << " blocks" << endl;
+
+ for( int i = 0; i < m_starBlockList.at( currentRegion )->getBlockCount(); ++i ) {
+ StarBlock *block = m_starBlockList.at( currentRegion )->block( i );
+ // qDebug() << "---> Drawing stars from block " << i << " of trixel " <<
+ // currentRegion << ". SB has " << block->getStarCount() << " stars" << endl;
+ for( int j = 0; j < block->getStarCount(); j++ ) {
+
+ StarObject *curStar = block->star( j );
+
+ // qDebug() << "We claim that he's from trixel " << currentRegion
+ //<< ", and indexStar says he's from " << m_skyMesh->indexStar( curStar );
+
+ if ( curStar->updateID != updateID )
+ curStar->JITupdate();
+
+ float mag = curStar->mag();
+
+ if ( mag > maglim )
+ break;
+
+ if( skyp->drawPointSource(curStar, mag, curStar->spchar() ) )
+ visibleStarCount++;
+ }
+ }
+
+ // DEBUG: Uncomment to identify problems with Star Block Factory / preservation of Magnitude Order in the LRU Cache
+ // verifySBLIntegrity();
+ t_drawUnnamed += t.restart();
+
+ }
+ m_skyMesh->inDraw( false );
+#endif
+
+ //if(m_staticStars) {
+ SkyMapLite *map = SkyMapLite::Instance();
+ KStarsData* data = KStarsData::Instance();
+ UpdateID updateID = data->updateID();
+
+ //FIXME_FOV -- maybe not clamp like that...
+ float radius = map->projector()->fov();
+ if ( radius > 90.0 ) radius = 90.0;
+
+ if ( m_skyMesh != SkyMesh::Instance() && m_skyMesh->inDraw() ) {
+ printf("Warning: aborting concurrent DeepStarComponent::draw()");
+ }
+ bool checkSlewing = ( map->isSlewing() && Options::hideOnSlew() );
+
+ //shortcuts to inform whether to draw different objects
+ bool hideFaintStars( checkSlewing && Options::hideStars() );
+ double hideStarsMag = Options::magLimitHideStar();
+
+ //adjust maglimit for ZoomLevel
+ // double lgmin = log10(MINZOOM);
+ // double lgmax = log10(MAXZOOM);
+ // double lgz = log10(Options::zoomFactor());
+ // TODO: Enable hiding of faint stars
+
+ float maglim = StarComponent::zoomMagnitudeLimit();
+
+ if( maglim < m_deepStarComp->triggerMag || !m_staticStars ) {
+ hide();
+ return;
+ } else {
+ show();
+ }
+
+ float m_zoomMagLimit = maglim;
+
+ m_skyMesh->inDraw( true );
+
+ SkyPoint* focus = map->focus();
+ m_skyMesh->aperture( focus, radius + 1.0, DRAW_BUF ); // divide by 2 for testing
+
+ MeshIterator region(m_skyMesh, DRAW_BUF);
+
+ // If we are to hide the fainter stars (eg: while slewing), we set the magnitude limit to hideStarsMag.
+ if( hideFaintStars && maglim > hideStarsMag )
+ maglim = hideStarsMag;
+
+ StarBlockFactory *m_StarBlockFactory = StarBlockFactory::Instance();
+ // m_StarBlockFactory->drawID = m_skyMesh->drawID();
+ // qDebug() << "Mesh size = " << m_skyMesh->size() << "; drawID = " << m_skyMesh->drawID();
+
+ /*t_dynamicLoad = 0;
+ t_updateCache = 0;
+ t_drawUnnamed = 0;*/
+
+ //visibleStarCount = 0;
+
+ // Mark used blocks in the LRU Cache. Not required for static stars
+ if( !m_staticStars ) {
+ while( region.hasNext() ) {
+ Trixel currentRegion = region.next();
+ for( int i = 0; i < m_starBlockList->at( currentRegion )->getBlockCount(); ++i ) {
+ StarBlock *prevBlock = ( ( i >= 1 ) ? m_starBlockList->at( currentRegion )->block( i - 1 ) : NULL );
+ StarBlock *block = m_starBlockList->at( currentRegion )->block( i );
+
+ if( i == 0 && !m_StarBlockFactory->markFirst( block ) )
+ qDebug() << "markFirst failed in trixel" << currentRegion;
+ if( i > 0 && !m_StarBlockFactory->markNext( prevBlock, block ) )
+ qDebug() << "markNext failed in trixel" << currentRegion << "while marking block" << i;
+ if( i < m_starBlockList->at( currentRegion )->getBlockCount()
+ && m_starBlockList->at( currentRegion )->block( i )->getFaintMag() < maglim )
+ break;
+ }
+ }
+ //t_updateCache = t.restart();
+ region.reset();
+ }
+
+ m_StarBlockFactory->drawID = m_skyMesh->drawID();
+
+ int regionID = -1;
+ if(region.hasNext()) {
+ regionID = region.next();
+ }
+
+ int trixelID = 0;
+
+ QSGNode *firstTrixel = firstChild();
+ TrixelNode *trixel = static_cast<TrixelNode *>(firstTrixel);
+
+ while( trixel != 0 ) {
+ if(trixelID != regionID) {
+ trixel->hide();
+
+ trixel = static_cast<TrixelNode *>(trixel->nextSibling());
+
+ trixelID++;
+
+ continue;
+ } else {
+ trixel->show();
+
+ if(region.hasNext()) {
+ regionID = region.next();
+
+ }
+ }
+
+ if(m_staticStars) {
+
+ QSGNode *n = trixel->firstChild();
+
+ bool hide = false;
+
+ while(n != 0) {
+ PointSourceNode *point = static_cast<PointSourceNode *>(n);
+ n = n->nextSibling();
+
+ StarObject *curStar = static_cast<StarObject *>(point->skyObject());
+ float mag = curStar->mag();
+
+ // break loop if maglim is reached
+ if(!hide) {
+ if ( mag > maglim ) hide = true;
+ }
+
+ if(!hide) {
+ if ( curStar->updateID != KStarsData::Instance()->updateID() )
+ curStar->JITupdate();
+ point->setSizeMagLim(m_zoomMagLimit);
+ point->update();
+ } else {
+ point->hide();
+ }
+ }
+ } else if(false) {
+ if( !m_staticStars && !m_starBlockList->at( regionID )->fillToMag( maglim ) && maglim <= m_deepStarComp->m_FaintMagnitude * ( 1 - 1.5/16 ) ) {
+ qDebug() << "SBL::fillToMag( " << maglim << " ) failed for trixel "
+ << regionID << " !"<< endl;
+ }
+
+ for( int i = 0; i < m_starBlockList->at( regionID )->getBlockCount(); ++i ) {
+
+ bool hide = false;
+
+ StarBlock *block = m_starBlockList->at( regionID )->block( i );
+ for( int j = 0; j < block->getStarCount(); j++ ) {
+
+ StarNode *star = block->star( j );
+ StarObject *curStar = &(star->star);
+ PointSourceNode *point = star->starNode;
+
+ if ( curStar->updateID != updateID )
+ curStar->JITupdate();
+
+ float mag = curStar->mag();
+
+ if(!hide) {
+ if ( mag > maglim ) hide = true;
+ }
+
+ if(!hide) {
+ if(!point) {
+ star->starNode = new PointSourceNode(curStar, rootNode(), LabelsItem::label_t::NO_LABEL, curStar->spchar(),
+ curStar->mag(), regionID);
+ point = star->starNode;
+ trixel->appendChildNode(point);
+ }
+ point->setSizeMagLim(m_zoomMagLimit);
+ point->update();
+
+ } else {
+ if(point) point->hide();
+ }
+ }
+ }
+ }
+ trixel = static_cast<TrixelNode *>(trixel->nextSibling());
+
+ trixelID++;
+ }
+ m_skyMesh->inDraw( false );
+}
+//}
+
diff --git a/kstars/kstarslite/skyitems/deepstaritem.h b/kstars/kstarslite/skyitems/deepstaritem.h
new file mode 100644
index 0000000..625e690
--- /dev/null
+++ b/kstars/kstarslite/skyitems/deepstaritem.h
@@ -0,0 +1,57 @@
+/** *************************************************************************
+ deepstaritem.h - K Desktop Planetarium
+ -------------------
+ begin : 17/06/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 DEEPSTARITEM_H_
+#define DEEPSTARITEM_H_
+
+#include "skyitem.h"
+#include "skyopacitynode.h"
+#include "typedeflite.h"
+
+ /** @class DeepStarItem
+ *
+ *@short Class that handles unnamed Stars
+ *@author Artem Fedoskin
+ *@version 1.0
+ */
+
+class DeepStarComponent;
+class SkyMesh;
+class StarBlockFactory;
+class StarBlockList;
+
+class DeepStarItem : public SkyItem {
+public:
+ /**
+ * @short Constructor.
+ * @param rootNode parent RootNode that instantiated this object
+ */
+ DeepStarItem(DeepStarComponent *deepStarComp, RootNode *rootNode);
+
+ /**
+ * @short updates all trixels that contain stars
+ */
+ virtual void update();
+
+private:
+ SkyMesh *m_skyMesh;
+ StarBlockFactory *m_StarBlockFactory;
+
+ DeepStarComponent *m_deepStarComp;
+ QVector< StarBlockList *> *m_starBlockList;
+ bool m_staticStars;
+};
+#endif
+
diff --git a/kstars/kstarslite/skyitems/labelsitem.cpp b/kstars/kstarslite/skyitems/labelsitem.cpp
index e7939cc..dc1d0ac 100644
--- a/kstars/kstarslite/skyitems/labelsitem.cpp
+++ b/kstars/kstarslite/skyitems/labelsitem.cpp
@@ -147,6 +147,9 @@ void LabelsItem::update() {
updateChildLabels(label_t::STAR_LABEL);
}
+void LabelsItem::hideLabels(label_t labelType) {
+ if (labelType != NO_LABEL) m_labelsLists[labelType]->hide();
+}
void LabelsItem::setRootNode(RootNode *rootNode) {
//Remove from previous parent if had any
@@ -158,7 +161,7 @@ void LabelsItem::setRootNode(RootNode *rootNode) {
}
void LabelsItem::deleteLabels(label_t labelType) {
- if(labelType != label_t::NO_LABEL) {
+ if(labelType != NO_LABEL) {
LabelTypeNode *node = m_labelsLists[labelType];
while(QSGNode *n = node->firstChild()) { node->removeChildNode(n); delete n; }
}
diff --git a/kstars/kstarslite/skyitems/labelsitem.h b/kstars/kstarslite/skyitems/labelsitem.h
index 1f42876..2081dcf 100644
--- a/kstars/kstarslite/skyitems/labelsitem.h
+++ b/kstars/kstarslite/skyitems/labelsitem.h
@@ -146,7 +146,7 @@ public:
* @short hides all labels of type labelType
*/
- inline void hideLabels(label_t labelType) { m_labelsLists[labelType]->hide(); }
+ void hideLabels(label_t labelType);
/**
* @short sets m_rootNode and appends to it this node
diff --git a/kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp b/kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp
index b75a108..c45d2e7 100644
--- a/kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp
+++ b/kstars/kstarslite/skyitems/skynodes/pointsourcenode.cpp
@@ -31,7 +31,8 @@ PointSourceNode::PointSourceNode(SkyObject * skyObject, RootNode * parentNode,
m_label(0), m_labelType(labelType), m_rootNode(parentNode), m_trixel(trixel)
{
m_point = new PointNode(parentNode,spType,starWidth(size));
- appendChildNode(m_point);
+ //appendChildNode(m_opacity);
+ m_opacity->appendChildNode(m_point);
}
float PointSourceNode::starWidth(float mag) const
@@ -75,9 +76,10 @@ void PointSourceNode::update() {
if( visible && projector()->onScreen(pos) ) { // FIXME: onScreen here should use canvas size rather than SkyMap size, especially while printing in portrait mode!
m_point->setSize(starWidth(m_skyObject->mag()));
changePos(pos);
- m_point->show();
+ show();
+ //m_point->show();
- if(m_drawLabel) {
+ if(m_drawLabel && m_labelType != LabelsItem::label_t::NO_LABEL) {
if(!m_label) { //This way labels will be created only when they are needed
if(m_trixel != -1) {
m_label = m_rootNode->labelsItem()->addLabel(m_skyObject, m_labelType, m_trixel);
@@ -89,15 +91,13 @@ void PointSourceNode::update() {
} else {
if(m_label) m_label->hide();
}
-
-
} else {
hide();
}
-
}
void PointSourceNode::hide() {
if(m_label) m_label->hide();
- m_point->hide();
+ //m_point->hide();
+ SkyNode::hide();
}
diff --git a/kstars/kstarslite/skyitems/staritem.cpp b/kstars/kstarslite/skyitems/staritem.cpp
index 4514a54..c4a402f 100644
--- a/kstars/kstarslite/skyitems/staritem.cpp
+++ b/kstars/kstarslite/skyitems/staritem.cpp
@@ -20,6 +20,7 @@
#include "skynodes/pointsourcenode.h"
#include "labelsitem.h"
#include "staritem.h"
+#include "deepstaritem.h"
#include "starcomponent.h"
#include "starblockfactory.h"
@@ -28,9 +29,11 @@
StarItem::StarItem(StarComponent *starComp, RootNode *rootNode)
:SkyItem(LabelsItem::label_t::STAR_LABEL, rootNode), m_starComp(starComp)
- ,m_starLabels(rootNode->labelsItem()->getLabelNode(labelType()))
+ ,m_starLabels(rootNode->labelsItem()->getLabelNode(labelType())), m_stars(new SkyOpacityNode),
+ m_deepStars(new SkyOpacityNode)
{
StarIndex *trixels = m_starComp->starIndex();
+ appendChildNode(m_stars);
//Test
Options::setShowStarMagnitudes(false);
@@ -39,7 +42,7 @@ StarItem::StarItem(StarComponent *starComp, RootNode *rootNode)
for(int i = 0; i < trixels->size(); ++i) {
StarList *skyList = trixels->at(i);
TrixelNode *trixel = new TrixelNode;
- appendChildNode(trixel);
+ m_stars->appendChildNode(trixel);
for(int c = 0; c < skyList->size(); ++c) {
StarObject *star = skyList->at(c);
@@ -51,21 +54,28 @@ StarItem::StarItem(StarComponent *starComp, RootNode *rootNode)
}
}
+ appendChildNode(m_deepStars);
+
+ QVector<DeepStarComponent*> deepStars = m_starComp->m_DeepStarComponents;
+ int deepSize = deepStars.size();
+ for(int i = 0; i < deepSize; ++i) {
+ DeepStarItem *deepStar = new DeepStarItem(deepStars[i], rootNode);
+ rootNode->removeChildNode(deepStar);
+ m_deepStars->appendChildNode(deepStar);
+ }
+
m_skyMesh = SkyMesh::Instance();
m_StarBlockFactory = StarBlockFactory::Instance();
}
void StarItem::update() {
-
if( !m_starComp->selected() ) {
hide();
return;
}
SkyMapLite *map = SkyMapLite::Instance();
- const Projector *proj = map->projector();
KStarsData* data = KStarsData::Instance();
- UpdateID updateID = data->updateID();
bool checkSlewing = ( map->isSlewing() && Options::hideOnSlew() );
bool hideLabels = checkSlewing || !( Options::showStarMagnitudes() || Options::showStarNames() );
@@ -81,7 +91,7 @@ void StarItem::update() {
double maglim;
double m_zoomMagLimit; //Check it later. Needed for labels
- m_zoomMagLimit = maglim = m_starComp->zoomMagnitudeLimit();
+ m_zoomMagLimit = maglim = StarComponent::zoomMagnitudeLimit();
double labelMagLim = Options::starLabelDensity() / 5.0;
labelMagLim += ( 12.0 - labelMagLim ) * ( lgz - lgmin) / (lgmax - lgmin );
@@ -106,26 +116,30 @@ void StarItem::update() {
//Loop for drawing star images
+ float radius = map->projector()->fov();
+ if ( radius > 90.0 ) radius = 90.0;
+
+ m_skyMesh->inDraw( true );
+
+ SkyPoint* focus = map->focus();
+ m_skyMesh->aperture( focus, radius + 1.0, DRAW_BUF ); // divide by 2 for testing
+
MeshIterator region(m_skyMesh, DRAW_BUF);
// If we are hiding faint stars, then maglim is really the brighter of hideStarsMag and maglim
if( hideFaintStars && maglim > hideStarsMag )
maglim = hideStarsMag;
- m_magLim = maglim;
-
m_StarBlockFactory->drawID = m_skyMesh->drawID();
- int nTrixels = 0;
-
int regionID = -1;
if(region.hasNext()) {
regionID = region.next();
}
int trixelID = 0;
- //++nTrixels;
- QSGNode *firstTrixel = firstChild();
+
+ QSGNode *firstTrixel = m_stars->firstChild();
TrixelNode *trixel = static_cast<TrixelNode *>(firstTrixel);
QSGNode *firstLabel = m_starLabels->firstChild();
@@ -153,6 +167,8 @@ void StarItem::update() {
QSGNode *n = trixel->firstChild();
+ bool hide = false;
+
while(n != 0) {
PointSourceNode *point = static_cast<PointSourceNode *>(n);
n = n->nextSibling();
@@ -160,12 +176,12 @@ void StarItem::update() {
StarObject *curStar = static_cast<StarObject *>(point->skyObject());
float mag = curStar->mag();
- bool hide = false;
-
- // break loop if maglim is reached
- if ( mag > m_magLim ) hide = true;
bool drawLabel = false;
- if(mag < labelMagLim) drawLabel = true;
+ // break loop if maglim is reached
+ if(!hide) {
+ if ( mag > maglim ) hide = true;
+ if(!(hideLabels || mag > labelMagLim)) drawLabel = true;
+ }
if(!hide) {
if ( curStar->updateID != KStarsData::Instance()->updateID() )
@@ -191,8 +207,13 @@ void StarItem::update() {
}*/
// Now draw each of our DeepStarComponents
- /*for( int i =0; i < m_DeepStarComponents.size(); ++i ) {
- m_DeepStarComponents.at( i )->draw( skyp );
- }*/
+ QSGNode *deep = m_deepStars->firstChild();
+ while( deep != 0 ) {
+ DeepStarItem *deepStars = static_cast<DeepStarItem *>(deep);
+ deep = deep->nextSibling();
+ deepStars->update();
+ }
+
+ m_skyMesh->inDraw( false );
}
diff --git a/kstars/kstarslite/skyitems/staritem.h b/kstars/kstarslite/skyitems/staritem.h
index 831d0df..f30e7c2 100644
--- a/kstars/kstarslite/skyitems/staritem.h
+++ b/kstars/kstarslite/skyitems/staritem.h
@@ -42,15 +42,16 @@ public:
/**
* @short updates all trixels that contain stars
*/
- float m_magLim;
virtual void update();
private:
StarComponent *m_starComp;
SkyMesh *m_skyMesh;
StarBlockFactory *m_StarBlockFactory;
+
+ SkyOpacityNode *m_stars;
+ SkyOpacityNode *m_deepStars;
SkyOpacityNode *m_starLabels;
- //QMap<QSGOpacityNode *,LineListIndex *> m_lineIndexes;
};
#endif
diff --git a/kstars/skycomponents/deepstarcomponent.cpp b/kstars/skycomponents/deepstarcomponent.cpp
index 976f6c0..a2ca3e1 100644
--- a/kstars/skycomponents/deepstarcomponent.cpp
+++ b/kstars/skycomponents/deepstarcomponent.cpp
@@ -131,10 +131,17 @@ bool DeepStarComponent::loadStaticStars() {
/* Initialize star with data just read. */
StarObject* star;
if( starReader.guessRecordSize() == 32 )
+ #ifdef KSTARS_LITE
+ star = &(SB->addStar( stardata )->star);
+ #else
star = SB->addStar( stardata );
+ #endif
else
+ #ifdef KSTARS_LITE
+ star = &(SB->addStar( stardata )->star);
+ #else
star = SB->addStar( deepstardata );
-
+ #endif
if( star ) {
KStarsData* data = KStarsData::Instance();
star->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
@@ -306,8 +313,9 @@ void DeepStarComponent::draw( SkyPainter *skyp ) {
}
m_skyMesh->inDraw( false );
-#endif
+#else
Q_UNUSED(skyp)
+#endif
}
bool DeepStarComponent::openDataFile() {
@@ -388,7 +396,11 @@ SkyObject* DeepStarComponent::objectNearest( SkyPoint *p, double &maxrad )
for( int i = 0; i < m_starBlockList.at( currentRegion )->getBlockCount(); ++i ) {
StarBlock *block = m_starBlockList.at( currentRegion )->block( i );
for( int j = 0; j < block->getStarCount(); ++j ) {
+#ifdef KSTARS_LITE
+ StarObject* star = &(block->star( j )->star);
+#else
StarObject* star = block->star( j );
+#endif
if( !star ) continue;
if ( star->mag() > m_zoomMagLimit ) continue;
@@ -443,7 +455,11 @@ bool DeepStarComponent::starsInAperture( QList<StarObject *> &list, const SkyPoi
for( int i = 0; i < sbl->getBlockCount(); ++i ) {
StarBlock *block = sbl->block( i );
for( int j = 0; j < block->getStarCount(); ++j ) {
+#ifdef KSTARS_LITE
+ StarObject *star = &(block->star( j )->star);
+#else
StarObject *star = block->star( j );
+#endif
if( star->mag() > maglim )
break; // Stars are organized by magnitude, so this should work
if( star->angularDistanceTo( &center ).Degrees() <= radius )
diff --git a/kstars/skycomponents/deepstarcomponent.h b/kstars/skycomponents/deepstarcomponent.h
index fb00ee9..2427844 100644
--- a/kstars/skycomponents/deepstarcomponent.h
+++ b/kstars/skycomponents/deepstarcomponent.h
@@ -48,6 +48,8 @@ class StarBlockList;
class DeepStarComponent: public ListComponent
{
+ friend class DeepStarItem; //Needs access to staticStars and buch of other facilities
+
public:
DeepStarComponent( SkyComposite *parent, QString fileName, float trigMag, bool staticstars=false );
diff --git a/kstars/skycomponents/starblock.cpp b/kstars/skycomponents/starblock.cpp
index 373006d..2a28ff2 100644
--- a/kstars/skycomponents/starblock.cpp
+++ b/kstars/skycomponents/starblock.cpp
@@ -20,9 +20,26 @@
#include "starcomponent.h"
#include "skyobjects/stardata.h"
#include "skyobjects/deepstardata.h"
+#include "skymaplite.h"
#include <QDebug>
+#ifdef KSTARS_LITE
+#include "kstarslite/skyitems/skynodes/pointsourcenode.h"
+
+StarNode::StarNode()
+ :starNode(0)
+{
+
+}
+
+StarNode::~StarNode() {
+ if(starNode) {
+ SkyMapLite::Instance()->deleteSkyNode(starNode);
+ qDebug() << "REAL NODE DESTRUCTOR";
+ }
+}
+#endif
StarBlock::StarBlock( int nstars ) :
faintMag(-5),
@@ -32,7 +49,11 @@ StarBlock::StarBlock( int nstars ) :
next(0),
drawID(0),
nStars(0),
+#ifdef KSTARS_LITE
+ stars(nstars,StarNode())
+#else
stars(nstars, StarObject())
+#endif
{ }
@@ -51,7 +72,37 @@ StarBlock::~StarBlock()
if( parent )
parent -> releaseBlock( this );
}
+#ifdef KSTARS_LITE
+StarNode* StarBlock::addStar(const starData& data)
+{
+ if(isFull())
+ return 0;
+ StarNode& node = stars[nStars++];
+ StarObject& star = node.star;
+
+ star.init(&data);
+ if( star.mag() > faintMag )
+ faintMag = star.mag();
+ if( star.mag() < brightMag )
+ brightMag = star.mag();
+ return &node;
+}
+
+StarNode* StarBlock::addStar(const deepStarData& data)
+{
+ if(isFull())
+ return 0;
+ StarNode& node = stars[nStars++];
+ StarObject& star = node.star;
+ star.init(&data);
+ if( star.mag() > faintMag )
+ faintMag = star.mag();
+ if( star.mag() < brightMag )
+ brightMag = star.mag();
+ return &node;
+}
+#else
StarObject* StarBlock::addStar(const starData& data)
{
if(isFull())
@@ -79,3 +130,4 @@ StarObject* StarBlock::addStar(const deepStarData& data)
brightMag = star.mag();
return &star;
}
+#endif
diff --git a/kstars/skycomponents/starblock.h b/kstars/skycomponents/starblock.h
index 67a7bb4..c2e72de 100644
--- a/kstars/skycomponents/starblock.h
+++ b/kstars/skycomponents/starblock.h
@@ -25,9 +25,22 @@
class StarObject;
class StarBlockList;
+class PointSourceNode;
struct starData;
struct deepStarData;
+#ifdef KSTARS_LITE
+#include "starobject.h"
+
+struct StarNode {
+ StarNode();
+ ~StarNode();
+
+ StarObject star;
+ PointSourceNode *starNode;
+};
+#endif
+
/**
*@class StarBlock
*Holds a block of stars and various peripheral variables to mark its place in data structures
@@ -59,8 +72,13 @@ public:
*@param data data to initialize star with.
*@return pointer to star initialized with data. NULL if block is full.
*/
+#ifdef KSTARS_LITE
+ StarNode* addStar(const starData& data);
+ StarNode* addStar(const deepStarData& data);
+#else
StarObject* addStar(const starData& data);
StarObject* addStar(const deepStarData& data);
+#endif
/**
*@short Returns true if the StarBlock is full
@@ -86,8 +104,11 @@ public:
*@param Index of StarBlock to return
*@return A pointer to the i-th StarObject
*/
+#ifdef KSTARS_LITE
+ inline StarNode *star( int i ) { return &stars[i]; }
+#else
inline StarObject *star( int i ) { return &stars[i]; }
-
+#endif
// These methods are there because we might want to make faintMag and brightMag private at some point
/**
*@short Return the magnitude of the brightest star in this StarBlock
@@ -129,7 +150,11 @@ public:
/** Number of initialized stars in StarBlock. */
int nStars;
/** Array of stars. */
+#ifdef KSTARS_LITE
+ QVector<StarNode> stars;
+#else
QVector<StarObject> stars;
+#endif
};
#endif
diff --git a/kstars/skycomponents/starblocklist.cpp b/kstars/skycomponents/starblocklist.cpp
index 7560bf1..d57a573 100644
--- a/kstars/skycomponents/starblocklist.cpp
+++ b/kstars/skycomponents/starblocklist.cpp
@@ -22,6 +22,11 @@
#include "skyobjects/deepstardata.h"
#include "starcomponent.h"
+#ifdef KSTARS_LITE
+#include "skymaplite.h"
+#include "kstarslite/skyitems/skynodes/pointsourcenode.h"
+#endif
+
StarBlockList::StarBlockList( Trixel tr, DeepStarComponent *parent ) {
trixel = tr;
nStars = 0;
@@ -44,6 +49,13 @@ int StarBlockList::releaseBlock( StarBlock *block ) {
qDebug() << "ERROR: Trying to release a block which is not the last block! Trixel = " << trixel << endl;
else if( blocks.size() > 0 ) {
+ for(int i = 0; i < block->getStarCount(); ++i) {
+ PointSourceNode * node = block->star(i)->starNode;
+ if(node) {
+ SkyMapLite::Instance()->deleteSkyNode(node);
+ block->star(i)->starNode = 0;
+ }
+ }
blocks.removeLast();
nBlocks--;
diff --git a/kstars/skycomponents/starcomponent.cpp b/kstars/skycomponents/starcomponent.cpp
index 6478e72..e337453 100644
--- a/kstars/skycomponents/starcomponent.cpp
+++ b/kstars/skycomponents/starcomponent.cpp
@@ -76,6 +76,7 @@ StarComponent::StarComponent(SkyComposite *parent )
loadStaticData();
// Load any deep star catalogs that are available
loadDeepStarCatalogs();
+ //In KStars Lite star images are initialized in SkyMapLite
#ifndef KSTARS_LITE
SkyQPainter::initStarImages();
#endif
diff --git a/kstars/skymaplite.cpp b/kstars/skymaplite.cpp
index a2e123b..474970f 100644
--- a/kstars/skymaplite.cpp
+++ b/kstars/skymaplite.cpp
@@ -31,15 +31,17 @@
#include "skymesh.h"
#include "kstarslite/skyitems/rootnode.h"
+#include "kstarslite/skyitems/skynodes/skynode.h"
#include "ksplanetbase.h"
#include "ksutils.h"
#include <QSGSimpleRectNode>
-#include <QSGNode>
+//#include <QSGNode>
#include <QBitmap>
#include <QSGTexture>
#include <QQuickWindow>
+#include <QLinkedList>
namespace {
@@ -118,6 +120,9 @@ QSGNode* SkyMapLite::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upda
Q_UNUSED(updatePaintNodeData);
RootNode *n = static_cast<RootNode*>(oldNode);
+ qDeleteAll(m_deleteNodes);
+ m_deleteNodes.clear();
+
if(m_loadingFinished) {
if(!n) {
n = new RootNode();
@@ -125,12 +130,13 @@ QSGNode* SkyMapLite::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upda
n->update();
}
- ///DELETE
- //Reset m_fontSizeChanged
- setFontSizeChanged(false);
return n;
}
+void SkyMapLite::deleteSkyNode(SkyNode *skyNode) {
+ m_deleteNodes.append(skyNode);
+}
+
QSGTexture* SkyMapLite::getCachedTexture(int size, char spType) {
return textureCache[harvardToIndex(spType)][size];
}
@@ -523,7 +529,7 @@ QSGTexture *SkyMapLite::textToTexture(QString text, QColor color, bool zoomFont)
int height = fm.height();
QImage label(width, height, QImage::Format_ARGB32_Premultiplied);
- label.fill(0);
+ label.fill(Qt::transparent);
m_painter.begin(&label);
@@ -535,7 +541,7 @@ QSGTexture *SkyMapLite::textToTexture(QString text, QColor color, bool zoomFont)
m_painter.end();
QSGTexture *texture = window()->createTextureFromImage(label,
- QQuickWindow::TextureCanUseAtlas & QQuickWindow::TextureHasAlphaChannel);
+ QQuickWindow::TextureCanUseAtlas);
/*texture->setFiltering(QSGTexture::Linear);
texture->setHorizontalWrapMode(QSGTexture::ClampToEdge);
@@ -629,15 +635,13 @@ void SkyMapLite::initStarImages()
//[nSPclasses][nStarSizes];
// Cache array slice
- QVector<QPixmap *> pmap = imageCache[ harvardToIndex(color) ];
- pmap.append(new QPixmap());
+ QVector<QPixmap *> *pmap = &imageCache[ harvardToIndex(color) ];
+ pmap->append(new QPixmap(BigImage));
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(BigImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation )));
}
- imageCache[ harvardToIndex(color) ] = pmap;
+
}
+ //}
starColorMode = Options::starColorMode();
}
diff --git a/kstars/skymaplite.h b/kstars/skymaplite.h
index fd647a3..737f86e 100644
--- a/kstars/skymaplite.h
+++ b/kstars/skymaplite.h
@@ -26,6 +26,7 @@
#include <config-kstars.h>
#include <QQuickItem>
#include <QPolygonF>
+#include <QLinkedList>
#include "kstarsdata.h"
class dms;
@@ -39,6 +40,7 @@ class CometsItem;
class PlanetMoonsComponent;
class HorizonItem;
class LinesItem;
+class SkyNode;
class QSGTexture;
@@ -85,6 +87,12 @@ public:
/** Destructor (empty) */
~SkyMapLite();
+ /**
+ * @short skyNode will be deleted on the next call to updatePaintNode (currently used only in
+ * StarNode(struct in StarBlock))
+ */
+ void deleteSkyNode(SkyNode *skyNode);
+
/** @short Retrieve the Focus point; the position on the sky at the
*center of the skymap.
*@return a pointer to the central focus point of the sky map
@@ -585,6 +593,9 @@ private:
static SkyMapLite *pinstance;
QQuickItem *m_SkyMapLiteWrapper;
+ //Holds SkyNodes that need to be deleted
+ QLinkedList<SkyNode *> m_deleteNodes;
+
// Used to notify zoom-dependent labels about font size change
bool m_fontSizeChanged;
// Used for drawing labels
@@ -606,7 +617,6 @@ private:
QVector<QVector<QPixmap*>> imageCache;
//Textures created from cached star images
QVector<QVector<QSGTexture*>> textureCache;
-
};
#endif