VolumeBase* ECAT7VolumeReader::read(const VolumeURL& origin) throw (tgt::FileException, std::bad_alloc) { VolumeBase* result = 0; int volumeId = -1; std::string tmp = origin.getSearchParameter("volumeId"); if (! tmp.empty()) volumeId = stoi(tmp); VolumeList* collection = read(origin.getPath(), volumeId); if (collection && collection->size() == 1) { result = collection->first(); } else if (collection && collection->size() > 1) { while(!collection->empty()) { VolumeBase* vh = collection->first(); collection->remove(vh); delete vh; } delete collection; throw tgt::FileException("Only one volume expected", origin.getPath()); } delete collection; return result; }
void FFT::backward(VolumeList &volumes) { if (volumes.size() > 0 && volumes[0].domain != Domain::Time) { fftw_plan plan; try { plan = backward_plans.at(volumes.data); } catch (...) { int rank = 3; int n[] = { static_cast<int>(volumes[0].width), static_cast<int>(volumes[0].height), static_cast<int>(volumes[0].depth) }; int howmany = volumes.size(); int idist = volumes.volume_size_complex; int odist = volumes.volume_size_real; int istride = 1, ostride = 1; int *inembed = 0, *onembed = 0; plan = fftw_plan_many_dft_c2r(rank, n, howmany, reinterpret_cast<fftw_complex *>(volumes.data), inembed, istride, idist, volumes.data, onembed, ostride, odist, FFTW_ESTIMATE); backward_plans[volumes.data] = plan; } fftw_execute(plan); for (size_t i = 0; i < volumes.size(); ++i) { volumes[i] *= 1.0 / volumes[i].size; volumes[i].domain = Domain::Time; } } }
VolumeBase* VolumeReader::read(const VolumeURL& origin) throw (tgt::FileException, std::bad_alloc) { VolumeBase* result = 0; VolumeList* collection = read(origin.getPath()); if (collection && collection->size() == 1) { result = collection->first(); } else if (collection && collection->size() > 1) { delete collection; throw tgt::FileException("Only one volume expected", origin.getPath()); } delete collection; return result; }
void VolumeURLProperty::loadVolume() throw (tgt::FileException, std::bad_alloc){ std::string url = get(); if (url.empty()) { LWARNING("loadVolume(): empty URL"); return; } ProgressBar* progressBar = getProgressBar(); if (progressBar) { progressBar->setTitle("Loading volume"); progressBar->setProgressMessage("Loading volume ..."); } VolumeSerializerPopulator serializerPopulator(progressBar); VolumeList* volumeList = serializerPopulator.getVolumeSerializer()->read(url); if (progressBar) progressBar->hide(); if (volumeList && !volumeList->empty()) { VolumeBase* handle = volumeList->first(); tgtAssert(handle, "No handle"); setVolume(static_cast<Volume*>(handle)); // delete superfluous volumes if (volumeList->size() > 1) { LWARNING("More than one volume loaded from file: " + url + ". Discarding surplus volumes!"); for (size_t i=1; i<volumeList->size(); i++) delete volumeList->at(i); } // property does take ownership of loaded handles volumeOwner_ = true; } delete volumeList; }
VolumeBase* AmiraMeshReader::read(const VolumeURL& origin) throw (tgt::FileException, std::bad_alloc) { VolumeBase* result = 0; int timeframe = -1; std::string tmp = origin.getSearchParameter("timeframe"); if (! tmp.empty()) timeframe = stoi(tmp); VolumeList* collection = read(origin.getPath(), timeframe); if (collection && collection->size() == 1) { result = collection->first(); } else if (collection && collection->size() > 1) { delete collection; throw tgt::FileException("Only one volume expected", origin.getPath()); } delete collection; return result; }
void FFT::convolve(VolumeList &vols, Volume &mask) { if (vols.size() > 0 && vols[0].width == mask.width && vols[0].height == mask.height && vols[0].depth == mask.depth) { forward(vols); forward(mask); vols *= mask; size_t i = 0; for (size_t x = 0; x < vols[0].width; ++x) { for (size_t y = 0; y < vols[0].height; ++y) { for (size_t z = 0; z < vols[0].complex_depth; ++z) { if ((x+y+z) % 2) { for (size_t j = 0; j < vols.size(); ++j) { vols[j].complex_data[i] *= -1.0; } } ++i; } } } backward(vols); } }
void VolumeIOHelper::loadRawVolume(const std::string& filenameStd) { QString filename = QString::fromStdString(filenameStd); if (filename.isEmpty()) return; // query raw parameters via dialog std::string objectModel; std::string format; int numFrames; tgt::ivec3 dim; tgt::vec3 spacing; int headerSkip; bool bigEndian; tgt::mat4 trafoMat = tgt::mat4::identity; RawVolumeWidget* rawVW = new RawVolumeWidget(parent_, tr("Please enter the properties for <br><strong>") + filename + "</strong>", objectModel, format, numFrames, dim, spacing, headerSkip, bigEndian, trafoMat); if (!rawVW->exec() == QDialog::Accepted) return; // derive expected file size from provided properties uint formatBytes = 1;; if (format == "USHORT" || format == "USHORT_12" || format == "SHORT") formatBytes = 2; else if (format == "FLOAT") formatBytes = 4; else if (format == "UINT" || format == "INT") formatBytes = 4; int numChannels = 1; if (objectModel == "RGB") numChannels = 3; else if (objectModel == "RGBA") numChannels = 4; else if (objectModel.find("TENSOR_") == 0) numChannels = 6; uint rawSize = headerSkip + formatBytes * numChannels * (dim.x * dim.y * dim.z) * numFrames; // inform/query user, if file size does not match if (QFile(filename).size() != rawSize) { QMessageBox::StandardButton retButton = QMessageBox::Yes; if(QFile(filename).size() > rawSize) { QString msg = tr("The provided properties result in a size smaller\nthan the actual file size. Do you want to continue?"); retButton = QMessageBox::question(parent_, tr("Size mismatch"), msg, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); } else if (QFile(filename).size() < rawSize) { QString msg = tr("The provided properties result in a size\ngreater than the actual file size."); retButton = QMessageBox::warning(parent_, tr("Size mismatch"), msg, QMessageBox::Cancel); } if (retButton != QMessageBox::Yes && retButton != QMessageBox::Ok) return; } qApp->processEvents(); // load raw volume try { for (int frame=0; frame < numFrames; ++frame) { RawVolumeReader rawReader(progressBar_); rawReader.setReadHints(dim, spacing, objectModel, format, frame, headerSkip, bigEndian); VolumeList* collection = rawReader.read(filename.toStdString()); if (collection && !collection->empty()) { tgtAssert(collection->size() == 1, "More than one raw volume returned"); Volume* volumeHandle = static_cast<Volume*>(collection->first()); oldVolumePosition(volumeHandle); volumeHandle->setPhysicalToWorldMatrix(trafoMat); volumeHandle->setTimestep(static_cast<float>(frame)); emit(volumeLoaded(volumeHandle)); } delete collection; } } 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: " << filename.toStdString()); QErrorMessage* errorMessageDialog = new QErrorMessage(VoreenApplicationQt::qtApp()->getMainWindow()); errorMessageDialog->showMessage("Bad allocation while reading file: " + filename); } }