Commit 271ec5f0 authored by Mike Kremer's avatar Mike Kremer
Browse files

Make use of std::vector's reserve in order to keep memory consumption as low...

Make use of std::vector's reserve in order to keep memory consumption as low as possible when loading files.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12587 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1c3d072a
......@@ -435,6 +435,8 @@ bool FileOFFPlugin::readFileOptions(QString _filename, OFFImporter& _importer) {
ifs.close();
_importer.maxFaceValence(vertexCount);
if(vertexCount == 3) {
_importer.addOption(OFFImporter::TRIMESH);
_importer.removeOption(OFFImporter::POLYMESH);
......@@ -592,6 +594,9 @@ bool FileOFFPlugin::parseASCII(std::istream& _in, OFFImporter& _importer, DataTy
sstr >> nF;
sstr >> dummy;
// Reserve memory
_importer.reserve(nV, nF * _importer.maxFaceValence() /*Upper bound*/, nF);
// read vertices: coord [hcoord] [normal] [color] [texcoord]
for (uint i=0; i<nV && !_in.eof(); ++i) {
......@@ -874,6 +879,9 @@ bool FileOFFPlugin::parseBinary(std::istream& _in, OFFImporter& _importer, DataT
readValue(_in, nF);
readValue(_in, dummy);
// Reserve memory
_importer.reserve(nV, nF * _importer.maxFaceValence() /*Upper bound*/, nF);
// read vertices: coord [hcoord] [normal] [color] [texcoord]
for (uint i=0; i<nV && !_in.eof(); ++i)
{
......
......@@ -58,7 +58,8 @@ OFFImporter::OFFImporter() :
polyMesh_(0),
triMesh_(0),
object_(0),
objectOptions_(0) {}
objectOptions_(0),
maxFaceValence_(0) {}
//-----------------------------------------------------------------------------
......@@ -482,6 +483,24 @@ uint OFFImporter::n_texCoords(){
//-----------------------------------------------------------------------------
void OFFImporter::reserve(unsigned int _nv, unsigned int _ne, unsigned int _nf) {
vertices_.reserve(_nv);
normals_.reserve(_nv);
texCoords_.reserve(_nv);
colors_.reserve(_nv);
if(isPolyMesh() && polyMesh_ != 0) {
polyMesh_->reserve(_nv, _ne, _nf);
}
if(isTriangleMesh() && triMesh_ != 0) {
triMesh_->reserve(_nv, _ne, _nf);
}
}
//-----------------------------------------------------------------------------
BaseObject* OFFImporter::getObject(){
return object_;
......
......@@ -102,6 +102,10 @@ class OFFImporter
/// add initial object
void addObject( BaseObject* _object );
unsigned int maxFaceValence() const { return maxFaceValence_; }
void maxFaceValence(unsigned int _maxValence) { maxFaceValence_ = _maxValence; }
/// add a vertex with coordinate \c _point
VertexHandle addVertex(const Vec3f& _point);
......@@ -151,6 +155,9 @@ class OFFImporter
uint n_vertices();
uint n_normals();
uint n_texCoords();
// Reserve memory for all entity types
void reserve(unsigned int _nv, unsigned int _ne, unsigned int _nf);
/// Path of the OFF file
QString path();
......@@ -214,6 +221,9 @@ class OFFImporter
// Store invalid face vertex handles
std::vector<OMVHandles> invalidFaces_;
// Keep track of max face valence
unsigned int maxFaceValence_;
};
//=============================================================================
......
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