File: gridding.cpp

package info (click to toggle)
odin 2.0.5-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,196 kB
  • sloc: cpp: 62,638; sh: 4,541; makefile: 779
file content (83 lines) | stat: -rw-r--r-- 2,267 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "gridding.h"

#include <tjutils/tjtest.h>


// instantiate one special template for checking at compile time
#ifdef ODIN_DEBUG
template class Gridding<float,1>;
template class CoordTransformation<STD_complex,2>;
#endif


/////////////////////////////////////////////////////

// unit test

#ifndef NO_UNIT_TEST

#include "statistics.h"

class GriddingTest : public UnitTest {

 public:
  GriddingTest() : UnitTest("Gridding") {}

 private:
  bool check() const {
    Log<UnitTest> odinlog(this,"check");

    // Test using a 3*FOV/4 (filled with 1) and FOV/2 (filled with 2) box
    int testsize=128;
    Data<float,2> testbox(testsize,testsize); testbox=0.0;
    Range inner(testsize/8, 7*testsize/8-1);
    testbox(inner,inner)=1.0;
    inner=Range(testsize/4, 3*testsize/4-1);
    testbox(inner,inner)=2.0;
//    testbox.autowrite("testbox.jdx");

    float radialfactor=1.2; // so that sampling disk covers the whole box
    int ncycles=int(radialfactor*testsize/2+0.5); // suffucient sampling in radial direction
    int spirsize=int(radialfactor*int(2.0*PII*ncycles*testsize)+0.5); // suffucient along spiral

    STD_vector<GriddingPoint<2> > src_coords(spirsize);
    Data<float,1> src(spirsize); src=0.0;
    for(int i=0; i<spirsize; i++) {
      float s=radialfactor*float(i)/float(spirsize);
      float phase=2.0*PII*ncycles*s;
      float x=s*cos(phase);
      float y=s*sin(phase);
      src_coords[i].coord(0)=x;
      src_coords[i].coord(1)=y;
      if(fabs(x)<0.75 && fabs(y)<0.75) src(i)=1.0;
      if(fabs(x)<0.5 && fabs(y)<0.5) src(i)=2.0;
    }
//    src.autowrite("src.jdx");

    Data<float,2> dst(testbox.shape());

    LDRfilter gridkernel;
    gridkernel.set_function("Gauss");

    Gridding<float,2> gridder;
    gridder.init(dst.shape(), 2.0, src_coords, gridkernel, sqrt(2.0)*2.0/float(testsize));

    Data<float,2> griddedbox(gridder(src));
//    griddedbox.autowrite("griddedbox.jdx");

    Data<float,2> diff(testbox-griddedbox);
//    diff.autowrite("diff.jdx");
    float absdiff=sum(fabs(diff));
    if(absdiff>30.0) {
      ODINLOG(odinlog,errorLog) << "absdiff=" << absdiff << STD_endl;
      return false;
    }


    return true;
  }

};

void alloc_GriddingTest() {new GriddingTest();} // create test instance
#endif