Thursday, 5 September 2013

DICOM Tag editing using dcm4che

dcm4che is a collection of open source applications and utilities for the healthcare enterprise. These applications have been developed in the Java programming language for performance and portability, supporting deployment on JDK 1.4 and up.
At the core of the dcm4che project is a robust implementation of the DICOM standard. The dcm4che-1.x DICOM toolkit is used in many production applications across the world, while the current (2.x) version of the toolkit has been re-architected for high performance and flexibility.
Also contained within the dcm4che project is dcm4chee (the extra ‘e’ stands for ‘enterprise’). dcm4chee is an Image Manager/Image Archive (according to IHE). The application contains the DICOM, HL7 services and interfaces that are required to provide storage, retrieval, and workflow to a healthcare environment. dcm4chee is pre-packaged and deployed within the JBoss application server. By taking advantage of many JBoss features (JMS, EJB, Servlet Engine, etc.), and assuming the role of several IHE actors for the sake of interoperability, the application provides many robust and scalable services:
Following jar files are needed for this activity
    dcm4che.jar
    dcm4che-core-2.0.21.jar
    log4j-1.2.13.jar
    slf4j-api-1.5.0.jar
    slf4j-log4j12-1.5.0.jar
    package dicomeditor;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import org.dcm4che2.data.BasicDicomObject;
    import org.dcm4che2.data.DicomObject;
    import org.dcm4che2.data.Tag;
    import org.dcm4che2.data.VR;
    import org.dcm4che2.io.DicomInputStream;
    import org.dcm4che2.io.DicomOutputStream;
    /**
     *
     * @author awaiswaheed
     */
    public class DicomEditor {
        public void UpdateTags() {
            String sourceFolder = "D:\\WRONGTAGS";
            String destinationFolder = "D:\\CRRTAGS";
            //First Delete Temp Folder Files before copy images there
            File[] tempImages = new File(destinationFolder).listFiles();
            for (int j = 0; j < tempImages.length; j++) {
                tempImages[j].delete();
            }
            //now get all files in tag folder
            File[] allFiles = new File(sourceFolder).listFiles();
            DicomObject dcmObj = new BasicDicomObject();
            DicomInputStream din = null;
            for (int i = 0; i < allFiles.length; i++) {
                System.out.println("Current Image in Progress = " + (i + 1)
                        + " out of = " + allFiles.length);
                try {
                    din = new DicomInputStream(allFiles[i]);
                    din.readDicomObject(dcmObj, -1);
                    //System.out.println(" Tag.PatientID  *******************   " + Tag.PatientID);
                    //dcmObj.putString(1048608, VR.LO, "1234");
                    dcmObj.putString(Tag.PatientName, VR.LO, "XYZPatientName");
                    dcmObj.putString(Tag.PatientBirthDate, VR.DA, "19690101");
                    dcmObj.putString(Tag.PatientAge, VR.AS, "060Y");
                    dcmObj.putString(Tag.Modality, VR.CS, "NM");
                    dcmObj.putString(Tag.AccessionNumber, VR.SH, "1213456");
                    this.writeFile(dcmObj, destinationFolder, "\\" + allFiles[i].getName());
                    din.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } //Loop
            //get all files from tag file and delete them
        }
        public void writeFile(DicomObject obj, String copyServer, String fileName) {
            File f = new File(copyServer + fileName);
            FileOutputStream fos;
            try {
                fos = new FileOutputStream(f);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return;
            }
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            DicomOutputStream dos = new DicomOutputStream(bos);
            try {
                dos.writeDicomFile(obj);
            } catch (IOException e) {
                e.printStackTrace();
                return;
            } finally {
                try {
                    dos.close();
                } catch (IOException ignore) {
                }
            }
        }
        public static void main(String[] args) {
            DicomEditor dcmEdit = new DicomEditor();
            dcmEdit.UpdateTags();
        }
    }

Wednesday, 4 September 2013

JavaFX 2 Circle Path For Animation



package arcdemo;

import javafx.animation.PathTransition;
import javafx.animation.PathTransition.OrientationType;
import javafx.animation.PathTransitionBuilder;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.ArcTo;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.PathBuilder;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 *
 * @author Jay.Thakkar
 */
public class ArcDemo extends Application {

    private PathTransition pathTransitionEllipse;
    private PathTransition pathTransitionCircle;

    private void init(Stage primaryStage) {
        Group root = new Group();
        primaryStage.setResizable(false);
        primaryStage.setScene(new Scene(root, 600, 460));

        // Ellipse path example
        Rectangle rect = new Rectangle(0, 0, 40, 40);
        rect.setArcHeight(10);
        rect.setArcWidth(10);
        rect.setFill(Color.ORANGE);
        root.getChildren().add(rect);

        Path path = createEllipsePath(200, 200, 50, 100, 45);
        root.getChildren().add(path);

        pathTransitionEllipse = PathTransitionBuilder.create()
                .duration(Duration.seconds(4))
                .path(path)
                .node(rect)
                .orientation(OrientationType.ORTHOGONAL_TO_TANGENT)
                .cycleCount(Timeline.INDEFINITE)
                .autoReverse(false)
                .build();


        // Cirle path example

        Rectangle rect2 = new Rectangle(0, 0, 20, 20);
        rect2.setArcHeight(10);
        rect2.setArcWidth(10);
        rect2.setFill(Color.GREEN);
        root.getChildren().add(rect2);

        Path path2 = createEllipsePath(400, 200, 150, 150, 0);
        root.getChildren().add(path2);

        pathTransitionCircle = PathTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .path(path2)
                .node(rect2)
                .orientation(OrientationType.ORTHOGONAL_TO_TANGENT)
                .cycleCount(Timeline.INDEFINITE)
                .autoReverse(false)
                .build();
    }

    private Path createEllipsePath(double centerX, double centerY, double radiusX, double radiusY, double rotate) {
        ArcTo arcTo = new ArcTo();
        arcTo.setX(centerX - radiusX + 1); // to simulate a full 360 degree celcius circle.
        arcTo.setY(centerY - radiusY);
        arcTo.setSweepFlag(false);
        arcTo.setLargeArcFlag(true);
        arcTo.setRadiusX(radiusX);
        arcTo.setRadiusY(radiusY);
        arcTo.setXAxisRotation(rotate);

        Path path = PathBuilder.create()
                .elements(
                new MoveTo(centerX - radiusX, centerY - radiusY),
                arcTo,
                new ClosePath()) // close 1 px gap.
                .build();
        path.setStroke(Color.DODGERBLUE);
        path.getStrokeDashArray().setAll(5d, 5d);
        return path;
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        init(primaryStage);
        primaryStage.show();
        pathTransitionEllipse.play();
        pathTransitionCircle.play();
    }

    public static void main(String[] args) {
        launch(args);
    }
}