Skip to content

Commit

Permalink
Better viewer everywhere (#61)
Browse files Browse the repository at this point in the history
* Switch to convex hull visualization
* Use the newer viewer everywhere but in ROS related viewer
  • Loading branch information
niosus authored Feb 4, 2020
1 parent dcb78a0 commit 9120087
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 118 deletions.
6 changes: 4 additions & 2 deletions examples/simple_nodes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ target_link_libraries(show_objects_kitti
projections
ground_remove
folder_reader
visualization
viewer
drawable
${MY_QT_LIBRARIES}
${Boost_LIBRARIES}
${PCL_LIBRARIES}
Expand All @@ -20,7 +21,8 @@ target_link_libraries(show_objects_moosmann
projections
ground_remove
folder_reader
visualization
viewer
drawable
${MY_QT_LIBRARIES}
${Boost_LIBRARIES}
${PCL_LIBRARIES}
Expand Down
15 changes: 10 additions & 5 deletions examples/simple_nodes/show_objects_kitti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@

#include "ground_removal/depth_ground_remover.h"
#include "projections/projection_params.h"
#include "qt/drawables/drawable_cloud.h"
#include "qt/drawables/object_painter.h"
#include "utils/cloud.h"
#include "utils/folder_reader.h"
#include "utils/radians.h"
#include "utils/timer.h"
#include "utils/velodyne_utils.h"
#include "visualization/visualizer.h"

#include "tclap/CmdLine.h"

Expand All @@ -39,7 +40,7 @@ using std::string;
using namespace depth_clustering;

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

ObjectPainter object_painter{visualizer,
ObjectPainter::OutlineType::kPolygon3d};

depth_ground_remover.AddClient(&clusterer);
clusterer.AddClient(visualizer->object_clouds_client());
clusterer.AddClient(&object_painter);

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

for (auto path : cloud_reader.GetAllFilePaths()) {
time_utils::Timer timer;
auto cloud = ReadKittiCloud(path);
cloud->InitProjection(*proj_params_ptr);
visualizer->OnNewObjectReceived(*cloud, 0);
visualizer->Clear();
visualizer->AddDrawable(DrawableCloud::FromCloud(cloud));
depth_ground_remover.OnNewObjectReceived(*cloud, 0);

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

QApplication application(argc, argv);
// visualizer should be created from a gui thread
Visualizer visualizer;
Viewer visualizer;
visualizer.show();

// create and run loader thread
Expand Down
16 changes: 11 additions & 5 deletions examples/simple_nodes/show_objects_moosmann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

#include "ground_removal/depth_ground_remover.h"
#include "projections/projection_params.h"
#include "qt/drawables/object_painter.h"
#include "qt/drawables/drawable_cloud.h"
#include "qt/viewer/viewer.h"
#include "utils/cloud.h"
#include "utils/folder_reader.h"
#include "utils/radians.h"
#include "utils/timer.h"
#include "utils/velodyne_utils.h"
#include "visualization/visualizer.h"

#include "tclap/CmdLine.h"

Expand All @@ -40,7 +42,7 @@ using std::to_string;
using namespace depth_clustering;

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

ObjectPainter object_painter{visualizer,
ObjectPainter::OutlineType::kPolygon3d};

depth_ground_remover.AddClient(&clusterer);
clusterer.AddClient(visualizer->object_clouds_client());
clusterer.AddClient(&object_painter);

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

QApplication application(argc, argv);
// visualizer should be created from a gui thread
Visualizer visualizer;
Viewer visualizer;
visualizer.show();

// create and run loader thread
Expand Down
2 changes: 1 addition & 1 deletion src/clusterers/image_based_clusterer.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ImageBasedClusterer : public AbstractClusterer {
* @param[in] cloud The cloud to cluster
* @param[in] sender_id The sender identifier
*/
void OnNewObjectReceived(const Cloud& cloud, const int sender_id) override {
void OnNewObjectReceived(const Cloud& cloud, int) override {
// generate a projection from a point cloud
if (!cloud.projection_ptr()) {
fprintf(stderr, "ERROR: projection not initialized in cloud.\n");
Expand Down
5 changes: 4 additions & 1 deletion src/qt/drawables/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
add_library(drawable SHARED
drawable_cloud.cpp
object_painter.cpp
drawable_polygon3d.cpp
drawable_cube.cpp)
target_link_libraries(drawable
${OpenCV_LIBS}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY})
${OPENGL_glu_LIBRARY})
46 changes: 0 additions & 46 deletions src/qt/drawables/bbox_painter.h

This file was deleted.

1 change: 1 addition & 0 deletions src/qt/drawables/drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Drawable {
public:
using Ptr = std::shared_ptr<Drawable>;
using UniquePtr = std::unique_ptr<Drawable>;
virtual void Draw() const = 0;
virtual ~Drawable() {}
};
Expand Down
8 changes: 7 additions & 1 deletion src/qt/drawables/drawable_cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
#include "./drawable_cube.h"
#include <GL/glut.h>

namespace depth_clustering {

void DrawableCube::Draw() const {
if (_scale.z() < 0.3) { return; }
if (_scale.z() < 0.3) {
return;
}
glPushMatrix();
glTranslatef(_center.x(), _center.y(), _center.z());
glScalef(_scale.x(), _scale.y(), _scale.z());
Expand Down Expand Up @@ -53,3 +57,5 @@ void DrawableCube::Draw() const {
glEnd();
glPopMatrix();
}

} // namespace depth_clustering
10 changes: 8 additions & 2 deletions src/qt/drawables/drawable_cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <Eigen/Core>

#include "qt/drawables/drawable.h"
#include "utils/mem_utils.h"

namespace depth_clustering {

class DrawableCube : public Drawable {
public:
Expand All @@ -16,10 +19,11 @@ class DrawableCube : public Drawable {
: _center{center}, _scale{scale}, _color{color} {}

void Draw() const override;
static DrawableCube::Ptr Create(
static DrawableCube::UniquePtr Create(
const Eigen::Vector3f& center, const Eigen::Vector3f& scale,
const Eigen::Vector3f& color = Eigen::Vector3f(1.0f, 0.5f, 0.2f)) {
return std::make_shared<DrawableCube>(DrawableCube(center, scale, color));
return mem_utils::make_unique<DrawableCube>(
DrawableCube(center, scale, color));
}

~DrawableCube() override {}
Expand All @@ -30,4 +34,6 @@ class DrawableCube : public Drawable {
Eigen::Vector3f _color;
};

} // namespace depth_clustering

#endif // SRC_QT_DRAWABLES_DRAWABLE_CUBE_H_
44 changes: 44 additions & 0 deletions src/qt/drawables/drawable_polygon3d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright Igor Bogoslavskyi, year 2017.
// In case of any problems with the code please contact me.
// Email: [email protected].

#include "./drawable_polygon3d.h"
#include <GL/glut.h>

namespace depth_clustering {

void DrawablePolygon3d::Draw() const {
if (polygon_.empty()) {
return;
}
glPushMatrix();
const auto start = polygon_.front();
glColor3f(color_[0], color_[1], color_[2]);
glLineWidth(4.0f);
glBegin(GL_LINE_STRIP);

// Bottom polygon
for (const auto& point : polygon_) {
glVertex3f(point.x(), point.y(), point.z());
}
glVertex3f(start.x(), start.y(), start.z());

// Top polygon
for (const auto& point : polygon_) {
glVertex3f(point.x(), point.y(), point.z() + height_);
}
glVertex3f(start.x(), start.y(), start.z() + height_);

glEnd();

glBegin(GL_LINES);
// For the Sides of the polygon
for (const auto& point : polygon_) {
glVertex3f(point.x(), point.y(), point.z());
glVertex3f(point.x(), point.y(), point.z() + height_);
}
glEnd();
glPopMatrix();
}

} // namespace depth_clustering
42 changes: 42 additions & 0 deletions src/qt/drawables/drawable_polygon3d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright Igor Bogoslavskyi, year 2017.
// In case of any problems with the code please contact me.
// Email: [email protected].

#ifndef SRC_QT_DRAWABLES_DRAWABLE_POLYGON3D_H_
#define SRC_QT_DRAWABLES_DRAWABLE_POLYGON3D_H_

#include <Eigen/Core>
#include <vector>

#include "qt/drawables/drawable.h"
#include "utils/mem_utils.h"

namespace depth_clustering {

class DrawablePolygon3d : public Drawable {
public:
using AlignedEigenVectors =
std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>>;
DrawablePolygon3d(const AlignedEigenVectors& polygon, float height,
const Eigen::Vector3f& color)
: polygon_{polygon}, height_{height}, color_{color} {}

void Draw() const override;
static DrawablePolygon3d::UniquePtr Create(
const AlignedEigenVectors& polygon, float height,
const Eigen::Vector3f& color = Eigen::Vector3f(1.0f, 0.5f, 0.2f)) {
return mem_utils::make_unique<DrawablePolygon3d>(
DrawablePolygon3d(polygon, height, color));
}

~DrawablePolygon3d() override {}

private:
AlignedEigenVectors polygon_;
float height_;
Eigen::Vector3f color_;
};

} // namespace depth_clustering

#endif // SRC_QT_DRAWABLES_DRAWABLE_POLYGON3D_H_
Loading

0 comments on commit 9120087

Please sign in to comment.