Cogs.Core
DepthResampleTask.cpp
1#include <algorithm>
2#include "SinglePingIsoSurfacesTasks.h"
3#include "DepthResampleTask.h"
4#include "Platform/Instrumentation.h"
5
6using std::max;
7using std::min;
8using std::floor;
9
10using namespace Cogs::Core::EchoSounder;
11
12
13DepthResampleTask::DepthResampleTask(float* valuesOut,
14 const float depthStepOut,
15 const int sampleCountOut,
16 const float* valuesIn,
17 const float depthStepIn,
18 const int sampleCountIn,
19 const int beamBegin,
20 const int beamEnd)
21 :
22 valuesOut(valuesOut),
23 depthStepOut(depthStepOut),
24 sampleCountOut(sampleCountOut),
25 valuesIn(valuesIn),
26 depthStepIn(depthStepIn),
27 sampleCountIn(sampleCountIn),
28 beamBegin(beamBegin),
29 beamEnd(beamEnd)
30{ }
31
32
33void DepthResampleTask::operator()()
34{
35 CpuInstrumentationScope(SCOPE_ECHOSOUNDER, "DepthResample");
36
37 //const auto depthStepIn = parent->depthStep;
38 //const auto depthStepOut = parent->depthStepResample;
39 //const auto sampleCountIn = parent->sampleCount;
40 //const auto sampleCountOut = parent->sampleCountResample;
41
42 const auto inStepOut = depthStepOut / depthStepIn; //depthStepIn / depthStepOut;
43
44 const auto Q = std::max(1, sampleCountIn) - 1;
45 for (int b = beamBegin; b < beamEnd; b++) {
46 const auto * currIn = valuesIn + b*sampleCountIn;
47 auto * currOut = valuesOut + b*sampleCountOut;
48 int j0 = 0;
49 float j1f = inStepOut;
50 float val0 = currIn[0];
51 for (int i = 0; i < sampleCountOut; i++, j1f += inStepOut) {
52 int j1 = min(Q, static_cast<int>(floor(j1f)));
53 float acc = val0;
54 for (int k = j0 + 1; k + 1 < j1; k++) {
55 acc += currIn[k];
56 }
57 if (j0 != j1) {
58 val0 = currIn[j1];
59 }
60 acc += val0;
61 auto res = acc / (max(1, j1 - j0) + 1.f);
62 currOut[i] = res;
63 j0 = j1;
64 }
65 }
66
67}