17 #include "libmesh/mesh_generation.h" 18 #include "libmesh/unstructured_mesh.h" 31 "scale_to_one",
true,
"Whether or not to scale the image so its max dimension is 1");
34 "cells_per_pixel<=1.0",
35 "The number of mesh cells per pixel, must be <=1 ");
43 _scale_to_one(getParam<bool>(
"scale_to_one")),
44 _cells_per_pixel(getParam<
Real>(
"cells_per_pixel"))
53 _scale_to_one(getParam<bool>(
"scale_to_one")),
54 _cells_per_pixel(getParam<
Real>(
"cells_per_pixel"))
58 std::unique_ptr<MooseMesh>
61 return std::make_unique<ImageMesh>(*this);
81 mooseError(
"ImageMesh error: Cannot create a 3D ImageMesh from an image stack with ",
88 int xpixels = 0, ypixels = 0, zpixels =
filenames.size();
132 MeshTools::Generation::build_cube(dynamic_cast<UnstructuredMesh &>(
getMesh()),
148 int xpixels = 0, ypixels = 0;
172 MeshTools::Generation::build_square(dynamic_cast<UnstructuredMesh &>(
getMesh()),
186 std::string error_message =
"";
189 char temp_file[] =
"file_command_output.XXXXXX";
202 error_message =
"Error creating temporary file in ImageMesh::buildMesh()";
207 std::ostringstream command;
208 command <<
"file " << filename <<
" 2>/dev/null 1>" << temp_file;
211 int exit_status = std::system(command.str().c_str());
214 if (exit_status != 0)
216 error_message =
"Error calling 'file' command in ImageMesh::buildMesh()";
221 std::ifstream fin(temp_file);
224 std::string command_result;
225 std::getline(fin, command_result);
234 xpixels = 0, ypixels = 0;
235 pcrecpp::RE re(
"(\\d+) x (\\d+)");
236 re.PartialMatch(command_result, &xpixels, &ypixels);
239 if ((xpixels == 0) || (ypixels == 0))
241 error_message =
"Regex failed to find a match in " + command_result;
247 std::remove(temp_file);
250 if (error_message !=
"")
void buildMesh3D(const std::vector< std::string > &filenames)
buildMesh() calls this helper function to build 3D ImageMeshes from stacks of images.
ImageMesh(const InputParameters ¶meters)
virtual std::unique_ptr< MooseMesh > safeClone() const override
A safer version of the clone() method that hands back an allocated object wrapped in a smart pointer...
const std::vector< std::string > & filenames()
static InputParameters validParams()
auto max(const L &left, const R &right)
void buildMesh2D(const std::string &filename)
buildMesh() calls this helper function to build 2D ImageMeshes.
Mesh generated from parameters.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
virtual void buildMesh() override
Must be overridden by child classes.
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
registerMooseObject("MooseApp", ImageMesh)
const Real & _cells_per_pixel
A number <= 1.0 which determines the number of cells in the mesh per pixel in each direction...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
unsigned int _nx
Number of elements in x, y, z direction.
const bool _scale_to_one
If true, forces the maximum width (height) of the mesh to be 1.0 while retaining the original aspect ...
static InputParameters validParams()
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...
A 2D GeneratedMesh where xmin, xmax, etc.
std::vector< std::string > _filenames
static InputParameters validParams()