Mercurial > hg > orthanc-java
comparison JavaSDK/be/uclouvain/orthanc/DicomInstance.java @ 0:3ecef5782f2c
initial commit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Oct 2023 17:59:44 +0200 |
parents | |
children | 26c08ff926a3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3ecef5782f2c |
---|---|
1 package be.uclouvain.orthanc; | |
2 | |
3 /** | |
4 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium | |
5 * SPDX-License-Identifier: GPL-3.0-or-later | |
6 */ | |
7 | |
8 /** | |
9 * Java plugin for Orthanc | |
10 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium | |
11 * | |
12 * This program is free software: you can redistribute it and/or | |
13 * modify it under the terms of the GNU General Public License as | |
14 * published by the Free Software Foundation, either version 3 of the | |
15 * License, or (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, but | |
18 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 * General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program. If not, see http://www.gnu.org/licenses/. | |
24 **/ | |
25 | |
26 | |
27 /** | |
28 * DICOM instance managed by the Orthanc core | |
29 **/ | |
30 public class DicomInstance { | |
31 private long self; | |
32 | |
33 /** | |
34 * Construct a Java object wrapping a C object that is managed by Orthanc. | |
35 * @param self Pointer to the C object. | |
36 **/ | |
37 protected DicomInstance(long self) { | |
38 if (self == 0) { | |
39 throw new IllegalArgumentException("Null pointer"); | |
40 } else { | |
41 this.self = self; | |
42 } | |
43 } | |
44 | |
45 /** | |
46 * Return the C object that is associated with this Java wrapper. | |
47 * @return Pointer to the C object. | |
48 **/ | |
49 protected long getSelf() { | |
50 return self; | |
51 } | |
52 | |
53 @Override | |
54 protected void finalize() throws Throwable { | |
55 dispose(); | |
56 super.finalize(); | |
57 } | |
58 | |
59 /** | |
60 * Manually deallocate the C object that is associated with this Java wrapper. | |
61 * | |
62 * This method can be used to immediately deallocate the C object, | |
63 * instead of waiting for the garbage collector to dispose the Java wrapper. | |
64 **/ | |
65 public void dispose() { | |
66 if (self != 0) { | |
67 NativeSDK.OrthancPluginFreeDicomInstance(self); | |
68 self = 0; | |
69 } | |
70 } | |
71 | |
72 /** | |
73 * Parse a DICOM instance. | |
74 * | |
75 * This function parses a memory buffer that contains a DICOM file. The function | |
76 * returns a new pointer to a data structure that is managed by the Orthanc core. | |
77 * | |
78 * @param buffer The memory buffer containing the DICOM instance. | |
79 * @return The newly constructed object. | |
80 **/ | |
81 public static DicomInstance createDicomInstance( | |
82 byte[] buffer) { | |
83 return new DicomInstance(NativeSDK.OrthancPluginCreateDicomInstance(buffer)); | |
84 } | |
85 | |
86 /** | |
87 * Parse and transcode a DICOM instance. | |
88 * | |
89 * This function parses a memory buffer that contains a DICOM file, then transcodes | |
90 * it to the given transfer syntax. The function returns a new pointer to a data | |
91 * structure that is managed by the Orthanc core. | |
92 * | |
93 * @param buffer The memory buffer containing the DICOM instance. | |
94 * @param transferSyntax The transfer syntax UID for the transcoding. | |
95 * @return The newly constructed object. | |
96 **/ | |
97 public static DicomInstance transcodeDicomInstance( | |
98 byte[] buffer, | |
99 String transferSyntax) { | |
100 return new DicomInstance(NativeSDK.OrthancPluginTranscodeDicomInstance(buffer, transferSyntax)); | |
101 } | |
102 | |
103 | |
104 /** | |
105 * Get the AET of a DICOM instance. | |
106 * | |
107 * This function returns the Application Entity Title (AET) of the DICOM modality | |
108 * from which a DICOM instance originates. | |
109 * | |
110 * @return The resulting string. | |
111 **/ | |
112 public String getInstanceRemoteAet() { | |
113 return NativeSDK.OrthancPluginGetInstanceRemoteAet(self); | |
114 } | |
115 | |
116 /** | |
117 * Get the size of a DICOM file. | |
118 * | |
119 * This function returns the number of bytes of the given DICOM instance. | |
120 * | |
121 * @return The size of the file, -1 in case of error. | |
122 **/ | |
123 public long getInstanceSize() { | |
124 return NativeSDK.OrthancPluginGetInstanceSize(self); | |
125 } | |
126 | |
127 /** | |
128 * Get the DICOM tag hierarchy as a JSON file. | |
129 * | |
130 * This function returns a pointer to a newly created string containing a JSON | |
131 * file. This JSON file encodes the tag hierarchy of the given DICOM instance. | |
132 * | |
133 * @return The resulting string. | |
134 **/ | |
135 public String getInstanceJson() { | |
136 return NativeSDK.OrthancPluginGetInstanceJson(self); | |
137 } | |
138 | |
139 /** | |
140 * Get the DICOM tag hierarchy as a JSON file (with simplification). | |
141 * | |
142 * This function returns a pointer to a newly created string containing a JSON | |
143 * file. This JSON file encodes the tag hierarchy of the given DICOM instance. In | |
144 * contrast with ::OrthancPluginGetInstanceJson(), the returned JSON file is in its | |
145 * simplified version. | |
146 * | |
147 * @return The resulting string. | |
148 **/ | |
149 public String getInstanceSimplifiedJson() { | |
150 return NativeSDK.OrthancPluginGetInstanceSimplifiedJson(self); | |
151 } | |
152 | |
153 /** | |
154 * Check whether a DICOM instance is associated with some metadata. | |
155 * | |
156 * This function checks whether the DICOM instance of interest is associated with | |
157 * some metadata. As of Orthanc 0.8.1, in the callbacks registered by | |
158 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only possibly available | |
159 * metadata are "ReceptionDate", "RemoteAET" and "IndexInSeries". | |
160 * | |
161 * @param metadata The metadata of interest. | |
162 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error. | |
163 **/ | |
164 public int hasInstanceMetadata( | |
165 String metadata) { | |
166 return NativeSDK.OrthancPluginHasInstanceMetadata(self, metadata); | |
167 } | |
168 | |
169 /** | |
170 * Get the value of some metadata associated with a given DICOM instance. | |
171 * | |
172 * This functions returns the value of some metadata that is associated with the | |
173 * DICOM instance of interest. Before calling this function, the existence of the | |
174 * metadata must have been checked with ::OrthancPluginHasInstanceMetadata(). | |
175 * | |
176 * @param metadata The metadata of interest. | |
177 * @return The resulting string. | |
178 **/ | |
179 public String getInstanceMetadata( | |
180 String metadata) { | |
181 return NativeSDK.OrthancPluginGetInstanceMetadata(self, metadata); | |
182 } | |
183 | |
184 /** | |
185 * Get the origin of a DICOM file. | |
186 * | |
187 * This function returns the origin of a DICOM instance that has been received by | |
188 * Orthanc. | |
189 * | |
190 * @return The origin of the instance. | |
191 **/ | |
192 public InstanceOrigin getInstanceOrigin() { | |
193 return InstanceOrigin.getInstance(NativeSDK.OrthancPluginGetInstanceOrigin(self)); | |
194 } | |
195 | |
196 /** | |
197 * Get the transfer syntax of a DICOM file. | |
198 * | |
199 * This function returns a pointer to a newly created string that contains the | |
200 * transfer syntax UID of the DICOM instance. The empty string might be returned if | |
201 * this information is unknown. | |
202 * | |
203 * @return The resulting string. | |
204 **/ | |
205 public String getInstanceTransferSyntaxUid() { | |
206 return NativeSDK.OrthancPluginGetInstanceTransferSyntaxUid(self); | |
207 } | |
208 | |
209 /** | |
210 * Check whether the DICOM file has pixel data. | |
211 * | |
212 * This function returns a Boolean value indicating whether the DICOM instance | |
213 * contains the pixel data (7FE0,0010) tag. | |
214 * | |
215 * @return "1" if the DICOM instance contains pixel data, or "0" if the tag is | |
216 * missing, or "-1" in the case of an error. | |
217 **/ | |
218 public int hasInstancePixelData() { | |
219 return NativeSDK.OrthancPluginHasInstancePixelData(self); | |
220 } | |
221 | |
222 /** | |
223 * Get the number of frames in a DICOM instance. | |
224 * | |
225 * This function returns the number of frames that are part of a DICOM image | |
226 * managed by the Orthanc core. | |
227 * | |
228 * @return The number of frames (will be zero in the case of an error). | |
229 **/ | |
230 public int getInstanceFramesCount() { | |
231 return NativeSDK.OrthancPluginGetInstanceFramesCount(self); | |
232 } | |
233 | |
234 /** | |
235 * Get the raw content of a frame in a DICOM instance. | |
236 * | |
237 * This function returns a memory buffer containing the raw content of a frame in a | |
238 * DICOM instance that is managed by the Orthanc core. This is notably useful for | |
239 * compressed transfer syntaxes, as it gives access to the embedded files (such as | |
240 * JPEG, JPEG-LS or JPEG2k). The Orthanc core transparently reassembles the | |
241 * fragments to extract the raw frame. | |
242 * | |
243 * @param frameIndex The index of the frame of interest. | |
244 * @return The resulting memory buffer. | |
245 **/ | |
246 public byte[] getInstanceRawFrame( | |
247 int frameIndex) { | |
248 return NativeSDK.OrthancPluginGetInstanceRawFrame(self, frameIndex); | |
249 } | |
250 | |
251 /** | |
252 * Decode one frame from a DICOM instance. | |
253 * | |
254 * This function decodes one frame of a DICOM image that is managed by the Orthanc | |
255 * core. | |
256 * | |
257 * @param frameIndex The index of the frame of interest. | |
258 * @return The newly constructed object. | |
259 **/ | |
260 public Image getInstanceDecodedFrame( | |
261 int frameIndex) { | |
262 return new Image(NativeSDK.OrthancPluginGetInstanceDecodedFrame(self, frameIndex)); | |
263 } | |
264 | |
265 /** | |
266 * Writes a DICOM instance to a memory buffer. | |
267 * | |
268 * This function returns a memory buffer containing the serialization of a DICOM | |
269 * instance that is managed by the Orthanc core. | |
270 * | |
271 * @return The resulting memory buffer. | |
272 **/ | |
273 public byte[] serializeDicomInstance() { | |
274 return NativeSDK.OrthancPluginSerializeDicomInstance(self); | |
275 } | |
276 | |
277 /** | |
278 * Format a DICOM memory buffer as a JSON string. | |
279 * | |
280 * This function takes as DICOM instance managed by the Orthanc core, and outputs a | |
281 * JSON string representing the tags of this DICOM file. | |
282 * | |
283 * @param format The output format. | |
284 * @param flags Flags governing the output. | |
285 * @param maxStringLength The maximum length of a field. Too long fields will be | |
286 * output as "null". The 0 value means no maximum length. | |
287 * @return The resulting string. | |
288 **/ | |
289 public String getInstanceAdvancedJson( | |
290 DicomToJsonFormat format, | |
291 DicomToJsonFlags flags, | |
292 int maxStringLength) { | |
293 return NativeSDK.OrthancPluginGetInstanceAdvancedJson(self, format.getValue(), flags.getValue(), maxStringLength); | |
294 } | |
295 | |
296 } |