void TrackView::editToggleInterpolationType() { SyncDocument *doc = getDocument(); if (editTrack < getTrackCount()) { SyncTrack *t = getTrack(editTrack); QMap<int, SyncTrack::TrackKey> keyMap = t->getKeyMap(); QMap<int, SyncTrack::TrackKey>::const_iterator it = keyMap.lowerBound(editRow); if (it != keyMap.constBegin() && it.key() != editRow) --it; if (it.key() > editRow || it == keyMap.constEnd()) { QApplication::beep(); return; } // copy and modify SyncTrack::TrackKey newKey = *it; newKey.type = (SyncTrack::TrackKey::KeyType) ((newKey.type + 1) % SyncTrack::TrackKey::KEY_TYPE_COUNT); // apply change to data-set doc->setKeyFrame(t, newKey); // update user interface dirtyCurrentValue(); } else QApplication::beep(); }
QRgb ColorElement::get_color(double v, bool smooth) { /* exact match */ //if(colorMap.contains(v)) return colorMap.value(v); /* out of bounderies */ if(v<=minVal) return colorMap.begin().value(); if(v>=maxVal) return (colorMap.end()-1).value(); /* std case */ QMap<double,QRgb>::Iterator it=colorMap.lowerBound(v); if(smooth) { double fact=(v-(it-1).key())/((it).key()-(it-1).key()); double fact2=1-fact; QRgb minVal=(it-1).value(); QRgb maxVal=it.value(); int r,g,b; r=(int)(fact2*qRed(minVal)+fact*qRed(maxVal)+0.5); g=(int)(fact2*qGreen(minVal)+fact*qGreen(maxVal)+0.5); b=(int)(fact2*qBlue(minVal)+fact*qBlue(maxVal)+0.5); return qRgba(r,g,b,transparence); } else { if(v-(it-1).key()<it.key()-v) return (it).value(); else return (it-1).value(); } }
void HoleFinderPrivate::finalizeHoles() { QMap<double, Hole> tmpMap; double totalVolume = 0.0; for (QVector<Hole>::const_iterator it = this->holes.constBegin(), it_end = this->holes.constEnd(); it != it_end; ++it) { double volume = it->volume(); tmpMap.insertMulti(volume, *it); totalVolume += volume; } QMap<double, Hole>::const_iterator largestHole = tmpMap.constEnd() - 1; QMap<double, Hole>::const_iterator smallestHole = tmpMap.lowerBound(this->minVolume); if (smallestHole == tmpMap.constEnd()) { smallestHole = tmpMap.lowerBound(0.1 * largestHole.key()); qWarning() << "HoleFinderPrivate::finalizeHoles No holes satisfying the " "minimum specified volume of " << this->minVolume << "." " Using a minimum volume that is 10% of the largest hole," << smallestHole.key(); } this->holeMap.clear(); double trimmedVolume = 0.0; for (QMap<double, Hole>::const_iterator it = smallestHole, it_end = tmpMap.constEnd(); it != it_end; ++it) { trimmedVolume += it.key(); this->holeMap.insertMulti(it.key(), it.value()); } this->holes.clear(); DEBUGOUT("finalizeHoles") "Total hole volume:" << totalVolume; DEBUGOUT("finalizeHoles") "Trimmed hole volume:" << trimmedVolume; DEBUGOUT("finalizeHoles") "Largest hole volume:" << largestHole.key(); DEBUGOUT("finalizeHoles") "Smallest hole volume:" << smallestHole.key(); DEBUGOUT("finalizeHoles") "Total holes:" << tmpMap.size(); DEBUGOUT("finalizeHoles") "Trimmed holes:" << this->holeMap.size(); }
/*! \internal */ static QPair<int, int> findMissingKey(const QMap<int, QPlaceContent> &map) { int start = 0; while (map.contains(start)) ++start; QMap<int, QPlaceContent>::const_iterator it = map.lowerBound(start); if (it == map.end()) return qMakePair(start, -1); int end = start; while (!map.contains(end)) ++end; return qMakePair(start, end - 1); }
float calculateRenderAccuracy(const glm::vec3& position, const AABox& bounds, float octreeSizeScale, int boundaryLevelAdjust) { float largestDimension = bounds.getLargestDimension(); const float maxScale = (float)TREE_SCALE; float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, octreeSizeScale) / OCTREE_TO_MESH_RATIO; static std::once_flag once; static QMap<float, float> shouldRenderTable; std::call_once(once, [&] { float SMALLEST_SCALE_IN_TABLE = 0.001f; // 1mm is plenty small float scale = maxScale; float factor = 1.0f; while (scale > SMALLEST_SCALE_IN_TABLE) { scale /= 2.0f; factor /= 2.0f; shouldRenderTable[scale] = factor; } }); float closestScale = maxScale; float visibleDistanceAtClosestScale = visibleDistanceAtMaxScale; QMap<float, float>::const_iterator lowerBound = shouldRenderTable.lowerBound(largestDimension); if (lowerBound != shouldRenderTable.constEnd()) { closestScale = lowerBound.key(); visibleDistanceAtClosestScale = visibleDistanceAtMaxScale * lowerBound.value(); } if (closestScale < largestDimension) { visibleDistanceAtClosestScale *= 2.0f; } // FIXME - for now, it's either visible or not visible. We want to adjust this to eventually return // a floating point for objects that have small angular size to indicate that they may be rendered // with lower preciscion float distanceToCamera = glm::length(bounds.calcCenter() - position); return (distanceToCamera <= visibleDistanceAtClosestScale) ? 1.0f : 0.0f; }
bool LODManager::shouldRender(const RenderArgs* args, const AABox& bounds) { const float maxScale = (float)TREE_SCALE; const float octreeToMeshRatio = 4.0f; // must be this many times closer to a mesh than a voxel to see it. float octreeSizeScale = args->_sizeScale; int boundaryLevelAdjust = args->_boundaryLevelAdjust; float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, octreeSizeScale) / octreeToMeshRatio; float distanceToCamera = glm::length(bounds.calcCenter() - args->_viewFrustum->getPosition()); float largestDimension = bounds.getLargestDimension(); static bool shouldRenderTableNeedsBuilding = true; static QMap<float, float> shouldRenderTable; if (shouldRenderTableNeedsBuilding) { float SMALLEST_SCALE_IN_TABLE = 0.001f; // 1mm is plenty small float scale = maxScale; float factor = 1.0f; while (scale > SMALLEST_SCALE_IN_TABLE) { scale /= 2.0f; factor /= 2.0f; shouldRenderTable[scale] = factor; } shouldRenderTableNeedsBuilding = false; } float closestScale = maxScale; float visibleDistanceAtClosestScale = visibleDistanceAtMaxScale; QMap<float, float>::const_iterator lowerBound = shouldRenderTable.lowerBound(largestDimension); if (lowerBound != shouldRenderTable.constEnd()) { closestScale = lowerBound.key(); visibleDistanceAtClosestScale = visibleDistanceAtMaxScale * lowerBound.value(); } if (closestScale < largestDimension) { visibleDistanceAtClosestScale *= 2.0f; } return distanceToCamera <= visibleDistanceAtClosestScale; };
void TextEditorOverlay::mapEquivalentSelections() { m_equivalentSelections.clear(); m_equivalentSelections.resize(m_selections.size()); QMap<QString, int> all; for (int i = 0; i < m_selections.size(); ++i) all.insertMulti(selectionText(i).toLower(), i); const QList<QString> &uniqueKeys = all.uniqueKeys(); foreach (const QString &key, uniqueKeys) { QList<int> indexes; QMap<QString, int>::const_iterator lbit = all.lowerBound(key); QMap<QString, int>::const_iterator ubit = all.upperBound(key); while (lbit != ubit) { indexes.append(lbit.value()); ++lbit; } foreach (int index, indexes) m_equivalentSelections[index] = indexes; }
Map *TileStamp::randomVariation() const { if (d->variations.isEmpty()) return 0; QMap<qreal, const TileStampVariation *> probabilityThresholds; qreal sum = 0.0; for (const TileStampVariation &variation : d->variations) { sum += variation.probability; probabilityThresholds.insert(sum, &variation); } qreal random = ((qreal)rand() / RAND_MAX) * sum; auto it = probabilityThresholds.lowerBound(random); const TileStampVariation *variation; if (it != probabilityThresholds.end()) variation = it.value(); else variation = &d->variations.last(); // floating point may have failed us return variation->map; }
int ScriptInfo::lineOffset(int lineNumber) { QMap<int, int>::const_iterator it = m_lineOffsets.constFind(lineNumber); if (it != m_lineOffsets.constEnd()) return it.value(); int offset; it = m_lineOffsets.constFind(lineNumber - 1); if (it != m_lineOffsets.constEnd()) { offset = it.value(); offset = m_code.indexOf(QLatin1Char('\n'), offset); if (offset != -1) ++offset; m_lineOffsets.insert(lineNumber, offset); } else { int index; it = m_lineOffsets.lowerBound(lineNumber); --it; if (it != m_lineOffsets.constBegin()) { index = it.key(); offset = it.value(); } else { index = m_lineNumber; offset = 0; } int j = index; for ( ; j < lineNumber; ++j) { m_lineOffsets.insert(j, offset); offset = m_code.indexOf(QLatin1Char('\n'), offset); if (offset == -1) break; ++offset; } m_lineOffsets.insert(j, offset); } return offset; }
void PluginGauss::loadRefDatas()//const ProjectSettings& settings) { mRefDatas.clear(); QString calibPath = getRefsPath(); QDir calibDir(calibPath); QFileInfoList files = calibDir.entryInfoList(QStringList(), QDir::Files); for(int i=0; i<files.size(); ++i) { if(files[i].suffix().toLower() == "csv") { QFile file(files[i].absoluteFilePath()); if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { QMap<QString, QMap<double, double> > curves; QMap<double, double> curveG; QMap<double, double> curveG95Sup; QMap<double, double> curveG95Inf; QTextStream stream(&file); while(!stream.atEnd()) { QString line = stream.readLine(); if(!isComment(line)) { QStringList values = line.split(","); if(values.size() >= 3) { double t = values[0].toDouble(); double g = values[1].toDouble(); double gSup = g + 1.96 * values[2].toDouble(); double gInf = g - 1.96 * values[2].toDouble(); curveG[t] = g; curveG95Sup[t] = gSup; curveG95Inf[t] = gInf; } } } file.close(); // The curves do not have 1-year precision! // We have to interpolate in the blanks double tmin = curveG.firstKey(); double tmax = curveG.lastKey(); for(double t=tmin; t<tmax; ++t)//t+=settings.mStep)//++t) { if(curveG.find(t) == curveG.end()) { // This actually return the iterator with the nearest greater key !!! QMap<double, double>::const_iterator iter = curveG.lowerBound(t); if(iter != curveG.end()) { double t_upper = iter.key(); --iter; if(iter != curveG.begin()) { double t_under = iter.key(); //qDebug() << t_under << " < " << t << " < " << t_upper; double g_under = curveG[t_under]; double g_upper = curveG[t_upper]; double gsup_under = curveG95Sup[t_under]; double gsup_upper = curveG95Sup[t_upper]; double ginf_under = curveG95Inf[t_under]; double ginf_upper = curveG95Inf[t_upper]; curveG[t] = interpolate(t, t_under, t_upper, g_under, g_upper); curveG95Sup[t] = interpolate(t, t_under, t_upper, gsup_under, gsup_upper); curveG95Inf[t] = interpolate(t, t_under, t_upper, ginf_under, ginf_upper); } else { curveG[t] = 0; curveG95Sup[t] = 0; curveG95Inf[t] = 0; } } else { curveG[t] = 0; curveG95Sup[t] = 0; curveG95Inf[t] = 0; } } } // Store the resulting curves : curves["G"] = curveG; curves["G95Sup"] = curveG95Sup; curves["G95Inf"] = curveG95Inf; mRefDatas[files[i].fileName().toLower()] = curves; } } } }