Skip to content

Commit

Permalink
change layer names to strings and clean up layer key
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhhughes committed Nov 19, 2024
1 parent 8de35eb commit b5f8823
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 304 deletions.
34 changes: 24 additions & 10 deletions include/spark_dsg/dynamic_scene_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,29 @@ class DynamicSceneGraph {
using Layers = std::map<LayerId, SceneGraphLayer::Ptr>;
//! Dynamic layer container
using DynamicLayers = std::map<uint32_t, DynamicSceneGraphLayer::Ptr>;
//! Callback type
using LayerVisitor = std::function<void(LayerKey, BaseLayer*)>;

friend class SceneGraphLogger;

struct LayerKey {
std::optional<LayerId> layer;
uint32_t prefix = 0;
bool dynamic = false;

LayerKey() = default;
LayerKey(LayerId layer_id);
LayerKey(LayerId layer_id, uint32_t prefix);
bool isParent(const LayerKey& other) const;
bool isValid() const { return layer.has_value(); }
operator bool() const { return isValid(); }
bool operator==(const LayerKey& other) const;
inline bool operator!=(const LayerKey& other) const {
return !this->operator==(other);
}
};

//! Callback type
using LayerVisitor = std::function<void(LayerKey, BaseLayer*)>;

/**
* @brief Construct the scene graph (with a default layer factory)
*/
Expand Down Expand Up @@ -360,13 +378,6 @@ class DynamicSceneGraph {
*/
bool removeEdge(NodeId source, NodeId target);

/**
* @brief check if a particular node id is a dynamic node
* @param source Node to check
* @returns Return true if the node is a dynamic node
*/
bool isDynamic(NodeId source) const;

/**
* @brief Get the number of layers in the graph
* @return number of layers in the graph
Expand Down Expand Up @@ -528,7 +539,7 @@ class DynamicSceneGraph {
std::shared_ptr<Mesh> mesh() const;

//! Current static layer ids in the graph
const LayerIds layer_ids;
const LayerIds& layer_ids() const;

//! Any extra information about the graph
nlohmann::json metadata;
Expand Down Expand Up @@ -574,6 +585,7 @@ class DynamicSceneGraph {
void visitLayers(const LayerVisitor& cb);

protected:
LayerIds layer_ids_;
Layers layers_;
std::map<LayerId, DynamicLayers> dynamic_layers_;

Expand Down Expand Up @@ -632,4 +644,6 @@ class DynamicSceneGraph {
*/
DynamicSceneGraph::LayerIds getDefaultLayerIds();

std::ostream& operator<<(std::ostream& out, const DynamicSceneGraph::LayerKey& key);

} // namespace spark_dsg
26 changes: 0 additions & 26 deletions include/spark_dsg/layer_prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,6 @@
*/
namespace spark_dsg {

struct LayerKey {
LayerId layer;
uint32_t prefix = 0;
bool dynamic = false;

LayerKey();

LayerKey(LayerId layer_id);

LayerKey(LayerId layer_id, uint32_t prefix);

bool isParent(const LayerKey& other) const;

bool valid() const;

bool operator==(const LayerKey& other) const;

inline bool operator!=(const LayerKey& other) const {
return !this->operator==(other);
}
};

std::ostream& operator<<(std::ostream& out, const LayerKey& key);

class LayerPrefix {
public:
LayerPrefix(char key);
Expand Down Expand Up @@ -100,6 +76,4 @@ class LayerPrefix {
} value_;
};

std::ostream& operator<<(std::ostream& out, const LayerKey& key);

} // namespace spark_dsg
27 changes: 14 additions & 13 deletions include/spark_dsg/scene_graph_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ struct EdgeKey {
* @note A higher layer id corresponds to parents for interlayer edges
*/
struct DsgLayers {
inline const static LayerId SEGMENTS = 1; //< Pre-Object node layer (static)
inline const static LayerId OBJECTS = 2; //< Object node layer (static)
inline const static LayerId AGENTS = 2; //< Agents layer (dynamic)
inline const static LayerId PLACES = 3; //< Places node layer (as well as structure)
inline const static LayerId STRUCTURE = 3; //< Struct node layer (as well as places)
inline const static LayerId ROOMS = 4; //< Room node layer
inline const static LayerId BUILDINGS = 5; //< Building node layer
inline const static LayerId MESH_PLACES = 20; //< Mesh (2D) Places node layer
inline const static LayerId UNKNOWN =
std::numeric_limits<LayerId>::max(); //< Catchall layer ID

static std::string LayerIdToString(LayerId id);
static LayerId StringToLayerId(const std::string& id_str);
//< Pre-Object node layer (static)
inline const static std::string SEGMENTS = "SEGMENTS";
//< Object node layer (static)
inline const static std::string OBJECTS = "OBJECTS";
//< Agents layer (dynamic)
inline const static std::string AGENTS = "AGENTS";
//< Places node layer
inline const static std::string PLACES = "PLACES";
// //< Mesh (2D) Places node layer
inline const static std::string MESH_PLACES = "MESH_PLACES";
//< Room node layer
inline const static std::string ROOMS = "ROOMS";
//< Building node layer
inline const static std::string BUILDINGS = "BUILDINGS";
};

namespace graph_utilities {
Expand Down
15 changes: 7 additions & 8 deletions include/spark_dsg/scene_graph_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@
* -------------------------------------------------------------------------- */
#pragma once
#include "spark_dsg/bounding_box.h"
#include "spark_dsg/layer_prefix.h"
#include "spark_dsg/scene_graph_types.h"
#include "spark_dsg/spark_dsg_fwd.h"

namespace spark_dsg {

using SgNodeCallback = std::function<void(const DynamicSceneGraph&, const NodeId)>;

void getAncestorsOfLayer(const DynamicSceneGraph& graph,
NodeId parent,
LayerKey child_layer,
const SgNodeCallback& callback);
void getNodeAncestorsAtDepth(
const DynamicSceneGraph& graph,
NodeId parent,
size_t depth,
const std::function<void(const DynamicSceneGraph&, const NodeId)>& callback);

BoundingBox computeAncestorBoundingBox(
const DynamicSceneGraph& graph,
NodeId parent,
LayerId child_layer = DsgLayers::PLACES,
size_t depth = 1,
BoundingBox::Type bbox_type = BoundingBox::Type::AABB);

} // namespace spark_dsg
2 changes: 0 additions & 2 deletions python/bindings/src/spark_dsg_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ PYBIND11_MODULE(_dsg_bindings, module) {
.def_readonly_static("AGENTS", &DsgLayers::AGENTS)
.def_readonly_static("PLACES", &DsgLayers::PLACES)
.def_readonly_static("MESH_PLACES", &DsgLayers::MESH_PLACES)
.def_readonly_static("STRUCTURE", &DsgLayers::STRUCTURE)
.def_readonly_static("ROOMS", &DsgLayers::ROOMS)
.def_readonly_static("BUILDINGS", &DsgLayers::BUILDINGS);

Expand Down Expand Up @@ -769,7 +768,6 @@ PYBIND11_MODULE(_dsg_bindings, module) {
[](DynamicSceneGraph& graph, NodeSymbol source, NodeSymbol target) -> bool {
return graph.removeEdge(source, target);
})
.def("is_dynamic", &DynamicSceneGraph::isDynamic)
.def("num_layers", &DynamicSceneGraph::numLayers)
.def("num_dynamic_layers_of_type", &DynamicSceneGraph::numDynamicLayersOfType)
.def("num_dynamic_layers", &DynamicSceneGraph::numDynamicLayers)
Expand Down
Loading

0 comments on commit b5f8823

Please sign in to comment.