• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 10124913218

27 Jul 2024 04:27PM UTC coverage: 12.208%. First build
10124913218

Pull #3794

github

gzotti
Reduced to max.4 additional threads
Pull Request #3794: Parallelize ephemeris computation with C++ parallelism.

208 of 369 new or added lines in 24 files covered. (56.37%)

14439 of 118271 relevant lines covered (12.21%)

19314.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.91
/src/core/modules/Comet.cpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2010 Bogdan Marinov
4
 * Copyright (C) 2014 Georg Zotti (Tails)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
19
 */
20
 
21
#include "Comet.hpp"
22
#include "Orbit.hpp"
23

24
#include "StelApp.hpp"
25
#include "StelCore.hpp"
26
#include "StelPainter.hpp"
27

28
#include "StelTexture.hpp"
29
#include "StelToneReproducer.hpp"
30
#include "StelTranslator.hpp"
31
#include "StelUtils.hpp"
32
#include "StelMovementMgr.hpp"
33
#include "StelModuleMgr.hpp"
34
#include "LandscapeMgr.hpp"
35
#include "StelLocaleMgr.hpp"
36

37
#include <QDebug>
38
#include <QElapsedTimer>
39

40
// for compute tail shape
41
#define COMET_TAIL_SLICES 16u // segments around the perimeter
42
#define COMET_TAIL_STACKS 16u // cuts along the rotational axis
43

44
// These are to avoid having index arrays for each comet when all are equal.
45
bool Comet::createTailIndices=true;
46
bool Comet::createTailTextureCoords=true;
47
StelTextureSP Comet::comaTexture;
48
StelTextureSP Comet::tailTexture;
49
QVector<Vec2f> Comet::tailTexCoordArr; // computed only once for all Comets.
50
QVector<unsigned short> Comet::tailIndices; // computed only once for all Comets.
51

52
Comet::Comet(const QString& englishName,
×
53
             double radius,
54
             double oblateness,
55
             Vec3f halocolor,
56
             float albedo,
57
             float roughness,
58
             float outgas_intensity,
59
             float outgas_falloff,
60
             const QString& atexMapName,
61
             const QString& aobjModelName,
62
             posFuncType coordFunc,
63
             KeplerOrbit* orbitPtr,
64
             OsculatingFunctType *osculatingFunc,
65
             bool acloseOrbit,
66
             bool hidden,
67
             const QString& pTypeStr,
68
             float dustTailWidthFact,
69
             float dustTailLengthFact,
70
             float dustTailBrightnessFact)
×
71
        : Planet (englishName,
72
                  radius,
73
                  oblateness,
74
                  halocolor,
75
                  albedo,
76
                  roughness,
77
                  atexMapName,
78
                  "", // no normalmap.
79
                  "", // no horizon map
80
                  aobjModelName,
81
                  coordFunc,
82
                  orbitPtr,
83
                  osculatingFunc,
84
                  acloseOrbit,
85
                  hidden,
86
                  false, //No atmosphere
87
                  true, //halo
88
                  pTypeStr),
89
          slopeParameter(-10.f), // -10 == uninitialized: used in getVMagnitude()
×
90
          isCometFragment(false),
×
91
          iauDesignation(""),
×
92
          extraDesignations(),
×
93
          extraDesignationsHtml(),
×
94
          discoverer(""),
×
95
          discoveryDate(""),
×
96
          tailFactors(-1., -1.), // mark "invalid"
×
97
          tailActive(false),
×
98
          tailBright(false),
×
99
          deltaJDEtail(15.0*StelCore::JD_MINUTE), // update tail geometry every 15 minutes only
×
100
          lastJDEtail(0.0),
×
101
          dustTailWidthFactor(dustTailWidthFact),
×
102
          dustTailLengthFactor(dustTailLengthFact),
×
103
          dustTailBrightnessFactor(dustTailBrightnessFact),
×
104
          intensityFovScale(1.0f),
×
105
          intensityMinFov(0.001f), // when zooming in further, Coma is no longer visible.
×
106
          intensityMaxFov(0.010f) // when zooming out further, Coma is fully visible (when enabled).
×
107
{
108
        this->outgas_intensity =outgas_intensity;
×
109
        this->outgas_falloff   =outgas_falloff;
×
110

111
        gastailVertexArr.clear();
×
112
        dusttailVertexArr.clear();
×
113
        comaVertexArr.clear();
×
114
        gastailColorArr.clear();
×
115
        dusttailColorArr.clear();
×
116

117
        //TODO: Name processing?
118
}
×
119

120
Comet::~Comet()
×
121
{
122
}
×
123

124
void Comet::setAbsoluteMagnitudeAndSlope(const float magnitude, const float slope)
×
125
{
126
        if ((slope < -2.5f) || (slope > 25.0f))
×
127
        {
128
                // Slope G can become slightly smaller than 0. -10 is mark of invalidity.
129
                qDebug() << "Warning: Suspect slope parameter value" << slope << "for comet" << getEnglishName() << "(rarely exceeding -1...20)";
×
130
                return;
×
131
        }
132
        absoluteMagnitude = magnitude;
×
133
        slopeParameter = slope;
×
134
}
135

