void AtlasManager::addToAtlas(int firstBrickIndex, int lastBrickIndex, float* mappedBuffer) { while (_brickMap.count(firstBrickIndex) && firstBrickIndex <= lastBrickIndex) firstBrickIndex++; while (_brickMap.count(lastBrickIndex) && lastBrickIndex >= firstBrickIndex) lastBrickIndex--; if (lastBrickIndex < firstBrickIndex) return; int sequenceLength = lastBrickIndex - firstBrickIndex + 1; float* sequenceBuffer = new float[sequenceLength*_nBrickVals]; size_t bufferSize = sequenceLength * _brickSize; long long offset = TSP::dataPosition() + static_cast<long long>(firstBrickIndex) * static_cast<long long>(_brickSize); _tsp->file().seekg(offset); _tsp->file().read(reinterpret_cast<char*>(sequenceBuffer), bufferSize); _nDiskReads++; for (int brickIndex = firstBrickIndex; brickIndex <= lastBrickIndex; brickIndex++) { if (!_brickMap.count(brickIndex)) { unsigned int atlasCoords = _freeAtlasCoords.back(); _freeAtlasCoords.pop_back(); int level = _nOtLevels - floor(log((7.0 * (float(brickIndex % _nOtNodes)) + 1.0))/log(8)) - 1; assert(atlasCoords <= 0x0FFFFFFF); unsigned int atlasData = (level << 28) + atlasCoords; _brickMap.insert(std::pair<unsigned int, unsigned int>(brickIndex, atlasData)); _nStreamedBricks++; fillVolume(&sequenceBuffer[_nBrickVals*(brickIndex - firstBrickIndex)], mappedBuffer, atlasCoords); } } delete[] sequenceBuffer; }
inline int Puzzle::fillVolume(GridPoint* gp, int fillValue) { if(gp->fill != unoccupiedFill) return 0; int volume = 1; gp->fill = fillValue; for(std::vector<GridPoint*>::iterator ni = gp->neighborList.begin(); ni != gp->neighborList.end(); ++ni) volume += fillVolume(*ni, fillValue); return volume; }
bool PaintBall::keyPressEvent(QKeyEvent *event) { if (m_frame.grabsMouse() == false) return false; if (event->key() == Qt::Key_Space) { QString cmd; bool ok; QString mesg; mesg = "tag, thickness\n\n"; mesg += QString("Current tag value = %1\nCurrent surface thickness value = %2").arg(m_tag).arg(m_thickness), cmd = QInputDialog::getText(0, "PaintBall", mesg, QLineEdit::Normal, "", &ok); if (ok && !cmd.isEmpty()) processCommand(cmd); return true; } if (event->key() == Qt::Key_T) { // tag all if (event->modifiers() & Qt::ShiftModifier) emit tagVolume(m_tag, false); else emit tagVolume(m_tag, true); return true; } else if (event->key() == Qt::Key_F) { // tag connected region if (event->modifiers() & Qt::ShiftModifier) emit fillVolume(m_tag, false); else emit fillVolume(m_tag, true); return true; } else if (event->key() == Qt::Key_D) { // tag connected region if (event->modifiers() & Qt::ShiftModifier) emit dilateVolume(m_tag, m_thickness, false); else emit dilateVolume(m_tag, m_thickness, true); return true; } else if (event->key() == Qt::Key_E) { // tag connected region if (event->modifiers() & Qt::ShiftModifier) emit erodeVolume(m_tag, m_thickness, false); else emit erodeVolume(m_tag, m_thickness, true); return true; } else if (event->key() == Qt::Key_S) { // tag surface if (event->modifiers() & Qt::ShiftModifier) emit tagSurface(m_tag, m_thickness, false, false); else emit tagSurface(m_tag, m_thickness, true, false); return true; } else if (event->key() == Qt::Key_C) { // tag connected surface if (event->modifiers() & Qt::ShiftModifier) emit tagSurface(m_tag, m_thickness, false, true); else emit tagSurface(m_tag, m_thickness, true, true); return true; } else if (event->key() == Qt::Key_X) { m_constraints->setTranslationConstraintType(AxisPlaneConstraint::AXIS); m_constraints->setTranslationConstraintDirection(Vec(1,0,0)); m_frame.setConstraint(m_constraints); return true; } else if (event->key() == Qt::Key_Y) { m_constraints->setTranslationConstraintType(AxisPlaneConstraint::AXIS); m_constraints->setTranslationConstraintDirection(Vec(0,1,0)); m_frame.setConstraint(m_constraints); return true; } else if (event->key() == Qt::Key_Z) { m_constraints->setTranslationConstraintType(AxisPlaneConstraint::AXIS); m_constraints->setTranslationConstraintDirection(Vec(0,0,1)); m_frame.setConstraint(m_constraints); return true; } else if (event->key() == Qt::Key_W) { m_constraints->setTranslationConstraintType(AxisPlaneConstraint::FREE); m_frame.setConstraint(m_constraints); return true; } return false; }