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