Skip to content

Commit

Permalink
Speedup for NomenclatureItems
Browse files Browse the repository at this point in the history
- found big waste of time in profiler
  • Loading branch information
gzotti committed Aug 30, 2024
1 parent 4a134b3 commit 76b128a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/core/modules/NomenclatureItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ QString NomenclatureItem::getNomenclatureTypeLatinString(NomenclatureItemType nT
return map.value(nType, "");
}

QString NomenclatureItem::getNomenclatureTypeDescription(NomenclatureItemType nType, QString englishName)
QString NomenclatureItem::getNomenclatureTypeDescription(NomenclatureItemType nType, const QString &englishName)
{
Q_ASSERT(niTypeDescriptionMap.size()>20); // should be filled, not sure how many.
QString ret=niTypeDescriptionMap.value(nType, q_("Undocumented landform type."));
Expand Down Expand Up @@ -175,7 +175,7 @@ float NomenclatureItem::getSelectPriority(const StelCore* core) const
// so that clicking on the planet in halo does not select any feature point.
float priority=planet->getSelectPriority(core)+5.f;
// check visibility of feature
const float scale = getAngularDiameterRatio(core);
const float scale = getAngularDiameterRatio(core, core->getProjection(StelCore::FrameJ2000)->getFov());
const float planetScale = 2.f*static_cast<float>(planet->getAngularRadius(core))/core->getProjection(StelCore::FrameJ2000)->getFov();

// Require the planet to cover 1/10 of the screen to make it worth clicking on features.
Expand Down Expand Up @@ -359,12 +359,12 @@ double NomenclatureItem::getAngularRadius(const StelCore* core) const
return std::atan2(0.5*size*planet->getSphereScale()/AU, getJ2000EquatorialPos(core).norm()) * M_180_PI;
}

float NomenclatureItem::getAngularDiameterRatio(const StelCore *core) const
float NomenclatureItem::getAngularDiameterRatio(const StelCore *core, const float fov) const
{
return static_cast<float>(2.*getAngularRadius(core))/core->getProjection(StelCore::FrameJ2000)->getFov();
return static_cast<float>(2.*getAngularRadius(core))/fov;
}

void NomenclatureItem::draw(StelCore* core, StelPainter *painter)
void NomenclatureItem::draw(StelCore* core, StelPainter *painter, const float fov) const
{
// show special points only?
if (getFlagShowSpecialNomenclatureOnly() && nType<NomenclatureItem::niSpecialPointPole)
Expand All @@ -390,7 +390,7 @@ void NomenclatureItem::draw(StelCore* core, StelPainter *painter)

// check visibility of feature
Vec3d srcPos;
const float scale = getAngularDiameterRatio(core);
const float scale = getAngularDiameterRatio(core, fov);

if (painter->getProjector()->projectCheck(XYZ, srcPos) && (equPos.normSquared() >= XYZ.normSquared())
&& (scale>0.04f && (scale<0.5f || nType>=NomenclatureItem::niSpecialPointPole )))
Expand Down Expand Up @@ -451,7 +451,7 @@ double NomenclatureItem::getSolarAltitude(const StelCore *core) const
return h*M_180_PI;
}

NomenclatureItem::NomenclatureItemType NomenclatureItem::getNomenclatureItemType(const QString abbrev)
NomenclatureItem::NomenclatureItemType NomenclatureItem::getNomenclatureItemType(const QString &abbrev)
{
// codes for types of features (details: https://planetarynames.wr.usgs.gov/DescriptorTerms)
static const QMap<QString, NomenclatureItem::NomenclatureItemType> niTypes = {
Expand Down Expand Up @@ -516,7 +516,7 @@ NomenclatureItem::NomenclatureItemType NomenclatureItem::getNomenclatureItemType
}
QMap<NomenclatureItem::NomenclatureItemType, QString> NomenclatureItem::niTypeStringMap;
QMap<NomenclatureItem::NomenclatureItemType, QString> NomenclatureItem::niTypeDescriptionMap;
NomenclatureItem::PlanetCoordinateOrientation NomenclatureItem::getPlanetCoordinateOrientation(QString planetName)
NomenclatureItem::PlanetCoordinateOrientation NomenclatureItem::getPlanetCoordinateOrientation(const QString &planetName)
{
// data from https://planetarynames.wr.usgs.gov/TargetCoordinates.
// Commented away where they are equal to te default value.
Expand Down
10 changes: 5 additions & 5 deletions src/core/modules/NomenclatureItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class NomenclatureItem : public StelObject
//! * -1000. is used as "invalid" value. The result should then not be used.
Vec4d getRTSTime(const StelCore* core, const double altitude=0.) const override;

void draw(StelCore* core, StelPainter *painter);
void draw(StelCore* core, StelPainter *painter, const float fov) const;
NomenclatureItemType getNomenclatureType() const { return nType;}

static void setFlagLabels(bool b){ labelsFader = b; }
Expand All @@ -203,7 +203,7 @@ class NomenclatureItem : public StelObject

protected:
//! returns a type enum for a given 2-letter code
static NomenclatureItemType getNomenclatureItemType(const QString abbrev);
static NomenclatureItemType getNomenclatureItemType(const QString &abbrev);
//! Should be triggered once at start and then whenever program language setting changes.
static void createNameLists();

Expand All @@ -220,14 +220,14 @@ class NomenclatureItem : public StelObject
static bool showSpecialNomenclatureOnly;

// ratio of angular size of feature to the FOV
float getAngularDiameterRatio(const StelCore *core) const;
float getAngularDiameterRatio(const StelCore *core, const float fov) const;

static QString getNomenclatureTypeLatinString(NomenclatureItemType nType);
static QString getNomenclatureTypeString(NomenclatureItemType nType);
static QString getNomenclatureTypeDescription(NomenclatureItemType nType, QString englishName);
static QString getNomenclatureTypeDescription(NomenclatureItemType nType, const QString &englishName);
//! Returns the description of the feature coordinates where available, or pcoPlanetographicWest360.
//! The default value ensures valid central meridian data for the gas giants.
static PlanetCoordinateOrientation getPlanetCoordinateOrientation(QString planetName);
static PlanetCoordinateOrientation getPlanetCoordinateOrientation(const QString &planetName);
PlanetCoordinateOrientation getPlanetCoordinateOrientation() const;
//! return whether counting sense of the coordinates is positive towards the east
static bool isEastPositive(PlanetCoordinateOrientation pco);
Expand Down
3 changes: 2 additions & 1 deletion src/core/modules/NomenclatureMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ void NomenclatureMgr::draw(StelCore* core)

painter.setFont(font);
const SphericalCap& viewportRegion = painter.getProjector()->getBoundingCap();
const float fov=core->getProjection(StelCore::FrameJ2000)->getFov();

for (const auto& p : nomenclatureItems.uniqueKeys())
{
Expand All @@ -313,7 +314,7 @@ void NomenclatureMgr::draw(StelCore* core)
{
const NomenclatureItemP& nItem = i.value();
if (nItem)
nItem->draw(core, &painter);
nItem->draw(core, &painter, fov);
}
}
// avoid further forcing
Expand Down

0 comments on commit 76b128a

Please sign in to comment.