Search in sources :

Example 1 with VR

use of org.dcm4che3.data.VR in project karnak by OsiriX-Foundation.

the class Profile method applyAction.

public void applyAction(Attributes dcm, Attributes dcmCopy, HMAC hmac, ProfileItem profilePassedInSequence, ActionItem actionPassedInSequence, AttributeEditorContext context) {
    for (int tag : dcm.tags()) {
        VR vr = dcm.getVR(tag);
        final ExprCondition exprCondition = new ExprCondition(dcmCopy);
        ActionItem currentAction = null;
        ProfileItem currentProfile = null;
        for (ProfileItem profileEntity : profiles.stream().filter(p -> !(p instanceof CleanPixelData)).collect(Collectors.toList())) {
            currentProfile = profileEntity;
            if (profileEntity.getCondition() == null || profileEntity.getCodeName().equals(ProfileItemType.DEFACING.getClassAlias()) || profileEntity.getCodeName().equals(ProfileItemType.CLEAN_PIXEL_DATA.getClassAlias())) {
                currentAction = profileEntity.getAction(dcm, dcmCopy, tag, hmac);
            } else {
                boolean conditionIsOk = (Boolean) ExpressionResult.get(profileEntity.getCondition(), exprCondition, Boolean.class);
                if (conditionIsOk) {
                    currentAction = profileEntity.getAction(dcm, dcmCopy, tag, hmac);
                }
            }
            if (currentAction != null) {
                break;
            }
            if (profileEntity.equals(profilePassedInSequence)) {
                currentAction = actionPassedInSequence;
                break;
            }
        }
        if (!(currentAction instanceof Remove) && !(currentAction instanceof ReplaceNull) && vr == VR.SQ) {
            final ProfileItem finalCurrentProfile = currentProfile;
            final ActionItem finalCurrentAction = currentAction;
            Sequence seq = dcm.getSequence(tag);
            if (seq != null) {
                for (Attributes d : seq) {
                    applyAction(d, dcmCopy, hmac, finalCurrentProfile, finalCurrentAction, context);
                }
            }
        } else {
            if (currentAction != null) {
                try {
                    currentAction.execute(dcm, tag, hmac);
                } catch (final Exception e) {
                    LOGGER.error("Cannot execute the currentAction {} for tag: {}", currentAction, TagUtils.toString(tag), e);
                }
            }
        }
    }
}
Also used : ProfileItem(org.karnak.backend.model.profiles.ProfileItem) 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) ActionItem(org.karnak.backend.model.action.ActionItem) Attributes(org.dcm4che3.data.Attributes) Remove(org.karnak.backend.model.action.Remove) Sequence(org.dcm4che3.data.Sequence) ReplaceNull(org.karnak.backend.model.action.ReplaceNull) ExprCondition(org.karnak.backend.model.expression.ExprCondition) CleanPixelData(org.karnak.backend.model.profiles.CleanPixelData) VR(org.dcm4che3.data.VR)

Example 2 with VR

use of org.dcm4che3.data.VR 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 3 with VR

use of org.dcm4che3.data.VR in project dcm4che by dcm4che.

the class SAXWriter method writeValues.

private void writeValues(VR vr, Object val, boolean bigEndian, SpecificCharacterSet cs) throws SAXException {
    if (vr.isStringType())
        val = vr.toStrings(val, bigEndian, cs);
    int vm = vr.vmOf(val);
    for (int i = 0; i < vm; i++) {
        String s = vr.toString(val, bigEndian, i, null);
        addAttribute("number", Integer.toString(i + 1));
        if (vr == VR.PN) {
            PersonName pn = new PersonName(s, true);
            startElement("PersonName");
            writePNGroup("Alphabetic", pn, PersonName.Group.Alphabetic);
            writePNGroup("Ideographic", pn, PersonName.Group.Ideographic);
            writePNGroup("Phonetic", pn, PersonName.Group.Phonetic);
            endElement("PersonName");
        } else {
            startElement("Value");
            if (s != null)
                writeText(s);
            endElement("Value");
        }
    }
}
Also used : PersonName(org.dcm4che3.data.PersonName)

Example 4 with VR

use of org.dcm4che3.data.VR in project dcm4che by dcm4che.

the class DicomFileDetector method isEVR.

private static boolean isEVR(byte[] b134, int rlen) {
    int tagLE = ByteUtils.bytesToTagLE(b134, 0);
    int tagBE = ByteUtils.bytesToTagBE(b134, 0);
    VR vr = VR.valueOf(ByteUtils.bytesToVR(b134, 4));
    return vr != null && vr == ElementDictionary.getStandardElementDictionary().vrOf(tagLE >= 0 && tagLE < tagBE ? tagLE : tagBE);
}
Also used : VR(org.dcm4che3.data.VR)

Example 5 with VR

use of org.dcm4che3.data.VR in project dcm4che by dcm4che.

the class JSONWriter method readValue.

@Override
public void readValue(DicomInputStream dis, Attributes attrs) throws IOException {
    int tag = dis.tag();
    VR vr = dis.vr();
    int len = dis.length();
    if (TagUtils.isGroupLength(tag)) {
        dis.readValue(dis, attrs);
    } else if (dis.isExcludeBulkData()) {
        dis.readValue(dis, attrs);
    } else {
        gen.writeStartObject(TagUtils.toHexString(tag));
        gen.write("vr", vr.name());
        if (vr == VR.SQ || len == -1) {
            hasItems.addLast(false);
            dis.readValue(dis, attrs);
            if (hasItems.removeLast())
                gen.writeEnd();
        } else if (len > 0) {
            if (dis.isIncludeBulkDataURI()) {
                writeBulkData(dis.createBulkData(dis));
            } else {
                byte[] b = dis.readValue();
                if (tag == Tag.TransferSyntaxUID || tag == Tag.SpecificCharacterSet || TagUtils.isPrivateCreator(tag))
                    attrs.setBytes(tag, vr, b);
                writeValue(vr, b, dis.bigEndian(), attrs.getSpecificCharacterSet(vr), false);
            }
        }
        gen.writeEnd();
    }
}
Also used : VR(org.dcm4che3.data.VR)

Aggregations

VR (org.dcm4che3.data.VR)9 Attributes (org.dcm4che3.data.Attributes)3 IOException (java.io.IOException)2 BulkData (org.dcm4che3.data.BulkData)2 DicomInputStream (org.dcm4che3.io.DicomInputStream)2 Color (java.awt.Color)1 Shape (java.awt.Shape)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BigInteger (java.math.BigInteger)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1