PyArrayObject* get_keypoint_strokes(int keypointId, int instance) { if(keypointsPixels.size() > 0) { std::pair <std::unordered_multimap<int,std::pair<int, int> >::iterator, std::unordered_multimap<int,std::pair<int, int>>::iterator> ret; ret = keypointsPixels.equal_range(keypoints[keypointId].class_id); npy_intp size_pts[2]; size_pts[0] = std::distance(ret.first, ret.second); size_pts[1] = 2; PyArrayObject* out = (PyArrayObject *) PyArray_SimpleNew( 2, size_pts, NPY_OBJECT ); int strokesCount = 0; for (std::unordered_multimap<int,std::pair<int, int> >::iterator it=ret.first; it!=ret.second; it++) { char* ptr = (char*) PyArray_GETPTR2(out, strokesCount, 0); PyArray_SETITEM(out, ptr, PyInt_FromLong(it->second.first)); ptr = (char*) PyArray_GETPTR2(out, strokesCount, 1); PyArray_SETITEM(out, ptr, PyInt_FromLong(it->second.second)); strokesCount++; } return out; } std::vector<std::vector<cv::Ptr<StrokeDir> > >& strokes = instances[instance].segmenter->keypointStrokes[keypointId]; npy_intp size_pts[2]; int strokesCount = 0; for( size_t i = 0; i < strokes.size(); i++ ) { strokesCount += strokes[i].size(); } size_pts[0] = strokesCount; size_pts[1] = 4; PyArrayObject* out = (PyArrayObject *) PyArray_SimpleNew( 2, size_pts, NPY_OBJECT ); strokesCount = 0; for( size_t i = 0; i < strokes.size(); i++ ) { for( size_t j = 0; j < strokes[i].size(); j++ ) { char* ptr = (char*) PyArray_GETPTR2(out, strokesCount, 0); PyArray_SETITEM(out, ptr, PyInt_FromLong(strokes[i][j]->center.x)); ptr = (char*) PyArray_GETPTR2(out, strokesCount, 1); PyArray_SETITEM(out, ptr, PyInt_FromLong(strokes[i][j]->center.y)); ptr = (char*) PyArray_GETPTR2(out, strokesCount, 2); PyArray_SETITEM(out, ptr, PyInt_FromLong(strokes[i][j]->direction.x)); ptr = (char*) PyArray_GETPTR2(out, strokesCount, 3); PyArray_SETITEM(out, ptr, PyInt_FromLong(strokes[i][j]->direction.y)); strokesCount++; } } return out; }
void filesIncomingToRawFilesInfo(Utils::raw_fileinfo *raw[], const std::unordered_multimap<std::string, HttpServer::FileIncoming> &map) { if (raw && map.size() ) { raw_fileinfo *arr = new raw_fileinfo[map.size()]; *raw = arr; size_t i = 0; for (auto it = map.cbegin(); map.cend() != it; ++it, ++i) { arr[i].key = stlStringToPChar(it->first); const HttpServer::FileIncoming &file = it->second; arr[i].file_name = stlStringToPChar(file.getName() ); arr[i].file_type = stlStringToPChar(file.getType() ); arr[i].file_size = file.getSize(); } } }
void packFilesIncoming( std::vector<char> &buf, const std::unordered_multimap<std::string, Transfer::FileIncoming> &map ) { packNumber(buf, map.size() ); for (auto it = map.cbegin(); map.cend() != it; ++it) { packString(buf, it->first); const Transfer::FileIncoming &file = it->second; packString(buf, file.getTmpName() ); packString(buf, file.getName() ); packString(buf, file.getType() ); packNumber(buf, file.getSize() ); } }
inline std::string PrettyPrint(const std::unordered_multimap<A, B, Hash, Predicate, Allocator>& maptoprint, const bool add_delimiters=false, const std::string& separator=", ") { std::ostringstream strm; if (maptoprint.size() > 0) { if (add_delimiters) { strm << "{"; typename std::unordered_multimap<A, B, Hash, Predicate, Allocator>::const_iterator itr; for (itr = maptoprint.begin(); itr != maptoprint.end(); ++itr) { std::pair<A, B> cur_pair(itr->first, itr->second); if (itr != maptoprint.begin()) { strm << separator << PrettyPrint(cur_pair, add_delimiters, separator); } else { strm << PrettyPrint(cur_pair, add_delimiters, separator); } } strm << "}"; } else { typename std::unordered_multimap<A, B, Hash, Predicate, Allocator>::const_iterator itr; for (itr = maptoprint.begin(); itr != maptoprint.end(); ++itr) { std::pair<A, B> cur_pair(itr->first, itr->second); if (itr != maptoprint.begin()) { strm << separator << PrettyPrint(cur_pair, add_delimiters, separator); } else { strm << PrettyPrint(cur_pair, add_delimiters, separator); } } } } return strm.str(); }
void operator()(msgpack::object::with_zone& o, const std::unordered_multimap<K, V, Hash, Compare, Alloc>& v) const { o.type = msgpack::type::MAP; if(v.empty()) { o.via.map.ptr = nullptr; o.via.map.size = 0; } else { uint32_t size = checked_get_container_size(v.size()); msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size)); msgpack::object_kv* const pend = p + size; o.via.map.ptr = p; o.via.map.size = size; typename std::unordered_multimap<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin()); do { p->key = msgpack::object(it->first, o.zone); p->val = msgpack::object(it->second, o.zone); ++p; ++it; } while(p < pend); } }