1 /*
2  *
3  *  Copyright (C) 1998-2012, OFFIS e.V.
4  *  All rights reserved.  See COPYRIGHT file for details.
5  *
6  *  This software and supporting documentation were developed by
7  *
8  *    OFFIS e.V.
9  *    R&D Division Health
10  *    Escherweg 2
11  *    D-26121 Oldenburg, Germany
12  *
13  *
14  *  Module: dcmpstat
15  *
16  *  Author: Marco Eichelberg
17  *
18  *  Purpose:
19  *    classes: DVPSImageBoxContent
20  *
21  */
22 
23 #ifndef DVPSIB_H
24 #define DVPSIB_H
25 
26 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
27 #include "dcmtk/dcmpstat/dvpstyp.h"     /* for enum types */
28 #include "dcmtk/dcmpstat/dpdefine.h"
29 #include "dcmtk/dcmdata/dcitem.h"
30 #include "dcmtk/ofstd/ofstring.h"
31 #include "dcmtk/dcmdata/dctk.h"
32 #include "dcmtk/dcmnet/dimse.h"
33 
34 class DVPSPresentationLUT_PList;
35 class DVConfiguration;
36 
37 /** the representation of a Image Box Content SQ item for Stored Print
38  */
39 
40 class DCMTK_DCMPSTAT_EXPORT DVPSImageBoxContent
41 {
42 public:
43  /// default constructor
44   DVPSImageBoxContent();
45 
46   /// copy constructor
47   DVPSImageBoxContent(const DVPSImageBoxContent& copy);
48 
49   /** clone method.
50    *  @return a pointer to a new DVPSImageBoxContent object containing
51    *  a copy of this object.
52    */
clone()53   DVPSImageBoxContent *clone() { return new DVPSImageBoxContent(*this); }
54 
55   /// destructor
56   virtual ~DVPSImageBoxContent();
57 
58   /** resets the object to initial state.
59    *  After this call, the object is in the same state as after
60    *  creation with the default constructor.
61    */
62   void clear();
63 
64   /** reads an image box content item from a DICOM dataset.
65    *  The DICOM elements of the referenced item are copied
66    *  from the dataset to this object.
67    *  The completeness of the item (presence of all required elements,
68    *  value multiplicity) is checked.
69    *  If this method returns an error code, the object is in undefined state afterwards.
70    *  @param dset the item of the ImageBoxContentSequence from which the data is to be read
71    *  @param presentationLUTList list of presentation LUTs which may be referenced
72    *  @return EC_Normal if successful, an error code otherwise.
73    */
74   OFCondition read(DcmItem &dset, DVPSPresentationLUT_PList& presentationLUTList);
75 
76   /** writes the image box managed by this object to a DICOM dataset.
77    *  Copies of the DICOM element managed by this object are inserted into
78    *  the DICOM dataset.
79    *  @param dset the the item of the ImageBoxContentSequence to which the data is written
80    *  @param writeRequestedImageSize if false, the Requested Image Size attribute is not written,
81    *    e.g. because it is not supported by the target printer.
82    *  @param writeReferencedPLUTSQ if false, the Referenced Presentation LUT Sequence is not written,
83    *    e.g. because a "general" presentation LUT is used instead of those referenced by the image boxes.
84    *  @return EC_Normal if successful, an error code otherwise.
85    */
86   OFCondition write(DcmItem &dset, OFBool writeRequestedImageSize, OFBool writeReferencedPLUTSQ = OFTrue);
87 
88   /** create default values for all missing type 1 elements.
89    *  Called before a stored print object is written.
90    *  @param renumber if true, a new imageBoxPosition values is created
91    *  @param number new imageBoxPosition to be assigned
92    *  @param ignoreEmptyImages if true, an empty image box position does not cause an error.
93    *  @return EC_Normal if successful, an error code otherwise.
94    */
95   OFCondition createDefaultValues(OFBool renumber, unsigned long number, OFBool ignoreEmptyImages);
96 
97   /** returns the referencedSOPClassUID from the ReferencedImageSequence
98    *  @return referencedSOPClassUID string
99    */
100   const char *getSOPClassUID();
101 
102   /** sets the content of this image box object.
103    *  @param instanceuid SOP instance UID of this image box
104    *  @param retrieveaetitle retrieve AETITLE of the referenced image
105    *  @param refstudyuid study instance UID of the referenced image
106    *  @param refseriesuid series instance UID of the referenced image
107    *  @param refsopclassuid SOP class UID of the referenced image
108    *  @param refsopinstanceuid SOP instance UID of the referenced image
109    *  @param requestedimagesize requested images size for this image
110    *  @param patientid patient ID for the referenced image
111    *  @param presentationlutreference referenced SOP instance UID for the referenced Presentation LUT,
112    *  @return EC_Normal if successful, an error code otherwise.
113    */
114   OFCondition setContent(
115     const char *instanceuid,
116     const char *retrieveaetitle,
117     const char *refstudyuid,
118     const char *refseriesuid,
119     const char *refsopclassuid,
120     const char *refsopinstanceuid,
121     const char *requestedimagesize,
122     const char *patientid,
123     const char *presentationlutreference);
124 
125   /** sets the (optional) requested decimate/crop behaviour for this image box.
126    *  @param value new enumerated value. The caller is responsible for
127    *    making sure that the selected printer supports decimate/crop
128    *    if a non-default value is set.
129    *  @return EC_Normal if successful, an error code otherwise.
130    */
131   OFCondition setRequestedDecimateCropBehaviour(DVPSDecimateCropBehaviour value);
132 
133   /** gets the current requested decimate/crop behaviour setting
134    *  that is used for this image box.
135    *  @return requested decimate/crop behaviour
136    */
137   DVPSDecimateCropBehaviour getRequestedDecimateCropBehaviour();
138 
139   /** checks whether image box has additional settings
140    *  that are not default.
141    *  @return OFTrue if additional settings exist, OFFalse otherwise.
142    */
143   OFBool hasAdditionalSettings();
144 
145   /** gets the (optional) referenced Presentation LUT Instance UID.
146    *  @return UID, may be NULL.
147    */
148   const char *getReferencedPresentationLUTInstanceUID();
149 
150   /** gets the polarity.
151    *  @return polarity, may be NULL.
152    */
153   const char *getPolarity();
154 
155   /** gets the requested image size.
156    *  @return requested image size, may be NULL.
157    */
158   const char *getRequestedImageSize();
159 
160   /** gets the (optional) magnification type.
161    *  @return magnification type, may be NULL.
162    */
163   const char *getMagnificationType();
164 
165   /** gets the (optional) smoothing type.
166    *  @return smoothing type, may be NULL.
167    */
168   const char *getSmoothingType();
169 
170   /** gets the (optional) configuration information.
171    *  @return configuration information, may be NULL.
172    */
173   const char *getConfigurationInformation();
174 
175   /** gets the current SOP Instance UID.
176    *  @return SOP Instance UID, may be NULL.
177    */
178   const char *getSOPInstanceUID();
179 
180   /** gets the current image box position, 0 if none is set.
181    *  @return image box position
182    */
183   Uint16 getImageBoxPosition();
184 
185   /** sets the polarity.
186    *  @param value new attribute value (NORMAL or REVERSE), may be NULL.
187    *  @return EC_Normal if successful, an error code otherwise.
188    */
189   OFCondition setPolarity(const char *value);
190 
191   /** sets the requested image size.
192    *  @param value new attribute value, may be NULL.
193    *  @return EC_Normal if successful, an error code otherwise.
194    */
195   OFCondition setRequestedImageSize(const char *value);
196 
197   /** sets the (optional) magnification type.
198    *  @param value new attribute value, may be NULL.
199    *    The caller is responsible for making sure
200    *    that the value is valid for the selected printer.
201    *  @return EC_Normal if successful, an error code otherwise.
202    */
203   OFCondition setMagnificationType(const char *value);
204 
205   /** sets the (optional) smoothing type.
206    *  @param value new attribute value, may be NULL.
207    *    The caller is responsible for making sure
208    *    that the value is valid for the selected printer.
209    *  @return EC_Normal if successful, an error code otherwise.
210    */
211   OFCondition setSmoothingType(const char *value);
212 
213   /** sets the (optional) configuration information.
214    *  @param value new attribute value, may be NULL.
215    *    The caller is responsible for making sure
216    *    that the value is valid for the selected printer.
217    *  @return EC_Normal if successful, an error code otherwise.
218    */
219   OFCondition setConfigurationInformation(const char *value);
220 
221   /** sets the SOP instance UID (which is returned by the Print SCP).
222    *  @param value new attribute value, must not be NULL.
223    *  @return EC_Normal if successful, an error code otherwise.
224    */
225   OFCondition setSOPInstanceUID(const char *value);
226 
227   /** sets magnification type, smoothing type and configuration information back to default.
228    *  @return EC_Normal if successful, an error code otherwise.
229    */
230   OFCondition setDefault();
231 
232   /** returns the image UIDs that are required to look up the referenced image in the database
233    *  @param studyUID Study UID of the image
234    *  @param seriesUID series UID of the image
235    *  @param instanceUID instance UID of the image
236    *  @return EC_Normal if successful, an error code otherwise.
237    */
238   OFCondition getImageReference(const char *&studyUID, const char *&seriesUID, const char *&instanceUID);
239 
240   /** writes the attributes managed by this objects that are part of a
241    *  basic grayscale image box N-SET request into the DICOM dataset.
242    *  Copies of the DICOM element managed by this object are inserted into
243    *  the DICOM dataset.
244    *  @param dset the dataset to which the data is written
245    *  @return EC_Normal if successful, an error code otherwise.
246    */
247   OFCondition prepareBasicImageBox(DcmItem &dset);
248 
249   /** checks whether the given Presentation LUT type could be used together
250    *  with this image box on a Print SCP that requires a matching alignment
251    *  between a Presentation LUT and the image pixel data.
252    *  @param align LUT alignment type
253    *  @return OFTrue if matching, OFFalse otherwise
254    */
255   OFBool matchesPresentationLUT(DVPSPrintPresentationLUTAlignment align) const;
256 
257   /** performs a Print SCP Basic Grayscale Image Box N-SET operation.
258    *  The results of the N-SET operation are stored in the objects passed as
259    *  rsp and rspDataset.
260    *  @param cfg config file facility
261    *  @param cfgname symbolic printer name in config file
262    *  @param rqDataset N-SET request dataset
263    *  @param rsp N-SET response message
264    *  @param rspDataset N-SET response dataset passed back in this parameter
265    *  @param imageDataset a hardcopy grayscale image (without general study
266    *     and general series modules which must be added by the caller)
267    *     containing the image data from the N-SET request is written to
268    *     this dataset if the method returns successfully.
269    *  @param align describes the current Presentation LUT. Used if the Print
270    *     SCP has been configured to enforce a matching of Presentation LUT
271    *     and pixel data bit depth.
272    *  @param presentationLUTnegotiated
273    *    OFTrue if support for the Presentation LUT SOP class
274    *    has been negotiated at association negotiation
275    *  @return OFTrue if N-SET operation was successful, OFFalse otherwise.
276    */
277   OFBool printSCPSet(
278     DVConfiguration& cfg,
279     const char *cfgname,
280     DcmDataset *rqDataset,
281     T_DIMSE_Message& rsp,
282     DcmDataset *& rspDataset,
283     DcmDataset &imageDataset,
284     DVPSPrintPresentationLUTAlignment align,
285     OFBool presentationLUTnegotiated);
286 
287   /** assigns new values for study instance UID, series instance UID
288    *  and retrieve aetitle.
289    *  @param studyUID new studyUID
290    *  @param seriesUID new seriesUID
291    *  @param aetitle new retrieve aetitle, must not be NULL.
292    *  @return EC_Normal if successful, an error code otherwise.
293    */
294   OFCondition setUIDsAndAETitle(
295     DcmUniqueIdentifier& studyUID,
296     DcmUniqueIdentifier& seriesUID,
297     const char *aetitle);
298 
299 private:
300   /// private undefined assignment operator
301   DVPSImageBoxContent& operator=(const DVPSImageBoxContent&);
302 
303   /** writes a Referenced Presentation LUT SQ to the given
304    *  dataset. Helper function used in the more general write() method.
305    *  @param dset the dataset to which the data is written
306    *  @return EC_Normal if successful, an error code otherwise.
307    */
308   OFCondition addReferencedPLUTSQ(DcmItem &dset);
309 
310   /** evaluates the contents of the Basic Grayscale Image Sequence during a
311    *  Print SCP Basic Grayscale Image Box N-SET operation.
312    *  The results of the N-SET operation are stored in the object passed as rsp.
313    *  @param cfg config file facility
314    *  @param cfgname symbolic printer name in config file
315    *  @param rqDataset first item of the Basic Grayscale Image Sequence
316    *  @param rsp N-SET response message
317    *  @param imageDataset a hardcopy grayscale image (without general study
318    *     and general series modules which must be added by the caller)
319    *     containing the image data from the N-SET request is written to
320    *     this dataset if the method returns successfully.
321    *  @param align describes the current Presentation LUT. Used if the Print
322    *     SCP has been configured to enforce a matching of Presentation LUT
323    *     and pixel data bit depth.
324    *  @param presentationLUTnegotiated
325    *    OFTrue if support for the Presentation LUT SOP class
326    *    has been negotiated at association negotiation
327    *  @return OFTrue if N-SET operation was successful, OFFalse otherwise.
328    */
329   OFBool printSCPEvaluateBasicGrayscaleImageSequence(
330    DVConfiguration& cfg,
331    const char *cfgname,
332    DcmItem *rqDataset,
333    T_DIMSE_Message& rsp,
334    DcmDataset &imageDataset,
335    DVPSPrintPresentationLUTAlignment align,
336    OFBool presentationLUTnegotiated);
337 
338   /// Module=Image_Box_List, VR=UI, VM=1, Type 1(c)
339   DcmUniqueIdentifier      sOPInstanceUID;
340   /// Module=Image_Box_List, VR=US, VM=1, Type 1
341   DcmUnsignedShort         imageBoxPosition;
342   /// Module=Image_Box_List, VR=CS, VM=1, Type 2
343   DcmCodeString            polarity;
344   /// Module=Image_Box_List, VR=CS, VM=1, Type 3
345   DcmCodeString            magnificationType;
346   /// Module=Image_Box_List, VR=ST, VM=1, Type 3
347   DcmShortText             configurationInformation;
348   /// Module=Image_Box_List, VR=CS, VM=1, Type 3
349   DcmCodeString            smoothingType;
350   /// Module=Image_Box_List, VR=DS, VM=1, Type 3
351   DcmDecimalString         requestedImageSize;
352   /// Module=Image_Box_List (Supplement 38), VR=CS, VM=1, Type 3
353   DcmCodeString            requestedDecimateCropBehavior;
354 
355   /* the following attributes belong to the ReferencedImageSequence
356    * which must have exactly one item here.
357    */
358   /// Module=Image_Box_List, VR=AE, VM=1-n, Type 1
359   DcmApplicationEntity     retrieveAETitle;
360   /// Module=Image_Box_List, VR=UI, VM=1, Type 1
361   DcmUniqueIdentifier      referencedSOPClassUID;
362   /// Module=Image_Box_List, VR=UI, VM=1, Type 1
363   DcmUniqueIdentifier      referencedSOPInstanceUID;
364   /// Module=Image_Box_List, VR=UI, VM=1, Type 1
365   DcmUniqueIdentifier      studyInstanceUID;
366   /// Module=Image_Box_List, VR=UI, VM=1, Type 1
367   DcmUniqueIdentifier      seriesInstanceUID;
368   /// Module=Image_Box_List, VR=IS, VM=1, Type 1c
369   DcmIntegerString         referencedFrameNumber;
370   /// Module=Image_Box_List, VR=LO, VM=1, Type 2
371   DcmLongString            patientID;
372 
373   // we do not support the ReferencedImageOverlayBoxSequence which is retired in Supplement 35 anyway.
374 
375   // the ReferencedPresentationLUTSequence is only created/read on the fly
376   DcmUniqueIdentifier      referencedPresentationLUTInstanceUID;
377 
378   /// describes whether the image depth is 8 bit or 12 bit.
379   DVPSImageDepth           imageDepth;
380 
381 };
382 
383 #endif
384