Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : 19 : 20 : #ifndef LIBMESH_STL_IO_H 21 : #define LIBMESH_STL_IO_H 22 : 23 : // Local includes 24 : #include "libmesh/libmesh_common.h" 25 : #include "libmesh/mesh_output.h" 26 : #include "libmesh/mesh_input.h" 27 : 28 : // C++ includes 29 : #include <map> 30 : 31 : namespace libMesh 32 : { 33 : 34 : // Forward declarations 35 : class MeshBase; 36 : enum ElemType : int; 37 : 38 : /** 39 : * This class implements reading and writing triangle meshes in the 40 : * STL format. 41 : * 42 : * \author Roy H. Stogner 43 : * \date 2024 44 : */ 45 : class STLIO : public MeshInput<MeshBase>, 46 : public MeshOutput<MeshBase> 47 : { 48 : public: 49 : 50 : /** 51 : * Constructor. Takes a reference to a constant mesh object. 52 : * This constructor will only allow us to write the mesh. 53 : */ 54 : explicit 55 : STLIO (const MeshBase &); 56 : 57 : /** 58 : * Constructor. Takes a writable reference to a mesh object. 59 : * This constructor is required to let us read in a mesh. 60 : */ 61 : explicit 62 : STLIO (MeshBase &); 63 : 64 : /** 65 : * This method implements writing a mesh to a specified file. 66 : * We currently only support ASCII writes. 67 : */ 68 : virtual void write (const std::string &) override; 69 : 70 : /** 71 : * This method implements reading a mesh from a specified file. 72 : */ 73 : virtual void read (const std::string & mesh_file) override; 74 : 75 : /** 76 : * This method implements reading a mesh from a specified ASCII 77 : * input stream. 78 : */ 79 : virtual void read_ascii (std::istream & input); 80 : 81 : /** 82 : * This method implements reading a mesh from a specified binary 83 : * input stream. 84 : * 85 : * If the size in bytes is known a priori then it can be passed in 86 : * to allow for additional error checking. 87 : */ 88 : virtual void read_binary (std::istream & input, 89 : std::size_t input_size = 0); 90 : 91 : /** 92 : * This method gets a name after a set or an ASCII read 93 : */ 94 : const std::string & name () { return _name; } 95 : 96 : /** 97 : * This method sets a name to write 98 : */ 99 0 : virtual void set_name (const std::string & name) { _name = name; } 100 : 101 : /** 102 : * Flag indicating whether or not to subdivide second order 103 : * elements when writing. This option is not yet supported. 104 : */ 105 : bool subdivide_second_order() { return _subdivide_second_order; } 106 : 107 : void set_subdivide_second_order(bool subdivide) 108 : { _subdivide_second_order = subdivide; } 109 : 110 : private: 111 : 112 : /** 113 : * Helper to open possibly-zipped files 114 : */ 115 : std::unique_ptr<std::istream> open_file(const std::string & filename); 116 : 117 : /** 118 : * Flag to subdivide second order elements 119 : */ 120 : bool _subdivide_second_order; 121 : 122 : std::string _name; 123 : }; 124 : 125 : } // namespace libMesh 126 : 127 : 128 : #endif // LIBMESH_STL_IO_H