www.mooseframework.org
ImageSampler.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // MOOSE includes
13 #include "FileRangeBuilder.h"
14 #include "ConsoleStream.h"
15 
16 #include "libmesh/bounding_box.h"
17 #include <array>
18 
19 // VTK includes
20 #ifdef LIBMESH_HAVE_VTK
21 
22 // Some VTK header files have extra semi-colons in them, and clang
23 // loves to warn about it...
24 #include "libmesh/ignore_warnings.h"
25 
26 #include "vtkSmartPointer.h"
27 #include "vtkPNGReader.h"
28 #include "vtkTIFFReader.h"
29 #include "vtkImageData.h"
30 #include "vtkStringArray.h"
31 #include "vtkImageThreshold.h"
32 #include "vtkImageNormalize.h"
33 #include "vtkImageCast.h"
34 #include "vtkImageShiftScale.h"
35 #include "vtkImageMagnitude.h"
36 #include "vtkImageFlip.h"
37 
38 #include "libmesh/restore_warnings.h"
39 
40 #endif
41 
42 class MooseMesh;
43 
48 {
49 public:
59 
60  ImageSampler(const InputParameters & parameters);
61 
66  virtual Real sample(const Point & p) const;
67 
71  virtual void setupImageSampler(MooseMesh & mesh);
72 
73 protected:
77  void vtkShiftAndScale();
78 
82  void vtkThreshold();
83 
89  void vtkMagnitude();
90 
91 private:
92 #ifdef LIBMESH_HAVE_VTK
93 
95  vtkSmartPointer<vtkStringArray> _files;
96 
98  vtkImageData * _data;
99 
101  vtkAlgorithmOutput * _algorithm;
102 
104  vtkSmartPointer<vtkImageReader2> _image;
105 
107  vtkSmartPointer<vtkImageThreshold> _image_threshold;
108 
110  vtkSmartPointer<vtkImageShiftScale> _shift_scale_filter;
111 
113  vtkSmartPointer<vtkImageMagnitude> _magnitude_filter;
114 #endif
115 
117  Point _origin;
118 
120  std::vector<int> _dims;
121 
124 
126  std::vector<double> _voxel;
127 
129 #ifdef LIBMESH_HAVE_VTK
130  unsigned int _component;
131 #endif
132 
134  BoundingBox _bounding_box;
135 
138 
141 
143  std::array<bool, 3> _flip;
144 };
A helper class for re-directing output streams to Console output objects form MooseObjects.
Definition: ConsoleStream.h:30
unsigned int _component
Component to extract.
Definition: ImageSampler.h:130
vtkAlgorithmOutput * _algorithm
VTK-6 seems to work better in terms of "algorithm outputs" rather than vtkImageData pointers...
Definition: ImageSampler.h:101
virtual void setupImageSampler(MooseMesh &mesh)
Perform initialization of image data.
Definition: ImageSampler.C:78
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
vtkSmartPointer< vtkImageReader2 > _image
Complete image data.
Definition: ImageSampler.h:104
ConsoleStream _is_console
Create a console stream object for this helper class.
Definition: ImageSampler.h:140
virtual Real sample(const Point &p) const
Return the pixel value for the given point.
Definition: ImageSampler.C:216
BoundingBox _bounding_box
Bounding box for testing points.
Definition: ImageSampler.h:134
vtkImageData * _data
Complete image data.
Definition: ImageSampler.h:98
std::vector< double > _voxel
Physical pixel size.
Definition: ImageSampler.h:126
vtkSmartPointer< vtkImageMagnitude > _magnitude_filter
Pointer to the magnitude filter.
Definition: ImageSampler.h:113
void vtkShiftAndScale()
Apply image re-scaling using the vtkImageShiftAndRescale object.
Definition: ImageSampler.C:272
Point _origin
Origin of image.
Definition: ImageSampler.h:117
vtkSmartPointer< vtkImageShiftScale > _shift_scale_filter
Pointer to the shift and scaling filter.
Definition: ImageSampler.h:110
const InputParameters & _is_pars
Parameters for interface.
Definition: ImageSampler.h:137
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
static InputParameters validParams()
Constructor.
Definition: ImageSampler.C:18
ImageSampler(const InputParameters &parameters)
Definition: ImageSampler.C:56
void vtkThreshold()
Perform thresholding.
Definition: ImageSampler.C:299
vtkSmartPointer< vtkStringArray > _files
List of file names to extract data.
Definition: ImageSampler.h:95
A helper class for reading and sampling images using VTK.
Definition: ImageSampler.h:47
Point _physical_dims
Physical dimensions of image.
Definition: ImageSampler.h:123
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.
Definition: ImageSampler.h:120
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void vtkMagnitude()
Convert the image to greyscale.
Definition: ImageSampler.C:253
vtkSmartPointer< vtkImageThreshold > _image_threshold
Pointer to thresholding filter.
Definition: ImageSampler.h:107
std::array< bool, 3 > _flip
image flip
Definition: ImageSampler.h:143