DT algorithm by: Pedro Felzenszwalb
| 192 | |
| 193 | // DT algorithm by: Pedro Felzenszwalb |
| 194 | int8u* gradient_contour::contour_create(path_storage* ps) |
| 195 | { |
| 196 | int8u* result = NULL; |
| 197 | |
| 198 | if (ps) |
| 199 | { |
| 200 | // I. Render Black And White NonAA Stroke of the Path |
| 201 | // Path Bounding Box + Some Frame Space Around [configurable] |
| 202 | agg::conv_curve<agg::path_storage> conv(*ps); |
| 203 | |
| 204 | double x1, y1, x2, y2; |
| 205 | |
| 206 | if (agg::bounding_rect_single(conv, 0, &x1, &y1, &x2, &y2)) |
| 207 | { |
| 208 | // Create BW Rendering Surface |
| 209 | int width = int(ceil(x2 - x1)) + m_frame * 2 + 1; |
| 210 | int height = int(ceil(y2 - y1)) + m_frame * 2 + 1; |
| 211 | |
| 212 | int8u* buffer = new int8u[width * height]; |
| 213 | |
| 214 | if (buffer) |
| 215 | { |
| 216 | std::memset(buffer, 255, width * height); |
| 217 | |
| 218 | // Setup VG Engine & Render |
| 219 | agg::rendering_buffer rb; |
| 220 | rb.attach(buffer, width, height, width); |
| 221 | |
| 222 | agg::pixfmt_gray8 pf(rb); |
| 223 | agg::renderer_base<agg::pixfmt_gray8> renb(pf); |
| 224 | |
| 225 | agg::renderer_primitives< |
| 226 | agg::renderer_base<agg::pixfmt_gray8>> |
| 227 | prim(renb); |
| 228 | agg::rasterizer_outline<renderer_primitives< |
| 229 | agg::renderer_base<agg::pixfmt_gray8>>> |
| 230 | ras(prim); |
| 231 | |
| 232 | agg::trans_affine mtx; |
| 233 | mtx *= agg::trans_affine_translation( |
| 234 | -x1 + m_frame, -y1 + m_frame); |
| 235 | |
| 236 | agg::conv_transform<agg::conv_curve<agg::path_storage>> |
| 237 | trans(conv, mtx); |
| 238 | |
| 239 | prim.line_color(agg::rgba8(0, 0, 0, 255)); |
| 240 | ras.add_path(trans); |
| 241 | |
| 242 | // II. Distance Transform |
| 243 | // Create Float Buffer + 0 vs infinity assignment |
| 244 | float* image = new float[width * height]; |
| 245 | |
| 246 | if (image) |
| 247 | { |
| 248 | for (int y = 0, l = 0; y < height; y++) |
| 249 | { |
| 250 | for (int x = 0; x < width; x++, l++) |
| 251 | { |
nothing calls this directly
no test coverage detected