Search in sources :

Example 1 with BulkData

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);
        }
    }
}
Also used : Color(java.awt.Color) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) VR(org.dcm4che3.data.VR) Attributes(org.dcm4che3.data.Attributes) ReplaceNull(org.karnak.backend.model.action.ReplaceNull) LoggerFactory(org.slf4j.LoggerFactory) MarkerFactory(org.slf4j.MarkerFactory) HashMap(java.util.HashMap) StringUtil(org.weasis.core.util.StringUtil) Remove(org.karnak.backend.model.action.Remove) ArrayList(java.util.ArrayList) SecretEntity(org.karnak.backend.data.entity.SecretEntity) Map(java.util.Map) ProfileItem(org.karnak.backend.model.profiles.ProfileItem) ProjectEntity(org.karnak.backend.data.entity.ProjectEntity) BigInteger(java.math.BigInteger) BulkData(org.dcm4che3.data.BulkData) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ActionItem(org.karnak.backend.model.action.ActionItem) ExpressionResult(org.karnak.backend.model.expression.ExpressionResult) ExprCondition(org.karnak.backend.model.expression.ExprCondition) Shape(java.awt.Shape) DefacingUtil.isAxial(org.karnak.backend.dicom.DefacingUtil.isAxial) HMAC(org.karnak.backend.model.profilepipe.HMAC) Logger(org.slf4j.Logger) ActionTags(org.karnak.backend.model.profiles.ActionTags) Set(java.util.Set) HashContext(org.karnak.backend.model.profilepipe.HashContext) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData) Collectors(java.util.stream.Collectors) TagUtils(org.dcm4che3.util.TagUtils) List(java.util.List) ProfileItemType(org.karnak.backend.enums.ProfileItemType) Tag(org.dcm4che3.data.Tag) Marker(org.slf4j.Marker) MDC(org.slf4j.MDC) Sequence(org.dcm4che3.data.Sequence) Defacer(org.karnak.backend.dicom.Defacer) Fragments(org.dcm4che3.data.Fragments) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) DefacingUtil.isCT(org.karnak.backend.dicom.DefacingUtil.isCT) Comparator(java.util.Comparator) Collections(java.util.Collections) Defacing(org.karnak.backend.model.profiles.Defacing) MaskArea(org.dcm4che3.img.op.MaskArea) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData) Fragments(org.dcm4che3.data.Fragments) BulkData(org.dcm4che3.data.BulkData) MaskArea(org.dcm4che3.img.op.MaskArea)

Example 2 with BulkData

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;
}
Also used : SpecificCharacterSet(org.dcm4che3.data.SpecificCharacterSet) Attributes(org.dcm4che3.data.Attributes) BulkData(org.dcm4che3.data.BulkData) DicomMetaData(org.dcm4che3.img.DicomMetaData) File(java.io.File)

Example 3 with BulkData

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());
}
Also used : XPEGParser(org.dcm4che3.imageio.codec.XPEGParser)

Example 4 with BulkData

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';
}
Also used : DicomInputStream(org.dcm4che3.io.DicomInputStream)

Example 5 with BulkData

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;
}
Also used : Attributes(org.dcm4che3.data.Attributes) Fragments(org.dcm4che3.data.Fragments) BulkData(org.dcm4che3.data.BulkData)

Aggregations

BulkData (org.dcm4che3.data.BulkData)17 Attributes (org.dcm4che3.data.Attributes)10 Fragments (org.dcm4che3.data.Fragments)9 IncludeBulkData (org.dcm4che3.io.DicomInputStream.IncludeBulkData)5 Sequence (org.dcm4che3.data.Sequence)3 VR (org.dcm4che3.data.VR)3 DicomInputStream (org.dcm4che3.io.DicomInputStream)3 File (java.io.File)2 IOException (java.io.IOException)2 Value (org.dcm4che3.data.Value)2 ImageDescriptor (org.dcm4che3.imageio.codec.ImageDescriptor)2 Test (org.junit.Test)2 Color (java.awt.Color)1 Shape (java.awt.Shape)1 StringWriter (java.io.StringWriter)1 BigInteger (java.math.BigInteger)1 SeekableByteChannel (java.nio.channels.SeekableByteChannel)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1