1 /*=========================================================================
4 Module: $RCSfile: PrintFile.cxx,v $
6 Date: $Date: 2005/06/22 08:37:54 $
7 Version: $Revision: 1.41 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmSeqEntry.h"
20 #include "gdcmSQItem.h"
21 #include "gdcmBinEntry.h"
23 #include "gdcmFileHelper.h"
24 #include "gdcmDebug.h"
26 #include "gdcmArgMgr.h"
31 void ShowLutData(gdcm::File *e1);
33 void ShowLutData(gdcm::File *e1)
35 // Nothing is written yet to get LUT Data user friendly
36 // The following is to be moved into a PixelReadConvert method
37 // Let here, waiting for a clever idea on the way to do it.
39 gdcm::SeqEntry *modLutSeq = e1->GetSeqEntry(0x0028,0x3000);
42 gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem();
45 std::string lutDescriptor = sqi->GetEntryValue(0x0028,0x3002);
46 if ( /*lutDescriptor == GDCM_UNFOUND*/ 0 )
48 //gdcmWarningMacro( "LUT Descriptor is missing" );
49 std::cout << "LUT Descriptor is missing" << std::endl;
52 int length; // LUT length in Bytes
53 int deb; // Subscript of the first Lut Value
54 int nbits; // Lut item size (in Bits)
56 int nbRead; // nb of items in LUT descriptor (must be = 3)
58 nbRead = sscanf( lutDescriptor.c_str(),
60 &length, &deb, &nbits );
61 std::cout << "length " << length
67 //gdcmWarningMacro( "Wrong LUT descriptor" );
68 std::cout << "Wrong LUT descriptor" << std::endl;
70 //LUT Data (CTX dependent)
71 gdcm::BinEntry *b = sqi->GetBinEntry(0x0028,0x3006);
74 int BitsAllocated = e1->GetBitsAllocated();
75 if ( BitsAllocated <= 8 )
78 if ( ( nbits == 16 ) && ( BitsAllocated == 8 ) )
80 // when LUT item size is different than pixel size
81 mult = 2; // high byte must be = low byte
85 // See PS 3.3-2003 C.11.1.1.2 p 619
88 uint8_t *lut = b->GetBinArea();
89 for( int i=0; i < length; ++i )
91 std::cout << i+deb << " : \t"
92 << (int) (lut[i*mult + 1]) << std::endl;
97 uint16_t *lut = (uint16_t *)(b->GetBinArea());
98 for( int i=0; i < length; ++i )
100 std::cout << i+deb << " : \t"
101 << (int) (((uint16_t *)lut)[i])
107 std::cout << "No LUT Data BinEntry (0x0028,0x3006) found?!? "
111 std::cout << "No First SQ Item within (0x0028,0x3000) ?!? "
115 std::cout << "No LUT Data SeqEntry (0x0028,0x3000) found "
120 int main(int argc, char *argv[])
124 " \n PrintFile : \n",
125 " Display the header of a ACR-NEMA/PAPYRUS/DICOM File",
126 " usage: PrintFile filein=fileName [level=n] [noshadow] [noseq] [debug] ",
127 " level = 0,1,2 : depending on the amount of details user wants to see",
128 " noshadow : user doesn't want to load Private groups (odd number)",
129 " noseq : user doesn't want to load Sequences ",
130 " debug : user wants to run the program in 'debug mode' ",
131 " showlut : user wants to display the Palette Color (as an int array)",
134 // Initialize Arguments Manager
135 gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
139 am->ArgMgrUsage(usage); // Display 'usage'
144 char *fileName = am->ArgMgrWantString("filein",usage);
147 if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
148 loadMode = NO_SEQ | NO_SHADOW;
149 else if ( am->ArgMgrDefined("noshadow") )
150 loadMode = NO_SHADOW;
151 else if ( am->ArgMgrDefined("noseq") )
156 int level = am->ArgMgrGetInt("level", 2);
158 if (am->ArgMgrDefined("debug"))
159 gdcm::Debug::DebugOn();
161 bool showlut = ( 0 != am->ArgMgrDefined("SHOWLUT") );
163 /* if unused Param we give up */
164 if ( am->ArgMgrPrintUnusedLabels() )
166 am->ArgMgrUsage(usage);
171 delete am; // we don't need Argument Manager any longer
173 // ----------- End Arguments Manager ---------
175 // gdcm::File::IsReadable() is no usable here, because we deal with
176 // any kind of gdcm-Parsable *document*
177 // not only gdcm::File (as opposed to gdcm::DicomDir)
179 gdcm::File *e1 = new gdcm::File();
180 e1->SetLoadMode(loadMode);
182 bool res = e1->Load( fileName );
189 gdcm::FileHelper *f1 = new gdcm::FileHelper(e1);
190 f1->SetPrintLevel( level );
194 std::cout << "\n\n" << std::endl;
196 std::cout <<std::endl;
197 std::cout <<" dataSize " << f1->GetImageDataSize() << std::endl;
198 std::cout <<" dataSizeRaw " << f1->GetImageDataRawSize() << std::endl;
200 int nX,nY,nZ,sPP,planarConfig;
201 std::string pixelType;
205 std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
207 pixelType = e1->GetPixelType();
208 sPP = e1->GetSamplesPerPixel();
209 planarConfig = e1->GetPlanarConfiguration();
211 std::cout << " pixelType= [" << pixelType
212 << "] SamplesPerPixel= [" << sPP
213 << "] PlanarConfiguration= [" << planarConfig
215 << " PhotometricInterpretation= ["
216 << e1->GetEntryValue(0x0028,0x0004)
219 int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
220 std::cout << " NumberOfScalarComponents = " << numberOfScalarComponents
222 << " LUT = " << (e1->HasLUT() ? "TRUE" : "FALSE")
225 if ( e1->GetEntryValue(0x0002,0x0010) == gdcm::GDCM_NOTLOADED )
227 std::cout << "Transfer Syntax not loaded. " << std::endl
228 << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
233 std::string transferSyntaxName = e1->GetTransferSyntaxName();
234 std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]"
236 std::cout << " SwapCode= " << e1->GetSwapCode() << std::endl;
238 // Display the LUT as an int array (for debugging purpose)
239 if ( e1->HasLUT() && showlut )
241 uint8_t* lutrgba = f1->GetLutRGBA();
244 std::cout << "Lut RGBA (Palette Color) not built " << std::endl;
246 // Nothing is written yet to get LUT Data user friendly
247 // The following is to be moved into a PixelRedaConvert method
249 gdcm::SeqEntry *modLutSeq = e1->GetSeqEntry(0x0028,0x3000);
252 gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem();
255 std::string lutDescriptor = sqi->GetEntryValue(0x0028,0x3002);
256 int length; // LUT length in Bytes
257 int deb; // Subscript of the first Lut Value
258 int nbits; // Lut item size (in Bits)
259 int nbRead; // nb of items in LUT descriptor (must be = 3)
261 nbRead = sscanf( lutDescriptor.c_str(),
263 &length, &deb, &nbits );
266 //gdcmWarningMacro( "Wrong LUT descriptor" );
267 std::cout << "Wrong LUT descriptor" << std::endl;
269 gdcm::BinEntry *b = sqi->GetBinEntry(0x0028,0x3006);
272 if ( b->GetLength() != 0 )
274 std::cout << "---------------------------------------"
275 << " We should never reach this point "
277 //LoadEntryBinArea(b); //LUT Data (CTX dependent)
283 std::cout << "No LUT Data (0x0028,0x3000) found " << std::endl;
287 if ( f1->GetLutItemSize() == 8 )
289 for (int i=0;i<f1->GetLutItemNumber();i++)
290 std::cout << i << " : \t"
291 << (int)(lutrgba[i*4]) << " "
292 << (int)(lutrgba[i*4+1]) << " "
293 << (int)(lutrgba[i*4+2]) << std::endl;
295 else // LutItemSize assumed to be = 16
297 uint16_t* lutrgba16 = (uint16_t*)lutrgba;
298 for (int i=0;i<f1->GetLutItemNumber();i++)
299 std::cout << i << " : \t"
300 << (int)(lutrgba16[i*4]) << " "
301 << (int)(lutrgba16[i*4+1]) << " "
302 << (int)(lutrgba16[i*4+2]) << std::endl;
308 std::cout << "Try LUT Data "<< std::endl;
312 if (e1->IsReadable())
313 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
315 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
316 std::cout<<std::flush;