3 //#define GRID_POINT_FULL -2
4 //#define GRID_POINT_EMPTY -1
10 //TODO change these back into #defines up top
11 private static int GRID_POINT_FULL;
12 private static int GRID_POINT_EMPTY;
18 public int[][] points_unaligned;
28 /* =============================================================================
30 * =============================================================================
31 grid_t* grid_alloc (long width, long height, long depth);
33 well... need to implement
36 public Grid alloc(int width,int height,int depth) {
37 Grid grid = new Grid();
45 int n = width * height * depth;
47 // long* points_unaligned = (long*) malloc(n*sizeof(long) + CACHE_LINE_SIZE);
48 int[][] points_unaligned = new int[n][1];
50 grid.points_unaligned = points_unaligned;
53 grid.points_unaligned[i][0] = grid.GRID_POINT_EMPTY;
61 /* =============================================================================
63 * =============================================================================
65 //grid_t* Pgrid_alloc (long width, long height, long depth);
68 /* =============================================================================
70 * =============================================================================
71 void grid_free (grid_t* gridPtr);
75 public static void free(Grid gridPtr) {
80 /* =============================================================================
82 * =============================================================================
83 void Pgrid_free (grid_t* gridPtr);
88 /* =============================================================================
90 * =============================================================================
91 void grid_copy (grid_t* dstGridPtr, grid_t* srcGridPtr);
93 public void copy(Grid dstGridPtr, Grid srcGridPtr)
95 if((srcGridPtr.width == dstGridPtr.width) ||
96 (srcGridPtr.height == dstGridPtr.height) ||
97 (srcGridPtr.depth == dstGridPtr.depth))
99 int n = srcGridPtr.width * srcGridPtr.height * srcGridPtr.depth;
102 dstGridPtr.points_unaligned[i][0] =
103 srcGridPtr.points_unaligned[i][0];
107 System.out.println("Grid copy failed");
113 /* =============================================================================
115 * =============================================================================
116 bool_t grid_isPointValid (grid_t* gridPtr, long x, long y, long z);
118 public boolean isPointValid(int x,int y,int z)
120 if(x < 0 || x >= width ||
121 y < 0 || y >= height ||
131 /* =============================================================================
133 * =============================================================================
134 long* grid_getPointRef (grid_t* gridPtr, long x, long y, long z);
136 it is returning the index of the point
138 public int getPointIndex(int x,int y,int z)
140 return ((z * height) + y) * width + x;
144 /* =============================================================================
145 * grid_getPointIndices
146 * =============================================================================
147 void grid_getPointIndices (grid_t* gridPtr,
148 long* gridPointPtr, long* xPtr, long* yPtr, long* zPtr);
150 public void getPointIndices(int gridPointIndex,int[] xPtr, int[] yPtr,int[] zPtr)
152 int height = this.height;
153 int width = this.width;
154 int area = height * width;
155 int index3d = (gridPointIndex);
156 zPtr[0] = index3d / area;
157 int index2d = index3d % area;
158 yPtr[0] = index2d / width;
159 xPtr[0] = index2d % width;
163 /* =============================================================================
165 * =============================================================================
166 long grid_getPoint (grid_t* gridPtr, long x, long y, long z);
168 public int getPoint(int x,int y,int z)
170 return this.points_unaligned[getPointIndex(x,y,z)][0];
173 public int getPoint(int index)
175 return this.points_unaligned[index][0];
182 //added to support redos
183 public Coordinate getCoordinate(int index)
185 //((z * height) + y) * width + x;
186 Coordinate c = new Coordinate();
187 int x = index % width;
188 int y = (index/width)%height;
189 int z = (index/width)/height;
191 //TODO remove after debugging
192 if(index != this.getPoint(x, y, z))
193 System.out.println("getCordinate() in Grid.java FAILS...");
195 return c.alloc(x, y, z);
198 /* =============================================================================
200 * =============================================================================
201 bool_t grid_isPointEmpty (grid_t* gridPtr, long x, long y, long z);
203 public boolean isPointEmpty(int x,int y,int z)
205 int value = getPoint(x,y,z);
206 return ((value == GRID_POINT_EMPTY) ? true:false);
211 /* =============================================================================
213 * =============================================================================
214 bool_t grid_isPointFull (grid_t* gridPtr, long x, long y, long z);
216 public boolean isPointFull(int x,int y,int z)
218 int value = getPoint(x,y,z);
219 return ((value == GRID_POINT_FULL) ? true : false);
223 /* =============================================================================
225 * =============================================================================
226 void grid_setPoint (grid_t* gridPtr, long x, long y, long z, long value);
228 public void setPoint(int x,int y,int z,int value)
230 points_unaligned[getPointIndex(x,y,z)][0] = value;
234 /* =============================================================================
236 * =============================================================================
238 void grid_addPath (grid_t* gridPtr, vector_t* pointVectorPtr);
241 public void addPath(Vector_t pointVectorPtr)
244 int n = pointVectorPtr.vector_getSize();
246 for(i = 0; i < n; i++) {
247 Coordinate coordinatePtr = (Coordinate)pointVectorPtr.vector_at(i);
248 int x = coordinatePtr.x;
249 int y = coordinatePtr.y;
250 int z = coordinatePtr.z;
252 // System.out.println("x = " + x + " y = " + y + " z = " + z);
253 setPoint(x,y,z,GRID_POINT_FULL);
257 public void TM_addPath(Vector_t pointVectorPtr)
260 int n = pointVectorPtr.vector_getSize();
262 for(i = 0; i < n; i++) {
263 int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
264 points_unaligned[gridPointIndex][0] = GRID_POINT_FULL;
268 /* =============================================================================
270 * =============================================================================
273 TMgrid_addPath (TM_ARGDECL grid_t* gridPtr, vector_t* pointVectorPtr);
277 /* =============================================================================
279 * =============================================================================
280 void grid_print (grid_t* gridPtr);
286 for(z = 0; z < depth; z++) {
287 System.out.println("[z = " + z + "]");
289 for(x = 0; x < width; x++) {
291 for(y = 0; y < height; y++) {
292 System.out.print(points_unaligned[getPointIndex(x,y,z)][0] + " ");
294 System.out.println("");
296 System.out.println("");
302 /* =============================================================================
306 * =============================================================================