136
void Comet::translateName(const StelTranslator &translator)
×
137
{
138
        static const QRegularExpression cometNamePattern("^(.+)[(](.+)[)]\\s*$");
×
139
        QRegularExpressionMatch matchCometName = cometNamePattern.match(englishName);
×
140
        if (matchCometName.hasMatch())
×
141
                nameI18 = QString("%1(%2)").arg(matchCometName.captured(1),translator.qtranslate(matchCometName.captured(2), "comet"));
×
142
        else
143
                nameI18 = translator.qtranslate(englishName, "comet");
×
144
}
×
145

146
QString Comet::getInfoStringName(const StelCore *core, const InfoStringGroup& flags) const
×
147
{
148
        Q_UNUSED(core) Q_UNUSED(flags)
149
        QString str;
×
150
        QTextStream oss(&str);
×
151

152
        oss << "<h2>";
×
153
        oss << getNameI18n(); // UI translation can differ from sky translation
×
154

155
        if (!iauDesignation.isEmpty() &&  !getNameI18n().contains(iauDesignation))
×
156
                oss << QString(" - %1").arg(iauDesignation);
×
157

158
        if (!getExtraDesignations().isEmpty())
×
159
                oss << QString(" - %1").arg(extraDesignationsHtml.join(" - "));
×
160

161
        if (sphereScale != 1.)
×
162
        {
163
                oss.setRealNumberNotation(QTextStream::FixedNotation);
×
164
                oss.setRealNumberPrecision(1);
×
165
                oss << QString::fromUtf8(" (\xC3\x97") << sphereScale << ")";
×
166
        }
167
        oss << "</h2>";
×
168

169
        return str;
×
170
}
×
171

172
QString Comet::getInfoStringAbsoluteMagnitude(const StelCore *core, const InfoStringGroup& flags) const
×
173
{
174
        Q_UNUSED(core)
175
        QString str;
×
176
        QTextStream oss(&str);
×
177
        if (flags&AbsoluteMagnitude)
×
178
        {
179
                //TODO: Make sure absolute magnitude is a sane value
180
                //If the two parameter magnitude system is not used, don't display this
181
                //value. (Using radius/albedo doesn't make any sense for comets.)
182
                // Note that slope parameter can be <0 (down to -2?), so -10 is now used for "uninitialized"
183
                if (slopeParameter >= -9.9f)
×
184
                        oss << QString("%1: %2<br/>").arg(q_("Absolute Magnitude")).arg(absoluteMagnitude, 0, 'f', 2);
×
185
        }
186

187
        return str;
×
188
}
×
189

190
QString Comet::getInfoStringSize(const StelCore *core, const InfoStringGroup &flags) const
×
191
{
192
        // TRANSLATORS: Unit of measure for distance - kilometers
193
        QString km = qc_("km", "distance");
×
194
        // TRANSLATORS: Unit of measure for distance - milliones kilometers
195
        QString Mkm = qc_("M km", "distance");
×
196
        const bool withDecimalDegree = StelApp::getInstance().getFlagShowDecimalDegrees();
×
197
        QString str;
×
198
        QTextStream oss(&str);
×
199

200
        if (flags&Size)
×
201
        {
202
                // Given the very irregular shape, other terminology like "equatorial radius" do not make much sense.
203
                oss << QString("<br/>%1: %2 %3<br/>").arg(q_("Core diameter"), QString::number(AU * 2.0 * getEquatorialRadius(), 'f', 1) , qc_("km", "distance"));
×
204
        }
205
        if ((flags&Size) && (tailFactors[0]>0.0f))
×
206
        {
207
                // GZ: Add estimates for coma diameter and tail length.
208
                QString comaEst = q_("Coma diameter (estimate)");
×
209
                const double coma = std::floor(static_cast<double>(tailFactors[0])*AU/1000.0)*1000.0;
×
210
                const double tail = static_cast<double>(tailFactors[1])*AU;
×
211
                const double distanceKm = AU * getJ2000EquatorialPos(core).norm();
×
212
                // Try to estimate tail length in degrees.
213
                // TODO: Take projection effect into account!
214
                // The estimates here assume that the tail is seen from the side.
215
                QString comaDeg, tailDeg;
×
216
                if (withDecimalDegree)
×
217
                {
218
                        comaDeg = StelUtils::radToDecDegStr(atan(coma/distanceKm),4,false,true);
×
219
                        tailDeg = StelUtils::radToDecDegStr(atan(tail/distanceKm),4,false,true);
×
220
                }
221
                else
222
                {
223
                        comaDeg = StelUtils::radToDmsStr(atan(coma/distanceKm));
×
224
                        tailDeg = StelUtils::radToDmsStr(atan(tail/distanceKm));
×
225
                }
226
                if (coma>1e6)
×
227
                        oss << QString("%1: %2 %3 (%4)<br/>").arg(comaEst, QString::number(coma*1e-6, 'G', 3), Mkm, comaDeg);
×
228
                else
229
                        oss << QString("%1: %2 %3 (%4)<br/>").arg(comaEst, QString::number(coma, 'f', 0), km, comaDeg);
×
230
                oss << QString("%1: %2 %3 (%4)<br/>").arg(q_("Gas tail length (estimate)"), QString::number(tail*1e-6, 'G', 3), Mkm, tailDeg);
×
231
        }
×
232
        return str;
×
233
}
×
234

