Commit a205cbf1 authored by Amandine  TOURNAY's avatar Amandine TOURNAY
Browse files

Added project

parent 95a6878d
.idea/
target/
.settings/
*.iml
.project
.classpath
\ No newline at end of file
<?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">
<modelVersion>4.0.0</modelVersion>
<!-- Inherited Icy Parent POM -->
<parent>
<groupId>org.bioimageanalysis.icy</groupId>
<artifactId>parent-pom-plugin</artifactId>
<version>1.0.3</version>
</parent>
<!-- Project Information -->
<artifactId>animation-3d</artifactId>
<version>1.3.1</version>
<packaging>jar</packaging>
<name>Animation 3D</name>
<description>Generate nice dataset animations with interpolated camera points.</description>
<url>http://icy.bioimageanalysis.org/plugin/animation-3d/</url>
<inceptionYear>2020</inceptionYear>
<organization>
<name>Institut Pasteur</name>
<url>https://pasteur.fr</url>
</organization>
<licenses>
<license>
<name>GNU GPLv3</name>
<url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>tprovoost</id>
<name>Thomas Provoost</name>
<url>http://icy.bioimageanalysis.org/author/tprovoost/</url>
<roles>
<role>founder</role>
<role>developer</role>
</roles>
</developer>
<developer>
<id>sdallongeville</id>
<name>Stéphane Dallongeville</name>
<url>https://research.pasteur.fr/fr/member/stephane-dallongeville/</url>
<roles>
<role>founder</role>
<role>lead</role>
<role>architect</role>
<role>developer</role>
<role>debugger</role>
<role>tester</role>
<role>maintainer</role>
<role>support</role>
</roles>
</developer>
</developers>
<!-- Project properties -->
<properties>
</properties>
<!-- Project build configuration -->
<build>
</build>
<!-- List of project's dependencies -->
<dependencies>
<!-- The core of Icy -->
<dependency>
<groupId>org.bioimageanalysis.icy</groupId>
<artifactId>icy-kernel</artifactId>
</dependency>
<dependency>
<groupId>org.bioimageanalysis.icy</groupId>
<artifactId>flying-camera</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.bioimageanalysis.icy</groupId>
<artifactId>xuggler</artifactId>
<version>5.5.2</version>
</dependency>
</dependencies>
<!-- Icy Maven repository (to find parent POM) -->
<repositories>
<repository>
<id>icy</id>
<name>Icy's Nexus</name>
<url>https://icy-nexus.pasteur.fr/repository/Icy/</url>
</repository>
</repositories>
</project>
package plugins.tprovoost.animation3d;
import icy.gui.dialog.MessageDialog;
import icy.gui.frame.IcyFrame;
import icy.plugin.PluginLauncher;
import icy.plugin.abstract_.PluginActionable;
import icy.sequence.Sequence;
import icy.system.thread.ThreadUtil;
import java.util.ArrayList;
import plugins.tprovoost.flycam.FlyCam;
import plugins.tprovoost.flycam.FlyCamOverlay;
public class Animation3D extends PluginActionable
{
private Kinematics3D mainFrame;
@Override
public void run()
{
Sequence seq = getActiveSequence();
if (seq == null)
{
MessageDialog.showDialog("You must have a sequence opened for this operation.");
return;
}
// FlyCam is not running on this sequence ?
if (!seq.hasOverlay(FlyCamOverlay.class))
{
// start FlyCam
ThreadUtil.invokeNow(new Runnable()
{
@Override
public void run()
{
new FlyCam().run();
}
});
}
// get the FlyCam overlay
final FlyCamOverlay overlay = (FlyCamOverlay) seq.getOverlays(FlyCamOverlay.class).get(0);
// create the frame now
mainFrame = new Kinematics3D(overlay);
mainFrame.setVisible(true);
mainFrame.addToDesktopPane();
}
public Kinematics3D getKinematics3D()
{
return mainFrame;
}
/**
* Returns the first Animation3D in the list of IcyFrames. If it doesn't
* exist, create an instance first.
*
* @return Kinematics3D
*/
public static Kinematics3D getAnimation3D()
{
ArrayList<IcyFrame> frames = IcyFrame.getAllFrames(Kinematics3D.class);
if (frames.isEmpty())
{
Animation3D p = (Animation3D) PluginLauncher.start(Animation3D.class.getName());
return p.getKinematics3D();
}
else
return (Kinematics3D) frames.get(0);
}
/**
* Returns the Animation3D of index <code>idx</code> in the list of
* IcyFrames. If it doesn't exist, returns null;
*
* @param idx int
* @return Kinematics3D
*/
public static Kinematics3D getAnimation3D(int idx)
{
ArrayList<IcyFrame> frames = IcyFrame.getAllFrames(Kinematics3D.class);
if (frames.isEmpty())
{
return null;
}
else
{
return (Kinematics3D) frames.get(idx);
}
}
}
package plugins.tprovoost.animation3d;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JSlider;
import plugins.tprovoost.flycam.CameraPosition;
public class KeySlider extends JSlider implements MouseListener, MouseMotionListener
{
private static final long serialVersionUID = 1L;
// private ArrayList<Integer> key = new ArrayList<Integer>();
private int fps = 15;
private int timelength;
private Point currentPoint = null;
private CameraPosition currentCamera;
private List<CameraPosition> cameraPositions = new ArrayList<CameraPosition>();
public KeySlider(int min, int max, int value)
{
super(min, max, value);
setPaintTicks(true);
setPaintLabels(true);
addMouseListener(this);
addMouseMotionListener(this);
}
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Insets ins = getInsets();
int w = getWidth();
int h = getHeight();
Graphics2D g2 = (Graphics2D) g.create();
// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
// RenderingHints.VALUE_ANTIALIAS_ON);
// g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// display red keys in component.
g2.setColor(new Color(210, 27, 58));
for (CameraPosition cam : cameraPositions)
{
float step = ((w - 31) / (float) getMaximum());
int positionx = Math.round(ins.left + 11 + cam.timeIndex * step);
g2.fillRect(positionx - 1, h - 12, 3, 6);
}
// // display Seconds:Frame.
g2.setColor(Color.black);
drawCenteredString(g2, "Frame: #" + getValue() + " / " + timeFormat(getValue()) + " s", getMaximum() / 2, 10,
false);
g2.dispose();
}
private String timeFormat(int t)
{
String modulo;
if (t % getFps() < 10)
{
modulo = "0" + t % getFps();
}
else
{
modulo = "" + t % getFps();
}
String SecondFrame;
SecondFrame = "" + (t / getFps()) + ":" + modulo + "0";
return SecondFrame;
}
/**
* @param g
* @param s
* @param v
* Tick corresponding to the center of the string.
*/
private void drawCenteredString(Graphics g, String s, int v, int y, boolean ShowTick)
{
FontMetrics metrics = getFontMetrics(g.getFont());
float step = ((getWidth() - 16.0f) / (float) getMaximum());
int positionx = Math.round(6 + v * step);
g.drawString(s, positionx - metrics.stringWidth(s) / 2, y);
if (ShowTick)
g.drawLine(positionx, 35, positionx, 30);
}
// public void addKey(int timeKey)
// {
// key.add(timeKey);
// repaint();
// }
//
// public void removeKey(int TimeKey)
// {
// key.remove((Integer) TimeKey);
// repaint();
// }
//
// public void removeAllKey()
// {
// key.clear();
// repaint();
// }
// public ArrayList<Integer> getKeys()
// {
// return key;
// }
/**
* @return the timelength
*/
public int getTimelength()
{
return timelength;
}
/**
* @param timelength
* the timelength to set
*/
public void setTimelength(int timelength)
{
this.timelength = timelength;
}
/**
* @return the fps
*/
public int getFps()
{
return fps;
}
/**
* @param fps
* the fps to set
*/
public void setFps(int fps)
{
this.fps = fps;
}
@Override
public void setMaximum(int maximum)
{
super.setMaximum(maximum);
if (maximum < 5)
{
setMinorTickSpacing(maximum);
setLabelTable(createStandardLabels(maximum));
}
else
{
setMajorTickSpacing(maximum / 5);
setMinorTickSpacing(maximum / 10);
setLabelTable(createStandardLabels(maximum / 5));
}
}
@Override
public void mouseDragged(MouseEvent e)
{
if (currentPoint != null && currentCamera != null)
{
int xmov = e.getPoint().x - currentPoint.x;
int max = getMaximum();
float step = (getWidth()) / (float) max;
int timeIndex = (int) (e.getPoint().x / step);
if (timeIndex == 0)
{
timeIndex = 1;
}
else if (timeIndex >= max)
{
timeIndex = max;
}
else if (cameraExists(timeIndex))
{
if (Math.signum(xmov) == -1.0d)
{
timeIndex--;
}
else if (Math.signum(xmov) == 1.0d)
{
timeIndex++;
}
}
System.out.println(timeIndex);
currentCamera.timeIndex = timeIndex;
currentPoint = e.getPoint();
}
repaint();
}
private boolean cameraExists(int timeIndex)
{
for (CameraPosition cam : cameraPositions)
{
if (cam.timeIndex == timeIndex)
return true;
}
return false;
}
@Override
public void mouseMoved(MouseEvent e)
{
}
@Override
public void mouseClicked(MouseEvent e)
{
}
@Override
public void mousePressed(MouseEvent e)
{
Insets ins = getInsets();
int w = getWidth();
int h = getHeight();
for (CameraPosition cam : cameraPositions)
{
float step = ((w - 31) / (float) getMaximum());
int positionx = Math.round(ins.left + 11 + cam.timeIndex * step);
Rectangle rect = new Rectangle(positionx - 1, h - 12, 3, 6);
if (rect.contains(e.getPoint()))
{
currentCamera = cam;
currentPoint = e.getPoint();
break;
}
}
}
@Override
public void mouseReleased(MouseEvent e)
{
currentCamera = null;
currentPoint = e.getPoint();
}
@Override
public void mouseEntered(MouseEvent e)
{
}
@Override
public void mouseExited(MouseEvent e)
{
}
public void setCameraPositions(List<CameraPosition> value)
{
cameraPositions = value;
}
public List<CameraPosition> getCameraPositions()
{
return cameraPositions;
}
}
This diff is collapsed.
package plugins.tprovoost.animation3d;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Hashtable;
import javax.swing.JPanel;
public class TablePanel extends JPanel
{
/**
*
*/
private static final long serialVersionUID = 1L;
private Hashtable<String, Boolean> busy = new Hashtable<String, Boolean>();
private GridBagLayout gridbag;
private GridBagConstraints c;
public final static int WEST = GridBagConstraints.WEST;
public final static int EAST = GridBagConstraints.EAST;
public final static int CENTER = GridBagConstraints.CENTER;
private final Insets DEFAULT_INSETS = new Insets(2, 2, 2, 2);
private final int DEFAULT_ANCHOR = CENTER;
public TablePanel()
{
super();
gridbag = new GridBagLayout();
setLayout(gridbag);
c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
// c.fill = GridBagConstraints.NONE;
c.gridx = -1;
c.gridy = -1;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0.0; // see later
c.weighty = 0.0; // see later
}
public void newLine()
{
c.gridx = -1;
c.gridy++;
}
public Component add(Component component)
{
return add(component, 1, 1, null, -1);
}
public Component add(Component component, int colspan, int rowspan)
{
return add(component, colspan, rowspan, null, -1);
}
public Component add(Component component, int colspan, int rowspan, int anchor)
{
return add(component, colspan, rowspan, null, anchor);
}
public Component add(Component component, int colspan, int rowspan, Insets insets, int anchor)
{
c.gridx++;
while (isBusy(c.gridx, c.gridy))
c.gridx++;
c.gridwidth = colspan;
c.gridheight = rowspan;
for (int i = 0; i < colspan; i++)
{
for (int j = 0; j < rowspan; j++)
{
setBusy(c.gridx + i, c.gridy + j);
}
}
if (anchor != -1)
{
c.anchor = anchor;
}
else
{
c.anchor = DEFAULT_ANCHOR;
}
if (insets != null)
{
c.insets = insets;
}
else
{
c.insets = DEFAULT_INSETS;
}
gridbag.setConstraints(component, c);
return super.add(component);
}
private void setBusy(int x, int y)
{
busy.put(new String(y + "-" + x), new Boolean(true));
}
private boolean isBusy(int x, int y)
{
return busy.get(new String(c.gridy + "-" + c.gridx)) != null;
}
}