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

improve performance for small vectors/faces

refs #2421

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20720 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 676e07a7
......@@ -62,6 +62,7 @@
#include "FileOBJ.hh"
#include <iostream>
#include <algorithm>
// Defines for the type handling drop down box
......@@ -73,20 +74,6 @@
//-----------------------------------------------------------------------------
// help functions
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_;
};
float getFloat( QTextStream& _source)
{
......@@ -215,7 +202,11 @@ namespace{
void remove_duplicated_vertices(VHandles& _indices)
{
_indices.erase(std::remove_if(_indices.begin(),_indices.end(),HasSeen<int>()),_indices.end());
VHandles::iterator endIter = _indices.end();
for (VHandles::iterator iter = _indices.begin(); iter != endIter; ++iter)
endIter = std::remove(iter+1, endIter, *(iter));
_indices.erase(endIter,_indices.end());
}
//-----------------------------------------------------------------------------
......
......@@ -73,21 +73,13 @@
#include <algorithm>
//-----------------------------------------------------------------------------------------------------
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);
}
void remove_duplicated_vertices(std::vector<quint32>& _indices)
{
std::vector<quint32>::iterator endIter = _indices.end();
for (std::vector<quint32>::iterator iter = _indices.begin(); iter != endIter; ++iter)
endIter = std::remove(iter+1, endIter, *(iter));
private:
mutable std::set<T> seen_;
};
_indices.erase(endIter,_indices.end());
}
//-----------------------------------------------------------------------------------------------------
......@@ -1971,41 +1963,9 @@ 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."));
}
remove_duplicated_vertices(indices);
if (!skipFace)
if (indices.size() >= 3)
{
CellType cell;
cell.type = 7; // VTK_POLYGON
......
Supports Markdown
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