6#include <boost/regex.hpp>
10 void updateCache(
const std::vector<bool> &pixels, std::vector<int> &cache,
int x,
int width) {
11 const int height = cache.size();
12 for (
int y = 0; y < height; ++ y) {
13 if (pixels[x + y * width]) {
40 std::vector<int> cache(M, 0);
41 std::stack<std::pair<int, int> > stack;
42 for (
int x = N - 1; x >= 0; -- x) {
43 updateCache(pixels, cache, x, N);
45 for (
int y = 0; y < M; ++ y) {
46 if (cache[y] > width) {
47 stack.push(std::make_pair(y, width));
49 }
else if (cache[y] < width) {
52 std::tie(y0, w0) = stack.top();
54 if (width * (y - y0) > bestArea) {
55 bestLL.x_m = x; bestLL.y_m = y0;
56 bestUR.
x_m = x + width; bestUR.
y_m = y;
57 bestArea = width * (y - y0);
60 }
while (!stack.empty() && cache[y] < width);
63 stack.push(std::make_pair(y0, width));
70 std::tie(y0, w0) = stack.top();
72 if (width * (N - y0) > bestArea) {
73 bestLL.x_m = x; bestLL.y_m = y0;
74 bestUR.
x_m = x + width; bestUR.
y_m = N;
75 bestArea = width * (N - y0);
80 return std::make_pair(bestLL, bestUR);
87 std::vector<IntPixel_t> rectangles;
93 if (area > maxArea) maxArea = area;
98 rectangles.push_back(pix);
100 for (
int y = pix.first.y_m; y < pix.second.y_m; ++ y) {
101 int idx = y * N + pix.first.x_m;
102 for (
int x = pix.first.x_m; x < pix.second.x_m; ++ x, ++ idx) {
108 for (
int y = 0; y < M; ++ y) {
109 for (
int x = 0; x < N; ++ x, ++idx) {
122 Mask *pixmap =
static_cast<Mask*
>(fun);
125 std::string filename = arguments.
get(0);
126 if (filename[0] ==
'\'' && filename.back() ==
'\'') {
127 filename = filename.substr(1, filename.length() - 2);
130 if (!std::filesystem::exists(filename)) {
131 ERRORMSG(
"file '" << filename <<
"' doesn't exists" <<
endl);
144 }
catch (std::runtime_error &
e) {
149 if (pixel_width < 0.0) {
150 std::cout <<
"Mask: a negative width provided '"
151 << arguments.
get(0) <<
" = " << pixel_width * width <<
"'"
156 if (pixel_height < 0.0) {
157 std::cout <<
"Mask: a negative height provided '"
158 << 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)
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
std::pair< IntPoint, IntPoint > IntPixel_t
long computeArea(const IntPoint &ll, const IntPoint &ur) const
std::pair< IntPoint, IntPoint > findMaximalRectangle(const std::vector< bool > &pixels, int height, int width) const
std::vector< Rectangle > pixels_m
std::vector< IntPixel_t > minimizeNumberOfRectangles(std::vector< bool > pixels, int height, int width)
std::vector< bool > getPixels() const
unsigned int getWidth() const
unsigned int getHeight() const
Vektor< double, 3 > Vector_t