IDS peak ICV v1.0.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{
25namespace experimental
26{
37{
38public:
46 explicit RegionSelector(const std::vector<Region>& regions);
47
53 std::vector<Region> GetRegions();
54
65
76
87
101
102protected:
103 RegionSelector() = default;
104
105private:
106 template <typename T>
108 const detail::select_by_function_t<peak::common::detail::c_type_of_t<T>>& selectBy, const T& interval);
109
110 std::vector<Region> m_regions;
111};
112
113inline RegionSelector::RegionSelector(const std::vector<Region>& regions)
114 : m_regions{ regions }
115{}
116
117inline std::vector<Region> RegionSelector::GetRegions()
118{
119 return m_regions;
120}
121
123{
124 return SelectBy<peak::common::IntervalU>(
125 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByArea_GetCount, PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByArea, interval);
126}
127
129{
130 return SelectBy<peak::common::IntervalF>(PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityX_GetCount,
131 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityX, interval);
132}
133
135{
136 return SelectBy<peak::common::IntervalF>(PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityY_GetCount,
137 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityY, interval);
138}
139
141{
142 return SelectBy<peak::common::RectangleF>(PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityRect_GetCount,
143 PEAK_ICV_C_ABI_PREFIX peak_icv_Region_SelectByCenterOfGravityRect, rect);
144}
145
146template <typename T>
147RegionSelector RegionSelector::SelectBy(
149 const detail::select_by_function_t<peak::common::detail::c_type_of_t<T>>& selectBy, const T& interval)
150{
151 if (m_regions.empty())
152 {
153 return {};
154 }
155
156 std::vector<peak_icv_region_handle> handles;
157 handles.reserve(m_regions.size());
158
159 std::transform(m_regions.begin(), m_regions.end(), std::back_inserter(handles), [](const auto& region) {
160 return peak::common::detail::BackendAccessor<peak::icv::experimental::Region>::BackendHandle(region);
161 });
162
163 size_t count = 0;
165 return selectByGetCount(
166 handles.data(), handles.size(), peak::common::detail::BackendAccessor<T>::CreateCType(interval), &count);
167 });
168
169 if (count == 0)
170 {
171 return {};
172 }
173
174 std::vector<peak_icv_region_handle> selectedHandles(count);
176 return selectBy(handles.data(), handles.size(), peak::common::detail::BackendAccessor<T>::CreateCType(interval),
177 selectedHandles.data(), selectedHandles.size());
178 });
179 return RegionSelector(peak::common::detail::BackendAccessor<peak::icv::experimental::Region>::CreateInstances(selectedHandles));
180}
181
182} /* namespace experimental */
183} /* namespace icv */
184} /* namespace peak */
Represents a continuous numeric interval with inclusive lower and upper bounds.
A generic rectangle defined by a point and a size.
RegionSelector SelectByArea(const peak::common::IntervalU &interval)
Select a number of regions from a set of input regions by their area.
RegionSelector SelectByCenterOfGravityRect(const peak::common::RectangleF &rect)
Select a number of regions from a set of input regions by their center of gravity.
std::vector< Region > GetRegions()
Returns the selected regions.
RegionSelector SelectByCenterOfGravityY(const peak::common::IntervalF &interval)
Select a number of regions from a set of input regions by their center of gravity y.
RegionSelector SelectByCenterOfGravityX(const peak::common::IntervalF &interval)
Select a number of regions from a set of input regions by their center of gravity x.
RegionSelector(const std::vector< Region > &regions)
Constructor.
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