Skip to content
GitLab
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
cd21b3b6
Commit
cd21b3b6
authored
Sep 17, 2021
by
Baptiste Esteban
Browse files
Start working on FITS plugin
parent
c3203a3b
Pipeline
#30133
failed with stages
in 3 minutes and 11 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
conanfile.py
View file @
cd21b3b6
...
...
@@ -32,7 +32,8 @@ class Pylene(ConanFile):
"fmt/6.0.0"
,
"tbb/2020.0"
,
"xsimd/7.4.6"
,
"boost/1.75.0"
"boost/1.75.0"
,
"cfitsio/4.0.0"
]
def
_build_python
(
self
):
...
...
@@ -71,7 +72,7 @@ class Pylene(ConanFile):
self
.
cpp_info
.
components
[
"Core"
].
includedirs
=
[
"include"
]
self
.
cpp_info
.
components
[
"Core"
].
requires
=
[
"range-v3::range-v3"
,
"fmt::fmt"
,
"tbb::tbb"
,
"xsimd::xsimd"
,
"boost::headers"
]
# IO component
# IO component
(FreeImage)
self
.
cpp_info
.
components
[
"IO-freeimage"
].
system_libs
.
append
(
"freeimage"
)
self
.
cpp_info
.
components
[
"IO-freeimage"
].
names
[
"cmake_find_package"
]
=
"IO-freeimage"
self
.
cpp_info
.
components
[
"IO-freeimage"
].
names
[
"cmake_find_package_multi"
]
=
"IO-freeimage"
...
...
@@ -79,6 +80,14 @@ class Pylene(ConanFile):
self
.
cpp_info
.
components
[
"IO-freeimage"
].
includedirs
=
[
"include"
]
self
.
cpp_info
.
components
[
"IO-freeimage"
].
requires
=
[
"Core"
]
# IO component (cfitsio)
self
.
cpp_info
.
components
[
"IO-fits"
].
names
[
"cmake_find_package"
]
=
"IO-fits"
self
.
cpp_info
.
components
[
"IO-fits"
].
names
[
"cmake_find_package_multi"
]
=
"IO-fits"
self
.
cpp_info
.
components
[
"IO-fits"
].
libs
=
[
"Pylene-io-fits"
]
self
.
cpp_info
.
components
[
"IO-fits"
].
includedirs
=
[
"include"
]
self
.
cpp_info
.
components
[
"IO-fits"
].
requires
=
[
"Core"
,
"cfitsio::cfitsio"
]
# Pylene-numpy component
if
self
.
_build_python
():
self
.
cpp_info
.
components
[
"Pylene-numpy"
].
names
[
"cmake_find_pakage_multi"
]
=
"Pylene-numpy"
...
...
img/test.fit
0 → 100644
View file @
cd21b3b6
File added
pylene/CMakeLists.txt
View file @
cd21b3b6
...
...
@@ -7,6 +7,7 @@ find_package(TBB REQUIRED tbb)
find_package
(
range-v3 0.10.0 REQUIRED
)
find_package
(
fmt 6.0 REQUIRED
)
find_package
(
xsimd REQUIRED
)
find_package
(
cfitsio REQUIRED
)
set
(
PYLENE_USE_TBB YES CACHE BOOL
"Set to NO to disable use of TBB and parallelization"
)
...
...
@@ -102,6 +103,18 @@ target_include_directories(Pylene-io-freeimage PUBLIC
)
target_link_libraries
(
Pylene-io-freeimage PUBLIC FreeImage::FreeImage Pylene-core
)
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
)
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-freeimage PUBLIC cfitsio::cfitsio Pylene-core
)
# Compiler configurations
target_compile_features
(
Pylene-core PUBLIC cxx_std_20
)
...
...
pylene/include/mln/io/imread.hpp
View file @
cd21b3b6
...
...
@@ -8,4 +8,10 @@ namespace mln::io
{
mln
::
ndbuffer_image
imread
(
const
std
::
string
&
filename
);
void
imread
(
const
std
::
string
&
filename
,
mln
::
ndbuffer_image
&
out
);
}
namespace
fits
{
mln
::
ndbuffer_image
imread
(
const
std
::
string
&
filename
,
int
ind
=
0
);
void
imread
(
const
std
::
string
&
filename
,
mln
::
ndbuffer_image
&
out
,
int
ind
=
0
);
}
// namespace fits
}
// namespace mln::io
pylene/include/mln/io/private/cfitsio_plugin.hpp
0 → 100644
View file @
cd21b3b6
#pragma once
#include
<mln/io/private/plugin.hpp>
namespace
mln
::
io
::
fits
::
internal
{
class
cfitsio_reader_plugin
final
:
public
mln
::
io
::
internal
::
plugin_reader
{
public:
cfitsio_reader_plugin
()
=
delete
;
cfitsio_reader_plugin
(
int
ind
);
~
cfitsio_reader_plugin
()
final
;
void
open
(
const
char
*
filename
)
final
;
void
close
()
final
;
private:
const
int
m_image_index
;
};
}
// namespace mln::io::fist::internal
\ No newline at end of file
pylene/src/io/cfitsio_plugin.cpp
0 → 100644
View file @
cd21b3b6
#include
<mln/io/private/cfitsio_plugin.hpp>
#include
<fitsio.h>
#include
<fmt/format.h>
#include
<stdexcept>
#include
<tuple>
namespace
mln
::
io
::
fits
::
internal
{
namespace
{
std
::
pair
<
mln
::
sample_type_id
,
int
>
get_type_info
(
int
type
)
{
switch
(
type
)
{
case
BYTE_IMG
:
return
{
mln
::
sample_type_id
::
UINT8
,
TBYTE
};
case
SHORT_IMG
:
return
{
mln
::
sample_type_id
::
INT16
,
TSHORT
};
case
LONG_IMG
:
return
{
mln
::
sample_type_id
::
INT32
,
TINT
};
case
LONGLONG_IMG
:
return
{
mln
::
sample_type_id
::
INT64
,
TLONGLONG
};
case
FLOAT_IMG
:
return
{
mln
::
sample_type_id
::
FLOAT
,
TFLOAT
};
case
DOUBLE_IMG
:
return
{
mln
::
sample_type_id
::
DOUBLE
,
TDOUBLE
};
break
;
default:
throw
std
::
runtime_error
(
"Unhandled data type"
);
}
return
{};
}
struct
impl_cfitsio_t
:
mln
::
io
::
internal
::
plugin_base
::
impl_t
{
fitsfile
*
file
=
nullptr
;
int
datatype
;
void
read_next_line
(
std
::
byte
*
__restrict
buffer
)
final
{
int
anynul
;
int
nullpix
=
0
;
int
status
;
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
));
}
m_line
++
;
}
void
write_next_line
(
const
std
::
byte
*
/* buffer */
)
final
{
std
::
abort
();
}
private:
int
m_line
=
0
;
};
}
// namespace
cfitsio_reader_plugin
::
cfitsio_reader_plugin
(
int
ind
)
:
m_image_index
(
ind
)
{
}
cfitsio_reader_plugin
::~
cfitsio_reader_plugin
()
{
this
->
close
();
}
void
cfitsio_reader_plugin
::
open
(
const
char
*
filename
)
{
int
status
;
// Open the file
fitsfile
*
file
;
fits_open_file
(
&
file
,
filename
,
READONLY
,
&
status
);
if
(
status
)
throw
std
::
runtime_error
(
fmt
::
format
(
"Unable to read the file {}"
,
filename
));
// Go to the index of the image
fits_movrel_hdu
(
file
,
m_image_index
,
nullptr
,
&
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
int
hdu_type
;
fits_get_hdu_type
(
file
,
&
hdu_type
,
&
status
);
if
(
hdu_type
!=
IMAGE_HDU
)
throw
std
::
runtime_error
(
fmt
::
format
(
"HDU at index {} is not an image"
,
m_image_index
));
// Get the number of dimension
int
ndim
;
fits_get_img_dim
(
file
,
&
ndim
,
&
status
);
if
(
ndim
==
0
||
ndim
>
4
)
throw
std
::
runtime_error
(
fmt
::
format
(
"Unhandled image number of dimension (Got {}, expected in [1 - 4]"
,
ndim
));
// Get the dimensions
long
dims
[
4
];
fits_get_img_size
(
file
,
ndim
,
dims
,
&
status
);
// Get the type info
int
type
;
fits_get_img_type
(
file
,
&
type
,
&
status
);
const
auto
[
sample_type
,
datatype
]
=
get_type_info
(
type
);
auto
impl
=
std
::
make_unique
<
impl_cfitsio_t
>
();
impl
->
file
=
file
;
impl
->
m_ndim
=
ndim
;
for
(
int
i
=
0
;
i
<
ndim
;
i
++
)
impl
->
m_dims
[
i
]
=
dims
[
i
];
impl
->
m_sample_type_id
=
sample_type
;
this
->
m_impl
=
std
::
move
(
impl
);
}
void
cfitsio_reader_plugin
::
close
()
{
auto
*
impl
=
static_cast
<
impl_cfitsio_t
*>
(
this
->
m_impl
.
get
());
if
(
impl
&&
impl
->
file
)
{
int
status
;
fits_close_file
(
impl
->
file
,
&
status
);
impl
->
file
=
nullptr
;
}
}
}
// namespace mln::io::fits::internal
\ No newline at end of file
pylene/src/io/imread.cpp
View file @
cd21b3b6
#include
<mln/io/imread.hpp>
#include
<mln/io/private/io.hpp>
#include
<mln/io/private/freeimage_plugin.hpp>
#include
<mln/core/image/ndbuffer_image.hpp>
#include
<mln/io/private/cfitsio_plugin.hpp>
#include
<mln/io/private/freeimage_plugin.hpp>
#include
<mln/io/private/io.hpp>
namespace
mln
::
io
{
...
...
@@ -18,4 +19,20 @@ 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
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment