Developer Documentation
BaseImporter.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 the baseclass for IOManager importer modules
48 //
49 //=============================================================================
50 
51 
52 #ifndef __BASEIMPORTER_HH__
53 #define __BASEIMPORTER_HH__
54 
55 
56 //=== INCLUDES ================================================================
57 
58 
59 // STL
60 #include <vector>
61 
62 // OpenMesh
64 #include <OpenMesh/Core/Geometry/VectorT.hh>
65 #include <OpenMesh/Core/Mesh/BaseKernel.hh>
66 
67 
68 //== NAMESPACES ===============================================================
69 
70 
71 namespace OpenMesh {
72 namespace IO {
73 
74 
75 //=== IMPLEMENTATION ==========================================================
76 
77 
83 class OPENMESHDLLEXPORT BaseImporter
84 {
85 public:
86 
87  // base class needs virtual destructor
88  virtual ~BaseImporter() {}
89 
90 
91  // add a vertex with coordinate \c _point
92  virtual VertexHandle add_vertex(const Vec3f& _point) = 0;
93 
94  // add a vertex without coordinate. Use set_point to set the position deferred
95  virtual VertexHandle add_vertex() = 0;
96 
97  // add an edge. Use set_next, set_vertex and set_face to set corresponding entities for halfedges
98  virtual HalfedgeHandle add_edge(VertexHandle _vh0, VertexHandle _vh1) = 0;
99 
100  // add a face with indices _indices refering to vertices
101  typedef std::vector<VertexHandle> VHandles;
102  virtual FaceHandle add_face(const VHandles& _indices) = 0;
103 
104  // add a face with incident halfedge
105  virtual FaceHandle add_face(HalfedgeHandle _heh) = 0;
106 
107  // add texture coordinates per face, _vh references the first texcoord
108  virtual void add_face_texcoords( FaceHandle _fh, VertexHandle _vh, const std::vector<Vec2f>& _face_texcoords) = 0;
109 
110  // add texture 3d coordinates per face, _vh references the first texcoord
111  virtual void add_face_texcoords( FaceHandle _fh, VertexHandle _vh, const std::vector<Vec3f>& _face_texcoords) = 0;
112 
113  // Set the texture index for a face
114  virtual void set_face_texindex( FaceHandle _fh, int _texId ) = 0;
115 
116  // Set coordinate of the given vertex. Use this function, if you created a vertex without coordinate
117  virtual void set_point(VertexHandle _vh, const Vec3f& _point) = 0;
118 
119  // Set outgoing halfedge for the given vertex.
120  virtual void set_halfedge(VertexHandle _vh, HalfedgeHandle _heh) = 0;
121 
122  // set vertex normal
123  virtual void set_normal(VertexHandle _vh, const Vec3f& _normal) = 0;
124 
125  // set vertex color
126  virtual void set_color(VertexHandle _vh, const Vec3uc& _color) = 0;
127 
128  // set vertex color
129  virtual void set_color(VertexHandle _vh, const Vec4uc& _color) = 0;
130 
131  // set vertex color
132  virtual void set_color(VertexHandle _vh, const Vec3f& _color) = 0;
133 
134  // set vertex color
135  virtual void set_color(VertexHandle _vh, const Vec4f& _color) = 0;
136 
137  // set vertex texture coordinate
138  virtual void set_texcoord(VertexHandle _vh, const Vec2f& _texcoord) = 0;
139 
140  // set vertex status
141  virtual void set_status(VertexHandle _vh, const OpenMesh::Attributes::StatusInfo& _status) = 0;
142 
143  // set next halfedge handle
144  virtual void set_next(HalfedgeHandle _heh, HalfedgeHandle _next) = 0;
145 
146  // set incident face handle for given halfedge
147  virtual void set_face(HalfedgeHandle _heh, FaceHandle _fh) = 0;
148 
149  // set vertex texture coordinate
150  virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord) = 0;
151 
152  // set 3d vertex texture coordinate
153  virtual void set_texcoord(VertexHandle _vh, const Vec3f& _texcoord) = 0;
154 
155  // set 3d vertex texture coordinate
156  virtual void set_texcoord(HalfedgeHandle _heh, const Vec3f& _texcoord) = 0;
157 
158  // set halfedge status
159  virtual void set_status(HalfedgeHandle _heh, const OpenMesh::Attributes::StatusInfo& _status) = 0;
160 
161  // set edge color
162  virtual void set_color(EdgeHandle _eh, const Vec3uc& _color) = 0;
163 
164  // set edge color
165  virtual void set_color(EdgeHandle _eh, const Vec4uc& _color) = 0;
166 
167  // set edge color
168  virtual void set_color(EdgeHandle _eh, const Vec3f& _color) = 0;
169 
170  // set edge color
171  virtual void set_color(EdgeHandle _eh, const Vec4f& _color) = 0;
172 
173  // set edge status
174  virtual void set_status(EdgeHandle _eh, const OpenMesh::Attributes::StatusInfo& _status) = 0;
175 
176  // set face normal
177  virtual void set_normal(FaceHandle _fh, const Vec3f& _normal) = 0;
178 
179  // set face color
180  virtual void set_color(FaceHandle _fh, const Vec3uc& _color) = 0;
181 
182  // set face color
183  virtual void set_color(FaceHandle _fh, const Vec4uc& _color) = 0;
184 
185  // set face color
186  virtual void set_color(FaceHandle _fh, const Vec3f& _color) = 0;
187 
188  // set face color
189  virtual void set_color(FaceHandle _fh, const Vec4f& _color) = 0;
190 
191  // set face status
192  virtual void set_status(FaceHandle _fh, const OpenMesh::Attributes::StatusInfo& _status) = 0;
193 
194  // Store a property in the mesh mapping from an int to a texture file
195  // Use set_face_texindex to set the index for each face
196  virtual void add_texture_information( int _id , std::string _name ) = 0;
197 
198  // get reference to base kernel
199  virtual BaseKernel* kernel() { return 0; }
200 
201  virtual bool is_triangle_mesh() const { return false; }
202 
203  // reserve mem for elements
204  virtual void reserve( unsigned int /* nV */,
205  unsigned int /* nE */,
206  unsigned int /* nF */) {}
207 
208  // query number of faces, vertices, normals, texcoords
209  virtual size_t n_vertices() const = 0;
210  virtual size_t n_faces() const = 0;
211  virtual size_t n_edges() const = 0;
212 
213 
214  // pre-processing
215  virtual void prepare() {}
216 
217  // post-processing
218  virtual void finish() {}
219 };
220 
221 
222 //=============================================================================
223 } // namespace IO
224 } // namespace OpenMesh
225 //=============================================================================
226 #endif
227 //=============================================================================
Handle for a vertex entity.
Definition: Handles.hh:120
Handle for a halfedge entity.
Definition: Handles.hh:127
Handle for a face entity.
Definition: Handles.hh:141
Handle for a edge entity.
Definition: Handles.hh:134