Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Backofen, Rainer
amdis
Commits
9878746e
Commit
9878746e
authored
Nov 07, 2011
by
Praetorius, Simon
Browse files
PngReader added to io
parent
2459d26c
Changes
2
Hide whitespace changes
Inline
Side-by-side
AMDiS/src/io/PngReader.cc
0 → 100644
View file @
9878746e
//
// 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/src/io/PngReader.h
0 → 100644
View file @
9878746e
// ============================================================================
// == ==
// == 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment