Skip to content

Commit

Permalink
Draw crater type NomenclatureItems as ellipse
Browse files Browse the repository at this point in the history
  • Loading branch information
gzotti committed Jul 25, 2023
1 parent 9ae98aa commit 58f0be9
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 31 deletions.
39 changes: 39 additions & 0 deletions src/core/StelPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,45 @@ void StelPainter::drawCircle(float x, float y, float r)
enableClientStates(false);
}

// rx: radius in x axis
// ry: radius in y axis
// angle rotation (counterclockwise), radians [0..2pi]
void StelPainter::drawEllipse(float x, float y, float rX, float rY, float angle)
{
if (rX <= 1.0f || rY <= 1.0f)
return;
// Taken largely from Nebula::renderEllipticMarker()
// Take into account device pixel density and global scale ratio, as we are drawing 2D stuff.
const auto pixelRatio = getProjector()->getDevicePixelsPerPixel();
const auto scale = pixelRatio * StelApp::getInstance().getGlobalScalingRatio();
rX *= scale;
rY *= scale;

//const float radiusY = 0.35 * size;
//const float radiusX = aspectRatio * radiusY;
const int numPoints = std::lround(std::clamp(qMax(rX, rY)/3, 32.f, 1024.f));
std::vector<float> vertexData;
vertexData.reserve(numPoints*2);
const float*const cossin = StelUtils::ComputeCosSinTheta(numPoints);
const auto cosa = std::cos(angle);
const auto sina = std::sin(angle);
for(int n = 0; n < numPoints; ++n)
{
const auto cosb = cossin[2*n], sinb = cossin[2*n+1];
const auto pointX = rX*sinb;
const auto pointY = rY*cosb;
vertexData.push_back(x + pointX*cosa - pointY*sina);
vertexData.push_back(y + pointY*cosa + pointX*sina);
}
const auto vertCount = vertexData.size() / 2;
setLineSmooth(true);
setLineWidth(scale * std::clamp(qMax(rX, rY)/40, 1.f, 2.f));
enableClientStates(true);
setVertexPointer(2, GL_FLOAT, vertexData.data());
drawFromArray(StelPainter::LineLoop, vertCount, 0, false);
enableClientStates(false);
}

