Project
Loading...
Searching...
No Matches
GPUDisplayInterpolation.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include <cstdio>
16#include "GPUDisplay.h"
17
18using namespace o2::gpu;
19
20void GPUDisplay::opengl_spline::create(const vecpod<float>& x, const vecpod<float>& y)
21{
22 ma.clear();
23 mb.clear();
24 mc.clear();
25 md.clear();
26 mx.clear();
27 if (x.size() != y.size() || x.size() < 2) {
28 return;
29 }
30 int32_t k = x.size() - 1;
31 if (mVerbose) {
32 for (uint32_t i = 0; i < x.size(); i++) {
33 GPUInfo("Point %u: %f --> %f", i, x[i], y[i]);
34 }
35 }
36 ma.resize(k + 1);
37 mb.resize(k + 1);
38 mc.resize(k + 1);
39 md.resize(k + 1);
40 mx.resize(k + 1);
41 vecpod<float> h(k + 1), alpha(k + 1), l(k + 1), mu(k + 1), z(k + 1);
42 for (int32_t i = 0; i <= k; i++) {
43 ma[i] = y[i];
44 }
45 for (int32_t i = 0; i < k; i++) {
46 h[i] = x[i + 1] - x[i];
47 }
48 for (int32_t i = 1; i < k; i++) {
49 alpha[i] = 3.f / h[i] * (ma[i + 1] - ma[i]) - 3.f / h[i - 1] * (ma[i] - ma[i - 1]);
50 }
51 l[0] = l[k] = 1;
52 mu[0] = z[0] = z[k] = mc[k] = 0;
53 for (int32_t i = 1; i < k; i++) {
54 l[i] = 2.f * (x[i + 1] - x[i - 1]) - h[i - 1] * mu[i - 1];
55 mu[i] = h[i] / l[i];
56 z[i] = (alpha[i] - h[i - 1] * z[i - 1]) / l[i];
57 }
58 for (int32_t i = k - 1; i >= 0; i--) {
59 mc[i] = z[i] - mu[i] * mc[i + 1];
60 mb[i] = (ma[i + 1] - ma[i]) / h[i] - h[i] / 3.f * (mc[i + 1] + 2.f * mc[i]);
61 md[i] = (mc[i + 1] - mc[i]) / (3.f * h[i]);
62 }
63 for (int32_t i = 0; i <= k; i++) {
64 mx[i] = x[i];
65 }
66}
67
68float GPUDisplay::opengl_spline::evaluate(float x)
69{
70 int32_t base = 0;
71 const int32_t k = mx.size() - 1;
72 if (k < 0) {
73 return (0);
74 }
75 while (base < k - 1 && x > mx[base + 1]) {
76 base++;
77 }
78 float retVal = ma[base];
79 x -= mx[base];
80 const float xx = x;
81 retVal += mb[base] * x;
82 x *= xx;
83 retVal += mc[base] * x;
84 x *= xx;
85 retVal += md[base] * x;
86 if (mVerbose) {
87 GPUInfo("Evaluate: %f --> %f (basepoint %d)", xx, retVal, base);
88 }
89 return (retVal);
90}
int32_t i
int32_t retVal
Class for time synchronization of RawReader instances.
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
GLint GLenum GLint x
Definition glcorearb.h:403
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
constexpr float mu
Definition SpecsV2.h:27
typename std::vector< T, vecpod_allocator< T > > vecpod
Definition vecpod.h:31