void OsmAnd::TextRasterizer_P::measureHaloGlyphs( const Style& style, const QVector<LinePaint>& paints, QVector<SkScalar>& outGlyphWidths) const { for (const auto& linePaint : constOf(paints)) { for (const auto& textPaint : constOf(linePaint.textPaints)) { const auto haloPaint = getHaloPaint(textPaint.paint, style); const auto glyphsCount = haloPaint.countText( textPaint.text.constData(), textPaint.text.length()*sizeof(QChar)); const auto previousSize = outGlyphWidths.size(); outGlyphWidths.resize(previousSize + glyphsCount); const auto pWidth = outGlyphWidths.data() + previousSize; haloPaint.getTextWidths( textPaint.text.constData(), textPaint.text.length()*sizeof(QChar), pWidth); *pWidth += -textPaint.bounds.left(); } } }
std::shared_ptr<OsmAnd::ObfDataInterface> OsmAnd::ObfsCollection_P::obtainDataInterface() const { // Check if sources were invalidated if (_collectedSourcesInvalidated.loadAcquire() > 0) collectSources(); // Create ObfReaders from collected sources QList< std::shared_ptr<const ObfReader> > obfReaders; { QReadLocker scopedLocker(&_collectedSourcesLock); for(const auto& collectedSources : constOf(_collectedSources)) { obfReaders.reserve(obfReaders.size() + collectedSources.size()); for(const auto& obfFile : constOf(collectedSources)) { std::shared_ptr<const ObfReader> obfReader(new ObfReader(obfFile)); if (!obfReader->isOpened() || !obfReader->obtainInfo()) continue; obfReaders.push_back(qMove(obfReader)); } } } return std::shared_ptr<ObfDataInterface>(new ObfDataInterface(obfReaders)); }
std::shared_ptr<OsmAnd::ResolvedMapStyle_P::RuleNode> OsmAnd::ResolvedMapStyle_P::resolveRuleNode( const std::shared_ptr<const UnresolvedMapStyle::RuleNode>& unresolvedRuleNode) { const std::shared_ptr<RuleNode> resolvedRuleNode(new RuleNode( unresolvedRuleNode->isSwitch)); // Resolve values for (const auto& itUnresolvedValueEntry : rangeOf(constOf(unresolvedRuleNode->values))) { const auto& name = itUnresolvedValueEntry.key(); const auto& value = itUnresolvedValueEntry.value(); // Find value definition id and object const auto valueDefId = getValueDefinitionIdByName(name); const auto& valueDef = getValueDefinitionById(valueDefId); if (valueDefId < 0 || !valueDef) { LogPrintf(LogSeverityLevel::Warning, "Ignoring unknown value '%s' = '%s'", qPrintable(name), qPrintable(value)); continue; } // Try to resolve value ResolvedValue resolvedValue; if (!resolveValue(value, valueDef->dataType, valueDef->isComplex, resolvedValue)) { LogPrintf(LogSeverityLevel::Warning, "Ignoring value for '%s' since '%s' can not be resolved", qPrintable(name), qPrintable(value)); continue; } resolvedRuleNode->values[valueDefId] = resolvedValue; } // <switch>/<case> subnodes for (const auto& unresolvedChild : constOf(unresolvedRuleNode->oneOfConditionalSubnodes)) { const auto resolvedChild = resolveRuleNode(unresolvedChild); if (!resolvedChild) return nullptr; resolvedRuleNode->oneOfConditionalSubnodes.push_back(resolvedChild); } // <apply> subnodes for (const auto& unresolvedChild : constOf(unresolvedRuleNode->applySubnodes)) { const auto resolvedChild = resolveRuleNode(unresolvedChild); if (!resolvedChild) return nullptr; resolvedRuleNode->applySubnodes.push_back(resolvedChild); } return resolvedRuleNode; }
OsmAnd::RoutePlannerContext::RoutePlannerContext( const QList< std::shared_ptr<ObfReader> >& sources, const std::shared_ptr<RoutingConfiguration>& routingConfig, const QString& vehicle, bool useBasemap, float initialHeading /*= std::numeric_limits<float>::quiet_NaN()*/, QHash<QString, QString>* options /*=nullptr*/, size_t memoryLimit ) : _useBasemap(useBasemap) , _memoryUsageLimit(memoryLimit) , _loadedTiles(0) , _initialHeading(initialHeading) , sources(sources) , configuration(routingConfig) , _routeStatistics(new RouteStatistics) , profileContext(new RoutingProfileContext(configuration->routingProfiles[vehicle], options)) { _partialRecalculationDistanceLimit = Utilities::parseArbitraryFloat(configuration->resolveAttribute(vehicle, "recalculateDistanceHelp"), 10000.0f); _heuristicCoefficient = Utilities::parseArbitraryFloat(configuration->resolveAttribute(vehicle, "heuristicCoefficient"), 1.0f); _planRoadDirection = Utilities::parseArbitraryInt(configuration->resolveAttribute(vehicle, "planRoadDirection"), 0); _roadTilesLoadingZoomLevel = Utilities::parseArbitraryUInt(configuration->resolveAttribute(vehicle, "zoomToLoadTiles"), DefaultRoadTilesLoadingZoomLevel); for(const auto& source : constOf(sources)) { const auto& obfInfo = source->obtainInfo(); for(const auto& routingSection : constOf(obfInfo->routingSections)) _sourcesLUT.insert(routingSection.get(), source); } }
bool OsmAnd::ObfDataInterface::loadMapObjects( QList< std::shared_ptr<const OsmAnd::Model::BinaryMapObject> >* resultOut, MapFoundationType* foundationOut, const AreaI& area31, const ZoomLevel zoom, const IQueryController* const controller /*= nullptr*/, const FilterMapObjectsByIdSignature filterById /*= nullptr*/, ObfMapSectionReader_Metrics::Metric_loadMapObjects* const metric /*= nullptr*/) { if (foundationOut) *foundationOut = MapFoundationType::Undefined; // Iterate through all OBF readers for(const auto& obfReader : constOf(obfReaders)) { // Check if request is aborted if (controller && controller->isAborted()) return false; // Iterate over all map sections of each OBF reader const auto& obfInfo = obfReader->obtainInfo(); for(const auto& mapSection : constOf(obfInfo->mapSections)) { // Check if request is aborted if (controller && controller->isAborted()) return false; // Read objects from each map section OsmAnd::ObfMapSectionReader::loadMapObjects(obfReader, mapSection, zoom, &area31, resultOut, foundationOut, filterById, nullptr, controller, metric); } } return true; }
bool OsmAnd::MapRendererKeyedSymbolsResource::obtainData(bool& dataAvailable, const IQueryController* queryController) { // Obtain collection link and maintain it const auto link_ = link.lock(); if (!link_) return false; const auto collection = static_cast<MapRendererKeyedResourcesCollection*>(&link_->collection); // Get source std::shared_ptr<IMapDataProvider> provider_; bool ok = resourcesManager->obtainProviderFor(static_cast<MapRendererBaseResourcesCollection*>(collection), provider_); if (!ok) return false; const auto provider = std::static_pointer_cast<IMapKeyedDataProvider>(provider_); // Obtain source data from provider std::shared_ptr<IMapKeyedDataProvider::Data> keyedData; const auto requestSucceeded = provider->obtainData(key, keyedData); if (!requestSucceeded) return false; // Store data dataAvailable = static_cast<bool>(keyedData); if (dataAvailable) _sourceData = std::static_pointer_cast<IMapKeyedSymbolsProvider::Data>(keyedData); // Process data if (!dataAvailable) return true; // Convert data for (const auto& mapSymbol : constOf(_sourceData->symbolsGroup->symbols)) { const auto rasterMapSymbol = std::dynamic_pointer_cast<RasterMapSymbol>(mapSymbol); if (!rasterMapSymbol) continue; rasterMapSymbol->bitmap = resourcesManager->adjustBitmapToConfiguration( rasterMapSymbol->bitmap, AlphaChannelPresence::Present); } // Register all obtained symbols _mapSymbolsGroup = _sourceData->symbolsGroup; const auto self = shared_from_this(); QList< PublishOrUnpublishMapSymbol > mapSymbolsToPublish; mapSymbolsToPublish.reserve(_mapSymbolsGroup->symbols.size()); for (const auto& symbol : constOf(_mapSymbolsGroup->symbols)) { PublishOrUnpublishMapSymbol mapSymbolToPublish = { _mapSymbolsGroup, std::static_pointer_cast<const MapSymbol>(symbol), self }; mapSymbolsToPublish.push_back(mapSymbolToPublish); } resourcesManager->batchPublishMapSymbols(mapSymbolsToPublish); return true; }
bool OsmAnd::ResolvedMapStyle_P::mergeAndResolveParameters() { // Process styles chain in direct order, to exclude redefined parameters auto citUnresolvedMapStyle = iteratorOf(owner->unresolvedMapStylesChain); while (citUnresolvedMapStyle.hasNext()) { const auto& unresolvedMapStyle = citUnresolvedMapStyle.next(); for (const auto& unresolvedParameter : constOf(unresolvedMapStyle->parameters)) { const auto nameId = resolveStringIdInLUT(unresolvedParameter->name); auto& resolvedParameter = _parameters[nameId]; // Skip already defined parameters if (resolvedParameter) continue; // Resolve possible values QList<MapStyleConstantValue> resolvedPossibleValues; for (const auto& possibleValue : constOf(unresolvedParameter->possibleValues)) { MapStyleConstantValue resolvedPossibleValue; if (!parseConstantValue(possibleValue, unresolvedParameter->dataType, false, resolvedPossibleValue)) { LogPrintf(LogSeverityLevel::Error, "Failed to parse '%s' as possible value for '%s' (%s)", qPrintable(possibleValue), qPrintable(unresolvedParameter->name), qPrintable(unresolvedParameter->title)); return false; } resolvedPossibleValues.push_back(qMove(resolvedPossibleValue)); } // Create new resolved parameter const std::shared_ptr<Parameter> newResolvedParameter(new Parameter( unresolvedParameter->title, unresolvedParameter->description, unresolvedParameter->category, nameId, unresolvedParameter->dataType, resolvedPossibleValues)); resolvedParameter = newResolvedParameter; // Register parameter as value definition const auto newValueDefId = _valuesDefinitions.size(); const std::shared_ptr<ParameterValueDefinition> inputValueDefinition(new ParameterValueDefinition( newValueDefId, unresolvedParameter->name, newResolvedParameter)); _valuesDefinitions.push_back(inputValueDefinition); _valuesDefinitionsIndicesByName.insert(unresolvedParameter->name, newValueDefId); } } return true; }
bool OsmAnd::MapRendererKeyedSymbolsResource::uploadToGPU() { bool ok; bool anyUploadFailed = false; const auto link_ = link.lock(); const auto collection = static_cast<MapRendererKeyedResourcesCollection*>(&link_->collection); QHash< std::shared_ptr<MapSymbol>, std::shared_ptr<const GPUAPI::ResourceInGPU> > uploaded; for (const auto& symbol : constOf(_sourceData->symbolsGroup->symbols)) { // Prepare data and upload to GPU std::shared_ptr<const GPUAPI::ResourceInGPU> resourceInGPU; ok = resourcesManager->uploadSymbolToGPU(symbol, resourceInGPU); // If upload have failed, stop if (!ok) { LogPrintf(LogSeverityLevel::Error, "Failed to upload keyed symbol"); anyUploadFailed = true; break; } // Mark this symbol as uploaded uploaded.insert(symbol, qMove(resourceInGPU)); } // If at least one symbol failed to upload, consider entire tile as failed to upload, // and unload its partial GPU resources if (anyUploadFailed) { uploaded.clear(); return false; } // All resources have been uploaded to GPU successfully by this point _retainableCacheMetadata = _sourceData->retainableCacheMetadata; _sourceData.reset(); for (const auto& entry : rangeOf(constOf(uploaded))) { const auto& symbol = entry.key(); auto& resource = entry.value(); // Unload GPU data from symbol, since it's uploaded already resourcesManager->releaseGpuUploadableDataFrom(symbol); // Move reference _resourcesInGPU.insert(symbol, qMove(resource)); } return true; }
bool OsmAnd::ObfDataInterface::loadIntersectionsFromStreets( const QList< std::shared_ptr<const Street> >& streets, QHash< std::shared_ptr<const Street>, QList< std::shared_ptr<const StreetIntersection> > >* resultOut /*= nullptr*/, const AreaI* const bbox31 /*= nullptr*/, const ObfAddressSectionReader::IntersectionVisitorFunction visitor /*= nullptr*/, const std::shared_ptr<const IQueryController>& queryController /*= nullptr*/) { for (const auto& obfReader : constOf(obfReaders)) { if (queryController && queryController->isAborted()) return false; const auto& obfInfo = obfReader->obtainInfo(); for (const auto& addressSection : constOf(obfInfo->addressSections)) { if (queryController && queryController->isAborted()) return false; if (bbox31) { bool accept = false; accept = accept || addressSection->area31.contains(*bbox31); accept = accept || addressSection->area31.intersects(*bbox31); accept = accept || bbox31->contains(addressSection->area31); if (!accept) continue; } for (const auto& street : constOf(streets)) { if (addressSection != street->streetGroup->obfSection) continue; QList< std::shared_ptr<const StreetIntersection> > intermediateResult; OsmAnd::ObfAddressSectionReader::loadIntersectionsFromStreet( obfReader, street, resultOut ? &intermediateResult : nullptr, bbox31, visitor, queryController); if (resultOut) resultOut->insert(street, intermediateResult); } } } return true; }
bool OsmAnd::ObfDataInterface::loadAmenityCategories( QHash<QString, QStringList>* outCategories, const AreaI* const pBbox31 /*= nullptr*/, const std::shared_ptr<const IQueryController>& queryController /*= nullptr*/) { for (const auto& obfReader : constOf(obfReaders)) { if (queryController && queryController->isAborted()) return false; const auto& obfInfo = obfReader->obtainInfo(); for (const auto& poiSection : constOf(obfInfo->poiSections)) { if (queryController && queryController->isAborted()) return false; if (pBbox31) { bool accept = false; accept = accept || poiSection->area31.contains(*pBbox31); accept = accept || poiSection->area31.intersects(*pBbox31); accept = accept || pBbox31->contains(poiSection->area31); if (!accept) continue; } std::shared_ptr<const ObfPoiSectionCategories> categories; OsmAnd::ObfPoiSectionReader::loadCategories( obfReader, poiSection, categories, queryController); if (!categories) continue; for (auto mainCategoryIndex = 0; mainCategoryIndex < categories->mainCategories.size(); mainCategoryIndex++) { outCategories->insert( categories->mainCategories[mainCategoryIndex], categories->subCategories[mainCategoryIndex]); } } } return true; }
bool OsmAnd::ResolvedMapStyle_P::mergeAndResolveAttributes() { QHash<StringId, std::shared_ptr<Attribute> > attributes; // Process styles chain in direct order to ensure "overridden" <case> elements are processed first auto citUnresolvedMapStyle = iteratorOf(owner->unresolvedMapStylesChain); while (citUnresolvedMapStyle.hasNext()) { const auto& unresolvedMapStyle = citUnresolvedMapStyle.next(); for (const auto& unresolvedAttribute : constOf(unresolvedMapStyle->attributes)) { const auto nameId = resolveStringIdInLUT(unresolvedAttribute->name); auto& resolvedAttribute = attributes[nameId]; // Create resolved attribute if needed if (!resolvedAttribute) resolvedAttribute.reset(new Attribute(nameId)); const auto resolvedRuleNode = resolveRuleNode(unresolvedAttribute->rootNode); resolvedAttribute->rootNode->oneOfConditionalSubnodes.append(resolvedRuleNode->oneOfConditionalSubnodes); } } _attributes = copyAs< StringId, std::shared_ptr<const IMapStyle::IAttribute> >(attributes); return true; }
void OsmAnd::RoutingConfiguration::parseRoutingRuleset( QXmlStreamReader* xmlParser, RoutingProfile* routingProfile, RoutingRuleset::Type rulesetType, QStack< std::shared_ptr<struct RoutingRule> >& ruleset ) { const auto& attribs = xmlParser->attributes(); std::shared_ptr<RoutingRule> routingRule(new RoutingRule()); routingRule->_tagName = xmlParser->name().toString(); routingRule->_t = attribs.value("t").toString(); routingRule->_v = attribs.value("v").toString(); routingRule->_param = attribs.value("param").toString(); routingRule->_value1 = attribs.value("value1").toString(); routingRule->_value2 = attribs.value("value2").toString(); routingRule->_type = attribs.value("type").toString(); if(routingRule->_type == "" && rulesetType == RoutingRuleset::Type::RoadSpeed ) { routingRule->_type = "speed"; } auto context = routingProfile->getRuleset(rulesetType); if(routingRule->_tagName == "select") { context->registerSelectExpression(attribs.value("value").toString(), routingRule->_type); addRulesetSubclause(routingRule.get(), context.get()); for(const auto& item : constOf(ruleset)) addRulesetSubclause(item.get(), context.get()); } else if (!ruleset.isEmpty() && ruleset.top()->_tagName == "select") { addRulesetSubclause(routingRule.get(), context.get()); } ruleset.push(routingRule); }
void OsmAnd::RasterizerEnvironment_P::applyTo( MapStyleEvaluator& evaluator ) const { QMutexLocker scopedLocker(&_settingsChangeMutex); for(const auto& settingEntry : rangeOf(constOf(_settings))) { const auto& valueDef = settingEntry.key(); const auto& settingValue = settingEntry.value(); switch(valueDef->dataType) { case MapStyleValueDataType::Integer: evaluator.setIntegerValue(valueDef->id, settingValue.isComplex ? settingValue.asComplex.asInt.evaluate(owner->displayDensityFactor) : settingValue.asSimple.asInt); break; case MapStyleValueDataType::Float: evaluator.setFloatValue(valueDef->id, settingValue.isComplex ? settingValue.asComplex.asFloat.evaluate(owner->displayDensityFactor) : settingValue.asSimple.asFloat); break; case MapStyleValueDataType::Boolean: case MapStyleValueDataType::String: case MapStyleValueDataType::Color: assert(!settingValue.isComplex); evaluator.setIntegerValue(valueDef->id, settingValue.asSimple.asUInt); break; } } }
void OsmAnd::MapRasterizer_P::rasterizeMapPrimitives( const Context& context, SkCanvas& canvas, const MapPrimitiviser::PrimitivesCollection& primitives, PrimitivesType type, const std::shared_ptr<const IQueryController>& queryController) { assert(type != PrimitivesType::Points); for (const auto& primitive : constOf(primitives)) { if (queryController && queryController->isAborted()) return; if (type == PrimitivesType::Polygons) { rasterizePolygon( context, canvas, primitive); } else if (type == PrimitivesType::Polylines || type == PrimitivesType::Polylines_ShadowOnly) { rasterizePolyline( context, canvas, primitive, (type == PrimitivesType::Polylines_ShadowOnly)); } } }
void OsmAnd::CachingRoadLocator_P::clearCacheNotInTiles(const QSet<TileId> tiles, const ZoomLevel zoomLevel, const bool checkAlsoIntersection) { clearCacheConditional( [tiles, zoomLevel, checkAlsoIntersection] (const std::shared_ptr<const ObfRoutingSectionReader::DataBlock>& dataBlock) -> bool { bool shouldRemove = true; for (const auto& tileId : constOf(tiles)) { const auto tileBBox31 = Utilities::tileBoundingBox31(tileId, zoomLevel); if (tileBBox31.contains(dataBlock->area31) || dataBlock->area31.contains(tileBBox31)) { shouldRemove = false; break; } if (checkAlsoIntersection && tileBBox31.intersects(dataBlock->area31)) { shouldRemove = false; break; } } return shouldRemove; }); }
QBitArray OsmAnd::RoutingRulesetContext::encode( const std::shared_ptr<const ObfRoutingSectionInfo>& section, const QVector<uint32_t>& roadTypes ) { QBitArray bitset(ruleset->owner->_universalRules.size()); auto itTagValueAttribIdCache = owner->_tagValueAttribIdCache.find(section); if(itTagValueAttribIdCache == owner->_tagValueAttribIdCache.end()) itTagValueAttribIdCache = owner->_tagValueAttribIdCache.insert(section, QMap<uint32_t, uint32_t>()); for(const auto& type : constOf(roadTypes)) { auto itId = itTagValueAttribIdCache->find(type); if(itId == itTagValueAttribIdCache->end()) { const auto& encodingRule = section->_d->_encodingRules[type]; assert(encodingRule); auto id = ruleset->owner->registerTagValueAttribute(encodingRule->_tag, encodingRule->_value); itId = itTagValueAttribIdCache->insert(type, id); } auto id = *itId; if(bitset.size() <= id) bitset.resize(id + 1); bitset.setBit(id); } return bitset; }
void OsmAnd::MapRendererTiledResourcesCollection::Snapshot::forEachResourceExecute(const ResourceActionCallback action) { QReadLocker scopedLocker(&_lock); bool doCancel = false; for (const auto& storage : constOf(_storage)) { for (const auto& entry : constOf(storage)) { action(entry, doCancel); if (doCancel) return; } } }
void OsmAnd::ObfRoutingSectionReader_P::querySubsections( const std::unique_ptr<ObfReader_P>& reader, const QList< std::shared_ptr<ObfRoutingSubsectionInfo> >& in, QList< std::shared_ptr<const ObfRoutingSubsectionInfo> >* resultOut /*= nullptr*/, IQueryFilter* filter /*= nullptr*/, std::function<bool (const std::shared_ptr<const ObfRoutingSubsectionInfo>&)> visitor /*= nullptr*/) { auto cis = reader->_codedInputStream.get(); for(const auto& subsection : constOf(in)) { // If section is completely outside of bbox, skip it if(filter && !filter->acceptsArea(subsection->_area31)) continue; // Load children if they are not yet loaded if(subsection->_subsectionsOffset != 0 && subsection->_subsections.isEmpty()) { cis->Seek(subsection->_offset); auto oldLimit = cis->PushLimit(subsection->_length); cis->Skip(subsection->_subsectionsOffset - subsection->_offset); const auto contains = !filter || filter->acceptsArea(subsection->_area31); readSubsectionChildrenHeaders(reader, subsection, contains ? std::numeric_limits<uint32_t>::max() : 1); cis->PopLimit(oldLimit); } querySubsections(reader, subsection->_subsections, resultOut, filter, visitor); if(!visitor || visitor(subsection)) { if(resultOut) resultOut->push_back(subsection); } } }
void OsmAnd::RoutePlanner::calculateTimeSpeedInRoute( OsmAnd::RoutePlannerContext::CalculationContext* context, QVector< std::shared_ptr<RouteSegment> >& route ) { for(const auto& segment : constOf(route)) { float distOnRoadToPass = 0; float speed = context->owner->profileContext->getSpeed(segment->road); if (qFuzzyCompare(speed, 0)) speed = context->owner->profileContext->profile->minDefaultSpeed; const auto isIncrement = segment->startPointIndex < segment->endPointIndex; float distanceSum = 0; for(auto pointIdx = segment->startPointIndex; pointIdx != segment->endPointIndex; isIncrement ? pointIdx++ : pointIdx--) { const auto& point1 = segment->road->points[pointIdx]; const auto& point2 = segment->road->points[pointIdx + (isIncrement ? +1 : -1)]; auto distance = Utilities::distance( Utilities::get31LongitudeX(point1.x), Utilities::get31LatitudeY(point1.y), Utilities::get31LongitudeX(point2.x), Utilities::get31LatitudeY(point2.y) ); distanceSum += distance; auto obstacle = context->owner->profileContext->getObstaclesExtraTime(segment->road, pointIdx); if (obstacle < 0) obstacle = 0; distOnRoadToPass += distance / speed + obstacle; } // last point turn time can be added // if (i + 1 < result.size()) { distOnRoadToPass += ctx.getRouter().calculateTurnTime(); } segment->_time = distOnRoadToPass; segment->_speed = speed; segment->_distance = distanceSum; } }
QString OsmAnd::ResolvedMapStyle_P::dumpRuleNodeOutputValues( const std::shared_ptr<const RuleNode>& ruleNode, const QString& prefix, const bool allowOverride) const { QString dump; const auto builtinValueDefs = MapStyleBuiltinValueDefinitions::get(); for (const auto& ruleValueEntry : rangeOf(constOf(ruleNode->values))) { const auto valueDefId = ruleValueEntry.key(); const auto& valueDef = getValueDefinitionById(valueDefId); // Skip all non-Output values if (valueDef->valueClass != MapStyleValueDefinition::Class::Output) continue; const auto& resolvedRuleValue = ruleValueEntry.value(); dump += prefix + QString(QLatin1String("%1 %2 = %3;\n")) .arg(allowOverride ? QLatin1String("setOrOverride") : QLatin1String("setIfNotSet")) .arg(valueDef->name) .arg(dumpResolvedValue(resolvedRuleValue, valueDef->dataType)); } return dump; }
bool OsmAnd::ObfsCollection_P::remove(const ObfsCollection::SourceOriginId entryId) { QWriteLocker scopedLocker(&_sourcesOriginsLock); const auto itSourceOrigin = _sourcesOrigins.find(entryId); if (itSourceOrigin == _sourcesOrigins.end()) return false; const auto& sourceOrigin = *itSourceOrigin; if (sourceOrigin->type == SourceOriginType::Directory) { const auto& directoryAsSourceOrigin = std::static_pointer_cast<const DirectoryAsSourceOrigin>(sourceOrigin); for(const auto watchedSubdirectory : constOf(directoryAsSourceOrigin->watchedSubdirectories)) _fileSystemWatcher->removePath(watchedSubdirectory); _fileSystemWatcher->removePath(directoryAsSourceOrigin->directory.canonicalPath()); } else if (sourceOrigin->type == SourceOriginType::File) { const auto& fileAsSourceOrigin = std::static_pointer_cast<const FileAsSourceOrigin>(sourceOrigin); _fileSystemWatcher->removePath(fileAsSourceOrigin->fileInfo.canonicalFilePath()); } _sourcesOrigins.erase(itSourceOrigin); invalidateCollectedSources(); return true; }
void OsmAnd::AtlasMapRendererDebugStage_OpenGL::renderLines3D() { const auto gpuAPI = getGPUAPI(); GL_CHECK_PRESENT(glUseProgram); GL_CHECK_PRESENT(glUniformMatrix4fv); GL_CHECK_PRESENT(glUniform1f); GL_CHECK_PRESENT(glUniform2f); GL_CHECK_PRESENT(glUniform3f); GL_CHECK_PRESENT(glDrawElements); gpuAPI->glBindVertexArray_wrapper(_vaoLine3D); GL_CHECK_RESULT; // Activate program glUseProgram(_programLine3D.id); GL_CHECK_RESULT; // Set projection*view*model matrix: const auto& mProjectionView = internalState.mPerspectiveProjection * internalState.mCameraView; glUniformMatrix4fv(_programLine3D.vs.param.mProjectionViewModel, 1, GL_FALSE, glm::value_ptr(mProjectionView)); GL_CHECK_RESULT; for(const auto& primitive : constOf(_lines3D)) { const auto& line = primitive.first; const auto& color = primitive.second; // Set line color glUniform4f(_programLine3D.fs.param.color, SkColorGetR(color) / 255.0f, SkColorGetG(color) / 255.0f, SkColorGetB(color) / 255.0f, SkColorGetA(color) / 255.0f); GL_CHECK_RESULT; // Iterate over pairs of points auto itV0 = line.cbegin(); auto itV1 = itV0 + 1; for(const auto itEnd = line.cend(); itV1 != itEnd; itV0 = itV1, ++itV1) { const auto& v0 = *itV0; const auto& v1 = *itV1; // Set line coordinates glUniform4f(_programLine3D.vs.param.v0, v0.x, v0.y, v0.z, 1.0f); GL_CHECK_RESULT; glUniform4f(_programLine3D.vs.param.v1, v1.x, v1.y, v1.z, 1.0f); GL_CHECK_RESULT; // Draw the line actually glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, nullptr); GL_CHECK_RESULT; } } // Deactivate program glUseProgram(0); GL_CHECK_RESULT; // Deselect VAO gpuAPI->glBindVertexArray_wrapper(0); GL_CHECK_RESULT; }
bool OsmAnd::MapRendererTiledResourcesCollection::updateCollectionSnapshot() const { const auto invalidatesDiscarded = _collectionSnapshotInvalidatesCount.fetchAndAddOrdered(0); if (invalidatesDiscarded == 0) return true; // Copy from original storage to temp storage Storage storageCopy; { if (!_collectionLock.tryLockForRead()) return false; for (int zoomLevel = MinZoomLevel; zoomLevel <= MaxZoomLevel; zoomLevel++) { const auto& sourceStorageLevel = constOf(_storage)[zoomLevel]; auto& targetStorageLevel = storageCopy[zoomLevel]; targetStorageLevel = detachedOf(sourceStorageLevel); } _collectionLock.unlock(); } _collectionSnapshotInvalidatesCount.fetchAndAddOrdered(-invalidatesDiscarded); // Copy from temp storage to snapshot { QWriteLocker scopedLocker(&_snapshot->_lock); _snapshot->_storage = qMove(storageCopy); } return true; }
OsmAnd::EmbeddedFontFinder::EmbeddedFontFinder( const std::shared_ptr<const ICoreResourcesProvider>& coreResourcesProvider_ /*= getCoreResourcesProvider()*/) : coreResourcesProvider(coreResourcesProvider_) { for (const auto embeddedFontResource : constOf(resources)) { const auto fontData = coreResourcesProvider->getResource(embeddedFontResource); if (fontData.isNull()) { LogPrintf(LogSeverityLevel::Error, "Failed to load embedded font data for '%s'", qPrintable(embeddedFontResource)); continue; } const auto font = SkiaUtilities::createTypefaceFromData(fontData); if (!font) { LogPrintf(LogSeverityLevel::Error, "Failed to create SkTypeface from embedded font data for '%s'", qPrintable(embeddedFontResource)); continue; } _fonts.push_back(font); } }
bool OsmAnd::AtlasMapRendererDebugStage_OpenGL::renderLines2D() { const auto gpuAPI = getGPUAPI(); const auto& internalState = getInternalState(); GL_CHECK_PRESENT(glUseProgram); GL_CHECK_PRESENT(glUniformMatrix4fv); GL_CHECK_PRESENT(glUniform1f); GL_CHECK_PRESENT(glUniform2f); GL_CHECK_PRESENT(glUniform3f); GL_CHECK_PRESENT(glDrawElements); gpuAPI->useVAO(_vaoLine2D); // Activate program glUseProgram(_programLine2D.id); GL_CHECK_RESULT; // Set projection*view*model matrix: glUniformMatrix4fv(_programLine2D.vs.param.mProjectionViewModel, 1, GL_FALSE, glm::value_ptr(internalState.mOrthographicProjection)); GL_CHECK_RESULT; for(const auto& primitive : constOf(_lines2D)) { const auto& line = primitive.first; const auto& color = primitive.second; // Set line color glUniform4f(_programLine2D.fs.param.color, SkColorGetR(color) / 255.0f, SkColorGetG(color) / 255.0f, SkColorGetB(color) / 255.0f, SkColorGetA(color) / 255.0f); GL_CHECK_RESULT; // Iterate over pairs of points auto itV0 = line.cbegin(); auto itV1 = itV0 + 1; for(const auto itEnd = line.cend(); itV1 != itEnd; itV0 = itV1, ++itV1) { const auto& v0 = *itV0; const auto& v1 = *itV1; // Set line coordinates glUniform2f(_programLine2D.vs.param.v0, v0.x, currentState.windowSize.y - v0.y); GL_CHECK_RESULT; glUniform2f(_programLine2D.vs.param.v1, v1.x, currentState.windowSize.y - v1.y); GL_CHECK_RESULT; // Draw the line actually glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, nullptr); GL_CHECK_RESULT; } } // Deactivate program glUseProgram(0); GL_CHECK_RESULT; gpuAPI->unuseVAO(); return true; }
bool OsmAnd::MapMarker_P::applyChanges() { QReadLocker scopedLocker1(&_lock); if (!_hasUnappliedChanges) return false; QReadLocker scopedLocker2(&_symbolsGroupsRegistryLock); for (const auto& symbolGroup_ : constOf(_symbolsGroupsRegistry)) { const auto symbolGroup = symbolGroup_.lock(); if (!symbolGroup) continue; for (const auto& symbol_ : constOf(symbolGroup->symbols)) { symbol_->isHidden = _isHidden; if (const auto symbol = std::dynamic_pointer_cast<AccuracyCircleMapSymbol>(symbol_)) { symbol->setPosition31(_position); symbol->isHidden = _isHidden || !_isAccuracyCircleVisible; symbol->scale = _accuracyCircleRadius; } if (const auto symbol = std::dynamic_pointer_cast<BillboardRasterMapSymbol>(symbol_)) { symbol->setPosition31(_position); symbol->modulationColor = _pinIconModulationColor; } if (const auto symbol = std::dynamic_pointer_cast<KeyedOnSurfaceRasterMapSymbol>(symbol_)) { symbol->setPosition31(_position); const auto citDirection = _directions.constFind(symbol->key); if (citDirection != _directions.cend()) symbol->direction = *citDirection; } } } _hasUnappliedChanges = false; return true; }
void OsmAnd::MapObject::EncodingDecodingRules::verifyRequiredRulesExist() { uint32_t lastUsedRuleId = 0u; if (!decodingRules.isEmpty()) lastUsedRuleId = *qMaxElement(keysOf(constOf(decodingRules))); createRequiredRules(lastUsedRuleId); }
bool OsmAnd::ObfDataInterface::scanAddressesByName( const QString& query, QList< std::shared_ptr<const OsmAnd::Address> >* outAddresses, const AreaI* const bbox31 /*= nullptr*/, const ObfAddressStreetGroupTypesMask streetGroupTypesFilter /*= fullObfAddressStreetGroupTypesMask()*/, const bool includeStreets /*= true*/, const ObfAddressSectionReader::VisitorFunction visitor /*= nullptr*/, const std::shared_ptr<const IQueryController>& queryController /*= nullptr*/) { for (const auto& obfReader : constOf(obfReaders)) { if (queryController && queryController->isAborted()) return false; const auto& obfInfo = obfReader->obtainInfo(); for (const auto& addressSection : constOf(obfInfo->addressSections)) { if (queryController && queryController->isAborted()) return false; if (bbox31) { bool accept = false; accept = accept || addressSection->area31.contains(*bbox31); accept = accept || addressSection->area31.intersects(*bbox31); accept = accept || bbox31->contains(addressSection->area31); if (!accept) continue; } OsmAnd::ObfAddressSectionReader::scanAddressesByName( obfReader, addressSection, query, outAddresses, bbox31, streetGroupTypesFilter, includeStreets, visitor, queryController); } } return true; }
void OsmAnd::AtlasMapRendererDebugStage_OpenGL::renderQuads3D() { const auto gpuAPI = getGPUAPI(); GL_CHECK_PRESENT(glUseProgram); GL_CHECK_PRESENT(glUniformMatrix4fv); GL_CHECK_PRESENT(glUniform1f); GL_CHECK_PRESENT(glUniform2f); GL_CHECK_PRESENT(glUniform3f); GL_CHECK_PRESENT(glDrawElements); gpuAPI->glBindVertexArray_wrapper(_vaoQuad3D); GL_CHECK_RESULT; // Activate program glUseProgram(_programQuad3D.id); GL_CHECK_RESULT; // Set projection*view*model matrix: const auto& mProjectionView = internalState.mPerspectiveProjection * internalState.mCameraView; glUniformMatrix4fv(_programQuad3D.vs.param.mProjectionViewModel, 1, GL_FALSE, glm::value_ptr(mProjectionView)); GL_CHECK_RESULT; for(const auto& primitive : constOf(_quads3D)) { const auto& p0 = std::get<0>(primitive); const auto& p1 = std::get<1>(primitive); const auto& p2 = std::get<2>(primitive); const auto& p3 = std::get<3>(primitive); const auto& color = std::get<4>(primitive); // Set quad color glUniform4f(_programQuad3D.fs.param.color, SkColorGetR(color) / 255.0f, SkColorGetG(color) / 255.0f, SkColorGetB(color) / 255.0f, SkColorGetA(color) / 255.0f); GL_CHECK_RESULT; // Set points glUniform4f(_programQuad3D.vs.param.v0, p0.x, p0.y, p0.z, 1.0f); GL_CHECK_RESULT; glUniform4f(_programQuad3D.vs.param.v1, p1.x, p1.y, p1.z, 1.0f); GL_CHECK_RESULT; glUniform4f(_programQuad3D.vs.param.v2, p2.x, p2.y, p2.z, 1.0f); GL_CHECK_RESULT; glUniform4f(_programQuad3D.vs.param.v3, p3.x, p3.y, p3.z, 1.0f); GL_CHECK_RESULT; // Draw the quad actually glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr); GL_CHECK_RESULT; } // Deactivate program glUseProgram(0); GL_CHECK_RESULT; // Deselect VAO gpuAPI->glBindVertexArray_wrapper(0); GL_CHECK_RESULT; }
QList< std::shared_ptr<const OsmAnd::MapStylePreset> > OsmAnd::MapStylesPresetsCollection_P::getCollection() const { QList< std::shared_ptr<const MapStylePreset> > result; for(const auto& preset : constOf(_order)) result.push_back(preset); return result; }