OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::BlockGifWriter< T > Class Template Reference

BlockGifWriter writes given functor data to image file of format .ppm. More...

#include <blockGifWriter.h>

+ Collaboration diagram for olb::BlockGifWriter< T >:

Public Member Functions

 BlockGifWriter (std::string const &map="leeloo")
 
void write (BlockF2D< T > &f, T minValue, T maxValue, int iT=0, std::string const &name="emptyName")
 writes functor values normed to interval [0,1].
 
void write (BlockF2D< T > &f, int iT=0, std::string const &name="emptyName")
 writes functor data and determines its util::min-/maxValue
 
void write (int iT=0)
 writes functors stored at pointerVec
 
void addFunctor (BlockF2D< T > &f, std::string const &name="emptyName")
 put functor to _pointerVec, to simplify writing process of several functors
 
void addFunctor (BlockF2D< T > &f, T minValue, T maxValue, std::string const &name="emptyName")
 

Detailed Description

template<typename T>
class olb::BlockGifWriter< T >

BlockGifWriter writes given functor data to image file of format .ppm.

There are two different modes

  1. mode: image maxValue and minValue are computed every time. this implies that image data is scaled every time exactly to interval [0,1]. this may lead to different scaling of the functor data concerning the time steps
  2. mode: image maxValue and minValue are passed by the user once. this static use, prevents a rescaling effect for each time step.
Parameters
mapdetermines the color of the graphics

Definition at line 48 of file blockGifWriter.h.

Constructor & Destructor Documentation

◆ BlockGifWriter()

template<typename T >
olb::BlockGifWriter< T >::BlockGifWriter ( std::string const & map = "leeloo")

Definition at line 41 of file blockGifWriter.hh.

42 : clout(std::cout, "BlockGifWriter"), _colorRange(1024), _numColors(1024),
43 _colorMap(graphics::mapGenerators::generateMap<T>(map)), _minValue(0),
44 _maxValue(1)
45{ }

Member Function Documentation

◆ addFunctor() [1/2]

template<typename T >
void olb::BlockGifWriter< T >::addFunctor ( BlockF2D< T > & f,
std::string const & name = "emptyName" )

put functor to _pointerVec, to simplify writing process of several functors

Definition at line 153 of file blockGifWriter.hh.

154{
155 _pointerVec.push_back(&f);
156
157 if ( name == "emptyName") {
158 _name.push_back(f.getName() );
159 }
160 _name.push_back(name);
161
162 _autoScale.push_back(true);
163 _minValue.push_back(T());
164 _maxValue.push_back(T());
165}

References olb::GenericF< T, S >::getName().

+ Here is the call graph for this function:

◆ addFunctor() [2/2]

template<typename T >
void olb::BlockGifWriter< T >::addFunctor ( BlockF2D< T > & f,
T minValue,
T maxValue,
std::string const & name = "emptyName" )

Definition at line 168 of file blockGifWriter.hh.

170{
171 _pointerVec.push_back(&f);
172
173 if ( name == "emptyName") {
174 _name.push_back(f.getName() );
175 }
176 _name.push_back(name);
177
178 _autoScale.push_back(false);
179 _minValue.push_back(minValue);
180 _maxValue.push_back(maxValue);
181}

References olb::GenericF< T, S >::getName().

+ Here is the call graph for this function:

◆ write() [1/3]

template<typename T >
void olb::BlockGifWriter< T >::write ( BlockF2D< T > & f,
int iT = 0,
std::string const & name = "emptyName" )

writes functor data and determines its util::min-/maxValue

Definition at line 101 of file blockGifWriter.hh.

102{
103 // determine util::min-/maxValue
104 int i[2] = {0,0};
105 // initialize util::min-/maxValue
106 T minValue[1];
107 T maxValue[1];
108 f(minValue,i);
109 f(maxValue,i);
110 for (i[0] = 1; i[0] < f.getBlockStructure().getNx(); i[0]++) {
111 for (i[1] = 1; i[1] < f.getBlockStructure().getNy(); i[1]++) {
112 T valueTmp[1];
113 f(valueTmp,i);
114 if (valueTmp[0] < minValue[0]) {
115 minValue[0] = valueTmp[0];
116 }
117 if (valueTmp[0] > maxValue[0]) {
118 maxValue[0] = valueTmp[0];
119 }
120 }
121 }
122 if (maxValue[0] <= minValue[0]) {
123 minValue[0] = T();
124 maxValue[0] = T(1);
125 }
126 // call write() with util::min-/maxValue
127 write(f, minValue[0], maxValue[0], iT, name);
128}
void write(BlockF2D< T > &f, T minValue, T maxValue, int iT=0, std::string const &name="emptyName")
writes functor values normed to interval [0,1].

References olb::BlockF2D< T >::getBlockStructure().

+ Here is the call graph for this function:

◆ write() [2/3]

template<typename T >
void olb::BlockGifWriter< T >::write ( BlockF2D< T > & f,
T minValue,
T maxValue,
int iT = 0,
std::string const & name = "emptyName" )

writes functor values normed to interval [0,1].

imageValue is computed according to : if functorValue >= maxValue then the imageValue is clipped to 1 else imageValue = (minValue - functorValue) / (minValue - maxValue)

Definition at line 48 of file blockGifWriter.hh.

50{
51 // [!] exeption image(f) != 1
52 if ( f.getTargetDim() != 1 ) {
53 clout << "Error: Functor targetDim is not 1. " << std::endl;
54 exit(-1);
55 }
56 else {
57 if ( singleton::mpi().getRank() == 0 ) {
58 std::string fullNamePpm;
59 if ( name == "emptyName") {
60 fullNamePpm = createFileName( singleton::directories().getImageOutDir(),
61 f.getName(), iT);
62 }
63 else {
64 fullNamePpm = createFileName( singleton::directories().getImageOutDir(),
65 name, iT);
66 }
67 fullNamePpm = fullNamePpm + ".ppm" ;
68 std::ofstream fout( fullNamePpm.c_str() );
69
70 // write header
71 fout << "P3\n";
72 // dimension of image
73 fout << f.getBlockStructure().getNx() << " "
74 << f.getBlockStructure().getNy() << "\n";
75 // dynamic range
76 fout << (_colorRange - 1) << "\n";
77
78 int i[2] = {0,0};
79 for (i[1] = f.getBlockStructure().getNy() - 1; i[1] >= 0; --i[1]) {
80 for (i[0] = 0; i[0] < f.getBlockStructure().getNx(); ++i[0]) {
81 T evaluated[1];
82 f(evaluated,i);
83 // scales evaluated in [getMinValue(),getMaxValue()] to [0,1]
84 evaluated[0] = (minValue - evaluated[0]) / (minValue - maxValue);
85 // sets evaluated notin [getMinValue(),getMaxValue()] to 1
86 if ( evaluated[0] >= T(1) ) {
87 evaluated[0] = 1;
88 }
89 graphics::rgb<T> color = _colorMap.get(evaluated[0]);
90 fout << (int)(color.r * (_colorRange - 1)) << " "
91 << (int)(color.g * (_colorRange - 1)) << " "
92 << (int)(color.b * (_colorRange - 1)) << "\n";
93 }
94 }
95 fout.close();
96 }
97 }
98}
void exit(int exitcode)
Definition singleton.h:165
MpiManager & mpi()
Directories & directories()
Definition singleton.h:150
std::string createFileName(std::string name)
for .pvd masterFile
Definition fileName.hh:34

References olb::graphics::rgb< T >::b, olb::createFileName(), olb::singleton::directories(), olb::graphics::rgb< T >::g, olb::BlockF2D< T >::getBlockStructure(), olb::GenericF< T, S >::getName(), olb::BlockStructureD< D >::getNx(), olb::BlockStructureD< D >::getNy(), olb::GenericF< T, S >::getTargetDim(), olb::singleton::mpi(), and olb::graphics::rgb< T >::r.

+ Here is the call graph for this function:

◆ write() [3/3]

template<typename T >
void olb::BlockGifWriter< T >::write ( int iT = 0)

writes functors stored at pointerVec

Definition at line 133 of file blockGifWriter.hh.

134{
135 if ( _pointerVec.empty() ) {
136 // secure code. doesn't appear on console ??
137 clout << "Error: Please add functor via addFunctor()";
138 }
139 else {
140 int i = 0;
141 for ( auto it = _pointerVec.cbegin(); it != _pointerVec.cend(); ++it, ++i) {
142 if (_autoScale[i]) {
143 write(**it, iT, _name[i]);
144 }
145 else {
146 write(**it, _minValue[i], _maxValue[i], iT, _name[i]);
147 }
148 }
149 }
150}

The documentation for this class was generated from the following files: