Search in sources :

Example 36 with IParticleRecord

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

the class ParticleGroup method computeMinMeanMaxDistances.

public void computeMinMeanMaxDistances() {
    meanDistance = 0;
    maxDistance = Double.MIN_VALUE;
    minDistance = Double.MAX_VALUE;
    List<Double> distances = new ArrayList<>();
    for (IParticleRecord point : pointData) {
        // Add sample to mean distance
        double dist = len(point.x(), point.y(), point.z());
        if (Double.isFinite(dist)) {
            distances.add(dist);
            maxDistance = Math.max(maxDistance, dist);
            minDistance = Math.min(minDistance, dist);
        }
    }
    // Mean is computed as half of the 90th percentile to avoid outliers
    distances.sort(Double::compare);
    int idx = (int) Math.ceil((90d / 100d) * (double) distances.size());
    meanDistance = distances.get(idx - 1) / 2d;
}
Also used : IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 37 with IParticleRecord

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

the class ParticleGroup method addHit.

public void addHit(Vector3d p0, Vector3d p1, NaturalCamera camera, Array<IFocus> hits) {
    int n = pointData.size();
    if (GaiaSky.instance.isOn(ct) && this.opacity > 0) {
        Vector3d beamDir = new Vector3d();
        Array<Pair<Integer, Double>> temporalHits = new Array<>();
        for (int i = 0; i < n; i++) {
            if (filter(i)) {
                IParticleRecord pb = pointData.get(i);
                Vector3d posd = fetchPosition(pb, cPosD, D31.get(), getDeltaYears());
                beamDir.set(p1).sub(p0);
                if (camera.direction.dot(posd) > 0) {
                    // The star is in front of us
                    // Diminish the size of the star
                    // when we are close by
                    double dist = posd.len();
                    double angle = getRadius(i) / dist / camera.getFovFactor();
                    double distToLine = Intersectord.distanceLinePoint(p0, p1, posd.put(D31.get()));
                    double value = distToLine / dist;
                    if (value < 0.01) {
                        temporalHits.add(new Pair<>(i, angle));
                    }
                }
            }
        }
        Pair<Integer, Double> best = null;
        for (Pair<Integer, Double> hit : temporalHits) {
            if (best == null)
                best = hit;
            else if (hit.getSecond() > best.getSecond()) {
                best = hit;
            }
        }
        if (best != null) {
            // We found the best hit
            candidateFocusIndex = best.getFirst();
            updateFocusDataPos();
            hits.add(this);
            return;
        }
    }
    candidateFocusIndex = -1;
    updateFocusDataPos();
}
Also used : Array(com.badlogic.gdx.utils.Array) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 38 with IParticleRecord

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

the class ParticleGroup method computeGeomCentre.

/**
 * Computes the geometric centre of this data cloud
 *
 * @param forceRecompute Recomputes the geometric centre even if it has been already computed
 */
public Vector3d computeGeomCentre(boolean forceRecompute) {
    if (pointData != null && (forceRecompute || geomCentre == null)) {
        geomCentre = new Vector3d(0, 0, 0);
        int n = pointData.size();
        for (IParticleRecord pb : pointData) {
            geomCentre.add(pb.x(), pb.y(), pb.z());
        }
        geomCentre.scl(1d / (double) n);
    }
    return geomCentre;
}
Also used : IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 39 with IParticleRecord

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

the class ParticleGroup method updateMetadata.

/**
 * Updates the metadata information, to use for sorting. For particles, only the position (distance
 * from camera) is important.
 *
 * @param time   The time frame provider.
 * @param camera The camera.
 */
public void updateMetadata(ITimeFrameProvider time, ICamera camera) {
    Vector3b camPos = camera.getPos();
    int n = pointData.size();
    for (int i = 0; i < n; i++) {
        IParticleRecord d = pointData.get(i);
        // Pos
        Vector3d x = D31.get().set(d.x(), d.y(), d.z());
        metadata[i] = filter(i) ? camPos.dst2d(x) : Double.MAX_VALUE;
    }
}
Also used : IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 40 with IParticleRecord

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

the class ParticleGroup method getAbsolutePosition.

public Vector3b getAbsolutePosition(String name, Vector3b out) {
    if (index.containsKey(name)) {
        int idx = index.get(name);
        IParticleRecord pb = pointData.get(idx);
        out.set(pb.x(), pb.y(), pb.z());
        return out;
    } else {
        return null;
    }
}
Also used : 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