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