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

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .