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");
30 params.
addParam<
Real>(
"max", 1,
"The maximum for the variable we want to use");
31 params.
addParam<
Real>(
"min", 0,
"The minimum for the variable we want to use");
35 "resolution", 25,
"resolution>0",
"The length of the longest side of the image in pixels.");
38 "out_bounds_shade>=0 & out_bounds_shade<=1",
39 "Color for the parts of the image that are out of bounds." 40 "Value is between 1 and 0.");
43 "transparency>=0 & transparency<=1",
44 "Value is between 0 and 1" 45 "where 0 is completely transparent and 1 is completely opaque. " 46 "Default transparency of the image is no transparency.");
53 _resolution(getParam<unsigned
int>(
"resolution")),
55 _transparent_background(getParam<bool>(
"transparent_background")),
56 _transparency(getParam<
Real>(
"transparency")),
58 _variable(getParam<VariableName>(
"variable")),
59 _max(getParam<
Real>(
"max")),
60 _min(getParam<
Real>(
"min")),
61 _out_bounds_shade(getParam<
Real>(
"out_bounds_shade"))
71 unsigned int variable_number = 0;
75 mooseInfo(
"PNGOutput is not currently scalable.");
77 bool var_found =
false;
97 const std::vector<unsigned int> var_nums = {variable_number};
196 unsigned int number_of_destination_colors = 1;
201 number_of_destination_colors = 3;
206 number_of_destination_colors = 2;
211 number_of_destination_colors = 2;
216 number_of_destination_colors = 1;
222 auto color_spectrum_max = (256 * number_of_destination_colors) - 1;
223 auto color = (
unsigned int)(selection * color_spectrum_max);
230 if (color > color_spectrum_max)
232 color = color_spectrum_max;
236 auto magnitude = color % 256;
250 else if (color < 512)
271 rgb[0] = (
int)(255.0 * (0.231373 + (0.002485 * (
float)magnitude)));
272 rgb[1] = (
int)(255.0 * (0.298039 + (0.002223 * (
float)magnitude)));
273 rgb[2] = (
int)(255.0 * (0.752941 + (0.000439 * (
float)magnitude)));
278 rgb[0] = (
int)(255.0 * (0.865003 - (0.000624 * (
float)magnitude)));
279 rgb[1] = (
int)(255.0 * (0.865003 - (0.003331 * (
float)magnitude)));
280 rgb[2] = (
int)(255.0 * (0.865003 - (0.002808 * (
float)magnitude)));
296 rgb[0] = 255 - magnitude;
297 rgb[1] = 255 - magnitude;
307 rgb[2] = 255 - magnitude;
330 Point max_point =
_box.max();
331 Point min_point =
_box.min();
334 Real dist_x = max_point(0) - min_point(0);
335 Real dist_y = max_point(1) - min_point(1);
343 Real normalized_resolution;
360 std::ostringstream png_file;
361 png_file <<
_file_base <<
"_" << std::setfill(
'0') << std::setw(3) <<
_t_step <<
".png";
365 png_structp pngp =
nullptr;
366 png_infop infop =
nullptr;
370 std::vector<png_byte> row((width + 1) * 4);
376 fp = fopen(png_file.str().c_str(),
"wb");
378 pngp = png_create_write_struct(PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
380 mooseError(
"Failed to make the pointer string for the png.");
382 infop = png_create_info_struct(pngp);
384 mooseError(
"Failed to make an info pointer for the png.");
387 png_init_io(pngp, fp);
395 (
_color ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_GRAY),
397 PNG_COMPRESSION_TYPE_DEFAULT,
398 PNG_FILTER_TYPE_DEFAULT);
400 png_write_info(pngp, infop);
411 for (
Real y = max_point(1); y >= min_point(1); y -= 1. / normalized_resolution)
414 unsigned int index = 0;
415 for (
Real x = min_point(0); x <= max_point(0); x += 1. / normalized_resolution)
418 (*_mesh_function)(pt,
_time, dv,
nullptr);
428 png_write_row(pngp, row.data());
432 png_write_end(pngp,
nullptr);
435 if (infop !=
nullptr)
436 png_free_data(pngp, infop, PNG_FREE_ALL, -1);
438 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()
Basic constructor. Takes parameters passed in to create a PNGOutput object.
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.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
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...
const unsigned int _resolution
Variable to determine the size, or resolution, of the image.
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()
bool checkFileWriteable(const std::string &filename, bool throw_on_unwritable=true)
Check if the file is writable (path exists and permissions)
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)
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
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
virtual void output()
Called to run the functions in this class.