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-2017 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 Note
34  For efficiency, the zones are sorted before creating the faces.
35  The class is thus derived from MeshedSurface.
36 
37 SourceFiles
38  STLsurfaceFormat.C
39  STLsurfaceFormatASCII.L
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef STLsurfaceFormat_H
44 #define STLsurfaceFormat_H
45 
46 #include "STLReader.H"
47 #include "MeshedSurface.H"
48 #include "MeshedSurfaceProxy.H"
49 #include "UnsortedMeshedSurface.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 namespace fileFormats
56 {
57 
58 /*---------------------------------------------------------------------------*\
59  Class fileFormats::STLsurfaceFormat Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 template<class Face>
63 class STLsurfaceFormat
64 :
65  public MeshedSurface<Face>,
66  public STLCore
67 {
68  // Private Member Functions
69 
70  //- Write Face (ASCII)
71  static inline void writeShell
72  (
73  Ostream& os,
74  const UList<point>& pts,
75  const Face& f
76  );
77 
78  //- Write Face (BINARY)
79  static inline void writeShell
80  (
81  ostream& os,
82  const UList<point>& pts,
83  const Face& f,
84  const label zoneI
85  );
86 
87 
88 public:
89 
90  // Constructors
91 
92  //- Construct from file name
93  STLsurfaceFormat(const fileName& filename);
94 
95 
96  //- Destructor
97  virtual ~STLsurfaceFormat() = default;
98 
99 
100  // Static Member Functions
101 
102  //- Write surface mesh components by proxy (as ASCII)
103  static void writeAscii
104  (
105  const fileName& filename,
106  const MeshedSurfaceProxy<Face>& surf
107  );
108 
109  //- Write surface mesh components by proxy (as BINARY)
110  static void writeBinary
111  (
112  const fileName& filename,
113  const MeshedSurfaceProxy<Face>& surf
114  );
115 
116  //- Write UnsortedMeshedSurface (as ASCII) sorted by zone
117  static void writeAscii
118  (
119  const fileName& filename,
120  const UnsortedMeshedSurface<Face>& surf
121  );
122 
123  //- Write UnsortedMeshedSurface (as BINARY) unsorted by zone
124  static void writeBinary
125  (
126  const fileName& filename,
127  const UnsortedMeshedSurface<Face>& surf
128  );
129 
130  //- Write surface mesh components by proxy
131  // as ASCII or BINARY or dependent on the extension
132  static void write
133  (
134  const fileName& filename,
135  const MeshedSurfaceProxy<Face>& surf,
136  const STLFormat format
137  );
138 
139  //- Write UnsortedMeshedSurface
140  // as ASCII or BINARY or dependent on the extension
141  static void write
142  (
143  const fileName& filename,
144  const UnsortedMeshedSurface<Face>& surf,
145  const STLFormat format
146  );
147 
148 
149  //- Write surface mesh components by proxy
150  // as ASCII or BINARY, depending on the extension
151  static void write
152  (
153  const fileName& filename,
154  const MeshedSurfaceProxy<Face>& surf,
155  const dictionary& options = dictionary::null
156  );
157 
158  //- Write UnsortedMeshedSurface
159  // as ASCII or BINARY, depending on the extension
160  static void write
161  (
162  const fileName& filename,
163  const UnsortedMeshedSurface<Face>& surf,
164  const dictionary& options = dictionary::null
165  );
166 
167 
168  // Member Functions
169 
170  //- Read from file
171  virtual bool read(const fileName& filename);
172 
173  //- Write surface mesh to file
174  virtual void write
175  (
176  const fileName& name,
177  const dictionary& options = dictionary::null
178  ) const
179  {
180  write(name, MeshedSurfaceProxy<Face>(*this), options);
181  }
182 };
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace fileFormats
188 } // End namespace Foam
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 #ifdef NoRepository
193  #include "STLsurfaceFormat.C"
194 #endif
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 #endif
199 
200 // ************************************************************************* //
MeshedSurfaceProxy.H
STLReader.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
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:257
Foam::fileFormats::STLsurfaceFormat
Provide a means of reading/writing STL files (ASCII and BINARY).
Definition: STLsurfaceFormat.H:62
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:78
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:385
UnsortedMeshedSurface.H
format
word format(conversionProperties.get< word >("format"))
Foam::fileFormats::STLsurfaceFormat::~STLsurfaceFormat
virtual ~STLsurfaceFormat()=default
Destructor.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::UnsortedMeshedSurface
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Definition: MeshedSurface.H:79
Foam::fileFormats::STLsurfaceFormat::write
static void write(const fileName &filename, const MeshedSurfaceProxy< Face > &surf, const STLFormat format)
Write surface mesh components by proxy.
Definition: STLsurfaceFormat.C:424
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
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::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::fileFormats::STLsurfaceFormat::writeAscii
static void writeAscii(const fileName &filename, const MeshedSurfaceProxy< Face > &surf)
Write surface mesh components by proxy (as ASCII)
Definition: STLsurfaceFormat.C:203
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