为什么旋转3D点块后顶点法线会翻转? [英] Why do vertex normals flip after rotating 3D point cloulds?

查看:120
本文介绍了为什么旋转3D点块后顶点法线会翻转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个人脸3D点云样本.蓝点云表示目标面部,红点云表示模板.下图显示目标和模板面在不同方向上对齐(目标面大致沿x轴,模板面大致沿y轴).

I have two samples of 3D point cloud of human face. The blue point cloud denote target face and the red point cloud indicates the template. The image below shows that the target and template face are aligned in different directions (target face roughly along x-axis, template face roughly along y-axis).

图1: 鼻子周围的区域如图1所示.

Figure 1: The region around the nose is displayed in Figure 1.

我想以鼻尖为旋转中心旋转我的目标脸(蓝色脸)(我将目标平移到图1之前的模板上,这样两张脸的鼻尖即centerpt叠加)以与模板面(红色面)大致对齐.我使用以下MATLAB代码旋转了目标面部:

I want to rotate my target face (blue face) with nasal tip as the center of rotation (I translated the target to the template prior to Figure1 so that the tip of nose, i.e., the centerpt, for both faces are superimposed) to grossly align with the template face (red face). I rotated the target face with the following MATLAB code:

% PCA for the target face
targetFaceptfmt = pointCloud(targetFace); % Convert to point cloud format
point = [templateFace(3522, 1), templateFace(3522, 2), templateFace(3522, 3)]; % The 3522th point in the templateFace is the nasal tip point used as center of rotation later on
radius = 20; % 20mm
[NNTarIndex, NNTarDist] = findNeighborsInRadius(Locationptfmt, point, radius); % Find all vertices within 20 of the nasal tip point on the target face
NNTar = select(Locationptfmt, NNTarIndex); % Select the identified points for PCA
[TarVec,TarSCORE,TarVal] = pca(NNTar.Location); % Do PCA for target face using vertices close to the nasal tip

% PCA for the template face
templateFaceptfmt = pointCloud(templateFace); % Convert to point cloud format
[NNTemIndex, NNTemDist] = findNeighborsInRadius( templateFaceptfmt, point, radius); % Find all vertices within 20 of the nasal tip point on the template
NNTem = select(templateFaceptfmt, NNTemIndex); % Select the identified points for PCA
[TemVec,TemSCORE,TemVal] = pca(NNTem.Location); % Do PCA for template face using vertices close to the nasal tip

% Rotate target face with nasal tip point as the center of rotation
targetFace_r = R * (targetFace-cenertpt)' + centerpt';
targetFace_new = targetFace_r';

