STLCore.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) 2016-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::fileFormats::STLCore
28
29Description
30 Core routines used when reading/writing STL files.
31
32SourceFiles
33 STLCore.C
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef STLCore_H
38#define STLCore_H
39
40#include "STLpoint.H"
41#include "STLtriangle.H"
42#include <memory>
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46namespace Foam
47{
48namespace fileFormats
49{
50
51/*---------------------------------------------------------------------------*\
52 Class fileFormats::STLCore Declaration
53\*---------------------------------------------------------------------------*/
55class STLCore
56{
57public:
58
59 // Public Data Types
60
61 //- Enumeration for the format of data in the stream
62 enum STLFormat
63 {
65 BINARY,
67 };
68
69
70protected:
71
72 // Protected Member Functions
73
74 //- Detect 'stlb' extension as binary when format = UNKNOWN.
75 // Otherwise test if format == BINARY.
76 static bool isBinaryName
77 (
78 const fileName& filename,
79 const STLFormat format
80 );
81
82
83 //- Check contents to detect if the file is a binary STL.
84 // Return the estimated number of triangles or 0 on error.
85 static int detectBinaryHeader(const fileName& filename);
86
87
88 //- Read STL binary file header.
89 // Return the opened file stream and estimated number of triangles.
90 // The stream is invalid and number of triangles is 0 on error.
91 static std::unique_ptr<std::istream>
93 (
94 const fileName& filename,
95 label& nTrisEstimated
96 );
97
98 //- Write STL binary file and number of triangles to stream
99 static void writeBinaryHeader(ostream& os, uint32_t nTris);
100
101
102 // Constructors
103
104 //- Default construct
105 STLCore() = default;
106};
107
108
109// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110
111} // End namespace fileFormats
112} // End namespace Foam
113
114// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
115
116#endif
117
118// ************************************************************************* //
Core routines used when reading/writing STL files.
Definition: STLCore.H:55
static bool isBinaryName(const fileName &filename, const STLFormat format)
Detect 'stlb' extension as binary when format = UNKNOWN.
Definition: STLCore.C:67
STLCore()=default
Default construct.
static int detectBinaryHeader(const fileName &filename)
Check contents to detect if the file is a binary STL.
Definition: STLCore.C:88
static void writeBinaryHeader(ostream &os, uint32_t nTris)
Write STL binary file and number of triangles to stream.
Definition: STLCore.C:227
static std::unique_ptr< std::istream > readBinaryHeader(const fileName &filename, label &nTrisEstimated)
Read STL binary file header.
Definition: STLCore.C:148
STLFormat
Enumeration for the format of data in the stream.
Definition: STLCore.H:62
@ UNKNOWN
Detect based on (input) content or (output) extension.
Definition: STLCore.H:65
A class for handling file names.
Definition: fileName.H:76
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
word format(conversionProperties.get< word >("format"))