1 /*
2  *
3  *  Copyright (C) 1999-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: DVPSStoredPrint
20  *
21  */
22 
23 
24 #ifndef DVPSSP_H
25 #define DVPSSP_H
26 
27 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
28 
29 #include "dcmtk/ofstd/ofstream.h"
30 #include "dcmtk/ofstd/ofstring.h"
31 #include "dcmtk/dcmpstat/dvpstyp.h"         /* for enum types */
32 #include "dcmtk/dcmpstat/dvpspll.h"         /* for class DVPSPresentationLUT_PList */
33 #include "dcmtk/dcmpstat/dvpsibl.h"         /* for class DVPSImageBoxContent_PList */
34 #include "dcmtk/dcmpstat/dvpsabl.h"         /* for class DVPSAnnotationContent_PList */
35 #include "dcmtk/dcmpstat/dvpstat.h"		 /* for class DVPresentationState */
36 #include "dcmtk/dcmpstat/dvpspr.h"			 /* for class DVPrintMessageHandler */
37 
38 class DicomImage;
39 class DVPSPresentationLUT;
40 class DVConfiguration;
41 /** the representation of a Stored Print object
42  */
43 
44 class DCMTK_DCMPSTAT_EXPORT DVPSStoredPrint
45 {
46  public:
47   /** constructor
48    *  @param illumin default Illumination setting
49    *  @param reflection default Reflected Ambient Light setting
50    *  @param aetitle application entity title of the print originator (SCU)
51    */
52   DVPSStoredPrint(Uint16 illumin, Uint16 reflection, const char *aetitle = NULL);
53 
54   /// copy constructor
55   DVPSStoredPrint(const DVPSStoredPrint& copy);
56 
57   /** clone method.
58    *  @return a pointer to a new DVPSStoredPrint object containing
59    *  a copy of this object.
60    */
clone()61   DVPSStoredPrint *clone() { return new DVPSStoredPrint(*this); }
62 
63   /// destructor
64   virtual ~DVPSStoredPrint();
65 
66   /** reset the object to initial state.
67    *  After this call, the object is in the same state as after
68    *  creation with the default constructor.
69    */
70   void clear();
71 
72   /** reads a Stored Print object from a DICOM dataset.
73    *  The DICOM elements of the stored print object are copied
74    *  from the dataset to this object.
75    *  The completeness of the object (presence of all required elements,
76    *  value multiplicity) is checked.
77    *  If this method returns an error code, the object is in undefined state afterwards.
78    *  @param dset the dataset from which the data is to be read
79    *  @return EC_Normal if successful, an error code otherwise.
80    */
81   OFCondition read(DcmItem &dset);
82 
83   /** writes the Stored Print object to a DICOM dataset.
84    *  Copies of the DICOM elements managed by this object are inserted into
85    *  the DICOM dataset.
86    *  @param dset the dataset to which the data is written
87    *  @param writeRequestedImageSize if false, the Requested Image Size attributes are not written,
88    *    e. g. because they are not supported by the target printer.
89    *  @param limitImages if true, only the number of image references
90    *    that are needed for the current image display format (film layout) are written.
91    *    If false, all image references are written.
92    *  @param updateDecimateCrop if true, the decimate/crop attribute on image box level
93    *    is replaced by the global stored print level setting in all image boxes
94    *    prior to writing the dataset.
95    *  @param ignoreEmptyImages if true, all image boxes without image box position are ignored
96    *    when writing.
97    *  @return EC_Normal if successful, an error code otherwise.
98    */
99   OFCondition write(
100     DcmItem &dset,
101     OFBool writeRequestedImageSize,
102     OFBool limitImages,
103     OFBool updateDecimateCrop,
104     OFBool ignoreEmptyImages);
105 
106   /** sets the name of the current printer.
107    *  This name is identical to the unique entry used in the configuration file.
108    *  @return name of the current printer
109    */
110   OFCondition setOriginator(const char *aetitle);
111 
112   /** sets the application entity title of the print SCU.
113    *  @return application entity title of the print SCU
114    */
115   OFCondition setDestination(const char *aetitle);
116 
117   /** sets the application entity title of the print SCP.
118    *  @return application entity title of the print SCP
119    */
120   OFCondition setPrinterName(const char *name);
121 
122   /** sets the image display format to 'STANDARD\columns,rows'.
123    *  The caller must make sure that the column and row values are
124    *  valid for the selected printer.
125    *  @param columns number of columns
126    *  @param rows number of rows
127    *  @return EC_Normal if successful, an error code otherwise.
128    */
129   OFCondition setImageDisplayFormat(unsigned long columns, unsigned long rows);
130 
131   /** sets the (optional) film size ID.
132    *  @param value new attribute value, may be NULL.
133    *    The caller is responsible for making sure
134    *    that the value is valid for the selected printer.
135    *  @return EC_Normal if successful, an error code otherwise.
136    */
137   OFCondition setFilmSizeID(const char *value);
138 
139   /** sets the (optional) magnification type.
140    *  @param value new attribute value, may be NULL.
141    *    The caller is responsible for making sure
142    *    that the value is valid for the selected printer.
143    *  @return EC_Normal if successful, an error code otherwise.
144    */
145   OFCondition setMagnificationType(const char *value);
146 
147   /** sets the (optional) smoothing type.
148    *  @param value new attribute value, may be NULL.
149    *    The caller is responsible for making sure
150    *    that the value is valid for the selected printer.
151    *  @return EC_Normal if successful, an error code otherwise.
152    */
153   OFCondition setSmoothingType(const char *value);
154 
155   /** sets the (optional) configuration information.
156    *  @param value new attribute value, may be NULL.
157    *    The caller is responsible for making sure
158    *    that the value is valid for the selected printer.
159    *  @return EC_Normal if successful, an error code otherwise.
160    */
161   OFCondition setConfigurationInformation(const char *value);
162 
163   /** sets the (optional) requested resolution ID.
164    *  @param value new attribute value, may be NULL.
165    *    The caller is responsible for making sure
166    *    that the value is valid for the selected printer.
167    *  @return EC_Normal if successful, an error code otherwise.
168    */
169   OFCondition setResolutionID(const char *value);
170 
171   /** sets the (optional) film orientation.
172    *  @param value new enumerated value. The caller is responsible for
173    *    making sure that the selected printer supports film orientation
174    *    if a non-default value is set.
175    *  @return EC_Normal if successful, an error code otherwise.
176    */
177   OFCondition setFilmOrientation(DVPSFilmOrientation value);
178 
179   /** sets the (optional) trim (printing of borders).
180    *  @param value new enumerated value. The caller is responsible for
181    *    making sure that the selected printer supports trim
182    *    if a non-default value is set.
183    *  @return EC_Normal if successful, an error code otherwise.
184    */
185   OFCondition setTrim(DVPSTrimMode value);
186 
187   /** sets the (optional) requested decimate/crop behaviour
188    *  for all image boxes managed by this stored print object.
189    *  @param value new enumerated value. The caller is responsible for
190    *    making sure that the selected printer supports decimate/crop
191    *    if a non-default value is set.
192    *  @return EC_Normal if successful, an error code otherwise.
193    */
194   OFCondition setRequestedDecimateCropBehaviour(DVPSDecimateCropBehaviour value);
195 
196   /** sets the (optional) border density.
197    *  @param value new attribute value, may be NULL.
198    *    The caller is responsible for making sure
199    *    that the value is valid for the selected printer.
200    *  @return EC_Normal if successful, an error code otherwise.
201    */
202   OFCondition setBorderDensity(const char *value);
203 
204   /** sets the (optional) empty image density.
205    *  @param value new attribute value, may be NULL.
206    *    The caller is responsible for making sure
207    *    that the value is valid for the selected printer.
208    *  @return EC_Normal if successful, an error code otherwise.
209    */
210   OFCondition setEmtpyImageDensity(const char *value);
211 
212   /** sets the (optional) max density.
213    *  @param value new attribute value, may be NULL.
214    *    The caller is responsible for making sure
215    *    that the value is valid for the selected printer.
216    *  @return EC_Normal if successful, an error code otherwise.
217    */
218   OFCondition setMaxDensity(const char *value);
219 
220   /** sets the (optional) min density.
221    *  @param value new attribute value, may be NULL.
222    *    The caller is responsible for making sure
223    *    that the value is valid for the selected printer.
224    *  @return EC_Normal if successful, an error code otherwise.
225    */
226   OFCondition setMinDensity(const char *value);
227 
228   /** deletes all optional attribute values that might not be
229    *  supported by all printers. Film size ID, magnification and smoothing type,
230    *  configuration information, requested resolution ID,
231    *  trim and requested decimate/crop behaviour, border and empty image density
232    *  are reset to default. For all registered images, magnification, smoothing type
233    *  and configuration information are also set back to default.
234    *  @param name name of the new printer (optional)
235    *  @param aetitle of the new printer (optional)
236    *  @return EC_Normal if successful, an error code otherwise.
237    */
238   OFCondition newPrinter(const char *name = NULL, const char *destinationAE = NULL); // short cut, delete all optional settings
239 
240   /** gets the the application entity title of the print SCU.
241    *  @return application entity title of the print SCP
242    */
243   const char *getOriginator();
244   /** gets the the application entity title of the print SCP.
245    *  @return application entity title of the print SCP
246    */
247   const char *getDestination();
248   /** gets the name of the current printer.
249    *  @return name of the current printer
250    */
251   const char *getPrinterName();
252 
253   /** gets the number of columns of the current image display format.
254    *  @return number of columns.
255    */
256   unsigned long getImageDisplayFormatColumns();
257 
258   /** gets the number of rows of the current image display format.
259    *  @return number of rows.
260    */
261   unsigned long getImageDisplayFormatRows();
262 
263   /** gets the current film orientation.
264    *  @return film orientation.
265    */
266   DVPSFilmOrientation getFilmOrientation();
267 
268   /** gets the current trim mode.
269    *  @return trim mode.
270    */
271   DVPSTrimMode getTrim();
272 
273   /** gets the current requested decimate/crop behaviour setting
274    *  that is used for all image boxes managed by this object.
275    *  @return requested decimate/crop behaviour
276    */
getRequestedDecimateCropBehaviour()277   DVPSDecimateCropBehaviour getRequestedDecimateCropBehaviour()
278   {
279     return decimateCropBehaviour;
280   }
281 
282   /** gets the Study Instance UID.
283    *  @return Study Instance UID, may be NULL.
284    */
285   const char *getStudyInstanceUID();
286 
287   /** gets the Series Instance UID.
288    *  @return Series Instance UID, may be NULL.
289    */
290   const char *getSeriesInstanceUID();
291 
292   /** gets the SOP Instance UID.
293    *  @return SOP Instance UID, may be NULL.
294    */
295   const char *getSOPInstanceUID();
296 
297   /** gets the (optional) film size ID.
298    *  @return film size ID, may be NULL.
299    */
300   const char *getFilmSizeID();
301 
302   /** gets the (optional) magnification type.
303    *  @return magnification type, may be NULL.
304    */
305   const char *getMagnificationType();
306 
307   /** gets the (optional) smoothing type.
308    *  @return smoothing type, may be NULL.
309    */
310   const char *getSmoothingType();
311 
312   /** gets the (optional) configuration information.
313    *  @return configuration information, may be NULL.
314    */
315   const char *getConfigurationInformation();
316 
317   /** gets the (optional) requestes resolution ID
318    *  @return requested resolution ID, may be NULL.
319    */
320   const char *getResolutionID();
321 
322   /** gets the (optional) border density.
323    *  @return border density, may be NULL.
324    */
325   const char *getBorderDensity();
326 
327   /** gets the (optional) empty image density.
328    *  @return empty image density, may be NULL.
329    */
330   const char *getEmtpyImageDensity();
331 
332   /** gets the (optional) max density.
333    *  The string returned becomes invalid after the next
334    *  call to getMaxDensity or getMinDensity.
335    *  @return max density, may be NULL.
336    */
337   const char *getMaxDensity();
338 
339   /** gets the (optional) min density.
340    *  The string returned becomes invalid after the next
341    *  call to getMaxDensity or getMinDensity.
342    *  @return min density, may be NULL.
343    */
344   const char *getMinDensity();
345 
346   /** gets the (optional) max density.
347    *  @return max density (default: 300).
348    */
349   Uint16 getMaxDensityValue();
350 
351   /** gets the (optional) min density.
352    *  @return min density (default: 20).
353    */
354   Uint16 getMinDensityValue();
355 
356   /** gets the number of images currently registered in this object.
357    *  @return number of images.
358    */
getNumberOfImages()359   size_t getNumberOfImages()
360   {
361     return imageBoxContentList.size();
362   }
363 
364   /** gets the number of annotations currently registered in this object.
365    *  @return number of annotations.
366    */
getNumberOfAnnotations()367   size_t getNumberOfAnnotations()
368   {
369     return annotationContentList.size();
370   }
371 
372   /** deletes one of the registered images.
373    *  @param idx index, must be < getNumberOfImages()
374    *  @return EC_Normal if successful, an error code otherwise.
375    */
376   OFCondition deleteImage(size_t idx);
377 
378   /** deletes multiple of the registered
379    *  images, starting with the first one.
380    *  @param number number of images to delete, must be <= getNumberOfImages()
381    *  @return EC_Normal if successful, an error code otherwise.
382    */
383   OFCondition deleteMultipleImages(size_t number);
384 
385   /** deletes as many images as fit on the current page according
386    *  to the image display format settings. Used to remove images
387    *  from the queue after a print job with one film box has been
388    *  spooled.
389    *  @return EC_Normal if successful, an error code otherwise.
390    */
391   OFCondition deleteSpooledImages();
392 
393   /** checks if one of the registered images has additional settings that are not
394    *  default values on the image box level.
395    *  @param idx index, must be < getNumberOfImages()
396    *  @return EC_Normal if successful, an error code otherwise.
397    */
imageHasAdditionalSettings(size_t idx)398   OFBool imageHasAdditionalSettings(size_t idx)
399   {
400     return imageBoxContentList.imageHasAdditionalSettings(idx);
401   }
402 
403   /** sets the polarity for the given registered image box.
404    *  @param idx index, must be < getNumberOfImages()
405    *  @param value new attribute value (NORMAL or REVERSE), may be NULL.
406    *  @return EC_Normal if successful, an error code otherwise.
407    */
setImagePolarity(size_t idx,const char * value)408   OFCondition setImagePolarity(size_t idx, const char *value)
409   {
410     return imageBoxContentList.setImagePolarity(idx, value);
411   }
412 
413   /** sets the requested size for the given registered image box.
414    *  @param idx index, must be < getNumberOfImages()
415    *  @param value new attribute value (in mm), may be NULL.
416    *  @return EC_Normal if successful, an error code otherwise.
417    */
setImageRequestedSize(size_t idx,const char * value)418   OFCondition setImageRequestedSize(size_t idx, const char *value)
419   {
420     return imageBoxContentList.setImageRequestedSize(idx, value);
421   }
422 
423   /** sets the (optional) magnification type for the given registered image box.
424    *  @param idx index, must be < getNumberOfImages()
425    *  @param value new attribute value, may be NULL.
426    *    The caller is responsible for making sure
427    *    that the value is valid for the selected printer.
428    *  @return EC_Normal if successful, an error code otherwise.
429    */
setImageMagnificationType(size_t idx,const char * value)430   OFCondition setImageMagnificationType(size_t idx, const char *value)
431   {
432     return imageBoxContentList.setImageMagnificationType(idx, value);
433   }
434 
435   /** sets the (optional) smoothing type for the given registered image box.
436    *  @param idx index, must be < getNumberOfImages()
437    *  @param value new attribute value, may be NULL.
438    *    The caller is responsible for making sure
439    *    that the value is valid for the selected printer.
440    *  @return EC_Normal if successful, an error code otherwise.
441    */
setImageSmoothingType(size_t idx,const char * value)442   OFCondition setImageSmoothingType(size_t idx, const char *value)
443   {
444     return imageBoxContentList.setImageSmoothingType(idx, value);
445   }
446 
447   /** sets the (optional) configuration information for the given registered image box.
448    *  @param idx index, must be < getNumberOfImages()
449    *  @param value new attribute value, may be NULL.
450    *    The caller is responsible for making sure
451    *    that the value is valid for the selected printer.
452    *  @return EC_Normal if successful, an error code otherwise.
453    */
setImageConfigurationInformation(size_t idx,const char * value)454   OFCondition setImageConfigurationInformation(size_t idx, const char *value)
455   {
456     return imageBoxContentList.setImageConfigurationInformation(idx, value);
457   }
458 
459   /** gets the polarity for the given registered image box.
460    *  @param idx index, must be < getNumberOfImages()
461    *  @return polarity (NORMAL or REVERSE), may be NULL.
462    */
getImagePolarity(size_t idx)463   const char *getImagePolarity(size_t idx)
464   {
465     return imageBoxContentList.getImagePolarity(idx);
466   }
467 
468   /** gets the requested size for the given registered image box.
469    *  @param idx index, must be < getNumberOfImages()
470    *  @return requested size (in mm), may be NULL.
471    */
getImageRequestedSize(size_t idx)472   const char *getImageRequestedSize(size_t idx)
473   {
474     return imageBoxContentList.getImageRequestedSize(idx);
475   }
476 
477   /** gets the (optional) magnification type for the given registered image box.
478    *  @param idx index, must be < getNumberOfImages()
479    *  @return magnification type, may be NULL.
480    */
getImageMagnificationType(size_t idx)481   const char *getImageMagnificationType(size_t idx)
482   {
483     return imageBoxContentList.getImageMagnificationType(idx);
484   }
485 
486   /** gets the (optional) smoothing type for the given registered image box.
487    *  @param idx index, must be < getNumberOfImages()
488    *  @return smoothing type, may be NULL.
489    */
getImageSmoothingType(size_t idx)490   const char *getImageSmoothingType(size_t idx)
491   {
492     return imageBoxContentList.getImageSmoothingType(idx);
493   }
494 
495   /** gets the (optional) configuration information for the given registered image box.
496    *  @param idx index, must be < getNumberOfImages()
497    *  @return configuration information, may be NULL.
498    */
getImageConfigurationInformation(size_t idx)499   const char *getImageConfigurationInformation(size_t idx)
500   {
501     return imageBoxContentList.getImageConfigurationInformation(idx);
502   }
503 
504   /** gets the presentation LUT for the given registered image box.
505    *  If not available the presentation LUT of the film box is used.
506    *  @param idx index, must be < getNumberOfImages()
507    *  @return pointer to presentation LUT, may be NULL.
508    */
509   DVPSPresentationLUT *getImagePresentationLUT(size_t idx);
510 
511   /** gets the "global" presentation LUT which overrides the settings for the image boxes.
512    *  If not available the presentation LUT of the image box is used.
513    *  @return pointer to presentation LUT, may be NULL.
514    */
515   DVPSPresentationLUT *getPresentationLUT();
516 
517   /** resets the Presentation LUT to the default setting. i.e. the presentation LUT
518    *  which is specified separately for each image box is used.
519    *  @return EC_Normal if successful, an error code otherwise.
520    */
521   OFCondition setDefaultPresentationLUT();
522 
523   /** sets the current Presentation LUT shape (overrides the image box settings).
524    *  Only DVPSP_identity and DVPSP_lin_od are allowed.
525    *  @param shape the new presentation LUT shape.
526    *  @return EC_Normal if successful, an error code otherwise.
527    */
528   OFCondition setPresentationLUTShape(DVPSPresentationLUTType shape);
529 
530   /** stores a presentation lookup table in the stored print object.
531    *  This method stores a presentation lookup table in the
532    *  stored print object and activates it. This LUT overrides the
533    *  settings made for the individual image boxes. If unsuccessful,
534    *  LUT is not set.
535    *  @param dset dataset from which the Presentation LUT SQ or Shape is read.
536    *  @return EC_Normal if successful, an error code otherwise.
537    */
538   OFCondition setPresentationLookupTable(DcmItem &dset);
539 
540   /** converts an optical density (OD) value to an 8/12/16-bit P-value which is linear to luminance.
541    *  The output is not calibrated according to the GSDF.  This can be done by convertPValueToDDL() in
542    *  class DVPSPresentationState.  The attributes illumination, reflected ambient light and min/max
543    *  density (default 20/300) from this stored print object are used for the calculation.
544    *  @param density in hundreds of OD (e.g. 150 corressponds to 1.5 OD)
545    *  @param bits number of bits used for the output value (8, 12, 16)
546    *  @return P-Value, 0..0xFF, 0..0xFFF, 0..0xFFFF, < 0 if an error occurred.
547    */
548   Sint32 convertODtoPValue(Uint16 density, unsigned int bits = 8);
549 
550   /** writes the general study and series module attributes for a grayscale hardcopy image
551    *  that is related to this stored print object to a DICOM dataset.
552    *  Copies of the DICOM elements managed by this object are inserted into
553    *  the DICOM dataset.
554    *  @param dset the dataset to which the data is written
555    *  @return EC_Normal if successful, an error code otherwise.
556    */
557   OFCondition writeHardcopyImageAttributes(DcmItem &dset);
558 
559   /** creates a new image box object and sets the content of this image box object.
560    *  @param retrieveaetitle retrieve AETITLE of the referenced image
561    *  @param refstudyuid Study instance UID of the referenced image
562    *  @param refseriesuid Series instance UID of the referenced image
563    *  @param refsopclassuid SOP Class UID of the referenced image
564    *  @param refsopinstanceuid SOP instance UID of the referenced image
565    *  @param requestedimagesize requested images size for this image, may be NULL (absent)
566    *  @param patientid patient ID for the referenced image, may be NULL (absent)
567    *  @param presentationlut presentation LUT to be used, may be NULL (absent)
568    *  @param inversePLUT true if presentation LUT is for Monochrome1 and must be inversed.
569    *  @return EC_Normal if successful, an error code otherwise.
570    */
571   OFCondition addImageBox(
572     const char *retrieveaetitle,
573     const char *refstudyuid,
574     const char *refseriesuid,
575     const char *refsopclassuid,
576     const char *refsopinstanceuid,
577     const char *requestedimagesize,
578     const char *patientid,
579     DVPSPresentationLUT *presentationlut,
580     OFBool inversePLUT);
581 
582   /** creates a new image box object and sets the content of this image box object.
583    *  This is a specialized version of the method with the same name and more parameters.
584    *  SOP Class is assumed to be Grayscale Hardcopy, Study and Series are derived from
585    *  the Stored Print internal defaults.
586    *  @param retrieveaetitle retrieve AETITLE of the referenced image
587    *  @param refsopinstanceuid SOP instance UID of the referenced image
588    *  @param requestedimagesize requested images size for this image, default: absent
589    *  @param patientid patient ID for the referenced image, default: absent
590    *  @param presentationlut presentation LUT to be used, may be NULL (absent)
591    *  @param inversePLUT true if presentation LUT is for Monochrome1 and must be inversed.
592    *  @return EC_Normal if successful, an error code otherwise.
593    */
594   OFCondition addImageBox(
595     const char *retrieveaetitle,
596     const char *refsopinstanceuid,
597     const char *requestedimagesize=NULL,
598     const char *patientid=NULL,
599     DVPSPresentationLUT *presentationlut=NULL,
600     OFBool inversePLUT=OFFalse);
601 
602   /** deletes all existing annotations and creates a new one,
603    *  with given text and position. Sets annotation display format
604    *  to the given value.
605    *
606    *  @param displayformat annotation display format
607    *  @param text annotation text
608    *  @param position annotation position
609    *  @return EC_Normal if successful, an error code otherwise.
610    */
611   OFCondition setSingleAnnotation(
612     const char *displayformat,
613     const char *text,
614     Uint16 position);
615 
616   /** deletes all annotations, clears annotation display format.
617    */
618   void deleteAnnotations();
619 
620   /** sets a new SOP Instance UID for the Stored Print object.
621    *  @param uid new SOP Instance UID
622    *  @return EC_Normal if successful, an error code otherwise.
623    */
624   OFCondition setInstanceUID(const char *uid);
625 
626   /** clears the SOP instance UID for the Stored Print object.
627    *  a new UID is assigned automatically when writing the object.
628    */
clearInstanceUID()629   void clearInstanceUID() { sOPInstanceUID.clear(); }
630 
631   /** returns the image UIDs that are required to look up the referenced image in the database
632    *  @param idx index, must be < getNumberOfImages()
633    *  @param studyUID Study UID of the image
634    *  @param seriesUID series UID of the image
635    *  @param instanceUID instance UID of the image
636    *  @return EC_Normal if successful, an error code otherwise.
637    */
getImageReference(size_t idx,const char * & studyUID,const char * & seriesUID,const char * & instanceUID)638   OFCondition getImageReference(size_t idx, const char *&studyUID, const char *&seriesUID, const char *&instanceUID)
639   {
640     return imageBoxContentList.getImageReference(idx, studyUID, seriesUID, instanceUID);
641   }
642 
643   /** returns a description of the currently activated Presentation LUT (if
644    *  any) in terms of the Presentation LUT matching rule (see description
645    *  of enum type for details).
646    *  @return Presentation LUT alignment
647    */
getReferencedPresentationLUTAlignment()648   DVPSPrintPresentationLUTAlignment getReferencedPresentationLUTAlignment() { return referencedPresentationLUTAlignment; }
649 
650   /** Requests the properties of the printer (Printer SOP Instance N-GET).
651    *  The properties are not returned, but if the message handler is switched to "dump mode",
652    *  the DIMSE communication will be printed.
653    *  @param printHandler print communication handler, association must be open.
654    *  @return EC_Normal upon success, an error code otherwise.
655    */
656   OFCondition printSCUgetPrinterInstance(DVPSPrintMessageHandler& printHandler);
657 
658   /** checks whether a presentation LUT or LUT shape is active in this stored print object.
659    *  In this case, if the printer supports the Presentation LUT SOP class,
660    *  a Presentation LUT SOP Instance is created in the printer.
661    *  @param printHandler print communication handler, association must be open.
662    *  @param printerRequiresMatchingLUT true if printer requires presentation LUTs matching the image depth
663    *  @param printerLUTRenderingPreferred true if SCP side presentation LUTs should be preferred
664    *    even if printer supports 12-bit image transmission.
665    *  @param printerSupports12Bit true if printer supports 12 bit transmission
666    *  @return EC_Normal upon success, an error code otherwise.
667    */
668   OFCondition printSCUpreparePresentationLUT(
669      DVPSPrintMessageHandler& printHandler,
670      OFBool printerRequiresMatchingLUT,
671      OFBool printerLUTRenderingPreferred,
672      OFBool printerSupports12Bit);
673 
674   /** Creates a DICOM Basic Film Session SOP Instance in the printer.
675    *  @param printHandler print communication handler, association must be open.
676    *  @param dset DICOM dataset containing all Basic Film Session attributes managed outside this class
677    *  @param plutInSession true if printer expects referenced presentation LUT sequence, illumination
678    *    and reflected ambient light in basic film session, false if it expects them in basic film box.
679    *  @return EC_Normal upon success, an error code otherwise.
680    */
681   OFCondition printSCUcreateBasicFilmSession(
682     DVPSPrintMessageHandler& printHandler,
683     DcmDataset& dset,
684     OFBool plutInSession);
685 
686   /** Creates a DICOM Basic Film Box SOP Instance in the printer.
687    *  This method only allows one basic film box to exist at any time -
688    *  collation is not supported.
689    *  @param printHandler print communication handler, association must be open.
690    *  @param plutInSession true if printer expects referenced presentation LUT sequence, illumination
691    *    and reflected ambient light in basic film session, false if it expects them in basic film box.
692    *  @return EC_Normal upon success, an error code otherwise.
693    */
694   OFCondition printSCUcreateBasicFilmBox(DVPSPrintMessageHandler& printHandler, OFBool plutInSession);
695 
696   /** Transmits a DICOM image to the printer (Basic Grayscale Image Box N-SET).
697    *  @param printHandler print communication handler, association must be open.
698    *  @param idx index of the image reference from which the Image Box settings are taken,
699    *     must be < getNumberOfImages().
700    *  @param image DICOM image to be printed
701    *  @param useMonochrome1 if true, the image is transmitted in MONOCHROME1 photometric interpretation.
702    *    Default is false, image is transmitted in MONOCHROME2 in this case.
703    *  @return EC_Normal upon success, an error code otherwise.
704    */
705   OFCondition printSCUsetBasicImageBox(
706     DVPSPrintMessageHandler& printHandler,
707     size_t idx,
708     DicomImage& image,
709     OFBool useMonochrome1=OFFalse);
710 
711   /** Transmits a DICOM annotation to the printer (Basic Annotation Box N-SET).
712    *  @param printHandler print communication handler, association must be open.
713    *  @param idx index of the annotation from which the settings are taken,
714    *     must be < getNumberOfAnnotations().
715    *  @return EC_Normal upon success, an error code otherwise.
716    */
717   OFCondition printSCUsetBasicAnnotationBox(
718     DVPSPrintMessageHandler& printHandler,
719     size_t idx);
720 
721   /** Prints the current DICOM Basic Film Box SOP Instance.
722    *  @param printHandler print communication handler, association must be open.
723    *  @return EC_Normal upon success, an error code otherwise.
724    */
725   OFCondition printSCUprintBasicFilmBox(DVPSPrintMessageHandler& printHandler);
726 
727   /** Prints the current DICOM Basic Film Session.
728    *  @param printHandler print communication handler, association must be open.
729    *  @return EC_Normal upon success, an error code otherwise.
730    */
731   OFCondition printSCUprintBasicFilmSession(DVPSPrintMessageHandler& printHandler);
732 
733   /** Deletes all objects currently present in the print association.
734    *  @param printHandler print communication handler, association must be open.
735    *  @return EC_Normal upon success, an error code otherwise.
736    */
737   OFCondition printSCUdelete(DVPSPrintMessageHandler& printHandler);
738 
739   /** sets the illumination to be used
740    *  with the print Presentation LUT SOP Class.
741    *  @param value new attribute value, in cd/m2.
742    *    The caller is responsible for making sure
743    *    that the value is valid for the selected printer.
744    *  @return EC_Normal if successful, an error code otherwise.
745    */
746   OFCondition setPrintIllumination(Uint16 value);
747 
748   /** gets the current illumination setting
749    *  used with the print Presentation LUT SOP Class.
750    *  @return illumination in cd/m2
751    */
752   Uint16 getPrintIllumination();
753 
754   /** sets the reflected ambient light to be used
755    *  with the print Presentation LUT SOP Class.
756    *  @param value new attribute value, in cd/m2.
757    *    The caller is responsible for making sure
758    *    that the value is valid for the selected printer.
759    *  @return EC_Normal if successful, an error code otherwise.
760    */
761   OFCondition setPrintReflectedAmbientLight(Uint16 value);
762 
763   /** gets the current reflected ambient light setting
764    *  used with the print Presentation LUT SOP Class.
765    *  @return reflected ambient light in cd/m2
766    */
767   Uint16 getPrintReflectedAmbientLight();
768 
769   /** performs a Print SCP Basic Film Box N-CREATE operation on a newly
770    *  created instance of this class. The results of the operation are
771    *  stored in the objects passed as rsp, rspDataset and
772    *  globalPresentationLUTList.
773    *  @param cfg config file facility
774    *  @param cfgname symbolic printer name in config file
775    *  @param rqDataset N-CREATE request dataset, may be NULL
776    *  @param rsp N-CREATE response message
777    *  @param rspDataset N-CREATE response dataset passed back in this parameter
778    *  @param presentationLUTnegotiated
779    *    OFTrue if support for the Presentation LUT SOP class
780    *    has been negotiated at association negotiation and is supported on
781    *    Basic Film Box level
782    *  @param globalPresentationLUTList
783    *    list of presentation LUTs managed by the Print SCP.
784    *    If a SCP default Presentation LUT needs to be created as the result
785    *    of the N-CREATE operation, it is stored in this list.
786    *  @param filmSessionUID
787    *    SOP instance UID of the Basic Film Session object
788    *  @param study study UID to be used when storing Stored Print or image objects
789    *  @param psSeries series UID to be used when storing Stored Print objects
790    *  @param imgSeries series UID to be used when storing image objects (Hardcopy Grayscale)
791    *  @return OFTrue if N-CREATE was successful, OFFalse otherwise.
792    */
793   OFBool printSCPCreate(
794     DVConfiguration& cfg,
795     const char *cfgname,
796     DcmDataset *rqDataset,
797     T_DIMSE_Message& rsp,
798     DcmDataset *& rspDataset,
799     OFBool presentationLUTnegotiated,
800     DVPSPresentationLUT_PList& globalPresentationLUTList,
801     const char *filmSessionUID,
802     DcmUniqueIdentifier& study,
803     DcmUniqueIdentifier& psSeries,
804     DcmUniqueIdentifier& imgSeries);
805 
806   /** performs a Print SCP Basic Film Box N-SET operation on an instance of
807    *  this class. The results of the N-SET operation are stored in the
808    *  objects passed as rsp and rspDataset.
809    *  @param cfg config file facility
810    *  @param cfgname symbolic printer name in config file
811    *  @param rqDataset N-SET request dataset
812    *  @param rsp N-SET response message
813    *  @param rspDataset N-SET response dataset passed back in this parameter
814    *  @param presentationLUTnegotiated
815    *    OFTrue if support for the Presentation LUT SOP class
816    *    has been negotiated at association negotiation and is supported on
817    *    Basic Film Box level
818    *  @param globalPresentationLUTList
819    *    list of presentation LUTs managed by the Print SCP
820    *  @return OFTrue if N-SET was successful, OFFalse otherwise.
821    */
822   OFBool printSCPSet(
823     DVConfiguration& cfg,
824     const char *cfgname,
825     DcmDataset *rqDataset,
826     T_DIMSE_Message& rsp,
827     DcmDataset *& rspDataset,
828     OFBool presentationLUTnegotiated,
829     DVPSPresentationLUT_PList& globalPresentationLUTList);
830 
831   /** checks whether the given UID string matches the film box UID.
832    *  @param c uid to be compared
833    *  @return OFTrue if equal, OFFalse otherwise
834    */
isFilmBoxInstance(const char * c)835   OFBool isFilmBoxInstance(const char *c) { if (c && (filmBoxInstanceUID == c)) return OFTrue; else return OFFalse; }
836 
837   /** checks whether the Presentation LUT with the given UID
838    *  is referenced by this Stored Print object on the film box level.
839    *  Presentation LUT references on Image Box level are ignored.
840    *  @param c uid to be compared
841    *  @return OFTrue if equal, OFFalse otherwise
842    */
843   OFBool usesPresentationLUT(const char *c);
844 
845   /** looks up the image box with the given SOP instance UID in the image box list
846    *  and returns a pointer to a new object containing a copy of this
847    *  image box. If the object is not found, NULL is returned.
848    *  @param uid SOP instance UID of the image box to be looked up
849    *  @return pointer to copied image box object, may be NULL.
850    */
duplicateImageBox(const char * uid)851   DVPSImageBoxContent *duplicateImageBox(const char *uid) { return imageBoxContentList.duplicateImageBox(uid); }
852 
853   /** checks whether any of the image boxes managed by the image box list
854    *  has the same position as the given one, but a different
855    *  SOP instance UID.  This is used during a Print SCP basic grayscale
856    *  image box N-SET operation to check whether an image position clash exists.
857    *  @param uid SOP instance UID of the image box to be looked up
858    *  @param position image position to be looked up
859    */
haveImagePositionClash(const char * uid,Uint16 position)860   OFBool haveImagePositionClash(const char *uid, Uint16 position)  { return imageBoxContentList.haveImagePositionClash(uid, position); }
861 
862   /** adds the given image box object to the image box list.
863    *  Any other object existing in the list with the same SOP instance UID is removed.
864    *  Used during a Print SCP basic grayscale image box N-SET operation.
865    *  @param newImageBox new image box object to be added to the list.
866    */
replaceImageBox(DVPSImageBoxContent * newImageBox)867   void replaceImageBox(DVPSImageBoxContent *newImageBox) { imageBoxContentList.replace(newImageBox); }
868 
869   /** updates the list of Presentation LUTs managed by the Stored Print object
870    *  from a global list. If a Presentation LUT is active on Film Box level, the corresponding
871    *  LUT is copied from the global presentation LUT list.
872    *  Presentation LUT references on Image Box level are ignored.
873    *  Used during a Print SCP N-ACTION operation.
874    *  @param globalPresentationLUTList list of presentation LUTs managed by the Print SCP
875    */
876   void updatePresentationLUTList(DVPSPresentationLUT_PList& globalPresentationLUTList);
877 
878   /** checks whether the given Presentation LUT type could be used together
879    *  with all image boxes in this film box on a Print SCP that requires a matching
880    *  alignment between a Presentation LUT and the image pixel data.
881    *  @param align LUT alignment type
882    *  @return OFTrue if matching, OFFalse otherwise
883    */
matchesPresentationLUT(DVPSPrintPresentationLUTAlignment align)884   OFBool matchesPresentationLUT(DVPSPrintPresentationLUTAlignment align) const
885   {
886     return imageBoxContentList.matchesPresentationLUT(align);
887   }
888 
889   /** replaces the settings for illumination, reflected ambient light and
890    *  referenced Presentation LUT in this film box.
891    *  Used by a Print SCP if Presentation LUT is implemented on Film Session
892    *  level.
893    *  @param newIllumination new value for illumination
894    *  @param newReflectedAmbientLight new value for reflectedAmbientLight
895    *  @param newReferencedPLUT new value for referenced presentation LUT instance UID
896    *  @param newAlignment new alignment type of active presentation LUT
897    */
898   void overridePresentationLUTSettings(
899       DcmUnsignedShort& newIllumination,
900       DcmUnsignedShort& newReflectedAmbientLight,
901       DcmUniqueIdentifier& newReferencedPLUT,
902       DVPSPrintPresentationLUTAlignment newAlignment);
903 
904   /** checks whether any of the image boxes has an image box position
905    *  assigned. If no image box position is assigned, the stored print object
906    *  cannot be written and a Print SCP should return a warning
907    *  status upon receipt of an N-ACTION request.
908    *  @return OFTrue if empty page (no image box position assigned), OFFalse otherwise.
909    */
emptyPageWarning()910   OFBool emptyPageWarning() { return imageBoxContentList.emptyPageWarning(); }
911 
912  private:
913 
914   /// private undefined assignment operator
915   DVPSStoredPrint& operator=(const DVPSStoredPrint&);
916 
917   /* checks if given SOP class UID is an image storage SOP class
918    * @return OFTrue if image SOP class, OFFalse otherwise.
919    */
920   OFBool isImageStorageSOPClass(OFString& sopclassuid);
921 
922   /** create default values for all missing type 1 elements.
923    *  Called before a stored print object is written.
924    *  @return EC_Normal if successful, an error code otherwise.
925    */
926   OFCondition createDefaultValues();
927 
928   /** writes a Referenced Presentation LUT SQ to the given
929    *  dataset. Helper function used in the more general write() method.
930    *  @param dset the dataset to which the data is written
931    *  @return EC_Normal if successful, an error code otherwise.
932    */
933   OFCondition addReferencedPLUTSQ(DcmItem &dset);
934 
935   /** writes a Referenced Presentation LUT SQ, Illumination and
936    *  reflected ambient light to the given dataset.
937    *  Helper function used when creating Basic Film Session or
938    *  Basic Film Box.
939    *  @param dset the dataset to which the data is written
940    *  @return EC_Normal if successful, an error code otherwise.
941    */
942   OFCondition addPresentationLUTReference(DcmItem& dset);
943 
944   /** invalidates the cached number of columns and rows
945    */
946   void invalidateCache();
947 
948   /** updates the cached number of columns and rows
949    */
950   void updateCache();
951 
952   /* Module: Patient (M)
953    */
954   /// Module=Patient, VR=PN, VM=1, Type 1
955   DcmPersonName            patientName;
956   /// Module=Patient, VR=LO, VM=1, Type 2
957   DcmLongString            patientID;
958   /// Module=Patient, VR=DA, VM=1, Type 2
959   DcmDate                  patientBirthDate;
960   /// Module=Patient, VR=CS, VM=1, Type 2
961   DcmCodeString            patientSex;
962 
963   /* Module: General Study (M)
964    */
965   /// Module=General_Study, VR=UI, VM=1, Type 1
966   DcmUniqueIdentifier      studyInstanceUID;
967   /// Module=General_Study, VR=DA, VM=1, Type 2
968   DcmDate                  studyDate;
969   /// Module=General_Study, VR=TM, VM=1, Type 2
970   DcmTime                  studyTime;
971   /// Module=General_Study, VR=PN, VM=1, Type 2
972   DcmPersonName            referringPhysicianName;
973   /// Module=General_Study, VR=SH, VM=1, Type 2
974   DcmShortString           studyID;
975   /// Module=General_Study, VR=SH, VM=1, Type 2
976   DcmShortString           accessionNumber;
977 
978   /* Module: General Series (M)
979    */
980   /// Module=General_Series, VR=UI, VM=1, Type 1
981   DcmUniqueIdentifier      seriesInstanceUID;
982   /// Module=General_Series, VR=IS, VM=1, Type 2
983   DcmIntegerString         seriesNumber;
984 
985   /* Module: General Equipment (M)
986    */
987   /// Module=General_Equipment, VR=LO, VM=1, Type 2
988   DcmLongString            manufacturer;
989 
990   /* Module: Printer Characteristics (M)
991    */
992   // the PrintManagementCapabilitiesSequence is only created/checked on the fly
993 
994   // PrinterCharacteristicsSequence
995   /// Module=Printer_Characteristics_Module, VR=AE, VM=1, Type 2
996   DcmApplicationEntity     originator;
997   /// Module=Printer_Characteristics_Module, VR=AE, VM=1, Type 2
998   DcmApplicationEntity     destination;
999   /// Module=Printer_Characteristics_Module, VR=LO, VM=1, Type 3
1000   DcmLongString            printerName;
1001 
1002   /* Module: Film Box (M)
1003    */
1004   /// Module=Film_Box_Module, VR=IS, VM=1, Type 2
1005   DcmIntegerString         instanceNumber;
1006   /* the following attributes belong to the Film Box Content SQ (Type 1) */
1007   /// Module=Film_Box_Module, VR=ST, VM=1, Type 1
1008   DcmShortText             imageDisplayFormat;
1009   /// Module=Film_Box_Module, VR=CS, VM=1, Type 3
1010   DcmCodeString            annotationDisplayFormatID;
1011   /// Module=Film_Box_Module, VR=CS, VM=1, Type 2
1012   DcmCodeString            filmOrientation;
1013   /// Module=Film_Box_Module, VR=CS, VM=1, Type 2
1014   DcmCodeString            filmSizeID;
1015   /// Module=Film_Box_Module, VR=CS, VM=1, Type 2
1016   DcmCodeString            magnificationType;
1017   /// Module=Film_Box_Module, VR=CS, VM=1, Type 3
1018   DcmCodeString            smoothingType;
1019   /// Module=Film_Box_Module, VR=CS, VM=1, Type 3
1020   DcmCodeString            borderDensity;
1021   /// Module=Film_Box_Module, VR=CS, VM=1, Type 3
1022   DcmCodeString            emptyImageDensity;
1023   /// Module=Film_Box_Module, VR=US, VM=1, Type 3
1024   DcmUnsignedShort         minDensity;
1025   /// Module=Film_Box_Module, VR=US, VM=1, Type 2
1026   DcmUnsignedShort         maxDensity;
1027   /// Module=Film_Box_Module, VR=CS, VM=1, Type 3
1028   DcmCodeString            trim;
1029   /// Module=Film_Box_Module, VR=ST, VM=1, Type 2
1030   DcmShortText             configurationInformation;
1031   /// Module=Film_Box_Module, VR=US, VM=1, Type 2c required if presentation SOP class present
1032   DcmUnsignedShort         illumination;
1033   /// Module=Film_Box_Module, VR=US, VM=1, Type 2c required if presentation SOP class present
1034   DcmUnsignedShort         reflectedAmbientLight;
1035   /// Module=Film_Box_Module (Supplement 38), VR=CS, VM=1, Type 3
1036   DcmCodeString            requestedResolutionID;
1037   /// the ReferencedPresentationLUTSequence is only created/read on the fly
1038   DcmUniqueIdentifier      referencedPresentationLUTInstanceUID;
1039 
1040   /** The Print SCP can be configured to enforce a rule requiring that the
1041    *  number of entries in a Presentation LUT matches the bit depth of the
1042    *  image pixel data. This member variable describes the type of the
1043    *  current presentation LUT (if any).
1044    */
1045   DVPSPrintPresentationLUTAlignment referencedPresentationLUTAlignment;
1046 
1047   /* Module: Image Box List (M)
1048    */
1049   /// Module=Image_Box_List_Module, VR=SQ, VM=1, Type 1
1050   DVPSImageBoxContent_PList imageBoxContentList;
1051 
1052   /* Module: Annotation List (U)
1053    */
1054   /// Module=Annotation_List_Module, VR=SQ, VM=1, Type 3
1055   DVPSAnnotationContent_PList annotationContentList;
1056 
1057   /* Module: Presentation LUT List (U)
1058    */
1059   DVPSPresentationLUT_PList presentationLUTList;
1060 
1061   /* Module: SOP Common (M)
1062    * we don't store the SOP Class UID because it is well known.
1063    */
1064   /// Module=SOP_Common, VR=UI, VM=1, Type 1
1065   DcmUniqueIdentifier      sOPInstanceUID;
1066   /// Module=SOP_Common, VR=CS, VM=1-n, Type 1C
1067   DcmCodeString            specificCharacterSet;
1068   /// Module=SOP_Common, VR=DA, VM=1, Type 3
1069   DcmDate                  instanceCreationDate;
1070   /// Module=SOP_Common, VR=TM, VM=1, Type 3
1071   DcmTime                  instanceCreationTime;
1072 
1073   /// used when creating hardcopy image objects
1074   DcmUniqueIdentifier      imageSeriesInstanceUID;
1075 
1076   /// flag indicating whether the currentXX values are up to date
1077   OFBool currentValuesValid;
1078   /// current number of columns
1079   unsigned long currentNumCols;
1080   /// current number of rows
1081   unsigned long currentNumRows;
1082 
1083   /// requested decimate/crop behaviour used in all image boxes
1084   DVPSDecimateCropBehaviour decimateCropBehaviour;
1085 
1086   /// the current film session instance
1087   OFString filmSessionInstanceUID;
1088 
1089   /// the current film box instance
1090   OFString filmBoxInstanceUID;
1091 
1092   /** the current presentation LUT instance. If used as Print SCU, the
1093    *  content of this string can differ from referencedPresentationLUTInstanceUID
1094    *  which contains the UID from the Stored Print object wheras this
1095    *  string contains the UID assigned by the remote Print SCP.
1096    *  If used as Print SCP, these strings should always be equal.
1097    */
1098   OFString presentationLUTInstanceUID;
1099 
1100   /// stores the "global" presentation LUT that overrides the image box LUTs (optional)
1101   DVPSPresentationLUT globalPresentationLUT;
1102 
1103   /// flag indicating whether the globalPresentationLUT is currently valid or not
1104   OFBool globalPresentationLUTValid;
1105 
1106   /// transmit images in 12 bit for the current print job
1107   OFBool transmitImagesIn12Bit;
1108 
1109   /// presentation LUTs are rendered on SCP side
1110   OFBool renderPresentationLUTinSCP;
1111 
1112   /// temporary buffer for getMaxDensity and getMinDensity
1113   OFString tempDensity;
1114 
1115 };
1116 
1117 #endif
1118