void StelPainter::drawSprite2dMode(float x, float y, float radius)
{
static float vertexData[] = {-10.,-10.,10.,-10., 10.,10., -10.,10.};
Expand Down
6 changes: 6 additions & 0 deletions src/core/StelPainter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class StelPainter : protected QOpenGLFunctions
//! Draw a simple circle, 2d viewport coordinates in pixel
void drawCircle(float x, float y, float r);

//! Draw a simple ellipse, 2d viewport coordinates in pixel
//! @param rx: radius in x axis
//! @param ry: radius in y axis
//! @param angle: rotation (counterclockwise), radians [0..2pi]
void drawEllipse(float x, float y, float rx, float ry, float angle);

//! Draw a square using the current texture at the given projected 2d position.
//! This method is not thread safe.
//! @param x x position in the viewport in pixel.
Expand Down
54 changes: 30 additions & 24 deletions src/core/modules/NomenclatureItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

const QString NomenclatureItem::NOMENCLATURE_TYPE = QStringLiteral("NomenclatureItem");
Vec3f NomenclatureItem::color = Vec3f(0.1f,1.0f,0.1f);
bool NomenclatureItem::flagOutlineCraters = false;
bool NomenclatureItem::hideLocalNomenclature = false;
bool NomenclatureItem::showTerminatorZoneOnly = false;
int NomenclatureItem::terminatorMinAltitude=-2;
Expand Down Expand Up @@ -355,23 +356,23 @@ float NomenclatureItem::getAngularDiameterRatio(const StelCore *core) const

void NomenclatureItem::draw(StelCore* core, StelPainter *painter)
{
// show special points only?
if (getFlagShowSpecialNomenclatureOnly() && nType<NomenclatureItem::niSpecialPointPole)
return;

if (getFlagHideLocalNomenclature() && planet==core->getCurrentPlanet())
return;

// Called by NomenclatureMgr, so we don't need to check if labelsFader is true.
// The painter has been set to enable blending.
const Vec3d equPos = planet->getJ2000EquatorialPos(core);
Vec3d XYZ = getJ2000EquatorialPos(core);
const 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.normSquared() < 150.*150.*AU_KM*AU_KM )
return;

if (getFlagHideLocalNomenclature())
{
// Check the state when needed only!
if (planet==core->getCurrentPlanet())
return;
}

const double screenSize = 2.*getAngularRadius(core)*M_PI_180*static_cast<double>(painter->getProjector()->getPixelPerRadAtCenter());
const double screenRadius = getAngularRadius(core)*M_PI_180*static_cast<double>(painter->getProjector()->getPixelPerRadAtCenter());

// We can use ratio of angular size to the FOV to checking visibility of features also!
// double scale = getAngularSize(core)/painter->getProjector()->getFov();
Expand All @@ -380,29 +381,34 @@ void NomenclatureItem::draw(StelCore* core, StelPainter *painter)
// check visibility of feature
Vec3d srcPos;
const float scale = getAngularDiameterRatio(core);
NomenclatureItem::NomenclatureItemType niType = getNomenclatureType();

if (getFlagShowSpecialNomenclatureOnly())
{
// show special points only
if (niType<NomenclatureItem::niSpecialPointPole)
return;
}

if (painter->getProjector()->projectCheck(XYZ, srcPos) && (equPos.normSquared() >= XYZ.normSquared())
&& (scale>0.04f && (scale<0.5f || niType>=NomenclatureItem::niSpecialPointPole )))
&& (scale>0.04f && (scale<0.5f || nType>=NomenclatureItem::niSpecialPointPole )))
{
const float solarAltitude=getSolarAltitude(core);
// Throw out real items if not along the terminator?
if ( (niType<NomenclatureItem::niSpecialPointPole) && showTerminatorZoneOnly && (solarAltitude > terminatorMaxAltitude || solarAltitude < terminatorMinAltitude) )
if ( (nType<NomenclatureItem::niSpecialPointPole) && showTerminatorZoneOnly && (solarAltitude > terminatorMaxAltitude || solarAltitude < terminatorMinAltitude) )
return;
float brightness=(solarAltitude<0. ? 0.25f : 1.0f);
if (niType>=NomenclatureItem::niSpecialPointPole)
brightness = 0.5f;
const float brightness=(nType>=NomenclatureItem::niSpecialPointPole ? 0.5f : (solarAltitude<0. ? 0.25f : 1.0f));
painter->setColor(color*brightness, labelsFader.getInterstate());
painter->drawCircle(static_cast<float>(srcPos[0]), static_cast<float>(srcPos[1]), 2.f);
if (nType==niCrater || nType==niSatelliteFeature) // probably all satellite features are satellite craters
painter->drawCircle(static_cast<float>(srcPos[0]), static_cast<float>(srcPos[1]), screenSize/2.);
if (flagOutlineCraters && (nType==niCrater || nType==niSatelliteFeature)) // probably all satellite features are satellite craters
{
// Compute aspectRatio and angle from position of planet and own position, parallactic angle, ...
double ra, de, raPl, dePl;
StelUtils::rectToSphe(&ra, &de, XYZ);
StelUtils::rectToSphe(&raPl, &dePl, equPos);
const double distDegrees=StelLocation::distanceDegrees(raPl*M_180_PIf, dePl*M_180_PIf, ra*M_180_PIf, de*M_180_PIf);
const double plRadiusDeg=planet->getAngularRadius(core);
const double sinDistCenter=distDegrees/plRadiusDeg; // 0...1
if (sinDistCenter>1.f)
qWarning() << "Distance greater 1";
const double angleDistCenterRad=asin(sinDistCenter); // 0..pi/2 on the lunar/planet sphere
const double aspectRatio=cos(angleDistCenterRad);
const double angle=atan2(ra-raPl, de-dePl);
const double par = static_cast<double>(getParallacticAngle(core));
painter->drawEllipse(static_cast<float>(srcPos[0]), static_cast<float>(srcPos[1]), screenRadius, screenRadius*aspectRatio, angle-par );
}
painter->drawText(static_cast<float>(srcPos[0]), static_cast<float>(srcPos[1]), nameI18n, 0, 5.f, 5.f, false);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core/modules/NomenclatureItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class NomenclatureItem : public StelObject
mutable Vec3d XYZ; // holds J2000 position in space (i.e. including planet position, offset from planetocenter)
mutable double jde; // jde time of XYZ value
static Vec3f color;
static bool flagOutlineCraters; // draw craters and satellite features as ellipses?
static bool hideLocalNomenclature;
static bool showTerminatorZoneOnly;
static int terminatorMinAltitude;
Expand Down
12 changes: 12 additions & 0 deletions src/core/modules/NomenclatureMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void NomenclatureMgr::init()
setFlagShowTerminatorZoneOnly(conf->value("astro/flag_planets_nomenclature_terminator_only", false).toBool());
setTerminatorMinAltitude(conf->value("astro/planet_nomenclature_solar_altitude_min", -5).toInt());
setTerminatorMaxAltitude(conf->value("astro/planet_nomenclature_solar_altitude_max", 40).toInt());
setFlagOutlineCraters(conf->value("astro/flag_planets_nomenclature_outline_craters", false).toBool());
setFlagHideLocalNomenclature(conf->value("astro/flag_hide_local_nomenclature", true).toBool());
setFlagShowSpecialNomenclatureOnly(conf->value("astro/flag_special_nomenclature_only", false).toBool());

Expand Down Expand Up @@ -553,6 +554,17 @@ int NomenclatureMgr::getTerminatorMaxAltitude() const
return NomenclatureItem::terminatorMaxAltitude;
}

