STLAsciiParseI.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 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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\*---------------------------------------------------------------------------*/
27
28// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
29
31{
32 if (solidName.empty())
33 {
34 solidName = "solid"; // Could also use solid0, solid1, ...
35 }
36
37 auto iter = nameLookup_.cfind(solidName);
38 if (iter.found())
39 {
40 if (groupId_ != iter.val())
41 {
42 sorted_ = false; // Group appeared out of order
43 groupId_ = iter.val();
44 }
45 }
46 else
47 {
49 if (nameLookup_.insert(solidName, groupId_))
50 {
51 names_.append(solidName);
52 sizes_.append(0);
53 }
54 else
55 {
56 FatalErrorInFunction<< "Duplicate solid-name: " << solidName
57 << exit(FatalError);
58 }
59 }
60}
61
62
64{
65 nFacetPoints_ = 0;
66 nVertexCmpt_ = 0;
67}
68
69
71{
72 nVertexCmpt_ = 0;
73}
74
75
77{
78 currVertex_[nVertexCmpt_] = val;
79
80 if (++nVertexCmpt_ == 3)
81 {
82 points_.append(currVertex_);
83 nVertexCmpt_ = 0;
84 ++nFacetPoints_;
85 }
86
87 return !nVertexCmpt_;
88}
89
90
92{
93 //-> safer, but slower: readFloat(text, currVertex_[nVertexCmpt_]);
94 currVertex_[nVertexCmpt_] = ::atof(text);
95
96 if (++nVertexCmpt_ == 3)
97 {
98 points_.append(currVertex_);
99 nVertexCmpt_ = 0;
100 ++nFacetPoints_;
101 }
102
103 return !nVertexCmpt_;
104}
105
106
108{
109 if (nFacetPoints_ == 3)
110 {
111 facets_.append(groupId_);
112 sizes_[groupId_]++;
113 }
114 else
115 {
116 if (nFacetPoints_ > 3)
117 {
118 nFacetPoints_ -= 3;
119 }
120
121 if (nFacetPoints_)
122 {
123 points_.resize(points_.size() - nFacetPoints_);
124 }
125 }
126
127 nFacetPoints_ = 0;
128}
129
130
131// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
132
133inline Foam::Detail::STLAsciiParse::STLAsciiParse(const label approxNpoints)
134:
135 sorted_(true),
136 groupId_(-1),
137 lineNum_(1),
138 nFacetPoints_(0),
139 nVertexCmpt_(0),
140 points_(approxNpoints),
141 facets_(approxNpoints/2)
142{}
143
144
145// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146
148{
149 sorted_ = true;
150 groupId_ = -1;
151 lineNum_ = 0;
152
153 nFacetPoints_ = 0;
154 nVertexCmpt_ = 0;
155
156 points_.clear();
157 facets_.clear();
158 names_.clear();
159 sizes_.clear();
160 nameLookup_.clear();
161}
162
163
165{
166 return sorted_;
167}
168
169
171{
172 return points_;
173}
174
175
177{
178 return facets_;
179}
180
181
183{
184 return names_;
185}
186
187
189{
190 return sizes_;
191}
192
193
194// ************************************************************************* //
Internal class used when parsing STL ASCII format.
Definition: STLAsciiParse.H:55
void beginFacet()
Action when entering 'facet'.
bool sorted() const
Do all the solid groups appear in order?
DynamicList< STLpoint > & points()
A list of unstitched triangle points.
HashTable< label > nameLookup_
Definition: STLAsciiParse.H:77
void beginSolid(word solidName)
Action when entering 'solid'.
bool addVertexComponent(float val)
Add next vertex component. On each third call, adds the point.
DynamicList< word > names_
Definition: STLAsciiParse.H:75
void endFacet()
Action on 'endfacet'.
DynamicList< label > sizes_
Definition: STLAsciiParse.H:76
void clear()
Reset stored values.
void resetVertex()
Reset vertex component to zero.
DynamicList< label > & sizes()
Solid sizes in the order of their appearance.
DynamicList< word > & names()
Solid names in the order of their appearance.
DynamicList< label > & facets()
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
Definition: HashTableI.H:141
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130