50 #include "OFFImporter.hh" 79 polyMesh_ = polyMeshObj->
mesh();
81 objectOptions_ |= POLYMESH;
82 objectOptions_ &= ~TRIMESH;
84 }
else if ( triMeshObj ){
86 triMesh_ = triMeshObj->
mesh();
88 objectOptions_ |= TRIMESH;
89 objectOptions_ &= ~POLYMESH;
92 std::cerr <<
"Error: Cannot add object. Type is unknown!" << std::endl;
101 if ( vertices_.size() > _index )
102 return vertices_[ _index ];
111 texCoords_.push_back( _coord );
113 return texCoords_.size()-1;
120 normals_.push_back( _normal );
122 return normals_.size()-1;
129 colors_.push_back( _color );
131 return colors_.size()-1;
159 if ( isTriangleMesh() ){
164 if ( _texCoordID < (
int) texCoords_.size() ){
167 if ( !
triMesh()->has_vertex_texcoords2D() )
168 triMesh()->request_vertex_texcoords2D();
170 if ( vertexMapTri_.find( _vh ) != vertexMapTri_.end() )
171 triMesh()->set_texcoord2D( vertexMapTri_[_vh], texCoords_[ _texCoordID ] );
172 objectOptions_ |= VERTEXTEXCOORDS;
175 std::cerr <<
"Error: TexCoord ID too large" << std::endl;
178 }
else if ( isPolyMesh() ){
183 if ( _texCoordID < (
int) texCoords_.size() ){
186 if ( !
polyMesh()->has_vertex_texcoords2D() )
187 polyMesh()->request_vertex_texcoords2D();
189 if ( vertexMapPoly_.find( _vh ) != vertexMapPoly_.end() )
190 polyMesh()->set_texcoord2D( vertexMapPoly_[_vh], texCoords_[ _texCoordID ] );
191 objectOptions_ |= VERTEXTEXCOORDS;
194 std::cerr <<
"Error: TexCoord ID too large" << std::endl;
204 if ( isTriangleMesh() ){
209 if ( _normalID < (
int) normals_.size() ){
211 if ( vertexMapTri_.find( _vh ) != vertexMapTri_.end() ){
213 objectOptions_ |= VERTEXNORMAL;
217 std::cerr <<
"Error: normal ID too large" << std::endl;
220 }
else if ( isPolyMesh() ){
225 if ( _normalID < (
int) normals_.size() ){
227 if ( vertexMapPoly_.find( _vh ) != vertexMapPoly_.end() ){
229 objectOptions_ |= VERTEXNORMAL;
233 std::cerr <<
"Error: normal ID too large" << std::endl;
244 vertices_.push_back( _point );
246 int id = vertices_.size()-1;
248 if ( isTriangleMesh() ){
251 if ( !
triMesh() )
return false;
254 }
else if ( isPolyMesh() ){
271 if ( isTriangleMesh() ){
276 std::vector< TriMesh::VertexHandle > vertices;
278 for (uint i=0; i < _indices.size(); i++){
280 if ( vertexMapTri_.find( _indices[i] ) != vertexMapTri_.end() ){
282 vertices.push_back( vertexMapTri_[ _indices[i] ] );
285 std::cerr <<
"Error: Cannot add face. Undefined index (" << _indices[i] <<
")" << std::endl;
290 TriMesh::FaceHandle fh =
triMesh()->add_face( vertices );
293 faceMapTri_.push_back( fh );
294 faceIndex = faceMapTri_.size()-1;
297 invalidFaces_.push_back( vertices );
300 }
else if ( isPolyMesh() ){
305 std::vector< PolyMesh::VertexHandle > vertices;
307 for (uint i=0; i < _indices.size(); i++){
309 if ( vertexMapPoly_.find( _indices[i] ) != vertexMapPoly_.end() ){
311 vertices.push_back( vertexMapPoly_[ _indices[i] ] );
314 std::cerr <<
"Error: Cannot add face. Undefined index (" << _indices[i] <<
")" << std::endl;
319 PolyMesh::FaceHandle fh =
polyMesh()->add_face( vertices );
322 faceMapPoly_.push_back(fh);
323 faceIndex = faceMapPoly_.size()-1;
326 invalidFaces_.push_back( vertices );
337 if(invalidFaces_.empty())
return;
339 if ( isTriangleMesh() ) {
341 for(std::vector<OMVHandles>::iterator it = invalidFaces_.begin();
342 it != invalidFaces_.end(); ++it) {
344 OMVHandles& vhandles = *it;
347 for (
unsigned int j = 0; j < vhandles.size(); ++j)
350 vhandles[j] =
triMesh()->add_vertex(p);
355 if (
triMesh()->has_vertex_status()) {
356 triMesh()->status(vhandles[j]).set_fixed_nonmanifold(
true);
364 if (
triMesh()->has_face_status())
365 triMesh()->status(fh).set_fixed_nonmanifold(
true);
368 if (
triMesh()->has_edge_status()) {
370 for(; fe_it.is_valid(); ++fe_it) {
371 triMesh()->status(*fe_it).set_fixed_nonmanifold(
true);
375 faceMapTri_.push_back(fh);
378 }
else if ( isPolyMesh() ) {
380 for(std::vector<OMVHandles>::iterator it = invalidFaces_.begin();
381 it != invalidFaces_.end(); ++it) {
383 OMVHandles& vhandles = *it;
386 for (
unsigned int j = 0; j < vhandles.size(); ++j)
389 vhandles[j] =
polyMesh()->add_vertex(p);
394 if (
polyMesh()->has_vertex_status()) {
395 polyMesh()->status(vhandles[j]).set_fixed_nonmanifold(
true);
404 polyMesh()->status(fh).set_fixed_nonmanifold(
true);
407 if (
polyMesh()->has_edge_status()) {
409 for(; fe_it.is_valid(); ++fe_it) {
410 polyMesh()->status(*fe_it).set_fixed_nonmanifold(
true);
414 faceMapPoly_.push_back(fh);
419 invalidFaces_.clear();
424 bool OFFImporter::isTriangleMesh(){
425 return objectOptions_ & TRIMESH;
430 bool OFFImporter::isPolyMesh(){
431 return objectOptions_ & POLYMESH;
436 bool OFFImporter::isBinary(){
437 return objectOptions_ & BINARY;
444 return objectOptions_ & VERTEXNORMAL;
449 bool OFFImporter::hasTextureCoords(){
450 return objectOptions_ & VERTEXTEXCOORDS;
455 bool OFFImporter::hasVertexColors() {
456 return objectOptions_ & VERTEXCOLOR;
461 bool OFFImporter::hasFaceColors() {
462 return objectOptions_ & FACECOLOR;
468 return objectOptions_ & _option;
474 return vertices_.size();
479 uint OFFImporter::n_normals(){
480 return normals_.size();
485 uint OFFImporter::n_texCoords(){
486 return texCoords_.size();
491 void OFFImporter::reserve(
unsigned int _nv,
unsigned int _ne,
unsigned int _nf) {
493 vertices_.reserve(_nv);
494 normals_.reserve(_nv);
495 texCoords_.reserve(_nv);
496 colors_.reserve(_nv);
498 if(isPolyMesh() && polyMesh_ != 0) {
499 polyMesh_->reserve(_nv, _ne, _nf);
502 if(isTriangleMesh() && triMesh_ != 0) {
503 triMesh_->reserve(_nv, _ne, _nf);
522 void OFFImporter::setPath(QString _path){
529 objectOptions_ = _options;
535 objectOptions_ |= _option;
541 if(objectOptions_ & _option) objectOptions_ -= _option;
547 return objectOptions_;
563 if ( isTriangleMesh() ){
568 if ( _colorIndex < (
int) colors_.size() ){
570 if ( vertexMapTri_.find( _vh ) != vertexMapTri_.end() ){
571 triMesh()->set_color( vertexMapTri_[_vh], colors_[_colorIndex] );
572 objectOptions_ |= VERTEXCOLOR;
576 std::cerr <<
"Error: Color ID too large" << std::endl;
579 }
else if ( isPolyMesh() ){
584 if ( _colorIndex < (
int) colors_.size() ){
586 if ( vertexMapPoly_.find( _vh ) != vertexMapPoly_.end() ){
587 polyMesh()->set_color( vertexMapPoly_[_vh], colors_[_colorIndex] );
588 objectOptions_ |= VERTEXCOLOR;
592 std::cerr <<
"Error: Color ID too large" << std::endl;
603 if ( isTriangleMesh() ){
608 if ( _colorIndex < (
int) colors_.size() ){
610 if ( _fh < (
int)faceMapTri_.size() ) {
611 triMesh()->set_color( faceMapTri_[_fh],colors_[_colorIndex] );
612 objectOptions_ |= FACECOLOR;
616 std::cerr <<
"Error: Color ID too large" << std::endl;
619 }
else if ( isPolyMesh() ){
624 if ( _colorIndex < (
int) colors_.size() ){
626 if ( _fh < (
int)faceMapPoly_.size() ) {
627 polyMesh()->set_color( faceMapPoly_[_fh], colors_[_colorIndex] );
628 objectOptions_ |= FACECOLOR;
632 std::cerr <<
"Error: Color ID too large" << std::endl;
void setObjectOptions(ObjectOptions _options)
void setFaceColor(FaceHandle _fh, int _colorIndex)
set face color
Type for a MeshObject containing a triangle mesh.
Vec3f vertex(uint _index)
get vertex with given index
int addColor(const Vec4f &_color)
add a color
void setVertexColor(VertexHandle _vh, int _colorIndex)
set vertex color
int addTexCoord(const Vec2f &_coord)
add texture coordinates
BaseObject * getObject()
get BaseObject data of object
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
bool hasVertexNormals()
Query Object Options.
MeshT * mesh()
return a pointer to the mesh
~OFFImporter()
base class needs virtual destructor
void setNormal(VertexHandle _vh, int _normalID)
set vertex normal
void removeOption(ObjectOptionsE _option)
remove an option
int addFace(const VHandles &_indices)
add a face with indices _indices refering to vertices
uint n_vertices()
Global Properties.
void setVertexTexCoord(VertexHandle _vh, int _texCoordID)
set vertex texture coordinate
ObjectOptions & objectOptions()
get Object Options
int addNormal(const Vec3f &_normal)
add a normal
void addObject(BaseObject *_object)
add initial object
Handle for a face entity.
Type for a Meshobject containing a poly mesh.
PolyMesh * polyMesh()
get a pointer to the active polyMesh
Kernel::Point Point
Coordinate type.
TriMesh * triMesh()
get a pointer to the active triMesh
void setObjectName(QString _name)
change the name of an object
bool hasOption(ObjectOptionsE _option)
test if object has a certain option
QString path()
Path of the OFF file.
void addOption(ObjectOptionsE _option)
add an option
VertexHandle addVertex(const Vec3f &_point)
add a vertex with coordinate _point
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )