10 #ifdef MOOSE_HAVE_LIBPNG 17 #include "libmesh/mesh_tools.h" 25 params.
addParam<
bool>(
"transparent_background",
27 "Determination of whether the background will be transparent.");
29 "The name of the variable to use when creating the image");
31 "The maximum for the variable we want to use. If unspecified, the maximum " 32 "of the variable's DOF values is used");
34 "The minimum for the variable we want to use. If unspecified, the minimum " 35 "of the variable's DOF values is used");
37 params.
addParam<Point>(
"frame_center",
39 "Center of the frame when defining the rectangular plotting region " 40 "dimensions. Applied after the frame rotation");
44 "First axis to generate the rectangular plotting region. The axis vector will be normalized");
45 params.
addParam<Point>(
"second_axis",
47 "Second axis to generate the rectangular plotting region. The axis vector " 48 "will be normalized");
51 "Minimum coordinate along the first axis. Defaults to mesh bounding box min X value");
54 "Maximum coordinate along the first axis. Defaults to mesh bounding box max X value");
57 "Minimum coordinate along the second axis. Default to mesh bounding box min Y value");
60 "Maximum coordinate along the second axis. Default to mesh bounding box max Y value");
62 "Rectangular box extent");
64 MooseEnum color(
"GRAY BRYW BWR RWB BR",
"BR");
67 "resolution", 25,
"resolution>0",
"The length of the longest side of the image in pixels.");
70 "out_bounds_shade>=0 & out_bounds_shade<=1",
71 "Color for the parts of the image that are out of bounds." 72 "Value is between 1 and 0.");
75 "transparency>=0 & transparency<=1",
76 "Value is between 0 and 1" 77 "where 0 is completely transparent and 1 is completely opaque. " 78 "Default transparency of the image is no transparency.");
86 _resolution(getParam<unsigned
int>(
"resolution")),
88 _transparent_background(getParam<bool>(
"transparent_background")),
89 _transparency(getParam<
Real>(
"transparency")),
91 _variable(getParam<VariableName>(
"variable")),
92 _max(isParamValid(
"max") ? getParam<
Real>(
"max") :
std::numeric_limits<
Real>::
max()),
93 _min(isParamValid(
"min") ? getParam<
Real>(
"min") : -
std::numeric_limits<
Real>::
max()),
94 _out_bounds_shade(getParam<
Real>(
"out_bounds_shade"))
96 if (!MooseUtils::absoluteFuzzyEqual(
97 getParam<Point>(
"first_axis") * getParam<Point>(
"second_axis"), 0))
98 paramWarning(
"first_axis",
"The two axis are not orthogonal");
106 unsigned int variable_number = 0;
110 mooseInfo(
"PNGOutput is not currently scalable.");
112 bool var_found =
false;
130 paramError(
"variable",
"This doesn't exist.");
132 const std::vector<unsigned int> var_nums = {variable_number};
231 unsigned int number_of_destination_colors = 1;
236 number_of_destination_colors = 3;
241 number_of_destination_colors = 2;
246 number_of_destination_colors = 2;
251 number_of_destination_colors = 1;
257 auto color_spectrum_max = (256 * number_of_destination_colors) - 1;
258 auto color = (
unsigned int)(selection * color_spectrum_max);
265 if (color > color_spectrum_max)
267 color = color_spectrum_max;
271 auto magnitude = color % 256;
285 else if (color < 512)
306 rgb[0] = (
int)(255.0 * (0.231373 + (0.002485 * (
float)magnitude)));
307 rgb[1] = (
int)(255.0 * (0.298039 + (0.002223 * (
float)magnitude)));
308 rgb[2] = (
int)(255.0 * (0.752941 + (0.000439 * (
float)magnitude)));
313 rgb[0] = (
int)(255.0 * (0.865003 - (0.000624 * (
float)magnitude)));
314 rgb[1] = (
int)(255.0 * (0.865003 - (0.003331 * (
float)magnitude)));
315 rgb[2] = (
int)(255.0 * (0.865003 - (0.002808 * (
float)magnitude)));
331 rgb[0] = 255 - magnitude;
332 rgb[1] = 255 - magnitude;
342 rgb[2] = 255 - magnitude;
365 Point max_point =
_box.max();
366 Point min_point =
_box.min();
370 min_point(0) = getParam<Real>(
"min_x");
372 min_point(1) = getParam<Real>(
"min_y");
374 max_point(0) = getParam<Real>(
"max_x");
376 max_point(1) = getParam<Real>(
"max_y");
379 Real dist_x = max_point(0) - min_point(0);
380 Real dist_y = max_point(1) - min_point(1);
399 std::ostringstream png_file;
400 png_file <<
_file_base <<
"_" << std::setfill(
'0') << std::setw(3) <<
_t_step <<
".png";
404 png_structp pngp =
nullptr;
405 png_infop infop =
nullptr;
409 std::vector<png_byte> row((width + 1) * 4);
415 fp = fopen(png_file.str().c_str(),
"wb");
421 const png_uint_32 runtime_libpng_ver = png_access_version_number();
422 if (runtime_libpng_ver / 100 != PNG_LIBPNG_VER / 100)
426 ": runtime libpng version ",
428 " is ABI-incompatible with the version ",
429 static_cast<png_uint_32
>(PNG_LIBPNG_VER),
430 " used at compile time.");
436 pngp = png_create_write_struct(PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
438 mooseError(
"Failed to make the pointer string for the png.");
440 infop = png_create_info_struct(pngp);
442 mooseError(
"Failed to make an info pointer for the png.");
445 png_init_io(pngp, fp);
453 (
_color ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_GRAY),
455 PNG_COMPRESSION_TYPE_DEFAULT,
456 PNG_FILTER_TYPE_DEFAULT);
458 png_write_info(pngp, infop);
464 Point center(0, 0, 0);
466 center = getParam<Point>(
"frame_center");
468 center = Point((min_point(0) + max_point(0)) / 2, (min_point(1) + max_point(1)) / 2, 0);
470 const auto first_axis = getParam<Point>(
"first_axis").unit();
471 const auto second_axis = getParam<Point>(
"second_axis").unit();
477 for (
const auto iy :
make_range((
unsigned int)height))
479 for (
const auto ix :
make_range((
unsigned int)width + 1))
484 (min_point(0) +
Real(ix) /
_resolution * (max_point(0) - min_point(0))) * first_axis +
485 (min_point(1) +
Real(iy) /
_resolution * (max_point(1) - min_point(1))) * second_axis;
487 (*_mesh_function)(pt,
_time, dv,
nullptr);
495 png_write_row(pngp, row.data());
499 png_write_end(pngp,
nullptr);
502 if (infop !=
nullptr)
503 png_free_data(pngp, infop, PNG_FREE_ALL, -1);
505 png_destroy_write_struct(&pngp, &infop);
unsigned int _nl_sys_num
What nonlinear system the variable is in.
void mooseInfo(Args &&... args) const
void makePNG()
Function that creates the PNG.
const InputParameters & _pars
The object's parameters.
std::unique_ptr< libMesh::MeshFunction > _mesh_function
Pointer to the libMesh::MeshFunction object in which the read data is stored.
const unsigned int invalid_uint
const MooseEnum _color
Way to specify color vs grayscale image creation.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
virtual std::size_t numNonlinearSystems() const override
void makeMeshFunc()
Function to create the mesh_function.
static InputParameters validParams()
unsigned int number() const
Get variable number coming from libMesh.
const bool _transparent_background
Indicates whether to make the background transparent.
Real reverseScale(Real value_to_unscale)
Function for reversing the applyScale function.
Real _out_bounds_shade
Value of the colors that are outside of the libmesh bounds.
std::string _file_base
The base filename from the input paramaters.
void calculateRescalingValues()
Function to populate values to the variables used for scaling.
int & _t_step
The current time step.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Output class to create a 2D figure in PNG format.
auto max(const L &left, const R &right)
const unsigned int _resolution
Variable to determine the size, or resolution, of the image.
void mooseWarning(Args &&... args) const
virtual libMesh::DofMap & dofMap()
Gets writeable reference to the dof map.
virtual NumericVector< Number > & serializedSolution()
Returns a reference to a serialized version of the solution vector for this subproblem.
registerMooseObject("MooseApp", PNGOutput)
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
const Real _transparency
Controls transparency level for the general image.
static InputParameters validParams()
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Real _max
Variables that store the max and min of the values in the variable used.
virtual Real max() const =0
virtual Real min() const =0
AuxiliarySystem & getAuxiliarySystem()
virtual bool hasVariable(const std::string &var_name) const
Query a system for a variable.
virtual NonlinearSystem & getNonlinearSystem(const unsigned int sys_num)
Real applyScale(Real value_to_scale)
Function for applying scaling to given values.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _scaling_min
Values used for rescaling the image.
BoundingBox _box
The boundaries of the image.
libMesh::EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
VariableName _variable
The name of the variable to use to create the png.
IntRange< T > make_range(T beg, T end)
MooseMesh * _mesh_ptr
A convenience pointer to the current mesh (reference or displaced depending on "use_displaced") ...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
PNGOutput(const InputParameters ¶meters)
bool checkFileWriteable(const std::string &filename, bool throw_on_unwritable)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
void paramWarning(const std::string ¶m, Args... args) const
An outputter with filename support.
void setRGB(png_byte *rgb, Real selection)
Method for assigning color values to the PNG.
processor_id_type processor_id() const
Real & _time
The current time for output purposes.
void ErrorVector unsigned int
const Elem & get(const ElemType type_in)
virtual void output()
Called to run the functions in this class.