14 #include "libmesh/cell_hex8.h" 15 #include "libmesh/face_quad4.h" 20 #include "libmesh/mesh_generation.h" 21 #include "libmesh/unstructured_mesh.h" 34 "scale_to_one",
true,
"Whether or not to scale the image so its max dimension is 1");
37 "cells_per_pixel<=1.0",
38 "The number of mesh cells per pixel, must be <=1 ");
46 _scale_to_one(getParam<bool>(
"scale_to_one")),
47 _cells_per_pixel(getParam<
Real>(
"cells_per_pixel"))
56 _scale_to_one(getParam<bool>(
"scale_to_one")),
57 _cells_per_pixel(getParam<
Real>(
"cells_per_pixel"))
61 std::unique_ptr<MooseMesh>
84 mooseError(
"ImageMesh error: Cannot create a 3D ImageMesh from an image stack with ",
91 int xpixels = 0, ypixels = 0, zpixels =
filenames.size();
135 MeshTools::Generation::build_cube(dynamic_cast<UnstructuredMesh &>(
getMesh()),
151 int xpixels = 0, ypixels = 0;
175 MeshTools::Generation::build_square(dynamic_cast<UnstructuredMesh &>(
getMesh()),
189 std::string error_message =
"";
192 char temp_file[] =
"file_command_output.XXXXXX";
205 error_message =
"Error creating temporary file in ImageMesh::buildMesh()";
210 std::ostringstream command;
211 command <<
"file " << filename <<
" 2>/dev/null 1>" << temp_file;
214 int exit_status = std::system(command.str().c_str());
217 if (exit_status != 0)
219 error_message =
"Error calling 'file' command in ImageMesh::buildMesh()";
224 std::ifstream fin(temp_file);
227 std::string command_result;
228 std::getline(fin, command_result);
237 xpixels = 0, ypixels = 0;
238 pcrecpp::RE re(
"(\\d+) x (\\d+)");
239 re.PartialMatch(command_result, &xpixels, &ypixels);
242 if ((xpixels == 0) || (ypixels == 0))
244 error_message =
"Regex failed to find a match in " + command_result;
250 std::remove(temp_file);
253 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()
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
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.
MooseApp & _app
The MOOSE application this is associated with.
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()