Hello.
This is my first time using a forum, so please bear with me and my ignorance.
I’m a 3rd year university student, and am currently tackling a dissertation project in a Visualisation of a 3D terrain using Java 3d.
I am currently trying to create a 3D Array to hold elevation data for my landscape. I am using the StringTokenizer to read in a elevation data set file, and store it in my array. The Data file contains [3] - colums [51] - rows and [51] sets of these data values. This has been taken from a map of a landscape, where i broke the map down into a grid of 51 * 51 squares. Each square has data pertaining to x, height, and y values - eg. (2, 11400, 12)
with an “a” separating each column of information, and a “b”
I am currently getting compiler errors which i cannot understand, ??? and was hoping someone could give me some advice on the section of code which i am about to show.
Any help would be much appreciated
thank you for your time
package terraingrid;
import java.io.;
import java.util.;
/**
*
-
@author Owner
*/
public class Reader {// instance made using empty constructor of reader1 class
Reader reader = new Reader();
int col;
int row;
int height;/** Creates a new instance of Reader */
public Reader() {}
public void ReaderOfArray(){
// can access the array as follows
ArrayMaker myarray = new ArrayMaker();
int col = reader.ArrayMaker.myarray[0][0][0]; // = x of [0][0]
int row = reader.ArrayMaker.myarray[1][10][29]; // = y of [10][29] etc
int height = reader.ArrayMaker.myarray[10][30][1]; // = height of [][]
// and to run the Test1 Method
reader.Test1();
}
//could be in a file Reader1.java and then public class Reader1{ //etc
//Test1 is created to read in the file containing all the elevation
//data for the 3D Polygon Model to be created to represent the
//landscape
class ReaderTokenizer {
//---------------FIELDS================================
//instance of the array class
//ArrayMaker myarray = new ArrayMaker();
//or with other constructor
ArrayMaker myarray = new ArrayMaker();
//--------CONSTRUCTORS-----------------------------------------------------------
//empty constructor
public ReaderTokenizer(){
int col[];
int row[];
int height[];
}
//------------------METHODS=============================
// don’t make static
public void Test1() throws FileNotFoundException, IOException{
FileReader file = new FileReader
("H:\\University of Liverpool\\3rd Year\\COMP390 - Dissertation\\edited terrain data\\EDF.txt");
//remember to change the pathname of the file
BufferedReader fileInput = new BufferedReader(file);
int col, row, height;
ArrayMaker myarray = new ArrayMaker();
String token;
// Read file
StringTokenizer Tokenizer = new StringTokenizer(fileInput.readLine(),"(),", true);
while (Tokenizer.hasMoreTokens()) {
for(col = 0; col < myarray.length; col++){
for(row = 0; row < myarray[col].length; row++){
// recognize the ( and go to next token
token = Tokenizer.nextToken();
System.out.println(token);
col = Integer.parseInt(token = Tokenizer.nextToken());
// recognize the , and go to next token
token = Tokenizer.nextToken();
System.out.println(token);
row = Integer.parseInt(token = Tokenizer.nextToken());
// recognize the , and go to next token
token = Tokenizer.nextToken();
System.out.println(token);
height = Integer.parseInt(token = Tokenizer.nextToken());
//recognize the ) and go to next token
token = Tokenizer.nextToken();
System.out.println(token);
//access the instance of arraymaker made as a field to access the array and set values
ArrayMaker.myarray[0][col][row] = col;
ArrayMaker.myarray[1][col][row] = row;
ArrayMaker.myarray[2][col][row] = height;
//the For loops set [x,y,z][row][0 to 50](inner loop)
//outer loops sets [x,y,z][0][0 to 50], [x,y,z][1][0 to 50], [x,y,z][2][0 to 50], etc
}//end inner for loop
}//end outer for loop
//need to put these inside loop, may need to play about with it
//dataLine = new StringTokenizer(fileInput.readLine());
if (Tokenizer.nextToken().compareTo("a")==0){
token = Tokenizer.nextToken();
}//space between brackets
else {
}
if (Tokenizer.nextToken().compareTo("b")==0){
break;
}//space between brackets
else {
}
}// end Test1 method
}//end class
}
class ArrayMaker {
int[][][] myarray = new int[3][51][51]; // this is 51 by 51 with indices 0 to 50
//constructor to initialise my array as public, for use by all
//inner classes of class Reader
public ArrayMaker(){
ArrayMaker myarray = new ArrayMaker();
}
public ArrayMaker(int nocol,int norows, int noheight){
myarray = new int[nocol][norows][noheight];
}
//
//no methods for this class
}
}