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: 1285 $ *
45  * $Date: 2015-06-16 10:52:20 +0200 (Di, 16 Jun 2015) $ *
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 
64 #include <stdio.h>
65 #include <string>
66 #include <fstream>
67 #include <vector>
68 
69 #include <OpenMesh/Core/System/config.h>
70 #include <OpenMesh/Core/Utils/SingletonT.hh>
71 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh>
72 #include <OpenMesh/Core/IO/writer/BaseWriter.hh>
73 
74 
75 //== NAMESPACES ===============================================================
76 
77 
78 namespace OpenMesh {
79 namespace IO {
80 
81 
82 //=== IMPLEMENTATION ==========================================================
83 
84 
94 class OPENMESHDLLEXPORT _PLYWriter_ : public BaseWriter
95 {
96 public:
97 
98  _PLYWriter_();
99 
101  virtual ~_PLYWriter_() {};
102 
103  std::string get_description() const { return "PLY polygon file format"; }
104  std::string get_extensions() const { return "ply"; }
105 
106  bool write(const std::string&, BaseExporter&, Options, std::streamsize _precision = 6) const;
107 
108  bool write(std::ostream&, BaseExporter&, Options, std::streamsize _precision = 6) const;
109 
110  size_t binary_size(BaseExporter& _be, Options _opt) const;
111 
112  enum ValueType {
113  Unsupported = 0,
114  ValueTypeFLOAT32, ValueTypeFLOAT,
115  ValueTypeINT32, ValueTypeINT , ValueTypeUINT,
116  ValueTypeUCHAR, ValueTypeCHAR, ValueTypeUINT8,
117  ValueTypeUSHORT, ValueTypeSHORT,
118  ValueTypeDOUBLE
119  };
120 
121 private:
122  mutable Options options_;
123 
124  struct CustomProperty
125  {
126  ValueType type;
127  const BaseProperty* property;
128  CustomProperty(const BaseProperty* const _p):type(Unsupported),property(_p){}
129  };
130 
131  const char* nameOfType_[12];
132 
134  std::vector<CustomProperty> writeCustomTypeHeader(std::ostream& _out, BaseKernel::const_prop_iterator _begin, BaseKernel::const_prop_iterator _end) const;
135  void write_customProp_ascii(std::ostream& _our, const CustomProperty& _prop, size_t _index) const;
136 
137 protected:
138  void writeValue(ValueType _type, std::ostream& _out, int value) const;
139  void writeValue(ValueType _type, std::ostream& _out, unsigned int value) const;
140  void writeValue(ValueType _type, std::ostream& _out, float value) const;
141 
142  bool write_ascii(std::ostream& _out, BaseExporter&, Options) const;
143  bool write_binary(std::ostream& _out, BaseExporter&, Options) const;
145  void write_header(std::ostream& _out, BaseExporter& _be, Options& _opt, std::vector<CustomProperty>& _ovProps, std::vector<CustomProperty>& _ofProps) const;
146 };
147 
148 
149 //== TYPE DEFINITION ==========================================================
150 
151 
154 OPENMESHDLLEXPORT _PLYWriter_& PLYWriter();
155 
156 
157 //=============================================================================
158 } // namespace IO
159 } // namespace OpenMesh
160 //=============================================================================
161 #endif
162 //=============================================================================
virtual ~_PLYWriter_()
Destructor.
Definition: PLYWriter.hh:101
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
std::string get_extensions() const
Return file format&#39;s extension.
Definition: PLYWriter.hh:104
Implementation of the PLY format writer.
Definition: PLYWriter.hh:94
Set options for reader/writer modules.
Definition: Options.hh:95
_PLYWriter_ __PLYWriterInstance
Declare the single entity of the PLY writer.
Definition: PLYWriter.cc:76
Abstract class defining the basic interface of a dynamic property.
Definition: BaseProperty.hh:65
Base class for all writer modules.
Definition: BaseWriter.hh:88
std::string get_description() const
Return short description of the supported file format.
Definition: PLYWriter.hh:103
Base class for exporter modules.
Definition: BaseExporter.hh:89
size_t binary_size(const Mesh &_mesh, const std::string &_ext, Options _opt=Options::Default)
Get binary size of data.
Definition: MeshIO.hh:260

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