Prepare for removing module by moving its properties

This commit is contained in:
Emma Broman
2021-06-21 13:23:38 +02:00
parent 933580e08c
commit c2a7fab3e1
8 changed files with 105 additions and 98 deletions

View File

@@ -28,101 +28,20 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/globalscallbacks.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <ghoul/logging/logmanager.h>
namespace {
constexpr const openspace::properties::Property::PropertyInfo MinBoundingSphereInfo = {
"MinimalValidBoundingSphere",
"Minimal Valid Bounding Sphere",
"The minimal allowed value for a bounding sphere, in meters. Used for "
"computation of target positions and path generation, to avoid issues when "
"there is no bounding sphere."
};
constexpr openspace::properties::Property::PropertyInfo RelevantNodeTagsInfo = {
"RelevantNodeTags",
"Relevant Node Tags",
"List of tags for the nodes that are relevant for path creation, for example "
"when avoiding collisions."
};
} // namespace
namespace openspace {
AutoNavigationModule::AutoNavigationModule()
: OpenSpaceModule(Name)
, _minValidBoundingSphere(MinBoundingSphereInfo, 10.0, 1.0, 3e10)
, _relevantNodeTags(RelevantNodeTagsInfo)
{
addPropertySubOwner(_pathNavigationHandler);
addProperty(_minValidBoundingSphere);
_relevantNodeTags = std::vector<std::string>{
"planet_solarSystem",
"moon_solarSystem"
};;
_relevantNodeTags.onChange([this]() { findRelevantNodes(); });
addProperty(_relevantNodeTags);
}
pathnavigation::PathNavigationHandler& AutoNavigationModule::PathNavigationHandler() {
return _pathNavigationHandler;
}
double AutoNavigationModule::minValidBoundingSphere() const {
return _minValidBoundingSphere;
}
const std::vector<SceneGraphNode*>& AutoNavigationModule::relevantNodes() {
if (!_hasInitializedRelevantNodes) {
findRelevantNodes();
_hasInitializedRelevantNodes = true;
}
return _relevantNodes;
}
void AutoNavigationModule::findRelevantNodes() {
const std::vector<SceneGraphNode*>& allNodes =
global::renderEngine->scene()->allSceneGraphNodes();
const std::vector<std::string> relevantTags = _relevantNodeTags;
if (allNodes.empty() || relevantTags.empty()) {
_relevantNodes = std::vector<SceneGraphNode*>();
return;
}
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()
);
// does not match any tags => not interesting
if (result == relevantTags.end()) {
return false;
}
return node->renderable() && (node->boundingSphere() > 0.0);
};
std::vector<SceneGraphNode*> resultingNodes;
std::copy_if(
allNodes.begin(),
allNodes.end(),
std::back_inserter(resultingNodes),
isRelevant
);
_relevantNodes = resultingNodes;
}
scripting::LuaLibrary AutoNavigationModule::luaLibrary() const {
scripting::LuaLibrary res;
res.name = "autonavigation";

View File

@@ -27,7 +27,6 @@
#include <openspace/util/openspacemodule.h>
#include <openspace/documentation/documentation.h>
#include <modules/autonavigation/pathnavigationhandler.h>
namespace openspace {
@@ -40,22 +39,13 @@ public:
virtual ~AutoNavigationModule() = default;
pathnavigation::PathNavigationHandler& PathNavigationHandler();
double minValidBoundingSphere() const;
const std::vector<SceneGraphNode*>& relevantNodes();
scripting::LuaLibrary luaLibrary() const override;
private:
void internalInitialize(const ghoul::Dictionary&) override;
void findRelevantNodes();
pathnavigation::PathNavigationHandler _pathNavigationHandler;
properties::DoubleProperty _minValidBoundingSphere;
properties::StringListProperty _relevantNodeTags;
std::vector<SceneGraphNode*> _relevantNodes;
bool _hasInitializedRelevantNodes = false;
};
} // namespace openspace

View File

@@ -48,8 +48,8 @@ namespace {
namespace openspace::pathnavigation {
AvoidCollisionCurve::AvoidCollisionCurve(const Waypoint& start, const Waypoint& end) {
_relevantNodes =
global::moduleEngine->module<AutoNavigationModule>()->relevantNodes();
auto module = global::moduleEngine->module<AutoNavigationModule>();
_relevantNodes = module->PathNavigationHandler().relevantNodes();
const glm::dvec3 startNodeCenter = start.node()->worldPosition();
const glm::dvec3 endNodeCenter = end.node()->worldPosition();

View File

@@ -214,8 +214,9 @@ Waypoint PathCreator::computeDefaultWaypoint(const NodeInfo& info,
}
SceneGraphNode* PathCreator::findNodeNearTarget(const SceneGraphNode* node) {
auto module = global::moduleEngine->module<AutoNavigationModule>();
const std::vector<SceneGraphNode*>& relevantNodes =
global::moduleEngine->module<AutoNavigationModule>()->relevantNodes();
module->PathNavigationHandler().relevantNodes();
for (SceneGraphNode* n : relevantNodes) {
if (n->identifier() == node->identifier()) {

View File

@@ -29,7 +29,7 @@
namespace openspace::pathnavigation {
class Waypoint;
struct Waypoint;
class PathCreator {
public:

View File

@@ -28,6 +28,8 @@
#include <modules/autonavigation/pathcreator.h>
#include <openspace/engine/globals.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/camera.h>
#include <openspace/util/timemanager.h>
@@ -77,6 +79,21 @@ namespace {
"Orbit Speed Factor",
"Controls the speed of the orbiting around an anchor."
};
constexpr const openspace::properties::Property::PropertyInfo MinBoundingSphereInfo = {
"MinimalValidBoundingSphere",
"Minimal Valid Bounding Sphere",
"The minimal allowed value for a bounding sphere, in meters. Used for "
"computation of target positions and path generation, to avoid issues when "
"there is no bounding sphere."
};
constexpr openspace::properties::Property::PropertyInfo RelevantNodeTagsInfo = {
"RelevantNodeTags",
"Relevant Node Tags",
"List of tags for the nodes that are relevant for path creation, for example "
"when avoiding collisions."
};
} // namespace
namespace openspace::pathnavigation {
@@ -95,6 +112,8 @@ PathNavigationHandler::PathNavigationHandler()
, _applyStopBehaviorWhenIdle(ApplyStopBehaviorWhenIdleInfo, false)
, _speedScale(SpeedScaleInfo, 1.f, 0.01f, 2.f)
, _orbitSpeedFactor(OrbitSpeedFactorInfo, 0.5, 0.0, 20.0)
, _minValidBoundingSphere(MinBoundingSphereInfo, 10.0, 1.0, 3e10)
, _relevantNodeTags(RelevantNodeTagsInfo)
{
_defaultCurveOption.addOptions({
{ Path::CurveType::AvoidCollision, "AvoidCollision" },
@@ -117,6 +136,15 @@ PathNavigationHandler::PathNavigationHandler()
addProperty(_stopBehavior);
addProperty(_orbitSpeedFactor);
addProperty(_minValidBoundingSphere);
_relevantNodeTags = std::vector<std::string>{
"planet_solarSystem",
"moon_solarSystem"
};;
_relevantNodeTags.onChange([this]() { findRelevantNodes(); });
addProperty(_relevantNodeTags);
}
PathNavigationHandler::~PathNavigationHandler() {} // NOLINT
@@ -348,6 +376,58 @@ std::vector<glm::dvec3> PathNavigationHandler::controlPoints() const {
return points;
}
double PathNavigationHandler::minValidBoundingSphere() const {
return _minValidBoundingSphere;
}
const std::vector<SceneGraphNode*>& PathNavigationHandler::relevantNodes() {
if (!_hasInitializedRelevantNodes) {
findRelevantNodes();
_hasInitializedRelevantNodes = true;
}
return _relevantNodes;
}
void PathNavigationHandler::findRelevantNodes() {
const std::vector<SceneGraphNode*>& allNodes =
global::renderEngine->scene()->allSceneGraphNodes();
const std::vector<std::string> relevantTags = _relevantNodeTags;
if (allNodes.empty() || relevantTags.empty()) {
_relevantNodes = std::vector<SceneGraphNode*>();
return;
}
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()
);
// does not match any tags => not interesting
if (result == relevantTags.end()) {
return false;
}
return node->renderable() && (node->boundingSphere() > 0.0);
};
std::vector<SceneGraphNode*> resultingNodes;
std::copy_if(
allNodes.begin(),
allNodes.end(),
std::back_inserter(resultingNodes),
isRelevant
);
_relevantNodes = resultingNodes;
}
void PathNavigationHandler::removeRollRotation(CameraPose& pose, double deltaTime) {
const glm::dvec3 anchorPos = anchor()->worldPosition();
const glm::dvec3 cameraDir = glm::normalize(

View File

@@ -25,10 +25,14 @@
#ifndef __OPENSPACE_MODULE_AUTONAVIGATION___PATHNAVIGATIONHANDLER___H__
#define __OPENSPACE_MODULE_AUTONAVIGATION___PATHNAVIGATIONHANDLER___H__
#include <openspace/properties/propertyowner.h>
#include <modules/autonavigation/path.h>
#include <openspace/properties/list/stringlistproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/doubleproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <ghoul/glm.h>
namespace openspace {
@@ -69,7 +73,12 @@ public:
std::vector<glm::dvec3> curveViewDirections(int nSteps) const;
std::vector<glm::dvec3> controlPoints() const;
double minValidBoundingSphere() const;
const std::vector<SceneGraphNode*>& relevantNodes();
private:
void findRelevantNodes();
void removeRollRotation(CameraPose& pose, double deltaTime);
void applyStopBehavior(double deltaTime);
@@ -85,6 +94,12 @@ private:
properties::BoolProperty _applyStopBehaviorWhenIdle;
properties::OptionProperty _stopBehavior;
properties::DoubleProperty _minValidBoundingSphere;
properties::StringListProperty _relevantNodeTags;
std::vector<SceneGraphNode*> _relevantNodes;
bool _hasInitializedRelevantNodes = false;
};
} // namespace openspace::pathnavigation

View File

@@ -106,8 +106,10 @@ SceneGraphNode* Waypoint::node() const {
double Waypoint::findValidBoundingSphere(const SceneGraphNode* node) {
double bs = static_cast<double>(node->boundingSphere());
const double minValidBoundingSphere =
global::moduleEngine->module<AutoNavigationModule>()->minValidBoundingSphere();
auto module = global::moduleEngine->module<AutoNavigationModule>();
const double minValidBoundingSphere =
module->PathNavigationHandler().minValidBoundingSphere();
if (bs < minValidBoundingSphere) {
// If the bs of the target is too small, try to find a good value in a child node.