Skip to content

Commit 9a10adc

Browse files
committed
Merge pull request #236 from wiedemeyer/extended_protonect
Extension of Protonect to allow selection of pipeline and device
2 parents ef34cfc + eb612cc commit 9a10adc

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

examples/protonect/Protonect.cpp

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <libfreenect2/frame_listener_impl.h>
3535
#include <libfreenect2/threading.h>
3636
#include <libfreenect2/registration.h>
37+
#include <libfreenect2/packet_pipeline.h>
3738

3839
bool protonect_shutdown = false;
3940

@@ -54,13 +55,67 @@ int main(int argc, char *argv[])
5455
binpath = program_path.substr(0, executable_name_idx);
5556
}
5657

57-
5858
libfreenect2::Freenect2 freenect2;
59-
libfreenect2::Freenect2Device *dev = freenect2.openDefaultDevice();
59+
libfreenect2::Freenect2Device *dev = 0;
60+
libfreenect2::PacketPipeline *pipeline = 0;
61+
62+
if(freenect2.enumerateDevices() == 0)
63+
{
64+
std::cout << "no device connected!" << std::endl;
65+
return -1;
66+
}
67+
68+
std::string serial = freenect2.getDefaultDeviceSerialNumber();
69+
70+
for(int argI = 1; argI < argc; ++argI)
71+
{
72+
const std::string arg(argv[argI]);
73+
74+
if(arg == "cpu")
75+
{
76+
if(!pipeline)
77+
pipeline = new libfreenect2::CpuPacketPipeline();
78+
}
79+
else if(arg == "gl")
80+
{
81+
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
82+
if(!pipeline)
83+
pipeline = new libfreenect2::OpenGLPacketPipeline();
84+
#else
85+
std::cout << "OpenGL pipeline is not supported!" << std::endl;
86+
#endif
87+
}
88+
else if(arg == "cl")
89+
{
90+
#ifdef LIBFREENECT2_WITH_OPENCL_SUPPORT
91+
if(!pipeline)
92+
pipeline = new libfreenect2::OpenCLPacketPipeline();
93+
#else
94+
std::cout << "OpenCL pipeline is not supported!" << std::endl;
95+
#endif
96+
}
97+
else if(arg.find_first_not_of("0123456789") == std::string::npos) //check if parameter could be a serial number
98+
{
99+
serial = arg;
100+
}
101+
else
102+
{
103+
std::cout << "Unknown argument: " << arg << std::endl;
104+
}
105+
}
106+
107+
if(pipeline)
108+
{
109+
dev = freenect2.openDevice(serial, pipeline);
110+
}
111+
else
112+
{
113+
dev = freenect2.openDevice(serial);
114+
}
60115

61116
if(dev == 0)
62117
{
63-
std::cout << "no device connected or failure opening the default one!" << std::endl;
118+
std::cout << "failure opening device!" << std::endl;
64119
return -1;
65120
}
66121

0 commit comments

Comments
 (0)