Search in sources :

Example 1 with BillboardGalaxy

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

the class NBGLoader method loadData.

@Override
public Array<CelestialBody> loadData() {
    Array<CelestialBody> galaxies = new Array<>(false, 900);
    long baseId = 8500000;
    long offset = 0;
    if (active)
        for (String file : files) {
            FileHandle f = Settings.settings.data.dataFileHandle(file);
            InputStream data = f.read();
            BufferedReader br = new BufferedReader(new InputStreamReader(data));
            try {
                String line;
                int linenum = 0;
                while ((line = br.readLine()) != null) {
                    if (linenum > 0) {
                        // Add galaxy
                        String[] tokens = line.split(",");
                        String name = tokens[0];
                        String altname = tokens[1];
                        double ra = Parser.parseDouble(tokens[2]);
                        double dec = Parser.parseDouble(tokens[3]);
                        double distMpc = Parser.parseDouble(tokens[4]);
                        double distPc = distMpc * 1e6d;
                        double kmag = Parser.parseDouble(tokens[5]);
                        double bmag = Parser.parseDouble(tokens[6]);
                        double a26 = Parser.parseDouble(tokens[7]);
                        double ba = Parser.parseDouble(tokens[8]);
                        int hrv = Parser.parseInt(tokens[9]);
                        int i = Parser.parseInt(tokens[10]);
                        int tt = Parser.parseInt(tokens[11]);
                        String Mcl = tokens[12];
                        String img = tokens[13];
                        double sizepc = Parser.parseDouble(tokens[14]);
                        CelestialBody g;
                        if (img == null || img.isEmpty()) {
                            // Regular shaded light point
                            Apfloat dist = new Apfloat(distMpc * Constants.MPC_TO_U, Constants.PREC);
                            Vector3b pos = Coordinates.sphericalToCartesian(Math.toRadians(ra), Math.toRadians(dec), dist, new Vector3b());
                            float colorbv = 0;
                            float absmag = (float) (kmag - 2.5 * Math.log10(Math.pow(distPc / 10d, 2d)));
                            NBGalaxy gal = new NBGalaxy(pos, (float) kmag, absmag, colorbv, altname.isBlank() ? new String[] { name } : new String[] { name, altname }, (float) ra, (float) dec, (float) bmag, (float) a26, (float) ba, hrv, i, tt, Mcl, baseId + offset);
                            gal.setParent("NBG");
                            g = gal;
                        } else {
                            // Billboard
                            BillboardGalaxy gal = new BillboardGalaxy(new String[] { name, altname }, ra, dec, distPc, sizepc, "data/tex/extragal/" + img);
                            // Fade in parsecs from sun
                            gal.setFade(new double[] { distPc * 0.3, distPc * 0.6 });
                            g = gal;
                        }
                        galaxies.add(g);
                        offset++;
                    }
                    linenum++;
                }
            } catch (IOException e) {
                logger.error(e);
            } finally {
                try {
                    br.close();
                } catch (IOException e) {
                    logger.error(e);
                }
            }
        }
    logger.info(I18n.txt("notif.catalog.init", galaxies.size));
    return galaxies;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileHandle(com.badlogic.gdx.files.FileHandle) InputStream(java.io.InputStream) IOException(java.io.IOException) NBGalaxy(gaiasky.scenegraph.NBGalaxy) Apfloat(org.apfloat.Apfloat) Array(com.badlogic.gdx.utils.Array) Vector3b(gaiasky.util.math.Vector3b) BillboardGalaxy(gaiasky.scenegraph.BillboardGalaxy) CelestialBody(gaiasky.scenegraph.CelestialBody) BufferedReader(java.io.BufferedReader)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)1 Array (com.badlogic.gdx.utils.Array)1 BillboardGalaxy (gaiasky.scenegraph.BillboardGalaxy)1 CelestialBody (gaiasky.scenegraph.CelestialBody)1 NBGalaxy (gaiasky.scenegraph.NBGalaxy)1 Vector3b (gaiasky.util.math.Vector3b)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Apfloat (org.apfloat.Apfloat)1