diff --git a/AMDiS/src/io/PngReader.cc b/AMDiS/src/io/PngReader.cc index 5673bf4fa21206dac7c1f5a1214ba2e5ca2f71df..56048cdc8b666e4617081d60c63e72daa9d8db49 100644 --- a/AMDiS/src/io/PngReader.cc +++ b/AMDiS/src/io/PngReader.cc @@ -17,7 +17,7 @@ namespace AMDiS { /** \brief * Copies the values of a value file to a DOF vector. */ - void PngReader::readValue(std::string filename, + void PngReader::readValues(std::string filename, DOFVector<double> *vec) { FUNCNAME("ValueReader::readValue()"); @@ -67,6 +67,9 @@ namespace AMDiS { const BasisFunction *basFcts = vec->getFeSpace()->getBasisFcts(); int numBasFcts = basFcts->getNumber(); DegreeOfFreedom *localIndices = new DegreeOfFreedom[numBasFcts]; + + double xMin = 0.0, xMax = 1.0, yMin = 0.0, yMax = 1.0; + getMeshDimension(vec->getFeSpace()->getMesh(), xMin, xMax, yMin, yMax); TraverseStack stack; ElInfo *elInfo = stack.traverseFirst(vec->getFeSpace()->getMesh(), -1, @@ -78,8 +81,10 @@ namespace AMDiS { basFcts->getLocalIndices(el, vec->getFeSpace()->getAdmin(), localIndices); for (int i = 0; i < numBasFcts; i++) { - col = static_cast<int>(((elInfo->getCoords())[i][0])*(info_ptr->width-1)); - row = static_cast<int>((1.0-(elInfo->getCoords())[i][1])*(info_ptr->height-1)); + double lambdaX = ((elInfo->getCoords())[i][0] - xMin)/(xMax - xMin); + double lambdaY = ((elInfo->getCoords())[i][1] - yMin)/(yMax - yMin); + col = static_cast<int>(lambdaX*(info_ptr->width-1)); + row = static_cast<int>((1.0-lambdaY)*(info_ptr->height-1)); switch (bytesPerPixel) { case 1: value = static_cast<double>(info_ptr->row_pointers[row][col]); diff --git a/AMDiS/src/io/PngReader.h b/AMDiS/src/io/PngReader.h index 553dde1a8c42707ce785146b568c5fe5510e0037..b404a34196e074ea29337e5823a231315425e1c9 100644 --- a/AMDiS/src/io/PngReader.h +++ b/AMDiS/src/io/PngReader.h @@ -36,9 +36,32 @@ namespace AMDiS { { public: /// Copies the values of a value file to a DOF vector. - static void readValue(std::string filename, + static void readValues(std::string filename, DOFVector<double> *dofVector); - }; + + 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]; + }; }