void FileSystem::checkSelectedFileIsSupported(const QString &selectedFile) const { QString str; str = "*." + fileSuffix(selectedFile); bool support = Config::supportedReadFormats().contains(str, Qt::CaseInsensitive); if (!support) throw std::runtime_error(QObject::tr("The file format is not supported.").toStdString()); }
void ImageSampler::setupImageSampler(MooseMesh & mesh) { #ifdef LIBMESH_HAVE_VTK // Get access to the Mesh object MeshTools::BoundingBox bbox = MeshTools::bounding_box(mesh.getMesh()); // Set the dimensions from the Mesh if not set by the User if (_is_pars.isParamValid("dimensions")) _physical_dims = _is_pars.get<Point>("dimensions"); else { _physical_dims(0) = bbox.max()(0) - bbox.min()(0); #if LIBMESH_DIM > 1 _physical_dims(1) = bbox.max()(1) - bbox.min()(1); #endif #if LIBMESH_DIM > 2 _physical_dims(2) = bbox.max()(2) - bbox.min()(2); #endif } // Set the origin from the Mesh if not set in the input file if (_is_pars.isParamValid("origin")) _origin = _is_pars.get<Point>("origin"); else { _origin(0) = bbox.min()(0); #if LIBMESH_DIM > 1 _origin(1) = bbox.min()(1); #endif #if LIBMESH_DIM > 2 _origin(2) = bbox.min()(2); #endif } // An array of filenames, to be filled in std::vector<std::string> filenames; // The file suffix, to be determined std::string file_suffix; // Try to parse our own file range parameters. If that fails, then // see if the associated Mesh is an ImageMesh and use its. If that // also fails, then we have to throw an error... // // The parseFileRange method sets parameters, thus a writable reference to the InputParameters // object must be obtained from the warehouse. Generally, this should be avoided, but // this is a special case. if (_status != 0) { // We don't have parameters, so see if we can get them from ImageMesh ImageMesh * image_mesh = dynamic_cast<ImageMesh*>(&mesh); if (!image_mesh) mooseError("No file range parameters were provided and the Mesh is not an ImageMesh."); // Get the ImageMesh's parameters. This should work, otherwise // errors would already have been thrown... filenames = image_mesh->filenames(); file_suffix = image_mesh->fileSuffix(); } else { // Use our own parameters (using 'this' b/c of conflicts with filenames the local variable) filenames = this->filenames(); file_suffix = fileSuffix(); } // Storage for the file names _files = vtkSmartPointer<vtkStringArray>::New(); for (unsigned i=0; i<filenames.size(); ++i) _files->InsertNextValue(filenames[i]); // Error if no files where located if (_files->GetNumberOfValues() == 0) mooseError("No image file(s) located"); // Read the image stack. Hurray for VTK not using polymorphism in a // smart way... we actually have to explicitly create the type of // reader based on the file extension, using an if-statement... if (file_suffix == "png") _image = vtkSmartPointer<vtkPNGReader>::New(); else if (file_suffix == "tiff" || file_suffix == "tif") _image = vtkSmartPointer<vtkTIFFReader>::New(); else mooseError("Un-supported file type '" << file_suffix << "'"); // Now that _image is set up, actually read the images // Indicate that data read has started _is_console << "Reading image(s)..." << std::endl; // Extract the data _image->SetFileNames(_files); _image->Update(); _data = _image->GetOutput(); _algorithm = _image->GetOutputPort(); // Set the image dimensions and voxel size member variable int * dims = _data->GetDimensions(); for (unsigned int i = 0; i < 3; ++i) { _dims.push_back(dims[i]); _voxel.push_back(_physical_dims(i)/_dims[i]); } // Set the dimensions of the image and bounding box _data->SetSpacing(_voxel[0], _voxel[1], _voxel[2]); _data->SetOrigin(_origin(0), _origin(1), _origin(2)); _bounding_box.min() = _origin; _bounding_box.max() = _origin + _physical_dims; // Indicate data read is completed _is_console << " ...image read finished" << std::endl; // Set the component parameter // If the parameter is not set then vtkMagnitude() will applied if (_is_pars.isParamValid("component")) { unsigned int n = _data->GetNumberOfScalarComponents(); _component = _is_pars.get<unsigned int>("component"); if (_component >= n) mooseError("'component' parameter must be empty or have a value of 0 to " << n-1); } else _component = 0; // Apply filters, the toggling on and off of each filter is handled internally vtkMagnitude(); vtkShiftAndScale(); vtkThreshold(); vtkFlip(); #endif }
bool FileSystem::fileMayBeSave(const QString &file) { return Config::supportedSaveFormats().contains("*." + fileSuffix(file), Qt::CaseInsensitive); }
int main(int argc, char * argv[]){ ArgumentContainer args("parse", false); PositionalArgument<string> filePrefix(&args, "file_prefix", "file prefix", ""); PositionalArgument<string> fileSuffix(&args, "file_suffix", "file suffix", ""); if (args.parse(argc, argv)){ args.usage(cerr); return -1; } unsigned rateSpace[] = {10, 20, 30, 40, 50, 60, 70, 80, 90}; unsigned rateSpaceReversed[] = {90, 80, 70, 60, 50, 40, 30, 20, 10}; unsigned rateSpaceSize = 9; CounterTraceReader baseline(filePrefix.getValue() + fileSuffix.getValue()); map<unsigned, map<unsigned, CounterTraceReader*> > readers; for(unsigned i = 0; i < rateSpaceSize; i++){ for(unsigned j = 0; j < rateSpaceSize; j++){ ostringstream fileName; //multi_2_hybrid_ft_pause_space_10_90_rate_10_90 fileName << filePrefix.getValue() << "_space_" << rateSpace[i] << "_" << rateSpaceReversed[i] << "_rate_" << rateSpace[j] << "_" << rateSpaceReversed[j] << fileSuffix.getValue(); readers[i][j] = new CounterTraceReader(fileName.str()); } } vector<uint64> keyList; baseline.getKeyList(&keyList); uint64 sum = 0; uint64 sumBaseline = 0; map<unsigned, map<unsigned, uint64> >sums; for(unsigned k = 0; k < keyList.size(); k++){ uint64 min = numeric_limits<uint64>::max(); unsigned minRate = numeric_limits<unsigned>::max(), minSpace = numeric_limits<unsigned>::max(); for(unsigned i = 0; i < rateSpaceSize; i++){ for(unsigned j = 0; j < rateSpaceSize; j++){ uint64 v = readers[i][j]->getValue(keyList[k], "cycles"); if (v < min){ min = v; minSpace = i; minRate = j; } sums[i][j] += readers[i][j]->getValue(keyList[k], "cycles"); } } cout << "rate: " << rateSpace[minRate] << " space: " << rateSpace[minSpace] << endl; sum += min; sumBaseline += baseline.getValue(keyList[k], "cycles"); } uint64 min = numeric_limits<uint64>::max(); for(unsigned i = 0; i < rateSpaceSize; i++){ for(unsigned j = 0; j < rateSpaceSize; j++){ uint64 v = sums[i][j]; if (v < min){ min = v; } } } cout << sumBaseline << "\t" << min << "\t" << sum << endl; return 0; }
QString QucsDoc::fileSuffix (void) { return fileSuffix (DocName); }