Skip to content

Commit

Permalink
Merge pull request #11 from ami-iit/labels
Browse files Browse the repository at this point in the history
Add the possibility to show labels on the headset
  • Loading branch information
S-Dafarra authored Feb 16, 2022
2 parents 0999145 + f44849a commit d67ca69
Show file tree
Hide file tree
Showing 17 changed files with 851 additions and 31 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ set(CMAKE_CXX_EXTENSIONS OFF)


### Dependencies
# Fetching GLFont for displaying labels
option(YARP_OPENXR_USES_SYSTEM_GLFont OFF)
if(YARP_OPENXR_USES_SYSTEM_GLFont)
find_package(GLFont REQUIRED)
else()
include(FetchContent)
FetchContent_Declare(glfont
GIT_REPOSITORY https://github.com/ami-iit/GLFont
GIT_TAG 64a02d6dc382e2bc052e90b15d80cc9792d689c5)

FetchContent_GetProperties(glfont)
if(NOT glfont_POPULATED)
message(STATUS "Fetching GLFont...")
FetchContent_MakeAvailable(glfont)
endif()
endif()

find_package(YCM REQUIRED)
find_package(YARP 3.4 COMPONENTS os sig dev math idl_tools REQUIRED)
find_package(Threads REQUIRED)
Expand Down
8 changes: 6 additions & 2 deletions src/devices/openxrheadset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ set(yarp_openxrheadset_SRCS
OpenXrInterface.cpp
impl/OpenXrQuadLayer.cpp
impl/OpenXrInterfaceImpl.cpp
LabelPortToQuadLayer.cpp
)

set(yarp_openxrheadset_HDRS
OpenXrConfig.h
OpenGLConfig.h
OpenXrHeadsetLogComponent.h
PortToQuadLayer.h
ImagePortToQuadLayer.h
LabelPortToQuadLayer.h
OpenXrInterface.h
OpenXrEigenConversions.h
impl/OpenXrQuadLayer.h
Expand Down Expand Up @@ -79,6 +81,7 @@ target_link_libraries(yarp_openxrheadset
GLEW::GLEW
OpenGL::GL
Eigen3::Eigen
GLFont::GLFont
)

if (NOT WIN32)
Expand All @@ -105,6 +108,7 @@ if(BUILD_TESTING)
GLEW::GLEW
OpenGL::GL
Eigen3::Eigen
GLFont::GLFont
)

if (NOT WIN32)
Expand All @@ -113,7 +117,7 @@ if(BUILD_TESTING)

target_include_directories(openxrheadset_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_features(yarp_openxrheadset PUBLIC cxx_std_20) #C++20 is used for the designated initialization of structs
target_compile_features(openxrheadset_test PUBLIC cxx_std_20) #C++20 is used for the designated initialization of structs

add_test(NAME openxrheadset_test COMMAND openxrheadset_test)

Expand Down
1 change: 1 addition & 0 deletions src/devices/openxrheadset/EyePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void EyePort::close()
m_initialized = false;
m_eyeAnglesPort.close();
m_tfPublisher = nullptr;
m_layer.close();
}

void EyePort::setEyePosition(const Eigen::Vector3f &position)
Expand Down
4 changes: 2 additions & 2 deletions src/devices/openxrheadset/EyePort.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <yarp/os/Stamp.h>
#include <yarp/os/BufferedPort.h>
#include <OpenXrInterface.h>
#include <PortToQuadLayer.h>
#include <ImagePortToQuadLayer.h>

#include <Eigen/Core>
#include <Eigen/Geometry>
Expand All @@ -33,7 +33,7 @@ class EyePort
Eigen::Quaternionf m_rotationOffset;
Eigen::Vector3f m_eyePosition;
Eigen::Vector3f m_eyeRelativeImagePosition;
PortToQuadLayer<yarp::sig::ImageOf<yarp::sig::PixelRgb>> m_layer;
ImagePortToQuadLayer<yarp::sig::ImageOf<yarp::sig::PixelRgb>> m_layer;
yarp::os::BufferedPort<yarp::sig::Vector> m_eyeAnglesPort;
bool m_initialized{false};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* BSD-2-Clause license. See the accompanying LICENSE file for details.
*/

#ifndef YARP_OPENXRHEADSET_PORTTOQUADLAYER_H
#define YARP_OPENXRHEADSET_PORTTOQUADLAYER_H
#ifndef YARP_OPENXRHEADSET_IMAGEPORTTOQUADLAYER_H
#define YARP_OPENXRHEADSET_IMAGEPORTTOQUADLAYER_H

#include <OpenGLConfig.h>

Expand All @@ -23,10 +23,10 @@
#include <OpenXrHeadsetLogComponent.h>

template <typename ImageType>
class PortToQuadLayer
class ImagePortToQuadLayer
{
std::shared_ptr<IOpenXrQuadLayer> m_quadLayer{nullptr};
std::shared_ptr<yarp::os::BufferedPort<ImageType>> m_portPtr;
std::unique_ptr<yarp::os::BufferedPort<ImageType>> m_portPtr;
GLuint m_glWriteBufferId = 0;
GLuint m_glReadBufferId = 0;
GLuint m_imageTexture;
Expand All @@ -38,6 +38,23 @@ class PortToQuadLayer

public:

void close()
{
if (m_glWriteBufferId != 0)
{
glDeleteFramebuffers(1, &m_glWriteBufferId);
m_glWriteBufferId = 0;
}

if (m_glReadBufferId != 0)
{
glDeleteFramebuffers(1, &m_glReadBufferId);
m_glReadBufferId = 0;
}

m_portPtr->close();
}

bool initialize(std::shared_ptr<IOpenXrQuadLayer> quadLayer, const std::string& portName)
{
yCTrace(OPENXRHEADSET);
Expand Down Expand Up @@ -96,7 +113,7 @@ class PortToQuadLayer
m_newImageDesiredPosition = m_quadLayer->layerPosition();
m_newImageDesiredQuaternion = m_quadLayer->layerQuaternion();

m_portPtr = std::make_shared<yarp::os::BufferedPort<ImageType>>();
m_portPtr = std::make_unique<yarp::os::BufferedPort<ImageType>>();

if (!m_portPtr->open(portName))
{
Expand Down Expand Up @@ -348,4 +365,4 @@ class PortToQuadLayer

};

#endif // YARP_OPENXRHEADSET_PORTTOQUADLAYER_H
#endif // YARP_OPENXRHEADSET_IMAGEPORTTOQUADLAYER_H
Loading

0 comments on commit d67ca69

Please sign in to comment.