PngReader.h 1.99 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.



/** \file ValueReader.h */

#ifndef AMDIS_VALUEREADER_H
#define AMDIS_VALUEREADER_H

#include "AMDiS.h"

namespace AMDiS {

  /** \ingroup Input
   *  
   * \brief
   * Static class which reads a png file and gets values for each pixel
   */ 
  class PngReader
  {
  public:
    /// Copies the values of a value file to a DOF vector.
Praetorius, Simon's avatar
Praetorius, Simon committed
39
    static void readValues(std::string filename,
Praetorius, Simon's avatar
Praetorius, Simon committed
40
			  DOFVector<double> *dofVector);
Praetorius, Simon's avatar
Praetorius, Simon committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

  private:
    
    static void getMeshDimension(Mesh* mesh, double &xMin, double &xMax, double &yMin, double &yMax)
    {
      WorldVector<double> minDim; minDim.set(1.e10);
      WorldVector<double> maxDim; maxDim.set(-1.e10);

      TraverseStack stack;
      ElInfo *elInfo = stack.traverseFirst(mesh, 0, Mesh::CALL_EL_LEVEL | Mesh::FILL_COORDS);
      while (elInfo) {
	for (int i = 0; i <= mesh->getDim(); i++) {
	  WorldVector<double> &coords = elInfo->getMacroElement()->getCoord(i);
	  for (int j = 0; j < coords.getSize(); ++j) {
	    minDim[j] = std::min(minDim[j], coords[j]);
	    maxDim[j] = std::max(maxDim[j], coords[j]);
	  }
	}
	elInfo = stack.traverseNext(elInfo);
      }

      xMin = minDim[0]; xMax = maxDim[0];
      yMin = minDim[1]; yMax = maxDim[1];
    };
Praetorius, Simon's avatar
Praetorius, Simon committed
65
66
67
68

}

#endif