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;
}
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();
}
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;
}
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;
}
}
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;
}
}
Aggregations