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

Added support for unnamed static stars. Started working on dynamic

stars.
parent 7fd5cf74
......@@ -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
......
/** *************************************************************************
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 );
}
//}
/** *************************************************************************
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
......@@ -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; }
}
......
......@@ -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
......
......@@ -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();
}
......@@ -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()) {