Skip to content

Commit d5def39

Browse files
author
Thiemo Wiedemeyer
committed
Extended Protonect to allow selection of the pipeline and the device via parameters.
1 parent 2e72fa9 commit d5def39

File tree

1 file changed

+85
-3
lines changed

1 file changed

+85
-3
lines changed

examples/protonect/Protonect.cpp

Lines changed: 85 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,94 @@ 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+
std::string serial;
62+
63+
enum {
64+
DEFAULT,
65+
CPU,
66+
OPENGL,
67+
OPENCL
68+
} selected_pipeline = DEFAULT;
69+
70+
for(int argI = 1; argI < argc; ++argI)
71+
{
72+
const std::string arg(argv[argI]);
73+
74+
if(arg == "cpu")
75+
{
76+
selected_pipeline = CPU;
77+
}
78+
else if(arg == "gl")
79+
{
80+
selected_pipeline = OPENGL;
81+
}
82+
else if(arg == "cl")
83+
{
84+
selected_pipeline = OPENCL;
85+
}
86+
else if(arg.find_first_not_of("0123456789") == std::string::npos) //check if parameter could be a serial number
87+
{
88+
serial = arg;
89+
}
90+
else
91+
{
92+
std::cout << "Unknown argument: " << arg << std::endl;
93+
}
94+
}
95+
96+
switch(selected_pipeline)
97+
{
98+
case DEFAULT:
99+
break;
100+
case CPU:
101+
pipeline = new libfreenect2::CpuPacketPipeline();
102+
break;
103+
case OPENGL:
104+
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
105+
pipeline = new libfreenect2::OpenGLPacketPipeline();
106+
#else
107+
std::cout << "OpenGL pipeline is not supported! Using default pipeline instead." << std::endl;
108+
#endif
109+
break;
110+
case OPENCL:
111+
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
112+
pipeline = new libfreenect2::OpenCLPacketPipeline();
113+
#else
114+
std::cout << "OpenCL pipeline is not supported! Using default pipeline instead." << std::endl;
115+
#endif
116+
break;
117+
}
118+
119+
if(serial.empty() && pipeline)
120+
{
121+
dev = freenect2.openDefaultDevice(pipeline);
122+
}
123+
else if(serial.empty())
124+
{
125+
dev = freenect2.openDefaultDevice();
126+
}
127+
else if(pipeline)
128+
{
129+
dev = freenect2.openDevice(serial, pipeline);
130+
}
131+
else
132+
{
133+
dev = freenect2.openDevice(serial);
134+
}
60135

61136
if(dev == 0)
62137
{
63-
std::cout << "no device connected or failure opening the default one!" << std::endl;
138+
if(serial.empty())
139+
{
140+
std::cout << "no device connected or failure opening the default one!" << std::endl;
141+
}
142+
else
143+
{
144+
std::cout << "could not open device with serial: " << serial << "!" << std::endl;
145+
}
64146
return -1;
65147
}
66148

0 commit comments

Comments
 (0)