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 -------------------------------------------------------------------------------
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 
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  {
48  groupId_ = sizes_.size();
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 
133 inline 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 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Detail::STLAsciiParse::clear
void clear()
Reset stored values.
Definition: STLAsciiParseI.H:147
Foam::Detail::STLAsciiParse::sizes
DynamicList< label > & sizes()
Solid sizes in the order of their appearance.
Definition: STLAsciiParseI.H:188
Foam::Detail::STLAsciiParse::sizes_
DynamicList< label > sizes_
Definition: STLAsciiParse.H:76
Foam::DynamicList< Foam::STLpoint >
Foam::Detail::STLAsciiParse::endFacet
void endFacet()
Action on 'endfacet'.
Definition: STLAsciiParseI.H:107
Foam::HashTable::insert
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
Foam::Detail::STLAsciiParse::sorted
bool sorted() const
Do all the solid groups appear in order?
Definition: STLAsciiParseI.H:164
Foam::Detail::STLAsciiParse::facets
DynamicList< label > & facets()
Definition: STLAsciiParseI.H:176
Foam::Detail::STLAsciiParse::sorted_
bool sorted_
Definition: STLAsciiParse.H:60
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::Detail::STLAsciiParse::STLAsciiParse
STLAsciiParse(const STLAsciiParse &)=delete
No copy construct.
Foam::Detail::STLAsciiParse::resetVertex
void resetVertex()
Reset vertex component to zero.
Definition: STLAsciiParseI.H:70
Foam::FatalError
error FatalError
Foam::Detail::STLAsciiParse::nameLookup_
HashTable< label > nameLookup_
Definition: STLAsciiParse.H:77
Foam::Detail::STLAsciiParse::points
DynamicList< STLpoint > & points()
A list of unstitched triangle points.
Definition: STLAsciiParseI.H:170
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::Detail::STLAsciiParse::addVertexComponent
bool addVertexComponent(float val)
Add next vertex component. On each third call, adds the point.
Definition: STLAsciiParseI.H:76
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::Detail::STLAsciiParse::names
DynamicList< word > & names()
Solid names in the order of their appearance.
Definition: STLAsciiParseI.H:182
Foam::HashTable::cfind
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
Definition: HashTableI.H:141
Foam::Detail::STLAsciiParse::groupId_
label groupId_
Definition: STLAsciiParse.H:61
Foam::Detail::STLAsciiParse::beginSolid
void beginSolid(word solidName)
Action when entering 'solid'.
Definition: STLAsciiParseI.H:30
Foam::Detail::STLAsciiParse::beginFacet
void beginFacet()
Action when entering 'facet'.
Definition: STLAsciiParseI.H:63
Foam::Detail::STLAsciiParse::names_
DynamicList< word > names_
Definition: STLAsciiParse.H:75