15 #include "libmesh/mesh_tools.h" 24 params.
addParam<Point>(
"origin",
"Origin of the image (defaults to mesh origin)");
26 "x,y,z dimensions of the image (defaults to mesh dimensions)");
29 "The image RGB-component to return, leaving this blank will result in a greyscale value " 30 "for the image to be created. The component number is zero based, i.e. 0 returns the first " 31 "(RED) component of the image.");
34 params.
addParam<
double>(
"shift", 0,
"Value to add to all pixels; occurs prior to scaling");
36 "scale", 1,
"Multiplier to apply to all pixel values; occurs after shifting");
40 params.
addParam<
double>(
"threshold",
"The threshold value");
42 "upper_value", 1,
"The value to set for data greater than the threshold value");
44 "lower_value", 0,
"The value to set for data less than the threshold value");
48 params.
addParam<
bool>(
"flip_x",
false,
"Flip the image along the x-axis");
49 params.
addParam<
bool>(
"flip_y",
false,
"Flip the image along the y-axis");
50 params.
addParam<
bool>(
"flip_z",
false,
"Flip the image along the z-axis");
58 #ifdef LIBMESH_HAVE_VTK
63 _is_console((parameters.getCheckedPointerParam<
MooseApp *>(
"_moose_app"))->getOutputWarehouse())
66 #ifndef LIBMESH_HAVE_VTK 69 mooseError(
"libMesh must be configured with VTK enabled to utilize MeshBaseImageSampler");
80 #ifdef LIBMESH_HAVE_VTK 82 BoundingBox bbox = MeshTools::create_bounding_box(
mesh);
117 std::string file_suffix;
148 _files = vtkSmartPointer<vtkStringArray>::New();
151 _files->InsertNextValue(filename);
154 if (
_files->GetNumberOfValues() == 0)
160 if (file_suffix ==
"png")
161 _image = vtkSmartPointer<vtkPNGReader>::New();
162 else if (file_suffix ==
"tiff" || file_suffix ==
"tif")
163 _image = vtkSmartPointer<vtkTIFFReader>::New();
165 mooseError(
"Un-supported file type '", file_suffix,
"'");
178 int * dims =
_data->GetDimensions();
179 for (
unsigned int i = 0; i < 3; ++i)
181 _dims.push_back(dims[i]);
192 _is_console <<
" ...image read finished" << std::endl;
198 unsigned int n =
_data->GetNumberOfScalarComponents();
201 mooseError(
"'component' parameter must be empty or have a value of 0 to ", n - 1);
217 #ifdef LIBMESH_HAVE_VTK 224 std::vector<int> x(3, 0);
225 for (
int i = 0; i < LIBMESH_DIM; ++i)
236 if (x[i] ==
_dims[i])
242 return _data->GetScalarComponentAsDouble(x[0], x[1], x[2],
_component);
253 #ifdef LIBMESH_HAVE_VTK 272 #ifdef LIBMESH_HAVE_VTK 278 if (shift == 0 &&
scale == 1)
299 #ifdef LIBMESH_HAVE_VTK 306 mooseError(
"When thresholding is applied, both the upper_value and lower_value parameters must " 335 #ifdef LIBMESH_HAVE_VTK 354 #ifdef LIBMESH_HAVE_VTK 355 vtkSmartPointer<vtkImageFlip>
358 vtkSmartPointer<vtkImageFlip> flip_image = vtkSmartPointer<vtkImageFlip>::New();
360 flip_image->SetFilteredAxis(axis);
366 flip_image->Update();
vtkSmartPointer< vtkImageMagnitude > _magnitude_filter
Pointer to the magnitude filter.
void vtkMagnitude()
Convert the image to greyscale.
Point _physical_dims
Physical dimensions of image.
std::vector< int > _dims
Pixel dimension of image.
Point _origin
Origin of image.
vtkSmartPointer< vtkImageFlip > imageFlip(const int &axis)
Helper method for flipping image.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
vtkAlgorithmOutput * _algorithm
VTK-6 seems to work better in terms of "algorithm outputs" rather than vtkImageData pointers...
const InputParameters & _is_pars
Parameters for interface.
const std::vector< std::string > & filenames()
Base class for MOOSE-based applications.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
static InputParameters validParams()
BoundingBox _bounding_box
Bounding box for testing points.
static InputParameters validParams()
Constructor.
void libmesh_ignore(const Args &...)
virtual void setupImageSampler(MeshBase &mesh)
Perform initialization of image data.
MeshBaseImageSampler(const InputParameters ¶meters)
vtkSmartPointer< vtkImageFlip > _flip_filter
Pointers to image flipping filter. May be used for x, y, or z.
unsigned int _component
Component to extract.
vtkSmartPointer< vtkStringArray > _files
List of file names to extract data.
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
vtkImageData * _data
Complete image data.
vtkSmartPointer< vtkImageShiftScale > _shift_scale_filter
Pointer to the shift and scaling filter.
vtkSmartPointer< vtkImageThreshold > _image_threshold
Pointer to thresholding filter.
std::vector< double > _voxel
Physical pixel size.
void vtkFlip()
Perform image flipping.
void vtkThreshold()
Perform thresholding.
vtkSmartPointer< vtkImageReader2 > _image
Complete image data.
ConsoleStream _is_console
Create a console stream object for this helper class.
void vtkShiftAndScale()
Apply image re-scaling using the vtkImageShiftAndRescale object.
virtual Real sample(const Point &p)
Return the pixel value for the given point.