STLsurfaceFormat.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::fileFormats::STLsurfaceFormat
29 
30 Description
31  Provide a means of reading/writing STL files (ASCII and BINARY).
32 
33  Output stream options: ASCII/BINARY, compression for ASCII only
34 
35  Output dictionary options: ignored
36 
37 Note
38  For efficiency, the zones are sorted before creating the faces.
39  The class is thus derived from MeshedSurface.
40 
41 SourceFiles
42  STLsurfaceFormat.C
43  STLsurfaceFormatASCII.L
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef Foam_STLsurfaceFormat_H
48 #define Foam_STLsurfaceFormat_H
49 
50 #include "STLReader.H"
51 #include "MeshedSurface.H"
52 #include "MeshedSurfaceProxy.H"
53 #include "UnsortedMeshedSurface.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 namespace fileFormats
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class fileFormats::STLsurfaceFormat Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 template<class Face>
67 class STLsurfaceFormat
68 :
69  public MeshedSurface<Face>,
70  public STLCore
71 {
72  // Private Member Functions
73 
74  //- Write Face (ASCII)
75  static inline void writeShell
76  (
77  Ostream& os,
78  const UList<point>& pts,
79  const Face& f
80  );
81 
82  //- Write Face (BINARY)
83  static inline void writeShell
84  (
85  ostream& os,
86  const UList<point>& pts,
87  const Face& f,
88  const label zoneI
89  );
90 
91 
92 public:
93 
94  // Constructors
95 
96  //- Construct from file name
97  explicit STLsurfaceFormat(const fileName& filename);
98 
99 
100  //- Destructor
101  virtual ~STLsurfaceFormat() = default;
102 
103 
104  // Static Functions
105 
106  //- Write surface mesh components by proxy (as ASCII)
107  static void writeAscii
108  (
109  const fileName& filename,
110  const MeshedSurfaceProxy<Face>& surf,
112  );
113 
114  //- Write surface mesh components by proxy (as BINARY)
115  static void writeBinary
116  (
117  const fileName& filename,
118  const MeshedSurfaceProxy<Face>& surf
119  );
120 
121  //- Write UnsortedMeshedSurface (as ASCII) sorted by zone
122  static void writeAscii
123  (
124  const fileName& filename,
125  const UnsortedMeshedSurface<Face>& surf,
127  );
128 
129  //- Write UnsortedMeshedSurface (as BINARY) unsorted by zone
130  static void writeBinary
131  (
132  const fileName& filename,
133  const UnsortedMeshedSurface<Face>& surf
134  );
135 
136  //- Write surface mesh components (by proxy) in STL format
137  //- as ASCII or BINARY or dependent on the extension
138  static void write
139  (
140  const fileName& filename,
141  const MeshedSurfaceProxy<Face>& surf,
142  const STLFormat format,
144  );
145 
146  //- Write UnsortedMeshedSurface
147  // as ASCII or BINARY or dependent on the extension
148  static void write
149  (
150  const fileName& filename,
151  const UnsortedMeshedSurface<Face>& surf,
152  const STLFormat format,
154  );
155 
156 
157  //- Write surface mesh components (by proxy) in STL format
158  //- as ASCII or BINARY, depending on the extension
159  static void write
160  (
161  const fileName& filename,
162  const MeshedSurfaceProxy<Face>& surf,
163  IOstreamOption streamOpt = IOstreamOption(),
164  const dictionary& options = dictionary::null
165  );
166 
167  //- Write UnsortedMeshedSurface
168  //- as ASCII or BINARY, depending on the extension
169  static void write
170  (
171  const fileName& filename,
172  const UnsortedMeshedSurface<Face>& surf,
173  IOstreamOption streamOpt = IOstreamOption(),
174  const dictionary& options = dictionary::null
175  );
176 
177 
178  // Member Functions
179 
180  //- Read from file
181  virtual bool read(const fileName& filename) override;
182 
183  //- Write surface mesh to file (by proxy)
184  virtual void write
185  (
186  const fileName& name,
187  IOstreamOption streamOpt = IOstreamOption(),
188  const dictionary& options = dictionary::null
189  ) const override
190  {
191  write(name, MeshedSurfaceProxy<Face>(*this), streamOpt, options);
192  }
193 
194  //- Write surface mesh to file (by proxy)
195  virtual void write
196  (
197  const fileName& name,
198  const word& fileType, /* ignored */
199  IOstreamOption streamOpt = IOstreamOption(),
200  const dictionary& options = dictionary::null
201  ) const override
202  {
203  write(name, MeshedSurfaceProxy<Face>(*this), streamOpt, options);
204  }
205 };
206 
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 } // End namespace fileFormats
211 } // End namespace Foam
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 #ifdef NoRepository
216  #include "STLsurfaceFormat.C"
217 #endif
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #endif
223 // ************************************************************************* //
A surface geometry mesh, in which the surface zone information is conveyed by the &#39;zoneId&#39; associated...
Definition: MeshedSurface.H:76
A class for handling file names.
Definition: fileName.H:72
STLFormat
Enumeration for the format of data in the stream.
Definition: STLCore.H:59
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
virtual bool read(const fileName &filename) override
Read from file.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Provide a means of reading/writing STL files (ASCII and BINARY).
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Core routines used when reading/writing STL files.
Definition: STLCore.H:50
STLsurfaceFormat(const fileName &filename)
Construct from file name.
A simple container for options an IOstream can normally have.
static void writeBinary(const fileName &filename, const MeshedSurfaceProxy< Face > &surf)
Write surface mesh components by proxy (as BINARY)
static void writeAscii(const fileName &filename, const MeshedSurfaceProxy< Face > &surf, IOstreamOption::compressionType comp=IOstreamOption::UNCOMPRESSED)
Write surface mesh components by proxy (as ASCII)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
static void write(const fileName &filename, const MeshedSurfaceProxy< Face > &surf, const STLFormat format, IOstreamOption::compressionType comp=IOstreamOption::UNCOMPRESSED)
Write surface mesh components (by proxy) in STL format as ASCII or BINARY or dependent on the extensi...
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:486
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:75
labelList f(nPoints)
word format(conversionProperties.get< word >("format"))
virtual ~STLsurfaceFormat()=default
Destructor.
Namespace for OpenFOAM.
const pointField & pts