Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KiT-RT
KiT-RT
Commits
9281d43d
Commit
9281d43d
authored
Nov 30, 2020
by
jannick.wolters
Browse files
fixed image_conversion tests
parent
8ae90316
Changes
2
Hide whitespace changes
Inline
Side-by-side
code/src/toolboxes/interpolation.cpp
View file @
9281d43d
...
...
@@ -20,7 +20,7 @@ Interpolation::Interpolation( const Vector& x, const Vector& y, const Matrix& da
// Set-up: check validity of input
void
Interpolation
::
Setup
()
{
// 1D
// 1D
if
(
_dim
==
1u
)
{
// Length of tables must be equal
if
(
_x
.
size
()
!=
_y
.
size
()
)
ErrorMessages
::
Error
(
"Vectors are of unequal length!"
,
CURRENT_FUNCTION
);
...
...
@@ -28,7 +28,7 @@ void Interpolation::Setup() {
// Values must be sorted ascendingly (property is used later when searching tables)
for
(
unsigned
i
=
0
;
i
<
_x
.
size
()
-
1u
;
i
++
)
{
if
(
!
(
_x
[
i
]
<
_x
[
i
+
1
]
)
)
ErrorMessages
::
Error
(
"x is not sorted ascendingly!"
,
CURRENT_FUNCTION
);
if
(
!
(
_x
[
i
]
<
_x
[
i
+
1
]
)
)
ErrorMessages
::
Error
(
"x is not sorted ascendingly!"
,
CURRENT_FUNCTION
);
}
}
...
...
@@ -37,7 +37,7 @@ void Interpolation::Setup() {
// Length of tables must be equal
if
(
_x
.
size
()
!=
_data
.
rows
()
)
ErrorMessages
::
Error
(
"x and data are of unequal length!"
,
CURRENT_FUNCTION
);
if
(
_y
.
size
()
!=
_data
.
columns
()
)
ErrorMessages
::
Error
(
"y and data are of unequal length!"
,
CURRENT_FUNCTION
);
// Values must be sorted ascendingly (property is used later when searching tables)
for
(
unsigned
i
=
0
;
i
<
_x
.
size
()
-
1u
;
i
++
)
{
if
(
!
(
_x
[
i
]
<
_x
[
i
+
1
]
)
)
ErrorMessages
::
Error
(
"x is not sorted ascendingly!"
,
CURRENT_FUNCTION
);
...
...
@@ -50,7 +50,7 @@ void Interpolation::Setup() {
// 1D interpolation
double
Interpolation
::
operator
()(
double
x
)
const
{
// Check whether 1D
// Check whether 1D
if
(
_dim
!=
1u
)
ErrorMessages
::
Error
(
"Invalid data dimension for operator(x)!"
,
CURRENT_FUNCTION
);
// x must be between min and max of table values
if
(
x
<
_x
[
0
]
||
x
>
_x
[
_x
.
size
()
-
1u
]
)
ErrorMessages
::
Error
(
"Extrapolation is not supported!"
,
CURRENT_FUNCTION
);
...
...
@@ -94,7 +94,7 @@ double Interpolation::operator()( double x, double y ) const {
unsigned
xId
=
IndexOfClosestValue
(
x
,
_x
);
unsigned
yId
=
IndexOfClosestValue
(
y
,
_y
);
// store all 16 interpolation points needed
// store all 16 interpolation points needed
double
points
[
4
][
4
];
for
(
int
i
=
-
1
;
i
<
3
;
++
i
)
{
unsigned
idx_y
;
...
...
@@ -127,7 +127,7 @@ double Interpolation::operator()( double x, double y ) const {
}
}
// extension of 1D interpolation to Vector input
// extension of 1D interpolation to Vector input
Vector
Interpolation
::
operator
()(
Vector
v
)
const
{
Vector
res
(
v
.
size
()
);
for
(
unsigned
i
=
0
;
i
<
v
.
size
();
++
i
)
{
...
...
@@ -153,8 +153,7 @@ inline double Interpolation::EvalCubic1DSpline( double param[4], double x ) cons
x
*
(
3.0
*
(
param
[
1
]
-
param
[
2
]
)
+
param
[
3
]
-
param
[
0
]
)
)
)
);
}
//find index of closes value to 'value' in vector 'v'
// find index of closes value to 'value' in vector 'v'
unsigned
Interpolation
::
IndexOfClosestValue
(
double
value
,
const
Vector
&
v
)
const
{
auto
i
=
std
::
min_element
(
begin
(
v
),
end
(
v
),
[
=
](
double
x
,
double
y
)
{
return
abs
(
x
-
value
)
<
abs
(
y
-
value
);
}
);
return
std
::
distance
(
begin
(
v
),
i
);
...
...
code/tests/test_image_conversion.cpp
View file @
9281d43d
...
...
@@ -9,14 +9,15 @@
#include "toolboxes/textprocessingtoolbox.h"
TEST_CASE
(
"convert image data to grayscale matrix"
,
"[image I/O]"
)
{
std
::
string
config_file_name
=
"../tests/
input/image_conversion.cfg"
;
std
::
string
config_file_name
=
std
::
string
(
TESTS_PATH
)
+
"
input/image_conversion.cfg"
;
Config
*
config
=
new
Config
(
config_file_name
);
// just to init spdlog
std
::
string
testImage
=
"../tests/
input/mini_phantom.png"
;
std
::
string
testImage
=
std
::
string
(
TESTS_PATH
)
+
"
input/mini_phantom.png"
;
std
::
string
testMesh
=
config
->
GetMeshFile
();
Matrix
gsImage
=
createSU2MeshFromImage
(
testImage
,
testMesh
);
gsImage
.
transpose
();
SECTION
(
"grayscale matrix"
)
{
REQUIRE
(
std
::
filesystem
::
exists
(
testMesh
)
);
// mesh has been created
REQUIRE
(
gsImage
.
rows
()
>
0
);
// atleast some data is stored
...
...
@@ -66,11 +67,9 @@ TEST_CASE( "convert image data to grayscale matrix", "[image I/O]" ) {
unsigned
m
=
gsImage
.
rows
();
unsigned
n
=
gsImage
.
columns
();
Vector
x
(
m
+
1
),
y
(
n
+
1
);
for
(
unsigned
i
=
0
;
i
<
m
+
1
;
++
i
)
{
x
[
i
]
=
static_cast
<
double
>
(
i
)
/
static_cast
<
double
>
(
m
)
*
(
xMax
-
xMin
);
}
for
(
unsigned
i
=
0
;
i
<
n
+
1
;
++
i
)
y
[
i
]
=
static_cast
<
double
>
(
i
)
/
static_cast
<
double
>
(
n
)
*
(
yMax
-
yMin
);
Vector
x
(
m
),
y
(
n
);
for
(
unsigned
i
=
0
;
i
<
m
;
++
i
)
x
[
i
]
=
static_cast
<
double
>
(
i
)
/
static_cast
<
double
>
(
m
-
1
)
*
(
xMax
-
xMin
);
for
(
unsigned
i
=
0
;
i
<
n
;
++
i
)
y
[
i
]
=
static_cast
<
double
>
(
i
)
/
static_cast
<
double
>
(
n
-
1
)
*
(
yMax
-
yMin
);
Interpolation
interp
(
x
,
y
,
gsImage
);
std
::
vector
<
double
>
result
(
mesh
->
GetNumCells
(),
0.0
);
...
...
jannick.wolters
@jm2154
mentioned in commit
d089a099
·
Apr 30, 2021
mentioned in commit
d089a099
mentioned in commit d089a09907614bd8884ea5fe6823ec962b0d3cba
Toggle commit list
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