Skip to content

Commit

Permalink
Nomenclature: cache the item positions
Browse files Browse the repository at this point in the history
This actually simplify the code, because we don't have to check if the
XYZ value has been computed, instead we can just call
getJ2000EquatorialPos.
  • Loading branch information
guillaumechereau committed Oct 31, 2017
1 parent af2be46 commit 6053cb5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
43 changes: 24 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 @@ -52,7 +51,6 @@ NomenclatureItem::NomenclatureItem(PlanetP nPlanet,
, longitude(nLongitude)
, size(nSize)
{
initialized = true;
}

NomenclatureItem::~NomenclatureItem()
Expand Down Expand Up @@ -806,6 +804,28 @@ 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; // XYZ is member variable with equatorial J2000.0 coordinates
StelUtils::spheToRect((longitude + planet->getAxisRotation()) * M_PI/180.0, latitude * M_PI/180.0, XYZ0);
// For now, assume spherical planets, simply scale by radius.
XYZ0 *= 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 */
XYZ = equPos + (core->matVsop87ToJ2000 * planet->getRotEquatorialToVsop87()) * XYZ0;
return XYZ;
}

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

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; // XYZ is member variable with equatorial J2000.0 coordinates
StelUtils::spheToRect((longitude + planet->getAxisRotation()) * M_PI/180.0, latitude * M_PI/180.0, XYZ0);
// For now, assume spherical planets, simply scale by radius.
XYZ0 *= 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 */
XYZ = equPos + (core->matVsop87ToJ2000 * planet->getRotEquatorialToVsop87()) * XYZ0;
Vec3d XYZ = getJ2000EquatorialPos(core);
// 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 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,8 +157,8 @@ class NomenclatureItem : public StelObject
float getLongitude(void) const {return longitude;}

private:
bool initialized;
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
19 changes: 8 additions & 11 deletions src/core/modules/NomenclatureMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void NomenclatureMgr::draw(StelCore* core)
for (auto i = nomenclatureItems.find(p); i != nomenclatureItems.end() && i.key() == p; ++i)
{
const NomenclatureItemP& nItem = i.value();
if (nItem && nItem->initialized)
if (nItem)
nItem->draw(core, &painter);
}
}
Expand Down Expand Up @@ -430,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 @@ -441,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 @@ -462,7 +459,7 @@ StelObjectP NomenclatureMgr::searchByName(const QString& englishName) const
{
foreach(const NomenclatureItemP& nItem, nomenclatureItems)
{
if (nItem->initialized && nItem->XYZ.lengthSquared() > 0 && nItem->getNomenclatureType()!=NomenclatureItem::niSatelliteFeature && nItem->getEnglishName().toUpper() == englishName.toUpper())
if (nItem->getNomenclatureType()!=NomenclatureItem::niSatelliteFeature && nItem->getEnglishName().toUpper() == englishName.toUpper())
{
return qSharedPointerCast<StelObject>(nItem);
}
Expand All @@ -478,7 +475,7 @@ StelObjectP NomenclatureMgr::searchByNameI18n(const QString& nameI18n) const
{
foreach(const NomenclatureItemP& nItem, nomenclatureItems)
{
if (nItem->initialized && nItem->XYZ.lengthSquared() > 0 && nItem->getNomenclatureType()!=NomenclatureItem::niSatelliteFeature && nItem->getNameI18n().toUpper() == nameI18n.toUpper())
if (nItem->getNomenclatureType()!=NomenclatureItem::niSatelliteFeature && nItem->getNameI18n().toUpper() == nameI18n.toUpper())
{
return qSharedPointerCast<StelObject>(nItem);
}
Expand Down

0 comments on commit 6053cb5

Please sign in to comment.