235
// Nothing interesting?
236
QString Comet::getInfoStringExtra(const StelCore *core, const InfoStringGroup &flags) const
×
237
{
238
        Q_UNUSED(core)
239
        QString str;
×
240
        QTextStream oss(&str);
×
241
        if (flags&Extra)
×
242
        {
243
                if (!discoveryDate.isEmpty())
×
244
                        oss << QString("%1: %2<br/>").arg(q_("Discovered"), getDiscoveryCircumstances());
×
245
        }
246
        return str;
×
247
}
×
248

249
QVariantMap Comet::getInfoMap(const StelCore *core) const
×
250
{
251
        QVariantMap map = Planet::getInfoMap(core);
×
252
        map.insert("tail-length-km", tailFactors[1]*AUf);
×
253
        map.insert("coma-diameter-km", tailFactors[0]*AUf);
×
254

255
        return map;
×
256
}
×
257

258
QString Comet::getDiscoveryCircumstances() const
×
259
{
260
        QString ddate = StelUtils::localeDiscoveryDateString(discoveryDate);
×
261
        if (discoverer.isEmpty())
×
262
                return ddate;
×
263
        else
264
                return QString("%1 (%2)").arg(ddate, discoverer);
×
265
}
×
266

267
double Comet::getSiderealPeriod() const
×
268
{
269
        const double semiMajorAxis=static_cast<KeplerOrbit*>(orbitPtr)->getSemimajorAxis();
×
270
        return ((semiMajorAxis>0) ? KeplerOrbit::calculateSiderealPeriod(semiMajorAxis, 1.0) : 0.);
×
271
}
272

273
float Comet::getVMagnitude(const StelCore* core) const
×
274
{
275
        //If the two parameter system is not used,
276
        //use the default radius/albedo mechanism
277
        if (slopeParameter < -9.0f)
×
278
        {
279
                return Planet::getVMagnitude(core);
×
280
        }
281

282
        //Calculate distances
283
        const Vec3d& observerHeliocentricPosition = core->getObserverHeliocentricEclipticPos();
×
284
        const Vec3d& cometHeliocentricPosition = getHeliocentricEclipticPos();
×
285
        const float cometSunDistance = static_cast<float>(cometHeliocentricPosition.norm());
×
286
        const float observerCometDistance = static_cast<float>((observerHeliocentricPosition - cometHeliocentricPosition).norm());
×
287

288
        //Calculate apparent magnitude
289
        //Sources: http://www.clearskyinstitute.com/xephem/help/xephem.html#mozTocId564354
290
        //(XEphem manual, section 7.1.2.3 "Magnitude models"), also
291
        //http://www.ayton.id.au/gary/Science/Astronomy/Ast_comets.htm#Comet%20facts:
292
        // GZ: Note that Meeus, Astr.Alg.1998 p.231, has m=absoluteMagnitude+5log10(observerCometDistance) + kappa*log10(cometSunDistance)
293
        // with kappa typically 5..15. MPC provides Slope parameter. So we should expect to have slopeParameter (a word only used for minor planets!) for our comets 2..6
294
        return absoluteMagnitude + 5.f * std::log10(observerCometDistance) + 2.5f * slopeParameter * std::log10(cometSunDistance);
×
295
}
296

297
void Comet::update(int deltaTime)
×
298
{
299
        Planet::update(deltaTime);
×
300

301
        //calculate FOV fade value, linear fade between intensityMaxFov and intensityMinFov
302
        const float vfov = static_cast<float>(StelApp::getInstance().getCore()->getMovementMgr()->getCurrentFov());
×
303
        intensityFovScale = qBound(0.25f,(vfov - intensityMinFov) / (intensityMaxFov - intensityMinFov),1.0f);
×
304

305
        // The rest deals with updating tail geometries and brightness
306
        StelCore* core=StelApp::getInstance().getCore();
×
307
        double dateJDE=core->getJDE();
×
308

309
        if (!static_cast<KeplerOrbit*>(orbitPtr)->objectDateGoodEnoughForOrbits(dateJDE)) return; // don't do anything if out of useful date range. This allows having hundreds of comet elements.
×
310

311
        //GZ: I think we can make deltaJDtail adaptive, depending on distance to sun! For some reason though, this leads to a crash!
312
        //deltaJDtail=StelCore::JD_SECOND * qBound(1.0, eclipticPos.length(), 20.0);
313

314
        if (fabs(lastJDEtail-dateJDE)>deltaJDEtail)
×
315
        {
316
                lastJDEtail=dateJDE;
×
317

318
                if (static_cast<KeplerOrbit*>(orbitPtr)->getUpdateTails()){
×
319
                        // Compute lengths and orientations from orbit object, but only if required.
320
                        tailFactors=getComaDiameterAndTailLengthAU();
×
321

322
                        // Note that we use a diameter larger than what the formula returns. A scale factor of 1.2 is ad-hoc/empirical (GZ), but may look better.
323
                        computeComa(1.0f*tailFactors[0]); // TBD: APPARENTLY NO SCALING? REMOVE 1.0 and note above.
×
324

325
                        tailActive = (tailFactors[1] > tailFactors[0]); // Inhibit tails drawing if too short. Would be nice to include geometric projection angle, but this is too costly.
×
326

327
                        if (tailActive)
×
328
                        {
329
                                float gasTailEndRadius=qMax(tailFactors[0], 0.025f*tailFactors[1]) ; // This avoids too slim gas tails for bright comets like Hale-Bopp.
×
330
                                float gasparameter=gasTailEndRadius*gasTailEndRadius/(2.0f*tailFactors[1]); // parabola formula: z=r²/2p, so p=r²/2z
×
331
                                // The dust tail is thicker and usually shorter. The factors can be configured in the elements.
332
                                float dustparameter=gasTailEndRadius*gasTailEndRadius*dustTailWidthFactor*dustTailWidthFactor/(2.0f*dustTailLengthFactor*tailFactors[1]);
×
333

334
                                // Find valid parameters to create paraboloid vertex arrays: dustTail, gasTail.
335
                                computeParabola(gasparameter, gasTailEndRadius, -0.5f*gasparameter, gastailVertexArr,  tailTexCoordArr, tailIndices);
×
336
                                //gastailColorArr.fill(Vec3f(0.3,0.3,0.3), gastailVertexArr.length());
337
                                // Now we make a skewed parabola. Skew factor (xOffset, last arg) is rather ad-hoc/empirical. TBD later: Find physically correct solution.
338
                                computeParabola(dustparameter, dustTailWidthFactor*gasTailEndRadius, -0.5f*dustparameter, dusttailVertexArr, tailTexCoordArr, tailIndices, 25.0f*static_cast<float>(static_cast<KeplerOrbit*>(orbitPtr)->getVelocity().norm()));
×
339
                                //dusttailColorArr.fill(Vec3f(0.3,0.3,0.3), dusttailVertexArr.length());
340

341

342
                                // 2014-08 for 0.13.1 Moved from drawTail() to save lots of computation per frame (There *are* folks downloading all 730 MPC current comet elements...)
343
                                // Find rotation matrix from 0/0/1 to eclipticPosition: crossproduct for axis (normal vector), dotproduct for angle.
344
                                Vec3d eclposNrm=eclipticPos+aberrationPush; eclposNrm.normalize();
×
345
                                gasTailRot=Mat4d::rotation(Vec3d(0.0, 0.0, 1.0)^(eclposNrm), std::acos(Vec3d(0.0, 0.0, 1.0).dot(eclposNrm)) );
×
346

347
                                Vec3d velocity=static_cast<KeplerOrbit*>(orbitPtr)->getVelocity(); // [AU/d]
×
348
                                // This was a try to rotate a straight parabola somewhat away from the antisolar direction.
349
                                //Mat4d dustTailRot=Mat4d::rotation(eclposNrm^(-velocity), 0.15f*std::acos(eclposNrm.dot(-velocity))); // GZ: This scale factor of 0.15 is empirical from photos of Halley and Hale-Bopp.
350
                                // The curved tail is curved towards positive X. We first rotate around the Z axis into a direction opposite of the motion vector, then again the antisolar rotation applies.
351
                                // In addition, we let the dust tail already start with a light tilt.
352
                                dustTailRot=gasTailRot * Mat4d::zrotation(atan2(velocity[1], velocity[0]) + M_PI) * Mat4d::yrotation(5.0*velocity.norm());
×
353

354
                                // Rotate vertex arrays:
355
                                Vec3d* gasVertices= static_cast<Vec3d*>(gastailVertexArr.data());
×
356
                                Vec3d* dustVertices=static_cast<Vec3d*>(dusttailVertexArr.data());
×
357
                                for (unsigned short int i=0; i<COMET_TAIL_SLICES*COMET_TAIL_STACKS+1; ++i)
×
358
                                {
359
                                        gasVertices[i].transfo4d(gasTailRot);
×
360
                                        dustVertices[i].transfo4d(dustTailRot);
×
361
                                }
362
                        }
363
                        static_cast<KeplerOrbit*>(orbitPtr)->setUpdateTails(false); // don't update until position has been recalculated elsewhere
×
364
                }
365
        }
366

367
        // And also update magnitude and tail brightness/extinction here.
368
        const bool withAtmosphere=(core->getSkyDrawer()->getFlagHasAtmosphere());
×
369

370
        StelToneReproducer* eye = core->getToneReproducer();
×
371
        const float lum = core->getSkyDrawer()->surfaceBrightnessToLuminance(getVMagnitude(core)+13.0f); // How to calibrate?
×
372
        // Get the luminance scaled between 0 and 1
373
        float aLum =eye->adaptLuminanceScaled(lum);
×
374

375

376
        // To make comet more apparent in overviews, take field of view into account:
377
        const float fov=core->getProjection(core->getAltAzModelViewTransform())->getFov();
×
378
        if (fov>20)
×
379
                aLum*= (fov/20.0f);
×
380

381
        // Now inhibit tail drawing if still too dim.
382
        if (aLum<0.002f)
×
383
        {
384
                // Far too dim: don't even show tail...
385
                tailBright=false;
×
386
                return;
×
387
        } else
388
                tailBright=true;
×
389

390
        // Separate factors, but avoid overly bright tails. I limit to about 0.7 for overlapping both tails which should not exceed full-white.
391
        float gasMagFactor=qMin(0.9f*aLum, 0.7f);
×
392
        float dustMagFactor=qMin(dustTailBrightnessFactor*aLum, 0.7f);
×
393

394
        // TODO: Maybe make gas color distance dependent? (various typical ingredients outgas at different temperatures...)
395
        Vec3f gasColor(0.15f*gasMagFactor,0.35f*gasMagFactor,0.6f*gasMagFactor); // Orig color 0.15/0.15/0.6.
×
396
        Vec3f dustColor(dustMagFactor, dustMagFactor,0.6f*dustMagFactor);
×
397

398
        if (withAtmosphere)
×
399
        {
400
                Extinction extinction=core->getSkyDrawer()->getExtinction();
×
401

402
                // Not only correct the color values for extinction, but for twilight conditions, also make tail end less visible.
403
                // I consider sky brightness over 1cd/m^2 as reason to shorten tail.
404
                // Below this brightness, the tail brightness loss by this method is insignificant:
405
                // Just counting through the vertices might make a spiral appearance. Maybe even better than stackwise? Let's see...
406
                const float avgAtmLum=GETSTELMODULE(LandscapeMgr)->getAtmosphereAverageLuminance();
×
407
                const float brightnessDecreasePerVertexFromHead=1.0f/(COMET_TAIL_SLICES*COMET_TAIL_STACKS)  * avgAtmLum;
×
408
                float brightnessPerVertexFromHead=1.0f;
×
409

410
                gastailColorArr.clear();
×
411
                dusttailColorArr.clear();
×
412
                for (int i=0; i<gastailVertexArr.size(); ++i)
×
413
                {
414
                        // Gastail extinction:
415
                        Vec3d vertAltAz=core->j2000ToAltAz(gastailVertexArr.at(i), StelCore::RefractionOn);
×
416
                        vertAltAz.normalize();
×
417
                        Q_ASSERT(fabs(vertAltAz.normSquared()-1.0) < 0.001);
×
418
                        float oneMag=0.0f;
×
419
                        extinction.forward(vertAltAz, &oneMag);
×
420
                        float extinctionFactor=std::pow(0.4f, oneMag); // drop of one magnitude: factor 2.5 or 40%
×
421
                        gastailColorArr.append(gasColor*extinctionFactor* brightnessPerVertexFromHead*intensityFovScale);
×
422

423
                        // dusttail extinction:
424
                        vertAltAz=core->j2000ToAltAz(dusttailVertexArr.at(i), StelCore::RefractionOn);
×
425
                        vertAltAz.normalize();
×
426
                        Q_ASSERT(fabs(vertAltAz.normSquared()-1.0) < 0.001);
×
427
                        oneMag=0.0f;
×
428
                        extinction.forward(vertAltAz, &oneMag);
×
429
                        extinctionFactor=std::pow(0.4f, oneMag); // drop of one magnitude: factor 2.5 or 40%
×
430
                        dusttailColorArr.append(dustColor*extinctionFactor * brightnessPerVertexFromHead*intensityFovScale);
×
431

432
                        brightnessPerVertexFromHead-=brightnessDecreasePerVertexFromHead;
×
433
                }
434
        }
435
        else // no atmosphere: set all vertices to same brightness.
436
        {
437
                gastailColorArr.fill(gasColor  *intensityFovScale, gastailVertexArr.length());
×
438
                dusttailColorArr.fill(dustColor*intensityFovScale, dusttailVertexArr.length());
×
439
        }
440
        //qDebug() << "Comet " << getEnglishName() <<  "JDE: " << date << "gasR" << gasColor[0] << " dustR" << dustColor[0];
441
}
442

