IDS peak ICV v1.0.0
Loading...
Searching...
No Matches
peak_icv_region.ipp
Go to the documentation of this file.
1
11#pragma once
12
15
16namespace peak
17{
18namespace icv
19{
20namespace experimental
21{
22inline detail::handle_of_t<Region> Region::GetHandle() const
23{
24 return m_regionHandle;
25}
26
27inline detail::handle_of_t<Region>* Region::GetHandleAddress()
28{
29 return &m_regionHandle;
30}
31
33{
35 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Create(&m_regionHandle);
36 });
37}
38
39inline Region::Region(const std::vector<peak::common::Point>& points)
40{
41 std::vector<peak_common_point> cPoints(points.size());
42 std::transform(points.begin(), points.end(), cPoints.begin(), [](const auto& cppPoint) -> peak_common_point {
43 return { cppPoint.GetX(), cppPoint.GetY() };
44 });
46 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_CreateFromPoints(&m_regionHandle, cPoints.data(), cPoints.size());
47 });
48}
49
50inline Region::Region(const peak::common::Rectangle& rect)
51{
53 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_CreateFromRectangle(
54 &m_regionHandle, peak::common::detail::BackendAccessor<peak::common::Rectangle>::CreateCType(rect));
55 });
56}
57
58inline Region::Region(peak_icv_region_handle regionHandle) noexcept
59 : m_regionHandle{ regionHandle }
60{}
61
62inline Region::Region(const Region& other)
63{
64 if (m_regionHandle != other.m_regionHandle)
65 {
67 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_IncreaseUseCount(other.m_regionHandle);
68 });
69 m_regionHandle = other.m_regionHandle;
70 }
71}
72
73inline Region::Region(Region&& other) noexcept
74{
75 if (m_regionHandle != other.m_regionHandle)
76 {
77 m_regionHandle = other.m_regionHandle;
78 other.m_regionHandle = nullptr;
79 }
80}
81
82inline Region::~Region()
83{
84 if (m_regionHandle)
85 {
86 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Destroy(m_regionHandle);
87 }
88}
89
90inline Region& Region::operator=(const Region& other)
91{
92 if (m_regionHandle != other.m_regionHandle)
93 {
94 if (m_regionHandle)
95 {
97 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Destroy(m_regionHandle);
98 });
99 }
100
102 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_IncreaseUseCount(other.m_regionHandle);
103 });
104 m_regionHandle = other.m_regionHandle;
105 }
106
107 return *this;
108}
109
110inline Region& Region::operator=(Region&& other) noexcept
111{
112 if (m_regionHandle != other.m_regionHandle)
113 {
114 if (m_regionHandle)
115 {
117 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Destroy(m_regionHandle);
118 });
119 }
120
121 m_regionHandle = other.m_regionHandle;
122 other.m_regionHandle = nullptr;
123 }
124
125 return *this;
126}
127
128inline std::vector<peak::common::Point> Region::GetPoints() const
129{
130 size_t numPoints = 0;
132 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_GetPoints_GetCount(m_regionHandle, &numPoints);
133 });
134
135 if (numPoints == 0)
136 {
137 return {};
138 }
139
140 std::vector<peak_common_point> points(numPoints);
141 std::vector<peak::common::Point> cppPoints{};
142 cppPoints.reserve(numPoints);
143
145 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_GetPoints(m_regionHandle, points.data(), numPoints);
146 });
147
148 std::transform(points.begin(), points.end(), std::back_inserter(cppPoints), [](const auto& cPoint) {
149 return peak::common::detail::BackendAccessor<peak::common::Point>::CreateInstance(cPoint);
150 });
151
152 return cppPoints;
153}
154
155inline std::vector<Region> Region::GetConnectedComponents() const
156{
157 size_t numConnectedComponents = 0;
158
160 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_GetConnectedComponents_GetCount(m_regionHandle, &numConnectedComponents);
161 });
162
163 if (numConnectedComponents == 0)
164 {
165 return {};
166 }
167
168 std::vector<peak_icv_region_handle> regionHandles(numConnectedComponents);
169
171 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Array_Create(regionHandles.data(), numConnectedComponents);
172 });
173
175 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_GetConnectedComponents(m_regionHandle, regionHandles.data(), numConnectedComponents);
176 });
177
178 return peak::common::detail::BackendAccessor<Region>::CreateInstances(regionHandles);
179}
180
181inline size_t Region::GetArea() const
182{
183 size_t area = 0;
184
186 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_GetArea(m_regionHandle, &area);
187 });
188
189 return area;
190}
191
192inline peak::common::PointF Region::GetCenterOfGravity() const
193{
194 peak_common_point_f centerOfGravity{};
195
197 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_GetCenterOfGravity(m_regionHandle, &centerOfGravity);
198 });
199
200 return peak::common::detail::BackendAccessor<peak::common::PointF>::CreateInstance(centerOfGravity);
201}
202
203inline bool Region::operator==(const Region& rhs) const
204{
205 if (m_regionHandle == rhs.m_regionHandle)
206 {
207 return true;
208 }
209
210 bool is_equal = false;
212 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Compare(m_regionHandle, rhs.m_regionHandle, &is_equal);
213 });
214
215 return is_equal;
216}
217
218inline bool Region::operator!=(const Region& rhs) const
219{
220 return !(*this == rhs);
221}
222
223inline void Region::Draw(Image& image, const detail::DrawingOptions& options) const
224{
225 const auto imageHandle = peak::common::detail::BackendAccessor<Image>::BackendHandle(image);
226 const auto optionsC = peak::common::detail::BackendAccessor<detail::DrawingOptions>::CreateCType(options);
228 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Draw(imageHandle, m_regionHandle, optionsC);
229 });
230}
231
232inline Region Region::Intersection(const Region& other) const
233{
234 Region outputRegion;
236 const auto otherHandle = peak::common::detail::BackendAccessor<Region>::BackendHandle(other);
237 const auto outputRegionHandleAddress = peak::common::detail::BackendAccessor<Region>::BackendHandleAddress(outputRegion);
238 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Intersection(m_regionHandle, otherHandle, outputRegionHandleAddress);
239 });
240 return outputRegion;
241}
242
243inline Region Region::Difference(const Region& other) const
244{
245 Region outputRegion;
247 const auto otherHandle = peak::common::detail::BackendAccessor<Region>::BackendHandle(other);
248 const auto outputRegionHandleAddress = peak::common::detail::BackendAccessor<Region>::BackendHandleAddress(outputRegion);
249 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Difference(m_regionHandle, otherHandle, outputRegionHandleAddress);
250 });
251 return outputRegion;
252}
253
254inline Region Region::Union(const Region& other) const
255{
256 Region outputRegion;
258 const auto otherHandle = peak::common::detail::BackendAccessor<Region>::BackendHandle(other);
259 const auto outputRegionHandleAddress = peak::common::detail::BackendAccessor<Region>::BackendHandleAddress(outputRegion);
260 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Union(m_regionHandle, otherHandle, outputRegionHandleAddress);
261 });
262 return outputRegion;
263}
264
265inline Region Region::Dilation(const Region& structuringElement) const
266{
267 Region outputRegion;
269 const auto seHandle = peak::common::detail::BackendAccessor<Region>::BackendHandle(structuringElement);
270 const auto outputRegionHandleAddress = peak::common::detail::BackendAccessor<Region>::BackendHandleAddress(outputRegion);
271 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Dilation(m_regionHandle, seHandle, outputRegionHandleAddress);
272 });
273 return outputRegion;
274}
275
276inline Region Region::Erosion(const Region& structuringElement) const
277{
278 Region outputRegion;
280 const auto seHandle = peak::common::detail::BackendAccessor<Region>::BackendHandle(structuringElement);
281 const auto outputRegionHandleAddress = peak::common::detail::BackendAccessor<Region>::BackendHandleAddress(outputRegion);
282 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Erosion(m_regionHandle, seHandle, outputRegionHandleAddress);
283 });
284 return outputRegion;
285}
286
287inline Region Region::Scale(
288 const peak::common::Size& inputSize, const peak::common::Size& outputSize, const Interpolation& interpolation) const
289{
290 Region outputRegion;
292 const auto outputRegionHandleAddress = peak::common::detail::BackendAccessor<Region>::BackendHandleAddress(outputRegion);
293 return PEAK_ICV_C_ABI_PREFIX peak_icv_Region_Scale(m_regionHandle, { inputSize.GetWidth(), inputSize.GetHeight() },
294 { outputSize.GetWidth(), outputSize.GetHeight() }, static_cast<peak_icv_interpolation>(interpolation),
295 outputRegionHandleAddress);
296 });
297 return outputRegion;
298}
299} /* namespace experimental */
300
301} /* namespace icv */
302} /* namespace peak */
A generic rectangle defined by a point and a size.
Represents a two-dimensional size with non-negative width and height.
constexpr T GetWidth() const
Returns the width.
constexpr T GetHeight() const
Returns the height.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
A region consists of a set of points in the image plane.
Region()
Creates an empty Region.
Interpolation
Interpolation method for image transformations.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
peak::common::detail::c_type_of_t< Type > * handle_of_t