Search in sources :

Example 26 with IParticleRecord

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

the class StarGroupBinaryIO method readParticles.

/**
 * Reads a single star group from the given input stream.
 *
 * @param in The input stream to read the star group from
 * @return A list with a single star group object
 */
public List<SceneGraphNode> readParticles(InputStream in) {
    List<IParticleRecord> data = provider.loadData(in, 1.0);
    StarGroup sg = new StarGroup();
    sg.setData(data);
    List<SceneGraphNode> l = new ArrayList<>(1);
    l.add(sg);
    return l;
}
Also used : StarGroup(gaiasky.scenegraph.StarGroup) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) ArrayList(java.util.ArrayList)

Example 27 with IParticleRecord

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

the class StarGroupSerializedIO method writeParticles.

public void writeParticles(List<SceneGraphNode> list, OutputStream out, int version) {
    if (list.size() > 0) {
        StarGroup sg = (StarGroup) list.get(0);
        List<IParticleRecord> l = new ArrayList<>(sg.size());
        for (IParticleRecord p : sg.data()) {
            l.add(p);
        }
        try {
            ObjectOutputStream oos = new ObjectOutputStream(out);
            oos.writeObject(l);
            oos.close();
        } catch (Exception e) {
            logger.error(e);
        }
    }
}
Also used : StarGroup(gaiasky.scenegraph.StarGroup) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) ArrayList(java.util.ArrayList) ObjectOutputStream(java.io.ObjectOutputStream)

Example 28 with IParticleRecord

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

the class StarGroupSerializedIO method readParticles.

/**
 * Reads a single star group from the given input stream.
 *
 * @param in
 *            The input stream to read the star group from
 * @return A list with a single star group object
 */
public List<SceneGraphNode> readParticles(InputStream in) {
    List<IParticleRecord> data = provider.loadData(in, 1.0);
    StarGroup sg = new StarGroup();
    sg.setData(data);
    List<SceneGraphNode> l = new ArrayList<>(1);
    l.add(sg);
    return l;
}
Also used : StarGroup(gaiasky.scenegraph.StarGroup) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) ArrayList(java.util.ArrayList)

Example 29 with IParticleRecord

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

the class BrightestStars method sample.

@Override
public boolean sample(List<IParticleRecord> inputStars, OctreeNode octant, float percentage) {
    // Calculate nObjects for this octant based on maxObjs and the MAX_PART
    int nInput = inputStars.size();
    int nObjects = MathUtils.clamp(Math.round(nInput * percentage), 1, Integer.MAX_VALUE);
    StarGroup sg = new StarGroup();
    List<IParticleRecord> data = new ArrayList<>();
    if (nInput <= MIN_PART || octant.depth >= MAX_DEPTH) {
        if (!DISCARD) {
            // Never discard any
            for (IParticleRecord s : inputStars) {
                if (s.octant() == null) {
                    data.add(s);
                    s.setOctant(octant);
                }
            }
        } else {
            if (nInput <= MIN_PART) {
                // Downright use all stars that have not been assigned
                for (IParticleRecord s : inputStars) {
                    if (s.octant() == null) {
                        data.add(s);
                        s.setOctant(octant);
                    }
                }
            } else {
                // Select sample, discard the rest
                inputStars.sort(comp);
                for (int i = 0; i < nObjects; i++) {
                    IParticleRecord s = inputStars.get(i);
                    if (s.octant() == null) {
                        data.add(s);
                        s.setOctant(octant);
                    }
                }
                discarded += nInput - nObjects;
            }
        }
        sg.setData(data, false);
        octant.add(sg);
        sg.octant = octant;
        sg.octantId = octant.pageId;
        return true;
    } else {
        // Extract sample
        inputStars.sort(comp);
        int added = 0;
        int i = 0;
        while (added < nObjects && i < inputStars.size()) {
            IParticleRecord s = inputStars.get(i);
            if (s.octant() == null) {
                // Add star
                data.add(s);
                s.setOctant(octant);
                added++;
            }
            i++;
        }
        if (added > 0) {
            sg.setData(data, false);
            octant.add(sg);
            sg.octant = octant;
            sg.octantId = octant.pageId;
        }
        // It is leaf if we added all the stars
        return added == inputStars.size();
    }
}
Also used : StarGroup(gaiasky.scenegraph.StarGroup) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) ArrayList(java.util.ArrayList)

Example 30 with IParticleRecord

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

the class BrightestStarsSimple method sample.

@Override
public boolean sample(List<IParticleRecord> inputStars, OctreeNode octant, float percentage) {
    StarGroup sg = new StarGroup();
    List<IParticleRecord> data = new ArrayList<>();
    int nInput = inputStars.size();
    inputStars.sort(comp);
    int added = 0;
    while (added < MAX_PART && added < nInput) {
        IParticleRecord sb = inputStars.get(added);
        if (sb.octant() == null) {
            data.add(sb);
            sb.setOctant(octant);
            added++;
        }
    }
    if (added > 0) {
        sg.setData(data, false);
        octant.add(sg);
        sg.octant = octant;
        sg.octantId = octant.pageId;
    }
    return added == inputStars.size();
}
Also used : StarGroup(gaiasky.scenegraph.StarGroup) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) ArrayList(java.util.ArrayList)

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