На главную... Продукты | Технологии | Классификаторы | Проекты | Скачать | Цены| Форум | Статьи | Обучение | Контакты

mapSetBreakCallAndParmEx isrepaint == 1, но картинка не обновляется

Поиск  Пользователи  Правила  Войти
Форум » Linux » Средства разработки ГИС-приложений для Linux
Страницы: 1
RSS
mapSetBreakCallAndParmEx isrepaint == 1, но картинка не обновляется
 
Рендеринг карты с помощью mapPaintToXImage длится 8 секунд,
поэтому я хочу хоть что-то показывать пользователю в это время.
Для этого я думал воспользоваться mapSetBreakCallAndParmEx и ее параметром isrepaint,
но почему-то хотя вызовов callback достаточно много, где-то один раз в секунду:

Код
isrepaint 1, since call 669 ms
isrepaint 1, since call 2010 ms
isrepaint 1, since call 3297 ms
isrepaint 1, since call 3912 ms
isrepaint 1, since call 4274 ms
isrepaint 1, since call 4640 ms
isrepaint 1, since call 5043 ms
isrepaint 1, since call 5955 ms
isrepaint 1, since call 6618 ms
isrepaint 1, since call 7061 ms
isrepaint 1, since call 7893 ms
mapPaintToXImage takes 8123 ms


но все время до завершения рендеринга картинка черная,
можно это как-то "ГИС Панораму" что-то отрисовывать в буфер,
если она "isrepaint" не ноль отдает?
Или может я как-то неправильно использую mapSetBreakCallAndParmEx ?


mapGetPaintStepEx(hmap_) и mapGetPaintStep(hmap_) возвращают 300,
кстати в mapapi.h неправильный комментарий для mapGetPaintStepEx

Код
#include <cassert>
#include <cmath>
#include <cstdint>
#include <stdexcept>

#include <QApplication>
#include <QElapsedTimer>
#include <QImage>
#include <QPainter>
#include <QScreen>
#include <QWidget>
#include <QtDebug>

#include <mapapi.h>
#include <qdmcmp.h>

using Pixel = uint32_t;

struct CallBackParams {
  QWidget *w;
  QElapsedTimer *timer;
};

static long int map_paint_break_callback(void *aparm, long int isrepaint) {
  auto param = static_cast<CallBackParams *>(aparm);
  fprintf(stderr, "isrepaint %ld, since call %lld ms\n", isrepaint,
          param->timer->elapsed());
  if (isrepaint) {
    fprintf(stderr, "force repaint\n");
    param->w->repaint();
  }
  return 0;
}

class MyW final : public QWidget {
public:
  explicit MyW(HMAP hmap) : hmap_(hmap) {}
  void startRendering() {
    qDebug() << "MyW size: " << size();
    img_ = QImage{size(), QImage::Format_RGB32};
    img_.fill(Qt::black);
    long int img_center_x = 0, img_center_y = 0;
    mapSetViewScale(hmap_, &img_center_x, &img_center_y, 25000 /*200000*/);

    double x = (55. + 44. / 60.) / 180. * 3.14;
    double y = (37. + 38. / 60.) / 180. * 3.14;
    double h = 0;
    mapGeoWGS84ToGeo3D(hmap_, &x, &y, &h);
    mapGeoToPlane(hmap_, &x, &y);
    mapPlaneToPicture(hmap_, &x, &y);
    int left = static_cast<int>(std::round(x));
    int top = static_cast<int>(std::round(y));

    XIMAGEDESC image_desc{reinterpret_cast<char *>(img_.bits()),
                          img_.width(),
                          img_.height(),
                          sizeof(Pixel) * 8,
                          sizeof(Pixel),
                          img_.width() * sizeof(Pixel)};

    RECT all_rect{left, top, left + img_.width(), top + img_.height()};

    QElapsedTimer timer;
    timer.start();
    CallBackParams cb_parms{this, &timer};
    mapSetBreakCallAndParmEx(hmap_, map_paint_break_callback, &cb_parms);
    auto ret = mapPaintToXImage(hmap_, &image_desc, 0, 0, &all_rect);
    assert(ret != 0);
    mapSetBreakCallAndParmEx(hmap_, nullptr, nullptr);
    qInfo("mapPaintToXImage takes %lld ms", timer.elapsed());
    update();
  }
  void showEvent(QShowEvent *e) override { QWidget::showEvent(e); }
  void paintEvent(QPaintEvent *) override {
    qDebug("paintEvent");
    QPainter painter{this};
    painter.drawImage(QPoint{0, 0}, img_);
  }

  void keyPressEvent(QKeyEvent *event) override {
    if (event->key() == Qt::Key_R) {
      qDebug("you call repaint");
      startRendering();
    }
  }

private:
  QImage img_;
  HMAP hmap_;
};

int main(int argc, char *argv[]) {
  QApplication app(argc, argv);
  QDMapView forProtection;

  auto screen = app.primaryScreen();
  qDebug() << "screen size: " << screen->size() << ", screen depth "
           << screen->depth() << ", dpi x " << screen->physicalDotsPerInchX()
           << ", dpi y " << screen->physicalDotsPerInchY();

  const int max_width = 4000;
  const int max_height = 4000;

  mapMessageEnable(1);
  // mapSetFrameTree(1);
  mapSetMaxScreenImageSize(max_width, max_height);

  const auto width_mm = static_cast<qreal>(screen->size().width()) /
                        screen->physicalDotsPerInchX() * 25.4;
  const auto height_mm = static_cast<qreal>(screen->size().height()) /
                         screen->physicalDotsPerInchY() * 25.4;
  qDebug() << "width_mm: " << width_mm << ", height_mm " << height_mm;
  mapSetScreenSizePro(std::hypot(width_mm, height_mm));
  mapSetScreenPrecisionEx(screen->physicalDotsPerInchX() / 25.4 * 1000.,
                          screen->physicalDotsPerInchY() / 25.4 * 1000.);

  qInfo("map access version %lX", GetMapAccessVersion());

  long errcode = 0;
  HMAP hmap = mapOpenAnyData(QString::fromUtf8(argv[1]).utf16(), GENERIC_READ,
                             &errcode);
  assert(hmap != 0);
  assert(mapIsGeoSupported(hmap) != 0);

  MyW w(hmap);
  w.showMaximized();
  return app.exec();
}
Изменено: Евгений Душистов - 07.02.2019 15:40:26
Страницы: 1
Читают тему (гостей: 1)



© КБ Панорама, 1991-2024

Регистрируясь или авторизуясь на форуме, Вы соглашаетесь с Политикой конфиденциальности