mirror of
https://github.com/boostorg/gil.git
synced 2026-01-24 05:52:13 +00:00
Support construction from step_size, step_count, and a function for angles Implement angle and radious version of Hough line transform and adds a demo with static line that goes over secondary diagonal. Implement incremental line raster Implement naive line raster Implement Bresenham line raster Leave only Bresenham line rasterization Naive and incremental algorithms were removed because they are supposed to produce the same results anyway. The reason for diverging results is inaccuracy of floating point numbers Add circle rendering through trigonometric functions, using arctan(1 / (radius + 1)) as minimal angle step. Trigonometric circle rasterizer does not follow circle equation, but still produces very round shapes. A new testing methodology needs to be devised for this rasterizer. The new version accepts start and points inclusively and tries to use canonic representation during computations. Slope decided to be is (diff_y + 1) / (diff_x + 1).
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
// Boost.GIL (Generic Image Library) - tests
|
|
//
|
|
// Copyright 2020 Olzhas Zhumabek <anonymous.from.applecity@gmail.com>
|
|
//
|
|
// Use, modification and distribution are subject to the Boost Software License,
|
|
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
#include <boost/gil.hpp>
|
|
#include <boost/gil/extension/io/png.hpp>
|
|
|
|
#include <limits>
|
|
#include <vector>
|
|
|
|
namespace gil = boost::gil;
|
|
|
|
const std::ptrdiff_t size = 256;
|
|
|
|
void line_bresenham(std::ptrdiff_t width, std::ptrdiff_t height, const std::string& output_name)
|
|
{
|
|
const auto rasterizer = gil::bresenham_line_rasterizer{};
|
|
std::vector<gil::point_t> line_points(rasterizer.point_count(width, height));
|
|
|
|
gil::gray8_image_t image(size, size);
|
|
auto view = gil::view(image);
|
|
|
|
rasterizer({0, 0}, {width - 1, height - 1}, line_points.begin());
|
|
for (const auto& point : line_points)
|
|
{
|
|
view(point) = std::numeric_limits<gil::uint8_t>::max();
|
|
}
|
|
|
|
gil::write_view(output_name, view, gil::png_tag{});
|
|
}
|
|
|
|
int main()
|
|
{
|
|
line_bresenham(256, 256, "line-bresenham-256-256.png");
|
|
line_bresenham(256, 128, "line-bresenham-256-128.png");
|
|
line_bresenham(256, 1, "line-bresenham-256-1.png");
|
|
line_bresenham(1, 256, "line-bresenham-1-256.png");
|
|
}
|