1 /*=========================================================================
4 Module: $RCSfile: PrintFile.cxx,v $
6 Date: $Date: 2005/07/05 13:26:32 $
7 Version: $Revision: 1.44 $
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 *f);
33 void ShowLutData(gdcm::File *f)
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 = f->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 = f->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] [noshadowseq][noshadow][noseq][debug] ",
127 " level = 0,1,2 : depending on the amount of details user wants to see",
128 " noshadowseq: user doesn't want to load Private Sequences",
129 " noshadow : user doesn't want to load Private groups (odd number)",
130 " noseq : user doesn't want to load Sequences ",
131 " debug : user wants to run the program in 'debug mode' ",
132 " showlut :user wants to display the Palette Color (as an int array)",
135 // Initialize Arguments Manager
136 gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
138 if (argc == 1 || am->ArgMgrDefined("usage") )
140 am->ArgMgrUsage(usage); // Display 'usage'
145 char *fileName = am->ArgMgrWantString("filein",usage);
147 int loadMode = 0x00000000;
148 if ( am->ArgMgrDefined("noshadowseq") )
149 loadMode |= NO_SHADOWSEQ;
152 if ( am->ArgMgrDefined("noshadow") )
153 loadMode |= NO_SHADOW;
154 if ( am->ArgMgrDefined("noseq") )
158 int level = am->ArgMgrGetInt("level", 2);
160 bool showlut = ( 0 != am->ArgMgrDefined("SHOWLUT") );
162 if (am->ArgMgrDefined("debug"))
163 gdcm::Debug::DebugOn();
165 /* if unused Param we give up */
166 if ( am->ArgMgrPrintUnusedLabels() )
168 am->ArgMgrUsage(usage);
173 delete am; // we don't need Argument Manager any longer
175 // ----------- End Arguments Manager ---------
177 // gdcm::File::IsReadable() is no usable here, because we deal with
178 // any kind of gdcm-Parsable *document*
179 // not only gdcm::File (as opposed to gdcm::DicomDir)
181 gdcm::File *f = new gdcm::File();
182 f->SetLoadMode(loadMode);
184 bool res = f->Load( fileName );
191 gdcm::FileHelper *fh = new gdcm::FileHelper(f);
192 fh->SetPrintLevel( level );
196 std::cout << "\n\n" << std::endl;
198 std::cout <<std::endl;
199 std::cout <<" dataSize " << fh->GetImageDataSize() << std::endl;
200 std::cout <<" dataSizeRaw " << fh->GetImageDataRawSize() << std::endl;
202 int nX,nY,nZ,sPP,planarConfig;
203 std::string pixelType;
207 std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
209 pixelType = f->GetPixelType();
210 sPP = f->GetSamplesPerPixel();
211 planarConfig = f->GetPlanarConfiguration();
213 std::cout << " pixelType= [" << pixelType
214 << "] SamplesPerPixel= [" << sPP
215 << "] PlanarConfiguration= [" << planarConfig
217 << " PhotometricInterpretation= ["
218 << f->GetEntryValue(0x0028,0x0004)
221 int numberOfScalarComponents=f->GetNumberOfScalarComponents();
222 std::cout << " NumberOfScalarComponents = " << numberOfScalarComponents
224 << " LUT = " << (f->HasLUT() ? "TRUE" : "FALSE")
227 if ( f->GetEntryValue(0x0002,0x0010) == gdcm::GDCM_NOTLOADED )
229 std::cout << "Transfer Syntax not loaded. " << std::endl
230 << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
235 std::string transferSyntaxName = f->GetTransferSyntaxName();
236 std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]"
238 std::cout << " SwapCode= " << f->GetSwapCode() << std::endl;
240 //std::cout << "\n\n" << std::endl;
241 //std::cout << "X spacing " << f->GetXSpacing() << std::endl;
242 //std::cout << "Y spacing " << f->GetYSpacing() << std::endl;
243 //std::cout << "Z spacing " << f->GetZSpacing() << std::endl;
245 // Display the LUT as an int array (for debugging purpose)
246 if ( f->HasLUT() && showlut )
248 uint8_t* lutrgba = fh->GetLutRGBA();
251 std::cout << "Lut RGBA (Palette Color) not built " << std::endl;
253 // Nothing is written yet to get LUT Data user friendly
254 // The following is to be moved into a PixelRedaConvert method
256 gdcm::SeqEntry *modLutSeq = f->GetSeqEntry(0x0028,0x3000);
259 gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem();
262 std::string lutDescriptor = sqi->GetEntryValue(0x0028,0x3002);
263 int length; // LUT length in Bytes
264 int deb; // Subscript of the first Lut Value
265 int nbits; // Lut item size (in Bits)
266 int nbRead; // nb of items in LUT descriptor (must be = 3)
268 nbRead = sscanf( lutDescriptor.c_str(),
270 &length, &deb, &nbits );
273 //gdcmWarningMacro( "Wrong LUT descriptor" );
274 std::cout << "Wrong LUT descriptor" << std::endl;
276 gdcm::BinEntry *b = sqi->GetBinEntry(0x0028,0x3006);
279 if ( b->GetLength() != 0 )
281 std::cout << "---------------------------------------"
282 << " We should never reach this point "
284 //LoadEntryBinArea(b); //LUT Data (CTX dependent)
290 std::cout << "No LUT Data (0x0028,0x3000) found " << std::endl;
294 if ( fh->GetLutItemSize() == 8 )
296 for (int i=0;i<fh->GetLutItemNumber();i++)
297 std::cout << i << " : \t"
298 << (int)(lutrgba[i*4]) << " "
299 << (int)(lutrgba[i*4+1]) << " "
300 << (int)(lutrgba[i*4+2]) << std::endl;
302 else // LutItemSize assumed to be = 16
304 uint16_t* lutrgba16 = (uint16_t*)lutrgba;
305 for (int i=0;i<fh->GetLutItemNumber();i++)
306 std::cout << i << " : \t"
307 << (int)(lutrgba16[i*4]) << " "
308 << (int)(lutrgba16[i*4+1]) << " "
309 << (int)(lutrgba16[i*4+2]) << std::endl;
315 std::cout << "Try LUT Data "<< std::endl;
320 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
322 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
323 std::cout<<std::flush;