Viewer::Viewer(const char* title, const FilePath& applicationPath, const FilePath& settingsFilePath):
    m_Path(settingsFilePath.directory()),
    m_Settings(applicationPath.file(), settingsFilePath),
    m_WindowManager(m_Settings.m_WindowSize.x, m_Settings.m_WindowSize.y,
                    title),
    m_GUI(applicationPath.file(), m_WindowManager),
    m_ShaderManager(applicationPath.directory() + "shaders"),
    m_GLImageRenderer(m_ShaderManager),
    m_ViewController(m_WindowManager.getWindow()) {

    std::clog << "applicationPath = " << applicationPath << std::endl;
    std::clog << "settingsFilePath = " << settingsFilePath << std::endl;

    initScene();
    initConfigManager();

    m_ViewController.setSpeed(m_Settings.m_fSpeedFarRatio * length(size(m_pScene->getBBox())));

    std::clog << "Number of system threads = " << getSystemThreadCount() << std::endl;

    m_RenderModule.setUp(m_Path,
                         m_Settings.m_pCacheRoot,
                         m_Settings.m_FramebufferSize);

    {
        // Load current config
        auto pConfig = m_Settings.m_pCacheRoot->FirstChildElement("Config");
        if(pConfig) {
            std::string name;
            if(getAttribute(*pConfig, "name", name)) {
                try {
                    ProjectiveCamera camera;
                    m_ConfigManager.loadConfig(name, camera, *m_pScene,
                        m_Settings.m_FramebufferSize.x, m_Settings.m_FramebufferSize.y,
                        m_ZNearFar.x, m_ZNearFar.y);
                    m_nCurrentConfig = m_ConfigManager.getConfigIndex(name);
                } catch(...) {
                    std::cerr << "Unable to load previously cached configuration" << std::endl;
                }
            }
        } else {
            auto configCount = m_ConfigManager.getConfigs().size();
            if(configCount > 0u) {
                ProjectiveCamera camera;
                m_ConfigManager.loadConfig(0, camera, *m_pScene,
                    m_Settings.m_FramebufferSize.x, m_Settings.m_FramebufferSize.y,
                    m_ZNearFar.x, m_ZNearFar.y);
                m_nCurrentConfig = 0;
            } else {
                LOG(INFO) << "No configs for the scene, the program might eventually crash.";
            }
        }
    }
}
Exemple #2
0
	bool find(const std::string& name, FilePath& result, bool recursive=true) {
		bool found = false;
		if (dir && APR_SUCCESS == check_apr(apr_dir_open(&dir, dirname.c_str(), mPool))) {
			// iterate over directory:
			while ((!found) && APR_SUCCESS == (apr_dir_read(&dirent, APR_FINFO_TYPE|APR_FINFO_NAME, dir))) {
				//printf("test %s %s\n", dirname.c_str(), dirent.name);
				if (dirent.filetype == APR_REG && dirent.name && std::string(dirent.name) == name) {
					result.file(dirent.name);
					result.path(dirname);
					found = true;
					break;
				} else if (recursive && dirent.filetype == APR_DIR && dirent.name && dirent.name[0] != '.') {
					Path path(dirname + dirent.name + AL_FILE_DELIMITER);
					found = path.find(name, result, true);
				}
			}
		} else {
			printf("couldn't open directory %s\n", dirname.c_str());
		}
		return found;
	}
	int glob(const std::string& regex, FileList& result, bool recursive=true) {
		std::regex e(regex);
		if (dir && APR_SUCCESS == check_apr(apr_dir_open(&dir, dirname.c_str(), mPool))) {
			// iterate over directory:
			while (APR_SUCCESS == (apr_dir_read(&dirent, APR_FINFO_TYPE|APR_FINFO_NAME, dir))) {
				//printf("test %s %s\n", dirname.c_str(), dirent.name);
				if (dirent.filetype == APR_REG && dirent.name && std::regex_match(dirname+dirent.name,e) ) {
					FilePath res;
					res.file(dirent.name);
					res.path(dirname);
					result.add(res);
				} else if (recursive && dirent.filetype == APR_DIR && dirent.name && dirent.name[0] != '.') {
					Path path(dirname + dirent.name + AL_FILE_DELIMITER);
					path.glob(regex, result, true);
				}
			}
		} else {
			AL_WARN("couldn't open directory %s", dirname.c_str());
		}
		return result.count();
	}
void DoradeFile::open_file(const string &filename, const bool newFile) throw(Fault) {

    char msg[2048];
    FilePath filePath;
    useBigEndian_ = false;

    if(file_ != NULL){
	close_file();
    }

    if(newFile){
	// bWrite new File.
	if((file_ = fopen(filename.c_str(),"w")) == NULL){
	    sprintf(msg,"DoradeFile::open_file failed: %s \n",strerror(errno));
	    throw Fault(msg);
	}
	newFile_ = true;
    }else{
	// Read existing file.
	if((file_ = fopen(filename.c_str(),"r")) == NULL){
	    sprintf(msg,"DoradeFile::open_file failed: %s \n",strerror(errno));
	    throw Fault(msg);
	}
	newFile_ = false;
	useBigEndian_ = test_big_endian();
    }

    filePath.file(filename);

    stringValues_["file_name"]      = filePath.get_name();
    stringValues_["directory_name"] = filePath.get_directory();

    if(decoder_ == NULL){
	decoder_ = new Decoder();
	decoder_->buffers_big_endian(useBigEndian_);
    }

}