443

444
// Draw the Comet and all the related infos: name, circle etc... GZ: Taken from Planet.cpp 2013-11-05 and extended
445
void Comet::draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont)
×
446
{
447
        if (hidden)
×
448
                return;
×
449

450
        // Exclude drawing if user set a hard limit magnitude.
451
        if (core->getSkyDrawer()->getFlagPlanetMagnitudeLimit() && (getVMagnitude(core) > core->getSkyDrawer()->getCustomPlanetMagnitudeLimit()))
×
452
                return;
×
453

454
        if (getEnglishName() == core->getCurrentLocation().planetName)
×
455
        { // Maybe even don't do that? E.g., draw tail while riding the comet? Decide later.
456
                return;
×
457
        }
458

459
        // This test seemed necessary for reasonable fps in case too many comet elements are loaded.
460
        // Problematic: Early-out here of course disables the wanted hint circles for dim comets.
461
        // The line makes hints for comets 5 magnitudes below sky limiting magnitude visible.
462
        // If comet is too faint to be seen, don't bother rendering. (Massive speedup if people have hundreds of comet elements!)
463
        if ((getVMagnitude(core)-5.0f) > core->getSkyDrawer()->getLimitMagnitude() && !core->getCurrentLocation().planetName.contains("Observer", Qt::CaseInsensitive))
×
464
        {
465
                return;
×
466
        }
467
        if (!static_cast<KeplerOrbit*>(orbitPtr)->objectDateGoodEnoughForOrbits(core->getJDE())) return; // don't draw at all if out of useful date range. This allows having hundreds of comet elements.
×
468

469
        Mat4d mat = Mat4d::translation(eclipticPos+aberrationPush) * rotLocalToParent;
×
470
        // This removed totally the Planet shaking bug!!!
471
        StelProjector::ModelViewTranformP transfo = core->getHeliocentricEclipticModelViewTransform();
×
472
        transfo->combine(mat);
×
473

474
        // Compute the 2D position and check if in the screen
475
        const StelProjectorP prj = core->getProjection(transfo);
×
476
        const double screenRd = (getAngularRadius(core))*M_PI_180*static_cast<double>(prj->getPixelPerRadAtCenter());
×
477
        const double viewport_left = prj->getViewportPosX();
×
478
        const double viewport_bottom = prj->getViewportPosY();
×
479
        const bool projectionValid=prj->project(Vec3d(0.), screenPos);
×
480
        if (projectionValid
×
481
                && screenPos[1] > viewport_bottom - screenRd
×
482
                && screenPos[1] < viewport_bottom + prj->getViewportHeight()+screenRd
×
483
                && screenPos[0] > viewport_left - screenRd
×
484
                && screenPos[0] < viewport_left + prj->getViewportWidth() + screenRd)
×
485
        {
486
                // Draw the name, and the circle if it's not too close from the body it's turning around
487
                // this prevents name overlapping (ie for jupiter satellites)
488
                float ang_dist = 300.f*static_cast<float>(atan(getEclipticPos().norm()/getEquinoxEquatorialPos(core).norm())/core->getMovementMgr()->getCurrentFov());
×
489
                // if (ang_dist==0.f) ang_dist = 1.f; // if ang_dist == 0, the Planet is sun.. --> GZ: we can remove it.
490

491
                // by putting here, only draw orbit if Comet is visible for clarity
492
                drawOrbit(core);  // TODO - fade in here also...
×
493

494
                labelsFader = (flagLabels && ang_dist>0.25f && maxMagLabels>getVMagnitude(core));
×
495

NEW
496
                const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
×
NEW
497
                StelPainter sPainter(prj);
×
NEW
498
                drawHints(core, sPainter, planetNameFont);
×
499

500
                draw3dModel(core,transfo,static_cast<float>(screenRd));
×
501
        }
×
502
        else
503
                if (!projectionValid && prj.data()->getNameI18() == q_("Orthographic"))
×
504
                        return; // End prematurely. This excludes bad "ghost" comet tail on the wrong hemisphere in ortho projection! Maybe also Fisheye, but it's less problematic.
×
505
        else if (permanentDrawingOrbits) // A special case for demos
×
506
                        drawOrbit(core);
×
507

508

509
        // If comet is too faint to be seen, don't bother rendering. (Massive speedup if people have hundreds of comets!)
510
        // This test moved here so that hints are still drawn.
511
        if ((getVMagnitude(core)-5.0f) > core->getSkyDrawer()->getLimitMagnitude())
×
512
        {
513
                return;
×
514
        }
515

516
        // but tails should also be drawn if comet core is off-screen...
517
        if (tailActive && tailBright)
×
518
        {
519
                drawTail(core,transfo,true);  // gas tail
×
520
                drawTail(core,transfo,false); // dust tail
×
521
        }
522
        //Coma: this is just a fan disk tilted towards the observer;-)
523
        drawComa(core, transfo);
×
524
        return;
×
525
}
×
526

