STLtriangle.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2017 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 Class
28  Foam::STLtriangle
29 
30 Description
31  A triangle representation for STL files.
32 
33 SourceFiles
34  STLtriangleI.H
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef STLtriangle_H
39 #define STLtriangle_H
40 
41 #include "STLpoint.H"
42 #include "Istream.H"
43 #include "Ostream.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward Declarations
51 class STLtriangle;
52 inline Ostream& operator<<(Ostream& os, const STLtriangle& tri);
53 
54 /*---------------------------------------------------------------------------*\
55  Class STLtriangle Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class STLtriangle
59 {
60  // Typedefs
61 
62  //- Attribute is 16-bit
63  typedef unsigned short STLattrib;
64 
65  // Private data
66  // NB: The order of the members (1 normal, 3 points, 1 attribute) is
67  // essential when reading/writing binary content.
68 
69  //- The face normal and the three points defining the triangle.
70  // Some programs may write zero or other junk for the normal.
71  STLpoint normal_, a_, b_, c_;
72 
73  //- The attribute information could be for 'color' or solid id, etc
74  STLattrib attrib_;
75 
76 
77 public:
78 
79  // Constructors
80 
81  //- Construct null
82  inline STLtriangle();
83 
84  //- Construct from components
85  inline STLtriangle
86  (
87  const STLpoint& normal,
88  const STLpoint& a,
89  const STLpoint& b,
90  const STLpoint& c,
91  unsigned short attrib
92  );
93 
94  //- Construct from istream (read binary)
95  inline STLtriangle(std::istream& is);
96 
97 
98  // Member Functions
99 
100  // Access
101 
102  inline const STLpoint& normal() const;
103  inline const STLpoint& a() const;
104  inline const STLpoint& b() const;
105  inline const STLpoint& c() const;
106  inline unsigned short attrib() const;
107 
108 
109  // Read
110 
111  //- Read from istream (binary)
112  inline void read(std::istream& is);
113 
114 
115  // Write
116 
117  //- Write to ostream (binary)
118  inline void write(std::ostream& os) const;
119 
120  //- Write to Ostream (ASCII)
121  inline Ostream& print(Ostream& os) const;
122 
123 
124  //- Write components to Ostream (ASCII)
125  inline static void write
126  (
127  Ostream& os,
128  const vector& norm,
129  const point& pt0,
130  const point& pt1,
131  const point& pt2
132  );
133 
134  //- Write components to Ostream (ASCII), calculating the normal
135  inline static void write
136  (
137  Ostream& os,
138  const point& pt0,
139  const point& pt1,
140  const point& pt2
141  );
142 
143 
144  // Ostream Operator
145 
146  //- Print triangle contents
147  friend Ostream& operator<<(Ostream& os, const STLtriangle& tri);
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Foam
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #include "STLtriangleI.H"
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #endif
162 
163 // ************************************************************************* //
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
STLpoint.H
STLtriangleI.H
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
Istream.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::STLtriangle::operator<<
friend Ostream & operator<<(Ostream &os, const STLtriangle &tri)
Print triangle contents.
Ostream.H
Foam::STLtriangle::b
const STLpoint & b() const
Definition: STLtriangleI.H:74
Foam::STLtriangle::c
const STLpoint & c() const
Definition: STLtriangleI.H:80
Foam::STLtriangle
A triangle representation for STL files.
Definition: STLtriangle.H:57
Foam::STLpoint
A vertex point or facet normal representation for STL files.
Definition: STLpoint.H:49
Foam::Vector< scalar >
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