Merge branch 'featureReaderPerformance' into 'master'

Feature reader performance

Added minor Performance tweaks to the file Readers.
Unittests on Linux work fine.
compilation on Linux and Windows (vs2013) works fine.
i could not run unittests on Windows, as i have no gtest on my dev machine.

See merge request !1
This commit is contained in:
Jan Möbius
2015-09-14 14:40:44 +02:00
3 changed files with 37 additions and 26 deletions

View File

@@ -172,6 +172,8 @@ read_material(std::fstream& _in)
std::string keyWrd; std::string keyWrd;
std::string textureName; std::string textureName;
std::stringstream stream;
std::string key; std::string key;
Material mat; Material mat;
float f1,f2,f3; float f1,f2,f3;
@@ -193,7 +195,8 @@ read_material(std::fstream& _in)
if ( line.empty() ) if ( line.empty() )
continue; continue;
std::stringstream stream(line); stream.str(line);
stream.clear();
stream >> keyWrd; stream >> keyWrd;
@@ -305,6 +308,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
std::string matname; std::string matname;
std::stringstream stream, lineData, tmp;
// Options supplied by the user // Options supplied by the user
Options userOptions = _opt; Options userOptions = _opt;
@@ -329,7 +334,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
continue; continue;
} }
std::stringstream stream(line); stream.str(line);
stream.clear();
stream >> keyWrd; stream >> keyWrd;
@@ -463,7 +469,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
// read full line after detecting a face // read full line after detecting a face
std::string faceLine; std::string faceLine;
std::getline(stream,faceLine); std::getline(stream,faceLine);
std::stringstream lineData( faceLine ); lineData.str( faceLine );
lineData.clear();
FaceHandle fh; FaceHandle fh;
BaseImporter::VHandles faceVertices; BaseImporter::VHandles faceVertices;
@@ -484,7 +491,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
if( found != std::string::npos ){ if( found != std::string::npos ){
// read the index value // read the index value
std::stringstream tmp( vertex.substr(0,found) ); tmp.str( vertex.substr(0,found) );
tmp.clear();
// If we get an empty string this property is undefined in the file // If we get an empty string this property is undefined in the file
if ( vertex.substr(0,found).empty() ) { if ( vertex.substr(0,found).empty() ) {
@@ -507,7 +515,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
} else { } else {
// last component of the vertex, read it. // last component of the vertex, read it.
std::stringstream tmp( vertex ); tmp.str( vertex );
tmp.clear();
tmp >> value; tmp >> value;
// Clear vertex after finished reading the line // Clear vertex after finished reading the line

View File

@@ -182,16 +182,18 @@ _OFFReader_::read_ascii(std::istream& _in, BaseImporter& _bi, Options& _opt) con
{ {
unsigned int i, j, k, l, idx; unsigned int i, j, k, l, idx;
unsigned int nV, nF, dummy; unsigned int nV, nF, dummy;
OpenMesh::Vec3f v, n; OpenMesh::Vec3f v, n;
OpenMesh::Vec2f t; OpenMesh::Vec2f t;
OpenMesh::Vec3i c3; OpenMesh::Vec3i c3;
OpenMesh::Vec3f c3f; OpenMesh::Vec3f c3f;
OpenMesh::Vec4i c4; OpenMesh::Vec4i c4;
OpenMesh::Vec4f c4f; OpenMesh::Vec4f c4f;
BaseImporter::VHandles vhandles; BaseImporter::VHandles vhandles;
VertexHandle vh; VertexHandle vh;
std::stringstream stream;
std::string trash;
// read header line // read header line
std::string header; std::string header;
@@ -227,13 +229,12 @@ _OFFReader_::read_ascii(std::istream& _in, BaseImporter& _bi, Options& _opt) con
int colorType = getColorType(line, options_.vertex_has_texcoord() ); int colorType = getColorType(line, options_.vertex_has_texcoord() );
std::stringstream stream( line ); stream.str(line);
stream.clear();
//perhaps read COLOR //perhaps read COLOR
if ( options_.vertex_has_color() ){ if ( options_.vertex_has_color() ){
std::string trash;
switch (colorType){ switch (colorType){
case 0 : break; //no color case 0 : break; //no color
case 1 : stream >> trash; break; //one int (isn't handled atm) case 1 : stream >> trash; break; //one int (isn't handled atm)
@@ -315,9 +316,8 @@ _OFFReader_::read_ascii(std::istream& _in, BaseImporter& _bi, Options& _opt) con
int colorType = getColorType(line, false ); int colorType = getColorType(line, false );
std::stringstream stream( line ); stream.str(line);
stream.clear();
std::string trash;
switch (colorType){ switch (colorType){
case 0 : break; //no color case 0 : break; //no color

View File

@@ -249,6 +249,9 @@ read_stla(std::istream& _in, BaseImporter& _bi, Options& _opt) const
std::string line; std::string line;
std::string garbage;
std::stringstream strstream;
bool facet_normal(false); bool facet_normal(false);
while( _in && !_in.eof() ) { while( _in && !_in.eof() ) {
@@ -265,9 +268,8 @@ read_stla(std::istream& _in, BaseImporter& _bi, Options& _opt) const
// Normal found? // Normal found?
if (line.find("facet normal") != std::string::npos) { if (line.find("facet normal") != std::string::npos) {
std::stringstream strstream(line); strstream.str(line);
strstream.clear();
std::string garbage;
// facet // facet
strstream >> garbage; strstream >> garbage;
@@ -292,9 +294,9 @@ read_stla(std::istream& _in, BaseImporter& _bi, Options& _opt) const
std::getline(_in, line); std::getline(_in, line);
trimStdString(line); trimStdString(line);
std::stringstream strstream(line); strstream.str(line);
strstream.clear();
std::string garbage;
strstream >> garbage; strstream >> garbage;
strstream >> v[0]; strstream >> v[0];