[Kstars-devel] branches/kstars/summer/kdeedu/kstars/kstars/skycomponents

Akarsh Simha akarshsimha at gmail.com
Mon Jun 16 01:32:28 CEST 2008


SVN commit 820982 by asimha:

Lots of general fixes:

+ Improving code quality

+ Removing unused / unimplemented functions

+ Completing some TODOs

CCMAIL: kstars-devel at kde.org



 M  +2 -0      starblockfactory.cpp  
 M  +3 -34     starblockfactory.h  
 M  +22 -11    starblocklist.cpp  
 M  +10 -2     starblocklist.h  
 M  +4 -2      starcomponent.cpp  
 M  +3 -43     starcomponent.h  


--- branches/kstars/summer/kdeedu/kstars/kstars/skycomponents/starblockfactory.cpp #820981:820982
@@ -147,6 +147,7 @@
     return true;
 }
 
+/*
 bool StarBlockFactory::groupMove( StarBlock *start, const int nblocks ) {
 
     StarBlock *end;
@@ -191,6 +192,7 @@
     start->prev = NULL;
     first = start;
 }
+*/
 
 int StarBlockFactory::deleteBlocks( int nblocks ) {
     int i;
--- branches/kstars/summer/kdeedu/kstars/kstars/skycomponents/starblockfactory.h #820981:820982
@@ -53,16 +53,7 @@
      */
     ~StarBlockFactory();
 
-    // DEPRECATED. TODO: Make this private, or probably discard it
     /**
-     *@short  Appends N new blocks to the end of the list
-     *
-     *@param  Number of blocks to append
-     *@return Number of blocks successfully appended
-     */
-    //   int addNewBlocks( int nblocks );
-
-    /**
      *@short  Return a StarBlock available for use
      *
      *This method first checks if there are any cached StarBlocks that are not in use.
@@ -92,21 +83,10 @@
      */
     bool markNext( StarBlock *after, StarBlock *block );
 
-    // DEPRECATED
-    /**
-     *@short  Move a group of blocks as they are to the front
-     *
-     *This function moves a group of blocks, maintaining the links within the group as they
-     *are, to the front. This is useful if the whole block was used in an operation, but the
-     *last used block should be the first dropped block, if the cache need to drop a block
-     *
-     *@param  start   Pointer to the start of the group to move
-     *@param  nblocks Number of blocks to include in the group
-     *@return true on success, false if the group was not correctly defined
-     */
-    bool groupMove( StarBlock *start, const int nblocks );
+    quint32 drawID;            // A number identifying the current draw cycle
 
-    // DEPRECATED. TODO: Make this private
+ private:
+
     /**
      *@short  Deletes the N least recently used blocks
      *
@@ -115,17 +95,6 @@
      */
     int deleteBlocks( int nblocks );
 
-    quint32 drawID;            // A number identifying the current draw cycle
-
- private:
-
-    /**
-     *@short  Update drawIDs of nblocks blocks starting at start
-     *
-     *@param  start   Pointer to the start of the group to sync drawIDs of
-     *@param  nblocks Number of blocks in the group
-     */
-
     StarBlock *first, *last;   // Pointers to the beginning and end of the linked list
     int nBlocks;               // Number of blocks we currently have in the cache
     int nCache;                // Number of blocks to start recycling cached blocks at
--- branches/kstars/summer/kdeedu/kstars/kstars/skycomponents/starblocklist.cpp #820981:820982
@@ -22,17 +22,21 @@
 #include "starcomponent.h"
 
 StarBlockList::StarBlockList(Trixel tr) : trixel(tr), nStars(0), nBlocks(0),
-                                          readOffset(0) {
-    // TODO: Implement this if necessary
+                                          readOffset(0), faintMag(-5.0) {
 }
 
 StarBlockList::~StarBlockList() {
+    // NOTE: Rest of the StarBlocks are taken care of by StarBlockFactory
     if( blocks[0] )
         delete blocks[0];
 }
 
-void StarBlockList::releaseBlock( StarBlock *block ) {
-    nBlocks -= blocks.removeAll( block );
+int StarBlockList::releaseBlock( StarBlock *block ) {
+    int nRemoved;
+    nRemoved = blocks.removeAll( block );
+    nBlocks -= nRemoved;
+    faintMag = blocks[nBlocks - 1]->faintMag;
+    return nRemoved;
 }
 
 bool StarBlockList::fillToMag( float maglim ) {
@@ -45,12 +49,12 @@
     if( nBlocks == 0 )
         return false;
 
-    if( blocks[nBlocks - 1]->faintMag >= maglim )
+    if( faintMag >= maglim )
         return true;
 
     if( nBlocks == 1 ) {
         StarBlock *newBlock;
-        nStars += blocks[0]->getStarCount();
+        nStars = blocks[0]->getStarCount();
         newBlock =  SBFactory->getBlock();
         if(!newBlock) {
             kDebug() << "Could not get new block from StarBlockFactory::getBlock() in trixel " 
@@ -72,8 +76,11 @@
     }
     
     fseek( dataFile, readOffset, SEEK_SET );
-    
-    while( maglim >= blocks[nBlocks - 1]->faintMag && nStars < dSReader->getRecordCount( trixelId ) + blocks[0]->getStarCount() ) {
+    /*
+    kDebug() << "Reading trixel " << trixel << ", id on disk = " << trixelId << ", record count = " 
+             << dSReader->getRecordCount( trixelId ) << ", first block = " << blocks[0]->getStarCount();
+    */
+    while( maglim >= faintMag && nStars < dSReader->getRecordCount( trixelId ) + blocks[0]->getStarCount() ) {
         if( blocks[nBlocks - 1]->isFull() ) {
             blocks.append( SBFactory->getBlock() );
             if( !blocks[nBlocks] ) {
@@ -84,21 +91,25 @@
             SBFactory->markNext( blocks[nBlocks - 1], blocks[nBlocks] );
             ++nBlocks;
         }
+
         fread( &stardata, sizeof( starData ), 1, dataFile );
         StarComponent::byteSwap( &stardata );
-        if( maglim < blocks[nBlocks - 1]->faintMag )
-            break;
         readOffset += sizeof( starData );
+
         star.init( &stardata );
         blocks[nBlocks - 1]->addStar( &star );
+        faintMag = blocks[nBlocks - 1]->faintMag;
         nStars++;
     }
-    return true;
+
+
+    return ( ( maglim < faintMag ) ? true : false );
 }
 
 void StarBlockList::setStaticBlock( StarBlock *block ) {
     if ( block && nBlocks == 0 ) {
         blocks.append( block );
+        faintMag = blocks[0]->faintMag;
         nBlocks = 1;
     }
 }
--- branches/kstars/summer/kdeedu/kstars/kstars/skycomponents/starblocklist.h #820981:820982
@@ -67,8 +67,9 @@
     /**
      *@short  Drops the StarBlock with the given pointer from the list
      *@param  Pointer to the StarBlock to remove
+     *@return Number of entries removed from the QList
      */
-    void releaseBlock( StarBlock *block );
+    int releaseBlock( StarBlock *block );
 
     /**
      *@short  Returns the i-th block in this StarBlockList
@@ -76,7 +77,7 @@
      *@param  Index of the required block
      *@return The StarBlock requested for, NULL if index out of bounds
      */
-    inline StarBlock *block( int i ) { return ( ( i < nBlocks ) ? blocks[ i ] : NULL ); }
+    inline StarBlock *block( unsigned int i ) { return ( ( i < nBlocks ) ? blocks[ i ] : NULL ); }
 
     /**
      *@short  Returns the total number of stars in this StarBlockList
@@ -90,10 +91,17 @@
      */
     inline int getBlockCount() { return nBlocks; }
 
+    /**
+     *@short  Returns the magnitude of the faintest star currently stored
+     *@return Magnitude of faintest star stored in this StarBlockList
+     */
+    inline int getFaintMag() { return faintMag; }
+
  private:
     Trixel trixel;
     unsigned long nStars;
     long readOffset;
+    float faintMag;
     QList < StarBlock *> blocks;
     unsigned int nBlocks;
 
--- branches/kstars/summer/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #820981:820982
@@ -273,8 +273,10 @@
             addLabel( o, curStar );
         }
 
-        if( !m_starBlockList[ currentRegion ]->fillToMag( maglim ) ) {
-            kDebug() << "SBL::fillToMag( " << maglim << " ) failed!"<< endl;
+        // TODO: Hardcoded star catalog faint limit
+        if( !m_starBlockList[ currentRegion ]->fillToMag( maglim ) && maglim <= 12.0 ) {
+            kDebug() << "SBL::fillToMag( " << maglim << " ) failed for trixel " 
+                     << currentRegion << " !"<< endl;
         }
 
         //        kDebug() << "Drawing SBL for trixel " << currentRegion << ", SBL has " 
--- branches/kstars/summer/kdeedu/kstars/kstars/skycomponents/starcomponent.h #820981:820982
@@ -109,19 +109,6 @@
 
     void loadShallowStarData();
 
-    // REMOVED
-    /**
-     *@short Read one StarBlock of nstars stars from dataFile
-     *If nstars is not specified or -1, read as many stars as the StarBlock can hold
-     *
-     *@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
-     *@return true on success, false on failure
-     */
-    //    bool readStarBlock(StarBlock *SB, BinFileHelper *dataReader, int nstars=-1);
-
-
     SkyObject* objectNearest(SkyPoint *p, double &maxrad );
 
     SkyObject* findStarByGenetiveName( const QString name );
@@ -139,36 +126,9 @@
 
     SkyObject* findByName( const QString &name );
 
-    // REMOVED
-    /**
-     * @short usually does nothing.  If we are drawing faint stars and if
-     * Options:::magLimitDrawStar() is greater than m_faaintMagnitude then
-     * the first time we are called we just pop up a splash screen. Then
-     * the second time we are called we actually re-read the data file and
-     * finally erase the pop up.
-     */
-    //    void rereadData();
-
-    // REMOVED
-    /**
-     *@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();     
-
-    // REMOVED
-    /**
-     *@short returns an estimate of the stars.dat line number for a given
-     * star magnitude.
-     */
-    //    int lineNumber( float mag );
-
     // TODO: Find the right place for this method
     static void byteSwap( starData *stardata );
 
-    // TODO: Decide what to do with the following two
     static StarBlockFactory m_StarBlockFactory;
     static BinFileHelper deepStarReader;
 
@@ -187,7 +147,7 @@
     bool           m_hideLabels;
 
     KStarsData*    m_Data;
-    float          m_FaintMagnitude;   // WARNING: No longer used
+    float          m_FaintMagnitude;
     bool           starsLoaded;
     float          m_zoomMagLimit;
 
@@ -269,11 +229,11 @@
         int blockIndex;                // Index of current block in SBL
         int starIndex;                 // Index of current star in SB
         long Index;                    // Overall index of current star
-        bool named;                    // Tells us whether
+        bool named;                    // Tells us whether a star is named
         Trixel trixel;
     };
 
-    friend class TrixelIterator;
+    //    friend class TrixelIterator;
 
 };
 


More information about the Kstars-devel mailing list