【发布时间】:2018-01-14 09:56:32
【问题描述】:
我有如下问题如图。我有点云和由四面体算法生成的网格。我将如何使用该算法雕刻网格?地标是点云吗?
算法伪代码:
for every 3D feature point
convert it 2D projected coordinates
for every 2D feature point
cast a ray toward the polygons of the mesh
get intersection point
if zintersection < z of 3D feature point
for ( every triangle vertices )
cull that triangle.
这是Guru Spektre提到的算法的后续实现:)
更新算法代码:
int i;
for (i = 0; i < out.numberofpoints; i++)
{
Ogre::Vector3 ray_pos = pos; // camera position);
Ogre::Vector3 ray_dir = (Ogre::Vector3 (out.pointlist[(i*3)], out.pointlist[(3*i)+1], out.pointlist[(3*i)+2]) - pos).normalisedCopy(); // vertex - camea pos ;
Ogre::Ray ray;
ray.setOrigin(Ogre::Vector3( ray_pos.x, ray_pos.y, ray_pos.z));
ray.setDirection(Ogre::Vector3(ray_dir.x, ray_dir.y, ray_dir.z));
Ogre::Vector3 result;
unsigned int u1;
unsigned int u2;
unsigned int u3;
bool rayCastResult = RaycastFromPoint(ray.getOrigin(), ray.getDirection(), result, u1, u2, u3);
if ( rayCastResult )
{
Ogre::Vector3 targetVertex(out.pointlist[(i*3)], out.pointlist[(3*i)+1], out.pointlist[(3*i)+2]);
float distanceTargetFocus = targetVertex.squaredDistance(pos);
float distanceIntersectionFocus = result.squaredDistance(pos);
if(abs(distanceTargetFocus) >= abs(distanceIntersectionFocus))
{
if ( u1 != -1 && u2 != -1 && u3 != -1)
{
std::cout << "Remove index "<< "u1 ==> " <<u1 << "u2 ==>"<<u2<<"u3 ==> "<<u3<< std::endl;
updatedIndices.erase(updatedIndices.begin()+ u1);
updatedIndices.erase(updatedIndices.begin()+ u2);
updatedIndices.erase(updatedIndices.begin()+ u3);
}
}
}
}
if ( updatedIndices.size() <= out.numberoftrifaces)
{
std::cout << "current face list===> "<< out.numberoftrifaces << std::endl;
std::cout << "deleted face list===> "<< updatedIndices.size() << std::endl;
manual->begin("Pointcloud", Ogre::RenderOperation::OT_TRIANGLE_LIST);
for (int n = 0; n < out.numberofpoints; n++)
{
Ogre::Vector3 vertexTransformed = Ogre::Vector3( out.pointlist[3*n+0], out.pointlist[3*n+1], out.pointlist[3*n+2]) - mReferencePoint;
vertexTransformed *=1000.0 ;
vertexTransformed = mDeltaYaw * vertexTransformed;
manual->position(vertexTransformed);
}
for (int n = 0 ; n < updatedIndices.size(); n++)
{
int n0 = updatedIndices[n+0];
int n1 = updatedIndices[n+1];
int n2 = updatedIndices[n+2];
if ( n0 < 0 || n1 <0 || n2 <0 )
{
std::cout<<"negative indices"<<std::endl;
break;
}
manual->triangle(n0, n1, n2);
}
manual->end();
跟进算法:
我现在有两个版本,一个是三角版,另一个是雕刻版。
这不是表面网格。 这是两个文件 http://www.mediafire.com/file/cczw49ja257mnzr/ahmed_non_triangulated.obj http://www.mediafire.com/file/cczw49ja257mnzr/ahmed_triangulated.obj
【问题讨论】:
-
我在 cmets 中写的东西至少需要我 2 周的全职编码(因为我过去没有做任何类似的事情,需要从头开始编码)我没有也没有时间,也没有心情。这就是为什么您的另一个问题被标记为关闭太宽泛。生成的代码将远大于 30Kb 的限制,解释它的文字可能会填满整本书。除非使用计算着色器,否则 OpenGL 和 DirecX 对此没有多大帮助,但调试会花费更多时间,所以我强烈建议在 CPU 端执行此操作,并且仅在工作端口到 GPU 时执行此操作
-
点云的加载和可视化没什么,可以很快编码。您缺少的是 Raycasting 和 Mesh CSG 之类的数学,大量的试验和错误来设置会有所帮助的视图(可能从 6 个基本视图开始不会有多大好处)看看这些 stackoverflow.com/a/48092685/2521214 @ 987654324@ 并将它们移植到 CPU
-
您需要实现射线三角形相交(在第二个链接中),然后您需要从网格中实现面移除。因为我不知道你用什么结构......只能猜测。
-
为此我需要更多关于您的图像和世界坐标系的信息,其中 (0,0,0) 以及哪个方向指向哪个轴
-
通过比较距离 ....
|target_vertex-focus| >= |face_ray_intersection-focus|表示您在目标顶点之前击中面部并且应该被移除。为了提高速度,您不需要sqrt可以比较它们的长度...
标签: algorithm graphics 3d computer-vision 3d-reconstruction