Skip to content

Commit 9120087

Browse files
authored
Better viewer everywhere (PRBonn#61)
* Switch to convex hull visualization * Use the newer viewer everywhere but in ROS related viewer
1 parent dcb78a0 commit 9120087

19 files changed

+260
-118
lines changed

examples/simple_nodes/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ target_link_libraries(show_objects_kitti
66
projections
77
ground_remove
88
folder_reader
9-
visualization
9+
viewer
10+
drawable
1011
${MY_QT_LIBRARIES}
1112
${Boost_LIBRARIES}
1213
${PCL_LIBRARIES}
@@ -20,7 +21,8 @@ target_link_libraries(show_objects_moosmann
2021
projections
2122
ground_remove
2223
folder_reader
23-
visualization
24+
viewer
25+
drawable
2426
${MY_QT_LIBRARIES}
2527
${Boost_LIBRARIES}
2628
${PCL_LIBRARIES}

examples/simple_nodes/show_objects_kitti.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
#include "ground_removal/depth_ground_remover.h"
2727
#include "projections/projection_params.h"
28+
#include "qt/drawables/drawable_cloud.h"
29+
#include "qt/drawables/object_painter.h"
2830
#include "utils/cloud.h"
2931
#include "utils/folder_reader.h"
3032
#include "utils/radians.h"
3133
#include "utils/timer.h"
3234
#include "utils/velodyne_utils.h"
33-
#include "visualization/visualizer.h"
3435

3536
#include "tclap/CmdLine.h"
3637

@@ -39,7 +40,7 @@ using std::string;
3940
using namespace depth_clustering;
4041

4142
void ReadData(const Radians& angle_tollerance, const string& in_path,
42-
Visualizer* visualizer) {
43+
Viewer* visualizer) {
4344
// delay reading for one second to allow GUI to load
4445
std::this_thread::sleep_for(std::chrono::milliseconds(500));
4546
// now load the data
@@ -63,16 +64,20 @@ void ReadData(const Radians& angle_tollerance, const string& in_path,
6364
angle_tollerance, min_cluster_size, max_cluster_size);
6465
clusterer.SetDiffType(DiffFactory::DiffType::ANGLES);
6566

67+
ObjectPainter object_painter{visualizer,
68+
ObjectPainter::OutlineType::kPolygon3d};
69+
6670
depth_ground_remover.AddClient(&clusterer);
67-
clusterer.AddClient(visualizer->object_clouds_client());
71+
clusterer.AddClient(&object_painter);
6872

6973
fprintf(stderr, "INFO: everything initialized\n");
7074

7175
for (auto path : cloud_reader.GetAllFilePaths()) {
7276
time_utils::Timer timer;
7377
auto cloud = ReadKittiCloud(path);
7478
cloud->InitProjection(*proj_params_ptr);
75-
visualizer->OnNewObjectReceived(*cloud, 0);
79+
visualizer->Clear();
80+
visualizer->AddDrawable(DrawableCloud::FromCloud(cloud));
7681
depth_ground_remover.OnNewObjectReceived(*cloud, 0);
7782

7883
uint max_wait_time = 100;
@@ -108,7 +113,7 @@ int main(int argc, char* argv[]) {
108113

109114
QApplication application(argc, argv);
110115
// visualizer should be created from a gui thread
111-
Visualizer visualizer;
116+
Viewer visualizer;
112117
visualizer.show();
113118

114119
// create and run loader thread

examples/simple_nodes/show_objects_moosmann.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525

2626
#include "ground_removal/depth_ground_remover.h"
2727
#include "projections/projection_params.h"
28+
#include "qt/drawables/object_painter.h"
29+
#include "qt/drawables/drawable_cloud.h"
30+
#include "qt/viewer/viewer.h"
2831
#include "utils/cloud.h"
2932
#include "utils/folder_reader.h"
3033
#include "utils/radians.h"
3134
#include "utils/timer.h"
3235
#include "utils/velodyne_utils.h"
33-
#include "visualization/visualizer.h"
3436

3537
#include "tclap/CmdLine.h"
3638

@@ -40,7 +42,7 @@ using std::to_string;
4042
using namespace depth_clustering;
4143

4244
void ReadData(const Radians& angle_tollerance, const string& in_path,
43-
Visualizer* visualizer) {
45+
Viewer* visualizer) {
4446
// delay reading for one second to allow GUI to load
4547
std::this_thread::sleep_for(std::chrono::milliseconds(500));
4648
// now load the data
@@ -65,14 +67,18 @@ void ReadData(const Radians& angle_tollerance, const string& in_path,
6567
angle_tollerance, min_cluster_size, max_cluster_size);
6668
clusterer.SetDiffType(DiffFactory::DiffType::ANGLES);
6769

70+
ObjectPainter object_painter{visualizer,
71+
ObjectPainter::OutlineType::kPolygon3d};
72+
6873
depth_ground_remover.AddClient(&clusterer);
69-
clusterer.AddClient(visualizer->object_clouds_client());
74+
clusterer.AddClient(&object_painter);
7075

7176
for (const auto& path : image_reader.GetAllFilePaths()) {
7277
auto depth_image = MatFromDepthPng(path);
7378
auto cloud_ptr = Cloud::FromImage(depth_image, *proj_params_ptr);
7479
time_utils::Timer timer;
75-
visualizer->OnNewObjectReceived(*cloud_ptr, 0);
80+
visualizer->Clear();
81+
visualizer->AddDrawable(DrawableCloud::FromCloud(cloud_ptr));
7682
depth_ground_remover.OnNewObjectReceived(*cloud_ptr, 0);
7783
auto current_millis = timer.measure(time_utils::Timer::Units::Milli);
7884
fprintf(stderr, "INFO: It took %lu ms to process and show everything.\n",
@@ -108,7 +114,7 @@ int main(int argc, char* argv[]) {
108114

109115
QApplication application(argc, argv);
110116
// visualizer should be created from a gui thread
111-
Visualizer visualizer;
117+
Viewer visualizer;
112118
visualizer.show();
113119

114120
// create and run loader thread

src/clusterers/image_based_clusterer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ImageBasedClusterer : public AbstractClusterer {
8888
* @param[in] cloud The cloud to cluster
8989
* @param[in] sender_id The sender identifier
9090
*/
91-
void OnNewObjectReceived(const Cloud& cloud, const int sender_id) override {
91+
void OnNewObjectReceived(const Cloud& cloud, int) override {
9292
// generate a projection from a point cloud
9393
if (!cloud.projection_ptr()) {
9494
fprintf(stderr, "ERROR: projection not initialized in cloud.\n");

src/qt/drawables/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
add_library(drawable SHARED
22
drawable_cloud.cpp
3+
object_painter.cpp
4+
drawable_polygon3d.cpp
35
drawable_cube.cpp)
46
target_link_libraries(drawable
7+
${OpenCV_LIBS}
58
${OPENGL_gl_LIBRARY}
6-
${OPENGL_glu_LIBRARY})
9+
${OPENGL_glu_LIBRARY})

src/qt/drawables/bbox_painter.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/qt/drawables/drawable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class Drawable {
1111
public:
1212
using Ptr = std::shared_ptr<Drawable>;
13+
using UniquePtr = std::unique_ptr<Drawable>;
1314
virtual void Draw() const = 0;
1415
virtual ~Drawable() {}
1516
};

src/qt/drawables/drawable_cube.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
#include "./drawable_cube.h"
66
#include <GL/glut.h>
77

8+
namespace depth_clustering {
9+
810
void DrawableCube::Draw() const {
9-
if (_scale.z() < 0.3) { return; }
11+
if (_scale.z() < 0.3) {
12+
return;
13+
}
1014
glPushMatrix();
1115
glTranslatef(_center.x(), _center.y(), _center.z());
1216
glScalef(_scale.x(), _scale.y(), _scale.z());
@@ -53,3 +57,5 @@ void DrawableCube::Draw() const {
5357
glEnd();
5458
glPopMatrix();
5559
}
60+
61+
} // namespace depth_clustering

src/qt/drawables/drawable_cube.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <Eigen/Core>
99

1010
#include "qt/drawables/drawable.h"
11+
#include "utils/mem_utils.h"
12+
13+
namespace depth_clustering {
1114

1215
class DrawableCube : public Drawable {
1316
public:
@@ -16,10 +19,11 @@ class DrawableCube : public Drawable {
1619
: _center{center}, _scale{scale}, _color{color} {}
1720

1821
void Draw() const override;
19-
static DrawableCube::Ptr Create(
22+
static DrawableCube::UniquePtr Create(
2023
const Eigen::Vector3f& center, const Eigen::Vector3f& scale,
2124
const Eigen::Vector3f& color = Eigen::Vector3f(1.0f, 0.5f, 0.2f)) {
22-
return std::make_shared<DrawableCube>(DrawableCube(center, scale, color));
25+
return mem_utils::make_unique<DrawableCube>(
26+
DrawableCube(center, scale, color));
2327
}
2428

2529
~DrawableCube() override {}
@@ -30,4 +34,6 @@ class DrawableCube : public Drawable {
3034
Eigen::Vector3f _color;
3135
};
3236

37+
} // namespace depth_clustering
38+
3339
#endif // SRC_QT_DRAWABLES_DRAWABLE_CUBE_H_
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright Igor Bogoslavskyi, year 2017.
2+
// In case of any problems with the code please contact me.
3+
4+
5+
#include "./drawable_polygon3d.h"
6+
#include <GL/glut.h>
7+
8+
namespace depth_clustering {
9+
10+
void DrawablePolygon3d::Draw() const {
11+
if (polygon_.empty()) {
12+
return;
13+
}
14+
glPushMatrix();
15+
const auto start = polygon_.front();
16+
glColor3f(color_[0], color_[1], color_[2]);
17+
glLineWidth(4.0f);
18+
glBegin(GL_LINE_STRIP);
19+
20+
// Bottom polygon
21+
for (const auto& point : polygon_) {
22+
glVertex3f(point.x(), point.y(), point.z());
23+
}
24+
glVertex3f(start.x(), start.y(), start.z());
25+
26+
// Top polygon
27+
for (const auto& point : polygon_) {
28+
glVertex3f(point.x(), point.y(), point.z() + height_);
29+
}
30+
glVertex3f(start.x(), start.y(), start.z() + height_);
31+
32+
glEnd();
33+
34+
glBegin(GL_LINES);
35+
// For the Sides of the polygon
36+
for (const auto& point : polygon_) {
37+
glVertex3f(point.x(), point.y(), point.z());
38+
glVertex3f(point.x(), point.y(), point.z() + height_);
39+
}
40+
glEnd();
41+
glPopMatrix();
42+
}
43+
44+
} // namespace depth_clustering

0 commit comments

Comments
 (0)