static Variant HHVM_METHOD(IntlDateFormatter, localtime, const String& value, VRefParam position) { DATFMT_GET(data, this_, uninit_null()); int32_t parse_pos = -1; if (!position.isNull()) { parse_pos = position.toInt64(); if (parse_pos > value.size()) { return false; } } UErrorCode error = U_ZERO_ERROR; String uValue(u16(value, error)); if (U_FAILURE(error)) { data->setError(error, "Error converting timezone to UTF-16"); return false; } error = U_ZERO_ERROR; UCalendar *cal = const_cast<UCalendar*>(udat_getCalendar(data->datefmt())); udat_parseCalendar(data->datefmt(), cal, (UChar*)uValue.c_str(), uValue.size() / sizeof(UChar), &parse_pos, &error); Array ret = Array::Create(); error = U_ZERO_ERROR; add_to_localtime_arr(ret, cal, UCAL_SECOND, s_tm_sec, error); add_to_localtime_arr(ret, cal, UCAL_MINUTE, s_tm_min, error); add_to_localtime_arr(ret, cal, UCAL_HOUR_OF_DAY, s_tm_hour, error); add_to_localtime_arr(ret, cal, UCAL_YEAR, s_tm_year, error, -1900); add_to_localtime_arr(ret, cal, UCAL_DAY_OF_MONTH, s_tm_mday, error); add_to_localtime_arr(ret, cal, UCAL_DAY_OF_WEEK, s_tm_wday, error, -1); add_to_localtime_arr(ret, cal, UCAL_DAY_OF_YEAR, s_tm_yday, error); add_to_localtime_arr(ret, cal, UCAL_MONTH, s_tm_mon, error); if (U_FAILURE(error)) { data->setError(error, "Date parsing - localtime failed : " "could not get a field from calendar"); return false; } error = U_ZERO_ERROR; auto isDST = ucal_inDaylightTime(cal, &error); if (U_FAILURE(error)) { data->setError(error, "Date parsing - localtime failed : " "while checking if currently in DST."); return false; } ret.set(s_tm_isdst, isDST ? 1 : 0); position = (int64_t)parse_pos; return ret; }
float BayesFilter::addNeighborProb(cv::Mat & prediction, unsigned int col, const std::map<int, int> & neighbors, const std::map<int, int> & idToIndexMap) const { UASSERT((unsigned int)prediction.cols == idToIndexMap.size() && (unsigned int)prediction.rows == idToIndexMap.size() && col < (unsigned int)prediction.cols && col < (unsigned int)prediction.rows); float sum=0; for(std::map<int, int>::const_iterator iter=neighbors.begin(); iter!=neighbors.end(); ++iter) { int index = uValue(idToIndexMap, iter->first, -1); if(index >= 0) { sum += ((float*)prediction.data)[col + index*prediction.cols] = _predictionLC[iter->second+1]; } } return sum; }
uint64_t uintFromHex (std::string const& strSrc) { uint64_t uValue (0); if (strSrc.size () > 16) Throw<std::invalid_argument> ("overlong 64-bit value"); for (auto c : strSrc) { int ret = charUnHex (c); if (ret == -1) Throw<std::invalid_argument> ("invalid hex digit"); uValue = (uValue << 4) | ret; } return uValue; }
void RTABMapApp::handleEvent(UEvent * event) { if(camera_ && camera_->isRunning()) { // called from events manager thread, so protect the data if(event->getClassName().compare("OdometryEvent") == 0) { LOGI("Received OdometryEvent!"); if(odomMutex_.try_lock()) { odomEvents_.clear(); if(camera_->isRunning()) { odomEvents_.push_back(*((rtabmap::OdometryEvent*)(event))); } odomMutex_.unlock(); } } if(status_.first == rtabmap::RtabmapEventInit::kInitialized && event->getClassName().compare("RtabmapEvent") == 0) { LOGI("Received RtabmapEvent!"); if(camera_->isRunning()) { boost::mutex::scoped_lock lock(rtabmapMutex_); rtabmapEvents_.push_back(((rtabmap::RtabmapEvent*)event)->getStats()); } } } if(event->getClassName().compare("PoseEvent") == 0) { if(poseMutex_.try_lock()) { poseEvents_.clear(); poseEvents_.push_back(((rtabmap::PoseEvent*)event)->pose()); poseMutex_.unlock(); } } if(event->getClassName().compare("CameraTangoEvent") == 0) { rtabmap::CameraTangoEvent * tangoEvent = (rtabmap::CameraTangoEvent*)event; // Call JAVA callback with tango event msg bool success = false; if(jvm && RTABMapActivity) { JNIEnv *env = 0; jint rs = jvm->AttachCurrentThread(&env, NULL); if(rs == JNI_OK && env) { jclass clazz = env->GetObjectClass(RTABMapActivity); if(clazz) { jmethodID methodID = env->GetMethodID(clazz, "tangoEventCallback", "(ILjava/lang/String;Ljava/lang/String;)V" ); if(methodID) { env->CallVoidMethod(RTABMapActivity, methodID, tangoEvent->type(), env->NewStringUTF(tangoEvent->key().c_str()), env->NewStringUTF(tangoEvent->value().c_str())); success = true; } } } jvm->DetachCurrentThread(); } if(!success) { UERROR("Failed to call RTABMapActivity::tangoEventCallback"); } } if(event->getClassName().compare("RtabmapEventInit") == 0) { LOGI("Received RtabmapEventInit!"); status_.first = ((rtabmap::RtabmapEventInit*)event)->getStatus(); status_.second = ((rtabmap::RtabmapEventInit*)event)->getInfo(); if(status_.first == rtabmap::RtabmapEventInit::kClosed) { clearSceneOnNextRender_ = true; } // Call JAVA callback with init msg bool success = false; if(jvm && RTABMapActivity) { JNIEnv *env = 0; jint rs = jvm->AttachCurrentThread(&env, NULL); if(rs == JNI_OK && env) { jclass clazz = env->GetObjectClass(RTABMapActivity); if(clazz) { jmethodID methodID = env->GetMethodID(clazz, "rtabmapInitEventCallback", "(ILjava/lang/String;)V" ); if(methodID) { env->CallVoidMethod(RTABMapActivity, methodID, status_.first, env->NewStringUTF(status_.second.c_str())); success = true; } } } jvm->DetachCurrentThread(); } if(!success) { UERROR("Failed to call RTABMapActivity::rtabmapInitEventsCallback"); } } if(event->getClassName().compare("PostRenderEvent") == 0) { LOGI("Received PostRenderEvent!"); const rtabmap::Statistics & stats = ((PostRenderEvent*)event)->getStats(); int nodes = (int)uValue(stats.data(), rtabmap::Statistics::kMemoryWorking_memory_size(), 0.0f) + uValue(stats.data(), rtabmap::Statistics::kMemoryShort_time_memory_size(), 0.0f); int words = (int)uValue(stats.data(), rtabmap::Statistics::kKeypointDictionary_size(), 0.0f); float updateTime = uValue(stats.data(), rtabmap::Statistics::kTimingTotal(), 0.0f); int loopClosureId = stats.loopClosureId()>0?stats.loopClosureId():stats.proximityDetectionId()>0?stats.proximityDetectionId():0; int highestHypId = (int)uValue(stats.data(), rtabmap::Statistics::kLoopHighest_hypothesis_id(), 0.0f); int databaseMemoryUsed = (int)uValue(stats.data(), rtabmap::Statistics::kMemoryDatabase_memory_used(), 0.0f); int inliers = (int)uValue(stats.data(), rtabmap::Statistics::kLoopVisual_inliers(), 0.0f); int rejected = (int)uValue(stats.data(), rtabmap::Statistics::kLoopRejectedHypothesis(), 0.0f); int featuresExtracted = stats.getSignatures().size()?stats.getSignatures().rbegin()->second.getWords().size():0; float hypothesis = uValue(stats.data(), rtabmap::Statistics::kLoopHighest_hypothesis_value(), 0.0f); // Call JAVA callback with some stats UINFO("Send statistics to GUI"); bool success = false; if(jvm && RTABMapActivity) { JNIEnv *env = 0; jint rs = jvm->AttachCurrentThread(&env, NULL); if(rs == JNI_OK && env) { jclass clazz = env->GetObjectClass(RTABMapActivity); if(clazz) { jmethodID methodID = env->GetMethodID(clazz, "updateStatsCallback", "(IIIIFIIIIIFIFI)V" ); if(methodID) { env->CallVoidMethod(RTABMapActivity, methodID, nodes, words, totalPoints_, totalPolygons_, updateTime, loopClosureId, highestHypId, databaseMemoryUsed, inliers, featuresExtracted, hypothesis, lastDrawnCloudsCount_, renderingFPS_, rejected); success = true; } } } jvm->DetachCurrentThread(); } if(!success) { UERROR("Failed to call RTABMapActivity::updateStatsCallback"); } } }