Filter is moved out of Wavelets

This commit is contained in:
Samuel Li 2016-07-10 14:08:39 -06:00
parent c15633d66e
commit a26fa39c40
2 changed files with 112 additions and 113 deletions

@ -30,121 +30,120 @@
namespace vtkm {
namespace worklet {
// Wavelet filter class;
// functionally equivalent to WaveFiltBase and its subclasses in VAPoR.
class WaveletFilter
{
public:
// constructor
WaveletFilter( const std::string &wname )
{
lowDecomposeFilter = highDecomposeFilter =
lowReconstructFilter = highReconstructFilter = NULL;
this->filterLength = 0;
if( wname.compare("CDF9/7") == 0 )
{
this->filterLength = 9;
AllocateFilterMemory();
wrev( vtkm::worklet::internal::hm4_44, lowDecomposeFilter, filterLength );
qmf_wrev( vtkm::worklet::internal::h4, highDecomposeFilter, filterLength );
verbatim_copy( vtkm::worklet::internal::h4, lowReconstructFilter, filterLength );
qmf_even( vtkm::worklet::internal::hm4_44, highReconstructFilter, filterLength );
}
else
{
// throw an error here
}
}
// destructor
virtual ~WaveletFilter()
{
if( lowDecomposeFilter ) delete[] lowDecomposeFilter;
if( highDecomposeFilter ) delete[] highDecomposeFilter;
if( lowReconstructFilter ) delete[] lowReconstructFilter;
if( highReconstructFilter ) delete[] highReconstructFilter;
}
protected:
vtkm::Id filterLength;
vtkm::Float64* lowDecomposeFilter;
vtkm::Float64* highDecomposeFilter;
vtkm::Float64* lowReconstructFilter;
vtkm::Float64* highReconstructFilter;
void AllocateFilterMemory()
{
lowDecomposeFilter = new vtkm::Float64[ this->filterLength ];
highDecomposeFilter = new vtkm::Float64[ this->filterLength ];
lowReconstructFilter = new vtkm::Float64[ this->filterLength ];
highReconstructFilter = new vtkm::Float64[ this->filterLength ];
}
// Flipping operation; helper function to initialize a filter.
void wrev( const vtkm::Float64* sigIn, vtkm::Float64* sigOut, vtkm::Id sigLength )
{
for( vtkm::Id count = 0; count < sigLength; count++)
sigOut[count] = sigIn[sigLength - count - 1];
}
// Quadrature mirror filtering operation: helper function to initialize a filter.
void qmf_even ( const vtkm::Float64* sigIn, vtkm::Float64* sigOut, vtkm::Id sigLength )
{
for (vtkm::Id count = 0; count < sigLength; count++)
{
sigOut[count] = sigIn[sigLength - count - 1];
if (sigLength % 2 == 0) {
if (count % 2 != 0) {
sigOut[count] = -1.0 * sigOut[count];
}
}
else {
if (count % 2 == 0) {
sigOut[count] = -1.0 * sigOut[count];
}
}
}
}
// Flipping and QMF at the same time: helper function to initialize a filter.
void qmf_wrev ( const vtkm::Float64* sigIn, vtkm::Float64* sigOut, vtkm::Id sigLength )
{
for (vtkm::Id count = 0; count < sigLength; count++) {
sigOut[count] = sigIn[sigLength - count - 1];
if (sigLength % 2 == 0) {
if (count % 2 != 0) {
sigOut[count] = -1 * sigOut[count];
}
}
else {
if (count % 2 == 0) {
sigOut[count] = -1 * sigOut[count];
}
}
}
vtkm::Float64 tmp;
for (vtkm::Id count = 0; count < sigLength/2; count++) {
tmp = sigOut[count];
sigOut[count] = sigOut[sigLength - count - 1];
sigOut[sigLength - count - 1] = tmp;
}
}
// Verbatim Copying: helper function to initialize a filter.
void verbatim_copy ( const vtkm::Float64* sigIn, vtkm::Float64* sigOut, vtkm::Id sigLength )
{
for (vtkm::Id count = 0; count < sigLength; count++)
sigOut[count] = sigIn[count];
}
}; // class Filter
class Wavelets
{
public:
// Wavelet filter class;
// functionally equivalent to WaveFiltBase and its subclasses in VAPoR.
class Filter
{
public:
// constructor
Filter( const std::string &wname )
{
lowDecomposeFilter = highDecomposeFilter =
lowReconstructFilter = highReconstructFilter = NULL;
this->filterLength = 0;
if( wname.compare("CDF9/7") == 0 )
{
this->filterLength = 9;
AllocateFilterMemory();
wrev( vtkm::worklet::internal::hm4_44, lowDecomposeFilter, filterLength );
qmf_wrev( vtkm::worklet::internal::h4, highDecomposeFilter, filterLength );
verbatim_copy( vtkm::worklet::internal::h4, lowReconstructFilter, filterLength );
qmf_even( vtkm::worklet::internal::hm4_44, highReconstructFilter, filterLength );
}
else
{
// throw an error here
}
}
// destructor
virtual ~Filter()
{
if( lowDecomposeFilter ) delete[] lowDecomposeFilter;
if( highDecomposeFilter ) delete[] highDecomposeFilter;
if( lowReconstructFilter ) delete[] lowReconstructFilter;
if( highReconstructFilter ) delete[] highReconstructFilter;
}
protected:
vtkm::Id filterLength;
vtkm::Float64* lowDecomposeFilter;
vtkm::Float64* highDecomposeFilter;
vtkm::Float64* lowReconstructFilter;
vtkm::Float64* highReconstructFilter;
void AllocateFilterMemory()
{
lowDecomposeFilter = new vtkm::Float64[ this->filterLength ];
highDecomposeFilter = new vtkm::Float64[ this->filterLength ];
lowReconstructFilter = new vtkm::Float64[ this->filterLength ];
highReconstructFilter = new vtkm::Float64[ this->filterLength ];
}
// Flipping operation; helper function to initialize a filter.
void wrev( const vtkm::Float64* sigIn, vtkm::Float64* sigOut, vtkm::Id sigLength )
{
for( vtkm::Id count = 0; count < sigLength; count++)
sigOut[count] = sigIn[sigLength - count - 1];
}
// Quadrature mirror filtering operation: helper function to initialize a filter.
void qmf_even ( const vtkm::Float64* sigIn, vtkm::Float64* sigOut, vtkm::Id sigLength )
{
for (vtkm::Id count = 0; count < sigLength; count++)
{
sigOut[count] = sigIn[sigLength - count - 1];
if (sigLength % 2 == 0) {
if (count % 2 != 0) {
sigOut[count] = -1.0 * sigOut[count];
}
}
else {
if (count % 2 == 0) {
sigOut[count] = -1.0 * sigOut[count];
}
}
}
}
// Flipping and QMF at the same time: helper function to initialize a filter.
void qmf_wrev ( const vtkm::Float64* sigIn, vtkm::Float64* sigOut, vtkm::Id sigLength )
{
for (vtkm::Id count = 0; count < sigLength; count++) {
sigOut[count] = sigIn[sigLength - count - 1];
if (sigLength % 2 == 0) {
if (count % 2 != 0) {
sigOut[count] = -1 * sigOut[count];
}
}
else {
if (count % 2 == 0) {
sigOut[count] = -1 * sigOut[count];
}
}
}
vtkm::Float64 tmp;
for (vtkm::Id count = 0; count < sigLength/2; count++) {
tmp = sigOut[count];
sigOut[count] = sigOut[sigLength - count - 1];
sigOut[sigLength - count - 1] = tmp;
}
}
// Verbatim Copying: helper function to initialize a filter.
void verbatim_copy ( const vtkm::Float64* sigIn, vtkm::Float64* sigOut, vtkm::Id sigLength )
{
for (vtkm::Id count = 0; count < sigLength; count++)
sigOut[count] = sigIn[count];
}
}; // class Filter
// helper worklet
class ForwardTransform: public vtkm::worklet::WorkletMapField

@ -49,7 +49,7 @@ void TestWavelets()
// make a wavelet filter
std::string wname = "CDF9/7";
vtkm::worklet::Wavelets::Filter CDF97( wname );
vtkm::worklet::WaveletFilter CDF97( wname );
// initialize the worklet
vtkm::worklet::Wavelets::ForwardTransform forwardTransform;