char Config::getValue(std::string option) { std::map<std::string, std::string>::iterator it = mConfData.find(option); SAssert( it != mConfData.end(), "Key: " + option + " not found in " + mFilePath); SAssert(it->second.length() == 1, "String can't be loaded into a single char"); return (it->second.at(0)); }
void Animation::reevaluateSizeValues() { mSliceWidth = (unsigned short) (mSprite.getTexture()->getSize().x / mColumns); mSliceHeight = (unsigned short) ( mSprite.getTexture()->getSize().y / mRows); SAssert(mSliceWidth*mColumns <= mSprite.getTexture()->getSize().x, "Slice size too large"); SAssert(mSliceHeight*mRows <= mSprite.getTexture()->getSize().y, "Slice size too large"); }
void ButtonList::add(Button* button) { SAssert(mCurSize < mMaxSize, "index out of range"); mButtons[mCurSize] = button; ++mCurSize; SAssert(button->getMapX() <= MAP_WIDTH && button->getMapY() >= 0 && button->getMapX() >= 0 && button->getMapY() <= MAP_HEIGHT, "mMapX/Y is out of range"); mMap[button->getMapX()][button->getMapY()] = button; }
Float InterpolatedSpectrum::eval(Float lambda) const { typedef std::vector<Float>::const_iterator it; SAssert(m_wavelength.size() > 0); if (lambda < m_wavelength[0] || lambda > m_wavelength[m_wavelength.size()-1]) return 0; std::pair<it, it> result = std::equal_range(m_wavelength.begin(), m_wavelength.end(), lambda); size_t idx1 = result.first - m_wavelength.begin(); size_t idx2 = result.second - m_wavelength.begin(); if (idx1 == idx2) { Float x_a = m_wavelength[idx1-1]; Float x_b = m_wavelength[idx1]; Float y_a = m_value[idx1-1]; Float y_b = m_value[idx1]; Float t = (lambda - x_a) / (x_b-x_a); return y_a + t * (y_b-y_a); } else if (idx2 == idx1+1) { /* Hit a value exactly */ return m_value[idx1]; } else { SLog(EError, "Internal error while interpolating spectrum values"); return 0; } }
static std::string typeMaskToString(unsigned int typeMask) { std::ostringstream oss; oss << "{ "; #define isset(mask) (typeMask & mask) == mask { if (isset(BSDF::EAll)) { oss << "all "; typeMask &= ~BSDF::EAll; } if (isset(BSDF::ESmooth)) { oss << "smooth "; typeMask &= ~BSDF::ESmooth; } if (isset(BSDF::EDiffuse)) { oss << "diffuse "; typeMask &= ~BSDF::EDiffuse; } if (isset(BSDF::EGlossy)) { oss << "glossy "; typeMask &= ~BSDF::EGlossy; } if (isset(BSDF::EDelta)) { oss << "delta"; typeMask &= ~BSDF::EDelta; } if (isset(BSDF::EDelta1D)) { oss << "delta1D "; typeMask &= ~BSDF::EDelta1D; } if (isset(BSDF::EDiffuseReflection)) { oss << "diffuseReflection "; typeMask &= ~BSDF::EDiffuseReflection; } if (isset(BSDF::EDiffuseTransmission)) { oss << "diffuseTransmission "; typeMask &= ~BSDF::EDiffuseTransmission; } if (isset(BSDF::EGlossyReflection)) { oss << "glossyReflection "; typeMask &= ~BSDF::EGlossyReflection; } if (isset(BSDF::EGlossyTransmission)) { oss << "glossyTransmission "; typeMask &= ~BSDF::EGlossyTransmission; } if (isset(BSDF::EDeltaReflection)) { oss << "deltaReflection "; typeMask &= ~BSDF::EDeltaReflection; } if (isset(BSDF::EDeltaTransmission)) { oss << "deltaTransmission "; typeMask &= ~BSDF::EDeltaTransmission; } if (isset(BSDF::EDelta1DReflection)) { oss << "delta1DReflection "; typeMask &= ~BSDF::EDelta1DReflection; } if (isset(BSDF::EDelta1DTransmission)) { oss << "delta1DTransmission "; typeMask &= ~BSDF::EDelta1DTransmission; } if (isset(BSDF::ENull)) { oss << "null "; typeMask &= ~BSDF::ENull; } if (isset(BSDF::EAnisotropic)) { oss << "anisotropic "; typeMask &= ~BSDF::EAnisotropic; } if (isset(BSDF::EFrontSide)) { oss << "frontSide "; typeMask &= ~BSDF::EFrontSide; } if (isset(BSDF::EBackSide)) { oss << "backSide "; typeMask &= ~BSDF::EBackSide; } if (isset(BSDF::EUsesSampler)) { oss << "usesSampler "; typeMask &= ~BSDF::EUsesSampler; } if (isset(BSDF::ESpatiallyVarying)) { oss << "spatiallyVarying"; typeMask &= ~BSDF::ESpatiallyVarying; } if (isset(BSDF::ENonSymmetric)) { oss << "nonSymmetric"; typeMask &= ~BSDF::ENonSymmetric; } } #undef isset SAssert(typeMask == 0); oss << "}"; return oss.str(); }
AABB1 AnimatedTransform::getTimeBounds() const { if (m_tracks.size() == 0) #if !defined(__clang__) return AABB1(0.0f, 0.0f); #else // HACK Workaround for clang { AABB1 b; b.min = b.max = 0.0f; return b; } #endif Float min = std::numeric_limits<Float>::infinity(); Float max = -std::numeric_limits<Float>::infinity(); for (size_t i=0; i<m_tracks.size(); ++i) { const AbstractAnimationTrack *track = m_tracks[i]; size_t size = track->getSize(); SAssert(size > 0); min = std::min(min, track->getTime(0)); max = std::max(max, track->getTime(size-1)); } #if !defined(__clang__) return AABB1(min, max); #else // HACK Workaround for clang AABB1 b; b.min = min; b.max = max; return b; #endif }
void Config::loadToMemory(std::string file) { mFile.open(file); SAssert(mFile.is_open(), "Could not open config file: " + mFilePath); std::string line = ""; while(std::getline(mFile, line)) { std::size_t comment = line.find('#', 0); if(comment == std::string::npos) { //Removes Spaces std::string::size_type space = line.find(' '); while (std::string::npos != space) { line.erase(space, 1); space = line.find(' '); } std::istringstream is_line(line); std::string key; if( std::getline(is_line, key, '=') ) { std::string value; if( std::getline(is_line, value) ) { mConfData.emplace(key, value); } } } } }
MTS_NAMESPACE_BEGIN void Spectrum::staticInitialization() { if (SPECTRUM_SAMPLES == 3) { /* CIE RGB primaries */ m_wavelengths[0] = 700.0f; m_wavelengths[1] = 546.1f; m_wavelengths[2] = 438.8f; } else { SAssert(SPECTRUM_SAMPLES <= CIE_count); std::ostringstream oss; Float stepSize = SPECTRUM_RANGE / (Float) SPECTRUM_SAMPLES; for (int i=0; i<SPECTRUM_SAMPLES; i++) { int wavelength = SPECTRUM_MIN_WAVELENGTH + (int) (stepSize * i); m_wavelengths[i] = (Float) wavelength; oss << wavelength; if (i+1<SPECTRUM_SAMPLES) oss << ", "; } Spectrum s(1.0f); m_normalization = s.getLuminance(); m_invNormalization = 1.0f / m_normalization; SLog(EDebug, "Configuring for spectral rendering using " "the wavelengths %s", oss.str().c_str()); } }
double Config::getValue(std::string option) { std::map<std::string, std::string>::iterator it = mConfData.find(option); SAssert( it != mConfData.end(), "Key: " + option + " not found in " + mFilePath); return std::stod(it->second); }
bool SSoundBuffer::loadResource() { mSBuffer = new sf::SoundBuffer(); bool success = mSBuffer->loadFromFile(getRef()); SAssert(success, "Loading failed for some reason."); return success; }
void SSprite::draw(sf::RenderWindow &win) { sync(); SAssert(mSTex.isLoaded(), "The texture isn't loaded. " + mSTex.getRef()); win.draw(mSprite); }
void Effects::addEffect(EffectImp* effect) { SAssert(mCurSize < MAX_SIZE, "index out of bounds"); mEffectList[mCurSize] = effect; ++mCurSize; evaluate(); }
Config::Config(std::string filePath, bool implicitLoad) : mConfData(), mFilePath(filePath), mFile() { SAssert(str::contains(filePath, ".cfg"), "config file: " + filePath + " is of unknown format"); if(implicitLoad) { loadToMemory(mFilePath); } }
TTm TSysTm::GetTmFromMSecs(const uint64& MSecs){ TUInt64 FileTmUnits(MSecs*uint64(10000)); SYSTEMTIME SysTm; FILETIME FileTm; FileTm.dwHighDateTime=FileTmUnits.GetMsVal(); FileTm.dwLowDateTime=FileTmUnits.GetLsVal(); SAssert(FileTimeToSystemTime(&FileTm, &SysTm)); return TTm(SysTm.wYear, SysTm.wMonth, SysTm.wDay, SysTm.wDayOfWeek, SysTm.wHour, SysTm.wMinute, SysTm.wSecond, SysTm.wMilliseconds); }
void SHVector::convolve(const SHVector &kernel) { SAssert(kernel.getBands() == m_bands); for (int l=0; l<m_bands; ++l) { Float alpha = std::sqrt(4 * (Float) M_PI / (2*l + 1)); for (int m=-l; m<=l; ++m) operator()(l, m) *= alpha * kernel(l, 0); } }
Float VonMisesFisherDistr::forMeanCosine(Float g) { if (g == 0) return 0; else if (g < 0) SLog(EError, "Error: vMF distribution cannot be created for g<0."); BrentSolver brentSolver(100, 1e-6f); BrentSolver::Result result = brentSolver.solve( boost::bind(&meanCosineFunctor, _1, g), 0, 1000); SAssert(result.success); return result.x; }
void SHRotation::operator()(const SHVector &source, SHVector &target) const { SAssert(source.getBands() == target.getBands()); for (int l=0; l<source.getBands(); ++l) { const SHRotation::Matrix &M = blocks[l]; for (int m1=-l; m1<=l; ++m1) { Float result = 0; for (int m2=-l; m2<=l; ++m2) result += M(m1+l, m2+l)*source(l, m2); target(l, m1) = result; } } }
void ResourceHandler::load(std::string ref) { if(str::contains(ref, ".xoxo", false)) { loadResources(ref); } else { SAssert(mLoadables.count(ref) > 0, "Couldn't load file: " + ref); Loadable& tmp = mLoadables.at(ref); tmp.load(); mCurLoaded.insert(std::pair<std::string, Loadable&>(ref, tmp)); } }
void ResourceHandler::addResources(std::string fileRef) { std::ifstream stream(fileRef); SAssert(!stream.bad(), "Stream went bad! - " + fileRef); std::string nextLine; while(!stream.eof()) { std::getline(stream, nextLine); if(nextLine.length() > 0) { add(nextLine); } } }
void Config::saveConfigChange() { close(); mFile.open(mFilePath); SAssert(mFile.is_open(), "Could not open config file: " + mFilePath); std::string tempString = ""; std::string line = ""; while(std::getline(mFile, line)) { std::size_t comment = line.find('#', 0); if(comment == std::string::npos) { //Removes Spaces std::string::size_type space = line.find(' '); while (std::string::npos != space) { line.erase(space, 1); space = line.find(' '); } std::istringstream is_line(line); std::string key; if( std::getline(is_line, key, '=') ) { std::string value; if( std::getline(is_line, value) ) { std::map<std::string, std::string>::iterator it = mConfData.find(key); value = it->second; line = key + " = " + value; } } } for( std::size_t i = 0; i < line.length(); i++ ) { tempString.push_back(line.at(i)); } tempString.push_back('\n'); } std::filebuf fb; fb.open(mFilePath, std::ios::out); std::ostream os(&fb); os << tempString; fb.close(); }
void Animation::draw(sf::RenderWindow &win) { if(mTexVersion != mSTex->getVersion()) { mSprite.setTexture(getTexture()); reevaluateSizeValues(); mTexVersion = mSTex->getVersion(); } SAssert(mSTex->isLoaded(), "The texture isn't loaded. " + mSTex->getRef()); int curFrame = getCurrentFrame(); sf::IntRect r(sf::IntRect(curFrame*mSliceWidth, mCurrentRow*mSliceHeight, mSliceWidth, mSliceHeight)); mSprite.setTextureRect(r); win.draw(mSprite); }
bool Config::getValue(std::string option) { std::map<std::string, std::string>::iterator it = mConfData.find(option); SAssert( it != mConfData.end(), "Key: " + option + " not found in " + mFilePath); if(it->second == "false") { return false; } else if(it->second == "true") { return true; } else { SError("Conversion Error" , "Cannot convert " + it->second + " to bool" ); #ifdef NDEBUG return false; #endif } }
Matrix3x3 SHVector::mu2() const { const Float sqrt5o3 = std::sqrt((Float) 5/ (Float) 3); const Float sqrto3 = std::sqrt((Float) 1/ (Float) 3); Matrix3x3 result; result.setZero(); SAssert(m_bands > 0); result(0, 0) = result(1, 1) = result(2, 2) = sqrt5o3*operator()(0,0); if (m_bands >= 3) { result(0, 0) += -operator()(2,0)*sqrto3 + operator()(2,2); result(0, 1) = operator()(2,-2); result(0, 2) = -operator()(2, 1); result(1, 0) = operator()(2,-2); result(1, 1) += -operator()(2,0)*sqrto3 - operator()(2,2); result(1, 2) = -operator()(2,-1); result(2, 0) = -operator()(2, 1); result(2, 1) = -operator()(2,-1); result(2, 2) += 2*sqrto3*operator()(2,0); } return result * (2*std::sqrt((Float) M_PI / 15)); }
Button* ButtonList::getFirst() { SAssert(mButtons[0] != NULL, "No buttons to start on"); return mButtons[0]; }
void InterpolatedSpectrum::appendSample(Float lambda, Float value) { SAssert(m_wavelength.size() == 0 || m_wavelength[m_wavelength.size()-1] < lambda); m_wavelength.push_back(lambda); m_value.push_back(value); }
const sf::SoundBuffer &SSoundBuffer::getSoundBuffer() const { SAssert(isLoaded(), "You need to load files before playing them."); return *mSBuffer; }
void RenderSettingsDialog::apply(SceneContext *ctx) { Scene *scene = new Scene(ctx->scene); ref<Sensor> oldSensor = scene->getSensor(); Film *oldFilm = oldSensor->getFilm(); Properties filmProps = oldSensor->getFilm()->getProperties(); ref<PluginManager> pluginMgr = PluginManager::getInstance(); /* Temporarily set up a new file resolver */ ref<Thread> thread = Thread::getThread(); ref<FileResolver> oldResolver = thread->getFileResolver(); ref<FileResolver> newResolver = oldResolver->clone(); newResolver->prependPath(fs::absolute(scene->getSourceFile()).parent_path()); thread->setFileResolver(newResolver); /* Configure the reconstruction filter */ Properties rFilterProps(getPluginName(ui->rFilterBox)); if (m_rFilterNode != NULL) m_rFilterNode->putProperties(rFilterProps); ref<ReconstructionFilter> rFilter = static_cast<ReconstructionFilter *> (pluginMgr->createObject(MTS_CLASS(ReconstructionFilter), rFilterProps)); rFilter->configure(); /* Configure the sampler */ Properties samplerProps(getPluginName(ui->samplerBox)); if (m_samplerNode != NULL) m_samplerNode->putProperties(samplerProps); ref<Sampler> sampler = static_cast<Sampler *> (pluginMgr->createObject(MTS_CLASS(Sampler), samplerProps)); sampler->configure(); /* Configure the integrator */ Properties integratorProps(getPluginName(ui->integratorBox)); if (m_integratorNode != NULL) m_integratorNode->putProperties(integratorProps); ref<Integrator> integrator = static_cast<Integrator *> (pluginMgr->createObject(MTS_CLASS(Integrator), integratorProps)); integrator->configure(); if (ui->icBox->isChecked()) { Properties icProps("irrcache"); if (m_icNode != NULL) m_icNode->putProperties(icProps); ref<Integrator> ic = static_cast<Integrator *> (pluginMgr->createObject(MTS_CLASS(Integrator), icProps)); ic->addChild(integrator); ic->configure(); integrator = ic; } if (ui->aiBox->isChecked()) { Properties aiProps("adaptive"); if (m_aiNode != NULL) m_aiNode->putProperties(aiProps); ref<Integrator> ai = static_cast<Integrator *> (pluginMgr->createObject(MTS_CLASS(Integrator), aiProps)); ai->addChild(integrator); ai->configure(); integrator = ai; } QStringList resolution = ui->resolutionBox->currentText().split('x'); SAssert(resolution.size() == 2); Vector2i cropSize( std::max(1, resolution[0].toInt()), std::max(1, resolution[1].toInt())); /* Configure the film */ Vector2i oldSize = oldFilm->getSize(); Vector2i oldCropSize = oldFilm->getCropSize(); Point2i oldCropOffset = oldFilm->getCropOffset(); Vector2i size(math::roundToInt((oldSize.x * cropSize.x / (Float) oldCropSize.x)), math::roundToInt((oldSize.y * cropSize.y / (Float) oldCropSize.y))); Point2i cropOffset(math::roundToInt((oldCropOffset.x * cropSize.x / (Float) oldCropSize.x)), math::roundToInt((oldCropOffset.y * cropSize.y / (Float) oldCropSize.y))); filmProps.setInteger("width", size.x, false); filmProps.setInteger("height", size.y, false); /* g-pt and g-bdpt only work with multifilm. */ if (getPluginName(ui->integratorBox) == "gbdpt" || getPluginName(ui->integratorBox) == "gpt") filmProps.setPluginName("multifilm"); else filmProps.setPluginName("hdrfilm"); if (size.x != cropSize.x || size.y != cropSize.y || cropOffset.x != 0 || cropOffset.y != 0) { filmProps.setInteger("cropWidth", cropSize.x, false); filmProps.setInteger("cropHeight", cropSize.y, false); filmProps.setInteger("cropOffsetX", cropOffset.x, false); filmProps.setInteger("cropOffsetY", cropOffset.y, false); } else { filmProps.removeProperty("cropWidth"); filmProps.removeProperty("cropHeight"); filmProps.removeProperty("cropOffsetX"); filmProps.removeProperty("cropOffsetY"); } ctx->originalSize = cropSize; ref<Film> film = static_cast<Film *> (pluginMgr->createObject( MTS_CLASS(Film), filmProps)); film->addChild(rFilter); film->configure(); if (cropSize.x != ctx->framebuffer->getWidth() || cropSize.y != ctx->framebuffer->getHeight()) { ctx->framebuffer = new Bitmap(Bitmap::ERGBA, Bitmap::EFloat32, cropSize); ctx->framebuffer->clear(); ctx->mode = EPreview; } /* Configure the sensor */ Properties sensorProps = oldSensor->getProperties(); if (oldSensor->getClass()->derivesFrom(MTS_CLASS(PerspectiveCamera))) { sensorProps.removeProperty("focalLength"); sensorProps.setString("fovAxis", "y", false); sensorProps.setFloat("fov", static_cast<const PerspectiveCamera *>(oldSensor.get())->getYFov(), false); } ref<Sensor> newSensor = static_cast<Sensor *> (pluginMgr->createObject(MTS_CLASS(Sensor), sensorProps)); newSensor->addChild(sampler); newSensor->addChild(film); newSensor->setMedium(oldSensor->getMedium()); newSensor->configure(); /* Update the scene with the newly constructed elements */ scene->removeSensor(oldSensor); scene->addSensor(newSensor); scene->setSensor(newSensor); scene->setSampler(sampler); scene->setIntegrator(integrator); scene->configure(); ctx->scene = scene; thread->setFileResolver(oldResolver); }
Float SHVector::computeNormalization(int l, int m) { SAssert(m>=0); return std::sqrt( ((2*l+1) * boost::math::factorial<Float>(l-m)) / (4 * (Float) M_PI * boost::math::factorial<Float>(l+m))); }
const sf::Texture &Animation::getTexture() const { SAssert(mSTex->isLoaded(), "You need to load the texture before using. " + mSTex->getRef()); return mSTex->getTexture(); }
const sf::Texture& SSprite::getTexture() const { SAssert(mSTex.isLoaded(), "You need to load the texture before using. " + mSTex.getRef()); return mSTex.getTexture(); }