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