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