Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
410761f9
Commit
410761f9
authored
13 years ago
by
Tobias Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
significant speed improvement for DX file reading by using StringRef
parent
822b4fa1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/io/src/img/map_io_dx_handler.cc
+29
-8
29 additions, 8 deletions
modules/io/src/img/map_io_dx_handler.cc
with
29 additions
and
8 deletions
modules/io/src/img/map_io_dx_handler.cc
+
29
−
8
View file @
410761f9
...
...
@@ -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
=
boo
st
::
lexical_cast
<
Real
>
(
boost
::
trim_copy
(
tokens
[
j
])
);
}
catch
(
boost
::
bad_lexical_ca
st
&
)
{
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
++
)
{
st
d
::
pair
<
bool
,
float
>
result
=
fields
[
j
].
trim
().
to_float
(
);
if
(
!
result
.
fir
st
)
{
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
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment