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
Olena
pylene
Commits
6ce9514e
Commit
6ce9514e
authored
Sep 18, 2021
by
Baptiste Esteban
Browse files
Solve too much errors + start working on tests
parent
cd21b3b6
Pipeline
#30144
failed with stages
in 1 minute and 57 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
pylene/CMakeLists.txt
View file @
6ce9514e
...
...
@@ -107,13 +107,14 @@ add_library(Pylene-io-fits)
add_library
(
Pylene::IO-fits ALIAS Pylene-io-fits
)
target_sources
(
Pylene-io-fits PRIVATE
src/io/cfitsio_plugin.cpp
src/io/io.cpp
)
target_compile_features
(
Pylene-io-fits PUBLIC cxx_std_20
)
target_include_directories
(
Pylene-io-fits PUBLIC
$<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries
(
Pylene-io-f
reeimage
PUBLIC cfitsio::cfitsio Pylene-core
)
target_link_libraries
(
Pylene-io-f
its
PUBLIC cfitsio::cfitsio Pylene-core
)
# Compiler configurations
target_compile_features
(
Pylene-core PUBLIC cxx_std_20
)
...
...
pylene/src/io/cfitsio_plugin.cpp
View file @
6ce9514e
#include <mln/core/image/ndimage.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/private/cfitsio_plugin.hpp>
#include <mln/io/private/io.hpp>
#include <fitsio.h>
#include <fmt/format.h>
...
...
@@ -6,8 +10,10 @@
#include <stdexcept>
#include <tuple>
namespace
mln
::
io
::
fits
::
internal
namespace
mln
::
io
::
fits
{
namespace
internal
{
namespace
{
std
::
pair
<
mln
::
sample_type_id
,
int
>
get_type_info
(
int
type
)
...
...
@@ -42,13 +48,13 @@ namespace mln::io::fits::internal
{
int
anynul
;
int
nullpix
=
0
;
int
status
;
int
status
=
0
;
fits_read_img
(
file
,
datatype
,
m_line
*
m_dims
[
0
]
+
1
,
m_dims
[
0
],
&
nullpix
,
buffer
,
&
anynul
,
&
status
);
if
(
status
)
{
char
msg
[
80
];
fits_get_errstatus
(
status
,
msg
);
throw
std
::
runtime_error
(
fmt
::
format
(
"Unable to
write
the image ({})"
,
msg
));
throw
std
::
runtime_error
(
fmt
::
format
(
"Unable to
read
the image ({})"
,
msg
));
}
m_line
++
;
}
...
...
@@ -69,7 +75,7 @@ namespace mln::io::fits::internal
void
cfitsio_reader_plugin
::
open
(
const
char
*
filename
)
{
int
status
;
int
status
=
0
;
// Open the file
fitsfile
*
file
;
...
...
@@ -79,7 +85,7 @@ namespace mln::io::fits::internal
// Go to the index of the image
fits_movrel_hdu
(
file
,
m_image_index
,
nullptr
,
&
status
);
if
(
!
status
)
if
(
status
)
throw
std
::
runtime_error
(
fmt
::
format
(
"Could not find the image at index {}"
,
m_image_index
));
// Check if the HDU is an image
...
...
@@ -109,6 +115,7 @@ namespace mln::io::fits::internal
for
(
int
i
=
0
;
i
<
ndim
;
i
++
)
impl
->
m_dims
[
i
]
=
dims
[
i
];
impl
->
m_sample_type_id
=
sample_type
;
impl
->
datatype
=
datatype
;
this
->
m_impl
=
std
::
move
(
impl
);
}
...
...
@@ -123,4 +130,18 @@ namespace mln::io::fits::internal
impl
->
file
=
nullptr
;
}
}
}
// namespace mln::io::fits::internal
\ No newline at end of file
}
// namespace internal
mln
::
ndbuffer_image
imread
(
const
std
::
string
&
filename
,
int
ind
)
{
mln
::
ndbuffer_image
out
;
imread
(
filename
,
out
,
ind
);
return
out
;
}
void
imread
(
const
std
::
string
&
filename
,
mln
::
ndbuffer_image
&
out
,
int
ind
)
{
internal
::
cfitsio_reader_plugin
p
(
ind
);
mln
::
io
::
internal
::
load
(
&
p
,
filename
.
c_str
(),
out
);
}
}
// namespace mln::io::fits
\ No newline at end of file
pylene/src/io/imread.cpp
View file @
6ce9514e
...
...
@@ -19,20 +19,4 @@ namespace mln::io
internal
::
freeimage_reader_plugin
p
;
internal
::
load
(
&
p
,
filename
.
c_str
(),
out
);
}
namespace
fits
{
mln
::
ndbuffer_image
imread
(
const
std
::
string
&
filename
,
int
ind
=
0
)
{
mln
::
ndbuffer_image
out
;
imread
(
filename
,
out
,
ind
);
return
out
;
}
void
imread
(
const
std
::
string
&
filename
,
mln
::
ndbuffer_image
&
out
,
int
ind
=
0
)
{
internal
::
cfitsio_reader_plugin
p
(
ind
);
mln
::
io
::
internal
::
load
(
&
p
,
filename
.
c_str
(),
out
);
}
}
// namespace fits
}
// namespace mln::io
tests/io/CMakeLists.txt
View file @
6ce9514e
add_core_test
(
UTIo_freeimage freeimage.cpp
)
add_core_test
(
UTIo_imprint imprint.cpp
)
add_core_test
(
UTIo_cfitsio cfitsio.cpp
)
target_link_libraries
(
UTIo_cfitsio PUBLIC Pylene::IO-fits
)
\ No newline at end of file
tests/io/cfitsio.cpp
0 → 100644
View file @
6ce9514e
#include <mln/io/imread.hpp>
#include <fixtures/ImageCompare/image_compare.hpp>
#include <fixtures/ImagePath/image_path.hpp>
#include <gtest/gtest.h>
static
const
auto
filename
=
fixtures
::
ImagePath
::
concat_with_filename
(
"test.fit"
);
TEST
(
IO
,
cfitsio_not_an_image
)
{
bool
has_raised
=
false
;
try
{
auto
img
=
mln
::
io
::
fits
::
imread
(
filename
,
0
);
(
void
)
img
;
}
catch
(
std
::
runtime_error
&
)
{
has_raised
=
true
;
}
ASSERT_TRUE
(
has_raised
);
}
TEST
(
IO
,
cfitsio_2D_uint8
)
{
auto
img
=
mln
::
io
::
fits
::
imread
(
filename
,
1
);
ASSERT_TRUE
(
img
.
sample_type
()
==
mln
::
sample_type_id
::
UINT8
);
}
TEST
(
IO
,
cfitsio_2D_int16
)
{
auto
img
=
mln
::
io
::
fits
::
imread
(
filename
,
2
);
ASSERT_TRUE
(
img
.
sample_type
()
==
mln
::
sample_type_id
::
INT16
);
}
TEST
(
IO
,
cfitsio_2D_int32
)
{
auto
img
=
mln
::
io
::
fits
::
imread
(
filename
,
3
);
ASSERT_TRUE
(
img
.
sample_type
()
==
mln
::
sample_type_id
::
INT32
);
}
TEST
(
IO
,
cfitsio_2D_int64
)
{
auto
img
=
mln
::
io
::
fits
::
imread
(
filename
,
4
);
ASSERT_TRUE
(
img
.
sample_type
()
==
mln
::
sample_type_id
::
INT64
);
}
TEST
(
IO
,
cfitsio_2D_float
)
{
auto
img
=
mln
::
io
::
fits
::
imread
(
filename
,
5
);
ASSERT_TRUE
(
img
.
sample_type
()
==
mln
::
sample_type_id
::
FLOAT
);
}
TEST
(
IO
,
cfitsio_2D_double
)
{
auto
img
=
mln
::
io
::
fits
::
imread
(
filename
,
6
);
ASSERT_TRUE
(
img
.
sample_type
()
==
mln
::
sample_type_id
::
DOUBLE
);
}
\ No newline at end of file
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