Search in sources :

Example 1 with Vector2d

use of gaiasky.util.math.Vector2d in project gaiasky by langurmonkey.

the class SolarNeighbourhoodMinimapScale method position.

public float[] position(Vector3d pos, float[] out) {
    Vector3d p = aux3d1.set(pos).mul(trans);
    Vector2d pos2d = aux2d1;
    pos2d.set(p.z, p.y).scl(from);
    float cx = u2Px(pos2d.x, side2);
    float cy = u2Px(pos2d.y, sideshort2);
    out[0] = cx;
    out[1] = cy;
    pos2d.set(-p.x, p.z).scl(from);
    cx = u2Px(pos2d.x, side2);
    cy = u2Px(pos2d.y, side2);
    out[2] = cx;
    out[3] = cy;
    return out;
}
Also used : Vector2d(gaiasky.util.math.Vector2d) Vector3d(gaiasky.util.math.Vector3d)

Example 2 with Vector2d

use of gaiasky.util.math.Vector2d in project gaiasky by langurmonkey.

the class AbstractMinimapScale method renderCameraSide.

protected void renderCameraSide(float viewportAlpha) {
    // Position
    float cx = this.camp[0];
    float cy = this.camp[1];
    // Direction
    float dx = this.camd[0];
    float dy = this.camd[1];
    // Viewport
    sr.setColor(1, 1, 1, viewportAlpha);
    Vector2d endx = aux2d1.set(dx, dy).scl(40f);
    endx.rotate(-cam.getCamera().fieldOfView / 2d);
    float c1x = (float) endx.x + cx;
    float c1y = (float) endx.y + cy;
    endx.set(dx, dy).scl(40f);
    endx.rotate(cam.getCamera().fieldOfView / 2d);
    sr.triangle(cx, cy, c1x, c1y, (float) endx.x + cx, (float) endx.y + cy);
    // Position
    endx = aux2d1.set(dx, dy);
    endx.rotate(-cam.getCamera().fieldOfView / 2d);
    c1x = (float) endx.x + cx;
    c1y = (float) endx.y + cy;
    endx.set(dx, dy);
    endx.rotate(cam.getCamera().fieldOfView / 2d);
    sr.setColor(camc);
    sr.triangle(cx, cy, c1x, c1y, (float) endx.x + cx, (float) endx.y + cy);
    sr.setColor(0, 0, 0, 1);
    sr.circle(cx, cy, 8f);
    sr.setColor(camc);
    sr.circle(cx, cy, 6f);
}
Also used : Vector2d(gaiasky.util.math.Vector2d)

Example 3 with Vector2d

use of gaiasky.util.math.Vector2d in project gaiasky by langurmonkey.

the class MilkyWayMinimapScale method position.

public float[] position(Vector3d pos, float[] out) {
    Vector3d p = aux3d1.set(pos).mul(trans);
    Vector2d pos2d = aux2d1;
    // Side
    pos2d.set(p.z, p.y).scl(from);
    float cx = u2Px(pos2d.x - 8000.0, side2);
    float cy = u2Px(pos2d.y, sideshort2);
    out[0] = cx;
    out[1] = cy;
    // Top
    pos2d.set(-p.x, p.z).scl(from);
    cx = u2Px(pos2d.x, side2);
    cy = u2Px(pos2d.y - 8000.0, side2);
    out[2] = cx;
    out[3] = cy;
    return out;
}
Also used : Vector2d(gaiasky.util.math.Vector2d) Vector3d(gaiasky.util.math.Vector3d)

Example 4 with Vector2d

use of gaiasky.util.math.Vector2d in project gaiasky by langurmonkey.

the class STILDataProvider method loadData.

/**
 * @param ds             The data source.
 * @param factor         Length factor.
 * @param preCallback    A function that runs before.
 * @param updateCallback A function that runs after each object has loaded. Gets two longs, the first holds the current number of loaded objects and the
 *                       second holds the total number of objects to load.
 * @param postCallback   A function that runs after the data has been loaded.
 *
 * @return The list of particle records.
 */
public List<IParticleRecord> loadData(DataSource ds, double factor, Runnable preCallback, RunnableLongLong updateCallback, Runnable postCallback) {
    try {
        if (factory != null) {
            // RNG
            final Random r = new Random(123L);
            // Add extra builders
            List<TableBuilder> builders = factory.getDefaultBuilders();
            builders.add(new CsvTableBuilder());
            builders.add(new AsciiTableBuilder());
            if (preCallback != null)
                preCallback.run();
            // Try to load
            StarTable table = factory.makeStarTable(ds);
            long count = table.getRowCount();
            initLists((int) count);
            UCDParser ucdParser = new UCDParser();
            ucdParser.parse(table);
            int resampledLightCurves = 0;
            int noPeriods = 0;
            if (ucdParser.haspos) {
                BVToTeff_ballesteros bvToTEff = new BVToTeff_ballesteros();
                int nInvalidParallaxes = 0;
                long i = 0L;
                long step = Math.max(1L, Math.round(count / 100d));
                RowSequence rs = table.getRowSequence();
                while (rs.next()) {
                    Object[] row = rs.getRow();
                    try {
                        // POSITION
                        Pair<UCD, Double> a = getDoubleUcd(ucdParser.POS1, row);
                        Pair<UCD, Double> b = getDoubleUcd(ucdParser.POS2, row);
                        Pair<UCD, Double> c;
                        String unitC;
                        Pair<UCD, Double> pos3 = getDoubleUcd(ucdParser.POS3, row);
                        // Check missing pos3 -> Use default parallax
                        if (ucdParser.POS3.isEmpty() || pos3 == null || pos3.getSecond() == null || !Double.isFinite(pos3.getSecond())) {
                            c = new Pair<>(null, 0.04);
                            unitC = "mas";
                            nInvalidParallaxes++;
                        } else {
                            c = getDoubleUcd(ucdParser.POS3, row);
                            assert c != null;
                            unitC = c.getFirst().unit;
                        }
                        assert a != null;
                        assert b != null;
                        PositionType pt = ucdParser.getPositionType(a.getFirst(), b.getFirst(), c.getFirst());
                        // Check negative parallaxes -> Use default for consistency
                        if (pt.isParallax() && (c.getSecond() == null || c.getSecond().isNaN() || c.getSecond() <= 0)) {
                            c.setSecond(0.04);
                            unitC = "mas";
                            nInvalidParallaxes++;
                        }
                        Position p = new Position(a.getSecond(), a.getFirst().unit, b.getSecond(), b.getFirst().unit, c.getSecond(), unitC, pt);
                        double distPc = p.gsposition.len();
                        if ((pt.isParallax() && c.getSecond() <= 0) || !Double.isFinite(distPc) || distPc < 0) {
                            // Next
                            break;
                        }
                        p.gsposition.scl(Constants.PC_TO_U);
                        // Find out RA/DEC/Dist
                        Vector3d sph = new Vector3d();
                        Coordinates.cartesianToSpherical(p.gsposition, sph);
                        // PROPER MOTION
                        Vector3d pm;
                        double muAlphaStar = 0, muDelta = 0, radVel = 0;
                        // Only supported if position is equatorial spherical coordinates (ra/dec)
                        if (pt == PositionType.EQ_SPH_DIST || pt == PositionType.EQ_SPH_PLX) {
                            Pair<UCD, Double> pma = getDoubleUcd(ucdParser.PMRA, row);
                            Pair<UCD, Double> pmb = getDoubleUcd(ucdParser.PMDEC, row);
                            Pair<UCD, Double> pmc = getDoubleUcd(ucdParser.RADVEL, row);
                            muAlphaStar = pma != null ? pma.getSecond() : 0;
                            muDelta = pmb != null ? pmb.getSecond() : 0;
                            radVel = pmc != null ? pmc.getSecond() : 0;
                            double raRad = new Angle(a.getSecond(), a.getFirst().unit).get(AngleUnit.RAD);
                            double decRad = new Angle(b.getSecond(), b.getFirst().unit).get(AngleUnit.RAD);
                            pm = AstroUtils.properMotionsToCartesian(muAlphaStar, muDelta, radVel, raRad, decRad, distPc, new Vector3d());
                        } else {
                            pm = new Vector3d(Vector3d.Zero);
                        }
                        // MAGNITUDE
                        double appMag;
                        if (!ucdParser.MAG.isEmpty()) {
                            Pair<UCD, Double> appMagPair = getDoubleUcd(ucdParser.MAG, row);
                            assert appMagPair != null;
                            appMag = appMagPair.getSecond();
                        } else {
                            // Default magnitude
                            appMag = 15;
                        }
                        // Scale magnitude if needed
                        double magScl = (datasetOptions != null && datasetOptions.type == DatasetOptions.DatasetLoadType.STARS || (datasetOptions != null && datasetOptions.type == DatasetLoadType.VARIABLES)) ? datasetOptions.magnitudeScale : 0f;
                        appMag = appMag - magScl;
                        // Absolute magnitude to pseudo-size
                        final double absMag = AstroUtils.apparentToAbsoluteMagnitude(distPc, appMag);
                        final float size = (float) absoluteMagnitudeToPseudoSize(absMag);
                        // COLOR
                        float color;
                        if (!ucdParser.COL.isEmpty()) {
                            Pair<UCD, Double> colPair = getDoubleUcd(ucdParser.COL, row);
                            if (colPair == null) {
                                color = 0.656f;
                            } else {
                                color = colPair.getSecond().floatValue();
                            }
                        } else {
                            // Default color
                            color = 0.656f;
                        }
                        // VARIABILITY
                        float[] variMags = null;
                        double[] variTimes = null;
                        double pf = 0;
                        int nVari = 0;
                        if (ucdParser.hasvari) {
                            Pair<UCD, Double> period = getDoubleUcd(ucdParser.VARI_PERIOD, row);
                            if (!ucdParser.hasperiod || period == null || !Double.isFinite(period.getSecond())) {
                                // Skip stars without period
                                noPeriods++;
                                continue;
                            } else {
                                pf = period.getSecond();
                            }
                            Pair<UCD, double[]> variMagsPair = getDoubleArrayUcd(ucdParser.VARI_MAGS, row);
                            assert variMagsPair != null;
                            double[] variMagsDouble = variMagsPair.getSecond();
                            nVari = variMagsDouble.length;
                            variMags = new float[nVari];
                            Pair<UCD, double[]> variTimesPair = getDoubleArrayUcd(ucdParser.VARI_TIMES, row);
                            assert variTimesPair != null;
                            variTimes = variTimesPair.getSecond();
                            double[] auxMags = variMagsDouble;
                            double[] auxTimes = variTimes;
                            // SANITIZE (no NaNs)
                            List<Double> magnitudesList = new ArrayList<>();
                            List<Double> timesList = new ArrayList<>();
                            int idx = 0;
                            for (double mag : auxMags) {
                                if (Double.isFinite(mag)) {
                                    magnitudesList.add(mag - magScl);
                                    timesList.add(auxTimes[idx]);
                                }
                                idx++;
                            }
                            variMagsDouble = magnitudesList.stream().mapToDouble(Double::doubleValue).toArray();
                            variTimes = timesList.stream().mapToDouble(Double::doubleValue).toArray();
                            nVari = variMagsDouble.length;
                            // FOLD
                            List<Vector2d> list = new ArrayList<>(nVari);
                            for (int k = 0; k < nVari; k++) {
                                double phase = ((variTimes[k] - variTimes[0]) % pf);
                                list.add(new Vector2d(phase, variMagsDouble[k]));
                            }
                            list.sort(Comparator.comparingDouble(o -> o.x));
                            for (int k = 0; k < nVari; k++) {
                                Vector2d point = list.get(k);
                                variTimes[k] = point.x + variTimes[0];
                                variMagsDouble[k] = point.y;
                            }
                            // RESAMPLE (only if too many samples)
                            final int MAX_VARI = VariableGroupRenderSystem.MAX_VARI;
                            if (variMagsDouble.length > MAX_VARI) {
                                nVari = MAX_VARI;
                                double t0 = variTimes[0];
                                double tn = variTimes[variTimes.length - 1];
                                double tStep = (tn - t0) / (nVari - 1);
                                UnivariateInterpolator interp = new LinearInterpolator();
                                UnivariateFunction f = interp.interpolate(variTimes, variMagsDouble);
                                variMagsDouble = new double[nVari];
                                variTimes = new double[nVari];
                                for (idx = 0; idx < nVari; idx++) {
                                    double t = t0 + tStep * idx;
                                    variTimes[idx] = t;
                                    variMagsDouble[idx] = f.value(t);
                                }
                                resampledLightCurves++;
                            }
                            // Convert magnitudes to sizes
                            assert variMags.length == variTimes.length;
                            for (int j = 0; j < variMagsDouble.length; j++) {
                                double variAbsoluteMag = AstroUtils.apparentToAbsoluteMagnitude(distPc, variMagsDouble[j]);
                                variMags[j] = (float) absoluteMagnitudeToPseudoSize(variAbsoluteMag);
                            }
                        }
                        // EFFECTIVE TEMPERATURE
                        float tEff;
                        if (!ucdParser.TEFF.isEmpty()) {
                            Pair<UCD, Double> tEffPair = getDoubleUcd(ucdParser.TEFF, row);
                            assert tEffPair != null;
                            tEff = tEffPair.getSecond().floatValue();
                        } else {
                            // Convert B-V to T_eff using Ballesteros 2012
                            tEff = (float) bvToTEff.bvToTeff(color);
                        }
                        // RGB
                        float[] rgb = ColorUtils.BVtoRGB(color);
                        // float[] rgb = ColorUtils.teffToRGB_harre(teff);
                        float col = Color.toFloatBits(rgb[0], rgb[1], rgb[2], 1.0f);
                        // IDENTIFIER AND NAME
                        String[] names;
                        long id = -1L;
                        int hip = -1;
                        if (ucdParser.NAME.isEmpty()) {
                            // Empty name
                            if (!ucdParser.ID.isEmpty()) {
                                // We have ID
                                Pair<UCD, String> namePair = getStringUcd(ucdParser.ID, row);
                                assert namePair != null;
                                names = new String[] { namePair.getSecond() };
                                if (namePair.getFirst().colname.equalsIgnoreCase("hip")) {
                                    hip = Integer.parseInt(namePair.getSecond());
                                    id = hip;
                                } else {
                                    id = ++starId;
                                }
                            } else {
                                // Empty ID
                                id = ++starId;
                                names = new String[] { Long.toString(id) };
                            }
                        } else {
                            // We have a name
                            Pair<UCD, String>[] namePairs = getAllStringsUcd(ucdParser.NAME, row);
                            Array<String> namesArray = new Array<>(false, namePairs.length);
                            for (Pair<UCD, String> pair : namePairs) {
                                String[] currNames = pair.getSecond().split(Constants.nameSeparatorRegex);
                                for (String actualName : currNames) {
                                    if (actualName != null && !actualName.isEmpty() && !TextUtils.contains(forbiddenNameValues, actualName, true)) {
                                        namesArray.add(actualName);
                                    }
                                }
                            }
                            names = new String[namesArray.size];
                            int k = 0;
                            for (String n : namesArray) {
                                names[k++] = n;
                            }
                            if (names.length == 0) {
                                names = new String[] { Long.toString(id) };
                            }
                            // Take care of HIP stars
                            if (!ucdParser.ID.isEmpty()) {
                                Pair<UCD, String> idPair = getStringUcd(ucdParser.ID, row);
                                assert idPair != null;
                                if (idPair.getFirst().colname.equalsIgnoreCase("hip")) {
                                    hip = Integer.parseInt(idPair.getSecond());
                                    id = hip;
                                } else {
                                    id = ++starId;
                                }
                            } else {
                                id = ++starId;
                            }
                        }
                        // Populate provider lists
                        colors.put(id, rgb);
                        sphericalPositions.put(id, new double[] { sph.x, sph.y, sph.z });
                        if (datasetOptions == null || datasetOptions.type == DatasetOptions.DatasetLoadType.STARS || datasetOptions.type == DatasetOptions.DatasetLoadType.VARIABLES) {
                            double[] dataD = new double[ParticleRecord.STAR_SIZE_D];
                            float[] dataF = new float[ParticleRecord.STAR_SIZE_F];
                            dataD[ParticleRecord.I_X] = p.gsposition.x;
                            dataD[ParticleRecord.I_Y] = p.gsposition.y;
                            dataD[ParticleRecord.I_Z] = p.gsposition.z;
                            dataF[ParticleRecord.I_FPMX] = (float) pm.x;
                            dataF[ParticleRecord.I_FPMY] = (float) pm.y;
                            dataF[ParticleRecord.I_FPMZ] = (float) pm.z;
                            dataF[ParticleRecord.I_FMUALPHA] = (float) muAlphaStar;
                            dataF[ParticleRecord.I_FMUDELTA] = (float) muDelta;
                            dataF[ParticleRecord.I_FRADVEL] = (float) radVel;
                            dataF[ParticleRecord.I_FAPPMAG] = (float) appMag;
                            dataF[ParticleRecord.I_FABSMAG] = (float) absMag;
                            dataF[ParticleRecord.I_FCOL] = col;
                            dataF[ParticleRecord.I_FSIZE] = size;
                            dataF[ParticleRecord.I_FHIP] = hip;
                            // Extra
                            ObjectDoubleMap<UCD> extraAttributes = addExtraAttributes(ucdParser, row);
                            if (ucdParser.TEFF.isEmpty()) {
                                UCD tEffUCD = new UCD("phys.temperature.effective", "teff", "K", -1);
                                extraAttributes = initExtraAttributes(extraAttributes);
                                extraAttributes.put(tEffUCD, tEff);
                            } else {
                                extraAttributes = initExtraAttributes(extraAttributes);
                                extraAttributes.put(ucdParser.TEFF.first(), tEff);
                            }
                            final IParticleRecord sb;
                            if (datasetOptions != null && datasetOptions.type == DatasetLoadType.VARIABLES || variMags != null) {
                                sb = new VariableRecord(dataD, dataF, nVari, pf, variMags, variTimes, id, names, extraAttributes);
                            } else {
                                sb = new ParticleRecord(dataD, dataF, id, names, extraAttributes);
                            }
                            list.add(sb);
                            int appMagClamp = (int) MathUtilsd.clamp(appMag, 0, 21);
                            countsPerMag[appMagClamp] += 1;
                        } else if (datasetOptions.type == DatasetOptions.DatasetLoadType.PARTICLES) {
                            double[] point = new double[3];
                            point[ParticleRecord.I_X] = p.gsposition.x;
                            point[ParticleRecord.I_Y] = p.gsposition.y;
                            point[ParticleRecord.I_Z] = p.gsposition.z;
                            // Extra
                            ObjectDoubleMap<UCD> extraAttributes = addExtraAttributes(ucdParser, row);
                            IParticleRecord pb = new ParticleRecord(point, null, null, names, extraAttributes);
                            list.add(pb);
                        }
                    } catch (Exception e) {
                        logger.debug(e);
                        logger.debug("Exception parsing row " + i + ": skipping");
                    }
                    i++;
                    if (updateCallback != null && i % step == 0) {
                        updateCallback.run(i, count);
                    }
                }
                if (nInvalidParallaxes > 0) {
                    logger.warn("Found " + nInvalidParallaxes + " rows with nonexistent or negative parallax. Using the default 0.04 mas for them.");
                }
                if (resampledLightCurves > 0) {
                    logger.warn(resampledLightCurves + " light curves resampled to fit in default array size (=" + VariableGroupRenderSystem.MAX_VARI + ")");
                }
                if (noPeriods > 0) {
                    logger.warn("Skipped " + noPeriods + " variable stars without a period");
                }
            } else {
                logger.error("Table not loaded: Position not found");
            }
        }
    } catch (Exception e) {
        logger.error(e);
    } finally {
        if (postCallback != null)
            postCallback.run();
    }
    return list;
}
Also used : java.util(java.util) Array(com.badlogic.gdx.utils.Array) Vector3d(gaiasky.util.math.Vector3d) ParticleRecord(gaiasky.scenegraph.particle.ParticleRecord) DataSource(uk.ac.starlink.util.DataSource) UnivariateInterpolator(org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator) Level(java.util.logging.Level) UCD(gaiasky.util.ucd.UCD) TableBuilder(uk.ac.starlink.table.TableBuilder) Angle(gaiasky.util.units.Quantity.Angle) Parser(gaiasky.util.parse.Parser) AstroUtils(gaiasky.util.coord.AstroUtils) AngleUnit(gaiasky.util.units.Quantity.Angle.AngleUnit) DatasetLoadType(gaiasky.data.group.DatasetOptions.DatasetLoadType) Path(java.nio.file.Path) PositionType(gaiasky.util.units.Position.PositionType) VariableRecord(gaiasky.scenegraph.particle.VariableRecord) LongMap(com.badlogic.gdx.utils.LongMap) FileDataSource(uk.ac.starlink.util.FileDataSource) Vector2d(gaiasky.util.math.Vector2d) VariableGroupRenderSystem(gaiasky.render.system.VariableGroupRenderSystem) LinearInterpolator(org.apache.commons.math3.analysis.interpolation.LinearInterpolator) CsvTableBuilder(uk.ac.starlink.table.formats.CsvTableBuilder) FileWriter(java.io.FileWriter) Coordinates(gaiasky.util.coord.Coordinates) IOException(java.io.IOException) gaiasky.util(gaiasky.util) Color(com.badlogic.gdx.graphics.Color) Position(gaiasky.util.units.Position) AsciiTableBuilder(uk.ac.starlink.table.formats.AsciiTableBuilder) BVToTeff_ballesteros(gaiasky.util.color.BVToTeff_ballesteros) StarTable(uk.ac.starlink.table.StarTable) RowSequence(uk.ac.starlink.table.RowSequence) Log(gaiasky.util.Logger.Log) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction) MathUtilsd(gaiasky.util.math.MathUtilsd) UCDParser(gaiasky.util.ucd.UCDParser) StarTableFactory(uk.ac.starlink.table.StarTableFactory) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) ColorUtils(gaiasky.util.color.ColorUtils) InputStream(java.io.InputStream) AsciiTableBuilder(uk.ac.starlink.table.formats.AsciiTableBuilder) CsvTableBuilder(uk.ac.starlink.table.formats.CsvTableBuilder) TableBuilder(uk.ac.starlink.table.TableBuilder) CsvTableBuilder(uk.ac.starlink.table.formats.CsvTableBuilder) AsciiTableBuilder(uk.ac.starlink.table.formats.AsciiTableBuilder) ParticleRecord(gaiasky.scenegraph.particle.ParticleRecord) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) Vector2d(gaiasky.util.math.Vector2d) VariableRecord(gaiasky.scenegraph.particle.VariableRecord) UnivariateInterpolator(org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator) UnivariateFunction(org.apache.commons.math3.analysis.UnivariateFunction) Position(gaiasky.util.units.Position) RowSequence(uk.ac.starlink.table.RowSequence) UCDParser(gaiasky.util.ucd.UCDParser) IOException(java.io.IOException) PositionType(gaiasky.util.units.Position.PositionType) Array(com.badlogic.gdx.utils.Array) BVToTeff_ballesteros(gaiasky.util.color.BVToTeff_ballesteros) Angle(gaiasky.util.units.Quantity.Angle) Vector3d(gaiasky.util.math.Vector3d) LinearInterpolator(org.apache.commons.math3.analysis.interpolation.LinearInterpolator) StarTable(uk.ac.starlink.table.StarTable) UCD(gaiasky.util.ucd.UCD) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 5 with Vector2d

use of gaiasky.util.math.Vector2d in project gaiasky by langurmonkey.

the class DatasetPreferencesWindow method addFadeAttributes.

private void addFadeAttributes(Table container) {
    float tfw = 220f;
    OwnLabel fadeLabel = new OwnLabel(I18n.txt("gui.dsload.fade"), skin, "hud-header");
    container.add(fadeLabel).colspan(2).left().padTop(pad15).padBottom(pad10).row();
    // Info
    String ssInfoStr = I18n.txt("gui.dsload.fade.info") + '\n';
    int ssLines = GlobalResources.countOccurrences(ssInfoStr, '\n');
    TextArea fadeInfo = new OwnTextArea(ssInfoStr, skin, "info");
    fadeInfo.setDisabled(true);
    fadeInfo.setPrefRows(ssLines + 1);
    fadeInfo.setWidth(taWidth);
    fadeInfo.clearListeners();
    container.add(fadeInfo).colspan(2).left().padTop(pad5).padBottom(pad10).row();
    // Fade in
    fadeIn = new OwnCheckBox(I18n.txt("gui.dsload.fade.in"), skin, pad5);
    Vector2d fi = ci.object != null ? ci.object.getFadeIn() : null;
    container.add(fadeIn).left().padRight(pad10).padBottom(pad5);
    HorizontalGroup fadeInGroup = new HorizontalGroup();
    fadeInGroup.space(pad5);
    fadeInMin = new OwnTextField(fi != null ? String.format("%.14f", fi.x * Constants.U_TO_PC) : "0", skin);
    fadeInMin.setWidth(tfw);
    fadeInMax = new OwnTextField(fi != null ? String.format("%.14f", fi.y * Constants.U_TO_PC) : "1", skin);
    fadeInMax.setWidth(tfw);
    fadeInGroup.addActor(new OwnLabel("[", skin));
    fadeInGroup.addActor(fadeInMin);
    fadeInGroup.addActor(new OwnLabel(", ", skin));
    fadeInGroup.addActor(fadeInMax);
    fadeInGroup.addActor(new OwnLabel("] " + I18n.txt("gui.unit.pc"), skin));
    fadeIn.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            boolean disable = !fadeIn.isChecked();
            for (Actor child : fadeInGroup.getChildren()) {
                if (child instanceof OwnLabel) {
                    ((OwnLabel) child).setDisabled(disable);
                } else if (child instanceof OwnTextField) {
                    ((OwnTextField) child).setDisabled(disable);
                }
            }
            return true;
        }
        return false;
    });
    fadeIn.setChecked(fi == null);
    fadeIn.setProgrammaticChangeEvents(true);
    fadeIn.setChecked(fi != null);
    container.add(fadeInGroup).left().padBottom(pad5).row();
    // Fade out
    fadeOut = new OwnCheckBox(I18n.txt("gui.dsload.fade.out"), skin, pad5);
    Vector2d fo = ci.object != null ? ci.object.getFadeOut() : null;
    container.add(fadeOut).left().padRight(pad10).padBottom(pad5);
    HorizontalGroup fadeOutGroup = new HorizontalGroup();
    fadeOutGroup.space(pad5);
    fadeOutMin = new OwnTextField(fo != null ? String.format("%.10f", fo.x * Constants.U_TO_PC) : "5000", skin);
    fadeOutMin.setWidth(tfw);
    fadeOutMax = new OwnTextField(fo != null ? String.format("%.10f", fo.y * Constants.U_TO_PC) : "10000", skin);
    fadeOutMax.setWidth(tfw);
    fadeOutGroup.addActor(new OwnLabel("[", skin));
    fadeOutGroup.addActor(fadeOutMin);
    fadeOutGroup.addActor(new OwnLabel(", ", skin));
    fadeOutGroup.addActor(fadeOutMax);
    fadeOutGroup.addActor(new OwnLabel("] " + I18n.txt("gui.unit.pc"), skin));
    fadeOut.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            boolean disable = !fadeOut.isChecked();
            for (Actor child : fadeOutGroup.getChildren()) {
                if (child instanceof OwnLabel) {
                    ((OwnLabel) child).setDisabled(disable);
                } else if (child instanceof OwnTextField) {
                    ((OwnTextField) child).setDisabled(disable);
                }
            }
            return true;
        }
        return false;
    });
    fadeOut.setChecked(fo == null);
    fadeOut.setProgrammaticChangeEvents(true);
    fadeOut.setChecked(fo != null);
    // Validators
    FloatValidator fadeVal = new FloatValidator(0f, 1e10f);
    IValidator fadeInMinVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeInMax, fadeOutMin, fadeOutMax }, null);
    IValidator fadeInMaxVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeOutMin, fadeOutMax }, new OwnTextField[] { fadeInMin });
    IValidator fadeOutMinVal = new TextFieldComparatorValidator(fadeVal, new OwnTextField[] { fadeOutMax }, new OwnTextField[] { fadeInMin, fadeInMax });
    IValidator fadeOutMaxVal = new TextFieldComparatorValidator(fadeVal, null, new OwnTextField[] { fadeInMin, fadeInMax, fadeOutMin });
    // Set them
    fadeInMin.setValidator(fadeInMinVal);
    fadeInMax.setValidator(fadeInMaxVal);
    fadeOutMin.setValidator(fadeOutMinVal);
    fadeOutMax.setValidator(fadeOutMaxVal);
    container.add(fadeOutGroup).left().padBottom(pad5).row();
}
Also used : TextFieldComparatorValidator(gaiasky.util.validator.TextFieldComparatorValidator) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) Vector2d(gaiasky.util.math.Vector2d) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) IValidator(gaiasky.util.validator.IValidator) Actor(com.badlogic.gdx.scenes.scene2d.Actor) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) FloatValidator(gaiasky.util.validator.FloatValidator)

Aggregations

Vector2d (gaiasky.util.math.Vector2d)7 Vector3d (gaiasky.util.math.Vector3d)4 Color (com.badlogic.gdx.graphics.Color)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 HorizontalGroup (com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)1 TextArea (com.badlogic.gdx.scenes.scene2d.ui.TextArea)1 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)1 Array (com.badlogic.gdx.utils.Array)1 LongMap (com.badlogic.gdx.utils.LongMap)1 DatasetLoadType (gaiasky.data.group.DatasetOptions.DatasetLoadType)1 VariableGroupRenderSystem (gaiasky.render.system.VariableGroupRenderSystem)1 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)1 ParticleRecord (gaiasky.scenegraph.particle.ParticleRecord)1 VariableRecord (gaiasky.scenegraph.particle.VariableRecord)1 gaiasky.util (gaiasky.util)1 Log (gaiasky.util.Logger.Log)1 BVToTeff_ballesteros (gaiasky.util.color.BVToTeff_ballesteros)1 ColorUtils (gaiasky.util.color.ColorUtils)1 AstroUtils (gaiasky.util.coord.AstroUtils)1 Coordinates (gaiasky.util.coord.Coordinates)1