Interpolation
Namespace: DISP3DLIB · Library: 3D Display Library
#include <disp3D/interpolation.h>
class DISP3DLIB::Interpolation
This class holds methods for creating distance-based weight matrices and for interpolating signals.
This class holds methods for creating distance-based weight matrices and for interpolating signals
QSharedPointer<SparseMatrix<float>> weights = Interpolation::createInterpolationMat(projected, distances, Interpolation::linear); // inverse-distance weights
const VectorXf atVertices = Interpolation::interpolateSignal(*weights, Vector2f(1.0f, 4.0f)); // one value per sensor
Public Methods
Interpolation()
Static Methods
createInterpolationMat(vecProjectedSensors, matDistanceTable, interpolationFunction, dCancelDist, vecExcludeIndex)
createInterpolationMat Calculates the weight matrix for interpolation.
Parameters:
-
vecProjectedSensors : const Eigen::VectorXi & Mesh vertex index of each sensor (one column per sensor).
-
matDistanceTable : const QSharedPointer<Eigen::MatrixXd> Distance table (nVertices x nSensors), e.g. from
GeometryInfo::scdc. -
interpolationFunction : double()(double)* Distance function whose inverse magnitude gives the weight.
-
dCancelDist : const double Distances at or above this value get zero weight.
-
vecExcludeIndex : const Eigen::VectorXi & Sensor column indices that are not pinned to their own vertex.
Returns:
- QSharedPointer< Eigen::SparseMatrix< float > > — Row-normalised sparse weight matrix (nVertices x nSensors), or an empty matrix if the table is empty.
interpolateSignal(matInterpolationMatrix, vecMeasurementData)
interpolateSignal Interpolates sensor data using the weight matrix (shared pointer version).
Parameters:
-
matInterpolationMatrix : const QSharedPointer< Eigen::SparseMatrix< float > > Weight matrix (nVertices x nSensors).
-
vecMeasurementData : const QSharedPointer<Eigen::VectorXf> & Sensor values (nSensors).
Returns:
- Eigen::VectorXf — Interpolated vertex values, or an empty vector on dimension mismatch.
interpolateSignal(matInterpolationMatrix, vecMeasurementData)
interpolateSignal Interpolates sensor data using the weight matrix (reference version).
Parameters:
-
matInterpolationMatrix : const Eigen::SparseMatrix< float > & Weight matrix (nVertices x nSensors).
-
vecMeasurementData : const Eigen::VectorXf & Sensor values (nSensors).
Returns:
- Eigen::VectorXf — Interpolated vertex values, or an empty vector on dimension mismatch.
linear(dIn)
linear Identity interpolation function.
Parameters:
- dIn : const double Input distance.
Returns:
- double — dIn unchanged.
gaussian(dIn)
gaussian Gaussian interpolation function (sigma=1).
Parameters:
- dIn : const double Input distance.
Returns:
- double — exp(-dIn^2 / 2).
square(dIn)
square Negative parabola interpolation function with y-offset of 1.
Parameters:
- dIn : const double Input distance.
Returns:
- double — max(1 - dIn^2 / 9, 0).
cubic(dIn)
cubic Cubic hyperbola interpolation function.
Parameters:
- dIn : const double Input distance.
Returns:
- double — dIn^3.
Example
- Full source:
src/examples/ex_disp3d_scene/main.cpp - Build target:
ex_disp3d_scene(runs under CTest)
Used in examples
ex_disp3d_scene
Disp3D scene data: sensor-to-surface interpolation, electrodes, MRI slices, video overlay and layers.
QSharedPointer<SparseMatrix<float>> weights = Interpolation::createInterpolationMat(projected, distances, Interpolation::linear); // inverse-distance weights
const VectorXf atVertices = Interpolation::interpolateSignal(*weights, Vector2f(1.0f, 4.0f)); // one value per sensor
// vertex 5: weights 1/2 and 1/4, normalised to 2/3 and 1/3 -> 1 * 2/3 + 4 * 1/3 = 2; vertex 3 is equidistant -> 2.5
ok &= expect(std::fabs(atVertices(0) - 1.0f) < 1e-6f && std::fabs(atVertices(15) - 4.0f) < 1e-6f && std::fabs(atVertices(5) - 2.0f) < 1e-6f && std::fabs(atVertices(3) - 2.5f) < 1e-6f,
QString("Interpolation: sensors kept, vertex 5 = %1, vertex 3 = %2").arg(atVertices(5)).arg(atVertices(3)));
ex_interpolation
Example of using the interpolation library and geometryInfo library.
//weight matrix
qint64 startTimeWMat = QDateTime::currentMSecsSinceEpoch();
QSharedPointer<SparseMatrix<float>> interpolationMatrix = Interpolation::createInterpolationMat(mappedSubSet,
distanceMatrix,
Interpolation::linear,
FLOAT_INFINITY);
std::cout << "Weight matrix duration: " << QDateTime::currentMSecsSinceEpoch() - startTimeWMat << " ms " << std::endl;
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>