2014-05-13 18:06:01 +00:00
|
|
|
#ifndef slic3r_MotionPlanner_hpp_
|
|
|
|
#define slic3r_MotionPlanner_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2017-05-05 07:59:56 +00:00
|
|
|
#include "BoundingBox.hpp"
|
2014-05-13 18:06:01 +00:00
|
|
|
#include "ClipperUtils.hpp"
|
|
|
|
#include "ExPolygonCollection.hpp"
|
|
|
|
#include "Polyline.hpp"
|
2014-05-28 08:16:58 +00:00
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
2017-05-05 07:59:56 +00:00
|
|
|
#include <memory>
|
2014-05-13 18:06:01 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#define MP_INNER_MARGIN scale_(1.0)
|
|
|
|
#define MP_OUTER_MARGIN scale_(2.0)
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2015-12-21 13:46:35 +00:00
|
|
|
class MotionPlanner;
|
2014-05-28 08:16:58 +00:00
|
|
|
|
2015-12-21 13:46:35 +00:00
|
|
|
class MotionPlannerEnv
|
2014-05-13 18:06:01 +00:00
|
|
|
{
|
2015-12-21 13:46:35 +00:00
|
|
|
friend class MotionPlanner;
|
2014-05-13 18:06:01 +00:00
|
|
|
|
2017-05-05 07:59:56 +00:00
|
|
|
public:
|
|
|
|
ExPolygon island;
|
|
|
|
BoundingBox island_bbox;
|
2015-12-21 13:46:35 +00:00
|
|
|
ExPolygonCollection env;
|
|
|
|
MotionPlannerEnv() {};
|
2017-05-05 07:59:56 +00:00
|
|
|
MotionPlannerEnv(const ExPolygon &island) : island(island), island_bbox(get_extents(island)) {};
|
2015-12-21 13:46:35 +00:00
|
|
|
Point nearest_env_point(const Point &from, const Point &to) const;
|
2014-05-28 08:16:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MotionPlannerGraph
|
|
|
|
{
|
2015-01-06 19:52:36 +00:00
|
|
|
friend class MotionPlanner;
|
|
|
|
|
2017-05-05 07:59:56 +00:00
|
|
|
private:
|
|
|
|
typedef int node_t;
|
|
|
|
typedef double weight_t;
|
|
|
|
struct Neighbor {
|
|
|
|
node_t target;
|
2014-05-28 08:16:58 +00:00
|
|
|
weight_t weight;
|
2017-05-05 07:59:56 +00:00
|
|
|
Neighbor(node_t arg_target, weight_t arg_weight) : target(arg_target), weight(arg_weight) {}
|
2014-05-28 08:16:58 +00:00
|
|
|
};
|
2017-05-05 07:59:56 +00:00
|
|
|
typedef std::vector<std::vector<Neighbor>> adjacency_list_t;
|
2014-05-28 08:16:58 +00:00
|
|
|
adjacency_list_t adjacency_list;
|
|
|
|
|
2017-05-05 07:59:56 +00:00
|
|
|
public:
|
|
|
|
Points nodes;
|
|
|
|
void add_edge(size_t from, size_t to, double weight);
|
|
|
|
size_t find_closest_node(const Point &point) const { return point.nearest_point_index(this->nodes); }
|
|
|
|
Polyline shortest_path(size_t from, size_t to) const;
|
2014-05-13 18:06:01 +00:00
|
|
|
};
|
|
|
|
|
2015-12-21 13:46:35 +00:00
|
|
|
class MotionPlanner
|
|
|
|
{
|
2017-05-05 07:59:56 +00:00
|
|
|
public:
|
2015-12-21 13:46:35 +00:00
|
|
|
MotionPlanner(const ExPolygons &islands);
|
2017-05-05 07:59:56 +00:00
|
|
|
~MotionPlanner() {}
|
|
|
|
|
|
|
|
Polyline shortest_path(const Point &from, const Point &to);
|
|
|
|
size_t islands_count() const { return this->islands.size(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool initialized;
|
|
|
|
std::vector<MotionPlannerEnv> islands;
|
|
|
|
MotionPlannerEnv outer;
|
|
|
|
std::vector<std::unique_ptr<MotionPlannerGraph>> graphs;
|
2015-12-21 13:46:35 +00:00
|
|
|
|
2017-05-05 07:59:56 +00:00
|
|
|
void initialize();
|
|
|
|
const MotionPlannerGraph& init_graph(int island_idx);
|
|
|
|
const MotionPlannerEnv& get_env(int island_idx) const
|
|
|
|
{ return (island_idx == -1) ? this->outer : this->islands[island_idx]; }
|
2015-12-21 13:46:35 +00:00
|
|
|
};
|
|
|
|
|
2014-05-13 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|