OpenMesh
BaseWriter.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2025, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43
44
45//=============================================================================
46//
47// Implements the baseclass for IOManager writer modules
48//
49//=============================================================================
50
51
52#ifndef __BASEWRITER_HH__
53#define __BASEWRITER_HH__
54
55
56//=== INCLUDES ================================================================
57
58
59// STD C++
60#include <iosfwd>
61#include <string>
62
63// OpenMesh
64#include <OpenMesh/Core/System/config.h>
65#include <OpenMesh/Core/IO/Options.hh>
66#include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
67
68
69//== NAMESPACES ===============================================================
70
71
72namespace OpenMesh {
73namespace IO {
74
75
76//=== IMPLEMENTATION ==========================================================
77
78
83class OPENMESHDLLEXPORT BaseWriter
84{
85public:
86
87 typedef unsigned int Option;
88
90 virtual ~BaseWriter() {};
91
93 virtual std::string get_description() const = 0;
94
96 virtual std::string get_extensions() const = 0;
97
103 virtual bool can_u_write(const std::string& _filename) const;
104
111 virtual bool write(const std::string& _filename,
112 BaseExporter& _be,
113 const Options& _writeOptions,
114 std::streamsize _precision = 6) const = 0;
115
122 virtual bool write(std::ostream& _os,
123 BaseExporter& _be,
124 const Options& _writeOptions,
125 std::streamsize _precision = 6) const = 0;
126
128 virtual size_t binary_size(BaseExporter&, const Options&) const { return 0; }
129
130
131
132protected:
133
134 bool check(BaseExporter& _be, const Options& _writeOptions) const
135 {
136 // Check for all Options. When we want to write them (_opt.check() ) , they have to be available ( has_ )
137 // Converts to not A (write them) or B (available)
138 return ( !_writeOptions.check(Options::VertexNormal ) || _be.has_vertex_normals())
139 && ( !_writeOptions.check(Options::VertexTexCoord)|| _be.has_vertex_texcoords())
140 && ( !_writeOptions.check(Options::VertexColor) || _be.has_vertex_colors())
141 && ( !_writeOptions.check(Options::FaceNormal) || _be.has_face_normals())
142 && ( !_writeOptions.check(Options::FaceColor) || _be.has_face_colors());
143 }
144};
145
146
147//=============================================================================
148} // namespace IO
149} // namespace OpenMesh
150//=============================================================================
151#endif
152//=============================================================================
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Definition: mconvert.cc:103
Base class for exporter modules.
Definition: BaseExporter.hh:85
Set options for reader/writer modules.
Definition: Options.hh:92
@ FaceNormal
Has (r) / store (w) face normals.
Definition: Options.hh:109
@ FaceColor
Has (r) / store (w) face colors.
Definition: Options.hh:110
@ VertexNormal
Has (r) / store (w) vertex normals.
Definition: Options.hh:105
@ VertexTexCoord
Has (r) / store (w) texture coordinates.
Definition: Options.hh:107
@ VertexColor
Has (r) / store (w) vertex colors.
Definition: Options.hh:106
Base class for all writer modules.
Definition: BaseWriter.hh:84
virtual bool write(std::ostream &_os, BaseExporter &_be, const Options &_writeOptions, std::streamsize _precision=6) const =0
Write to a std::ostream.
virtual std::string get_extensions() const =0
Return file format's extension.
virtual bool write(const std::string &_filename, BaseExporter &_be, const Options &_writeOptions, std::streamsize _precision=6) const =0
Write to a file.
virtual ~BaseWriter()
Destructor.
Definition: BaseWriter.hh:90
virtual size_t binary_size(BaseExporter &, const Options &) const
Returns expected size of file if binary format is supported else 0.
Definition: BaseWriter.hh:128
virtual std::string get_description() const =0
Return short description of the supported file format.

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .