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