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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "ZoneArray.hpp"
#include "StelApp.hpp"
#include "StelFileMgr.hpp"
#include "StelGeodesicGrid.hpp"
#include "StelObject.hpp"
#include "StelPainter.hpp"
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#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" static unsigned int stel_bswap_32(unsigned int val)
#include "renderer/StelRenderer.hpp"
#include "StelApp.hpp"
#include "StelFileMgr.hpp"
#include "StelGeodesicGrid.hpp"
#include "StelObject.hpp"
static unsigned int stel_bswap_32(unsigned int val) {
return (((val) & 0xff000000) >> 24) | (((val) & 0x00ff0000) >> 8) |
(((val) & 0x0000ff00) << 8) | (((val) & 0x000000ff) << 24);
}
namespace BigStarCatalogExtension
{ {
return (((val) & 0xff000000) >> 24) | (((val) & 0x00ff0000) >> 8) |
(((val) & 0x0000ff00) << 8) | (((val) & 0x000000ff) << 24);
}
static const Vec3f north(0,0,1); static const Vec3f north(0,0,1);
void ZoneArray::initTriangle(int index, const Vec3f &c0, const Vec3f &c1, void ZoneArray::initTriangle(int index, const Vec3f &c0, const Vec3f &c1, c
const Vec3f &c2) onst 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:
double mu0,mu1,f,h; // Initialize star_position_scale. This scale is used to multiply st
ars position
// encoded as integers so that it optimize precision over the triang
le.
// It has to be computed for each triangle because the relative orie
ntation of the 2 axis is different for each triangle.
float mu0,mu1,f,h;
mu0 = (c0-z.center)*z.axis0; mu0 = (c0-z.center)*z.axis0;
mu1 = (c0-z.center)*z.axis1; mu1 = (c0-z.center)*z.axis1;
f = 1.0/sqrt(1.0-mu0*mu0-mu1*mu1); f = 1.f/std::sqrt(1.f-mu0*mu0-mu1*mu1);
h = fabs(mu0)*f; h = std::fabs(mu0)*f;
if (star_position_scale < h) star_position_scale = h; if (star_position_scale < h) star_position_scale = h;
h = fabs(mu1)*f; h = std::fabs(mu1)*f;
if (star_position_scale < h) star_position_scale = h; if (star_position_scale < h) star_position_scale = h;
mu0 = (c1-z.center)*z.axis0; mu0 = (c1-z.center)*z.axis0;
mu1 = (c1-z.center)*z.axis1; mu1 = (c1-z.center)*z.axis1;
f = 1.0/sqrt(1.0-mu0*mu0-mu1*mu1); f = 1.f/std::sqrt(1.f-mu0*mu0-mu1*mu1);
h = fabs(mu0)*f; h = std::fabs(mu0)*f;
if (star_position_scale < h) star_position_scale = h; if (star_position_scale < h) star_position_scale = h;
h = fabs(mu1)*f; h = std::fabs(mu1)*f;
if (star_position_scale < h) star_position_scale = h; if (star_position_scale < h) star_position_scale = h;
mu0 = (c2-z.center)*z.axis0; mu0 = (c2-z.center)*z.axis0;
mu1 = (c2-z.center)*z.axis1; mu1 = (c2-z.center)*z.axis1;
f = 1.0/sqrt(1.0-mu0*mu0-mu1*mu1); f = 1.f/std::sqrt(1.f-mu0*mu0-mu1*mu1);
h = fabs(mu0)*f; h = std::fabs(mu0)*f;
if (star_position_scale < h) star_position_scale = h; if (star_position_scale < h) star_position_scale = h;
h = fabs(mu1)*f; h = std::fabs(mu1)*f;
if (star_position_scale < h) star_position_scale = h; if (star_position_scale < h) star_position_scale = h;
} }
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__))
skipping to change at line 170 skipping to change at line 170
{ {
dbStr += "error - not a catalogue file."; dbStr += "error - not a catalogue file.";
qDebug() << dbStr; qDebug() << dbStr;
return 0; return 0;
} }
ZoneArray *rval = 0; ZoneArray *rval = 0;
dbStr += QString("%1_%2v%3_%4; ").arg(level).arg(type).arg(major).ar g(minor); dbStr += QString("%1_%2v%3_%4; ").arg(level).arg(type).arg(major).ar g(minor);
switch (type) switch (type)
{ {
case 0: case 0:
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 Star1 // When this assertion fails you must redefi
// for your compiler. ne Star1
// Because your compiler does not pack the data, // for your compiler.
// which is crucial for this application. // Because your compiler does not pack the d
Q_ASSERT(sizeof(Star1) == 28); ata,
rval = new HipZoneArray(file, byte_swap, use_mmap, l // which is crucial for this application.
evel, mag_min, mag_range, mag_steps); Q_ASSERT(sizeof(Star1) == 28);
if (rval == 0) rval = new HipZoneArray(file, byte_swap, use
{ _mmap, level, mag_min, mag_range, mag_steps);
dbStr += "error - no memory "; if (rval == 0)
} {
} dbStr += "error - no memory ";
break; }
case 1: }
if (major > MAX_MAJOR_FILE_VERSION) break;
{ case 1:
dbStr += "warning - unsupported version "; if (major > MAX_MAJOR_FILE_VERSION)
} {
else dbStr += "warning - unsupported version ";
{ }
// When this assertion fails you must redefine Star2 else
// for your compiler. {
// Because your compiler does not pack the data, // When this assertion fails you must redefi
// which is crucial for this application. ne Star2
// for your compiler.
// Because your compiler does not pack the d
ata,
// which is crucial for this application.
#ifndef _MSC_BUILD #ifndef _MSC_BUILD
Q_ASSERT(sizeof(Star2) == 10); Q_ASSERT(sizeof(Star2) == 10);
#endif #endif
rval = new SpecialZoneArray<Star2>(file, byte_swap, rval = new SpecialZoneArray<Star2>(file, byt
use_mmap, level, mag_min, mag_range, mag_steps); e_swap, use_mmap, level, mag_min, mag_range, mag_steps);
if (rval == 0) if (rval == 0)
{
dbStr += "error - no memory ";
}
}
break;
case 2:
if (major > MAX_MAJOR_FILE_VERSION)
{ {
dbStr += "error - no memory "; dbStr += "warning - unsupported version ";
} }
} else
break; {
case 2: // When this assertion fails you must redefi
if (major > MAX_MAJOR_FILE_VERSION) ne Star3
{ // for your compiler.
dbStr += "warning - unsupported version "; // Because your compiler does not pack the d
} ata,
else // which is crucial for this application.
{
// When this assertion fails you must redefine Star3
// for your compiler.
// Because your compiler does not pack the data,
// which is crucial for this application.
#ifndef _MSC_BUILD #ifndef _MSC_BUILD
Q_ASSERT(sizeof(Star3) == 6); Q_ASSERT(sizeof(Star3) == 6);
#endif #endif
rval = new SpecialZoneArray<Star3>(file, byte_swap, rval = new SpecialZoneArray<Star3>(file, byt
use_mmap, level, mag_min, mag_range, mag_steps); e_swap, use_mmap, level, mag_min, mag_range, mag_steps);
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;
} }
if (rval && rval->isInitialized()) if (rval && rval->isInitialized())
{ {
dbStr += QString("%1").arg(rval->getNrOfStars()); dbStr += QString("%1").arg(rval->getNrOfStars());
qDebug() << dbStr; qDebug() << dbStr;
} }
else else
{ {
dbStr += " - initialization failed"; dbStr += " - initialization failed";
qDebug() << dbStr; qDebug() << dbStr;
if (rval) if (rval)
{ {
delete rval; delete rval;
rval = 0; rval = 0;
} }
} }
return rval; return rval;
} }
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::readFile(QFile& file, void *data, qint64 size) 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)
skipping to change at line 308 skipping to change at line 308
{ {
hipIndex[hip].a = this; hipIndex[hip].a = this;
hipIndex[hip].z = z; hipIndex[hip].z = z;
hipIndex[hip].s = s; hipIndex[hip].s = s;
} }
} }
} }
} }
template<class Star> template<class Star>
void SpecialZoneArray<Star>::scaleAxis(void) void SpecialZoneArray<Star>::scaleAxis()
{ {
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>
skipping to change at line 484 skipping to change at line 484
if (zones) if (zones)
{ {
delete[] getZones(); delete[] getZones();
zones = NULL; zones = NULL;
} }
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 void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool is
(StelProjectorP projector, StelRenderer* renderer, int index, bool i InsideViewport, const RCMag* rcmag_table,
s_inside, int limitMagIndex, StelCore* core, int maxMagStarName, float names_b
const float *rcmag_table, StelCore* core, unsigned int maxMagStarNa rightness, const QVector<SphericalCap> &boundingCaps) const
me, {
float names_brightness) const StelSkyDrawer* drawer = core->getSkyDrawer();
{ Vec3f vf;
StelSkyDrawer* drawer = core->getSkyDrawer(); static const double d2000 = 2451545.0;
SpecialZoneData<Star> *const z = getZones() + index; const float movementFactor = (M_PI/180)*(0.0001/3600) * ((core->getJDay
Vec3f vf; ()-d2000)/365.25) / star_position_scale;
const Star *const end = z->getStars() + z->size;
static const double d2000 = 2451545.0; // GZ, added for extinction
const double movementFactor = (M_PI/180)*(0.0001/3600) * ((core->get const Extinction& extinction=core->getSkyDrawer()->getExtinction();
JDay()-d2000)/365.25) / star_position_scale; const bool withExtinction=drawer->getFlagHasAtmosphere() && extinction.
const float* tmpRcmag; // will point to precomputed rC in table getExtinctionCoefficient()>=0.01f;
Extinction extinction=core->getSkyDrawer()->getExtinction(); const float k = 0.001f*mag_range/mag_steps; // from StarMgr.cpp line 65
const bool withExtinction=(drawer->getFlagHasAtmosphere() && extinct 4
ion.getExtinctionCoefficient()>=0.01f);
const float k = (0.001f*mag_range)/mag_steps; // from StarMgr.cpp li // Allow artificial cutoff:
ne 654 // find the (integer) mag at which is just bright enough to be drawn
// GZ: allow artificial cutoff: .
const int clampStellarMagnitude_mmag = (int) floor(drawer->getCustom int cutoffMagStep=limitMagIndex;
StarMagnitudeLimit() * 1000.0f); if (drawer->getFlagStarMagnitudeLimit())
// find s->mag, which is the step into the magnitudes which is just {
bright enough to be drawn. cutoffMagStep = ((int)(drawer->getCustomStarMagnitudeLimit()
int cutoffMagStep=(drawer->getFlagStarMagnitudeLimit() ? (clampStell *1000.f) - mag_min)*mag_steps/mag_range;
arMagnitude_mmag - mag_min)*mag_steps/mag_range : mag_steps); if (cutoffMagStep>limitMagIndex)
cutoffMagStep = limitMagIndex;
// go through all stars, which are sorted by magnitude (bright stars }
first) Q_ASSERT(cutoffMagStep<RCMAG_TABLE_SIZE);
for (const Star *s=z->getStars();s<end;++s)
{ // Go through all stars, which are sorted by magnitude (bright stars
if (s->mag > cutoffMagStep) break; // e.g. naked-eye stars o first)
nly. const SpecialZoneData<Star>* zoneToDraw = getZones() + index;
tmpRcmag = rcmag_table+2*s->mag; const Star* lastStar = zoneToDraw->getStars() + zoneToDraw->size;
if (*tmpRcmag<=0.f) break; // no size for this and following for (const Star* s=zoneToDraw->getStars();s<lastStar;++s)
(even dimmer, unextincted) stars? --> early exit {
s->getJ2000Pos(z,movementFactor, vf); // Artifical cutoff per magnitude
if (s->mag > cutoffMagStep)
const Vec3d vd(vf[0], vf[1], vf[2]); break;
if (withExtinction) // Because of the test above, the star should always be visi
{ ble from this point.
//GZ: We must compute position first, then shift mag
nitude. // Array of 2 numbers containing radius and magnitude
Vec3d altAz = core->j2000ToAltAz(vd, StelCore::Refra const RCMag* tmpRcmag = &rcmag_table[s->mag];
ctionOn);
float extMagShift = 0.0f; // Get the star position from the array
extinction.forward(&altAz, &extMagShift); s->getJ2000Pos(zoneToDraw, movementFactor, vf);
const int extMagShiftStep =
qMin((int)floor(extMagShift / k), RCMAG_TABL // If the star zone is not strictly contained inside the vie
E_SIZE-mag_steps); wport, eliminate from the
if ((s->mag + extMagShiftStep) > cutoffMagStep) // i // beginning the stars actually outside viewport.
.e., if extincted it is dimmer than cutoff, so remove [draw with hopefully if (!isInsideViewport)
zero size]. {
{ bool isVisible = true;
tmpRcmag = rcmag_table + 2 * (RCMAG_TABLE_SI foreach (const SphericalCap& cap, boundingCaps)
ZE-1); {
} // Don't use if (!cap.contains(vf)) here bec
else ause we don't want to normalize the vector yet, but know
{ // that it's almost normalized, enough for m
tmpRcmag = rcmag_table + 2 * (s->mag+extMagS anually computing the intersection avoiding the assert.
hiftStep); if (vf[0]*static_cast<float>(cap.n[0])+vf[1]
*static_cast<float>(cap.n[1])+vf[2]*static_cast<float>(cap.n[2])<static_cas
t<float>(cap.d))
{
isVisible = false;
continue;
}
} }
if (!isVisible)
continue;
} }
Vec3f win; int extinctedMagIndex = s->mag;
if(drawer->pointSourceVisible(&(*projector), vf, tmpRcmag, ! if (withExtinction)
is_inside, win))
{ {
drawer->drawPointSource(win, tmpRcmag, s->bV); Vec3f altAz(vf);
if(s->hasName() && s->mag < maxMagStarName && s->has altAz.normalize();
ComponentID()<=1) core->j2000ToAltAzInPlaceNoRefraction(&altAz);
{ float extMagShift=0.0f;
const float offset = *tmpRcmag*0.7f; extinction.forward(altAz, &extMagShift);
const Vec3f& colorr = (StelApp::getInstance( extinctedMagIndex = s->mag + (int)(extMagShift/k);
).getVisionModeNight() ? Vec3f(0.8f, 0.0f, 0.0f) : StelSkyDrawer::indexToCo if (extinctedMagIndex >= cutoffMagStep) // i.e., if
lor(s->bV))*0.75f; extincted it is dimmer than cutoff, so remove
continue;
renderer->setGlobalColor(colorr[0], colorr[1 tmpRcmag = &rcmag_table[extinctedMagIndex];
], colorr[2], names_brightness); }
renderer->drawText(TextParams(vf, projector,
s->getNameI18n()) if (drawer->drawPointSource(sPainter, vf, *tmpRcmag, s->bV,
.shift(offset, offset).us !isInsideViewport) && s->hasName() && extinctedMagIndex < maxMagStarName &&
eGravity()); s->hasComponentID()<=1)
} {
const float offset = tmpRcmag->radius*0.7f;
const Vec3f colorr = StelSkyDrawer::indexToColor(s->
bV)*0.75f;
sPainter->setColor(colorr[0], colorr[1], colorr[2],n
ames_brightness);
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 void SpecialZoneArray<Star>::searchAround(const StelCore* core, int index,
(const StelCore* core, int index, const Vec3d &v, double cosLimFov, 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.) * ((core->g etJDay()-d2000)/365.25)/ star_position_scale; const double movementFactor = (M_PI/180.)*(0.0001/3600.) * ((core->g etJDay()-d2000)/365.25)/ star_position_scale;
const SpecialZoneData<Star> *const z = getZones()+index; const SpecialZoneData<Star> *const z = getZones()+index;
Vec3f tmp; Vec3f tmp;
Vec3f vf(v[0], v[1], v[2]); 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*vf >= 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
 End of changes. 28 change blocks. 
177 lines changed or deleted 201 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/