-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequence.cpp
65 lines (55 loc) · 1.57 KB
/
sequence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <segmentation_and_tracking/scene.h>
using namespace std;
namespace bfs = boost::filesystem;
using namespace Eigen;
using boost::shared_ptr;
Sequence::Sequence(const std::string& root) :
root_(root)
{
assert(bfs::exists(root_));
// -- Get the number of scenes.
size_t num_scenes = 0;
bfs::directory_iterator end_itr;
for(bfs::directory_iterator itr(root); itr != end_itr; ++itr)
if((itr->path().extension().compare(".png") == 0) |
(itr->path().extension().compare(".jpg") == 0))
++num_scenes;
// -- Get the sorted scene names.
size_t idx = 0;
names_.resize(num_scenes);
for(bfs::directory_iterator itr(root); itr != end_itr; ++itr) {
if((itr->path().extension().compare(".png") == 0) |
(itr->path().extension().compare(".jpg") == 0)) {
string filename = itr->path().filename();
names_[idx] = filename.substr(0, filename.size() - 4);
++idx;
}
}
sort(names_.begin(), names_.end());
// -- Load all scenes.
scenes_.reserve(size());
for(size_t i = 0; i < size(); ++i)
scenes_.push_back(shared_ptr<Scene>(loadScene(i)));
}
size_t Sequence::size() const
{
return names_.size();
}
Scene* Sequence::loadScene(size_t idx) const
{
assert(idx < size());
string path = root_ + "/" + names_[idx];
return new Scene(path);
}
shared_ptr<Scene> Sequence::getScene(size_t idx) const
{
assert(idx < scenes_.size());
return scenes_[idx];
}
void Sequence::saveSegmentations() const
{
for(size_t i = 0; i < scenes_.size(); ++i) {
if(scenes_[i]->segmentation_)
scenes_[i]->saveSegmentation();
}
}