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 -------------------------------------------------------------------------------
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 "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 
54 inline Foam::STLtriangle::STLtriangle(std::istream& is)
55 {
56  read(is);
57 }
58 
59 
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
61 
63 {
64  return normal_;
65 }
66 
67 
68 inline const Foam::STLpoint& Foam::STLtriangle::a() const
69 {
70  return a_;
71 }
72 
73 
74 inline const Foam::STLpoint& Foam::STLtriangle::b() const
75 {
76  return b_;
77 }
78 
79 
80 inline const Foam::STLpoint& Foam::STLtriangle::c() const
81 {
82  return c_;
83 }
84 
85 
86 inline unsigned short Foam::STLtriangle::attrib() const
87 {
88  return attrib_;
89 }
90 
91 
92 inline 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 
99 inline 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 
121 inline void Foam::STLtriangle::write
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 
141 inline void Foam::STLtriangle::write
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 // ************************************************************************* //
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::STLtriangle::read
void read(std::istream &is)
Read from istream (binary)
Definition: STLtriangleI.H:92
Foam::STLtriangle::attrib
unsigned short attrib() const
Definition: STLtriangleI.H:86
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
triPointRef.H
Foam::OBJstream::write
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::STLtriangle::write
void write(std::ostream &os) const
Write to ostream (binary)
Definition: STLtriangleI.H:99
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::STLtriangle::print
Ostream & print(Ostream &os) const
Write to Ostream (ASCII)
Definition: STLtriangleI.H:106
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
os
OBJstream os(runTime.globalPath()/outputName)
Foam::STLtriangle::b
const STLpoint & b() const
Definition: STLtriangleI.H:74
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::STLtriangle::c
const STLpoint & c() const
Definition: STLtriangleI.H:80
Foam::STLtriangle
A triangle representation for STL files.
Definition: STLtriangle.H:57
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::STLpoint
A vertex point or facet normal representation for STL files.
Definition: STLpoint.H:49
Foam::Vector< scalar >
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::STLtriangle::normal
const STLpoint & normal() const
Definition: STLtriangleI.H:62
Foam::STLtriangle::STLtriangle
STLtriangle()
Construct null.
Definition: STLtriangleI.H:33
Foam::STLtriangle::a
const STLpoint & a() const
Definition: STLtriangleI.H:68
Foam::triPointRef
triangle< point, const point & > triPointRef
A triangle using referred points.
Definition: triangle.H:71