Beispiel #1
0
VolumeList* VolumeSerializer::readBrick(const std::string& url, tgt::ivec3 brickStartPos,
    int brickSize) const throw (tgt::FileException, std::bad_alloc)
{
    std::vector<VolumeReader*> matchingReaders = getReaders(url);
    tgtAssert(!matchingReaders.empty(), "readers vector empty (exception expected)");
    if (matchingReaders.size() == 1) {
        VolumeList* collection = matchingReaders.front()->readBrick(url, brickStartPos, brickSize);
        if (collection)
            appendPreferredReaderToOriginURLs(collection, matchingReaders.front());
        return collection;
    }
    else {
        // iterate over all possibly matching readers try to load data set, collect error messages
        std::vector<std::string> errors;
        for (size_t i=0; i<matchingReaders.size(); i++) {
            try {
                VolumeList* collection = matchingReaders.at(i)->readBrick(url, brickStartPos, brickSize);
                if (collection)
                    appendPreferredReaderToOriginURLs(collection, matchingReaders.at(i));
                return collection;
            }
            catch (const tgt::FileException& e) {
                errors.push_back(e.what());
            }
        }
        std::string errorMsg = "No VolumeReader was able to read the data set: " + strJoin(errors, "; ");
        throw tgt::FileException(errorMsg);
    }
}
Beispiel #2
0
std::string VolumeIOHelper::getVolumeReaderFilterString() const {
    tgtAssert(volumeSerializerPopulator_, "no volumeserializerpopulator");

    std::string filterStr;

    std::vector<std::string> extensionVec = volumeSerializerPopulator_->getSupportedReadExtensions();
    if (!extensionVec.empty()) {
        filterStr += "*." + strJoin(extensionVec, " *.");
    }

    std::vector<std::string> filenameVec = volumeSerializerPopulator_->getSupportedReadFilenames();
    if (!filenameVec.empty()) {
        filterStr += " " + strJoin(filenameVec, " ");
    }

    return "Volume Files (" + filterStr + ")";
}
Beispiel #3
0
END_TEST

