15 #include "libmesh/mesh_tools.h" 26 params.
addParam<
Point>(
"origin",
"Origin of the image (defaults to mesh origin)");
28 "x,y,z dimensions of the image (defaults to mesh dimensions)");
31 "The image RGB-component to return, leaving this blank will result in a greyscale value " 32 "for the image to be created. The component number is zero based, i.e. 0 returns the first " 33 "(RED) component of the image.");
36 params.
addParam<
double>(
"shift", 0,
"Value to add to all pixels; occurs prior to scaling");
38 "scale", 1,
"Multiplier to apply to all pixel values; occurs after shifting");
42 params.
addParam<
double>(
"threshold",
"The threshold value");
44 "upper_value", 1,
"The value to set for data greater than the threshold value");
46 "lower_value", 0,
"The value to set for data less than the threshold value");
50 params.
addParam<
bool>(
"flip_x",
false,
"Flip the image along the x-axis");
51 params.
addParam<
bool>(
"flip_y",
false,
"Flip the image along the y-axis");
52 params.
addParam<
bool>(
"flip_z",
false,
"Flip the image along the z-axis");
60 #ifdef LIBMESH_HAVE_VTK
66 (parameters.getCheckedPointerParam<
MooseApp *>(
"_moose_app"))->getOutputWarehouse()),
72 #ifndef LIBMESH_HAVE_VTK 75 mooseError(
"libMesh must be configured with VTK enabled to utilize ImageSampler");
86 #ifdef LIBMESH_HAVE_VTK 123 std::string file_suffix;
137 mooseError(
"No file range parameters were provided and the Mesh is not an ImageMesh.");
152 _files = vtkSmartPointer<vtkStringArray>::New();
155 _files->InsertNextValue(filename);
158 if (
_files->GetNumberOfValues() == 0)
164 if (file_suffix ==
"png")
165 _image = vtkSmartPointer<vtkPNGReader>::New();
166 else if (file_suffix ==
"tiff" || file_suffix ==
"tif")
167 _image = vtkSmartPointer<vtkTIFFReader>::New();
169 mooseError(
"Un-supported file type '", file_suffix,
"'");
182 int * dims =
_data->GetDimensions();
183 for (
unsigned int i = 0; i < 3; ++i)
185 _dims.push_back(dims[i]);
196 _is_console <<
" ...image read finished" << std::endl;
202 unsigned int n =
_data->GetNumberOfScalarComponents();
205 mooseError(
"'component' parameter must be empty or have a value of 0 to ", n - 1);
220 #ifdef LIBMESH_HAVE_VTK 227 std::vector<int> x(3, 0);
228 for (
int i = 0; i < LIBMESH_DIM; ++i)
236 if (x[i] ==
_dims[i])
241 x[i] =
_dims[i] - x[i] - 1;
246 return _data->GetScalarComponentAsDouble(x[0], x[1], x[2],
_component);
257 #ifdef LIBMESH_HAVE_VTK 276 #ifdef LIBMESH_HAVE_VTK 282 if (shift == 0 &&
scale == 1)
303 #ifdef LIBMESH_HAVE_VTK 310 mooseError(
"When thresholding is applied, both the upper_value and lower_value parameters must " libMesh::Point _physical_dims
Physical dimensions of image.
unsigned int _component
Component to extract.
vtkAlgorithmOutput * _algorithm
VTK-6 seems to work better in terms of "algorithm outputs" rather than vtkImageData pointers...
bool contains_point(const Point &) const
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
virtual void setupImageSampler(MooseMesh &mesh)
Perform initialization of image data.
const std::vector< std::string > & filenames()
Base class for MOOSE-based applications.
vtkSmartPointer< vtkImageReader2 > _image
Complete image data.
ConsoleStream _is_console
Create a console stream object for this helper class.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
libMesh::BoundingBox _bounding_box
Bounding box for testing points.
static InputParameters validParams()
vtkImageData * _data
Complete image data.
std::vector< double > _voxel
Physical pixel size.
void libmesh_ignore(const Args &...)
const Point & min() const
vtkSmartPointer< vtkImageMagnitude > _magnitude_filter
Pointer to the magnitude filter.
void vtkShiftAndScale()
Apply image re-scaling using the vtkImageShiftAndRescale object.
vtkSmartPointer< vtkImageShiftScale > _shift_scale_filter
Pointer to the shift and scaling filter.
const InputParameters & _is_pars
Parameters for interface.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
static InputParameters validParams()
Constructor.
ImageSampler(const InputParameters ¶meters)
void vtkThreshold()
Perform thresholding.
vtkSmartPointer< vtkStringArray > _files
List of file names to extract data.
libMesh::Point _origin
Origin of image.
To be called in the validParams functions of classes that need to operate on ranges of files...
std::vector< int > _dims
Pixel dimension of image.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void vtkMagnitude()
Convert the image to greyscale.
vtkSmartPointer< vtkImageThreshold > _image_threshold
Pointer to thresholding filter.
const Point & max() const
virtual libMesh::Real sample(const libMesh::Point &p) const
Return the pixel value for the given point.
std::array< bool, 3 > _flip
image flip
A 2D GeneratedMesh where xmin, xmax, etc.