-
大小: 6KB文件类型: .m金币: 1下载: 0 次发布日期: 2021-06-03
- 语言: Matlab
- 标签:
资源简介
matlab代码,可将三角网格网格转换成深度图,深度值是由三维点的z值计算而来
代码片段和文件信息
function mesh = pointCloud2mesh(data refNormal stdTol)
% mesh = meshD(data refNormal stdTol)
% Author : Ajmal Saeed Mian {ajmal@csse.uwa.edu.au}
% Computer Science. Univ of Western Australia
%
% This function takes data points performs triangulation on it filters out
% incorrecp polygons and outputs a mesh data structure like the newMesh
% function.
%
% Arguments : data - Nx3 vertex coordinates [x y z] of the pointcloud
% stdTol - (optional) tolerance for edge filtering. default is 0.6
%
% refNormal - (optional) 1x3 vector in the sensor direction
% =[0 0 1] if the sensor looking towards the -z_axis
%
% Return : mesh - mesh data structure
% vertices: Nx3 vertex coordinates
% triangles: M triangles using index numbers of the vertices
% resolution: the mean edge length of triangles
% stdeviation: the standard deviation o edge lengths
% triangleNormals: Mx3 normal vectors of each triangle
% vertexNormals: Nx3 normal vectors of each vertex
% vertexNtriangles: Nx1 cell of neighboring triangles
% of each vertex
% triangleNtriangles: Mx1 cell of nieghboring triangles
% of each triangle
%
% Copyright : This code is written by Ajmal Saeed Mian {ajmal@csse.uwa.edu.au}
% Computer Science The University of Western Australia. The code
% may be used modified and distributed for research purposes with
% acknowledgement of the author and inclusion this copyright information.
%
% Disclaimer : This code is provided as is without any warrantly.
warning off MATLAB:divideByZero;
if nargin == 1
PC = princomp(data);
data = data*PC;
refNormal = [0 0 1];
refNormal = refNormal * PC;
end
if nargin < 3
stdTol = 0.6;
end
tri = delaunay(data(:1)data(:2));
tri(:4) = 0; % initialize 4th column to store maximum edge length
edgeLength = [sqrt(sum((data(tri(:1):) - data(tri(:2):)).^22))...
sqrt(sum((data(tri(:2):) - data(tri(:3):)).^22))...
sqrt(sum((data(tri(:3):) - data(tri(:1):)).^22))];
tri(:4) = max(edgeLength[]2);
resolution = mean(edgeLength(:));
stdeviation = std(edgeLength(:));
filtLimit = resolution + stdTol*stdeviation;
bigTriangles = find(tri(:4) > filtLimit); %find index numbers of triagles with edgelength more than filtLimit
tri(bigTriangles:) = []; % remove all triangles with edgelength more than filtlimit
tri(:4) = []; % remove the max edgeLength column
edgeLength(bigTriangles:) = [];
评论
共有 条评论