Geometrize 1.0
C++ library for geometrizing images into geometric primitives
rasterizer.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <utility>
5#include <vector>
6
7#include "../bitmap/rgba.h"
8
9namespace geometrize
10{
11class Bitmap;
12class Circle;
13class Ellipse;
14class Line;
15class Polyline;
16class QuadraticBezier;
17class Shape;
18class Rectangle;
19class RotatedEllipse;
20class RotatedRectangle;
21class Triangle;
22class Scanline;
23}
24
25namespace geometrize
26{
27
33std::vector<std::pair<float, float>> getCornerPoints(const geometrize::RotatedRectangle& r);
34
40std::vector<std::pair<float, float>> getPointsOnRotatedEllipse(const geometrize::RotatedEllipse& e, std::size_t numPoints);
41
48void drawLines(geometrize::Bitmap& image, geometrize::rgba color, const std::vector<geometrize::Scanline>& lines);
49
56void copyLines(geometrize::Bitmap& destination, const geometrize::Bitmap& source, const std::vector<geometrize::Scanline>& lines);
57
66std::vector<std::pair<std::int32_t, std::int32_t>> bresenham(std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2);
67
73std::vector<geometrize::Scanline> scanlinesForPolygon(const std::vector<std::pair<float, float>>& points);
74
75std::vector<geometrize::Scanline> rasterize(const geometrize::Shape& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
76std::vector<geometrize::Scanline> rasterize(const geometrize::Circle& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
77std::vector<geometrize::Scanline> rasterize(const geometrize::Ellipse& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
78std::vector<geometrize::Scanline> rasterize(const geometrize::Line& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
79std::vector<geometrize::Scanline> rasterize(const geometrize::Polyline& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
80std::vector<geometrize::Scanline> rasterize(const geometrize::QuadraticBezier& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
81std::vector<geometrize::Scanline> rasterize(const geometrize::Rectangle& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
82std::vector<geometrize::Scanline> rasterize(const geometrize::RotatedEllipse& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
83std::vector<geometrize::Scanline> rasterize(const geometrize::RotatedRectangle& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
84std::vector<geometrize::Scanline> rasterize(const geometrize::Triangle& s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
85
92bool scanlinesOverlap(const std::vector<geometrize::Scanline>& first, const std::vector<geometrize::Scanline>& second);
93
100bool scanlinesContain(const std::vector<geometrize::Scanline>& first, const std::vector<geometrize::Scanline>& second);
101
102bool shapesOverlap(const geometrize::Shape& a, const geometrize::Shape& b, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
103bool shapeContains(const geometrize::Shape& container, const geometrize::Shape& containee, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
104
105std::vector<std::pair<std::int32_t, std::int32_t>> shapeToPixels(const geometrize::Shape& shape, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax);
106
107}
The Bitmap class is a helper class for working with bitmap data.
Definition: bitmap.h:16
The Circle class represents a circle.
Definition: circle.h:16
The Ellipse class represents an ellipse.
Definition: ellipse.h:16
The Line class represents a simple line.
Definition: line.h:16
The Polyline class represents a polyline.
Definition: polyline.h:18
The QuadraticBezier class represents a quadratic bezier curve.
Definition: quadraticbezier.h:16
The Rectangle class represents a rectangle.
Definition: rectangle.h:16
The RotatedEllipse class represents a rotated ellipse.
Definition: rotatedellipse.h:16
The RotatedRectangle class represents a rotated rectangle.
Definition: rotatedrectangle.h:16
Definition: shape.h:18
The Triangle class represents a triangle.
Definition: triangle.h:16
Definition: bitmap.cpp:8
std::vector< std::pair< float, float > > getPointsOnRotatedEllipse(const geometrize::RotatedEllipse &e, const std::size_t numPoints)
getPointsOnRotatedEllipse Calculates and returns a number of points on the given rotated ellipse.
Definition: rasterizer.cpp:57
std::vector< std::pair< std::int32_t, std::int32_t > > shapeToPixels(const geometrize::Shape &shape, const std::int32_t xMin, const std::int32_t yMin, const std::int32_t xMax, const std::int32_t yMax)
Definition: rasterizer.cpp:430
bool shapesOverlap(const geometrize::Shape &a, const geometrize::Shape &b, const std::int32_t xMin, const std::int32_t yMin, const std::int32_t xMax, const std::int32_t yMax)
Definition: rasterizer.cpp:420
std::vector< geometrize::Scanline > rasterize(const geometrize::Shape &s, std::int32_t xMin, std::int32_t yMin, std::int32_t xMax, std::int32_t yMax)
Definition: rasterizer.cpp:194
bool scanlinesContain(const std::vector< geometrize::Scanline > &first, const std::vector< geometrize::Scanline > &second)
scanlinesContain Returns true if the first vector of scanlines wholly contain the second vector of sc...
Definition: rasterizer.cpp:399
std::vector< std::pair< float, float > > getCornerPoints(const geometrize::RotatedRectangle &r)
getCornerPoints Gets the corner points of the given rotated rectangle.
Definition: rasterizer.cpp:30
std::vector< geometrize::Scanline > scanlinesForPolygon(const std::vector< std::pair< float, float > > &points)
scanlinesForPolygon Gets the scanlines for a series of points that make up an arbitrary polygon.
Definition: rasterizer.cpp:166
void drawLines(geometrize::Bitmap &image, const geometrize::rgba color, const std::vector< geometrize::Scanline > &lines)
drawLines Draws scanlines onto an image.
Definition: rasterizer.cpp:74
void copyLines(geometrize::Bitmap &destination, const geometrize::Bitmap &source, const std::vector< geometrize::Scanline > &lines)
copyLines Copies source pixels to a destination defined by a set of scanlines.
Definition: rasterizer.cpp:112
bool scanlinesOverlap(const std::vector< geometrize::Scanline > &first, const std::vector< geometrize::Scanline > &second)
scanlinesOverlap Returns true if any of the scanlines from the first vector overlap the second
Definition: rasterizer.cpp:385
bool shapeContains(const geometrize::Shape &container, const geometrize::Shape &containee, const std::int32_t xMin, const std::int32_t yMin, const std::int32_t xMax, const std::int32_t yMax)
Definition: rasterizer.cpp:425
std::vector< std::pair< std::int32_t, std::int32_t > > bresenham(std::int32_t x1, std::int32_t y1, const std::int32_t x2, const std::int32_t y2)
bresenham Bresenham's line algorithm. Returns the points on the line.
Definition: rasterizer.cpp:122
The rgba struct is a helper for manipulating RGBA8888 color data.
Definition: rgba.h:13