Commit 39a7aac4 authored by Mike Kremer's avatar Mike Kremer
Browse files

In order to load ALL mesh files (also those that contain non-manifold...

In order to load ALL mesh files (also those that contain non-manifold configurations), we have to check for degenerate faces before adding them. If this is not done, OpenFlipper crashes when adding these faces.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9824 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b230db05
......@@ -504,7 +504,7 @@ bool FileOFFPlugin::readOFFFile(QString _filename, OFFImporter& _importer) {
break;
}
return _importer.isBinary() ? parseBinary(ifile, _importer, type, _filename) : parseASCII(ifile, _importer, type, _filename);
}
......@@ -657,7 +657,11 @@ bool FileOFFPlugin::parseASCII(std::istream& _in, OFFImporter& _importer, DataTy
vhandles.push_back(VertexHandle(idx));
}
fh = _importer.addFace(vhandles);
if(checkDegenerateFace(vhandles)) {
fh = _importer.addFace(vhandles);
} else {
continue;
}
//perhaps read face COLOR
if ( _importer.hasFaceColors() ){
......@@ -718,6 +722,21 @@ bool FileOFFPlugin::parseASCII(std::istream& _in, OFFImporter& _importer, DataTy
//-----------------------------------------------------------------------------------------------------
bool FileOFFPlugin::checkDegenerateFace(const std::vector<VertexHandle>& _v) {
bool check = true;
int size = _v.size();
// Check if at least two elements in the list have the same value
for(int i = 0; i < size; ++i) {
for(int j = i+1; j < size; ++j) {
if(_v[i] == _v[j]) check = false;
}
}
return check;
}
//-----------------------------------------------------------------------------------------------------
int FileOFFPlugin::getColorType(std::string& _line, bool _texCoordsAvailable) const {
/*
0 : no Color
......
......@@ -202,6 +202,9 @@ class FileOFFPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
void trimString( std::string& _string);
/// Check for degenerate faces before adding them
bool checkDegenerateFace(const std::vector<VertexHandle>& _v);
/// Writer function
template< class MeshT >
bool writeMesh(std::ostream& _out, MeshT& _mesh );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment