File: PresentationStateOverlayObject.java

package info (click to toggle)
dicomscope 3.6.0-28
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,256 kB
  • sloc: java: 22,911; cpp: 5,957; sh: 270; makefile: 45
file content (194 lines) | stat: -rw-r--r-- 6,131 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 *
 *  Copyright (C) 1999, Institute for MicroTherapy
 *
 *  This software and supporting documentation were developed by
 *
 *    University of Witten/Herdecke
 *    Department of Radiology and MicroTherapy
 *    Institute for MicroTherapy
 *    Medical computer science
 *    
 *    Universitaetsstrasse 142
 *    44799 Bochum, Germany
 *    
 *    http://www.microtherapy.de/go/cs
 *    mailto:computer.science@microtherapy.de
 *
 *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND THE INSTITUTE MAKES  NO 
 *  WARRANTY REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY
 *  OR FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES 
 *  OR ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY 
 *  AND PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
 *
 *  Author :      $Author: kleber $
 *  Last update : $Date: 2001/06/06 10:32:30 $
 *  Revision :    $Revision: 1.1.1.1 $
 *  State:        $State: Exp $
*/

package viewer.presentation;

import J2Ci.*;
import main.*;

import java.awt.*;
import java.util.*;
import java.awt.geom.*;
import java.awt.image.*;

/**
 * This class manages the overlay data of one overlay. The data 
 * structure is encapsulate in the jDVPrStateParam_GetOverlayData.
 * <br>
 * The handling of the overlays is inconsistent with the handling of the
 * annotations. First the overlays will be rotated and flipped in the interface, 
 * the annoations not. Therefore they need an other transformation. Secondly the 
 * overlays have less functionality than the annotations. Especially this 
 * programm can only show overlays, if exist. This programm can not create overlays.
 *
 * 
 * @author Klaus Kleber
 * @since 30.04.1999
 * @see J2Ci.jDVPrStateParam_GetOverlayData
 * @see PresentationStateOverlayObject
 */
public  class PresentationStateOverlayObject 
{
    
    /**
     * Contains the index layer of the overlay.
     * 
     * @since 30.04.1999
     */
   int layerIndex;
    
    /**
     * Contains the index of the overlay in the layer with the index layerIndex.
     * 
     * @since 30.04.1999
     */
   int index;
    /**
     * Contains data structure of the presentation state in the c++ interface.
     * 
     * @since 30.04.1999
     * @see J2Ci.jDVPresentationState
     */
   public jDVPresentationState ps;
   
    /**
     * Contains data structure of the overlay in the c++ interface.
     * 
     * @since 30.04.1999
     * @see J2Ci.jDVPrStateParam_GetOverlayData
     */
   jDVPrStateParam_GetOverlayData overlayData;
    
    /**
     * Contains the number of bits used for printing the overlay
     */
    public int bits;
    
    /**
     * Contains the geometric representation of the overlay.
     * 
     * @since 30.04.1999
     */
   BufferedImage overlayImage;
    
    /**
     * Constructs a new object form the specified parameters.
     * 
     * @param ps Contains the current jDVPresentationState
     * @param layerIndex Contains the layer index of the overlay
     * @param imageIndex Contains the index of the overlay in the specified layer.
     * @since 30.04.1999
     */
   public PresentationStateOverlayObject(jDVPresentationState ps, int layerIndex, int imageIndex, int bits)
   {
        this.ps = ps;
        this.bits = bits;
        this.layerIndex = layerIndex;
        this.index = imageIndex;
        getData();
   }
    
    /**
     * Draws the overlay in the specified Graphics2D context.
     * 
     * @param g2 Contains the Graphics2D object
     * @param aff Contains applying transformations
     * @param imageIndex Contains the index of the overlay in the specified layer.
     * @since 30.04.1999
     */
    public void draw(Graphics2D g2, AffineTransform aff)
    {
        //System.out.println("Aff: "+ aff);
        g2.setTransform(aff);
        g2.drawImage(overlayImage,overlayData.left,overlayData.top ,null);
        //g2.drawImage(overlayImage, new AffineTransform(1f,0f,0f,1f,overlayData.left,overlayData.top), null);       
    }
    
    /**
     * Gets the overlay data from the c++ interface and create the 
     * geometric representation.
     *
     * @since 30.04.1999
     * @see J2Ci.jDVPrStateParam_GetOverlayData
     */
    public void getData()
    {
        //Contains the DataBuffer
        DataBuffer overlayBuffer = null;
        
        //Contains the WritableRaster
        WritableRaster wr ;
        
        //Contains the offset
        int bandOffsets[] = {0};
        
        overlayData = new jDVPrStateParam_GetOverlayData();
        overlayData.layer = layerIndex;
        overlayData.idx = index;
        overlayData.bits = bits;
        int status = ps.getOverlayData(overlayData);
        
        IndexColorModel overlayColorModel = null;
        //Creates the BufferedImage
        if (bits == 8) 
        {
            overlayBuffer =  new DataBufferByte(overlayData.overlayData,overlayData.width* overlayData.height);
            System.out.println("overlay trans: " + overlayData.foreground);
            overlayColorModel = GrayColorIndex.getOverlayGrayColorModel(overlayData.foreground);
            //GrayColorIndex.countValues(overlayData.overlayData);
        }
        else 
        {
            overlayBuffer =  new DataBufferUShort(overlayData.overlayData12,overlayData.width* overlayData.height);
            overlayColorModel = GrayColorIndex.getOverlayGray12ColorModel(overlayData.foreground);
            //GrayColorIndex.countValues(overlayData.overlayData12);
            
        }
         
         wr = Raster.createInterleavedRaster(overlayBuffer,
                                            overlayData.width,
                                            overlayData.height,
                                            overlayData.width,
                                            1, bandOffsets,null);
        
       
        overlayImage = new BufferedImage(overlayColorModel, wr, overlayColorModel.isAlphaPremultiplied(), null);
    }
} 



/*
 *  CVS Log
 *  $Log: PresentationStateOverlayObject.java,v $
 *  Revision 1.1.1.1  2001/06/06 10:32:30  kleber
 *  Init commit for DICOMscope 3.5
 *  Create new CVS
 *
*/