comparison OrthancStone/Sources/Toolbox/BucketAccumulator2D.h @ 1891:3716d72161d2

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Jan 2022 12:32:15 +0100
parents
children cdf91ad891a5
comparison
equal deleted inserted replaced
1890:6ce81914f7e4 1891:3716d72161d2
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 **/
22
23
24 #pragma once
25
26 #include "Internals/BucketMapper.h"
27
28 #include <list>
29 #include <vector>
30
31
32 namespace OrthancStone
33 {
34 class BucketAccumulator2D : public boost::noncopyable
35 {
36 private:
37 struct Bucket
38 {
39 size_t count_;
40 std::list<double> valuesX_;
41 std::list<double> valuesY_;
42 };
43
44 Internals::BucketMapper mapperX_;
45 Internals::BucketMapper mapperY_;
46 std::vector<Bucket> buckets_;
47 bool storeValues_;
48
49 size_t FindBestInternal() const;
50
51 size_t EncodeIndex(size_t x,
52 size_t y) const;
53
54 void DecodeIndex(size_t& x,
55 size_t& y,
56 size_t index) const;
57
58 public:
59 BucketAccumulator2D(double minValueX,
60 double maxValueX,
61 size_t countBucketsX,
62 double minValueY,
63 double maxValueY,
64 size_t countBucketsY,
65 bool storeValues);
66
67 void GetSize(size_t& x,
68 size_t& y) const;
69
70 double GetBucketLowX(size_t i) const
71 {
72 return mapperX_.GetBucketLow(i);
73 }
74
75 double GetBucketHighX(size_t i) const
76 {
77 return mapperX_.GetBucketHigh(i);
78 }
79
80 double GetBucketCenterX(size_t i) const
81 {
82 return mapperX_.GetBucketCenter(i);
83 }
84
85 double GetBucketLowY(size_t i) const
86 {
87 return mapperY_.GetBucketLow(i);
88 }
89
90 double GetBucketHighY(size_t i) const
91 {
92 return mapperY_.GetBucketHigh(i);
93 }
94
95 double GetBucketCenterY(size_t i) const
96 {
97 return mapperY_.GetBucketCenter(i);
98 }
99
100 size_t GetBucketContentSize(size_t x,
101 size_t y) const;
102
103 void GetBucketIndex(size_t& bucketX,
104 size_t& bucketY,
105 double valueX,
106 double valueY) const;
107
108 void AddValue(double valueX,
109 double valueY);
110
111 void FindBestBucket(size_t& bucketX,
112 size_t& bucketY) const
113 {
114 DecodeIndex(bucketX, bucketY, FindBestInternal());
115 }
116
117 void ComputeBestCenter(double& x,
118 double& y) const;
119
120 void ComputeBestMedian(double& x,
121 double& y) const;
122 };
123 }