STLReader.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 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::STLReader
29 
30 Description
31  Internal class used by the STLsurfaceFormat and triSurface.
32 
33 SourceFiles
34  STLReader.C
35  STLsurfaceFormatASCII.L
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_STLReader_H
40 #define Foam_STLReader_H
41 
42 #include "STLCore.H"
43 #include "labelledTri.H"
44 #include "IFstream.H"
45 #include "Ostream.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 namespace Detail
53 {
54 
55 // Forward declarations
56 class STLAsciiParse;
57 
58 } // End namespace Detail
59 
60 
61 namespace fileFormats
62 {
63 
64 /*---------------------------------------------------------------------------*\
65  Class fileFormats::STLReader Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class STLReader
69 :
70  public STLCore
71 {
72  // Private Data
73 
74  bool sorted_;
75 
76  //- The points supporting the facets
77  List<STLpoint> points_;
78 
79  //- The zones associated with the faces
80  List<label> zoneIds_;
81 
82  //- The solid names, in the order of their first appearance
83  List<word> names_;
84 
85  //- The solid count, in the order of their first appearance
86  List<label> sizes_;
87 
88  //- The STL format used
89  STLFormat format_;
90 
91 
92  // Private Member Functions
93 
94  //- Transfer parsed information to normal lists
95  void transfer(Detail::STLAsciiParse& parsed);
96 
97  //- Parse/read ASCII using Flex-based parser
98  bool readAsciiFlex(const fileName& filename);
99 
100  //- Parse/read ASCII using Ragel-based parser
101  bool readAsciiRagel(const fileName& filename);
102 
103  //- Parse/read ASCII using simple handwritten parser
104  bool readAsciiManual(const fileName& filename);
105 
106  //- Parse/read ASCII
107  bool readASCII(const fileName& filename);
108 
109  //- Read BINARY
110  bool readBINARY(const fileName& filename);
111 
112  //- Read ASCII or BINARY
113  bool readFile(const fileName& filename, const STLFormat format);
114 
115 
116  //- No copy construct
117  STLReader(const STLReader&) = delete;
118 
119  //- No copy assignment
120  void operator=(const STLReader&) = delete;
121 
122 
123 public:
124 
125  // Static Data
126 
127  //- ASCII parser types (0=Flex, 1=Ragel, 2=Manual)
128  static int parserType;
129 
130 
131  // Constructors
132 
133  //- Read from file, filling in the information.
134  // Auto-detect ASCII/BINARY format.
135  explicit STLReader(const fileName& filename);
136 
137  //- Read from file, filling in the information.
138  // Manually selected choice of ASCII/BINARY/UNKNOWN(detect) formats.
139  STLReader(const fileName& filename, const STLFormat format);
140 
141 
142  //- Destructor
143  ~STLReader() = default;
144 
145 
146  // Member Functions
147 
148  //- Flush all values
149  void clear();
150 
151  //- Calculate merge points mapping, return old to new pointMap.
152  // The merge tolerance based on ASCII or BINARY input format.
153  // \return number of unique points
154  label mergePointsMap(labelList& pointMap) const;
155 
156  //- Calculate merge points mapping, return old to new pointMap.
157  // \return number of unique points
158  label mergePointsMap(const scalar mergeTol, labelList& pointMap) const;
159 
160  //- File read was already sorted?
161  bool is_sorted() const noexcept { return sorted_; }
162 
163  //- Return full access to the points
164  List<STLpoint>& points() noexcept { return points_; }
165 
166  //- Return full access to the zoneIds
167  List<label>& zoneIds() noexcept { return zoneIds_; }
168 
169  //- The list of solid names in the order of their first appearance
170  List<word>& names() noexcept { return names_; }
171 
172  //- The list of solid sizes in the order of their first appearance
173  List<label>& sizes() noexcept { return sizes_; }
174 
175  //- The STL format used (ASCII or BINARY)
176  enum STLFormat stlFormat() const noexcept { return format_; }
177 };
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace fileFormats
183 } // End namespace Foam
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
Internal class used when parsing STL ASCII format.
Definition: STLAsciiParse.H:50
A class for handling file names.
Definition: fileName.H:72
STLFormat
Enumeration for the format of data in the stream.
Definition: STLCore.H:59
Internal class used by the STLsurfaceFormat and triSurface.
Definition: STLReader.H:63
List< word > & names() noexcept
The list of solid names in the order of their first appearance.
Definition: STLReader.H:219
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
Core routines used when reading/writing STL files.
Definition: STLCore.H:50
static int parserType
ASCII parser types (0=Flex, 1=Ragel, 2=Manual)
Definition: STLReader.H:153
List< STLpoint > & points() noexcept
Return full access to the points.
Definition: STLReader.H:209
enum STLFormat stlFormat() const noexcept
The STL format used (ASCII or BINARY)
Definition: STLReader.H:229
List< label > & zoneIds() noexcept
Return full access to the zoneIds.
Definition: STLReader.H:214
bool is_sorted() const noexcept
File read was already sorted?
Definition: STLReader.H:204
const direction noexcept
Definition: Scalar.H:258
void clear()
Flush all values.
Definition: STLReader.C:237
label mergePointsMap(labelList &pointMap) const
Calculate merge points mapping, return old to new pointMap.
Definition: STLReader.C:249
List< label > & sizes() noexcept
The list of solid sizes in the order of their first appearance.
Definition: STLReader.H:224
word format(conversionProperties.get< word >("format"))
~STLReader()=default
Destructor.
Namespace for OpenFOAM.