11 #include <boost/tuple/tuple.hpp>
20 #ifdef NUKLEI_USE_CIMG
28 OsuTxtReader::OsuTxtReader(
const std::string &observationArgs) :
29 rows_(0), columns_(0),
32 size_t pos = observationArgs.find(
':');
33 if (pos == std::string::npos)
34 geometryFileName = observationArgs;
37 geometryFileName = observationArgs.substr(0, pos);
38 appFileName = observationArgs.substr(pos+1);
42 OsuTxtReader::~OsuTxtReader()
48 void OsuTxtReader::init_()
53 in_.open(geometryFileName.c_str(), std::ios::in);
55 throw ObservationIOError(std::string(
"Could not open file ") +
56 geometryFileName +
" for reading.");
58 if ( !(in_ >> rows_ >> Match(
"rows") >> columns_ >> Match(
"columns")) )
59 throw ObservationIOError(
"Non-OsuTxt format.");
60 if ( !(in_ >> Match(
"pixels") >> Match(
"(flag") >> Match(
"X") >>
61 Match(
"Y") >> Match(
"Z):")) )
62 throw ObservationIOError(
"Non-OsuTxt format.");
64 throw ObservationIOError(
"Non-OsuTxt format.");
71 for (
unsigned i = 0; i < rows_*columns_; ++i)
80 for (
unsigned i = 0; i < rows_*columns_; ++i)
86 for (
unsigned i = 0; i < rows_*columns_; ++i)
92 for (
unsigned i = 0; i < rows_*columns_; ++i)
100 if (!appFileName.empty())
102 #ifdef NUKLEI_USE_CIMG
104 cimg_library::CImg<unsigned char> img(appFileName.c_str());
105 for (
unsigned r = 0; r < rows_; r++)
106 for (
unsigned c = 0; c < columns_; c++)
108 Vector3 rgb(
double(img(c*2,r*2,0,0))/255,
109 double(img(c*2,r*2,0,1))/255,
110 double(img(c*2,r*2,0,2))/255);
113 }
catch (cimg_library::CImgException &e) {
122 for (
unsigned r = 0; r < rows_; r++)
123 for (
unsigned c = 0; c < columns_; c++)
138 void OsuTxtReader::reset()
140 NUKLEI_TRACE_BEGIN();
146 NUKLEI_UNIQUE_PTR<Observation> OsuTxtReader::readObservation_()
148 NUKLEI_TRACE_BEGIN();
149 if (rows_ == 0 || columns_ == 0)
NUKLEI_THROW(
"Reader does not seem inited.");
153 if (currentIndex_ >= rows_*columns_)
154 return NUKLEI_UNIQUE_PTR<Observation>();
156 unsigned index = currentIndex_;
159 if (flags_[index] ==
false)
continue;
161 NUKLEI_UNIQUE_PTR<OsuTxtObservation> observation(
new OsuTxtObservation);
163 Vector3 loc(x_[index], y_[index], z_[index]);
164 observation->setLoc(loc);
165 RGBColor c(rgb_[index]);
166 observation->setColor(c);
168 return NUKLEI_UNIQUE_PTR<Observation>(NUKLEI_MOVE(observation));
171 return NUKLEI_UNIQUE_PTR<Observation>();