Line data Source code
1 : /** \file imagingUtils.cpp
2 : * \author Jared R. Males
3 : * \brief Implementation of imaging utilities
4 : * \ingroup wfp_files
5 : *
6 : */
7 :
8 : //***********************************************************************//
9 : // Copyright 2025 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 : #include "wfp/imagingUtils.hpp"
28 :
29 : #include "improc/eigenImage.hpp"
30 : using namespace mx::improc;
31 :
32 : #ifdef MXLIB_CUDA
33 :
34 : #include "math/cuda/cudaPtr.hpp"
35 : using namespace mx::cuda;
36 :
37 : #endif //MXLIB_CUDA
38 :
39 : //#include <iostream>
40 : #include <Eigen/Dense>
41 :
42 :
43 : namespace mx
44 : {
45 : namespace wfp
46 : {
47 :
48 :
49 : // CPU version
50 : template <typename realImageT, typename complexImageT>
51 1 : void extractIntensityImageAccum_cpu(
52 : realImageT &im, int imX0, int imXsz, int imY0, int imYsz, complexImageT &wf, int wfX0, int wfY0 )
53 : {
54 1 : int im_rows = im.cols();
55 :
56 1 : int wf_rows = wf.cols();
57 :
58 : typename realImageT::Scalar *im_data;
59 : typename complexImageT::Scalar *wf_data;
60 :
61 129 : for( int j = 0; j < imXsz; ++j )
62 : {
63 128 : im_data = &im.data()[imX0 + ( imY0 + j ) * im_rows];
64 128 : wf_data = &wf.data()[wfX0 + ( wfY0 + j ) * wf_rows];
65 16512 : for( int i = 0; i < imYsz; ++i )
66 : {
67 16384 : im_data[i] += norm( wf_data[i] );
68 : }
69 : }
70 1 : }
71 :
72 : template <>
73 1 : void extractIntensityImageAccum<eigenImage<float>, eigenImage<std::complex<float>>, 0>(
74 : eigenImage<float> &im, int imX0, int imXsz, int imY0, int imYsz, eigenImage<std::complex<float>> &wf, int wfX0, int wfY0 )
75 : {
76 1 : return extractIntensityImageAccum_cpu(im, imX0, imXsz, imY0, imYsz, wf, wfX0, wfY0);
77 : }
78 :
79 : template <>
80 0 : void extractIntensityImageAccum<eigenImage<double>, eigenImage<std::complex<double>>, 0>(
81 : eigenImage<double> &im, int imX0, int imXsz, int imY0, int imYsz, eigenImage<std::complex<double>> &wf, int wfX0, int wfY0 )
82 : {
83 0 : return extractIntensityImageAccum_cpu(im, imX0, imXsz, imY0, imYsz, wf, wfX0, wfY0);
84 : }
85 :
86 : #ifdef MXLIB_CUDA
87 :
88 : template <typename realT, typename complexT>
89 : cudaError_t extractIntensityImageAccum_gpu(
90 : realT *im, int im_cols, int imX0, int imXsz, int imY0, int imYsz, complexT *wf, int wf_cols, int wfX0, int wfY0 );
91 :
92 : template <>
93 : void extractIntensityImageAccum<cudaPtr<float>, cudaPtr<std::complex<float>>, 1>(
94 : cudaPtr<float> &im,
95 : int imX0,
96 : int imXsz,
97 : int imY0,
98 : int imYsz,
99 : cudaPtr<std::complex<float>> & wf,
100 : int wfX0,
101 : int wfY0 )
102 : {
103 : extractIntensityImageAccum_gpu( im.data(),im.cols(), imX0, imXsz, imY0, imYsz, wf.data(), wf.cols(), wfX0, wfY0 );
104 : }
105 :
106 :
107 : template <>
108 : void extractIntensityImageAccum<cudaPtr<double>, cudaPtr<std::complex<double>>, 1>(
109 : cudaPtr<double> &im,
110 : int imX0,
111 : int imXsz,
112 : int imY0,
113 : int imYsz,
114 : cudaPtr<std::complex<double>> &wf,
115 : int wfX0,
116 : int wfY0 )
117 : {
118 : extractIntensityImageAccum_gpu( im.data(), im.cols(), imX0, imXsz, imY0, imYsz, wf.data(), wf.cols(), wfX0, wfY0 );
119 : }
120 : #endif // MXLIB_CUDA
121 :
122 :
123 : } // namespace wfp
124 : } // namespace mx
|