STIR  6.2.0
SeparableLowPassArrayFilter2.h
Go to the documentation of this file.
1 //
2 //
10 /*
11  Copyright (C) 2000- 2011, IRSL
12  SPDX-License-Identifier: Apache-2.0
13  See STIR/LICENSE.txt for details
14 */
15 #ifndef __stir_SeparableLowPassArrayFilter2__H__
16 #define __stir_SeparableLowPassArrayFilter2__H__
17 
18 #include "stir/Array.h"
19 #include "stir/BasicCoordinate.h"
21 #include "stir/Succeeded.h"
22 #include "stir/shared_ptr.h"
23 #include "stir/VectorWithOffset.h"
24 #include "stir/ArrayFunction.h"
25 #include <iostream>
26 
28 
29 START_NAMESPACE_STIR
42 // TODO don't use 2Argument, but do 1arg explicitly as well
43 template <int num_dimensions, typename elemT>
45 {
46 public:
49  bool is_trivial() const;
50  // TODO reimplement get_*indices
51 protected:
53  virtual void do_it(Array<num_dimensions, elemT>& out_array, const Array<num_dimensions, elemT>& in_array) const;
54 };
55 
56 template <int num_dim, typename elemT>
58  : all_1d_array_filters(VectorWithOffset<shared_ptr<ArrayFunctionObject<1, elemT>>>(num_dim))
59 {}
60 
61 template <int num_dim, typename elemT>
63  const VectorWithOffset<shared_ptr<ArrayFunctionObject<1, elemT>>>& array_filters)
64  : all_1d_array_filters(array_filters)
65 {
66  assert(all_1d_array_filters.get_length() == num_dim);
67 }
68 
69 template <int num_dimensions, typename elemT>
70 void
72  const Array<num_dimensions, elemT>& in_array) const
73 {
74 
75  // if (!is_trivial())
76  apply_array_functions_on_each_index(out_array, in_array, all_1d_array_filters.begin(), all_1d_array_filters.end());
77  // else somehow copy in_array into out_array but keeping index ranges
78  // TODO
79 }
80 
81 template <int num_dim, typename elemT>
82 bool
84 {
85  for (typename VectorWithOffset<shared_ptr<ArrayFunctionObject<1, elemT>>>::const_iterator iter = all_1d_array_filters.begin();
86  iter != all_1d_array_filters.end();
87  ++iter)
88  {
89  // TODO insert condition on is_null_ptr here (see SeparableArrayFunctionObject)
90  if (!(*iter)->is_trivial())
91  return false;
92  }
93  return true;
94 }
95 
96 //----------------------------------------------
97 
98 template <int num_dimensions, typename elemT>
99 class SeparableLowPassArrayFilter2 : public SeparableArrayFunctionObject2<num_dimensions, elemT>
100 {
101 public:
103  SeparableLowPassArrayFilter2();
104 
105  SeparableLowPassArrayFilter2(const VectorWithOffset<elemT>& filter_coefficients);
106 
107 private:
108  VectorWithOffset<float> filter_coefficients;
109 };
110 
111 template <int num_dimensions, typename elemT>
112 SeparableLowPassArrayFilter2<num_dimensions, elemT>::SeparableLowPassArrayFilter2()
113 {
114  for (int i = 1; i <= num_dimensions; i++)
115  {
116  all_1d_array_filters[i - 1] = new ArrayFilter1DUsingConvolution<float>();
117  }
118 }
119 
120 template <int num_dimensions, typename elemT>
121 SeparableLowPassArrayFilter2<num_dimensions, elemT>::SeparableLowPassArrayFilter2(
122  const VectorWithOffset<elemT>& filter_coefficients_v)
123  : filter_coefficients(filter_coefficients_v)
124 {
125  assert(num_dimensions == 3);
126 
127  std::cerr << "Printing filter coefficients" << endl;
128  for (int i = filter_coefficients_v.get_min_index(); i <= filter_coefficients_v.get_max_index(); i++)
129  std::cerr << i << " " << filter_coefficients_v[i] << " " << endl;
130 
131  all_1d_array_filters[2] = new ArrayFilter1DUsingConvolution<float>(filter_coefficients_v);
132 
133  all_1d_array_filters[0] = new ArrayFilter1DUsingConvolution<float>();
134  all_1d_array_filters[1] = new ArrayFilter1DUsingConvolution<float>(filter_coefficients_v);
135 }
136 END_NAMESPACE_STIR
137 
138 #endif
A class for operations on n-dimensional Arrays.
Definition: ArrayFunctionObject.h:38
This class implements convolution of a 1D array with an arbitrary (i.e. potentially non-symmetric) ke...
Definition: ArrayFilter1DUsingConvolution.h:77
Declaration of class stir::Succeeded.
Declaration of class stir::ArrayFilter1DUsingConvolution.
A templated class for vectors, but with indices starting not from 0.
Definition: ArrayFilter1DUsingConvolution.h:31
A convenience class for children of ArrayFunctionObject. It implements the in-place operator() in ter...
Definition: ArrayFunctionObject_2ArgumentImplementation.h:41
int get_min_index() const
get value of first valid index
Definition: VectorWithOffset.inl:116
This class implements an n -dimensional ArrayFunctionObject whose operation is separable.
Definition: SeparableLowPassArrayFilter2.h:44
Declaration of class stir::ArrayFunctionObject_2ArgumentImplementation.
This include file provides some additional functionality for stir::Array objects. ...
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
defines the Array class for multi-dimensional (numeric) arrays
This file declares class stir::BasicCoordinate and some functions acting on stir::BasicCoordinate obj...
iterator begin()
use to initialise an iterator to the first element of the vector
Definition: VectorWithOffset.inl:182
defines the stir::VectorWithOffset class
This class defines multi-dimensional (numeric) arrays.
Definition: Array.h:73
int get_max_index() const
get value of last valid index
Definition: VectorWithOffset.inl:123
void apply_array_functions_on_each_index(Array< num_dim, elemT > &out_array, const Array< num_dim, elemT > &in_array, FunctionObjectPtrIter start, FunctionObjectPtrIter stop)
Apply a sequence of 1d array-function objects on every dimension of the input array, store in output array.
Definition: ArrayFunction.inl:220