Polish and docs for RenderableDistanceLabel and docs for RenderableNodeLine (#3485)

* Update add add documentation for `RenderableDistanceLabel`

* Move distancelabel to `base` module and remove now empty `vislab` module

* Add examples for `RenderableNodeLine` and `RenderableDistanceLabel`

* Fix faultily formatted documentation ID for `RenderableNodeLine`

* Make `RenderableDistanceLabel` unit use units from distanceconversion file

And simplify how the different names for a unit are specified

* Use new distanceUnitList() function for other classes that uses the units

* Change default unit to correct option according to documentation

* Make the text property readonly for `RenderableDistanceLabel`

* Add property to specify the precision of the number

distance label precision to docs

* Add examples with different units and descriptors

* Add docs description to `RenderableNodeLine`

* Update name in one of the examples

* Remove redundant switch cases

* Apply suggestions from code review

Co-authored-by: Ylva Selling <ylva.selling@gmail.com>

---------

Co-authored-by: Ylva Selling <ylva.selling@gmail.com>
This commit is contained in:
Emma Broman
2025-01-29 16:11:47 +01:00
committed by GitHub
parent ad0e5b92dc
commit 3d3580fa65
18 changed files with 267 additions and 346 deletions

View File

@@ -0,0 +1,27 @@
-- Basic
-- This example adds a distance label between two nodes in the scene, based on an existing
-- [RenderableNodeLine](#base_renderable_nodeline). Note that the identifier of the
-- `RenderableNodeLine` is accessed by importing another example asset, which also adds
-- the node line to the scene.
local nodelineAsset = asset.require("examples/renderable/renderablenodeline/nodeline")
local Node = {
Identifier = "RenderableDistanceLabel_Example",
Renderable = {
Type = "RenderableDistanceLabel",
NodeLine = nodelineAsset.NodeLine.Identifier
},
GUI = {
Name = "RenderableDistanceLabel - Basic",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)

View File

@@ -0,0 +1,27 @@
-- Set Unit
-- Per default, the distance is displayed in meters. This example shows how to specify a
-- specific unit, and how to set the precision of dislayed number.
local nodelineAsset = asset.require("examples/renderable/renderablenodeline/nodeline")
local Node = {
Identifier = "RenderableDistanceLabel_Example_Unit",
Renderable = {
Type = "RenderableDistanceLabel",
NodeLine = nodelineAsset.NodeLine.Identifier,
DistanceUnit = "AU",
Precision = 2
},
GUI = {
Name = "RenderableDistanceLabel - Unit",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)

View File

@@ -0,0 +1,29 @@
-- Custom Unit Descriptor
-- In addition to setting the unit, it is also possible to specify a custom unit
-- descriptor, i.e. a text that will de displayed for the unit instead of the default one.
-- Here, we write out "Astronomical Units" instead of using the default descriptor for AU.
local nodelineAsset = asset.require("examples/renderable/renderablenodeline/nodeline")
local Node = {
Identifier = "RenderableDistanceLabel_Example_CustomDescriptor",
Renderable = {
Type = "RenderableDistanceLabel",
NodeLine = nodelineAsset.NodeLine.Identifier,
DistanceUnit = "AU",
Precision = 2,
CustomUnitDescriptor = "Astronomical Units"
},
GUI = {
Name = "RenderableDistanceLabel - Custom Unit Descriptor",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)

View File

@@ -0,0 +1,35 @@
-- Basic
-- This example draws a line between two nodes in the scene, in this case the planets
-- Earth and Mars.
--
-- Note that this example asset is used in another example, for
-- [RenderableDistanceLabel](#base_renderable_distancelabel). Due to this, we export the
-- `Node` table so we can access and refer to its identifier in the other example, the
-- same way as we do for Earth and Mars in this asset.
local earth = asset.require("scene/solarsystem/planets/earth/earth")
local mars = asset.require("scene/solarsystem/planets/mars/mars")
local Node = {
Identifier = "RenderableNodeLine_Example",
Renderable = {
Type = "RenderableNodeLine",
StartNode = earth.Earth.Identifier,
EndNode = mars.Mars.Identifier
},
GUI = {
Name = "RenderableNodeLine - Basic",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)
-- Export the Node table so it can be used in another example
asset.export("NodeLine", Node)

View File

@@ -65,60 +65,11 @@ enum class DistanceUnit {
League
};
// Assumption: Unit names are sequential in memory
constexpr std::string_view DistanceUnitNanometer = "Nanometer";
constexpr std::string_view DistanceUnitMicrometer = "Micrometer";
constexpr std::string_view DistanceUnitMillimeter = "Millimeter";
constexpr std::string_view DistanceUnitCentimeter = "Centimeter";
constexpr std::string_view DistanceUnitDecimeter = "Decimeter";
constexpr std::string_view DistanceUnitMeter = "Meter";
constexpr std::string_view DistanceUnitKilometer = "Kilometer";
constexpr std::string_view DistanceUnitAU = "AU";
constexpr std::string_view DistanceUnitLighthour = "Lighthour";
constexpr std::string_view DistanceUnitLightday = "Lightday";
constexpr std::string_view DistanceUnitLightmonth = "Lightmonth";
constexpr std::string_view DistanceUnitLightyear = "Lightyear";
constexpr std::string_view DistanceUnitParsec = "Parsec";
constexpr std::string_view DistanceUnitKiloparsec = "Kiloparsec";
constexpr std::string_view DistanceUnitMegaparsec = "Megaparsec";
constexpr std::string_view DistanceUnitGigaparsec = "Gigaparsec";
constexpr std::string_view DistanceUnitGigalightyear = "Gigalightyear";
constexpr std::string_view DistanceUnitThou = "Thou";
constexpr std::string_view DistanceUnitInch = "Inch";
constexpr std::string_view DistanceUnitFoot = "Foot";
constexpr std::string_view DistanceUnitYard = "Yard";
constexpr std::string_view DistanceUnitChain = "Chain";
constexpr std::string_view DistanceUnitFurlong = "Furlong";
constexpr std::string_view DistanceUnitMile = "Mile";
constexpr std::string_view DistanceUnitLeague = "League";
// Assumption: Unit names are sequential in memory
constexpr std::string_view DistanceUnitNanometers = "Nanometers";
constexpr std::string_view DistanceUnitMicrometers = "Micrometers";
constexpr std::string_view DistanceUnitMillimeters = "Millimeters";
constexpr std::string_view DistanceUnitCentimeters = "Centimeters";
constexpr std::string_view DistanceUnitDecimeters = "Decimeters";
constexpr std::string_view DistanceUnitMeters = "Meters";
constexpr std::string_view DistanceUnitKilometers = "Kilometers";
constexpr std::string_view DistanceUnitAUs = "AU";
constexpr std::string_view DistanceUnitLighthours = "Lighthours";
constexpr std::string_view DistanceUnitLightdays = "Lightdays";
constexpr std::string_view DistanceUnitLightmonths = "Lightmonths";
constexpr std::string_view DistanceUnitLightyears = "Lightyears";
constexpr std::string_view DistanceUnitParsecs = "Parsecs";
constexpr std::string_view DistanceUnitKiloparsecs = "Kiloparsecs";
constexpr std::string_view DistanceUnitMegaparsecs = "Megaparsecs";
constexpr std::string_view DistanceUnitGigaparsecs = "Gigaparsecs";
constexpr std::string_view DistanceUnitGigalightyears = "Gigalightyears";
constexpr std::string_view DistanceUnitThous = "Thou";
constexpr std::string_view DistanceUnitInches = "Inches";
constexpr std::string_view DistanceUnitFeet = "Feet";
constexpr std::string_view DistanceUnitYards = "Yards";
constexpr std::string_view DistanceUnitChains = "Chains";
constexpr std::string_view DistanceUnitFurlongs = "Furlongs";
constexpr std::string_view DistanceUnitMiles = "Miles";
constexpr std::string_view DistanceUnitLeagues = "Leagues";
struct DistanceUnitName {
std::string_view singular;
std::string_view plural;
std::string_view abbreviation;
};
constexpr std::array<DistanceUnit, static_cast<int>(DistanceUnit::League) + 1>
DistanceUnits = {
@@ -132,114 +83,85 @@ DistanceUnits = {
DistanceUnit::Furlong, DistanceUnit::Mile, DistanceUnit::League
};
constexpr std::array<std::string_view, static_cast<int>(DistanceUnit::League) + 1>
DistanceUnitNamesSingular = {
DistanceUnitNanometer, DistanceUnitMicrometer, DistanceUnitMillimeter,
DistanceUnitCentimeter, DistanceUnitDecimeter, DistanceUnitMeter,
DistanceUnitKilometer, DistanceUnitAU, DistanceUnitLighthour,
DistanceUnitLightday, DistanceUnitLightmonth, DistanceUnitLightyear,
DistanceUnitParsec, DistanceUnitKiloparsec, DistanceUnitMegaparsec,
DistanceUnitGigaparsec, DistanceUnitGigalightyear, DistanceUnitThou, DistanceUnitInch,
DistanceUnitFoot, DistanceUnitYard, DistanceUnitChain, DistanceUnitFurlong,
DistanceUnitMile, DistanceUnitLeague
};
constexpr std::array<std::string_view, static_cast<int>(DistanceUnit::League) + 1>
DistanceUnitNamesPlural = {
DistanceUnitNanometers, DistanceUnitMicrometers, DistanceUnitMillimeters,
DistanceUnitCentimeters, DistanceUnitDecimeters, DistanceUnitMeters,
DistanceUnitKilometers, DistanceUnitAUs, DistanceUnitLighthours,
DistanceUnitLightdays, DistanceUnitLightmonths, DistanceUnitLightyears,
DistanceUnitParsecs, DistanceUnitKiloparsecs, DistanceUnitMegaparsecs,
DistanceUnitGigaparsecs, DistanceUnitGigalightyears, DistanceUnitThous,
DistanceUnitInches, DistanceUnitFeet, DistanceUnitYards, DistanceUnitChains,
DistanceUnitFurlongs, DistanceUnitMile, DistanceUnitLeague
};
// Note that the syntax here is required when initializing constexpr std::arrays with structs
constexpr std::array<DistanceUnitName, static_cast<int>(DistanceUnit::League) + 1>
DistanceUnitNames {{
{ "Nanometer", "Nanometers", "nm" },
{ "Micrometer", "Micrometers", "um" },
{ "Millimeter", "Millimeters", "mm" },
{ "Centimeter", "Centimeters", "cm" },
{ "Decimeter", "Decimeters", "dm" },
{ "Meter", "Meters", "m" },
{ "Kilometer", "Kilometers", "km" },
{ "AU", "AU", "au" },
{ "Lighthour", "Lighthours", "lh" },
{ "Lightday", "Lightdays", "ld" },
{ "Lightmonth", "Lightmonths", "lm" },
{ "Lightyear", "Lightyears", "ly" },
{ "Parsec", "Parsecs", "pc" },
{ "Kiloparsec", "Kiloparsecs", "kpc" },
{ "Megaparsec", "Megaparsecs", "Mpc" },
{ "Gigaparsec", "Gigaparsecs", "Gpc" },
{ "Gigalightyear", "Gigalightyears", "Gly" },
{ "Thou", "Thou", "th" },
{ "Inch", "Inches", "in" },
{ "Foot", "Feet", "ft" },
{ "Yard", "Yards", "yd" },
{ "Chain", "Chains", "ch" },
{ "Furlong", "Furlongs", "fur" },
{ "Mile", "Miles", "mi" },
{ "League", "Leagues", "league"}
}};
constexpr bool isValidDistanceUnitName(std::string_view name) {
for (std::string_view val : DistanceUnitNamesSingular) {
if (val == name) {
return true;
}
}
for (std::string_view val : DistanceUnitNamesPlural) {
if (val == name) {
for (DistanceUnit unit : DistanceUnits) {
const DistanceUnitName unitName = DistanceUnitNames[static_cast<int>(unit)];
if (name == unitName.singular || name == unitName.plural ||
name == unitName.abbreviation)
{
return true;
}
}
return false;
}
constexpr std::string_view nameForDistanceUnit(DistanceUnit unit, bool pluralForm = false)
constexpr std::string_view nameForDistanceUnit(DistanceUnit unit, bool usePluralForm = false)
{
switch (unit) {
case DistanceUnit::Nanometer:
case DistanceUnit::Micrometer:
case DistanceUnit::Millimeter:
case DistanceUnit::Centimeter:
case DistanceUnit::Decimeter:
case DistanceUnit::Meter:
case DistanceUnit::Kilometer:
case DistanceUnit::AU:
case DistanceUnit::Lighthour:
case DistanceUnit::Lightday:
case DistanceUnit::Lightmonth:
case DistanceUnit::Lightyear:
case DistanceUnit::Parsec:
case DistanceUnit::Kiloparsec:
case DistanceUnit::Megaparsec:
case DistanceUnit::Gigaparsec:
case DistanceUnit::Gigalightyear:
case DistanceUnit::Thou:
case DistanceUnit::Inch:
case DistanceUnit::Foot:
case DistanceUnit::Yard:
case DistanceUnit::Chain:
case DistanceUnit::Furlong:
case DistanceUnit::Mile:
case DistanceUnit::League:
if (pluralForm) {
return DistanceUnitNamesPlural[static_cast<int>(unit)];
}
else {
return DistanceUnitNamesSingular[static_cast<int>(unit)];
}
default:
throw ghoul::MissingCaseException();
}
const DistanceUnitName unitName = DistanceUnitNames[static_cast<int>(unit)];
return usePluralForm ? unitName.plural : unitName.singular;
}
constexpr std::string_view abbreviationForDistanceUnit(DistanceUnit unit) {
return DistanceUnitNames[static_cast<int>(unit)].abbreviation;
}
constexpr DistanceUnit distanceUnitFromString(std::string_view unitName) {
int found = -1;
int i = 0;
for (std::string_view val : DistanceUnitNamesSingular) {
if (val == unitName) {
found = i;
break;
for (DistanceUnit unit : DistanceUnits) {
const DistanceUnitName name = DistanceUnitNames[static_cast<int>(unit)];
if (name.singular == unitName || name.plural == unitName ||
name.abbreviation == unitName)
{
return static_cast<DistanceUnit>(i);
}
i++;
}
i = 0;
for (std::string_view val : DistanceUnitNamesPlural) {
if (val == unitName) {
found = i;
break;
}
i++;
}
if (found != -1) {
return static_cast<DistanceUnit>(found);
}
else {
throw ghoul::MissingCaseException();
}
throw ghoul::MissingCaseException();
}
constexpr std::vector<std::string> distanceUnitList() {
std::vector<std::string> res(DistanceUnits.size());
std::transform(
DistanceUnits.begin(),
DistanceUnits.end(),
res.begin(),
[](DistanceUnit unit) {
return std::string(nameForDistanceUnit(unit));
}
);
return res;
}
std::pair<double, std::string_view> simplifyDistance(double meters,
bool forceSingularForm = false);

View File

@@ -50,6 +50,7 @@ set(HEADER_FILES
rendering/pointcloud/sizemappingcomponent.h
rendering/renderablecartesianaxes.h
rendering/renderabledisc.h
rendering/renderabledistancelabel.h
rendering/renderablelabel.h
rendering/renderablemodel.h
rendering/renderablenodearrow.h
@@ -113,6 +114,7 @@ set(SOURCE_FILES
rendering/pointcloud/sizemappingcomponent.cpp
rendering/renderablecartesianaxes.cpp
rendering/renderabledisc.cpp
rendering/renderabledistancelabel.cpp
rendering/renderablelabel.cpp
rendering/renderablemodel.cpp
rendering/renderablenodearrow.cpp

View File

@@ -49,6 +49,7 @@
#include <modules/base/rendering/pointcloud/sizemappingcomponent.h>
#include <modules/base/rendering/renderablecartesianaxes.h>
#include <modules/base/rendering/renderabledisc.h>
#include <modules/base/rendering/renderabledistancelabel.h>
#include <modules/base/rendering/renderablelabel.h>
#include <modules/base/rendering/renderablemodel.h>
#include <modules/base/rendering/renderablenodearrow.h>
@@ -138,6 +139,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) {
fRenderable->registerClass<RenderableBoxGrid>("RenderableBoxGrid");
fRenderable->registerClass<RenderableCartesianAxes>("RenderableCartesianAxes");
fRenderable->registerClass<RenderableDisc>("RenderableDisc");
fRenderable->registerClass<RenderableDistanceLabel>("RenderableDistanceLabel");
fRenderable->registerClass<RenderableGrid>("RenderableGrid");
fRenderable->registerClass<RenderableLabel>("RenderableLabel");
fRenderable->registerClass<RenderableModel>("RenderableModel");
@@ -230,6 +232,7 @@ std::vector<documentation::Documentation> BaseModule::documentations() const {
RenderableBoxGrid::Documentation(),
RenderableCartesianAxes::Documentation(),
RenderableDisc::Documentation(),
RenderableDistanceLabel::Documentation(),
RenderableGrid::Documentation(),
RenderableInterpolatedPoints::Documentation(),
RenderableLabel::Documentation(),

View File

@@ -106,19 +106,6 @@ namespace {
openspace::properties::Property::Visibility::AdvancedUser
};
std::vector<std::string> unitList() {
std::vector<std::string> res(openspace::DistanceUnits.size());
std::transform(
openspace::DistanceUnits.begin(),
openspace::DistanceUnits.end(),
res.begin(),
[](openspace::DistanceUnit unit) {
return std::string(nameForDistanceUnit(unit));
}
);
return res;
}
struct [[codegen::Dictionary(DashboardItemDistance)]] Parameters {
enum class [[codegen::map(Type)]] TypeInfo {
Node,
@@ -143,7 +130,8 @@ namespace {
std::optional<bool> simplification;
// [[codegen::verbatim(RequestedUnitInfo.description)]]
std::optional<std::string> requestedUnit [[codegen::inlist(unitList())]];
std::optional<std::string> requestedUnit
[[codegen::inlist(openspace::distanceUnitList())]];
// [[codegen::verbatim(FormatStringInfo.description)]]
std::optional<std::string> formatString;

View File

@@ -57,25 +57,13 @@ namespace {
openspace::properties::Property::Visibility::User
};
std::vector<std::string> unitList() {
std::vector<std::string> res(openspace::DistanceUnits.size());
std::transform(
openspace::DistanceUnits.begin(),
openspace::DistanceUnits.end(),
res.begin(),
[](openspace::DistanceUnit unit) {
return std::string(nameForDistanceUnit(unit));
}
);
return res;
}
struct [[codegen::Dictionary(DashboardItemVelocity)]] Parameters {
// [[codegen::verbatim(SimplificationInfo.description)]]
std::optional<bool> simplification;
// [[codegen::verbatim(RequestedUnitInfo.description)]]
std::optional<std::string> requestedUnit [[codegen::inlist(unitList())]];
std::optional<std::string> requestedUnit
[[codegen::inlist(openspace::distanceUnitList())]];
};
#include "dashboarditemvelocity_codegen.cpp"

View File

@@ -22,7 +22,7 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/vislab/rendering/renderabledistancelabel.h>
#include <modules/base/rendering/renderabledistancelabel.h>
#include <modules/base/rendering/renderablenodeline.h>
#include <openspace/documentation/documentation.h>
@@ -30,6 +30,7 @@
#include <openspace/engine/globals.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <openspace/util/distanceconversion.h>
#include <ghoul/logging/logmanager.h>
#include <optional>
#include <string>
@@ -46,12 +47,9 @@ namespace {
openspace::properties::Property::Visibility::AdvancedUser
};
// @TODO (2024-04-26, emmbr) The unit and custom unit descriptor are confusing and
// should be reimplemented. Why are we using an int value for the unit??
constexpr openspace::properties::Property::PropertyInfo DistanceUnitInfo = {
"DistanceUnit",
"Distance Unit",
"Display Distance Unit",
"The unit in which the distance value should be displayed. Defaults to 'km' if "
"not specified.",
openspace::properties::Property::Visibility::User
@@ -61,19 +59,40 @@ namespace {
"CustomUnitDescriptor",
"Custom Unit Descriptor",
"Property to define a custom unit descriptor to use to describe the distance "
"value. Defaults to the units SI descriptor if not specified.",
"value. Defaults to the selected unit's SI descriptor if not specified.",
openspace::properties::Property::Visibility::AdvancedUser
};
constexpr openspace::properties::Property::PropertyInfo PrecisionInfo = {
"Precision",
"Precision",
"The precision in which to to show the distance number, i.e. the number of "
"digits after the decimal point.",
openspace::properties::Property::Visibility::User
};
// This `Renderable` creates a label that shows the distance between two nodes, based
// on an existing [RenderableNodeLine](#base_renderable_nodeline). The label
// will be placed halfway between the two scene graph nodes that the line connects.
//
// The unit in which the distance is displayed can be customized, as well as the
// precision of the number.
struct [[codegen::Dictionary(RenderableDistanceLabel)]] Parameters {
// [[codegen::verbatim(NodeLineInfo.description)]]
// The identifier of a scene graph node with a
// [RenderableNodeLine](#base_renderable_nodeline) that this label
// should track. The label text will be updating based on the distance from the
// node line's start and end.
std::string nodeLine;
// [[codegen::verbatim(DistanceUnitInfo.description)]]
std::optional<int> distanceUnit;
std::optional<std::string> distanceUnit
[[codegen::inlist(openspace::distanceUnitList())]];
// [[codegen::verbatim(CustomUnitDescriptorInfo.description)]]
std::optional<std::string> customUnitDescriptor;
// [[codegen::verbatim(PrecisionInfo.description)]]
std::optional<int> precision [[codegen::greaterequal(0)]];
};
#include "renderabledistancelabel_codegen.cpp"
} // namespace
@@ -81,25 +100,42 @@ namespace {
namespace openspace {
documentation::Documentation RenderableDistanceLabel::Documentation() {
return codegen::doc<Parameters>("vislab_renderable_distance_label");
return codegen::doc<Parameters>("base_renderable_distancelabel");
}
RenderableDistanceLabel::RenderableDistanceLabel(const ghoul::Dictionary& dictionary)
: RenderableLabel(dictionary)
, _nodelineId(NodeLineInfo)
, _distanceUnit(DistanceUnitInfo, 1, 0, 11)
, _distanceUnit(DistanceUnitInfo, properties::OptionProperty::DisplayType::Dropdown)
, _customUnitDescriptor(CustomUnitDescriptorInfo)
, _precision(PrecisionInfo, 0, 0, 10)
{
const Parameters p = codegen::bake<Parameters>(dictionary);
_nodelineId = p.nodeLine;
addProperty(_nodelineId);
_distanceUnit = p.distanceUnit.value_or(_distanceUnit);
for (const DistanceUnit u : DistanceUnits) {
_distanceUnit.addOption(
static_cast<int>(u),
std::string(nameForDistanceUnit(u))
);
}
_distanceUnit = static_cast<int>(DistanceUnit::Kilometer);
if (p.distanceUnit.has_value()) {
const DistanceUnit unit = distanceUnitFromString(*p.distanceUnit);
_distanceUnit = static_cast<int>(unit);
}
addProperty(_distanceUnit);
_customUnitDescriptor = p.customUnitDescriptor.value_or(_customUnitDescriptor);
addProperty(_customUnitDescriptor);
_precision = p.precision.value_or(_precision);
addProperty(_precision);
// The text will be updated automatically, so set the property to readonly
_text.setReadOnly(true);
}
void RenderableDistanceLabel::update(const UpdateData&) {
@@ -120,22 +156,18 @@ void RenderableDistanceLabel::update(const UpdateData&) {
return;
}
// Get used unit scale
const float scale = unit(_distanceUnit);
const DistanceUnit unit = static_cast<DistanceUnit>(_distanceUnit.value());
// Get unit descriptor text
std::string_view unitDescriptor = toString(_distanceUnit);
std::string_view unitDescriptor = abbreviationForDistanceUnit(unit);
if (!_customUnitDescriptor.value().empty()) {
unitDescriptor = _customUnitDescriptor;
}
// Get distance as string and remove fractional part
std::string distanceText = std::to_string(
std::round(nodeline->distance() / scale)
);
const int pos = static_cast<int>(distanceText.find('.'));
const std::string subStr = distanceText.substr(pos);
distanceText.erase(pos, subStr.size());
// Get distance as string
const double convertedDistance = convertMeters(nodeline->distance(), unit);
std::string distanceText = std::format("{:.{}f}", convertedDistance, _precision.value());
// Create final label text and set it
const std::string finalText = std::format("{} {}", distanceText, unitDescriptor);

View File

@@ -22,11 +22,15 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__
#define __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__
#ifndef __OPENSPACE_MODULE_BASE___RENDERABLEDISTANCELABEL___H__
#define __OPENSPACE_MODULE_BASE___RENDERABLEDISTANCELABEL___H__
#include <modules/base/rendering/renderablelabel.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/stringproperty.h>
namespace openspace {
namespace documentation { struct Documentation; }
@@ -40,11 +44,12 @@ public:
private:
properties::StringProperty _nodelineId;
properties::IntProperty _distanceUnit;
properties::OptionProperty _distanceUnit;
properties::StringProperty _customUnitDescriptor;
properties::IntProperty _precision;
bool _errorThrown = false;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__
#endif // __OPENSPACE_MODULE_BASE___RENDERABLEDISTANCELABEL___H__

View File

@@ -73,6 +73,8 @@ public:
protected:
properties::OptionProperty _blendMode;
properties::StringProperty _text;
float unit(int unit) const;
std::string_view toString(int unit) const;
@@ -92,8 +94,6 @@ private:
properties::FloatProperty _size;
properties::IVec2Property _minMaxSize;
properties::StringProperty _text;
properties::BoolProperty _enableFadingEffect;
properties::Vec2Property _fadeWidths;
properties::Vec2Property _fadeDistances;

View File

@@ -319,19 +319,11 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
const std::string stringUnit = std::get<std::string>(*p.modelScale);
// Find matching unit name in list of supported unit names
DistanceUnit distanceUnit;
bool wasFound = false;
for (int i = 0; i < DistanceUnitNamesSingular.size(); ++i) {
if (stringUnit == DistanceUnitNamesSingular[i]) {
wasFound = true;
distanceUnit = DistanceUnits[i];
}
}
if (wasFound) {
try {
DistanceUnit distanceUnit = distanceUnitFromString(stringUnit);
_modelScale = toMeter(distanceUnit);
}
else {
catch (const ghoul::MissingCaseException& e) {
std::string message = std::format("The given unit name '{}' does not "
"match any currently supported unit names", stringUnit);
LERROR(message);

View File

@@ -114,6 +114,13 @@ namespace {
return diffPos;
}
// This `Renderable` connects two scene graph nodes by drawing a line between them.
// The line will update dynamically if the position of the nodes change.
//
// One use case for the `RenderableNodeLine` is to visualize the distance between two
// objects. For this, a [RenderableDistanceLabel](#base_renderable_distancelabel) can
// also be added to show the distance as a number. That renderable is designed to show
// the distance between the start and end node for a given `RenderableNodeLine`.
struct [[codegen::Dictionary(RenderableNodeLine)]] Parameters {
// [[codegen::verbatim(StartNodeInfo.description)]]
std::optional<std::string> startNode [[codegen::identifier()]];
@@ -142,7 +149,7 @@ namespace {
namespace openspace {
documentation::Documentation RenderableNodeLine::Documentation() {
return codegen::doc<Parameters>("base_renderable_renderablenodeline");
return codegen::doc<Parameters>("base_renderable_nodeline");
}
RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)

View File

@@ -1,37 +0,0 @@
##########################################################################################
# #
# OpenSpace #
# #
# Copyright (c) 2014-2025 #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy of this #
# software and associated documentation files (the "Software"), to deal in the Software #
# without restriction, including without limitation the rights to use, copy, modify, #
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the following #
# conditions: #
# #
# The above copyright notice and this permission notice shall be included in all copies #
# or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A #
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT #
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF #
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE #
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
##########################################################################################
include(${PROJECT_SOURCE_DIR}/support/cmake/module_definition.cmake)
set(HEADER_FILES
rendering/renderabledistancelabel.h
)
source_group("Header Files" FILES ${HEADER_FILES})
set(SOURCE_FILES
rendering/renderabledistancelabel.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})
create_new_module("VisLab" vislab_module ${HEADER_FILES} ${SOURCE_FILES})

View File

@@ -1 +0,0 @@
set(DEFAULT_MODULE ON)

View File

@@ -1,51 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2025 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/vislab/vislabmodule.h>
#include <modules/vislab/rendering/renderabledistancelabel.h>
#include <openspace/documentation/documentation.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/templatefactory.h>
namespace openspace {
VisLabModule::VisLabModule() : OpenSpaceModule(Name) {}
void VisLabModule::internalInitialize(const ghoul::Dictionary&) {
ghoul::TemplateFactory<Renderable>* renderableFactory =
FactoryManager::ref().factory<Renderable>();
ghoul_assert(renderableFactory, "No renderable factory existed");
renderableFactory->registerClass<RenderableDistanceLabel>("RenderableDistanceLabel");
}
std::vector<documentation::Documentation>VisLabModule::documentations() const {
return {
RenderableDistanceLabel::Documentation()
};
}
} // namespace openspace

View File

@@ -1,47 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2025 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_VISLAB___VISLABMODULE___H__
#define __OPENSPACE_MODULE_VISLAB___VISLABMODULE___H__
#include <openspace/util/openspacemodule.h>
namespace openspace {
class VisLabModule : public OpenSpaceModule {
public:
constexpr static const char* Name = "VisLab";
VisLabModule();
std::vector<documentation::Documentation> documentations() const override;
private:
void internalInitialize(const ghoul::Dictionary&) override;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_VISLAB___VISLABMODULE___H__