use of gaiasky.scenegraph.particle.IParticleRecord 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;
}
use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.
the class StarGroupSerializedIO method writeParticles.
public void writeParticles(List<SceneGraphNode> list, OutputStream out, int version) {
if (list.size() > 0) {
StarGroup sg = (StarGroup) list.get(0);
List<IParticleRecord> l = new ArrayList<>(sg.size());
for (IParticleRecord p : sg.data()) {
l.add(p);
}
try {
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(l);
oos.close();
} catch (Exception e) {
logger.error(e);
}
}
}
use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.
the class StarGroupSerializedIO 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;
}
use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.
the class BrightestStars method sample.
@Override
public boolean sample(List<IParticleRecord> inputStars, OctreeNode octant, float percentage) {
// Calculate nObjects for this octant based on maxObjs and the MAX_PART
int nInput = inputStars.size();
int nObjects = MathUtils.clamp(Math.round(nInput * percentage), 1, Integer.MAX_VALUE);
StarGroup sg = new StarGroup();
List<IParticleRecord> data = new ArrayList<>();
if (nInput <= MIN_PART || octant.depth >= MAX_DEPTH) {
if (!DISCARD) {
// Never discard any
for (IParticleRecord s : inputStars) {
if (s.octant() == null) {
data.add(s);
s.setOctant(octant);
}
}
} else {
if (nInput <= MIN_PART) {
// Downright use all stars that have not been assigned
for (IParticleRecord s : inputStars) {
if (s.octant() == null) {
data.add(s);
s.setOctant(octant);
}
}
} else {
// Select sample, discard the rest
inputStars.sort(comp);
for (int i = 0; i < nObjects; i++) {
IParticleRecord s = inputStars.get(i);
if (s.octant() == null) {
data.add(s);
s.setOctant(octant);
}
}
discarded += nInput - nObjects;
}
}
sg.setData(data, false);
octant.add(sg);
sg.octant = octant;
sg.octantId = octant.pageId;
return true;
} else {
// Extract sample
inputStars.sort(comp);
int added = 0;
int i = 0;
while (added < nObjects && i < inputStars.size()) {
IParticleRecord s = inputStars.get(i);
if (s.octant() == null) {
// Add star
data.add(s);
s.setOctant(octant);
added++;
}
i++;
}
if (added > 0) {
sg.setData(data, false);
octant.add(sg);
sg.octant = octant;
sg.octantId = octant.pageId;
}
// It is leaf if we added all the stars
return added == inputStars.size();
}
}
use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.
the class BrightestStarsSimple method sample.
@Override
public boolean sample(List<IParticleRecord> inputStars, OctreeNode octant, float percentage) {
StarGroup sg = new StarGroup();
List<IParticleRecord> data = new ArrayList<>();
int nInput = inputStars.size();
inputStars.sort(comp);
int added = 0;
while (added < MAX_PART && added < nInput) {
IParticleRecord sb = inputStars.get(added);
if (sb.octant() == null) {
data.add(sb);
sb.setOctant(octant);
added++;
}
}
if (added > 0) {
sg.setData(data, false);
octant.add(sg);
sg.octant = octant;
sg.octantId = octant.pageId;
}
return added == inputStars.size();
}
Aggregations