annotate OrthancStone/UnitTestsSources/ComputationalGeometryTests.cpp @ 2108:7cff3c404430

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 18 Dec 2023 22:41:49 +0100
parents 07964689cb0b
children c23eef785569
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1906
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <gtest/gtest.h>
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1891
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
26 #include "../Sources/Toolbox/BucketAccumulator1D.h"
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include <Logging.h>
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include <OrthancException.h>
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 namespace
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 class CounterFactory : public OrthancStone::SegmentTree::IPayloadFactory
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 };
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
91 TEST(SegmentTree, Create)
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
1873
e0966648ebd0 unit tests of SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1872
diff changeset
93 CounterFactory factory(42);
1872
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 OrthancStone::SegmentTree root(4u, 15u, factory); // Check out Figure 1.1 (page 14) from textbook
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 ASSERT_EQ(4u, root.GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 ASSERT_EQ(15u, root.GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 ASSERT_EQ(21u, root.CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 ASSERT_EQ(9u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 n = &root.GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ASSERT_EQ(6u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 n = &root.GetLeftChild().GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ASSERT_EQ(4u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ASSERT_EQ(5u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 ASSERT_THROW(n->GetLeftChild(), Orthanc::OrthancException);
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ASSERT_THROW(n->GetRightChild(), Orthanc::OrthancException);
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 n = &root.GetLeftChild().GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 ASSERT_EQ(5u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 ASSERT_EQ(6u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 n = &root.GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 ASSERT_EQ(6u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 n = &root.GetLeftChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 ASSERT_EQ(6u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 ASSERT_EQ(7u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 n = &root.GetLeftChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 ASSERT_EQ(7u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 n = &root.GetLeftChild().GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 ASSERT_EQ(7u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 ASSERT_EQ(8u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 n = &root.GetLeftChild().GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 ASSERT_EQ(8u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 ASSERT_EQ(9u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 n = &root.GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 ASSERT_EQ(11u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 n = &root.GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 n = &root.GetRightChild().GetLeftChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 ASSERT_EQ(9u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 ASSERT_EQ(10u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 n = &root.GetRightChild().GetLeftChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 ASSERT_EQ(10u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 n = &root.GetRightChild().GetLeftChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 ASSERT_EQ(10u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 ASSERT_EQ(11u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 n = &root.GetRightChild().GetLeftChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 ASSERT_EQ(11u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 ASSERT_EQ(12u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 n = &root.GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 ASSERT_EQ(12u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 ASSERT_EQ(5u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 n = &root.GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 ASSERT_EQ(12u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 ASSERT_EQ(13u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 n = &root.GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 ASSERT_EQ(13u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 ASSERT_FALSE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 ASSERT_EQ(3u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 n = &root.GetRightChild().GetRightChild().GetRightChild().GetLeftChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 ASSERT_EQ(13u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 ASSERT_EQ(14u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 ASSERT_EQ(1u, n->CountNodes());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 n = &root.GetRightChild().GetRightChild().GetRightChild().GetRightChild();
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 ASSERT_EQ(14u, n->GetLowBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 ASSERT_EQ(15u, n->GetHighBound());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 ASSERT_TRUE(n->IsLeaf());
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
db8a8a19b543 SegmentTree
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
612
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
613 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
614 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
615
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
616 ASSERT_EQ(0u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
617 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
618
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
619 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
620 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
621 rectangles.push_back(OrthancStone::Extent2D(3, 3, 4, 3)); // empty rectangle
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
622
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
623 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
624 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
625
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
626 ASSERT_EQ(0u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
627 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
628
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
629 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
630 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
631 rectangles.push_back(OrthancStone::Extent2D(1, 1, 2, 2));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
632
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
633 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
634 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
635
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
636 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
637 ASSERT_EQ(5u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
638 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
639 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
640 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(2, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
641 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(1, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
642 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(1, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
643 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
644
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
645 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
646 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
647 rectangles.push_back(OrthancStone::Extent2D(1, 1, 2, 2));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
648 rectangles.push_back(OrthancStone::Extent2D(1, 3, 2, 4));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
649
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
650 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
651 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
652
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
653 ASSERT_EQ(2u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
654
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
655 ASSERT_EQ(5u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
656 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
657 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(2, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
658 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
659 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(1, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
660 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
661
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
662 ASSERT_EQ(5u, contours.back().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
663 ASSERT_TRUE(contours.back()[0].IsEqual(OrthancStone::ScenePoint2D(1, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
664 ASSERT_TRUE(contours.back()[1].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
665 ASSERT_TRUE(contours.back()[2].IsEqual(OrthancStone::ScenePoint2D(2, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
666 ASSERT_TRUE(contours.back()[3].IsEqual(OrthancStone::ScenePoint2D(1, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
667 ASSERT_TRUE(contours.back()[4].IsEqual(OrthancStone::ScenePoint2D(1, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
668 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
669
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
670 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
781 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(9, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
782 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(7, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
783 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(7, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
784 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(4, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
785 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
786 ASSERT_TRUE(contours.front()[9].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
787 ASSERT_TRUE(contours.front()[10].IsEqual(OrthancStone::ScenePoint2D(1, 6)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
788 ASSERT_TRUE(contours.front()[11].IsEqual(OrthancStone::ScenePoint2D(4, 6)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
789 ASSERT_TRUE(contours.front()[12].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
790 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
791
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
792 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
795 rectangles.push_back(OrthancStone::Extent2D(4, 6, 7, 8));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
796 rectangles.push_back(OrthancStone::Extent2D(4, 2, 7, 6));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
797
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
798 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
799 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
800
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
801 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
802 ASSERT_EQ(9u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
803 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
804 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(7, 8)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
805 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(7, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
806 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
807 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
808 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
809 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(1, 6)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
810 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(4, 6)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
811 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(4, 8)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
812 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
813
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
814 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
815 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
816 rectangles.push_back(OrthancStone::Extent2D(2, 2, 4, 4));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
817 rectangles.push_back(OrthancStone::Extent2D(3, 3, 5, 5));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
818
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
819 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
820 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
821
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
822 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
823 ASSERT_EQ(9u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
824 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(3, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
825 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(5, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
826 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(5, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
827 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
828 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
829 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
830 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(2, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
831 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(3, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
832 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(3, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
833 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
834
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
835 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
836 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
837 rectangles.push_back(OrthancStone::Extent2D(2, 2, 4, 4));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
838 rectangles.push_back(OrthancStone::Extent2D(3, 1, 5, 3));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
839
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
840 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
841 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
842
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
843 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
844 ASSERT_EQ(9u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
845 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
846 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
847 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(4, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
848 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(5, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
849 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(5, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
850 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(3, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
851 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(3, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
852 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
853 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(2, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
854 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
855
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
856 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
857 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
858 rectangles.push_back(OrthancStone::Extent2D(2, 2, 4, 4));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
859 rectangles.push_back(OrthancStone::Extent2D(1, 1, 3, 3));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
860
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
861 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
862 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
863
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
864 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
865 ASSERT_EQ(9u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
866 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
867 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
868 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(4, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
869 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(3, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
870 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(3, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
871 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(1, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
872 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(1, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
873 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
876
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
877 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
878 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
879 rectangles.push_back(OrthancStone::Extent2D(2, 2, 4, 4));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
880 rectangles.push_back(OrthancStone::Extent2D(1, 3, 3, 5));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
881
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
882 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
883 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
884
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
885 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
886 ASSERT_EQ(9u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
887 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
888 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(3, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
889 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(3, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
890 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
891 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
892 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
893 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
894 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(1, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
895 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(1, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
896 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
897
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
898 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
899 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
900 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 3));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
901 rectangles.push_back(OrthancStone::Extent2D(3, 1, 4, 2));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
902
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
903 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
904 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
905
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
906 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
907 ASSERT_EQ(9u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
908 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
909 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(3, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
910 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(3, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
911 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
912 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
913 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(3, 1)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
914 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(3, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
915 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
916 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
917 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
918
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
919 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
920 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
921 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 3));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
922 rectangles.push_back(OrthancStone::Extent2D(3, 3, 4, 4));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
923
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
924 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
925 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
930 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(3, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
931 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
932 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(4, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
942 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
943
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
944 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
945 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
946 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 3));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
947 rectangles.push_back(OrthancStone::Extent2D(1, 3, 2, 4));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
948
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
949 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
950 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
951
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
952 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
953 ASSERT_EQ(9u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
954 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
955 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(2, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
956 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
957 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(3, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
958 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(3, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
959 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
960 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
961 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(1, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
962 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
963 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
964
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
965 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
966 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
967 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 3));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
968 rectangles.push_back(OrthancStone::Extent2D(1, 1, 2, 2));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
969
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
970 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
971 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
976 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
977 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(3, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
978 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(3, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
988 }
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
989
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
990 {
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
991 std::list<OrthancStone::Extent2D> rectangles;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
992 rectangles.push_back(OrthancStone::Extent2D(2, 2, 3, 5));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
993 rectangles.push_back(OrthancStone::Extent2D(1, 3, 4, 4));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
994
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
995 std::list< std::vector<OrthancStone::ScenePoint2D> > contours;
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
996 OrthancStone::UnionOfRectangles::Apply(contours, rectangles);
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
997
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
998 ASSERT_EQ(1u, contours.size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
999 ASSERT_EQ(13u, contours.front().size());
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1000 ASSERT_TRUE(contours.front()[0].IsEqual(OrthancStone::ScenePoint2D(2, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1001 ASSERT_TRUE(contours.front()[1].IsEqual(OrthancStone::ScenePoint2D(3, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1002 ASSERT_TRUE(contours.front()[2].IsEqual(OrthancStone::ScenePoint2D(3, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1003 ASSERT_TRUE(contours.front()[3].IsEqual(OrthancStone::ScenePoint2D(4, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1004 ASSERT_TRUE(contours.front()[4].IsEqual(OrthancStone::ScenePoint2D(4, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1005 ASSERT_TRUE(contours.front()[5].IsEqual(OrthancStone::ScenePoint2D(3, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1006 ASSERT_TRUE(contours.front()[6].IsEqual(OrthancStone::ScenePoint2D(3, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1007 ASSERT_TRUE(contours.front()[7].IsEqual(OrthancStone::ScenePoint2D(2, 2)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1008 ASSERT_TRUE(contours.front()[8].IsEqual(OrthancStone::ScenePoint2D(2, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1009 ASSERT_TRUE(contours.front()[9].IsEqual(OrthancStone::ScenePoint2D(1, 3)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1010 ASSERT_TRUE(contours.front()[10].IsEqual(OrthancStone::ScenePoint2D(1, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1011 ASSERT_TRUE(contours.front()[11].IsEqual(OrthancStone::ScenePoint2D(2, 4)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
1012 ASSERT_TRUE(contours.front()[12].IsEqual(OrthancStone::ScenePoint2D(2, 5)));
b1f510e601d2 more unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
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
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1075 ASSERT_THROW(b.GetBucketIndex(-10.0001), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1076 ASSERT_EQ(0u, b.GetBucketIndex(-10));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1077 ASSERT_EQ(0u, b.GetBucketIndex(-0.0001));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1078 ASSERT_EQ(1u, b.GetBucketIndex(0));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1079 ASSERT_EQ(1u, b.GetBucketIndex(9.9999));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1080 ASSERT_EQ(2u, b.GetBucketIndex(10));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1081 ASSERT_EQ(2u, b.GetBucketIndex(19.9999));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1082 ASSERT_EQ(3u, b.GetBucketIndex(20));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1083 ASSERT_EQ(3u, b.GetBucketIndex(30));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1084 ASSERT_THROW(b.GetBucketIndex(30.0001), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1085
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1086 ASSERT_EQ(0u, b.FindBestBucket());
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
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
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
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
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1101 ASSERT_EQ(3u, b.GetBucketContentSize(b.FindBestBucket()));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
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
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
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
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1126
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1127 size_t bx, by;
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1128 b.FindBestBucket(bx, by);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1129 ASSERT_EQ(0u, bx);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1130 ASSERT_EQ(0u, by);
1890
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
1131
1891
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1132 for (by = 0; by < 3; by++)
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1133 {
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1134 for (bx = 0; bx < 4; bx++)
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1135 {
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1136 ASSERT_EQ(0u, b.GetBucketContentSize(bx, by));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1137 }
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1138 }
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1139
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1140 b.GetSize(bx, by);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1141 ASSERT_EQ(4u, bx);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1142 ASSERT_EQ(3u, by);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1143
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1144 ASSERT_DOUBLE_EQ(-10.0, b.GetBucketLowX(0));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1145 ASSERT_DOUBLE_EQ(0.0, b.GetBucketLowX(1));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1146 ASSERT_DOUBLE_EQ(10.0, b.GetBucketLowX(2));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1147 ASSERT_DOUBLE_EQ(20.0, b.GetBucketLowX(3));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1148 ASSERT_THROW(b.GetBucketLowX(4), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1149
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1150 ASSERT_DOUBLE_EQ(0.0, b.GetBucketLowY(0));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1151 ASSERT_DOUBLE_EQ(1.0, b.GetBucketLowY(1));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1152 ASSERT_DOUBLE_EQ(2.0, b.GetBucketLowY(2));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1153 ASSERT_THROW(b.GetBucketLowY(3), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1154
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1155 ASSERT_DOUBLE_EQ(0.0, b.GetBucketHighX(0));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1156 ASSERT_DOUBLE_EQ(10.0, b.GetBucketHighX(1));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1157 ASSERT_DOUBLE_EQ(20.0, b.GetBucketHighX(2));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1158 ASSERT_DOUBLE_EQ(30.0, b.GetBucketHighX(3));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1159 ASSERT_THROW(b.GetBucketHighX(4), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1160
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1161 ASSERT_DOUBLE_EQ(1.0, b.GetBucketHighY(0));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1162 ASSERT_DOUBLE_EQ(2.0, b.GetBucketHighY(1));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1163 ASSERT_DOUBLE_EQ(3.0, b.GetBucketHighY(2));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1164 ASSERT_THROW(b.GetBucketHighY(3), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1165
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1166 ASSERT_DOUBLE_EQ(-5.0, b.GetBucketCenterX(0));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1167 ASSERT_DOUBLE_EQ(5.0, b.GetBucketCenterX(1));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1168 ASSERT_DOUBLE_EQ(15.0, b.GetBucketCenterX(2));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1169 ASSERT_DOUBLE_EQ(25.0, b.GetBucketCenterX(3));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1170 ASSERT_THROW(b.GetBucketCenterX(4), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1171
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1172 ASSERT_DOUBLE_EQ(0.5, b.GetBucketCenterY(0));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1173 ASSERT_DOUBLE_EQ(1.5, b.GetBucketCenterY(1));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1174 ASSERT_DOUBLE_EQ(2.5, b.GetBucketCenterY(2));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1175 ASSERT_THROW(b.GetBucketCenterY(3), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1176
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1177 b.GetBucketIndex(bx, by, 5, 2.5);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1178 ASSERT_EQ(1u, bx);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1179 ASSERT_EQ(2u, by);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1180 b.AddValue(4.5, 2.2);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1181 ASSERT_THROW(b.AddValue(-10.001, 2), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1182 ASSERT_THROW(b.AddValue(30.001, 2), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1183 ASSERT_THROW(b.AddValue(0, -0.0001), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1184 ASSERT_THROW(b.AddValue(0, 3.0001), Orthanc::OrthancException);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1185
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1186 b.FindBestBucket(bx, by);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1187 ASSERT_EQ(1u, bx);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1188 ASSERT_EQ(2u, by);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1189
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1190 for (by = 0; by < 3; by++)
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1191 {
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1192 for (bx = 0; bx < 4; bx++)
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1193 {
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1194 ASSERT_EQ((bx == 1u && by == 2u) ? 1u : 0u, b.GetBucketContentSize(bx, by));
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1195 }
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1196 }
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1197
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1198 double dx, dy;
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1199 b.ComputeBestCenter(dx, dy);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1200 ASSERT_DOUBLE_EQ(5.0, dx);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1201 ASSERT_DOUBLE_EQ(2.5, dy);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
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
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
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
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1209 b.ComputeBestMedian(dx, dy);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1210 ASSERT_DOUBLE_EQ(4.5, dx);
3716d72161d2 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
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 }