OpenMesh: OpenMesh/Core/IO/writer/PLYWriter.hh Source File

| OpenMesh

PLYWriter.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, 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 * $Revision$ *
45 * $Date$ *
46 * *
47 \*===========================================================================*/
48
49
50 //=============================================================================
51 //
52 // Implements a writer module for PLY files
53 //
54 //=============================================================================
55
56
57 #ifndef __PLYWRITER_HH__
58 #define __PLYWRITER_HH__
59
60
61 //=== INCLUDES ================================================================
62
63 #include <string>
64 #include <ostream>
65 #include <vector>
66
67 #include <OpenMesh/Core/System/config.h>
68 #include <OpenMesh/Core/Utils/SingletonT.hh>
69 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
70 #include <OpenMesh/Core/IO/writer/BaseWriter.hh>
71 #include <OpenMesh/Core/Utils/GenProg.hh>
72
73
74 //== NAMESPACES ===============================================================
75
76
77 namespace OpenMesh {
78 namespace IO {
79
80
81 //=== IMPLEMENTATION ==========================================================
82
83
93 class OPENMESHDLLEXPORT _PLYWriter_ : public BaseWriter
94 {
95 public:
96
97 _PLYWriter_();
98
100 virtual ~_PLYWriter_() {};
101
102 std::string get_description() const { return "PLY polygon file format"; }
103 std::string get_extensions() const { return "ply"; }
104
105 bool write(const std::string&, BaseExporter&, Options, std::streamsize _precision = 6) const;
106
107 bool write(std::ostream&, BaseExporter&, Options, std::streamsize _precision = 6) const;
108
109 size_t binary_size(BaseExporter& _be, Options _opt) const;
110
111 enum ValueType {
112 Unsupported = 0,
113 ValueTypeFLOAT32, ValueTypeFLOAT,
114 ValueTypeINT32, ValueTypeINT , ValueTypeUINT,
115 ValueTypeUCHAR, ValueTypeCHAR, ValueTypeUINT8,
116 ValueTypeUSHORT, ValueTypeSHORT,
117 ValueTypeDOUBLE
118 };
119
120 private:
121 mutable Options options_;
122
123 struct CustomProperty
124 {
125 ValueType type;
126 const BaseProperty* property;
127 CustomProperty(const BaseProperty* const _p):type(Unsupported),property(_p){}
128 };
129
130 const char* nameOfType_[12];
131
133 std::vector<CustomProperty> writeCustomTypeHeader(std::ostream& _out, BaseKernel::const_prop_iterator _begin, BaseKernel::const_prop_iterator _end) const;
134 template<bool binary>
135 void write_customProp(std::ostream& _our, const CustomProperty& _prop, size_t _index) const;
136 template<typename T>
137 void writeProxy(ValueType _type, std::ostream& _out, T _value, OpenMesh::GenProg::TrueType /*_binary*/) const
138 {
139 writeValue(_type, _out, _value);
140 }
141 template<typename T>
142 void writeProxy(ValueType _type, std::ostream& _out, T _value, OpenMesh::GenProg::FalseType /*_binary*/) const
143 {
144 _out << " " << _value;
145 }
146
147 protected:
148 void writeValue(ValueType _type, std::ostream& _out, signed char value) const;
149 void writeValue(ValueType _type, std::ostream& _out, unsigned char value) const;
150 void writeValue(ValueType _type, std::ostream& _out, short value) const;
151 void writeValue(ValueType _type, std::ostream& _out, unsigned short value) const;
152 void writeValue(ValueType _type, std::ostream& _out, int value) const;
153 void writeValue(ValueType _type, std::ostream& _out, unsigned int value) const;
154 void writeValue(ValueType _type, std::ostream& _out, float value) const;
155 void writeValue(ValueType _type, std::ostream& _out, double value) const;
156
157 bool write_ascii(std::ostream& _out, BaseExporter&, Options) const;
158 bool write_binary(std::ostream& _out, BaseExporter&, Options) const;
160 void write_header(std::ostream& _out, BaseExporter& _be, Options& _opt, std::vector<CustomProperty>& _ovProps, std::vector<CustomProperty>& _ofProps) const;
161 };
162
163
164 //== TYPE DEFINITION ==========================================================
165
166
168 extern _PLYWriter_ __PLYWriterInstance;
169 OPENMESHDLLEXPORT _PLYWriter_& PLYWriter();
170
171
172 //=============================================================================
173 } // namespace IO
174 } // namespace OpenMesh
175 //=============================================================================
176 #endif
177 //=============================================================================
OpenMesh::IO::__PLYWriterInstance
_PLYWriter_ __PLYWriterInstance
Declare the single entity of the PLY writer.
Definition: PLYWriter.cc:72
OpenMesh::IO::_PLYWriter_::get_extensions
std::string get_extensions() const
Return file format&#39;s extension.
Definition: PLYWriter.hh:103
OpenMesh::IO::binary_size
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:273
OpenMesh::IO::_PLYWriter_::get_description
std::string get_description() const
Return short description of the supported file format.
Definition: PLYWriter.hh:102
OpenMesh::IO::BaseWriter
Base class for all writer modules.
Definition: BaseWriter.hh:88
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
OpenMesh::IO::BaseExporter
Base class for exporter modules.
Definition: BaseExporter.hh:89
OpenMesh::IO::_PLYWriter_
Implementation of the PLY format writer.
Definition: PLYWriter.hh:93
OpenMesh::BaseProperty
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:65
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:95
OpenMesh::IO::_PLYWriter_::~_PLYWriter_
virtual ~_PLYWriter_()
Destructor.
Definition: PLYWriter.hh:100