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);
unsigned int getHeight() const
AffineTransformation trafo_m
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
std::pair< IntPoint, IntPoint > findMaximalRectangle(const std::vector< bool > &pixels, int height, int width) const
double parseMathExpression(const std::string &str)
Vektor< double, 3 > Vector_t
std::pair< IntPoint, IntPoint > IntPixel_t
Inform & endl(Inform &inf)
unsigned int getWidth() const
std::vector< Rectangle > pixels_m
std::string::iterator iterator
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
unsigned int getLengthConsumed() const
std::vector< IntPixel_t > minimizeNumberOfRectangles(std::vector< bool > pixels, int height, int width)
std::string get(unsigned int i) const
long computeArea(const IntPoint &ll, const IntPoint &ur) const
virtual void print(int ident)
std::vector< bool > getPixels() const
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)
constexpr double e
The value of .