STLtriangleI.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
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) 2011 OpenFOAM Foundation
9 Copyright (C) 2016 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "triPointRef.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
34{}
35
36
38(
39 const STLpoint& normal,
40 const STLpoint& a,
41 const STLpoint& b,
42 const STLpoint& c,
43 unsigned short attrib
44)
45:
46 normal_(normal),
47 a_(a),
48 b_(b),
49 c_(c),
50 attrib_(attrib)
51{}
52
53
54inline Foam::STLtriangle::STLtriangle(std::istream& is)
55{
56 read(is);
57}
58
59
60// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
61
63{
64 return normal_;
65}
66
67
69{
70 return a_;
71}
72
73
75{
76 return b_;
77}
78
79
81{
82 return c_;
83}
84
85
86inline unsigned short Foam::STLtriangle::attrib() const
87{
88 return attrib_;
89}
90
91
92inline void Foam::STLtriangle::read(std::istream& is)
93{
94 is.read(reinterpret_cast<char*>(&normal_), 4*sizeof(STLpoint));
95 is.read(reinterpret_cast<char*>(&attrib_), sizeof(STLattrib));
96}
97
98
99inline void Foam::STLtriangle::write(std::ostream& os) const
100{
101 os.write(reinterpret_cast<const char*>(&normal_), 4*sizeof(STLpoint));
102 os.write(reinterpret_cast<const char*>(&attrib_), sizeof(STLattrib));
103}
104
105
107{
108 os << " facet normal "
109 << normal_.x() << ' ' << normal_.y() << ' ' << normal_.z() << nl
110 << " outer loop" << nl
111 << " vertex " << a_.x() << ' ' << a_.y() << ' ' << a_.z() << nl
112 << " vertex " << b_.x() << ' ' << b_.y() << ' ' << b_.z() << nl
113 << " vertex " << c_.x() << ' ' << c_.y() << ' ' << c_.z() << nl
114 << " endloop" << nl
115 << " endfacet" << nl;
116
117 return os;
118}
119
120
122(
123 Ostream& os,
124 const vector& norm,
125 const point& pt0,
126 const point& pt1,
127 const point& pt2
128)
129{
130 os << " facet normal "
131 << norm.x() << ' ' << norm.y() << ' ' << norm.z() << nl
132 << " outer loop" << nl
133 << " vertex " << pt0.x() << ' ' << pt0.y() << ' ' << pt0.z() << nl
134 << " vertex " << pt1.x() << ' ' << pt1.y() << ' ' << pt1.z() << nl
135 << " vertex " << pt2.x() << ' ' << pt2.y() << ' ' << pt2.z() << nl
136 << " endloop" << nl
137 << " endfacet" << nl;
138}
139
140
142(
143 Ostream& os,
144 const point& pt0,
145 const point& pt1,
146 const point& pt2
147)
148{
149 // Calculate the normal ourselves
150 const vector norm = triPointRef(pt0, pt1, pt2).unitNormal();
151
152 write(os, norm, pt0, pt1, pt2);
153}
154
155
156// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
157
159{
160 os << tri.normal_ << token::SPACE
161 << tri.a_ << token::SPACE
162 << tri.b_ << token::SPACE
163 << tri.c_ << token::SPACE
164 << tri.attrib_;
165
166 return os;
167}
168
169
170// ************************************************************************* //
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
A vertex point or facet normal representation for STL files.
Definition: STLpoint.H:52
A triangle representation for STL files.
Definition: STLtriangle.H:58
const STLpoint & a() const
Definition: STLtriangleI.H:68
const STLpoint & c() const
Definition: STLtriangleI.H:80
const STLpoint & normal() const
Definition: STLtriangleI.H:62
const STLpoint & b() const
Definition: STLtriangleI.H:74
unsigned short attrib() const
Definition: STLtriangleI.H:86
STLtriangle()
Construct null.
Definition: STLtriangleI.H:33
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
virtual bool write()
Write the output fields.
scalar print()
Print to screen.
@ SPACE
Space [isspace].
Definition: token.H:125
OBJstream os(runTime.globalPath()/outputName)
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
triangle< point, const point & > triPointRef
A triangle using referred points.
Definition: triangle.H:71
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
runTime write()
volScalarField & b
Definition: createFields.H:27