Updated header parsing and support of the defined array-1.0 header type
...
This commit is contained in:
parent
cd70bff6f5
commit
7d44d54356
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>ch.psi.imagej.zeromq</artifactId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>0.0.4-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -11,6 +11,16 @@
|
||||
<artifactId>jeromq</artifactId>
|
||||
<version>0.2.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20090211</version>
|
||||
</dependency> -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gov.nih.imagej</groupId>
|
||||
<artifactId>imagej</artifactId>
|
||||
|
@ -9,9 +9,13 @@ import ij.process.*;
|
||||
import java.awt.*;
|
||||
import ij.plugin.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.awt.event.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@ -21,6 +25,10 @@ import javax.swing.Timer;
|
||||
|
||||
import org.jeromq.ZMQ;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
|
||||
public class ZeroMQViewer implements PlugIn {
|
||||
|
||||
@ -58,6 +66,9 @@ public class ZeroMQViewer implements PlugIn {
|
||||
private Semaphore semaphore = new Semaphore(1);
|
||||
private JLabel lblMethod;
|
||||
private JComboBox<String> comboBoxMethod;
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper(new JsonFactory());
|
||||
// private HeaderInfo hinfo = new HeaderInfo();
|
||||
|
||||
public void run(String arg) {
|
||||
IJ.showStatus("Running ZeroMQ Viewer");
|
||||
@ -78,6 +89,7 @@ public class ZeroMQViewer implements PlugIn {
|
||||
while (isPluginRunning) {
|
||||
semaphore.acquire();
|
||||
collect=true;
|
||||
// hinfo.setVisible(true);
|
||||
try{
|
||||
if(img!=null){
|
||||
img.close();
|
||||
@ -136,28 +148,59 @@ public class ZeroMQViewer implements PlugIn {
|
||||
}
|
||||
}
|
||||
|
||||
private void readHeader(byte[] header){
|
||||
String sheader = new String(header);
|
||||
logger.info(sheader);
|
||||
@SuppressWarnings("unchecked")
|
||||
private void readHeader(byte[] h){
|
||||
try{
|
||||
String header = new String(h);
|
||||
// hinfo.setHeader(header);
|
||||
Map<String,Object> m = mapper.readValue(header, new TypeReference<HashMap<String,Object>>(){});
|
||||
if(((List<String>) m.get("htype")).contains("array-1.0")){ // currently we only support array-1.0 message types
|
||||
List<Integer> shape = (List<Integer>) m.get("shape");
|
||||
int nImageSizeX = shape.get(1);
|
||||
int nImageSizeY = shape.get(0);
|
||||
if(imageSizeX!=nImageSizeX || imageSizeY!=nImageSizeY){
|
||||
imageSizeX = nImageSizeX;
|
||||
imageSizeY = nImageSizeY;
|
||||
|
||||
img.close();
|
||||
img=null;
|
||||
}
|
||||
|
||||
if (img == null) {
|
||||
// TODO eventually use ByteProcessor or BinaryProcessor
|
||||
// BinaryProcessor p = new ij.process.BinaryProcessor(new
|
||||
// ByteProcessor(imageSizeX, imageSizeY));
|
||||
img = new ImagePlus("", new ShortProcessor(imageSizeX, imageSizeY));
|
||||
img.show();
|
||||
}
|
||||
img.setTitle(header);
|
||||
}
|
||||
else{
|
||||
logger.info("Header type is not supported ...");
|
||||
if(img!=null){
|
||||
img.close();
|
||||
img=null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IOException e){
|
||||
logger.log(Level.SEVERE, "Unable to parse header", e);
|
||||
}
|
||||
|
||||
// logger.info(sheader);
|
||||
}
|
||||
|
||||
private void readContent(byte[] content) {
|
||||
try {
|
||||
if (img == null) {
|
||||
// TODO eventually use ByteProcessor or BinaryProcessor
|
||||
// BinaryProcessor p = new ij.process.BinaryProcessor(new
|
||||
// ByteProcessor(imageSizeX, imageSizeY));
|
||||
img = new ImagePlus("", new ShortProcessor(imageSizeX, imageSizeY));
|
||||
img.show();
|
||||
if(content!=null && img!=null){
|
||||
// TODO Check whether this is needed
|
||||
short[] shorts = new short[content.length / 2];
|
||||
ByteBuffer.wrap(content).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);
|
||||
img.getProcessor().setPixels(shorts);
|
||||
|
||||
img.updateAndDraw();
|
||||
numImageUpdates++;
|
||||
}
|
||||
|
||||
// TODO Check whether this is needed
|
||||
short[] shorts = new short[content.length / 2];
|
||||
ByteBuffer.wrap(content).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);
|
||||
img.getProcessor().setPixels(shorts);
|
||||
|
||||
img.updateAndDraw();
|
||||
numImageUpdates++;
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, "UpdateImage got exception", ex);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user