Search in sources :

Example 11 with ParticleGroup

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

the class ParticleGroupInstRenderSystem method renderObject.

@Override
protected void renderObject(ExtShaderProgram shaderProgram, IRenderable renderable) {
    final ParticleGroup particleGroup = (ParticleGroup) renderable;
    synchronized (particleGroup) {
        if (!particleGroup.disposed) {
            boolean hlCmap = particleGroup.isHighlighted() && !particleGroup.isHlplain();
            int n = particleGroup.size();
            if (!inGpu(particleGroup)) {
                int offset = addMeshData(6, n);
                setOffset(particleGroup, offset);
                curr = meshes.get(offset);
                ensureInstanceAttribsSize(n * curr.instanceSize);
                float[] c = particleGroup.getColor();
                float[] colorMin = particleGroup.getColorMin();
                float[] colorMax = particleGroup.getColorMax();
                double minDistance = particleGroup.getMinDistance();
                double maxDistance = particleGroup.getMaxDistance();
                int numParticlesAdded = 0;
                for (int i = 0; i < n; i++) {
                    if (particleGroup.filter(i) && particleGroup.isVisible(i)) {
                        IParticleRecord particle = particleGroup.get(i);
                        double[] p = particle.rawDoubleData();
                        // COLOR
                        if (particleGroup.isHighlighted()) {
                            if (hlCmap) {
                                // Color map
                                double[] color = cmap.colormap(particleGroup.getHlcmi(), particleGroup.getHlcma().get(particle), particleGroup.getHlcmmin(), particleGroup.getHlcmmax());
                                tempInstanceAttribs[curr.instanceIdx + curr.colorOffset] = Color.toFloatBits((float) color[0], (float) color[1], (float) color[2], 1.0f);
                            } else {
                                // Plain
                                tempInstanceAttribs[curr.instanceIdx + curr.colorOffset] = Color.toFloatBits(c[0], c[1], c[2], c[3]);
                            }
                        } else {
                            if (colorMin != null && colorMax != null) {
                                double dist = Math.sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2]);
                                // fac = 0 -> colorMin,  fac = 1 -> colorMax
                                double fac = (dist - minDistance) / (maxDistance - minDistance);
                                interpolateColor(colorMin, colorMax, c, fac);
                            }
                            float r = 0, g = 0, b = 0;
                            if (particleGroup.colorNoise != 0) {
                                r = (float) ((StdRandom.uniform() - 0.5) * 2.0 * particleGroup.colorNoise);
                                g = (float) ((StdRandom.uniform() - 0.5) * 2.0 * particleGroup.colorNoise);
                                b = (float) ((StdRandom.uniform() - 0.5) * 2.0 * particleGroup.colorNoise);
                            }
                            tempInstanceAttribs[curr.instanceIdx + curr.colorOffset] = Color.toFloatBits(MathUtils.clamp(c[0] + r, 0, 1), MathUtils.clamp(c[1] + g, 0, 1), MathUtils.clamp(c[2] + b, 0, 1), MathUtils.clamp(c[3], 0, 1));
                        }
                        // SIZE
                        tempInstanceAttribs[curr.instanceIdx + sizeOffset] = (particleGroup.size + (float) (rand.nextGaussian() * particleGroup.size / 5d)) * particleGroup.highlightedSizeFactor();
                        // PARTICLE POSITION
                        tempInstanceAttribs[curr.instanceIdx + particlePosOffset] = (float) p[0];
                        tempInstanceAttribs[curr.instanceIdx + particlePosOffset + 1] = (float) p[1];
                        tempInstanceAttribs[curr.instanceIdx + particlePosOffset + 2] = (float) p[2];
                        curr.instanceIdx += curr.instanceSize;
                        curr.numVertices++;
                        numParticlesAdded++;
                    }
                }
                // Global (divisor=0) vertices (position, uv)
                curr.mesh.setVertices(tempVerts, 0, 24);
                // Per instance (divisor=1) vertices
                int count = numParticlesAdded * curr.instanceSize;
                setCount(particleGroup, count);
                curr.mesh.setInstanceAttribs(tempInstanceAttribs, 0, count);
                setInGpu(particleGroup, true);
            }
            /*
                 * RENDER
                 */
            curr = meshes.get(getOffset(particleGroup));
            if (curr != null) {
                float meanDist = (float) (particleGroup.getMeanDistance());
                double s = .3e-4f;
                shaderProgram.setUniformf("u_alpha", alphas[particleGroup.ct.getFirstOrdinal()] * particleGroup.getOpacity());
                shaderProgram.setUniformf("u_falloff", particleGroup.profileDecay);
                shaderProgram.setUniformf("u_sizeFactor", (float) (((StarSettings.getStarPointSize() * s)) * particleGroup.highlightedSizeFactor() * meanDist / Constants.DISTANCE_SCALE_FACTOR));
                shaderProgram.setUniformf("u_sizeLimits", (float) (particleGroup.particleSizeLimits[0] * particleGroup.highlightedSizeFactor()), (float) (particleGroup.particleSizeLimits[1] * particleGroup.highlightedSizeFactor()));
                try {
                    curr.mesh.render(shaderProgram, GL20.GL_TRIANGLES, 0, 6, n);
                } catch (IllegalArgumentException e) {
                    logger.error(e, "Render exception");
                }
            }
        }
    }
}
Also used : ParticleGroup(gaiasky.scenegraph.ParticleGroup) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 12 with ParticleGroup

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

the class DatasetPreferencesWindow method generateFilterTable.

private void generateFilterTable(Filter filter) {
    float minSelectWidth = 160f;
    filterTable.clearChildren();
    if (filter != null && filter.hasRules()) {
        // Operation
        OwnSelectBox<String> operation = new OwnSelectBox<>(skin);
        operation.setWidth(minSelectWidth);
        operation.setItems("and", "or", "xor");
        operation.setSelected(filter.getOperationString().toLowerCase());
        operation.addListener(event -> {
            if (event instanceof ChangeEvent) {
                String newOp = operation.getSelected();
                filter.setOperation(newOp);
                filterEdited = true;
                return true;
            }
            return false;
        });
        filterTable.add(new OwnLabel(I18n.txt("gui.dataset.filter.operation"), skin)).left().padRight(pad10 * 2f).padBottom(pad10);
        filterTable.add(operation).left().expandX().padBottom(pad10).row();
        // Rules
        Array<FilterRule> rules = filter.getRules();
        Table rulesTable = new Table(skin);
        filterTable.add(rulesTable).colspan(2);
        for (FilterRule rule : rules) {
            // UNIT
            OwnLabel unit = new OwnLabel(rule.getAttribute().getUnit(), skin);
            // ATTRIBUTE
            boolean stars = ci.object instanceof StarGroup || ci.object instanceof OctreeWrapper;
            Array<AttributeComboBoxBean> attrs = new Array<>(false, stars ? 12 : 7);
            // Add particle attributes (dist, alpha, delta)
            attrs.add(new AttributeComboBoxBean(new AttributeDistance()));
            attrs.add(new AttributeComboBoxBean(new AttributeRA()));
            attrs.add(new AttributeComboBoxBean(new AttributeDEC()));
            attrs.add(new AttributeComboBoxBean(new AttributeEclLatitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeEclLongitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeGalLatitude()));
            attrs.add(new AttributeComboBoxBean(new AttributeGalLongitude()));
            if (stars) {
                // Star-only attributes (appmag, absmag, mualpha, mudelta, radvel)
                attrs.add(new AttributeComboBoxBean(new AttributeAppmag()));
                attrs.add(new AttributeComboBoxBean(new AttributeAbsmag()));
                attrs.add(new AttributeComboBoxBean(new AttributeMualpha()));
                attrs.add(new AttributeComboBoxBean(new AttributeMudelta()));
                attrs.add(new AttributeComboBoxBean(new AttributeRadvel()));
            }
            // Colors
            attrs.add(new AttributeComboBoxBean(new AttributeColorRed()));
            attrs.add(new AttributeComboBoxBean(new AttributeColorGreen()));
            attrs.add(new AttributeComboBoxBean(new AttributeColorBlue()));
            // Extra attributes
            if (ci.object instanceof ParticleGroup) {
                ParticleGroup pg = (ParticleGroup) ci.object;
                if (pg.size() > 0) {
                    IParticleRecord first = pg.get(0);
                    if (first.hasExtra()) {
                        ObjectDoubleMap.Keys<UCD> ucds = first.extraKeys();
                        for (UCD ucd : ucds) attrs.add(new AttributeComboBoxBean(new AttributeUCD(ucd)));
                    }
                }
            }
            OwnSelectBox<AttributeComboBoxBean> attribute = new OwnSelectBox<>(skin);
            attribute.setItems(attrs);
            attribute.setSelected(getAttributeBean(rule.getAttribute(), attrs));
            attribute.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    IAttribute newAttr = attribute.getSelected().attr;
                    rule.setAttribute(newAttr);
                    // Update unit
                    unit.setText(newAttr.getUnit());
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(attribute).left().padRight(pad10).padBottom(pad5);
            // COMPARATOR
            String[] cmps = new String[] { "<", "<=", ">", ">=", "==", "!=" };
            OwnSelectBox<String> comparator = new OwnSelectBox<>(skin);
            comparator.setWidth(minSelectWidth);
            comparator.setItems(cmps);
            comparator.setSelected(rule.getComparator().toString());
            comparator.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    IComparator newComp = rule.getComparatorFromString(comparator.getSelected());
                    rule.setComparator(newComp);
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(comparator).left().padRight(pad10).padBottom(pad5);
            // VALUE
            FloatValidator fval = new FloatValidator(-Float.MAX_VALUE, Float.MAX_VALUE);
            OwnTextField value = new OwnTextField(Double.toString(rule.getValue()), skin, fval);
            value.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    if (value.isValid()) {
                        try {
                            rule.setValue(Float.parseFloat(value.getText()));
                            filterEdited = true;
                            return true;
                        } catch (Exception e) {
                            logger.error(e);
                            return false;
                        }
                    }
                    return false;
                }
                return false;
            });
            rulesTable.add(value).left().padRight(pad10).padBottom(pad5);
            // UNIT
            rulesTable.add(unit).left().padRight(pad10 * 3f).padBottom(pad5);
            // RUBBISH
            OwnTextIconButton rubbish = new OwnTextIconButton("", skin, "rubbish");
            rubbish.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.rule.remove"), skin));
            rubbish.addListener(event -> {
                if (event instanceof ChangeEvent) {
                    deleteRule(filter, rule);
                    filterEdited = true;
                    return true;
                }
                return false;
            });
            rulesTable.add(rubbish).left().padBottom(pad5).row();
        }
        // New rule button
        OwnTextIconButton addRule = new OwnTextIconButton(I18n.txt("gui.dataset.filter.rule.add"), skin, "add");
        addRule.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.rule.add"), skin));
        addRule.pad(pad10);
        rulesTable.add(addRule).left().padTop(pad10).row();
        addRule.addListener(event -> {
            if (event instanceof ChangeEvent) {
                dpw.addRule(filter);
                filterEdited = true;
                return true;
            }
            return false;
        });
    } else {
        // Add
        filterTable.add(new OwnLabel(I18n.txt("gui.dataset.filter.nofilters"), skin)).left().padBottom(pad10).row();
        OwnTextIconButton addFilter = new OwnTextIconButton(I18n.txt("gui.dataset.filter.add"), skin, "add");
        addFilter.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dataset.filter.add"), skin));
        addFilter.pad(pad10);
        filterTable.add(addFilter).left().padBottom(pad5).row();
        addFilter.addListener(event -> {
            if (event instanceof ChangeEvent) {
                dpw.addFilter();
                filterEdited = true;
                return true;
            }
            return false;
        });
    }
    pack();
}
Also used : FilterRule(gaiasky.util.filter.FilterRule) IComparator(gaiasky.util.filter.FilterRule.IComparator) AttributeComboBoxBean(gaiasky.interafce.beans.AttributeComboBoxBean) FloatValidator(gaiasky.util.validator.FloatValidator) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ParticleGroup(gaiasky.scenegraph.ParticleGroup) Array(com.badlogic.gdx.utils.Array) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) StarGroup(gaiasky.scenegraph.StarGroup) UCD(gaiasky.util.ucd.UCD) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) OctreeWrapper(gaiasky.scenegraph.octreewrapper.OctreeWrapper)

Aggregations

ParticleGroup (gaiasky.scenegraph.ParticleGroup)12 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)4 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)4 Stage (com.badlogic.gdx.scenes.scene2d.Stage)2 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)2 DatasetOptions (gaiasky.data.group.DatasetOptions)2 FadeNode (gaiasky.scenegraph.FadeNode)2 IFocus (gaiasky.scenegraph.IFocus)2 ArrayList (java.util.ArrayList)2 Message (org.astrogrid.samp.Message)2 Lwjgl3Graphics (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 Array (com.badlogic.gdx.utils.Array)1 DatasetLoadDialog (gaiasky.interafce.DatasetLoadDialog)1 AttributeComboBoxBean (gaiasky.interafce.beans.AttributeComboBoxBean)1 ISceneGraph (gaiasky.scenegraph.ISceneGraph)1 IStarFocus (gaiasky.scenegraph.IStarFocus)1 StarCluster (gaiasky.scenegraph.StarCluster)1 StarGroup (gaiasky.scenegraph.StarGroup)1