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-2021 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 STLsurfaceFormat_H
48 #define 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  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
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
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);
182 
183  //- Write surface mesh to file
184  virtual void write
185  (
186  const fileName& name,
187  IOstreamOption streamOpt = IOstreamOption(),
188  const dictionary& options = dictionary::null
189  ) const
190  {
191  write(name, MeshedSurfaceProxy<Face>(*this), streamOpt, options);
192  }
193 };
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 } // End namespace fileFormats
199 } // End namespace Foam
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #ifdef NoRepository
204  #include "STLsurfaceFormat.C"
205 #endif
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #endif
210 
211 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:79
MeshedSurfaceProxy.H
STLReader.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::fileFormats::STLsurfaceFormat::writeAscii
static void writeAscii(const fileName &filename, const MeshedSurfaceProxy< Face > &surf, IOstreamOption::compressionType comp=IOstreamOption::UNCOMPRESSED)
Write surface mesh components by proxy (as ASCII)
Definition: STLsurfaceFormat.C:204
Foam::fileFormats::STLsurfaceFormat::STLsurfaceFormat
STLsurfaceFormat(const fileName &filename)
Construct from file name.
Definition: STLsurfaceFormat.C:106
Foam::fileFormats::STLsurfaceFormat::writeBinary
static void writeBinary(const fileName &filename, const MeshedSurfaceProxy< Face > &surf)
Write surface mesh components by proxy (as BINARY)
Definition: STLsurfaceFormat.C:252
Foam::fileFormats::STLsurfaceFormat
Provide a means of reading/writing STL files (ASCII and BINARY).
Definition: STLsurfaceFormat.H:66
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:82
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:392
UnsortedMeshedSurface.H
format
word format(conversionProperties.get< word >("format"))
Foam::fileFormats::STLsurfaceFormat::~STLsurfaceFormat
virtual ~STLsurfaceFormat()=default
Destructor.
Foam::UnsortedMeshedSurface
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Definition: MeshedSurface.H:83
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fileFormats::STLsurfaceFormat::read
virtual bool read(const fileName &filename)
Read from file.
Definition: STLsurfaceFormat.C:118
STLsurfaceFormat.C
Foam::fileFormats::STLsurfaceFormat::write
static void write(const fileName &filename, const MeshedSurfaceProxy< Face > &surf, const STLFormat format, IOstreamOption::compressionType comp=IOstreamOption::UNCOMPRESSED)
Write surface mesh components by proxy.
Definition: STLsurfaceFormat.C:415
Foam::fileFormats::STLCore::STLFormat
STLFormat
Enumeration for the format of data in the stream.
Definition: STLCore.H:61
Foam::fileFormats::STLCore
Core routines used when reading/writing STL files.
Definition: STLCore.H:54
f
labelList f(nPoints)
Foam::UList
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:103
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:77
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::MeshedSurface
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: triSurfaceTools.H:80
MeshedSurface.H