527
void Comet::drawTail(StelCore* core, StelProjector::ModelViewTranformP transfo, bool gas)
×
528
{        
529
        StelPainter sPainter(core->getProjection(transfo));
×
530
        sPainter.setBlending(true, GL_ONE, GL_ONE);
×
531

532
        tailTexture->bind();
×
533

534
        if (gas) {
×
535
                StelVertexArray vaGas(static_cast<const QVector<Vec3d> >(gastailVertexArr), StelVertexArray::Triangles,
×
536
                                      static_cast<const QVector<Vec2f> >(tailTexCoordArr), tailIndices, static_cast<const QVector<Vec3f> >(gastailColorArr));
×
537
                sPainter.drawStelVertexArray(vaGas, true);
×
538

539
        } else {
×
540
                StelVertexArray vaDust(static_cast<const QVector<Vec3d> >(dusttailVertexArr), StelVertexArray::Triangles,
×
541
                                      static_cast<const QVector<Vec2f> >(tailTexCoordArr), tailIndices, static_cast<const QVector<Vec3f> >(dusttailColorArr));
×
542
                sPainter.drawStelVertexArray(vaDust, true);
×
543
        }
×
544
        sPainter.setBlending(false);
×
545
}
×
546

547
void Comet::drawComa(StelCore* core, StelProjector::ModelViewTranformP transfo)
×
548
{
549
        // Find rotation matrix from 0/0/1 to viewdirection! crossproduct for axis (normal vector), dotproduct for angle.
550
        Vec3d eclposNrm=eclipticPos+aberrationPush - core->getObserverHeliocentricEclipticPos()  ; eclposNrm.normalize();
×
551
        Mat4d comarot=Mat4d::rotation(Vec3d(0.0, 0.0, 1.0)^(eclposNrm), std::acos(Vec3d(0.0, 0.0, 1.0).dot(eclposNrm)) );
×
552
        StelProjector::ModelViewTranformP transfo2 = transfo->clone();
×
553
        transfo2->combine(comarot);
×
554
        StelPainter sPainter(core->getProjection(transfo2));
×
555

556
        sPainter.setBlending(true, GL_ONE, GL_ONE);
×
557

558
        StelToneReproducer* eye = core->getToneReproducer();
×
559
        float lum = core->getSkyDrawer()->surfaceBrightnessToLuminance(getVMagnitudeWithExtinction(core)+11.0f); // How to calibrate?
×
560
        // Get the luminance scaled between 0 and 1
561
        const float aLum =eye->adaptLuminanceScaled(lum);
×
562
        const float magFactor=qBound(0.25f*intensityFovScale, aLum*intensityFovScale, 2.0f);
×
563
        comaTexture->bind();
×
564
        sPainter.setColor(0.3f*magFactor,0.7f*magFactor,magFactor);
×
565
        StelVertexArray vaComa(static_cast<const QVector<Vec3d> >(comaVertexArr), StelVertexArray::Triangles, static_cast<const QVector<Vec2f> >(comaTexCoordArr));
×
566
        sPainter.drawStelVertexArray(vaComa, true);
×
567
        sPainter.setBlending(false);
×
568
}
×
569

