[Kstars-devel] branches/kstars/summer/kdeedu/kstars/kstars/skycomponents
Akarsh Simha
akarshsimha at gmail.com
Sun Jun 8 02:34:07 CEST 2008
SVN commit 818176 by asimha:
Changes to the StarComponent class:
+ Remove processStar() completely
+ Add a starsLoaded flag to indicate whether the named and bright
unnamed stars are loaded.
+ Change m_ReadOffset into a fixed size array (to store read offsets
for 512 trixels) instead of a QVector
+ Implementing readStarBlock() to read a block of Stars from the data
file. (Not tested yet)
+ Making plainStarTemplate a private member of the class
+ Adding an array of 512 StarBlockList objects
CCMAIL: kstars-devel at kde.org
M +75 -34 starcomponent.cpp
M +19 -35 starcomponent.h
--- branches/kstars/summer/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #818175:818176
@@ -39,14 +39,14 @@
#include "binfilehelper.h"
StarComponent::StarComponent(SkyComponent *parent )
- : ListComponent(parent), m_reindexNum(J2000), m_FaintMagnitude(-5.0)
+ : ListComponent(parent), m_reindexNum(J2000), m_FaintMagnitude(-5.0), starsLoaded(false)
{
m_skyMesh = SkyMesh::Instance();
m_starIndex = new StarIndex();
for (int i = 0; i < m_skyMesh->size(); i++) {
m_starIndex->append( new StarList() );
- m_readOffset.append( 0 );
+ m_readOffset[i] = 0;
}
m_highPMStars.append( new HighPMStarList( 840.0 ) );
m_highPMStars.append( new HighPMStarList( 304.0 ) );
@@ -338,6 +338,7 @@
return m_lineNumber[ mag ];
}
+// TODO: Give this method a better name
void StarComponent::readData( float newMagnitude )
{
// TODO: We may want to remove the newMagnitude argument. Currently, it is deprecated
@@ -351,15 +352,17 @@
QString name, gname, visibleName;
StarObject *star;
+ kDebug() << "Entered readData()";
// We now load all stars the first time this method is called and load nothing during subsequent calls:
- if ( newMagnitude <= m_FaintMagnitude || newMagnitude > 8.0 ) return; // TODO: Create the solution to handle > 8.0 mag stars
- m_FaintMagnitude = 8.00; // TODO: Find out if there could be a solution to load shallow stars dynamically
+ if(starsLoaded)
+ return;
// prepare to index stars to this date
m_skyMesh->setKSNumbers( &m_reindexNum );
-
+
+
/* Open the data files */
if((dataFile = dataReader.openFile("shallowstars.dat")) == NULL) {
kDebug() << "Could not open data file shallowstars.dat" << endl;
@@ -388,30 +391,6 @@
Trixel expectedTrixelId = -1;
QTime t;
- /* Create a template for plain ("unnamed") stars, from which we can do a memcpy()
- *
- * CAUTION: We avoid trying to construct StarObjects using the constructors [The C++ way]
- * in order to gain speed. Instead, one template StarObject is constructed and
- * all other unnamed stars are created by doing a raw copy from this using memcpy()
- * and then calling StarObject::init() to replace the default data with the correct
- * data.
- * This means that this section of the code plays around with pointers to a great
- * extend and has a chance of breaking down / causing segfaults.
- */
- stardata.mag = 0;
- stardata.spec_type[0] = 'A';
- stardata.spec_type[1] = '0';
- visibleName = "";
- stardata.dRA = 0;
- stardata.dDec = 0;
- stardata.parallax = 0;
- stardata.flags = 0;
- StarObject *plainStarTemplate = new StarObject(0, 0, stardata.mag/100.0, "", visibleName,
- QByteArray(stardata.spec_type, 2),
- stardata.dRA/10.0, stardata.dDec/10.0, stardata.parallax/10.0,
- stardata.flags & 0x02, stardata.flags & 0x04 );
-
-
/* TODO : Remove timing code when we are done with all possible optimizations */
t.start();
@@ -423,8 +402,8 @@
// The following code is not required, because we are anyway reading the file sequentially, and hence is commented out.
/*
- if(fseek(dataFile, dataReader.getOffset(i), SEEK_SET))
- kDebug() << "ERROR: Could not seek to offset " << dataReader.getOffset(i) << " to find trixel #" << i << endl;
+ if(fseek(dataFile, dataReader.getOffset(i), SEEK_SET))
+ kDebug() << "ERROR: Could not seek to offset " << dataReader.getOffset(i) << " to find trixel #" << i << endl;
*/
/* Recurse over stars in each trixel */
@@ -435,7 +414,6 @@
kDebug() << "ERROR: Could not read starData structure for star #" << j << " under trixel #" << i << endl;
}
-
// TODO: Add byteswapping code
gname = "";
@@ -468,10 +446,19 @@
stardata.parallax/10.0, stardata.flags & 0x02, stardata.flags & 0x04 );
}
else {
- // DANGEROUS CODE. Lots of pointer work!
+ /*
+ * CAUTION: We avoid trying to construct StarObjects using the constructors [The C++ way]
+ * in order to gain speed. Instead, one template StarObject is constructed and
+ * all other unnamed stars are created by doing a raw copy from this using memcpy()
+ * and then calling StarObject::init() to replace the default data with the correct
+ * data.
+ * This means that this section of the code plays around with pointers to a great
+ * extend and has a chance of breaking down / causing segfaults.
+ */
+
/* Make a copy of the star template and set up the data in it */
star = (StarObject *)malloc(sizeof(StarObject));
- star = (StarObject *)memcpy(star, plainStarTemplate, sizeof(StarObject));
+ star = (StarObject *)memcpy(star, &plainStarTemplate, sizeof(StarObject));
star -> init(stardata.RA/1000000.0, stardata.Dec/100000.0, stardata.mag/100.0,
QByteArray(stardata.spec_type, 2), stardata.dRA/10.0, stardata.dDec/10.0,
stardata.parallax/10.0, stardata.flags & 0x02, stardata.flags & 0x04);
@@ -505,8 +492,62 @@
dataReader.closeFile();
nameReader.closeFile();
kDebug() << "Loaded " << nstars << " stars in " << t.elapsed() << " ms" << endl;
+
+ // TODO: Fix things:
+ // Suppose the user wants stars down to 10th mag when zoomed out, this thing lies
+ // We need to deprecate that option as well
+ starsLoaded = true;
+ if(m_FaintMagnitude < 8.0)
+ m_FaintMagnitude = 8.0;
+
}
+
+bool StarComponent::readStarBlock(StarBlock *SB, FILE *dataFile, int nstars) {
+
+ int i;
+ starData stardata;
+ QString name, gname, visibleName;
+
+
+ if( SB == NULL || dataFile == NULL )
+ return false;
+
+ // Allocate the required amount of StarObjects
+ if( SB -> star )
+ free( SB -> star );
+
+ SB -> star = ( StarObject * )malloc( sizeof( StarObject ) * nstars );
+ if( !SB -> star )
+ return false;
+
+ // Read in the data from dataFile and fill into the StarBlock
+ for( i = 0; i < nstars; ++i ) {
+
+ if( !fread( &stardata, sizeof( starData ), 1, dataFile ) ) {
+ kDebug() << "ERROR: Premature termination of dataFile in readStarBlock. Expected "
+ << nstars << " records, but read " << i << endl;
+ SB -> star = ( StarObject * )realloc( SB -> star, sizeof( StarObject ) * i );
+ return false;
+ }
+
+
+ // TODO: Add byteswapping code
+
+ if(stardata.flags & 0x01) {
+ kDebug() << "WARNING: Named Star encountered while reading StarBlock. Name will not be loaded!";
+ continue;
+ }
+
+ memcpy( &(SB -> star[i]), &plainStarTemplate, sizeof( StarObject ) );
+ SB -> star[i].init( stardata.RA/1000000.0, stardata.Dec/100000.0, stardata.mag/100.0,
+ QByteArray( stardata.spec_type, 2 ), stardata.dRA/10.0, stardata.dDec/10.0,
+ stardata.parallax/10.0, stardata.flags & 0x02, stardata.flags & 0x04 );
+ }
+
+ return true;
+}
+
SkyObject* StarComponent::findStarByGenetiveName( const QString name ) {
return m_genName.value( name );
}
--- branches/kstars/summer/kdeedu/kstars/kstars/skycomponents/starcomponent.h #818175:818176
@@ -29,10 +29,11 @@
#include "listcomponent.h"
#include "kstarsdatetime.h"
#include "ksnumbers.h"
-
+#include "starblock.h"
#include "skylabel.h"
#include "typedef.h"
#include "highpmstarlist.h"
+#include "starobject.h"
class SkyComponent;
class KStarsData;
@@ -86,6 +87,17 @@
void readData( float newMagnitude );
+ /**@short Read one StarBlock of nstars stars from dataFile
+ *
+ *TODO: Assign a default value for nstars
+ *
+ *@param SB Pointer to the StarBlock to read data into
+ *@param dataFile Pointer to the binary data file to read from
+ *@param nstars Number of stars to read data for
+ */
+ bool readStarBlock(StarBlock *SB, FILE *dataFile, int nstars);
+
+
SkyObject* objectNearest(SkyPoint *p, double &maxrad );
SkyObject* findStarByGenetiveName( const QString name );
@@ -137,9 +149,11 @@
int m_lastLineNum;
bool m_validLineNums;
bool m_hideLabels;
+ quint16 m_readOffset[512];
KStarsData* m_Data;
- float m_FaintMagnitude;
+ float m_FaintMagnitude; // WARNING: DEPRECATED
+ bool starsLoaded;
float m_zoomMagLimit;
KStarsSplash* m_reloadSplash;
@@ -147,8 +161,8 @@
QVector<HighPMStarList*> m_highPMStars;
QHash<QString, SkyObject*> m_genName;
- QVector<qint16> m_readOffset;
+
/**
*@short adds a label to the lists of labels to be drawn prioritized
*by magnitude.
@@ -157,37 +171,6 @@
void reindexAll( KSNumbers *num );
- /**
- *Parse a line from a stars data file, construct a StarObject from the data,
- *and add it to the StarComponent.
- *
- *Each line is parsed according to the column
- *position in the line:
- *@li 0-1 RA hours [int]
- *@li 2-3 RA minutes [int]
- *@li 4-8 RA seconds [float]
- *@li 10 Dec sign [char; '+' or '-']
- *@li 11-12 Dec degrees [int]
- *@li 13-14 Dec minutes [int]
- *@li 15-18 Dec seconds [float]
- *@li 20-28 dRA/dt (milli-arcsec/yr) [float]
- *@li 29-37 dDec/dt (milli-arcsec/yr) [float]
- *@li 38-44 Parallax (milli-arcsec) [float]
- *@li 46-50 Magnitude [float]
- *@li 51-55 B-V color index [float]
- *@li 56-57 Spectral type [string]
- *@li 59 Multiplicity flag (1=true, 0=false) [int]
- *@li 61-64 Variability range of brightness (magnitudes; bank if not variable) [float]
- *@li 66-71 Variability period (days; blank if not variable) [float]
- *@li 72-END Name(s) [string]. This field may be blank. The string is the common
- * name for the star (e.g., "Betelgeuse"). If there is a colon, then
- * everything after the colon is the genetive name for the star (e.g.,
- * "alpha Orionis").
- *
- *@param line pointer to the line of data to be processed as a StarObject
- */
- StarObject* processStar( const QString &line );
-
typedef struct starData {
int32_t RA;
int32_t Dec;
@@ -207,9 +190,10 @@
char longName[32];
} starName;
+ StarBlockList m_starBlockList[512];
starData stardata;
starName starname;
-
+ StarObject plainStarTemplate;
};
More information about the Kstars-devel
mailing list