Skip to content
Snippets Groups Projects
Commit 410761f9 authored by Tobias Schmidt's avatar Tobias Schmidt
Browse files

significant speed improvement for DX file reading by using StringRef

parent 822b4fa1
Branches
Tags
No related merge requests found
......@@ -24,6 +24,7 @@
#include <sstream>
#include <ost/log.hh>
#include <ost/string_ref.hh>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/filesystem/fstream.hpp>
......@@ -45,6 +46,23 @@ namespace ost { namespace io {
using boost::format;
namespace {
bool IEquals(const StringRef& a, const StringRef& b)
{
if (a.size()!=b.size()) {
return false;
}
for (size_t i=0; i<a.size(); ++i) {
if (toupper(a[i])!=b[i]) {
return false;
}
}
return true;
}
}
String DX::FORMAT_STRING="defined_dx";
DX::DX (bool normalize_on_save):
......@@ -97,6 +115,9 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag
img::MapHandle mh2;
std::vector<String> tokens;
while (std::getline(infile,line)) {
if (line.empty()) {
continue;
}
// read gridpoints line
if (boost::iequals(line.substr(0,35), "object 1 class gridpositions counts")) {
boost::split(tokens, line, boost::is_any_of(" "), boost::token_compress_on);
......@@ -189,14 +210,14 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag
Real value=0;
for(int i=0; i<num_gridpoints; i+=3) {
std::getline(infile,line);
boost::split(tokens, line, boost::is_any_of(" "), boost::token_compress_on);
for (size_t j=0; j<tokens.size()-1; j++) { // three values per line
try {
value=boost::lexical_cast<Real>(boost::trim_copy(tokens[j]));
} catch(boost::bad_lexical_cast&) {
format fmer = format("Bad value line: Can't convert grid point value '%s' to Real constant.") % line;
throw IOException(fmer.str());
}
StringRef curr_line(line.c_str(), line.size());
std::vector<StringRef> fields=curr_line.split(' ');
for (size_t j=0; j<fields.size(); j++) {
std::pair<bool, float> result=fields[j].trim().to_float();
if (!result.first) {
throw IOException((format("Bad value line: Can't convert grid point value '%s' to Real constant.") % line).str());
}
value=result.second;
mh2.SetReal(img::Point(((i+j)/(v_size*w_size))%u_size,((i+j)/w_size)%v_size, (i+j)%w_size), value);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment