]> Creatis software - gdcm.git/blob - Testing/TestMakeIcon.cxx
* Minor coding-style clean up
[gdcm.git] / Testing / TestMakeIcon.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestMakeIcon.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/18 08:35:46 $
7   Version:   $Revision: 1.9 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmDebug.h"
19 #include "gdcmGlobal.h"
20 #include "gdcmCommon.h"
21 #include "gdcmFile.h"
22 #include "gdcmFileHelper.h"
23 #include "gdcmDataEntry.h"
24 #include "gdcmSeqEntry.h"
25 #include "gdcmSQItem.h"
26
27 // 0088 0200 SQ 1 Icon Image Sequence 
28
29 int TestMakeIcon (int argc, char *argv[])
30 {
31    // hard coded small image name
32    std::string input = GDCM_DATA_ROOT;
33    input += "/"; 
34    input += "LIBIDO-8-ACR_NEMA-Lena_128_128.acr";
35
36    std::string output = "testIcon.dcm";
37
38    gdcm::Debug::DebugOn();
39
40    if ( argc == 3 )
41    {
42       input  = argv[1];
43       output = argv[2];
44    }
45    else if ( argc < 3  )
46    {
47       std::cout << "   Usage: " << argv[0]
48                 << " input filename.dcm output Filename.dcm" << std::endl;
49    }
50
51    gdcm::File *f = new gdcm::File( );
52    f->SetFileName( input );
53    f->Load( );
54
55    if ( ! f->IsReadable() )
56    {
57       std::cout << " Failed to Open/Parse file" << input << std::endl;
58       delete f;
59       return 1;
60    }  
61    gdcm::FileHelper *fh = new gdcm::FileHelper(f); 
62    uint8_t *pixels = fh->GetImageData();
63    uint32_t lgth   = fh->GetImageDataSize();
64
65    gdcm::SeqEntry *icon = f->InsertSeqEntry(0x0088, 0x0200);
66    gdcm::SQItem *sqi = new gdcm::SQItem(1);
67    icon->AddSQItem(sqi, 1);
68
69    // icone is just define like the image
70    // The purpose is NOT to imagine an icon, 
71    // just check the stuff works
72
73    uint16_t binVal[3]={0x52f7,0xf358,0xad9b};
74  
75    sqi->InsertEntryString( "MONOCHROME2", 0x0028,0x0004);
76    sqi->InsertEntryString( "128", 0x0028,0x0010);
77    sqi->InsertEntryString( "8",   0x0028,0x0100);
78    sqi->InsertEntryString( "8",   0x0028,0x0101);
79    sqi->InsertEntryString( "7",   0x0028,0x0102);
80    sqi->InsertEntryString( "0",   0x0028,0x0103);
81    sqi->InsertEntryBinArea(  (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OW");
82    sqi->InsertEntryBinArea(  pixels, lgth, 0x7fe0,0x0010);
83    // just to see if it's stored a the right place
84    sqi->InsertEntryString( "128", 0x0028,0x0011);
85     
86    fh->WriteDcmExplVR(output);
87
88    delete f;
89
90    f = new gdcm::File();
91    f->SetFileName(output);
92    f->Load();
93    f->Print();
94    std::cout << "End of Print" << std::endl;
95
96    icon = f->GetSeqEntry(0x0088, 0x0200);
97    if (!icon)
98    {
99       std::cout << "Sequence 0088|0200 not found" << std::endl
100                 << "   ... Failed" << std::endl;
101       delete fh;
102       delete f;
103       return 1;
104    }
105    std::cout << "Sequence 0088|0200 found" << std::endl;
106    
107    sqi = icon->GetFirstSQItem();
108
109    if ( !sqi )
110    {
111       std::cout << "Sequence 0088|0200 has no SQItem" << std::endl
112                 << "   ... Failed" << std::endl;
113       delete fh;
114       delete f;
115       return 1;
116    }
117
118    std::cout << "First Item found" << std::endl;
119
120    // Test for entry 0028|0010
121    if ( !sqi->GetDataEntry(0x0028,0x0010) )
122    {
123       std::cout << "GetDataEntry 0028|0010 not found" << std::endl
124                 << "   ... Failed" << std::endl;
125       delete fh;
126       delete f;
127       return 1;
128    }
129    std::cout << "First Item ->DataEntry 0028|0010 found" << std::endl;
130    if ( sqi->GetDataEntry(0x0028,0x0010)->GetString() != "128" )
131    {
132       std::cout << "Value 0028|0010 don't match" << std::endl
133                 << "Read : " << sqi->GetDataEntry(0x0028,0x0010)->GetString()
134                 << " - Expected : 128" << std::endl
135                 << "   ... Failed" << std::endl;
136       delete fh;
137       delete f;
138       return 1;
139    }
140
141    // Test for entry 0028|0011
142    if ( !sqi->GetDataEntry(0x0028,0x0011) )
143    {
144       std::cout << "GetDataEntry 0028|0011 not found" << std::endl
145                 << "   ... Failed" << std::endl;
146       delete fh;
147       delete f;
148       return 1;
149    }
150    std::cout << "First Item ->DataEntry 0028|0011 found" << std::endl;
151    if ( sqi->GetDataEntry(0x0028,0x0011)->GetString() != "128" )
152    {
153       std::cout << "Value 0028|0011 don't match" << std::endl
154                 << "Read : " << sqi->GetDataEntry(0x0028,0x0011)->GetString()
155                 << " - Expected : 128" << std::endl
156                 << "   ... Failed" << std::endl;
157       delete fh;
158       delete f;
159       return 1;
160    }
161
162    // Test for entry 0028|0100
163    if ( !sqi->GetDataEntry(0x0028,0x0100) )
164    {
165       std::cout << "GetDataEntry 0028|0100 not found" << std::endl
166                 << "   ... Failed" << std::endl;
167       delete fh;
168       delete f;
169       return 1;
170    }
171    std::cout << "First Item ->DataEntry 0028|0100 found" << std::endl;
172    if ( sqi->GetDataEntry(0x0028,0x0100)->GetString() != "8" )
173    {
174       std::cout << "Value 0028|0100 don't match" << std::endl
175                 << "Read : " << sqi->GetDataEntry(0x0028,0x0100)->GetString()
176                 << " - Expected : 8" << std::endl
177                 << "   ... Failed" << std::endl;
178       delete fh;
179       delete f;
180       return 1;
181    }
182
183    // Test for entry 0028|0101
184    if ( !sqi->GetDataEntry(0x0028,0x0101) )
185    {
186       std::cout << "GetDataEntry 0028|0101 not found" << std::endl
187                 << "   ... Failed" << std::endl;
188       delete fh;
189       delete f;
190       return 1;
191    }
192    std::cout << "First Item ->DataEntry 0028|0101 found" << std::endl;
193    if ( sqi->GetDataEntry(0x0028,0x0101)->GetString() != "8" )
194    {
195       std::cout << "Value 0028|0101 don't match" << std::endl
196                 << "Read : " << sqi->GetDataEntry(0x0028,0x0101)->GetString()
197                 << " - Expected : 8" << std::endl
198                 << "   ... Failed" << std::endl;
199       delete fh;
200       delete f;
201       return 1;
202    }
203
204    // Test for entry 0028|0102
205    if ( !sqi->GetDataEntry(0x0028,0x0102) )
206    {
207       std::cout << "DataEntry 0028|0102 not found" << std::endl
208                 << "   ... Failed" << std::endl;
209       delete fh;
210       delete f;
211       return 1;
212    }
213    std::cout << "First Item ->DataEntry 0028|0102 found" << std::endl;
214    if ( sqi->GetDataEntry(0x0028,0x0102)->GetString() != "7" )
215    {
216       std::cout << "Value 0028|0102 don't match" << std::endl
217                 << "Read : " << sqi->GetDataEntry(0x0028,0x0102)->GetString()
218                 << " - Expected : 7" << std::endl
219                 << "   ... Failed" << std::endl;
220       delete fh;
221       delete f;
222       return 1;
223    }
224
225    // Test for entry 0028|0103
226    if ( !sqi->GetDataEntry(0x0028,0x0103) )
227    {
228       std::cout << "GetDataEntry 0028|0010 not found" << std::endl
229                 << "   ... Failed" << std::endl;
230       delete fh;
231       delete f;
232       return 1;
233    }
234    std::cout << "First Item ->DataEntry 0028|0103 found" << std::endl;
235    if ( sqi->GetDataEntry(0x0028,0x0103)->GetString() != "0" )
236    {
237       std::cout << "Value 0028|0103 don't match" << std::endl
238                 << "Read : " << sqi->GetDataEntry(0x0028,0x0103)->GetString()
239                 << " - Expected : 0" << std::endl
240                 << "   ... Failed" << std::endl;
241       delete fh;
242       delete f;
243       return 1;
244    }
245
246    // Test for entry 0005|0010
247    if ( !sqi->GetDataEntry(0x0005,0x0010) )
248    {
249       std::cout << "GetDataEntry 0005|0010 not found" << std::endl
250                 << "   ... Failed" << std::endl;
251       delete fh;
252       delete f;
253       return 1;
254    }
255    std::cout << "First Item ->GetDataEntry 0005|0010 found" << std::endl;
256    if( sqi->GetDataEntry(0x0005,0x0010)->GetLength() != 6 )
257    {
258       std::cout << "GetDataEntry size 0005|0010 don't match" << std::endl
259                 << "Read : " << sqi->GetDataEntry(0x0005,0x0010)->GetLength()
260                 << " - Expected : 6" << std::endl
261                 << "   ... Failed" << std::endl;
262       delete fh;
263       delete f;
264       return 1;
265    }
266
267    std::cout << "Length GetDataEntry 0005|0010 OK" << std::endl;
268
269    if( memcmp(sqi->GetDataEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
270    {
271       std::cout << "Value 0005|0010 don't match (DataEntry)" << std::endl
272                 << "   ... Failed" << std::endl;
273       delete fh;
274       delete f;
275       return 1;
276    }
277    std::cout << "Value DataEntry 0005|0010 OK" << std::endl;
278
279    delete fh;
280    delete f;
281    std::cout << "   ... OK" << std::endl;
282
283    return 0;
284 }