Search in sources :

Example 1 with ConstellationBoundaries

use of gaiasky.scenegraph.ConstellationBoundaries in project gaiasky by langurmonkey.

the class ConstelBoundariesLoader method loadData.

@Override
public Array<? extends SceneGraphNode> loadData() {
    Array<ConstellationBoundaries> boundaries = new Array<ConstellationBoundaries>();
    int n = 0;
    for (String f : files) {
        try {
            // load boundaries
            FileHandle file = Settings.settings.data.dataFileHandle(f);
            BufferedReader br = new BufferedReader(new InputStreamReader(file.read()));
            try {
                // Skip first line
                String line;
                ConstellationBoundaries boundary = new ConstellationBoundaries();
                boundary.ct = new ComponentTypes(ComponentType.Boundaries);
                List<List<Vector3d>> list = new ArrayList<>();
                List<Vector3d> buffer = new ArrayList<>(4);
                String lastName = "";
                int interp = 0;
                while ((line = br.readLine()) != null) {
                    if (!line.startsWith("#")) {
                        String[] tokens = line.split(separator);
                        String name = tokens[2];
                        String type = tokens.length > 3 ? tokens[3] : "O";
                        if (!name.equals(lastName)) {
                            // New line
                            list.add(buffer);
                            buffer = new ArrayList<>(20);
                            lastName = name;
                        }
                        if (type.equals("I")) {
                            interp++;
                        }
                        if ((type.equals("I") && LOAD_INTERPOLATED && interp % INTERPOLATED_MOD == 0) || type.equals("O")) {
                            // Load the data
                            double ra = Parser.parseDouble(tokens[0].trim()) * 15d;
                            double dec = Parser.parseDouble(tokens[1].trim());
                            double dist = 10 * Constants.AU_TO_U;
                            Vector3d point = Coordinates.sphericalToCartesian(Math.toRadians(ra), Math.toRadians(dec), dist, new Vector3d());
                            buffer.add(point);
                            n++;
                        }
                    }
                }
                list.add(buffer);
                boundary.setBoundaries(list);
                boundaries.add(boundary);
            } catch (IOException e) {
                Logger.getLogger(this.getClass()).error(e);
            }
        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    }
    Logger.getLogger(this.getClass()).info(I18n.txt("notif.boundaries.init", n));
    return boundaries;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileHandle(com.badlogic.gdx.files.FileHandle) ComponentTypes(gaiasky.render.ComponentTypes) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) ConstellationBoundaries(gaiasky.scenegraph.ConstellationBoundaries) Vector3d(gaiasky.util.math.Vector3d) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)1 Array (com.badlogic.gdx.utils.Array)1 ComponentTypes (gaiasky.render.ComponentTypes)1 ConstellationBoundaries (gaiasky.scenegraph.ConstellationBoundaries)1 Vector3d (gaiasky.util.math.Vector3d)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1