ddemidov / mba

Scattered data interpolation with multilevel B-Splines
MIT License
73 stars 23 forks source link

Multivariate interpolation #13

Open ajg12 opened 3 years ago

ajg12 commented 3 years ago

Is it possible to interpolate several different variables at the same time?

include

int main() { // Coordinates of data points. std::vector<mba::point<2>> coo = { {0.0, 0.0}, {0.0, 1.0}, {1.0, 0.0}, {1.0, 1.0}, {0.4, 0.4}, {0.6, 0.6} };

**// Data values.
std::vector<double> val = {
    0.2, 0.0, 0.0, -0.2, -1.0, 1.0
};**

// Bounding box containing the data points.
mba::point<2> lo = {-0.1, -0.1};
mba::point<2> hi = { 1.1,  1.1};

// Initial grid size.
mba::index<2> grid = {3, 3};

// Algorithm setup.
mba::MBA<2> interp(lo, hi, grid, coo, val);

// Get interpolated value at arbitrary location.
double w = interp(mba::point<2>{0.3, 0.7});

}

I mean, if for example in the example of the introduction the variable "val" could be an array with different variables to interpolate instead of a vector that only has space for one variable (regardless of how long it is).

I know that the algorithm can be initialized with the different variables, but if it could be initialized with all the variables to interpolate at the same time, it would be more optimal, I think, can this be done?

ddemidov commented 3 years ago

I am sorry, I don't think I understand the question. Do you want to interpolate vector fields as opposed to scalar (double) fields? I think it should be possible to replace the value type (double) with a template parameter. So, with some minor modifications to the mba code, you could in principle use something like Eigen::Vector3d, or any type that provides overloaded arithmetic operations, instead of double. This is not something I am willing to do currently, but I would gladly accept a pull request.