summaryrefslogtreecommitdiff
path: root/geom_bottleneck/bottleneck/include/neighb_oracle.h
blob: f6f78b1f68c8ffbfacc915357729dd1364bc53d4 (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
/*
    Copyrigth 2015, D. Morozov, M. Kerber, A. Nigmetov

    This file is part of GeomBottleneck.

    GeomBottleneck is free software: you can redistribute it and/or modify
    it under the terms of the Lesser GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    GeomBottleneck 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
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with GeomBottleneck.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef NEIGHB_ORACLE_H
#define NEIGHB_ORACLE_H

#include <unordered_map>
#include "basic_defs_bt.h"
#include <ANN/ANN.h>

namespace geom_bt {
class NeighbOracleAbstract{
public:
    virtual void deletePoint(const DiagramPoint& p) = 0;
    virtual void rebuild(const DiagramPointSet& S, double rr) = 0;
    // return true, if r-neighbour of q exists in pointSet,
    // false otherwise.
    // the neighbour is returned in result
    virtual bool getNeighbour(const DiagramPoint& q, DiagramPoint& result) const = 0;
    virtual void getAllNeighbours(const DiagramPoint& q, std::vector<DiagramPoint>& result) = 0;
    virtual ~NeighbOracleAbstract() {};
protected:
    double r;
    double distEpsilon;
};

class NeighbOracleSimple : public NeighbOracleAbstract
{
public:
    NeighbOracleSimple();
    NeighbOracleSimple(const DiagramPointSet& S, const double rr, const double dEps);
    void deletePoint(const DiagramPoint& p);
    void rebuild(const DiagramPointSet& S, const double rr);
    bool getNeighbour(const DiagramPoint& q, DiagramPoint& result) const;
    void getAllNeighbours(const DiagramPoint& q, std::vector<DiagramPoint>& result);
    ~NeighbOracleSimple() {};
private:
    DiagramPointSet pointSet;
};

class NeighbOracleAnn : public NeighbOracleAbstract
{
public:
    NeighbOracleAnn(const DiagramPointSet& S, const double rr, const double dEps);
    void deletePoint(const DiagramPoint& p);
    void rebuild(const DiagramPointSet& S, const double rr);
    bool getNeighbour(const DiagramPoint& q, DiagramPoint& result) const;
    void getAllNeighbours(const DiagramPoint& q, std::vector<DiagramPoint>& result);
    ~NeighbOracleAnn();
//private:
    //DiagramPointSet originalPointSet;
    std::vector<DiagramPoint> allPoints;
    DiagramPointSet diagonalPoints;
    std::unordered_map<DiagramPoint, size_t, DiagramPointHash> pointIdxLookup;
    // ann-stuff
    static constexpr double annEpsilon {0};
    static const int annK {1};
    static const int annDim{2};
    ANNpointArray annPoints;
    ANNkd_tree* kdTree;
    ANNidxArray annNeigbIndices;
    ANNpoint annQueryPoint;
    // to use in getAllNeighbours
    ANNpoint lo;
    ANNpoint hi;
    ANNidxArray annIndices;
    ANNdistArray annDistances;
};

//typedef NeighbOracleSimple NeighbOracle;
typedef NeighbOracleAnn NeighbOracle;

}
#endif