[Kstars-devel] KDE/kdeedu/kstars/kstars/skycomponents
James Bowlin
bowlin at mindspring.com
Wed Aug 22 22:28:37 CEST 2007
SVN commit 703551 by jbowlin:
Reduced the maximum star label density. If you think it is too small,
hit the "b" key and see what the hit ratio is. If it is 50% or less
then the label density is not too small. If the hit ratio is
significantly less than 50% then the label density may even be too high
since most labels are not getting drawn because they would overlap.
Prioritized the star labels based on magnitude. This was not exact.
I bin the labels based on the first two significant digits of the
star magnitude to avoid the expense of a sort. I could not see any
speed difference using this scheme. The downside is that the labels
for stars that have magnitudes within 0.1 will be drawn with the same
priority.
This brought the drawing of star labels outside of SkyLabeler::draw()
which then enabled me to bring the drawing of the constellation names
out of that routine as well which cleaned things up a little. Label
priority is now set by the order things are drawn in
SkyMapComposite::draw() as well as in SkyLabler::draw().
Cleaned up the starcomponent.h and SkyMapComposite::draw() a little.
CCMAIL:kstars-devel at kde.org
M +6 -6 constellationnamescomponent.cpp
M +4 -0 skylabel.h
M +1 -10 skylabeler.cpp
M +1 -3 skylabeler.h
M +3 -52 skymapcomposite.cpp
M +40 -6 starcomponent.cpp
M +35 -15 starcomponent.h
M +1 -1 typedef.h
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/constellationnamescomponent.cpp #703550:703551
@@ -100,14 +100,14 @@
SkyMap *map = ks->map();
QString name;
- //m_skyLabeler->useStdFont( psky );
+ SkyLabeler* skyLabeler = SkyLabeler::Instance();
- //Draw Constellation Names
- //psky.setPen( QColor( ks->data()->colorScheme()->colorNamed( "CNameColor" ) ) );
+ skyLabeler->useStdFont( psky );
+ psky.setPen( QColor( ks->data()->colorScheme()->colorNamed( "CNameColor" ) ) );
+
for ( int i = 0; i < objectList().size(); i++) {
SkyObject* p = objectList().at( i );
- //foreach ( SkyObject *p, objectList() ) {
if ( ! map->checkVisibility( p ) ) continue;
QPointF o = map->toScreen( p, scale );
@@ -126,8 +126,8 @@
float dx = 5.*( name.length() );
o.setX( o.x() - dx );
- SkyLabeler::AddLabel( o, name, CONSTEL_NAME_LABEL);
+ skyLabeler->drawLabel( psky, o, name );
}
- //m_skyLabeler->resetFont( psky );
+ skyLabeler->resetFont( psky );
}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skylabel.h #703550:703551
@@ -19,7 +19,11 @@
#define SKYLABEL_H
#include <QPointF>
+#include <QList>
+class SkyLabel;
+typedef QList<SkyLabel> LabelList;
+
class SkyLabel {
public:
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skylabeler.cpp #703550:703551
@@ -434,8 +434,8 @@
void SkyLabeler::draw( KStars* kstars, QPainter& psky )
{
+ resetFont( psky );
KStarsData* data = kstars->data();
-
psky.setPen( QColor( data->colorScheme()->colorNamed( "PNameColor" ) ) );
//psky.setPen( QColor( "red" ) );
drawLabels( psky, PLANET_LABEL );
@@ -450,15 +450,6 @@
drawLabels( psky, ASTEROID_LABEL );
drawLabels( psky, COMET_LABEL );
- if ( labelList[ CONSTEL_NAME_LABEL ].size() > 0 ) {
- useStdFont( psky );
- psky.setPen( QColor( data->colorScheme()->colorNamed( "CNameColor" ) ) );
- drawLabels( psky, CONSTEL_NAME_LABEL );
- resetFont( psky );
- }
-
- psky.setPen( QColor( data->colorScheme()->colorNamed( "SNameColor" ) ) );
- drawLabels( psky, STAR_LABEL );
}
void SkyLabeler::drawLabels( QPainter& psky, label_t type )
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skylabeler.h #703550:703551
@@ -36,8 +36,6 @@
typedef QList<LabelRun*> LabelRow;
typedef QVector<LabelRow*> ScreenRows;
-typedef QList<SkyLabel> LabelList;
-
enum label_t {
STAR_LABEL,
ASTEROID_LABEL,
@@ -218,7 +216,7 @@
/* @short a convenience routine that draws the label specified
* in the SkyLabel.
*/
- void drawLabel( QPainter& psky, SkyLabel& skyLabel ) {
+ void drawLabel( QPainter& psky, const SkyLabel& skyLabel ) {
drawLabel( psky, skyLabel.o , skyLabel.text );
}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.cpp #703550:703551
@@ -209,84 +209,35 @@
// info boxes have highest label priority
ks->infoBoxes()->reserveBoxes( psky );
- //TIMING
- //QTime t;
- //t.start();
- //1. Milky Way
-// t.start();
m_MilkyWay->draw( ks, psky, scale );
-// kDebug() << QString("Milky Way : %1 ms").arg( t.elapsed() );
- //2. Coordinate grid
-// t.start();
m_CoordinateGrid->draw( ks, psky, scale );
-// kDebug() << QString("Coord grid : %1 ms").arg( t.elapsed() );
- //3. Constellation boundaries
-// t.start();
m_CBoundLines->draw( ks, psky, scale );
-// kDebug() << QString("Cons Bound : %1 ms").arg( t.elapsed() );
- //4. Constellation lines
-// t.start();
m_CLines->draw( ks, psky, scale );
-// kDebug() << QString("Cons Lines : %1 ms").arg( t.elapsed() );
- //5. Constellation names
-// t.start();
- m_CNames->draw( ks, psky, scale );
-// kDebug() << QString("Cons Names : %1 ms").arg( t.elapsed() );
-
- //6. Equator
-// t.start();
m_Equator->draw( ks, psky, scale );
-// kDebug() << QString("Equator : %1 ms").arg( t.elapsed() );
- //7. Ecliptic
-// t.start();
m_Ecliptic->draw( ks, psky, scale );
-// kDebug() << QString("Ecliptic : %1 ms").arg( t.elapsed() );
- //8. Deep sky
-// t.start();
m_DeepSky->draw( ks, psky, scale );
-// kDebug() << QString("Deep sky : %1 ms").arg( t.elapsed() );
- //9. Custom catalogs
-// t.start();
m_CustomCatalogs->draw( ks, psky, scale );
-// kDebug() << QString("Custom cat : %1 ms").arg( t.elapsed() );
- //10. Stars
-// t.restart();
m_Stars->draw( ks, psky, scale );
-// kDebug() << QString("Stars : %1 ms").arg( t.elapsed() );
- //11. Solar system
-// t.start();
m_SolarSystem->draw( ks, psky, scale );
-// kDebug() << QString("Solar sys : %1 ms").arg( t.elapsed() );
- //12. Satellite tracks
-// t.start();
-//SATELLITE_DISABLE
-// m_Satellites->draw( ks, psky, scale );
-// kDebug() << QString("Satellites : %1 ms").arg( t.elapsed() );
+ //m_Satellites->draw( ks, psky, scale );
- //13. Object name labels
-// t.start();
ks->map()->drawObjectLabels( labelObjects(), psky, scale );
-// kDebug() << QString("Name labels : %1 ms").arg( t.elapsed() );
- //14. Horizon (and ground)
-// t.start();
m_Horizon->draw( ks, psky, scale );
-// kDebug() << QString("Horizon : %1 ms").arg( t.elapsed() );
- // use zoomed-in font if needed and draw all the labels
- m_skyLabeler->resetFont( psky );
m_skyLabeler->draw( ks, psky );
- m_skyLabeler->useStdFont( psky );
+ m_CNames->draw( ks, psky, scale );
+ m_Stars->drawLabels( ks, psky, scale );
m_skyMesh->inDraw( false );
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #703550:703551
@@ -54,6 +54,10 @@
m_zoomMagLimit = 0.0;
m_reloadSplash = m_reindexSplash = 0;
m_validLineNums = false;
+
+ for ( int i = 0; i <= MAX_LINENUMBER_MAG; i++ ) {
+ m_labelList[ i ] = new LabelList;
+ }
}
StarComponent::~StarComponent()
@@ -179,7 +183,7 @@
UpdateID updateID = data->updateID();
bool checkSlewing = ( map->isSlewing() && Options::hideOnSlew() );
- bool hideLabels = ( map->isSlewing() && Options::hideLabels() ) ||
+ m_hideLabels = ( map->isSlewing() && Options::hideLabels() ) ||
! ( Options::showStarMagnitudes() || Options::showStarNames() );
//shortcuts to inform whether to draw different objects
@@ -204,8 +208,8 @@
float sizeFactor = 6.0 + (lgz - lgmin);
- double labelMagLim = Options::starLabelDensity();
- labelMagLim += ( 16.0 - labelMagLim ) * ( lgz - lgmin) / (lgmax - lgmin );
+ double labelMagLim = Options::starLabelDensity() / 5.0;
+ labelMagLim += ( 12.0 - labelMagLim ) * ( lgz - lgmin) / (lgmax - lgmin );
if ( labelMagLim > 8.0 ) labelMagLim = 8.0;
//Set the brush
@@ -254,16 +258,46 @@
curStar->draw( psky, o.x(), o.y(), size, (starColorMode()==0),
starColorIntensity(), true, scale );
- if ( hideLabels || mag > labelMagLim ) continue;
+ if ( m_hideLabels || mag > labelMagLim ) continue;
float offset = scale * (6. + 0.5*( 5.0 - mag ) + 0.01*( zoom/500. ) );
QString sName = curStar->nameLabel( drawName, drawMag );
- SkyLabeler::AddLabel( QPointF( o.x() + offset, o.y() + offset), sName, STAR_LABEL );
+ //SkyLabeler::AddLabel( QPointF( o.x() + offset, o.y() + offset), sName, STAR_LABEL );
+ addLabel( QPointF( o.x() + offset, o.y() + offset), sName, mag );
}
}
}
-
+void StarComponent::addLabel( const QPointF& p, const QString& text, float mag)
+{
+ int idx = int( mag * 10.0 );
+ if ( idx < 0 ) idx = 0;
+ if ( idx > MAX_LINENUMBER_MAG ) idx = MAX_LINENUMBER_MAG;
+ m_labelList[ idx ]->append( SkyLabel( p, text ) );
+}
+
+void StarComponent::drawLabels(KStars *ks, QPainter& psky, double scale)
+{
+ if ( m_hideLabels ) return;
+
+ SkyLabeler* labeler = SkyLabeler::Instance();
+
+ psky.setPen( QColor( KStarsData::Instance()->colorScheme()->colorNamed( "SNameColor" ) ) );
+
+ int max = int( m_zoomMagLimit * 10.0 );
+ if ( max < 0 ) max = 0;
+ if ( max > MAX_LINENUMBER_MAG ) max = MAX_LINENUMBER_MAG;
+
+ for ( int i = 0; i <= max; i++ ) {
+ LabelList* list = m_labelList[ i ];
+ for ( int j = 0; j < list->size(); j++ ) {
+ labeler->drawLabel( psky, list->at( j ) );
+ }
+ list->clear();
+ }
+
+}
+
void StarComponent::readLineNumbers()
{
KSFileReader fileReader;
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.h #703550:703551
@@ -30,6 +30,7 @@
#include "kstarsdatetime.h"
#include "ksnumbers.h"
+#include "skylabel.h"
#include "typedef.h"
#include "highpmstarlist.h"
@@ -44,8 +45,6 @@
#define MAX_LINENUMBER_MAG 90
-//typedef QVector< StarList* > StarIndex;
-
class StarComponent: public ListComponent
{
public:
@@ -56,12 +55,19 @@
void update( KStarsData *data, KSNumbers *num );
+ bool selected();
+
void reindex( KSNumbers *num );
- virtual void draw(KStars *ks, QPainter& psky, double scale);
+ void draw(KStars *ks, QPainter& psky, double scale);
- virtual void init(KStarsData *data);
+ /* @short draw all the labels in the prioritized LabelLists and then
+ * clear the LabelLists.
+ */
+ void drawLabels(KStars *ks, QPainter& psky, double scale);
+ void init(KStarsData *data);
+
KStarsData *data() { return m_Data; }
/**@return the current setting of the color mode for stars (0=real colors,
@@ -109,9 +115,19 @@
*/
void rereadData();
+ /* @short reads in the small starlnum.idx file that contains the line
+ * numbers from the stars.dat file that correspond to rough 90
+ * different magnitudes. This allows us to estimate the number of
+ * lines that need to get read when partially reading stars.dat.
+ */
void readLineNumbers();
+
+ /* @short returns an estimate of the stars.dat line number for a given
+ * star magnitude.
+ */
int lineNumber( float mag );
+
private:
SkyMesh* m_skyMesh;
StarIndex* m_starIndex;
@@ -120,17 +136,30 @@
double m_reindexInterval;
int m_lineNumber[ MAX_LINENUMBER_MAG + 1 ];
+ LabelList* m_labelList[ MAX_LINENUMBER_MAG + 1 ];
qint64 m_lastFilePos;
int m_lastLineNum;
bool m_validLineNums;
+ bool m_hideLabels;
+ KStarsData* m_Data;
+ float m_FaintMagnitude;
+ float m_zoomMagLimit;
+ int m_ColorMode, m_ColorIntensity;
+
+ KStarsSplash* m_reloadSplash;
+ KStarsSplash* m_reindexSplash;
+
QVector<HighPMStarList*> m_highPMStars;
-
QHash<QString, SkyObject*> m_genName;
+ /* @short adds a label to the lists of labels to be drawn prioritized
+ * by magnitude.
+ */
+ void addLabel( const QPointF& p, const QString& text, float mag);
+
void reindexAll( KSNumbers *num );
-
/**
*Parse a line from a stars data file, construct a StarObject from the data,
*and add it to the StarComponent.
@@ -162,15 +191,6 @@
*/
StarObject* processStar( const QString &line );
- bool selected();
-
- KStarsData *m_Data;
- float m_FaintMagnitude;
- float m_zoomMagLimit;
- int m_ColorMode, m_ColorIntensity;
-
- KStarsSplash* m_reloadSplash;
- KStarsSplash* m_reindexSplash;
};
#endif
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/typedef.h #703550:703551
@@ -40,7 +40,7 @@
typedef QVector< SkyPoint*> SkyList;
typedef QHash< Trixel, bool> IndexHash;
typedef QList< StarObject*> StarList;
-typedef QVector< StarList* > StarIndex;
+typedef QVector< StarList*> StarIndex;
typedef QVector< LineList*> LineListList;
typedef QHash< Trixel, LineListList*> LineListHash; // Wanted LineListIndex but
// that is used by a class.
More information about the Kstars-devel
mailing list