Search in sources :

Example 31 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class MilkyWayReshaper method main.

public static void main(String[] args) {
    try {
        // Assets location
        String ASSETS_LOC = Settings.ASSETS_LOC + "/";
        Gdx.files = new Lwjgl3Files();
        // Add notification watch
        new ConsoleLogger();
        // Initialize number format
        NumberFormatFactory.initialize(new DesktopNumberFormatFactory());
        // Initialize date format
        DateFormatFactory.initialize(new DesktopDateFormatFactory());
        // Initialize i18n
        I18n.initialize(new FileHandle(ASSETS_LOC + "i18n/gsbundle"));
        // Initialize configuration
        File dummyv = new File(ASSETS_LOC + "data/dummyversion");
        if (!dummyv.exists()) {
            dummyv = new File(ASSETS_LOC + "dummyversion");
        }
        SettingsManager.initialize(new FileInputStream(ASSETS_LOC + "/conf/config.yaml"), new FileInputStream(dummyv));
        for (int ds = 0; ds < filesIn.length; ds++) {
            logger.info();
            int modulus = moduluses[ds];
            String fileIn = filesIn[ds];
            String fileOut = filesOut[ds];
            logger.info("Processing file: " + fileIn);
            // Load
            PointDataProvider provider = new PointDataProvider();
            List<IParticleRecord> particles = provider.loadData(fileIn);
            String out = Settings.settings.data.dataFile(fileOut);
            if (Files.exists(Paths.get(out))) {
                logger.error("ERROR - Output file exists: " + out);
                continue;
            }
            if (particles.size() > 0) {
                FileWriter fw = new FileWriter(out);
                int ntokens = particles.get(0).rawDoubleData().length;
                if (ntokens == 3) {
                    // Position
                    fw.write("X Y Z\n");
                } else if (ntokens == 4) {
                    // Position + size
                    fw.write("X Y Z size\n");
                } else if (ntokens == 7) {
                    // Position + size + color
                    fw.write("X Y Z size r g b\n");
                } else {
                    logger.error("ERROR - Incorrect number of fields: " + ntokens);
                    continue;
                }
                int particle = 0;
                int added = 0;
                for (IParticleRecord pb : particles) {
                    if (modulus == 0 || particle % modulus == 0) {
                        double[] d = pb.rawDoubleData();
                        for (int i = 0; i < d.length; i++) {
                            fw.write(d[i] + (i < d.length - 1 ? " " : ""));
                        }
                        fw.write("\n");
                        added++;
                    }
                    particle++;
                }
                fw.flush();
                fw.close();
                logger.info(I18n.txt("notif.written", added, out));
            } else {
                logger.info("No particles in input file");
            }
        }
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        logger.error(e, sw.toString());
    }
}
Also used : PointDataProvider(gaiasky.data.group.PointDataProvider) Lwjgl3Files(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Files) FileHandle(com.badlogic.gdx.files.FileHandle) DesktopDateFormatFactory(gaiasky.desktop.format.DesktopDateFormatFactory) ConsoleLogger(gaiasky.interafce.ConsoleLogger) DesktopNumberFormatFactory(gaiasky.desktop.format.DesktopNumberFormatFactory) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 32 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class BillboardGroup method transformData.

private void transformData() {
    // Set static coordinates to position
    coordinates.getEquatorialCartesianCoordinates(null, pos);
    // Initialise transform
    if (transformName != null) {
        Class<Coordinates> c = Coordinates.class;
        try {
            Method m = ClassReflection.getMethod(c, transformName);
            Matrix4d trf = (Matrix4d) m.invoke(null);
            coordinateSystem = trf.putIn(new Matrix4());
        } catch (ReflectionException e) {
            Logger.getLogger(this.getClass()).error("Error getting/invoking method Coordinates." + transformName + "()");
        }
    } else {
    // Equatorial, nothing
    }
    // Model
    Vector3 aux = new Vector3();
    Vector3 pos3 = pos.toVector3();
    // Transform all
    for (BillboardDataset bd : datasets) {
        List<IParticleRecord> a = bd.data;
        if (a != null) {
            for (int i = 0; i < a.size(); i++) {
                IParticleRecord pr = a.get(i);
                aux.set((float) pr.x(), (float) pr.z(), (float) pr.y());
                aux.scl(size).rotate(-90, 0, 1, 0).mul(coordinateSystem).add(pos3);
                pr.setPos(aux.x, aux.y, aux.z);
            }
        }
    }
}
Also used : ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException) BillboardDataset(gaiasky.scenegraph.particle.BillboardDataset) Coordinates(gaiasky.util.coord.Coordinates) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) Vector3(com.badlogic.gdx.math.Vector3) Method(com.badlogic.gdx.utils.reflect.Method) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 33 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord 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 34 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class StarGroup method generateIndex.

