Skip to content

Commit

Permalink
merged guillaume-chereau/stellarium/nomenclature-optimization. Nomenc…
Browse files Browse the repository at this point in the history
…lature: cache item positions
  • Loading branch information
guillaumechereau authored and gzotti committed Nov 4, 2017
2 parents b90b9af + 6053cb5 commit 8860143
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 39 deletions.
45 changes: 26 additions & 19 deletions src/core/modules/NomenclatureItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ NomenclatureItem::NomenclatureItem(PlanetP nPlanet,
float nLatitude,
float nLongitude,
float nSize)
: initialized(false)
, XYZ(0.0)
: XYZ(0.0)
, planet(nPlanet)
, identificator(nId)
, englishName(nName)
Expand All @@ -53,7 +52,6 @@ NomenclatureItem::NomenclatureItem(PlanetP nPlanet,
, size(nSize)
{
StelUtils::spheToRect((longitude /*+ planet->getAxisRotation()*/) * M_PI/180.0, latitude * M_PI/180.0, XYZpc);
initialized = true;
}

NomenclatureItem::~NomenclatureItem()
Expand Down Expand Up @@ -808,6 +806,29 @@ Vec3f NomenclatureItem::getInfoColor(void) const
return color;
}

Vec3d NomenclatureItem::getJ2000EquatorialPos(const StelCore* core) const
{
if (jde == core->getJDE()) return XYZ;
jde = core->getJDE();
const Vec3d equPos = planet->getJ2000EquatorialPos(core);
// Calculate the radius of the planet. It is necessary to re-scale it
const double r = planet->getRadius() * planet->getSphereScale();

Vec3d XYZ0;
// // For now, assume spherical planets, simply scale by radius.
XYZ0 = XYZpc*r;
// TODO1: handle ellipsoid bodies
// TODO2: intersect properly with OBJ bodies! (LP:1723742)

/* We have to calculate feature's coordinates in VSOP87 (this is Ecliptic J2000 coordinates).
Feature's original coordinates are in planetocentric system, so we have to multiply it by the rotation matrix.
planet->getRotEquatorialToVsop87() gives us the rotation matrix between Equatorial (on date) coordinates and Ecliptic J2000 coordinates.
So we have to make another change to obtain the rotation matrix using Equatorial J2000: we have to multiplay by core->matVsop87ToJ2000 */
// TODO: Maybe it is more efficient to add some getRotEquatorialToVsop87Zrotation() to the Planet class which returns a Mat4d computed in Planet::computeTransMatrix().
XYZ = equPos + (core->matVsop87ToJ2000 * planet->getRotEquatorialToVsop87()) * Mat4d::zrotation(planet->getAxisRotation()* M_PI/180.0) * XYZ0;
return XYZ;
}

