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 -------------------------------------------------------------------------------
11 License
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 "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 
50 inline Foam::STLtriangle::STLtriangle(std::istream& is)
51 {
52  read(is);
53 }
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
58 inline 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 
65 inline 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 
87 inline void Foam::STLtriangle::write
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 
107 inline 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 
124 inline 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 // ************************************************************************* //
void read(std::istream &is)
Read from istream (binary)
Definition: STLtriangleI.H:51
virtual Ostream & write(const char c) override
Write character.
Definition: OBJstream.C:69
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & print(Ostream &os) const
Write to Ostream (ASCII)
Definition: STLtriangleI.H:65
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
vector unitNormal() const
Return unit normal.
Definition: triangleI.H:178
void write(std::ostream &os) const
Write to ostream (binary)
Definition: STLtriangleI.H:58
Space [isspace].
Definition: token.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
STLtriangle()=default
Default construct.
const volScalarField & p0
Definition: EEqn.H:36
A vertex point or facet normal representation for STL files.
Definition: STLpoint.H:43