Cogs.Core
SampleVolumeTask_Vanilla.cpp
1#if 0
2#include "SampleVolumeTask.h"
3
4using namespace Cogs::Core;
5
6using glm::uvec3;
7using glm::ivec3;
8using glm::vec3;
9using glm::clamp;
10using glm::max;
11using glm::min;
12using glm::floor;
13using glm::ceil;
14using glm::inverse;
15
16void EchoSounder::SampleVolumeTask2::runVanilla(TileValue * dstValues,
17 uint16_t * timeValues,
18 const EchoSounder::PingInfo* pinf,
19 const uint32_t upperFansToRemove,
20 const uint32_t numPings,
21 const uint32_t numSamples,
22 const uint32_t gridSizeX,
23 const uint32_t gridSizeY,
24 const float depthOffset,
25 const float depthStep,
26 const float sampleSpacing,
27 const float decay,
28 const std::vector<float>& beamAngleAlongship,
29 const std::vector<float>& beamAngleAthwartship,
30 const glm::ivec3& this_minIndex,
31 const glm::ivec3& this_maxIndex)
32{
33 const auto time = pinf->time;
34 const auto weight = 1.f;// / data.numPings;
35 const auto numBeamsMajor = static_cast<uint32_t>(beamAngleAlongship.size());
36 const auto numBeamsMinor = static_cast<uint32_t>(beamAngleAthwartship.size());
37 const auto s = 1.f / sampleSpacing;
38 //const auto width = data.cellWidth;
39
40 const vec3 minPolar(beamAngleAthwartship.front(),
41 beamAngleAlongship.front(),
42 depthOffset);
43 const vec3 maxPolar(beamAngleAthwartship.back(),
44 beamAngleAlongship.back(),
45 depthOffset + (numSamples - 1)*depthStep);
46
47
48 const uvec3 maxTau(max(2u, numBeamsMinor) - 2,
49 max(2u + upperFansToRemove, numBeamsMajor) - 2 - upperFansToRemove,
50 max(2u, numSamples) - 2);
51
52 // map minPolar to 0 and maxPolar to N-1.
53 const vec3 polarToIndex = vec3(max(2u, numBeamsMinor) - 2,
54 max(2u, numBeamsMajor) - 2,
55 max(2u, numSamples) - 2) / (maxPolar - minPolar);
56
57 const auto * minorMu = beamAngleAthwartship.data();
58 const auto * majorMu = beamAngleAlongship.data();
59
60 for (uint32_t p = 0; p < numPings; p++) {
61
62 const auto minIndex = this_minIndex;// max(this_minIndex, ivec3(floor(s * pinf[p].boundingBoxTile[0])));
63 const auto maxIndex = this_maxIndex;// min(this_maxIndex, ivec3(ceil(s * pinf[p].boundingBoxTile[1])));
64 const auto * srcValues = pinf[p].field;
65
66 const auto rot = inverse(pinf[p].metaPing.arrayOrientationGlobal);
67 const auto shift = pinf[p].arrayPositionTile;
68 for (int k = minIndex.z; k < maxIndex.z; k++) {
69 for (int j = minIndex.y; j < maxIndex.y; j++) {
70 for (int i = minIndex.x; i < maxIndex.x; i++) {
71
72 const auto samplePosGrid = sampleSpacing*vec3(i, j, k);
73 if (samplePosGrid.z < pinf[p].depthRestriction) {
74 continue;
75 }
76
77 const auto samplePosArray = (samplePosGrid - shift);
78 const auto r2 = glm::dot(samplePosArray, samplePosArray);
79
80 bool in = true;
81
82 // Early exit
83 bool in_0 = 0.f <= glm::dot(pinf[p].boundingFrustumNormals[0], samplePosArray);
84 bool in_1 = 0.f <= glm::dot(pinf[p].boundingFrustumNormals[1], samplePosArray);
85 bool in_2 = 0.f <= glm::dot(pinf[p].boundingFrustumNormals[2], samplePosArray);
86 bool in_3 = 0.f <= glm::dot(pinf[p].boundingFrustumNormals[3], samplePosArray);
87 bool in_4 = pinf[p].minDepthSquared <= r2;
88 bool in_5 = r2 <= pinf[p].maxDepthSquared;
89 if (!in_0 || !in_1 || !in_2 || !in_3 || !in_4 || !in_5) {
90 continue;
91 }
92 const auto cartesianPos = rot * samplePosArray;
93 float r = std::sqrt(r2);
94
95 const float dirX = std::asin(cartesianPos.x / r);
96 const float dirY = std::asin(cartesianPos.y / r);
97 const auto polarPos = glm::vec3(dirY, dirX, r);
98
99 auto xi = polarToIndex*(polarPos - minPolar);
100 auto tau = uvec3(xi);
101
102 bool range_1_0 = tau.x <= maxTau.x; // Negative is also handled here due to unsigned type.
103 bool range_1_1 = tau.y <= maxTau.y;
104 bool range_1_2 = tau.z <= maxTau.z;
105 if (!range_1_0 || !range_1_1 || !range_1_2) {
106 continue;
107 }
108
109 // Bi-linear interpolation, nearest nb along depth.
110 float bx = xi.x - tau.x;
111 float by = xi.y - tau.y;
112
113 const auto val00 = srcValues[((tau.y + 0)*numBeamsMinor + (tau.x + 0))*numSamples + tau.z];
114 const auto val01 = srcValues[((tau.y + 1)*numBeamsMinor + (tau.x + 0))*numSamples + tau.z];
115 const auto val0 = (1.f - by)*PingValue_Decode(val00) + by*PingValue_Decode(val01);
116
117 const auto val10 = srcValues[((tau.y + 0)*numBeamsMinor + (tau.x + 1))*numSamples + tau.z];
118 const auto val11 = srcValues[((tau.y + 1)*numBeamsMinor + (tau.x + 1))*numSamples + tau.z];
119 const auto val1 = (1.f - by)*PingValue_Decode(val10) + by*PingValue_Decode(val11);
120
121 const auto val = (1.f - bx)*val0 + bx*val1;
122
123 auto dstOffset = (k*gridSizeY + j)*gridSizeX + i;
124
125 auto oldValue = TileValue_Decode(dstValues[dstOffset]);
126 if (oldValue == 0.0) oldValue = val;
127
128 dstValues[dstOffset] = TileValue_Encode(0.5f*oldValue + 0.5f*val);
129 //dstValues[dstOffset] = max(oldValue, val);
130 timeValues[dstOffset] = time;
131 }
132 }
133 }
134 }
135}
136#endif
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....