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

Fix "Plot Scene Graph" function #133

Merged
merged 1 commit into from
Nov 19, 2024
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
2 changes: 1 addition & 1 deletion common/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool saveDotImage(const tesseract_common::fs::path& dot_path,
gvc = gvContext();
fp = fopen(dot_path.c_str(), "r");
g = agread(fp, 0);
agsafeset(g, const_cast<char*>("dpi"), const_cast<char*>("300"), const_cast<char*>("300"));
agsafeset(g, const_cast<char*>("dpi"), const_cast<char*>("1000"), const_cast<char*>("1000"));
gvLayout(gvc, g, "dot");
gvRender(gvc, g, format.c_str(), fopen(save_path.c_str(), "w"));
gvFreeLayout(gvc, g);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class EnvironmentWidget : public QWidget
void setComponentInfo(std::shared_ptr<const ComponentInfo> component_info);
std::shared_ptr<const ComponentInfo> getComponentInfo() const;

public Q_SLOTS:
virtual void onPlotSceneGraph();

private:
struct Implementation;
std::unique_ptr<Ui::EnvironmentWidget> ui;
Expand Down
12 changes: 0 additions & 12 deletions environment/src/widgets/environment_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,4 @@ void EnvironmentWidget::setComponentInfo(std::shared_ptr<const ComponentInfo> co

std::shared_ptr<const ComponentInfo> EnvironmentWidget::getComponentInfo() const { return data_->component_info; }

void EnvironmentWidget::onPlotSceneGraph()
{
// tesseract_common::fs::path dot_path("/tmp/environment_widget_scene_graph.dot");
// tesseract_common::fs::path image_path("/tmp/environment_widget_scene_graph.png");
// data_->config->getEnvironment()->getSceneGraph()->saveDOT(dot_path.c_str());
// saveDotImage(dot_path, image_path, "png");

// auto* image_viewer = new ImageViewerWidget();
// image_viewer->loadImage(image_path.c_str());
// image_viewer->show();
}

} // namespace tesseract_gui
24 changes: 24 additions & 0 deletions scene_graph/src/models/scene_graph_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
#include <tesseract_qt/common/component_info.h>
#include <tesseract_qt/common/environment_manager.h>
#include <tesseract_qt/common/environment_wrapper.h>
#include <tesseract_qt/common/utils.h>
#include <tesseract_qt/common/widgets/image_viewer_widget.h>

#include <tesseract_common/utils.h>
#include <tesseract_scene_graph/graph.h>
#include <tesseract_scene_graph/link.h>
#include <tesseract_scene_graph/joint.h>
Expand Down Expand Up @@ -273,6 +276,27 @@ bool SceneGraphModel::eventFilter(QObject* obj, QEvent* event)
}
}
}
else if (event->type() == events::SceneGraphPlot::kType)
{
assert(dynamic_cast<events::SceneGraphPlot*>(event) != nullptr);
auto* e = static_cast<events::SceneGraphPlot*>(event);
if (e->getComponentInfo() == data_->component_info)
{
auto env_wrapper = EnvironmentManager::get(data_->component_info);
if (env_wrapper != nullptr && env_wrapper->getEnvironment()->isInitialized())
{
tesseract_common::fs::path dot_path(tesseract_common::getTempPath() + "environment_widget_scene_graph.dot");
tesseract_common::fs::path image_path(tesseract_common::getTempPath() + "environment_widget_scene_graph.png");

env_wrapper->getEnvironment()->getSceneGraph()->saveDOT(dot_path.c_str());
saveDotImage(dot_path, image_path, "png");

auto* image_viewer = new ImageViewerWidget();
image_viewer->loadImage(image_path.c_str());
image_viewer->show();
}
}
}

// Standard event processing
return QObject::eventFilter(obj, event);
Expand Down
Loading