Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aherbert bug fixes #22

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -97,6 +98,11 @@
<url>https://imagej.net/User:Saalfeld</url>
<properties><id>axtimwalde</id></properties>
</contributor>
<contributor>
<name>Alex Herbert</name>
<url>https://imagej.net/User:Aherbert</url>
<properties><id>aherbert</id></properties>
</contributor>
</contributors>

<mailingLists>
Expand Down Expand Up @@ -169,5 +175,22 @@
<groupId>org.scijava</groupId>
<artifactId>vecmath</artifactId>
</dependency>

<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
1 change: 0 additions & 1 deletion src/main/java/customnode/STLLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ private CustomMesh createCustomMesh() {
cm = new CustomTriangleMesh(vertices);
cm.loadedFromName = name;
cm.changed = false;
cm.changed = false;
return cm;
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/customnode/WavefrontExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ public static void save(final Map<String, CustomMesh> meshes,
objWriter.write(mat.name);
objWriter.write('\n');
// print faces
if (cmesh.getClass() == CustomTriangleMesh.class) writeTriangleFaces(
index, objWriter, name);
else if (cmesh.getClass() == CustomQuadMesh.class) writeQuadFaces(index,
if (cmesh instanceof CustomTriangleMesh)
writeTriangleFaces(index, objWriter, name);
else if (cmesh instanceof CustomQuadMesh) writeQuadFaces(index,
objWriter, name);
else if (cmesh.getClass() == CustomPointMesh.class) writePointFaces(
else if (cmesh instanceof CustomPointMesh) writePointFaces(
index, objWriter, name);
else if (cmesh.getClass() == CustomLineMesh.class) {
else if (cmesh instanceof CustomLineMesh) {
final CustomLineMesh clm = (CustomLineMesh) cmesh;
switch (clm.getMode()) {
case CustomLineMesh.PAIRWISE:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ij3d/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public Content(final String name,
public void addInstant(final ContentInstant ci) {
final int timepoint = ci.timepoint;
contents.put(timepoint, ci);
if (!contents.containsKey(timepoint)) {
if (!timepointToSwitchIndex.containsKey(timepoint)) {
timepointToSwitchIndex.put(timepoint, contentSwitch.numChildren());
contentSwitch.addChild(ci);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ij3d/Executer.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void saveAsU3D() {
}

public void loadView() {
final OpenDialog sd = new OpenDialog("Open view...", "", ".view");
final OpenDialog sd = new OpenDialog("Open view...", OpenDialog.getDefaultDirectory(), ".view");
final String dir = sd.getDirectory();
final String name = sd.getFileName();
if (dir == null || name == null) return;
Expand All @@ -386,7 +386,7 @@ public void saveView() {

public void loadSession() {
final OpenDialog sd =
new OpenDialog("Open session...", "session", ".scene");
new OpenDialog("Open session...", OpenDialog.getDefaultDirectory(), ".scene");
final String dir = sd.getDirectory();
final String name = sd.getFileName();
if (dir == null || name == null) return;
Expand Down
108 changes: 72 additions & 36 deletions src/main/java/ij3d/Image3DUniverse.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public class Image3DUniverse extends DefaultAnimatableUniverse {
/** A reference to the universe's shortcuts */
private ShortCuts shortcuts;

/** A reference to the universe's context menu */
private ContextMenu contextmenu;

/**
Expand Down Expand Up @@ -210,11 +211,16 @@ public void mouseClicked(final MouseEvent e) {

@Override
public void mousePressed(final MouseEvent e) {
contextmenu.showPopup(e);
// Remove redundant call to show pop-up.
// Pop-up is shown on mouse release allowing the mouse
// to be moved over content and the menu will be
// for the correct selected content
//contextmenu.showPopup(e);
}

@Override
public void mouseReleased(final MouseEvent e) {
if (e.isConsumed()) return;
contextmenu.showPopup(e);
}
});
Expand Down Expand Up @@ -333,6 +339,7 @@ public boolean isFullScreen() {
*/
@Override
public void cleanup() {
sync(false);
timeline.pause();
removeAllContents();
contents.clear();
Expand Down Expand Up @@ -443,7 +450,24 @@ public Executer getExecuter() {
public ShortCuts getShortcuts() {
return shortcuts;
}

/**
* Refresh the shortcuts using the menubar. This should be called if the standard
* menubar for the ImageJ3DWindow has been modified.
*
* @see #getMenuBar()
*/
public void refreshShortcuts() {
shortcuts = new ShortCuts(menubar);
}

/**
* Returns a reference to the universe's context menu.
*/
public ContextMenu getContextmenu() {
return contextmenu;
}

/**
* Returns a reference to the PointListDialog used by this universe
*/
Expand Down Expand Up @@ -647,8 +671,8 @@ public void recalculateGlobalMinMax() {
final Point3d min = new Point3d();
final Point3d max = new Point3d();

final Iterator it = contents();
Content c = (Content) it.next();
final Iterator<Content> it = contents();
Content c = it.next();
c.getMin(min);
c.getMax(max);
globalMin.set(min);
Expand Down Expand Up @@ -1424,7 +1448,7 @@ public void removeContent(final String name) {
* universe.
*/
@Override
public Iterator contents() {
public Iterator<Content> contents() {
return contents.values().iterator();
}

Expand All @@ -1434,7 +1458,7 @@ public Iterator contents() {
*
* @return
*/
public Collection getContents() {
public Collection<Content> getContents() {
if (contents == null) return null;
return contents.values();
}
Expand Down Expand Up @@ -1495,7 +1519,7 @@ public void loadView(final String file) throws IOException {
public void resetView() {
fireTransformationStarted();

// rotate so that y shows downwards
// rotate so that y shows downwards, z-axis away from the viewer
final Transform3D t = new Transform3D();
final AxisAngle4d aa = new AxisAngle4d(1, 0, 0, Math.PI);
t.set(aa);
Expand All @@ -1521,72 +1545,84 @@ public void resetView() {
* @param angle The angle in radians.
*/
public void rotateUniverse(final Vector3d axis, final double angle) {
fireTransformationStarted();
viewTransformer.rotate(axis, angle);
fireTransformationUpdated();
fireTransformationFinished();
}

/**
* Rotate the univere so that the user looks in the negative direction of the
* z-axis.
* Resets the rotation transform. This is used to provide specific view orientations.
*
* @param aa2 the new rotation transform (applied to the reset rotation)
*/
public void rotateToNegativeXY() {
private void resetRotationTransform(AxisAngle4d aa2) {
fireTransformationStarted();
getRotationTG().setTransform(new Transform3D());
// rotate so that y shows downwards, z-axis away from the viewer
// (i.e. reset the rotation). This is equivalent to rotateToPositiveXY.
final Transform3D t = new Transform3D();
final AxisAngle4d aa = new AxisAngle4d(1, 0, 0, Math.PI);
t.set(aa);
if (aa2 != null)
{
final Transform3D t2 = new Transform3D();
t2.set(aa2);
t.mul(t2);
}
getRotationTG().setTransform(t);
// TODO - The bounding box and coordinate system are not refreshed.
fireTransformationUpdated();
fireTransformationFinished();
}


// The methods below rotate the default view to look along a given axis

/**
* Rotate the univere so that the user looks in the positive direction of the
* Rotate the universe so that the user looks in the negative direction of the
* z-axis.
*/
public void rotateToNegativeXY() {
resetRotationTransform(new AxisAngle4d(0, 1, 0, Math.PI));
}

/**
* Rotate the universe so that the user looks in the positive direction of the
* z-axis. This is the default view.
*/
public void rotateToPositiveXY() {
fireTransformationStarted();
getRotationTG().setTransform(new Transform3D());
waitForNextFrame();
rotateUniverse(new Vector3d(0, 1, 0), Math.PI);
resetRotationTransform(null);
}

/**
* Rotate the univere so that the user looks in the negative direction of the
* Rotate the universe so that the user looks in the negative direction of the
* y-axis.
*/
public void rotateToNegativeXZ() {
fireTransformationStarted();
getRotationTG().setTransform(new Transform3D());
waitForNextFrame();
rotateUniverse(new Vector3d(1, 0, 0), Math.PI / 2);
resetRotationTransform(new AxisAngle4d(1, 0, 0, Math.PI / 2));
}

/**
* Rotate the univere so that the user looks in the positive direction of the
* Rotate the universe so that the user looks in the positive direction of the
* y-axis.
*/
public void rotateToPositiveXZ() {
fireTransformationStarted();
getRotationTG().setTransform(new Transform3D());
waitForNextFrame();
rotateUniverse(new Vector3d(0, 1, 0), -Math.PI / 2);
resetRotationTransform(new AxisAngle4d(1, 0, 0, -Math.PI / 2));
}

/**
* Rotate the univere so that the user looks in the negative direction of the
* Rotate the universe so that the user looks in the negative direction of the
* x-axis.
*/
public void rotateToNegativeYZ() {
fireTransformationStarted();
getRotationTG().setTransform(new Transform3D());
waitForNextFrame();
rotateUniverse(new Vector3d(0, 1, 0), Math.PI / 2);
resetRotationTransform(new AxisAngle4d(0, 1, 0, Math.PI / 2));
}

/**
* Rotate the univere so that the user looks in the positive direction of the
* Rotate the universe so that the user looks in the positive direction of the
* x-axis.
*/
public void rotateToPositiveYZ() {
fireTransformationStarted();
getRotationTG().setTransform(new Transform3D());
waitForNextFrame();
rotateUniverse(new Vector3d(1, 0, 0), -Math.PI / 2);
resetRotationTransform(new AxisAngle4d(0, 1, 0, -Math.PI / 2));
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/ij3d/UniverseSynchronizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public void transformationUpdated(final View view) {

@Override
public void universeClosed() {
removeUniverse(u);
//removeUniverse(u);
// Do not call removeUniverse(u)
// as this will remove this adapter from the list of universe listeners
// (i.e. u.removeUniverseListener(l))
// so modifying the current list of listeners on which universeClosed()
// is currently being invoked by the closing universe.
universes.remove(u);
}
};
u.addUniverseListener(l);
Expand Down Expand Up @@ -75,6 +81,7 @@ private static final void setGlobalTransform(final Image3DUniverse u,
final int num = group.getNumTransforms();
for (int i = 0; i < num; i++)
group.getTransformGroup(i).setTransform(transform.transforms[i]);
u.getViewPlatformTransformer().updateFrontBackClip();
u.fireTransformationUpdated();
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/ij3d/behaviors/InteractiveBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,12 @@ else if (c != null && c.getType() == ContentConstants.ORTHO && axis != -1)
case KeyEvent.VK_PAGE_DOWN:
viewTransformer.zoom(-1);
return;

case KeyEvent.VK_COMMA:
viewTransformer.rotateZ(TWO_RAD);
return;
case KeyEvent.VK_PERIOD:
viewTransformer.rotateZ(-TWO_RAD);
return;
}
}
// If we arrive here, the event was not handled.
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ij3d/shapes/BoundingBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public BoundingBox(final Point3f minp, final Point3f maxp, final Color3f color)
final float ly = max.y - min.y;
final float lz = max.z - min.z;
final float max = Math.max(lx, Math.max(ly, lz));
if (max <= 0)
// No bounding box
return;
float min = Math.min(lx, Math.min(ly, lz));
if (min == 0 || max / min > 100) min = max;
double tmp = 0.00001f;
Expand Down Expand Up @@ -198,12 +201,17 @@ private Appearance createAppearance(final Color3f color) {

private Geometry makeLine(final Point3f start, final Point3f end,
final Color3f color, final float tickDistance, final float first,
final float tickSize, final boolean noTicks)
final float tickSize, boolean noTicks)
{
final float lineLength = start.distance(end);
final int nTicks =
(int) Math.floor((lineLength - first) / tickDistance) + 1;

// Avoid negative array size. This occurs when the (lineLength - first)
// is negative.
if (nTicks < 1)
noTicks = true;

final int n = noTicks ? 2 : nTicks * 6 + 2;

final Point3f[] coords = new Point3f[n];
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ij3d/shapes/CoordinateSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public CoordinateSystem(final float length, final Color3f color) {
this.length = length;
this.color = color;
setCapability(BranchGroup.ALLOW_DETACH);

// No coordinate system
if (length <= 0)
return;

final Shape3D lines = new Shape3D();
lines.setGeometry(createGeometry());
Expand Down
Loading