2016-11-21 4 views
-1

Ich kann 3D-Punkte in einer Farbe zeichnen, sagen wir grün. Aber ich versage es, einzelne Farbe auf jeden Punkt anzuwenden.Punktwolke mit individueller Farbe

bool applyColor = true; 
glPointSize(3); 
glBegin(GL_POINTS); 
glColor3ub(0,255,0); 

for(auto vpMP : vpMPs){ 
    if(applyColor){ 
     cv::Vec3b rgb = vpMP->rgb; 
     glColor3ub(rgb[2], rgb[1], rgb[0]); 
     cout << (int)rgb[0] << ", " << (int)rgb[1] << ", " << (int)rgb[2] << endl; // Prints out right values 
    } 
    cv::Mat pos = vpMP->GetWorldPos(); 
    glVertex3f(pos.at<float>(0),pos.at<float>(1),pos.at<float>(2)); 
} 
glEnd(); 

Irgendwelche Anhaltspunkte?

glVertex3f funktioniert gut, Punkte erscheinen dort, wo sie sein sollten.

Mit applyColor = false werden Punkte grün angezeigt.

Mit applyColor = true, zeigen Punkte schwarz, wenn sie rgb sein sollten. BTW, rgb [i] sind vorzeichenlose Zeichen.

Vielen Dank!

+0

Also was siehst du in 'cout'? Welche Werte gibt es in 'vpMP-> rgb'? – ybungalobill

+0

cout druckt Zeilen wie diese: '244, 98, 12' alle korrekten rgb-Werte von 0 bis 255. –

+0

Das bedeutet, dass das Problem in dem Code liegt, den Sie nicht angezeigt haben. Bitte poste ein [MCVE] (http://stackoverflow.com/help/mcve). – ybungalobill

Antwort

0

Ich konnte nicht meinen alten Code arbeiten, und, wie @ybungalobill darauf hinwies, dass Code alte veraltete Fest-Funktion-Pipeline verwendet, so bewegte ich zu diesem moderneren Ansatz, der funktioniert.

nur Teilcode Angezeigt:

bool color = true; 
struct glPunto{ 
    float x; 
    float y; 
    float z; 
    uchar r; 
    uchar g; 
    uchar b; 
    char padding[17]; // Así la estructura es múltiplo de 32 bytes 
}; 
glPunto glPuntos[N]; 


int i = 0; 
for(auto punto : vpMPs){ 
    cv::Mat pos = punto->GetWorldPos(); 
    auto rgb = punto->rgb; 

    glPunto &glp = glPuntos[i++]; 

    glp.x = pos.at<float>(0); 
    glp.y = pos.at<float>(1); 
    glp.z = pos.at<float>(2); 

    if(color){ 
     glp.r = rgb[2]; 
     glp.g = rgb[1]; 
     glp.b = rgb[0]; 
    } else { 
     glp.r = 0; 
     glp.g = 0; 
     glp.b = 0; 
    } 
} 

glPointSize(color?4:2); 
glEnableClientState(GL_VERTEX_ARRAY); 
glVertexPointer(3, GL_FLOAT, sizeof(glPunto), &glPuntos[0].x); 
glEnableClientState (GL_COLOR_ARRAY); 
glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(glPunto), &glPuntos[0].r); 

glDrawArrays(GL_POINTS, 0, i); 

glDisableClientState (GL_COLOR_ARRAY); 
glDisableClientState (GL_VERTEX_ARRAY); 

immer noch nicht den Stand der Technik Dies stellt. Es wäre besser, wenn es glVertexAttribPointer verwendet.

Verwandte Themen