31 const std::vector<bool>& pixels,
unsigned int N,
32 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;
57 bestUR.
y_m = y + height;
58 bestArea = height * (x - tmp.first);
61 }
while (!stack.empty() && cache[x] < height);
64 stack.push(std::make_pair(tmp.first, height));
70 std::pair<unsigned int, unsigned int> tmp = stack.top();
72 if (M > tmp.first && height * (M - tmp.first) > bestArea) {
73 bestLL.x_m = tmp.first;
76 bestUR.
y_m = y + height;
77 bestArea = height * (M - tmp.first);
82 return std::make_pair(bestLL, bestUR);
86 std::vector<bool> pixels,
unsigned int N,
88 std::vector<IntPixel_t> rectangles;
90 unsigned int maxArea = 0;
93 unsigned int area =
computeArea(pix.first, pix.second);
94 if (area > maxArea) maxArea = area;
95 if (1000 * area < maxArea || area <= 1) {
99 rectangles.push_back(pix);
101 for (
int y = pix.first.y_m; y < pix.second.y_m; ++y) {
102 unsigned int idx = y * M + pix.first.x_m;
103 for (
int x = pix.first.x_m; x < pix.second.x_m; ++x, ++idx) {
109 unsigned int idx = 0;
110 for (
unsigned int y = 0; y < N; ++y) {
111 for (
unsigned int x = 0; x < M; ++x, ++idx) {
124 Mask* pixmap =
static_cast<Mask*
>(fun);
127 std::string filename = arguments.
get(0);
128 if (filename[0] ==
'\'' && filename.back() ==
'\'') {
129 filename = filename.substr(1, filename.length() - 2);
132 if (!std::filesystem::exists(filename)) {
133 *ippl::Error <<
"file '" << filename <<
"' doesn't exists" << endl;
138 unsigned int width = reader.
getWidth();
139 unsigned int height = reader.
getHeight();
146 }
catch (std::runtime_error& e) {
147 std::cout << e.what() << std::endl;
151 if (pixel_width < 0.0) {
152 std::cout <<
"Mask: a negative width provided '" << arguments.
get(0) <<
" = "
153 << pixel_width * width <<
"'" << std::endl;
157 if (pixel_height < 0.0) {
158 std::cout <<
"Mask: a negative height provided '" << arguments.
get(1) <<
" = "
159 << pixel_height * height <<
"'" << std::endl;
173 double midX = 0.5 * (ur.
x_m + ll.
x_m);
174 double midY = 0.5 * (ur.
y_m + ll.
y_m);
180 pixmap->
pixels_m.back().computeBoundingBox();