其中,targetFacetemplateFace分别包含未旋转目标面和模板面的坐标. targetFace_r包含围绕鼻尖旋转后目标面部的坐标,R是通过PCA计算的旋转矩阵(请参见

where targetFace and templateFace contains coordinates for the unrotated target face and the template face, respectively. The targetFace_r contains coordinates for the target face after rotation around nasal tip, R is the rotation matrix calculated through PCA (See here for source of formula for rotation), and centerpt is the nasal tip point which is used as the center of rotation. I then plotted the transposed targetFace_r, i.e., the targetFace_new, with normals added to each vertex:

图2:

在旋转之前,目标面和模板面的法线通常指向相似的方向(图1).旋转后,目标面和模板面都沿y轴对齐(这是我想要的),但是,目标面和模板面的法线指向相反的方向.考虑到没有对模板面进行任何更改,我意识到旋转后计算出的目标面的法线会被翻转.但是我不知道为什么.我在R中使用了Rvcg包的checkFaceOrientation函数来检查沿法线的扩展是否会增加质心的大小.对于模板面,我返回了TRUE,但是对于目标面,我返回了FALSE,这确认了目标面的顶点法线是否被翻转.

Before rotation, the normals for the target face and template face are generally pointing toward similar directions (Figure 1). After rotation, the target and template face are both aligned along the y-axis (which is what I want), however, normals for the target face and template face point toward opposite directions. Bearing in mind that no changes were made to the template face, I realized that normals of the target face calculated after rotation are flipped. But I do not know why. I used the checkFaceOrientation function of the Rvcg package in R to check if expansion along normals increases centroid size. I was returned TRUE for the template face but FALSE for the target face, which confirms that vertex normals for the target face are flipped.

顶点法线在MATLAB中的计算如下:

Vertex normals were calculated in MATLAB as follows:

TR = triangulation(Faces, Vertices); % Triangulation based on face and vertex information
VN = vertexNormal(TR); % Calculate vertext normal

其中Faces包含人脸信息,即连接性列表,而Vertices包含顶点的坐标.对于旋转前的目标面,旋转后的目标面以及模板面,顶点法线分别进行计算.在旋转目标面前后,我使用相同的Faces数据来计算顶点法线.

where Faces contains face information, i.e., the connectivity list, and Vertices contains coordiantes for vertices. For target face before rotation, target face after rotation, and template face, vertex normals were calcuated separately. I used the same Faces data for calculation of vertex normal before and after rotating the target face.

顶点法线翻转会导致错误,需要进一步分析.结果,我必须手动翻转法线以使其指向与模板面法线相似的位置.

The flipped vertex normals resulted in errors for some further analyses. As a result, I have to manually flip the normals to make them pointing similarly to normals of the template face.

图3: 图3显示,在手动翻转法线后,目标和模板面的法线通常指向相似的方向.

Figure 3: Figure 3 shows that after manually flip the normals, normals of the target and template face are generally pointing similarly in direction.

我的问题是为什么旋转翻转后计算出的目标面部法线?在什么情况下3D点云的旋转会导致顶点法线的翻转?

My question is why does the normals of the target face calculated after rotation flipped? In what case does rotation of 3D point cloud result in flipping of vertex normals?

可能有用的其他信息:我获得的旋转矩阵R如下,供您参考:

Some further informaiton that may be useful: the rotation matrix R I obtained is as follows for your reference:

0.0473096146726546  0.867593376108813   -0.495018720950670
0.987013081649028   0.0355601323276586  0.156654567895508
-0.153515396665006  0.496001220483328   0.854643675613313

trace(R) = 1 + 2cos(alpha)起,我通过acos((trace(R)-1)/2)*180/pi计算了alpha,相对于鼻尖点旋转角度为91.7904.

Since trace(R) = 1 + 2cos(alpha), I calcualted alpha through acos((trace(R)-1)/2)*180/pi, which yielded an angle of rotation of 91.7904, relative to the nasal tip point.

推荐答案

如果我正确理解了所有内容,则看来您的旋转矩阵实际上是对旋转加反射进行编码.如果您的矩阵大约是:

If I'm understanding everything correctly, it looks like your rotation matrix is actually encoding a rotation plus a reflection. If your matrix is approximately:

 0.04  0.86  -0.49
 0.98  0.03   0.15
-0.15  0.49   0.85

然后,沿正轴指向的每个单位矢量的图像为:

Then the image of each unit vector pointing along the positive axes are:

x = [ 0.04 0.98 -0.15]
y = [ 0.86 0.03  0.49]
z = [-0.49 0.15  0.85]

但是,如果取xy(cross(x, y))的叉积,则得到的近似值为[0.49 -0.15 -0.85],这是对z的取反,这意味着矩阵对两个旋转和反射.自然地,将网格的顶点与反射矩阵相乘会反转其多边形的缠绕顺序,从而产生倒置的法线.

However, if you take the cross-product of x and y (cross(x, y)), you get approximately [0.49 -0.15 -0.85], which is the negation of z, which implies that the matrix is encoding both a rotation and a reflection. Naturally, multiplying a mesh's vertices by a reflection matrix will reverse the winding order of its polygons, yielding inverted normals.

在您引用的幻灯片中,它指出生成旋转矩阵的PCA方法在3D情况下应仅考虑四种不同的轴组合,以确保输出矩阵遵循右手法则.如果检查了所有轴组合,则PCA在搜索最佳匹配时将考虑旋转空间和反射空间.如果是这种情况,并且如果数据中存在一些噪声,使得模板的左半部分与目标的右半部分稍有匹配,反之亦然,则PCA方法可能会生成一个像这样的反射矩阵.你观察.也许您可能想重新审视如何从PCA结果中生成R的逻辑?

In the slides that you referenced, it states that the PCA method of generating a rotation matrix should only be considering four different combinations of axes in the 3D case, to ensure that the output matrix obeys the right-hand rule. If all combinations of axes were checked, that would allow PCA to consider both rotated and reflected spaces when searching for a best match. If that were the case, and if there some noise in the data such that the left half of the template is a slightly better match to the right half of the target and vice versa, then the PCA method might generate a reflection matrix like the one you observe. Perhaps you might want to reexamine the logic of how R is generated from the PCA results?

这篇关于为什么旋转3D点块后顶点法线会翻转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