1 /* =============================================================================
5 * =============================================================================
7 * Copyright (C) Stanford University, 2006. All Rights Reserved.
10 * =============================================================================
12 * For the license of bayes/sort.h and bayes/sort.c, please see the header
15 * ------------------------------------------------------------------------
17 * For the license of kmeans, please see kmeans/LICENSE.kmeans
19 * ------------------------------------------------------------------------
21 * For the license of ssca2, please see ssca2/COPYRIGHT
23 * ------------------------------------------------------------------------
25 * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26 * header of the files.
28 * ------------------------------------------------------------------------
30 * For the license of lib/rbtree.h and lib/rbtree.c, please see
31 * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
33 * ------------------------------------------------------------------------
35 * Unless otherwise noted, the following license applies to STAMP files:
37 * Copyright (c) 2007, Stanford University
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions are
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
47 * * Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
52 * * Neither the name of Stanford University nor the names of its
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66 * THE POSSIBILITY OF SUCH DAMAGE.
68 * =============================================================================
71 import java.lang.Long;
77 public int[][][] points_unaligned;
79 public static int GRID_POINT_FULL;
80 public static int GRID_POINT_EMPTY;
85 GRID_POINT_EMPTY = -1;
88 /* =============================================================================
90 * =============================================================================
91 grid_t* grid_alloc (long width, long height, long depth);
93 well... need to implement
96 public static Grid alloc(int width,int height,int depth) {
97 Grid grid = new Grid();
100 grid.height = height;
103 int[][][] points_unaligned = new int[width][height][depth];
106 for(int i=0;i<width;i++)
107 for(int j=0;j<height;j++)
108 for(int k=0;k<depth;k++)
109 points_unaligned[i][j][k]= GRID_POINT_EMPTY;
111 grid.points_unaligned = points_unaligned;
116 public static Grid scratchalloc(int width,int height,int depth) {
117 Grid grid = new Grid();
119 grid.height = height;
121 int[][][] points_unaligned = new int[width][height][depth];
122 grid.points_unaligned = points_unaligned;
128 /* =============================================================================
130 * =============================================================================
131 void grid_copy (grid_t* dstGridPtr, grid_t* srcGridPtr);
133 public static void copy(Grid dstGridPtr,Grid srcGridPtr) {
134 if((srcGridPtr.width == dstGridPtr.width) ||
135 (srcGridPtr.height == dstGridPtr.height) ||
136 (srcGridPtr.depth == dstGridPtr.depth)) {
137 deepArrayCopy(dstGridPtr.points_unaligned, srcGridPtr.points_unaligned);
141 //Array copy function added to replace System.deepArrayCopy in original
142 //assumes they are of the same size
143 private static void deepArrayCopy(int[][][] dst, int[][][] src)
145 for(int i = 0; i < src.length; i++)
146 for(int j = 0; j < src[i].length; j++)
147 for(int k = 0; k < src[i][j].length; k++)
148 dst[i][j][k] = src[i][j][k];
151 /* =============================================================================
153 * =============================================================================
154 bool_t grid_isPointValid (grid_t* gridPtr, long x, long y, long z);
156 public boolean isPointValid(int x,int y,int z) {
157 return x>=0 && x< width && y>=0 && y<height && z>=0 && z<depth;
161 public int getPoint(int x,int y,int z) {
162 return this.points_unaligned[x][y][z];
166 /* =============================================================================
168 * =============================================================================
169 bool_t grid_isPointEmpty (grid_t* gridPtr, long x, long y, long z); {
172 public boolean isPointEmpty(int x,int y,int z) {
173 return points_unaligned[x][y][z]==GRID_POINT_EMPTY;
178 /* =============================================================================
180 * =============================================================================
181 bool_t grid_isPointFull (grid_t* gridPtr, long x, long y, long z);
183 public boolean isPointFull(int x,int y,int z) {
184 return points_unaligned[x][y][z]==GRID_POINT_FULL;
188 /* =============================================================================
190 * =============================================================================
191 void grid_setPoint (grid_t* gridPtr, long x, long y, long z, long value);
193 public void setPoint(int x,int y,int z,int value) {
194 points_unaligned[x][y][z] = value;
198 /* =============================================================================
200 * =============================================================================
202 void grid_addPath (grid_t* gridPtr, vector_t* pointVectorPtr);
204 public void addPath(Vector_t pointVectorPtr) {
206 int n = pointVectorPtr.vector_getSize();
208 for(i = 0; i < n; i++) {
209 Coordinate coordinatePtr = (Coordinate)pointVectorPtr.vector_at(i);
210 int x = coordinatePtr.x;
211 int y = coordinatePtr.y;
212 int z = coordinatePtr.z;
214 points_unaligned[x][y][z]=GRID_POINT_FULL;
218 public boolean TM_addPath(Vector_t pointVectorPtr) {
220 int n = pointVectorPtr.vector_getSize();
222 int height = this.height;
223 int width = this.width;
224 int area = height * width;
225 boolean dowrites=true;
226 for(i = 1; i < (n-1); i++) {
227 int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
228 int z = gridPointIndex / area;
229 int index2d = gridPointIndex % area;
230 int y = index2d / width;
231 int x = index2d % width;
232 if (points_unaligned[x][y][z] != GRID_POINT_EMPTY) {
237 for(i = 1; i < (n-1); i++) {
238 int gridPointIndex = ((Integer)(pointVectorPtr.vector_at(i))).intValue();
239 int z = gridPointIndex / area;
240 int index2d = gridPointIndex % area;
241 int y = index2d / width;
242 int x = index2d % width;
243 int[] array=points_unaligned[x][y];
244 if (dowrites) array[z] = GRID_POINT_FULL;
249 public int getPointIndex(int x,int y,int z) {
250 return ((z * height) + y) * width + x;
254 public void print() {
255 int width = this.width;
256 int height = this.height;
257 int depth = this.depth;
259 for (int z = 0; z < depth; z++) {
260 System.out.println("[z ="+z+"]");
261 for (int x = 0; x < width; x++) {
262 for (int y = 0; y < height; y++) {
263 String str=String.valueOf(points_unaligned[x][y][z]);
264 for(int sp=0; sp<(4-str.length());sp++)
265 System.out.print(" ");
266 System.out.print(str);
268 System.out.println("");
270 System.out.println("");
276 /* =============================================================================
280 * =============================================================================