示例#1
0
std::pair<int, int> Network::checkOnlineMags(const QUrl & url) {
    int lowestAvailableMag = NUM_MAG_DATASETS;
    int highestAvailableMag = 0;
    int maxMagCount = int_log(NUM_MAG_DATASETS) + 1;

    QProgressDialog progress("Network Operation…", "Abort", 0, 100, state->mainWindow);
    progress.setModal(true);
    std::vector<qint64> bytesReceivedAll(maxMagCount);
    std::vector<qint64> bytesTotalAll(maxMagCount);
    std::vector<std::unique_ptr<QNetworkReply>> replies(maxMagCount);
    QTimer::singleShot(400, &progress, &QProgressDialog::show);

    QEventLoop pause;
    for (int currMag = 1; currMag <= NUM_MAG_DATASETS; currMag *= 2) {
        QUrl magUrl = url;
        magUrl.setPath(QString("%1/mag%2/knossos.conf").arg(url.path()).arg(currMag));
        auto * replyPtr = manager.get(QNetworkRequest{magUrl});
        replies[int_log(currMag)] = decltype(replies)::value_type{replyPtr};
        QObject::connect(replyPtr, &QNetworkReply::finished, [magUrl, &pause, &maxMagCount, currMag, replyPtr, &lowestAvailableMag, &highestAvailableMag]() {
            auto & reply = *replyPtr;
            if (reply.error() == QNetworkReply::NoError) {
                lowestAvailableMag = std::min(lowestAvailableMag, currMag);
                highestAvailableMag = std::max(highestAvailableMag, currMag);
            }
            if (--maxMagCount == 0) {
                pause.exit();
            }
        });
        auto processProgress = [&progress, currMag, &bytesReceivedAll, &bytesTotalAll](qint64 bytesReceived, qint64 bytesTotal){
            bytesReceivedAll[int_log(currMag)] = bytesReceived;
            bytesTotalAll[int_log(currMag)] = bytesTotal;
            const auto received = std::accumulate(std::begin(bytesReceivedAll), std::end(bytesReceivedAll), qint64{0});
            const auto total = std::accumulate(std::begin(bytesTotalAll), std::end(bytesTotalAll), qint64{0});
            progress.setRange(0, total);
            progress.setValue(received);
        };
        QObject::connect(replyPtr, &QNetworkReply::downloadProgress, processProgress);
        QObject::connect(replyPtr, &QNetworkReply::uploadProgress, processProgress);
        QObject::connect(&progress, &QProgressDialog::canceled, replyPtr, &QNetworkReply::abort);
    }

    pause.exec();

    if (lowestAvailableMag > highestAvailableMag) {
        throw std::runtime_error{"no mags detected"};
    }

    return {lowestAvailableMag, highestAvailableMag};
}
UL_int DigitalSequence_advanced::get_log_BufferLenForBase(UL_int base)
{

   if((base>= 2)&&(base<=10)) return int_log(get_BufferLenForBase(base),base);
   if(base<=MAX_BUFFER_LEN) return 1;

   return 0;
}
void DatasetPropertyWidget::loadSettings() {
    QSettings settings;
    settings.beginGroup(DATASET_WIDGET);
    path->clear();
    path->insertItems(0, settings.value(DATASET_MRU).toStringList());
    if (state->M == 0) {//M is invalid
        state->M = settings.value(DATASET_M, 3).toInt();
    }
    settings.endGroup();

    supercubeEdgeSpin->setValue(state->M);
    supercubeEdgeSpinValueChanged(state->M);//refill label

    //settings depending on M
    state->cubeSetElements = state->M * state->M * state->M;
    state->cubeSetBytes = state->cubeSetElements * state->cubeBytes;

    for(uint i = 0; i < state->viewerState->numberViewports; i++) {
        state->viewerState->vpConfigs[i].texture.texUnitsPerDataPx /= static_cast<float>(state->magnification);
        state->viewerState->vpConfigs[i].texture.usedTexLengthDc = state->M;
    }

    if(state->M * state->cubeEdgeLength >= TEXTURE_EDGE_LEN) {
        qDebug() << "Please choose smaller values for M or N. Your choice exceeds the KNOSSOS texture size!";
        throw std::runtime_error("Please choose smaller values for M or N. Your choice exceeds the KNOSSOS texture size!");
    }

    // We're not doing stuff in parallel, yet. So we skip the locking
    // part.
    // This *10 thing is completely arbitrary. The larger the table size,
    // the lower the chance of getting collisions and the better the loading
    // order will be respected. *10 doesn't seem to have much of an effect
    // on performance but we should try to find the optimal value some day.
    // Btw: A more clever implementation would be to use an array exactly the
    // size of the supercube and index using the modulo operator.
    // sadly, that realization came rather late. ;)

    // creating the hashtables is cheap, keeping the datacubes is
    // memory expensive..
    for(int i = 0; i <= NUM_MAG_DATASETS; i = i * 2) {
        state->Dc2Pointer[int_log(i)] = Hashtable::ht_new(state->cubeSetElements * 10);
        state->Oc2Pointer[int_log(i)] = Hashtable::ht_new(state->cubeSetElements * 10);
        if(i == 0) i = 1;
    }
}
示例#4
0
std::pair<bool, char *> getRawCube(const Coordinate & pos) {
    const auto posDc = pos.cube(state->cubeEdgeLength, state->magnification);

    state->protectCube2Pointer.lock();
    auto rawcube = Coordinate2BytePtr_hash_get_or_fail(state->Oc2Pointer[int_log(state->magnification)], posDc);
    state->protectCube2Pointer.unlock();

    return std::make_pair(rawcube != nullptr, rawcube);
}
示例#5
0
void ZoomWidget::reinitializeOrthoZoomWidgets() {
    const auto mags = int_log(state->viewer->highestMag()) - int_log(state->viewer->lowestMag()) + 1;
    const auto interval = 50;

    zoomStep = std::pow(2, 1./interval);
    int max_value = std::ceil(std::log(state->viewer->highestScreenPxXPerDataPx() / state->viewer->lowestScreenPxXPerDataPx()) / std::log(zoomStep));
    orthoZoomSlider.numTicks = mags > 1 ? mags : 0;
    orthoZoomSlider.highestMag = state->viewer->highestMag();
    const auto orthoZoomSliderBlock = orthoZoomSlider.blockSignals(true);
    orthoZoomSlider.setRange(0, max_value);
    orthoZoomSlider.setTickInterval(interval);
    updateOrthogonalZoomSlider();
    orthoZoomSlider.blockSignals(orthoZoomSliderBlock);

    const auto orthoZoomSpinBoxBlock = orthoZoomSpinBox.blockSignals(true);
    orthoZoomSpinBox.setMinimum(100 * (state->viewer->lowestScreenPxXPerDataPx(false) / state->viewer->lowestScreenPxXPerDataPx(false)));
    orthoZoomSpinBox.setMaximum(100 * (state->viewer->highestScreenPxXPerDataPx(false) / state->viewer->lowestScreenPxXPerDataPx(false)));
    updateOrthogonalZoomSpinBox();
    orthoZoomSlider.blockSignals(orthoZoomSpinBoxBlock);
}
hashtable *hashtable_alloc(size_t capacity,
                           uint32_t (*hash) (const void *),
                           int (*eq) (const void *, const void *)) {
  hashtable *ht = malloc(sizeof(hashtable));
  assert(ht);
  /* capacity must be power of 2 */
  ht->size     = 0;
  ht->capacity = int_pow2(int_log(2, 2*capacity));
  ht->table    = malloc(ht->capacity * sizeof(hash_elem *));
  assert(ht->table);
  memset(ht->table, 0, ht->capacity * sizeof(hash_elem *));
  ht->hash     = hash;
  ht->eq       = eq;
  return ht;
}
示例#7
0
/*
 * Builds the btree to index the map.
 */
int dm_table_complete(struct dm_table *t)
{
	int r = 0;
	unsigned int leaf_nodes;

	check_for_valid_limits(&t->limits);

	/* how many indexes will the btree have ? */
	leaf_nodes = dm_div_up(t->num_targets, KEYS_PER_NODE);
	t->depth = 1 + int_log(leaf_nodes, CHILDREN_PER_NODE);

	/* leaf layer has already been set up */
	t->counts[t->depth - 1] = leaf_nodes;
	t->index[t->depth - 1] = t->highs;

	if (t->depth >= 2)
		r = setup_indexes(t);

	return r;
}
示例#8
0
文件: main.cpp 项目: CCJY/coliru
constexpr std::size_t int_log(const std::size_t val, const std::size_t base = 2, const std::size_t res = 0) {
    return val < base ? res : int_log(val/base, base, res+1);
}
示例#9
0
文件: main.cpp 项目: CCJY/coliru
constexpr T int_log(const T & val, const T & base = 2, const T & res = 0) {
    return val < base ? res : int_log(val/base, base, res+1);
}