Let FileDataset load coordinates by specifying column ID for X, Y and Z

dimension.
This commit is contained in:
Martin Pernollet 2017-08-09 14:42:24 +02:00
parent 82d23a2992
commit 5b5016515e
1 changed files with 63 additions and 59 deletions

View File

@ -10,69 +10,73 @@ import org.jzy3d.maths.Coord3d;
import au.com.bytecode.opencsv.CSVReader;
public class FileDataset {
public static Coord3d[] loadArray(String filename) throws IOException {
int size = readNLines(filename);
float x;
float y;
float z;
public static Coord3d[] loadArray(String filename) throws IOException {
int size = readNLines(filename);
float x;
float y;
float z;
Coord3d[] coords = new Coord3d[size];
Coord3d[] coords = new Coord3d[size];
// Load file
CSVReader reader = new CSVReader(new FileReader(filename));
String[] nextLine;
int k = 0;
while ((nextLine = reader.readNext()) != null) {
if (nextLine.length < 3)
continue;
x = Float.parseFloat(nextLine[0]);
y = Float.parseFloat(nextLine[1]);
z = Float.parseFloat(nextLine[2]);
coords[k++] = new Coord3d(x, y, z);
}
reader.close();
return coords;
}
public static List<Coord3d> loadList(String filename) throws IOException {
float x;
float y;
float z;
// Load file
CSVReader reader = new CSVReader(new FileReader(filename));
String[] nextLine;
int k = 0;
while ((nextLine = reader.readNext()) != null) {
if (nextLine.length < 3)
continue;
x = Float.parseFloat(nextLine[0]);
y = Float.parseFloat(nextLine[1]);
z = Float.parseFloat(nextLine[2]);
coords[k++] = new Coord3d(x, y, z);
}
reader.close();
return coords;
}
List<Coord3d> coords = new ArrayList<Coord3d>();;
public static List<Coord3d> loadList(String filename) throws IOException {
return loadList(filename, 0, 1, 2);
}
// Load file
CSVReader reader = new CSVReader(new FileReader(filename));
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
if (nextLine.length < 3)
continue;
x = Float.parseFloat(nextLine[0]);
y = Float.parseFloat(nextLine[1]);
z = Float.parseFloat(nextLine[2]);
coords.add( new Coord3d(x, y, z) );
}
reader.close();
return coords;
}
/**********************************************/
public static List<Coord3d> loadList(String filename, int xColumn, int yColumn, int zColumn) throws IOException {
float x;
float y;
float z;
protected static int readNLines(String filename) throws IOException {
CSVReader reader = new CSVReader(new FileReader(filename));
int n = 0;
while (reader.readNext() != null)
n++;
reader.close();
return n;
}
List<Coord3d> coords = new ArrayList<Coord3d>();
public static Coord3d[] toArray(List<Coord3d> list) {
Coord3d[] points = new Coord3d[list.size()];
int k = 0;
for (Coord3d c : list) {
points[k++] = c;
}
return points;
}
// Load file
CSVReader reader = new CSVReader(new FileReader(filename));
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
if (nextLine.length < 3)
continue;
x = Float.parseFloat(nextLine[xColumn]);
y = Float.parseFloat(nextLine[yColumn]);
z = Float.parseFloat(nextLine[zColumn]);
coords.add(new Coord3d(x, y, z));
}
reader.close();
return coords;
}
/**********************************************/
protected static int readNLines(String filename) throws IOException {
CSVReader reader = new CSVReader(new FileReader(filename));
int n = 0;
while (reader.readNext() != null)
n++;
reader.close();
return n;
}
public static Coord3d[] toArray(List<Coord3d> list) {
Coord3d[] points = new Coord3d[list.size()];
int k = 0;
for (Coord3d c : list) {
points[k++] = c;
}
return points;
}
}