Search in sources :

Example 6 with ParticleGroup

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

the class UncertaintiesHandler method load.

private ParticleGroup load(long sid) {
    String source_id = String.valueOf(sid);
    ParticleGroup pg = new ParticleGroup();
    pg.setColor(colors[coloridx]);
    coloridx = (coloridx + 1) % colors.length;
    pg.setSize(3.5d);
    pg.setProfiledecay(0.3);
    pg.setName("");
    pg.setLabelcolor(new double[] { 1, 1, 1, 0 });
    pg.setLabelposition(new double[] { 0, 0, 0 });
    pg.setCt("Others");
    pg.setParent("Universe");
    pg.setProvider("gaiasky.data.group.UncertaintiesProvider");
    pg.setDatafile(path + source_id + ".csv");
    pg.initialize();
    return pg;
}
Also used : ParticleGroup(gaiasky.scenegraph.ParticleGroup)

Example 7 with ParticleGroup

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

the class ParticleGroupPointRenderSystem 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();
            if (!inGpu(particleGroup)) {
                int offset = addMeshData(particleGroup.size());
                setOffset(particleGroup, offset);
                curr = meshes.get(offset);
                float[] c = particleGroup.getColor();
                float[] colorMin = particleGroup.getColorMin();
                float[] colorMax = particleGroup.getColorMax();
                double minDistance = particleGroup.getMinDistance();
                double maxDistance = particleGroup.getMaxDistance();
                ensureTempVertsSize(particleGroup.size() * curr.vertexSize);
                int n = particleGroup.data().size();
                int numAdded = 0;
                for (int i = 0; i < n; i++) {
                    if (particleGroup.filter(i) && particleGroup.isVisible(i)) {
                        IParticleRecord pb = particleGroup.get(i);
                        double[] p = pb.rawDoubleData();
                        // COLOR
                        if (particleGroup.isHighlighted()) {
                            if (hlCmap) {
                                // Color map
                                double[] color = cmap.colormap(particleGroup.getHlcmi(), particleGroup.getHlcma().get(pb), particleGroup.getHlcmmin(), particleGroup.getHlcmmax());
                                tempVerts[curr.vertexIdx + curr.colorOffset] = Color.toFloatBits((float) color[0], (float) color[1], (float) color[2], 1.0f);
                            } else {
                                // Plain
                                tempVerts[curr.vertexIdx + 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);
                            }
                            tempVerts[curr.vertexIdx + 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, CMAP_VALUE
                        tempVerts[curr.vertexIdx + additionalOffset] = (particleGroup.size + (float) (rand.nextGaussian() * particleGroup.size / 5d)) * particleGroup.highlightedSizeFactor();
                        // POSITION
                        final int idx = curr.vertexIdx;
                        tempVerts[idx] = (float) p[0];
                        tempVerts[idx + 1] = (float) p[1];
                        tempVerts[idx + 2] = (float) p[2];
                        curr.vertexIdx += curr.vertexSize;
                        numAdded++;
                    }
                }
                int count = numAdded * curr.vertexSize;
                setCount(particleGroup, count);
                curr.mesh.setVertices(tempVerts, 0, count);
                setInGpu(particleGroup, true);
            }
            curr = meshes.get(getOffset(particleGroup));
            if (curr != null) {
                float meanDist = (float) (particleGroup.getMeanDistance());
                shaderProgram.setUniformf("u_alpha", alphas[particleGroup.ct.getFirstOrdinal()] * particleGroup.getOpacity());
                shaderProgram.setUniformf("u_falloff", particleGroup.profileDecay);
                shaderProgram.setUniformf("u_sizeFactor", (float) ((((stereoHalfWidth ? 2.0 : 1.0) * rc.scaleFactor * StarSettings.getStarPointSize() * 0.5)) * particleGroup.highlightedSizeFactor() * meanDist / (camera.getFovFactor() * Constants.DISTANCE_SCALE_FACTOR)));
                shaderProgram.setUniformf("u_sizeLimits", (float) (particleGroup.particleSizeLimitsPoint[0] / camera.getFovFactor()), (float) (particleGroup.particleSizeLimitsPoint[1] / camera.getFovFactor()));
                curr.mesh.render(shaderProgram, ShapeType.Point.getGlType());
            }
        }
    }
}
Also used : ParticleGroup(gaiasky.scenegraph.ParticleGroup) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 8 with ParticleGroup

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

