Mercurial > hg > orthanc-stone
annotate OrthancStone/UnitTestsSources/ComputationalGeometryTests.cpp @ 1960:40f8009ceb4e
added compatibility against release 1.10.1 of the DICOMweb plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Oct 2022 17:17:14 +0200 |
parents | 925aaf49150c |
children | 07964689cb0b |
rev | line source |
---|---|
1872 | 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 | |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
1872 | 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 | |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
16 * Lesser General Public License for more details. |
1872 | 17 * |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
19 * License along with this program. If not, see |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1872 | 21 **/ |
22 | |
23 | |
24 #include <gtest/gtest.h> | |
25 | |
1891 | 26 #include "../Sources/Toolbox/BucketAccumulator1D.h" |
27 #include "../Sources/Toolbox/BucketAccumulator2D.h" | |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
28 #include "../Sources/Toolbox/Internals/OrientedIntegerLine2D.h" |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
29 #include "../Sources/Toolbox/Internals/RectanglesIntegerProjection.h" |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
30 #include "../Sources/Toolbox/LinearAlgebra.h" |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
31 #include "../Sources/Toolbox/SegmentTree.h" |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1876
diff
changeset
|
32 #include "../Sources/Toolbox/UnionOfRectangles.h" |
1872 | 33 |
34 #include <Logging.h> | |
35 #include <OrthancException.h> | |
36 | |
37 | |
38 namespace | |
39 { | |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
40 typedef Orthanc::SingleValueObject<int> Counter; |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
41 |
1872 | 42 class CounterFactory : public OrthancStone::SegmentTree::IPayloadFactory |
43 { | |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
44 private: |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
45 int value_; |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
46 |
1872 | 47 public: |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
48 CounterFactory(int value) : |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
49 value_(value) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
50 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
51 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
52 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
53 virtual Orthanc::IDynamicObject* Create() ORTHANC_OVERRIDE |
1872 | 54 { |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
55 return new Counter(value_); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
56 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
57 }; |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
58 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
59 class IncrementVisitor : public OrthancStone::SegmentTree::IVisitor |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
60 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
61 private: |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
62 int increment_; |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
63 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
64 public: |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
65 IncrementVisitor(int increment) : |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
66 increment_(increment) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
67 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
68 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
69 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
70 virtual void Visit(const OrthancStone::SegmentTree& node, |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
71 bool fullyInside) ORTHANC_OVERRIDE |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
72 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
73 if (fullyInside) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
74 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
75 Counter& payload = node.GetTypedPayload<Counter>(); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
76 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
77 if (payload.GetValue() + increment_ < 0) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
78 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
80 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
81 else |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
82 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
83 payload.SetValue(payload.GetValue() + increment_); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
84 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
85 } |
1872 | 86 } |
87 }; | |
88 } | |
89 | |
90 | |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
91 TEST(SegmentTree, Create) |
1872 | 92 { |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
93 CounterFactory factory(42); |
1872 | 94 OrthancStone::SegmentTree root(4u, 15u, factory); // Check out Figure 1.1 (page 14) from textbook |
95 | |
96 ASSERT_EQ(4u, root.GetLowBound()); | |
97 ASSERT_EQ(15u, root.GetHighBound()); | |
98 ASSERT_FALSE(root.IsLeaf()); | |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
99 ASSERT_EQ(42, root.GetTypedPayload<Counter>().GetValue()); |
1872 | 100 ASSERT_EQ(21u, root.CountNodes()); |
101 | |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
102 const OrthancStone::SegmentTree* n = &root.GetLeftChild(); |
1872 | 103 ASSERT_EQ(4u, n->GetLowBound()); |
104 ASSERT_EQ(9u, n->GetHighBound()); | |
105 ASSERT_FALSE(n->IsLeaf()); | |
106 ASSERT_EQ(9u, n->CountNodes()); | |
107 | |
108 n = &root.GetLeftChild().GetLeftChild(); | |
109 ASSERT_EQ(4u, n->GetLowBound()); | |
110 ASSERT_EQ(6u, n->GetHighBound()); | |
111 ASSERT_FALSE(n->IsLeaf()); | |
112 ASSERT_EQ(3u, n->CountNodes()); | |
113 | |
114 n = &root.GetLeftChild().GetLeftChild().GetLeftChild(); | |
115 ASSERT_EQ(4u, n->GetLowBound()); | |
116 ASSERT_EQ(5u, n->GetHighBound()); | |
117 ASSERT_TRUE(n->IsLeaf()); | |
118 ASSERT_THROW(n->GetLeftChild(), Orthanc::OrthancException); | |
119 ASSERT_THROW(n->GetRightChild(), Orthanc::OrthancException); | |
120 ASSERT_EQ(1u, n->CountNodes()); | |
121 | |
122 n = &root.GetLeftChild().GetLeftChild().GetRightChild(); | |
123 ASSERT_EQ(5u, n->GetLowBound()); | |
124 ASSERT_EQ(6u, n->GetHighBound()); | |
125 ASSERT_TRUE(n->IsLeaf()); | |
126 ASSERT_EQ(1u, n->CountNodes()); | |
127 | |
128 n = &root.GetLeftChild().GetRightChild(); | |
129 ASSERT_EQ(6u, n->GetLowBound()); | |
130 ASSERT_EQ(9u, n->GetHighBound()); | |
131 ASSERT_FALSE(n->IsLeaf()); | |
132 ASSERT_EQ(5u, n->CountNodes()); | |
133 | |
134 n = &root.GetLeftChild().GetRightChild().GetLeftChild(); | |
135 ASSERT_EQ(6u, n->GetLowBound()); | |
136 ASSERT_EQ(7u, n->GetHighBound()); | |
137 ASSERT_TRUE(n->IsLeaf()); | |
138 ASSERT_EQ(1u, n->CountNodes()); | |
139 | |
140 n = &root.GetLeftChild().GetRightChild().GetRightChild(); | |
141 ASSERT_EQ(7u, n->GetLowBound()); | |
142 ASSERT_EQ(9u, n->GetHighBound()); | |
143 ASSERT_FALSE(n->IsLeaf()); | |
144 ASSERT_EQ(3u, n->CountNodes()); | |
145 | |
146 n = &root.GetLeftChild().GetRightChild().GetRightChild().GetLeftChild(); | |
147 ASSERT_EQ(7u, n->GetLowBound()); | |
148 ASSERT_EQ(8u, n->GetHighBound()); | |
149 ASSERT_TRUE(n->IsLeaf()); | |
150 ASSERT_EQ(1u, n->CountNodes()); | |
151 | |
152 n = &root.GetLeftChild().GetRightChild().GetRightChild().GetRightChild(); | |
153 ASSERT_EQ(8u, n->GetLowBound()); | |
154 ASSERT_EQ(9u, n->GetHighBound()); | |
155 ASSERT_TRUE(n->IsLeaf()); | |
156 ASSERT_EQ(1u, n->CountNodes()); | |
157 | |
158 n = &root.GetRightChild(); | |
159 ASSERT_EQ(9u, n->GetLowBound()); | |
160 ASSERT_EQ(15u, n->GetHighBound()); | |
161 ASSERT_FALSE(n->IsLeaf()); | |
162 ASSERT_EQ(11u, n->CountNodes()); | |
163 | |
164 n = &root.GetRightChild().GetLeftChild(); | |
165 ASSERT_EQ(9u, n->GetLowBound()); | |
166 ASSERT_EQ(12u, n->GetHighBound()); | |
167 ASSERT_FALSE(n->IsLeaf()); | |
168 ASSERT_EQ(5u, n->CountNodes()); | |
169 | |
170 n = &root.GetRightChild().GetLeftChild().GetLeftChild(); | |
171 ASSERT_EQ(9u, n->GetLowBound()); | |
172 ASSERT_EQ(10u, n->GetHighBound()); | |
173 ASSERT_TRUE(n->IsLeaf()); | |
174 ASSERT_EQ(1u, n->CountNodes()); | |
175 | |
176 n = &root.GetRightChild().GetLeftChild().GetRightChild(); | |
177 ASSERT_EQ(10u, n->GetLowBound()); | |
178 ASSERT_EQ(12u, n->GetHighBound()); | |
179 ASSERT_FALSE(n->IsLeaf()); | |
180 ASSERT_EQ(3u, n->CountNodes()); | |
181 | |
182 n = &root.GetRightChild().GetLeftChild().GetRightChild().GetLeftChild(); | |
183 ASSERT_EQ(10u, n->GetLowBound()); | |
184 ASSERT_EQ(11u, n->GetHighBound()); | |
185 ASSERT_TRUE(n->IsLeaf()); | |
186 ASSERT_EQ(1u, n->CountNodes()); | |
187 | |
188 n = &root.GetRightChild().GetLeftChild().GetRightChild().GetRightChild(); | |
189 ASSERT_EQ(11u, n->GetLowBound()); | |
190 ASSERT_EQ(12u, n->GetHighBound()); | |
191 ASSERT_TRUE(n->IsLeaf()); | |
192 ASSERT_EQ(1u, n->CountNodes()); | |
193 | |
194 n = &root.GetRightChild().GetRightChild(); | |
195 ASSERT_EQ(12u, n->GetLowBound()); | |
196 ASSERT_EQ(15u, n->GetHighBound()); | |
197 ASSERT_FALSE(n->IsLeaf()); | |
198 ASSERT_EQ(5u, n->CountNodes()); | |
199 | |
200 n = &root.GetRightChild().GetRightChild().GetLeftChild(); | |
201 ASSERT_EQ(12u, n->GetLowBound()); | |
202 ASSERT_EQ(13u, n->GetHighBound()); | |
203 ASSERT_TRUE(n->IsLeaf()); | |
204 ASSERT_EQ(1u, n->CountNodes()); | |
205 | |
206 n = &root.GetRightChild().GetRightChild().GetRightChild(); | |
207 ASSERT_EQ(13u, n->GetLowBound()); | |
208 ASSERT_EQ(15u, n->GetHighBound()); | |
209 ASSERT_FALSE(n->IsLeaf()); | |
210 ASSERT_EQ(3u, n->CountNodes()); | |
211 | |
212 n = &root.GetRightChild().GetRightChild().GetRightChild().GetLeftChild(); | |
213 ASSERT_EQ(13u, n->GetLowBound()); | |
214 ASSERT_EQ(14u, n->GetHighBound()); | |
215 ASSERT_TRUE(n->IsLeaf()); | |
216 ASSERT_EQ(1u, n->CountNodes()); | |
217 | |
218 n = &root.GetRightChild().GetRightChild().GetRightChild().GetRightChild(); | |
219 ASSERT_EQ(14u, n->GetLowBound()); | |
220 ASSERT_EQ(15u, n->GetHighBound()); | |
221 ASSERT_TRUE(n->IsLeaf()); | |
222 ASSERT_EQ(1u, n->CountNodes()); | |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
223 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
224 ASSERT_TRUE(root.FindLeaf(3) == NULL); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
225 for (size_t i = 4; i < 15; i++) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
226 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
227 n = root.FindLeaf(i); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
228 ASSERT_TRUE(n != NULL); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
229 ASSERT_TRUE(n->IsLeaf()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
230 ASSERT_EQ(i, n->GetLowBound()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
231 ASSERT_EQ(i + 1, n->GetHighBound()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
232 ASSERT_EQ(42, n->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
233 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
234 ASSERT_TRUE(root.FindLeaf(15) == NULL); |
1872 | 235 } |
1873
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
236 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
237 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
238 static bool CheckCounter(const OrthancStone::SegmentTree& node, |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
239 int expectedValue) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
240 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
241 if (node.GetTypedPayload<Counter>().GetValue() != expectedValue) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
242 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
243 return false; |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
244 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
245 else if (node.IsLeaf()) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
246 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
247 return true; |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
248 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
249 else |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
250 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
251 return (CheckCounter(node.GetLeftChild(), expectedValue) && |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
252 CheckCounter(node.GetRightChild(), expectedValue)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
253 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
254 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
255 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
256 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
257 #if 0 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
258 static void Print(const OrthancStone::SegmentTree& node, |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
259 unsigned int indent) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
260 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
261 for (size_t i = 0; i < indent; i++) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
262 printf(" "); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
263 printf("(%lu,%lu): %d\n", node.GetLowBound(), node.GetHighBound(), node.GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
264 if (!node.IsLeaf()) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
265 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
266 Print(node.GetLeftChild(), indent + 1); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
267 Print(node.GetRightChild(), indent + 1); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
268 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
269 } |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
270 #endif |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
271 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
272 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
273 TEST(SegmentTree, Visit) |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
274 { |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
275 CounterFactory factory(0); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
276 OrthancStone::SegmentTree root(4u, 15u, factory); // Check out Figure 1.1 (page 14) from textbook |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
277 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
278 ASSERT_TRUE(CheckCounter(root, 0)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
279 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
280 IncrementVisitor plus(1); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
281 IncrementVisitor minus(-1); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
282 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
283 root.VisitSegment(0, 20, plus); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
284 ASSERT_EQ(1, root.GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
285 ASSERT_TRUE(CheckCounter(root.GetLeftChild(), 0)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
286 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
287 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
288 root.VisitSegment(0, 20, plus); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
289 ASSERT_EQ(2, root.GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
290 ASSERT_TRUE(CheckCounter(root.GetLeftChild(), 0)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
291 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
292 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
293 root.VisitSegment(0, 20, minus); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
294 root.VisitSegment(0, 20, minus); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
295 ASSERT_TRUE(CheckCounter(root, 0)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
296 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
297 root.VisitSegment(8, 11, plus); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
298 ASSERT_EQ(0, root.FindNode(4, 15)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
299 ASSERT_EQ(0, root.FindNode(4, 9)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
300 ASSERT_EQ(0, root.FindNode(4, 6)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
301 ASSERT_EQ(0, root.FindNode(4, 5)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
302 ASSERT_EQ(0, root.FindNode(5, 6)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
303 ASSERT_EQ(0, root.FindNode(6, 9)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
304 ASSERT_EQ(0, root.FindNode(6, 7)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
305 ASSERT_EQ(0, root.FindNode(7, 9)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
306 ASSERT_EQ(0, root.FindNode(7, 8)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
307 ASSERT_EQ(1, root.FindNode(8, 9)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
308 ASSERT_EQ(0, root.FindNode(9, 15)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
309 ASSERT_EQ(0, root.FindNode(9, 12)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
310 ASSERT_EQ(1, root.FindNode(9, 10)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
311 ASSERT_EQ(0, root.FindNode(10, 12)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
312 ASSERT_EQ(1, root.FindNode(10, 11)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
313 ASSERT_EQ(0, root.FindNode(11, 12)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
314 ASSERT_EQ(0, root.FindNode(12, 15)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
315 ASSERT_EQ(0, root.FindNode(12, 13)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
316 ASSERT_EQ(0, root.FindNode(13, 15)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
317 ASSERT_EQ(0, root.FindNode(13, 14)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
318 ASSERT_EQ(0, root.FindNode(14, 15)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
319 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
320 root.VisitSegment(9, 11, minus); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
321 ASSERT_EQ(0, root.FindNode(4, 15)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
322 ASSERT_EQ(0, root.FindNode(4, 9)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
323 ASSERT_EQ(0, root.FindNode(4, 6)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
324 ASSERT_EQ(0, root.FindNode(4, 5)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
325 ASSERT_EQ(0, root.FindNode(5, 6)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
326 ASSERT_EQ(0, root.FindNode(6, 9)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
327 ASSERT_EQ(0, root.FindNode(6, 7)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
328 ASSERT_EQ(0, root.FindNode(7, 9)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
329 ASSERT_EQ(0, root.FindNode(7, 8)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
330 ASSERT_EQ(1, root.FindNode(8, 9)->GetTypedPayload<Counter>().GetValue()); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
331 ASSERT_TRUE(CheckCounter(root.GetRightChild(), 0)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
332 |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
333 root.VisitSegment(8, 9, minus); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
334 ASSERT_TRUE(CheckCounter(root, 0)); |
e0966648ebd0
unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1872
diff
changeset
|
335 } |
1874
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
336 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
337 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
338 TEST(UnionOfRectangles, RectanglesIntegerProjection) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
339 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
340 std::list<OrthancStone::Extent2D> rectangles; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
341 rectangles.push_back(OrthancStone::Extent2D(10, 20, 30, 40)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
342 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
343 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
344 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, true); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
345 ASSERT_EQ(2u, h.GetEndpointsCount()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
346 ASSERT_EQ(10, h.GetEndpointCoordinate(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
347 ASSERT_EQ(30, h.GetEndpointCoordinate(1)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
348 ASSERT_EQ(1u, h.GetProjectedRectanglesCount()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
349 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
350 ASSERT_EQ(1u, h.GetProjectedRectangleHigh(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
351 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
352 ASSERT_THROW(h.GetEndpointCoordinate(2), Orthanc::OrthancException); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
353 ASSERT_THROW(h.GetProjectedRectangleLow(1), Orthanc::OrthancException); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
354 ASSERT_THROW(h.GetProjectedRectangleHigh(1), Orthanc::OrthancException); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
355 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
356 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
357 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
358 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, false); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
359 ASSERT_EQ(2u, h.GetEndpointsCount()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
360 ASSERT_EQ(20, h.GetEndpointCoordinate(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
361 ASSERT_EQ(40, h.GetEndpointCoordinate(1)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
362 ASSERT_EQ(1u, h.GetProjectedRectanglesCount()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
363 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
364 ASSERT_EQ(1u, h.GetProjectedRectangleHigh(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
365 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
366 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
367 rectangles.push_back(OrthancStone::Extent2D(20, 30, 40, 50)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
368 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
369 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
370 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, true); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
371 ASSERT_EQ(4u, h.GetEndpointsCount()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
372 ASSERT_EQ(10, h.GetEndpointCoordinate(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
373 ASSERT_EQ(20, h.GetEndpointCoordinate(1)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
374 ASSERT_EQ(30, h.GetEndpointCoordinate(2)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
375 ASSERT_EQ(40, h.GetEndpointCoordinate(3)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
376 ASSERT_EQ(2u, h.GetProjectedRectanglesCount()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
377 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
378 ASSERT_EQ(2u, h.GetProjectedRectangleHigh(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
379 ASSERT_EQ(1u, h.GetProjectedRectangleLow(1)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
380 ASSERT_EQ(3u, h.GetProjectedRectangleHigh(1)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
381 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
382 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
383 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
384 OrthancStone::Internals::RectanglesIntegerProjection h(rectangles, false); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
385 ASSERT_EQ(4u, h.GetEndpointsCount()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
386 ASSERT_EQ(20, h.GetEndpointCoordinate(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
387 ASSERT_EQ(30, h.GetEndpointCoordinate(1)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
388 ASSERT_EQ(40, h.GetEndpointCoordinate(2)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
389 ASSERT_EQ(50, h.GetEndpointCoordinate(3)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
390 ASSERT_EQ(2u, h.GetProjectedRectanglesCount()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
391 ASSERT_EQ(0u, h.GetProjectedRectangleLow(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
392 ASSERT_EQ(2u, h.GetProjectedRectangleHigh(0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
393 ASSERT_EQ(1u, h.GetProjectedRectangleLow(1)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
394 ASSERT_EQ(3u, h.GetProjectedRectangleHigh(1)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
395 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
396 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
397 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
398 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
399 static void Convert(std::vector<size_t>& horizontal, |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
400 std::vector<size_t>& vertical, |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
401 const OrthancStone::Internals::OrientedIntegerLine2D::Chain& chain) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
402 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
403 horizontal.clear(); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
404 vertical.clear(); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
405 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
406 for (OrthancStone::Internals::OrientedIntegerLine2D::Chain::const_iterator |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
407 it = chain.begin(); it != chain.end(); ++it) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
408 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
409 horizontal.push_back(it->first); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
410 vertical.push_back(it->second); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
411 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
412 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
413 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
414 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
415 TEST(UnionOfRectangles, ExtractChains) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
416 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
417 std::vector<OrthancStone::Internals::OrientedIntegerLine2D> edges; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
418 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(0, 0, 10, 0)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
419 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(10, 0, 10, 20)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
420 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(10, 20, 0, 20)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
421 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
422 std::list<OrthancStone::Internals::OrientedIntegerLine2D::Chain> chains; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
423 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
424 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
425 std::vector<size_t> h, v; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
426 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
427 ASSERT_EQ(1u, chains.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
428 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
429 Convert(h, v, chains.front()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
430 ASSERT_EQ(4u, h.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
431 ASSERT_EQ(0u, h[0]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
432 ASSERT_EQ(10u, h[1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
433 ASSERT_EQ(10u, h[2]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
434 ASSERT_EQ(0u, h[3]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
435 ASSERT_EQ(4u, v.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
436 ASSERT_EQ(0u, v[0]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
437 ASSERT_EQ(0u, v[1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
438 ASSERT_EQ(20u, v[2]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
439 ASSERT_EQ(20u, v[3]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
440 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
441 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(5, 5, 10, 5)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
442 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
443 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
444 ASSERT_EQ(2u, chains.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
445 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
446 Convert(h, v, chains.front()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
447 ASSERT_EQ(4u, h.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
448 ASSERT_EQ(0u, h[0]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
449 ASSERT_EQ(10u, h[1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
450 ASSERT_EQ(10u, h[2]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
451 ASSERT_EQ(0u, h[3]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
452 ASSERT_EQ(4u, v.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
453 ASSERT_EQ(0u, v[0]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
454 ASSERT_EQ(0u, v[1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
455 ASSERT_EQ(20u, v[2]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
456 ASSERT_EQ(20u, v[3]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
457 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
458 Convert(h, v, chains.back()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
459 ASSERT_EQ(2u, h.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
460 ASSERT_EQ(5u, h[0]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
461 ASSERT_EQ(10u, h[1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
462 ASSERT_EQ(2u, v.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
463 ASSERT_EQ(5u, v[0]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
464 ASSERT_EQ(5u, v[1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
465 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
466 edges.push_back(OrthancStone::Internals::OrientedIntegerLine2D(0, 20, 5, 5)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
467 OrthancStone::Internals::OrientedIntegerLine2D::ExtractChains(chains, edges); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
468 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
469 ASSERT_EQ(1u, chains.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
470 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
471 Convert(h, v, chains.front()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
472 ASSERT_EQ(6u, h.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
473 ASSERT_EQ(0u, h[0]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
474 ASSERT_EQ(10u, h[1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
475 ASSERT_EQ(10u, h[2]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
476 ASSERT_EQ(0u, h[3]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
477 ASSERT_EQ(5u, h[4]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
478 ASSERT_EQ(10u, h[5]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
479 ASSERT_EQ(6u, v.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
480 ASSERT_EQ(0u, v[0]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
481 ASSERT_EQ(0u, v[1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
482 ASSERT_EQ(20u, v[2]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
483 ASSERT_EQ(20u, v[3]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
484 ASSERT_EQ(5u, v[4]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
485 ASSERT_EQ(5u, v[5]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1873
diff
changeset
|
486 } |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
487 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
488 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
489 TEST(UnionOfRectangles, Textbook) |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
490 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
491 // This is Figure 8.12 from textbook |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
492 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
493 std::list<OrthancStone::Extent2D> rectangles; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
494 rectangles.push_back(OrthancStone::Extent2D(1, 3, 13, 5)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
495 rectangles.push_back(OrthancStone::Extent2D(3, 1, 7, 12)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
496 rectangles.push_back(OrthancStone::Extent2D(5, 7, 11, 10)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
497 rectangles.push_back(OrthancStone::Extent2D(10, 2, 14, 8)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
498 rectangles.push_back(OrthancStone::Extent2D(3, 3, 4, 3)); // empty rectangle |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
499 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
500 for (unsigned int fillHole = 0; fillHole < 2; fillHole++) |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
501 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
502 if (fillHole) |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
503 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
504 rectangles.push_back(OrthancStone::Extent2D(6.5, 4.5, 10.5, 7.5)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
505 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
506 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
507 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
508 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
509 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
510 ASSERT_EQ(fillHole ? 1u : 2u, contours.size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
511 ASSERT_EQ(17u, contours.front().size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
512 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(3, 12))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
513 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 12))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
514 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 10))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
515 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(11, 10))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
516 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(11, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
517 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(14, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
518 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(14, 2))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
519 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(10, 2))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
520 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(10, 3))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
521 ASSERT_TRUE(contours.front()[9].IsEqual(OrthancStone::ScenePoint2D(7, 3))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
522 ASSERT_TRUE(contours.front()[10].IsEqual(OrthancStone::ScenePoint2D(7, 1))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
523 ASSERT_TRUE(contours.front()[11].IsEqual(OrthancStone::ScenePoint2D(3, 1))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
524 ASSERT_TRUE(contours.front()[12].IsEqual(OrthancStone::ScenePoint2D(3, 3))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
525 ASSERT_TRUE(contours.front()[13].IsEqual(OrthancStone::ScenePoint2D(1, 3))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
526 ASSERT_TRUE(contours.front()[14].IsEqual(OrthancStone::ScenePoint2D(1, 5))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
527 ASSERT_TRUE(contours.front()[15].IsEqual(OrthancStone::ScenePoint2D(3, 5))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
528 ASSERT_TRUE(contours.front()[16].IsEqual(OrthancStone::ScenePoint2D(3, 12))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
529 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
530 if (!fillHole) |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
531 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
532 ASSERT_EQ(5u, contours.back().size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
533 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(10, 7))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
534 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(7, 7))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
535 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(7, 5))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
536 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(10, 5))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
537 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(10, 7))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
538 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
539 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
540 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
541 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
542 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
543 #if 0 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
544 static void SaveSvg(const std::list< std::vector<OrthancStone::ScenePoint2D> >& contours) |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
545 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
546 float ww = 15; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
547 float hh = 13; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
548 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
549 FILE* fp = fopen("test.svg", "w"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
550 fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
551 fprintf(fp, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
552 fprintf(fp, "<svg width=\"%f\" height=\"%f\" viewBox=\"0 0 %f %f\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", 100.0f*ww, 100.0f*hh, ww, hh); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
553 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
554 // http://thenewcode.com/1068/Making-Arrows-in-SVG |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
555 fprintf(fp, "<defs>\n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
556 fprintf(fp, "<marker id=\"arrowhead\" markerWidth=\"2\" markerHeight=\"3\" \n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
557 fprintf(fp, "refX=\"2\" refY=\"1.5\" orient=\"auto\">\n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
558 fprintf(fp, "<polygon points=\"0 0, 2 1.5, 0 3\" />\n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
559 fprintf(fp, "</marker>\n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
560 fprintf(fp, "</defs>\n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
561 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
562 fprintf(fp, "<rect fill=\"#fff\" stroke=\"#000\" x=\"0\" y=\"0\" width=\"%f\" height=\"%f\"/>\n", ww, hh); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
563 |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
564 unsigned int count = 0; |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
565 |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
566 for (std::list< std::vector<OrthancStone::ScenePoint2D> >::const_iterator |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
567 it = contours.begin(); it != contours.end(); ++it, count++) |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
568 { |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
569 std::string color; |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
570 if (count == 0) |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
571 { |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
572 color = "blue"; |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
573 } |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
574 else if (count == 1) |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
575 { |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
576 color = "red"; |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
577 } |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
578 else if (count == 2) |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
579 { |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
580 color = "green"; |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
581 } |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
582 else if (count == 3) |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
583 { |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
584 color = "orange"; |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
585 } |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
586 else |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
587 { |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
588 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
589 } |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
590 |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
591 for (size_t i = 0; i + 1 < it->size(); i++) |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
592 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
593 float x1 = (*it)[i].GetX(); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
594 float x2 = (*it)[i + 1].GetX(); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
595 float y1 = (*it)[i].GetY(); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
596 float y2 = (*it)[i + 1].GetY(); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
597 |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
598 fprintf(fp, "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" stroke=\"%s\" stroke-width=\"0.05\" marker-end=\"url(#arrowhead)\"/>\n", x1, y1, x2, y2, color.c_str()); |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
599 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
600 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
601 fprintf(fp, "</svg>\n"); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
602 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
603 fclose(fp); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
604 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
605 #endif |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
606 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
607 |
1876 | 608 TEST(UnionOfRectangles, EdgeCases) |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
609 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
610 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
611 std::list<OrthancStone::Extent2D> rectangles; |
1876 | 612 |
613 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
614 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
615 | |
616 ASSERT_EQ(0u, contours.size()); | |
617 } | |
618 | |
619 { | |
620 std::list<OrthancStone::Extent2D> rectangles; | |
621 rectangles.push_back(OrthancStone::Extent2D(3, 3, 4, 3)); // empty rectangle | |
622 | |
623 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
624 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
625 | |
626 ASSERT_EQ(0u, contours.size()); | |
627 } | |
628 | |
629 { | |
630 std::list<OrthancStone::Extent2D> rectangles; | |
631 rectangles.push_back(OrthancStone::Extent2D(1, 1, 2, 2)); | |
632 | |
633 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
634 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
635 | |
636 ASSERT_EQ(1u, contours.size()); | |
637 ASSERT_EQ(5u, contours.front().size()); | |
638 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 2))); | |
639 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
640 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(2, 1))); | |
641 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(1, 1))); | |
642 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(1, 2))); | |
643 } | |
644 | |
645 { | |
646 std::list<OrthancStone::Extent2D> rectangles; | |
647 rectangles.push_back(OrthancStone::Extent2D(1, 1, 2, 2)); | |
648 rectangles.push_back(OrthancStone::Extent2D(1, 3, 2, 4)); | |
649 | |
650 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
651 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
652 | |
653 ASSERT_EQ(2u, contours.size()); | |
654 | |
655 ASSERT_EQ(5u, contours.front().size()); | |
656 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 4))); | |
657 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(2, 4))); | |
658 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(2, 3))); | |
659 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(1, 3))); | |
660 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(1, 4))); | |
661 | |
662 ASSERT_EQ(5u, contours.back().size()); | |
663 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(1, 2))); | |
664 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
665 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(2, 1))); | |
666 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(1, 1))); | |
667 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(1, 2))); | |
668 } | |
669 | |
670 { | |
671 std::list<OrthancStone::Extent2D> rectangles; | |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
672 rectangles.push_back(OrthancStone::Extent2D(1, 4, 4, 6)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
673 rectangles.push_back(OrthancStone::Extent2D(4, 6, 7, 8)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
674 rectangles.push_back(OrthancStone::Extent2D(4, 2, 7, 4)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
675 rectangles.push_back(OrthancStone::Extent2D(7, 4, 10, 6)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
676 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
677 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
678 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
679 |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
680 ASSERT_EQ(2u, contours.size()); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
681 |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
682 ASSERT_EQ(9u, contours.front().size()); |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
683 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(4, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
684 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
685 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 6))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
686 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(10, 6))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
687 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(10, 4))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
688 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(7, 4))); |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
689 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(7, 6))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
690 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(4, 6))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
691 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(4, 8))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
692 |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
693 ASSERT_EQ(9u, contours.back().size()); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
694 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(1, 6))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
695 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(4, 6))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
696 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(4, 4))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
697 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(7, 4))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
698 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(7, 2))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
699 ASSERT_TRUE(contours.back()[5].IsEqual(OrthancStone::ScenePoint2D(4, 2))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
700 ASSERT_TRUE(contours.back()[6].IsEqual(OrthancStone::ScenePoint2D(4, 4))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
701 ASSERT_TRUE(contours.back()[7].IsEqual(OrthancStone::ScenePoint2D(1, 4))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
702 ASSERT_TRUE(contours.back()[8].IsEqual(OrthancStone::ScenePoint2D(1, 6))); |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
703 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
704 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
705 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
706 std::list<OrthancStone::Extent2D> rectangles; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
707 rectangles.push_back(OrthancStone::Extent2D(1, 4, 4, 6)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
708 rectangles.push_back(OrthancStone::Extent2D(4, 4, 7, 6)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
709 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
710 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
711 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
712 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
713 ASSERT_EQ(1u, contours.size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
714 ASSERT_EQ(5u, contours.front().size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
715 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 6))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
716 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 6))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
717 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 4))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
718 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(1, 4))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
719 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(1, 6))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
720 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
721 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
722 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
723 std::list<OrthancStone::Extent2D> rectangles; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
724 rectangles.push_back(OrthancStone::Extent2D(1, 4, 4, 6)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
725 rectangles.push_back(OrthancStone::Extent2D(1, 6, 4, 8)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
726 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
727 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
728 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
729 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
730 ASSERT_EQ(1u, contours.size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
731 ASSERT_EQ(5u, contours.front().size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
732 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
733 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(4, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
734 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(4, 4))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
735 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(1, 4))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
736 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(1, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
737 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
738 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
739 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
740 std::list<OrthancStone::Extent2D> rectangles; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
741 rectangles.push_back(OrthancStone::Extent2D(1, 1, 2, 2)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
742 rectangles.push_back(OrthancStone::Extent2D(4, 4, 7, 6)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
743 rectangles.push_back(OrthancStone::Extent2D(4, 6, 7, 8)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
744 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
745 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
746 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
747 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
748 ASSERT_EQ(2u, contours.size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
749 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
750 ASSERT_EQ(5u, contours.front().size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
751 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(4, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
752 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
753 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 4))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
754 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 4))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
755 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
756 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
757 ASSERT_EQ(5u, contours.back().size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
758 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(1, 2))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
759 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(2, 2))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
760 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(2, 1))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
761 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(1, 1))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
762 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(1, 2))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
763 } |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
764 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
765 { |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
766 std::list<OrthancStone::Extent2D> rectangles; |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
767 rectangles.push_back(OrthancStone::Extent2D(1, 4, 5, 6)); |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
768 rectangles.push_back(OrthancStone::Extent2D(6, 4, 9, 6)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
769 rectangles.push_back(OrthancStone::Extent2D(4, 6, 7, 8)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
770 rectangles.push_back(OrthancStone::Extent2D(4, 2, 7, 6)); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
771 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
772 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
773 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
774 |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
775 ASSERT_EQ(1u, contours.size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
776 ASSERT_EQ(13u, contours.front().size()); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
777 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(4, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
778 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 8))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
779 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 6))); |
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
780 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(9, 6))); |
1876 | 781 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(9, 4))); |
782 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(7, 4))); | |
783 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(7, 2))); | |
784 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(4, 2))); | |
785 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(4, 4))); | |
786 ASSERT_TRUE(contours.front()[9].IsEqual(OrthancStone::ScenePoint2D(1, 4))); | |
787 ASSERT_TRUE(contours.front()[10].IsEqual(OrthancStone::ScenePoint2D(1, 6))); | |
788 ASSERT_TRUE(contours.front()[11].IsEqual(OrthancStone::ScenePoint2D(4, 6))); | |
789 ASSERT_TRUE(contours.front()[12].IsEqual(OrthancStone::ScenePoint2D(4, 8))); | |
790 } | |
791 | |
792 { | |
793 std::list<OrthancStone::Extent2D> rectangles; | |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
794 rectangles.push_back(OrthancStone::Extent2D(1, 4, 5, 6)); |
1876 | 795 rectangles.push_back(OrthancStone::Extent2D(4, 6, 7, 8)); |
796 rectangles.push_back(OrthancStone::Extent2D(4, 2, 7, 6)); | |
797 | |
798 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
799 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
800 | |
801 ASSERT_EQ(1u, contours.size()); | |
802 ASSERT_EQ(9u, contours.front().size()); | |
803 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(4, 8))); | |
804 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 8))); | |
805 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 2))); | |
806 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 2))); | |
807 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 4))); | |
808 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(1, 4))); | |
809 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(1, 6))); | |
810 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(4, 6))); | |
811 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(4, 8))); | |
812 } | |
813 | |
814 { | |
815 std::list<OrthancStone::Extent2D> rectangles; | |
816 rectangles.push_back(OrthancStone::Extent2D(2, 2, 4, 4)); | |
817 rectangles.push_back(OrthancStone::Extent2D(3, 3, 5, 5)); | |
818 | |
819 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
820 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
821 | |
822 ASSERT_EQ(1u, contours.size()); | |
823 ASSERT_EQ(9u, contours.front().size()); | |
824 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(3, 5))); | |
825 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(5, 5))); | |
826 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(5, 3))); | |
827 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 3))); | |
828 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 2))); | |
829 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
830 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(2, 4))); | |
831 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(3, 4))); | |
832 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(3, 5))); | |
833 } | |
834 | |
835 { | |
836 std::list<OrthancStone::Extent2D> rectangles; | |
837 rectangles.push_back(OrthancStone::Extent2D(2, 2, 4, 4)); | |
838 rectangles.push_back(OrthancStone::Extent2D(3, 1, 5, 3)); | |
839 | |
840 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
841 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
842 | |
843 ASSERT_EQ(1u, contours.size()); | |
844 ASSERT_EQ(9u, contours.front().size()); | |
845 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 4))); | |
846 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(4, 4))); | |
847 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(4, 3))); | |
848 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(5, 3))); | |
849 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(5, 1))); | |
850 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(3, 1))); | |
851 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(3, 2))); | |
852 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
853 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(2, 4))); | |
854 } | |
855 | |
856 { | |
857 std::list<OrthancStone::Extent2D> rectangles; | |
858 rectangles.push_back(OrthancStone::Extent2D(2, 2, 4, 4)); | |
859 rectangles.push_back(OrthancStone::Extent2D(1, 1, 3, 3)); | |
860 | |
861 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
862 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
863 | |
864 ASSERT_EQ(1u, contours.size()); | |
865 ASSERT_EQ(9u, contours.front().size()); | |
866 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 4))); | |
867 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(4, 4))); | |
868 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(4, 2))); | |
869 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(3, 2))); | |
870 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(3, 1))); | |
871 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(1, 1))); | |
872 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(1, 3))); | |
873 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(2, 3))); | |
874 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(2, 4))); | |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
875 } |
1876 | 876 |
877 { | |
878 std::list<OrthancStone::Extent2D> rectangles; | |
879 rectangles.push_back(OrthancStone::Extent2D(2, 2, 4, 4)); | |
880 rectangles.push_back(OrthancStone::Extent2D(1, 3, 3, 5)); | |
881 | |
882 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
883 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
884 | |
885 ASSERT_EQ(1u, contours.size()); | |
886 ASSERT_EQ(9u, contours.front().size()); | |
887 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 5))); | |
888 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(3, 5))); | |
889 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(3, 4))); | |
890 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 4))); | |
891 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 2))); | |
892 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
893 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(2, 3))); | |
894 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(1, 3))); | |
895 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(1, 5))); | |
896 } | |
897 | |
898 { | |
899 std::list<OrthancStone::Extent2D> rectangles; | |
900 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 3)); | |
901 rectangles.push_back(OrthancStone::Extent2D(3, 1, 4, 2)); | |
902 | |
903 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
904 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
905 | |
906 ASSERT_EQ(1u, contours.size()); | |
907 ASSERT_EQ(9u, contours.front().size()); | |
908 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 3))); | |
909 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(3, 3))); | |
910 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(3, 2))); | |
911 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 2))); | |
912 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 1))); | |
913 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(3, 1))); | |
914 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(3, 2))); | |
915 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
916 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(2, 3))); | |
917 } | |
918 | |
919 { | |
920 std::list<OrthancStone::Extent2D> rectangles; | |
921 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 3)); | |
922 rectangles.push_back(OrthancStone::Extent2D(3, 3, 4, 4)); | |
923 | |
924 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
925 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
926 | |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
927 ASSERT_EQ(2u, contours.size()); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
928 |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
929 ASSERT_EQ(5u, contours.front().size()); |
1876 | 930 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(3, 4))); |
931 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(4, 4))); | |
932 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(4, 3))); | |
933 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(3, 3))); | |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
934 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(3, 4))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
935 |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
936 ASSERT_EQ(5u, contours.back().size()); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
937 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(2, 3))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
938 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(3, 3))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
939 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(3, 2))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
940 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(2, 2))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
941 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(2, 3))); |
1876 | 942 } |
943 | |
944 { | |
945 std::list<OrthancStone::Extent2D> rectangles; | |
946 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 3)); | |
947 rectangles.push_back(OrthancStone::Extent2D(1, 3, 2, 4)); | |
948 | |
949 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
950 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
951 | |
952 ASSERT_EQ(1u, contours.size()); | |
953 ASSERT_EQ(9u, contours.front().size()); | |
954 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 4))); | |
955 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(2, 4))); | |
956 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(2, 3))); | |
957 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(3, 3))); | |
958 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(3, 2))); | |
959 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
960 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(2, 3))); | |
961 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(1, 3))); | |
962 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(1, 4))); | |
963 } | |
964 | |
965 { | |
966 std::list<OrthancStone::Extent2D> rectangles; | |
967 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 3)); | |
968 rectangles.push_back(OrthancStone::Extent2D(1, 1, 2, 2)); | |
969 | |
970 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
971 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
972 | |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
973 ASSERT_EQ(2u, contours.size()); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
974 |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
975 ASSERT_EQ(5u, contours.front().size()); |
1876 | 976 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 3))); |
977 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(3, 3))); | |
978 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(3, 2))); | |
979 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
1906
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
980 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(2, 3))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
981 |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
982 ASSERT_EQ(5u, contours.back().size()); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
983 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(1, 2))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
984 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(2, 2))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
985 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(2, 1))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
986 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(1, 1))); |
925aaf49150c
minor fix in UnionOfRectangles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1891
diff
changeset
|
987 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(1, 2))); |
1876 | 988 } |
989 | |
990 { | |
991 std::list<OrthancStone::Extent2D> rectangles; | |
992 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 5)); | |
993 rectangles.push_back(OrthancStone::Extent2D(1, 3, 4, 4)); | |
994 | |
995 std::list< std::vector<OrthancStone::ScenePoint2D> > contours; | |
996 OrthancStone::UnionOfRectangles::Apply(contours, rectangles); | |
997 | |
998 ASSERT_EQ(1u, contours.size()); | |
999 ASSERT_EQ(13u, contours.front().size()); | |
1000 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 5))); | |
1001 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(3, 5))); | |
1002 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(3, 4))); | |
1003 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 4))); | |
1004 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 3))); | |
1005 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(3, 3))); | |
1006 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(3, 2))); | |
1007 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(2, 2))); | |
1008 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(2, 3))); | |
1009 ASSERT_TRUE(contours.front()[9].IsEqual(OrthancStone::ScenePoint2D(1, 3))); | |
1010 ASSERT_TRUE(contours.front()[10].IsEqual(OrthancStone::ScenePoint2D(1, 4))); | |
1011 ASSERT_TRUE(contours.front()[11].IsEqual(OrthancStone::ScenePoint2D(2, 4))); | |
1012 ASSERT_TRUE(contours.front()[12].IsEqual(OrthancStone::ScenePoint2D(2, 5))); | |
1013 } | |
1875
b896f20d24ca
added UnionOfRectangles algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
1014 } |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1015 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1016 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1017 TEST(LinearAlgebra, ComputeMedian) |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1018 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1019 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1020 std::vector<double> v; |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1021 ASSERT_THROW(OrthancStone::LinearAlgebra::ComputeMedian(v), Orthanc::OrthancException); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1022 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1023 v.push_back(1); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1024 v.push_back(3); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1025 v.push_back(3); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1026 v.push_back(6); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1027 v.push_back(7); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1028 v.push_back(8); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1029 v.push_back(9); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1030 ASSERT_DOUBLE_EQ(6.0, OrthancStone::LinearAlgebra::ComputeMedian(v)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1031 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1032 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1033 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1034 std::vector<double> v; |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1035 v.push_back(1); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1036 v.push_back(2); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1037 v.push_back(3); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1038 v.push_back(4); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1039 v.push_back(5); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1040 v.push_back(6); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1041 v.push_back(8); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1042 v.push_back(9); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1043 ASSERT_DOUBLE_EQ(4.5, OrthancStone::LinearAlgebra::ComputeMedian(v)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1044 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1045 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1046 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1047 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1048 TEST(BucketAccumulator1D, Basic) |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1049 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1050 for (int storeValues = 0; storeValues <= 1; storeValues++) |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1051 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1052 OrthancStone::BucketAccumulator1D b(-10, 30, 4, storeValues != 0); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1053 ASSERT_EQ(4u, b.GetSize()); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1054 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1055 ASSERT_DOUBLE_EQ(-10.0, b.GetBucketLow(0)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1056 ASSERT_DOUBLE_EQ(0.0, b.GetBucketLow(1)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1057 ASSERT_DOUBLE_EQ(10.0, b.GetBucketLow(2)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1058 ASSERT_DOUBLE_EQ(20.0, b.GetBucketLow(3)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1059 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1060 ASSERT_DOUBLE_EQ(0.0, b.GetBucketHigh(0)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1061 ASSERT_DOUBLE_EQ(10.0, b.GetBucketHigh(1)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1062 ASSERT_DOUBLE_EQ(20.0, b.GetBucketHigh(2)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1063 ASSERT_DOUBLE_EQ(30.0, b.GetBucketHigh(3)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1064 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1065 ASSERT_DOUBLE_EQ(-5.0, b.GetBucketCenter(0)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1066 ASSERT_DOUBLE_EQ(5.0, b.GetBucketCenter(1)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1067 ASSERT_DOUBLE_EQ(15.0, b.GetBucketCenter(2)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1068 ASSERT_DOUBLE_EQ(25.0, b.GetBucketCenter(3)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1069 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1070 ASSERT_EQ(0u, b.GetBucketContentSize(0)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1071 ASSERT_EQ(0u, b.GetBucketContentSize(1)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1072 ASSERT_EQ(0u, b.GetBucketContentSize(2)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1073 ASSERT_EQ(0u, b.GetBucketContentSize(3)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1074 |
1891 | 1075 ASSERT_THROW(b.GetBucketIndex(-10.0001), Orthanc::OrthancException); |
1076 ASSERT_EQ(0u, b.GetBucketIndex(-10)); | |
1077 ASSERT_EQ(0u, b.GetBucketIndex(-0.0001)); | |
1078 ASSERT_EQ(1u, b.GetBucketIndex(0)); | |
1079 ASSERT_EQ(1u, b.GetBucketIndex(9.9999)); | |
1080 ASSERT_EQ(2u, b.GetBucketIndex(10)); | |
1081 ASSERT_EQ(2u, b.GetBucketIndex(19.9999)); | |
1082 ASSERT_EQ(3u, b.GetBucketIndex(20)); | |
1083 ASSERT_EQ(3u, b.GetBucketIndex(30)); | |
1084 ASSERT_THROW(b.GetBucketIndex(30.0001), Orthanc::OrthancException); | |
1085 | |
1086 ASSERT_EQ(0u, b.FindBestBucket()); | |
1087 ASSERT_DOUBLE_EQ(-5.0, b.ComputeBestCenter()); | |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1088 ASSERT_THROW(b.ComputeBestMedian(), Orthanc::OrthancException); // No data point |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1089 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1090 b.AddValue(-10.0); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1091 b.AddValue(0.0); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1092 b.AddValue(9.9999); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1093 b.AddValue(10.0); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1094 b.AddValue(20.0); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1095 b.AddValue(29.9999); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1096 b.AddValue(30.0); |
1891 | 1097 ASSERT_THROW(b.AddValue(-10.00001), Orthanc::OrthancException); |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1098 ASSERT_THROW(b.AddValue(30.00001), Orthanc::OrthancException); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1099 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1100 ASSERT_EQ(3u, b.FindBestBucket()); |
1891 | 1101 ASSERT_EQ(3u, b.GetBucketContentSize(b.FindBestBucket())); |
1102 ASSERT_DOUBLE_EQ(25.0, b.ComputeBestCenter()); | |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1103 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1104 ASSERT_EQ(1u, b.GetBucketContentSize(0)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1105 ASSERT_EQ(2u, b.GetBucketContentSize(1)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1106 ASSERT_EQ(1u, b.GetBucketContentSize(2)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1107 ASSERT_EQ(3u, b.GetBucketContentSize(3)); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1108 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1109 if (storeValues == 0) |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1110 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1111 ASSERT_THROW(b.ComputeBestMedian(), Orthanc::OrthancException); |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1112 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1113 else |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1114 { |
1891 | 1115 ASSERT_DOUBLE_EQ(29.9999, b.ComputeBestMedian()); |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1116 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1117 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1118 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1119 |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1120 TEST(BucketAccumulator2D, Basic) |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1121 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1122 for (int storeValues = 0; storeValues <= 1; storeValues++) |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1123 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1124 OrthancStone::BucketAccumulator2D b(-10, 30, 4, |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1125 0, 3, 3, storeValues != 0); |
1891 | 1126 |
1127 size_t bx, by; | |
1128 b.FindBestBucket(bx, by); | |
1129 ASSERT_EQ(0u, bx); | |
1130 ASSERT_EQ(0u, by); | |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1131 |
1891 | 1132 for (by = 0; by < 3; by++) |
1133 { | |
1134 for (bx = 0; bx < 4; bx++) | |
1135 { | |
1136 ASSERT_EQ(0u, b.GetBucketContentSize(bx, by)); | |
1137 } | |
1138 } | |
1139 | |
1140 b.GetSize(bx, by); | |
1141 ASSERT_EQ(4u, bx); | |
1142 ASSERT_EQ(3u, by); | |
1143 | |
1144 ASSERT_DOUBLE_EQ(-10.0, b.GetBucketLowX(0)); | |
1145 ASSERT_DOUBLE_EQ(0.0, b.GetBucketLowX(1)); | |
1146 ASSERT_DOUBLE_EQ(10.0, b.GetBucketLowX(2)); | |
1147 ASSERT_DOUBLE_EQ(20.0, b.GetBucketLowX(3)); | |
1148 ASSERT_THROW(b.GetBucketLowX(4), Orthanc::OrthancException); | |
1149 | |
1150 ASSERT_DOUBLE_EQ(0.0, b.GetBucketLowY(0)); | |
1151 ASSERT_DOUBLE_EQ(1.0, b.GetBucketLowY(1)); | |
1152 ASSERT_DOUBLE_EQ(2.0, b.GetBucketLowY(2)); | |
1153 ASSERT_THROW(b.GetBucketLowY(3), Orthanc::OrthancException); | |
1154 | |
1155 ASSERT_DOUBLE_EQ(0.0, b.GetBucketHighX(0)); | |
1156 ASSERT_DOUBLE_EQ(10.0, b.GetBucketHighX(1)); | |
1157 ASSERT_DOUBLE_EQ(20.0, b.GetBucketHighX(2)); | |
1158 ASSERT_DOUBLE_EQ(30.0, b.GetBucketHighX(3)); | |
1159 ASSERT_THROW(b.GetBucketHighX(4), Orthanc::OrthancException); | |
1160 | |
1161 ASSERT_DOUBLE_EQ(1.0, b.GetBucketHighY(0)); | |
1162 ASSERT_DOUBLE_EQ(2.0, b.GetBucketHighY(1)); | |
1163 ASSERT_DOUBLE_EQ(3.0, b.GetBucketHighY(2)); | |
1164 ASSERT_THROW(b.GetBucketHighY(3), Orthanc::OrthancException); | |
1165 | |
1166 ASSERT_DOUBLE_EQ(-5.0, b.GetBucketCenterX(0)); | |
1167 ASSERT_DOUBLE_EQ(5.0, b.GetBucketCenterX(1)); | |
1168 ASSERT_DOUBLE_EQ(15.0, b.GetBucketCenterX(2)); | |
1169 ASSERT_DOUBLE_EQ(25.0, b.GetBucketCenterX(3)); | |
1170 ASSERT_THROW(b.GetBucketCenterX(4), Orthanc::OrthancException); | |
1171 | |
1172 ASSERT_DOUBLE_EQ(0.5, b.GetBucketCenterY(0)); | |
1173 ASSERT_DOUBLE_EQ(1.5, b.GetBucketCenterY(1)); | |
1174 ASSERT_DOUBLE_EQ(2.5, b.GetBucketCenterY(2)); | |
1175 ASSERT_THROW(b.GetBucketCenterY(3), Orthanc::OrthancException); | |
1176 | |
1177 b.GetBucketIndex(bx, by, 5, 2.5); | |
1178 ASSERT_EQ(1u, bx); | |
1179 ASSERT_EQ(2u, by); | |
1180 b.AddValue(4.5, 2.2); | |
1181 ASSERT_THROW(b.AddValue(-10.001, 2), Orthanc::OrthancException); | |
1182 ASSERT_THROW(b.AddValue(30.001, 2), Orthanc::OrthancException); | |
1183 ASSERT_THROW(b.AddValue(0, -0.0001), Orthanc::OrthancException); | |
1184 ASSERT_THROW(b.AddValue(0, 3.0001), Orthanc::OrthancException); | |
1185 | |
1186 b.FindBestBucket(bx, by); | |
1187 ASSERT_EQ(1u, bx); | |
1188 ASSERT_EQ(2u, by); | |
1189 | |
1190 for (by = 0; by < 3; by++) | |
1191 { | |
1192 for (bx = 0; bx < 4; bx++) | |
1193 { | |
1194 ASSERT_EQ((bx == 1u && by == 2u) ? 1u : 0u, b.GetBucketContentSize(bx, by)); | |
1195 } | |
1196 } | |
1197 | |
1198 double dx, dy; | |
1199 b.ComputeBestCenter(dx, dy); | |
1200 ASSERT_DOUBLE_EQ(5.0, dx); | |
1201 ASSERT_DOUBLE_EQ(2.5, dy); | |
1202 | |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1203 if (storeValues == 0) |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1204 { |
1891 | 1205 ASSERT_THROW(b.ComputeBestMedian(dx, dy), Orthanc::OrthancException); |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1206 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1207 else |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1208 { |
1891 | 1209 b.ComputeBestMedian(dx, dy); |
1210 ASSERT_DOUBLE_EQ(4.5, dx); | |
1211 ASSERT_DOUBLE_EQ(2.2, dy); | |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1212 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1213 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
1214 } |