From 9564942d70295b8f8991923805be9de7de4c326d Mon Sep 17 00:00:00 2001 From: Michael Doube Date: Tue, 25 Oct 2011 17:49:37 +0200 Subject: [PATCH 1/3] Change visibility of methods and fields to private --- .../doube/bonej/pqct/Read_Stratec_File.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/org/doube/bonej/pqct/Read_Stratec_File.java b/src/org/doube/bonej/pqct/Read_Stratec_File.java index 8fa7af4c..c145f198 100644 --- a/src/org/doube/bonej/pqct/Read_Stratec_File.java +++ b/src/org/doube/bonej/pqct/Read_Stratec_File.java @@ -31,28 +31,28 @@ public class Read_Stratec_File extends ImagePlus implements PlugIn { //Global variables //Stratec header stuff - public byte[] PName = new byte[40]; // - public String PatName; - public long PatNo; - public int PatMeasNo; - public long PatBirth; // - public long MeasDate; // - public double VoxelSize; // - public int PicX0; // - public int PicY0; // - public int PicMatrixX; // - public int PicMatrixY; // - public byte[] MInfo = new byte[324]; // - public String MeasInfo; - public byte[] Dev = new byte[13]; - public String Device; - public byte[] PID = new byte[13]; - public String PatID; - public double ObjLen; // - public short[] data; - public short min,max; - public String fileName; - public String properties; + private byte[] PName = new byte[40]; // + private String PatName; + private long PatNo; + private int PatMeasNo; + private long PatBirth; // + private long MeasDate; // + private double VoxelSize; // + private int PicX0; // + private int PicY0; // + private int PicMatrixX; // + private int PicMatrixY; // + private byte[] MInfo = new byte[324]; // + private String MeasInfo; + private byte[] Dev = new byte[13]; + private String Device; + private byte[] PID = new byte[13]; + private String PatID; + private double ObjLen; // + private short[] data; + private short min,max; + private String fileName; + private String properties; public Read_Stratec_File() { //Constructor //this = null; @@ -88,7 +88,7 @@ public void run(String arg) { if (this.getHeight()<1) return; } - public void read(String directory){ + private void read(String directory){ File fileIn = new File(directory+fileName); long fileLength = fileIn.length(); try{BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(fileIn)); @@ -135,7 +135,7 @@ public void read(String directory){ } } - public void readHeader(byte[] fileData){ + private void readHeader(byte[] fileData){ byte stringLength; int offset =12; VoxelSize = Double.longBitsToDouble((long) ( ((long) (fileData[offset+7] & 0xFF))<<56 | ((long) (fileData[offset+6] & 0xFF))<<48 | ((long) (fileData[offset+5] & 0xFF))<<40 | ((long) (fileData[offset+4] & 0xFF))<<32 | ((long) (fileData[offset+3] & 0xFF))<<24 | ((long) (fileData[offset+2] & 0xFF))<<16 | ((long) (fileData[offset+1] & 0xFF))<<8 | ((long) (fileData[offset+0] & 0xFF))<<0)); @@ -188,7 +188,7 @@ public void readHeader(byte[] fileData){ PicMatrixY = ((int) ((int) (fileData[offset+1] & 0xFF)) <<8 | ((int) (fileData[offset+0] & 0xFF))); } - public void setProperties(){ + private void setProperties(){ String[] propertyNames = {"File Name","Pixel Spacing","ObjLen","MeasInfo","Acquisition Date", "Device","PatMeasNo","PatNo","Patient's Birth Date","Patient's Name", "Patient ID","PicX0","PicY0", From 7ad10ba46e0f404d8b30727919f17f49a258f331 Mon Sep 17 00:00:00 2001 From: Michael Doube Date: Tue, 25 Oct 2011 17:50:56 +0200 Subject: [PATCH 2/3] Remove unused fields --- src/org/doube/bonej/pqct/Read_Stratec_File.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/org/doube/bonej/pqct/Read_Stratec_File.java b/src/org/doube/bonej/pqct/Read_Stratec_File.java index c145f198..fe378536 100644 --- a/src/org/doube/bonej/pqct/Read_Stratec_File.java +++ b/src/org/doube/bonej/pqct/Read_Stratec_File.java @@ -49,8 +49,6 @@ public class Read_Stratec_File extends ImagePlus implements PlugIn { private byte[] PID = new byte[13]; private String PatID; private double ObjLen; // - private short[] data; - private short min,max; private String fileName; private String properties; From cc1d97d1983283ab8d43e8333b1c019c754ba11b Mon Sep 17 00:00:00 2001 From: Michael Doube Date: Tue, 25 Oct 2011 21:26:35 +0200 Subject: [PATCH 3/3] Add a public opener API to Read_Stratec_File This means external plugins can open Stratec pQCT files and control what happens to the resulting ImagePlus (e.g. when to call show() on it). --- .../doube/bonej/pqct/Read_Stratec_File.java | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/org/doube/bonej/pqct/Read_Stratec_File.java b/src/org/doube/bonej/pqct/Read_Stratec_File.java index fe378536..6cb9a5af 100644 --- a/src/org/doube/bonej/pqct/Read_Stratec_File.java +++ b/src/org/doube/bonej/pqct/Read_Stratec_File.java @@ -56,6 +56,26 @@ public Read_Stratec_File() { //Constructor //this = null; } + /** + * Opens a Stratec pQCT file + * + * @param path full path to the file + * @return ImagePlus containing the calibrated pQCT image + * @throws IllegalArgumentException if the path is null or the file is not normal + */ + public ImagePlus open(String path) throws IllegalArgumentException { + if (path == null) + throw new IllegalArgumentException("Path cannot be null"); + File theFile = new File(path); + if (!theFile.isFile()) + throw new IllegalArgumentException("Path is not a normal file"); + String directory = theFile.getParent()+"/"; + fileName = theFile.getName(); + read(directory); + fileInfo(); + return this; + } + //Overriding the abstract runnable run method. Apparently plugins run in threads public void run(String arg) { String directory; @@ -71,6 +91,15 @@ public void run(String arg) { } if (fileName==null) return; read(directory); + fileInfo(); + if (arg.isEmpty() && this.getHeight()>0){ + this.show(); + return; + } + if (this.getHeight()<1) return; + } + + private void fileInfo() { FileInfo fi = this.getFileInfo(); fi.pixelWidth = VoxelSize; fi.pixelHeight = VoxelSize; @@ -79,13 +108,8 @@ public void run(String arg) { fi.info = properties; fi.fileType = ij.io.FileInfo.GRAY16_SIGNED; // this.setFileInfo(fi); - if (arg.isEmpty() && this.getHeight()>0){ - this.show(); - return; - } - if (this.getHeight()<1) return; } - + private void read(String directory){ File fileIn = new File(directory+fileName); long fileLength = fileIn.length();