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-2023 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  An OFstream that keeps track of vertices and provides convenience
32  output methods for OBJ files.
33 
34 SourceFiles
35  OBJstream.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_OBJstream_H
40 #define Foam_OBJstream_H
41 
42 #include "OFstream.H"
43 #include "point.H"
44 #include "edge.H"
45 #include "face.H"
46 #include "triangle.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 class treeBoundBox;
55 
56 /*---------------------------------------------------------------------------*\
57  Class OBJstream Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 class OBJstream
61 :
62  public OFstream
63 {
64  // Private Data
65 
66  bool startOfLine_;
67 
68  label nVertices_;
69 
70 
71  // Private Member Functions
72 
73  //- State engine to count number of vertices.
74  //- Triggered on newline and 'v' (vertex).
75  inline void vertex_state(const char c);
76 
77 public:
78 
79  //- Declare type-name (no debug switch)
80  ClassNameNoDebug("OBJstream");
81 
82 
83  // Constructors
84 
85  //- Construct from pathname (ASCII, uncompressed)
86  explicit OBJstream
87  (
88  const fileName& pathname,
89  IOstreamOption streamOpt = IOstreamOption()
90  );
91 
92  //- Construct from pathname, format (uncompressed)
93  OBJstream
94  (
95  const fileName& pathname,
98  )
99  :
100  OBJstream(pathname, IOstreamOption(fmt, cmp))
101  {}
102 
103 
104  //- Destructor
105  ~OBJstream() = default;
106 
107 
108  // Member Functions
109 
110  // Access
111 
112  //- Return the number of vertices written
113  label nVertices() const noexcept { return nVertices_; }
114 
115 
116  // Write Functions
117 
118  //- Inherit write methods from OFstream
119  using OFstream::write;
121 
122  //- Write character
123  virtual Ostream& write(const char c) override;
124 
125  //- Write character/string content, with/without surrounding quotes
126  virtual Ostream& writeQuoted
127  (
128  const char* str,
129  std::streamsize len,
130  const bool quoted=true
131  ) override;
132 
133  //- Write character string
134  virtual Ostream& write(const char* str) override;
135 
136  //- Write word
137  virtual Ostream& write(const word& str) override;
138 
139  //- Write string
140  virtual Ostream& write(const std::string& str) override;
141 
142 
143  // Direct write functionality
144 
145  //- Write comment (with '# ' prefix)
146  Ostream& writeComment(const std::string& str);
147 
148  //- Write point (vertex)
149  Ostream& write(const point& p);
150 
151  //- Write point and vector normal ('vn')
152  Ostream& write(const point& p, const vector& n);
153 
154  //- Write multiple points
155  Ostream& write(const UList<point>& points);
156 
157  //- Write edge as points with line
158  Ostream& write(const edge& e, const UList<point>& points);
159 
160  //- Write line
161  Ostream& write(const linePointRef& ln);
162 
163  //- Write line with points and vector normals ('vn')
164  Ostream& write
165  (
166  const linePointRef& ln,
167  const vector& n0,
168  const vector& n1
169  );
170 
171  //- Write line joining two points
172  Ostream& writeLine(const point& p0, const point& p1);
173 
174  //- Write triangle as points with lines/filled-polygon
175  Ostream& write(const triPointRef& f, const bool lines = true);
176 
177  //- Write face loop points with lines/filled-polygon
179  (
180  const UList<point>& points,
181  const bool lines = true
182  );
183 
184  //- Write face as points with lines/filled-polygon
185  Ostream& write
186  (
187  const face& f,
188  const UList<point>& points,
189  const bool lines = true
190  );
191 
192  //- Write patch faces as points with lines/filled-polygon
193  Ostream& write
194  (
195  const UList<face>& faces,
196  const pointField& points,
197  const bool lines = true
198  );
199 
200  //- Write edges as points with lines.
201  // Optionally eliminate unused points.
202  Ostream& write
203  (
204  const UList<edge>& edges,
205  const UList<point>& points,
206  const bool compact = false
207  );
208 
209  //- Write tree-bounding box with lines/filled-polygons
210  Ostream& write(const treeBoundBox& bb, const bool lines = true);
211 };
212 
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 } // End namespace Foam
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #endif
221 
222 // ************************************************************************* //
Ostream & writeFace(const UList< point > &points, const bool lines=true)
Write face loop points with lines/filled-polygon.
Definition: OBJstream.C:279
ClassNameNoDebug("OBJstream")
Declare type-name (no debug switch)
A triangle primitive used to calculate face normals and swept volumes. Uses referred points...
Definition: triangle.H:217
A line primitive.
Definition: line.H:52
A class for handling file names.
Definition: fileName.H:72
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
virtual Ostream & write(const char c) override
Write character.
Definition: OBJstream.C:69
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true) override
Write character/string content, with/without surrounding quotes.
Definition: OSstream.C:101
OBJstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption())
Construct from pathname (ASCII, uncompressed)
Definition: OBJstream.C:56
Output to file stream, using an OSstream.
Definition: OFstream.H:49
A simple container for options an IOstream can normally have.
label nVertices() const noexcept
Return the number of vertices written.
Definition: OBJstream.H:120
~OBJstream()=default
Destructor.
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Default construct (ASCII, UNCOMPRESSED, currentVersion) or construct with format, compression...
Ostream & writeComment(const std::string &str)
Write comment (with &#39;# &#39; prefix)
Definition: OBJstream.C:133
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
const pointField & points
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition: edge.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true) override
Write character/string content, with/without surrounding quotes.
Definition: OBJstream.C:78
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:105
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:1237
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
virtual bool write(const token &tok) override
Write token to stream or otherwise handle it.
Definition: OSstream.C:29
Ostream & writeLine(const point &p0, const point &p1)
Write line joining two points.
Definition: OBJstream.C:234
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
An OFstream that keeps track of vertices and provides convenience output methods for OBJ files...
Definition: OBJstream.H:55
labelList f(nPoints)
const dimensionedScalar c
Speed of light in a vacuum.
streamFormat
Data format (ascii | binary)
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:90
label n
volScalarField & p
const volScalarField & p0
Definition: EEqn.H:36
Namespace for OpenFOAM.