START_TEST(test_strJoin)
{
    char **list;
    size_t size;

    listCreate(list, &size);
    listAdd(list, "foo", &size);
    listAdd(list, "bar", &size);
    listAdd(list, "xyz", &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo bar xyz"), NULL);
    fail_unless(strEquals(strJoin("()", list, size), "foo()bar()xyz"), NULL);
    listRemove(list, 1, &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo xyz"), NULL);
    listRemove(list, 1, &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo"), NULL);
    listRemove(list, 0, &size);
    fail_unless(strEquals(strJoin(" ", list, size), ""), NULL);
    listFree(list);
}
Beispiel #4
0
VolumeList* VolumeSerializer::read(const std::string& url) const
    throw (tgt::FileException, std::bad_alloc)
{
    std::vector<VolumeReader*> matchingReaders = getReaders(url);
    tgtAssert(!matchingReaders.empty(), "readers vector empty (exception expected)");
    if (matchingReaders.size() == 1) {
        VolumeList* collection = matchingReaders.front()->read(url);
        if (collection)
            appendPreferredReaderToOriginURLs(collection, matchingReaders.front());
        return collection;
    }
    else {
         std::vector<std::string> errors;

        // if preferred reader is specified and available, use it for loading the data set
        VolumeReader* prefReader = 0;
        VolumeURL urlOrigin(url);
        std::string prefReaderStr = urlOrigin.getSearchParameter("preferredReader");
        if (prefReaderStr != "")
            prefReader = getReaderByName(prefReaderStr);
        if (prefReader) {
            try {
                VolumeList* collection = prefReader->read(url);
                if (collection)
                    appendPreferredReaderToOriginURLs(collection,  prefReader);
                return collection;
            }
            catch (const tgt::FileException& e) {
                errors.push_back(e.what());
            }
        }

        // if no preferred reader or preferred reader could not load the data set,
        // iterate over all possibly matching readers and try to load data set, collect error messages
        for (size_t i=0; i<matchingReaders.size(); i++) {
            if (matchingReaders.at(i) == prefReader)
                continue;
            try {
                VolumeList* collection = matchingReaders.at(i)->read(url);
                if (collection)
                    appendPreferredReaderToOriginURLs(collection,  matchingReaders.at(i));
                return collection;
            }
            catch (const tgt::FileException& e) {
                errors.push_back(e.what());
            }
        }
        std::string errorMsg = "No VolumeReader was able to read the data set: " + strJoin(errors, "; ");
        throw tgt::FileException(errorMsg);

    }
}
Beispiel #5
0
void ImageSource::initialize() throw (tgt::Exception) {
    RenderProcessor::initialize();

#ifdef VRN_MODULE_DEVIL
    std::string filterStr = "Image files (*." + strJoin(DevILModule::getSupportedReadExtensions(), " *.") + ")";
    imageFile_.setFileFilter(filterStr);
#endif

    shader_ = ShdrMgr.loadSeparate("passthrough.vert", "copyimage.frag",
        generateHeader() + "#define NO_DEPTH_TEX\n", false);

    loadImage(imageFile_.get());
}
Beispiel #6
0
void CanvasRenderer::initialize() throw (tgt::Exception) {
    RenderProcessor::initialize();

#ifdef VRN_MODULE_DEVIL
    std::string imageExtensions = "*." + strJoin(DevILModule::getSupportedWriteExtensions(), ";; *.");
    screenshotFilename_.setFileFilter(imageExtensions);
#endif

    if (getProcessorWidget())
        getProcessorWidget()->updateFromProcessor();

    shader_ = ShdrMgr.loadSeparate("passthrough.vert", "copyimage.frag", generateHeader(), false);

    errorTex_ = TexMgr.load(VoreenApplication::app()->getResourcePath("textures/error.tga"));
    canvasSize_.setMaxValue(tgt::ivec2(GpuCaps.getMaxTextureSize()));
}
Beispiel #7
0
void VolumeSerializer::write(const std::string& url, const VolumeBase* volumeHandle) const throw (tgt::FileException)
{
    std::vector<VolumeWriter*> matchingWriters = getWriters(url);
    tgtAssert(!matchingWriters.empty(), "writers vector empty (exception expected)");
    if (matchingWriters.size() == 1) {
        return matchingWriters.front()->write(url, volumeHandle);
    }
    else {
        // iterate over all possibly matching writers try to load data set, collect error messages
        std::vector<std::string> errors;
        for (size_t i=0; i<matchingWriters.size(); i++) {
            try {
                return matchingWriters.at(i)->write(url, volumeHandle);
            }
            catch (const tgt::FileException& e) {
                errors.push_back(e.what());
            }
        }
        std::string errorMsg = "No VolumeWriter was able to write the data set: " + strJoin(errors, "; ");
        throw tgt::FileException(errorMsg);
    }
}
Beispiel #8
0
/**
 * 检查并创建一个目录或一个文件的父目录
 * @param pszPath(const char *): 要检查的路径
 * @see 
 * @return 0(成功)
 * @return -1(失败)
 */
int checkCreateDir(const char *pszPath)
{
    struct stat statbuf;

    char szFileCopy[MAX_FILENAME_LEN];
    char szDir[MAX_FILENAME_LEN];
    int iDirLen = MAX_FILENAME_LEN;
    char *apszField[MAX_STR_FIELD_NUM];
    int iFieldNum = 0;
    char *pcFieldBegin = NULL;
    char *pcFieldEnd = NULL;
    int iLastIsFile = 0;
    int iLen = 0;
    int i = 0;

    if (pszPath == NULL)
    {
        return -1;
    }

    iLen = strlen(pszPath);
    if ((iLen < 1) || (iLen >= MAX_FILENAME_LEN))
    {
        return -1;
    }

    /*
     * 最后不以斜杠结尾,是文件
     */
    if (pszPath[iLen - 1] != '/')
    {
        iLastIsFile = 1;
    }

    strncpy(szFileCopy, pszPath, MAX_FILENAME_LEN);
    szFileCopy[MAX_FILENAME_LEN - 1] = '\0';

    /*
     * 解析成文件夹名数组
     */
    pcFieldEnd = szFileCopy;
    iFieldNum = 0;
    // 如果是绝对路径
    if (pcFieldEnd[0] == '/')
    {
        // 去除所有的多余的斜杠
        for (; *pcFieldEnd; ++pcFieldEnd)
        {
            if ('/' == *pcFieldEnd)
            {
                *pcFieldEnd = '\0';
                continue;
            }
            break;
        }
        pcFieldBegin = pcFieldEnd;
        pcFieldEnd = strchr(pcFieldBegin, '/');
        // 没有文件夹部分,则返回错误
        if (NULL == pcFieldEnd)
        {
            return -1;
        }
        --pcFieldBegin;
        *pcFieldBegin = '/';
        *pcFieldEnd = '\0';
        ++pcFieldEnd;
        apszField[0] = pcFieldBegin;
        iFieldNum = 1;
        
    }

    for (; iFieldNum <= MAX_STR_FIELD_NUM; ++iFieldNum)
    {
        if (pcFieldEnd)
        {
            // 去除所有的多余的斜杠
            for (; *pcFieldEnd; ++pcFieldEnd)
            {
                if ('/' == *pcFieldEnd)
                {
                    *pcFieldEnd = '\0';
                    continue;
                }
                break;
            }
            // 没有下一个有效的文件名,则跳出
            if ('\0' == *pcFieldEnd)
            {
                break;
            }
        }
        else
        {
            // 不存在下一个文件名,则跳出
            break;
        }
        pcFieldBegin = pcFieldEnd;
        apszField[iFieldNum] = pcFieldBegin;
        pcFieldEnd = strchr(pcFieldBegin, '/');
    }

    // 结束符设置,如果当前字段太多,则退出
    if (iFieldNum > MAX_STR_FIELD_NUM)
    {
        return -1;
    }

    if (iLastIsFile)
    {
        --iFieldNum;
        apszField[iFieldNum] = NULL;
    }
    for (i = 0; i < iFieldNum; i++)
    {
        /*
         * 如果存在点开头的文件夹,则退出
         */
        if (apszField[i][0] == '.')
        {
            return -2;
        }

        /*
         * 保证每一层目录都存在
         */
        if (strJoin(szDir, iDirLen, apszField, i + 1, "/") < 0)
        {
            return -1;
        }

        if (stat(szDir, &statbuf) == -1)
        {
            // 错误不是文件夹不存在或者创建失败则返回错误
            if ((errno != ENOENT) || (mkdir(szDir, 0755) == -1))
            {
                return -1;
            }
        }
        else if (!S_ISDIR(statbuf.st_mode))
        {
            return -1;
        }
    }

    return 0;
}
void VoreenApplication::initialize() {
    if (initialized_) {
        if (tgt::LogManager::isInited())
            LWARNING("init() Application already initialized. Skip.");
        return;
    }

    //
    // Command line parser
    //
    prepareCommandParser();
    cmdParser_.execute();

    //
    // tgt initialization
    //
    tgt::InitFeature::Features featureset;
    if (appFeatures_ & APP_CONSOLE_LOGGING)
        featureset = tgt::InitFeature::ALL;
    else
        featureset = tgt::InitFeature::Features(tgt::InitFeature::ALL &~ tgt::InitFeature::LOG_TO_CONSOLE);
    tgt::init(featureset, logLevel_);

    // detect documents path first, needed for log file
#ifdef WIN32
    TCHAR szPath[MAX_PATH];
    // get "my documents" directory
    if (SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, szPath) == S_OK)
        documentsPath_ = szPath;
#else
    if (getenv("HOME") != 0)
        documentsPath_ = getenv("HOME");
#endif

    // HTML logging
    if (appFeatures_ & APP_HTML_LOGGING) {

#ifdef VRN_DEPLOYMENT
        LogMgr.reinit(documentsPath_);
#endif

        if (logFile_.empty())
            logFile_ = name_ + "-log.html";

        // add a file logger
        tgt::Log* log = new tgt::HtmlLog(logFile_);
        log->addCat("", true, logLevel_);
        LogMgr.addLog(log);
    }

    // log version
    VoreenVersion::logAll("voreen.VoreenApplication");

#ifdef VRN_DEPLOYMENT
    LINFO("Deployment build.");
#endif

    //
    // Path detection
    //

    // detect base path based on program location
    string prog = cmdParser_.getProgramPath();

    basePath_ = ".";
    // cut path from program location
    string::size_type p = prog.find_last_of("/\\");
    if (p != string::npos) {
        basePath_ = prog.substr(0, p);
        prog = prog.substr(p + 1);
    }

    // try to find base path starting at program path
    basePath_ = tgt::FileSystem::absolutePath(findBasePath(basePath_));
    LINFO("Base path: " << basePath_);

    // mac app resources path
#ifdef __APPLE__
    appBundleResourcesPath_ = findAppBundleResourcesPath();
    if (appBundleResourcesPath_.empty())
        LERROR("Application bundle's resources path could not be detected!");
    else
        LINFO("Application bundle's resources path: " << appBundleResourcesPath_);
#endif

    // shader path
    if (appFeatures_ & APP_SHADER) {
#if defined(__APPLE__) && defined(VRN_DEPLOYMENT)
        shaderPath_ = appBundleResourcesPath_ + "/glsl";
#else
        shaderPath_ = findShaderPath(basePath_);
#endif
    }

    // data path
    if (appFeatures_ & APP_DATA) {
        dataPath_ = findDataPath(basePath_);
        cachePath_ = dataPath_ + "/cache";
        temporaryPath_ = dataPath_ + "/tmp";
        volumePath_ = findVolumePath(basePath_);
#if defined(__APPLE__) && defined(VRN_DEPLOYMENT)
        fontPath_ = appBundleResourcesPath_ + "/fonts";
        texturePath_ = appBundleResourcesPath_ + "/textures";
        documentationPath_ = appBundleResourcesPath_ + "/doc";
#else
        fontPath_ = dataPath_ + "/fonts";
        texturePath_ = dataPath_ + "/textures";
        documentationPath_ = findDocumentationPath(basePath_);
#endif
    }

    // log location of HTML log to console
    if ((appFeatures_ & APP_HTML_LOGGING) && !logFile_.empty()) {
        std::string logPath = tgt::FileSystem::absolutePath(logFile_);
        LINFO("HTML log file: " << logPath);
    }

    // core pseudo module is always included
    addModule(new CoreModule());

    //
    // Modules
    //
    if (appFeatures_ & APP_AUTOLOAD_MODULES) {
        LDEBUG("Loading modules from module registration header");
        addAllModules(this);
        if (modules_.empty()) {
            LWARNING("No modules loaded");
        }
        else {
            std::vector<std::string> moduleNames;
            for (size_t i=0; i<modules_.size(); i++)
                moduleNames.push_back(modules_[i]->getName());
            LINFO("Modules: " << strJoin(moduleNames, ", "));
        }
    }
    else {
        LDEBUG("Module auto loading disabled");
    }

    // init timer
    schedulingTimer_ = createTimer(&eventHandler_);
    eventHandler_.addListenerToFront(this);

    initialized_ = true;
}