From 18d97df8bc11b6289abc2807da764cb769c97839 Mon Sep 17 00:00:00 2001 From: Elie Zananiri Date: Sun, 6 Oct 2019 20:54:07 -0400 Subject: [PATCH] Add getters for world position and texture coordinate. --- src/ofxRealSense2/Device.cpp | 22 ++++++++++++++++++++++ src/ofxRealSense2/Device.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/ofxRealSense2/Device.cpp b/src/ofxRealSense2/Device.cpp index 0c9a166..988c65e 100644 --- a/src/ofxRealSense2/Device.cpp +++ b/src/ofxRealSense2/Device.cpp @@ -550,6 +550,28 @@ namespace ofxRealSense2 return 0.0f; } + ofDefaultVertexType Device::getWorldPosition(int x, int y) const + { + int idx = y * this->getDepthTex().getWidth() + x; + if (idx < this->points.size()) + { + auto vertices = this->points.get_vertices(); + return ofDefaultVertexType(vertices[idx].x, vertices[idx].y, vertices[idx].z); + } + return ofDefaultVertexType(); + } + + ofDefaultTexCoordType Device::getTexCoord(int x, int y) const + { + int idx = y * this->getDepthTex().getWidth() + x; + if (idx < this->points.size()) + { + auto texCoords = this->points.get_texture_coordinates(); + return ofDefaultTexCoordType(texCoords[idx].u, texCoords[idx].v); + } + return ofDefaultTexCoordType(); + } + const rs2::device& Device::getNativeDevice() const { return this->device; diff --git a/src/ofxRealSense2/Device.h b/src/ofxRealSense2/Device.h index 0bbbe25..5227029 100644 --- a/src/ofxRealSense2/Device.h +++ b/src/ofxRealSense2/Device.h @@ -60,6 +60,8 @@ namespace ofxRealSense2 const size_t getNumPoints() const; float getDistance(int x, int y) const; + ofDefaultVertexType getWorldPosition(int x, int y) const; + ofDefaultTexCoordType getTexCoord(int x, int y) const; const rs2::device& getNativeDevice() const; const rs2::pipeline& getNativePipeline() const;