Commit ae88caf8 authored by Matthias Möller's avatar Matthias Möller
Browse files

- fix: no crash, if loaded face is degenerated

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17804 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 6411bad9
......@@ -53,6 +53,9 @@
#include "FileVTK.hh"
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/common/GlobalOptions.hh"
......@@ -68,6 +71,24 @@
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif
//-----------------------------------------------------------------------------------------------------
namespace{
template<typename T>
class HasSeen : public std::unary_function <T, bool>
{
public:
HasSeen () : seen_ () { }
bool operator ()(const T& i) const
{
return (!seen_.insert(i).second);
}
private:
mutable std::set<T> seen_;
};
}
//-----------------------------------------------------------------------------------------------------
/// Constructor
......@@ -1947,19 +1968,58 @@ bool FileVTKPlugin::loadMeshPolygons(QString _spec,QTextStream& _in,MeshT*& _mes
}
if ( _in.status() == QTextStream::Ok ) {
//check, if there exists duplicate vertices inside of the face
//std::vector< quint32 >::iterator newEndIter = std::remove_if(indices.begin(),indices.end(),HasSeen<int>(seen));
size_t dublicatedIndices = std::count_if(indices.begin(),indices.end(),HasSeen<int>());
bool skipFace = false;
if (dublicatedIndices != 0)
{
//if so, check, if it is only a degenerated face
//remove all consecutive vertices which are equal
std::vector< quint32 >::iterator endIter = indices.end();
std::vector< quint32 >::iterator adjIter = std::adjacent_find(indices.begin(),endIter);
while( adjIter != indices.end() )
{
indices.erase(adjIter);
--dublicatedIndices;
adjIter = std::adjacent_find(indices.begin(),indices.end());
}
if (dublicatedIndices != 0)
{
//remove circles (e.g. indices: 1 2 3 2 1 -> 1 2 3)
const std::vector< quint32 >::iterator endCheckVertices = indices.begin()+dublicatedIndices;
const std::vector< quint32 >::iterator missIter = std::mismatch(indices.begin(),endCheckVertices,indices.rbegin()).first;
skipFace = (missIter != endCheckVertices);
//skip face, if no match was found, otherwise, delete the circle
if (!skipFace)
indices.erase(indices.begin(),endCheckVertices);
}
if (!skipFace)
emit log(LOGWARN,tr("Repair and add degenerated face!"));
else
emit log(LOGERR,tr("Face uses same Vertex several times. Can not restore. Skip."));
}
if (!skipFace)
{
CellType cell;
cell.type = 7; // VTK_POLYGON
cell.indices = indices;
cell.index = addFace(_mesh, indices);
_cells.push_back(cell);
}
} else {
emit log(LOGERR,tr("Read corrupted face data!"));
emit log(LOGERR,tr("Read corrupted face data!"));
// Restore error logging state before returning
if ( errorEnabled )
omerr().enable();
// Restore error logging state before returning
if ( errorEnabled )
omerr().enable();
return false;
return false;
}
++read;
}
......
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