Skip to content

Commit b25520f

Browse files
author
IronStark
committed
增加了对OpenNI的支持,实现了基于signal - slot的点云传递
1 parent 5d7b9eb commit b25520f

10 files changed

Lines changed: 170 additions & 54 deletions

src/Kinect/opennigrabber.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef OPNIGRABBER
2+
#define OPNIGRABBER
3+
4+
#include <pcl/io/openni_grabber.h>
5+
#include <pcl/visualization/cloud_viewer.h>
6+
#include <QObject>
7+
#include <QThread>
8+
typedef pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr RGBAPointCloudConstPtr;
9+
10+
class myOpenNIViewer:public QObject
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
myOpenNIViewer():isWorking(false){}
16+
void cloud_cb_ (const RGBAPointCloudConstPtr &cloud)
17+
{
18+
// if (!viewer.wasStopped())
19+
// viewer.showCloud(cloud);
20+
emit newPointCloud(cloud);
21+
}
22+
~myOpenNIViewer(){}
23+
signals:
24+
void newPointCloud(const RGBAPointCloudConstPtr &cloud);
25+
26+
public slots:
27+
void startWork(){
28+
interface = new pcl::OpenNIGrabber();
29+
boost::function<void (const RGBAPointCloudConstPtr&)> f =
30+
boost::bind (&myOpenNIViewer::cloud_cb_, this, _1);
31+
interface->registerCallback (f);
32+
interface->start();
33+
isWorking = true;
34+
while(isWorking){
35+
boost::this_thread::sleep (boost::posix_time::seconds (1));
36+
}
37+
}
38+
void stopWork() {
39+
isWorking = false;
40+
interface->stop();
41+
delete interface;
42+
}
43+
private:
44+
pcl::Grabber* interface;
45+
bool isWorking;
46+
// pcl::visualization::CloudViewer viewer;
47+
};
48+
#endif

src/Kinect/opennigrabber.hpp

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

src/SLKinectDialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ SLKinectDialog::SLKinectDialog(SLStudio *parent) :QDialog(parent), ui(new Ui::SL
1515
delay = 33.333; //ms
1616
}
1717

18-
Freenect::Freenect* SLKinectDialog::myfreenect_ = new(Freenect::Freenect);
19-
MyFreenectDevice* SLKinectDialog::mydevice_ = &myfreenect_->createDevice<MyFreenectDevice>(0);
18+
// Freenect::Freenect* SLKinectDialog::myfreenect_ = new(Freenect::Freenect);
19+
// MyFreenectDevice* SLKinectDialog::mydevice_ = &myfreenect_->createDevice<MyFreenectDevice>(0);
2020
// Freenect::Freenect* myfreenect_;
2121
// MyFreenectDevice* mydevice_=&myfreenect_->createDevice<MyFreenectDevice>(0);
2222

@@ -67,8 +67,8 @@ void SLKinectDialog::onActionOk()
6767
}
6868
else
6969
{
70-
// freenect = new(Freenect::Freenect);
71-
// device = &freenect->createDevice<MyFreenectDevice>(0);
70+
myfreenect_ = new(Freenect::Freenect);
71+
mydevice_ = &myfreenect_->createDevice<MyFreenectDevice>(0);
7272
mydevice_->startVideo();
7373
mydevice_->startDepth();
7474
liveViewTimer = startTimer(delay);

src/SLKinectDialog.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ private slots:
3232
int liveViewTimer;
3333
// Freenect::Freenect* myfreenect_ = new(Freenect::Freenect);
3434
// MyFreenectDevice* mydevice_ = & myfreenect_->createDevice<MyFreenectDevice>(0);
35+
Freenect::Freenect* myfreenect_;
36+
MyFreenectDevice* mydevice_;
3537
// static int x;
36-
static Freenect::Freenect* myfreenect_;
37-
static MyFreenectDevice* mydevice_;
38+
// static Freenect::Freenect* myfreenect_;
39+
// static MyFreenectDevice* mydevice_;
3840
};
3941

4042
// Freenect::Freenect* SLKinectDialog::myfreenect_ = new(Freenect::Freenect);

src/SLPointCloudWidget.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <QFileDialog>
2828
#include <QKeyEvent>
2929

