Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/Internals/RectanglesIntegerProjection.cpp @ 1905:e318b524ad3f
use UnionOfRectangles algorithm to render RT-STRUCT
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 31 Jan 2022 18:50:35 +0100 |
parents | 08f2476e8f5e |
children | 07964689cb0b |
rev | line source |
---|---|
1874
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * License along with this program. If not, see |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "RectanglesIntegerProjection.h" |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include <OrthancException.h> |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include <algorithm> |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 #include <cassert> |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 namespace OrthancStone |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 namespace Internals |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 class RectanglesIntegerProjection::Endpoint |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 private: |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 size_t intervalIndex_; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 double value_; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 bool isLow_; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 public: |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 Endpoint(size_t intervalIndex, |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 double value, |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 bool isLow) : |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 intervalIndex_(intervalIndex), |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 value_(value), |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 isLow_(isLow) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 bool operator< (const Endpoint& other) const |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 if (value_ < other.value_) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 return true; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 else if (value_ == other.value_) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
1905
e318b524ad3f
use UnionOfRectangles algorithm to render RT-STRUCT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1874
diff
changeset
|
61 return static_cast<int>(isLow_) < static_cast<int>(other.isLow_); |
1874
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 else |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 return false; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 size_t GetIntervalIndex() const |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 return intervalIndex_; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 double GetValue() const |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 return value_; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 bool IsLow() const |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 return isLow_; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 }; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 RectanglesIntegerProjection::RectanglesIntegerProjection(const std::list<Extent2D>& rectangles, |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 bool isHorizontal) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 std::vector<Endpoint> endpoints; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 endpoints.reserve(2 * rectangles.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 size_t count = 0; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 for (std::list<Extent2D>::const_iterator it = rectangles.begin(); it != rectangles.end(); ++it) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 if (!it->IsEmpty()) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 if (isHorizontal) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 assert(it->GetX1() < it->GetX2()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 endpoints.push_back(Endpoint(count, it->GetX1(), true)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 endpoints.push_back(Endpoint(count, it->GetX2(), false)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 else |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 assert(it->GetY1() < it->GetY2()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 endpoints.push_back(Endpoint(count, it->GetY1(), true)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 endpoints.push_back(Endpoint(count, it->GetY2(), false)); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 assert(endpoints[endpoints.size() - 2] < endpoints[endpoints.size() - 1]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 count++; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 std::sort(endpoints.begin(), endpoints.end()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 intervalsLow_.resize(count); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 intervalsHigh_.resize(count); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 endpointsToDouble_.reserve(count); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 for (size_t i = 0; i < endpoints.size(); i++) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 if (endpointsToDouble_.empty() || |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 endpointsToDouble_.back() < endpoints[i].GetValue()) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 endpointsToDouble_.push_back(endpoints[i].GetValue()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 size_t intervalIndex = endpoints[i].GetIntervalIndex(); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 if (endpoints[i].IsLow()) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 intervalsLow_[intervalIndex] = endpointsToDouble_.size() - 1; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 else |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 intervalsHigh_[intervalIndex] = endpointsToDouble_.size() - 1; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 for (size_t i = 0; i < intervalsLow_.size(); i++) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 assert(intervalsLow_[i] < intervalsHigh_[i]); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 double RectanglesIntegerProjection::GetEndpointCoordinate(size_t index) const |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 if (index >= endpointsToDouble_.size()) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 else |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 return endpointsToDouble_[index]; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 size_t RectanglesIntegerProjection::GetProjectedRectanglesCount() const |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 assert(intervalsLow_.size() == intervalsHigh_.size()); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 return intervalsLow_.size(); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 size_t RectanglesIntegerProjection::GetProjectedRectangleLow(size_t index) const |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 if (index >= GetProjectedRectanglesCount()) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 else |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 return intervalsLow_[index]; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 size_t RectanglesIntegerProjection::GetProjectedRectangleHigh(size_t index) const |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 if (index >= GetProjectedRectanglesCount()) |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 else |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 { |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 return intervalsHigh_[index]; |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 } |
08f2476e8f5e
added classes OrientedIntegerLine2D and RectanglesIntegerProjection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 } |