📄 dicomfile.java
字号:
Part10vr = false;
}else if(TransferSyntax.matches("1.2.840.10008.1.2.2\\p{ASCII}??")){
if (debug_level > 3) System.out.println("Explicit VR Big Endian");
Part10Endian = false;
Part10vr = true;
}else{
if (debug_level > 3) System.out.println("Explicit VR Big Endian:");
Part10Endian = true;
Part10vr = true;
}
}
}
if(!dicomPart10 && tag.equals("(0000,0000)") && length == 0){
//僾儕僼傿僋僗暥傪撉傒旘偽偟丄0002僞僌偺帪柧帵揑VRLtlEndian偵偡傞
din.skip(124); //128+4偐傜1夞撉傒崬傫偩暘傪堷偔
if (debug_level > 3) System.out.println("skip");
isLtlEndian = true;
vrType = true;
dicomPart10 = Part10flag = true;
if (debug_level > 3) System.out.println("part10 ");
}
//抣弌椡
if (debug_level > 5){
StringBuffer buffer=new StringBuffer();
for(int i=0; i<dicomData.getValue(tag).length; i++){
String tmp=Integer.toHexString(dicomData.getValue(tag)[i] & 0xff);
if(tmp.length()==1){buffer.append('0').append(tmp);
}else{
buffer.append(tmp);
}
}
System.out.println("Value = " + buffer);
}
} // while 偙偙傑偱丅
//DicomPart10梡flag夝彍
if(dicomPart10){
Part10flag = dicomPart10 = false;
isLtlEndian = Part10Endian2;
vrType = Part10vr2;
}
din.close();
inS.close();
}
catch(EOFException eof){
System.out.println("DicomFile.EOFException: " + eof.getMessage() );
}
catch(IOException ioe){
System.out.println("DicomFile.IOException: " + ioe.getMessage() );
}
catch(Exception e){
System.out.println("DicomFile.Exception: " + e.getMessage() );
}
// 僾儔僀僶僔乕懳嶔偺僐乕僪
// (0010,0010)偺僨乕僞傪
// Takahiro Katoji -> T*k*h*r* *a*o*i
// 偺傛偆側乽*乿崿偠傝偺暥帤楍偵曄姺偡傞
if(patientPrivacy) {
String patientName;
// 尰嵼DicomData偵僙僢僩偝傟偰偄傞姵幰柤傪庢摼偡傞
patientName = dicomData.getAnalyzedValue("(0010,0010)");
StringBuffer patientBuf = new StringBuffer(patientName);
// 姵幰柤偺婏悢斣栚偺暥帤傪乽*乿偵曄姺偡傞
for(int i=0; i < patientName.length(); i++) {
if(i % 2 == 1) patientBuf.setCharAt(i, '*');
}
// 曄姺屻偺暥帤楍傪DicomData偵栠偡
dicomData.setAnalyzedValue("(0010,0010)", patientBuf.toString());
}
// DicomData傪曉偟偰廔椆
return dicomData;
}
// 2bytes撉傫偱Int偵曄姺
private int readInt2(byte[] argtmp){
int tmp;
if(isLtlEndian) {
tmp = ((0x000000ff & argtmp[1]) << 8 | (0x000000ff & argtmp[0]));
} else {
tmp = ((0x000000ff & argtmp[0]) << 8 | (0x000000ff & argtmp[1]));
}
return tmp;
}
// 4bytes撉傫偱Int偵曄姺
private int readInt4(byte[] argtmp){
int tmp;
if(isLtlEndian) {
tmp = ((0x000000ff & argtmp[3]) << 24 | (0x000000ff & argtmp[2]) << 16
| (0x000000ff & argtmp[1]) << 8 | (0x000000ff & argtmp[0]));
} else {
tmp = ((0x000000ff & argtmp[0]) << 24 | (0x000000ff & argtmp[1]) << 16
| (0x000000ff & argtmp[2]) << 8 | (0x000000ff & argtmp[3]));
}
return tmp;
}
// VR傪夝愅偟僨乕僞梫慺偺抣傪揔愗側彂幃偵曄姺偡傞丅
private void analyzer(String currentTag, String currentVR) {
if(currentVR==null){
// VR偑柍偄応崌
dicomData.setAnalyzedValue(currentTag, "Not contain VR.");
}
else if(dicomData.getValueLength(currentTag)==0){
// 戝偒偝0偼柍帇
dicomData.setAnalyzedValue(currentTag, "");
}
else if(currentVR.equals("PN") | currentVR.equals("LO")
| currentVR.equals("SH") | currentVR.equals("LT")
| currentVR.equals("ST") | currentVR.equals("UI")
| currentVR.equals("DS") | currentVR.equals("CS")
| currentVR.equals("IS") | currentVR.equals("AS")){
// 晛捠偺暥帤楍
for(int j=0; j<dicomData.getValueLength(currentTag); j++)
if((dicomData.getValue(currentTag))[j] == 0)
(dicomData.getValue(currentTag))[j] = 20;
dicomData.setAnalyzedValue(currentTag, new String(dicomData.getValue(currentTag)));
}
else if(currentVR.equals("SS")){
int tmp;
// 16bit晞崌晅2恑悢
if(isLtlEndian){
tmp = (((int)(dicomData.getValue(currentTag))[1] & 0x000000ff) << 8)
| ((int)(dicomData.getValue(currentTag))[0] & 0x000000ff);
} else {
tmp = (((int)(dicomData.getValue(currentTag))[0] & 0x000000ff) << 8)
| ((int)(dicomData.getValue(currentTag))[1] & 0x000000ff);
}
if((tmp & 0x00008000)==0x00008000) // 晞崌張棟
tmp |= 0xffff0000;
dicomData.setAnalyzedValue(currentTag, Integer.toString(tmp));
}
else if(currentVR.equals("US")){
int tmp;
// 16bit晞崌柍2恑悢
if(isLtlEndian){
tmp = (((int)(dicomData.getValue(currentTag))[1] & 0x000000ff) << 8)
| ((int)(dicomData.getValue(currentTag))[0] & 0x000000ff);
} else {
tmp = (((int)(dicomData.getValue(currentTag))[0] & 0x000000ff) << 8)
| ((int)(dicomData.getValue(currentTag))[1] & 0x000000ff);
}
dicomData.setAnalyzedValue(currentTag, Integer.toString(tmp));
}
else if(currentVR.equals("UL")){
int tmp;
// 32bit晞崌柍2恑悢
if (isLtlEndian){
tmp = (((int)(dicomData.getValue(currentTag))[3] & 0x000000ff) << 24)
| (((int)(dicomData.getValue(currentTag))[2] & 0x000000ff) << 16)
| (((int)(dicomData.getValue(currentTag))[1] & 0x000000ff) << 8)
| ((int)(dicomData.getValue(currentTag))[0] & 0x000000ff);
} else {
tmp = (((int)(dicomData.getValue(currentTag))[0] & 0x000000ff) << 24)
| (((int)(dicomData.getValue(currentTag))[1] & 0x000000ff) << 16)
| (((int)(dicomData.getValue(currentTag))[2] & 0x000000ff) << 8)
| ((int)(dicomData.getValue(currentTag))[3] & 0x000000ff);
}
dicomData.setAnalyzedValue(currentTag, Integer.toString(tmp));
}
else if(currentVR.equals("TM")){
// 帪娫 hh:mm:ss.frac
dicomData.setAnalyzedValue(currentTag, new String(dicomData.getValue(currentTag)));
StringBuffer buffer = new StringBuffer(dicomData.getAnalyzedValue(currentTag));
buffer.insert(2, ":");
buffer.insert(5, ":");
dicomData.setAnalyzedValue(currentTag, buffer.toString());
}
else if(currentVR.equals("DA")){
// 擔晅 yyyy.mm.dd
dicomData.setAnalyzedValue(currentTag, new String(dicomData.getValue(currentTag)));
// 8bytes偟偐側偄偲偒偼,乽-乿傪捛壛偡傞
if(dicomData.getValueLength(currentTag)==8){
StringBuffer buffer = new StringBuffer(dicomData.getAnalyzedValue(currentTag));
buffer.insert(4, "-");
buffer.insert(7, "-");
dicomData.setAnalyzedValue(currentTag, buffer.toString());
}else if(dicomData.getValueLength(currentTag) == 10){
// 10bytes偺偲偒偼,乽.乿乽-乿偵曄峏偡傞
StringTokenizer st = new StringTokenizer(dicomData.getAnalyzedValue(currentTag), ".");
String temp = st.nextToken();
temp += "-" + st.nextToken();
temp += "-" + st.nextToken();
dicomData.setAnalyzedValue(currentTag, temp);
}
}
else
// 僒億乕僩偟偰偄側偄僞僌
dicomData.setAnalyzedValue(currentTag, "Unknown VR");
// 僨僶僢僌梡
if (debug_level > 3) System.out.println("AnalyzedValue :" + dicomData.getAnalyzedValue(currentTag));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -