Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer, es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Ein Anmelden über dieses erzeugt ein neues Konto. Das alte Konto ist über den Reiter "Standard" erreichbar. Die Administratoren

Dear Gitlab user, it is now possible to log in to our service using the ZIH login/LDAP. Logging in via this will create a new account. The old account can be accessed via the "Standard" tab. The administrators

Commit 9878746e authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

PngReader added to io

parent 2459d26c
//
// 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.
#include "PngReader.h"
#include "png.h"
namespace AMDiS {
/** \brief
* Copies the values of a value file to a DOF vector.
*/
void PngReader::readValue(std::string filename,
DOFVector<double> *vec)
{
FUNCNAME("ValueReader::readValue()");
TEST_EXIT(filename != "")("Filename not specified!\n");
TEST_EXIT(vec)("no DOF vector specified\n");
png_structp png_ptr;
png_infop info_ptr;
FILE *fp;
unsigned int sig_read = 0;
int row, col, nVertices, nElements;
int bytesPerPixel = 0;
// Open files and create the png data structures.
if ((fp = fopen(filename.c_str(), "rb")) == NULL)
TEST_EXIT(0)("ERROR: file can not be opened\n");
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
TEST_EXIT(0)("ERROR in png_create_read_struct\n");
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
TEST_EXIT(0)("ERROR in png_create_info_struct\n");
if (setjmp(png_jmpbuf(png_ptr)))
TEST_EXIT(0)("ERROR in png_jmpbuf\n");
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, sig_read);
// Read the whole png at once to the pointer info_ptr.
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
bytesPerPixel = info_ptr->rowbytes / info_ptr->width;
cout << "Read image: " << filename << endl;
cout << "Size: " << info_ptr->width << " x " << info_ptr->height << " pixel" << endl;
cout << "Bytes per pixel: " << bytesPerPixel << endl;
double value = 0;
const DOFAdmin* admin = vec->getFeSpace()->getAdmin();
int n0 = admin->getNumberOfPreDofs(VERTEX); //offset zum globale DOF-managment
int dim = vec->getFeSpace()->getMesh()->getDim();
int dow = Global::getGeo(WORLD);
const BasisFunction *basFcts = vec->getFeSpace()->getBasisFcts();
int numBasFcts = basFcts->getNumber();
DegreeOfFreedom *localIndices = new DegreeOfFreedom[numBasFcts];
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirst(vec->getFeSpace()->getMesh(), -1,
Mesh::CALL_LEAF_EL |
Mesh::FILL_COORDS);
while (elInfo) {
const DegreeOfFreedom **dof = elInfo->getElement()->getDof();
Element *el = elInfo->getElement();
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));
switch (bytesPerPixel) {
case 1:
value = static_cast<double>(info_ptr->row_pointers[row][col]);
break;
case 3:
value =
1.0/3.0/255.0 * (static_cast<double>(info_ptr->row_pointers[row][3*col]) +
static_cast<double>(info_ptr->row_pointers[row][col*3 + 1]) +
static_cast<double>(info_ptr->row_pointers[row][col*3 + 2]));
break;
default:
TEST_EXIT(false)("ERROR: bytesPerPixel=%d is unknown case!\n",bytesPerPixel)
}
(*vec)[localIndices[i]] = value;
}
elInfo = stack.traverseNext(elInfo);
}
delete [] localIndices;
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return(0);
}
}
// ============================================================================
// == ==
// == 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.
static void readValue(std::string filename,
DOFVector<double> *dofVector);
};
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment