Skip to content

Commit e56768a

Browse files
nathanhhughesGoldenZephyr
authored andcommitted
Feature/viser (#73)
* (wip) start working on viser-based visualizer * draw basic structure * use array view of graph for visualization * add gui and update * add colors * working default colormaps * start on config hooks * fix updating on config changes * factor out graph from viser renderer and add context manager * add conditional text * clear labels from scene * Feature/viser aaron (#75) * Fix viser with empty layer? * fix * another fix * make viser optional because of number of deps * add initial bounding box attempt * add docstrings and clean up layer draw * fix gui settings * fix interlayer and add agents default --------- Co-authored-by: Aaron Ray <aaronray@mit.edu>
1 parent 13f7fc8 commit e56768a

File tree

8 files changed

+617
-681
lines changed

8 files changed

+617
-681
lines changed

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ readme = "README.md"
1010
license = "BSD-3-Clause"
1111
requires-python = ">=3.8"
1212
dependencies = [
13+
"click",
1314
"numpy",
1415
"seaborn",
1516
"shapely",
@@ -28,11 +29,7 @@ classifiers = [
2829
]
2930

3031
[project.optional-dependencies]
31-
viz = [
32-
"plotly",
33-
"open3d >= 0.17",
34-
"scipy",
35-
]
32+
viz = ["trimesh", "viser"]
3633

3734
[project.urls]
3835
Repository = "https://github.com/MIT-SPARK/Spark-DSG"

python/bindings/src/color.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,29 @@
3434
* -------------------------------------------------------------------------- */
3535
#include "spark_dsg/python/color.h"
3636

37+
#include <pybind11/eigen.h>
3738
#include <spark_dsg/color.h>
39+
#include <spark_dsg/colormaps.h>
40+
41+
#include <Eigen/Dense>
3842

3943
namespace spark_dsg::python {
4044

4145
namespace py = pybind11;
42-
43-
using namespace spark_dsg;
46+
using namespace py::literals;
4447

4548
void init_color(py::module_& m) {
46-
// TODO(nathan) colormaps
47-
4849
py::class_<Color>(m, "Color")
50+
.def(py::init())
4951
.def_readwrite("r", &Color::r)
5052
.def_readwrite("g", &Color::g)
5153
.def_readwrite("b", &Color::b)
52-
.def_readwrite("a", &Color::a);
54+
.def_readwrite("a", &Color::a)
55+
.def("to_float_array", [](const Color& c) { return Eigen::Vector3f(c.r / 255.0, c.g / 255.0, c.b / 255.0); });
56+
57+
m.def("colorbrewer_color", &colormaps::colorbrewerId);
58+
m.def("distinct_150_color", &colormaps::distinct150Id);
59+
m.def("rainbow_color", &colormaps::rainbowId, "id"_a, "ids_per_revolution"_a = 16);
5360
}
5461

5562
} // namespace spark_dsg::python

python/bindings/src/scene_graph_layer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ void init_scene_graph_layer(py::module_& m) {
109109
.def("num_nodes", &LayerView::numNodes)
110110
.def("num_edges", &LayerView::numEdges)
111111
.def("get_position", &LayerView::getPosition)
112+
.def_property(
113+
"key", [](const LayerView& view) { return view.id; }, nullptr)
112114
.def_property(
113115
"id", [](const LayerView& view) { return view.id.layer; }, nullptr)
114116
.def_property(

python/spark_dsg/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
SceneGraphLayer,
5151
compute_ancestor_bounding_box,
5252
)
53-
from spark_dsg.open3d_visualization import render_to_open3d
5453
from spark_dsg.torch_conversion import scene_graph_layer_to_torch, scene_graph_to_torch
55-
from spark_dsg.visualization import plot_scene_graph
5654

5755

5856
def add_bounding_boxes_to_layer(
@@ -104,7 +102,7 @@ def _hash_layerkey(key):
104102

105103
def _get_layer_id(graph, name):
106104
warnings.warn(
107-
"'get_layer_key' is deprecated. Please use 'get_layer_key'",
105+
"'get_layer_id' is deprecated. Please use 'get_layer_key'",
108106
DeprecationWarning,
109107
stacklevel=2,
110108
)
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
"""Entry point for visualizing scene graph."""
22

3+
import time
4+
35
import click
46
import spark_dsg as dsg
5-
from spark_dsg.open3d_visualization import render_to_open3d
7+
from spark_dsg.viser import ViserRenderer
68

79

810
@click.command("visualize")
911
@click.argument("filepath", type=click.Path(exists=True))
10-
def cli(filepath):
12+
@click.option("--ip", default="localhost")
13+
@click.option("--port", default="8080")
14+
def cli(filepath, ip, port):
1115
"""Visualize a scene graph from FILEPATH using Open3D."""
1216
G = dsg.DynamicSceneGraph.load(filepath)
13-
render_to_open3d(G)
14-
print("Done.")
17+
18+
with ViserRenderer(ip, port=port) as renderer:
19+
renderer.draw(G)
20+
while True:
21+
time.sleep(10.0)

0 commit comments

Comments
 (0)