use of org.dcm4che3.data.BulkData in project karnak by OsiriX-Foundation.
the class Profile method applyCleanPixelData.
public void applyCleanPixelData(Attributes dcmCopy, AttributeEditorContext context, ProfileEntity profileEntity) {
Object pix = dcmCopy.getValue(Tag.PixelData);
if ((pix instanceof BulkData || pix instanceof Fragments) && !profileEntity.getMaskEntities().isEmpty() && profiles.stream().anyMatch(p -> p instanceof CleanPixelData)) {
String sopClassUID = dcmCopy.getString(Tag.SOPClassUID);
if (!StringUtil.hasText(sopClassUID)) {
throw new IllegalStateException("DICOM Object does not contain sopClassUID");
}
String scuPattern = sopClassUID + ".";
MaskArea mask = getMask(dcmCopy.getString(Tag.StationName));
// BurnedInAnnotation
if (isCleanPixelAllowedDependingImageType(dcmCopy, sopClassUID, scuPattern) && evaluateConditionCleanPixelData(dcmCopy)) {
context.setMaskArea(mask);
if (mask == null) {
throw new IllegalStateException("Clean pixel is not applied: mask not defined in station name");
}
} else {
context.setMaskArea(null);
}
}
}
use of org.dcm4che3.data.BulkData in project Weasis by nroduit.
the class RawImageIO method readMetaData.
private synchronized DicomMetaData readMetaData() {
DicomMetaData header = HEADER_CACHE.get(this);
if (header != null) {
return header;
}
Attributes dcm = new Attributes(tags.size() + attributes.size());
SpecificCharacterSet cs = attributes.getSpecificCharacterSet();
dcm.setSpecificCharacterSet(cs.toCodes());
DicomMediaUtils.fillAttributes(tags, dcm);
dcm.addAll(attributes);
File file = imageCV.getFile();
BulkData bdl = new BulkData(file.toURI().toString(), FileRawImage.HEADER_LENGTH, (int) file.length() - FileRawImage.HEADER_LENGTH, false);
dcm.setValue(Tag.PixelData, VR.OW, bdl);
header = new DicomMetaData(dcm, UID.ImplicitVRLittleEndian);
HEADER_CACHE.put(this, header);
return header;
}
use of org.dcm4che3.data.BulkData in project dcm4che by dcm4che.
the class StowRS method writeFile.
private void writeFile(String contentLocation, OutputStream out, StowChunk stowChunk) throws Exception {
String bulkdataContentType1 = bulkdataFileContentType.getMediaType();
StowRSBulkdata stowRSBulkdata = contentLocBulkdata.get(contentLocation);
XPEGParser parser = stowRSBulkdata.getParser();
if (bulkdataFileContentType.getBulkdataTypeTag() == Tag.PixelData && tsuid)
bulkdataContentType1 = bulkdataContentType1 + "; transfer-syntax=" + parser.getTransferSyntaxUID();
LOG.info("> Bulkdata Content Type: " + bulkdataContentType1);
writePartHeaders(out, bulkdataContentType1, contentLocation);
int offset = 0;
int length = (int) stowRSBulkdata.getFileLength();
long positionAfterAPPSegments = parser != null ? parser.getPositionAfterAPPSegments() : -1L;
if (noApp && positionAfterAPPSegments != -1L) {
offset = (int) positionAfterAPPSegments;
out.write(-1);
out.write((byte) JPEG.SOI);
}
length -= offset;
out.write(Files.readAllBytes(stowRSBulkdata.getBulkdataFilePath()), offset, length);
stowChunk.setAttributes(stowRSBulkdata.bulkdataFile.length());
}
use of org.dcm4che3.data.BulkData in project dcm4che by dcm4che.
the class PlanarConfig method processFile.
private char processFile(File file) {
try {
Attributes dataset;
WritePlanarConfiguration writePlanarConfiguration = new WritePlanarConfiguration();
try (DicomInputStream is = new DicomInputStream(file)) {
is.setIncludeBulkData(DicomInputStream.IncludeBulkData.URI);
is.setDicomInputHandler(writePlanarConfiguration);
dataset = is.readDataset();
}
VR.Holder vr = new VR.Holder();
Object value = dataset.getValue(Tag.PixelData, vr);
if (value == null) {
skipped++;
return 'p';
}
ColorPMI colorPMI;
try {
colorPMI = ColorPMI.valueOf(dataset.getString(Tag.PhotometricInterpretation));
} catch (IllegalArgumentException e) {
skipped++;
return 'm';
}
if (!(value instanceof BulkData)) {
skipped++;
return 'c';
}
int pc;
try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
pc = planarConfiguration(file, raf, (BulkData) value, dataset, colorPMI);
if (pc == dataset.getInt(Tag.PlanarConfiguration, 0)) {
correct[pc]++;
return CORRECT_CH[pc];
}
if (fix[pc]) {
writePlanarConfiguration.writeTo(raf, pc);
}
}
wrong[pc]++;
if (uids && (fix[pc] || !fix[1 - pc]))
uidslog().println(dataset.getString(Tag.SOPInstanceUID));
return WRONG_CH[pc];
} catch (IOException e) {
System.err.println("Failed to update " + file + ':');
e.printStackTrace(System.err);
failed++;
}
return 'E';
}
use of org.dcm4che3.data.BulkData in project dcm4che by dcm4che.
the class XMLTest method createTestDataset.
private Attributes createTestDataset() {
Attributes dataset = new Attributes();
dataset.setString(Tag.SpecificCharacterSet, VR.CS, "ISO 2022 IR 87");
dataset.setString(Tag.ImageType, VR.CS, "DERIVED", null, "PRIMARY", "", "TEST");
dataset.setNull(Tag.AccessionNumber, VR.SH);
Attributes item = new Attributes(2);
dataset.newSequence(Tag.SourceImageSequence, 1).add(item);
item.setString(Tag.ReferencedSOPClassUID, VR.UI, UID.CTImageStorage);
item.setString(Tag.ReferencedSOPInstanceUID, VR.UI, "1.2.3.4");
dataset.setString(Tag.PatientName, VR.PN, "af^ag=if^ig=pf^pg");
dataset.setBytes("PRIVATE", 0x00090002, VR.OB, new byte[] { 0, 1 });
dataset.setDouble(Tag.FrameTime, VR.DS, 33.0);
dataset.setInt(Tag.SamplesPerPixel, VR.US, 1);
dataset.setInt(Tag.NumberOfFrames, VR.IS, 1);
dataset.setInt(Tag.FrameIncrementPointer, VR.AT, Tag.FrameTime);
dataset.setValue(Tag.OverlayData, VR.OW, new BulkData("someuuid", null, false));
Fragments frags = dataset.newFragments(Tag.PixelData, VR.OB, 2);
frags.add(null);
frags.add(new BulkData(null, "file:/PixelData?offset=1234&length=5678", false));
return dataset;
}
Aggregations