]> Creatis software - gdcm.git/blob - Testing/TestMakeIcon.cxx
New gdcm2 style syntax for Load()
[gdcm.git] / Testing / TestMakeIcon.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestMakeIcon.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/07/08 13:39:57 $
7   Version:   $Revision: 1.7 $
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(output);
92    f->Print();
93    std::cout << "End of Print" << std::endl;
94
95    icon = f->GetSeqEntry(0x0088, 0x0200);
96    if (!icon)
97    {
98       std::cout << "Sequence 0088|0200 not found" << std::endl
99                 << "   ... Failed" << std::endl;
100       delete fh;
101       delete f;
102       return 1;
103    }
104    std::cout << "Sequence 0088|0200 found" << std::endl;
105    
106    sqi = icon->GetFirstSQItem();
107
108    if ( !sqi )
109    {
110       std::cout << "Sequence 0088|0200 has no SQItem" << std::endl
111                 << "   ... Failed" << std::endl;
112       delete fh;
113       delete f;
114       return 1;
115    }
116
117    std::cout << "First Item found" << std::endl;
118
119    // Test for entry 0028|0010
120    if ( !sqi->GetValEntry(0x0028,0x0010) )
121    {
122       std::cout << "ValEntry 0028|0010 not found" << std::endl
123                 << "   ... Failed" << std::endl;
124       delete fh;
125       delete f;
126       return 1;
127    }
128    std::cout << "First Item ->ValEntry 0028|0010 found" << std::endl;
129    if ( sqi->GetValEntry(0x0028,0x0010)->GetValue() != "128" )
130    {
131       std::cout << "Value 0028|0010 don't match" << std::endl
132                 << "Read : " << sqi->GetValEntry(0x0028,0x0010)->GetValue()
133                 << " - Expected : 128" << std::endl
134                 << "   ... Failed" << std::endl;
135       delete fh;
136       delete f;
137       return 1;
138    }
139
140    // Test for entry 0028|0011
141    if ( !sqi->GetValEntry(0x0028,0x0011) )
142    {
143       std::cout << "ValEntry 0028|0011 not found" << std::endl
144                 << "   ... Failed" << std::endl;
145       delete fh;
146       delete f;
147       return 1;
148    }
149    std::cout << "First Item ->ValEntry 0028|0011 found" << std::endl;
150    if ( sqi->GetValEntry(0x0028,0x0011)->GetValue() != "128" )
151    {
152       std::cout << "Value 0028|0011 don't match" << std::endl
153                 << "Read : " << sqi->GetValEntry(0x0028,0x0011)->GetValue()
154                 << " - Expected : 128" << std::endl
155                 << "   ... Failed" << std::endl;
156       delete fh;
157       delete f;
158       return 1;
159    }
160
161    // Test for entry 0028|0100
162    if ( !sqi->GetValEntry(0x0028,0x0100) )
163    {
164       std::cout << "ValEntry 0028|0100 not found" << std::endl
165                 << "   ... Failed" << std::endl;
166       delete fh;
167       delete f;
168       return 1;
169    }
170    std::cout << "First Item ->ValEntry 0028|0100 found" << std::endl;
171    if ( sqi->GetValEntry(0x0028,0x0100)->GetValue() != "8" )
172    {
173       std::cout << "Value 0028|0100 don't match" << std::endl
174                 << "Read : " << sqi->GetValEntry(0x0028,0x0100)->GetValue()
175                 << " - Expected : 8" << std::endl
176                 << "   ... Failed" << std::endl;
177       delete fh;
178       delete f;
179       return 1;
180    }
181
182    // Test for entry 0028|0101
183    if ( !sqi->GetValEntry(0x0028,0x0101) )
184    {
185       std::cout << "ValEntry 0028|0101 not found" << std::endl
186                 << "   ... Failed" << std::endl;
187       delete fh;
188       delete f;
189       return 1;
190    }
191    std::cout << "First Item ->ValEntry 0028|0101 found" << std::endl;
192    if ( sqi->GetValEntry(0x0028,0x0101)->GetValue() != "8" )
193    {
194       std::cout << "Value 0028|0101 don't match" << std::endl
195                 << "Read : " << sqi->GetValEntry(0x0028,0x0101)->GetValue()
196                 << " - Expected : 8" << std::endl
197                 << "   ... Failed" << std::endl;
198       delete fh;
199       delete f;
200       return 1;
201    }
202
203    // Test for entry 0028|0102
204    if ( !sqi->GetValEntry(0x0028,0x0102) )
205    {
206       std::cout << "ValEntry 0028|0102 not found" << std::endl
207                 << "   ... Failed" << std::endl;
208       delete fh;
209       delete f;
210       return 1;
211    }
212    std::cout << "First Item ->ValEntry 0028|0102 found" << std::endl;
213    if ( sqi->GetValEntry(0x0028,0x0102)->GetValue() != "7" )
214    {
215       std::cout << "Value 0028|0102 don't match" << std::endl
216                 << "Read : " << sqi->GetValEntry(0x0028,0x0102)->GetValue()
217                 << " - Expected : 7" << std::endl
218                 << "   ... Failed" << std::endl;
219       delete fh;
220       delete f;
221       return 1;
222    }
223
224    // Test for entry 0028|0103
225    if ( !sqi->GetValEntry(0x0028,0x0103) )
226    {
227       std::cout << "ValEntry 0028|0010 not found" << std::endl
228                 << "   ... Failed" << std::endl;
229       delete fh;
230       delete f;
231       return 1;
232    }
233    std::cout << "First Item ->ValEntry 0028|0103 found" << std::endl;
234    if ( sqi->GetValEntry(0x0028,0x0103)->GetValue() != "0" )
235    {
236       std::cout << "Value 0028|0103 don't match" << std::endl
237                 << "Read : " << sqi->GetValEntry(0x0028,0x0103)->GetValue()
238                 << " - Expected : 0" << std::endl
239                 << "   ... Failed" << std::endl;
240       delete fh;
241       delete f;
242       return 1;
243    }
244
245    // Test for entry 0005|0010
246    if ( !sqi->GetBinEntry(0x0005,0x0010) )
247    {
248       std::cout << "BinEntry 0005|0010 not found" << std::endl
249                 << "   ... Failed" << std::endl;
250       delete fh;
251       delete f;
252       return 1;
253    }
254    std::cout << "First Item ->BinEntry 0005|0010 found" << std::endl;
255    if( sqi->GetBinEntry(0x0005,0x0010)->GetLength() != 6 )
256    {
257       std::cout << "BinEntry size 0005|0010 don't match" << std::endl
258                 << "Read : " << sqi->GetValEntry(0x0005,0x0010)->GetLength()
259                 << " - Expected : 6" << std::endl
260                 << "   ... Failed" << std::endl;
261       delete fh;
262       delete f;
263       return 1;
264    }
265
266    std::cout << "Length BinEntry 0005|0010 OK" << std::endl;
267
268    if( memcmp(sqi->GetBinEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
269    {
270       std::cout << "Value 0005|0010 don't match (BinEntry)" << std::endl
271                 << "   ... Failed" << std::endl;
272       delete fh;
273       delete f;
274       return 1;
275    }
276    std::cout << "Value BinEntry 0005|0010 OK" << std::endl;
277
278    delete fh;
279    delete f;
280    std::cout << "   ... OK" << std::endl;
281
282    return 0;
283 }