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#include "GPULogging.h"
18
19using namespace o2::gpu;
20
21void GPUDisplay::opengl_spline::create(const vecpod<float>& x, const vecpod<float>& y)
22{
23 ma.clear();
24 mb.clear();
25 mc.clear();
26 md.clear();
27 mx.clear();
28 if (x.size() != y.size() || x.size() < 2) {
29 return;
30 }
31 int32_t k = x.size() - 1;
32 if (mVerbose) {
33 for (uint32_t i = 0; i < x.size(); i++) {
34 GPUInfo("Point %u: %f --> %f", i, x[i], y[i]);
35 }
36 }
37 ma.resize(k + 1);
38 mb.resize(k + 1);
39 mc.resize(k + 1);
40 md.resize(k + 1);
41 mx.resize(k + 1);
42 vecpod<float> h(k + 1), alpha(k + 1), l(k + 1), mu(k + 1), z(k + 1);
43 for (int32_t i = 0; i <= k; i++) {
44 ma[i] = y[i];
45 }
46 for (int32_t i = 0; i < k; i++) {
47 h[i] = x[i + 1] - x[i];
48 }
49 for (int32_t i = 1; i < k; i++) {
50 alpha[i] = 3.f / h[i] * (ma[i + 1] - ma[i]) - 3.f / h[i - 1] * (ma[i] - ma[i - 1]);
51 }
52 l[0] = l[k] = 1;
53 mu[0] = z[0] = z[k] = mc[k] = 0;
54 for (int32_t i = 1; i < k; i++) {
55 l[i] = 2.f * (x[i + 1] - x[i - 1]) - h[i - 1] * mu[i - 1];
56 mu[i] = h[i] / l[i];
57 z[i] = (alpha[i] - h[i - 1] * z[i - 1]) / l[i];
58 }
59 for (int32_t i = k - 1; i >= 0; i--) {
60 mc[i] = z[i] - mu[i] * mc[i + 1];
61 mb[i] = (ma[i + 1] - ma[i]) / h[i] - h[i] / 3.f * (mc[i + 1] + 2.f * mc[i]);
62 md[i] = (mc[i + 1] - mc[i]) / (3.f * h[i]);
63 }
64 for (int32_t i = 0; i <= k; i++) {
65 mx[i] = x[i];
66 }
67}
68
69float GPUDisplay::opengl_spline::evaluate(float x)
70{
71 int32_t base = 0;
72 const int32_t k = mx.size() - 1;
73 if (k < 0) {
74 return (0);
75 }
76 while (base < k - 1 && x > mx[base + 1]) {
77 base++;
78 }
79 float retVal = ma[base];
80 x -= mx[base];
81 const float xx = x;
82 retVal += mb[base] * x;
83 x *= xx;
84 retVal += mc[base] * x;
85 x *= xx;
86 retVal += md[base] * x;
87 if (mVerbose) {
88 GPUInfo("Evaluate: %f --> %f (basepoint %d)", xx, retVal, base);
89 }
90 return (retVal);
91}
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 double mu
Definition SpecsV2.h:32
typename std::vector< T, vecpod_allocator< T > > vecpod
Definition vecpod.h:31