Loading...
Searching...
No Matches
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-2022 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/>.
27\*---------------------------------------------------------------------------*/
28
29#include "triangle.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
34(
35 const STLpoint& normal,
36 const STLpoint& p0,
37 const STLpoint& p1,
38 const STLpoint& p2,
39 uint16_t attrib
40)
41:
42 normal_(normal),
43 a_(p0),
44 b_(p1),
45 c_(p2),
46 attrib_(attrib)
47{}
48
49
50inline Foam::STLtriangle::STLtriangle(std::istream& is)
52 read(is);
53}
54
55
56// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57
58inline void Foam::STLtriangle::read(std::istream& is)
59{
60 is.read(reinterpret_cast<char*>(&normal_), 4*sizeof(STLpoint));
61 is.read(reinterpret_cast<char*>(&attrib_), sizeof(STLattrib));
62}
63
64
65inline void Foam::STLtriangle::write(std::ostream& os) const
66{
67 os.write(reinterpret_cast<const char*>(&normal_), 4*sizeof(STLpoint));
68 os.write(reinterpret_cast<const char*>(&attrib_), sizeof(STLattrib));
69}
70
71
73{
74 os << " facet normal "
75 << normal_.x() << ' ' << normal_.y() << ' ' << normal_.z() << nl
76 << " outer loop" << nl
77 << " vertex " << a_.x() << ' ' << a_.y() << ' ' << a_.z() << nl
78 << " vertex " << b_.x() << ' ' << b_.y() << ' ' << b_.z() << nl
79 << " vertex " << c_.x() << ' ' << c_.y() << ' ' << c_.z() << nl
80 << " endloop" << nl
81 << " endfacet" << nl;
82
83 return os;
84}
85
86
88(
89 Ostream& os,
90 const vector& norm,
91 const point& p0,
92 const point& p1,
93 const point& p2
94)
95{
96 os << " facet normal "
97 << norm.x() << ' ' << norm.y() << ' ' << norm.z() << nl
98 << " outer loop" << nl
99 << " vertex " << p0.x() << ' ' << p0.y() << ' ' << p0.z() << nl
100 << " vertex " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl
101 << " vertex " << p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl
102 << " endloop" << nl
103 << " endfacet" << nl;
104}
105
106
107inline void Foam::STLtriangle::write
108(
109 Ostream& os,
110 const point& p0,
111 const point& p1,
112 const point& p2
113)
114{
115 // Calculate the normal ourselves
116 const vector norm = triPointRef::unitNormal(p0, p1, p2);
118 write(os, norm, p0, p1, p2);
119}
120
121
122// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
123
124inline Foam::Ostream& Foam::operator<<(Ostream& os, const STLtriangle& tri)
125{
126 os << tri.normal() << token::SPACE
127 << tri.a() << token::SPACE
128 << tri.b() << token::SPACE
129 << tri.c() << token::SPACE
130 << tri.attrib();
131
132 return os;
133}
134
135
136// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A vertex point or facet normal representation for STL files.
Definition STLpoint.H:46
A triangle representation for STL files.
Definition STLtriangle.H:55
void write(std::ostream &os) const
Write to ostream (binary).
const STLpoint & a() const noexcept
const STLpoint & normal() const noexcept
Ostream & print(Ostream &os) const
Write to Ostream (ASCII).
const STLpoint & b() const noexcept
const STLpoint & c() const noexcept
STLtriangle()=default
Default construct.
uint16_t attrib() const noexcept
void read(std::istream &is)
Read from istream (binary).
const Cmpt & x() const noexcept
Access to the vector x component.
Definition Vector.H:135
const Cmpt & z() const noexcept
Access to the vector z component.
Definition Vector.H:145
const Cmpt & y() const noexcept
Access to the vector y component.
Definition Vector.H:140
@ SPACE
Space [isspace].
Definition token.H:144
const volScalarField & p0
Definition EEqn.H:36
OBJstream os(runTime.globalPath()/outputName)
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
vector point
Point is a vector.
Definition point.H:37
Vector< scalar > vector
Definition vector.H:57
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
runTime write()