void VolumeIOHelper::loadOrigin(const VolumeURL& origin, VolumeReader* reader) { tgtAssert(reader, "null pointer passed"); try { VolumeBase* handle = reader->read(origin); if (handle) { handle->getOrigin().addSearchParameter("preferredReader", reader->getClassName()); emit(volumeLoaded(handle)); } else { LERROR("Reader '" << reader->getClassName() << "' returned null pointer as volume (exception expected)"); } } catch (const tgt::FileException& e) { LERROR(e.what()); QErrorMessage* errorMessageDialog = new QErrorMessage(VoreenApplicationQt::qtApp()->getMainWindow()); errorMessageDialog->showMessage(e.what()); } catch (std::bad_alloc&) { LERROR("bad allocation while reading file: " << origin.getURL()); QErrorMessage* errorMessageDialog = new QErrorMessage(VoreenApplicationQt::qtApp()->getMainWindow()); errorMessageDialog->showMessage("Bad allocation while reading file: " + QString::fromStdString(origin.getURL())); } catch (std::exception& e) { LERROR("unknown exception while reading file '" << origin.getURL() << "':" << e.what()); QErrorMessage* errorMessageDialog = new QErrorMessage(VoreenApplicationQt::qtApp()->getMainWindow()); errorMessageDialog->showMessage("Unknown exception while reading file '" + QString::fromStdString(origin.getURL()) + "': " + e.what()); } }
VolumeBase* MultiVolumeReader::read(const VolumeURL& origin) throw (tgt::FileException, std::bad_alloc) { std::string path = extractPurePathFromFileName(origin.getPath()); std::string refFile = origin.getSearchParameter("file"); if (refFile == "") throw tgt::FileException("'file' parameter missing in URL", origin.getURL()); VolumeURL refOrigin(path + refFile); LINFO("Loading file " + refOrigin.getPath()); VolumeBase* handle = 0; if (populator_) handle = populator_->getVolumeSerializer()->read(refOrigin); else { VolumeSerializerPopulator populator; handle = populator.getVolumeSerializer()->read(refOrigin); } if (handle) handle->setOrigin(origin); return handle; }
void VolumeURLListProperty::loadVolume(const std::string& url, bool invalidateUI /*=true*/) throw (tgt::FileException, std::bad_alloc) { if (!containsURL(url)) { LWARNING("loadVolume(): passed URL not contained by this property: " << url); return; } // delete volume, if already loaded and owned by the property if (getVolume(url) && isOwner(url)) delete getVolume(url); handleMap_.erase(url); ownerMap_.erase(url); ProgressBar* progressBar = getProgressBar(); if (progressBar) { progressBar->setTitle("Loading volume"); progressBar->setProgressMessage("Loading volume ..."); } VolumeSerializerPopulator serializerPopulator(progressBar); VolumeBase* handle = serializerPopulator.getVolumeSerializer()->read(VolumeURL(url)); if (progressBar) progressBar->hide(); if (handle) { // url may have been altered by loading routine if (url != handle->getOrigin().getURL()) { bool selected = isSelected(url); selectionMap_.erase(url); selectionMap_[handle->getOrigin().getURL()] = selected; for (size_t i=0; i<value_.size(); i++) { if (value_[i] == url) { value_[i] = handle->getOrigin().getURL(); break; } } } handleMap_[handle->getOrigin().getURL()] = handle; ownerMap_[handle->getOrigin().getURL()] = true; } if(invalidateUI) invalidate(); }