Loading...
Searching...
No Matches
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-2023 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.good())
39 {
40 if (groupId_ != iter.val())
41 {
42 sorted_ = false; // Group appeared out of order
43 groupId_ = iter.val();
44 }
45 }
46 else
47 {
48 groupId_ = sizes_.size();
49 if (nameLookup_.insert(solidName, groupId_))
50 {
51 names_.push_back(std::move(solidName));
52 sizes_.push_back(0);
53 }
54 else
55 {
57 << "Duplicate solid-name: " << solidName << nl
58 << exit(FatalError);
59 }
60 }
61}
62
63
68}
69
72{
73 nVertexCmpt_ = 0;
74}
75
76
78{
79 currVertex_[nVertexCmpt_] = val;
80
81 if (++nVertexCmpt_ == 3)
82 {
83 points_.push_back(currVertex_);
84 nVertexCmpt_ = 0;
86 }
87
88 return !nVertexCmpt_;
89}
90
91
92inline bool Foam::Detail::STLAsciiParse::addVertexComponent(const char* text)
93{
94 //-> safer, but slower: readFloat(text, currVertex_[nVertexCmpt_]);
95 currVertex_[nVertexCmpt_] = ::atof(text);
96
97 if (++nVertexCmpt_ == 3)
98 {
99 points_.push_back(currVertex_);
100 nVertexCmpt_ = 0;
101 ++nFacetPoints_;
102 }
104 return !nVertexCmpt_;
105}
106
107
109{
110 if (nFacetPoints_ == 3)
111 {
112 facets_.push_back(groupId_);
113 ++sizes_[groupId_];
114 }
115 else
116 {
117 if (nFacetPoints_ > 3)
118 {
119 nFacetPoints_ -= 3;
120 }
121
122 if (nFacetPoints_)
123 {
124 points_.resize(points_.size() - nFacetPoints_);
125 }
126 }
127
128 nFacetPoints_ = 0;
130
131
132// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133
134inline Foam::Detail::STLAsciiParse::STLAsciiParse(const label nTrisEstimated)
135:
136 sorted_(true),
137 groupId_(-1),
138 lineNum_(1),
139 nFacetPoints_(0),
140 nVertexCmpt_(0),
141 points_(3*nTrisEstimated),
142 facets_(nTrisEstimated)
144
145
146// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147
149{
150 sorted_ = true;
151 groupId_ = -1;
152 lineNum_ = 0;
153
154 nFacetPoints_ = 0;
155 nVertexCmpt_ = 0;
156
157 points_.clear();
158 facets_.clear();
159 names_.clear();
160 sizes_.clear();
161 nameLookup_.clear();
162}
163
164
165// ************************************************************************* //
DynamicList< label > facets_
void beginFacet()
Action when entering 'facet'.
HashTable< label > nameLookup_
void beginSolid(word solidName)
Action when entering 'solid'.
bool addVertexComponent(float val)
Add next vertex component. On each third call, adds the point.
STLpoint currVertex_
Scratch space for reading 'vertex'.
int nFacetPoints_
The number of local points on the current facet.
DynamicList< word > names_
void endFacet()
Action on 'endfacet'.
STLAsciiParse(const STLAsciiParse &)=delete
No copy construct.
DynamicList< STLpoint > points_
DynamicList< label > sizes_
int nVertexCmpt_
Current vertex component when reading 'vertex'.
void clear()
Reset stored values.
void resetVertex()
Reset vertex component to zero.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50