void NomenclatureMgr::setFlagOutlineCraters(bool b)
{
NomenclatureItem::flagOutlineCraters = b;
emit flagOutlineCratersChanged(b);
}

bool NomenclatureMgr::getFlagOutlineCraters() const
{
return NomenclatureItem::flagOutlineCraters;
}

void NomenclatureMgr::setFlagHideLocalNomenclature(bool b)
{
NomenclatureItem::hideLocalNomenclature = b;
Expand Down
7 changes: 7 additions & 0 deletions src/core/modules/NomenclatureMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class NomenclatureMgr : public StelObjectModule
Q_PROPERTY(bool flagShowTerminatorZoneOnly READ getFlagShowTerminatorZoneOnly WRITE setFlagShowTerminatorZoneOnly NOTIFY flagShowTerminatorZoneOnlyChanged)
Q_PROPERTY(int terminatorMinAltitude READ getTerminatorMinAltitude WRITE setTerminatorMinAltitude NOTIFY terminatorMinAltitudeChanged)
Q_PROPERTY(int terminatorMaxAltitude READ getTerminatorMaxAltitude WRITE setTerminatorMaxAltitude NOTIFY terminatorMaxAltitudeChanged)
Q_PROPERTY(bool flagOutlineCraters READ getFlagOutlineCraters WRITE setFlagOutlineCraters NOTIFY flagOutlineCratersChanged)
Q_PROPERTY(bool flagHideLocalNomenclature READ getFlagHideLocalNomenclature WRITE setFlagHideLocalNomenclature NOTIFY localNomenclatureHidingChanged)
Q_PROPERTY(bool specialNomenclatureOnlyDisplayed READ getFlagShowSpecialNomenclatureOnly WRITE setFlagShowSpecialNomenclatureOnly NOTIFY specialNomenclatureOnlyDisplayingChanged)
Q_PROPERTY(Vec3f nomenclatureColor READ getColor WRITE setColor NOTIFY nomenclatureColorChanged)
Expand Down Expand Up @@ -119,6 +120,11 @@ public slots:
//! Get maximum solar altitude (degrees) to draw only nomenclature along the terminator.
int getTerminatorMaxAltitude() const;

//! Set flag which determines if craters and satellite features (which are usually also craters) are outlined as ellipses.
void setFlagOutlineCraters(bool b);
//! Get the current value of the flag which determines if craters and satellite features (which are usually also craters) are outlined as ellipses.
bool getFlagOutlineCraters() const;

//! Set flag which determines if nomenclature labels are drawn or hidden on the celestial body of observer.
void setFlagHideLocalNomenclature(bool b);
//! Get the current value of the flag which determines if nomenclature labels are drawn or hidden on the celestial body of observer.
Expand All @@ -139,6 +145,7 @@ public slots:
void flagShowTerminatorZoneOnlyChanged(bool b);
void terminatorMinAltitudeChanged(int deg);
void terminatorMaxAltitudeChanged(int deg);
void flagOutlineCratersChanged(bool b);
void localNomenclatureHidingChanged(bool b);
void specialNomenclatureOnlyDisplayingChanged(bool b);
void nomenclatureColorChanged(const Vec3f & color) const;
Expand Down
1 change: 1 addition & 0 deletions src/gui/ConfigurationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ void ConfigurationDialog::saveAllSettings()
conf->setValue("astro/flag_show_obj_self_shadows", propMgr->getStelPropertyValue("SolarSystem.flagShowObjSelfShadows").toBool());
conf->setValue("astro/apparent_magnitude_algorithm", Planet::getApparentMagnitudeAlgorithmString());
conf->setValue("astro/flag_planets_nomenclature", propMgr->getStelPropertyValue("NomenclatureMgr.flagShowNomenclature").toBool());
conf->setValue("astro/flag_planets_nomenclature_outline_craters",propMgr->getStelPropertyValue("NomenclatureMgr.flagOutlineCraters").toBool());
conf->setValue("astro/flag_hide_local_nomenclature", propMgr->getStelPropertyValue("NomenclatureMgr.flagHideLocalNomenclature").toBool());
conf->setValue("astro/flag_special_nomenclature_only", propMgr->getStelPropertyValue("NomenclatureMgr.specialNomenclatureOnlyDisplayed").toBool());
conf->setValue("astro/flag_planets_nomenclature_terminator_only",propMgr->getStelPropertyValue("NomenclatureMgr.flagShowTerminatorZoneOnly").toBool());
Expand Down
1 change: 1 addition & 0 deletions src/gui/ViewDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ void ViewDialog::createDialogContent()
connectDoubleProperty(ui->planetsLabelsHorizontalSlider, "SolarSystem.labelsAmount",0.0,10.0);
connectCheckBox(ui->planetNomenclatureCheckBox, "actionShow_Planets_Nomenclature");
connectColorButton(ui->planetNomenclatureColor, "NomenclatureMgr.nomenclatureColor", "color/planet_nomenclature_color");
connectBoolProperty(ui->outlineCratersCheckBox, "NomenclatureMgr.flagOutlineCraters");
connectColorButton(ui->planetLabelColor, "SolarSystem.labelsColor", "color/planet_names_color");
connectColorButton(ui->planetTrailsColor, "SolarSystem.trailsColor", "color/object_trails_color");
connectBoolProperty(ui->planetTrailsCheckBox, "SolarSystem.trailsDisplayed");
Expand Down
25 changes: 18 additions & 7 deletions src/gui/viewDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2021,11 +2021,22 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="showSpecialNomenclatureOnlyCheckBox">
<property name="text">
<string>Show special nomenclature points only</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_Nomenclature">
<item>
<widget class="QCheckBox" name="outlineCratersCheckBox">
<property name="text">
<string>Outline craters</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showSpecialNomenclatureOnlyCheckBox">
<property name="text">
<string>Show special nomenclature points only</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
Expand Down Expand Up @@ -5690,12 +5701,12 @@
</resources>
<connections/>
<buttongroups>
<buttongroup name="buttonGroupDisplayedDSOCatalogs">
<buttongroup name="buttonGroupDisplayedDSOTypes">
<property name="exclusive">
<bool>false</bool>
</property>
</buttongroup>
<buttongroup name="buttonGroupDisplayedDSOTypes">
<buttongroup name="buttonGroupDisplayedDSOCatalogs">
<property name="exclusive">
<bool>false</bool>
</property>
Expand Down

0 comments on commit 58f0be9

Please sign in to comment.