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 *ippl::Error <<
"file '" << filename <<
"' doesn't exists" << endl;
135 unsigned int width = reader.
getWidth();
136 unsigned int height = reader.
getHeight();
143 }
catch (std::runtime_error &e) {
144 std::cout << e.what() << std::endl;
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);
178 pixmap->
pixels_m.back().computeBoundingBox();