Skip to content

Commit

Permalink
Add getRootNode to TaskComposerGraph and update TaskComposerNodeInfo …
Browse files Browse the repository at this point in the history
…to store root_uuid
  • Loading branch information
Levi-Armstrong committed Aug 16, 2024
1 parent c2c6e17 commit a345a15
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tesseract_task_composer/core/src/task_composer_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ std::unique_ptr<TaskComposerNodeInfo> 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<TaskComposerNode> task_node)
{
boost::uuids::uuid uuid = task_node->getUUID();
Expand Down
2 changes: 0 additions & 2 deletions tesseract_task_composer/core/src/task_composer_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ int TaskComposerNode::run(TaskComposerContext& context, OptionalTaskComposerExec
{
auto info = std::make_unique<TaskComposerNodeInfo>(*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;
Expand Down
4 changes: 4 additions & 0 deletions tesseract_task_composer/core/src/task_composer_node_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ TaskComposerNodeInfo::TaskComposerNodeInfo(const TaskComposerNode& node)
if (type == TaskComposerNodeType::GRAPH || type == TaskComposerNodeType::PIPELINE)
{
const auto& graph = static_cast<const TaskComposerGraph&>(node);
root_uuid = graph.getRootNode();
terminals = graph.getTerminals();
abort_terminal = graph.getAbortTerminalIndex();
assert(!root_uuid.is_nil());
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 1 addition & 9 deletions tesseract_task_composer/core/src/task_composer_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ std::unique_ptr<TaskComposerNodeInfo> 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!");
Expand Down

0 comments on commit a345a15

Please sign in to comment.