570
// Formula found at http://www.projectpluto.com/update7b.htm#comet_tail_formula
571
Vec2f Comet::getComaDiameterAndTailLengthAU() const
×
572
{
573
        const float r = static_cast<float>(getHeliocentricEclipticPos().norm());
×
574
        const float mhelio = absoluteMagnitude + slopeParameter * log10(r);
×
575
        const float Do = powf(10.0f, ((-0.0033f*mhelio - 0.07f) * mhelio + 3.25f));
×
576
        const float common = 1.0f - powf(10.0f, (-2.0f*r));
×
577
        const float D = Do * common * (1.0f - powf(10.0f, -r)) * (1000.0f*AU_KMf);
×
578
        const float Lo = powf(10.0f, ((-0.0075f*mhelio - 0.19f) * mhelio + 2.1f));
×
579
        const float L = Lo*(1.0f-powf(10.0f, -4.0f*r)) * common * (1e6f*AU_KMf);
×
580
        return Vec2f(D, L);
×
581
}
582

583
void Comet::computeComa(const float diameter)
×
584
{
585
        StelPainter::computeFanDisk(0.5f*diameter, 3, 3, comaVertexArr, comaTexCoordArr);
×
586
}
×
587

588
//! create parabola shell to represent a tail. Designed for slices=16, stacks=16, but should work with other sizes as well.
589
//! (Maybe slices must be an even number.)
590
// Parabola equation: z=x²/2p.
591
// xOffset for the dust tail, this may introduce a bend. Units are x per sqrt(z).
592
void Comet::computeParabola(const float parameter, const float radius, const float zshift,
×
593
                                                  QVector<Vec3d>& vertexArr, QVector<Vec2f>& texCoordArr,
594
                                                  QVector<unsigned short> &indices, const float xOffset)
