use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemGeometryGroup method createSphere.
/**
* Creates the geometry for a sphere using the given number of divisions.
*
* @param divisions the divisions
* @return the geometry array
*/
public static GeometryArray createSphere(int divisions) {
final int flags = Primitive.GENERATE_NORMALS | Primitive.ENABLE_APPEARANCE_MODIFY | Primitive.ENABLE_GEOMETRY_PICKING;
final Sphere sphere = new Sphere(1, flags, divisions, null);
return (GeometryArray) sphere.getShape(0).getGeometry();
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemPointMesh method setItemColor.
@Override
public void setItemColor(Color3f[] color) {
this.color = null;
if (color.length != size()) {
throw new IllegalArgumentException("list of size " + size() + " expected");
}
final GeometryArray ga = (GeometryArray) getGeometry();
if (ga == null) {
return;
}
ga.setColors(0, color);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemPointMesh method reorderFast.
@Override
public void reorderFast(int[] indices) {
changed = true;
final int oldSize = size();
final int size = (indices == null) ? 0 : Math.min(oldSize, indices.length);
if (size == 0 || indices == null) {
mesh.clear();
this.setGeometry(null);
return;
}
// From here on we assume the current geometry will not be null
// as this only happens when the original size is zero. Size has
// been checked at this point to be the smaller of new and old.
final GeometryArray ga = (GeometryArray) getGeometry();
// Reorder all things in the geometry: coordinates and colour
final Point3f[] oldCoords = mesh.toArray(new Point3f[oldSize]);
final float[] oldColors = new float[oldSize * 3];
ga.getColors(0, oldColors);
final Point3f[] coords = new Point3f[size];
final float[] colors = new float[size * 3];
for (int i = 0; i < size; i++) {
final int j = indices[i];
coords[i] = oldCoords[j];
System.arraycopy(oldColors, j * 3, colors, i * 3, 3);
}
mesh = Arrays.asList(coords);
ga.updateData(new GeometryUpdater() {
@Override
public void updateData(Geometry geometry) {
final GeometryArray ga = (GeometryArray) geometry;
// We re-use the geometry and just truncate the vertex count
ga.setCoordinates(0, coords);
ga.setColors(0, colors);
ga.setValidVertexCount(coords.length);
}
});
// this.setGeometry(ga);
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemTriangleMesh method setItemColor.
@Override
public void setItemColor(Color3f[] color) {
this.color = null;
final int size = size();
if (color.length != size) {
throw new IllegalArgumentException("list of size " + size + " expected");
}
final GeometryArray ga = (GeometryArray) getGeometry();
if (ga == null) {
return;
}
final int objectSize = objectVertices.length;
final int N = objectSize * size;
final Color3f[] colors = new Color3f[N];
int index = 0;
for (final Color3f c : color) {
for (int j = objectSize; j-- > 0; ) {
colors[index++] = c;
}
}
ga.setColors(0, colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method createImage3DUniverse.
/**
* Creates the image 3D universe with a unique name.
*
* @param title the title
* @param titleList the title list (of titles to ignore)
* @return the image 3D universe
*/
private Image3DUniverse createImage3DUniverse(String title, List<String> titleList) {
// Get a unique name by appending numbers to the end
String title2 = title;
int counter = 2;
while (titleList.contains(title2)) {
title2 = title + " " + (counter++);
}
final Image3DUniverse universe = new Image3DUniverse();
universe.addUniverseListener(new LocalUniverseListener());
universe.setShowBoundingBoxUponSelection(false);
universe.showAttribute(DefaultUniverse.ATTRIBUTE_SCALEBAR, false);
// Capture a canvas mouse click/region and identify the coordinates.
final ImageCanvas3D canvas = (ImageCanvas3D) universe.getCanvas();
final BranchGroup scene = universe.getScene();
final MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent event) {
if (!consumeEvent(event)) {
return;
}
// Consume the event
event.consume();
// This finds the vertex indices of the rendered object.
final Pair<Content, IntersectionInfo> pair = getPickedContent(canvas, scene, event.getX(), event.getY());
if (pair == null) {
// Do the same as the mouseClicked in Image3DUniverse
universe.select(null);
return;
}
// Only process content added from localisations
final Content c = pair.getKey();
if (!(c.getUserData() instanceof ResultsMetaData)) {
// Do the same as the mouseClicked in Image3DUniverse
universe.select(c);
return;
}
final ResultsMetaData data = (ResultsMetaData) c.getUserData();
final MemoryPeakResults results = data.results;
// Look up the localisation from the clicked vertex
final ContentInstant content = c.getCurrent();
int index = -1;
if (content.getContent() instanceof CustomMeshNode) {
final CustomMeshNode node = (CustomMeshNode) content.getContent();
final CustomMesh mesh = node.getMesh();
int vertexCount;
final GeometryArray ga = (GeometryArray) mesh.getGeometry();
// Default to the number of vertices
vertexCount = ga.getValidVertexCount();
final int countPerLocalisation = vertexCount / results.size();
// Determine the localisation
final int vertexIndex = pair.getValue().getVertexIndices()[0];
index = vertexIndex / countPerLocalisation;
} else if (content.getContent() instanceof ItemGroupNode) {
// All shapes have the index as the user data
final Object o = pair.getValue().getGeometry().getUserData();
if (o instanceof Integer) {
index = (Integer) pair.getValue().getGeometry().getUserData();
}
}
if (index == -1) {
return;
}
final PeakResult result = results.get(index);
if (event.getClickCount() > 1) {
// Centre on the localisation
final Point3d coordinate = new Point3d();
coordinate.set(data.points.get(index));
// Handle the local transform of the content ...
final Transform3D vWorldToLocal = getVworldToLocal(content);
vWorldToLocal.transform(coordinate);
universe.centerAt(coordinate);
} else if (event.isShiftDown()) {
// Ctrl+Shift held down to remove selected
data.removeFromSelectionModel(result);
} else {
// Ctrl held down to set selection
data.addToSelectionModel(result);
}
}
private boolean consumeEvent(final MouseEvent event) {
if (event.isConsumed() || event.getButton() != MouseEvent.BUTTON1 || !(event.isControlDown())) {
return false;
}
if (event.getClickCount() == 1) {
return true;
}
return (event.getClickCount() == 2);
}
};
// 0 = ImageCanvas3D
// 1 = DefaultUniverse
// 2 = Image3DUniverse
final MouseListener[] l = canvas.getMouseListeners();
for (int i = 0; i < l.length; i++) {
if (l[i].getClass().getName().contains("Image3DUniverse")) {
// We want to be before the Image3DUniverse to allow consuming the click event.
// Only allow the click event.
// This disables the right-click pop-up menu.
// It doesn't have anything of use for localisations anyway.
canvas.removeMouseListener(l[i]);
canvas.addMouseListener(mouseListener);
canvas.addMouseListener(new MouseListenerWrapper(l[i], MouseListenerWrapper.MOUSE_CLICKED));
}
}
// 0 = ImageCanvas3D
// 1 = DefaultUniverse
// 2 = Image3DUniverse
// 3 = EventCatcher (from scijava)
final MouseMotionListener[] ml = canvas.getMouseMotionListeners();
for (int i = 0; i < ml.length; i++) {
if (ml[i].getClass().getName().contains("Image3DUniverse")) {
// Ignore this as it just shows the name in the IJ status bar
canvas.removeMouseMotionListener(ml[i]);
}
}
// Finally display the window
universe.show();
final ImageWindow3D window = universe.getWindow();
GUI.center(window);
window.setTitle(title2);
WindowManager.addWindow(window);
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent event) {
WindowManager.removeWindow(window);
}
});
// Add a new menu for SMLM functionality
createSmlmMenuBar(universe);
return universe;
}
Aggregations