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 STLReader_H
40 #define 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  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  inline bool sorted() const
162  {
163  return sorted_;
164  }
165 
166  //- Return full access to the points
167  inline List<STLpoint>& points()
168  {
169  return points_;
170  }
171 
172  //- Return full access to the zoneIds
173  inline List<label>& zoneIds()
174  {
175  return zoneIds_;
176  }
177 
178  //- The list of solid names in the order of their first appearance
179  inline List<word>& names()
180  {
181  return names_;
182  }
183 
184  //- The list of solid sizes in the order of their first appearance
185  inline List<label>& sizes()
186  {
187  return sizes_;
188  }
189 
190  //- The STL format used (ASCII or BINARY)
191  inline enum STLFormat stlFormat() const
192  {
193  return format_;
194  }
195 };
196 
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace fileFormats
201 } // End namespace Foam
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 #endif
206 
207 // ************************************************************************* //
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::fileFormats::STLReader::~STLReader
~STLReader()=default
Destructor.
Foam::Detail::STLAsciiParse
Internal class used when parsing STL ASCII format.
Definition: STLAsciiParse.H:54
STLCore.H
Foam::fileFormats::STLReader::sizes
List< label > & sizes()
The list of solid sizes in the order of their first appearance.
Definition: STLReader.H:184
format
word format(conversionProperties.get< word >("format"))
Foam::fileFormats::STLReader::stlFormat
enum STLFormat stlFormat() const
The STL format used (ASCII or BINARY)
Definition: STLReader.H:190
Foam::fileFormats::STLReader::zoneIds
List< label > & zoneIds()
Return full access to the zoneIds.
Definition: STLReader.H:172
Foam::fileFormats::STLReader::sorted
bool sorted() const
File read was already sorted?
Definition: STLReader.H:160
Foam::fileFormats::STLReader::clear
void clear()
Flush all values.
Definition: STLReader.C:244
Foam::fileFormats::STLReader::names
List< word > & names()
The list of solid names in the order of their first appearance.
Definition: STLReader.H:178
Foam::fileFormats::STLReader::points
List< STLpoint > & points()
Return full access to the points.
Definition: STLReader.H:166
Foam::fileFormats::STLReader::mergePointsMap
label mergePointsMap(labelList &pointMap) const
Calculate merge points mapping, return old to new pointMap.
Definition: STLReader.C:256
IFstream.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Ostream.H
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
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::fileFormats::STLReader::parserType
static int parserType
ASCII parser types (0=Flex, 1=Ragel, 2=Manual)
Definition: STLReader.H:127
labelledTri.H
Foam::fileFormats::STLReader
Internal class used by the STLsurfaceFormat and triSurface.
Definition: STLReader.H:67