From f3cb91d65c2f8c4afe0531492e9f826a045d1cab Mon Sep 17 00:00:00 2001 From: Levi Armstrong Date: Thu, 15 Aug 2024 14:20:10 -0500 Subject: [PATCH] Add getRootNode to TaskComposerGraph and update TaskComposerNodeInfo to store root_uuid --- .../core/task_composer_graph.h | 6 ++++++ .../core/task_composer_node_info.h | 7 +++++-- .../core/src/task_composer_graph.cpp | 14 ++++++++++++++ .../core/src/task_composer_node.cpp | 2 -- .../core/src/task_composer_node_info.cpp | 10 +++++++--- .../core/src/task_composer_pipeline.cpp | 10 +--------- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_graph.h b/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_graph.h index 2132a16e4b..49de1d3d75 100644 --- a/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_graph.h +++ b/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_graph.h @@ -59,6 +59,12 @@ class TaskComposerGraph : public TaskComposerNode TaskComposerGraph(TaskComposerGraph&&) = delete; TaskComposerGraph& operator=(TaskComposerGraph&&) = delete; + /** + * @brief Get the root node of the graph + * @return The root node uuid + */ + boost::uuids::uuid getRootNode() const; + /** * @brief Add a node to the pipeline * @return The node ID which should be used with adding edges diff --git a/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_node_info.h b/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_node_info.h index 6bce2b33f6..f8cdaec107 100644 --- a/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_node_info.h +++ b/tesseract_task_composer/core/include/tesseract_task_composer/core/task_composer_node_info.h @@ -72,6 +72,9 @@ class TaskComposerNodeInfo /** @brief The task uuid */ boost::uuids::uuid uuid{}; + /** @brief If type is Pipeline or Graph this will be the root node of the pipeline or graph, otherwise null */ + boost::uuids::uuid root_uuid{}; + /** * @brief The parent uuid * @details This is set when the node is added to a graph @@ -102,8 +105,8 @@ class TaskComposerNodeInfo /** @brief The graph of pipeline terminals */ std::vector terminals; - /** @brief Indicate if abort terminal was assigned. Only valid for graph and pipelines */ - int abort_terminal{ -1 }; + /** @brief Indicate if it can trigger a abort. */ + bool triggers_abort{ false }; /** @brief Value returned from the Task on completion */ int return_value{ -1 }; diff --git a/tesseract_task_composer/core/src/task_composer_graph.cpp b/tesseract_task_composer/core/src/task_composer_graph.cpp index 76fb10b5e0..046a81f506 100644 --- a/tesseract_task_composer/core/src/task_composer_graph.cpp +++ b/tesseract_task_composer/core/src/task_composer_graph.cpp @@ -267,6 +267,20 @@ std::unique_ptr TaskComposerGraph::runImpl(TaskComposerCon throw std::runtime_error("TaskComposerGraph, with name '" + name_ + "' has no node info for any of the leaf nodes!"); } +boost::uuids::uuid TaskComposerGraph::getRootNode() const +{ + boost::uuids::uuid root_node{}; + for (const auto& pair : nodes_) + { + if (pair.second->getInboundEdges().empty()) + { + root_node = pair.first; + break; + } + } + return root_node; +} + boost::uuids::uuid TaskComposerGraph::addNode(std::unique_ptr task_node) { boost::uuids::uuid uuid = task_node->getUUID(); diff --git a/tesseract_task_composer/core/src/task_composer_node.cpp b/tesseract_task_composer/core/src/task_composer_node.cpp index e8119339b0..a244acc140 100644 --- a/tesseract_task_composer/core/src/task_composer_node.cpp +++ b/tesseract_task_composer/core/src/task_composer_node.cpp @@ -141,8 +141,6 @@ int TaskComposerNode::run(TaskComposerContext& context, OptionalTaskComposerExec { auto info = std::make_unique(*this); info->start_time = start_time; - info->input_keys = input_keys_; - info->output_keys = output_keys_; info->return_value = 0; info->color = "grey"; info->status_code = 0; diff --git a/tesseract_task_composer/core/src/task_composer_node_info.cpp b/tesseract_task_composer/core/src/task_composer_node_info.cpp index 9860ab722e..c92cbc7360 100644 --- a/tesseract_task_composer/core/src/task_composer_node_info.cpp +++ b/tesseract_task_composer/core/src/task_composer_node_info.cpp @@ -55,12 +55,14 @@ TaskComposerNodeInfo::TaskComposerNodeInfo(const TaskComposerNode& node) , outbound_edges(node.outbound_edges_) , input_keys(node.input_keys_) , output_keys(node.output_keys_) + , triggers_abort(node.trigger_abort_) { if (type == TaskComposerNodeType::GRAPH || type == TaskComposerNodeType::PIPELINE) { const auto& graph = static_cast(node); + root_uuid = graph.getRootNode(); terminals = graph.getTerminals(); - abort_terminal = graph.getAbortTerminalIndex(); + triggers_abort = (graph.getAbortTerminalIndex() >= 0); } } @@ -72,6 +74,7 @@ bool TaskComposerNodeInfo::operator==(const TaskComposerNodeInfo& rhs) const equal &= name == rhs.name; equal &= ns == rhs.ns; equal &= uuid == rhs.uuid; + equal &= root_uuid == rhs.root_uuid; equal &= parent_uuid == rhs.parent_uuid; equal &= type == rhs.type; equal &= type_hash_code == rhs.type_hash_code; @@ -86,7 +89,7 @@ bool TaskComposerNodeInfo::operator==(const TaskComposerNodeInfo& rhs) const equal &= input_keys == rhs.input_keys; equal &= output_keys == rhs.output_keys; equal &= terminals == rhs.terminals; - equal &= abort_terminal == rhs.abort_terminal; + equal &= triggers_abort == rhs.triggers_abort; equal &= color == rhs.color; equal &= dotgraph == rhs.dotgraph; equal &= data_storage == rhs.data_storage; @@ -104,6 +107,7 @@ void TaskComposerNodeInfo::serialize(Archive& ar, const unsigned int /*version*/ ar& boost::serialization::make_nvp("name", name); ar& boost::serialization::make_nvp("ns", ns); ar& boost::serialization::make_nvp("uuid", uuid); + ar& boost::serialization::make_nvp("root_uuid", root_uuid); ar& boost::serialization::make_nvp("parent_uuid", parent_uuid); ar& boost::serialization::make_nvp("type", type); ar& boost::serialization::make_nvp("type_hash_code", type_hash_code); @@ -119,7 +123,7 @@ void TaskComposerNodeInfo::serialize(Archive& ar, const unsigned int /*version*/ ar& boost::serialization::make_nvp("input_keys", input_keys); ar& boost::serialization::make_nvp("output_keys", output_keys); ar& boost::serialization::make_nvp("terminals", terminals); - ar& boost::serialization::make_nvp("abort_terminal", abort_terminal); + ar& boost::serialization::make_nvp("triggers_abort", triggers_abort); ar& boost::serialization::make_nvp("color", color); ar& boost::serialization::make_nvp("dotgraph", dotgraph); ar& boost::serialization::make_nvp("data_storage", data_storage); diff --git a/tesseract_task_composer/core/src/task_composer_pipeline.cpp b/tesseract_task_composer/core/src/task_composer_pipeline.cpp index 4c8fb4543e..f793780215 100644 --- a/tesseract_task_composer/core/src/task_composer_pipeline.cpp +++ b/tesseract_task_composer/core/src/task_composer_pipeline.cpp @@ -58,15 +58,7 @@ std::unique_ptr TaskComposerPipeline::runImpl(TaskComposer tesseract_common::Timer timer; timer.start(); - boost::uuids::uuid root_node{}; - for (const auto& pair : nodes_) - { - if (pair.second->getInboundEdges().empty()) - { - root_node = pair.first; - break; - } - } + boost::uuids::uuid root_node = getRootNode(); if (root_node.is_nil()) throw std::runtime_error("TaskComposerPipeline, with name '" + name_ + "' does not have a root node!");