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 @@ ...@@ -24,6 +24,7 @@
#include <sstream> #include <sstream>
#include <ost/log.hh> #include <ost/log.hh>
#include <ost/string_ref.hh>
#include <boost/iostreams/filter/gzip.hpp> #include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/filtering_stream.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
...@@ -45,6 +46,23 @@ namespace ost { namespace io { ...@@ -45,6 +46,23 @@ namespace ost { namespace io {
using boost::format; 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"; String DX::FORMAT_STRING="defined_dx";
DX::DX (bool normalize_on_save): DX::DX (bool normalize_on_save):
...@@ -97,6 +115,9 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag ...@@ -97,6 +115,9 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag
img::MapHandle mh2; img::MapHandle mh2;
std::vector<String> tokens; std::vector<String> tokens;
while (std::getline(infile,line)) { while (std::getline(infile,line)) {
if (line.empty()) {
continue;
}
// read gridpoints line // read gridpoints line
if (boost::iequals(line.substr(0,35), "object 1 class gridpositions counts")) { if (boost::iequals(line.substr(0,35), "object 1 class gridpositions counts")) {
boost::split(tokens, line, boost::is_any_of(" "), boost::token_compress_on); 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 ...@@ -189,14 +210,14 @@ void MapIODxHandler::Import(img::MapHandle& mh, std::istream& infile, const Imag
Real value=0; Real value=0;
for(int i=0; i<num_gridpoints; i+=3) { for(int i=0; i<num_gridpoints; i+=3) {
std::getline(infile,line); std::getline(infile,line);
boost::split(tokens, line, boost::is_any_of(" "), boost::token_compress_on); StringRef curr_line(line.c_str(), line.size());
for (size_t j=0; j<tokens.size()-1; j++) { // three values per line std::vector<StringRef> fields=curr_line.split(' ');
try { for (size_t j=0; j<fields.size(); j++) {
value=boost::lexical_cast<Real>(boost::trim_copy(tokens[j])); std::pair<bool, float> result=fields[j].trim().to_float();
} catch(boost::bad_lexical_cast&) { if (!result.first) {
format fmer = format("Bad value line: Can't convert grid point value '%s' to Real constant.") % line; throw IOException((format("Bad value line: Can't convert grid point value '%s' to Real constant.") % line).str());
throw IOException(fmer.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); 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