use of gaiasky.data.util.PointCloudData in project gaiasky by langurmonkey.
the class OrbitalParametersProvider method loadOld.
public void loadOld(String file, OrbitDataLoaderParameter parameter) {
OrbitComponent params = parameter.orbitalParamaters;
try {
// Parameters of the ellipse
double a = params.semimajoraxis;
double f = params.e * params.semimajoraxis;
double b = Math.sqrt(Math.pow(a, 2) - Math.pow(f, 2));
int nSamples = Math.min(Math.max(50, (int) (a * 0.01)), 100);
double step = 360d / nSamples;
Vector3d[] samples = new Vector3d[nSamples + 1];
int i = 0;
for (double angledeg = 0; angledeg < 360; angledeg += step) {
double angleRad = Math.toRadians(angledeg);
Vector3d point = new Vector3d(b * Math.sin(angleRad), 0d, a * Math.cos(angleRad));
samples[i] = point;
i++;
}
// Last, to close the orbit.
samples[i] = samples[0].cpy();
Matrix4d transform = new Matrix4d();
transform.scl(Constants.KM_TO_U);
data = new PointCloudData();
for (Vector3d point : samples) {
point.mul(transform);
data.x.add(point.x);
data.y.add(point.y);
data.z.add(point.z);
data.time.add(Instant.now());
}
EventManager.publish(Event.ORBIT_DATA_LOADED, this, data, parameter.name);
} catch (Exception e) {
Logger.getLogger(this.getClass()).error(e);
}
}
use of gaiasky.data.util.PointCloudData in project gaiasky by langurmonkey.
the class FileDataLoader method load.
/**
* Loads the data in the input stream into an OrbitData object.
*/
public PointCloudData load(InputStream data) throws Exception {
PointCloudData orbitData = new PointCloudData();
BufferedReader br = new BufferedReader(new InputStreamReader(data));
String line;
Timestamp last = new Timestamp(0);
while ((line = br.readLine()) != null) {
if (!line.isEmpty() && !line.startsWith("#")) {
// Read line
String[] tokens = line.split("\\s+");
if (tokens.length >= 4) {
// Valid data line
Timestamp t = Timestamp.valueOf(tokens[0].replace('_', ' '));
Matrix4d transform = new Matrix4d();
transform.scl(Constants.KM_TO_U);
if (!t.equals(last)) {
orbitData.time.add(t.toInstant());
/* From Data coordinates to OpenGL world coordinates
* Z -> -X
* X -> Y
* Y -> Z
*/
Vector3d pos = new Vector3d(parsed(tokens[1]), parsed(tokens[2]), parsed(tokens[3]));
pos.mul(transform);
orbitData.x.add(pos.x);
orbitData.y.add(pos.y);
orbitData.z.add(pos.z);
last.setTime(t.getTime());
}
}
}
}
br.close();
return orbitData;
}
use of gaiasky.data.util.PointCloudData in project gaiasky by langurmonkey.
the class HeliotropicOrbitDataLoader method load.
/**
* Loads the data in the input stream and transforms it into Cartesian
* <b>ecliptic</b> coordinates. The reference system of the data goes as
* follows:
* <ul>
* <li>Origin of frame : Earth</li>
* <li>X and Y axis in the EQUATORIAL PLANE with X pointing in the direction
* of vernal equinox.</li>
* <li>Z perpendicular to the the EQUATORIAL PLANE in the north direction
* </li>
* <li>The Y direction is defined to have (X,Y,Z) as a "three axis"
* positively oriented.</li>
* </ul>
* <p>
* The simulation reference system:
* <ul>
* <li>- XZ lies in the ECLIPTIC PLANE, with Z pointing to the vernal
* equinox.</li>
* <li>- Y perpendicular to the ECLIPTIC PLANE pointing north.</li>
* </ul>
*
* @param data The input stream with the data to load
* @throws Exception
*/
public PointCloudData load(InputStream data) throws Exception {
PointCloudData orbitData = new PointCloudData();
BufferedReader br = new BufferedReader(new InputStreamReader(data));
String line;
Instant previousAddedTime = null;
int lineNum = 1;
while ((line = br.readLine()) != null) {
// Skip header (first line)
if (lineNum > 1 && !line.isEmpty() && !line.startsWith("#")) {
String[] tokens = line.split(",");
try {
// Valid data line
// Julian date
double jd = parsed(tokens[0]);
Instant time = AstroUtils.julianDateToInstant(jd);
/*
* From Data coordinates to OpenGL world coordinates Z -> -X
* X -> Y Y -> Z
*/
Vector3d pos = new Vector3d(parsed(tokens[2]), parsed(tokens[3]), -parsed(tokens[1]));
// Transform to heliotropic using the Sun's ecliptic longitude
Vector3d posHel = correctSunLongitude(pos, time, 0);
// To ecliptic again
pos.mul(Coordinates.eqToEcl());
posHel.mul(Coordinates.eqToEcl());
boolean add = count == 0 || previousAddedTime == null || (time.toEpochMilli() - previousAddedTime.toEpochMilli() >= maxMsSep);
if (add) {
orbitData.time.add(time);
orbitData.x.add(posHel.x * Constants.KM_TO_U);
orbitData.y.add(posHel.y * Constants.KM_TO_U);
orbitData.z.add(posHel.z * Constants.KM_TO_U);
previousAddedTime = time;
}
count++;
} catch (Exception e) {
logger.error("Error loading line: " + count);
}
}
lineNum++;
}
br.close();
return orbitData;
}
use of gaiasky.data.util.PointCloudData in project gaiasky by langurmonkey.
the class OrbitSamplerDataProvider method load.
@Override
public void load(String file, OrbitDataLoaderParameter parameter) {
// Sample using VSOP
// If num samples is not defined, we use 300 samples per year of period
// Prevent overlapping by rescaling the period
double period = parameter.orbitalPeriod * 0.99d;
int numSamples = parameter.numSamples > 0 ? parameter.numSamples : (int) (300.0 * period / 365.0);
numSamples = Math.max(100, Math.min(2000, numSamples));
data = new PointCloudData();
String bodyDesc = parameter.name;
Instant d = Instant.ofEpochMilli(parameter.ini.getTime());
double last = 0, accum = 0;
// Milliseconds of this orbit in one revolution
double orbitalMs = period * 86400000.0;
double stepMs = orbitalMs / (double) numSamples;
// Load orbit data
for (int i = 0; i <= numSamples; i++) {
AstroUtils.getEclipticCoordinates(bodyDesc, d, ecl, true);
double eclx = ecl.x.doubleValue();
if (last == 0) {
last = Math.toDegrees(eclx);
}
accum += Math.toDegrees(eclx) - last;
last = Math.toDegrees(eclx);
if (accum > 360) {
break;
}
Coordinates.sphericalToCartesian(ecl, ecl);
ecl.mul(Coordinates.eclToEq()).scl(1);
data.x.add(ecl.x.doubleValue());
data.y.add(ecl.y.doubleValue());
data.z.add(ecl.z.doubleValue());
data.time.add(d);
d = Instant.ofEpochMilli(d.toEpochMilli() + (long) stepMs);
}
// Close the circle
data.x.add(data.x.get(0));
data.y.add(data.y.get(0));
data.z.add(data.z.get(0));
d = Instant.ofEpochMilli(d.toEpochMilli() + (long) stepMs);
data.time.add(Instant.ofEpochMilli(d.toEpochMilli()));
if (writeData) {
try {
OrbitDataWriter.writeOrbitData(writeDataPath + "orb." + bodyDesc.toUpperCase() + ".dat", data);
} catch (IOException e) {
Logger.getLogger(this.getClass()).error(e);
}
}
Logger.getLogger(this.getClass()).info(I18n.txt("notif.orbitdataof.loaded", parameter.name, data.getNumPoints()));
}
use of gaiasky.data.util.PointCloudData in project gaiasky by langurmonkey.
the class VertGPURenderSystem method renderStud.
@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
if (isLine()) {
// Enable GL_LINE_SMOOTH
Gdx.gl20.glEnable(GL11.GL_LINE_SMOOTH);
Gdx.gl.glHint(GL20.GL_NICEST, GL11.GL_LINE_SMOOTH_HINT);
// Enable GL_LINE_WIDTH
Gdx.gl20.glEnable(GL20.GL_LINE_WIDTH);
}
this.camera = camera;
renderables.forEach(r -> {
T renderable = (T) r;
/*
* ADD LINES
*/
if (!inGpu(renderable)) {
// Remove previous line data if present
if (getOffset(renderable) >= 0) {
clearMeshData(getOffset(renderable));
setOffset(renderable, -1);
}
// Actually add data
PointCloudData od = renderable.getPointCloud();
int nPoints = od.getNumPoints();
// Initialize or fetch mesh data
if (getOffset(renderable) < 0) {
setOffset(renderable, addMeshData(nPoints));
} else {
curr = meshes.get(getOffset(renderable));
// Check we still have capacity, otherwise, reinitialize.
if (curr.numVertices != od.getNumPoints()) {
curr.clear();
curr.mesh.dispose();
meshes.set(getOffset(renderable), null);
setOffset(renderable, addMeshData(nPoints));
}
}
// Coord maps time
long t0 = od.getDate(0).getEpochSecond();
long t1 = od.getDate(od.getNumPoints() - 1).getEpochSecond();
long t01 = t1 - t0;
// Ensure vertices capacity
ensureTempVertsSize((nPoints + 2) * curr.vertexSize);
curr.vertices = tempVerts;
float[] cc = renderable.getColor();
for (int point_i = 0; point_i < nPoints; point_i++) {
coord((float) ((double) (od.getDate(point_i).getEpochSecond() - t0) / (double) t01));
color(cc[0], cc[1], cc[2], 1.0);
vertex((float) od.getX(point_i), (float) od.getY(point_i), (float) od.getZ(point_i));
}
// Close loop
if (renderable.isClosedLoop()) {
coord(1f);
color(cc[0], cc[1], cc[2], 1.0);
vertex((float) od.getX(0), (float) od.getY(0), (float) od.getZ(0));
}
int count = nPoints * curr.vertexSize;
setCount(renderable, count);
curr.mesh.setVertices(curr.vertices, 0, count);
curr.vertices = null;
setInGpu(renderable, true);
}
curr = meshes.get(getOffset(renderable));
/*
* RENDER
*/
ExtShaderProgram shaderProgram = getShaderProgram();
shaderProgram.begin();
// Regular
if (isLine())
Gdx.gl.glLineWidth(renderable.getPrimitiveSize() * Settings.settings.scene.lineWidth);
if (isPoint())
shaderProgram.setUniformf("u_pointSize", renderable.getPrimitiveSize());
shaderProgram.setUniformMatrix("u_worldTransform", renderable.getLocalTransform());
shaderProgram.setUniformMatrix("u_projView", camera.getCamera().combined);
shaderProgram.setUniformf("u_alpha", (float) (renderable.getAlpha()) * getAlpha(renderable));
shaderProgram.setUniformf("u_coordPos", renderable instanceof Orbit ? (float) ((Orbit) renderable).coord : 1f);
shaderProgram.setUniformf("u_period", renderable instanceof Orbit && ((Orbit) renderable).oc != null ? (float) ((Orbit) renderable).oc.period : 0f);
if (renderable.getParent() != null) {
Vector3d urp = renderable.getParent().getUnrotatedPos();
if (urp != null)
shaderProgram.setUniformf("u_parentPos", (float) urp.x, (float) urp.y, (float) urp.z);
else
shaderProgram.setUniformf("u_parentPos", 0, 0, 0);
}
// Rel, grav, z-buffer
addEffectsUniforms(shaderProgram, camera);
curr.mesh.render(shaderProgram, renderable.getGlPrimitive());
shaderProgram.end();
});
}
Aggregations