Commit e4c891ad by wester

kinect update

parent 7bad8df5
...@@ -93,6 +93,7 @@ ...@@ -93,6 +93,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="glut.h" /> <ClInclude Include="glut.h" />
<ClInclude Include="SteamVrTrackingServer.h" />
<ClInclude Include="main.h" /> <ClInclude Include="main.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
...@@ -32,5 +32,8 @@ ...@@ -32,5 +32,8 @@
<ClInclude Include="main.h"> <ClInclude Include="main.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="SteamVrTrackingServer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
#include <chrono> #include "SteamVrTrackingServer.h"
#include <csignal>
#include <iostream>
#include <thread>
#include <sstream>
#include <openvr.h>
struct Config struct Config
{ {
std::string hostname = "127.0.0.1";
int port = 5672;
std::string exchange = "irpose";
bool debug = false; bool debug = false;
int messages_per_second = 60;
} config_; } config_;
bool running_ = true;
vr::IVRSystem *vr_system_ = nullptr; vr::IVRSystem *vr_system_ = nullptr;
vr::TrackedDevicePose_t tracked_device_poses_[vr::k_unMaxTrackedDeviceCount]; vr::TrackedDevicePose_t tracked_device_poses_[vr::k_unMaxTrackedDeviceCount];
void signalHandler(int signum)
{
running_ = false;
}
bool init() bool initVR()
{ {
// Loading the SteamVR Runtime // Loading the SteamVR Runtime
...@@ -57,7 +44,7 @@ bool init() ...@@ -57,7 +44,7 @@ bool init()
return true; return true;
} }
void shutdown() void shutdownVR()
{ {
if (vr_system_) if (vr_system_)
{ {
...@@ -134,16 +121,7 @@ void printMatrix(const vr::HmdMatrix34_t &htm) ...@@ -134,16 +121,7 @@ void printMatrix(const vr::HmdMatrix34_t &htm)
} }
} }
int main2(int argc, char *argv[]) void printVRDevices() {
{
if (!init())
{
shutdown();
return 1;
}
if (false)
{
std::cout << "List of available VR devices:" << std::endl; std::cout << "List of available VR devices:" << std::endl;
for (int nDevice = 0; nDevice < vr::k_unMaxTrackedDeviceCount; ++nDevice) for (int nDevice = 0; nDevice < vr::k_unMaxTrackedDeviceCount; ++nDevice)
{ {
...@@ -172,23 +150,16 @@ int main2(int argc, char *argv[]) ...@@ -172,23 +150,16 @@ int main2(int argc, char *argv[])
std::cout << "\t\tType: " << type << std::endl; std::cout << "\t\tType: " << type << std::endl;
std::cout << "\t\tSerial: " << serial << std::endl; std::cout << "\t\tSerial: " << serial << std::endl;
} }
}
shutdown(); int main2(int argc, char *argv[])
return 0; {
} if (!initVR())
signal(SIGINT, signalHandler);
std::cout << "Tracking started. Cancel with Ctrl-C" << std::endl;
std::chrono::duration<double, std::milli> cycle_time;
if (config_.messages_per_second > 0)
{ {
cycle_time = std::chrono::duration<double, std::milli>(1000.0 / config_.messages_per_second); shutdownVR();
return 1;
} }
printVRDevices();
while (running_)
{
auto start = std::chrono::steady_clock::now();
handleInput(); handleInput();
...@@ -248,48 +219,9 @@ int main2(int argc, char *argv[]) ...@@ -248,48 +219,9 @@ int main2(int argc, char *argv[])
std::cout << "Pose of device " << nDevice << " (" << type << ")" << std::endl; std::cout << "Pose of device " << nDevice << " (" << type << ")" << std::endl;
printMatrix(htm); printMatrix(htm);
} }
const uint32_t size = 1024;
char serial[size];
vr_system_->GetStringTrackedDeviceProperty(nDevice, vr::ETrackedDeviceProperty::Prop_SerialNumber_String, serial, size);
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
std::ostringstream message;
message << "%YAML:1.0\n";
message << "object_type: \"" << model_type << "\"\n";
message << "serial: \"" << serial << "\"\n";
message << "timestamp: \"" << std::to_string(timestamp) << "\"\n";
message << "pose: !!opencv-matrix\n rows: 4\n cols: 4\n dt: f\n data: [ ";
message << htm.m[0][0] << ", ";
message << htm.m[0][1] << ", ";
message << htm.m[0][2] << ", ";
message << htm.m[0][3] << ", ";
message << htm.m[1][0] << ", ";
message << htm.m[1][1] << ", ";
message << htm.m[1][2] << ", ";
message << htm.m[1][3] << ", ";
message << htm.m[2][0] << ", ";
message << htm.m[2][1] << ", ";
message << htm.m[2][2] << ", ";
message << htm.m[2][3] << ", ";
message << "0.0, 0.0, 0.0, 1.0 ]\n";
message << "source_type: \"steam_vr\"\n";
message << "source_serial: \"steam_vr_1\"\n";
if (config_.debug)
{
std::cout << message.str() << std::endl;
}
}
if (config_.messages_per_second > 0)
{
std::this_thread::sleep_until(start + cycle_time);
}
} }
shutdown(); shutdownVR();
return 0; return 0;
} }
#pragma once
#include <iostream>
#include <sstream>
#include <openvr.h>
bool initVR();
void shutdownVR();
\ No newline at end of file
#include "main.h" #include "main.h"
#include "glut.h" #include "glut.h"
#include "SteamVRTrackingServer.h"
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>
...@@ -93,13 +94,6 @@ void getRgbData(IMultiSourceFrame* frame, bool writFrameToFile) { ...@@ -93,13 +94,6 @@ void getRgbData(IMultiSourceFrame* frame, bool writFrameToFile) {
// Get data from frame // Get data from frame
colorframe->CopyConvertedFrameDataToArray(colorwidth*colorheight*4, rgbimage, ColorImageFormat_Rgba); colorframe->CopyConvertedFrameDataToArray(colorwidth*colorheight*4, rgbimage, ColorImageFormat_Rgba);
if (writFrameToFile) {
points.clear();
points.reserve(width*height * 3);
colors.clear();
colors.reserve(width*height * 3);
}
// Write color array for vertices // Write color array for vertices
float* fdest = (float*)frameColors; float* fdest = (float*)frameColors;
for (int i = 0; i < width*height; i++) { for (int i = 0; i < width*height; i++) {
...@@ -132,13 +126,19 @@ void getRgbData(IMultiSourceFrame* frame, bool writFrameToFile) { ...@@ -132,13 +126,19 @@ void getRgbData(IMultiSourceFrame* frame, bool writFrameToFile) {
if (colorframe) colorframe->Release(); if (colorframe) colorframe->Release();
} }
void getKinectData() { void getKinectData(bool writeFrameInVector) {
IMultiSourceFrame* frame = NULL; IMultiSourceFrame* frame = NULL;
if (SUCCEEDED(reader->AcquireLatestFrame(&frame))) { if (SUCCEEDED(reader->AcquireLatestFrame(&frame))) {
getDepthData(frame);
getRgbData(frame, writeFile);
writeFile = false;
if (writeFrameInVector) {
points.clear();
points.reserve(width*height * 3);
colors.clear();
colors.reserve(width*height * 3);
}
getDepthData(frame);
getRgbData(frame, writeFrameInVector);
glBindBuffer(GL_ARRAY_BUFFER, vboId); glBindBuffer(GL_ARRAY_BUFFER, vboId);
glBufferData(GL_ARRAY_BUFFER, width*height * 3 * sizeof(GLfloat), framePositions, GL_DYNAMIC_DRAW); glBufferData(GL_ARRAY_BUFFER, width*height * 3 * sizeof(GLfloat), framePositions, GL_DYNAMIC_DRAW);
...@@ -178,8 +178,6 @@ void writePointCloud() { ...@@ -178,8 +178,6 @@ void writePointCloud() {
myfile.close(); myfile.close();
} }
void rotateCamera() { void rotateCamera() {
...@@ -190,11 +188,17 @@ void rotateCamera() { ...@@ -190,11 +188,17 @@ void rotateCamera() {
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
gluLookAt(x,0,z,0,0,radius/2,0,1,0); gluLookAt(x,0,z,0,0,radius/2,0,1,0);
angle += 0.002; //angle += 0.002;
} }
void drawKinectData() { void drawKinectData() {
getKinectData();
getKinectData(writeFile);
if (writeFile) {
writePointCloud();
writeFile = false;
}
rotateCamera(); rotateCamera();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
...@@ -212,7 +216,7 @@ void drawKinectData() { ...@@ -212,7 +216,7 @@ void drawKinectData() {
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
writePointCloud();
} }
void keyPressed(unsigned char key, int x, int y) void keyPressed(unsigned char key, int x, int y)
...@@ -232,6 +236,12 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -232,6 +236,12 @@ void keyPressed(unsigned char key, int x, int y)
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (!init(argc, argv)) return 1; if (!init(argc, argv)) return 1;
if (!initKinect()) return 1; if (!initKinect()) return 1;
if (!initVR())
{
shutdownVR();
}
// OpenGL setup // OpenGL setup
glClearColor(0,0,0,0); glClearColor(0,0,0,0);
glClearDepth(1.0f); glClearDepth(1.0f);
......
...@@ -6,6 +6,7 @@ const int colorheight = 1080; ...@@ -6,6 +6,7 @@ const int colorheight = 1080;
void drawKinectData(); void drawKinectData();
void keyPressed(unsigned char key, int x, int y); void keyPressed(unsigned char key, int x, int y);
void writePointCloud();
struct pntsHeader { struct pntsHeader {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment