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;
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;
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(
auto it : invalidFaces_) {
337 OMVHandles& vhandles = it;
340 for (
unsigned int j = 0; j < vhandles.size(); ++j)
343 vhandles[j] =
triMesh()->add_vertex(p);
348 if (
triMesh()->has_vertex_status()) {
349 triMesh()->status(vhandles[j]).set_fixed_nonmanifold(
true);
357 if (
triMesh()->has_face_status())
358 triMesh()->status(fh).set_fixed_nonmanifold(
true);
361 if (
triMesh()->has_edge_status()) {
362 for(
auto fe_it : fh.
edges()) {
363 triMesh()->status(fe_it).set_fixed_nonmanifold(
true);
367 faceMapTri_.push_back(fh);
370 }
else if ( isPolyMesh() ) {
372 for(
auto it : invalidFaces_) {
374 OMVHandles& vhandles = it;
377 for (
unsigned int j = 0; j < vhandles.size(); ++j)
380 vhandles[j] =
polyMesh()->add_vertex(p);
385 if (
polyMesh()->has_vertex_status()) {
386 polyMesh()->status(vhandles[j]).set_fixed_nonmanifold(
true);
395 polyMesh()->status(fh).set_fixed_nonmanifold(
true);
398 if (
polyMesh()->has_edge_status()) {
399 for(
auto fe_it : fh.
edges()) {
400 polyMesh()->status(fe_it).set_fixed_nonmanifold(
true);
404 faceMapPoly_.push_back(fh);
409 invalidFaces_.clear();
414bool OFFImporter::isTriangleMesh(){
415 return objectOptions_ & TRIMESH;
420bool OFFImporter::isPolyMesh(){
421 return objectOptions_ & POLYMESH;
426bool OFFImporter::isBinary(){
427 return objectOptions_ & BINARY;
434 return objectOptions_ & VERTEXNORMAL;
439bool OFFImporter::hasTextureCoords(){
440 return objectOptions_ & VERTEXTEXCOORDS;
445bool OFFImporter::hasVertexColors() {
446 return objectOptions_ & VERTEXCOLOR;
451bool OFFImporter::hasFaceColors() {
452 return objectOptions_ & FACECOLOR;
458 return objectOptions_ & _option;
464 return vertices_.size();
469uint OFFImporter::n_normals(){
470 return normals_.size();
475uint OFFImporter::n_texCoords(){
476 return texCoords_.size();
481void OFFImporter::reserve(
unsigned int _nv,
unsigned int _ne,
unsigned int _nf) {
483 vertices_.reserve(_nv);
484 normals_.reserve(_nv);
485 texCoords_.reserve(_nv);
486 colors_.reserve(_nv);
488 if(isPolyMesh() && polyMesh_ != 0) {
489 polyMesh_->reserve(_nv, _ne, _nf);
492 if(isTriangleMesh() && triMesh_ != 0) {
493 triMesh_->reserve(_nv, _ne, _nf);
512void OFFImporter::setPath(QString _path){
519 objectOptions_ = _options;
525 objectOptions_ |= _option;
531 if(objectOptions_ & _option) objectOptions_ -= _option;
537 return objectOptions_;
553 if ( isTriangleMesh() ){
558 if ( _colorIndex < (
int) colors_.size() ){
560 if ( vertexMapTri_.find( _vh ) != vertexMapTri_.end() ){
561 triMesh()->set_color( vertexMapTri_[_vh], colors_[_colorIndex] );
562 objectOptions_ |= VERTEXCOLOR;
566 std::cerr <<
"Error: Color ID too large" << std::endl;
569 }
else if ( isPolyMesh() ){
574 if ( _colorIndex < (
int) colors_.size() ){
576 if ( vertexMapPoly_.find( _vh ) != vertexMapPoly_.end() ){
577 polyMesh()->set_color( vertexMapPoly_[_vh], colors_[_colorIndex] );
578 objectOptions_ |= VERTEXCOLOR;
582 std::cerr <<
"Error: Color ID too large" << std::endl;
593 if ( isTriangleMesh() ){
598 if ( _colorIndex < (
int) colors_.size() ){
600 if ( _fh < (
int)faceMapTri_.size() ) {
601 triMesh()->set_color( faceMapTri_[_fh],colors_[_colorIndex] );
602 objectOptions_ |= FACECOLOR;
606 std::cerr <<
"Error: Color ID too large" << std::endl;
609 }
else if ( isPolyMesh() ){
614 if ( _colorIndex < (
int) colors_.size() ){
616 if ( _fh < (
int)faceMapPoly_.size() ) {
617 polyMesh()->set_color( faceMapPoly_[_fh], colors_[_colorIndex] );
618 objectOptions_ |= FACECOLOR;
622 std::cerr <<
"Error: Color ID too large" << std::endl;
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
MeshT * mesh()
return a pointer to the mesh
int addTexCoord(const Vec2f &_coord)
add texture coordinates
ObjectOptions & objectOptions()
get Object Options
TriMesh * triMesh()
get a pointer to the active triMesh
PolyMesh * polyMesh()
get a pointer to the active polyMesh
void setObjectOptions(ObjectOptions _options)
VertexHandle addVertex(const Vec3f &_point)
add a vertex with coordinate _point
void setVertexTexCoord(VertexHandle _vh, int _texCoordID)
set vertex texture coordinate
bool hasVertexNormals()
Query Object Options.
void setObjectName(QString _name)
change the name of an object
void setVertexColor(VertexHandle _vh, int _colorIndex)
set vertex color
int addFace(const VHandles &_indices)
add a face with indices _indices refering to vertices
void addOption(ObjectOptionsE _option)
add an option
uint n_vertices()
Global Properties.
int addNormal(const Vec3f &_normal)
add a normal
void removeOption(ObjectOptionsE _option)
remove an option
Vec3f vertex(uint _index)
get vertex with given index
~OFFImporter()
base class needs virtual destructor
void setFaceColor(FaceHandle _fh, int _colorIndex)
set face color
QString path()
Path of the OFF file.
void addObject(BaseObject *_object)
add initial object
bool hasOption(ObjectOptionsE _option)
test if object has a certain option
int addColor(const Vec4f &_color)
add a color
BaseObject * getObject()
get BaseObject data of object
void setNormal(VertexHandle _vh, int _normalID)
set vertex normal
Kernel::FaceHandle FaceHandle
Scalar type.
Kernel::Point Point
Coordinate type.
Type for a Meshobject containing a poly mesh.
Type for a MeshObject containing a triangle mesh.
PolyConnectivity::ConstFaceEdgeRange edges() const
Returns a range of edges of the face (PolyConnectivity::fv_range())