Connecting Tech Pros Worldwide Forums | Help | Site Map

Image sequence listing ...

majestik666@gmail.com
Guest
 
Posts: n/a
#1: Dec 20 '07
Am not sure if it's been asked before (did a search but didn't come up
with anything
related...).
I'm trying to write some code to "collapse" image sequences into
a single item , i.e.:
image.1.exr
image.2.exr
....
image.100.exr

into
image.[1-100].exr

This is for display only so i do not show up 100 files but only one
as some file managers do.

Anyone got any info on doing this quickly ?

I use Boost already in my app, so I guess the regex boost lib could
help
but not really sure of the most efficient way of doing it

Victor Bazarov
Guest
 
Posts: n/a
#2: Dec 20 '07

re: Image sequence listing ...


majestik666@gmail.com wrote:
Quote:
Am not sure if it's been asked before (did a search but didn't come up
with anything
related...).
I'm trying to write some code to "collapse" image sequences into
a single item , i.e.:
image.1.exr
image.2.exr
...
image.100.exr
>
into
image.[1-100].exr
>
This is for display only so i do not show up 100 files but only one
as some file managers do.
>
Anyone got any info on doing this quickly ?
What's your C++ language question? Are you trying to declare an array
to help you manage the sequence? You can also do it using 'std::map'
or 'std::vector', but I am unsure what to recommend since you didn't
show any code, and C++ doesn't have a definition of "image", nor does
it have a definition of "collapsing" of those.
Quote:
I use Boost already in my app, so I guess the regex boost lib could
help
but not really sure of the most efficient way of doing it
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


majestik666@gmail.com
Guest
 
Posts: n/a
#3: Dec 20 '07

re: Image sequence listing ...


On Dec 20, 12:43 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Quote:
majestik...@gmail.com wrote:
Quote:
Am not sure if it's been asked before (did a search but didn't come up
with anything
related...).
I'm trying to write some code to "collapse" image sequences into
a single item , i.e.:
image.1.exr
image.2.exr
...
image.100.exr
>
Quote:
into
image.[1-100].exr
>
Quote:
This is for display only so i do not show up 100 files but only one
as some file managers do.
>
Quote:
Anyone got any info on doing this quickly ?
>
What's your C++ language question? Are you trying to declare an array
to help you manage the sequence? You can also do it using 'std::map'
or 'std::vector', but I am unsure what to recommend since you didn't
show any code, and C++ doesn't have a definition of "image", nor does
it have a definition of "collapsing" of those.
>
Quote:
I use Boost already in my app, so I guess the regex boost lib could
help
but not really sure of the most efficient way of doing it
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Well I guess my c++ question is about
how do you list a folder, and while doing that
collapsing the filenames that are in the form prefix.%d.suffix
into "groups" like prefix.[first-last].suffix
it's not image related really, just about how to work out
the strings to collapes into one.
Victor Bazarov
Guest
 
Posts: n/a
#4: Dec 20 '07

re: Image sequence listing ...


majestik666@gmail.com wrote:
Quote:
[..]
Well I guess my c++ question is about
how do you list a folder, and while doing that
collapsing the filenames that are in the form prefix.%d.suffix
into "groups" like prefix.[first-last].suffix
it's not image related really, just about how to work out
the strings to collapes into one.
Ah... OK. Folders aside, files aside, your question is what you
should do to form "blah.[N-M].blah" if you have a bunch of strings
all containing "blah.<N>.blah", "blah.<N+1>.blah", etc., until the
"blah.<M>.blah" where N and M are two numbers. Right?

This is not a C++ language question. It's an algorithm question.
You need an algorithm for string processing. I would probably
suggest something like

