VTK-m  2.0
WaveletFilter.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 
11 #ifndef vtk_m_worklet_wavelets_waveletfilter_h
12 #define vtk_m_worklet_wavelets_waveletfilter_h
13 
14 #include <vtkm/cont/ArrayHandle.h>
15 
17 
18 #include <vtkm/Math.h>
19 
20 namespace vtkm
21 {
22 namespace worklet
23 {
24 
25 namespace wavelets
26 {
27 
29 {
34  BIOR4_4, // the same as CDF9_7
35  BIOR3_3, // the same as CDF8_4
36  BIOR2_2, // the same as CDF5_3
37  BIOR1_1 // the same as HAAR
38 };
39 
40 // Wavelet filter class;
41 // functionally equivalent to WaveFiltBase and its subclasses in VAPoR.
43 {
44 public:
45  // constructor
47  : Symmetricity(true)
48  , FilterLength(0)
49  , LowDecomposeFilter(nullptr)
50  , HighDecomposeFilter(nullptr)
51  , LowReconstructFilter(nullptr)
52  , HighReconstructFilter(nullptr)
53  {
54  if (wtype == CDF9_7 || wtype == BIOR4_4)
55  {
56  this->FilterLength = 9;
57  this->AllocateFilterMemory();
62  }
63  else if (wtype == CDF8_4 || wtype == BIOR3_3)
64  {
65  this->FilterLength = 8;
66  this->AllocateFilterMemory();
71  }
72  else if (wtype == CDF5_3 || wtype == BIOR2_2)
73  {
74  this->FilterLength = 5;
75  this->AllocateFilterMemory();
80  }
81  else if (wtype == HAAR || wtype == BIOR1_1)
82  {
83  this->FilterLength = 2;
84  this->AllocateFilterMemory();
89  }
90  this->MakeArrayHandles();
91  }
92 
93  // destructor
95  {
100  if (LowDecomposeFilter)
101  {
102  delete[] LowDecomposeFilter;
104  nullptr;
105  }
106  }
107 
109 
110  bool isSymmetric() { return this->Symmetricity; }
111 
113 
114  const FilterType& GetLowDecomposeFilter() const { return this->LowDecomType; }
115  const FilterType& GetHighDecomposeFilter() const { return this->HighDecomType; }
116  const FilterType& GetLowReconstructFilter() const { return this->LowReconType; }
117  const FilterType& GetHighReconstructFilter() const { return this->HighReconType; }
118 
119 private:
130 
132  {
133  LowDecomposeFilter = new vtkm::Float64[static_cast<std::size_t>(FilterLength * 4)];
137  }
138 
140  {
141  LowDecomType =
143  HighDecomType =
145  LowReconType =
147  HighReconType =
149  }
150 
151  // Flipping operation; helper function to initialize a filter.
152  void wrev(const vtkm::Float64* arrIn, vtkm::Float64* arrOut, vtkm::Id length)
153  {
154  for (vtkm::Id count = 0; count < length; count++)
155  {
156  arrOut[count] = arrIn[length - count - 1];
157  }
158  }
159 
160  // Quadrature mirror filtering operation: helper function to initialize a filter.
161  void qmf_even(const vtkm::Float64* arrIn, vtkm::Float64* arrOut, vtkm::Id length)
162  {
163  if (length % 2 == 0)
164  {
165  for (vtkm::Id count = 0; count < length; count++)
166  {
167  arrOut[count] = arrIn[length - count - 1];
168  if (count % 2 != 0)
169  {
170  arrOut[count] = -1.0 * arrOut[count];
171  }
172  }
173  }
174  else
175  {
176  for (vtkm::Id count = 0; count < length; count++)
177  {
178  arrOut[count] = arrIn[length - count - 1];
179  if (count % 2 == 0)
180  {
181  arrOut[count] = -1.0 * arrOut[count];
182  }
183  }
184  }
185  }
186 
187  // Flipping and QMF at the same time: helper function to initialize a filter.
188  void qmf_wrev(const vtkm::Float64* arrIn, vtkm::Float64* arrOut, vtkm::Id length)
189  {
190  qmf_even(arrIn, arrOut, length);
191 
192  vtkm::Float64 tmp;
193  for (vtkm::Id count = 0; count < length / 2; count++)
194  {
195  tmp = arrOut[count];
196  arrOut[count] = arrOut[length - count - 1];
197  arrOut[length - count - 1] = tmp;
198  }
199  }
200 
201  // Verbatim Copying: helper function to initialize a filter.
202  void verbatim_copy(const vtkm::Float64* arrIn, vtkm::Float64* arrOut, vtkm::Id length)
203  {
204  for (vtkm::Id count = 0; count < length; count++)
205  {
206  arrOut[count] = arrIn[count];
207  }
208  }
209 
210 }; // class WaveletFilter.
211 } // namespace wavelets.
212 
213 } // namespace worklet
214 } // namespace vtkm
215 
216 #endif
vtkm::worklet::wavelets::WaveletFilter::LowDecomposeFilter
vtkm::Float64 * LowDecomposeFilter
Definition: WaveletFilter.h:122
vtkm::worklet::wavelets::WaveletFilter::GetLowReconstructFilter
const FilterType & GetLowReconstructFilter() const
Definition: WaveletFilter.h:116
vtkm::worklet::wavelets::WaveletFilter::LowDecomType
FilterType LowDecomType
Definition: WaveletFilter.h:126
vtkm::cont::make_ArrayHandle
VTKM_CONT vtkm::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, vtkm::Id numberOfValues, vtkm::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:217
vtkm::worklet::wavelets::WaveletFilter::MakeArrayHandles
void MakeArrayHandles()
Definition: WaveletFilter.h:139
vtkm::cont::ArrayHandle< vtkm::Float64 >
ArrayHandle.h
vtkm::worklet::wavelets::WaveletFilter::HighDecomposeFilter
vtkm::Float64 * HighDecomposeFilter
Definition: WaveletFilter.h:123
vtkm::worklet::wavelets::BIOR2_2
@ BIOR2_2
Definition: WaveletFilter.h:36
vtkm::worklet::wavelets::h2
const vtkm::Float64 h2[18]
Definition: FilterBanks.h:74
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::wavelets::WaveletFilter
Definition: WaveletFilter.h:42
vtkm::worklet::wavelets::WaveletFilter::HighReconType
FilterType HighReconType
Definition: WaveletFilter.h:129
vtkm::worklet::wavelets::WaveletFilter::WaveletFilter
WaveletFilter(WaveletName wtype)
Definition: WaveletFilter.h:46
vtkm::worklet::wavelets::WaveletFilter::GetHighReconstructFilter
const FilterType & GetHighReconstructFilter() const
Definition: WaveletFilter.h:117
vtkm::worklet::wavelets::WaveletFilter::LowReconType
FilterType LowReconType
Definition: WaveletFilter.h:128
vtkm::worklet::wavelets::CDF8_4
@ CDF8_4
Definition: WaveletFilter.h:32
vtkm::worklet::wavelets::WaveletFilter::wrev
void wrev(const vtkm::Float64 *arrIn, vtkm::Float64 *arrOut, vtkm::Id length)
Definition: WaveletFilter.h:152
vtkm::worklet::wavelets::CDF9_7
@ CDF9_7
Definition: WaveletFilter.h:30
vtkm::worklet::wavelets::HAAR
@ HAAR
Definition: WaveletFilter.h:33
vtkm::worklet::wavelets::WaveletFilter::HighDecomType
FilterType HighDecomType
Definition: WaveletFilter.h:127
vtkm::worklet::wavelets::WaveletFilter::GetFilterLength
vtkm::Id GetFilterLength()
Definition: WaveletFilter.h:108
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::wavelets::WaveletFilter::GetHighDecomposeFilter
const FilterType & GetHighDecomposeFilter() const
Definition: WaveletFilter.h:115
vtkm::worklet::wavelets::h4
const vtkm::Float64 h4[9]
Definition: FilterBanks.h:43
vtkm::worklet::wavelets::WaveletFilter::HighReconstructFilter
vtkm::Float64 * HighReconstructFilter
Definition: WaveletFilter.h:125
vtkm::worklet::wavelets::WaveletFilter::Symmetricity
bool Symmetricity
Definition: WaveletFilter.h:120
vtkm::worklet::wavelets::WaveletFilter::AllocateFilterMemory
void AllocateFilterMemory()
Definition: WaveletFilter.h:131
vtkm::worklet::wavelets::WaveletFilter::qmf_even
void qmf_even(const vtkm::Float64 *arrIn, vtkm::Float64 *arrOut, vtkm::Id length)
Definition: WaveletFilter.h:161
vtkm::worklet::wavelets::WaveletFilter::verbatim_copy
void verbatim_copy(const vtkm::Float64 *arrIn, vtkm::Float64 *arrOut, vtkm::Id length)
Definition: WaveletFilter.h:202
vtkm::worklet::wavelets::hm4_44
const vtkm::Float64 hm4_44[9]
Definition: FilterBanks.h:24
vtkm::worklet::wavelets::h3
const vtkm::Float64 h3[20]
Definition: FilterBanks.h:108
vtkm::worklet::wavelets::WaveletFilter::FilterLength
vtkm::Id FilterLength
Definition: WaveletFilter.h:121
Math.h
vtkm::worklet::wavelets::WaveletFilter::LowReconstructFilter
vtkm::Float64 * LowReconstructFilter
Definition: WaveletFilter.h:124
vtkm::worklet::wavelets::WaveletFilter::GetLowDecomposeFilter
const FilterType & GetLowDecomposeFilter() const
Definition: WaveletFilter.h:114
vtkm::worklet::wavelets::CDF5_3
@ CDF5_3
Definition: WaveletFilter.h:31
vtkm::worklet::wavelets::h1
const vtkm::Float64 h1[10]
Definition: FilterBanks.h:96
vtkm::worklet::wavelets::WaveletName
WaveletName
Definition: WaveletFilter.h:28
vtkm::worklet::wavelets::hm1_11
const vtkm::Float64 hm1_11[2]
Definition: FilterBanks.h:93
vtkm::worklet::wavelets::BIOR3_3
@ BIOR3_3
Definition: WaveletFilter.h:35
vtkm::CopyFlag::Off
@ Off
vtkm::worklet::wavelets::WaveletFilter::~WaveletFilter
~WaveletFilter()
Definition: WaveletFilter.h:94
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::wavelets::WaveletFilter::isSymmetric
bool isSymmetric()
Definition: WaveletFilter.h:110
vtkm::worklet::wavelets::BIOR1_1
@ BIOR1_1
Definition: WaveletFilter.h:37
vtkm::worklet::wavelets::hm3_33
const vtkm::Float64 hm3_33[8]
Definition: FilterBanks.h:101
vtkm::worklet::wavelets::hm2_22
const vtkm::Float64 hm2_22[6]
Definition: FilterBanks.h:68
vtkm::cont::ArrayHandle::ReleaseResources
VTKM_CONT void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:559
vtkm::worklet::wavelets::WaveletFilter::qmf_wrev
void qmf_wrev(const vtkm::Float64 *arrIn, vtkm::Float64 *arrOut, vtkm::Id length)
Definition: WaveletFilter.h:188
vtkm::worklet::wavelets::BIOR4_4
@ BIOR4_4
Definition: WaveletFilter.h:34
FilterBanks.h