mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
imagingUtils_test.cpp
Go to the documentation of this file.
1/** \file imagingUtils_test.cpp
2 * \brief Tests CPU and CUDA imaging utilities.
3 */
4#include "../../catch2/catch.hpp"
5#ifdef MXLIB_CUDA
6#include "../../cudaTestUtils.hpp"
7#endif
8
9#define MX_NO_ERROR_REPORTS
10
11#include <iostream>
12
14
15/// Make a complex wavefront and extract it as an intensity image on CPU
16/**
17 * \ingroup imagingUtils_unit_tests
18 */
19TEST_CASE( "Make a complex wavefront and extract it as an intensity image on CPU", "[wfp]" )
20{
21 typedef float realT;
22 typedef std::complex<realT> complexT;
23
24 typedef mx::improc::eigenImage<realT> realImageT;
25 typedef mx::improc::eigenImage<complexT> complexFieldT;
26
27
28 int wfSz = 128;
29
30 realImageT im(wfSz, wfSz);
31 im.setZero();
32 complexFieldT wf(wfSz, wfSz);
33
34 for(int cc = 0; cc < wfSz; ++cc)
35 {
36 for(int rr = 0; rr < wfSz; ++rr)
37 {
38 wf(rr,cc) = std::complex(rr,cc);
39 }
40 }
41
43
44 bool fail = false;
45 for(int cc = 0; cc < wfSz; ++cc)
46 {
47 for(int rr = 0; rr < wfSz; ++rr)
48 {
49 realT val = rr*rr + cc*cc;
50 if(im(rr,cc) != val)
51 {
52 fail=true;
53 break;
54 }
55
56 }
57
58 if(fail)
59 {
60 break;
61 }
62 }
63
64 REQUIRE(fail == false);
65}
66
67#if defined( MXLIB_CUDA ) || defined( __DOXY_ONLY__ )
68/// Make a complex wavefront and extract it as an intensity image on GPU
69/**
70 * \ingroup imagingUtils_unit_tests
71 */
72TEST_CASE( "Make a complex wavefront and extract it as an intensity image on GPU", "[wfp]" )
73{
74 if( !mxlibTest::cudaDeviceAvailable() )
75 {
76 WARN( "CUDA runtime is available but no CUDA device is present" );
77 return;
78 }
79
80 typedef float realT;
81 typedef std::complex<realT> complexT;
82
83 typedef mx::improc::eigenImage<realT> realImageT;
84 typedef mx::improc::eigenImage<complexT> complexFieldT;
85
86
87 int wfSz = 128;
88
89 realImageT im(wfSz, wfSz);
90 im.setZero();
91 complexFieldT wf(wfSz, wfSz);
92
93 for(int cc = 0; cc < wfSz; ++cc)
94 {
95 for(int rr = 0; rr < wfSz; ++rr)
96 {
97 wf(rr,cc) = std::complex(rr,cc);
98 }
99 }
100
101 mx::cuda::cudaPtr<complexT> devWf;
102 devWf.upload(wf.data(), wfSz, wfSz);
103
104 mx::cuda::cudaPtr<realT> devIm;
105 devIm.resize(wfSz, wfSz);
106
107 mx::wfp::extractIntensityImageAccum<mx::cuda::cudaPtr<realT>, mx::cuda::cudaPtr<complexT>,1>(devIm,0,wfSz,0,wfSz,devWf,0,0);
108
109 devIm.download(im.data());
110
111 bool fail = false;
112 for(int cc = 0; cc < wfSz; ++cc)
113 {
114 for(int rr = 0; rr < wfSz; ++rr)
115 {
116 realT val = rr*rr + cc*cc;
117 if(im(rr,cc) != val)
118 {
119 fail=true;
120 break;
121 }
122
123 }
124
125 if(fail)
126 {
127 break;
128 }
129 }
130
131 REQUIRE(fail == false);
132}
133#endif // MXLIB_CUDA
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
TEST_CASE("Make a complex wavefront and extract it as an intensity image on CPU", "[wfp]")
Make a complex wavefront and extract it as an intensity image on CPU.
Utilities for modeling image formation.
void extractIntensityImageAccum(realImageT &im, int imX0, int imXsz, int imY0, int imYsz, complexImageT &wf, int wfX0, int wfY0)
Extract the intensity image from a complex wavefront and accumulate the result.