Merge lp:~guillaume-chereau/stellarium/nomenclature-optimization into lp:stellarium

Proposed by Alexander Wolf
Status: Merged
Merged at revision: 9942
Proposed branch: lp:~guillaume-chereau/stellarium/nomenclature-optimization
Merge into: lp:stellarium
Diff against target: 267 lines (+85/-43) (has conflicts)
4 files modified
src/core/modules/NomenclatureItem.cpp (+46/-25)
src/core/modules/NomenclatureItem.hpp (+6/-4)
src/core/modules/NomenclatureMgr.cpp (+31/-12)
src/core/modules/NomenclatureMgr.hpp (+2/-2)
Text conflict in src/core/modules/NomenclatureItem.cpp
Text conflict in src/core/modules/NomenclatureItem.hpp
To merge this branch: bzr merge lp:~guillaume-chereau/stellarium/nomenclature-optimization
Reviewer Review Type Date Requested Status
Alexander Wolf Approve
gzotti Approve
Review via email: mp+333183@code.launchpad.net
To post a comment you must log in.
Revision history for this message
gzotti (georg-zotti) wrote :

Sorry, I may have caused the merge conflict. The long/lat->Vec3d XYZpc computation is done in the constructor, and a rotation matrix added to the position computation, should be easy to fix, but I cannot commit to that branch. Apart from that, this makes things better and solves an ugly bug, so I approve.