the class ParticleGroupRenderSystem 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();
            if (!inGpu(particleGroup)) {
                int n = particleGroup.size();
                int offset = addMeshData(n * 4, n * 6);
                setOffset(particleGroup, offset);
                curr = meshes.get(offset);
                ensureTempVertsSize(n * 4 * curr.vertexSize);
                ensureTempIndicesSize(n * 6);
                float[] c = particleGroup.getColor();
                float[] colorMin = particleGroup.getColorMin();
                float[] colorMax = particleGroup.getColorMax();
                double minDistance = particleGroup.getMinDistance();
                double maxDistance = particleGroup.getMaxDistance();
                int numVerticesAdded = 0;
                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();
                        // 4 vertices per particle
                        for (int vert = 0; vert < 4; vert++) {
                            // Vertex POSITION
                            tempVerts[curr.vertexIdx + posOffset] = vertPos[vert].getFirst();
                            tempVerts[curr.vertexIdx + posOffset + 1] = vertPos[vert].getSecond();
                            // UV coordinates
                            tempVerts[curr.vertexIdx + uvOffset] = vertUV[vert].getFirst();
                            tempVerts[curr.vertexIdx + uvOffset + 1] = vertUV[vert].getSecond();
                            // COLOR
                            if (particleGroup.isHighlighted()) {
                                if (hlCmap) {
                                    // Color map
                                    double[] color = cmap.colormap(particleGroup.getHlcmi(), particleGroup.getHlcma().get(particle), particleGroup.getHlcmmin(), particleGroup.getHlcmmax());
                                    tempVerts[curr.vertexIdx + curr.colorOffset] = Color.toFloatBits((float) color[0], (float) color[1], (float) color[2], 1.0f);
                                } else {
                                    // Plain
                                    tempVerts[curr.vertexIdx + 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);
                                }
                                tempVerts[curr.vertexIdx + 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
                            tempVerts[curr.vertexIdx + sizeOffset] = (particleGroup.size + (float) (rand.nextGaussian() * particleGroup.size / 5d)) * particleGroup.highlightedSizeFactor();
                            // PARTICLE POSITION
                            tempVerts[curr.vertexIdx + particlePosOffset] = (float) p[0];
                            tempVerts[curr.vertexIdx + particlePosOffset + 1] = (float) p[1];
                            tempVerts[curr.vertexIdx + particlePosOffset + 2] = (float) p[2];
                            curr.vertexIdx += curr.vertexSize;
                            curr.numVertices++;
                            numVerticesAdded++;
                        }
                        // Indices
                        quadIndices(curr);
                        numParticlesAdded++;
                    }
                }
                int count = numVerticesAdded * curr.vertexSize;
                setCount(particleGroup, count);
                curr.mesh.setVertices(tempVerts, 0, count);
                curr.mesh.setIndices(tempIndices, 0, numParticlesAdded * 6);
                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);
                } catch (IllegalArgumentException e) {
                    logger.error(e, "Render exception");
                }
            }
        }
    }
}
Also used : ParticleGroup(gaiasky.scenegraph.ParticleGroup) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 9 with ParticleGroup

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

the class UncertaintiesHandler method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case SHOW_UNCERTAINTIES:
            if (data[0] instanceof IStarFocus) {
                final IStarFocus s = (IStarFocus) data[0];
                GaiaSky.postRunnable(new Runnable() {

                    @Override
                    public void run() {
                        ParticleGroup pg = load(s.getCandidateId());
                        GaiaSky.instance.sceneGraph.getRoot().addChild(pg, true);
                        particleGroups.add(pg);
                    }
                });
            }
            break;
        case HIDE_UNCERTAINTIES:
            GaiaSky.postRunnable(new Runnable() {

                @Override
                public void run() {
                    for (ParticleGroup pg : particleGroups) {
                        GaiaSky.instance.sceneGraph.getRoot().removeChild(pg, true);
                    }
                    particleGroups.clear();
                }
            });
            break;
        default:
            break;
    }
}
Also used : IStarFocus(gaiasky.scenegraph.IStarFocus) ParticleGroup(gaiasky.scenegraph.ParticleGroup)

Example 10 with ParticleGroup

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

the class SAMPClient method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case FOCUS_CHANGED:
            if (!preventProgrammaticEvents) {
                if (conn != null && conn.isConnected()) {
                    if (data[0] instanceof ParticleGroup) {
                        ParticleGroup pg = (ParticleGroup) data[0];
                        if (idToNode.containsValue(pg)) {
                            String id = idToNode.getBackward(pg);
                            String url = idToUrl.get(id);
                            int row = pg.getCandidateIndex();
                            Message msg = new Message("table.highlight.row");
                            msg.addParam("row", Integer.toString(row));
                            msg.addParam("table-id", id);
                            msg.addParam("url", url);
                            try {
                                conn.getConnection().notifyAll(msg);
                            } catch (SampException e) {
                                logger.error(e);
                            }
                        }
                    } else if (data[0] instanceof StarCluster) {
                        StarCluster sc = (StarCluster) data[0];
                        if (sc.parent instanceof FadeNode) {
                            // Comes from a catalog
                            FadeNode parent = (FadeNode) sc.parent;
                            if (idToNode.containsValue(parent)) {
                                String id = idToNode.getBackward(parent);
                                String url = idToUrl.get(id);
                                int row = parent.children.indexOf(sc, true);
                                Message msg = new Message("table.highlight.row");
                                msg.addParam("row", Integer.toString(row));
                                msg.addParam("table-id", id);
                                msg.addParam("url", url);
                                try {
                                    conn.getConnection().notifyAll(msg);
                                } catch (SampException e) {
                                    logger.error(e);
                                }
                            }
                        }
                    }
                }
            }
            break;
        case CATALOG_REMOVE:
            String dsName = (String) data[0];
            if (idToNode.containsKey(dsName)) {
                idToNode.removeKey(dsName);
            }
            idToUrl.remove(dsName);
            break;
        case DISPOSE:
            if (conn != null) {
                conn.setActive(false);
            }
            break;
    }
}
Also used : Message(org.astrogrid.samp.Message) ParticleGroup(gaiasky.scenegraph.ParticleGroup) FadeNode(gaiasky.scenegraph.FadeNode) StarCluster(gaiasky.scenegraph.StarCluster)

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