3DiVi Face SDK  3.24.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups
TemplatesIndex.h
Go to the documentation of this file.
1 
9 #ifndef __PBIO_API__PBIO__TEMPLATES_INDEX_H_
10 #define __PBIO_API__PBIO__TEMPLATES_INDEX_H_
11 
12 
13 #include <ostream>
14 #include <sstream>
15 #include <vector>
16 #include <string>
17 
18 
19 #include "ComplexObject.h"
20 #include "Error.h"
21 #include "SmartPtr.h"
22 #include "stl_wraps_impls/WrapOStreamImpl.h"
23 
24 
25 
26 
27 namespace pbio
28 {
29 
30 class Recognizer;
31 
37 class TemplatesIndex : public ComplexObject
38 {
39 public:
40 
46  typedef LightSmartPtr<TemplatesIndex>::tPtr Ptr;
47 
65  std::string getMethodName() const;
66 
84  size_t size() const;
85 
109  pbio::Template::Ptr at(size_t i) const;
110 
111 
132  void reserveSearchMemory(const int queries_count) const;
133 
134  void add(pbio::Template::Ptr templ, const std::string& uuid);
135 
136  void remove(const std::string& uuid);
137 
138  void remove(const std::vector<std::string>& uuids);
139 
140  void concat(TemplatesIndex::Ptr otherIndex);
141 
142 private:
143 
145  const DHPtr &dll_handle,
146  void* impl);
147 
148  friend class Recognizer;
149  friend class object_with_ref_counter<TemplatesIndex>;
150 };
151 
152 } // pbio namespace
153 
154 
155 
156 
160 
161 namespace pbio
162 {
163 
164 inline
165 TemplatesIndex::TemplatesIndex(
166  const DHPtr &dll_handle,
167  void* impl):
168 ComplexObject(dll_handle, impl)
169 {
170  // nothing else
171 }
172 
173 
174 
175 inline
176 std::string TemplatesIndex::getMethodName() const
177 {
178  std::ostringstream name_stream;
179  pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
180 
181  void* exception = NULL;
182 
183  _dll_handle->TemplatesIndex_getMethodName(
184  _impl,
185  &name_stream_wrap,
186  pbio::stl_wraps::WrapOStream::write_func,
187  &exception);
188 
189  checkException(exception, *_dll_handle);
190 
191  return name_stream.str();
192 }
193 
194 
195 inline
196 size_t TemplatesIndex::size() const
197 {
198  void* exception = NULL;
199 
200  const size_t size = _dll_handle->TemplatesIndex_size(
201  _impl,
202  &exception);
203 
204  checkException(exception, *_dll_handle);
205 
206  return size;
207 }
208 
209 
210 inline
212 {
213  void* exception = NULL;
214 
215  pbio::facerec::TemplateImpl* const result_impl = _dll_handle->TemplatesIndex_at(
216  _impl,
217  i,
218  &exception);
219 
220  checkException(exception, *_dll_handle);
221 
222  return Template::Ptr::make(_dll_handle, result_impl);
223 }
224 
225 
226 inline
227 void TemplatesIndex::reserveSearchMemory(const int queries_count) const
228 {
229  void* exception = NULL;
230 
231  _dll_handle->TemplatesIndex_reserveSearchMemory(
232  _impl,
233  queries_count,
234  &exception);
235 
236  checkException(exception, *_dll_handle);
237 }
238 
239 inline void TemplatesIndex::add(pbio::Template::Ptr templ, const std::string& uuid)
240 {
241  void* exception = NULL;
242 
243  _dll_handle->ResizableTemplatesIndex_add_1(_impl, static_cast<pbio::facerec::TemplateImpl*>(templ->_impl), uuid.data(), &exception);
244 
245  checkException(exception, *_dll_handle);
246 }
247 
248 inline void TemplatesIndex::remove(const std::string& uuid)
249 {
250  void* exception = NULL;
251 
252  _dll_handle->ResizableTemplatesIndex_remove_1(_impl, uuid.data(), &exception);
253 
254  checkException(exception, *_dll_handle);
255 }
256 
257 inline void TemplatesIndex::remove(const std::vector<std::string>& uuids)
258 {
259  void* exception = NULL;
260 
261  const char** data = new const char*[uuids.size()];
262 
263  for (size_t i = 0; i < uuids.size(); i++)
264  {
265  data[i] = uuids[i].data();
266  }
267 
268  _dll_handle->ResizableTemplatesIndex_remove_2(_impl, data, uuids.size(), &exception);
269 
270  delete[] data;
271 
272  checkException(exception, *_dll_handle);
273 }
274 
275 inline void TemplatesIndex::concat(TemplatesIndex::Ptr otherIndex)
276 {
277  void* exception = NULL;
278 
279  _dll_handle->ResizableTemplatesIndex_concatenate(_impl, otherIndex->_impl, &exception);
280 
281  checkException(exception, *_dll_handle);
282 }
283 
284 } // pbio namespace
285 #endif // __PBIO_API__PBIO__TEMPLATES_INDEX_H_
size_t size() const
Get a number of templates in the index. Thread-safe.
Definition: TemplatesIndex.h:196
Interface object for working with the template index.
Definition: TemplatesIndex.h:37
std::string getMethodName() const
Get a method name. Thread-safe.
Definition: TemplatesIndex.h:176
Definition: Recognizer.h:64
Interface object for creating and matching templates.
Definition: Recognizer.h:37
LightSmartPtr< Template >::tPtr Ptr
Alias for the type of a smart pointer to Template.
Definition: Template.h:46
LightSmartPtr< TemplatesIndex >::tPtr Ptr
Alias for the type of a smart pointer to TemplatesIndex.
Definition: TemplatesIndex.h:46
Error - the class of exceptions thrown when errors occur.
void reserveSearchMemory(const int queries_count) const
Reserve memory for temporary buffers used while searching. These temporary buffers require 8 * size()...
Definition: TemplatesIndex.h:227
SmartPtr.
pbio::Template::Ptr at(size_t i) const
Get an i-th template. Thread-safe.
Definition: TemplatesIndex.h:211