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"))
53 std::unique_ptr<MeshBase>
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 !=
"")
static InputParameters validParams()
const bool _scale_to_one
If true, forces the maximum width (height) of the mesh to be 1.0 while retaining the original aspect ...
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...
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh(unsigned int dim=libMesh::invalid_uint)
Build a replicated mesh.
const std::vector< std::string > & filenames()
Generates a line, square, or cube mesh with uniformly spaced or biased elements.
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
void buildMesh3D(const std::vector< std::string > &filenames, MeshBase &mesh)
generate() calls this helper function to build 3D ImageMeshes from stacks of images.
static InputParameters validParams()
auto max(const L &left, const R &right)
static InputParameters validParams()
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
ImageMeshGenerator(const InputParameters ¶meters)
unsigned int & _nx
Number of elements in x, y, z direction.
void buildMesh2D(const std::string &filename, MeshBase &mesh)
generate() calls this helper function to build 2D ImageMeshes.
To be called in the validParams functions of classes that need to operate on ranges of files...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real & _cells_per_pixel
A number <= 1.0 which determines the number of cells in the mesh per pixel in each direction...
registerMooseObject("MooseApp", ImageMeshGenerator)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
A 2D GeneratedMesh where xmin, xmax, etc.
std::vector< std::string > _filenames