/** * Determines the absolute path (including drive letter for Windows) for the * current path. * * @return the absolute path */ const std::string Filename::getAbsolutePath(void) const { std::string path; #if defined(WIN32) char *pathBuf; DWORD bufsize = GetFullPathName(getFullFilename().c_str(), 0, NULL, NULL); if (bufsize != 0) { pathBuf = new char[bufsize + 1]; char * filenamePart; GetFullPathName(getFullFilename().c_str(), bufsize + 1, pathBuf, &filenamePart); *filenamePart = '\0'; path = pathBuf; delete[] pathBuf; } #elif defined(linux) char pathBuf[PATH_MAX]; if (getcwd(pathBuf, PATH_MAX) != NULL) { strcat(pathBuf, "/"); strcat(pathBuf, getFullFilename().c_str()); dirname(pathBuf); strcat(pathBuf, "/"); path = pathBuf; } #endif return path; } // Filename::getAbsolutePath
void MainWindow::new_database() { load_db l; QString selectedFilter; QString fname = QFileDialog::getSaveFileName(this, l.caption, homedir, l.filter, &selectedFilter, QFileDialog::DontConfirmOverwrite); // make sure that, if the 3 letter extension was left selected // in Qt's OS X file open dialog, // the filename actually ends with that extension. // Otherwise usability breaks in jarring ways. changeDB(getFullFilename(fname, selectedFilter)); }
/** * Save an MD workspace to a vts/vtu file. * @param workspace: the workspace which is to be saved. * @param filename: the name of the file to which the workspace is to be saved. * @param normalization: the visual normalization option * @param recursionDepth: the recursion depth for MDEvent Workspaces determines * @param compressorType: the compression type used by VTK * from which level data should be displayed */ void SaveMDWorkspaceToVTKImpl::saveMDWorkspace( const Mantid::API::IMDWorkspace_sptr &workspace, const std::string &filename, VisualNormalization normalization, int recursionDepth, const std::string &compressorType) { auto isHistoWorkspace = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(workspace) != nullptr; auto fullFilename = getFullFilename(filename, isHistoWorkspace); const vtkXMLWriter::CompressorType compressor = [&compressorType] { if (compressorType == "NONE") { return vtkXMLWriter::NONE; } else if (compressorType == "ZLIB") { return vtkXMLWriter::ZLIB; } else { // This should never happen. Mantid::Kernel::Logger g_log("SaveMDWorkspaceToVTK"); g_log.warning("Incorrect CompressorType: " + compressorType + ". Using CompressorType=NONE."); return vtkXMLWriter::NONE; } }(); // Define a time slice. auto time = selectTimeSliceValue(*workspace); // Get presenter and data set factory set up auto factoryChain = getDataSetFactoryChain(isHistoWorkspace, normalization, time); auto presenter = getPresenter(isHistoWorkspace, workspace, recursionDepth); // Create the vtk data NullProgressAction nullProgressA; NullProgressAction nullProgressB; auto dataSet = presenter->execute(factoryChain.get(), nullProgressA, nullProgressB); // Do an orthogonal correction dataSet = getDataSetWithOrthogonalCorrection(dataSet, presenter.get(), workspace, isHistoWorkspace); // ParaView 5.1 checks the range of the entire signal array, including blank // cells. if (isHistoWorkspace) { auto structuredGrid = vtkStructuredGrid::SafeDownCast(dataSet); vtkIdType imageSize = structuredGrid->GetNumberOfCells(); vtkNew<vtkFloatArray> signal; signal->SetNumberOfComponents(1); signal->SetNumberOfTuples(imageSize); auto oldSignal = structuredGrid->GetCellData()->GetScalars(); for (vtkIdType index = 0; index < imageSize; ++index) { if (structuredGrid->IsCellVisible(index)) { signal->SetComponent(index, 0, oldSignal->GetTuple1(index)); } else { signal->SetComponent(index, 0, std::numeric_limits<float>::quiet_NaN()); } } structuredGrid->GetCellData()->SetScalars(signal.GetPointer()); } // Write the data to the file vtkSmartPointer<vtkXMLWriter> writer = getXMLWriter(isHistoWorkspace); auto writeSuccessFlag = writeDataSetToVTKFile(writer, dataSet, fullFilename, compressor); if (!writeSuccessFlag) { throw std::runtime_error("SaveMDWorkspaceToVTK: VTK could not write " "your data set to a file."); } }