// find the beginning of the sequence
int N;
for (N = 0; N < INT_MAX; ++N) {
std::ostringstream os;
os << "prefix." << N << ".suffix";
std::string filename(os.str());
if (/* exists the file with pattern 'filename' */)
break;
}
// now N is your start
int M;
for (int M = N; M<INT_MAX; ++M) {
std::ostringstream os;
os << "prefix." << M << ".suffix";
std::string filenam(os.str());
if (/* does NOT exist file with pattern 'filename' */)
break;
}
if (--M N) { // got the sequence!
std::ostringstream os;
os << "prefix.[" << N << '-' << M << "].suffix";
return os.str(); // here you go
}
else { // it's a single file, maybe.
...
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


majestik666@gmail.com
Guest
 
Posts: n/a
#5: Dec 20 '07

re: Image sequence listing ...


On Dec 20, 1:27 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Quote:
majestik...@gmail.com wrote:
Quote:
[..]
Well I guess my c++ question is about
how do you list a folder, and while doing that
collapsing the filenames that are in the form prefix.%d.suffix
into "groups" like prefix.[first-last].suffix
it's not image related really, just about how to work out
the strings to collapes into one.
>
Ah... OK. Folders aside, files aside, your question is what you
should do to form "blah.[N-M].blah" if you have a bunch of strings
all containing "blah.<N>.blah", "blah.<N+1>.blah", etc., until the
"blah.<M>.blah" where N and M are two numbers. Right?
>
This is not a C++ language question. It's an algorithm question.
You need an algorithm for string processing. I would probably
suggest something like
>
// find the beginning of the sequence
int N;
for (N = 0; N < INT_MAX; ++N) {
std::ostringstream os;
os << "prefix." << N << ".suffix";
std::string filename(os.str());
if (/* exists the file with pattern 'filename' */)
break;
}
// now N is your start
int M;
for (int M = N; M<INT_MAX; ++M) {
std::ostringstream os;
os << "prefix." << M << ".suffix";
std::string filenam(os.str());
if (/* does NOT exist file with pattern 'filename' */)
break;
}
if (--M N) { // got the sequence!
std::ostringstream os;
os << "prefix.[" << N << '-' << M << "].suffix";
return os.str(); // here you go
}
else { // it's a single file, maybe.
...
}
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
well yes it's the problem, but the initial conditions are a bit
different
let's say i have a list of strings in the form you mentioned
prefix.<N>.suffix, I can have different prefixes etc.
but I guess I cannot avoid going through the files one by one
and looking if i can join it with other files in the same folder.
Victor Bazarov
Guest
 
Posts: n/a
#6: Dec 20 '07

re: Image sequence listing ...


majestik666@gmail.com wrote:
Quote:
On Dec 20, 1:27 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Quote:
>majestik...@gmail.com wrote:
Quote:
>>[..]
>>Well I guess my c++ question is about
>>how do you list a folder, and while doing that
>>collapsing the filenames that are in the form prefix.%d.suffix
>>into "groups" like prefix.[first-last].suffix
>>it's not image related really, just about how to work out
>>the strings to collapes into one.
>>
>Ah... OK. Folders aside, files aside, your question is what you
>should do to form "blah.[N-M].blah" if you have a bunch of strings
>all containing "blah.<N>.blah", "blah.<N+1>.blah", etc., until the
>"blah.<M>.blah" where N and M are two numbers. Right?
>>
>This is not a C++ language question. It's an algorithm question.
>You need an algorithm for string processing. I would probably
>suggest something like
>>
> // find the beginning of the sequence
> int N;
> for (N = 0; N < INT_MAX; ++N) {
> std::ostringstream os;
> os << "prefix." << N << ".suffix";
> std::string filename(os.str());
> if (/* exists the file with pattern 'filename' */)
> break;
> }
> // now N is your start
> int M;
> for (int M = N; M<INT_MAX; ++M) {
> std::ostringstream os;
> os << "prefix." << M << ".suffix";
> std::string filenam(os.str());
> if (/* does NOT exist file with pattern 'filename' */)
> break;
> }
> if (--M N) { // got the sequence!
> std::ostringstream os;
> os << "prefix.[" << N << '-' << M << "].suffix";
> return os.str(); // here you go
> }
> else { // it's a single file, maybe.
> ...
> }
>>
>V
>--
>Please remove capital 'A's when replying by e-mail
>I do not respond to top-posted replies, please don't ask
>
well yes it's the problem, but the initial conditions are a bit
different
let's say i have a list of strings in the form you mentioned
prefix.<N>.suffix, I can have different prefixes etc.
but I guess I cannot avoid going through the files one by one
and looking if i can join it with other files in the same folder.
It's all in how you check for the existence of the file. If your
system allows enumerating with a pattern (like "*.1001.img"), then
you're in luck and you need to put the asterisk instead of 'prefix'.

The algorithm as I wrote it is also substandard from the performance
point of view. It would be nice if you could simply get all the
strings (names of the files) fitting the pattern "*.[0-9]+.suffix",
and sort them while disregarding the prefix (you need a custom
comparison functor for that). Then you simply have an array of
strings, and the very first one contains your N, which you can
simply extract from the string itself. And you can simply keep
extracting the number from each string and compare it to what you
expect (previous + 1). If it isn't, your sequence is over, and
you may need to start another sequence...

Anyway, this doesn't seem to be a C++ topic either. Try posting to
comp.programming, the general algorithm discussion newsgroup.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Closed Thread