mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
eigenImage.hpp
Go to the documentation of this file.
1/** \file eigenImage.hpp
2 * \brief Tools for using the eigen library for image processing
3 * \ingroup image_processing_files
4 * \author Jared R. Males (jaredmales@gmail.com)
5 *
6 */
7
8//***********************************************************************//
9// Copyright 2015, 2016, 2017 Jared R. Males (jaredmales@gmail.com)
10//
11// This file is part of mxlib.
12//
13// mxlib is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// mxlib is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25//***********************************************************************//
26
27#ifndef improc_eigenImage_hpp
28#define improc_eigenImage_hpp
29
30#pragma GCC system_header
31#include <Eigen/Dense>
32
33#include "../math/vectorUtils.hpp"
34
35namespace mx
36{
37namespace improc
38{
39
40/// Definition of the eigenImage type, which is an alias for Eigen::Array.
41/** \ingroup eigen_image_processing
42 */
43template <typename scalarT>
44using eigenImage = Eigen::Array<scalarT, -1, -1>;
45
46/// Definition of the eigenMap type, which is an alias for Eigen::Map<Array>.
47/** \ingroup eigen_image_processing
48 */
49template <typename scalarT>
50using eigenMap = Eigen::Map<Eigen::Array<scalarT, -1, -1>>;
51
52/// Test whether a type is an eigenCube by testing whether it has a typedef of "is_eigenCube"
53/** Used for compile-time determination of type
54 * Example usage:
55 * \code
56 * bool is_eC = is_eigenCube<eigenCube<float> >; //Evaluates to true
57 * bool is_not_eC = is_eigenCube<eigenImagef>; //Evaluates to false
58 * \endcode
59 *
60 * This was taken directly from the example at http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error
61 *
62 * \ingroup eigen_image_processing
63 */
64template <typename T>
66{
67 // Types "yes" and "no" are guaranteed to have different sizes,
68 // specifically sizeof(yes) == 1 and sizeof(no) == 2.
69 typedef char yes[1];
70 typedef char no[2];
71
72 template <typename imageT>
73 static yes &test( typename imageT::is_eigenCube * );
74
75 template <typename>
76 static no &test( ... );
77
78 // If the "sizeof" of the result of calling test<T>(0) would be equal to sizeof(yes),
79 // the first overload worked and T has a nested type named "is_eigenCube".
80 static const bool value = sizeof( test<T>( 0 ) ) == sizeof( yes );
81};
82
83/// Function object to return the number of planes for any Eigen like object, whether 2D or a 3D cube.
84/** Uses SFINAE to check for 3D eigenCube.
85 *
86 * \ingroup eigen_image_processing
87 */
88template <typename arrT, bool isCube = is_eigenCube<arrT>::value>
90{
91 // If it's an eigenCube, call planes planes()
92 int operator()( const arrT &arr )
93 {
94 return arr.planes();
95 }
96};
97
98template <typename arrT>
99struct eigenArrPlanes<arrT, false>
100{
101 // If it's not an eigenCube, never call planes()
102 int operator()( const arrT &arr )
103 {
104 return 1;
105 }
106};
107
108
109} // namespace improc
110} // namespace mx
111
112#endif // improc_eigenImage_hpp
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
Eigen::Map< Eigen::Array< scalarT, -1, -1 > > eigenMap
Definition of the eigenMap type, which is an alias for Eigen::Map<Array>.
The mxlib c++ namespace.
Definition mxlib.hpp:37
Function object to return the number of planes for any Eigen like object, whether 2D or a 3D cube.
Test whether a type is an eigenCube by testing whether it has a typedef of "is_eigenCube".