PCB Environment 2

Loading...
Searching...
No Matches
Rasterizer.hpp
1#ifndef GYM_PCB_RASTERIZER_H
2#define GYM_PCB_RASTERIZER_H
3
8
9#include "UniformGrid25.hpp"
10#include "AShape.hpp"
11
12#define RASTERIZE_CAPS_MASK_SOURCE 0x1
13#define RASTERIZE_CAPS_MASK_TARGET 0x2
14
15#define RASTERIZE_CAPS_MASK_BOTH (RASTERIZE_CAPS_MASK_SOURCE | RASTERIZE_CAPS_MASK_TARGET)
16
17#define RASTERIZE_MASK_SEGMENTS 0x1
18#define RASTERIZE_MASK_VIAS 0x2
19#define RASTERIZE_MASK_CAPS 0x4
20#define RASTERIZE_MASK_JUNCTIONS 0x8
21#define RASTERIZE_MASK_ALL 0xf
22
23#define RASTERIZE_MASK_CAPS_AND_JUNCTIONS (RASTERIZE_MASK_CAPS | RASTERIZE_MASK_JUNCTIONS)
24
25 class Track;
26
27 struct IndexRange
28{
29 IndexRange(uint z0, uint z1, uint y0, uint y1, uint x0, uint x1) : Z0(z0), Z1(z1), Y0(y0), Y1(y0), X0(x0), X1(x1) { }
30 uint Z0, Z1;
31 uint Y0, Y1;
32 uint X0, X1;
33 uint countX() const { return X1 - X0 + 1; }
34 uint countY() const { return Y1 - Y0 + 1; }
35 uint countXY() const { return countX() * countY(); }
36 uint countZ() const { return Z1 - Z0 + 1; }
37 uint count() const { return countXY() * countZ(); }
38};
39
40 class BaseROP
41{
42 public:
43 void reserve(uint N) { }
44 virtual void writeRangeZYX(uint Z0, uint Z1, uint Y0, uint Y1, uint X0, uint X1) = 0;
45 void writeRangeZX(uint Z0, uint Z1, uint Y, uint X0, uint X1) { writeRangeZYX(Z0, Z1, Y, Y, X0, X1); }
46 void writeRangeZY(uint Z0, uint Z1, uint Y0, uint Y1, uint X) { writeRangeZYX(Z0, Z1, Y0, Y1, X, X); }
47 void writeRangeYX(uint Z, uint Y0, uint Y1, uint X0, uint X1) { writeRangeZYX(Z, Z, Y0, Y1, X0, X1); }
48 void writeRangeY(uint Z, uint Y0, uint Y1, uint X) { writeRangeZYX(Z, Z, Y0, Y1, X, X); }
49 void writeRangeX(uint Z, uint Y, uint X0, uint X1) { writeRangeZYX(Z, Z, Y, Y, X0, X1); }
50};
51 class RecordRangesROP final : public BaseROP
52{
53 public:
54 void reserve(uint N) { mRanges.reserve(mRanges.size() + N); }
55 void writeRangeZYX(uint Z0, uint Z1, uint Y0, uint Y1, uint X0, uint X1) override { mRanges.emplace_back(Z0, Z1, Y0, Y1, X0, X1); }
56 const std::vector<IndexRange>& getRanges() const { return mRanges; }
57 private:
58 std::vector<IndexRange> mRanges;
59};
60
61 template<class ROP> class Rasterizer
62{
63 public:
64 Rasterizer(const UniformGrid25 &G) : mGrid(G) { mTolerance = G.EdgeLen / 1024.0; }
65 ROP OP;
66
67 void setExpansion(Real s) { mExpansion = s; }
68
69 // Rules:
70 // * All shapes except segments are closed sets (bundaries included).
71 // * Fill uses the midpoint rule except when only 1 point is covered.
72 // * Segments are open sets on the sides and closed sets on the caps.
73
74 void rasterizeFill(const Bbox_2&, uint Z0, uint Z1);
75 void rasterizeLine(const Bbox_2&, uint Z0, uint Z1);
76 void rasterizeFill(const Segment_25&);
77 void rasterizeLine(const Segment_25&);
78 void rasterizeFill(const Segment_25&, uint Z0, uint Z1);
79 void rasterizeLine(const Segment_25&, uint Z0, uint Z1);
80 void rasterizeFill(const WideSegment_25&, uint capsMask = RASTERIZE_CAPS_MASK_BOTH);
81 void rasterizeLine(const WideSegment_25&, uint capsMask = RASTERIZE_CAPS_MASK_BOTH);
82 void rasterizeFill(const WideSegment_25&, uint capsMask, uint Z0, uint Z1);
83 void rasterizeLine(const WideSegment_25&, uint capsMask, uint Z0, uint Z1);
84 void rasterizeFill(const Circle_2&, uint Z0, uint Z1);
85 void rasterizeLine(const Circle_2&, uint Z0, uint Z1);
86 void rasterizeFill(const Triangle_2&, uint Z0, uint Z1);
87 void rasterizeLine(const Triangle_2&, uint Z0, uint Z1);
88 void rasterizeFill(const Polygon_2&, uint Z0, uint Z1);
89 void rasterizeLine(const Polygon_2&, uint Z0, uint Z1);
90
91 void rasterizeFill(const AShape *, uint Z0, uint Z1);
92 void rasterizeLine(const AShape *, uint Z0, uint Z1);
93
94 void rasterizeFill(const Track&, uint mask = RASTERIZE_MASK_ALL);
95 void rasterizeLine(const Track&);
96
97 void rasterizeRanges(const std::vector<IndexRange>&);
98
99 private:
100 void rasterizeDSegment(const Segment_2&, uint Z0, uint Z1, Real ex);
101 void rasterizeHSegment(const Segment_2&, uint Z0, uint Z1, Real ex);
102 void rasterizeVSegment(const Segment_2&, uint Z0, uint Z1, Real ex);
103 void rasterizeDSegmentLine(const Segment_2&, uint Z0, uint Z1);
104 void rasterizeHSegmentLine(const Segment_2&, uint Z0, uint Z1);
105 void rasterizeVSegmentLine(const Segment_2&, uint Z0, uint Z1);
106
107 private:
108 const UniformGrid25 &mGrid;
109 Real mExpansion{0.0};
110 Real mTolerance;
111};
112
113#endif // GYM_PCB_RASTERIZER_H
AShape
Definition AShape.hpp:21
BaseROP
Definition Rasterizer.hpp:41
RecordRangesROP
Definition Rasterizer.hpp:52
Segment_25
Definition Geometry.hpp:155
Track
Definition Track.hpp:21
UniformGrid25
Definition UniformGrid25.hpp:9
WideSegment_25
Definition AShape.hpp:332