1 // This is gel/octree/VoxmapPoints.cxx
2 //:
3 // \file
4 // \author
5 // Author: Geoffrey Cross, Oxford RRG
6 // Created: 17 May 99
7 // Modifications:
8 //   990517 Geoff Initial version.
9 //
10 //-----------------------------------------------------------------------------
11 
12 #include <utility>
13 #include "VoxmapPoints.h"
14 
15 // Default ctor
VoxmapPoints(int d,vnl_double_3 c,double s)16 VoxmapPoints::VoxmapPoints( int d, vnl_double_3 c, double s)
17   : depth(d),
18     nocorners( int(1<<depth)+1),
19     nocentres( int(1<<depth)),
20     centre(c),
21     size(s)
22     //    corners( nocorners, nocorners, nocorners),
23     //    centres( nocentres, nocentres, nocentres)
24 {
25 }
26 
27 
GetCentre(int x,int y,int z,int d) const28 vnl_double_3 VoxmapPoints::GetCentre( int x, int y, int z, int d) const
29 {
30   if (d!= depth)
31     return GetCorner( x*2,y*2,z*2,1,1,1,d+1);
32 
33   if (centres.fullp(x,y,z))
34     return centres(x,y,z);
35 
36   vnl_double_3 np( centre[0]-size/2+size/nocentres*(x+0.5),
37                    centre[1]-size/2+size/nocentres*(y+0.5),
38                    centre[2]-size/2+size/nocentres*(z+0.5));
39 
40   centres.put(x,y,z,np);
41 
42   return np;
43 }
44 
45 
GetCorner(int x,int y,int z,int dx,int dy,int dz,int d) const46 vnl_double_3 VoxmapPoints::GetCorner( int x, int y, int z, int dx, int dy, int dz, int d) const
47 {
48   int dd= 1<<(depth-d);
49 
50   int ix= (x+dx)*dd;
51   int iy= (y+dy)*dd;
52   int iz= (z+dz)*dd;
53 
54   if (corners.fullp(ix,iy,iz))
55     return cornerpoints[corners(ix,iy,iz)];
56 
57   vnl_double_3 np( centre[0]-size/2+(ix)*size/(nocorners-1),
58                    centre[1]-size/2+(iy)*size/(nocorners-1),
59                    centre[2]-size/2+(iz)*size/(nocorners-1));
60 
61   corners.put(ix,iy,iz,cornerpoints.size());
62   cornerpoints.push_back( np);
63 
64   return np;
65 }
66 
67 
GetCornerIndex(int x,int y,int z,int dx,int dy,int dz,int d) const68 int VoxmapPoints::GetCornerIndex( int x, int y, int z, int dx, int dy, int dz, int d) const
69 {
70   int dd= 1<<(depth-d);
71 
72   int ix= (x+dx)*dd;
73   int iy= (y+dy)*dd;
74   int iz= (z+dz)*dd;
75 
76   if (corners.fullp(ix,iy,iz))
77     return corners(ix,iy,iz);
78 
79   vnl_double_3 np( centre[0]-size/2+(ix)*size/(nocorners-1),
80                    centre[1]-size/2+(iy)*size/(nocorners-1),
81                    centre[2]-size/2+(iz)*size/(nocorners-1));
82 
83   corners.put(ix,iy,iz,cornerpoints.size());
84   cornerpoints.push_back( np);
85 
86   return cornerpoints.size()-1;
87 }
88 
89 #include "vbl/vbl_sparse_array_3d.hxx"
90 VBL_SPARSE_ARRAY_3D_INSTANTIATE(vnl_double_3);
91