aimsdata  4.7.0
Neuroimaging data handling
borderfiller.h
Go to the documentation of this file.
1 #ifndef AIMSDATA_BORDER_BORDERFILLER_H
2 #define AIMSDATA_BORDER_BORDERFILLER_H
3 
4 //--- aims -------------------------------------------------------------------
6 #include <aims/math/mathelem.h> // MathUtil
7 #include <aims/resampling/splineresampler.h> // mirrorCoeff
8 //--- cartodata --------------------------------------------------------------
9 #include <cartodata/volume/volume.h> // VolumeRef
10 //----------------------------------------------------------------------------
11 
12 namespace aims
13 {
14 
15  //==========================================================================
16  // BORDER FILLER
17  //==========================================================================
21  template <typename T>
23  {
24  public:
26  static void fillConstant( carto::VolumeRef<T> in, const T & value = 0 );
34  static void fillMedian( carto::VolumeRef<T> in, Point4dl size = Point4dl(-1,-1,-1,-1) );
36  static void fillNearest( carto::VolumeRef<T> in );
38  static void fillMirror( carto::VolumeRef<T> in );
39  };
40 
41  template <typename T>
43  {
44  BorderIterator<T> brd( in );
45  typename BorderIterator<T>::iterator i;
46 
47  for( i = brd.begin(); i != brd.end(); ++i )
48  *i = value;
49  }
50 
51  template <typename T>
53  {
54  std::vector<int> bs = in.getBorders();
55  if( size[0] < 0 )
56  size[0] = ( bs[0] >= bs[1] ? bs[0] : bs[1] );
57  if( size[1] < 0 )
58  size[1] = ( bs[2] >= bs[3] ? bs[2] : bs[3] );
59  if( size[2] < 0 )
60  size[2] = ( bs[4] >= bs[5] ? bs[4] : bs[5] );
61  if( size[3] < 0 )
62  size[3] = ( bs[6] >= bs[7] ? bs[6] : bs[7] );
63  BorderIterator<T> brdin( in, true, size );
64  T med = aims::MathUtil<T>::median( brdin.begin(), brdin.end() );
65 
66  BorderIterator<T> brdout( in );
67  typename BorderIterator<T>::iterator i;
68  for( i = brdout.begin(); i != brdout.end(); ++i )
69  *i = med;
70  }
71 
72  template <typename T>
74  {
75  BorderIterator<T> brd( in );
76  typename BorderIterator<T>::iterator i;
77  Point4dl current;
78  for( i = brd.begin(); i != brd.end(); ++i )
79  {
80  current = i.coordinate();
81  if( current[0] < 0 )
82  current[0] = 0;
83  else if( current[0] >= in.getSizeX() )
84  current[0] = in.getSizeX() - 1;
85  if( current[1] < 0 )
86  current[1] = 0;
87  else if( current[1] >= in.getSizeX() )
88  current[1] = in.getSizeX() - 1;
89  if( current[2] < 0 )
90  current[2] = 0;
91  else if( current[2] >= in.getSizeX() )
92  current[2] = in.getSizeX() - 1;
93  if( current[3] < 0 )
94  current[3] = 0;
95  else if( current[3] >= in.getSizeX() )
96  current[3] = in.getSizeX() - 1;
97  *i = in( current[0], current[1], current[2], current[3] );
98  }
99  }
100 
101 
102  template <typename T>
104  {
105  BorderIterator<T> brd( in );
106  typename BorderIterator<T>::iterator i;
107  Point4dl current;
108  for( i = brd.begin(); i != brd.end(); ++i )
109  {
110  current = i.coordinate();
111  current[0] = mirrorCoeff( current[0], in.getSizeX() );
112  current[1] = mirrorCoeff( current[1], in.getSizeY() );
113  current[2] = mirrorCoeff( current[2], in.getSizeZ() );
114  current[3] = mirrorCoeff( current[3], in.getSizeT() );
115  *i = in( current[0], current[1], current[2], current[3] );
116  }
117  }
118 
119 } // namespace aims
120 
121 #endif // AIMSDATA_BORDER_BORDERFILLER_H
int getSizeX() const
int getSizeY() const
int getSizeZ() const
This class contains static methods to fill the border of a VolumeRef with chosen values.
Definition: borderfiller.h:22
int getSizeT() const
The class for EcatSino data write operation.
Definition: border.h:42
static void fillNearest(carto::VolumeRef< T > in)
Each voxel of the border is assigned with the nearest inside voxel.
Definition: borderfiller.h:73
static void fillMedian(carto::VolumeRef< T > in, Point4dl size=Point4dl(-1,-1,-1,-1))
Fills the border with a "median" value.
Definition: borderfiller.h:52
Point4dl coordinate() const
Returns the coordinates of the current point in the linked volume.
static void fillConstant(carto::VolumeRef< T > in, const T &value=0)
Fills the border with a constant value.
Definition: borderfiller.h:42
Represents the border of a volume.
static void fillMirror(carto::VolumeRef< T > in)
The border is filled by mirroring the inside border of same size.
Definition: borderfiller.h:103
static T median(Iterator b, Iterator e, T default_value=(T) 0)
Definition: mathelem.h:143
std::vector< int > getBorders() const