Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
portablepixelmap.hh
Go to the documentation of this file.
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set ts=8 sw=4 et sts=4:
3
4// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef PORTABLEPIXELMAP_HH
8#define PORTABLEPIXELMAP_HH
9
10#include <fstream>
11#include <sstream>
12#include <iostream>
13#include <string>
14#include <vector>
15#include <array>
16#include <map>
17#include <utility>
18
19
21
22#include <dune/istl/bvector.hh>
23
24#include <dune/grid/yaspgrid.hh>
25
28
44{
45 public:
51
58
59// typedef unsigned short int CType;
60 typedef unsigned char CType;
61 typedef unsigned short int KeyType;
62
69
78
81 {
82 key_filled_ = false;
83 }
84
91 ColorMap(const std::string filename)
92 {
93 std::string str;
94 std::ifstream file;
95
96 file.open(filename.c_str());
97
98 std::getline(file, str);
99
100 if (str.find("dune-fufem colorkey")!=std::string::npos)
101 {
102 char char_arr[256];
103
104 /* get rid of comment and empty lines */
105 do {
106 file.getline(char_arr,256);
107 str = char_arr; // I do not use the method std::getline(std::istream,std::string) because it does not set the istream-gcount which will be needed later. Therefore I need to do this ugly conversion
108 str.erase(0,str.find_first_not_of(" \n\t"));
109 } while (str[0] == 35 or str.empty()); // ASCII(35) = #
110
111 file.seekg(-file.gcount(),std::ios_base::cur);
112
113 unsigned short int value=0;
114 Color keycolor(0);
115 KeyType key=0;
116
117 while (true)
118 {
119 file >> std::skipws >> key;
120 for (int j=0; j<3; ++j)
121 {
122 file >> std::skipws >> value;
123 keycolor[j] = value;
124 }
125 insertInColorKey(key, keycolor);
126 if (file.eof() or file.fail())
127 break;
128 }
129 }
130 else
131 DUNE_THROW(Dune::Exception, "unknown file format");
132 }
133
140 bool insertInColorKey(const KeyType key, const Color color)
141 {
142 bool inserted = colorkey_.insert(std::make_pair(key,color)).second;
143 key_filled_ = ( inserted ? false : key_filled_ );
144 return inserted;
145 }
146
154 Color map(const double fMin, const double fMax, const double fVal) const
155 {
156 if (colorkey_.size()<2)
157 DUNE_THROW(Dune::Exception, "No valid ColorKey has been specified");
158
160 KeyType keymax = colorkey_.rbegin()->first;
161 double keyval = (fVal - fMin)/(fMax - fMin) * keymax;
162 if (keyval>keymax)
163 keyval = keymax;
164 else if (keyval < 0)
165 keyval = 0.0;
166
167 std::pair<CType,Color> col2 = *colorkey_.lower_bound(floor(keyval + 0.5)),
168 col1 = col2;
169 if (col2.first!=floor(keyval+0.5)) col1 = *(--colorkey_.lower_bound(floor(keyval+ 0.5)));
170
171 double intp = ( col2.first==col1.first ? 0 : (keyval - col1.first)/(col2.first - col1.first) );
172
173 for (int i=0; i<3; ++i)
174 dcol[i] = (1-intp)*col1.second[i] + intp*col2.second[i];
175
176 Color ret_col(0.0);
177
178 for (int i = 0; i<3; ++i)
179 ret_col[i] = floor(dcol[i]+0.5);
180
181
182 return ret_col;
183 }
184
202 double inv_map(const double fMin, const double fMax, const Color color)
203 {
204 if (colorkey_.size()<2)
205 DUNE_THROW(Dune::Exception, "No valid ColorKey has been specified");
206
207 if (not key_filled_)
208 fill_in_colorkey();
209
210 ColorKey::iterator it = colorkey_.begin();
211 ColorKey::iterator endit = colorkey_.end();
212
213 KeyType keymax = colorkey_.rbegin()->first;
214
215 ColorKey::iterator keycolor;
216 double mindiff = 1000.0;
217
219
220 for (;it != endit; ++it)
221 {
222 for (int j =0; j<3; ++j)
223 diff_col[j] = int(color[j])-int(it->second[j]);
224
225 if (diff_col.one_norm() < mindiff)
226 {
227 mindiff = diff_col.one_norm();
228 keycolor = it;
229
230 if (mindiff == 0)
231 return fMin + keycolor->first*(fMax-fMin)/keymax;
232 }
233 }
234
235 Dune::FieldVector<int,3> difff_col;
236 for (int j =0; j<3; ++j)
237 {
238 diff_col[j] = (keycolor->first != 0 ? int(color[j]) - int(colorkey_[(keycolor->first)-1][j]) : 255);
239 difff_col[j] = (keycolor->first != 255 ? int(color[j]) - int(colorkey_[(keycolor->first)+1][j]) : 255);
240 }
241
242 double nextdiff=0.0;
243 int modifier=0;
244 if (diff_col.one_norm() <= difff_col.one_norm())
245 {
246 nextdiff = diff_col.one_norm();
247 modifier = -1;
248 }
249 else
250 {
251 nextdiff = difff_col.one_norm();
252 modifier = 1;
253 }
254
255 double intp = mindiff/(mindiff+nextdiff);
256
257
258 return fMin + ((1 - intp)*keycolor->first + intp*(keycolor->first + modifier))*(fMax-fMin)/keymax;
259 }
260
267 void exportColorMapGraphic(const std::string filename="colormap.ppm", IODataFormat df=Bin) const
268 {
269 unsigned short int width = 256,
270 height = 25;
271
272 std::ofstream* ppmfile;
273 if (df==Bin)
274 ppmfile = new std::ofstream(filename.c_str(), std::ios::trunc | std::ios::out | std::ios::binary);
275 else
276 ppmfile = new std::ofstream(filename.c_str(), std::ios::trunc | std::ios::out);
277
278 /* write preliminaries ("P3"/"P6", some comment, height, width, maxval) to stream */
279 (*ppmfile) << (df==Bin ? "P6" : "P3") << std::endl << "# file created by PortablePixelMap (dune-fufem)" << std::endl << "# colormap" << std::endl << width << " " << height << std::endl << 255 << std::endl;
280
281 for (int j= 0; j<height; ++j)
282 {
283 for (int i= 0; i<width; ++i)
284 {
285 /* we transform the function value to the corresponding point in [0,255]^3 */
286 Color color = map(0, width-1, i);
287
288 /* write color to stream - take care: << operator for char writes the corresponding ascii character */
289 for (int c=0; c<3; ++c)
290 if (df==Bin)
291 ppmfile->write(reinterpret_cast<char*>(&(color[c])),sizeof(CType));
292 else
293 (*ppmfile) << int(color[c]) << " ";
294
295 if (df==ASCII)
296 (*ppmfile) << std::endl;
297 }
298 }
299
300 /* close PPM */
301 ppmfile->close();
302 delete ppmfile;
303 ppmfile=0;
304 }
305
314 void exportColorMap(std::string filename="colormap", ColorMapFileFormat format=CM)
315 {
316 if (format == CM)
317 {
318 std::string extension = (filename.rfind(".")!=std::string::npos ? filename.substr(filename.rfind(".")) : "");
319 if (extension != ".cm")
320 filename.append(".cm");
321
322 std::ofstream cmfile(filename.c_str(), std::ios::trunc | std::ios::out);
323
324 /* write preliminaries to stream */
325 cmfile << "dune-fufem colorkey format" << std::endl << "# file created by ColorMap (dune-fufem)" << std::endl;
326
327 ColorKey::const_iterator it = colorkey_.begin();
328 ColorKey::const_iterator endit = colorkey_.end();
329
330 for (; it != endit; ++it)
331 {
332 /* write key to stream */
333 cmfile << it->first << " ";
334 /* write color to stream - take care: << operator for char writes the corresponding ascii character */
335 for (int c=0; c<3; ++c)
336 cmfile << short(it->second[c]) << (c<2?" ":"");
337 cmfile << std::endl;
338 }
339
340 /* close CM */
341 cmfile.close();
342 }
343 }
344
345 int size()
346 {
347 return colorkey_.size();
348 }
349 private:
353 static const CType MAXVAL_=255;
354
355 ColorKey colorkey_;
356
357 bool key_filled_;
358
364 void fill_in_colorkey()
365 {
366 ColorKey::iterator it = colorkey_.begin();
367 ColorKey::iterator endit = colorkey_.end();
368 ColorKey::iterator nextit = it;
369 ++nextit;
370
371 ColorKey new_elements;
372 ColorKey::iterator new_elements_pos = new_elements.end();
373
374 while (nextit != endit)
375 {
376 for (KeyType i = it->first+1; i < nextit->first; ++i)
377 {
378 KeyType spread = nextit->first - it->first;
379 double frac = double(i - it->first)/spread;
380
381 Dune::FieldVector<double,3> db_col(0.0);
382 for (int j=0; j<3; ++j)
383 db_col[j] = (1-frac)*it->second[j] + frac*nextit->second[j];
384
385 Color new_color;
386 new_color[0] = floor(db_col[0]+0.5);
387 new_color[1] = floor(db_col[1]+0.5);
388 new_color[2] = floor(db_col[2]+0.5);
389 if (new_elements_pos!=new_elements.end())
390 new_elements_pos = new_elements.insert(++new_elements_pos, std::make_pair(i,new_color));
391 else
392 new_elements_pos = (new_elements.insert(std::make_pair(i,new_color))).first;
393 }
394 it = nextit;
395 ++nextit;
396 }
397
398 colorkey_.insert(new_elements.begin(),new_elements.end());
399 key_filled_ = true;
400 }
401};
402
411{
412 public:
414
415 typedef GridType::Codim<0>::Geometry::LocalCoordinate LocalDomainType;
417
418 using DomainType = typename GridType::template Codim<0>::Geometry::GlobalCoordinate;
420
422
425
428
429
436
437 private:
438 typedef ColorMap::Color Color;
439
440 unsigned int
441 width_,
442 height_;
443
444 DomainType::field_type
445 xDomainMin_,
446 xDomainMax_,
447 yDomainMin_,
448 yDomainMax_;
449
450 const RangeType
451 fRangeMin_,
452 fRangeMax_;
453
454 std::vector<unsigned int> imgParams_;
455
456 ColorMap colormap_;
457
458 Basis* basis_;
459 CoeffType coeffs_;
460 FunctionType* pixMapFunction_;
461 GridType* grid_;
462
463 using DomainFieldType = typename Dune::template FieldTraits<DomainType>::field_type;
464
465 template<class Function>
466 using RangeFieldTypeFor = typename Dune::template FieldTraits<std::decay_t<std::invoke_result_t<Function, DomainType>>>::field_type;
467
468 public:
479 PortablePixelMap(const DomainType::field_type xDomainMin, const DomainType::field_type xDomainMax,
480 const DomainType::field_type yDomainMin, const DomainType::field_type yDomainMax,
481 const RangeType fRangeMin, const RangeType fRangeMax,
482 const ColorMap colormap):
483 xDomainMin_(xDomainMin),
484 xDomainMax_(xDomainMax),
485 yDomainMin_(yDomainMin),
486 yDomainMax_(yDomainMax),
487 fRangeMin_(fRangeMin),
488 fRangeMax_(fRangeMax),
489 colormap_(colormap)
490 {
491 if (fRangeMax<=fRangeMin)
492 DUNE_THROW(Dune::RangeError, "Range of function values has inverse bounds or zero length.");
493 }
494
501 PortablePixelMap(const RangeType fRangeMin, const RangeType fRangeMax, const ColorMap colormap):
502 xDomainMin_(0),
503 xDomainMax_(0),
504 yDomainMin_(0),
505 yDomainMax_(0),
506 fRangeMin_(fRangeMin),
507 fRangeMax_(fRangeMax),
508 colormap_(colormap),
509 grid_(NULL)
510 {
511 if (fRangeMax<=fRangeMin)
512 DUNE_THROW(Dune::RangeError, "Range of function values has inverse bounds or zero length.");
513 }
514
526 void readPixelMap(const char* filename, const int width=-1, const int height=-1, const int xoffset=0, const int yoffset=0)
527 {
528 std::string str;
529 std::string ppmID;
530 std::ifstream ppmfile;
531
532 ppmfile.open(filename);
533
534 /* get rid of leading comment lines */
535 do {
536 std::getline(ppmfile, ppmID);
537 } while (ppmID[0] == 35); // ASCII(35) = #
538
539 if (ppmID!="P3" and ppmID!="P6")
540 DUNE_THROW(Dune::Exception,"File is not a PPM-File.");
541
542 int count = 0;
543 while (count < 3)
544 {
545 ppmfile >> std::skipws >> str;
546 if (str[0] == 35)
547 {
548 ppmfile.ignore(1024,10);
549 continue;
550 }
551 else
552 {
553 imgParams_.push_back(std::atoi(str.c_str()));
554 ++count;
555 }
556 }
557
558 int imgWidth = imgParams_[0],
559 imgHeight = imgParams_[1],
560 maxval_ = imgParams_[2];
561
562 unsigned short int datalength = maxval_ > 255 ? 2 : 1;
563 if (datalength==2)
564 DUNE_THROW(Dune::Exception, "At the moment only PixelMaps with 8Bit/color channel, i.e. a maxval of 255 may be processed due to a restriction of ColorMap::CType to unsigned char.");
565
566 count = 0;
567
568
569 width < 0 ? width_ = imgWidth : width_ = width;
570 height < 0 ? height_ = imgHeight : height_ = height;
571
572 if(xDomainMax_-xDomainMin_ <= 0.0)
573 {
574 xDomainMin_ = 0;
575 xDomainMax_ = width_-1;
576
577 yDomainMin_ = 0;
578 yDomainMax_ = height_-1;
579 }
580
581 unsigned short int value=0;
582
583 int p1 = ceil(log(width_ -1)/log(2)),
584 p2 = ceil(log(height_-1)/log(2)),
585 i = (p1-p2 >= 0)? p1-p2 : 0,
586 j = (p1-p2 >= 0)? 0 : p2-p1;
587
590
591 L[0] = pow(2, p1);
592 L[1] = pow(2, p2);
593 s[0] = pow(2, i);
594 s[1] = pow(2, j);
595
596 grid_ = new GridType(L,s);
597 for (int k=0; k<std::min(p1,p2); ++k)
598 grid_->globalRefine(1);
599
600 basis_ = new Basis(grid_->leafGridView());
601 coeffs_.resize(basis_->size());
602 coeffs_ = 0.0;
603 pixMapFunction_ = new FunctionType(Dune::Functions::makeDiscreteGlobalBasisFunction<RangeType>(*basis_, coeffs_));
604
605 /* if it's the binary format we need to open in binary mode */
606 if (ppmID == "P6")
607 {
608 ppmfile.close();
609 ppmfile.open(filename,std::ios::binary);
610 }
611
612 /* Skip yoffset pixel lines and xoffset pixel columns */
613 for (int k=0; k < 3*(yoffset*imgWidth+xoffset); ++k)
614 if (ppmID=="P6")
615 ppmfile.read(reinterpret_cast<char*>(&value), datalength*sizeof(char));
616 else
617 ppmfile >> std::skipws >> value;
618
619 /* read width x height color values */
620 for (std::size_t i=0; i<height_; ++i)
621 {
622 for(std::size_t j=0; j<width_; ++j)
623 {
624 Color pix_color(0);
625 for (std::size_t c=0; c<3; ++c)
626 {
627 if (ppmID == "P6")
628 ppmfile.read(reinterpret_cast<char*>(&(pix_color[c])), datalength*sizeof(char));
629 else
630 {
631 ppmfile >> std::skipws >> value;
632 pix_color[c] = value;
633 }
634
635 if (ppmfile.eof())
636 break;
637
638 pix_color[c] = value;
639 }
640 coeffs_[(height_-1-i)*(L[0]+1)+j] = colormap_.inv_map(fRangeMin_, fRangeMax_, pix_color);
641 }
642
643 /* Skip rest of pixel line */
644 for (std::size_t k=0; k < 3*(imgWidth-width_); ++k)
645 if (ppmID=="P6")
646 ppmfile.read(reinterpret_cast<char*>(&value), datalength*sizeof(char));
647 else
648 ppmfile >> std::skipws >> value;
649 }
650
651 }
652
672 template <typename FType>
673 static void exportPixelMap( const char* filename,
674 const FType& function,
675 RangeFieldTypeFor<FType> fRangeMin, RangeFieldTypeFor<FType> fRangeMax,
676 const DomainFieldType xDomainMin, const DomainFieldType xDomainMax,
677 const DomainFieldType yDomainMin, const DomainFieldType yDomainMax,
678 const unsigned int width, const unsigned int height,
679 const std::string info,
680 const ColorMap colormap, IODataFormat df=Bin)
681 {
683 using RangeFieldType = RangeFieldTypeFor<FType>;
684
685 DomainFieldType xLength = xDomainMax - xDomainMin;
686 DomainFieldType yLength = yDomainMax - yDomainMin;
687
688 RangeFieldType rangeInterval = fRangeMax-fRangeMin;
689
690 if (xLength <= 0.0 or yLength <= 0.0 or rangeInterval <= 0.0)
691 DUNE_THROW(Dune::RangeError,"Domain has zero or negative extension or range interval has zero length or negative extension(thrown by PortablePixelMap::exportPixelMap.");
692
693 DomainType r(0.0);
694 RangeType fval(0.0);
695
696 std::ofstream* ppmfile;
697
698 if (df==Bin)
699 ppmfile = new std::ofstream(filename, std::ios::trunc | std::ios::out | std::ios::binary);
700 else
701 ppmfile = new std::ofstream(filename, std::ios::trunc | std::ios::out);
702
703 // write preliminaries ("P3", some comment, height, width, maxval) to stream
704 (*ppmfile) << (df==Bin ? "P6" : "P3") << std::endl << "# file created by PortablePixelMap (dune-fufem)" << std::endl << "# " << info << std::endl << width << " " << height << std::endl << 255 << std::endl;
705
706 r[0] = xDomainMin;
707 r[1] = yDomainMax;
708
709 for (std::size_t j= 0; j<height; ++j)
710 {
711 r[0] = xDomainMin;
712 for (std::size_t i= 0; i<width; ++i)
713 {
714 fval = function(r);
715
716 // we transform the function value to the corresponding point in [0,255]^3
717 Color color = colormap.map(fRangeMin, fRangeMax, fval);
718
719 // colorval >> endl >> PPM
720 for (int c=0; c<3; ++c)
721 if (df==Bin)
722 ppmfile->write(reinterpret_cast<char*>(&(color[c])),sizeof(ColorMap::CType));
723 else
724 (*ppmfile) << int(color[c]) << " ";
725
726 if (df==ASCII)
727 (*ppmfile) << std::endl;
728
729 r[0] = xDomainMin + (i+1)*xLength/(width-1);
730 }
731 r[1] = yDomainMax - (j+1)*yLength/(height-1);
732 }
733
734 // close PPM
735 ppmfile->close();
736 }
737
738 /* \brief evaluates interpolated pixelmap at global point
739 *
740 * The pixelmap is evaluated at point x of the domain \f$ \Omega \f$
741 * assuming a linear transformation \f$ \Omega \longrightarrow [0,width_]\times[0,height_]\f$. The returnvalue is scaled
742 * according to \f$[fRangeMin_,fRangeMax_]\f$.
743 *
744 * \param x point in \f$ \Omega \f$ at which to evaluate
745 * \returns the function value
746 */
748 {
749 if (pixMapFunction_==0)
750 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
751
752 DomainType xx = x;
753
754 xx[0] = (x[0]-xDomainMin_)/(xDomainMax_-xDomainMin_)*(width_-1);
755 xx[1] = (x[1]-yDomainMin_)/(yDomainMax_-yDomainMin_)*(height_-1);
756
757 return (*pixMapFunction_)(xx);
758 }
759
761 {
762 if (ppm.pixMapFunction_==0)
763 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
764 return localFunction(*(ppm.pixMapFunction_));
765 }
766
767 const EntitySet& entitySet() const
768 {
769 if (pixMapFunction_==0)
770 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
771 return pixMapFunction_->entitySet();
772 }
773
774 /* \brief provides read access to the coefficient vector
775 */
776 const CoeffType& getCoeffs() const
777 {
778 if (pixMapFunction_==0)
779 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
780
781 return coeffs_;
782 }
783
784 /* \brief provides access to the grid on which the interpolated pixelmap lives
785 */
786 const GridType& getGrid() const
787 {
788 if (pixMapFunction_==0)
789 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
790
791 return *grid_;
792 }
793
794 /* \brief provides access to the width of the imported pixelmap section
795 */
796 unsigned int getWidth() const
797 {
798 if (pixMapFunction_==0)
799 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
800
801 return width_;
802 }
803
804 /* \brief provides access to the height of the imported pixelmap section
805 */
806 unsigned int getHeight() const
807 {
808 if (pixMapFunction_==0)
809 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
810
811 return height_;
812 }
813
814 /* \brief provides access to the width of the full (original) pixelmap image
815 */
816 unsigned int getImgWidth() const
817 {
818 if (pixMapFunction_==0)
819 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
820
821 return imgParams_[0];
822 }
823
824 /* \brief provides access to the height of the full (original) pixelmap image
825 */
826 unsigned int getImgHeight() const
827 {
828 if (pixMapFunction_==0)
829 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
830
831 return imgParams_[1];
832 }
833
834 /* \brief provides access to the used maximal value in the (original and imported) pixelmap corresponding to white
835 */
836 unsigned int getWhiteValue() const
837 {
838 if (pixMapFunction_==0)
839 DUNE_THROW(Dune::Exception,"No pixelmap has been loaded. Use readPixelMap() first.");
840
841 return imgParams_[2];
842 }
843
844 void exportColormapGraphic(const std::string filename="colormap.ppm") const
845 {
846 colormap_.exportColorMapGraphic(filename);
847 }
848
850 {
851 if (grid_!=0)
852 delete grid_;
853 if (pixMapFunction_!=0)
854 delete pixMapFunction_;
855 if (basis_!=0)
856 delete basis_;
857 }
858};
859
860#endif
861
#define DUNE_THROW(E,...)
constexpr Iterator end()
constexpr FieldTraits< value_type >::real_type one_norm() const
friend friend class Entity
GridViewEntitySet< GridView, 0 > EntitySet
Class to represent a color map.
Definition portablepixelmap.hh:44
void exportColorMapGraphic(const std::string filename="colormap.ppm", IODataFormat df=Bin) const
writes a ppm-file to harddisk as an illustration of the colormap
Definition portablepixelmap.hh:267
std::map< KeyType, Color > ColorKey
The actual type of the ColorKey.
Definition portablepixelmap.hh:77
void exportColorMap(std::string filename="colormap", ColorMapFileFormat format=CM)
writes the colorkey to a file in an own format (.cm)
Definition portablepixelmap.hh:314
IODataFormat
Definition portablepixelmap.hh:54
@ ASCII
Definition portablepixelmap.hh:55
@ Bin
Definition portablepixelmap.hh:56
double inv_map(const double fMin, const double fMax, const Color color)
maps a color to a scalar
Definition portablepixelmap.hh:202
ColorMap(const std::string filename)
Construction from dune-fufem colormap (.cm) File.
Definition portablepixelmap.hh:91
Dune::FieldVector< CType, 3 > Color
The type used to represent the color.
Definition portablepixelmap.hh:68
bool insertInColorKey(const KeyType key, const Color color)
insert keyvalues into the ColorKey
Definition portablepixelmap.hh:140
unsigned short int KeyType
Definition portablepixelmap.hh:61
unsigned char CType
Definition portablepixelmap.hh:60
int size()
Definition portablepixelmap.hh:345
ColorMapFileFormat
Definition portablepixelmap.hh:48
@ CM
Definition portablepixelmap.hh:49
Color map(const double fMin, const double fMax, const double fVal) const
maps a scalar to a color
Definition portablepixelmap.hh:154
ColorMap()
Definition portablepixelmap.hh:80
Class wrapping a portable pixmap (acquired from PPM files) providing it as a piecewise bi-linear Grid...
Definition portablepixelmap.hh:411
typename FunctionType::LocalFunction LocalFunction
Definition portablepixelmap.hh:426
const EntitySet & entitySet() const
Definition portablepixelmap.hh:767
Dune::FieldVector< double, 1 > RangeType
Definition portablepixelmap.hh:419
PortablePixelMap(const DomainType::field_type xDomainMin, const DomainType::field_type xDomainMax, const DomainType::field_type yDomainMin, const DomainType::field_type yDomainMax, const RangeType fRangeMin, const RangeType fRangeMax, const ColorMap colormap)
Constructor.
Definition portablepixelmap.hh:479
IODataFormat
Definition portablepixelmap.hh:432
@ ASCII
Definition portablepixelmap.hh:433
@ Bin
Definition portablepixelmap.hh:434
~PortablePixelMap()
Definition portablepixelmap.hh:849
PortablePixelMap(const RangeType fRangeMin, const RangeType fRangeMax, const ColorMap colormap)
Constructor.
Definition portablepixelmap.hh:501
unsigned int getWhiteValue() const
Definition portablepixelmap.hh:836
Dune::Functions::LagrangeBasis< GridType::LeafGridView, 1 > Basis
Definition portablepixelmap.hh:421
Dune::Functions::DiscreteGlobalBasisFunction< Basis, CoeffType, Dune::Functions::HierarchicNodeToRangeMap, RangeType > FunctionType
Definition portablepixelmap.hh:424
RangeType operator()(const DomainType &x) const
Definition portablepixelmap.hh:747
void exportColormapGraphic(const std::string filename="colormap.ppm") const
Definition portablepixelmap.hh:844
unsigned int getHeight() const
Definition portablepixelmap.hh:806
friend LocalFunction localFunction(const PortablePixelMap &ppm)
Definition portablepixelmap.hh:760
GridType::Codim< 0 >::Geometry::LocalCoordinate LocalDomainType
Definition portablepixelmap.hh:415
unsigned int getWidth() const
Definition portablepixelmap.hh:796
Dune::YaspGrid< 2 > GridType
Definition portablepixelmap.hh:413
unsigned int getImgWidth() const
Definition portablepixelmap.hh:816
typename GridType::template Codim< 0 >::Geometry::GlobalCoordinate DomainType
Definition portablepixelmap.hh:418
Dune::BlockVector< RangeType > CoeffType
Definition portablepixelmap.hh:423
void readPixelMap(const char *filename, const int width=-1, const int height=-1, const int xoffset=0, const int yoffset=0)
reads the specified rectangular section of a pixelmap (PPM)
Definition portablepixelmap.hh:526
unsigned int getImgHeight() const
Definition portablepixelmap.hh:826
const GridType & getGrid() const
Definition portablepixelmap.hh:786
static void exportPixelMap(const char *filename, const FType &function, RangeFieldTypeFor< FType > fRangeMin, RangeFieldTypeFor< FType > fRangeMax, const DomainFieldType xDomainMin, const DomainFieldType xDomainMax, const DomainFieldType yDomainMin, const DomainFieldType yDomainMax, const unsigned int width, const unsigned int height, const std::string info, const ColorMap colormap, IODataFormat df=Bin)
creates a PPM (P3) file from a given scalar function
Definition portablepixelmap.hh:673
typename FunctionType::EntitySet EntitySet
Definition portablepixelmap.hh:427
GridType::Codim< 0 >::Entity Element
Definition portablepixelmap.hh:416
const CoeffType & getCoeffs() const
Definition portablepixelmap.hh:776
T append(T... args)
T atoi(T... args)
T begin(T... args)
T c_str(T... args)
T close(T... args)
T empty(T... args)
T end(T... args)
T endl(T... args)
T eof(T... args)
T erase(T... args)
T fail(T... args)
T find_first_not_of(T... args)
T find(T... args)
T gcount(T... args)
T getline(T... args)
T ignore(T... args)
T insert(T... args)
T lower_bound(T... args)
T make_pair(T... args)
T min(T... args)
T open(T... args)
T push_back(T... args)
T rbegin(T... args)
T read(T... args)
T seekg(T... args)
T size(T... args)
T skipws(T... args)
T write(T... args)