Skip to content

Commit

Permalink
Merge pull request #5 from mdoube/testing
Browse files Browse the repository at this point in the history
Add opener API to Read_Stratec_File
  • Loading branch information
tjrantal committed Oct 25, 2011
2 parents 79f523c + cc1d97d commit 4ab43c6
Showing 1 changed file with 53 additions and 31 deletions.
84 changes: 53 additions & 31 deletions src/org/doube/bonej/pqct/Read_Stratec_File.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,51 @@
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 String fileName;
private String properties;

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;
Expand All @@ -73,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;
Expand All @@ -81,14 +108,9 @@ 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;
}
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));
Expand Down Expand Up @@ -135,7 +157,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));
Expand Down Expand Up @@ -188,7 +210,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",
Expand Down

0 comments on commit 4ab43c6

Please sign in to comment.