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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
29 
30 inline void Foam::Detail::STLAsciiParse::beginSolid(word solidName)
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 
65 {
66  nFacetPoints_ = 0;
67  nVertexCmpt_ = 0;
68 }
69 
70 
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;
85  ++nFacetPoints_;
86  }
87 
88  return !nVertexCmpt_;
89 }
90 
91 
92 inline 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;
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133 
134 inline 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)
143 {}
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 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
void beginSolid(word solidName)
Action when entering &#39;solid&#39;.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
DynamicList< word > names_
Definition: STLAsciiParse.H:77
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
void beginFacet()
Action when entering &#39;facet&#39;.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
STLAsciiParse(const STLAsciiParse &)=delete
No copy construct.
bool addVertexComponent(float val)
Add next vertex component. On each third call, adds the point.
void clear()
Reset stored values.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:152
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
Definition: HashTableI.H:113
A class for handling words, derived from Foam::string.
Definition: word.H:63
DynamicList< label > sizes_
Definition: STLAsciiParse.H:78
void push_back(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:555
void endFacet()
Action on &#39;endfacet&#39;.
void resetVertex()
Reset vertex component to zero.
HashTable< label > nameLookup_
Definition: STLAsciiParse.H:79