Developer Documentation

OFFImporter.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
43
44
45 #ifndef OFFIMPORTER_HH
46 #define OFFIMPORTER_HH
47
48
49 //=== INCLUDES ================================================================
50
51
52 // STL
53 #include <vector>
54
55 // OpenMesh
56 #include <OpenFlipper/common/GlobalDefines.hh>
57 #include <OpenMesh/Core/Geometry/VectorT.hh>
58 #include <ObjectTypes/PolyMesh/PolyMesh.hh>
59 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
60 #include <OpenFlipper/common/BaseObject.hh>
61
62 //=== IMPLEMENTATION ==========================================================
63
64 typedef int VertexHandle;
65 typedef int FaceHandle;
66 typedef std::vector<VertexHandle> VHandles;
67 typedef std::vector<OpenMesh::VertexHandle> OMVHandles;
68 typedef OpenMesh::Vec4f Vec4f;
69 typedef OpenMesh::Vec3f Vec3f;
70 typedef OpenMesh::Vec2f Vec2f;
71 typedef OpenMesh::Vec4uc Vec4uc;
72 typedef OpenMesh::Vec3uc Vec3uc;
73
74
75 class OFFImporter
76 {
77 public:
78
79 enum ObjectOptionsE
80 {
81 NONE = 0,
82 BINARY = 1,
83 TRIMESH = 1 << 1,
84 POLYMESH = 1 << 2,
85 VERTEXNORMAL = 1 << 3,
86 VERTEXTEXCOORDS = 1 << 4,
87 VERTEXCOLOR = 1 << 5,
88 FACECOLOR = 1 << 6,
89 COLORALPHA = 1 << 7,
90 FORCE_NOCOLOR = 1 << 8,
91 FORCE_NONORMALS = 1 << 9,
92 FORCE_NOTEXTURES = 1 << 10
93 };
94
95 typedef uint ObjectOptions;
96
98 OFFImporter();
99
101 ~OFFImporter();
102
104 void addObject( BaseObject* _object );
105
106 unsigned int maxFaceValence() const { return maxFaceValence_; }
107
108 void maxFaceValence(unsigned int _maxValence) { maxFaceValence_ = _maxValence; }
109
111 VertexHandle addVertex(const Vec3f& _point);
112
114 Vec3f vertex(uint _index);
115
117 int addTexCoord(const Vec2f& _coord);
118
120 int addColor(const Vec4f& _color);
121
123 int addNormal(const Vec3f& _normal);
124
126 PolyMesh* polyMesh();
127
129 TriMesh* triMesh();
130
132 void setVertexTexCoord(VertexHandle _vh, int _texCoordID);
133
135 void setNormal(VertexHandle _vh, int _normalID);
136
138 void setVertexColor(VertexHandle _vh, int _colorIndex);
139
141 void setFaceColor(FaceHandle _fh, int _colorIndex);
142
144 int addFace(const VHandles& _indices);
145
147 bool hasVertexNormals();
148 bool hasTextureCoords();
149 bool hasVertexColors();
150 bool hasFaceColors();
151 bool isTriangleMesh();
152 bool isPolyMesh();
153 bool isBinary();
154
156 uint n_vertices();
157 uint n_normals();
158 uint n_texCoords();
159
160 // Reserve memory for all entity types
161 void reserve(unsigned int _nv, unsigned int _ne, unsigned int _nf);
162
164 QString path();
165 void setPath(QString _path);
166
169 void setObjectOptions(ObjectOptions _options);
170
172 void addOption(ObjectOptionsE _option);
173
175 void removeOption(ObjectOptionsE _option);
176
178 bool hasOption(ObjectOptionsE _option);
179
181 ObjectOptions& objectOptions();
182
184 void setObjectName(QString _name);
185
187 BaseObject* getObject();
188
192 void finish();
193
194 private:
195
196 // general data
197 std::vector< Vec3f > vertices_;
198 std::vector< Vec3f > normals_;
199 std::vector< Vec2f > texCoords_;
200 std::vector< Vec4f > colors_;
201
202 // file path
203 QString path_;
204
205 // polyMesh data
206 std::map< int, PolyMesh::VertexHandle > vertexMapPoly_;
207
208 std::vector< PolyMesh::FaceHandle > faceMapPoly_;
209
210 PolyMesh* polyMesh_;
211
212 // triMesh data
213 std::map< int, TriMesh::VertexHandle > vertexMapTri_;
214
215 std::vector< TriMesh::FaceHandle > faceMapTri_;
216
217 TriMesh* triMesh_;
218
219 //object data
220 BaseObject* object_;
221 ObjectOptions objectOptions_;
222
223 // Store invalid face vertex handles
224 std::vector<OMVHandles> invalidFaces_;
225
226 // Keep track of max face valence
227 unsigned int maxFaceValence_;
228 };
229
230 //=============================================================================
231 #endif // OFFIMPORTER_HH
232 //=============================================================================
OFFImporter::OFFImporter
OFFImporter()
constructor
Definition: OFFImporter.cc:56
OFFImporter::triMesh
TriMesh * triMesh()
get a pointer to the active triMesh
Definition: OFFImporter.cc:141
OFFImporter::finish
void finish()
Definition: OFFImporter.cc:329
TriangleMesh.hh
OFFImporter::vertex
Vec3f vertex(uint _index)
get vertex with given index
Definition: OFFImporter.cc:93
GlobalDefines.hh
OFFImporter::getObject
BaseObject * getObject()
get BaseObject data of object
Definition: OFFImporter.cc:503
OFFImporter::hasVertexNormals
bool hasVertexNormals()
Query Object Options.
Definition: OFFImporter.cc:436
OFFImporter::setObjectOptions
void setObjectOptions(ObjectOptions _options)
Definition: OFFImporter.cc:522
OFFImporter::setVertexTexCoord
void setVertexTexCoord(VertexHandle _vh, int _texCoordID)
set vertex texture coordinate
Definition: OFFImporter.cc:151
OFFImporter::addNormal
int addNormal(const Vec3f &_normal)
add a normal
Definition: OFFImporter.cc:113
OFFImporter::hasOption
bool hasOption(ObjectOptionsE _option)
test if object has a certain option
Definition: OFFImporter.cc:461
BaseObject.hh
OFFImporter::polyMesh
PolyMesh * polyMesh()
get a pointer to the active polyMesh
Definition: OFFImporter.cc:131
OFFImporter::addObject
void addObject(BaseObject *_object)
add initial object
Definition: OFFImporter.cc:66
OFFImporter::setNormal
void setNormal(VertexHandle _vh, int _normalID)
set vertex normal
Definition: OFFImporter.cc:196
OFFImporter::path
QString path()
Path of the OFF file.
Definition: OFFImporter.cc:510
OFFImporter::~OFFImporter
~OFFImporter()
base class needs virtual destructor
Definition: OFFImporter.cc:49
OFFImporter::setVertexColor
void setVertexColor(VertexHandle _vh, int _colorIndex)
set vertex color
Definition: OFFImporter.cc:555
OFFImporter
Definition: OFFImporter.hh:75
OFFImporter::addTexCoord
int addTexCoord(const Vec2f &_coord)
add texture coordinates
Definition: OFFImporter.cc:104
OFFImporter::setObjectName
void setObjectName(QString _name)
change the name of an object
Definition: OFFImporter.cc:546
OFFImporter::addVertex
VertexHandle addVertex(const Vec3f &_point)
add a vertex with coordinate _point
Definition: OFFImporter.cc:236
BaseObject
Definition: BaseObject.hh:82
OpenMesh::VectorT< float, 4 >
OFFImporter::addColor
int addColor(const Vec4f &_color)
add a color
Definition: OFFImporter.cc:122
OFFImporter::addOption
void addOption(ObjectOptionsE _option)
add an option
Definition: OFFImporter.cc:528
OFFImporter::addFace
int addFace(const VHandles &_indices)
add a face with indices _indices refering to vertices
Definition: OFFImporter.cc:261
OFFImporter::objectOptions
ObjectOptions & objectOptions()
get Object Options
Definition: OFFImporter.cc:540
OFFImporter::removeOption
void removeOption(ObjectOptionsE _option)
remove an option
Definition: OFFImporter.cc:534
OFFImporter::n_vertices
uint n_vertices()
Global Properties.
Definition: OFFImporter.cc:467
PolyMesh.hh
OFFImporter::setFaceColor
void setFaceColor(FaceHandle _fh, int _colorIndex)
set face color
Definition: OFFImporter.cc:595