【源码】将多种输入(片、面)输出到STL三角形网格的函数stlwrite

在这里插入图片描述
stlwrite(FILE, FV) 将立体光刻(STL)文件写入由FV定义的三角剖面。

stlwrite(FILE, FV) writes a stereolithography (STL) file to FILE for a

triangulated patch defined by FV (a structure with fields ‘vertices’

and ‘faces’).

stlwrite(FILE, FACES, VERTICES)函数将面与顶点进行了分离,而不是放在FV结构体中。

stlwrite(FILE, FACES, VERTICES) takes faces and vertices separately,

rather than in an FV struct.

stlwrite(FILE, X, Y, Z)从面数据的X、Y、Z三维创建STL文件。

stlwrite(FILE, X, Y, Z) creates an STL file from surface data in X, Y,

and Z.

stlwrite使用以下指定的三角化选项将网格数据三角化成三角状表面。

stlwrite triangulates this gridded data into a triangulated surface using triangulation options specified below.

X、Y、Z均为大小相同的二维矩阵。

X, Y and Z can be two-dimensional arrays with the same size.

如果X和Y是长度分别等于SIZE(Z,2)和SIEZE(Z,1)的向量,则通过MESHGRID来创建网格数据。

If X and Y are vectors with length equal to SIZE(Z,2) and SIZE(Z,1), respectively, they are passed through MESHGRID to create gridded data.

如果X或Y是标量值,则它们用于指定网格点之间的X和Y间距。

If X or Y are scalar values, they are used to specify the X and Y spacing between grid points.

stlwrite(…,‘PropertyName’,VALUE,‘PropertyName’,VALUE,…)在输出STL文件时具有以下特性可供选择:

stlwrite(…,‘PropertyName’,VALUE,‘PropertyName’,VALUE,…) writes an

STL file using the following property values:

MODE - 写文件采用“二进制”(默认模式)还是“ascii”。

MODE - File is written using ‘binary’ (default) or ‘ascii’.

TITLE - 写入STL文件的文本字头(最多80个字母)。

TITLE - Header text (max 80 chars) written to the STL file.

TRIANGULATION - 当使用网格数据时,TRIANGULATION可选为:

‘delaunay’ - (默认) X、Y的Delaunay三角剖分

‘f’ - 网格四边形的前斜切分割

‘b’ - 四边形的反斜切分割

‘x’ - 四边形的交叉剖分

TRIANGULATION - When used with gridded data, TRIANGULATION is either:

‘delaunay’ - (default) Delaunay triangulation of X, Y

‘f’ - Forward slash division of grid quads

‘b’ - Back slash division of quadrilaterals

‘x’ - Cross division of quadrilaterals

FACECOLOR - 对于面/点输入,采用单色彩(1 x 3)或每面一种色彩(N x 3)。RGB用5个bit表示,即0 - 31,以VisCAM/SolidView格式存储。

FACECOLOR - Single colour (1-by-3) or one-colour-per-face (N-by-3) vector of RGB colours, for face/vertex input. RGB range is 5 bits (0:31), stored in VisCAM/SolidView format.

Example 1:
% Write binary STL from face/vertex data
tmpvol = false(20,20,20); % Empty voxel volume
tmpvol(8:12,8:12,5:15) = 1; % Turn some voxels on
fv = isosurface(~tmpvol, 0.5); % Make patch w. faces “out”
stlwrite(‘test.stl’,fv) % Save to binary .stl

Example 2:
% Write ascii STL from gridded data
[X,Y] = deal(1:40); % Create grid reference
Z = peaks(40); % Create grid height
stlwrite(‘test.stl’,X,Y,Z,‘mode’,‘ascii’)

Example 3:
% Write binary STL with coloured faces
cVals = fv.vertices(fv.faces(:,1),3); % Colour by Z height.
cLims = [min(cVals) max(cVals)]; % Transform height values
nCols = 255; cMap = jet(nCols); % onto an 8-bit colour map
fColsDbl = interp1(linspace(cLims(1),cLims(2),nCols),cMap,cVals);
fCols8bit = fColsDbl*255; % Pass cols in 8bit (0-255) RGB triplets
stlwrite(‘testCol.stl’,fv,‘FaceColor’,fCols8bit)

源码下载地址:

http://page5.dfpan.com/fs/0lcj2221f29106288c5/

更多精彩文章请关注微信号:在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42825609/article/details/85029015