Skip to content

Commit

Permalink
Merge pull request #13646 from Hysrok/PNGOuput
Browse files Browse the repository at this point in the history
Create a PNG image output object
  • Loading branch information
permcody committed Jul 16, 2019
2 parents 7c981d7 + 985490b commit 5351080
Show file tree
Hide file tree
Showing 13 changed files with 889 additions and 2 deletions.
14 changes: 14 additions & 0 deletions framework/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ ifneq (x$(MOOSE_NO_PERF_GRAPH), x)
libmesh_CXXFLAGS += -DMOOSE_NO_PERF_GRAPH
endif

#
# libPNG Definition
#
png_LIB :=
ifneq (, $(shell which pkg-config 2>/dev/null))
RET_CODE := $(shell pkg-config --libs libpng 2>/dev/null 1>&2; echo $$?)

ifeq (0,$(RET_CODE))
png_LIB = $(shell pkg-config --libs libpng)
libmesh_CXXFLAGS += $(shell pkg-config --cflags-only-I libpng)
libmesh_CXXFLAGS += -DMOOSE_HAVE_LIBPNG
endif
endif

# Make.common used to provide an obj-suffix which was related to the
# machine in question (from config.guess, i.e. @host@ in
# contrib/utils/Make.common.in) and the $(METHOD).
Expand Down
18 changes: 18 additions & 0 deletions framework/doc/content/source/outputs/png/PNGOutput.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# PNGOutput (Outputs)

The PNGOutput object is the class for writing png files from the input files.

Following is an example of all the different input variables that can be used.

```
[Outputs]
[png]
type = PNGOutput
transparent = true #indicates whether the background will be transparent
resolution = 50 #resolution of each point
color = RWB #indicates which color scheme to use (required)
out_bounds_shade = .5 #value from 0-1 indicating shade to use as background
transparency = 1 #value from 0(transparent)-1(opaque) for image.
[]
[]
```
84 changes: 84 additions & 0 deletions framework/include/outputs/png/PNGOutput.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifdef MOOSE_HAVE_LIBPNG

#pragma once

// pnglib includes
#include <png.h>
// MOOSE includes
#include "FileOutput.h"
#include "MooseEnum.h"
// libmesh includes
#include "libmesh/mesh_function.h"
#include "libmesh/bounding_box.h"

// Forward declarations
class PNGOutput;

template <>
InputParameters validParams<PNGOutput>();

class PNGOutput : public FileOutput
{
public:
// Basic constructor. Takes parameters passed in to create a PNGOutput object.
PNGOutput(const InputParameters & parameters);

protected:
// Method for assigning color values to the PNG
void setRGB(png_byte * rgb, Real selection);

// Function to create the mesh_function
void makeMeshFunc();

// Function to populate values to the variables used for scaling
void calculateRescalingValues();

// Function for applying scaling to given values.
Real applyScale(Real value_to_scale);

// Function for reversing the applyScale function.
Real reverseScale(Real value_to_unscale);

// Function that creates the PNG
void makePNG();

// Called to run the functions in this class.
virtual void output(const ExecFlagType & type);

// Variable to determine the size, or resolution, of the image.
unsigned int _resolution;

// Way to specify color vs grayscale image creation.
MooseEnum _color;

// Indicates whether to make the background transparent.
bool _transparent_background;

// Controls transparency level for the general image.
Real _transparency;

/// Pointer the libMesh::MeshFunction object that the read data is stored
std::unique_ptr<MeshFunction> _mesh_function;

// The boundaries of the image.
BoundingBox _box;

// Values used for rescaling the image.
Real _scaling_min;
Real _scaling_max;
Real _shift_value;

// Value of the colorrs that are outside of the libmesh bounds.
Real _out_bounds_shade;
};

#endif
2 changes: 1 addition & 1 deletion framework/moose.mk
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ $(hit_LIB): $(hit_objects)
$(moose_LIB): $(moose_objects) $(pcre_LIB) $(gtest_LIB) $(hit_LIB) $(pyhit_LIB)
@echo "Linking Library "$@"..."
@$(libmesh_LIBTOOL) --tag=CXX $(LIBTOOLFLAGS) --mode=link --quiet \
$(libmesh_CXX) $(CXXFLAGS) $(libmesh_CXXFLAGS) -o $@ $(moose_objects) $(pcre_LIB) $(libmesh_LIBS) $(libmesh_LDFLAGS) $(EXTERNAL_FLAGS) -rpath $(FRAMEWORK_DIR)
$(libmesh_CXX) $(CXXFLAGS) $(libmesh_CXXFLAGS) -o $@ $(moose_objects) $(pcre_LIB) $(png_LIB) $(libmesh_LIBS) $(libmesh_LDFLAGS) $(EXTERNAL_FLAGS) -rpath $(FRAMEWORK_DIR)
@$(libmesh_LIBTOOL) --mode=install --quiet install -c $(moose_LIB) $(FRAMEWORK_DIR)

## Clang static analyzer
Expand Down
Loading

0 comments on commit 5351080

Please sign in to comment.