Skip to content

Commit a9cb82c

Browse files
committed
Added grid trilinear interpolation computation online. This will reduce the DLL memory requirements by a factor of 7 approximatelly
1 parent a61d71d commit a9cb82c

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/dllnode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class DLLNode
7777
m_tfCache = false;
7878

7979
// Compute trilinear interpolation map
80-
m_grid3d.computeTrilinearInterpolation();
80+
//m_grid3d.computeTrilinearInterpolation(); /* Now we compute the approximation online */
8181

8282
// Setup solver parameters
8383
m_solver.setMaxNumIterations(m_solverMaxIter);

src/dllsolver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DLLCostFunction
4848
nx = ca*_px - sa*_py + tx;
4949
ny = sa*_px + ca*_py + ty;
5050
nz = _pz + tz;
51-
p = _grid.getPointDistInterpolation(nx, ny, nz);
51+
p = _grid.computeDistInterpolation(nx, ny, nz);
5252
c0 = p.a0; c1 = p.a1; c2 = p.a2; c3 = p.a3; c4 = p.a4; c5 = p.a5; c6 = p.a6; c7 = p.a7;
5353

5454
residuals[0] = _weight*(c0 + c1*nx + c2*ny + c3*nz + c4*nx*ny + c5*nx*nz + c6*ny*nz + c7*nx*ny*nz);

src/grid3d.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,56 @@ class Grid3d
292292
return r;
293293
}
294294

295+
TrilinearParams computeDistInterpolation(const double x, const double y, const double z)
296+
{
297+
TrilinearParams r;
298+
299+
if(isIntoMap(x, y, z))
300+
{
301+
// Get 3D point index
302+
uint64_t i = point2grid(x, y, z);
303+
304+
// Get neightbour values to compute trilinear interpolation
305+
float c000, c001, c010, c011, c100, c101, c110, c111;
306+
c000 = m_grid[i].dist;
307+
c001 = m_grid[i+m_gridStepZ].dist;
308+
c010 = m_grid[i+m_gridStepY].dist;
309+
c011 = m_grid[i+m_gridStepY+m_gridStepZ].dist;
310+
c100 = m_grid[i+1].dist;
311+
c101 = m_grid[i+1+m_gridStepZ].dist;
312+
c110 = m_grid[i+1+m_gridStepY].dist;
313+
c111 = m_grid[i+1+m_gridStepY+m_gridStepZ].dist;
314+
315+
// Compute trilinear parameters
316+
const float div = -m_oneDivRes*m_oneDivRes*m_oneDivRes;
317+
float x0, y0, z0, x1, y1, z1;
318+
x0 = ((int)(x*m_oneDivRes))*m_resolution;
319+
x1 = x0+m_resolution;
320+
y0 = ((int)(y*m_oneDivRes))*m_resolution;
321+
y1 = y0+m_resolution;
322+
z0 = ((int)(z*m_oneDivRes))*m_resolution;
323+
z1 = z0+m_resolution;
324+
r.a0 = (-c000*x1*y1*z1 + c001*x1*y1*z0 + c010*x1*y0*z1 - c011*x1*y0*z0
325+
+ c100*x0*y1*z1 - c101*x0*y1*z0 - c110*x0*y0*z1 + c111*x0*y0*z0)*div;
326+
r.a1 = (c000*y1*z1 - c001*y1*z0 - c010*y0*z1 + c011*y0*z0
327+
- c100*y1*z1 + c101*y1*z0 + c110*y0*z1 - c111*y0*z0)*div;
328+
r.a2 = (c000*x1*z1 - c001*x1*z0 - c010*x1*z1 + c011*x1*z0
329+
- c100*x0*z1 + c101*x0*z0 + c110*x0*z1 - c111*x0*z0)*div;
330+
r.a3 = (c000*x1*y1 - c001*x1*y1 - c010*x1*y0 + c011*x1*y0
331+
- c100*x0*y1 + c101*x0*y1 + c110*x0*y0 - c111*x0*y0)*div;
332+
r.a4 = (-c000*z1 + c001*z0 + c010*z1 - c011*z0 + c100*z1
333+
- c101*z0 - c110*z1 + c111*z0)*div;
334+
r.a5 = (-c000*y1 + c001*y1 + c010*y0 - c011*y0 + c100*y1
335+
- c101*y1 - c110*y0 + c111*y0)*div;
336+
r.a6 = (-c000*x1 + c001*x1 + c010*x1 - c011*x1 + c100*x0
337+
- c101*x0 - c110*x0 + c111*x0)*div;
338+
r.a7 = (c000 - c001 - c010 + c011 - c100
339+
+ c101 + c110 - c111)*div;
340+
}
341+
342+
return r;
343+
}
344+
295345
bool computeTrilinearInterpolation(void)
296346
{
297347
// Delete existing parameters if the exists

0 commit comments

Comments
 (0)