6#include <boost/regex.hpp>
7#include <boost/filesystem.hpp>
10 void Mask::updateCache(
const std::vector<bool> &pixels, std::vector<unsigned int> &cache,
unsigned int y)
const {
11 const unsigned int M = cache.size();
12 unsigned int idx = y * M;
13 for (
unsigned int x = 0; x < M; ++ x, ++ idx) {
31 unsigned int M )
const {
37 unsigned int bestArea = 0;
39 std::vector<unsigned int> cache(M, 0);
40 std::stack<std::pair<unsigned int, unsigned int> > stack;
41 for (
unsigned int y = N - 1; y + 1 > 0; -- y) {
43 unsigned int height = 0;
44 for (
unsigned int x = 0; x < M; ++ x) {
45 if (cache[x] > height) {
46 stack.push(std::make_pair(x, height));
48 }
else if (cache[x] < height) {
49 std::pair<unsigned int, unsigned int> tmp;
53 if (x > tmp.first && height * (x - tmp.first) > bestArea) {
54 bestLL.x_m = tmp.first; bestLL.y_m = y;
55 bestUR.
x_m = x; bestUR.
y_m = y + height;
56 bestArea = height * (x - tmp.first);
59 }
while (!stack.empty() && cache[x] < height);
62 stack.push(std::make_pair(tmp.first, height));
68 std::pair<unsigned int, unsigned int> tmp = stack.top();
70 if (M > tmp.first && height * (M - tmp.first) > bestArea) {
71 bestLL.x_m = tmp.first; bestLL.y_m = y;
72 bestUR.
x_m = M; bestUR.
y_m = y + height;
73 bestArea = height * (M - tmp.first);
78 return std::make_pair(bestLL, bestUR);
85 std::vector<IntPixel_t> rectangles;
87 unsigned int maxArea = 0;
90 unsigned int area =
computeArea(pix.first, pix.second);
91 if (area > maxArea) maxArea = area;
92 if (1000 * area < maxArea || area <= 1) {
96 rectangles.push_back(pix);
98 for (
int y = pix.first.y_m; y < pix.second.y_m; ++ y) {
99 unsigned int idx = y * M + pix.first.x_m;
100 for (
int x = pix.first.x_m; x < pix.second.x_m; ++ x, ++ idx) {
106 unsigned int idx = 0;
107 for (
unsigned int y = 0; y < N; ++ y) {
108 for (
unsigned int x = 0; x < M; ++ x, ++idx) {
121 Mask *pixmap =
static_cast<Mask*
>(fun);
124 std::string filename = arguments.
get(0);
125 if (filename[0] ==
'\'' && filename.back() ==
'\'') {
126 filename = filename.substr(1, filename.length() - 2);
129 if (!boost::filesystem::exists(filename)) {
130 ERRORMSG(
"file '" << filename <<
"' doesn't exists" <<
endl);
135 unsigned int width = reader.
getWidth();
136 unsigned int height = reader.
getHeight();
143 }
catch (std::runtime_error &
e) {
148 if (pixel_width < 0.0) {
149 std::cout <<
"Mask: a negative width provided '"
150 << arguments.
get(0) <<
" = " << pixel_width * width <<
"'"
155 if (pixel_height < 0.0) {
156 std::cout <<
"Mask: a negative height provided '"
157 << arguments.
get(1) <<
" = " << pixel_height * height <<
"'"
172 double midX = 0.5 * (ur.
x_m + ll.
x_m);
173 double midY = 0.5 * (ur.
y_m + ll.
y_m);
175 Vector_t(0, 1, (midY - 0.5 * height) * pixel_height));
178 pixmap->
pixels_m.back().computeBoundingBox();
187 for (
auto pix:
pixels_m) pix.print(ident);
191 for (
auto pix:
pixels_m) pix.apply(bfuncs);
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
Inform & endl(Inform &inf)
constexpr double e
The value of.
double parseMathExpression(const std::string &str)
std::string::iterator iterator
AffineTransformation trafo_m
std::string get(unsigned int i) const
unsigned int getLengthConsumed() const
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)
virtual void print(int ident)
std::vector< IntPixel_t > minimizeNumberOfRectangles(std::vector< bool > pixels, unsigned int height, unsigned int width)
std::pair< IntPoint, IntPoint > findMaximalRectangle(const std::vector< bool > &pixels, unsigned int height, unsigned int width) const
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
unsigned int computeArea(const IntPoint &ll, const IntPoint &ur) const
std::pair< IntPoint, IntPoint > IntPixel_t
void updateCache(const std::vector< bool > &pixels, std::vector< unsigned int > &cache, unsigned int y) const
std::vector< Rectangle > pixels_m
std::vector< bool > getPixels() const
unsigned int getWidth() const
unsigned int getHeight() const
Vektor< double, 3 > Vector_t