595
{
596
        // keep the array and replace contents. However, using replace() is only slightly faster.
597
        if (vertexArr.length() < static_cast<int>(((COMET_TAIL_SLICES*COMET_TAIL_STACKS+1))))
×
598
                vertexArr.resize((COMET_TAIL_SLICES*COMET_TAIL_STACKS+1));
×
599
        if (createTailIndices) indices.clear();
×
600
        if (createTailTextureCoords) texCoordArr.clear();
×
601
        // The parabola has triangular faces with vertices on two circles that are rotated against each other. 
602
        float xa[2*COMET_TAIL_SLICES];
603
        float ya[2*COMET_TAIL_SLICES];
604
        float x, y, z;
605
        
606
        // fill xa, ya with sin/cosines. TBD: make more efficient with index mirroring etc.
607
        float da=M_PIf/COMET_TAIL_SLICES; // full circle/2slices
×
608
        for (unsigned short int i=0; i<2*COMET_TAIL_SLICES; ++i){
×
609
                xa[i]=-sin(i*da);
×
610
                ya[i]=cos(i*da);
×
611
        }
612
        
613
        vertexArr.replace(0, Vec3d(0.0, 0.0, static_cast<double>(zshift)));
×
614
        int vertexArrIndex=1;
×
615
        if (createTailTextureCoords) texCoordArr << Vec2f(0.5f, 0.5f);
×
616
        // define the indices lying on circles, starting at 1: odd rings have 1/slices+1/2slices, even-numbered rings straight 1/slices
617
        // inner ring#1
618
        for (unsigned short int ring=1; ring<=COMET_TAIL_STACKS; ++ring){
×
619
                z=ring*radius/COMET_TAIL_STACKS; z=z*z/(2*parameter) + zshift;
×
620
                const float xShift= xOffset*z*z;
×
621
                for (unsigned short int i=ring & 1; i<2*COMET_TAIL_SLICES; i+=2) { // i.e., ring1 has shifted vertices, ring2 has even ones.
×
622
                        x=xa[i]*radius*ring/COMET_TAIL_STACKS;
×
623
                        y=ya[i]*radius*ring/COMET_TAIL_STACKS;
×
624
                        vertexArr.replace(vertexArrIndex++, Vec3d(static_cast<double>(x+xShift), static_cast<double>(y), static_cast<double>(z)));
×
625
                        if (createTailTextureCoords) texCoordArr << Vec2f(0.5f+ 0.5f*x/radius, 0.5f+0.5f*y/radius);
×
626
                }
627
        }
628
        // now link the faces with indices.
629
        if (createTailIndices)
×
630
        {
631
                for (unsigned short i=1; i<COMET_TAIL_SLICES; ++i) indices << 0 << i << i+1;
×
632
                indices << 0 << COMET_TAIL_SLICES << 1; // close inner fan.
×
633
                // The other slices are a repeating pattern of 2 possibilities. Index @ring always is on the inner ring (slices-agon)
634
                for (unsigned short ring=1; ring<COMET_TAIL_STACKS; ring+=2) { // odd rings
×
635
                        const unsigned short int first=(ring-1)*COMET_TAIL_SLICES+1;
×
636
                        for (unsigned short int i=0; i<COMET_TAIL_SLICES-1; ++i){
×
637
                                indices << first+i << first+COMET_TAIL_SLICES+i << first+COMET_TAIL_SLICES+1+i;
×
638
                                indices << first+i << first+COMET_TAIL_SLICES+1+i << first+1+i;
×
639
                        }
640
                        // closing slice: mesh with other indices...
641
                        indices << ring*COMET_TAIL_SLICES << (ring+1)*COMET_TAIL_SLICES << ring*COMET_TAIL_SLICES+1;
×
642
                        indices << ring*COMET_TAIL_SLICES << ring*COMET_TAIL_SLICES+1 << first;
×
643
                }
644

645
                for (unsigned short int ring=2; ring<COMET_TAIL_STACKS; ring+=2) { // even rings: different sequence.
×
646
                        const unsigned short int first=(ring-1)*COMET_TAIL_SLICES+1;
×
647
                        for (unsigned short int i=0; i<COMET_TAIL_SLICES-1; ++i){
×
648
                                indices << first+i << first+COMET_TAIL_SLICES+i << first+1+i;
×
649
                                indices << first+1+i << first+COMET_TAIL_SLICES+i << first+COMET_TAIL_SLICES+1+i;
×
650
                        }
651
                        // closing slice: mesh with other indices...
652
                        indices << ring*COMET_TAIL_SLICES << (ring+1)*COMET_TAIL_SLICES << first;
×
653
                        indices << first << (ring+1)*COMET_TAIL_SLICES << ring*COMET_TAIL_SLICES+1;
×
654
                }
655
        }
656
        createTailIndices=false;
×
657
        createTailTextureCoords=false;
×
658
}
×
659

660
void Comet::setIAUDesignation(const QString& designation)
×
661
{
662
        static const QRegularExpression periodicDesignationPattern("^(\\d+)P/");
×
663
        static const QRegularExpression periodicCometPattern("^P/([\\w\\s]+)$");
×
664
        QRegularExpressionMatch matchPeriodicNumber = periodicDesignationPattern.match(englishName);
×
665
        QRegularExpressionMatch matchPeriodicComet  = periodicCometPattern.match(designation);
×
666
        if (matchPeriodicNumber.hasMatch() && matchPeriodicComet.hasMatch())
×
667
        {
668
                // combined designation for numbered periodic comets - 1P/1982 U1 or 146P/1984 W1
669
                iauDesignation = QString("%1P/%2").arg(matchPeriodicNumber.captured(1), matchPeriodicComet.captured(1));
×
670
        }
671
        else
672
                iauDesignation = designation;
×
673
}
×
674

675
void Comet::setExtraDesignations(QStringList codes)
×
676
{
677
        extraDesignations = codes;
×
678
        for (const auto& c : codes)
×
679
        {
680
                extraDesignationsHtml << renderDiscoveryDesignationHtml(c);
×
681
        }
682
}
×
683

684
QString Comet::renderDiscoveryDesignationHtml(const QString &plainTextName)
3✔
685
{
686
        static const QRegularExpression discoveryDesignationPattern("^(\\d{4}[a-z]{1})(\\d+)$");
3✔
687
        QRegularExpressionMatch match=discoveryDesignationPattern.match(plainTextName);
3✔
688
        if (match.hasMatch())
3✔
689
        {
690
                QString main = match.captured(1);
2✔
691
                QString suffix = match.captured(2);
2✔
692
                return (QString("%1<sub>%2</sub>").arg(main, suffix));
4✔
693
        }
2✔
694
        else
695
                return plainTextName;
1✔
696
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc