Search in sources :

Example 1 with AbstractOctreeWrapper

use of gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper in project gaiasky by langurmonkey.

the class SceneGraph method addToHipMap.

private void addToHipMap(SceneGraphNode node) {
    if (node instanceof AbstractOctreeWrapper) {
        AbstractOctreeWrapper aow = (AbstractOctreeWrapper) node;
        Set<SceneGraphNode> set = aow.parenthood.keySet();
        for (SceneGraphNode ape : set) addToHipMap(ape);
    } else {
        synchronized (hipMap) {
            if (node instanceof CelestialBody) {
                CelestialBody s = (CelestialBody) node;
                if (s instanceof Star && ((Star) s).hip > 0) {
                    if (hipMap.containsKey(((Star) s).hip)) {
                        logger.debug(I18n.txt("error.id.hip.duplicate", ((Star) s).hip));
                    } else {
                        hipMap.put(((Star) s).hip, s);
                    }
                }
            } else if (node instanceof StarGroup) {
                List<IParticleRecord> stars = ((StarGroup) node).data();
                for (IParticleRecord pb : stars) {
                    if (pb.hip() > 0) {
                        hipMap.put(pb.hip(), new Position(pb.x(), pb.y(), pb.z(), pb.pmx(), pb.pmy(), pb.pmz()));
                    }
                }
            }
        }
    }
}
Also used : IPosition(gaiasky.util.tree.IPosition) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)

Example 2 with AbstractOctreeWrapper

use of gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper 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 AbstractOctreeWrapper

use of gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper in project gaiasky by langurmonkey.

the class StreamingOctreeLoader method loadData.

@Override
public Array<? extends SceneGraphNode> loadData() {
    AbstractOctreeWrapper octreeWrapper = loadOctreeData();
    if (octreeWrapper != null) {
        // Initialize daemon loader thread.
        daemon = new OctreeLoaderThread(octreeWrapper, this);
        daemon.setDaemon(true);
        daemon.setName("gaiasky-worker-octreeload");
        daemon.setPriority(Thread.MIN_PRIORITY);
        daemon.start();
        // Initialize timer to flush the queue at regular intervals.
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                flushLoadQueue();
            }
        }, 1000, 1000);
        // Add octreeWrapper to result list and return.
        Array<SceneGraphNode> result = new Array<>(false, 1);
        result.add(octreeWrapper);
        logger.info(I18n.txt("notif.catalog.init", octreeWrapper.root.countObjects()));
        return result;
    } else {
        return new Array<>(false, 1);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)

Example 4 with AbstractOctreeWrapper

use of gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper in project gaiasky by langurmonkey.

the class OctreeGroupLoader method loadOctreeData.

@Override
protected AbstractOctreeWrapper loadOctreeData() {
    /*
         * LOAD METADATA
         */
    logger.info(I18n.txt("notif.loading", metadata));
    MetadataBinaryIO metadataReader = new MetadataBinaryIO();
    OctreeNode root = metadataReader.readMetadataMapped(metadata);
    if (root != null) {
        logger.info(I18n.txt("notif.nodeloader", root.numNodesRec(), metadata));
        logger.info(I18n.txt("notif.loading", particles));
        /*
             * CREATE OCTREE WRAPPER WITH ROOT NODE - particle group is by default
             * parallel, so we never use OctreeWrapperConcurrent
             */
        AbstractOctreeWrapper octreeWrapper = new OctreeWrapper("Universe", root);
        octreeWrapper.setFadeout(new double[] { 8e3, 5e5 });
        // Catalog info
        String name = this.name != null ? this.name : "LOD data";
        String description = this.description != null ? this.description : "Octree-based LOD dataset";
        CatalogInfo ci = new CatalogInfo(name, description, null, CatalogInfoSource.LOD, 1.5f, octreeWrapper);
        ci.nParticles = params.containsKey("nobjects") ? (Long) params.get("nobjects") : -1;
        ci.sizeBytes = params.containsKey("size") ? (Long) params.get("size") : -1;
        EventManager.publish(Event.CATALOG_ADD, this, ci, false);
        dataVersionHint = name.contains("DR2") || name.contains("dr2") || description.contains("DR2") || description.contains("dr2") ? 0 : 1;
        /*
             * LOAD LOD LEVELS - LOAD PARTICLE DATA
             */
        try {
            int depthLevel = Math.min(OctreeNode.maxDepth, PRELOAD_DEPTH);
            loadLod(depthLevel, octreeWrapper);
            flushLoadedIds();
        } catch (IOException e) {
            logger.error(e);
        }
        return octreeWrapper;
    } else {
        logger.info("Dataset not found: " + metadata + " - " + particles);
        return null;
    }
}
Also used : MetadataBinaryIO(gaiasky.data.octreegen.MetadataBinaryIO) OctreeNode(gaiasky.util.tree.OctreeNode) CatalogInfo(gaiasky.util.CatalogInfo) IOException(java.io.IOException) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper) OctreeWrapper(gaiasky.scenegraph.octreewrapper.OctreeWrapper) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)

Example 5 with AbstractOctreeWrapper

use of gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper in project gaiasky by langurmonkey.

the class SceneGraph method removeFromHipMap.

private void removeFromHipMap(SceneGraphNode node) {
    if (node instanceof AbstractOctreeWrapper) {
        AbstractOctreeWrapper aow = (AbstractOctreeWrapper) node;
        Set<SceneGraphNode> set = aow.parenthood.keySet();
        for (SceneGraphNode ape : set) removeFromHipMap(ape);
    } else {
        synchronized (hipMap) {
            if (node instanceof CelestialBody) {
                CelestialBody s = (CelestialBody) node;
                if (s instanceof Star && ((Star) s).hip >= 0) {
                    hipMap.remove(((Star) s).hip);
                }
            } else if (node instanceof StarGroup) {
                StarGroup sg = (StarGroup) node;
                List<IParticleRecord> arr = sg.data();
                if (arr != null) {
                    for (IParticleRecord pb : arr) {
                        if (pb != null && pb.hip() >= 0)
                            hipMap.remove(pb.hip());
                    }
                }
            }
        }
    }
}
Also used : IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) AbstractOctreeWrapper(gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)

Aggregations

AbstractOctreeWrapper (gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)6 Array (com.badlogic.gdx.utils.Array)2 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)2 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 MetadataBinaryIO (gaiasky.data.octreegen.MetadataBinaryIO)1 ISceneGraph (gaiasky.scenegraph.ISceneGraph)1 StarGroup (gaiasky.scenegraph.StarGroup)1 OctreeWrapper (gaiasky.scenegraph.octreewrapper.OctreeWrapper)1 CatalogInfo (gaiasky.util.CatalogInfo)1 IPosition (gaiasky.util.tree.IPosition)1 OctreeNode (gaiasky.util.tree.OctreeNode)1 IOException (java.io.IOException)1