/**
 * Generates the index (maps star name and id to array index)
 *
 * @param pointData The star data
 *
 * @return An map{string,int} mapping names/ids to indexes
 */
public Map<String, Integer> generateIndex(Array<IParticleRecord> pointData) {
    Map<String, Integer> index = new HashMap<>();
    int n = pointData.size;
    for (int i = 0; i < n; i++) {
        IParticleRecord sb = pointData.get(i);
        if (sb.names() != null) {
            for (String lowerCaseName : sb.names()) {
                lowerCaseName = lowerCaseName.toLowerCase();
                index.put(lowerCaseName, i);
                String lcid = Long.toString(sb.id()).toLowerCase();
                if (sb.id() > 0 && !lcid.equals(lowerCaseName)) {
                    index.put(lcid, i);
                }
                if (sb.hip() > 0) {
                    String lowerCaseHip = "hip " + sb.hip();
                    if (!lowerCaseHip.equals(lowerCaseName))
                        index.put(lowerCaseHip, i);
                }
            }
        }
    }
    return index;
}
Also used : IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 35 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class StarGroup method render.

/**
 * Label rendering
 */
@Override
public void render(ExtSpriteBatch batch, ExtShaderProgram shader, FontRenderSystem sys, RenderingContext rc, ICamera camera) {
    float thOverFactor = (float) (Settings.settings.scene.star.threshold.point / Settings.settings.scene.label.number / camera.getFovFactor());
    Vector3d starPosition = D31.get();
    int n = Math.min(pointData.size(), Settings.settings.scene.star.group.numLabel);
    if (camera.getCurrent() instanceof FovCamera) {
        for (int i = 0; i < n; i++) {
            IParticleRecord star = pointData.get(active[i]);
            starPosition = fetchPosition(star, cPosD, starPosition, currDeltaYears);
            double distToCamera = starPosition.len();
            float radius = (float) getRadius(active[i]);
            float viewAngle = (float) (((radius / distToCamera) / camera.getFovFactor()) * Settings.settings.scene.star.brightness * 6f);
            if (camera.isVisible(viewAngle, starPosition, distToCamera)) {
                render2DLabel(batch, shader, rc, sys.font2d, camera, star.names()[0], starPosition);
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            int idx = active[i];
            renderStarLabel(idx, starPosition, thOverFactor, batch, shader, sys, rc, camera);
        }
        for (Integer i : forceLabelStars) {
            renderStarLabel(i, starPosition, thOverFactor, batch, shader, sys, rc, camera);
        }
    }
}
Also used : FovCamera(gaiasky.scenegraph.camera.FovCamera) Vector3d(gaiasky.util.math.Vector3d) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Aggregations

IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)48 Vector3d (gaiasky.util.math.Vector3d)10 StarGroup (gaiasky.scenegraph.StarGroup)8 ArrayList (java.util.ArrayList)6 Array (com.badlogic.gdx.utils.Array)5 Vector3 (com.badlogic.gdx.math.Vector3)4 ParticleGroup (gaiasky.scenegraph.ParticleGroup)4 OctreeNode (gaiasky.util.tree.OctreeNode)4 FileHandle (com.badlogic.gdx.files.FileHandle)3 ParticleRecord (gaiasky.scenegraph.particle.ParticleRecord)3 Coordinates (gaiasky.util.coord.Coordinates)3 Matrix4 (com.badlogic.gdx.math.Matrix4)2 LongMap (com.badlogic.gdx.utils.LongMap)2 Method (com.badlogic.gdx.utils.reflect.Method)2 ReflectionException (com.badlogic.gdx.utils.reflect.ReflectionException)2 IStarGroupDataProvider (gaiasky.data.group.IStarGroupDataProvider)2 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)2 ICamera (gaiasky.scenegraph.camera.ICamera)2 AbstractOctreeWrapper (gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)2 BillboardDataset (gaiasky.scenegraph.particle.BillboardDataset)2