[go: up one dir, main page]

Menu

[97b1d3]: / mia / core / pwh.cc  Maximize  Restore  History

Download this file

127 lines (99 with data), 3.4 kB

  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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_core_pwh_hh
#define mia_core_pwh_hh
#include <mia/core/pwh.hh>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <mia/core/interpolator1d.hh>
#include <mia/core/spacial_kernel.hh>
#include <mia/core/fft1d_r2c.hh>
#include <mia/core/errormacro.hh>
#include <complex>
#include <pwpdf/pwd2.h>
#include <boost/algorithm/minmax_element.hpp>
NS_MIA_BEGIN
using namespace std;
struct CParzenWindowHistogramImpl {
CParzenWindowHistogramImpl(double low, double high,
size_t values, const std::vector<double>& samples);
~CParzenWindowHistogramImpl();
double at(double x) const;
double derivative(double x) const;
C1DSpacialKernelPlugin::ProductPtr kernel;
std::shared_ptr<T1DConvoluteInterpolator<double> > interp;
double range_low;
double range_high;
double target_shift;
double target_scale;
double output_scale;
};
CParzenWindowHistogram::CParzenWindowHistogram(double low, double high,
size_t values, const std::vector<double>& samples):
impl(new CParzenWindowHistogramImpl(low, high, values, samples))
{
}
CParzenWindowHistogram::~CParzenWindowHistogram()
{
delete impl;
}
double CParzenWindowHistogram::operator [] (double i) const
{
return impl->at(i);
}
double CParzenWindowHistogram::derivative (double i) const
{
return impl->derivative(i);
}
CParzenWindowHistogramImpl::CParzenWindowHistogramImpl(double low, double high,
size_t values, const vector<double>& samples):
range_low(low),
range_high(high),
target_shift(low)
{
ParzenWindowsNfftPDF2 *pwd = parzen_windows_nfft_pdf2_new(samples.size(), values, low, high);
vector<double> alpha(samples.size(), 1.0);
vector<double> fast_sumresult(values);
bool result = parzen_windows_nfft_pdf2_estimate(pwd, &samples[0], &alpha[0], &fast_sumresult[0]);
parzen_windows_nfft_pdf2_free(pwd);
if (!result)
throw invalid_argument("CParzenWindowHistogram: input data bogus (bad range or number of samples");
interp.reset(new T1DConvoluteInterpolator<double>(fast_sumresult, PSplineKernel(new CSplineKernel3())));
}
CParzenWindowHistogramImpl::~CParzenWindowHistogramImpl()
{
}
double CParzenWindowHistogramImpl::at(double x) const
{
// this should be an option of the interpolator
if (x >= range_low && x <= range_high)
return (*interp)(x);
else return 0.0;
}
double CParzenWindowHistogramImpl::derivative(double x) const
{
// this should be an option of the interpolator
if (x >= range_low && x <= range_high)
return interp->derivative_at(x);
else return 0.0;
}
NS_MIA_END
#endif