<commit_before>#include "MainForm.moc"

#include <QtGui>
#include <iostream>

MainForm::MainForm(QGraphicsScene* img, nbt* bf, QWidget* parent_)
                 : QGraphicsView(img, parent_), scene_(), bf_(bf), scale_(1) {
  connect(this, SIGNAL(scaleSig()), this, SLOT(scale()));
  connect(this, SIGNAL(renderNewImage()), this, SLOT(populateSceneItem()));
  connect(this, SIGNAL(saveToFileSignal()), this, SLOT(saveToFile()));
}

void MainForm::populateScene() {
  int index = 0;
  for (int i = bf_->zPos_min(); i <= bf_->zPos_max(); ++i) {
    int j;
    #pragma omp parallel for
    for (j = bf_->xPos_min(); j <= bf_->xPos_max(); ++j) {
      bool result = false;
      const QImage& img = bf_->getImage(j, i, &result);
      if (!result) continue;
      #pragma omp atomic
      index += 1;
      #pragma omp critical
      {
        images.push(img);
        coords.push(QPair<int, int>(j, i));
      }
      if (index > 10000) {
        #pragma omp critical
        bf_->clearCache();
      }
      #pragma omp critical
      emit renderNewImage();
    }
  }
  bf_->clearCache();
  emit saveToFileSignal();

  // QPen pen;
  // pen.setColor(QColor(255, 0, 0, 255));
  // scene()->addEllipse(185, 50, 5, 5, pen);
  // rotate(270.0f);
  // 187 52
  // setTransform(QTransform().scale(1, 1));
}

void MainForm::saveToFile() {
  QImage image(scene()->sceneRect().toAlignedRect().size(), QImage::Format_ARGB32_Premultiplied);
  image.fill(0);
  QPainter painter(&image);
  scene()->render(&painter);
  image.save("image.png");
}

void MainForm::populateSceneItem() {
  QImage img;
  QPair<int, int> coor;
  if (images.try_pop(img) && coords.try_pop(coor)) {
    QGraphicsPixmapItem* pi = scene()->addPixmap(QPixmap::fromImage(img));
    pi->setFlag(QGraphicsItem::ItemIsMovable, false);
    pi->setFlag(QGraphicsItem::ItemIsSelectable, false);
    // std::cout << 16 * coor.first << " " << 16 * coor.second << std::endl;
    pi->setPos(16 * coor.first, 16 * coor.second);<commit_msg>moved clear out of threads<commit_after>#include "MainForm.moc"

#include <QtGui>
#include <iostream>

MainForm::MainForm(QGraphicsScene* img, nbt* bf, QWidget* parent_)
                 : QGraphicsView(img, parent_), scene_(), bf_(bf), scale_(1) {
  connect(this, SIGNAL(scaleSig()), this, SLOT(scale()));
  connect(this, SIGNAL(renderNewImage()), this, SLOT(populateSceneItem()));
  connect(this, SIGNAL(saveToFileSignal()), this, SLOT(saveToFile()));
}

void MainForm::populateScene() {
  int index = 0;
  for (int i = bf_->zPos_min(); i <= bf_->zPos_max(); ++i) {
    int j;
    #pragma omp parallel for
    for (j = bf_->xPos_min(); j <= bf_->xPos_max(); ++j) {
      bool result = false;
      const QImage& img = bf_->getImage(j, i, &result);
      if (!result) continue;
      #pragma omp atomic
      index += 1;
      #pragma omp critical
      {
        images.push(img);
        coords.push(QPair<int, int>(j, i));
      }
      #pragma omp critical
      emit renderNewImage();
    }
    if (index > 10000) {
      bf_->clearCache();
    }
  }
  bf_->clearCache();
  emit saveToFileSignal();

  // QPen pen;
  // pen.setColor(QColor(255, 0, 0, 255));
  // scene()->addEllipse(185, 50, 5, 5, pen);
  // rotate(270.0f);
  // 187 52
  // setTransform(QTransform().scale(1, 1));
}

void MainForm::saveToFile() {
  QImage image(scene()->sceneRect().toAlignedRect().size(), QImage::Format_ARGB32_Premultiplied);
  image.fill(0);
  QPainter painter(&image);
  scene()->render(&painter);
  image.save("image.png");
  exit(1);
}

void MainForm::populateSceneItem() {
  QImage img;
  QPair<int, int> coor;
  if (images.try_pop(img) && coords.try_pop(coor)) {
    QGraphicsPixmapItem* pi = scene()->addPixmap(QPixmap::fromImage(img));
    pi->setFlag(QGraphicsItem::ItemIsMovable, false);
    pi->setFlag(QGraphicsItem::ItemIsSelectable, false);
    // std::cout << 16 * coor.first << " " << 16 * coor.second << std::endl;
    pi->setPos(16 * coor.first, 16 * coor.second);
{'fraction_non_alphanumeric': 0.1827821257258268, 'fraction_numerical': 0.022973996465539007, 'mean_word_length': 3.538373424971363, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3491464', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1422, 'n_words': 291}