IDS peak ICV v1.2.0
Loading...
Searching...
No Matches
peak_icv_region_selector.hpp
Go to the documentation of this file.
1
11#pragma once
12
17#include <peak_icv_c/selectors/peak_icv_region_selector.h>
18
19#include <functional>
20
21namespace peak
22{
23namespace icv
24{
37{
38public:
46 explicit RegionSelector(const std::vector<Region>& regions);
47
53 std::vector<Region> GetRegions();
54
68
82
96
114
115protected:
116 RegionSelector() = default;
117
118private:
119 template <typename T>
121 const detail::select_by_function_t<peak::common::detail::c_type_of_t<T>>& selectBy, const T& interval);
122
123 std::vector<Region> m_regions;
124};
125
126inline RegionSelector::RegionSelector(const std::vector<Region>& regions)
127 : m_regions{ regions }
128{}
129
130inline std::vector<Region> RegionSelector::GetRegions()
131{
132 return m_regions;
133}
134
136{
137 return SelectBy<peak::common::IntervalU>(
138 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByArea_GetCount, PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByArea, interval);
139}
140
142{
143 return SelectBy<peak::common::IntervalF>(PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityX_GetCount,
144 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityX, interval);
145}
146
148{
149 return SelectBy<peak::common::IntervalF>(PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityY_GetCount,
150 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityY, interval);
151}
152
154{
155 return SelectBy<peak::common::RectangleF>(PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityRect_GetCount,
156 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityRect, rect);
157}
158
159template <typename T>
160RegionSelector RegionSelector::SelectBy(
162 const detail::select_by_function_t<peak::common::detail::c_type_of_t<T>>& selectBy, const T& interval)
163{
164 if (m_regions.empty())
165 {
166 return {};
167 }
168
169 std::vector<peak_icv_region_handle> handles;
170 handles.reserve(m_regions.size());
171
172 std::transform(m_regions.begin(), m_regions.end(), std::back_inserter(handles), [](const auto& region) {
173 return peak::common::detail::BackendAccessor<peak::icv::Region>::BackendHandle(region);
174 });
175
176 size_t count = 0;
178 return selectByGetCount(
179 handles.data(), handles.size(), peak::common::detail::BackendAccessor<T>::CreateCType(interval), &count);
180 });
181
182 if (count == 0)
183 {
184 return {};
185 }
186
187 std::vector<peak_icv_region_handle> selectedHandles(count);
189 return selectBy(handles.data(), handles.size(), peak::common::detail::BackendAccessor<T>::CreateCType(interval),
190 selectedHandles.data(), selectedHandles.size());
191 });
192 return RegionSelector(peak::common::detail::BackendAccessor<peak::icv::Region>::CreateInstances(selectedHandles));
193}
194
195} /* namespace icv */
196} /* namespace peak */
Represents a continuous numeric interval with inclusive lower and upper bounds.
A generic rectangle defined by a point and a size.
Selects regions based on feature criteria.
RegionSelector SelectByArea(const peak::common::IntervalU &interval)
Selects regions by area.
RegionSelector SelectByCenterOfGravityRect(const peak::common::RectangleF &rect)
Selects regions by center of gravity within a rectangle.
RegionSelector SelectByCenterOfGravityY(const peak::common::IntervalF &interval)
Selects regions by center of gravity Y.
RegionSelector SelectByCenterOfGravityX(const peak::common::IntervalF &interval)
Selects regions by center of gravity X.
RegionSelector(const std::vector< Region > &regions)
Constructs a selector for the specified set of regions.
typename c_type_of_< Type >::type c_type_of_t
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
std::function< peak_icv_status(peak_icv_region_handle *, size_t, T, peak_icv_region_handle *, size_t)> select_by_function_t
std::function< peak_icv_status(peak_icv_region_handle *, size_t, T, size_t *)> select_by_get_count_function_t