Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
The container registry cleanup task is now completed and the registry can be used normally.
Open sidebar
IP
elsa
Commits
d8a124a2
Commit
d8a124a2
authored
Apr 15, 2022
by
andibraimllari
Committed by
AndiBraimllari
Apr 15, 2022
Browse files
clip a container
parent
4229e118
Pipeline
#873216
failed with stages
in 122 minutes and 43 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
elsa/core/DataContainer.cpp
View file @
d8a124a2
...
...
@@ -609,6 +609,20 @@ namespace elsa
}
}
template
<
typename
data_t
>
DataContainer
<
data_t
>
clip
(
DataContainer
<
data_t
>
dc
,
data_t
min
,
data_t
max
)
{
for
(
int
i
=
0
;
i
<
dc
.
getSize
();
++
i
)
{
if
(
dc
[
i
]
<
min
)
{
dc
[
i
]
=
min
;
}
else
if
(
dc
[
i
]
>
max
)
{
dc
[
i
]
=
max
;
}
}
return
dc
;
}
template
<
typename
data_t
>
DataContainer
<
data_t
>
concatenate
(
const
DataContainer
<
data_t
>&
dc1
,
const
DataContainer
<
data_t
>&
dc2
)
...
...
@@ -693,6 +707,9 @@ namespace elsa
template
class
DataContainer
<
complex
<
double
>
>
;
template
class
DataContainer
<
index_t
>;
template
DataContainer
<
float
>
clip
<
float
>
(
DataContainer
<
float
>
dc
,
float
min
,
float
max
);
template
DataContainer
<
double
>
clip
<
double
>
(
DataContainer
<
double
>
dc
,
double
min
,
double
max
);
template
DataContainer
<
float
>
concatenate
<
float
>
(
const
DataContainer
<
float
>&
,
const
DataContainer
<
float
>&
);
template
DataContainer
<
double
>
concatenate
<
double
>
(
const
DataContainer
<
double
>&
,
...
...
elsa/core/DataContainer.h
View file @
d8a124a2
...
...
@@ -517,6 +517,10 @@ namespace elsa
return
os
;
}
/// clip the container values outside of the interval, to the interval edges
template
<
typename
data_t
>
DataContainer
<
data_t
>
clip
(
DataContainer
<
data_t
>
dc
,
data_t
min
,
data_t
max
);
/// Concatenate two DataContainers to one (requires copying of both)
template
<
typename
data_t
>
DataContainer
<
data_t
>
concatenate
(
const
DataContainer
<
data_t
>&
dc1
,
...
...
elsa/core/tests/test_DataContainer.cpp
View file @
d8a124a2
...
...
@@ -927,6 +927,150 @@ TEST_CASE("DataContainer: Testing iterators for DataContainer")
}
}
TEST_CASE_TEMPLATE
(
"DataContainer: Clip a DataContainer"
,
data_t
,
float
,
double
)
{
GIVEN
(
"some 1D vectors"
)
{
index_t
size
=
7
;
IndexVector_t
numCoeff
(
1
);
numCoeff
<<
size
;
VolumeDescriptor
desc
(
numCoeff
);
data_t
min
=
6
;
data_t
max
=
19
;
Vector_t
<
data_t
>
dataVec1
(
desc
.
getNumberOfCoefficients
());
dataVec1
<<
6
,
10
,
7
,
18
,
10
,
11
,
9
;
Vector_t
<
data_t
>
expectedDataVec1
(
desc
.
getNumberOfCoefficients
());
expectedDataVec1
<<
6
,
10
,
7
,
18
,
10
,
11
,
9
;
Vector_t
<
data_t
>
dataVec2
(
desc
.
getNumberOfCoefficients
());
dataVec2
<<
4
,
-
23
,
7
,
18
,
18
,
10
,
10
;
Vector_t
<
data_t
>
expectedDataVec2
(
desc
.
getNumberOfCoefficients
());
expectedDataVec2
<<
min
,
min
,
7
,
18
,
18
,
10
,
10
;
Vector_t
<
data_t
>
dataVec3
(
desc
.
getNumberOfCoefficients
());
dataVec3
<<
14
,
23
,
7
,
18
,
20
,
10
,
10
;
Vector_t
<
data_t
>
expectedDataVec3
(
desc
.
getNumberOfCoefficients
());
expectedDataVec3
<<
14
,
max
,
7
,
18
,
max
,
10
,
10
;
Vector_t
<
data_t
>
dataVec4
(
desc
.
getNumberOfCoefficients
());
dataVec4
<<
1
,
23
,
5
,
28
,
20
,
30
,
0
;
Vector_t
<
data_t
>
expectedDataVec4
(
desc
.
getNumberOfCoefficients
());
expectedDataVec4
<<
min
,
max
,
min
,
max
,
max
,
max
,
min
;
WHEN
(
"creating a data container out of a vector within bounds"
)
{
DataContainer
dc
(
desc
,
dataVec1
);
auto
clipped
=
clip
(
dc
,
min
,
max
);
THEN
(
"the size of the clipped DataContainer is equal to that of the original container"
)
{
REQUIRE_EQ
(
clipped
.
getSize
(),
size
);
}
THEN
(
"the values correspond to the original DataContainers"
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
INFO
(
"Error at position: "
,
i
);
REQUIRE_EQ
(
clipped
[
i
],
expectedDataVec1
[
i
]);
}
}
}
WHEN
(
"creating a data container out of a vector within or lower than the bounds"
)
{
DataContainer
dc
(
desc
,
dataVec2
);
auto
clipped
=
clip
(
dc
,
min
,
max
);
THEN
(
"the size of the clipped DataContainer is equal to that of the original container"
)
{
REQUIRE_EQ
(
clipped
.
getSize
(),
size
);
}
THEN
(
"the values correspond to the original DataContainers"
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
INFO
(
"Error at position: "
,
i
);
REQUIRE_EQ
(
clipped
[
i
],
expectedDataVec2
[
i
]);
}
}
}
WHEN
(
"creating a data container out of a vector within or higher than the bounds"
)
{
DataContainer
dc
(
desc
,
dataVec3
);
auto
clipped
=
clip
(
dc
,
min
,
max
);
THEN
(
"the size of the clipped DataContainer is equal to that of the original container"
)
{
REQUIRE_EQ
(
clipped
.
getSize
(),
size
);
}
THEN
(
"the values correspond to the original DataContainers"
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
INFO
(
"Error at position: "
,
i
);
REQUIRE_EQ
(
clipped
[
i
],
expectedDataVec3
[
i
]);
}
}
}
WHEN
(
"creating a data container out of a vector outside the bounds"
)
{
DataContainer
dc
(
desc
,
dataVec4
);
auto
clipped
=
clip
(
dc
,
min
,
max
);
THEN
(
"the size of the clipped DataContainer is equal to that of the original container"
)
{
REQUIRE_EQ
(
clipped
.
getSize
(),
size
);
}
THEN
(
"the values correspond to the original DataContainers"
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
INFO
(
"Error at position: "
,
i
);
REQUIRE_EQ
(
clipped
[
i
],
expectedDataVec4
[
i
]);
}
}
}
}
GIVEN
(
"a 2D data container"
)
{
IndexVector_t
numCoeff
(
2
);
numCoeff
<<
3
,
2
;
VolumeDescriptor
desc
(
numCoeff
);
data_t
min
=
0
;
data_t
max
=
8
;
Vector_t
<
data_t
>
dataVec
(
desc
.
getNumberOfCoefficients
());
dataVec
<<
-
19
,
-
23
,
7
,
8
,
20
,
1
;
Vector_t
<
data_t
>
expectedDataVec
(
desc
.
getNumberOfCoefficients
());
expectedDataVec
<<
min
,
min
,
7
,
8
,
max
,
1
;
WHEN
(
"creating a data container out of a vector within and outside of both bounds"
)
{
DataContainer
dc
(
desc
,
dataVec
);
auto
clipped
=
clip
(
dc
,
min
,
max
);
THEN
(
"the size of the clipped DataContainer is equal to that of the original container"
)
{
REQUIRE_EQ
(
clipped
.
getSize
(),
desc
.
getNumberOfCoefficients
());
}
THEN
(
"the values correspond to the original DataContainers"
)
{
for
(
int
i
=
0
;
i
<
desc
.
getNumberOfCoefficients
();
++
i
)
{
INFO
(
"Error at position: "
,
i
);
REQUIRE_EQ
(
clipped
[
i
],
expectedDataVec
[
i
]);
}
}
}
}
}
TEST_CASE_TEMPLATE
(
"DataContainer: Concatenate two DataContainers"
,
data_t
,
float
,
double
,
complex
<
float
>
,
complex
<
double
>
)
{
...
...
Write
Preview
Supports
Markdown
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