Hi,
I am trying to display a point cloud using PyOpenGL and pygame.
My code reads the .ply file and displays the point cloud but produces some weird artifacts at certain regions of the cloud.
This is what I get. E.g. the face looks weird.
This is what I expect:
This is my current code:
if __name__ == "__main__":
#initialize window
pg.init()
pg.display.set_caption('Test')
display = (1680, 1050)
pg.display.set_mode(display, DOUBLEBUF | OPENGL)
#read data
pointcloud = "pointcloud.ply"
pointcloud = o3d.io.read_point_cloud(pointcloud)
points = np.asarray(pointcloud.points, dtype=np.float32)
colors = np.asarray(pointcloud.colors, dtype=np.float32)
# vertexBuffer
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, points, GL_STATIC_DRAW)
# colorBuffer
cba = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, cba)
glBufferData(GL_ARRAY_BUFFER, colors, GL_STATIC_DRAW)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
gluPerspective(60, display[0] / display[1], 0.1, 2500)
glClearColor(255, 255, 255, 1.0) # backround color white
glTranslate(-200, -500, -1800)
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
quit()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glVertexPointer(3, GL_FLOAT, 3*4, None)
glBindBuffer(GL_ARRAY_BUFFER, cba)
glColorPointer(3, GL_FLOAT, 3*4, None)
glDrawArrays(GL_POINTS, 0, len(points))
pg.display.flip()
pg.time.wait(30)
What is causing these artifacts and how can I fix these?