Working distance label

This commit is contained in:
Lovisa Hassler
2020-01-09 12:01:00 +01:00
parent 4ffc5595d9
commit 07cc8d4a4f
4 changed files with 64 additions and 78 deletions

View File

@@ -46,11 +46,6 @@
#include <ghoul/glm.h>
#include <glm/gtx/string_cast.hpp>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <string>
#include <modules/base/rendering/renderablenodeline.h>
namespace {
constexpr const char* _loggerCat = "base::RenderableLabels";
@@ -181,12 +176,6 @@ namespace {
"Fade-In/-Out ending speed."
};
constexpr openspace::properties::Property::PropertyInfo NodeLineInfo = {
"NodeLine",
"Node Line",
"Optional property to track a nodeline. When tracking the label text will be updating the distance "
"from the nodeline start and end. "
};
} // namespace
namespace openspace {
@@ -327,7 +316,6 @@ RenderableLabels::RenderableLabels(const ghoul::Dictionary& dictionary)
, _pixelSizeControl(PixelSizeControlInfo, false)
, _enableFadingEffect(EnableFadingEffectInfo, false)
, _labelText(LabelTextInfo)
, _nodeLine(NodeLineInfo)
, _fadeStartDistance(FadeStartDistInfo, 1.f, 0.f, 100.f)
, _fadeEndDistance(FadeEndDistInfo, 1.f, 0.f, 100.f)
, _fadeStartSpeed(FadeStartSpeedInfo, 1.f, 1.f, 100.f)
@@ -460,11 +448,6 @@ RenderableLabels::RenderableLabels(const ghoul::Dictionary& dictionary)
_fadeStartDistance = dictionary.value<float>(FadeStartDistInfo.identifier);
}
if (dictionary.hasKey(NodeLineInfo.identifier)) {
_nodeLine = dictionary.value<std::string>(NodeLineInfo.identifier);
addProperty(_nodeLine);
}
addProperty(_fadeStartDistance);
_fadeStartUnitOption.addOption(Meter, MeterUnit);
@@ -701,31 +684,6 @@ void RenderableLabels::render(const RenderData& data, RendererTasks&) {
//}
}
//void RenderableLabels::update(const UpdateData& data) {
//
// if (global::renderEngine.scene()->sceneGraphNode(_nodeLine)) {
//
// // Calculate distance
// SceneGraphNode* nodelineNode = global::renderEngine.scene()->sceneGraphNode(_nodeLine);
// RenderableNodeLine* nodeline = dynamic_cast<RenderableNodeLine*>(nodelineNode->renderable());
// double myDistance = nodeline->getDistance();
//
// // format string
// float scale = getUnit(Kilometer);
// std::string distanceText = std::to_string(std::round(myDistance / scale));
// int pos = distanceText.find(".");
// std::string subStr = distanceText.substr(pos);
// distanceText.erase(pos, subStr.size());
// std::string finalText = distanceText + " " + KilometerUnit;
// setLabelText(finalText);
//
// // Update placement of label with transformation matrix
// glm::dvec3 start = global::renderEngine.scene()->sceneGraphNode(nodeline->_start)->worldPosition();
// glm::dvec3 end = global::renderEngine.scene()->sceneGraphNode(nodeline->_end)->worldPosition();
// glm::dvec3 goalPos = start + (end - start) / 2.0;
// _transformationMatrix = glm::translate(glm::dmat4(1.0), goalPos);
// }
//}
void RenderableLabels::setLabelText(const std::string & newText) {
_labelText = newText;

View File

@@ -72,7 +72,12 @@ public:
protected:
properties::OptionProperty _blendMode;
private:
float getUnit(int unit) const;
// Data may require some type of transformation prior the spice transformation being
// applied.
glm::dmat4 _transformationMatrix = glm::dmat4(1.0);
enum Unit {
Meter = 0,
Kilometer,
@@ -88,6 +93,7 @@ private:
GigalightYears
};
private:
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable);
@@ -96,8 +102,6 @@ private:
float linearSmoothStepFunc(float x, float startX, float endX, float sUnit,
float eUnit) const;
float getUnit(int unit) const;
properties::Vec4Property _labelColor;
properties::FloatProperty _labelSize;
properties::FloatProperty _fontSize;
@@ -106,7 +110,6 @@ private:
properties::BoolProperty _pixelSizeControl;
properties::BoolProperty _enableFadingEffect;
properties::StringProperty _labelText;
properties::StringProperty _nodeLine;
properties::FloatProperty _fadeStartDistance;
properties::FloatProperty _fadeEndDistance;
properties::FloatProperty _fadeStartSpeed;
@@ -123,10 +126,6 @@ private:
std::string _labelFile;
std::string _colorOptionString;
std::string _datavarSizeOptionString;
// Data may require some type of transformation prior the spice transformation being
// applied.
glm::dmat4 _transformationMatrix = glm::dmat4(1.0);
};
} // namespace openspace

View File

@@ -24,8 +24,24 @@
#include <modules/vislab/rendering/renderabledistancelabel.h>
#include <modules/base/rendering/renderablenodeline.h>
#include <openspace/documentation/documentation.h>
//#include <openspace/documentation/verifier.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <string>
namespace {
constexpr const char* _loggerCat = "RenderableDistanceLabel";
constexpr openspace::properties::Property::PropertyInfo NodeLineInfo = {
"NodeLine",
"Node Line",
"Property to track a nodeline. When tracking the label text will be updating the distance "
"from the nodeline start and end. "
};
}
namespace openspace {
@@ -35,45 +51,57 @@ documentation::Documentation RenderableDistanceLabel::Documentation() {
"Renderable Distance Label",
"vislab_renderable_distance_label",
{
{
NodeLineInfo.identifier,
new StringVerifier,
Optional::No,
NodeLineInfo.description
},
}
};
}
RenderableDistanceLabel::RenderableDistanceLabel(const ghoul::Dictionary& dictionary)
: RenderableLabels(dictionary)
, _nodeLine(NodeLineInfo)
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"RenderableDistanceLabel"
);
if (dictionary.hasKey(NodeLineInfo.identifier)) {
_nodeLine = dictionary.value<std::string>(NodeLineInfo.identifier);
addProperty(_nodeLine);
}
}
//void RenderableDistanceLabel::update(const UpdateData& data) {
//
// if (global::renderEngine.scene()->sceneGraphNode(_nodeLine)) {
//
// // Calculate distance
// SceneGraphNode* nodelineNode = global::renderEngine.scene()->sceneGraphNode(_nodeLine);
// RenderableNodeLine* nodeline = dynamic_cast<RenderableNodeLine*>(nodelineNode->renderable());
// double myDistance = nodeline->getDistance();
//
// // format string
// float scale = getUnit(Kilometer);
// std::string distanceText = std::to_string(std::round(myDistance / scale));
// int pos = distanceText.find(".");
// std::string subStr = distanceText.substr(pos);
// distanceText.erase(pos, subStr.size());
// std::string finalText = distanceText + " " + KilometerUnit;
// setLabelText(finalText);
//
// // Update placement of label with transformation matrix
// glm::dvec3 start = global::renderEngine.scene()->sceneGraphNode(nodeline->_start)->worldPosition();
// glm::dvec3 end = global::renderEngine.scene()->sceneGraphNode(nodeline->_end)->worldPosition();
// glm::dvec3 goalPos = start + (end - start) / 2.0;
// _transformationMatrix = glm::translate(glm::dmat4(1.0), goalPos);
// }
//}
void RenderableDistanceLabel::update(const UpdateData& data) {
if (global::renderEngine.scene()->sceneGraphNode(_nodeLine)) {
// Calculate distance
SceneGraphNode* nodelineNode = global::renderEngine.scene()->sceneGraphNode(_nodeLine);
RenderableNodeLine* nodeline = dynamic_cast<RenderableNodeLine*>(nodelineNode->renderable());
double myDistance = nodeline->getDistance();
// format string
float scale = getUnit(Kilometer);
std::string distanceText = std::to_string(std::round(myDistance / scale));
int pos = distanceText.find(".");
std::string subStr = distanceText.substr(pos);
distanceText.erase(pos, subStr.size());
std::string finalText = distanceText + " Km";
setLabelText(finalText);
// Update placement of label with transformation matrix
glm::dvec3 start = global::renderEngine.scene()->sceneGraphNode(nodeline->_start)->worldPosition();
glm::dvec3 end = global::renderEngine.scene()->sceneGraphNode(nodeline->_end)->worldPosition();
glm::dvec3 goalPos = start + (end - start) / 2.0;
_transformationMatrix = glm::translate(glm::dmat4(1.0), goalPos);
}
}
} // namespace openspace

View File

@@ -28,7 +28,6 @@
#include <modules/base/rendering/renderablelabels.h>
namespace openspace {
namespace documentation { struct Documentation; }
@@ -37,9 +36,11 @@ class RenderableDistanceLabel : public RenderableLabels {
public:
RenderableDistanceLabel(const ghoul::Dictionary& dictionary);
// void update(const UpdateData& data) override;
void update(const UpdateData& data) override;
static documentation::Documentation Documentation();
properties::StringProperty _nodeLine;
private:
};