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: DVPSPresentationLUT
20  *
21  */
22 
23 #ifndef DVPSPL_H
24 #define DVPSPL_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/dcvrus.h"
30 #include "dcmtk/dcmdata/dcvrui.h"
31 #include "dcmtk/dcmdata/dcvrlo.h"
32 
33 struct T_DIMSE_Message;
34 
35 class DicomImage;
36 class DiLookupTable;
37 class DcmDataset;
38 
39 /** the representation of a Presentation LUT Content SQ item for Stored Print
40  */
41 
42 class DCMTK_DCMPSTAT_EXPORT DVPSPresentationLUT
43 {
44 public:
45   /// default constructor
46   DVPSPresentationLUT();
47 
48   /// copy constructor
49   DVPSPresentationLUT(const DVPSPresentationLUT& copy);
50 
51   /** clone method.
52    *  @return a pointer to a new DVPSPresentationLUT object containing
53    *  a copy of this object.
54    */
clone()55   DVPSPresentationLUT *clone() { return new DVPSPresentationLUT(*this); }
56 
57   /// destructor
58   virtual ~DVPSPresentationLUT();
59 
60   /** resets the object to initial state.
61    *  After this call, the object is in the same state as after
62    *  creation with the default constructor.
63    */
64   void clear();
65 
66   /** reads an Presentation LUT from a DICOM dataset.
67    *  The DICOM elements of the referenced item are copied
68    *  from the dataset to this object.
69    *  The completeness of the item (presence of all required elements,
70    *  value multiplicity) is checked.
71    *  If this method returns an error code, the object is in undefined state afterwards.
72    *  @param dset the item of the PresentationLUTContentSequence from which the data is to be read
73    *  @param withSOPInstance true if SOPinstanceUID should be read (when used with Stored Print).
74    *  @return EC_Normal if successful, an error code otherwise.
75    */
76   OFCondition read(DcmItem &dset, OFBool withSOPInstance);
77 
78   /** writes the Presentation LUT managed by this object to a DICOM dataset.
79    *  Copies of the DICOM element managed by this object are inserted into
80    *  the DICOM dataset.
81    *  @param dset the the item of the PresentationLUTContentSequence to which the data is written
82    *  @param withSOPInstance true if SOPinstanceUID should be written (when used with Stored Print).
83    *  @return EC_Normal if successful, an error code otherwise.
84    */
85   OFCondition write(DcmItem &dset, OFBool withSOPInstance);
86 
87   /** checks whether current presentation LUT is inverse, i.e.
88    *  shape is INVERSE or first LUT entry larger than last LUT entry.
89    */
90   OFBool isInverse();
91 
92   /** gets the current Presentation LUT type.
93    *  @return the current presentation LUT type
94    */
getType()95   DVPSPresentationLUTType getType() { return presentationLUT; }
96 
97   /** gets a description of the Presentation LUT in terms of
98    *  its restrictions for use with a Print SCP that requires
99    *  Presentation LUT number of entries to match the bit depth
100    *  of the image pixel data.
101    *  @return the current presentation LUT alignment type
102    */
103   DVPSPrintPresentationLUTAlignment getAlignment();
104 
105   /** checks if a real Presentation LUT (not shape) is available.
106    *  @return OFTrue if this object contains
107    *    a presentation LUT, no matter if it is activated or not.
108    *    Returns OFFalse otherwise.
109    */
110   OFBool haveTable();
111 
112   /** gets a description of the current presentation LUT.
113    *  For well-known presentation LUT shapes, a standard text
114    *  is returned. For presentation LUTs, the LUT explanation
115    *  is returned if it exists and a standard text otherwise.
116    *  This method never returns NULL.
117    *  @return a pointer to a string describing the current presentation LUT.
118    */
119   const char *getCurrentExplanation();
120 
121   /** returns the LUT explanation of the presentation LUT if it exists and is non-empty.
122    *  Otherwise returns NULL.
123    *  @return a string pointer
124    */
125   const char *getLUTExplanation();
126 
127   /** returns the SOP instance UID of the presentation LUT if present.
128    *  Otherwise returns NULL.
129    *  @return a string pointer
130    */
131   const char *getSOPInstanceUID();
132 
133   /** stores a presentation lookup table and activates it.
134    *  The LUT is copied. If the method returns EC_Normal,
135    *  any old presentation LUT is overwritten.
136    *  If the method returns an error code, an old LUT is left unchanged.
137    *  @param lutDescriptor the LUT Descriptor in DICOM format (VM=3)
138    *  @param lutData the LUT Data in DICOM format
139    *  @param lutExplanation the LUT Explanation in DICOM format, may be empty.
140    *  @return EC_Normal if successful, an error code otherwise.
141    */
142   OFCondition setLUT(
143     DcmUnsignedShort& lutDescriptor,
144     DcmUnsignedShort& lutData,
145     DcmLongString& lutExplanation);
146 
147   /** sets the current Presentation LUT type.
148    *  DVPSP_table can only be used if the object
149    *  contains a lookup table, i.e. if haveTable() returns OFTrue.
150    *  @param newType the new presentation LUT type.
151    *  @return EC_Normal if successful, an error code otherwise.
152    */
153   OFCondition setType(DVPSPresentationLUTType newType);
154 
155   /** inverts presentation LUT or presentation state LUT shape.
156    *  @return EC_Normal upon success, an error code otherwise.
157    */
158   OFCondition invert();
159 
160   /** activates the current presentation transform in the given DicomImage.
161    *  @param image the DicomImage for which the presentation transform is to be set.
162    *  @param printLUT OFTrue if presentation LUT is activated for print bitmap rendering
163    *    (in this case there is no implicit scaling of the input width of the LUT and,
164    *    therefore, the VOI transformation - which is absent for print - is used),
165    *    OFFalse otherwise (softcopy rendering, default)
166    *  @return OFTrue if successful, OFFalse otherwise.
167    */
168   OFBool activate(DicomImage *image, OFBool printLUT = OFFalse);
169 
170   /** activates the inverse LUT of the current presentation LUT (if any) in the given DicomImage.
171    *  Presentation LUT shape is not supported by this method.
172    *  @param image the DicomImage for which the inverse presentation LUT is to be set.
173    *  @return OFTrue if successful, OFFalse otherwise.
174    */
175   OFBool activateInverseLUT(DicomImage *image);
176 
177   /** creates a DiLookupTable instance from the LUT table
178    *  managed by this object. The returned object must be freed by the caller.
179    *  @return new DiLookupTable object, may be NULL if no LUT present.
180    */
181   DiLookupTable *createDiLookupTable();
182 
183   /** compares a DiLookupTable instance with the LUT table
184    *  managed by this object. Returns OFTrue if equal, OFFalse otherwise.
185    *  @param lut DiLookupTable object to compare with
186    *  @return comparison, true if equal
187    */
188   OFBool compareDiLookupTable(DiLookupTable *lut);
189 
190   /** sets the SOP instance UID.
191    *  @param value new attribute value, must not be NULL.
192    *  @return EC_Normal if successful, an error code otherwise.
193    */
194   OFCondition setSOPInstanceUID(const char *value);
195 
196   /** checks whether the current Presentation LUT (or shape) is
197    *  legal when used with Supplement 22.
198    *  @return true if current Presentation LUT is legal for print.
199    */
200   OFBool isLegalPrintPresentationLUT();
201 
202   /** checks whether the current Presentation LUT (or shape)
203    *  matches the current image bit depth in number of entries and first value mapped.
204    *  @param is12bit true if the image is 12 bit, false if the image is 8 bit
205    *  @return true if Presentation LUT matches, false otherwise.
206    */
207   OFBool matchesImageDepth(OFBool is12bit);
208 
209   /** performs a Print SCP N-CREATE operation on a newly created instance of
210    *  this class. The results of the operation are stored in the objects
211    *  passed as rsp and rspDataset.
212    *  @param rqDataset N-CREATE request dataset, may be NULL
213    *  @param rsp N-CREATE response message
214    *  @param rspDataset N-CREATE response dataset passed back in this parameter
215    *  @param matchRequired boolean flag specifying whether the SCP should
216    *    enforce a rule that all Presentation LUTs must match with the
217    *    bit depth of the image pixel data.
218    *  @param supports12Bit boolean flag specifying whether the SCP should
219    *    allow 12 bit/pixel image data transmission. Affects handling of
220    *    matching rule.
221    *  @return OFTrue if operation was successful, OFFalse otherwise.
222    */
223   OFBool printSCPCreate(
224     DcmDataset *rqDataset,
225     T_DIMSE_Message& rsp,
226     DcmDataset *& rspDataset,
227     OFBool matchRequired,
228     OFBool supports12Bit);
229 
230 private:
231   /// private undefined assignment operator
232   DVPSPresentationLUT& operator=(const DVPSPresentationLUT&);
233 
234   /// describes active type of presentation LUT.
235   DVPSPresentationLUTType  presentationLUT;
236   /// Module=Softcopy_Presentation_LUT, VR=xs, VM=3, Type 1c
237   DcmUnsignedShort         presentationLUTDescriptor;
238   /// Module=Softcopy_Presentation_LUT, VR=LO, VM=1, Type 3
239   DcmLongString            presentationLUTExplanation;
240   /// Module=Softcopy_Presentation_LUT, VR=xs, VM=1-n, Type 1c
241   DcmUnsignedShort         presentationLUTData;
242 
243   /// Module=Presentation_LUT_List, VR=UI, VM=1, Type 1
244   DcmUniqueIdentifier      sOPInstanceUID;
245 
246 };
247 
248 #endif
249