Developer Documentation
Loading...
Searching...
No Matches
OBJImporter.hh
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
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#pragma once
43
44#define TEXTUREINDEX "OriginalTexIndexMapping"
45
46//=== INCLUDES ================================================================
47
48
49// STL
50#include <vector>
51
52// OpenMesh
54#include <OpenMesh/Core/Geometry/VectorT.hh>
58
59
60#ifdef ENABLE_BSPLINECURVE_SUPPORT
62#endif
63
64#ifdef ENABLE_BSPLINESURFACE_SUPPORT
66#endif
67
68#include "Material.hh"
69
70//=== IMPLEMENTATION ==========================================================
71
72typedef int VertexHandle;
73typedef int FaceHandle;
74typedef std::vector<VertexHandle> VHandles;
75typedef std::vector<OpenMesh::VertexHandle> OMVHandles;
82
83
84
86{
87 public:
88
89 enum ObjectOptionsE
90 {
91 NONE = 0,
92 TRIMESH = 1,
93 POLYMESH = 1 << 1,
94 CURVE = 1 << 2,
95 SURFACE = 1 << 3,
96 NORMALS = 1 << 4,
97 TEXCOORDS = 1 << 5,
98 FACECOLOR = 1 << 6,
99 TEXTURE = 1 << 7,
100 FORCE_NOCOLOR = 1 << 8,
101 FORCE_NONORMALS = 1 << 9,
102 FORCE_NOTEXTURES = 1 << 10
103 };
104
105 typedef unsigned int ObjectOptions;
106
108 OBJImporter() : degreeU_(0),degreeV_(0),currentGroup_(0) {
109 // Add default group
110 addGroup("DefaultGroup");
111 }
112
114 ~OBJImporter();
115
117 VertexHandle addVertex(const Vec3d& _point);
118
120 Vec3d vertex(unsigned int _index);
121
123 int addTexCoord(const Vec2f& _coord);
124
126 int addNormal(const Vec3d& _normal);
127
129 void setDegreeU(int _degree);
130 void setDegreeV(int _degree);
131
133 int degreeU();
134 int degreeV();
135
137 void setObject( BaseObject* _object, int _groupId );
138
147 int currentGroup();
148
151
154
155#ifdef ENABLE_BSPLINECURVE_SUPPORT
156 BSplineCurve* currentCurve();
158 unsigned int numCurves() { return curvesMap_.size(); }
160 void setCurveGroupId(const unsigned int _count, const int _id);
162 int getCurveGroupId(const unsigned int _count);
164 void setCurveParentId(const int _curveGroup, const int _parentGroup);
166 int getCurveParentId(const int _curveGroup);
167#endif
168
169#ifdef ENABLE_BSPLINECURVE_SUPPORT
170 BSplineSurface* currentSurface();
172 unsigned int numSurfaces() { return surfacesMap_.size(); }
174 void setSurfaceGroupId(const unsigned int _count, const int _id);
176 int getSurfaceGroupId(const unsigned int _count);
178 void setSurfaceParentId(const int _surfaceGroup, const int _parentGroup);
180 int getSurfaceParentId(const int _surfaceGroup);
181#endif
182
184 void addUsedVertices(int _groupId);
185
187 void setVertexTexCoord(VertexHandle _vh, int _texCoordID);
188
190 void setNormal(int _index, int _normalID);
191
193 void addFace(const VHandles& _indices);
194
196 void addFace(const VHandles& _indices, const std::vector<int>& _face_texcoords);
197
198 private:
199 bool addFace(const VHandles& _indices, OpenMesh::FaceHandle &_outFH, std::vector< TriMesh::VertexHandle > &_outTriVertices, std::vector< PolyMesh::VertexHandle > &_outPolyVertices);
200 public:
201
203 void forceMeshType( ObjectOptions _meshType );
204
206 bool hasNormals(int _objectID);
207 bool hasTexture(int _objectID);
208 bool hasTextureCoords(int _objectID);
209 bool isTriangleMesh(int _objectID);
210 bool isPolyMesh(int _objectID);
211 bool isCurve(int _objectID);
212 bool isSurface(int _objectID);
213 bool isNone(int _objectID);
214
216 void setOption( ObjectOptionsE _option);
217
219 void setOption( ObjectOptionsE _option, int _groupId);
220
222 unsigned int n_vertices();
223 unsigned int n_normals();
224 unsigned int n_texCoords();
225
232 unsigned int groupCount();
233
235 BaseObject* object(int _groupId );
236
238 MaterialList& materials();
239
241 void addMaterial(std::string _materialName);
242
244 const std::vector<std::string> usedMaterials(unsigned int _objectID);
245 void useMaterial( std::string _materialName );
246
248 void useVertex(int _vertex_index);
249
251 QString path();
252 void setPath(QString _path);
253
256 void setObjectOptions(ObjectOptions _options);
257
259 bool noOptions();
260
262 bool hasOption( unsigned int _id, ObjectOptions _option );
263
265 void setObjectName(int _objectID, QString _name);
266
267 // Add a new group
268 int addGroup(const QString& _groupName);
269 int groupId(const QString& _groupName) const;
270 unsigned int numGroups() const { return groupNames_.size(); }
271 const QString groupName(const int _grpId) const;
272 void setGroupName(const int _grp, const QString& _name);
273
274 void setCurrentGroup(const int _current);
275 int currentGroup() const;
276
280 void finish();
281
282 private:
283
284 bool vertexListIsManifold(const std::vector<PolyMesh::VertexHandle>& _vertices) const;
285
286 // general data
287 std::vector< Vec3d > vertices_;
288 std::vector< Vec3d > normals_;
289 std::vector< Vec2f > texCoords_;
290
291 //stores half edge normals of the current face
292 std::map<TriMesh::VertexHandle,TriMesh::Normal> storedTriHENormals_;
293 std::map<TriMesh::VertexHandle,PolyMesh::Normal> storedPolyHENormals_;
294
295 int degreeU_;
296 int degreeV_;
297
298 MaterialList materials_;
299
300 QString path_;
301
302 std::vector<QString> groupNames_;
303 int currentGroup_;
304
305 // polyMesh data
306 std::vector<std::map< int, PolyMesh::VertexHandle > > vertexMapPoly_;
307
308 PolyMesh::FaceHandle addedFacePoly_;
309
310 // triMesh data
311 std::vector<std::map< int, TriMesh::VertexHandle > > vertexMapTri_;
312
313 std::vector<std::vector< TriMesh::FaceHandle > > addedFacesTri_;
314
315 //std::vector< BaseObject* > objects_;
316
317 //object data
318 std::vector<TriMeshObject*> triMeshes_;
319 std::vector<PolyMeshObject*> polyMeshes_;
320#ifdef ENABLE_BSPLINECURVE_SUPPORT
321 std::vector<BSplineCurveObject*> bSplineCurves_;
322#endif
323#ifdef ENABLE_BSPLINESURFACE_SUPPORT
324 std::vector<BSplineSurfaceObject*> bSplineSurfaces_;
325#endif
326
327 std::vector< ObjectOptions > objectOptions_;
328
329 // for each object a vector of materialNames
330 std::vector< std::vector< std::string > > usedMaterials_;
331
332 // for each object a vector of vertex indices
333 // this ensures that a vertex defined first gets a lower index
334 std::vector< std::map< int, VertexHandle > > usedVertices_;
335
336 // Store vertices of invalid faces due to non-manifold
337 // configurations.
338 std::vector< std::vector< OMVHandles > > invalidFaces_;
339
340#ifdef ENABLE_BSPLINECURVE_SUPPORT
342 std::map<unsigned int, int> curvesMap_;
344 std::map<int, int> curveParentGroupMap_;
345#endif
346
347#ifdef ENABLE_BSPLINESURFACE_SUPPORT
349 std::map<unsigned int, int> surfacesMap_;
351 std::map<int, int> surfaceParentGroupMap_;
352#endif
353
354};
355
unsigned int groupCount()
Number of groups currently stored in the importer.
Vec3d vertex(unsigned int _index)
get vertex with given index
void addMaterial(std::string _materialName)
Add a material.
void setDegreeV(int _degree)
set degree V direction
void setVertexTexCoord(VertexHandle _vh, int _texCoordID)
set vertex texture coordinate
unsigned int n_vertices()
Global Properties.
void useVertex(int _vertex_index)
used vertices
void setObjectOptions(ObjectOptions _options)
void addUsedVertices(int _groupId)
add all vertices that are used to the mesh (in correct order)
void addFace(const VHandles &_indices)
add a face with indices _indices refering to vertices
int addTexCoord(const Vec2f &_coord)
add texture coordinates
VertexHandle addVertex(const Vec3d &_point)
add a vertex with coordinate _point
int degreeU()
get current degree
void setDegreeU(int _degree)
set degree
OBJImporter()
Constructor.
bool noOptions()
Return true if the importer has no options stored.
QString path()
Path of the OBJ file.
void forceMeshType(ObjectOptions _meshType)
force all meshes to be opened with specific type
int addNormal(const Vec3d &_normal)
add a normal
void setNormal(int _index, int _normalID)
set vertex normal
bool hasOption(unsigned int _id, ObjectOptions _option)
check if object with given id has given option
BaseObject * object(int _groupId)
return object for the given group
void setObjectName(int _objectID, QString _name)
change the name of an object
TriMesh * currentTriMesh()
get a pointer to the active triMesh
void setOption(ObjectOptionsE _option)
Set Object Option.
void setObject(BaseObject *_object, int _groupId)
add an object
MaterialList & materials()
return all loaded materials
int degreeV()
get current degree
const std::vector< std::string > usedMaterials(unsigned int _objectID)
used materials
bool hasNormals(int _objectID)
Query Object Options.
int currentGroup()
Get the id of the current group.
PolyMesh * currentPolyMesh()
get a pointer to the active polyMesh
~OBJImporter()
base class needs virtual destructor
Kernel::FaceHandle FaceHandle
Scalar type.
Definition PolyMeshT.hh:139
Handle for a face entity.
Definition Handles.hh:142