float NomenclatureItem::getVMagnitude(const StelCore* core) const
{
Q_UNUSED(core);
Expand All @@ -830,22 +851,8 @@ void NomenclatureItem::draw(StelCore* core, StelPainter *painter)
return;

const Vec3d equPos = planet->getJ2000EquatorialPos(core);
Vec3d XYZ = getJ2000EquatorialPos(core);

// Calculate the radius of the planet. It is necessary to re-scale it
const double r = planet->getRadius() * planet->getSphereScale();

Vec3d XYZ0;
// // For now, assume spherical planets, simply scale by radius.
XYZ0 = XYZpc*r;
// TODO1: handle ellipsoid bodies
// TODO2: intersect properly with OBJ bodies! (LP:1723742)

/* We have to calculate feature's coordinates in VSOP87 (this is Ecliptic J2000 coordinates).
Feature's original coordinates are in planetocentric system, so we have to multiply it by the rotation matrix.
planet->getRotEquatorialToVsop87() gives us the rotation matrix between Equatorial (on date) coordinates and Ecliptic J2000 coordinates.
So we have to make another change to obtain the rotation matrix using Equatorial J2000: we have to multiplay by core->matVsop87ToJ2000 */
// TODO: Maybe it is more efficient to add some getRotEquatorialToVsop87Zrotation() to the Planet class which returns a Mat4d computed in Planet::computeTransMatrix().
XYZ = equPos + (core->matVsop87ToJ2000 * planet->getRotEquatorialToVsop87()) * Mat4d::zrotation(planet->getAxisRotation()* M_PI/180.0) * XYZ0;
// In case we are located at a labeled site, don't show this label or any labels within 150 km. Else we have bad flicker...
if (XYZ.lengthSquared() < 150.*150.*AU_KM*AU_KM )
return;
Expand All @@ -865,7 +872,7 @@ void NomenclatureItem::draw(StelCore* core, StelPainter *painter)

// check visibility of feature
Vec3d srcPos;
if (painter->getProjector()->projectCheck(XYZ, srcPos) && (equPos.length() >= XYZ.length()) && (planet->getVMagnitude(core)<20.) && (screenSize>50. && screenSize<750.))
if (painter->getProjector()->projectCheck(XYZ, srcPos) && (equPos.length() >= XYZ.length()) && (screenSize>50. && screenSize<750.))
{
painter->setColor(color[0], color[1], color[2], 1.0);
painter->drawCircle(srcPos[0], srcPos[1], 2.f);
Expand Down
9 changes: 3 additions & 6 deletions src/core/modules/NomenclatureItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ class NomenclatureItem : public StelObject
//! @flags a set of flags with information types to include.
virtual QString getInfoString(const StelCore* core, const InfoStringGroup& flags) const;
virtual Vec3f getInfoColor(void) const;
virtual Vec3d getJ2000EquatorialPos(const StelCore*) const
{
return XYZ;
}
virtual Vec3d getJ2000EquatorialPos(const StelCore*) const;
//! Get the visual magnitude of a nomenclature item. Dummy method, returns 99.
virtual float getVMagnitude(const StelCore* core) const;
//! Get the angular size of nomenclature item.
Expand Down Expand Up @@ -160,9 +157,9 @@ class NomenclatureItem : public StelObject
float getLongitude(void) const {return longitude;}

private:
bool initialized;
Vec3d XYZpc; // holds planetocentric position (from longitude/latitude)
Vec3d XYZ; // holds J2000 position
mutable Vec3d XYZ; // holds J2000 position
mutable double jde; // jde time of XYZ value
static Vec3f color;
static bool hideLocalNomenclature;

Expand Down
43 changes: 31 additions & 12 deletions src/core/modules/NomenclatureMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void NomenclatureMgr::loadNomenclature()
{
NomenclatureItemP nom = NomenclatureItemP(new NomenclatureItem(p, featureId, name, context, ntype, latitude, longitude, size));
if (!nom.isNull())
nomenclatureItems.append(nom);
nomenclatureItems.insert(p, nom);

readOk++;
}
Expand All @@ -379,11 +379,29 @@ void NomenclatureMgr::draw(StelCore* core)
StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
StelPainter painter(prj);
painter.setFont(font);
const SphericalCap& viewportRegion = painter.getProjector()->getBoundingCap();

foreach (const NomenclatureItemP& nItem, nomenclatureItems)
foreach(PlanetP p, nomenclatureItems.uniqueKeys())
{
if (nItem && nItem->initialized)
nItem->draw(core, &painter);
// Early exit if the planet is not visible or too small to render the
// labels.
const Vec3d equPos = p->getJ2000EquatorialPos(core);
const double r = p->getRadius() * p->getSphereScale();
double angularSize = atan2(r, equPos.length());
double screenSize = angularSize * painter.getProjector()->getPixelPerRadAtCenter();
if (screenSize < 50) continue;
Vec3d n = equPos; n.normalize();
SphericalCap boundingCap(n, cos(angularSize));
if (!viewportRegion.intersects(boundingCap)) continue;
if (p->getVMagnitude(core) >= 20.) continue;

// Render all the items of this planet.
for (auto i = nomenclatureItems.find(p); i != nomenclatureItems.end() && i.key() == p; ++i)
{
const NomenclatureItemP& nItem = i.value();
if (nItem)
nItem->draw(core, &painter);
}
}

if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
Expand Down Expand Up @@ -412,7 +430,7 @@ void NomenclatureMgr::drawPointer(StelCore* core, StelPainter& painter)
}
}

QList<StelObjectP> NomenclatureMgr::searchAround(const Vec3d& av, double limitFov, const StelCore*) const
QList<StelObjectP> NomenclatureMgr::searchAround(const Vec3d& av, double limitFov, const StelCore* core) const
{
QList<StelObjectP> result;

Expand All @@ -423,14 +441,11 @@ QList<StelObjectP> NomenclatureMgr::searchAround(const Vec3d& av, double limitFo

foreach(const NomenclatureItemP& nItem, nomenclatureItems)
{
if (nItem->initialized && nItem->XYZ.lengthSquared() > 0)
equPos = nItem->getJ2000EquatorialPos(core);
equPos.normalize();
if (equPos[0]*v[0] + equPos[1]*v[1] + equPos[2]*v[2]>=cosLimFov)
{
equPos = nItem->XYZ;
equPos.normalize();
if (equPos[0]*v[0] + equPos[1]*v[1] + equPos[2]*v[2]>=cosLimFov)
{
result.append(qSharedPointerCast<StelObject>(nItem));
}
result.append(qSharedPointerCast<StelObject>(nItem));
}
}

Expand All @@ -445,7 +460,9 @@ StelObjectP NomenclatureMgr::searchByName(const QString& englishName) const
foreach(const NomenclatureItemP& nItem, nomenclatureItems)
{
if (nItem->getNomenclatureType()!=NomenclatureItem::niSatelliteFeature && nItem->getEnglishName().toUpper() == englishName.toUpper())
{
return qSharedPointerCast<StelObject>(nItem);
}
}
}

Expand All @@ -459,7 +476,9 @@ StelObjectP NomenclatureMgr::searchByNameI18n(const QString& nameI18n) const
foreach(const NomenclatureItemP& nItem, nomenclatureItems)
{
if (nItem->getNomenclatureType()!=NomenclatureItem::niSatelliteFeature && nItem->getNameI18n().toUpper() == nameI18n.toUpper())
{
return qSharedPointerCast<StelObject>(nItem);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/modules/NomenclatureMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "NomenclatureItem.hpp"

#include <QFont>
#include <QList>
#include <QMultiHash>

class StelPainter;
class QSettings;
Expand Down Expand Up @@ -136,7 +136,7 @@ public slots:
QFont font;
QSettings* conf;
StelTextureSP texPointer;
QList<NomenclatureItemP> nomenclatureItems;
QMultiHash<PlanetP, NomenclatureItemP> nomenclatureItems;
};

#endif /*_NOMENCLATUREMGR_HPP_*/

0 comments on commit 8860143

Please sign in to comment.