diff --git a/examples/protonect/CMakeLists.txt b/examples/protonect/CMakeLists.txt index 1c29e413d..7e352a8d5 100644 --- a/examples/protonect/CMakeLists.txt +++ b/examples/protonect/CMakeLists.txt @@ -155,6 +155,22 @@ ADD_DEFINITIONS(-DRESOURCES_INC) ADD_LIBRARY(freenect2 SHARED ${SOURCES}) TARGET_LINK_LIBRARIES(freenect2 ${LIBRARIES}) +ADD_EXECUTABLE(test_opengl + src/test_opengl_depth_packet_processor.cpp +) + +TARGET_LINK_LIBRARIES(test_opengl + freenect2 +) + +ADD_EXECUTABLE(test_opengl_dump + src/test_opengl_dump.cpp +) + +TARGET_LINK_LIBRARIES(test_opengl_dump + freenect2 +) + ADD_EXECUTABLE(Protonect Protonect.cpp ) diff --git a/examples/protonect/src/test_opengl_depth_packet_processor.cpp b/examples/protonect/src/test_opengl_depth_packet_processor.cpp index 7c91d3fd7..51ce61a9f 100644 --- a/examples/protonect/src/test_opengl_depth_packet_processor.cpp +++ b/examples/protonect/src/test_opengl_depth_packet_processor.cpp @@ -58,6 +58,9 @@ int main(int argc, char **argv) { glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); +#ifdef __APPLE__ + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#endif glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); @@ -74,7 +77,7 @@ int main(int argc, char **argv) { libfreenect2::OpenGLDepthPacketProcessor processor(window, true); processor.setConfiguration(cfg); processor.setFrameListener(&fl); - processor.loadP0TablesFromFiles((binpath + "../p00.bin").c_str(), (binpath + "../p01.bin").c_str(), (binpath + "../p02.bin").c_str()); + processor.loadP0TablesFromFiles((binpath + "p00.bin").c_str(), (binpath + "p01.bin").c_str(), (binpath + "p02.bin").c_str()); processor.load11To16LutFromFile(""); processor.loadXTableFromFile(""); processor.loadZTableFromFile(""); @@ -82,7 +85,7 @@ int main(int argc, char **argv) { libfreenect2::CpuDepthPacketProcessor ref_processor; ref_processor.setConfiguration(cfg); ref_processor.setFrameListener(&fl); - ref_processor.loadP0TablesFromFiles((binpath + "../p00.bin").c_str(), (binpath + "../p01.bin").c_str(), (binpath + "../p02.bin").c_str()); + ref_processor.loadP0TablesFromFiles((binpath + "p00.bin").c_str(), (binpath + "p01.bin").c_str(), (binpath + "p02.bin").c_str()); ref_processor.load11To16LutFromFile(""); ref_processor.loadXTableFromFile(""); ref_processor.loadZTableFromFile(""); @@ -93,7 +96,7 @@ int main(int argc, char **argv) { p.buffer_length = 352*424*10*2; p.buffer = new unsigned char[p.buffer_length]; - loadBufferFromFile(binpath + "../rawir/rawir_4599.bin", p.buffer, p.buffer_length); + loadBufferFromFile(binpath + "rawir.bin", p.buffer, p.buffer_length); libfreenect2::Frame *ir, *depth; cv::Mat cpu_ir, cpu_depth, ogl_ir, ogl_depth; diff --git a/examples/protonect/src/test_opengl_dump.cpp b/examples/protonect/src/test_opengl_dump.cpp new file mode 100644 index 000000000..d9dc05275 --- /dev/null +++ b/examples/protonect/src/test_opengl_dump.cpp @@ -0,0 +1,130 @@ +/* + * This file is part of the OpenKinect Project. http://www.openkinect.org + * + * Copyright (c) 2014 individual OpenKinect contributors. See the CONTRIB file + * for details. + * + * This code is licensed to you under the terms of the Apache License, version + * 2.0, or, at your option, the terms of the GNU General Public License, + * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses, + * or the following URLs: + * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.gnu.org/licenses/gpl-2.0.txt + * + * If you redistribute this file in source form, modified or unmodified, you + * may: + * 1) Leave this header intact and distribute it under the same terms, + * accompanying it with the APACHE20 and GPL20 files, or + * 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or + * 3) Delete the GPL v2 clause and accompany it with the APACHE20 file + * In all cases you must keep the copyright notice intact and include a copy + * of the CONTRIB file. + * + * Binary distributions must follow the binary distribution requirements of + * either License. + */ + +#include +#include + +#include +#include +#include +#include +#include + +static bool data_dumped = false; + +class LIBFREENECT2_API DumpPacketProcessor : public libfreenect2::DepthPacketProcessor +{ +public: + DumpPacketProcessor() {} + + virtual void loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length) + { + libfreenect2::protocol::P0TablesResponse* p0table = (libfreenect2::protocol::P0TablesResponse*)buffer; + + if(buffer_length < sizeof(libfreenect2::protocol::P0TablesResponse)) + { + std::cerr << "[CpuDepthPacketProcessor::loadP0TablesFromCommandResponse] P0Table response too short!" << std::endl; + return; + } + + std::cerr << "[DumpPacketProcessor::loadP0TablesFromCommandResponse] Exporting p0 tables" << std::endl; + std::ofstream p00out("p00.bin", std::ios::out | std::ios::binary); + p00out.write(reinterpret_cast(p0table->p0table0), 512*424*sizeof(uint16_t)); + p00out.close(); + + std::ofstream p01out("p01.bin", std::ios::out | std::ios::binary); + p01out.write(reinterpret_cast(p0table->p0table1), 512*424*sizeof(uint16_t)); + p01out.close(); + + std::ofstream p02out("p02.bin", std::ios::out | std::ios::binary); + p02out.write(reinterpret_cast(p0table->p0table2), 512*424*sizeof(uint16_t)); + p02out.close(); + } + + virtual void process(const libfreenect2::DepthPacket &packet) + { + if(!::data_dumped && (packet.sequence > 16)) + { + std::cerr << "[DumpPacketProcessor::process] Exporting depth packet " << packet.sequence << std::endl; + std::ofstream rawIrOut("rawir.bin", std::ios::out | std::ios::binary); + rawIrOut.write(reinterpret_cast(packet.buffer), packet.buffer_length); + rawIrOut.close(); + ::data_dumped = true; + } + } +}; + +class LIBFREENECT2_API DumpPacketPipeline : public libfreenect2::BasePacketPipeline +{ +protected: + virtual libfreenect2::DepthPacketProcessor *createDepthPacketProcessor() + { + DumpPacketProcessor *depth_processor = new DumpPacketProcessor(); + return depth_processor; + } + +public: + DumpPacketPipeline() + { + initialize(); + } +}; + +int main(int argc, char **argv) +{ + std::string program_path(argv[0]); + size_t executable_name_idx = program_path.rfind("test_opengl"); + std::string binpath = "./"; + + if(executable_name_idx != std::string::npos) + { + binpath = program_path.substr(0, executable_name_idx); + } + + libfreenect2::Freenect2 freenect2; + libfreenect2::Freenect2Device *dev; + dev = freenect2.openDefaultDevice(new DumpPacketPipeline()); + + if(dev == 0) + { + std::cout << "no device connected or failure opening the default one!" << std::endl; + return -1; + } + + dev->start(); + + while(!data_dumped) + { + std::cerr << "."; + libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(100)); + } + std::cerr << std::endl; + + dev->stop(); + dev->close(); + + return 0; +}