stereolabs/zed-openpose

Creating a class similar to PeoplesObject in GLViewer.hpp/GLViewer.cpp

giopri13 opened this issue · 3 comments

Hello everyone.
I'm trying to create a class to visualize an outline in 3D for the interactive static objects defined in the scene, such that, when people touch the item, the 3D viewer shows its position.

At first, I realized a small demo instantiating a PeoplesObject cubeObj, different from the already included peopleObj used for detected people, and using setVerts() and update() to set the correct cube vertices. It worked, but only showing this cubeObj in the GLViewer window and not the 3D skeleton.
So I tried to differentiate by creating a class which, for now (just to have a second demo), is basically a clone of PeoplesObject and calling it CubesObject. At the moment it has the same methods as the original class, and will be expanded to better suit my project. The problem is that now that I have PeoplesObject peopleObj and CubesObject cubeObj I can only see the 3D skeleton of the person in the scene and not the item.

Does anyone have a clue about what is going on? Why did the two objects peopleObj and cubeObj conflict when they were from the same class PeoplesObject? Why doesn't the new class have the same functionalities as the one it is based on?

I'm sorry to post such a complicated and specific question, but I would rather rely on the experience of people way more capable than I am than trying to second guess anything - at least I can really learn something discussing about possible solutions.

Hi,
Can you share the code to reproduce that? Maybe it's a opengl conflict. You can check that OpenGL is actually perfoming as expected by calling glGetError() at different position to check if it returns a value != 0

In GLViewer.hpp

`
/*
Custom class CubeObject, inspired by PeoplesObject and modified to represent cuboids in the GLViewer Window
*/

class CubesObject {
GLuint vaoID_;
GLuint vboID_[3];
int current_fc;
std::mutex mtx;
std::vectorsl::float3 vert;
std::vectorsl::float3 clr;
std::vector m_indices_;
bool update;

public:
CubesObject();
~CubesObject();

void updateMesh();

void cpy(CubesObject &other) {
    mtx.lock();
    vert = other.vert;
    clr = other.clr;
    m_indices_ = other.m_indices_;
    update = other.update;
    mtx.unlock();
}

void clear() {
    mtx.lock();
    vert.clear();
    m_indices_.clear();
    mtx.unlock();
}

void setVert(std::vector<sl::float3> &vertices, std::vector<sl::float3> &clr);

void draw();

}; `

In GLViewer.cpp
`
CubesObject::CubesObject() {
current_fc = 0;
vaoID_ = 0;
update = false;
}

CubesObject::~CubesObject() {
current_fc = 0;
if (vaoID_)
glDeleteBuffers(3, vboID_);
}

void CubesObject::setVert(std::vectorsl::float3 &vertices, std::vectorsl::float3 &clr) {
mtx.lock();
vert = vertices;
this->clr = clr;

m_indices_.clear();
m_indices_.reserve(vertices.size());
for (int i = 0; i < vertices.size(); i++)
    m_indices_.push_back(i);

update = true;
mtx.unlock();

}

void CubesObject::updateMesh() {
if (update) {
mtx.lock();

    if (vaoID_ == 0) {
        glGenVertexArrays(1, &vaoID_);
        glGenBuffers(3, vboID_);
    }

    glBindVertexArray(vaoID_);

    glBindBuffer(GL_ARRAY_BUFFER, vboID_[0]);
    glBufferData(GL_ARRAY_BUFFER, vert.size() * sizeof (sl::float3), &vert[0], GL_DYNAMIC_DRAW);
    glVertexAttribPointer(Shader::ATTRIB_VERTICES_POS, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(Shader::ATTRIB_VERTICES_POS);

    glBindBuffer(GL_ARRAY_BUFFER, vboID_[1]);
    glBufferData(GL_ARRAY_BUFFER, clr.size() * sizeof (sl::float3), &clr[0], GL_DYNAMIC_DRAW);
    glVertexAttribPointer(Shader::ATTRIB_COLOR_POS, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(Shader::ATTRIB_COLOR_POS);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID_[2]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices_.size() * sizeof (unsigned int), &m_indices_[0], GL_DYNAMIC_DRAW);

    current_fc = (int) m_indices_.size();

    glBindVertexArray(0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    mtx.unlock();
}
update = false;

}

void CubesObject::draw() {
if ((current_fc > 0) && (vaoID_ > 0) && mtx.try_lock()) {
glBindVertexArray(vaoID_);
glLineWidth(4);
glDrawElements(GL_LINES, (GLsizei) current_fc, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
mtx.unlock();
}
} `

In main.cpp I create a CubesObject cubeObj, enter the coordinates of the objects, initialize cubeObj with item vertices as it is done with peoplesObj in fill_people_ogl() and call viewer.update(cubeObj) in the rendering section of run()

Edit: Sorry for the broken code insertion

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days