Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
iMSTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ben Boeckel
iMSTK
Commits
c9d6ef46
Commit
c9d6ef46
authored
3 years ago
by
Harald Scheirich
Browse files
Options
Downloads
Patches
Plain Diff
Replace image cast with new calls
parent
50712cb4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Source/Geometry/Mesh/imstkImageData.cpp
+3
-38
3 additions, 38 deletions
Source/Geometry/Mesh/imstkImageData.cpp
Source/Geometry/Testing/imstkImageDataTest.cpp
+78
-0
78 additions, 0 deletions
Source/Geometry/Testing/imstkImageDataTest.cpp
with
81 additions
and
38 deletions
Source/Geometry/Mesh/imstkImageData.cpp
+
3
−
38
View file @
c9d6ef46
...
...
@@ -25,35 +25,6 @@
namespace
imstk
{
template
<
typename
FROM_TYPE
,
typename
TO_TYPE
>
static
void
castArray
(
std
::
shared_ptr
<
DataArray
<
FROM_TYPE
>>
fromArray
,
std
::
shared_ptr
<
DataArray
<
TO_TYPE
>>
toArray
)
{
const
DataArray
<
FROM_TYPE
>&
fromArrayRef
=
*
fromArray
;
DataArray
<
TO_TYPE
>&
toArrayRef
=
*
toArray
;
const
size_t
numVals
=
fromArray
->
size
();
for
(
size_t
i
=
0
;
i
<
numVals
;
i
++
)
{
toArrayRef
[
i
]
=
static_cast
<
TO_TYPE
>
(
fromArrayRef
[
i
]);
}
}
template
<
typename
FROM_TYPE
>
static
void
castImage
(
std
::
shared_ptr
<
AbstractDataArray
>
fromScalars
,
std
::
shared_ptr
<
ImageData
>
toImage
)
{
const
ScalarType
toType
=
toImage
->
getScalars
()
->
getScalarType
();
switch
(
toType
)
{
TemplateMacro
(
castArray
(
std
::
dynamic_pointer_cast
<
DataArray
<
FROM_TYPE
>>
(
fromScalars
),
std
::
dynamic_pointer_cast
<
DataArray
<
IMSTK_TT
>>
(
toImage
->
getScalars
()));
);
default:
LOG
(
WARNING
)
<<
"Unknown scalar type"
;
break
;
}
;
}
ImageData
::
ImageData
(
const
std
::
string
&
name
)
:
PointSet
(
name
),
...
...
@@ -95,15 +66,9 @@ ImageData::cast(ScalarType toType)
{
// Create image of new type
std
::
shared_ptr
<
ImageData
>
results
=
std
::
make_shared
<
ImageData
>
();
results
->
allocate
(
toType
,
m_numComps
,
m_dims
,
m_spacing
,
m_origin
);
switch
(
m_scalarArray
->
getScalarType
())
{
TemplateMacro
(
castImage
<
IMSTK_TT
>
(
m_scalarArray
,
results
);
);
default:
LOG
(
WARNING
)
<<
"Unknown scalar type"
;
break
;
}
;
results
->
setOrigin
(
m_origin
);
results
->
setSpacing
(
m_spacing
);
results
->
setScalars
(
getScalars
()
->
cast
(
toType
),
m_numComps
,
m_dims
.
data
());
return
results
;
}
...
...
This diff is collapsed.
Click to expand it.
Source/Geometry/Testing/imstkImageDataTest.cpp
0 → 100644
+
78
−
0
View file @
c9d6ef46
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#include
"gtest/gtest.h"
#include
<memory>
#include
"imstkImageData.h"
#include
"imstkVecDataArray.h"
#include
"imstkMath.h"
using
namespace
imstk
;
namespace
{
VecDataArray
<
double
,
3
>
doubleArray
=
{
Vec3d
{
0
,
0
,
0
},
Vec3d
{
1
,
1
,
1
},
Vec3d
{
2
,
2
,
2
},
Vec3d
{
3
,
3
,
3
}
};
DataArray
<
int
>
intScalars
=
{
1
,
2
,
3
,
4
};
DataArray
<
double
>
doubleScalars
=
{
1.0
,
2.0
,
3.0
,
4.0
};
}
TEST
(
imstkImageDataTest
,
Cast
)
{
Vec3i
dim
=
{
2
,
2
,
0
};
Vec3d
spacing
=
{
1.0
,
2.0
,
3.0
};
Vec3d
origin
=
{
4.0
,
5.0
,
6.0
};
ImageData
img
;
img
.
setScalars
(
std
::
make_shared
<
DataArray
<
int
>>
(
intScalars
),
1
,
dim
.
data
());
img
.
setSpacing
(
spacing
);
img
.
setOrigin
(
origin
);
EXPECT_EQ
(
IMSTK_INT
,
img
.
getScalarType
());
auto
castImg
=
img
.
cast
(
IMSTK_DOUBLE
);
auto
newScalars
=
castImg
->
getScalars
();
EXPECT_EQ
(
IMSTK_DOUBLE
,
newScalars
->
getScalarType
());
auto
actualScalars
=
std
::
dynamic_pointer_cast
<
DataArray
<
double
>>
(
newScalars
);
EXPECT_TRUE
(
actualScalars
!=
nullptr
);
EXPECT_TRUE
(
dim
.
isApprox
(
castImg
->
getDimensions
()));
EXPECT_TRUE
(
spacing
.
isApprox
(
castImg
->
getSpacing
()));
EXPECT_TRUE
(
origin
.
isApprox
(
castImg
->
getOrigin
()));
for
(
int
i
=
0
;
i
<
actualScalars
->
size
();
++
i
)
{
EXPECT_DOUBLE_EQ
(
static_cast
<
double
>
(
intScalars
[
i
]),
(
*
actualScalars
)[
i
]);
}
}
int
imstkImageDataTest
(
int
argc
,
char
*
argv
[])
{
// Init Google Test & Mock
::
testing
::
InitGoogleTest
(
&
argc
,
argv
);
// Run tests with gtest
return
RUN_ALL_TESTS
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment