How do I take a 3d dimensional array and convert it into a model?

痞子三分冷 提交于 2020-01-24 14:25:08

问题


I'm using Open CV and I'm able to extract multidimensional data from and image with my codes but what would be an easy way to display it? I have a 3D array:

line start [x] [y] [z]
line end   [x] [y] [z]

Anything in between the lines will be filled with a solid flat surface.

Is there some kind of function I can use to easily display a 3d image given these points or whatever other points I'm missing?

Such as this pseudo code:

display_3d(x,y,z,angle)

Any help is highly appreciated. Also I'm using C++.


回答1:


I am not sure if i understand correctly but why do you have 3D array ???

  • array of 3D points representing surface is usually 1D array of 3D points:

            float points[n][3];
    // not float points[nx][ny][nz] !!!
    

I am not CV user so I will stick to (OpenGL) rendering, but you can use any other render instead.

1.if the points represents concave flat surface

  • on single plane!!!
  • and are in the order (not mixed up)
  • then you can use GL_TRIANGLE_FAN or anything similar in other renders.

    float points[n]={ {x,y,z},{x,y,z},...};
    glBegin(GL_TRIANGLE_FAN);
    glVertex3fv(points[0]);
    glVertex3fv(points[1]);
    glVertex3fv(points[2]);
    ...
    glVertex3fv(points[n-1]);
    glEnd();
    

2.if not then you have to triangulate your data

  • it is not an easy task but there are some libs out there that do it.
  • not sure if OpenCV can do that too, look for triangulation functions (ears drop,etc)
  • I prefer my own triangulation routines (better for debugging and also for additional polygon info) but a little hard to code it efficiently and correctly when you not used to used algorithms.



回答2:


First you need to find the convex hull of your points which means finding non-ambiguous and efficient representation of a set of points. Once you do that you will need to triangulate your mesh, usually using delaunay triangulation. QHull provides such functionality.



来源:https://stackoverflow.com/questions/15445927/how-do-i-take-a-3d-dimensional-array-and-convert-it-into-a-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!