9 DICOM Images

9.5 DICOM example

Some examples of DICOM use can be found in the artisynth.core.demos.dicom package. The model DicomTest loads a partial image of a heart, which is initially downloaded from the ArtiSynth website:

1 package artisynth.demos.dicom;
2
3 import java.awt.Color;
4 import java.io.File;
5 import java.io.IOException;
6
7 import artisynth.core.renderables.DicomViewer;
8 import artisynth.core.workspace.DriverInterface;
9 import artisynth.core.workspace.RootModel;
10 import maspack.fileutil.FileManager;
11 import maspack.util.PathFinder;
12
13 public class DicomTest extends RootModel {
14
15    // Dicom file name and URL from which to load it
16    String dicom_file = "MR-MONO2-8-16x-heart";
17    String dicom_url =
18       "http://www.artisynth.org/files/data/dicom/MR-MONO2-8-16x-heart.gz";
19
20    public void build(String[] args) throws IOException {
21
22       // cache image in a local directory ’data’ beneath Java source
23       String localDir = PathFinder.getSourceRelativePath(
24          this, "data/MONO2_HEART");
25       // create a file manager to get the file and download it if necessary
26       FileManager fileManager = new FileManager(localDir, "gz:"+dicom_url+"!/");
27       fileManager.setConsoleProgressPrinting(true);
28       fileManager.setOptions(FileManager.DOWNLOAD_ZIP); // download zip file first
29
30       // get the file from local directory, downloading first if needed
31       File dicomPath = fileManager.get(dicom_file);
32
33       // create a DicomViewer for the file
34       DicomViewer dcp = new DicomViewer("Heart", dicomPath.getAbsolutePath(),
35          null, /*check subdirectories*/false);
36
37       addRenderable(dcp); // add it to root model’s list of renderable
38    }

Lines 23-28 are responsible for downloading and extracting the sample DICOM zip file. In the end, dicomPath contains a reference to the desired DICOM file on the local system, which is used to create a viewer on line 34. We then add the viewer to the model for display purposes.

To run this example in ArtiSynth, select All demos > dicom > DicomTest from the Models menu. The model should load and initially appear as in Figure 9.3.

Figure 9.3: DICOM viewer image from DicomTest

.