1## Copyright (C) 2021 David Legland
2## All rights reserved.
3##
4## Redistribution and use in source and binary forms, with or without
5## modification, are permitted provided that the following conditions are met:
6##
7##     1 Redistributions of source code must retain the above copyright notice,
8##       this list of conditions and the following disclaimer.
9##     2 Redistributions in binary form must reproduce the above copyright
10##       notice, this list of conditions and the following disclaimer in the
11##       documentation and/or other materials provided with the distribution.
12##
13## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS''
14## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
17## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23##
24## The views and conclusions contained in the software and documentation are
25## those of the authors and should not be interpreted as representing official
26## policies, either expressed or implied, of the copyright holders.
27
28function writeMesh_stl(fileName, vertices, faces, varargin)
29%WRITEMESH_STL Write mesh data in the STL format.
30%
31%   writeMesh_stl(FNAME, VERTICES, FACES)
32%
33%   writeMesh_stl(FNAME, MESH)
34%
35%   writeMesh_stl(FNAME, VERTICES, FACES, ...) see stlwrite for additonal
36%   options
37%
38%   Example
39%   mesh = cylinderMesh([60 50 40 10 20 30 5], 1);
40%   writeMesh_stl('Cylinder.stl', mesh, 'bin');
41%
42%   References
43%   Wrapper function for MATLAB's build-in stlwrite.
44%
45%   See also
46%   meshes3d, writeMesh, writeMesh_off, writeMesh_ply
47
48% ------
49% Author: oqilipo
50% Created: 2021-02-13, using Matlab 9.9.0.1538559 (R2020b)
51% Copyright 2021
52
53%% Check inputs
54if ~ischar(fileName)
55    error('First argument must contain the name of the file');
56end
57
58% optionnaly parses data
59if isstruct(vertices)
60    if nargin > 2
61        varargin = [{faces} varargin{:}];
62    end
63    faces = vertices.faces;
64    vertices = vertices.vertices;
65end
66
67%% Write STL
68TR = triangulation(faces, vertices);
69stlwrite(TR,fileName, varargin{:})
70
71end
72