我们复制框属性出paraview包的:
box = struct();
box.translate = [-274.8975, -114.0316, -333.6671];
box.rotate = [27.066, 119.62, -175.472];
box.scale = [1.031, 0.663, 1.2233];
箱尺寸是相对于剪辑过滤器上定义的几何尺寸。因此,首先获取几何的范围,其顶点存储在surfpts中。
surfpts = ...; % [nPoints x 3]
mn = min(surfpts,[],1);
mx = max(surfpts,[],1);
在这个例子中,我想填充一个网格点的框。
box.xyz = arrayfun(@(a,b) linspace(a,b,n)', mn, mx, 'UniformOutput',false);
box.xyz = cell2mat(box.xyz);
[X,Y,Z] = ndgrid(box.xyz(:,1), box.xyz(:,2), box.xyz(:,3));
box.XYZ = [X(:), Y(:), Z(:)];
现在我们要根据我们做的盒子的Paraview 3D插件的动作来缩放,旋转和平移我们的网格(顺序!)。
% Scaling
box.XYZ = bsxfun(@times, box.XYZ, box.scale);
% Rotation
box.XYZ = (rotz(box.rotate(3)) * rotx(box.rotate(1)) * roty(box.rotate(2)) * box.XYZ')';
% Translation
box.XYZ = bsxfun(@plus, box.XYZ, box.translate);
最后,我们通过在ParaView中再次打开创建的框来检查结果。它与盒子完全匹配。
TR = delaunayTriangulation(box.XYZ);
[box_tri, box_pts] = TR.freeBoundary();
vtkwrite('tmp_box.vtk','polydata','triangle',box_pts(:,1),box_pts(:,2),box_pts(:,3),box_tri)