public VR vr() { return e.vr(); }
private void writeItem(DicomElement a, int index) throws SAXException, IOException { if (file != null) file = new File(file, Integer.toString(index+1)); if (a.vr() == VR.SQ) { writeContent(a.getDicomObject(index), TAG_ITEM); } else { final byte[] data = a.getFragment(index); writeFragment(a.vr(), data, a.bigEndian(), fpath(a.tag(), a.vr(), data.length)); } if (file != null) file = file.getParentFile(); }
private void onEndItem() throws SAXException { switch (state) { case EXPECT_ELM: attrs = attrs.getParent(); break; case EXPECT_FRAG: DicomElement sq = sqStack.peek(); byte[] data = getValue(sq.vr(), null); sq.addFragment(data != null ? data : EMPTY_VALUE); sb.setLength(0); out.reset(); break; default: throw new IllegalStateException("state:" + state); } state = State.EXPECT_NEXT_ITEM; }
public DicomElement get(int tag, VR vr) { DicomElement e = get(tag); if (e == null || e.vr() == vr) { return e; } if (e.vr() != VR.UN) { throw new UnsupportedOperationException("Update VR from " + e.vr() + " to " + vr + " not supported"); } if (vr != VR.SQ) { return putBytes(tag, vr, e.getBytes()); } DicomElement sq = putSequence(tag); if (!e.isEmpty()) { try { byte[] b = e.getBytes(); DicomInputStream in = new DicomInputStream( new ByteArrayInputStream(b), UID.ImplicitVRLittleEndian); in.readItems(sq, b.length); } catch (IOException e1) { throw new RuntimeException("Failed to parse value of " + e + " as sequence of items", e1); } } return sq; } }
private void onStartItem(String offStr, String src) { this.src = src; if (state != State.EXPECT_VAL_OR_FIRST_ITEM && state != State.EXPECT_NEXT_ITEM) { throw new IllegalStateException("state:" + state); } if (state == State.EXPECT_VAL_OR_FIRST_ITEM) { sqStack.push(vr == VR.SQ ? attrs.putSequence(tag) : attrs .putFragments(tag, vr, false)); } DicomElement sq = sqStack.peek(); if (sq.vr() == VR.SQ) { DicomObject parent = attrs; attrs = new BasicDicomObject(); ((BasicDicomObject) attrs).setParent(parent); if (offStr != null) { attrs.setItemOffset(Long.parseLong(offStr)); } sq.addDicomObject(attrs); state = State.EXPECT_ELM; } else { sb.setLength(0); state = State.EXPECT_FRAG; } }
public boolean visit(DicomElement attr) { if (attr.vr() == VR.SQ && attr.hasItems()) { for (int i = 0, n = attr.countItems(); i < n; ++i) { attr.getDicomObject(i).cacheGet(cacheGet); } } return true; } });
public boolean visit(DicomElement attr) { if (attr.vr() == VR.SQ && attr.hasItems()) { for (int i = 0, n = attr.countItems(); i < n; ++i) { attr.getDicomObject(i).cachePut(cachePut); } } return true; } });
private static Object[] writeStringValues(DicomElement elem, SpecificCharacterSet cs) { String[] ss = elem.getStrings(cs, cache); Object[] ret = new Object[ss.length]; VR vr = elem.vr(); for(int i = 0; i< ss.length ;i++){ String s = ss[i]; if (s == null || s.isEmpty()) ret[i] = null; else if( vr == VR.DS){ ret[i] = parseDS(s); }else if(vr == VR.IS){ ret[i] = parseIS(s); }else if(vr == VR.PN){ ret[i] = writePersonName(s); }else{ ret[i] = s; } } return ret; }
@Override public DicomElement next() { DicomElement attr = super.next(); if (attr.vr() == VR.SQ && attr.hasItems()) { return attr.filterItems(filter.getNestedDicomObject(attr.tag())); } return attr; }
/** Gets a pixel value from the given field - the field can be a regular integer * or it can be ob data. * @param ds * @param tag * @return */ public static Integer getIntPixelValue(DicomObject ds, int tag, boolean signed, int stored) { DicomElement de = ds.get(tag); if( de==null ) return null; VR vr = de.vr(); if( vr==VR.OB || vr==VR.OW ) { int ret = ByteUtils.bytesLE2ushort(de.getBytes(),0); if( signed ) { if( (ret & (1 << (stored-1))) !=0 ) { int andmask = (1 << stored) - 1; int ormask = ~andmask; ret |= ormask; } } return ret; } return de.getInt(true); }
private void readItemValue() throws IOException, DicomCodingException { DicomElement sq = sqStack.get(sqStack.size() - 1); if (vallen == -1) { if (sq.vr() == VR.UN) { DicomElement tmp = attrs.putSequence(sq.tag()); for (int i = 0, n = sq.countItems(); i < n; ++i) { if (sq.vr() != VR.SQ) { throw new DicomCodingException(TagUtils.toString(tag) + " " + sq.vr() + " contains item with unknown length."); if (sq.vr() == VR.SQ) { BasicDicomObject item = new BasicDicomObject(); item.setParent(attrs);
private void transcodeItem(DicomInputStream in) throws IOException { final DicomElement sq = in.sq(); final VR sqvr = sq.vr(); final int vallen = in.valueLength(); if (vallen == -1 || sqvr == VR.SQ) { out.writeHeader(Tag.Item, null, -1); in.readValue(in); out.writeHeader(Tag.ItemDelimitationItem, null, 0); } else { out.writeHeader(Tag.Item, null, in.valueLength()); transcodeValue(in, sqvr); } }
private void transcodeItem(DicomInputStream in) throws SAXException, IOException { final DicomElement sq = in.sq(); final int itemLen = in.valueLength(); final VR sqvr = sq.vr(); final int index = sq.countItems(); if (file != null) file = new File(file, Integer.toString(index+1)); final String fpath = fpath(sq.tag(), sqvr, itemLen); startItemElement(in.tagPosition(), itemLen, fpath); in.readValue(in); if (sq.hasFragments() && index < sq.countItems()) { byte[] data = sq.getFragment(index); if (fpath != null) { writeToFile(data); } else { final boolean bigEndian = in.getTransferSyntax().bigEndian(); sqvr.formatXMLValue(data, bigEndian, null, cbuf, ch); } sq.setFragment(index, EMPTY_BYTES); // allow gc to release byte[] } endItemElement(); if (file != null) file = file.getParentFile(); }
public void add(DicomElement a) { if (a.hasItems()) { final int n = a.countItems(); DicomElement t; if (a.vr() == VR.SQ) { t = putSequence(a.tag(), n); for (int i = 0; i < n; i++) { DicomObject srcItem = a.getDicomObject(i); BasicDicomObject item = new BasicDicomObject(srcItem.size()); item.setParent(this); srcItem.copyTo(item); t.addDicomObject(item); } } else { t = putFragments(a.tag(), a.vr(), a.bigEndian(), n); for (int i = 0; i < n; i++) { t.addFragment(a.getFragment(i)); } } a = t; } addInternal(a); }
private void writeElement(DicomObject attrs, DicomElement a) throws SAXException, IOException { VR vr = a.vr(); final int tag = a.tag(); if (file != null) file = new File(file, StringUtils.intToHex(tag)); String fpath = fpath(tag, vr, a.length()); startAttributeElement(tag, vr, a.length(), fpath, attrs); if (a.hasItems()) { for (int i = 0, n = a.countItems(); i < n; ++i) { writeItem(a, i); } } else { if (fpath != null) { writeToFile(a.getBytes()); } else { vr.formatXMLValue(a.getBytes(), a.bigEndian(), attrs.getSpecificCharacterSet(), cbuf, ch); } } endAttributeElement(); if (file != null) file = file.getParentFile(); }
public static Object toObject(Path parentPath, DicomElement elem, SpecificCharacterSet cs) { VR vr = elem.vr(); Object ret = null;
final VR vr = a.vr(); int len = a.length(); if (vr == VR.SQ) {
public boolean visit(DicomElement attr) { int tag = attr.tag(); VR vr = attr.vr(); if (!TagUtils.isPrivateDataElement(tag) || (!resolveDestinationPrivateTags && TagUtils.isPrivateCreatorDataElement(tag))) dest.add(attr);
return true; // Missing DicomElement (Value) match always final VR vr = test.vr(); if (vr instanceof VR.Fragment) return true; // ignore OB,OW,OF,UN filter attrs