review: Approve
Revision history for this message
Alexander Wolf (alexwolf) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/modules/NomenclatureItem.cpp'
2--- src/core/modules/NomenclatureItem.cpp 2017-10-31 13:14:51 +0000
3+++ src/core/modules/NomenclatureItem.cpp 2017-11-03 04:14:28 +0000
4@@ -40,8 +40,7 @@
5 float nLatitude,
6 float nLongitude,
7 float nSize)
8- : initialized(false)
9- , XYZ(0.0)
10+ : XYZ(0.0)
11 , planet(nPlanet)
12 , identificator(nId)
13 , englishName(nName)
14@@ -52,8 +51,11 @@
15 , longitude(nLongitude)
16 , size(nSize)
17 {
18+<<<<<<< TREE
19 StelUtils::spheToRect((longitude /*+ planet->getAxisRotation()*/) * M_PI/180.0, latitude * M_PI/180.0, XYZpc);
20 initialized = true;
21+=======
22+>>>>>>> MERGE-SOURCE
23 }
24
25 NomenclatureItem::~NomenclatureItem()
26@@ -808,35 +810,24 @@
27 return color;
28 }
29
30-float NomenclatureItem::getVMagnitude(const StelCore* core) const
31-{
32- Q_UNUSED(core);
33- return 99.f;
34-}
35-
36-double NomenclatureItem::getAngularSize(const StelCore* core) const
37-{
38- return std::atan2(size*planet->getSphereScale()/AU, getJ2000EquatorialPos(core).length()) * 180./M_PI;
39-}
40-
41-void NomenclatureItem::update(double deltaTime)
42-{
43- labelsFader.update((int)(deltaTime*1000));
44-}
45-
46-void NomenclatureItem::draw(StelCore* core, StelPainter *painter)
47-{
48- if (!getFlagLabels())
49- return;
50-
51+Vec3d NomenclatureItem::getJ2000EquatorialPos(const StelCore* core) const
52+{
53+ if (jde == core->getJDE()) return XYZ;
54+ jde = core->getJDE();
55 const Vec3d equPos = planet->getJ2000EquatorialPos(core);
56-
57 // Calculate the radius of the planet. It is necessary to re-scale it
58 const double r = planet->getRadius() * planet->getSphereScale();
59+<<<<<<< TREE
60
61 Vec3d XYZ0;
62 // // For now, assume spherical planets, simply scale by radius.
63 XYZ0 = XYZpc*r;
64+=======
65+ Vec3d XYZ0; // XYZ is member variable with equatorial J2000.0 coordinates
66+ StelUtils::spheToRect((longitude + planet->getAxisRotation()) * M_PI/180.0, latitude * M_PI/180.0, XYZ0);
67+ // For now, assume spherical planets, simply scale by radius.
68+ XYZ0 *= r;
69+>>>>>>> MERGE-SOURCE
70 // TODO1: handle ellipsoid bodies
71 // TODO2: intersect properly with OBJ bodies! (LP:1723742)
72
73@@ -844,8 +835,38 @@
74 Feature's original coordinates are in planetocentric system, so we have to multiply it by the rotation matrix.
75 planet->getRotEquatorialToVsop87() gives us the rotation matrix between Equatorial (on date) coordinates and Ecliptic J2000 coordinates.
76 So we have to make another change to obtain the rotation matrix using Equatorial J2000: we have to multiplay by core->matVsop87ToJ2000 */
77+<<<<<<< TREE
78 // TODO: Maybe it is more efficient to add some getRotEquatorialToVsop87Zrotation() to the Planet class which returns a Mat4d computed in Planet::computeTransMatrix().
79 XYZ = equPos + (core->matVsop87ToJ2000 * planet->getRotEquatorialToVsop87()) * Mat4d::zrotation(planet->getAxisRotation()* M_PI/180.0) * XYZ0;
80+=======
81+ XYZ = equPos + (core->matVsop87ToJ2000 * planet->getRotEquatorialToVsop87()) * XYZ0;
82+ return XYZ;
83+}
84+
85+float NomenclatureItem::getVMagnitude(const StelCore* core) const
86+{
87+ Q_UNUSED(core);
88+ return 99.f;
89+}
90+
91+double NomenclatureItem::getAngularSize(const StelCore* core) const
92+{
93+ return std::atan2(size*planet->getSphereScale()/AU, getJ2000EquatorialPos(core).length()) * 180./M_PI;
94+}
95+
96+void NomenclatureItem::update(double deltaTime)
97+{
98+ labelsFader.update((int)(deltaTime*1000));
99+}
100+
101+void NomenclatureItem::draw(StelCore* core, StelPainter *painter)
102+{
103+ if (!getFlagLabels())
104+ return;
105+
106+ const Vec3d equPos = planet->getJ2000EquatorialPos(core);
107+ Vec3d XYZ = getJ2000EquatorialPos(core);
108+>>>>>>> MERGE-SOURCE
109 // 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...
110 if (XYZ.lengthSquared() < 150.*150.*AU_KM*AU_KM )
111 return;
112@@ -865,7 +886,7 @@
113
114 // check visibility of feature
115 Vec3d srcPos;
116- if (painter->getProjector()->projectCheck(XYZ, srcPos) && (equPos.length() >= XYZ.length()) && (planet->getVMagnitude(core)<20.) && (screenSize>50. && screenSize<750.))
117+ if (painter->getProjector()->projectCheck(XYZ, srcPos) && (equPos.length() >= XYZ.length()) && (screenSize>50. && screenSize<750.))
118 {
119 painter->setColor(color[0], color[1], color[2], 1.0);
120 painter->drawCircle(srcPos[0], srcPos[1], 2.f);
121
122=== modified file 'src/core/modules/NomenclatureItem.hpp'
123--- src/core/modules/NomenclatureItem.hpp 2017-10-30 23:02:25 +0000
124+++ src/core/modules/NomenclatureItem.hpp 2017-11-03 04:14:28 +0000
125@@ -125,10 +125,7 @@
126 //! @flags a set of flags with information types to include.
127 virtual QString getInfoString(const StelCore* core, const InfoStringGroup& flags) const;
128 virtual Vec3f getInfoColor(void) const;
129- virtual Vec3d getJ2000EquatorialPos(const StelCore*) const
130- {
131- return XYZ;
132- }
133+ virtual Vec3d getJ2000EquatorialPos(const StelCore*) const;
134 //! Get the visual magnitude of a nomenclature item. Dummy method, returns 99.
135 virtual float getVMagnitude(const StelCore* core) const;
136 //! Get the angular size of nomenclature item.
137@@ -160,9 +157,14 @@
138 float getLongitude(void) const {return longitude;}
139
140 private:
141+<<<<<<< TREE
142 bool initialized;
143 Vec3d XYZpc; // holds planetocentric position (from longitude/latitude)
144 Vec3d XYZ; // holds J2000 position
145+=======
146+ mutable Vec3d XYZ; // holds J2000 position
147+ mutable double jde; // jde time of XYZ value
148+>>>>>>> MERGE-SOURCE
149 static Vec3f color;
150 static bool hideLocalNomenclature;
151
152
153=== modified file 'src/core/modules/NomenclatureMgr.cpp'
154--- src/core/modules/NomenclatureMgr.cpp 2017-10-29 07:28:02 +0000
155+++ src/core/modules/NomenclatureMgr.cpp 2017-11-03 04:14:28 +0000
156@@ -355,7 +355,7 @@
157 {
158 NomenclatureItemP nom = NomenclatureItemP(new NomenclatureItem(p, featureId, name, context, ntype, latitude, longitude, size));
159 if (!nom.isNull())
160- nomenclatureItems.append(nom);
161+ nomenclatureItems.insert(p, nom);
162
163 readOk++;
164 }
165@@ -379,11 +379,29 @@
166 StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
167 StelPainter painter(prj);
168 painter.setFont(font);
169+ const SphericalCap& viewportRegion = painter.getProjector()->getBoundingCap();
170
171- foreach (const NomenclatureItemP& nItem, nomenclatureItems)
172+ foreach(PlanetP p, nomenclatureItems.uniqueKeys())
173 {
174- if (nItem && nItem->initialized)
175- nItem->draw(core, &painter);
176+ // Early exit if the planet is not visible or too small to render the
177+ // labels.
178+ const Vec3d equPos = p->getJ2000EquatorialPos(core);
179+ const double r = p->getRadius() * p->getSphereScale();
180+ double angularSize = atan2(r, equPos.length());
181+ double screenSize = angularSize * painter.getProjector()->getPixelPerRadAtCenter();
182+ if (screenSize < 50) continue;
183+ Vec3d n = equPos; n.normalize();
184+ SphericalCap boundingCap(n, cos(angularSize));
185+ if (!viewportRegion.intersects(boundingCap)) continue;
186+ if (p->getVMagnitude(core) >= 20.) continue;
187+
188+ // Render all the items of this planet.
189+ for (auto i = nomenclatureItems.find(p); i != nomenclatureItems.end() && i.key() == p; ++i)
190+ {
191+ const NomenclatureItemP& nItem = i.value();
192+ if (nItem)
193+ nItem->draw(core, &painter);
194+ }
195 }
196
197 if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
198@@ -412,7 +430,7 @@
199 }
200 }
201
202-QList<StelObjectP> NomenclatureMgr::searchAround(const Vec3d& av, double limitFov, const StelCore*) const
203+QList<StelObjectP> NomenclatureMgr::searchAround(const Vec3d& av, double limitFov, const StelCore* core) const
204 {
205 QList<StelObjectP> result;
206
207@@ -423,14 +441,11 @@
208
209 foreach(const NomenclatureItemP& nItem, nomenclatureItems)
210 {
211- if (nItem->initialized && nItem->XYZ.lengthSquared() > 0)
212+ equPos = nItem->getJ2000EquatorialPos(core);
213+ equPos.normalize();
214+ if (equPos[0]*v[0] + equPos[1]*v[1] + equPos[2]*v[2]>=cosLimFov)
215 {
216- equPos = nItem->XYZ;
217- equPos.normalize();
218- if (equPos[0]*v[0] + equPos[1]*v[1] + equPos[2]*v[2]>=cosLimFov)
219- {
220- result.append(qSharedPointerCast<StelObject>(nItem));
221- }
222+ result.append(qSharedPointerCast<StelObject>(nItem));
223 }
224 }
225
226@@ -445,7 +460,9 @@
227 foreach(const NomenclatureItemP& nItem, nomenclatureItems)
228 {
229 if (nItem->getNomenclatureType()!=NomenclatureItem::niSatelliteFeature && nItem->getEnglishName().toUpper() == englishName.toUpper())
230+ {
231 return qSharedPointerCast<StelObject>(nItem);
232+ }
233 }
234 }
235
236@@ -459,7 +476,9 @@
237 foreach(const NomenclatureItemP& nItem, nomenclatureItems)
238 {
239 if (nItem->getNomenclatureType()!=NomenclatureItem::niSatelliteFeature && nItem->getNameI18n().toUpper() == nameI18n.toUpper())
240+ {
241 return qSharedPointerCast<StelObject>(nItem);
242+ }
243 }
244 }
245
246
247=== modified file 'src/core/modules/NomenclatureMgr.hpp'
248--- src/core/modules/NomenclatureMgr.hpp 2017-10-21 18:57:30 +0000
249+++ src/core/modules/NomenclatureMgr.hpp 2017-11-03 04:14:28 +0000
250@@ -26,7 +26,7 @@
251 #include "NomenclatureItem.hpp"
252
253 #include <QFont>
254-#include <QList>
255+#include <QMultiHash>
256
257 class StelPainter;
258 class QSettings;
259@@ -136,7 +136,7 @@
260 QFont font;
261 QSettings* conf;
262 StelTextureSP texPointer;
263- QList<NomenclatureItemP> nomenclatureItems;
264+ QMultiHash<PlanetP, NomenclatureItemP> nomenclatureItems;
265 };
266
267 #endif /*_NOMENCLATUREMGR_HPP_*/