Geometrize  1.0
C++ library for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
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 
9 namespace geometrize
10 {
11 class Bitmap;
12 class Circle;
13 class Ellipse;
14 class Line;
15 class Polyline;
16 class QuadraticBezier;
17 class Shape;
18 class Rectangle;
19 class RotatedEllipse;
20 class RotatedRectangle;
21 class Triangle;
22 class Scanline;
23 }
24 
25 namespace geometrize
26 {
27 
33 std::vector<std::pair<float, float>> getCornerPoints(const geometrize::RotatedRectangle& r);
34 
40 std::vector<std::pair<float, float>> getPointsOnRotatedEllipse(const geometrize::RotatedEllipse& e, std::size_t numPoints);
41 
48 void drawLines(geometrize::Bitmap& image, geometrize::rgba color, const std::vector<geometrize::Scanline>& lines);
49 
56 void copyLines(geometrize::Bitmap& destination, const geometrize::Bitmap& source, const std::vector<geometrize::Scanline>& lines);
57 
66 std::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 
73 std::vector<geometrize::Scanline> scanlinesForPolygon(const std::vector<std::pair<float, float>>& points);
74 
75 std::vector<geometrize::Scanline> rasterize(const geometrize::Shape& s, std::int32_t xBound, std::int32_t yBound);
76 std::vector<geometrize::Scanline> rasterize(const geometrize::Circle& s, std::int32_t xBound, std::int32_t yBound);
77 std::vector<geometrize::Scanline> rasterize(const geometrize::Ellipse& s, std::int32_t xBound, std::int32_t yBound);
78 std::vector<geometrize::Scanline> rasterize(const geometrize::Line& s, std::int32_t xBound, std::int32_t yBound);
79 std::vector<geometrize::Scanline> rasterize(const geometrize::Polyline& s, std::int32_t xBound, std::int32_t yBound);
80 std::vector<geometrize::Scanline> rasterize(const geometrize::QuadraticBezier& s, std::int32_t xBound, std::int32_t yBound);
81 std::vector<geometrize::Scanline> rasterize(const geometrize::Rectangle& s, std::int32_t xBound, std::int32_t yBound);
82 std::vector<geometrize::Scanline> rasterize(const geometrize::RotatedEllipse& s, std::int32_t xBound, std::int32_t yBound);
83 std::vector<geometrize::Scanline> rasterize(const geometrize::RotatedRectangle& s, std::int32_t xBound, std::int32_t yBound);
84 std::vector<geometrize::Scanline> rasterize(const geometrize::Triangle& s, std::int32_t xBound, std::int32_t yBound);
85 
92 bool scanlinesOverlap(const std::vector<geometrize::Scanline>& first, const std::vector<geometrize::Scanline>& second);
93 
100 bool scanlinesContain(const std::vector<geometrize::Scanline>& first, const std::vector<geometrize::Scanline>& second);
101 
102 bool shapesOverlap(const geometrize::Shape& a, const geometrize::Shape& b, std::int32_t xBound, std::int32_t yBound);
103 bool shapeContains(const geometrize::Shape& container, const geometrize::Shape& containee, std::int32_t xBound, std::int32_t yBound);
104 
105 std::vector<std::pair<std::int32_t, std::int32_t>> shapeToPixels(const geometrize::Shape& shape, const std::uint32_t xBound, const std::uint32_t yBound);
106 
107 }
The RotatedEllipse class represents a rotated ellipse.
Definition: rotatedellipse.h:15
The Circle class represents a circle.
Definition: circle.h:15
The Line class represents a simple line.
Definition: line.h:15
The Rectangle class represents a rectangle.
Definition: rectangle.h:15
std::vector< geometrize::Scanline > rasterize(const geometrize::Shape &s, std::int32_t xBound, std::int32_t yBound)
Definition: rasterizer.cpp:194
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
bool shapesOverlap(const geometrize::Shape &a, const geometrize::Shape &b, const std::int32_t xBound, const std::int32_t yBound)
Definition: rasterizer.cpp:409
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:389
The Ellipse class represents an ellipse.
Definition: ellipse.h:15
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
The Triangle class represents a triangle.
Definition: triangle.h:15
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
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:375
std::vector< std::pair< std::int32_t, std::int32_t > > shapeToPixels(const geometrize::Shape &shape, const std::uint32_t xBound, const std::uint32_t yBound)
Definition: rasterizer.cpp:419
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
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
The Polyline class represents a polyline.
Definition: polyline.h:17
bool shapeContains(const geometrize::Shape &container, const geometrize::Shape &containee, const std::int32_t xBound, const std::int32_t yBound)
Definition: rasterizer.cpp:414
The Bitmap class is a helper class for working with bitmap data.
Definition: bitmap.h:15
The rgba struct is a helper for manipulating RGBA8888 color data.
Definition: rgba.h:12
The RotatedRectangle class represents a rotated rectangle.
Definition: rotatedrectangle.h:15
Definition: shape.h:17
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
The QuadraticBezier class represents a quadratic bezier curve.
Definition: quadraticbezier.h:15