[Kstars-devel] KDE/kdeedu/kstars/kstars/skycomponents
Akarsh Simha
akarshsimha at gmail.com
Wed Feb 4 16:22:20 CET 2009
SVN commit 921118 by asimha:
Code quality improvements and a (rather critical) bugfix.
+ Removing old commented code that is no longer required
+ DeepStarComponent now uses functions used to find out star sizes and
the limiting magnitude from StarComponent. This not only reduces
code duplication but removes a critical bug where the star sizes
were not in proportion with their magnitude, but would vary from
catalog to catalog.
CCMAIL: kstars-devel at kde.org
M +3 -45 deepstarcomponent.cpp
M +63 -57 starcomponent.cpp
M +11 -1 starcomponent.h
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepstarcomponent.cpp #921117:921118
@@ -174,6 +174,7 @@
SkyMap *map = SkyMap::Instance();
KStarsData* data = KStarsData::Instance();
UpdateID updateID = data->updateID();
+ StarComponent *sc = StarComponent::Instance();
float radius = map->fov();
if ( radius > 90.0 ) radius = 90.0;
@@ -193,32 +194,8 @@
double lgz = log10(Options::zoomFactor());
// TODO: Enable hiding of faint stars
- // Old formula:
- // float maglim = ( 2.000 + 2.444 * Options::memUsage() / 10.0 ) * ( lgz - lgmin ) + Options::magLimitDrawStarZoomOut();
+ float maglim = sc->zoomMagnitudeLimit();
- /*
- Explanation for the following formula:
- --------------------------------------
- Estimates from a sample of 125000 stars shows that, magnitude
- limit vs. number of stars follows the formula:
- nStars = 10^(.45 * maglim + .95)
- (A better formula is available here: http://www.astro.uu.nl/~strous/AA/en/antwoorden/magnituden.html
- which we do not implement for simplicity)
- We want to keep the star density on screen a constant. This is directly proportional to the number of stars
- and directly proportional to the area on screen. The area is in turn inversely proportional to the square
- of the zoom factor ( zoomFactor / MINZOOM ). This means that (taking logarithms):
- 0.45 * maglim + 0.95 - 2 * log( ZoomFactor ) - log( Star Density ) - log( Some proportionality constant )
- hence the formula. We've gathered together all the constants and set it to 3.5, so as to set the minimum
- possible value of maglim to 3.5
- */
-
- // float maglim = 4.444 * ( lgz - lgmin ) + 2.222 * log10( Options::starDensity() ) + 3.5;
-
- // Reducing the slope w.r.t zoom factor to avoid the extremely fast increase in star density with zoom
- // that 4.444 gives us (although that is what the derivation gives us)
-
- float maglim = 3.7 * ( lgz - lgmin ) + 2.222 * log10( Options::starDensity() ) + 3.5;
-
if( maglim < triggerMag )
return;
@@ -248,22 +225,7 @@
visibleStarCount = 0;
t.start();
- // Old formula:
- // float sizeMagLim = ( 2.000 + 2.444 * Options::memUsage() / 10.0 ) * ( lgz - lgmin ) + 5.8;
- // Using the maglim to compute the sizes of stars reduces
- // discernability between brighter and fainter stars at high zoom
- // levels. To fix that, we use an "arbitrary" constant in place of
- // the variable star density.
- // Not using this formula now.
- // float sizeMagLim = 4.444 * ( lgz - lgmin ) + 5.0;
-
- float sizeMagLim = maglim;
-
- // if( sizeMagLim > m_FaintMagnitude * ( 1 - 1.5/16 ) )
- // sizeMagLim = m_FaintMagnitude * ( 1 - 1.5/16 );
- float sizeFactor = 10.0 + (lgz - lgmin);
-
// Mark used blocks in the LRU Cache. Not required for static stars
if( !staticStars ) {
while( region.hasNext() ) {
@@ -331,11 +293,7 @@
if ( ! map->onScreen( o ) ) continue;
- float size = ( sizeFactor*( sizeMagLim - mag ) / sizeMagLim ) + 1.;
- if ( size <= 1.0 ) size = 1.0;
- if( size > maxSize ) size = maxSize;
-
- curStar->draw( psky, o.x(), o.y(), size, (starColorMode()==0),
+ curStar->draw( psky, o.x(), o.y(), sc->starRenderingSize( mag ), (starColorMode()==0),
starColorIntensity(), true );
visibleStarCount++;
}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #921117:921118
@@ -192,26 +192,48 @@
printf("Done.\n");
}
+float StarComponent::faintMagnitude() const {
+ float faintmag = m_FaintMagnitude;
+ for( int i =0; i < m_DeepStarComponents.size(); ++i ) {
+ if( faintmag < m_DeepStarComponents.at( i )->faintMagnitude() )
+ faintmag = m_DeepStarComponents.at( i )->faintMagnitude();
+ }
+ return faintmag;
+}
+float StarComponent::starRenderingSize( float mag ) const {
+ //adjust maglimit for ZoomLevel
+ const double maxSize = 10.0;
-void StarComponent::draw( QPainter& psky )
-{
- if ( ! selected() ) return;
+ double lgmin = log10(MINZOOM);
+ double lgmax = log10(MAXZOOM);
+ double lgz = log10(Options::zoomFactor());
- SkyMap *map = SkyMap::Instance();
- KStarsData* data = KStarsData::Instance();
- UpdateID updateID = data->updateID();
+ // Old formula:
+ // float sizeMagLim = ( 2.000 + 2.444 * Options::memUsage() / 10.0 ) * ( lgz - lgmin ) + 5.8;
- bool checkSlewing = ( map->isSlewing() && Options::hideOnSlew() );
- m_hideLabels = ( map->isSlewing() && Options::hideLabels() ) ||
- ! ( Options::showStarMagnitudes() || Options::showStarNames() );
+ // Using the maglim to compute the sizes of stars reduces
+ // discernability between brighter and fainter stars at high zoom
+ // levels. To fix that, we use an "arbitrary" constant in place of
+ // the variable star density.
+ // Not using this formula now.
+ // float sizeMagLim = 4.444 * ( lgz - lgmin ) + 5.0;
- //shortcuts to inform whether to draw different objects
- bool hideFaintStars( checkSlewing && Options::hideStars() );
- double hideStarsMag = Options::magLimitHideStar();
+ float sizeMagLim = zoomMagnitudeLimit();
+ if( sizeMagLim > faintMagnitude() * ( 1 - 1.5/16 ) )
+ sizeMagLim = faintMagnitude() * ( 1 - 1.5/16 );
- reindex( data->updateNum() );
+ float sizeFactor = maxSize + (lgz - lgmin);
+ float size = ( sizeFactor*( sizeMagLim - mag ) / sizeMagLim ) + 1.;
+ if( size <= 1.0 ) size = 1.0;
+ if( size > maxSize ) size = maxSize;
+
+ return size;
+}
+
+float StarComponent::zoomMagnitudeLimit() const {
+
//adjust maglimit for ZoomLevel
double lgmin = log10(MINZOOM);
double lgmax = log10(MAXZOOM);
@@ -243,10 +265,34 @@
float maglim = 3.7 * ( lgz - lgmin ) + 2.222 * log10( Options::starDensity() ) + 3.5;
- m_zoomMagLimit = maglim;
+ return maglim;
- double maxSize = 10.0;
+}
+void StarComponent::draw( QPainter& psky )
+{
+ if ( ! selected() ) return;
+
+ SkyMap *map = SkyMap::Instance();
+ KStarsData* data = KStarsData::Instance();
+ UpdateID updateID = data->updateID();
+
+ bool checkSlewing = ( map->isSlewing() && Options::hideOnSlew() );
+ m_hideLabels = ( map->isSlewing() && Options::hideLabels() ) ||
+ ! ( Options::showStarMagnitudes() || Options::showStarNames() );
+
+ //shortcuts to inform whether to draw different objects
+ bool hideFaintStars( checkSlewing && Options::hideStars() );
+ double hideStarsMag = Options::magLimitHideStar();
+ reindex( data->updateNum() );
+
+ double lgmin = log10(MINZOOM);
+ double lgmax = log10(MAXZOOM);
+ double lgz = log10(Options::zoomFactor());
+
+ double maglim;
+ m_zoomMagLimit = maglim = zoomMagnitudeLimit();
+
double labelMagLim = Options::starLabelDensity() / 5.0;
labelMagLim += ( 12.0 - labelMagLim ) * ( lgz - lgmin) / (lgmax - lgmin );
if ( labelMagLim > 8.0 ) labelMagLim = 8.0;
@@ -276,31 +322,8 @@
int nTrixels = 0;
- /*
- t_drawNamed = 0;
- t_dynamicLoad = 0;
- t_updateCache = 0;
- t_drawUnnamed = 0;
- */
-
visibleStarCount = 0;
- // Old formula:
- // float sizeMagLim = ( 2.000 + 2.444 * Options::memUsage() / 10.0 ) * ( lgz - lgmin ) + 5.8;
-
- // Using the maglim to compute the sizes of stars reduces
- // discernability between brighter and fainter stars at high zoom
- // levels. To fix that, we use an "arbitrary" constant in place of
- // the variable star density.
- // Not using this formula now.
- // float sizeMagLim = 4.444 * ( lgz - lgmin ) + 5.0;
-
- float sizeMagLim = maglim;
-
- if( sizeMagLim > m_FaintMagnitude * ( 1 - 1.5/16 ) )
- sizeMagLim = m_FaintMagnitude * ( 1 - 1.5/16 );
- float sizeFactor = 10.0 + (lgz - lgmin);
-
while ( region.hasNext() ) {
++nTrixels;
Trixel currentRegion = region.next();
@@ -317,23 +340,15 @@
// break loop if maglim is reached
if ( mag > maglim || ( hideFaintStars && curStar->mag() > hideStarsMag ) ) {
- // kDebug() << "Breaking off @ mag = " << mag;
break;
}
- // kDebug() << "Passed mag limit. mag = " << mag;
-
if ( ! map->checkVisibility( curStar ) ) continue;
- // kDebug() << "Passed visibility";
QPointF o = map->toScreen( curStar );
if ( ! map->onScreen( o ) ) continue;
- float size = ( sizeFactor*( sizeMagLim - mag ) / sizeMagLim ) + 1.;
- if ( size <= 1.0 ) size = 1.0;
- if( size > maxSize ) size = maxSize;
-
- curStar->draw( psky, o.x(), o.y(), size, (starColorMode()==0),
+ curStar->draw( psky, o.x(), o.y(), starRenderingSize( mag ), (starColorMode()==0),
starColorIntensity(), true );
visibleStarCount++;
@@ -341,26 +356,17 @@
addLabel( o, curStar );
}
- // t_drawNamed += t.restart();
}
// Draw focusStar if not null
if( focusStar ) {
if ( focusStar->updateID != updateID )
focusStar->JITupdate( data );
-
float mag = focusStar->mag();
-
if ( map->checkVisibility( focusStar ) ) {
QPointF o = map->toScreen( focusStar );
-
if ( map->onScreen( o ) ) {
-
- float size = ( sizeFactor*( sizeMagLim - mag ) / sizeMagLim ) + 1.;
- if ( size <= 1.0 ) size = 1.0;
- if( size > maxSize ) size = maxSize;
-
- focusStar->draw( psky, o.x(), o.y(), size, (starColorMode()==0),
+ focusStar->draw( psky, o.x(), o.y(), starRenderingSize( mag ), (starColorMode()==0),
starColorIntensity(), true );
visibleStarCount++;
}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.h #921117:921118
@@ -104,9 +104,19 @@
*/
int starColorIntensity( void ) const;
- float faintMagnitude() const { return m_FaintMagnitude; }
+ /**
+ *@return the magnitude of the faintest star
+ */
+ float faintMagnitude() const;
+ /**
+ *@short Return the size of the star as rendered by KStars
+ *@return the Size of the star's representation on the skymap in pixels
+ */
+ float starRenderingSize( float mag ) const;
+ float zoomMagnitudeLimit() const;
+
/**
*@short Read data for stars which will remain static in the memory
*
More information about the Kstars-devel
mailing list