Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::OBJstream
29
30Description
31 An OFstream that keeps track of vertices and provides convenience
32 output methods for OBJ files.
33
34SourceFiles
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
50namespace Foam
51{
52
53// Forward Declarations
54class treeBoundBox;
56/*---------------------------------------------------------------------------*\
57 Class OBJstream Declaration
58\*---------------------------------------------------------------------------*/
59
60class 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
77public:
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)
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
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')
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
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
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.
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// ************************************************************************* //
label n
A simple container for options an IOstream can normally have.
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Default construct (ASCII, UNCOMPRESSED, currentVersion) or construct with format, compression.
streamFormat
Data format (ascii | binary | coherent).
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED).
@ UNCOMPRESSED
compression = false
OBJstream(const fileName &pathname, IOstreamOption::streamFormat fmt, IOstreamOption::compressionType cmp=IOstreamOption::UNCOMPRESSED)
Construct from pathname, format (uncompressed).
Definition OBJstream.H:97
label nVertices() const noexcept
Return the number of vertices written.
Definition OBJstream.H:120
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
~OBJstream()=default
Destructor.
Ostream & writeFace(const UList< point > &points, const bool lines=true)
Write face loop points with lines/filled-polygon.
Definition OBJstream.C:279
Ostream & writeLine(const point &p0, const point &p1)
Write line joining two points.
Definition OBJstream.C:234
Ostream & writeComment(const std::string &str)
Write comment (with '# ' prefix).
Definition OBJstream.C:133
ClassNameNoDebug("OBJstream")
Declare type-name (no debug switch).
OBJstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption())
Construct from pathname (ASCII, uncompressed).
Definition OBJstream.C:56
OFstream(std::nullptr_t)
Construct a null output file stream that behaves like /dev/null.
Definition OFstream.C:36
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true)=0
Write character/string content, with/without surrounding quotes.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
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:62
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
A class for handling file names.
Definition fileName.H:75
Standard boundBox with extra functionality for use in octree.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define ClassNameNoDebug(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:39
volScalarField & p
const volScalarField & p0
Definition EEqn.H:36
const pointField & points
Namespace for OpenFOAM.
line< point, const point & > linePointRef
A line using referred points.
Definition line.H:66
vector point
Point is a vector.
Definition point.H:37
const direction noexcept
Definition scalarImpl.H:265
triangle< point, const point & > triPointRef
A triangle using referred points.
Definition triangleFwd.H:46
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition POSIX.C:1239
runTime write()
labelList f(nPoints)
volScalarField & e