Do some initial cleanup

This commit is contained in:
Emma Broman
2020-09-25 16:11:56 +02:00
parent d79d77f7e5
commit 04130fe68a
19 changed files with 145 additions and 134 deletions

View File

@@ -115,9 +115,9 @@ AutoNavigationHandler::AutoNavigationHandler()
, _defaultStopBehavior(DefaultStopBehaviorInfo, properties::OptionProperty::DisplayType::Dropdown)
, _applyStopBehaviorWhenIdle(ApplyStopBehaviorWhenIdleInfo, false)
, _relevantNodeTags(RelevantNodeTagsInfo)
, _defaultPositionOffsetAngle(DefaultPositionOffsetAngleInfo, 30.0f, -90.0f, 90.0f)
, _defaultPositionOffsetAngle(DefaultPositionOffsetAngleInfo, 30.f, -90.f, 90.f)
, _nrSimulationSteps(NumberSimulationStepsInfo, 5, 2 , 10)
, _speedScale(SpeedScaleInfo, 1.0f, 0.01f, 2.0f)
, _speedScale(SpeedScaleInfo, 1.f, 0.01f, 2.f)
{
addPropertySubOwner(_atNodeNavigator);
@@ -125,7 +125,7 @@ AutoNavigationHandler::AutoNavigationHandler()
{ CurveType::AvoidCollision, "AvoidCollision" },
{ CurveType::Bezier3, "Bezier3" },
{ CurveType::Linear, "Linear" },
{ CurveType::ZoomOutOverview, "ZoomOutOverview"}
{ CurveType::ZoomOutOverview, "ZoomOutOverview"}
});
addProperty(_defaultCurveOption);
@@ -166,7 +166,7 @@ const SceneGraphNode* AutoNavigationHandler::anchor() const {
bool AutoNavigationHandler::hasFinished() const {
unsigned int lastIndex = (unsigned int)_pathSegments.size() - 1;
return _currentSegmentIndex > lastIndex;
return _currentSegmentIndex > lastIndex;
}
const std::vector<SceneGraphNode*>& AutoNavigationHandler::relevantNodes() const {
@@ -188,7 +188,9 @@ void AutoNavigationHandler::updateCamera(double deltaTime) {
// for testing, apply at node behavior when idle
if (_applyStopBehaviorWhenIdle) {
if (_atNodeNavigator.behavior() != _defaultStopBehavior.value()) {
_atNodeNavigator.setBehavior(AtNodeNavigator::Behavior(_defaultStopBehavior.value()));
_atNodeNavigator.setBehavior(
AtNodeNavigator::Behavior(_defaultStopBehavior.value())
);
}
_atNodeNavigator.updateCamera(deltaTime);
}
@@ -246,7 +248,7 @@ void AutoNavigationHandler::createPath(PathSpecification& spec) {
if (spec.stopAtTargetsSpecified()) {
_stopAtTargetsPerDefault = spec.stopAtTargets();
LINFO("Property for stop at targets per default was overridden by path specification.");
LINFO("Property for stop at targets per default was overridden by path specification.");
}
const int nrInstructions = (int)spec.instructions()->size();
@@ -289,7 +291,7 @@ void AutoNavigationHandler::startPath() {
}
ghoul_assert(
_stops.size() == (_pathSegments.size() - 1),
_stops.size() == (_pathSegments.size() - 1),
"Must have exactly one stop entry between every segment."
);
@@ -393,7 +395,7 @@ std::vector<glm::dvec3> AutoNavigationHandler::getCurveViewDirections(int nPerSe
glm::dquat orientation = p->interpolatedPose(u).rotation;
glm::dvec3 direction = glm::normalize(orientation * glm::dvec3(0.0, 0.0, -1.0));
viewDirections.push_back(direction);
}
}
glm::dquat orientation = p->interpolatedPose(1.0).rotation;
glm::dvec3 direction = glm::normalize(orientation * glm::dvec3(0.0, 0.0, -1.0));
viewDirections.push_back(direction);
@@ -463,7 +465,7 @@ void AutoNavigationHandler::pauseAtTarget(int i) {
bool hasDuration = _activeStop->duration.has_value();
std::string infoString = hasDuration ?
std::string infoString = hasDuration ?
fmt::format("{} seconds", _activeStop->duration.value()) : "until continued";
LINFO(fmt::format("Paused path at target {} / {} ({})",
@@ -501,7 +503,8 @@ void AutoNavigationHandler::addSegment(Instruction* ins, int index) {
}
else {
LWARNING(fmt::format(
"No path segment was created from instruction {}. No waypoints could be created.",
"No path segment was created from instruction {}. "
"No waypoints could be created.",
index
));
return;
@@ -513,9 +516,9 @@ void AutoNavigationHandler::addSegment(Instruction* ins, int index) {
}
_pathSegments.push_back(std::make_unique<PathSegment>(
lastWayPoint(),
lastWayPoint(),
waypointToAdd,
CurveType(curveType),
CurveType(curveType),
ins->duration
));
}
@@ -532,7 +535,7 @@ void AutoNavigationHandler::addStopDetails(const Instruction* ins) {
stopEntry.duration = ins->stopDuration;
std::string anchorIdentifier = lastWayPoint().nodeDetails.identifier;
stopEntry.behavior = AtNodeNavigator::Behavior(_defaultStopBehavior.value());
stopEntry.behavior = AtNodeNavigator::Behavior(_defaultStopBehavior.value());
if (ins->stopBehavior.has_value()) {
std::string behaviorString = ins->stopBehavior.value();
@@ -544,8 +547,8 @@ void AutoNavigationHandler::addStopDetails(const Instruction* ins) {
using Option = properties::OptionProperty::Option;
std::vector<Option> options = _defaultStopBehavior.options();
std::vector<Option>::iterator foundIt = std::find_if(
options.begin(),
options.end(),
options.begin(),
options.end(),
[&](Option& o) { return o.description == behaviorString; }
);
@@ -569,7 +572,7 @@ SceneGraphNode* AutoNavigationHandler::findNodeNearTarget(const SceneGraphNode*
glm::dvec3 nodePosition = node->worldPosition();
std::string nodeId = node->identifier();
const float proximityRadiusFactor = 3.0f;
const float proximityRadiusFactor = 3.f;
for (SceneGraphNode* n : _relevantNodes) {
if (n->identifier() == nodeId)
@@ -580,19 +583,19 @@ SceneGraphNode* AutoNavigationHandler::findNodeNearTarget(const SceneGraphNode*
glm::dvec3 positionModelCoords = invModelTransform * glm::dvec4(nodePosition, 1.0);
bool isClose = helpers::isPointInsideSphere(
positionModelCoords,
glm::dvec3(0.0, 0.0, 0.0),
positionModelCoords,
glm::dvec3(0.0, 0.0, 0.0),
proximityRadius
);
if (isClose)
if (isClose)
return n;
}
return nullptr;
}
// OBS! The desired default waypoint may vary between curve types.
// OBS! The desired default waypoint may vary between curve types.
// TODO: let the curves update the default position if no exact position is required
Waypoint AutoNavigationHandler::computeDefaultWaypoint(const TargetNodeInstruction* ins) {
SceneGraphNode* targetNode = sceneGraphNode(ins->nodeIdentifier);
@@ -610,7 +613,7 @@ Waypoint AutoNavigationHandler::computeDefaultWaypoint(const TargetNodeInstructi
// If the node is close to another node in the scene, make sure that the
// position is set to minimize risk of collision
stepDirection = glm::normalize(nodePos - closeNode->worldPosition());
}
}
else {
// Go to a point that is being lit up by the sun, slightly offsetted from sun direction
glm::dvec3 sunPos = glm::dvec3(0.0, 0.0, 0.0);
@@ -618,7 +621,7 @@ Waypoint AutoNavigationHandler::computeDefaultWaypoint(const TargetNodeInstructi
glm::dvec3 targetToPrev = prevPos - nodePos;
glm::dvec3 targetToSun = sunPos - nodePos;
glm::dvec3 axis = glm::normalize(glm::cross(targetToPrev, targetToSun));
const double angle = (double)glm::radians((-1.0f)*_defaultPositionOffsetAngle);
const double angle = (double)glm::radians((-1.f)*_defaultPositionOffsetAngle);
glm::dquat offsetRotation = angleAxis(angle, axis);
stepDirection = glm::normalize(offsetRotation * targetToSun);
@@ -647,12 +650,17 @@ std::vector<SceneGraphNode*> AutoNavigationHandler::findRelevantNodes() {
const std::vector<std::string> relevantTags = _relevantNodeTags;
if (allNodes.empty() || relevantTags.empty())
if (allNodes.empty() || relevantTags.empty())
return std::vector<SceneGraphNode*>{};
auto isRelevant = [&](const SceneGraphNode* node) {
const std::vector<std::string> tags = node->tags();
auto result = std::find_first_of(relevantTags.begin(), relevantTags.end(), tags.begin(), tags.end());
auto result = std::find_first_of(
relevantTags.begin(),
relevantTags.end(),
tags.begin(),
tags.end()
);
// does not match any tags => not interesting
if (result == relevantTags.end()) {
@@ -663,7 +671,12 @@ std::vector<SceneGraphNode*> AutoNavigationHandler::findRelevantNodes() {
};
std::vector<SceneGraphNode*> resultingNodes{};
std::copy_if(allNodes.begin(), allNodes.end(), std::back_inserter(resultingNodes), isRelevant);
std::copy_if(
allNodes.begin(),
allNodes.end(),
std::back_inserter(resultingNodes),
isRelevant
);
return resultingNodes;
}

View File

@@ -97,7 +97,7 @@ private:
std::vector<StopDetails> _stops; // 1 between every segment
AtNodeNavigator _atNodeNavigator; // responsible for navigation during stops
StopDetails* _activeStop = nullptr;
StopDetails* _activeStop = nullptr;
double _progressedTimeInStop = 0.0;
bool _isPlaying = false;
@@ -110,7 +110,7 @@ private:
properties::BoolProperty _stopAtTargetsPerDefault;
properties::OptionProperty _defaultStopBehavior;
// for testing pause behaviors.
// for testing pause behaviors.
// TODO: remove later, if it causes problems with regular navigation
properties::BoolProperty _applyStopBehaviorWhenIdle;
@@ -119,7 +119,7 @@ private:
properties::FloatProperty _defaultPositionOffsetAngle;
properties::IntProperty _nrSimulationSteps;
properties::FloatProperty _speedScale;
properties::FloatProperty _speedScale;
};
} // namespace openspace::autonavigation

View File

@@ -28,7 +28,7 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/globalscallbacks.h>
#include <openspace/engine/windowdelegate.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/logging/logmanager.h>
namespace {
constexpr const char* _loggerCat = "AutoNavigationModule";
@@ -43,7 +43,7 @@ namespace {
namespace openspace {
AutoNavigationModule::AutoNavigationModule()
AutoNavigationModule::AutoNavigationModule()
: OpenSpaceModule(Name),
_minValidBoundingSphere(MinBoundingSphereInfo, 10.0, 1.0, 3e10)
{
@@ -99,21 +99,21 @@ scripting::LuaLibrary AutoNavigationModule::luaLibrary() const {
&autonavigation::luascriptfunctions::generatePath,
{},
"table",
"Generate the path as described by the lua table input argument. TODO: Describe how a path instruction is defined?. "
"Generate the path as described by the lua table input argument. TODO: Describe how a path instruction is defined?. "
},
{
"generatePathFromFile",
&autonavigation::luascriptfunctions::generatePathFromFile,
{},
"string",
"Read an input file with lua instructions and use those to generate a camera path. TODO: Describe how a path instruction is defined?. "
"Read an input file with lua instructions and use those to generate a camera path. TODO: Describe how a path instruction is defined?. "
},
{
"getPathPositions",
&autonavigation::luascriptfunctions::getPathPositions,
{},
"number",
"FOR DEBUG. Sample positions along the path. The input argument is the number of samples per path segment. "
"FOR DEBUG. Sample positions along the path. The input argument is the number of samples per path segment. "
},
{
"getPathOrientations",
@@ -137,15 +137,13 @@ scripting::LuaLibrary AutoNavigationModule::luaLibrary() const {
"FOR DEBUG. Get control point positions from all pathsegments"
}
};
return res;
return res;
}
void AutoNavigationModule::internalInitialize(const ghoul::Dictionary&) {
global::callback::preSync.emplace_back([this]() {
_autoNavigationHandler.updateCamera(global::windowDelegate.deltaTime());
});
// TODO: register other classes (that are Factory created) and used in this module, if any
}
} // namespace openspace

View File

@@ -85,7 +85,7 @@ namespace openspace::autonavigation::luascriptfunctions {
PathSpecification spec = PathSpecification(TargetNodeInstruction{insDict});
AutoNavigationModule* module = global::moduleEngine.module<AutoNavigationModule>();
AutoNavigationModule* module = global::moduleEngine.module<AutoNavigationModule>();
AutoNavigationHandler& handler = module->AutoNavigationHandler();
handler.createPath(spec);
@@ -226,7 +226,7 @@ namespace openspace::autonavigation::luascriptfunctions {
ghoul::lua::push(L, 3, v.y);
lua_rawset(L, -4);
ghoul::lua::push(L, 4, v.z);
lua_rawset(L, -4);
lua_rawset(L, -4);
};
lua_newtable(L);

View File

@@ -40,7 +40,7 @@ namespace {
constexpr const char* _loggerCat = "AvoidCollisionCurve";
const double Epsilon = 1E-7;
const double CloseToNodeThresholdFactor = 5.0;
const double CloseToNodeThresholdFactor = 5.0;
const double AvoidCollisionDistanceFactor = 3.0;
const double CollisionBufferSizeFactor = 1.0;
const int MaxAvoidCollisionSteps = 10;
@@ -79,24 +79,24 @@ AvoidCollisionCurve::AvoidCollisionCurve(const Waypoint& start, const Waypoint&
}
// Add point for moving out if the end state is in opposite direction
//TODO: determine if its best to compare to end orientation or position
//TODO: determine if its best to compare to end orientation or position
glm::dvec3 startToEnd = end.position() - start.position();
double cosAngleToTarget = glm::dot(normalize(-startViewDirection), normalize(startToEnd));
bool targetInOppositeDirection = cosAngleToTarget > 0.7;
// TODO: reduce magical numbers / create constants
if (targetInOppositeDirection) {
glm::dquat midleRotation = glm::slerp(start.rotation(), end.rotation(), 0.5);
glm::dquat midleRotation = glm::slerp(start.rotation(), end.rotation(), 0.5);
glm::dvec3 middleViewDirection = midleRotation * glm::dvec3(0.0, 0.0, -1.0);
double stepOutdistance = 0.4 * glm::length(startToEnd);
glm::dvec3 newPosition = start.position() + 0.2 * startToEnd -
glm::dvec3 newPosition = start.position() + 0.2 * startToEnd -
stepOutdistance * glm::normalize(middleViewDirection);
_points.push_back(newPosition);
}
// Add an extra point to approach target
// Add an extra point to approach target
glm::dvec3 nodeToEnd = end.position() - endNodeCenter;
double distanceToEndNode = glm::length(nodeToEnd);
@@ -109,7 +109,7 @@ AvoidCollisionCurve::AvoidCollisionCurve(const Waypoint& start, const Waypoint&
_points.push_back(end.position());
_points.push_back(end.position());
// Create extra points to avoid collision
// Create extra points to avoid collision
removeCollisions();
_nrSegments = _points.size() - 3;
@@ -133,22 +133,22 @@ glm::dvec3 AvoidCollisionCurve::interpolate(double u) {
double uSegment = (u - segmentStart) / segmentDuration;
return interpolation::catmullRom(
uSegment,
_points[index],
_points[index + 1],
_points[index + 2],
_points[index + 3],
uSegment,
_points[index],
_points[index + 1],
_points[index + 2],
_points[index + 3],
1.0
);
}
// Try to reduce the risk of collision by approximating the curve with linear segments.
// Try to reduce the risk of collision by approximating the curve with linear segments.
// If a collision happens, create a new point for the path to go through, in an attempt to
// avoid that collision
void AvoidCollisionCurve::removeCollisions(int step) {
int nrSegments = _points.size() - 3;
if (step > MaxAvoidCollisionSteps)
if (step > MaxAvoidCollisionSteps)
return; // TODO: handle better / present warning if early out
for (int i = 0; i < nrSegments; ++i) {
@@ -156,7 +156,7 @@ void AvoidCollisionCurve::removeCollisions(int step) {
const glm::dvec3 lineEnd = _points[i + 2];
for (SceneGraphNode* node : _relevantNodes) {
// do collision check in relative coordinates, to avoid huge numbers
// do collision check in relative coordinates, to avoid huge numbers
const glm::dmat4 modelTransform = node->modelTransform();
glm::dvec3 p1 = glm::inverse(modelTransform) * glm::dvec4(lineStart, 1.0);
glm::dvec3 p2 = glm::inverse(modelTransform) * glm::dvec4(lineEnd, 1.0);
@@ -173,13 +173,13 @@ void AvoidCollisionCurve::removeCollisions(int step) {
if (!p1IsInside && !p2IsInside) {
radius += buffer;
}
glm::dvec3 intersectionPointModelCoords;
bool collision = helpers::lineSphereIntersection(
p1,
p2,
center,
radius,
p1,
p2,
center,
radius,
intersectionPointModelCoords
);
@@ -200,7 +200,7 @@ void AvoidCollisionCurve::removeCollisions(int step) {
break;
}
// to avoid collision, take a step in an orhtogonal direction of the
// to avoid collision, take a step in an orhtogonal direction of the
// collision point and add a new point
glm::dvec3 lineDirection = glm::normalize(lineEnd - lineStart);
glm::dvec3 nodeCenter = node->worldPosition();

View File

@@ -54,9 +54,9 @@ namespace openspace::autonavigation::helpers {
p = p1 + mu2 (p2 - p1)
Source: http://paulbourke.net/geometry/circlesphere/raysphere.c
*/
bool lineSphereIntersection(glm::dvec3 p1, glm::dvec3 p2, glm::dvec3 sc, double r,
bool lineSphereIntersection(glm::dvec3 p1, glm::dvec3 p2, glm::dvec3 sc, double r,
glm::dvec3& intersectionPoint)
{
{
long double a, b, c;
glm::dvec3 dp = p2 - p1;
@@ -166,8 +166,8 @@ namespace openspace::autonavigation::interpolation {
}
// uniform if tKnots are equally spaced, or else non uniform
glm::dvec3 piecewiseCubicBezier(double t, const std::vector<glm::dvec3>& points,
const std::vector<double>& tKnots)
glm::dvec3 piecewiseCubicBezier(double t, const std::vector<glm::dvec3>& points,
const std::vector<double>& tKnots)
{
ghoul_assert(points.size() > 4, "Minimum of four control points needed for interpolation!");
ghoul_assert((points.size() - 1) % 3 == 0, "A vector containing 3n + 1 control points must be provided!");
@@ -193,7 +193,7 @@ namespace openspace::autonavigation::interpolation {
points[idx + 2], points[idx + 3]);
}
glm::dvec3 piecewiseLinear(double t, const std::vector<glm::dvec3>& points,
glm::dvec3 piecewiseLinear(double t, const std::vector<glm::dvec3>& points,
const std::vector<double>& tKnots)
{
ghoul_assert(points.size() == tKnots.size(), "Must have equal number of points and times!");

View File

@@ -30,7 +30,7 @@
#include <ghoul/logging/logmanager.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <algorithm>
namespace openspace::autonavigation::helpers {
@@ -48,7 +48,7 @@ namespace openspace::autonavigation::helpers {
namespace openspace::autonavigation::interpolation {
// TODO: make all these into template functions.
// TODO: make all these into template functions.
// Alternatively, add cubicBezier interpolation in ghoul and only use
// ghoul's interpolator methods
@@ -67,7 +67,7 @@ namespace openspace::autonavigation::interpolation {
glm::dvec3 piecewiseCubicBezier(double t, const std::vector<glm::dvec3>& points,
const std::vector<double>& tKnots);
glm::dvec3 piecewiseLinear(double t, const std::vector<glm::dvec3>& points,
glm::dvec3 piecewiseLinear(double t, const std::vector<glm::dvec3>& points,
const std::vector<double>& tKnots);
} // namespace

View File

@@ -60,7 +60,7 @@ Instruction::Instruction(const ghoul::Dictionary& dictionary) {
}
if (dictionary.hasValue<ghoul::Dictionary>(KeyStopDetails)) {
ghoul::Dictionary stopDictionary =
ghoul::Dictionary stopDictionary =
dictionary.value<ghoul::Dictionary>(KeyStopDetails);
if (stopDictionary.hasValue<double>(KeyDuration)) {
@@ -75,7 +75,7 @@ Instruction::Instruction(const ghoul::Dictionary& dictionary) {
Instruction::~Instruction() {}
TargetNodeInstruction::TargetNodeInstruction(const ghoul::Dictionary& dictionary)
TargetNodeInstruction::TargetNodeInstruction(const ghoul::Dictionary& dictionary)
: Instruction(dictionary)
{
if (!dictionary.hasValue<std::string>(KeyTarget)) {
@@ -108,7 +108,7 @@ std::vector<Waypoint> TargetNodeInstruction::getWaypoints() const {
glm::dvec3 targetPos;
if (position.has_value()) {
// note that the anchor and reference frame is our targetnode.
// note that the anchor and reference frame is our targetnode.
// The position in instruction is given is relative coordinates.
targetPos = targetNode->worldPosition() +
targetNode->worldRotationMatrix() * position.value();

View File

@@ -57,11 +57,11 @@ glm::dvec3 PathCurve::positionAt(double relativeLength) {
// Returns curve parameter in range [0, 1]
double PathCurve::curveParameter(double s) {
if (s <= Epsilon) return 0.0;
if (s >= _totalLength) return 1.0;
if (s >= _totalLength) return 1.0;
unsigned int segmentIndex;
for (segmentIndex = 1; segmentIndex < _nrSegments; ++segmentIndex) {
if (s <= _lengthSums[segmentIndex])
if (s <= _lengthSums[segmentIndex])
break;
}
@@ -73,22 +73,22 @@ double PathCurve::curveParameter(double s) {
const double uMax = _parameterIntervals[segmentIndex];
double u = uMin + (uMax - uMin) * (segmentS / segmentLength);
const int nrIterations = 40;
const int nrIterations = 40;
// initialize root bounding limits for bisection
double lower = uMin;
double upper = uMax;
for (int i = 0; i < nrIterations; ++i) {
double F = arcLength(uMin, u) - segmentS;
double F = arcLength(uMin, u) - segmentS;
const double tolerance = 0.1; // meters. Note that distances are very large
if (std::abs(F) <= tolerance) {
return u;
}
// generate a candidate for Newton's method
double dfdu = approximatedDerivative(u, Epsilon); // > 0
// generate a candidate for Newton's method
double dfdu = approximatedDerivative(u, Epsilon); // > 0
double uCandidate = u - F / dfdu;
// update root-bounding interval and test candidate
@@ -96,7 +96,7 @@ double PathCurve::curveParameter(double s) {
upper = u;
u = (uCandidate <= lower) ? (upper + lower) / 2.0 : uCandidate;
}
else { // F < 0 => lower <= u < candidate
else { // F < 0 => lower <= u < candidate
lower = u;
u = (uCandidate >= upper) ? (upper + lower) / 2.0 : uCandidate;
}

View File

@@ -61,7 +61,7 @@ protected:
double arcLength(double limit = 1.0);
double arcLength(double lowerLimit, double upperLimit);
std::vector<glm::dvec3> _points;
std::vector<glm::dvec3> _points;
unsigned int _nrSegments;
std::vector<double> _parameterIntervals;

View File

@@ -43,8 +43,8 @@ namespace {
namespace openspace::autonavigation {
PathSegment::PathSegment(Waypoint start, Waypoint end, CurveType type,
std::optional<double> duration)
PathSegment::PathSegment(Waypoint start, Waypoint end, CurveType type,
std::optional<double> duration)
: _start(start), _end(end), _curveType(type)
{
initCurve();
@@ -87,7 +87,7 @@ CameraPose PathSegment::traversePath(double dt) {
AutoNavigationModule* module = global::moduleEngine.module<AutoNavigationModule>();
AutoNavigationHandler& handler = module->AutoNavigationHandler();
const int nrSteps = handler.nrSimulationStepsPerFrame();
const int nrSteps = handler.nrSimulationStepsPerFrame();
// compute displacement along the path during this frame
double displacement = 0.0;
@@ -101,11 +101,6 @@ CameraPose PathSegment::traversePath(double dt) {
_traveledDistance += displacement;
double relativeDisplacement = _traveledDistance / pathLength();
// TEST:
//LINFO("-----------------------------------");
//LINFO(fmt::format("relativeDisplacement = {}", relativeDisplacement));
//LINFO(fmt::format("progressedTime = {}", _progressedTime));
_progressedTime += dt;
return interpolatedPose(relativeDisplacement);
@@ -134,7 +129,7 @@ CameraPose PathSegment::interpolatedPose(double u) const {
void PathSegment::initCurve() {
_curve.reset();
switch (_curveType)
switch (_curveType)
{
case CurveType::AvoidCollision:
_curve = std::make_unique<AvoidCollisionCurve>(_start, _end);
@@ -160,7 +155,7 @@ void PathSegment::initCurve() {
case CurveType::Linear:
_curve = std::make_unique<LinearCurve>(_start, _end);
_rotationInterpolator = std::make_unique<EasedSlerpInterpolator>(
_start.rotation(),
_start.rotation(),
_end.rotation()
);
_speedFunction = std::make_unique<QuinticDampenedSpeed>();

View File

@@ -36,7 +36,7 @@ namespace openspace::autonavigation {
class PathSegment {
public:
PathSegment(Waypoint start, Waypoint end, CurveType type,
PathSegment(Waypoint start, Waypoint end, CurveType type,
std::optional<double> duration = std::nullopt);
~PathSegment() = default;
@@ -50,29 +50,29 @@ public:
const double duration() const;
const double pathLength() const;
const std::vector<glm::dvec3> getControlPoints() const; // TODO: remove this debugging function
const std::vector<glm::dvec3> getControlPoints() const; // debugging
CameraPose traversePath(double dt);
std::string getCurrentAnchor() const;
bool hasReachedEnd() const;
double speedAtTime(double time) const;
CameraPose interpolatedPose(double u) const;
CameraPose interpolatedPose(double u) const;
private:
private:
void initCurve();
Waypoint _start;
Waypoint _end;
double _duration;
CurveType _curveType;
CurveType _curveType;
std::unique_ptr<SpeedFunction> _speedFunction;
std::unique_ptr<RotationInterpolator> _rotationInterpolator;
std::unique_ptr<PathCurve> _curve;
// Playback variables
double _traveledDistance = 0.0;
double _traveledDistance = 0.0;
double _progressedTime = 0.0; // Time since playback started
};

View File

@@ -53,11 +53,11 @@ PathSpecification::PathSpecification(const ghoul::Dictionary& dictionary) {
"Path Specification"
);
ghoul::Dictionary instructions =
dictionary.value<ghoul::Dictionary>(KeyInstructions);
ghoul::Dictionary instructions =
dictionary.value<ghoul::Dictionary>(KeyInstructions);
for (size_t i = 1; i <= instructions.size(); ++i) {
ghoul::Dictionary insDict =
ghoul::Dictionary insDict =
instructions.value<ghoul::Dictionary>(std::to_string(i));
if (!insDict.hasValue<std::string>(KeyType)) {
@@ -151,9 +151,9 @@ documentation::Documentation PathSpecification::Documentation() {
}
// create correct type of instruction and present and throw error with useful
// error message if we failed.
// error message if we failed.
void PathSpecification::tryReadInstruction(int index, std::string type,
ghoul::Dictionary& dictionary)
ghoul::Dictionary& dictionary)
{
if (type == KeyTypeTargetNode) {
try {
@@ -176,7 +176,7 @@ void PathSpecification::tryReadInstruction(int index, std::string type,
}
else {
throw ghoul::RuntimeError(fmt::format(
"Failed reading instruction {}: Uknown instruction type '{}'",
"Failed reading instruction {}: Uknown instruction type '{}'",
index, type)
);
}

View File

@@ -46,7 +46,7 @@ public:
// Accessors
const std::vector<std::unique_ptr<Instruction>>* instructions() const;
Instruction* instruction(int i) const;
const bool stopAtTargets() const;
const bool stopAtTargets() const;
const bool stopAtTargetsSpecified() const;
const NavigationState& startState() const;
const bool hasStartState() const;
@@ -55,7 +55,7 @@ private:
void tryReadInstruction(int index, std::string type, ghoul::Dictionary& dictionary);
std::vector<std::unique_ptr<Instruction>> _instructions;
std::optional<bool> _stopAtTargets;
std::optional<bool> _stopAtTargets;
std::optional<NavigationState> _startState;
// TODO: maxSpeed or speedFactor or something?

View File

@@ -50,13 +50,13 @@ glm::dquat EasedSlerpInterpolator::interpolate(double u) {
return glm::slerp(_start, _end, uScaled);
}
LookAtRotator::LookAtRotator(glm::dquat start, glm::dquat end,
glm::dvec3 startLookAtPos,
glm::dvec3 endLookAtPos,
LookAtRotator::LookAtRotator(glm::dquat start, glm::dquat end,
glm::dvec3 startLookAtPos,
glm::dvec3 endLookAtPos,
PathCurve* path)
: RotationInterpolator(start, end),
_startLookAtPos(startLookAtPos),
_endLookAtPos(endLookAtPos),
_startLookAtPos(startLookAtPos),
_endLookAtPos(endLookAtPos),
_path(path)
{}
@@ -116,7 +116,7 @@ glm::dquat LookAtInterpolator::interpolate(double u) {
}
// handle up vector
glm::dvec3 startUp = _start * glm::dvec3(0.0, 1.0, 0.0);
glm::dvec3 startUp = _start * glm::dvec3(0.0, 1.0, 0.0);
glm::dvec3 endUp = _end * glm::dvec3(0.0, 1.0, 0.0);
double uUp = ghoul::cubicEaseInOut(u);

View File

@@ -41,8 +41,8 @@ protected:
// must be called by each subclass after initialization
void initIntegratedSum();
// store the sum of the function over the duration of the segment,
// so we don't need to recompue it every time we access the speed
// store the sum of the function over the duration of the segment,
// so we don't need to recompue it every time we access the speed
double _integratedSum = 0.0;
};
@@ -50,7 +50,7 @@ class SexticDampenedSpeed : public SpeedFunction {
public:
SexticDampenedSpeed();
double value(double t) const override;
};
};
class QuinticDampenedSpeed : public SpeedFunction {
public:

View File

@@ -37,9 +37,8 @@ namespace {
namespace openspace::autonavigation {
WaypointNodeDetails::WaypointNodeDetails(const std::string nodeIdentifier)
{
const SceneGraphNode* node = sceneGraphNode(nodeIdentifier);
WaypointNodeDetails::WaypointNodeDetails(const std::string nodeIdentifier) {
const SceneGraphNode* node = sceneGraphNode(nodeIdentifier);
if (!node) {
LERROR(fmt::format("Could not find node '{}'.", nodeIdentifier));
return;
@@ -49,25 +48,24 @@ WaypointNodeDetails::WaypointNodeDetails(const std::string nodeIdentifier)
validBoundingSphere = findValidBoundingSphere(node);
}
double WaypointNodeDetails::findValidBoundingSphere(const SceneGraphNode* node)
{
double WaypointNodeDetails::findValidBoundingSphere(const SceneGraphNode* node) {
double bs = static_cast<double>(node->boundingSphere());
const double minValidBoundingSphere =
const double minValidBoundingSphere =
global::moduleEngine.module<AutoNavigationModule>()->minValidBoundingSphere();
if (bs < minValidBoundingSphere) {
// If the bs of the target is too small, try to find a good value in a child node.
// Only check the closest children, to avoid deep traversal in the scene graph. Also,
// the possibility to find a bounding sphere represents the visual size of the
// target well is higher for these nodes.
// Only check the closest children, to avoid deep traversal in the scene graph.
// Also, the possibility to find a bounding sphere represents the visual size of
// the target well is higher for these nodes.
for (SceneGraphNode* child : node->children()) {
bs = static_cast<double>(child->boundingSphere());
if (bs > minValidBoundingSphere) {
LWARNING(fmt::format(
"The scene graph node '{}' has no, or a very small, bounding sphere. Using bounding sphere of child node '{}' in computations.",
node->identifier(),
"The scene graph node '{}' has no, or a very small, bounding sphere. "
"Using bounding sphere of child node '{}' in computations.",
node->identifier(),
child->identifier()
));
@@ -75,8 +73,11 @@ double WaypointNodeDetails::findValidBoundingSphere(const SceneGraphNode* node)
}
}
LWARNING(fmt::format("The scene graph node '{}' has no, or a very small,"
"bounding sphere. Using minimal value. This might lead to unexpected results.", node->identifier()));
LWARNING(fmt::format(
"The scene graph node '{}' has no, or a very small, bounding sphere. Using "
"minimal value. This might lead to unexpected results.",
node->identifier())
);
bs = minValidBoundingSphere;
}
@@ -92,7 +93,7 @@ Waypoint::Waypoint(const glm::dvec3& pos, const glm::dquat& rot, const std::stri
}
Waypoint::Waypoint(const NavigationState& ns) {
// OBS! The following code is exactly the same as used in
// OBS! The following code is exactly the same as used in
// NavigationHandler::applyNavigationState. Should probably be made into a function.
// TODO: make that function
const SceneGraphNode* referenceFrame = sceneGraphNode(ns.referenceFrame);
@@ -131,11 +132,15 @@ Waypoint::Waypoint(const NavigationState& ns) {
nodeDetails = WaypointNodeDetails{ ns.anchor };
}
glm::dvec3 Waypoint::position() const { return pose.position; }
glm::dvec3 Waypoint::position() const {
return pose.position;
}
glm::dquat Waypoint::rotation() const { return pose.rotation; }
glm::dquat Waypoint::rotation() const {
return pose.rotation;
}
SceneGraphNode* Waypoint::node() const {
SceneGraphNode* Waypoint::node() const {
return sceneGraphNode(nodeDetails.identifier);
}

View File

@@ -36,7 +36,7 @@ struct CameraPose {
glm::dquat rotation;
};
// The waypoint node is the anchor or target node.
// The waypoint node is the anchor or target node.
struct WaypointNodeDetails {
WaypointNodeDetails() = default;
WaypointNodeDetails(const std::string nodeIdentifier);
@@ -58,7 +58,7 @@ struct Waypoint {
glm::dvec3 position() const;
glm::dquat rotation() const;
SceneGraphNode* node() const;
SceneGraphNode* node() const;
CameraPose pose;
WaypointNodeDetails nodeDetails;

View File

@@ -44,7 +44,7 @@ namespace {
namespace openspace::autonavigation {
// Go far out to get a view of both tagets, aimed to match lookAt orientation
// Go far out to get a view of both tagets, aimed to match lookAt orientation
ZoomOutOverviewCurve::ZoomOutOverviewCurve(const Waypoint& start, const Waypoint& end) {
glm::dvec3 startNodePos = start.node()->worldPosition();
glm::dvec3 endNodePos = end.node()->worldPosition();
@@ -70,11 +70,11 @@ ZoomOutOverviewCurve::ZoomOutOverviewCurve(const Waypoint& start, const Waypoint
// Zoom out
if (startNode != endNode) {
// TODO: set a smarter orthogonal direction
// TODO: set a smarter orthogonal direction
glm::dvec3 parallell = glm::proj(startNodeToStartPos, startNodeToEndNode);
glm::dvec3 orthogonalDirction = normalize(startNodeToStartPos - parallell);
glm::dvec3 extraKnot = startNodePos + 0.5 * startNodeToEndNode
glm::dvec3 extraKnot = startNodePos + 0.5 * startNodeToEndNode
+ 1.5 * glm::length(startNodeToEndNode) * orthogonalDirction;
_points.push_back(extraKnot - 0.2 * startNodeToEndNode);