Search in sources :

Example 1 with StarGroup

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

the class OctreeGroupLoader method loadOctant.

public boolean loadOctant(final OctreeNode octant, final AbstractOctreeWrapper octreeWrapper, final boolean fullInit) {
    FileHandle octantFile = Settings.settings.data.dataFileHandle(particles + "particles_" + String.format("%06d", octant.pageId) + ".bin");
    if (!octantFile.exists() || octantFile.isDirectory()) {
        return false;
    }
    List<IParticleRecord> data = particleReader.loadDataMapped(octantFile.path(), 1.0, dataVersionHint);
    StarGroup sg = StarGroup.getDefaultStarGroup("stargroup-%%SGID%%", data, fullInit);
    sg.setEpoch(epoch);
    sg.setCatalogInfoBare(octreeWrapper.getCatalogInfo());
    synchronized (octant) {
        sg.octant = octant;
        sg.octantId = octant.pageId;
        // Add objects to octree wrapper node
        octreeWrapper.add(sg, octant);
        // Aux info
        if (GaiaSky.instance != null && GaiaSky.instance.sceneGraph != null)
            GaiaSky.instance.sceneGraph.addNodeAuxiliaryInfo(sg);
        nLoadedStars += sg.size();
        octant.add(sg);
        // Put it at the end of the queue
        touch(octant);
        octant.setStatus(LoadStatus.LOADED);
        // Update counts
        octant.touch(data.size());
        addLoadedInfo(octant.pageId, octant.countObjects());
    }
    return true;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) StarGroup(gaiasky.scenegraph.StarGroup) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 2 with StarGroup

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

the class SceneGraphJsonLoader method loadSceneGraph.

public static synchronized ISceneGraph loadSceneGraph(FileHandle[] jsonFiles, ITimeFrameProvider time, boolean multithreading, int maxThreads) throws FileNotFoundException, ReflectionException {
    ISceneGraph sg;
    logger.info(I18n.txt("notif.loading", "JSON data descriptor files:"));
    for (FileHandle fh : jsonFiles) {
        logger.info("\t" + fh.path() + " - exists: " + fh.exists());
        if (!fh.exists()) {
            logger.error(I18n.txt("error.loading.notexistent", fh.path()));
        }
    }
    Array<SceneGraphNode> nodes = new Array<>(false, 20600);
    for (FileHandle jsonFile : jsonFiles) {
        nodes.addAll(loadJsonFile(jsonFile));
    }
    // Initialize nodes and look for octrees
    boolean hasOctree = false;
    boolean hasStarGroup = false;
    for (SceneGraphNode node : nodes) {
        node.initialize();
        if (node instanceof AbstractOctreeWrapper) {
            hasOctree = true;
            AbstractOctreeWrapper aow = (AbstractOctreeWrapper) node;
            if (aow.children != null)
                for (SceneGraphNode n : aow.children) {
                    if (n instanceof StarGroup) {
                        hasStarGroup = true;
                        break;
                    }
                }
        }
        if (node instanceof StarGroup)
            hasStarGroup = true;
    }
    sg = SceneGraphImplementationProvider.provider.getImplementation(multithreading, hasOctree, hasStarGroup, maxThreads, nodes.size);
    sg.initialize(nodes, time, hasOctree, hasStarGroup);
    return sg;
}
Also used : Array(com.badlogic.gdx.utils.Array) ISceneGraph(gaiasky.scenegraph.ISceneGraph) FileHandle(com.badlogic.gdx.files.FileHandle) StarGroup(gaiasky.scenegraph.StarGroup) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)

Example 3 with StarGroup

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

the class OctreeGeneratorMag method generateOctree.

@Override
public OctreeNode generateOctree(List<IParticleRecord> catalog) {
    root = IOctreeGenerator.startGeneration(catalog, params);
    // Holds all octree nodes indexed by id
    LongMap<OctreeNode> idMap = new LongMap<>();
    idMap.put(root.pageId, root);
    // Contains the list of objects for each node
    Map<OctreeNode, List<IParticleRecord>> objMap = new HashMap<>();
    int catalogSize = catalog.size();
    int catalogIndex = 0;
    for (int level = 0; level <= 19; level++) {
        logger.info("Generating level " + level + " (" + (catalog.size() - catalogIndex) + " stars left)");
        while (catalogIndex < catalogSize) {
            // Add stars to nodes until we reach max part
            IParticleRecord sb = catalog.get(catalogIndex++);
            double x = sb.x();
            double y = sb.y();
            double z = sb.z();
            Long nodeId = getPositionOctantId(x, y, z, level);
            if (!idMap.containsKey(nodeId)) {
                // Create octant and parents if necessary
                OctreeNode octant = createOctant(nodeId, x, y, z, level);
                // Add to idMap
                idMap.put(octant.pageId, octant);
            }
            // Add star to node
            OctreeNode octant = idMap.get(nodeId);
            int addedNum = addStarToNode(sb, octant, objMap);
            if (addedNum >= params.maxPart) {
                // On to next level!
                break;
            }
        }
        if (catalogIndex >= catalog.size()) {
            // All stars added -> FINISHED
            break;
        }
    }
    if (params.postprocess) {
        logger.info("Post-processing octree: childcount=" + params.childCount + ", parentcount=" + params.parentCount);
        long mergedNodes = 0;
        long mergedObjects = 0;
        // We merge low-count nodes (<= childcount) with parents, if parents' count is <= parentcount
        Object[] nodes = objMap.keySet().toArray();
        // Sort by descending depth
        Arrays.sort(nodes, (node1, node2) -> {
            OctreeNode n1 = (OctreeNode) node1;
            OctreeNode n2 = (OctreeNode) node2;
            return Integer.compare(n2.depth, n1.depth);
        });
        int n = objMap.size();
        for (int i = n - 1; i >= 0; i--) {
            OctreeNode current = (OctreeNode) nodes[i];
            if (current.numChildren() == 0 && current.parent != null && objMap.containsKey(current) && objMap.containsKey(current.parent)) {
                List<IParticleRecord> childArr = objMap.get(current);
                List<IParticleRecord> parentArr = objMap.get(current.parent);
                if (childArr.size() <= params.childCount && parentArr.size() <= params.parentCount) {
                    // Merge children nodes with parent nodes, remove children
                    parentArr.addAll(childArr);
                    objMap.remove(current);
                    current.remove();
                    mergedNodes++;
                    mergedObjects += childArr.size();
                }
            }
        }
        logger.info("POSTPROCESS STATS:");
        logger.info("    Merged nodes:    " + mergedNodes);
        logger.info("    Merged objects:  " + mergedObjects);
    }
    // Tree is ready, create star groups
    Set<OctreeNode> nodes = objMap.keySet();
    for (OctreeNode node : nodes) {
        List<IParticleRecord> list = objMap.get(node);
        StarGroup sg = new StarGroup();
        sg.setData(list, false);
        node.add(sg);
        sg.octant = node;
        sg.octantId = node.pageId;
    }
    root.updateCounts();
    return root;
}
Also used : LongMap(com.badlogic.gdx.utils.LongMap) OctreeNode(gaiasky.util.tree.OctreeNode) StarGroup(gaiasky.scenegraph.StarGroup) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 4 with StarGroup

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

the class StarGroupBinaryIO method writeParticles.

public void writeParticles(List<SceneGraphNode> list, OutputStream out, int version) {
    if (list.size() > 0) {
        StarGroup sg = (StarGroup) list.get(0);
        provider.writeData(sg.data(), out, version);
    }
}
Also used : StarGroup(gaiasky.scenegraph.StarGroup)

Example 5 with StarGroup

use of gaiasky.scenegraph.StarGroup 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)

Aggregations

StarGroup (gaiasky.scenegraph.StarGroup)12 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)8 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)5 ArrayList (java.util.ArrayList)5 Array (com.badlogic.gdx.utils.Array)4 FileHandle (com.badlogic.gdx.files.FileHandle)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)1 LongMap (com.badlogic.gdx.utils.LongMap)1 AttributeComboBoxBean (gaiasky.interafce.beans.AttributeComboBoxBean)1 ISceneGraph (gaiasky.scenegraph.ISceneGraph)1 ParticleGroup (gaiasky.scenegraph.ParticleGroup)1 AbstractOctreeWrapper (gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)1 OctreeWrapper (gaiasky.scenegraph.octreewrapper.OctreeWrapper)1 FilterRule (gaiasky.util.filter.FilterRule)1 IComparator (gaiasky.util.filter.FilterRule.IComparator)1 OctreeNode (gaiasky.util.tree.OctreeNode)1 UCD (gaiasky.util.ucd.UCD)1 FloatValidator (gaiasky.util.validator.FloatValidator)1 ObjectOutputStream (java.io.ObjectOutputStream)1