diff --git a/CMakeLists.txt b/CMakeLists.txt index 872a1c3..9ef4601 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,13 @@ endif() project(QtKittiVisualizer) + + + +if (MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS -DBOOST_ALL_NO_LIB -DBOOST_ALL_DYN_LINK -DBOOST_LOG_DYN_LINK) +endif() + find_package(VTK REQUIRED) include(${VTK_USE_FILE}) @@ -29,7 +36,7 @@ set(PROJECT_BINARY_NAME qt-kitti-visualizer) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) -find_package(Boost 1.54 COMPONENTS program_options filesystem REQUIRED) +find_package(Boost 1.54 COMPONENTS program_options filesystem serialization REQUIRED) set(Boost_COMPONENTS_INCLUDE_DIRS ${Boost_INCLUDE_DIRS}) set(Boost_COMPONENTS_LIBRARY_DIRS ${Boost_LIBRARY_DIRS}) set(Boost_COMPONENTS_LIBRARIES ${Boost_LIBRARIES}) @@ -45,6 +52,7 @@ add_definitions(${PCL_DEFINITIONS}) set(CPP_FILES KittiConfig.cpp KittiDataset.cpp + KittiImage.cpp main.cpp QtKittiVisualizer.cpp ) diff --git a/KittiConfig.cpp b/KittiConfig.cpp index c2b23ea..114b8b8 100644 --- a/KittiConfig.cpp +++ b/KittiConfig.cpp @@ -25,11 +25,14 @@ limitations under the License. #include #include -std::string KittiConfig::data_directory = "../KittiData"; -std::string KittiConfig::raw_data_directory = "raw"; +//std::string KittiConfig::data_directory = "../KittiData"; +std::string KittiConfig::data_directory = "D:\\KITTI\\2011_09_26"; +std::string KittiConfig::raw_data_directory = ""; std::string KittiConfig::dataset_folder_template = "%|04|_sync"; -std::string KittiConfig::point_cloud_directory = "velodyne_points/data"; +std::string KittiConfig::point_cloud_directory = "velodyne_points\\data"; std::string KittiConfig::point_cloud_file_template = "%|010|.bin"; +std::string KittiConfig::image_directory = "image_02\\data"; +std::string KittiConfig::image_file_template = "%|010|.png"; std::string KittiConfig::tracklets_directory = "."; std::string KittiConfig::tracklets_file_name = "tracklet_labels.xml"; @@ -61,6 +64,24 @@ boost::filesystem::path KittiConfig::getTrackletsPath(int dataset) ; } +boost::filesystem::path KittiConfig::getImagePath(int dataset) +{ + + return boost::filesystem::path(data_directory) + / raw_data_directory + / (boost::format(dataset_folder_template) % dataset).str() + / image_directory + ; +} +boost::filesystem::path KittiConfig::getImagePath(int dataset, int frameId) +{ + + return getImagePath(dataset) + / (boost::format(image_file_template) % frameId).str() + ; +} + + int KittiConfig::getDatasetNumber(int index) { if (index >= 0 && index < availableDatasets.size()) diff --git a/KittiConfig.h b/KittiConfig.h index 362c90a..bc3c517 100644 --- a/KittiConfig.h +++ b/KittiConfig.h @@ -52,6 +52,8 @@ class KittiConfig static boost::filesystem::path getPointCloudPath(int dataset); static boost::filesystem::path getPointCloudPath(int dataset,int frameId); static boost::filesystem::path getTrackletsPath(int dataset); + static boost::filesystem::path getImagePath(int dataset); + static boost::filesystem::path getImagePath(int dataset, int frameId); /** Contains the numbers of data sets available from your data set folder */ static const std::vector availableDatasets; @@ -67,6 +69,8 @@ class KittiConfig static std::string dataset_folder_template; static std::string point_cloud_directory; static std::string point_cloud_file_template; + static std::string image_directory; + static std::string image_file_template; static std::string tracklets_directory; static std::string tracklets_file_name; diff --git a/KittiDataset.cpp b/KittiDataset.cpp index cef25ea..d861123 100644 --- a/KittiDataset.cpp +++ b/KittiDataset.cpp @@ -85,6 +85,11 @@ KittiPointCloud::Ptr KittiDataset::getPointCloud(int frameId) return cloud; } +std::string KittiDataset::getImageFileName(int frameId) +{ + return std::string(KittiConfig::getImagePath(_dataset, frameId).string()); +} + KittiPointCloud::Ptr KittiDataset::getTrackletPointCloud(KittiPointCloud::Ptr& pointCloud, const KittiTracklet& tracklet, int frameId) { int pose_number = frameId - tracklet.first_frame; diff --git a/KittiDataset.h b/KittiDataset.h index 693a7c5..d7da7ad 100644 --- a/KittiDataset.h +++ b/KittiDataset.h @@ -44,6 +44,7 @@ class KittiDataset KittiDataset(int dataset); int getNumberOfFrames(); KittiPointCloud::Ptr getPointCloud(int frameId); + std::string getImageFileName(int frameId); KittiPointCloud::Ptr getTrackletPointCloud(KittiPointCloud::Ptr& pointCloud, const KittiTracklet& tracklet, int frameId); Tracklets& getTracklets(); diff --git a/QtKittiVisualizer.cpp b/QtKittiVisualizer.cpp index e070e1b..492143d 100644 --- a/QtKittiVisualizer.cpp +++ b/QtKittiVisualizer.cpp @@ -46,7 +46,28 @@ limitations under the License. typedef pcl::visualization::PointCloudColorHandlerCustom KittiPointCloudColorHandlerCustom; -KittiVisualizerQt::KittiVisualizerQt(QWidget *parent, int argc, char** argv) : + +// enum for the camera angles +enum CameraView { front, eye_level, birds_eye, left_pers, right_pers, top }; +static const QString CAMVIEWSTR[] = { "Front", "Eye Level", "Birds Eye", "Left Perspective", "Right Perspective", "Top" }; + + + +void usleep(unsigned int usec) +{ + HANDLE timer; + LARGE_INTEGER ft; + + ft.QuadPart = -(10 * (__int64)usec); + + timer = CreateWaitableTimer(NULL, TRUE, NULL); + SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); +} + + +KittiVisualizerQt::KittiVisualizerQt(QWidget* parent, int argc, char** argv) : QMainWindow(parent), ui(new Ui::KittiVisualizerQt), dataset_index(0), @@ -66,10 +87,17 @@ KittiVisualizerQt::KittiVisualizerQt(QWidget *parent, int argc, char** argv) : // Set up user interface ui->setupUi(this); + for (int i = CameraView::front; i <= CameraView::top; i++) { + ui->viewComboBox->addItem(CAMVIEWSTR[i]); + } + + ui->toolBar->addWidget(ui->viewComboBox); ui->qvtkWidget_pclViewer->SetRenderWindow(pclVisualizer->getRenderWindow()); + pclVisualizer->initCameraParameters(); pclVisualizer->setupInteractor(ui->qvtkWidget_pclViewer->GetInteractor(), ui->qvtkWidget_pclViewer->GetRenderWindow()); pclVisualizer->setBackgroundColor(0, 0, 0); pclVisualizer->addCoordinateSystem(1.0); + pclVisualizer->registerKeyboardCallback(&KittiVisualizerQt::keyboardEventOccurred, *this, 0); this->setWindowTitle("Qt KITTI Visualizer"); ui->qvtkWidget_pclViewer->update(); @@ -79,6 +107,9 @@ KittiVisualizerQt::KittiVisualizerQt(QWidget *parent, int argc, char** argv) : loadPointCloud(); if (pointCloudVisible) showPointCloud(); + + loadImageFile(); + loadAvailableTracklets(); if (trackletBoundingBoxesVisible) showTrackletBoxes(); @@ -110,6 +141,11 @@ KittiVisualizerQt::KittiVisualizerQt(QWidget *parent, int argc, char** argv) : connect(ui->checkBox_showTrackletBoundingBoxes, SIGNAL (toggled(bool)), this, SLOT (showTrackletBoundingBoxesToggled(bool))); connect(ui->checkBox_showTrackletPointClouds, SIGNAL (toggled(bool)), this, SLOT (showTrackletPointCloudsToggled(bool))); connect(ui->checkBox_showTrackletInCenter, SIGNAL (toggled(bool)), this, SLOT (showTrackletInCenterToggled(bool))); + connect(ui->actionExit, SIGNAL (triggered()), this, SLOT (exitApplication())); + connect(ui->viewComboBox, SIGNAL (activated(int)),this, SLOT (camViewChanged(int))); + + ui->viewComboBox->setCurrentIndex(CameraView::birds_eye); + camViewChanged(CameraView::birds_eye); } KittiVisualizerQt::~KittiVisualizerQt() @@ -151,11 +187,13 @@ int KittiVisualizerQt::parseCommandLineOptions(int argc, char** argv) bool KittiVisualizerQt::loadNextFrame() { newFrameRequested(frame_index + 1); + return true; } bool KittiVisualizerQt::loadPreviousFrame() { newFrameRequested(frame_index - 1); + return true; } void KittiVisualizerQt::getTrackletColor(const KittiTracklet& tracklet, int &r, int& g, int& b) @@ -208,6 +246,7 @@ void KittiVisualizerQt::newDatasetRequested(int value) loadPointCloud(); if (pointCloudVisible) showPointCloud(); + loadImageFile(); loadAvailableTracklets(); if (trackletBoundingBoxesVisible) showTrackletBoxes(); @@ -233,6 +272,7 @@ void KittiVisualizerQt::newDatasetRequested(int value) updateFrameLabel(); updateTrackletLabel(); ui->qvtkWidget_pclViewer->update(); + ui->imageWidget->update(); } void KittiVisualizerQt::newFrameRequested(int value) @@ -260,6 +300,7 @@ void KittiVisualizerQt::newFrameRequested(int value) loadPointCloud(); if (pointCloudVisible) showPointCloud(); + loadImageFile(); loadAvailableTracklets(); if (trackletBoundingBoxesVisible) showTrackletBoxes(); @@ -351,6 +392,13 @@ void KittiVisualizerQt::loadPointCloud() pointCloud = dataset->getPointCloud(frame_index); } +void KittiVisualizerQt::loadImageFile() +{ + ui->imageWidget->setPixmapFile(dataset->getImageFileName(frame_index)); + ui->imageWidget->repaint(); + std::cout << "loaded:" << dataset->getImageFileName(frame_index) << std::endl; +} + void KittiVisualizerQt::showPointCloud() { KittiPointCloudColorHandlerCustom colorHandler(pointCloud, 255, 255, 255); @@ -428,9 +476,9 @@ void KittiVisualizerQt::updateTrackletLabel() void KittiVisualizerQt::showTrackletBoxes() { - double boxHeight = 0.0d; - double boxWidth = 0.0d; - double boxLength = 0.0d; + double boxHeight = 0.0f; + double boxWidth = 0.0f; + double boxLength = 0.0f; int pose_number = 0; for (int i = 0; i < availableTracklets.size(); ++i) @@ -569,3 +617,72 @@ void KittiVisualizerQt::keyboardEventOccurred (const pcl::visualization::Keyboar } } } + +void KittiVisualizerQt::exitApplication(void) +{ + QCoreApplication::exit(); +} + +/** \brief Set the camera pose given by position, viewpoint and up vector + * \param[in] pos_x the x coordinate of the camera location + * \param[in] pos_y the y coordinate of the camera location + * \param[in] pos_z the z coordinate of the camera location + * \param[in] view_x the x component of the view point of the camera + * \param[in] view_y the y component of the view point of the camera + * \param[in] view_z the z component of the view point of the camera + * \param[in] up_x the x component of the view up direction of the camera + * \param[in] up_y the y component of the view up direction of the camera + * \param[in] up_z the y component of the view up direction of the camera + * \param[in] viewport the viewport to modify camera of (0 modifies all cameras) + */ + + + +void KittiVisualizerQt::camViewChanged(int index) +{ + std::cout << "Selected View:" << index << std::endl; + + switch (index) { + case CameraView::front: + pclVisualizer->setCameraPosition(-100, 0, 0, + -17, 9.5, -9.5, + 0,0,1); + break; + + case CameraView::eye_level: + pclVisualizer->setCameraPosition(-100, 0, 20, + -17, 9.5, -9.5, + 0, 0, 1); + break; + + case CameraView::birds_eye: + pclVisualizer->setCameraPosition(-100, 10, 30, + -17, 9.5, -9.5, + 0, 0, 1); + break; + + + case CameraView::left_pers: + pclVisualizer->setCameraPosition(22, 150, 57, + 1, -57, 8, + 0, 0, 1); + break; + + + + case CameraView::right_pers: + pclVisualizer->setCameraPosition(-22, -150, 57, + 1, -57, 8, + 0, 0, 1); + break; + + + case CameraView::top: /* facing down on y */ + default: + + pclVisualizer->setCameraPosition(1, 29, -110, + 21, 6, 147, /* focal point */ + 0, -1, 0); + break; + } +} diff --git a/QtKittiVisualizer.h b/QtKittiVisualizer.h index 15f217a..fce7d8e 100644 --- a/QtKittiVisualizer.h +++ b/QtKittiVisualizer.h @@ -68,6 +68,8 @@ public slots: void showTrackletBoundingBoxesToggled(bool value); void showTrackletPointCloudsToggled(bool value); void showTrackletInCenterToggled(bool value); + void exitApplication(void); + void camViewChanged(int index); private: @@ -89,7 +91,7 @@ public slots: void updateDatasetLabel(); void updateFrameLabel(); void updateTrackletLabel(); - + void loadImageFile(); void loadPointCloud(); void showPointCloud(); void hidePointCloud(); diff --git a/QtKittiVisualizer.ui b/QtKittiVisualizer.ui index c607a7d..75ffed0 100644 --- a/QtKittiVisualizer.ui +++ b/QtKittiVisualizer.ui @@ -1,21 +1,4 @@ - KittiVisualizerQt @@ -167,6 +150,8 @@ limitations under the License. + + @@ -178,7 +163,7 @@ limitations under the License. 0 0 989 - 25 + 21 @@ -189,6 +174,17 @@ limitations under the License. + + + toolBar + + + TopToolBarArea + + + false + + Exit @@ -204,6 +200,12 @@ limitations under the License. QWidget
QVTKWidget.h
+ + KittiImage + QWidget +
KittiImage.h
+ 1 +
slider_dataSet diff --git a/kitti-devkit-raw/tracklets.h b/kitti-devkit-raw/tracklets.h index 7852286..b0ff89e 100644 --- a/kitti-devkit-raw/tracklets.h +++ b/kitti-devkit-raw/tracklets.h @@ -11,6 +11,7 @@ #include #include +extern void usleep(unsigned int usec); class Tracklets { public: