mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 07:34:03 -06:00
Performance improvements of the MotionPlanner
(rewrote the Dijkstra shortest path algorithm to use a binary priority heap instead of a dumb O(n^2) algorithm, added some bounding box tests to avoid expensive in-polygon tests if possible).
This commit is contained in:
parent
8a628c451c
commit
60528c5c2a
8 changed files with 340 additions and 313 deletions
|
@ -2,11 +2,13 @@
|
|||
#define slic3r_MotionPlanner_hpp_
|
||||
|
||||
#include "libslic3r.h"
|
||||
#include "BoundingBox.hpp"
|
||||
#include "ClipperUtils.hpp"
|
||||
#include "ExPolygonCollection.hpp"
|
||||
#include "Polyline.hpp"
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#define MP_INNER_MARGIN scale_(1.0)
|
||||
|
@ -20,11 +22,12 @@ class MotionPlannerEnv
|
|||
{
|
||||
friend class MotionPlanner;
|
||||
|
||||
public:
|
||||
ExPolygon island;
|
||||
public:
|
||||
ExPolygon island;
|
||||
BoundingBox island_bbox;
|
||||
ExPolygonCollection env;
|
||||
MotionPlannerEnv() {};
|
||||
MotionPlannerEnv(const ExPolygon &island) : island(island) {};
|
||||
MotionPlannerEnv(const ExPolygon &island) : island(island), island_bbox(get_extents(island)) {};
|
||||
Point nearest_env_point(const Point &from, const Point &to) const;
|
||||
};
|
||||
|
||||
|
@ -32,43 +35,43 @@ class MotionPlannerGraph
|
|||
{
|
||||
friend class MotionPlanner;
|
||||
|
||||
private:
|
||||
typedef int node_t;
|
||||
typedef double weight_t;
|
||||
struct neighbor {
|
||||
node_t target;
|
||||
private:
|
||||
typedef int node_t;
|
||||
typedef double weight_t;
|
||||
struct Neighbor {
|
||||
node_t target;
|
||||
weight_t weight;
|
||||
neighbor(node_t arg_target, weight_t arg_weight)
|
||||
: target(arg_target), weight(arg_weight) { }
|
||||
Neighbor(node_t arg_target, weight_t arg_weight) : target(arg_target), weight(arg_weight) {}
|
||||
};
|
||||
typedef std::vector< std::vector<neighbor> > adjacency_list_t;
|
||||
typedef std::vector<std::vector<Neighbor>> adjacency_list_t;
|
||||
adjacency_list_t adjacency_list;
|
||||
|
||||
public:
|
||||
Points nodes;
|
||||
//std::map<std::pair<size_t,size_t>, double> edges;
|
||||
void add_edge(size_t from, size_t to, double weight);
|
||||
size_t find_node(const Point &point) const;
|
||||
Polyline shortest_path(size_t from, size_t to);
|
||||
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;
|
||||
};
|
||||
|
||||
class MotionPlanner
|
||||
{
|
||||
public:
|
||||
public:
|
||||
MotionPlanner(const ExPolygons &islands);
|
||||
~MotionPlanner();
|
||||
Polyline shortest_path(const Point &from, const Point &to);
|
||||
size_t islands_count() const;
|
||||
~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;
|
||||
|
||||
private:
|
||||
bool initialized;
|
||||
std::vector<MotionPlannerEnv> islands;
|
||||
MotionPlannerEnv outer;
|
||||
std::vector<MotionPlannerGraph*> graphs;
|
||||
|
||||
void initialize();
|
||||
MotionPlannerGraph* init_graph(int island_idx);
|
||||
const MotionPlannerEnv& get_env(int island_idx) const;
|
||||
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]; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue