15#include "libmesh/unstructured_mesh.h"
16#include "libmesh/replicated_mesh.h"
17#include "libmesh/mesh_generation.h"
18#include "libmesh/face_quad4.h"
19#include "libmesh/cell_hex8.h"
35 "scale_to_one",
true,
"Whether or not to scale the image so its max dimension is 1");
38 "cells_per_pixel<=1.0",
39 "The number of mesh cells per pixel, must be <=1 ");
47 _scale_to_one(getParam<bool>(
"scale_to_one")),
48 _cells_per_pixel(getParam<Real>(
"cells_per_pixel"))
53std::unique_ptr<MeshBase>
65 return dynamic_pointer_cast<MeshBase>(
mesh);
74 mooseError(
"ImageMesh error: Cannot create a 3D ImageMesh from an image stack with ",
81 int xpixels = 0, ypixels = 0, zpixels =
filenames.size();
125 MeshTools::Generation::build_cube(
dynamic_cast<UnstructuredMesh &
>(
mesh),
141 int xpixels = 0, ypixels = 0;
165 MeshTools::Generation::build_square(
dynamic_cast<UnstructuredMesh &
>(
mesh),
179 std::string error_message =
"";
182 char temp_file[] =
"file_command_output.XXXXXX";
195 error_message =
"Error creating temporary file in ImageMesh::buildMesh()";
200 std::ostringstream command;
201 command <<
"file " << filename <<
" 2>/dev/null 1>" << temp_file;
204 int exit_status = std::system(command.str().c_str());
207 if (exit_status != 0)
209 error_message =
"Error calling 'file' command in ImageMesh::buildMesh()";
214 std::ifstream fin(temp_file);
217 std::string command_result;
218 std::getline(fin, command_result);
227 xpixels = 0, ypixels = 0;
228 pcrecpp::RE re(
"(\\d+) x (\\d+)");
229 re.PartialMatch(command_result, &xpixels, &ypixels);
232 if ((xpixels == 0) || (ypixels == 0))
234 error_message =
"Regex failed to find a match in " + command_result;
240 std::remove(temp_file);
243 if (error_message !=
"")
registerMooseObject("MooseApp", ImageMeshGenerator)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
To be called in the validParams functions of classes that need to operate on ranges of files.
const std::vector< std::string > & filenames()
static InputParameters validParams()
std::vector< std::string > _filenames
Generates a line, square, or cube mesh with uniformly spaced or biased elements.
static InputParameters validParams()
unsigned int & _nx
Number of elements in x, y, z direction.
A 2D GeneratedMesh where xmin, xmax, etc.
void buildMesh2D(const std::string &filename, MeshBase &mesh)
generate() calls this helper function to build 2D ImageMeshes.
void GetPixelInfo(std::string filename, int &xpixels, int &ypixels)
Process a single image with the 'file' command to find out the number of pixels in the x and y direct...
ImageMeshGenerator(const InputParameters ¶meters)
void buildMesh3D(const std::vector< std::string > &filenames, MeshBase &mesh)
generate() calls this helper function to build 3D ImageMeshes from stacks of images.
const bool _scale_to_one
If true, forces the maximum width (height) of the mesh to be 1.0 while retaining the original aspect ...
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const Real & _cells_per_pixel
A number <= 1.0 which determines the number of cells in the mesh per pixel in each direction.
static InputParameters validParams()
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh(unsigned int dim=libMesh::invalid_uint)
Build a replicated mesh.
T & declareMeshProperty(const std::string &data_name, Args &&... args)
Methods for writing out attributes to the mesh meta-data store, which can be retrieved from most othe...