44 #include "OFFImporter.hh" 73 polyMesh_ = polyMeshObj->
mesh();
75 objectOptions_ |= POLYMESH;
76 objectOptions_ &= ~TRIMESH;
78 }
else if ( triMeshObj ){
80 triMesh_ = triMeshObj->
mesh();
82 objectOptions_ |= TRIMESH;
83 objectOptions_ &= ~POLYMESH;
86 std::cerr <<
"Error: Cannot add object. Type is unknown!" << std::endl;
95 if ( vertices_.size() > _index )
96 return vertices_[ _index ];
105 texCoords_.push_back( _coord );
107 return texCoords_.size()-1;
114 normals_.push_back( _normal );
116 return normals_.size()-1;
123 colors_.push_back( _color );
125 return colors_.size()-1;
153 if ( isTriangleMesh() ){
158 if ( _texCoordID < (
int) texCoords_.size() ){
161 if ( !
triMesh()->has_vertex_texcoords2D() )
162 triMesh()->request_vertex_texcoords2D();
164 if ( vertexMapTri_.find( _vh ) != vertexMapTri_.end() )
165 triMesh()->set_texcoord2D( vertexMapTri_[_vh], texCoords_[ _texCoordID ] );
166 objectOptions_ |= VERTEXTEXCOORDS;
169 std::cerr <<
"Error: TexCoord ID too large" << std::endl;
172 }
else if ( isPolyMesh() ){
177 if ( _texCoordID < (
int) texCoords_.size() ){
180 if ( !
polyMesh()->has_vertex_texcoords2D() )
181 polyMesh()->request_vertex_texcoords2D();
183 if ( vertexMapPoly_.find( _vh ) != vertexMapPoly_.end() )
184 polyMesh()->set_texcoord2D( vertexMapPoly_[_vh], texCoords_[ _texCoordID ] );
185 objectOptions_ |= VERTEXTEXCOORDS;
188 std::cerr <<
"Error: TexCoord ID too large" << std::endl;
198 if ( isTriangleMesh() ){
203 if ( _normalID < (
int) normals_.size() ){
205 if ( vertexMapTri_.find( _vh ) != vertexMapTri_.end() ){
207 objectOptions_ |= VERTEXNORMAL;
211 std::cerr <<
"Error: normal ID too large" << std::endl;
214 }
else if ( isPolyMesh() ){
219 if ( _normalID < (
int) normals_.size() ){
221 if ( vertexMapPoly_.find( _vh ) != vertexMapPoly_.end() ){
223 objectOptions_ |= VERTEXNORMAL;
227 std::cerr <<
"Error: normal ID too large" << std::endl;
238 vertices_.push_back( _point );
240 int id = vertices_.size()-1;
242 if ( isTriangleMesh() ){
245 if ( !
triMesh() )
return false;
248 }
else if ( isPolyMesh() ){
265 if ( isTriangleMesh() ){
270 std::vector< TriMesh::VertexHandle > vertices;
272 for (uint i=0; i < _indices.size(); i++){
274 if ( vertexMapTri_.find( _indices[i] ) != vertexMapTri_.end() ){
276 vertices.push_back( vertexMapTri_[ _indices[i] ] );
279 std::cerr <<
"Error: Cannot add face. Undefined index (" << _indices[i] <<
")" << std::endl;
284 TriMesh::FaceHandle fh =
triMesh()->add_face( vertices );
287 faceMapTri_.push_back( fh );
288 faceIndex = faceMapTri_.size()-1;
291 invalidFaces_.push_back( vertices );
294 }
else if ( isPolyMesh() ){
299 std::vector< PolyMesh::VertexHandle > vertices;
301 for (uint i=0; i < _indices.size(); i++){
303 if ( vertexMapPoly_.find( _indices[i] ) != vertexMapPoly_.end() ){
305 vertices.push_back( vertexMapPoly_[ _indices[i] ] );
308 std::cerr <<
"Error: Cannot add face. Undefined index (" << _indices[i] <<
")" << std::endl;
313 PolyMesh::FaceHandle fh =
polyMesh()->add_face( vertices );
316 faceMapPoly_.push_back(fh);
317 faceIndex = faceMapPoly_.size()-1;
320 invalidFaces_.push_back( vertices );
331 if(invalidFaces_.empty())
return;
333 if ( isTriangleMesh() ) {
335 for(std::vector<OMVHandles>::iterator it = invalidFaces_.begin();
336 it != invalidFaces_.end(); ++it) {
338 OMVHandles& vhandles = *it;
341 for (
unsigned int j = 0; j < vhandles.size(); ++j)
344 vhandles[j] =
triMesh()->add_vertex(p);
349 if (
triMesh()->has_vertex_status()) {
350 triMesh()->status(vhandles[j]).set_fixed_nonmanifold(
true);
358 if (
triMesh()->has_face_status())
359 triMesh()->status(fh).set_fixed_nonmanifold(
true);
362 if (
triMesh()->has_edge_status()) {
364 for(; fe_it.is_valid(); ++fe_it) {
365 triMesh()->status(*fe_it).set_fixed_nonmanifold(
true);
369 faceMapTri_.push_back(fh);
372 }
else if ( isPolyMesh() ) {
374 for(std::vector<OMVHandles>::iterator it = invalidFaces_.begin();
375 it != invalidFaces_.end(); ++it) {
377 OMVHandles& vhandles = *it;
380 for (
unsigned int j = 0; j < vhandles.size(); ++j)
383 vhandles[j] =
polyMesh()->add_vertex(p);
388 if (
polyMesh()->has_vertex_status()) {
389 polyMesh()->status(vhandles[j]).set_fixed_nonmanifold(
true);
398 polyMesh()->status(fh).set_fixed_nonmanifold(
true);
401 if (
polyMesh()->has_edge_status()) {
403 for(; fe_it.is_valid(); ++fe_it) {
404 polyMesh()->status(*fe_it).set_fixed_nonmanifold(
true);
408 faceMapPoly_.push_back(fh);
413 invalidFaces_.clear();
418 bool OFFImporter::isTriangleMesh(){
419 return objectOptions_ & TRIMESH;
424 bool OFFImporter::isPolyMesh(){
425 return objectOptions_ & POLYMESH;
430 bool OFFImporter::isBinary(){
431 return objectOptions_ & BINARY;
438 return objectOptions_ & VERTEXNORMAL;
443 bool OFFImporter::hasTextureCoords(){
444 return objectOptions_ & VERTEXTEXCOORDS;
449 bool OFFImporter::hasVertexColors() {
450 return objectOptions_ & VERTEXCOLOR;
455 bool OFFImporter::hasFaceColors() {
456 return objectOptions_ & FACECOLOR;
462 return objectOptions_ & _option;
468 return vertices_.size();
473 uint OFFImporter::n_normals(){
474 return normals_.size();
479 uint OFFImporter::n_texCoords(){
480 return texCoords_.size();
485 void OFFImporter::reserve(
unsigned int _nv,
unsigned int _ne,
unsigned int _nf) {
487 vertices_.reserve(_nv);
488 normals_.reserve(_nv);
489 texCoords_.reserve(_nv);
490 colors_.reserve(_nv);
492 if(isPolyMesh() && polyMesh_ != 0) {
493 polyMesh_->reserve(_nv, _ne, _nf);
496 if(isTriangleMesh() && triMesh_ != 0) {
497 triMesh_->reserve(_nv, _ne, _nf);
516 void OFFImporter::setPath(QString _path){
523 objectOptions_ = _options;
529 objectOptions_ |= _option;
535 if(objectOptions_ & _option) objectOptions_ -= _option;
541 return objectOptions_;
557 if ( isTriangleMesh() ){
562 if ( _colorIndex < (
int) colors_.size() ){
564 if ( vertexMapTri_.find( _vh ) != vertexMapTri_.end() ){
565 triMesh()->set_color( vertexMapTri_[_vh], colors_[_colorIndex] );
566 objectOptions_ |= VERTEXCOLOR;
570 std::cerr <<
"Error: Color ID too large" << std::endl;
573 }
else if ( isPolyMesh() ){
578 if ( _colorIndex < (
int) colors_.size() ){
580 if ( vertexMapPoly_.find( _vh ) != vertexMapPoly_.end() ){
581 polyMesh()->set_color( vertexMapPoly_[_vh], colors_[_colorIndex] );
582 objectOptions_ |= VERTEXCOLOR;
586 std::cerr <<
"Error: Color ID too large" << std::endl;
597 if ( isTriangleMesh() ){
602 if ( _colorIndex < (
int) colors_.size() ){
604 if ( _fh < (
int)faceMapTri_.size() ) {
605 triMesh()->set_color( faceMapTri_[_fh],colors_[_colorIndex] );
606 objectOptions_ |= FACECOLOR;
610 std::cerr <<
"Error: Color ID too large" << std::endl;
613 }
else if ( isPolyMesh() ){
618 if ( _colorIndex < (
int) colors_.size() ){
620 if ( _fh < (
int)faceMapPoly_.size() ) {
621 polyMesh()->set_color( faceMapPoly_[_fh], colors_[_colorIndex] );
622 objectOptions_ |= FACECOLOR;
626 std::cerr <<
"Error: Color ID too large" << std::endl;
TriMesh * triMesh()
get a pointer to the active triMesh
Vec3f vertex(uint _index)
get vertex with given index
Kernel::Point Point
Coordinate type.
BaseObject * getObject()
get BaseObject data of object
bool hasVertexNormals()
Query Object Options.
void setObjectOptions(ObjectOptions _options)
void setVertexTexCoord(VertexHandle _vh, int _texCoordID)
set vertex texture coordinate
int addNormal(const Vec3f &_normal)
add a normal
bool hasOption(ObjectOptionsE _option)
test if object has a certain option
MeshT * mesh()
return a pointer to the mesh
PolyMesh * polyMesh()
get a pointer to the active polyMesh
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Type for a MeshObject containing a triangle mesh.
void addObject(BaseObject *_object)
add initial object
void setNormal(VertexHandle _vh, int _normalID)
set vertex normal
Handle for a face entity.
QString path()
Path of the OFF file.
~OFFImporter()
base class needs virtual destructor
void setVertexColor(VertexHandle _vh, int _colorIndex)
set vertex color
int addTexCoord(const Vec2f &_coord)
add texture coordinates
void setObjectName(QString _name)
change the name of an object
VertexHandle addVertex(const Vec3f &_point)
add a vertex with coordinate _point
int addColor(const Vec4f &_color)
add a color
void addOption(ObjectOptionsE _option)
add an option
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
int addFace(const VHandles &_indices)
add a face with indices _indices refering to vertices
ObjectOptions & objectOptions()
get Object Options
void removeOption(ObjectOptionsE _option)
remove an option
uint n_vertices()
Global Properties.
Type for a Meshobject containing a poly mesh.
void setFaceColor(FaceHandle _fh, int _colorIndex)
set face color