-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathNebula.cpp
More file actions
1439 lines (1298 loc) · 45.2 KB
/
Copy pathNebula.cpp
File metadata and controls
1439 lines (1298 loc) · 45.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Stellarium
* Copyright (C) 2002 Fabien Chereau
* Copyright (C) 2011 Alexander Wolf
* Copyright (C) 2015 Georg Zotti
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/
#include "Nebula.hpp"
#include "NebulaMgr.hpp"
#include "Planet.hpp"
#include "StelTexture.hpp"
#include "StelUtils.hpp"
#include "StelApp.hpp"
#include "StelModuleMgr.hpp"
#include "StelCore.hpp"
#include "StelPainter.hpp"
#include "RefractionExtinction.hpp"
#include <QTextStream>
#include <QFile>
#include <QString>
#include <QRegularExpression>
#include <QDebug>
#include <QBuffer>
const QString Nebula::NEBULA_TYPE = QStringLiteral("Nebula");
StelTextureSP Nebula::texCircle;
StelTextureSP Nebula::texCircleLarge;
StelTextureSP Nebula::texRegion;
StelTextureSP Nebula::texGalaxy;
StelTextureSP Nebula::texGalaxyLarge;
StelTextureSP Nebula::texOpenCluster;
StelTextureSP Nebula::texOpenClusterLarge;
StelTextureSP Nebula::texOpenClusterXLarge;
StelTextureSP Nebula::texGlobularCluster;
StelTextureSP Nebula::texGlobularClusterLarge;
StelTextureSP Nebula::texPlanetaryNebula;
StelTextureSP Nebula::texDiffuseNebula;
StelTextureSP Nebula::texDiffuseNebulaLarge;
StelTextureSP Nebula::texDiffuseNebulaXLarge;
StelTextureSP Nebula::texDarkNebula;
StelTextureSP Nebula::texDarkNebulaLarge;
StelTextureSP Nebula::texOpenClusterWithNebulosity;
StelTextureSP Nebula::texOpenClusterWithNebulosityLarge;
bool Nebula::drawHintProportional = false;
bool Nebula::surfaceBrightnessUsage = false;
bool Nebula::designationUsage = false;
float Nebula::hintsBrightness = 0.f;
Vec3f Nebula::labelColor = Vec3f(0.4f,0.3f,0.5f);
QMap<Nebula::NebulaType, Vec3f>Nebula::hintColorMap;
bool Nebula::flagUseTypeFilters = false;
Nebula::CatalogGroup Nebula::catalogFilters = Nebula::CatalogGroup(Nebula::CatNone);
Nebula::TypeGroup Nebula::typeFilters = Nebula::TypeGroup(Nebula::TypeAll);
bool Nebula::flagUseArcsecSurfaceBrightness = false;
bool Nebula::flagUseShortNotationSurfaceBrightness = true;
bool Nebula::flagUseOutlines = false;
bool Nebula::flagShowAdditionalNames = true;
bool Nebula::flagUseSizeLimits = false;
double Nebula::minSizeLimit = 1.0;
double Nebula::maxSizeLimit = 600.0;
const QMap<Nebula::NebulaType, QString> Nebula::typeEnglishStringMap = // Maps type to english name.
{
{ NebGx , N_("galaxy") },
{ NebAGx , N_("active galaxy") },
{ NebRGx , N_("radio galaxy") },
{ NebIGx , N_("interacting galaxy") },
{ NebQSO , N_("quasar") },
{ NebCl , N_("star cluster") },
{ NebOc , N_("open star cluster") },
{ NebGc , N_("globular star cluster") },
{ NebSA , N_("stellar association") },
{ NebSC , N_("star cloud") },
{ NebN , N_("nebula") },
{ NebPn , N_("planetary nebula") },
{ NebDn , N_("dark nebula") },
{ NebRn , N_("reflection nebula") },
{ NebBn , N_("bipolar nebula") },
{ NebEn , N_("emission nebula") },
{ NebCn , N_("cluster associated with nebulosity") },
{ NebHII , N_("HII region") },
{ NebSNR , N_("supernova remnant") },
{ NebISM , N_("interstellar matter") },
{ NebEMO , N_("emission object") },
{ NebBLL , N_("BL Lac object") },
{ NebBLA , N_("blazar") },
{ NebMolCld , N_("molecular cloud") },
{ NebYSO , N_("young stellar object") },
{ NebPossQSO, N_("possible quasar") },
{ NebPossPN , N_("possible planetary nebula") },
{ NebPPN , N_("protoplanetary nebula") },
{ NebStar , N_("star") },
{ NebSymbioticStar , N_("symbiotic star") },
{ NebEmissionLineStar, N_("emission-line star") },
{ NebSNC , N_("supernova candidate") },
{ NebSNRC , N_("supernova remnant candidate") },
{ NebGxCl , N_("cluster of galaxies") },
{ NebPartOfGx, N_("part of a galaxy") },
{ NebRegion , N_("region of the sky") },
{ NebUnknown, N_("object of unknown nature") }
};
Nebula::Nebula()
: StelObject()
, DSO_nb(0)
, M_nb(0)
, NGC_nb(0)
, IC_nb(0)
, C_nb(0)
, B_nb(0)
, Sh2_nb(0)
, VdB_nb(0)
, RCW_nb(0)
, LDN_nb(0)
, LBN_nb(0)
, Cr_nb(0)
, Mel_nb(0)
, PGC_nb(0)
, UGC_nb(0)
, Arp_nb(0)
, VV_nb(0)
, DWB_nb(0)
, Tr_nb(0)
, St_nb(0)
, Ru_nb(0)
, VdBHa_nb(0)
, Ced_nb("")
, PK_nb("")
, PNG_nb("")
, SNRG_nb("")
, ACO_nb("")
, HCG_nb("")
, ESO_nb("")
, VdBH_nb("")
, withoutID(false)
, nameI18("")
, mTypeString()
, bMag(99.)
, vMag(99.)
, majorAxisSize(0.)
, minorAxisSize(0.)
, orientationAngle(0)
, oDistance(0.)
, oDistanceErr(0.)
, redshift(99.)
, redshiftErr(0.)
, parallax(0.)
, parallaxErr(0.)
, nType()
{
outlineSegments.clear();
designations.clear();
}
Nebula::~Nebula()
{
}
QString Nebula::getMagnitudeInfoString(const StelCore *core, const InfoStringGroup& flags, const int decimals) const
{
QString res;
const float mmag = qMin(vMag, bMag);
if (mmag < 50.f && flags&Magnitude)
{
QString emag = "";
QString fsys = "";
bool bmag = false;
float mag = getVMagnitude(core);
float mage = getVMagnitudeWithExtinction(core);
bool hasAtmosphere = core->getSkyDrawer()->getFlagHasAtmosphere();
QString tmag = q_("Magnitude");
if (nType == NebDn || B_nb>0) // Dark nebulae or objects from Barnard catalog
tmag = q_("Opacity");
if (bMag < 50.f && vMag > 50.f)
{
fsys = QString("(%1 B").arg(q_("photometric passband"));
if (hasAtmosphere)
fsys.append(";");
else
fsys.append(")");
mag = getBMagnitude(core);
mage = getBMagnitudeWithExtinction(core);
bmag = true;
}
const float airmass = getAirmass(core);
if (nType != NebDn && B_nb==0 && airmass>-1.f) // Don't show extincted magnitude much below horizon where model is meaningless.
{
emag = QString("%1 <b>%2</b> %3 <b>%4</b> %5)").arg(q_("reduced to"), QString::number(mage, 'f', decimals), q_("by"), QString::number(airmass, 'f', 2), q_("Airmasses"));
if (!bmag)
emag = QString("(%1").arg(emag);
}
res = QString("%1: <b>%2</b> %3 %4<br />").arg(tmag, QString::number(mag, 'f', decimals), fsys, emag);
}
res += getExtraInfoStrings(Magnitude).join("");
return res;
}
QString Nebula::getInfoString(const StelCore *core, const InfoStringGroup& flags) const
{
QString str;
QTextStream oss(&str);
bool withDecimalDegree = StelApp::getInstance().getFlagShowDecimalDegrees();
if ((flags&Name) || (flags&CatalogNumber))
oss << "<h2>";
if (!nameI18.isEmpty() && flags&Name)
{
oss << getNameI18n();
QString aliases = getI18nAliases();
if (!aliases.isEmpty() && flagShowAdditionalNames)
oss << " (" << aliases << ")";
}
if (flags&CatalogNumber)
{
if (!nameI18.isEmpty() && !withoutID && flags&Name)
oss << "<br>";
oss << designations.join(" - ");
}
if ((flags&Name) || (flags&CatalogNumber))
oss << "</h2>";
if (flags&Name)
{
QStringList extraNames=getExtraInfoStrings(Name);
if (extraNames.length()>0)
oss << q_("Additional names: ") << extraNames.join(", ") << "<br/>";
}
if (flags&CatalogNumber)
{
QStringList extraCat=getExtraInfoStrings(CatalogNumber);
if (extraCat.length()>0)
oss << q_("Additional catalog numbers: ") << extraCat.join(", ") << "<br/>";
}
if (flags&ObjectType)
{
QString mt = getMorphologicalTypeString();
if (mt.isEmpty())
oss << QString("%1: <b>%2</b>").arg(q_("Type"), getObjectTypeI18n()) << "<br>";
else
oss << QString("%1: <b>%2</b> (%3)").arg(q_("Type"), getObjectTypeI18n(), mt) << "<br>";
oss << getExtraInfoStrings(ObjectType).join("");
}
oss << getMagnitudeInfoString(core, flags, 2);
if (flags&Extra)
{
if (vMag < 50 && bMag < 50)
oss << QString("%1: <b>%2</b>").arg(q_("Color Index (B-V)"), QString::number(bMag-vMag, 'f', 2)) << "<br />";
}
float mmag = qMin(vMag,bMag);
if (nType != NebDn && mmag < 50 && flags&Extra)
{
QString sb = q_("Surface brightness");
QString ae = q_("after extinction");
QString mu;
if (flagUseShortNotationSurfaceBrightness)
{
mu = QString("<sup>m</sup>/□'");
if (flagUseArcsecSurfaceBrightness)
mu = QString("<sup>m</sup>/□\"");
}
else
{
mu = QString("%1/%2<sup>2</sup>").arg(qc_("mag", "magnitude"), q_("arc-min"));
if (flagUseArcsecSurfaceBrightness)
mu = QString("%1/%2<sup>2</sup>").arg(qc_("mag", "magnitude"), q_("arc-sec"));
}
if (getSurfaceBrightness(core)<99.f)
{
if (getAirmass(core)>-1.f && getSurfaceBrightnessWithExtinction(core)<99.f) // Don't show extincted surface brightness much below horizon where model is meaningless.
{
oss << QString("%1: <b>%2</b> %5 (%3: <b>%4</b> %5)").arg(sb, QString::number(getSurfaceBrightness(core, flagUseArcsecSurfaceBrightness), 'f', 2),
ae, QString::number(getSurfaceBrightnessWithExtinction(core, flagUseArcsecSurfaceBrightness), 'f', 2), mu) << "<br />";
}
else
oss << QString("%1: <b>%2</b> %3").arg(sb, QString::number(getSurfaceBrightness(core, flagUseArcsecSurfaceBrightness), 'f', 2), mu) << "<br />";
if (getContrastIndex(core)<99.f)
oss << QString("%1: %2").arg(q_("Contrast index"), QString::number(getContrastIndex(core), 'f', 2)) << "<br />";
}
}
oss << getCommonInfoString(core, flags);
if (flags&Size && majorAxisSize>0.f)
{
QString majorAxS, minorAxS, sizeAx = q_("Size");
if (withDecimalDegree)
{
majorAxS = StelUtils::radToDecDegStr(static_cast<double>(majorAxisSize)*M_PI/180., 5, false, true);
minorAxS = StelUtils::radToDecDegStr(static_cast<double>(minorAxisSize)*M_PI/180., 5, false, true);
}
else
{
majorAxS = StelUtils::radToDmsPStr(static_cast<double>(majorAxisSize)*M_PI/180., 2);
minorAxS = StelUtils::radToDmsPStr(static_cast<double>(minorAxisSize)*M_PI/180., 2);
}
if (fuzzyEquals(majorAxisSize, minorAxisSize) || minorAxisSize==0.f)
oss << QString("%1: %2").arg(sizeAx, majorAxS) << "<br />";
else
{
oss << QString("%1: %2 x %3").arg(sizeAx, majorAxS, minorAxS) << "<br />";
if (orientationAngle>0)
oss << QString("%1: %2%3").arg(q_("Orientation angle")).arg(orientationAngle).arg(QChar(0x00B0)) << "<br />";
}
}
if (flags&Size)
oss << getExtraInfoStrings(Size).join("");
if (flags&Distance)
{
float distance, distanceErr, distanceLY, distanceErrLY;
if (qAbs(parallax)>0.f)
{
QString dx;
// distance in light years from parallax
distance = 3.162e-5f/(qAbs(parallax)*4.848e-9f);
distanceErr = 0.f;
if (parallaxErr>0.f)
distanceErr = qAbs(3.162e-5f/(qAbs(parallaxErr + parallax)*4.848e-9f) - distance);
if (distanceErr>0.f)
dx = QString("%1%2%3").arg(QString::number(distance, 'f', 3)).arg(QChar(0x00B1)).arg(QString::number(distanceErr, 'f', 3));
else
dx = QString("%1").arg(QString::number(distance, 'f', 3));
if (oDistance==0.f)
{
// TRANSLATORS: Unit of measure for distance - Light Years
QString ly = qc_("ly", "distance");
oss << QString("%1: %2 %3").arg(q_("Distance"), dx, ly) << "<br />";
}
}
if (oDistance>0.f)
{
QString dx, dy;
float dc = 3262.f;
int ms = 1;
//TRANSLATORS: Unit of measure for distance - kiloparsecs
QString dupc = qc_("kpc", "distance");
//TRANSLATORS: Unit of measure for distance - Light Years
QString duly = qc_("ly", "distance");
distance = oDistance;
distanceErr = oDistanceErr;
distanceLY = oDistance*dc;
distanceErrLY= oDistanceErr*dc;
if (oDistance>=1000.f)
{
distance = oDistance/1000.f;
distanceErr = oDistanceErr/1000.f;
//TRANSLATORS: Unit of measure for distance - Megaparsecs
dupc = qc_("Mpc", "distance");
}
if (distanceLY>=1e6f)
{
distanceLY /= 1e6f;
distanceErrLY /= 1e6f;
ms = 3;
//TRANSLATORS: Unit of measure for distance - Millions of Light Years
duly = qc_("M ly", "distance");
}
if (oDistanceErr>0.f)
{
dx = QString("%1%2%3").arg(QString::number(distance, 'f', 3)).arg(QChar(0x00B1)).arg(QString::number(distanceErr, 'f', 3));
dy = QString("%1%2%3").arg(QString::number(distanceLY, 'f', ms)).arg(QChar(0x00B1)).arg(QString::number(distanceErrLY, 'f', ms));
}
else
{
dx = QString("%1").arg(QString::number(distance, 'f', 3));
dy = QString("%1").arg(QString::number(distanceLY, 'f', ms));
}
oss << QString("%1: %2 %3 (%4 %5)").arg(q_("Distance"), dx, dupc, dy, duly) << "<br />";
}
oss << getExtraInfoStrings(Distance).join("");
}
if (flags&Extra)
{
if (redshift<99.f)
{
QString z;
if (redshiftErr>0.f)
z = QString("%1%2%3").arg(QString::number(redshift, 'f', 6)).arg(QChar(0x00B1)).arg(QString::number(redshiftErr, 'f', 6));
else
z = QString("%1").arg(QString::number(redshift, 'f', 6));
oss << QString("%1: %2").arg(q_("Redshift"), z) << "<br />";
}
if (qAbs(parallax)>0.f)
{
QString px;
if (parallaxErr>0.f)
px = QString("%1%2%3").arg(QString::number(qAbs(parallax), 'f', 3)).arg(QChar(0x00B1)).arg(QString::number(parallaxErr, 'f', 3));
else
px = QString("%1").arg(QString::number(qAbs(parallax), 'f', 3));
oss << QString("%1: %2 %3").arg(q_("Parallax"), px, qc_("mas", "parallax")) << "<br />";
}
if (!getMorphologicalTypeDescription().isEmpty())
oss << QString("%1: %2.").arg(q_("Morphological description"), getMorphologicalTypeDescription()) << "<br />";
}
oss << getSolarLunarInfoString(core, flags);
postProcessInfoString(str, flags);
return str;
}
QVariantMap Nebula::getInfoMap(const StelCore *core) const
{
QVariantMap map = StelObject::getInfoMap(core);
map["type"]=getObjectTypeI18n(); // replace "Nebula" type by detail. This is localized.
map.insert("morpho", getMorphologicalTypeString());
map.insert("surface-brightness", getSurfaceBrightness(core));
map.insert("designations", withoutID ? QString() : designations.join(" - "));
map.insert("bmag", bMag);
if (vMag < 50 && bMag < 50)
map.insert("bV", bMag-vMag);
if (redshift<99.f)
map.insert("redshift", redshift);
// TODO: more? Names? Data?
return map;
}
QString Nebula::getEnglishAliases() const
{
QString aliases = "";
int asize = englishAliases.size();
if (asize!=0)
{
if (asize>2) // Special case for many AKA
{
bool firstLine = true;
for(int i=1; i<=asize; i++)
{
aliases.append(englishAliases.at(i-1));
if (i<asize)
aliases.append(" - ");
if ((i % 2)==0 && firstLine) // 2 AKA-items on first line!
{
aliases.append("<br />");
firstLine = false;
}
if (i>3 && ((i-2) % 4)==0 && !firstLine && i<asize)
aliases.append("<br />");
}
}
else
aliases = nameI18Aliases.join(" - ");
}
return aliases;
}
QString Nebula::getI18nAliases() const
{
QString aliases = "";
int asize = nameI18Aliases.size();
if (asize!=0)
{
if (asize>2) // Special case for many AKA; NOTE: Should we add size to the config data for skyculture?
{
bool firstLine = true;
for(int i=1; i<=asize; i++)
{
aliases.append(nameI18Aliases.at(i-1));
if (i<asize)
aliases.append(" - ");
if ((i % 2)==0 && firstLine) // 2 AKA-items on first line!
{
aliases.append("<br />");
firstLine = false;
}
if (i>3 && ((i-2) % 4)==0 && !firstLine && i<asize)
aliases.append("<br />");
}
}
else
aliases = nameI18Aliases.join(" - ");
}
return aliases;
}
float Nebula::getVMagnitude(const StelCore* core) const
{
Q_UNUSED(core)
return vMag;
}
float Nebula::getBMagnitude(const StelCore* core) const
{
Q_UNUSED(core)
return bMag;
}
float Nebula::getBMagnitudeWithExtinction(const StelCore* core) const
{
Vec3d altAzPos = getAltAzPosGeometric(core);
altAzPos.normalize();
float mag = getBMagnitude(core);
// without the test, planets flicker stupidly in fullsky atmosphere-less view.
if (core->getSkyDrawer()->getFlagHasAtmosphere())
core->getSkyDrawer()->getExtinction().forward(altAzPos, &mag);
return mag;
}
double Nebula::getAngularRadius(const StelCore *) const
{
return static_cast<double>(0.5f*majorAxisSize);
}
float Nebula::getSelectPriority(const StelCore* core) const
{
float selectPriority = StelObject::getSelectPriority(core);
const NebulaMgr* nebMgr = (static_cast<NebulaMgr*>(StelApp::getInstance().getModuleMgr().getModule("NebulaMgr")));
// minimize unwanted selection of the deep-sky objects
if (!nebMgr->getFlagHints())
return selectPriority+3.f;
float mag = qMin(getVMagnitude(core), getBMagnitude(core));
float lim = mag;
float mLim = 15.0f;
if (nType==NebRegion) // special case for regions
mag = 3.f;
if (!objectInDisplayedCatalog() || !objectInDisplayedType())
return selectPriority+mLim;
const StelSkyDrawer* drawer = core->getSkyDrawer();
if (drawer->getFlagNebulaMagnitudeLimit() && (mag>static_cast<float>(drawer->getCustomNebulaMagnitudeLimit())))
return selectPriority+mLim;
const float maxMagHint = nebMgr->computeMaxMagHint(drawer);
// make very easy to select if labeled
if (surfaceBrightnessUsage)
{
lim = mag = getSurfaceBrightness(core);
mLim += 1.f;
}
if (nType==NebDn)
lim=mLim - mag - 2.0f*qMin(1.5f, majorAxisSize); // Note that "mag" field is used for opacity in this catalog!
else if (nType==NebHII) // Sharpless and LBN
lim=10.0f - 2.0f*qMin(1.5f, majorAxisSize); // Unfortunately, in Sh catalog, we always have mag=99=unknown!
if (std::min(mLim, lim)<=maxMagHint || outlineSegments.size()>0 || nType==NebRegion) // High priority for big DSO (with outlines) or regions
selectPriority = -10.f;
else
selectPriority -= 5.f;
return selectPriority;
}
Vec3f Nebula::getInfoColor(void) const
{
return (static_cast<NebulaMgr*>(StelApp::getInstance().getModuleMgr().getModule("NebulaMgr")))->getLabelsColor();
}
double Nebula::getCloseViewFov(const StelCore*) const
{
return majorAxisSize>0.f ? static_cast<double>(majorAxisSize) * 4. : 1.;
}
float Nebula::getSurfaceBrightness(const StelCore* core, bool arcsec) const
{
const float sq = (arcsec ? 3600.f*3600.f : 3600.f); // arcsec^2 or arcmin^2
const float mag = qMin(getVMagnitude(core), getBMagnitude(core));
if (mag<99.f && majorAxisSize>0.f && nType!=NebDn)
return mag + 2.5f*log10f(getSurfaceArea()*sq);
else
return 99.f;
}
float Nebula::getSurfaceBrightnessWithExtinction(const StelCore* core, bool arcsec) const
{
const float sq = (arcsec ? 3600.f*3600.f : 3600.f); // arcsec^2 or arcmin^2
const float mag = qMin(getVMagnitudeWithExtinction(core), getBMagnitudeWithExtinction(core));
if (mag<99.f && majorAxisSize>0.f && nType!=NebDn)
return mag + 2.5f*log10f(getSurfaceArea()*sq);
else
return 99.f;
}
float Nebula::getContrastIndex(const StelCore* core) const
{
// Compute an extended object's contrast index: http://www.unihedron.com/projects/darksky/NELM2BCalc.html
// Sky brightness
const auto luminance = core->getSkyDrawer()->getLightPollutionLuminance();
const float B_mpsas = StelCore::luminanceToMPSAS(luminance);
// Compute an extended object's contrast index
// Source: Clark, R.N., 1990. Appendix E in Visual Astronomy of the Deep Sky, Cambridge University Press and Sky Publishing.
// URL: http://www.clarkvision.com/visastro/appendix-e.html
const float emag = getSurfaceBrightnessWithExtinction(core, true);
if (emag<99.f)
return -0.4f * (emag - B_mpsas);
else
return 99.f;
}
float Nebula::getSurfaceArea(void) const
{
if (minorAxisSize==0.f)
return M_PIf*(majorAxisSize/2.f)*(majorAxisSize/2.f); // S = pi*R^2 = pi*(D/2)^2
else
return M_PIf*(majorAxisSize/2.f)*(minorAxisSize/2.f); // S = pi*a*b
}
Vec3f Nebula::getHintColor(Nebula::NebulaType nType)
{
return hintColorMap.value(nType, hintColorMap.value(NebUnknown));
}
float Nebula::getVisibilityLevelByMagnitude(void) const
{
StelCore* core = StelApp::getInstance().getCore();
const float mLim = 15.0f;
float lim = qMin(vMag, bMag);
if (surfaceBrightnessUsage)
{
lim = getSurfaceBrightness(core) - 3.f;
if (lim > 90.f) lim = mLim + 1.f;
}
else
{
if (lim > 90.f) lim = mLim;
// Dark nebulae. Not sure how to assess visibility from opacity? --GZ
if (nType==NebDn)
{
const float mag = getVMagnitude(core);
// GZ: ad-hoc visibility formula: assuming good visibility if objects of mag9 are visible, "usual" opacity 5 and size 30', better visibility (discernability) comes with higher opacity and larger size,
// 9-(opac-5)-2*(angularSize-0.5)
// GZ Not good for non-Barnards. weak opacity and large surface are antagonists. (some LDN are huge, but opacity 2 is not much to discern).
// The qMin() maximized the visibility gain for large objects.
if (majorAxisSize>0.f && mag<90.f)
lim = mLim - mag - 2.0f*qMin(majorAxisSize, 1.5f);
else
lim = (B_nb>0 ? 9.0f : 12.0f); // GZ I assume LDN objects are rather elusive.
}
else if (nType==NebHII) // NebHII={Sharpless, LBN, RCW} but also M42.
{
// artificially increase visibility of (most) Sharpless and LBN objects. No magnitude recorded:-(
lim=qMin(lim, 10.0f);
}
}
if (nType==NebRegion) // special case for regions
lim=3.0f;
return lim;
}
void Nebula::drawOutlines(StelPainter &sPainter, float maxMagHints) const
{
size_t segments = outlineSegments.size();
Vec3f color = getHintColor(nType);
// tune limits for outlines
float oLim = getVisibilityLevelByMagnitude() - 3.f;
float lum = 1.f;
Vec3f col(color*lum*hintsBrightness);
if (!objectInDisplayedType())
col.set(0.f,0.f,0.f);
sPainter.setColor(col, 1);
StelCore *core=StelApp::getInstance().getCore();
Vec3d vel=core->getCurrentPlanet()->getHeliocentricEclipticVelocity();
vel=StelCore::matVsop87ToJ2000*vel;
vel*=core->getAberrationFactor() * (AU/(86400.0*SPEED_OF_LIGHT));
// Show outlines
if (segments>0 && flagUseOutlines && oLim<=maxMagHints)
{
unsigned int i, j;
std::vector<Vec3d> *points;
sPainter.setBlending(true);
sPainter.setLineSmooth(true);
const SphericalCap& viewportHalfspace = sPainter.getProjector()->getBoundingCap();
for (i=0;i<segments;i++)
{
points = outlineSegments[i];
for (j=0;j<points->size()-1;j++)
{
Vec3d point1=points->at(j);
Vec3d point2=points->at(j+1);
if (core->getUseAberration())
{
point1+=vel;
point1.normalize();
point2+=vel;
point2.normalize();
}
sPainter.drawGreatCircleArc(point1, point2, &viewportHalfspace);
}
}
sPainter.setLineSmooth(false);
}
}
void Nebula::drawHints(StelPainter& sPainter, float maxMagHints, StelCore *core) const
{
size_t segments = outlineSegments.size();
if (segments>0 && flagUseOutlines)
return;
Vec3d win;
// Check visibility of DSO hints
if (!(sPainter.getProjector()->projectCheck(XYZ, win)))
return;
if (getVisibilityLevelByMagnitude()>maxMagHints)
return;
Vec3f color = getHintColor(nType);
const float size = 6.0f;
float scaledSize = 0.0f;
if (drawHintProportional)
scaledSize = static_cast<float>(getAngularRadius(Q_NULLPTR)) *(M_PI_180f*2.f)*static_cast<float>(sPainter.getProjector()->getPixelPerRadAtCenter());
float finalSize=qMax(size, scaledSize);
switch (nType)
{
case NebGx:
case NebIGx:
case NebAGx:
case NebQSO:
case NebPossQSO:
case NebBLL:
case NebBLA:
case NebRGx:
case NebGxCl:
if (finalSize > 35.f)
Nebula::texGalaxyLarge->bind();
else
Nebula::texGalaxy->bind();
break;
case NebOc:
case NebSA:
case NebSC:
case NebCl:
if (finalSize > 75.f)
Nebula::texOpenClusterXLarge->bind();
else if (finalSize > 35.f)
Nebula::texOpenClusterLarge->bind();
else
Nebula::texOpenCluster->bind();
break;
case NebGc:
if (finalSize > 35.f)
Nebula::texGlobularClusterLarge->bind();
else
Nebula::texGlobularCluster->bind();
break;
case NebN:
case NebHII:
case NebMolCld:
case NebYSO:
case NebRn:
case NebSNR:
case NebBn:
case NebEn:
case NebSNC:
case NebSNRC:
if (finalSize > 75.f)
Nebula::texDiffuseNebulaXLarge->bind();
else if (finalSize > 35.f)
Nebula::texDiffuseNebulaLarge->bind();
else
Nebula::texDiffuseNebula->bind();
break;
case NebPn:
case NebPossPN:
case NebPPN:
Nebula::texPlanetaryNebula->bind();
break;
case NebDn:
if (finalSize > 35.f)
Nebula::texDarkNebulaLarge->bind();
else
Nebula::texDarkNebula->bind();
break;
case NebCn:
if (finalSize > 35.f)
Nebula::texOpenClusterWithNebulosityLarge->bind();
else
Nebula::texOpenClusterWithNebulosity->bind();
break;
case NebRegion:
finalSize = size*2.f;
Nebula::texRegion->bind();
break;
//case NebEMO:
//case NebStar:
//case NebSymbioticStar:
//case NebEmissionLineStar:
default:
if (finalSize > 35.f)
Nebula::texCircleLarge->bind();
else
Nebula::texCircle->bind();
}
float lum = 1.f;
Vec3f col(color*lum*hintsBrightness);
if (!objectInDisplayedType())
col.set(0.f,0.f,0.f);
sPainter.setColor(col, 1);
sPainter.setBlending(true, GL_ONE, GL_ONE);
// Rotation looks good only for galaxies.
if ((nType <=NebQSO) || (nType==NebBLA) || (nType==NebBLL) )
{
// The rotation angle in drawSprite2dMode() is relative to screen. Make sure to compute correct angle from 90+orientationAngle.
// Find an on-screen direction vector from a point offset somewhat in declination from our object.
Vec3d XYZrel(getJ2000EquatorialPos(core));
XYZrel[2]*=0.95; XYZrel.normalize();
Vec3d XYrel;
sPainter.getProjector()->project(XYZrel, XYrel);
float screenAngle = static_cast<float>(atan2(XYrel[1]-XY[1], XYrel[0]-XY[0]));
sPainter.drawSprite2dMode(static_cast<float>(XY[0]), static_cast<float>(XY[1]), finalSize, screenAngle*M_180_PIf + orientationAngle);
}
else // no galaxy
sPainter.drawSprite2dMode(static_cast<float>(XY[0]), static_cast<float>(XY[1]), finalSize);
}
void Nebula::drawLabel(StelPainter& sPainter, float maxMagLabel) const
{
Vec3d win;
// Check visibility of DSO labels
if (!(sPainter.getProjector()->projectCheck(XYZ, win)))
return;
if (getVisibilityLevelByMagnitude()>maxMagLabel)
return;
sPainter.setColor(labelColor, objectInDisplayedType() ? hintsBrightness : 0.f);
const float size = static_cast<float>(getAngularRadius(Q_NULLPTR))*(M_PI_180f*2.f)*sPainter.getProjector()->getPixelPerRadAtCenter();
const float shift = 5.f + (drawHintProportional ? size*0.9f : 0.f);
QString str = getNameI18n();
if (str.isEmpty() || designationUsage)
str = getDSODesignation();
sPainter.drawText(static_cast<float>(XY[0])+shift, static_cast<float>(XY[1])+shift, str, 0, 0, 0, false);
}
QString Nebula::getDSODesignation() const
{
QString str = "";
// Get designation for DSO with priority as given here.
if (catalogFilters&CatM && M_nb>0)
str = QString("M %1").arg(M_nb);
else if (catalogFilters&CatC && C_nb>0)
str = QString("C %1").arg(C_nb);
else if (catalogFilters&CatNGC && NGC_nb>0)
str = QString("NGC %1").arg(NGC_nb);
else if (catalogFilters&CatIC && IC_nb>0)
str = QString("IC %1").arg(IC_nb);
else if (catalogFilters&CatB && B_nb>0)
str = QString("B %1").arg(B_nb);
else if (catalogFilters&CatSh2 && Sh2_nb>0)
str = QString("SH 2-%1").arg(Sh2_nb);
else if (catalogFilters&CatVdB && VdB_nb>0)
str = QString("vdB %1").arg(VdB_nb);
else if (catalogFilters&CatRCW && RCW_nb>0)
str = QString("RCW %1").arg(RCW_nb);
else if (catalogFilters&CatLDN && LDN_nb>0)
str = QString("LDN %1").arg(LDN_nb);
else if (catalogFilters&CatLBN && LBN_nb > 0)
str = QString("LBN %1").arg(LBN_nb);
else if (catalogFilters&CatCr && Cr_nb > 0)
str = QString("Cr %1").arg(Cr_nb);
else if (catalogFilters&CatMel && Mel_nb > 0)
str = QString("Mel %1").arg(Mel_nb);
else if (catalogFilters&CatPGC && PGC_nb > 0)
str = QString("PGC %1").arg(PGC_nb);
else if (catalogFilters&CatUGC && UGC_nb > 0)
str = QString("UGC %1").arg(UGC_nb);
else if (catalogFilters&CatCed && !Ced_nb.isEmpty())
str = QString("Ced %1").arg(Ced_nb);
else if (catalogFilters&CatArp && Arp_nb > 0)
str = QString("Arp %1").arg(Arp_nb);
else if (catalogFilters&CatVV && VV_nb > 0)
str = QString("VV %1").arg(VV_nb);
else if (catalogFilters&CatPK && !PK_nb.isEmpty())
str = QString("PK %1").arg(PK_nb);
else if (catalogFilters&CatPNG && !PNG_nb.isEmpty())
str = QString("PN G%1").arg(PNG_nb);
else if (catalogFilters&CatSNRG && !SNRG_nb.isEmpty())
str = QString("SNR G%1").arg(SNRG_nb);
else if (catalogFilters&CatACO && !ACO_nb.isEmpty())
str = QString("Abell %1").arg(ACO_nb);
else if (catalogFilters&CatHCG && !HCG_nb.isEmpty())
str = QString("HCG %1").arg(HCG_nb);
else if (catalogFilters&CatESO && !ESO_nb.isEmpty())
str = QString("ESO %1").arg(ESO_nb);
else if (catalogFilters&CatVdBH && !VdBH_nb.isEmpty())
str = QString("vdBH %1").arg(VdBH_nb);
else if (catalogFilters&CatDWB && DWB_nb > 0)
str = QString("DWB %1").arg(DWB_nb);
else if (catalogFilters&CatTr && Tr_nb > 0)
str = QString("Tr %1").arg(Tr_nb);
else if (catalogFilters&CatSt && St_nb > 0)
str = QString("St %1").arg(St_nb);
else if (catalogFilters&CatRu && Ru_nb > 0)
str = QString("Ru %1").arg(Ru_nb);
else if (catalogFilters&CatVdBHa && VdBHa_nb > 0)
str = QString("vdB-Ha %1").arg(VdBHa_nb);
return str;
}
QString Nebula::getDSODesignationWIC() const
{
if (!withoutID)
return designations.first();
else
return QString();
}
void Nebula::readDSO(QDataStream &in)
{
float ra, dec;
unsigned int oType;
in >> DSO_nb >> ra >> dec >> bMag >> vMag >> oType >> mTypeString >> majorAxisSize >> minorAxisSize
>> orientationAngle >> redshift >> redshiftErr >> parallax >> parallaxErr >> oDistance >> oDistanceErr
>> NGC_nb >> IC_nb >> M_nb >> C_nb >> B_nb >> Sh2_nb >> VdB_nb >> RCW_nb >> LDN_nb >> LBN_nb >> Cr_nb
>> Mel_nb >> PGC_nb >> UGC_nb >> Ced_nb >> Arp_nb >> VV_nb >> PK_nb >> PNG_nb >> SNRG_nb >> ACO_nb
>> HCG_nb >> ESO_nb >> VdBH_nb >> DWB_nb >> Tr_nb >> St_nb >> Ru_nb >> VdBHa_nb;
const unsigned int f = NGC_nb + IC_nb + M_nb + C_nb + B_nb + Sh2_nb + VdB_nb + RCW_nb + LDN_nb + LBN_nb + Cr_nb + Mel_nb + PGC_nb + UGC_nb + Arp_nb + VV_nb + DWB_nb + Tr_nb + St_nb + Ru_nb + VdBHa_nb;
if (f==0 && Ced_nb.isEmpty() && PK_nb.isEmpty() && PNG_nb.isEmpty() && SNRG_nb.isEmpty() && ACO_nb.isEmpty() && HCG_nb.isEmpty() && ESO_nb.isEmpty() && VdBH_nb.isEmpty())
withoutID = true;
if (M_nb > 0) designations << QString("M %1").arg(M_nb);
if (C_nb > 0) designations << QString("C %1").arg(C_nb);
if (NGC_nb > 0) designations << QString("NGC %1").arg(NGC_nb);
if (IC_nb > 0) designations << QString("IC %1").arg(IC_nb);
if (B_nb > 0) designations << QString("B %1").arg(B_nb);
if (Sh2_nb > 0) designations << QString("SH 2-%1").arg(Sh2_nb);
if (VdB_nb > 0) designations << QString("vdB %1").arg(VdB_nb);
if (RCW_nb > 0) designations << QString("RCW %1").arg(RCW_nb);
if (LDN_nb > 0) designations << QString("LDN %1").arg(LDN_nb);
if (LBN_nb > 0) designations << QString("LBN %1").arg(LBN_nb);
if (Cr_nb > 0) designations << QString("Cr %1").arg(Cr_nb);
if (Mel_nb > 0) designations << QString("Mel %1").arg(Mel_nb);
if (PGC_nb > 0) designations << QString("PGC %1").arg(PGC_nb);
if (UGC_nb > 0) designations << QString("UGC %1").arg(UGC_nb);
if (!Ced_nb.isEmpty()) designations << QString("Ced %1").arg(Ced_nb);
if (Arp_nb > 0) designations << QString("Arp %1").arg(Arp_nb);