/usr/include/mia-2.0/mia/core/splinekernel.hh is in libmia-2.0-dev 2.0.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | /* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2013 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_splinekernel_hh
#define mia_core_splinekernel_hh
#include <vector>
#include <memory>
#include <cmath>
#include <mia/core/defines.hh>
#include <mia/core/dictmap.hh>
#include <mia/core/factory.hh>
#include <mia/core/product_base.hh>
NS_MIA_BEGIN
class CSplineBoundaryCondition;
/**
\ingroup interpol
\brief Base class for all spline based interpolation kernels.
The kernel of spline based interpolations that provides the interface to
evaluate weights and indices into the coefficient field.
*/
class EXPORT_CORE CSplineKernel : public CProductBase{
public:
/// helper typedef for plugin handling
typedef CSplineKernel plugin_data;
/// helper typedef for plugin handling
typedef CSplineKernel plugin_type;
/// plugin handling type description
static const char *type_descr;
/// plugin handling data description
static const char *data_descr;
/// type for the weight vector
typedef std::vector<double> VWeight;
/// type for the index vector
typedef std::vector<int> VIndex;
/**
A struture to cache B-spline weights and indices
*/
struct SCache {
/**
Initialize the case by setting the index and weight array size and
mirror boundary sizes
@param s support size of the kernel which equals the size of the index and weight arrays
@param bc Boundary conditions to be used, this is a reference to the parent interpolator object
@param am set to true if indices always need to be set
*/
SCache(size_t s, const CSplineBoundaryCondition& bc, bool am);
/**
reset the parameters of the cache
*/
void reset();
/** last location the B-spline was evaluated at. This value is initialized to NaN
to make sure we
*/
double x;
/// last start index the B-spline was evaluated for
int start_idx;
/// last possible start index
int index_limit;
/// cached weights
VWeight weights;
/// cached indices
VIndex index;
/// the boundary condition to be applied
const CSplineBoundaryCondition& boundary_condition;
/// store whether indices were mirrored
bool is_flat;
/// always use mirror
bool never_flat;
};
/**
@param degree of the spline
@param shift location shift of the input coordinate to obtain the proper support
@param type interpolation type
@remark why to I give the type, it should alwas be bspline
*/
CSplineKernel(int degree, double shift, EInterpolation type);
/**
The virtual destructor is just here to avoid some warning
*/
virtual ~CSplineKernel();
/**
This operator evaluates the weights and indices of the interpolation
\param x input coordinate
\param[out] weight weights of the interpolation
\param[out] index indices corresponding to the weights, No boundary conditions are applied.
*/
void operator () (double x, VWeight& weight, VIndex& index)const;
/**
This operator evaluates the weights and indices of the interpolation at a given position.
The boundary conditions given in the value cache are applied.
The result is stored in the return value cache and this cache is only updated if neccesary
\param x location for which to evaluate weights and indices
\param[in,out] cache storage for returned value
*/
void operator () (double x, SCache& cache)const;
/**
This operator evaluates the weights and indices of the interpolation at a given position.
The boundary conditions given in the value cache are applied.
The result is stored in the return value cache and this cache is only updated if neccesary.
The index set is always fully set.
\param x location for which to evaluate weights and indices
\param[in,out] cache storage for returned value
*/
void get_cached(double x, SCache& cache)const;
/**
This operator evaluates the weights and indices of the interpolation at a given position.
The boundary conditions given in the value cache are applied.
The result is stored in the return value cache and this cache is always updated.
The index set will only be set correctly if the boundary conditions had to be applied.
\param x location for which to evaluate weights and indices
\param[in,out] cache storage for returned value
*/
void get_uncached(double x, SCache& cache)const;
/**
Evaluate the first order derivative weights of the B-Spline at the given position
@param x location where to evaluate the derivative
@param[out] weight the interpolation weights are stored here
@param[out] index the interpolation coefficient intices are stored here
*/
void derivative(double x, VWeight& weight, VIndex& index)const;
/**
Evaluate the derivative weights of the B-Spline at the given position
@param x location where to evaluate the derivative
@param[out] weight the interpolation weights are stored here
@param[out] index the interpolation coefficient intices are stored here
@param order order of the derivative to be evaluated
*/
void derivative(double x, VWeight& weight, VIndex& index, int order)const;
/**
Evaluate the indices of the coefficients that would be used for interpolation
@param x location where to evaluate
@param[out] index the interpolation coefficient indices are stored here
@returns start index
*/
int get_indices(double x, VIndex& index) const;
/** evaluate the weights, this needs to be implemented for a specific spline
\param x coordinate
\param[out] weight the weights
\remark why is this not a private function?
*/
virtual void get_weights(double x, VWeight& weight) const = 0;
/** evaluate the first order derivative weights, this needs to be implemented for a specific spline
\param x coordinate
\param[out] weight the weights
\remark why is this not a private function?
*/
virtual void get_derivative_weights(double x, VWeight& weight) const = 0;
/** evaluate the first order derivative weights, this needs to be implemented for a specific spline
\param x coordinate
\param[out] weight the weights
\param order derivative order
\remark why is this not a private function?
*/
virtual void get_derivative_weights(double x, VWeight& weight, int order) const = 0;
/**
Evaluate the weight at a single position
\param x location to evaluate B-spline at
\param order order of derivative to be evaluated (0 = value)
\returns B-spline weight
*/
virtual double get_weight_at(double x, int order) const;
/// @returns the type of this interpolator
EInterpolation get_type() const;
/**
\returns the poles of the spline used for pre-filtering
*/
const std::vector<double>& get_poles() const;
/**
\returns the size of the support of this kernel
*/
size_t size() const;
/// \returns the radius around zero where the B-spline does not evaluate to zero
double get_nonzero_radius() const;
///\returns the number of the neighboring grind points used on each side of the center
int get_active_halfrange()const;
/**
Evaluate the first coefficient index and the weights vor B-spline interpolation
\param x location to evaluate the spline at
\param[out] weights weights of the B-spline
\returns first index into the coefficient field to be used - note this may be a negiative value
*/
int get_start_idx_and_value_weights(double x, VWeight& weights) const;
/**
Evaluate the first coefficient index and the derivative weights vor B-spline interpolation
\param x location to evaluate the spline at
\param[out] weights weights of the B-spline
\returns first index into the coefficient field to be used - note this may be a negiative value
*/
int get_start_idx_and_derivative_weights(double x, VWeight& weights) const;
protected:
/** add a pole to the list of poles
\param x
*/
void add_pole(double x);
private:
int get_start_idx(double x) const;
/**
Helper function to fill the array index with consecutive values starting with i
*/
void fill_index(short i, VIndex& index) const;
size_t m_half_degree;
double m_shift;
std::vector<double> m_poles;
size_t m_support_size;
EInterpolation m_type;
std::vector<short> m_indices;
};
/**
\ingroup interpol
Pointer type for spline kernels
*/
typedef std::shared_ptr<CSplineKernel> PSplineKernel;
/// base plugin for spline kernels
typedef TFactory<CSplineKernel> CSplineKernelPlugin;
/**
\ingroup interpol
Plugin handler for the creation of spline kernels
*/
typedef THandlerSingleton<TFactoryPluginHandler<CSplineKernelPlugin> > CSplineKernelPluginHandler;
/**
\ingroup interpol
Create a spline kernel by using the provided plug-ins
\param descr the spline kernel description (e.g. "bspline:d=3" for a B-spline kernel of degree 3)
\returns the spline kernel stored in a shared pointer PSplineKernel.
*/
inline PSplineKernel produce_spline_kernel(const std::string& descr)
{
return CSplineKernelPluginHandler::instance().produce(descr);
}
FACTORY_TRAIT(CSplineKernelPluginHandler);
/**
\ingroup tests
Class to set up the plug-in search path for spline kernels when running tests
in the build tree
*/
struct EXPORT_CORE CSplineKernelTestPath {
CSplineKernelTestPath();
};
/**
@cond INTERNAL
@ingroup traits
@brief helper to determain the besr accuracy scalar type that type T can be converted to
*/
template <>
struct __cache_policy<CSplineKernelPlugin> {
static bool apply() {
return true;
}
};
template <typename T>
struct max_hold_type {
typedef double type;
};
/**
@ingroup traits
@brief trait to obtaine the type the spline coefficients are best represented in
*/
template <class T>
struct coeff_map {
typedef T value_type;
typedef double coeff_type;
};
/**
@ingroup traits
@brief specialization that marks that float should not be translated to double float
*/
template <>
struct coeff_map<float> {
typedef float value_type;
typedef float coeff_type;
};
/// @endcond
inline size_t CSplineKernel::size()const
{
return m_support_size;
}
/**
Approximate integration of a B-Spline kernel product
\f[
\int_{x_0}^L \frac{\partial^{d_1}}{\partial x^{d_1}} \beta(x - s_1)
\frac{\partial^{d_2}}{\partial x^{d_2}} \beta(x - s_2) dx
\f]
using the Simpson integration.
@param spline kernel \f$\beta\f$
@param s1
@param s2
@param d1
@param d2
@param n number of integration intervals
@param x0 start of interval
@param L end of interval
@returns value of integral
*/
double EXPORT_CORE integrate2(const CSplineKernel& spline, double s1, double s2, int d1, int d2, double n, double x0, double L);
NS_MIA_END
#endif
|