Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SLASpatIndex.hpp « SLA « libslic3r « src - github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 20b6fcd58938cacb354c575aab982decac86e470 (plain)
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
#ifndef SPATINDEX_HPP
#define SPATINDEX_HPP

#include <memory>
#include <utility>
#include <vector>

#include <Eigen/Geometry>

#include <libslic3r/BoundingBox.hpp>

namespace Slic3r {
namespace sla {

typedef Eigen::Matrix<double,   3, 1, Eigen::DontAlign> Vec3d;
using PointIndexEl = std::pair<Vec3d, unsigned>;

class PointIndex {
    class Impl;

    // We use Pimpl because it takes a long time to compile boost headers which
    // is the engine of this class. We include it only in the cpp file.
    std::unique_ptr<Impl> m_impl;
public:

    PointIndex();
    ~PointIndex();

    PointIndex(const PointIndex&);
    PointIndex(PointIndex&&);
    PointIndex& operator=(const PointIndex&);
    PointIndex& operator=(PointIndex&&);

    void insert(const PointIndexEl&);
    bool remove(const PointIndexEl&);

    inline void insert(const Vec3d& v, unsigned idx)
    {
        insert(std::make_pair(v, unsigned(idx)));
    }

    std::vector<PointIndexEl> query(std::function<bool(const PointIndexEl&)>) const;
    std::vector<PointIndexEl> nearest(const Vec3d&, unsigned k) const;
    std::vector<PointIndexEl> query(const Vec3d &v, unsigned k) const // wrapper
    {
        return nearest(v, k);
    }

    // For testing
    size_t size() const;
    bool empty() const { return size() == 0; }

    void foreach(std::function<void(const PointIndexEl& el)> fn);
    void foreach(std::function<void(const PointIndexEl& el)> fn) const;
};

using BoxIndexEl = std::pair<Slic3r::BoundingBox, unsigned>;

class BoxIndex {
    class Impl;
    
    // We use Pimpl because it takes a long time to compile boost headers which
    // is the engine of this class. We include it only in the cpp file.
    std::unique_ptr<Impl> m_impl;
public:
    
    BoxIndex();
    ~BoxIndex();
    
    BoxIndex(const BoxIndex&);
    BoxIndex(BoxIndex&&);
    BoxIndex& operator=(const BoxIndex&);
    BoxIndex& operator=(BoxIndex&&);
    
    void insert(const BoxIndexEl&);
    inline void insert(const BoundingBox& bb, unsigned idx)
    {
        insert(std::make_pair(bb, unsigned(idx)));
    }
    
    bool remove(const BoxIndexEl&);

    enum QueryType { qtIntersects, qtWithin };

    std::vector<BoxIndexEl> query(const BoundingBox&, QueryType qt);
    
    // For testing
    size_t size() const;
    bool empty() const { return size() == 0; }
    
    void foreach(std::function<void(const BoxIndexEl& el)> fn);
};

}
}

#endif // SPATINDEX_HPP