Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getRootNode to TaskComposerGraph and update TaskComposerNodeInfo to store root_uuid #505

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Expand Up @@ -102,8 +105,8 @@ class TaskComposerNodeInfo
/** @brief The graph of pipeline terminals */
std::vector<boost::uuids::uuid> 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 };
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
10 changes: 7 additions & 3 deletions tesseract_task_composer/core/src/task_composer_node_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const TaskComposerGraph&>(node);
root_uuid = graph.getRootNode();
terminals = graph.getTerminals();
abort_terminal = graph.getAbortTerminalIndex();
triggers_abort = (graph.getAbortTerminalIndex() >= 0);
}
}

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 All @@ -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;
Expand All @@ -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 All @@ -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);
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
Loading