ZoneArray.cpp   ZoneArray.cpp 
skipping to change at line 20 skipping to change at line 20
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "config.h"
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <io.h> #include <io.h>
#include <windows.h> #include <windows.h>
#endif #endif
#include "ZoneArray.hpp" #include "ZoneArray.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelGeodesicGrid.hpp" #include "StelGeodesicGrid.hpp"
#include "StelObject.hpp" #include "StelObject.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#ifdef HAVE_BYTESWAP_H static unsigned int stel_bswap_32(unsigned int val) {
#include <byteswap.h>
#else
static unsigned int bswap_32(unsigned int val) {
return (((val) & 0xff000000) >> 24) | (((val) & 0x00ff0000) >> 8) | return (((val) & 0xff000000) >> 24) | (((val) & 0x00ff0000) >> 8) |
(((val) & 0x0000ff00) << 8) | (((val) & 0x000000ff) << 24); (((val) & 0x0000ff00) << 8) | (((val) & 0x000000ff) << 24);
} }
#endif
namespace BigStarCatalogExtension namespace BigStarCatalogExtension
{ {
static const Vec3d north(0,0,1); static const Vec3f north(0,0,1);
void ZoneArray::initTriangle(int index, const Vec3d &c0, const Vec3d &c1, void ZoneArray::initTriangle(int index, const Vec3f &c0, const Vec3f &c1,
const Vec3d &c2) const Vec3f &c2)
{ {
// initialize center,axis0,axis1: // initialize center,axis0,axis1:
ZoneData &z(zones[index]); ZoneData &z(zones[index]);
z.center = c0+c1+c2; z.center = c0+c1+c2;
z.center.normalize(); z.center.normalize();
z.axis0 = north ^ z.center; z.axis0 = north ^ z.center;
z.axis0.normalize(); z.axis0.normalize();
z.axis1 = z.center ^ z.axis0; z.axis1 = z.center ^ z.axis0;
// initialize star_position_scale: // initialize star_position_scale:
double mu0,mu1,f,h; double mu0,mu1,f,h;
skipping to change at line 95 skipping to change at line 89
static inline int ReadInt(QFile& file, unsigned int &x) static inline int ReadInt(QFile& file, unsigned int &x)
{ {
const int rval = (4 == file.read((char*)&x, 4)) ? 0 : -1; const int rval = (4 == file.read((char*)&x, 4)) ? 0 : -1;
return rval; return rval;
} }
#if (!defined(__GNUC__)) #if (!defined(__GNUC__))
#warning Star catalogue loading has only been tested with gcc #warning Star catalogue loading has only been tested with gcc
#endif #endif
ZoneArray* ZoneArray::create(const QString& catalogFilePath, bool use_mmap, StelLoadingBar* lb) ZoneArray* ZoneArray::create(const QString& catalogFilePath, bool use_mmap)
{ {
QString dbStr; // for debugging output. QString dbStr; // for debugging output.
QFile* file = new QFile(catalogFilePath); QFile* file = new QFile(catalogFilePath);
if (!file->open(QIODevice::ReadOnly)) if (!file->open(QIODevice::ReadOnly))
{ {
qWarning() << "Error while loading " << catalogFilePath << " : failed to open file."; qWarning() << "Error while loading " << catalogFilePath << " : failed to open file.";
return 0; return 0;
} }
dbStr = "Loading \"" + catalogFilePath + "\": "; dbStr = "Loading \"" + catalogFilePath + "\": ";
unsigned int magic,major,minor,type,level,mag_min,mag_range,mag_step s; unsigned int magic,major,minor,type,level,mag_min,mag_range,mag_step s;
skipping to change at line 136 skipping to change at line 130
#if (!defined(__GNUC__)) #if (!defined(__GNUC__))
dbStr += "to native format "; dbStr += "to native format ";
#endif #endif
dbStr += "before mmap loading"; dbStr += "before mmap loading";
qWarning() << dbStr; qWarning() << dbStr;
use_mmap = false; use_mmap = false;
qWarning() << "Revert to not using mmmap"; qWarning() << "Revert to not using mmmap";
//return 0; //return 0;
} }
dbStr += "byteswap "; dbStr += "byteswap ";
type = bswap_32(type); type = stel_bswap_32(type);
major = bswap_32(major); major = stel_bswap_32(major);
minor = bswap_32(minor); minor = stel_bswap_32(minor);
level = bswap_32(level); level = stel_bswap_32(level);
mag_min = bswap_32(mag_min); mag_min = stel_bswap_32(mag_min);
mag_range = bswap_32(mag_range); mag_range = stel_bswap_32(mag_range);
mag_steps = bswap_32(mag_steps); mag_steps = stel_bswap_32(mag_steps);
} }
else if (magic == FILE_MAGIC) else if (magic == FILE_MAGIC)
{ {
// ok, FILE_MAGIC // ok, FILE_MAGIC
#if (!defined(__GNUC__)) #if (!defined(__GNUC__))
if (use_mmap) if (use_mmap)
{ {
// mmap only with gcc: // mmap only with gcc:
dbStr += "warning - you must convert catalogue " dbStr += "warning - you must convert catalogue "
+= "to native format before mmap loading"; += "to native format before mmap loading";
skipping to change at line 186 skipping to change at line 180
{ {
dbStr += "warning - unsupported version "; dbStr += "warning - unsupported version ";
} }
else else
{ {
// When this assertion fails you must redefine Star1 // When this assertion fails you must redefine Star1
// for your compiler. // for your compiler.
// Because your compiler does not pack the data, // Because your compiler does not pack the data,
// which is crucial for this application. // which is crucial for this application.
Q_ASSERT(sizeof(Star1) == 28); Q_ASSERT(sizeof(Star1) == 28);
rval = new HipZoneArray(file, byte_swap, use_mmap, l b, level, mag_min, mag_range, mag_steps); rval = new HipZoneArray(file, byte_swap, use_mmap, l evel, mag_min, mag_range, mag_steps);
if (rval == 0) if (rval == 0)
{ {
dbStr += "error - no memory "; dbStr += "error - no memory ";
} }
} }
break; break;
case 1: case 1:
if (major > MAX_MAJOR_FILE_VERSION) if (major > MAX_MAJOR_FILE_VERSION)
{ {
dbStr += "warning - unsupported version "; dbStr += "warning - unsupported version ";
} }
else else
{ {
// When this assertion fails you must redefine Star2 // When this assertion fails you must redefine Star2
// for your compiler. // for your compiler.
// Because your compiler does not pack the data, // Because your compiler does not pack the data,
// which is crucial for this application. // which is crucial for this application.
Q_ASSERT(sizeof(Star2) == 10); Q_ASSERT(sizeof(Star2) == 10);
rval = new SpecialZoneArray<Star2>(file, byte_swap, rval = new SpecialZoneArray<Star2>(file, byte_swap,
use_mmap, use_mmap, level, mag_min, mag_range, mag_steps);
lb, level, mag_mi
n,
mag_range, mag_st
eps);
if (rval == 0) if (rval == 0)
{ {
dbStr += "error - no memory "; dbStr += "error - no memory ";
} }
} }
break; break;
case 2: case 2:
if (major > MAX_MAJOR_FILE_VERSION) if (major > MAX_MAJOR_FILE_VERSION)
{ {
dbStr += "warning - unsupported version "; dbStr += "warning - unsupported version ";
} }
else else
{ {
// When this assertion fails you must redefine Star3 // When this assertion fails you must redefine Star3
// for your compiler. // for your compiler.
// Because your compiler does not pack the data, // Because your compiler does not pack the data,
// which is crucial for this application. // which is crucial for this application.
Q_ASSERT(sizeof(Star3) == 6); Q_ASSERT(sizeof(Star3) == 6);
rval = new SpecialZoneArray<Star3>(file, byte_swap, rval = new SpecialZoneArray<Star3>(file, byte_swap,
use_mmap, use_mmap, level, mag_min, mag_range, mag_steps);
lb, level, mag_mi
n,
mag_range, mag_st
eps);
if (rval == 0) if (rval == 0)
{ {
dbStr += "error - no memory "; dbStr += "error - no memory ";
} }
} }
break; break;
default: default:
dbStr += "error - bad file type "; dbStr += "error - bad file type ";
break; break;
} }
skipping to change at line 267 skipping to change at line 257
ZoneArray::ZoneArray(const QString& fname, QFile* file, int level, int mag_ min, ZoneArray::ZoneArray(const QString& fname, QFile* file, int level, int mag_ min,
int mag_range, int mag_steps) int mag_range, int mag_steps)
: fname(fname), level(level), mag_min(mag_min), : fname(fname), level(level), mag_min(mag_min),
mag_range(mag_range), mag_steps(mag_steps), mag_range(mag_range), mag_steps(mag_steps),
star_position_scale(0.0), zones(0), file(file) star_position_scale(0.0), zones(0), file(file)
{ {
nr_of_zones = StelGeodesicGrid::nrOfZones(level); nr_of_zones = StelGeodesicGrid::nrOfZones(level);
nr_of_stars = 0; nr_of_stars = 0;
} }
bool ZoneArray::readFileWithStelLoadingBar(QFile& file, void *data, qint64 size, StelLoadingBar*lb) bool ZoneArray::readFile(QFile& file, void *data, qint64 size)
{ {
int parts = 256; int parts = 256;
int part_size = (size + (parts>>1)) / parts; int part_size = (size + (parts>>1)) / parts;
if (part_size < 64*1024) if (part_size < 64*1024)
{ {
part_size = 64*1024; part_size = 64*1024;
parts = (size + (part_size>>1)) / part_size; parts = (size + (part_size>>1)) / part_size;
} }
float i = 0.f; float i = 0.f;
if (lb)
lb->Draw(i / parts);
i += 1.f; i += 1.f;
while (size > 0) while (size > 0)
{ {
const int to_read = (part_size < size) ? part_size : size; const int to_read = (part_size < size) ? part_size : size;
const int read_rc = file.read((char*)data, to_read); const int read_rc = file.read((char*)data, to_read);
if (read_rc != to_read) return false; if (read_rc != to_read) return false;
size -= read_rc; size -= read_rc;
data = ((char*)data) + read_rc; data = ((char*)data) + read_rc;
if (lb)
lb->Draw(i / parts);
i += 1.f; i += 1.f;
} }
return true; return true;
} }
void HipZoneArray::updateHipIndex(HipIndexStruct hipIndex[]) const void HipZoneArray::updateHipIndex(HipIndexStruct hipIndex[]) const
{ {
for (const SpecialZoneData<Star1> *z=getZones()+(nr_of_zones-1);z>=g etZones();z--) for (const SpecialZoneData<Star1> *z=getZones()+(nr_of_zones-1);z>=g etZones();z--)
{ {
for (const Star1 *s = z->getStars()+z->size-1;s>=z->getStars ();s--) for (const Star1 *s = z->getStars()+z->size-1;s>=z->getStars ();s--)
skipping to change at line 329 skipping to change at line 315
star_position_scale /= Star::MaxPosVal; star_position_scale /= Star::MaxPosVal;
for (ZoneData *z=zones+(nr_of_zones-1);z>=zones;z--) for (ZoneData *z=zones+(nr_of_zones-1);z>=zones;z--)
{ {
z->axis0 *= star_position_scale; z->axis0 *= star_position_scale;
z->axis1 *= star_position_scale; z->axis1 *= star_position_scale;
} }
} }
template<class Star> template<class Star>
SpecialZoneArray<Star>::SpecialZoneArray(QFile* file, bool byte_swap,bool u se_mmap, SpecialZoneArray<Star>::SpecialZoneArray(QFile* file, bool byte_swap,bool u se_mmap,
StelLoadingBar*lb, int level, int m int level, int mag_min, int mag_ran
ag_min, ge, int mag_steps)
int mag_range, int mag_steps)
: ZoneArray(file->fileName(), file, level, mag_min, mag_rang e, mag_steps), : ZoneArray(file->fileName(), file, level, mag_min, mag_rang e, mag_steps),
stars(0), mmap_start(0) stars(0), mmap_start(0)
{ {
if (nr_of_zones > 0) if (nr_of_zones > 0)
{ {
if (lb)
lb->Draw(0.f);
zones = new SpecialZoneData<Star>[nr_of_zones]; zones = new SpecialZoneData<Star>[nr_of_zones];
if (zones == 0) if (zones == 0)
{ {
qDebug() << "ERROR: SpecialZoneArray(" << level qDebug() << "ERROR: SpecialZoneArray(" << level
<< ")::SpecialZoneArray: no memory (1)"; << ")::SpecialZoneArray: no memory (1)";
exit(1); exit(1);
} }
unsigned int *zone_size = new unsigned int[nr_of_zones]; unsigned int *zone_size = new unsigned int[nr_of_zones];
if (zone_size == 0) if (zone_size == 0)
skipping to change at line 366 skipping to change at line 349
<< file->fileName(); << file->fileName();
delete[] getZones(); delete[] getZones();
zones = 0; zones = 0;
nr_of_zones = 0; nr_of_zones = 0;
} }
else else
{ {
const unsigned int *tmp = zone_size; const unsigned int *tmp = zone_size;
for (unsigned int z=0;z<nr_of_zones;z++,tmp++) for (unsigned int z=0;z<nr_of_zones;z++,tmp++)
{ {
const unsigned int tmp_spu_int32 = byte_swap ?bswap_32(*tmp):*tmp; const unsigned int tmp_spu_int32 = byte_swap ?stel_bswap_32(*tmp):*tmp;
nr_of_stars += tmp_spu_int32; nr_of_stars += tmp_spu_int32;
getZones()[z].size = tmp_spu_int32; getZones()[z].size = tmp_spu_int32;
} }
} }
// delete zone_size before allocating stars // delete zone_size before allocating stars
// in order to avoid memory fragmentation: // in order to avoid memory fragmentation:
delete[] zone_size; delete[] zone_size;
if (nr_of_stars == 0) if (nr_of_stars == 0)
{ {
skipping to change at line 422 skipping to change at line 405
} }
else else
{ {
stars = new Star[nr_of_stars]; stars = new Star[nr_of_stars];
if (stars == 0) if (stars == 0)
{ {
qDebug() << "ERROR: SpecialZoneArray (" << level qDebug() << "ERROR: SpecialZoneArray (" << level
<< ")::SpecialZoneArray: no memory (3)"; << ")::SpecialZoneArray: no memory (3)";
exit(1); exit(1);
} }
if (!readFileWithStelLoadingBar(*file,stars, sizeof(Star)*nr_of_stars,lb)) if (!readFile(*file,stars,sizeof(Star)*nr_of _stars))
{ {
delete[] stars; delete[] stars;
stars = 0; stars = 0;
nr_of_stars = 0; nr_of_stars = 0;
delete[] getZones(); delete[] getZones();
zones = 0; zones = 0;
nr_of_zones = 0; nr_of_zones = 0;
} }
else else
{ {
skipping to change at line 465 skipping to change at line 448
// need for byte_swap on a LE machine means that catalog is BE // need for byte_swap on a LE machine means that catalog is BE
byte_swap byte_swap
#endif #endif
); );
} }
} }
} }
file->close(); file->close();
} }
} }
if (lb)
lb->Draw(1.f);
} }
} }
template<class Star> template<class Star>
SpecialZoneArray<Star>::~SpecialZoneArray(void) SpecialZoneArray<Star>::~SpecialZoneArray(void)
{ {
if (stars) if (stars)
{ {
if (mmap_start != 0) if (mmap_start != 0)
{ {
skipping to change at line 501 skipping to change at line 482
nr_of_zones = 0; nr_of_zones = 0;
nr_of_stars = 0; nr_of_stars = 0;
} }
template<class Star> template<class Star>
void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool is _inside, const float *rcmag_table, StelCore* core, unsigned int maxMagStarN ame, void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool is _inside, const float *rcmag_table, StelCore* core, unsigned int maxMagStarN ame,
float names_brightness) const float names_brightness) const
{ {
StelSkyDrawer* drawer = core->getSkyDrawer(); StelSkyDrawer* drawer = core->getSkyDrawer();
SpecialZoneData<Star> *const z = getZones() + index; SpecialZoneData<Star> *const z = getZones() + index;
Vec3d v; Vec3f vf;
const Star *const end = z->getStars() + z->size; const Star *const end = z->getStars() + z->size;
static const double d2000 = 2451545.0; static const double d2000 = 2451545.0;
const double movementFactor = (M_PI/180)*(0.0001/3600) * ((core->get Navigator()->getJDay()-d2000)/365.25) / star_position_scale; const double movementFactor = (M_PI/180)*(0.0001/3600) * ((core->get Navigator()->getJDay()-d2000)/365.25) / star_position_scale;
const float* tmpRcmag; const float* tmpRcmag;
for (const Star *s=z->getStars();s<end;++s) for (const Star *s=z->getStars();s<end;++s)
{ {
tmpRcmag = rcmag_table+2*s->mag; tmpRcmag = rcmag_table+2*s->mag;
if (*tmpRcmag<=0.) if (*tmpRcmag<=0.f)
break; break;
s->getJ2000Pos(z,movementFactor, v); s->getJ2000Pos(z,movementFactor, vf);
if (drawer->drawPointSource(sPainter, v,tmpRcmag,s->bV, !is_ if (drawer->drawPointSource(sPainter, vf, tmpRcmag, s->bV, !
inside) && s->hasName() && s->mag < maxMagStarName) is_inside) && s->hasName() && s->mag < maxMagStarName)
{ {
const float offset = *tmpRcmag*0.7; const float offset = *tmpRcmag*0.7f;
const Vec3f& colorr = (StelApp::getInstance().getVis const Vec3f& colorr = (StelApp::getInstance().getVis
ionModeNight() ? Vec3f(0.8, 0.2, 0.2) : StelSkyDrawer::indexToColor(s->bV)) ionModeNight() ? Vec3f(0.8f, 0.2f, 0.2f) : StelSkyDrawer::indexToColor(s->b
*0.75; V))*0.75f;
sPainter->setColor(colorr[0], colorr[1], colorr[2],n ames_brightness); sPainter->setColor(colorr[0], colorr[1], colorr[2],n ames_brightness);
sPainter->drawText(v, s->getNameI18n(), 0, offset, o ffset, false); sPainter->drawText(Vec3d(vf[0], vf[1], vf[2]), s->ge tNameI18n(), 0, offset, offset, false);
} }
} }
} }
template<class Star> template<class Star>
void SpecialZoneArray<Star>::searchAround(const StelNavigator* nav, int ind ex, const Vec3d &v, double cosLimFov, void SpecialZoneArray<Star>::searchAround(const StelNavigator* nav, int ind ex, const Vec3d &v, double cosLimFov,
QList<StelObjectP > &result) QList<StelObjectP > &result)
{ {
static const double d2000 = 2451545.0; static const double d2000 = 2451545.0;
const double movementFactor = (M_PI/180.)*(0.0001/3600.) * ((nav->ge tJDay()-d2000)/365.25)/ star_position_scale; const double movementFactor = (M_PI/180.)*(0.0001/3600.) * ((nav->ge tJDay()-d2000)/365.25)/ star_position_scale;
const SpecialZoneData<Star> *const z = getZones()+index; const SpecialZoneData<Star> *const z = getZones()+index;
Vec3d tmp; Vec3f tmp;
Vec3f vf(v[0], v[1], v[2]);
for (const Star* s=z->getStars();s<z->getStars()+z->size;++s) for (const Star* s=z->getStars();s<z->getStars()+z->size;++s)
{ {
s->getJ2000Pos(z,movementFactor, tmp); s->getJ2000Pos(z,movementFactor, tmp);
tmp.normalize(); tmp.normalize();
if (tmp*v >= cosLimFov) if (tmp*vf >= cosLimFov)
{ {
// TODO: do not select stars that are too faint to d isplay // TODO: do not select stars that are too faint to d isplay
result.push_back(s->createStelObject(this,z)); result.push_back(s->createStelObject(this,z));
} }
} }
} }
} // namespace BigStarCatalogExtension } // namespace BigStarCatalogExtension
 End of changes. 25 change blocks. 
57 lines changed or deleted 35 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/