OBJstream.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) 2012-2015 OpenFOAM Foundation
9  Copyright (C) 2017-2020 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::OBJstream
29 
30 Description
31  OFstream that keeps track of vertices
32 
33 SourceFiles
34  OBJstream.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef OBJstream_H
39 #define OBJstream_H
40 
41 #include "OFstream.H"
42 #include "point.H"
43 #include "edge.H"
44 #include "face.H"
45 #include "triPointRef.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward Declarations
53 class treeBoundBox;
54 
55 /*---------------------------------------------------------------------------*\
56  Class OBJstream Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class OBJstream
60 :
61  public OFstream
62 {
63  // Private Data
64 
65  bool startOfLine_;
66 
67  label nVertices_;
68 
69 
70  // Private Member Functions
71 
72  void writeAndCheck(const char c);
73 
74 public:
75 
76  //- Declare type-name (with debug switch)
77  ClassName("OBJstream");
78 
79 
80  // Constructors
81 
82  //- Construct from pathname
83  explicit OBJstream
84  (
85  const fileName& pathname,
86  IOstreamOption streamOpt = IOstreamOption()
87  );
88 
89  //- Construct from pathname
91  (
92  const fileName& pathname,
93  streamFormat fmt,
95  compressionType comp = compressionType::UNCOMPRESSED
96  )
97  :
98  OBJstream(pathname, IOstreamOption(fmt, ver, comp))
99  {}
100 
101 
102  //- Destructor
103  ~OBJstream() = default;
104 
105 
106  // Member Functions
107 
108  // Access
109 
110  //- Return the number of vertices written
111  label nVertices() const
112  {
113  return nVertices_;
114  }
115 
116 
117  // Ostream implementation
118 
119  //- Inherit write from Ostream
120  using Ostream::write;
121 
122  //- Write character
123  virtual Ostream& write(const char c);
124 
125  //- Write character string
126  virtual Ostream& write(const char* str);
127 
128  //- Write word
129  virtual Ostream& write(const word& str);
130 
131  //- Write string
132  virtual Ostream& write(const string& str);
133 
134  //- Write std::string surrounded by quotes.
135  // Optional write without quotes.
136  virtual Ostream& writeQuoted
137  (
138  const std::string& str,
139  const bool quoted=true
140  );
141 
142 
143  // Direct write functionality
144 
145  //- Write point
146  Ostream& write(const point& pt);
147 
148  //- Write point and vector normal ('vn')
149  Ostream& write(const point& pt, const vector& n);
150 
151  //- Write edge as points and line
152  Ostream& write(const edge& e, const UList<point>& points);
153 
154  //- Write line
155  Ostream& write(const linePointRef& ln);
156 
157  //- Write line with points and vector normals ('vn')
158  Ostream& write
159  (
160  const linePointRef& ln,
161  const vector& n0,
162  const vector& n1
163  );
164 
165  //- Write triangle as points and lines/filled-polygon
166  Ostream& write(const triPointRef& f, const bool lines = true);
167 
168  //- Write face as points and lines/filled-polygon
169  Ostream& write
170  (
171  const face& f,
172  const UList<point>& points,
173  const bool lines = true
174  );
175 
176  //- Write patch faces as points and lines/filled-polygon
177  Ostream& write
178  (
179  const UList<face>& faces,
180  const pointField& points,
181  const bool lines = true
182  );
183 
184  //- Write edges as points and lines.
185  // Optionally eliminate unused points.
186  Ostream& write
187  (
188  const UList<edge>& edges,
189  const UList<point>& points,
190  const bool compact = false
191  );
192 
193  //- Write tree-bounding box as lines/filled-polygons
194  Ostream& write
195  (
196  const treeBoundBox& bb,
197  const bool lines = true
198  );
199 };
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #endif
209 
210 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::OBJstream::~OBJstream
~OBJstream()=default
Destructor.
Foam::OBJstream::ClassName
ClassName("OBJstream")
Declare type-name (with debug switch)
Foam::OBJstream
OFstream that keeps track of vertices.
Definition: OBJstream.H:58
Foam::IOstreamOption::IOstreamOption
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Definition: IOstreamOption.H:196
point.H
Foam::OBJstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OBJstream.C:108
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:87
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
face.H
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:168
triPointRef.H
Foam::OBJstream::write
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
OFstream.H
Foam::triangle
A triangle primitive used to calculate face normals and swept volumes.
Definition: triangle.H:62
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::Field< vector >
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
edge.H
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:87
Foam::OBJstream::nVertices
label nVertices() const
Return the number of vertices written.
Definition: OBJstream.H:110
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::line
A line primitive.
Definition: line.H:59
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:77
Foam::ln
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: MSwindows.C:915
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::OBJstream::OBJstream
OBJstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption())
Construct from pathname.
Definition: OBJstream.C:65