STLAsciiParse.H
Go to the documentation of this file.
1 /*--------------------------------*- C++ -*----------------------------------*\
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) 2018-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::Detail::STLAsciiParse
28 
29 Description
30  Internal class used when parsing STL ASCII format
31 
32 SourceFiles
33  STLAsciiParse.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef Foam_STLAsciiParse_H
38 #define Foam_STLAsciiParse_H
39 
40 #include "DynamicList.H"
41 #include "HashTable.H"
42 #include "STLpoint.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 namespace Detail
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class Detail::STLAsciiParse Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class STLAsciiParse
56 {
57 protected:
58 
59  // Protected Data
60 
61  bool sorted_;
62  label groupId_; // The current solid group
63  label lineNum_;
64 
65  //- The number of local points on the current facet
66  int nFacetPoints_;
67 
68  //- Current vertex component when reading 'vertex'
69  int nVertexCmpt_;
70 
71  //- Scratch space for reading 'vertex'
73 
79 
80 
81  // Protected Member Functions
82 
83  //- Action when entering 'solid'
84  inline void beginSolid(word solidName);
85 
86  //- Action when entering 'facet'
87  inline void beginFacet();
88 
89  //- Reset vertex component to zero
90  inline void resetVertex();
91 
92  //- Add next vertex component. On each third call, adds the point.
93  // \return true when point has been added (on the last component)
94  inline bool addVertexComponent(float val);
95 
96  //- Add next vertex component. On each third call, adds the point.
97  // \return true when point has been added (on the last component)
98  inline bool addVertexComponent(const char* text);
99 
100  //- Action on 'endfacet'
101  inline void endFacet();
102 
103 
104  //- No copy construct
105  STLAsciiParse(const STLAsciiParse&) = delete;
106 
107  //- No copy assignment
108  void operator=(const STLAsciiParse&) = delete;
109 
110 
111 public:
112 
113  // Constructors
114 
115  //- Construct with the estimated number of triangles in the STL
116  inline STLAsciiParse(const label nTrisEstimated);
117 
118 
119  // Member Functions
120 
121  //- Reset stored values
122  inline void clear();
123 
124  //- Do all the solid groups appear in order?
125  bool is_sorted() const noexcept { return sorted_; }
126 
127  //- A list of unstitched triangle points
129 
130  //- A list of facet IDs (group IDs)
131  //- corresponds to the number of triangles
133 
134  //- Solid names in the order of their appearance.
135  DynamicList<word>& names() noexcept { return names_; }
136 
137  //- Solid sizes in the order of their appearance.
138  DynamicList<label>& sizes() noexcept { return sizes_; }
139 };
140 
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 } // End namespace Detail
145 } // End namespace Foam
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 #include "STLAsciiParseI.H"
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #endif
154 
155 // ************************************************************************* //
Internal class used when parsing STL ASCII format.
Definition: STLAsciiParse.H:50
DynamicList< word > & names() noexcept
Solid names in the order of their appearance.
void beginSolid(word solidName)
Action when entering &#39;solid&#39;.
DynamicList< word > names_
Definition: STLAsciiParse.H:77
void beginFacet()
Action when entering &#39;facet&#39;.
int nFacetPoints_
The number of local points on the current facet.
Definition: STLAsciiParse.H:63
void operator=(const STLAsciiParse &)=delete
No copy assignment.
STLAsciiParse(const STLAsciiParse &)=delete
No copy construct.
bool addVertexComponent(float val)
Add next vertex component. On each third call, adds the point.
DynamicList< label > & sizes() noexcept
Solid sizes in the order of their appearance.
bool is_sorted() const noexcept
Do all the solid groups appear in order?
void clear()
Reset stored values.
DynamicList< label > facets_
Definition: STLAsciiParse.H:76
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
A class for handling words, derived from Foam::string.
Definition: word.H:63
DynamicList< STLpoint > points_
Definition: STLAsciiParse.H:75
const direction noexcept
Definition: Scalar.H:258
int nVertexCmpt_
Current vertex component when reading &#39;vertex&#39;.
Definition: STLAsciiParse.H:68
DynamicList< label > sizes_
Definition: STLAsciiParse.H:78
void endFacet()
Action on &#39;endfacet&#39;.
STLpoint currVertex_
Scratch space for reading &#39;vertex&#39;.
Definition: STLAsciiParse.H:73
DynamicList< label > & facets() noexcept
A list of facet IDs (group IDs) corresponds to the number of triangles.
void resetVertex()
Reset vertex component to zero.
DynamicList< STLpoint > & points() noexcept
A list of unstitched triangle points.
A vertex point or facet normal representation for STL files.
Definition: STLpoint.H:43
Namespace for OpenFOAM.
HashTable< label > nameLookup_
Definition: STLAsciiParse.H:79