summaryrefslogtreecommitdiff
path: root/matching/include/cell_with_value.h
blob: 25644d1de2d8cae910677ae44176e945e21a6a39 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// Created by narn on 16.07.19.
//

#ifndef MATCHING_DISTANCE_CELL_WITH_VALUE_H
#define MATCHING_DISTANCE_CELL_WITH_VALUE_H

#include <algorithm>

#include "common_defs.h"
#include "common_util.h"
#include "dual_box.h"

namespace md {

    enum class ValuePoint {
        center,
        lower_left,
        lower_right,
        upper_left,
        upper_right
    };

    std::ostream& operator<<(std::ostream& os, const ValuePoint& vp);

    const std::vector<ValuePoint> k_all_vps = {ValuePoint::center, ValuePoint::lower_left, ValuePoint::upper_left,
                       ValuePoint::upper_right, ValuePoint::lower_right};

    const std::vector<ValuePoint> k_corner_vps = {ValuePoint::lower_left, ValuePoint::upper_left,
                       ValuePoint::upper_right, ValuePoint::lower_right};

    // represents a cell in the dual space with the value
    // of the weighted bottleneck distance
    class CellWithValue {
    public:

        CellWithValue() = default;

        CellWithValue(const CellWithValue&) = default;

        CellWithValue(CellWithValue&&) = default;

        CellWithValue& operator=(const CellWithValue& other)& = default;

        CellWithValue& operator=(CellWithValue&& other) = default;

        CellWithValue(const DualBox& b, int level)
                :dual_box_(b), level_(level) { }

        DualBox dual_box() const { return dual_box_; }

        DualPoint center() const { return dual_box_.center(); }

        Real value_at(ValuePoint vp) const;

        bool has_value_at(ValuePoint vp) const;

        DualPoint value_point(ValuePoint vp) const;

        int level() const { return level_; }

        void set_value_at(ValuePoint vp, Real new_value);

        bool has_corner_value() const;

        Real stored_upper_bound() const;

        Real max_corner_value() const;

        Real min_value() const;

        bool has_max_possible_value() const { return has_max_possible_value_; }

        std::vector<CellWithValue> get_refined_cells() const;

        friend std::ostream& operator<<(std::ostream&, const CellWithValue&);

        void set_max_possible_value(Real new_upper_bound);

        int num_values() const;

#ifdef MD_DEBUG
        long long int id { 0 };

        static long long int max_id;

        std::vector<long long int> parent_ids;
#endif

    private:

        bool has_central_value() const { return central_value_ >= 0; }

        bool has_lower_left_value() const { return lower_left_value_ >= 0; }

        bool has_lower_right_value() const { return lower_right_value_ >= 0; }

        bool has_upper_left_value() const { return upper_left_value_ >= 0; }

        bool has_upper_right_value() const { return upper_right_value_ >= 0; }


        DualBox dual_box_;
        Real central_value_ {-1.0};
        Real lower_left_value_ {-1.0};
        Real lower_right_value_ {-1.0};
        Real upper_left_value_ {-1.0};
        Real upper_right_value_ {-1.0};

        Real max_possible_value_ {0.0};

        int level_ {0};

        bool has_max_possible_value_ {false};
    };

    std::ostream& operator<<(std::ostream& os, const CellWithValue& cell);
} // namespace md

#endif //MATCHING_DISTANCE_CELL_WITH_VALUE_H