Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/modules/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3765,7 +3765,7 @@ float Planet::getVMagnitude(const StelCore* core, double eclipseFactor) const
double Planet::getAngularRadius(const StelCore* core) const
{
const double rad = (rings ? rings->getSize() : equatorialRadius);
return std::atan2(rad*sphereScale,getJ2000EquatorialPos(core).norm()) * M_180_PI;
return std::asin(rad*sphereScale/getJ2000EquatorialPos(core).norm()) * M_180_PI;
}


Expand Down
21 changes: 18 additions & 3 deletions src/core/modules/StarMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "StelUtils.hpp"
#include "StelHealpix.hpp"
#include "StelObject.hpp"
#include "SolarSystem.hpp"

#include <QGlobalStatic>
#include <QTextStream>
Expand Down Expand Up @@ -1325,117 +1326,131 @@


// Draw all the stars
void StarMgr::draw(StelCore* core)
{
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
StelSkyDrawer* skyDrawer = core->getSkyDrawer();
// If stars are turned off don't waste time below
// projecting all stars just to draw disembodied labels
if (!static_cast<bool>(starsFader.getInterstate()))
return;

static StelSkyCultureMgr* scMgr = GETSTELMODULE(StelSkyCultureMgr);
const bool currentSkycultureUsesCommonStarnames=scMgr->getFlagOverrideUseCommonNames() ||
scMgr->currentSkycultureUsesCommonNames();

int maxSearchLevel = getMaxSearchLevel();
double margin = 0.; // pixel margin to be applied to viewport convex polygon
if (core->getSkyDrawer()->getFlagHasAtmosphere())
{
// Saemundsson's inversion formula for atmospheric refraction is not exact, so need some padding in terms of arcseconds
margin = 30000. * MAS2RAD * prj->getPixelPerRadAtCenter(); // 0.5 arcmin
}

QVector<SphericalCap> viewportCaps = prj->getViewportConvexPolygon(margin, margin)->getBoundingSphericalCaps();
viewportCaps.append(core->getVisibleSkyArea());
const GeodesicSearchResult* geodesic_search_result = core->getGeodesicGrid(maxSearchLevel)->search(viewportCaps,maxSearchLevel);

// Set temporary static variable for optimization
const float names_brightness = labelsFader.getInterstate() * starsFader.getInterstate();

// prepare for aberration: Explan. Suppl. 2013, (7.38)
const bool withAberration=core->getUseAberration();
Vec3d vel(0.);
if (withAberration)
{
vel = core->getAberrationVec(core->getJDE());
}

// Prepare openGL for drawing many stars
StelPainter sPainter(prj);
QFont font=QGuiApplication::font();
font.setPixelSize(fontSize);
sPainter.setFont(font);

skyDrawer->preDrawPointSource(&sPainter);

// Prepare a table for storing precomputed RCMag for all ZoneArrays
RCMag rcmag_table[RCMAG_TABLE_SIZE];

// Try to filter away stars hidden by the Moon!
bool filterMoon=false;
PlanetP moon = GETSTELMODULE(SolarSystem)->getMoon();
Vec3d moonPos=moon->getJ2000EquatorialPos(core);
const double moonRadius = moon->getEquatorialRadius() * moon->getSphereScale();
double angularSize = asin(moonRadius / moonPos.norm());
moonPos.normalize();
SphericalCap moonCap(moonPos, cos(angularSize));
for (auto &cap : viewportCaps)
{
if (cap.intersects(moonCap))
filterMoon=true;
}

// Draw all the stars of all the selected zones
for (const auto* z : std::as_const(gridLevels))
{
int limitMagIndex=RCMAG_TABLE_SIZE;
// overshoot by 7 mag because some stars (like HIP 16757) can get brighter than its catalogs min magnitude
const float mag_min = 0.001f*z->mag_min - 7.f;
for (int i=0;i<RCMAG_TABLE_SIZE;++i)
{
const float mag = mag_min+0.05*i; // 0.05 mag MagStepIncrement
if (skyDrawer->computeRCMag(mag, &rcmag_table[i])==false)
{
if (i==0)
goto exit_loop;

// The last magnitude at which the star is visible
limitMagIndex = i-1;

// We reached the point where stars are not visible anymore
// Fill the rest of the table with zero and leave.
for (;i<RCMAG_TABLE_SIZE;++i)
{
rcmag_table[i].luminance=0;
rcmag_table[i].radius=0;
}
break;
}
rcmag_table[i].radius *= starsFader.getInterstate();
}
lastMaxSearchLevel = z->level;

int maxMagStarName = 0;
if (labelsFader.getInterstate()>0.f)
{
// Adapt magnitude limit of the stars labels according to FOV and labelsAmount
float maxMag = (skyDrawer->getLimitMagnitude()-6.5f)*0.7f+(static_cast<float>(labelsAmount)*1.2f)-2.f;
int x = static_cast<int>((maxMag-mag_min)/0.05); // 0.05 mag MagStepIncrement
if (x > 0)
maxMagStarName = x;
}
int zone;
double withParallax = core->getUseParallax() * core->getParallaxFactor();
Vec3d diffPos(0., 0., 0.);
if (withParallax) {
diffPos = core->getParallaxDiff(core->getJDE());
}
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, vel, withParallax, diffPos, currentSkycultureUsesCommonStarnames);
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, vel, withParallax, diffPos, currentSkycultureUsesCommonStarnames, filterMoon, moonCap);
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, viewportCaps, withAberration, vel, withParallax, diffPos, currentSkycultureUsesCommonStarnames);
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, viewportCaps, withAberration, vel, withParallax, diffPos, currentSkycultureUsesCommonStarnames, filterMoon, moonCap);
// always check the last zone because it is a global zone
z->draw(&sPainter, (20<<(z->level<<1)), false, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, vel, withParallax, diffPos, currentSkycultureUsesCommonStarnames);
z->draw(&sPainter, (20<<(z->level<<1)), false, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, vel, withParallax, diffPos, currentSkycultureUsesCommonStarnames, filterMoon, moonCap);
}
exit_loop:

// Finish drawing many stars
skyDrawer->postDrawPointSource(&sPainter);

if (objectMgr->getFlagSelectedObjectPointer())
drawPointer(sPainter, core);
}


// Return a QList containing the stars located
// inside the limFov circle around position vv (in J2000 frame without aberration)

Check notice on line 1453 in src/core/modules/StarMgr.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/core/modules/StarMgr.cpp#L1329-L1453

Complex Method
QList<StelObjectP > StarMgr::searchAround(const Vec3d& vv, double limFov, const StelCore* core) const
{
QList<StelObjectP > result;
Expand Down
10 changes: 9 additions & 1 deletion src/core/modules/ZoneArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness,
const QVector<SphericalCap> &boundingCaps,
const bool withAberration, const Vec3d vel, const double withParallax, const Vec3d diffPos,
const bool withCommonNameI18n) const
const bool withCommonNameI18n,
const bool filterMoon, SphericalCap moonCap) const
{
StelSkyDrawer* drawer = core->getSkyDrawer();
Vec3d v;
Expand Down Expand Up @@ -543,6 +544,13 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
continue;
}

// If the star is covered by the Moon, don't draw (avoid displaying part of halo of occulted star!)
// TODO: This is a bad test. We should draw the moon into a stencil buffer and check that.
if (filterMoon)
{
if (moonCap.contains(v))
continue;
}
int extinctedMagIndex = magIndex;
float twinkleFactor=1.0f; // allow height-dependent twinkle.
if (withExtinction)
Expand Down
9 changes: 6 additions & 3 deletions src/core/modules/ZoneArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ZoneArray
virtual void searchWithin(const StelCore* core, int index, const SphericalRegionP region, const double withParallax, const Vec3d diffPos, const bool hipOnly, const float maxMag,
QList<StelObjectP > &result) const = 0;

virtual StelObjectP searchGaiaID(int index, const StarId source_id, int& matched) const = 0;
virtual StelObjectP searchGaiaID(int index, const StarId source_id, int& matched) const = 0;
virtual void searchGaiaIDepochPos(const StarId source_id, float dyrs,
double & RA,
double & DEC,
Expand All @@ -114,7 +114,9 @@ class ZoneArray
const RCMag* rcmag_table, int limitMagIndex, StelCore* core,
int maxMagStarName, float names_brightness,
const QVector<SphericalCap>& boundingCaps,
const bool withAberration, const Vec3d vel, const double withParallax, const Vec3d diffPos, const bool withCommonNameI18n) const = 0;
const bool withAberration, const Vec3d vel,
const double withParallax, const Vec3d diffPos, const bool withCommonNameI18n,
const bool filterMoon, SphericalCap moonCap) const = 0;

//! Get whether or not the catalog was successfully loaded.
//! @return @c true if at least one zone was loaded, otherwise @c false
Expand Down Expand Up @@ -187,7 +189,8 @@ class SpecialZoneArray : public ZoneArray
const RCMag *rcmag_table, int limitMagIndex, StelCore* core,
int maxMagStarName, float names_brightness,
const QVector<SphericalCap>& boundingCaps,
const bool withAberration, const Vec3d vel, const double withParallax, const Vec3d diffPos, const bool withCommonNameI18n) const override;
const bool withAberration, const Vec3d vel, const double withParallax, const Vec3d diffPos, const bool withCommonNameI18n,
const bool filterMoon, SphericalCap moonCap) const override;

void searchAround(const StelCore* core, int index, const Vec3d &v, const double withParallax,
const Vec3d diffPos, double cosLimFov, QList<StelObjectP > &result) override;
Expand Down
Loading