-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathsurface_vectorial.hpp
More file actions
148 lines (129 loc) · 5.38 KB
/
Copy pathsurface_vectorial.hpp
File metadata and controls
148 lines (129 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* This file is part of pcb2gcode.
*
* Copyright (C) 2016 Nicola Corna <nicola@corna.info>
*
* pcb2gcode is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* pcb2gcode is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with pcb2gcode. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SURFACE_VECTORIAL_H
#define SURFACE_VECTORIAL_H
#include <vector>
#include <list>
#include <forward_list>
#include <map>
#include <algorithm>
using std::vector;
using std::list;
using std::forward_list;
using std::map;
using std::pair;
using std::copy;
using std::swap;
#include <fstream>
using std::ofstream;
#include <memory>
using std::shared_ptr;
using std::dynamic_pointer_cast;
using std::make_shared;
using std::make_pair;
#include <boost/noncopyable.hpp>
#include "mill.hpp"
#include "gerberimporter.hpp"
#include "core.hpp"
#include "voronoi.hpp"
#include "units.hpp"
/******************************************************************************/
/*
*/
/******************************************************************************/
class Surface_vectorial: public Core, virtual public boost::noncopyable
{
public:
Surface_vectorial(unsigned int points_per_circle, ivalue_t width, ivalue_t height,
string name, string outputdir, bool tsp_2opt, MillFeedDirection::MillFeedDirection mill_feed_direction);
vector<vector<shared_ptr<icoords>>> get_toolpath(shared_ptr<RoutingMill> mill,
bool mirror);
void save_debug_image(string message);
void enable_filling();
void add_mask(shared_ptr<Core> surface);
void render(shared_ptr<VectorialLayerImporter> importer);
inline ivalue_t get_width_in() {
return width_in;
}
inline ivalue_t get_height_in() {
return height_in;
}
protected:
vector<shared_ptr<icoords> > get_single_toolpath(
shared_ptr<RoutingMill> mill, bool mirror, double tool_diameter, double overlap_width);
const unsigned int points_per_circle;
const ivalue_t width_in;
const ivalue_t height_in;
const string name;
const string outputdir;
const bool tsp_2opt;
static unsigned int debug_image_index;
bool fill;
const MillFeedDirection::MillFeedDirection mill_feed_direction;
shared_ptr<multi_polygon_type_fp> vectorial_surface;
coordinate_type_fp scale;
box_type_fp bounding_box;
shared_ptr<Surface_vectorial> mask;
// Points that are very close to each other, probably because of a
// rounding error, are merged together to a single location.
static size_t merge_near_points(multi_linestring_type_fp& mls);
// Returns a minimal number of toolpaths that include all the
// milling in the oroginal toolpaths. Each path is traversed
// once.
multi_linestring_type_fp eulerian_paths(const multi_linestring_type_fp& toolpaths);
// Fill thermal reliefs in with a polygon of appropriate size so
// that they will get milled even in voronoi mode or if the offset
// is larger than the half the thickness of the thermal relief.
// Returns the number of thermal reliefs found and filled.
size_t preserve_thermal_reliefs(multi_polygon_type_fp& milling_surface, const coordinate_type_fp& tollerance);
vector<multi_polygon_type_fp> offset_polygon(
const polygon_type_fp& input,
const polygon_type_fp& voronoi,
bool& contentions, coordinate_type_fp scaled_diameter,
coordinate_type_fp scaled_overlap,
unsigned int steps, bool do_voronoi);
// Given a ring, attach it to one of the ends of the toolpath. Only attach if
// there is a point on the ring that is close enough to the toolpath endpoint.
static bool attach_ring(
const ring_type_fp& ring, linestring_type_fp& toolpath,
const coordinate_type_fp& max_distance, const MillFeedDirection::MillFeedDirection& dir);
// Given a ring, attach it to one of the toolpaths. Only attach if there is a
// point on the ring that is close enough to one of the toolpaths' endpoints.
// If none of the toolpaths have a close enough endpint, a new toolpath is added
// to the list of toolpaths.
void attach_ring(const ring_type_fp& ring, multi_linestring_type_fp& toolpaths,
const coordinate_type_fp& max_distance, const MillFeedDirection::MillFeedDirection& dir);
// Given polygons, attach all the rings inside to the toolpaths.
void attach_polygons(const multi_polygon_type_fp& polygons, multi_linestring_type_fp& toolpaths,
const coordinate_type_fp& max_distance, const MillFeedDirection::MillFeedDirection& dir);
};
class svg_writer
{
public:
svg_writer(string filename, coordinate_type_fp scale, box_type_fp bounding_box);
template <typename multi_polygon_type_t>
void add(const multi_polygon_type_t& geometry, double opacity, bool stroke);
void add(const vector<polygon_type_fp>& geometries, double opacity,
int r = -1, int g = -1, int b = -1);
protected:
ofstream output_file;
box_type_fp bounding_box;
unique_ptr<bg::svg_mapper<point_type_fp> > mapper;
};
#endif // SURFACE_VECTORIAL_H