30-
SLPointCloudWidget::SLPointCloudWidget(QWidget *parent) : QVTKWidget(parent), surfaceReconstruction(false) {
30+
SLPointCloudWidget::SLPointCloudWidget(QWidget *parent) : QVTKWidget(parent), surfaceReconstruction(false),CordAdjust(true) {
3131

3232
visualizer = new pcl::visualization::PCLVisualizer("PCLVisualizer", false);
3333
this->SetRenderWindow(visualizer->getRenderWindow());
@@ -38,7 +38,7 @@ SLPointCloudWidget::SLPointCloudWidget(QWidget *parent) : QVTKWidget(parent), su
3838

3939
// Create point cloud viewport
4040
visualizer->setBackgroundColor(255, 255, 255);
41-
visualizer->addCoordinateSystem(50, 0);
41+
// visualizer->addCoordinateSystem(50, 0);
4242
visualizer->setCameraPosition(0,0,-50,0,0,0,0,-1,0);
4343
visualizer->setCameraClipDistances(0.1, 10000);
4444
// Initialize point cloud color handler
@@ -59,7 +59,7 @@ void SLPointCloudWidget::updateCalibration(){
5959
calibration.load("calibration.xml");
6060

6161
// Camera coordinate system
62-
visualizer->addCoordinateSystem(50, "camera", 0);
62+
// visualizer->addCoordinateSystem(50, "camera", 0);
6363

6464
// Projector coordinate system
6565
cv::Mat TransformPCV(3, 4, CV_32F);
@@ -68,7 +68,7 @@ void SLPointCloudWidget::updateCalibration(){
6868
Eigen::Affine3f TransformP;
6969
cv::cv2eigen(TransformPCV, TransformP.matrix());
7070

71-
visualizer->addCoordinateSystem(50, TransformP.inverse(), "projector", 0);
71+
// visualizer->addCoordinateSystem(50, TransformP.inverse(), "projector", 0);
7272
}
7373

7474
void SLPointCloudWidget::keyPressEvent(QKeyEvent *event){
@@ -99,7 +99,6 @@ void SLPointCloudWidget::keyPressEvent(QKeyEvent *event){
9999
}
100100

101101
void SLPointCloudWidget::updatePointCloud(PointCloudConstPtr _pointCloudPCL){
102-
103102
if(!_pointCloudPCL || _pointCloudPCL->points.empty())
104103
return;
105104

@@ -129,6 +128,25 @@ void SLPointCloudWidget::updatePointCloud(PointCloudConstPtr _pointCloudPCL){
129128
// std::cout << "PCL Widget: " << time.restart() << "ms" << std::endl;
130129
}
131130

131+
void SLPointCloudWidget::updateRGBAPointCloud(RGBAPointCloudConstPtr _RGBACloudPCL){
132+
133+
if(CordAdjust)
134+
{
135+
// visualizer->removeCoordinateSystem("Camera",0);
136+
// visualizer->removeCoordinateSystem("Projector",0);
137+
}
138+
if(!_RGBACloudPCL || _RGBACloudPCL->points.empty())
139+
return;
140+
RGBAPointCloudPCL = _RGBACloudPCL;
141+
if(!visualizer->updatePointCloud(RGBAPointCloudPCL,"RGBAPointCloud")){
142+
visualizer->addPointCloud(RGBAPointCloudPCL,"RGBAPointCloud");
143+
visualizer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,1.0,"RGBAPointCloud");
144+
}
145+
this->update();
146+
CordAdjust = false;
147+
emit newPointCloudDisplayed();
148+
}
149+
132150
void SLPointCloudWidget::savePointCloud(){
133151

134152
QString selectedFilter;

src/SLPointCloudWidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
typedef pcl::PointCloud<pcl::PointXYZRGB>::Ptr PointCloudPtr;
2323
typedef pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr PointCloudConstPtr;
24+
typedef pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr RGBAPointCloudConstPtr;
2425

2526
class SLPointCloudWidget : public QVTKWidget {
2627
Q_OBJECT
@@ -31,6 +32,7 @@ class SLPointCloudWidget : public QVTKWidget {
3132
void keyPressEvent(QKeyEvent *event);
3233
public slots:
3334
void updatePointCloud(PointCloudConstPtr _pointCloudPCL);
35+
void updateRGBAPointCloud(RGBAPointCloudConstPtr _RGBACloudPCL);
3436
void savePointCloud();
3537
void saveScreenShot();
3638
void updateCalibration();
@@ -39,10 +41,12 @@ class SLPointCloudWidget : public QVTKWidget {
3941
private:
4042
pcl::visualization::PCLVisualizer *visualizer;
4143
PointCloudConstPtr pointCloudPCL;
44+
RGBAPointCloudConstPtr RGBAPointCloudPCL;
4245
pcl::visualization::PointCloudColorHandler<pcl::PointXYZRGB>* colorHandler;
4346
bool surfaceReconstruction;
4447
pcl::OrganizedFastMesh<pcl::PointXYZRGB> *reconstructor;
4548
QTime time;
49+
bool CordAdjust;
4650
};
4751

4852
#endif // SLPOINTCLOUDWIDGET_H

src/SLStudio.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void SLStudio::onActionStart(){
128128
qRegisterMetaType< std::vector<cv::Mat> >("std::vector<cv::Mat>");
129129
qRegisterMetaType< PointCloudConstPtr >("PointCloudConstPtr");
130130

131+
131132
// Inter thread connections
132133
connect(scanWorker, SIGNAL(showHistogram(cv::Mat)), this, SLOT(onShowHistogram(cv::Mat)));
133134
connect(scanWorker, SIGNAL(newFrameSeq(std::vector<cv::Mat>)), decoderWorker, SLOT(decodeSequence(std::vector<cv::Mat>)));
@@ -161,6 +162,28 @@ void SLStudio::onActionStart(){
161162

162163
}
163164

165+
void SLStudio::onActionStartPointView()
166+
{
167+
qRegisterMetaType< RGBAPointCloudConstPtr >("RGBAPointCloudConstPtr");
168+
169+
PointCloudGrabber = new myOpenNIViewer();
170+
PointCloudGrabberThread = new QThread(this);
171+
PointCloudGrabberThread->setObjectName("PointCloudGrabberThread");
172+
PointCloudGrabber->moveToThread(PointCloudGrabberThread);
173+
connect(PointCloudGrabber,SIGNAL(newPointCloud(RGBAPointCloudConstPtr)),this,SLOT(receiveNewRGBAPointCloud(RGBAPointCloudConstPtr)));
174+
connect(PointCloudGrabberThread,SIGNAL(started()),PointCloudGrabber,SLOT(startWork()));
175+
connect(PointCloudGrabberThread,SIGNAL(finished()),PointCloudGrabber,SLOT(stopWork()));
176+
PointCloudGrabberThread->start(QThread::TimeCriticalPriority);
177+
// PointCloudGrabber->startWork();
178+
}
179+
180+
void SLStudio::onActionStopPointView()
181+
{
182+
// PointCloudGrabber->stopWork();
183+
PointCloudGrabberThread->quit();
184+
PointCloudGrabberThread->wait();
185+
}
186+
164187
void SLStudio::onActionStop(){
165188
// Stop processing on scan worker thread
166189
QMetaObject::invokeMethod(scanWorker, "stopWorking");
@@ -233,6 +256,14 @@ void SLStudio::receiveNewPointCloud(PointCloudConstPtr pointCloud){
233256
trackerDialog->receiveNewPointCloud(pointCloud);
234257
}
235258

259+
void SLStudio::receiveNewRGBAPointCloud(RGBAPointCloudConstPtr RGBApointCloud){
260+
if(ui->actionUpdatePointClouds->isChecked())
261+
ui->pointCloudWidget->updateRGBAPointCloud(RGBApointCloud);
262+
263+
// if(trackerDialog->isVisible())
264+
// trackerDialog->receiveNewPointCloud(pointCloud);
265+
}
266+
236267
void SLStudio::closeEvent(QCloseEvent *event){
237268

238269
// Save main window geometry

src/SLStudio.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "SLPointCloudWidget.h"
1919
#include "SLVideoDialog.h"
2020
#include "SLTrackerDialog.h"
21-
21+
#include "Kinect/opennigrabber.h"
2222

2323
namespace Ui {
2424
class SLStudio;
@@ -42,9 +42,12 @@ class SLStudio : public QMainWindow {
4242
void onActionPreferences();
4343
void onActionExportCalibration();
4444
void onActionKinect();
45+
void onActionStartPointView();
46+
void onActionStopPointView();
4547

4648
void updateDisplayRate();
4749
void receiveNewPointCloud(PointCloudConstPtr pointCloud);
50+
void receiveNewRGBAPointCloud(RGBAPointCloudConstPtr RGBApointCloud);
4851

4952
void imshow(const char* windowName, cv::Mat im, unsigned int x, unsigned int y);
5053
void hist(const char* windowName, cv::Mat im, unsigned int x, unsigned int y);
@@ -73,6 +76,9 @@ class SLStudio : public QMainWindow {
7376
SLTriangulatorWorker *triangulatorWorker;
7477
QThread *triangulatorThread;
7578

79+
myOpenNIViewer *PointCloudGrabber;
80+
QThread *PointCloudGrabberThread;
81+
7682
QTime *time;
7783
QSettings *settings;
7884

src/SLStudio.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ HEADERS += SLStudio.h \
7676
tracker/PoseFilter.h \
7777
cvtools.h \
7878
Kinect/opencvgrabber.hpp \
79-
Kinect/opennigrabber.hpp
79+
Kinect/opennigrabber.h
8080

8181

8282

@@ -145,7 +145,7 @@ unix:!macx {
145145
INCLUDEPATH += /usr/include/vtk-5.10/
146146
LIBS += -lQVTK -lvtkCommon -lvtkFiltering -lvtkRendering -lvtkIO -lvtkGraphics -lvtkHybrid
147147
# PCL pkg-config workaround
148-
LIBS += -lboost_system -lpcl_visualization -lpcl_common -lpcl_io -lpcl_search -lpcl_surface
148+
LIBS += -lboost_system -lpcl_visualization -lpcl_common -lpcl_io -lpcl_search -lpcl_surface -lboost_thread
149149
# PKG-config libs
150150
INCLUDEPATH += /usr/include/pcl-1.7 /usr/include/eigen3/
151151
PKGCONFIG += opencv pcl_registration-1.7 pcl_visualization-1.7 pcl_surface-1.7 pcl_search-1.7 pcl_filters-1.7 pcl_kdtree-1.7 pcl_tracking-1.7 flann eigen3

0 commit comments

Comments
 (0)