void NSRPopplerDocument::renderPage(int page) { double dpix, dpiy; if (_doc == NULL || page > getNumberOfPages() || page < 1) return; _page = _catalog->getPage(page); if (isTextOnly()) { PDFRectangle *rect; GooString *text; TextOutputDev *dev; dev = new TextOutputDev (0, gFalse, gFalse, gFalse); _doc->displayPageSlice(dev, _page->getNum(), 72, 72, 0, gFalse, gTrue, gFalse, -1, -1, -1, -1); rect = _page->getCropBox(); text = dev->getText(rect->x1, rect->y1, rect->x2, rect->y2); _text = processText(QString::fromUtf8(text->getCString())); delete text; delete dev; _readyForLoad = true; return; } if (isZoomToWidth()) { double wZoom = ((double) getScreenWidth() / (double) _page->getCropWidth() * 100.0); setZoomSilent((int) wZoom); } if (getZoom() > getMaxZoom()) setZoomSilent (getMaxZoom()); else if (getZoom() < getMinZoom()) setZoomSilent (getMinZoom()); if (_readyForLoad) _dev->startPage(0, NULL); dpix = _dpix * getZoom() / 100.0; dpiy = _dpiy * getZoom() / 100.0; _page->display(_dev, dpix, dpiy, getRotation(), gFalse, gFalse, gTrue, _catalog); _readyForLoad = true; }
bool ZDvidDataSliceHelper::actualContainedIn( const ZStackViewParam &viewParam, int zoom, int centerCutX, int centerCutY, bool centerCut) const { bool contained = false; if (m_currentViewParam.getViewPort().isEmpty() && !viewParam.getViewPort().isEmpty()) { if (m_currentViewParam.getSliceAxis() == neutube::EAxis::ARB) { //Must be on the same plane to be contained if (m_currentViewParam.getSliceViewParam().hasSamePlaneCenter( viewParam.getSliceViewParam())) { contained = true; } } else { if (viewParam.getZ() == m_currentViewParam.getZ()) { contained = true; } } } else if (viewParam.contains(m_currentViewParam)) { contained = ZDvidDataSliceHelper::IsResIncreasing( m_actualZoom, m_actualCenterCutWidth, m_actualCenterCutHeight, m_actualUsingCenterCut, zoom, centerCutX, centerCutY, centerCut, getWidth(), getHeight(), getMaxZoom()); } return contained; }
bool ZDvidDataSliceHelper::hasNewView(const ZStackViewParam &viewParam) const { int maxZoomLevel = getMaxZoom(); return !m_currentViewParam.contains(viewParam) || (viewParam.getZoomLevel(maxZoomLevel) < m_currentViewParam.getZoomLevel(maxZoomLevel)); }
int ZDvidDataSliceHelper::getLowresZoom() const { int zoom = getZoom() + 1; if (zoom > getMaxZoom()) { zoom -= 1; } return zoom; }
int NSRPopplerDocument::getMinZoom() { if (_page == NULL) return 0; if (QSize (_page->getCropWidth(), _page->getCropHeight()) == _cachedPageSize) return _cachedMinZoom; /* Each pixel needs 4 bytes (RGBA) of memory */ double pageSize = _page->getCropWidth() * _page->getCropHeight() * 4; if (pageSize > NSR_DOCUMENT_MAX_HEAP) _cachedMinZoom = getMaxZoom(); else _cachedMinZoom = (getMaxZoom() / 10) > 25 ? 25 : getMaxZoom() / 10; _cachedPageSize = QSize (_page->getCropWidth(), _page->getCropHeight()); return _cachedMinZoom; }
bool ZDvidDataSliceHelper::needHighResUpdate() const { if (getViewDataSize() == 0) { return true; } return IsResIncreasing( m_actualZoom, m_actualCenterCutWidth, m_actualCenterCutHeight, m_actualUsingCenterCut, m_zoom, m_centerCutWidth, m_centerCutHeight, m_usingCenterCut, getWidth(), getHeight(), getMaxZoom()); }
int ZDvidDataSliceHelper::updateParam(ZStackViewParam *param) { int maxZoomLevel = getMaxZoom(); if (maxZoomLevel < 3) { int width = param->getViewPort().width(); int height = param->getViewPort().height(); if (validateSize(&width, &height)) { param->resize(width, height); } } return maxZoomLevel; }
void ZDvidDataSliceHelper::inferUpdatePolicy(neutube::EAxis axis) { if (getMaxZoom() == 0) { if (axis == neutube::EAxis::ARB) { setUpdatePolicy(flyem::EDataSliceUpdatePolicy::HIDDEN); } else { setUpdatePolicy(flyem::EDataSliceUpdatePolicy::SMALL); } } else { if (axis == neutube::EAxis::ARB) { setUpdatePolicy(getPreferredUpdatePolicy()); } else { setUpdatePolicy(flyem::EDataSliceUpdatePolicy::LOWRES); } } }
ZStackViewParam ZDvidDataSliceHelper::getValidViewParam( const ZStackViewParam &viewParam) const { ZStackViewParam newViewParam = viewParam; int maxZoomLevel = getMaxZoom(); if (maxZoomLevel < 3) { int width = viewParam.getViewPort().width(); int height = viewParam.getViewPort().height(); if (validateSize(&width, &height)) { newViewParam.resize(width, height); } } return newViewParam; }
CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const EdgeInsets& padding) { CameraOptions options; if (latLngs.empty()) { return options; } // Calculate the bounds of the possibly rotated shape with respect to the viewport. PrecisionPoint nePixel = {-INFINITY, -INFINITY}; PrecisionPoint swPixel = {INFINITY, INFINITY}; for (LatLng latLng : latLngs) { PrecisionPoint pixel = pixelForLatLng(latLng); swPixel.x = std::min(swPixel.x, pixel.x); nePixel.x = std::max(nePixel.x, pixel.x); swPixel.y = std::min(swPixel.y, pixel.y); nePixel.y = std::max(nePixel.y, pixel.y); } double width = nePixel.x - swPixel.x; double height = nePixel.y - swPixel.y; // Calculate the zoom level. double scaleX = (getWidth() - padding.left - padding.right) / width; double scaleY = (getHeight() - padding.top - padding.bottom) / height; double minScale = ::fmin(scaleX, scaleY); double zoom = ::log2(getScale() * minScale); zoom = ::fmax(::fmin(zoom, getMaxZoom()), getMinZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. PrecisionPoint paddedNEPixel = { nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale, }; PrecisionPoint paddedSWPixel = { swPixel.x - padding.left / minScale, swPixel.y - padding.bottom / minScale, }; PrecisionPoint centerPixel = { (paddedNEPixel.x + paddedSWPixel.x) / 2, (paddedNEPixel.y + paddedSWPixel.y) / 2, }; options.center = latLngForPixel(centerPixel); options.zoom = zoom; return options; }
bool OsmAnd::ImageMapLayerProvider::obtainData( const IMapDataProvider::Request& request_, std::shared_ptr<IMapDataProvider::Data>& outData, std::shared_ptr<Metric>* const pOutMetric /*= nullptr*/) { const auto& request = MapDataProviderHelpers::castRequest<Request>(request_); if (pOutMetric) pOutMetric->reset(); // Check provider can supply this zoom level if (request.zoom > getMaxZoom() || request.zoom < getMinZoom()) { outData.reset(); return true; } if (!supportsNaturalObtainData()) return MapDataProviderHelpers::nonNaturalObtainData(this, request, outData, pOutMetric); // Obtain image data const auto image = obtainImage(request); if (image.isNull()) { outData.reset(); return true; } // Decode image data std::shared_ptr<SkBitmap> bitmap(new SkBitmap()); SkMemoryStream imageStream(image.constData(), image.length(), false); if (!SkImageDecoder::DecodeStream(&imageStream, bitmap.get(), SkColorType::kUnknown_SkColorType, SkImageDecoder::kDecodePixels_Mode)) return false; // Return tile outData.reset(new IRasterMapLayerProvider::Data( request.tileId, request.zoom, getAlphaChannelPresence(), getTileDensityFactor(), bitmap)); return true; }
CameraOptions Map::cameraForLatLngs(std::vector<LatLng> latLngs, EdgeInsets padding) { CameraOptions options; if (latLngs.empty()) { return options; } // Calculate the bounds of the possibly rotated shape with respect to the viewport. vec2<> nePixel = {-INFINITY, -INFINITY}; vec2<> swPixel = {INFINITY, INFINITY}; for (LatLng latLng : latLngs) { vec2<> pixel = pixelForLatLng(latLng); swPixel.x = std::min(swPixel.x, pixel.x); nePixel.x = std::max(nePixel.x, pixel.x); swPixel.y = std::min(swPixel.y, pixel.y); nePixel.y = std::max(nePixel.y, pixel.y); } vec2<> size = nePixel - swPixel; // Calculate the zoom level. double scaleX = (getWidth() - padding.left - padding.right) / size.x; double scaleY = (getHeight() - padding.top - padding.bottom) / size.y; double minScale = ::fmin(scaleX, scaleY); double zoom = ::log2(getScale() * minScale); zoom = ::fmax(::fmin(zoom, getMaxZoom()), getMinZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. vec2<> paddedNEPixel = { nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale, }; vec2<> paddedSWPixel = { swPixel.x - padding.left / minScale, swPixel.y - padding.bottom / minScale, }; vec2<> centerPixel = (paddedNEPixel + paddedSWPixel) * 0.5; LatLng centerLatLng = latLngForPixel(centerPixel); options.center = centerLatLng; options.zoom = zoom; return options; }
void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, Duration duration) { if (segment.empty()) { return; } // Calculate the bounds of the possibly rotated shape with respect to the viewport. vec2<> nePixel = {-INFINITY, -INFINITY}; vec2<> swPixel = {INFINITY, INFINITY}; for (LatLng latLng : segment) { vec2<> pixel = pixelForLatLng(latLng); swPixel.x = std::min(swPixel.x, pixel.x); nePixel.x = std::max(nePixel.x, pixel.x); swPixel.y = std::min(swPixel.y, pixel.y); nePixel.y = std::max(nePixel.y, pixel.y); } vec2<> size = nePixel - swPixel; // Calculate the zoom level. double scaleX = (getWidth() - padding.left - padding.right) / size.x; double scaleY = (getHeight() - padding.top - padding.bottom) / size.y; double minScale = std::fmin(scaleX, scaleY); double zoom = std::log2(getScale() * minScale); zoom = std::fmax(std::fmin(zoom, getMaxZoom()), getMinZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. vec2<> paddedNEPixel = { nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale, }; vec2<> paddedSWPixel = { swPixel.x - padding.left / minScale, swPixel.y - padding.bottom / minScale, }; vec2<> centerPixel = (paddedNEPixel + paddedSWPixel) * 0.5; LatLng centerLatLng = latLngForPixel(centerPixel); setLatLngZoom(centerLatLng, zoom, duration); }
std::vector<uint32_t> Map::getAnnotationsInBounds(const LatLngBounds& bounds, const AnnotationType& type) { return data->annotationManager.getAnnotationsInBounds(bounds, getMaxZoom(), type); }
void Map::removeAnnotations(const std::vector<uint32_t>& annotations) { auto result = data->annotationManager.removeAnnotations(annotations, getMaxZoom()); context->invoke(&MapContext::updateAnnotationTiles, result); }
AnnotationIDs Map::addShapeAnnotations(const std::vector<ShapeAnnotation>& annotations) { auto result = data->annotationManager.addShapeAnnotations(annotations, getMaxZoom()); context->invoke(&MapContext::updateAnnotationTiles, result.first); return result.second; }
void TransformState::setMinZoom(const double minZoom) { if (minZoom <= getMaxZoom()) { min_scale = zoomScale(util::clamp(minZoom, util::MIN_ZOOM, util::MAX_ZOOM)); } }
AnnotationIDs Map::addShapeAnnotations(const std::vector<ShapeAnnotation>& annotations) { auto result = data->getAnnotationManager()->addShapeAnnotations(annotations, getMaxZoom()); update(Update::Annotations); return result; }